Skip to content

Instantly share code, notes, and snippets.

@Roxbili
Created November 22, 2023 01:48
Show Gist options
  • Save Roxbili/f10d9486d2bf565c9361926fbf22768e to your computer and use it in GitHub Desktop.
Save Roxbili/f10d9486d2bf565c9361926fbf22768e to your computer and use it in GitHub Desktop.

保存以下内容为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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment