-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathruntime.hpp
76 lines (68 loc) · 1.61 KB
/
runtime.hpp
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
67
68
69
70
71
72
73
74
75
76
#include <CL/sycl.hpp>
#include <iostream>
template <int ndev, int nsub>
sycl::device getSubDevice() {
static auto devs = sycl::device::get_devices(sycl::info::device_type::gpu);
auto dev = devs[ndev];
try {
static auto subs = dev.template create_sub_devices<
sycl::info::partition_property::partition_by_affinity_domain>(
sycl::info::partition_affinity_domain::numa);
return subs[nsub];
} catch (sycl::exception &e) {
std::cout<<e.what()<<std::endl;
return dev;
};
}
template <int ndev, int nsub>
sycl::queue getQueue() {
static sycl::queue q(
getSubDevice<ndev, nsub>(),
sycl::property_list {
sycl::property::queue::enable_profiling(),
sycl::property::queue::in_order()
});
return q;
}
sycl::queue currentQueue(int ndev, int nsub) {
switch(ndev) {
case 0:
if (nsub == 0)
return getQueue<0,0>();
else
return getQueue<0,1>();
break;
case 1:
if (nsub == 0)
return getQueue<1,0>();
else
return getQueue<1,1>();
break;
}
throw std::exception();
}
sycl::device currentSubDevice(int ndev, int nsub) {
switch(ndev) {
case 0:
if (nsub == 0)
return getSubDevice<0,0>();
else
return getSubDevice<0,1>();
break;
case 1:
if (nsub == 0)
return getSubDevice<1,0>();
else
return getSubDevice<1,1>();
break;
}
throw std::exception();
}
static uint32_t g_dev_num = 1;
static uint32_t g_part_num = 0;
sycl::device currentSubDevice() {
return currentSubDevice(g_dev_num, g_part_num);
}
sycl::queue currentQueue() {
return currentQueue(g_dev_num, g_part_num);
}