imate
C++/CUDA Reference
Loading...
Searching...
No Matches
query_device.cu
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: Copyright 2021, Siavash Ameli <sameli@berkeley.edu>
3 * SPDX-License-Identifier: BSD-3-Clause
4 * SPDX-FileType: SOURCE
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the license found in the LICENSE.txt file in the root
8 * directory of this source tree.
9 */
10
11
12// =======
13// Headers
14// =======
15
16#include "./query_device.h"
17
18
19// ============
20// query device
21// ============
22
30
31void query_device(DeviceProperties& device_properties)
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.
void query_device(DeviceProperties &device_properties)
Queries GPU device information, such as the number of devices, number of multiprocessors,...
Properties of GPU devices.
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.