(I’m posting this here since I noticed some of the visitors to my repositories such as this one tend to notice this script which is not one of their main features. Also, I got asked about this the other day and the person who asked had not found the answer on StackOverflow for some reason.)
Consider the following scenario:
You want to compile some CUDA code on a machine that’s not your own (which happens if you’re distributing any piece of software intended for machines with different GPUs - and you’ll have this challenge in your CMake, or scons, or what-not).
How do you know which “sm_xx” value to specify with the “–gpu_architecture=” (or “–gpu_code=”) switch?
It’s a conundrum! To my knowledge (correct me if I’m wrong) no utility that’s part of CUDA provides that information; not even nvidia-smi (at least, not directly).
So here is a small script which does the trick, using a “here-document” C program compiled on the fly which just uses the CUDA runtime API to check (and is deleted after running).