It is not possible to verify which architecture is working on a piece of code, but there is no need to know, because it can be determined at compile time and processed accordingly. nvcc defines several preprocessor characters that can be used to parse the compilation path when compiling code. The symbol character __CUDA_ARCH__ , which is never determined when compiling the host code and is always determined when compiling the device code.
Thus, you can write a function like this:
__device__ __host__ float function(float x) { #ifdef __CUDA_ARCH__ return 10.0f * __sinf(x); #else return 10.0f * sin(x); #endif }
which produces a different code depending on whether it is compiled for the GPU or host. You can read a more detailed discussion of compilation control in this stack overflow question or in the C language extension in the CUDA programming guide.
source share