-
Notifications
You must be signed in to change notification settings - Fork 81
/
registration.cpp
123 lines (105 loc) · 4.04 KB
/
registration.cpp
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include <occa/defines.hpp>
#include <occa/internal/modes/dpcpp/registration.hpp>
#include <occa/internal/modes/dpcpp/device.hpp>
#include <occa/internal/modes/dpcpp/utils.hpp>
#include <occa/internal/utils/string.hpp>
#include <iostream>
namespace occa {
namespace dpcpp {
dpcppMode::dpcppMode() :
mode_t("dpcpp") {}
bool dpcppMode::init() {
#if OCCA_DPCPP_ENABLED
return occa::dpcpp::isEnabled();
#else
return false;
#endif
}
styling::section& dpcppMode::getDescription() {
static styling::section section("dpcpp");
if (section.size() == 0) {
int platform_id{0};
auto platform_list = ::sycl::platform::get_platforms();
for (auto p : platform_list)
{
std::string platform_name_str = p.get_info<::sycl::info::platform::name>();
section
.add("Platform " + toString(platform_id), platform_name_str)
.addDivider();
int device_id{0};
auto device_list = p.get_devices();
for (auto d : device_list)
{
std::string device_type_str;
if (d.is_gpu())
{
device_type_str = "gpu";
}
else if (d.is_cpu())
{
device_type_str = "cpu";
}
else if (d.is_accelerator())
{
device_type_str = "accelerator";
}
else
{
device_type_str = "TYPE UNKNOWN";
}
std::string device_name_str = d.get_info<::sycl::info::device::name>();
uint32_t max_compute_units = d.get_info<::sycl::info::device::max_compute_units>();
// Global memory is returned in bytes
uint64_t global_memory_B = d.get_info<::sycl::info::device::global_mem_size>();
std::string global_memory_str = stringifyBytes(global_memory_B);
// Local memory is returned in bytes
uint64_t local_memory_B = d.get_info<::sycl::info::device::local_mem_size>();
std::string local_memory_str = stringifyBytes(local_memory_B);
section
.add("Device " + toString(device_id), device_name_str)
.add("Device Type", device_type_str)
.add("Compute Cores", toString(max_compute_units))
.add("Global Memory", global_memory_str)
.add("Local Memory", local_memory_str)
.addDivider();
++device_id;
}
++platform_id;
}
// Remove last divider
section.groups.pop_back();
}
return section;
}
modeDevice_t* dpcppMode::newDevice(const occa::json &props) {
// Refactor this into a helper function.
OCCA_ERROR(
"[dpcpp] device not given a [platform_id] integer",
props.has("platform_id") && props["platform_id"].isNumber());
int platformID = props.get<int>("platform_id");
auto platforms{::sycl::platform::get_platforms()};
OCCA_ERROR(
"Invalid platform number (" + toString(platformID) + ")",
(static_cast<size_t>(platformID) < platforms.size()));
auto& platform = platforms[platformID];
OCCA_ERROR(
"[dpcpp] device not given a [device_id] integer",
props.has("device_id") && props["device_id"].isNumber());
int deviceID = props.get<int>("device_id");
auto devices{platform.get_devices()};
OCCA_ERROR(
"Invalid device number (" + toString(deviceID) + ")",
(static_cast<size_t>(deviceID) < devices.size()));
auto& dpcppDevice = devices[deviceID];
return new occa::dpcpp::device(setModeProp(props), dpcppDevice);
}
int dpcppMode::getDeviceCount(const occa::json& props) {
OCCA_ERROR(
"[dpcppMode::getDeviceCount] not given a [platform_id] integer",
props.has("platform_id") && props["platform_id"].isNumber());
int pID{props.get<int>("platform_id")};
return static_cast<int>(::sycl::platform::get_platforms()[pID].get_devices().size());
}
dpcppMode mode;
}
}