cuda-api-wrappers
Thin C++-flavored wrappers for the CUDA Runtime API
device_properties.hpp
Go to the documentation of this file.
1 
8 #pragma once
9 #ifndef CUDA_API_WRAPPERS_DEVICE_PROPERTIES_HPP_
10 #define CUDA_API_WRAPPERS_DEVICE_PROPERTIES_HPP_
11 
12 #include <cuda/api/constants.hpp>
13 #include <cuda/api/pci_id.hpp>
14 #include <cuda/common/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 
48  unsigned major;
49 
50  const char* name() const;
51  unsigned max_warp_schedulings_per_processor_cycle() const;
52  unsigned max_resident_warps_per_processor() const;
53  unsigned max_in_flight_threads_per_processor() const;
54 
61 
62  constexpr bool is_valid() const noexcept;
63 
64 };
65 
66 // TODO: Consider making this a non-POD struct,
67 // with a proper ctor checking validity, an operator converting to pair etc;
68 // however, that would require including at least ::std::utility, if not other
69 // stuff (e.g. for an ::std::hash specialization)
70 // TODO: If we constrained this to versions we know about, we could make the
71 // methods noexcept
79 
80  compute_architecture_t architecture;
81  unsigned minor_;
82 
83  constexpr static compute_capability_t from_combined_number(unsigned combined) noexcept;
84 
85  constexpr unsigned major() const { return architecture.major; }
86  unsigned constexpr minor() const { return minor_; }
87 
88  constexpr unsigned as_combined_number() const noexcept;
89  constexpr bool is_valid() const noexcept;
90  unsigned max_warp_schedulings_per_processor_cycle() const;
91  unsigned max_resident_warps_per_processor() const;
92  unsigned max_in_flight_threads_per_processor() const;
99 
100 
101 };
102 
108 constexpr compute_capability_t make_compute_capability(unsigned combined) noexcept;
109 
113 constexpr compute_capability_t make_compute_capability(unsigned major, unsigned minor) noexcept;
114 
127 struct properties_t : public cudaDeviceProp {
128 
129  properties_t() = default;
130  properties_t(const cudaDeviceProp& cdp) noexcept : cudaDeviceProp(cdp) { };
131  properties_t(cudaDeviceProp&& cdp) noexcept : cudaDeviceProp(cdp) { };
132  bool usable_for_compute() const noexcept;
133  compute_capability_t compute_capability() const noexcept { return { { (unsigned) major }, (unsigned) minor }; }
134  compute_architecture_t compute_architecture() const noexcept { return { (unsigned) major }; };
135  pci_location_t pci_id() const noexcept { return { pciDomainID, pciBusID, pciDeviceID }; }
136 
137  unsigned long long max_in_flight_threads_on_device() const
138  {
139  return compute_capability().max_in_flight_threads_per_processor() * multiProcessorCount;
140  }
141 
142  grid::block_dimension_t max_threads_per_block() const noexcept { return maxThreadsPerBlock; }
143  grid::block_dimension_t max_warps_per_block() const noexcept { return maxThreadsPerBlock / warp_size; }
144  size_t max_shared_memory_per_block() const noexcept { return sharedMemPerBlock; }
145  size_t global_memory_size() const noexcept { return totalGlobalMem; }
146  bool can_map_host_memory() const noexcept { return canMapHostMemory != 0; }
147 };
148 
149 } // namespace device
150 } // namespace cuda
151 
152 #include <cuda/api/detail/device_properties.hpp>
153 
154 #endif // CUDA_API_WRAPPERS_DEVICE_PROPERTIES_HPP_
All definitions and functionality wrapping the CUDA Runtime API.
Definition: array.hpp:17
A numeric designator of the computational capabilities of a CUDA device.
Definition: device_properties.hpp:78
unsigned size_t
Each physical core ("Symmetric Multiprocessor") on an nVIDIA GPU has a space of shared memory (see th...
Definition: types.hpp:342
Fundamental CUDA-related type definitions.
memory::shared::size_t max_shared_memory_per_block() const
unsigned major
A compute_capability_t has a "major" and a "minor" number, with "major" indicating the architecture; ...
Definition: device_properties.hpp:48
dimension_t block_dimension_t
CUDA kernels are launched in grids of blocks of threads, in 3 dimensions.
Definition: types.hpp:258
Location "coordinates" for a CUDA device on a PCIe bus.
Definition: pci_id.hpp:27
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:42
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:127
Definition of a wrapper class for CUDA PCI device ID information.