C++中编译期的宏定义怎么确认呢?
可以通过下面打印方式获取到。
#include <cstdio>
#define STR_HELPER(x) #x
#define STR(x) STR_HELPER(x)
__device__ void print_arch(){
const char my_compile_time_arch[] = STR(__CUDA_ARCH__);
printf("__CUDA_ARCH__: %s\n", my_compile_time_arch);
}
__global__ void example()
{
print_arch();
}
int main(){
const char macro[] = STR(__GCU_ARCH__);//
printf("__GCU_ARCH__: %s\n", macro);
const char macro1[] = STR(__CUDACC_VER_MAJOR__);//__GCU_ARCH__
printf("__CUDACC_VER_MAJOR__: %s\n", macro1);
const char my_compile_time_arch[] = STR(__CUDA_ARCH__);
printf("__CUDA_ARCH__: %s\n", my_compile_time_arch);
example<<<1,1>>>();
cudaDeviceSynchronize();
}