Why the __device__ variable can't be marked as constexpr?

Viewed 111

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?

1 Answers

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 keyword constexpr.

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.

Related