cuda-api-wrappers
Thin C++-flavored wrappers for the CUDA Runtime API
pci_id.hpp
Go to the documentation of this file.
1 
6 #pragma once
7 #ifndef CUDA_API_WRAPPERS_PCI_ID_HPP_
8 #define CUDA_API_WRAPPERS_PCI_ID_HPP_
9 
10 #include "types.hpp"
11 #include "error.hpp"
12 
13 #include <string>
14 
15 namespace cuda {
16 namespace device {
17 
25  // These are the values CUDA's API provides us with directly
26  int domain;
27  int bus;
28  int device;
29  int function;
30 
31  operator ::std::string() const;
32  // This is not a ctor so as to maintain the PODness
33  static pci_location_t parse(const ::std::string& id_str);
34  static pci_location_t parse(const char* id_str);
35 public:
36  static constexpr const int unused { -1 };
37  // In lieu of making this class a variant with 3 type combinations.
38 };
39 
40 namespace detail_ {
41 
48 inline id_t resolve_id(pci_location_t pci_id)
49 {
50  ::std::string as_string { pci_id };
51  id_t cuda_device_id;
52  auto result = cuDeviceGetByPCIBusId(&cuda_device_id, as_string.c_str());
53  throw_if_error_lazy(result,
54  "Failed obtaining a CUDA device ID corresponding to PCI id " + as_string);
55  return cuda_device_id;
56 }
57 
58 } // namespace detail_
59 
60 
61 } // namespace device
62 } // namespace cuda
63 
64 #endif // CUDA_API_WRAPPERS_PCI_ID_HPP_
All definitions and functionality wrapping the CUDA Runtime API.
Definition: array.hpp:22
CUdevice id_t
Numeric ID of a CUDA device used by the CUDA Runtime API.
Definition: types.hpp:752
Definition: kernel_launch.hpp:77
Location "coordinates" for a CUDA device on a PCIe bus.
Definition: pci_id.hpp:24
Facilities for exception-based handling of Runtime and Driver API errors, including a basic exception...
Fundamental CUDA-related type definitions.