保存以下内容为print_cuda_arch.cu
#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(){
example<<<1,1>>>();
cudaDeviceSynchronize();
}
编译并执行命令:
nvcc -o print_cuda_arch print_cuda_arch.cu
./print_cuda_arch