https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104714
--- Comment #1 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Tom de Vries from comment #0)
> [ FWIW, it would be great if we could simply specify -march=native, and have
> gcc query the nvidia driver to see what board there is using
> cuDeviceGetAttribute and CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR and
> CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR. And possibly handle the
> situation of multiple boards by using the minimum. But, much more involved
> to realize. ]
Though, it might be better to handle this externally, so have a tool:
...
$ cat test.c
#include <stdio.h>
#include <cuda.h>
int compute_capability_major;
int compute_capability_minor;
int
main (void)
{
cuInit(0);
int num_devices;
cuDeviceGetCount (&num_devices);
for (int i = 0; i < num_devices; ++i)
{
CUdevice device;
cuDeviceGet (&device, i);
cuDeviceGetAttribute (&compute_capability_major,
CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR,
device);
cuDeviceGetAttribute (&compute_capability_minor,
CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR,
device);
printf ("sm_%d%d\n", compute_capability_major, compute_capability_minor);
}
return 0;
}
...
that compiles like so:
...
$ gcc test.c -I ~/cuda/11.6.0/include -lcuda -o a.out -g
...
and prints:
...
$ ./a.out
sm_75
...
and then name the tool nvptx-print-native or some such and use:
...
native=$(nvptx-print-native)
$cc ... -march=$native
...
in scripts.