-
Notifications
You must be signed in to change notification settings - Fork 1
/
hamr_openmp_device.cxx
57 lines (49 loc) · 1.33 KB
/
hamr_openmp_device.cxx
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
#include "hamr_openmp_device.h"
#include <iostream>
#include <omp.h>
namespace hamr
{
// **************************************************************************
int get_openmp_host_identifier(int &dev_id)
{
dev_id = omp_get_initial_device();
return 0;
}
// **************************************************************************
int get_active_openmp_device(int &dev_id)
{
dev_id = omp_get_default_device();
return 0;
}
// **************************************************************************
int set_active_openmp_device(int dev_id)
{
omp_set_default_device(dev_id);
return 0;
}
// **************************************************************************
int HAMR_EXPORT get_openmp_device(const void *ptr, int &device_id)
{
(void)ptr;
device_id = 0;
return -1;
}
// --------------------------------------------------------------------------
activate_openmp_device::activate_openmp_device(int new_dev) : m_device(-1)
{
int cur_dev = -1;
if (!get_active_openmp_device(cur_dev) && (cur_dev != new_dev) &&
!set_active_openmp_device(new_dev))
{
m_device = cur_dev;
}
}
// --------------------------------------------------------------------------
activate_openmp_device::~activate_openmp_device()
{
if (m_device >= 0)
{
set_active_openmp_device(m_device);
}
}
}