Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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 :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading