imate
C++/CUDA Reference
device_properties.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 "./device_properties.h"
17 #include <cstdlib> // NULL
18 
19 
20 // ===========
21 // Constructor
22 // ===========
23 
26 
28  num_devices(0),
29  num_multiprocessors(NULL),
30  num_threads_per_multiprocessor(NULL)
31 {
32 }
33 
34 
35 // ==========
36 // Destructor
37 // ==========
38 
41 
43 {
44  this->deallocate_members();
45 }
46 
47 
48 // ==================
49 // deallocate members
50 // ==================
51 
54 
56 {
57  if (this->num_multiprocessors != NULL)
58  {
59  delete[] this->num_multiprocessors;
60  this->num_multiprocessors = NULL;
61  }
62 
63  if (this->num_threads_per_multiprocessor != NULL)
64  {
65  delete[] this->num_threads_per_multiprocessor;
66  this->num_threads_per_multiprocessor = NULL;
67  }
68 }
69 
70 
71 // ===============
72 // set num devices
73 // ===============
74 
80 
81 void DeviceProperties::set_num_devices(int num_devices_)
82 {
83  this->num_devices = num_devices_;
84 
85  // Deallocate members in case they were allocated before
86  this->deallocate_members();
87 
88  // Allocate members
89  this->num_multiprocessors = new int[this->num_devices];
90  this->num_threads_per_multiprocessor = new int[this->num_devices];
91 }
void deallocate_members()
Deallocates the member data.
~DeviceProperties()
Destructor.
DeviceProperties()
Constructor.
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.