Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@valgur
Last active April 24, 2019 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save valgur/12061b5606eec9892e1d43f9d58c7845 to your computer and use it in GitHub Desktop.
Save valgur/12061b5606eec9892e1d43f9d58c7845 to your computer and use it in GitHub Desktop.
Generate CUDA -gencode parameters for available GPU devices. Usage: chmod +x get_cuda_gencode.cpp && ./get_cuda_gencode.cpp
//usr/bin/env nvcc --run "$0" -o /tmp/get_cuda_gencode; rm /tmp/get_cuda_gencode; exit
#include <cuda_runtime_api.h>
#include <iostream>
#include <set>
int main(int argc, char *argv[]) {
cudaDeviceProp prop;
cudaError_t status;
int device_count;
status = cudaGetDeviceCount(&device_count);
if (status != cudaSuccess) {
std::cerr << "cudaGetDeviceCount() failed: " << cudaGetErrorString(status) << std::endl;
return -1;
}
if (device_count == 0) {
std::cerr << "No CUDA devices found" << std::endl;
return -1;
}
std::set<int> versions;
for (int device_index = 0; device_index < device_count; device_index++) {
status = cudaGetDeviceProperties(&prop, device_index);
if (status != cudaSuccess) {
std::cerr << "cudaGetDeviceCount() for device " << device_index << " failed: "
<< cudaGetErrorString(status) << std::endl;
return -1;
}
versions.insert(prop.major * 10 + prop.minor);
}
bool first = true;
for (auto &v : versions) {
if (!first)
std::cout << ' ';
first = false;
std::cout << "-gencode arch=compute_" << v << ",code=sm_" << v << " ";
}
std::cout << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment