Hi!
Quick question - are there any issues/concerns/implications with using C++ header <cstdint>
and using std::
integer types, e.g. std::int32_t
?
Example:
#include <cstdint>
__global__ void foo(std::int32_t x)
{
...
}
The code compiles and works (C++14), but I wonder if this is “correct” or can this cause issues in the future.
Thanks!
These types usually are just typedefs and work perfectly fine. If this worries you, you can use the official libcudacxx
GitHub - NVIDIA/libcudacxx: The C++ Standard Library for your entire system. which is a host/device standard library.
#include <cuda/std/cstdint>
__global__ void foo(cuda::std::int32_t* x){
*x = 42;
}
Thanks for the info!
Unfortunately we are restricted to not using libcudaxx at the moment, so we need to go for the Standard headers.
Will this also work when cross-compiling for another target, say Jetson? Are the host typedefs guaranteed to be the same as the target typedefs?
After some more research, I conclude that:
- Host and device must have the same size of ints, otherwise memcopying between host and device would not make sense.
- NVCC will use whichever host compiler (x86 or aarch64) as preprocessor.
- The preprocessed file will include the int types from /usr/include (x86) or /path/to/cross-toolchain/usr/include
So my conclusion is that host and device code use the same integer types, therefore it’s safe to use std::int32_t in device code.
Let me know if you see any flaw in my reasoning!