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 "constants.hpp"
13 #include "pci_id.hpp"
14 
15 #include "types.hpp"
16 
17 #include <cuda_runtime_api.h>
18 
19 #include <stdexcept>
20 
21 
22 // The following un-definitions avoid warnings about
23 // the use of `major` and `minor` in certain versions
24 // of the GNU C library
25 #ifdef major
26 #undef major
27 #endif
28 
29 #ifdef minor
30 #undef minor
31 #endif
32 
33 namespace cuda {
34 
35 namespace device {
36 
41 
54  unsigned major;
55 
56  const char* name() const;
57 
58  constexpr bool is_valid() const noexcept;
59 
60 };
61 
62 // TODO: Consider making this a non-POD struct,
63 // with a proper ctor checking validity, an operator converting to pair etc;
64 // however, that would require including at least ::std::utility, if not other
65 // stuff (e.g. for an ::std::hash specialization)
66 // TODO: If we constrained this to versions we know about, we could make the
67 // methods noexcept
75 
76  compute_architecture_t architecture;
77  unsigned minor_;
78 
79  constexpr static compute_capability_t from_combined_number(unsigned combined) noexcept;
80 
81  constexpr unsigned major() const { return architecture.major; }
82  unsigned constexpr minor() const { return minor_; }
83 
84  constexpr unsigned as_combined_number() const noexcept;
85  constexpr bool is_valid() const noexcept;
86  unsigned max_warp_schedulings_per_processor_cycle() const;
87  unsigned max_resident_warps_per_processor() const;
88  // Note: Based on _ConvertSMVer2Cores() in the CUDA samples helper code
89  unsigned max_in_flight_threads_per_processor() const;
93  memory::shared::size_t max_shared_memory_per_block() const;
94 };
95 
101 constexpr compute_capability_t make_compute_capability(unsigned combined) noexcept;
102 
106 constexpr compute_capability_t make_compute_capability(unsigned major, unsigned minor) noexcept;
107 
120 struct properties_t : public cudaDeviceProp {
121 
122  properties_t() = default;
123  properties_t(const cudaDeviceProp& cdp) noexcept : cudaDeviceProp(cdp) { };
124  properties_t(cudaDeviceProp&& cdp) noexcept : cudaDeviceProp(cdp) { };
125  bool usable_for_compute() const noexcept;
126  compute_capability_t compute_capability() const noexcept
127  {
128  return { { static_cast<unsigned>(major) }, static_cast<unsigned>(minor) };
129  }
130  compute_architecture_t compute_architecture() const noexcept { return { static_cast<unsigned>(major) }; };
131  pci_location_t pci_id() const noexcept { return { pciDomainID, pciBusID, pciDeviceID, pci_location_t::unused }; }
132 
133  unsigned long long max_in_flight_threads_on_device() const
134  {
135  return compute_capability().max_in_flight_threads_per_processor() * multiProcessorCount;
136  }
137 
138  grid::block_dimension_t max_threads_per_block() const noexcept { return maxThreadsPerBlock; }
139  grid::block_dimension_t max_warps_per_block() const noexcept { return maxThreadsPerBlock / warp_size; }
140  size_t max_shared_memory_per_block() const noexcept { return sharedMemPerBlock; }
141  size_t global_memory_size() const noexcept { return totalGlobalMem; }
142  bool can_map_host_memory() const noexcept { return canMapHostMemory != 0; }
143 };
144 
145 } // namespace device
146 } // namespace cuda
147 
149 
150 #endif // CUDA_API_WRAPPERS_DEVICE_PROPERTIES_HPP_
Implementation of methods and helper functions for device-property-related classes.
All definitions and functionality wrapping the CUDA Runtime API.
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:332
A numeric designator of the computational capabilities of a CUDA device.
Definition: device_properties.hpp:74
unsigned size_t
Each physical core ("Symmetric Multiprocessor") on an nVIDIA GPU has a space of shared memory (see th...
Definition: types.hpp:649
unsigned major
A compute_capability_t has a "major" and a "minor" number, with "major" indicating the architecture; ...
Definition: device_properties.hpp:54
Location "coordinates" for a CUDA device on a PCIe bus.
Definition: pci_id.hpp:24
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:48
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:120
int multiprocessor_count_t
Type of the number of mutiprocessors within a single GPU.
Definition: device_properties.hpp:40
Fundamental CUDA-related type definitions.
Definition of a wrapper class for CUDA PCI device ID information.