cuda-api-wrappers
Thin C++-flavored wrappers for the CUDA Runtime API
pci_id.hpp
Go to the documentation of this file.
1 
7 #pragma once
8 #ifndef CUDA_API_WRAPPERS_PCI_ID_CUH_
9 #define CUDA_API_WRAPPERS_PCI_ID_CUH_
10 
11 #include <cuda/api/error.hpp>
12 #include <cuda/common/types.hpp>
13 
14 #include <cuda_runtime_api.h>
15 
16 #include <string>
17 
18 namespace cuda {
19 namespace device {
20 
28  // This is simply what we get in CUDA's cudaDeviceProp structure
29  int domain;
30  int bus;
31  int device;
32  int function;
33 
34  operator ::std::string() const;
35  // This is not a ctor so as to maintain the PODness
36  static pci_location_t parse(const ::std::string& id_str);
37  static pci_location_t parse(const char* id_str);
38 public:
39  static constexpr const int unused { -1 };
40  // In lieu of making this class a variant with 3 type combinations.
41 };
42 
43 namespace detail_ {
44 
51 inline id_t resolve_id(pci_location_t pci_id)
52 {
53  ::std::string as_string { pci_id };
54  id_t cuda_device_id;
55  auto result = cudaDeviceGetByPCIBusId(&cuda_device_id, as_string.c_str());
56  throw_if_error(result,
57  "Failed obtaining a CUDA device ID corresponding to PCI id " + as_string);
58  return cuda_device_id;
59 }
60 
61 } // namespace detail_
62 
63 
64 } // namespace device
65 } // namespace cuda
66 
67 #endif // CUDA_API_WRAPPERS_PCI_ID_HPP_
All definitions and functionality wrapping the CUDA Runtime API.
Definition: array.hpp:20
Fundamental CUDA-related type definitions.
void throw_if_error(status_t status, const ::std::string &message) noexcept(false)
Do nothing...
Definition: error.hpp:221
Location "coordinates" for a CUDA device on a PCIe bus.
Definition: pci_id.hpp:27
Facilities for exception-based handling of Runtime API errors, including a basic exception class wrap...
int id_t
Numeric ID of a CUDA device used by the CUDA Runtime API.
Definition: types.hpp:524