MCPcopy Create free account
hub / github.com/NGSolve/ngsolve / InitCUDA

Function InitCUDA

ngscuda/cuda_ngstd.cpp:43–105  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41
42
43 void InitCUDA (int verbose)
44 {
45 int devCount;
46 printf("CUDA Device Query...\n");
47
48 cudaError_t err = cudaGetDeviceCount(&devCount);
49 if (err != cudaSuccess) {
50 fprintf(stderr, "cudaGetDeviceCount() failed: %s\n", cudaGetErrorString(err));
51 return;
52 }
53
54 if (devCount == 1)
55 printf("There is %d CUDA device.\n", devCount);
56 else
57 printf("There are %d CUDA devices.\n", devCount);
58
59 for (int i = 0; i < devCount; ++i)
60 {
61 // Get device properties
62 cudaDeviceProp devProp;
63 cudaGetDeviceProperties(&devProp, i);
64 int clock_rate;
65 cudaDeviceGetAttribute(&clock_rate, cudaDevAttrClockRate, i);
66
67 if(i==0)
68 gpu_clock = clock_rate * 1000;
69
70 if (verbose == 1)
71 {
72 cout << "CUDA Device " << i << ": " << devProp.name
73 << ", cap " << devProp.major << "." << devProp.minor << endl;
74 }
75 if (verbose >= 2)
76 {
77 cout << endl << "CUDA Device " << i << endl;
78 printDevProp(devProp, i);
79 }
80 }
81
82 int dev_id = 0;
83
84 const char* env_p = std::getenv("NGS_CUDA_DEVICE_INDEX");
85 if (env_p != nullptr)
86 {
87 dev_id = std::atoi(env_p);
88 cudaError_t err = cudaSetDevice(dev_id);
89 if (err != cudaSuccess) {
90 fprintf(stderr, "cudaSetDevice() failed: %s\n", cudaGetErrorString(err));
91 return;
92 }
93 }
94
95 cudaGetDevice(&dev_id);
96 if(verbose >= 1)
97 cout << "Using device " << dev_id << endl;
98
99
100#if defined(CUDA_VERSION)

Callers 1

PYBIND11_MODULEFunction · 0.85

Calls 1

printDevPropFunction · 0.85

Tested by

no test coverage detected