'Why the __device__ variable can't be marked as constexpr?
If I declare/define a variable like this:
__device__ constexpr int test{5};
I get an error
error: A
__device__variable cannot be marked constexpr
I can't find in the guide that restriction. The guide says:
I.4.20.9.
__managed__and__shared__variables cannot be marked with the keyword constexpr.
Moreover, my colleague with the same major compiler version (11) doesn't have this error.
What exactly causes this error on my machine?
Solution 1:[1]
In CUDA 11.2, such usage was not allowed. See here:
G.4.16.9.
__device__/__constant__/__shared__variables__device__,__constant__and__shared__variables cannot be marked with the keywordconstexpr.
In CUDA 11.4 (and beyond) such usage is allowed.
The change in behavior allowed by the compiler took place sometime between the CUDA 11.2.0 version and the CUDA 11.4.0 version.
Presumably the passing machine has a newer CUDA 11 version than yours.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
