imate
C++/CUDA Reference
query_device.cu File Reference
#include "./query_device.h"
Include dependency graph for query_device.cu:

Go to the source code of this file.

Functions

void query_device (DeviceProperties &device_properties)
 Queries GPU device information, such as the number of devices, number of multiprocessors, and the number of threads per each multiprocessor. More...
 

Function Documentation

◆ query_device()

void query_device ( DeviceProperties device_properties)

Queries GPU device information, such as the number of devices, number of multiprocessors, and the number of threads per each multiprocessor.

Parameters
[out]device_propertiesA struct to be filled with the number of devices, threads and multiprocessors.

Definition at line 31 of file query_device.cu.

32 {
33  // Query number of devices
34  int num_devices;
35  cudaError_t error = cudaGetDeviceCount(&num_devices);
36  if (error != cudaSuccess)
37  {
38  return;
39  }
40 
41  // Set number of devices
42  device_properties.set_num_devices(num_devices);
43 
44  // Read properties of each device
45  struct cudaDeviceProp properties;
46  for (int device = 0; device < num_devices; ++device)
47  {
48  cudaGetDeviceProperties(&properties, device);
49 
50  // Machines with no GPUs may still report one emulation device
51  if (properties.major == 9999)
52  {
53  // This is a gpu emulation not an actual device
54  device_properties.num_multiprocessors[device] = 0;
55 
56  device_properties.num_threads_per_multiprocessor[device] = 0;
57  }
58  else
59  {
60  device_properties.num_multiprocessors[device] = \
61  properties.multiProcessorCount;
62 
63  device_properties.num_threads_per_multiprocessor[device] = \
64  properties.maxThreadsPerMultiProcessor;
65  }
66  }
67 }
cudaError_t cudaGetDeviceCount(int *count)
Definition of CUDA's cudaGetDeviceCount function using dynamically loaded cudart library.
cudaError_t cudaGetDeviceProperties(cudaDeviceProp *prop, int device)
Definition of CUDA's cudaGetDeviceProperties function using dynamically loaded cudart library.
int * num_threads_per_multiprocessor
void set_num_devices(int num_devices_)
Sets the number of devices and allocates memory for member data with the size of devices.

References cudaGetDeviceCount(), cudaGetDeviceProperties(), DeviceProperties::num_multiprocessors, DeviceProperties::num_threads_per_multiprocessor, and DeviceProperties::set_num_devices().

Here is the call graph for this function: