-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Abstract the use of constexpr aggregate host/device constants #36311
Comments
A new Issue was created by @fwyzard Andrea Bocci. @Dr15Jones, @perrotta, @dpiparo, @makortel, @smuzaffar, @qliphy can you please review it and eventually sign/assign? Thanks. cms-bot commands are listed here |
assign heterogeneous |
Duplicate of #35370 |
Implemented in #37159 |
+heterogeneous |
This issue is fully signed and ready to be closed. |
-heterogeneous |
The method mentioned above does not work if the non-scalar element is a static member of a class like, e.g. in https://github.com/cms-sw/cmssw/blob/master/DataFormats/EcalDigi/interface/EcalConstants.h#L9 Replacing I have also tried to apply it to the whole class with |
@thomreis |
@VinInn yes, definitely. |
The ability to pass the class as a template is exactly why it was set up like this, yes. The Phase 2 ECAL reconstruction we are currently working on relies on it. |
what about
|
That compiles, yes, and runs as well. |
With namespace one {
__device__ constexpr float g[n] = {1.,2.};
}
struct One {
static constexpr float const * g = one::g;
}; is the access to |
Yes it seems as if it is. |
To do: document the use of the |
The use of host-side
consexpr
constants in device code is limited tolong double
)constexpr
functionsIn particular, it's not possible to use
constexpr
scalars by pointer or reference (e.g.std::min()
takes arguments by reference), or passconstexpr
arrays as pointers, or access elements ofconstexpr
arrays outside ofconstexpr
functions.The workaround that we found, is to write portable code that declare two copies of the constants, one on the host and one on the device:
We should probably abstract it with something like
to be used as
HOST_DEVICE_CONSTANT uint32_t values[N] = { ... };
Suggestions for a better name are welcome :-)
The text was updated successfully, but these errors were encountered: