cuda-api-wrappers
Thin C++-flavored wrappers for the CUDA Runtime API
device_properties.hpp
Go to the documentation of this file.
1 
7 #pragma once
8 #ifndef CUDA_API_WRAPPERS_DEVICE_PROPERTIES_HPP_
9 #define CUDA_API_WRAPPERS_DEVICE_PROPERTIES_HPP_
10 
11 #include "constants.hpp"
12 #include "pci_id.hpp"
13 
14 #include "types.hpp"
15 
16 #include <cuda_runtime_api.h>
17 
18 #include <stdexcept>
19 
20 
21 // The following un-definitions avoid warnings about
22 // the use of `major` and `minor` in certain versions
23 // of the GNU C library
24 #ifdef major
25 #undef major
26 #endif
27 
28 #ifdef minor
29 #undef minor
30 #endif
31 
32 namespace cuda {
33 
34 namespace device {
35 
38 
51  unsigned major;
52 
58  const char* name() const;
59 
62  constexpr bool is_valid() const noexcept;
63 
64 };
65 
76 
79 
83  unsigned minor_;
84 
93  constexpr static compute_capability_t from_combined_number(unsigned combined) noexcept;
94 
95  constexpr unsigned major() const { return architecture.major; }
96  unsigned constexpr minor() const { return minor_; }
97 
105  constexpr unsigned as_combined_number() const noexcept;
106 
109  constexpr bool is_valid() const noexcept;
110 
113  unsigned max_warp_schedulings_per_processor_cycle() const;
114  unsigned max_resident_warps_per_processor() const;
116 
118  unsigned max_in_flight_threads_per_processor() const;
119 
122  memory::shared::size_t max_shared_memory_per_block() const;
123 };
124 
130 constexpr compute_capability_t make_compute_capability(unsigned combined) noexcept;
131 
135 constexpr compute_capability_t make_compute_capability(unsigned major, unsigned minor) noexcept;
136 
149 struct properties_t : public cudaDeviceProp {
150 
151  properties_t() = default;
152  properties_t(const cudaDeviceProp& cdp) noexcept : cudaDeviceProp(cdp) { };
153  properties_t(cudaDeviceProp&& cdp) noexcept : cudaDeviceProp(cdp) { };
154 
158  bool usable_for_compute() const noexcept;
159  compute_capability_t compute_capability() const noexcept
160  {
161  return { { static_cast<unsigned>(major) }, static_cast<unsigned>(minor) };
162  }
163  compute_architecture_t compute_architecture() const noexcept { return { static_cast<unsigned>(major) }; };
164  pci_location_t pci_id() const noexcept { return { pciDomainID, pciBusID, pciDeviceID, {} }; }
165 
166  unsigned max_in_flight_threads_on_device() const
167  {
168  return compute_capability().max_in_flight_threads_per_processor() * multiProcessorCount;
169  }
170 
171  grid::block_dimension_t max_threads_per_block() const noexcept { return maxThreadsPerBlock; }
172  grid::block_dimension_t max_warps_per_block() const noexcept { return maxThreadsPerBlock / warp_size; }
173  size_t max_shared_memory_per_block() const noexcept { return sharedMemPerBlock; }
174  size_t global_memory_size() const noexcept { return totalGlobalMem; }
175  bool can_map_host_memory() const noexcept { return canMapHostMemory != 0; }
177 };
178 
179 } // namespace device
180 } // namespace cuda
181 
182 #include "detail/device_properties.hpp"
183 
184 #endif // CUDA_API_WRAPPERS_DEVICE_PROPERTIES_HPP_
Definitions and functionality wrapping CUDA APIs.
Definition: array.hpp:22
dimension_t block_dimension_t
CUDA kernels are launched in grids of blocks of threads, in 3 dimensions.
Definition: types.hpp:312
A numeric designator of the computational capabilities of a CUDA device.
Definition: device_properties.hpp:75
unsigned size_t
Each physical core ("Symmetric Multiprocessor") on an nVIDIA GPU has a space of shared memory (see th...
Definition: types.hpp:730
unsigned major
A compute_capability_t has a "major" and a "minor" number, with "major" indicating the architecture; ...
Definition: device_properties.hpp:51
Location "coordinates" for a CUDA device on a PCIe bus.
Definition: pci_id.hpp:24
compute_architecture_t architecture
The major capability designator.
Definition: device_properties.hpp:78
Fundamental CUDA-related constants and enumerations, not dependent on any more complex abstractions...
A numeric designator of an architectural generation of CUDA devices.
Definition: device_properties.hpp:45
constexpr compute_capability_t make_compute_capability(unsigned combined) noexcept
A named constructor idiom for {compute_capability_t}.
A structure holding a collection various properties of a device.
Definition: device_properties.hpp:149
constexpr bool is_valid() const noexcept
unsigned minor_
The minor designator, indicating mostly numeric choices of capabilities (e.g.
Definition: device_properties.hpp:83
int multiprocessor_count_t
Type of the number of mutiprocessors within a single GPU.
Definition: device_properties.hpp:37
Fundamental CUDA-related type definitions.
Definition of a wrapper class for CUDA PCI device ID information.