-
Notifications
You must be signed in to change notification settings - Fork 1
/
hamr_cuda_device.h
66 lines (49 loc) · 1.76 KB
/
hamr_cuda_device.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef hamr_cuda_device_h
#define hamr_cuda_device_h
#include "hamr_config.h"
///@file
namespace hamr
{
/// gets the device identifier for the first GPU. @returns zero if successful.
inline int HAMR_EXPORT get_cuda_device_identifier(int &dev_id) { dev_id = 0; return 0; }
/// gets the device identifier for the host. @returns zero if successful.
inline int HAMR_EXPORT get_cuda_host_identifier(int &dev_id) { dev_id = -1; return 0; }
/// gets the currently atcive CUDA device. @returns zero if successful.
int HAMR_EXPORT get_active_cuda_device(int &dev_id);
/// sets the active CUDA device. returns zero if successful.
int HAMR_EXPORT set_active_cuda_device(int dev_id);
/// gets the device that owns the given pointer. @returns zero if successful.
int HAMR_EXPORT get_cuda_device(const void *ptr, int &device_id);
/** Activate the specified CUDA device, and restore the previously active
* device when the object is destroyed.
*/
class HAMR_EXPORT activate_cuda_device
{
public:
activate_cuda_device() = delete;
activate_cuda_device(const activate_cuda_device &) = delete;
void operator=(const activate_cuda_device &) = delete;
activate_cuda_device(int id);
~activate_cuda_device();
private:
int m_device;
};
/** Activate peer to peer memory access between two devices, and deactivate when
* the object goes out of scope.
*/
class access_cuda_peer
{
public:
access_cuda_peer() : m_dest_device(-1), m_src_device(-1), m_symetric(false) {}
~access_cuda_peer() { disable(); }
/// enable peer to peer access. the dest device must active.
int enable(int dest_device, int src_device, bool symetric);
/// disable peer to peer access.
int disable();
private:
int m_dest_device;
int m_src_device;
int m_symetric;
};
}
#endif