Skip to content

Instantly share code, notes, and snippets.

@moznion
Created September 4, 2014 11:25
Show Gist options
  • Save moznion/6baa6995128a0ce5a18a to your computer and use it in GitHub Desktop.
Save moznion/6baa6995128a0ce5a18a to your computer and use it in GitHub Desktop.
#include <stdio.h>
int main(int argc, char** argv) {
cudaError_t err;
char *device_name = "Quadro K6000";
int device_count;
err = cudaGetDeviceCount(&device_count);
if (err) {
fprintf(stderr, "Cannnot get device count\n");
return err;
}
int *device_ids;
device_ids = (int *)malloc(sizeof(int) * device_count);
cudaDeviceProp device_prop;
int hits = 0;
for (int id = 0; id < device_count; id++) {
err = cudaGetDeviceProperties(&device_prop, id);
if (strcmp(device_prop.name, device_name) == 0) {
device_ids[hits] = id;
hits++;
}
}
for (int i = 0; i < hits; i++) {
printf("%d\n", device_ids[i]);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment