Last active
December 17, 2020 06:39
-
-
Save xwang233/56b4e2e0f1b29631d30d2e68e4cdc17f to your computer and use it in GitHub Desktop.
Shell script for determining the SM value for your (single) GPU. Based on https://gist.github.com/eyalroz/71ce52fa80acdd1c3b192e43a6c1d930
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Prints the compute capability of all the CUDA device installed | |
# on the system. | |
timestamp=$(date +%s.%N) | |
gcc_binary=${CMAKE_CXX_COMPILER:-$(which c++)} | |
cuda_root=${CUDA_DIR:-/usr/local/cuda} | |
CUDA_INCLUDE_DIRS=${CUDA_INCLUDE_DIRS:-${cuda_root}/include} | |
CUDA_CUDART_LIBRARY=${CUDA_CUDART_LIBRARY:-${cuda_root}/lib64/libcudart.so} | |
generated_binary="/tmp/cuda-compute-version-helper-$$-$timestamp" | |
# create a 'here document' that is code we compile and use to probe the card | |
source_code="$(cat << EOF | |
#include <stdio.h> | |
#include <cuda_runtime_api.h> | |
int main() | |
{ | |
cudaDeviceProp prop; | |
cudaError_t status; | |
int device_count; | |
status = cudaGetDeviceCount(&device_count); | |
if (status != cudaSuccess) { | |
fprintf(stderr,"cudaGetDeviceCount() failed: %s\n", cudaGetErrorString(status)); | |
return -1; | |
} | |
printf("Device, compute capability, PCI bus ID\n"); | |
for (int i=0; i < device_count; i++) { | |
status = cudaGetDeviceProperties(&prop, i); | |
if (status != cudaSuccess) { | |
fprintf(stderr,"cudaGetDeviceProperties() for device %d failed: %s\n", i, cudaGetErrorString(status)); | |
return -1; | |
} | |
int v = prop.major * 10 + prop.minor; | |
printf("%s, %d, %X\n", prop.name, v, prop.pciBusID); | |
} | |
} | |
EOF | |
)" | |
echo "$source_code" | $gcc_binary -x c++ -I"$CUDA_INCLUDE_DIRS" -o "$generated_binary" - -x none "$CUDA_CUDART_LIBRARY" | |
# probe the card and cleanup | |
$generated_binary | |
rm $generated_binary |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment