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 
33  optional<int> domain;
35  int bus;
36  int device;
37  optional<int> function;
39 
40  operator ::std::string() const;
41 
55  static pci_location_t parse(const ::std::string& id_str);
56 
58  static pci_location_t parse(const char* id_str);
59 };
60 
61 namespace detail_ {
62 
69 inline id_t resolve_id(pci_location_t pci_id)
70 {
71  ::std::string as_string { pci_id };
72  id_t cuda_device_id;
73  auto result = cuDeviceGetByPCIBusId(&cuda_device_id, as_string.c_str());
74  throw_if_error_lazy(result,
75  "Failed obtaining a CUDA device ID corresponding to PCI id " + as_string);
76  return cuda_device_id;
77 }
78 
79 } // namespace detail_
80 
81 
82 } // namespace device
83 } // namespace cuda
84 
85 #endif // CUDA_API_WRAPPERS_PCI_ID_HPP_
Definitions and functionality wrapping CUDA APIs.
Definition: array.hpp:22
optional< int > domain
The four fields of the PCI configuration space.
Definition: pci_id.hpp:34
CUdevice id_t
Numeric ID of a CUDA device used by the CUDA Runtime API.
Definition: types.hpp:850
static pci_location_t parse(const ::std::string &id_str)
Parse a string representation of a device&#39;s PCI location.
#define throw_if_error_lazy(status__,...)
A macro for only throwing an error if we&#39;ve failed - which also ensures no string is constructed unle...
Definition: error.hpp:316
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.