HAMR
The Heterogeneous Accelerator Memory Resource
hamr_device.h
Go to the documentation of this file.
1 #ifndef hamr_device_h
2 #define hamr_device_h
3 
4 #include "hamr_config.h"
5 #if defined(HAMR_ENABLE_CUDA)
6 #include "hamr_cuda_device.h"
7 #elif defined(HAMR_ENABLE_HIP)
8 #include "hamr_hip_device.h"
9 #elif defined(HAMR_ENABLE_OPENMP)
10 #include "hamr_openmp_device.h"
11 #endif
12 
13 ///@file
14 
15 namespace hamr
16 {
17 /// gets the device identifier for the first GPU. @returns zero if successful.
18 inline int HAMR_EXPORT get_device_identifier(int &dev_id)
19 {
20 #if defined(HAMR_ENABLE_CUDA)
21  return get_cuda_device_identifier(dev_id);
22 #elif defined(HAMR_ENABLE_HIP)
23  return get_hip_device_identifier(dev_id);
24 #elif defined(HAMR_ENABLE_OPENMP)
25  return get_openmp_device_identifier(dev_id);
26 #else
27  dev_id = -1;
28  return 0;
29 #endif
30 }
31 
32 /// gets the device identifier for the CPU. @returns zero if successful.
33 inline int HAMR_EXPORT get_cpu_identifier(int &dev_id)
34 {
35 #if defined(HAMR_ENABLE_CUDA)
36  return get_cuda_cpu_identifier(dev_id);
37 #elif defined(HAMR_ENABLE_HIP)
38  return get_hip_cpu_identifier(dev_id);
39 #elif defined(HAMR_ENABLE_OPENMP)
40  return get_openmp_cpu_identifier(dev_id);
41 #else
42  dev_id = -1;
43  return 0;
44 #endif
45 }
46 
47 /// gets the currently atcive device. @returns zero if successful.
48 inline int HAMR_EXPORT get_active_device(int &dev_id)
49 {
50 #if defined(HAMR_ENABLE_CUDA)
51  return get_active_cuda_device(dev_id);
52 #elif defined(HAMR_ENABLE_HIP)
53  return get_active_hip_device(dev_id);
54 #elif defined(HAMR_ENABLE_OPENMP)
55  return get_active_openmp_device(dev_id);
56 #else
57  dev_id = -1;
58  return 0;
59 #endif
60 }
61 
62 /// sets the active device. returns zero if successful.
63 inline int HAMR_EXPORT set_active_device(int dev_id)
64 {
65 #if defined(HAMR_ENABLE_CUDA)
66  return set_active_cuda_device(dev_id);
67 #elif defined(HAMR_ENABLE_HIP)
68  return set_active_hip_device(dev_id);
69 #elif defined(HAMR_ENABLE_OPENMP)
70  return set_active_openmp_device(dev_id);
71 #else
72  return 0;
73 #endif
74 }
75 
76 /// gets the device that owns the given pointer. @returns zero if successful.
77 inline int HAMR_EXPORT get_device(const void *ptr, int &device_id)
78 {
79 #if defined(HAMR_ENABLE_CUDA)
80  return get_cuda_device(ptr, device_id);
81 #elif defined(HAMR_ENABLE_HIP)
82  return get_hip_device(ptr, device_id);
83 #elif defined(HAMR_ENABLE_OPENMP)
84  return get_openmp_device(ptr, device_id);
85 #else
86  device_id = -1;
87  return 0;
88 #endif
89 }
90 
91 #if defined(HAMR_ENABLE_CUDA)
92 using activate_device = activate_cuda_device;
93 #elif defined(HAMR_ENABLE_HIP)
94 using activate_device = activate_hip_device;
95 #elif defined(HAMR_ENABLE_OPENMP)
96 using activate_device = activate_openmp_device;
97 #else
98 /** Activate the specified device, and restore the previously active
99  * device when the object is destroyed.
100  */
101 class HAMR_EXPORT activate_device
102 {
103 public:
104  activate_device() = delete;
105  activate_device(const activate_device &) = delete;
106  void operator=(const activate_device &) = delete;
107  activate_device(int) {}
108  ~activate_device() {}
109 };
110 #endif
111 
112 }
113 #endif
hamr::get_cuda_cpu_identifier
int HAMR_EXPORT get_cuda_cpu_identifier(int &dev_id)
gets the device identifier for the CPU.
Definition: hamr_cuda_device.h:14
hamr::set_active_cuda_device
int HAMR_EXPORT set_active_cuda_device(int dev_id)
sets the active CUDA device. returns zero if successful.
hamr::get_cuda_device
int HAMR_EXPORT get_cuda_device(const void *ptr, int &device_id)
gets the device that owns the given pointer.
hamr::get_openmp_device
int HAMR_EXPORT get_openmp_device(const void *ptr, int &device_id)
gets the device that owns the given pointer.
hamr::get_cpu_identifier
int HAMR_EXPORT get_cpu_identifier(int &dev_id)
gets the device identifier for the CPU.
Definition: hamr_device.h:33
hamr::get_cuda_device_identifier
int HAMR_EXPORT get_cuda_device_identifier(int &dev_id)
gets the device identifier for the first GPU.
Definition: hamr_cuda_device.h:11
hamr::get_hip_device
int HAMR_EXPORT get_hip_device(const void *ptr, int &device_id)
gets the device that owns the given pointer.
hamr::get_active_cuda_device
int HAMR_EXPORT get_active_cuda_device(int &dev_id)
gets the currently atcive CUDA device.
hamr::get_active_device
int HAMR_EXPORT get_active_device(int &dev_id)
gets the currently atcive device.
Definition: hamr_device.h:48
hamr::get_device
int HAMR_EXPORT get_device(const void *ptr, int &device_id)
gets the device that owns the given pointer.
Definition: hamr_device.h:77
hamr::get_device_identifier
int HAMR_EXPORT get_device_identifier(int &dev_id)
gets the device identifier for the first GPU.
Definition: hamr_device.h:18
hamr_hip_device.h
hamr::set_active_hip_device
int HAMR_EXPORT set_active_hip_device(int dev_id)
sets the active HIP device. returns zero if successful.
hamr_openmp_device.h
hamr
heterogeneous accelerator memory resource
Definition: hamr_buffer.h:40
hamr_cuda_device.h
hamr::set_active_device
int HAMR_EXPORT set_active_device(int dev_id)
sets the active device. returns zero if successful.
Definition: hamr_device.h:63
hamr::activate_device
Definition: hamr_device.h:101
hamr::get_openmp_cpu_identifier
int HAMR_EXPORT get_openmp_cpu_identifier(int &dev_id)
gets the device identifier for the CPU.
hamr::get_openmp_device_identifier
int HAMR_EXPORT get_openmp_device_identifier(int &dev_id)
gets the device identifier for the first GPU.
Definition: hamr_openmp_device.h:11
hamr::get_hip_device_identifier
int HAMR_EXPORT get_hip_device_identifier(int &dev_id)
gets the device identifier for the first GPU.
Definition: hamr_hip_device.h:11
hamr::set_active_openmp_device
int HAMR_EXPORT set_active_openmp_device(int dev_id)
sets the active HIP device. returns zero if successful.
hamr::get_active_openmp_device
int HAMR_EXPORT get_active_openmp_device(int &dev_id)
gets the currently atcive HIP device. returns zero if successful.
hamr::get_hip_cpu_identifier
int HAMR_EXPORT get_hip_cpu_identifier(int &dev_id)
gets the device identifier for the CPU.
Definition: hamr_hip_device.h:14
hamr::get_active_hip_device
int HAMR_EXPORT get_active_hip_device(int &dev_id)
gets the currently atcive HIP device. returns zero if successful.