forked from makortel/pixel-standalone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_oneapi.cc
110 lines (97 loc) · 3.66 KB
/
main_oneapi.cc
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
#include <chrono>
#include <cstring>
#include <iostream>
#include <memory>
#include <CL/sycl.hpp>
#include "analyzer_oneapi.h"
#include "input.h"
#include "modules.h"
#include "output.h"
namespace {
constexpr int NLOOPS = 100;
}
enum class DeviceType { all_devices = -1, default_device = 0, host_device, cpu_device, gpu_device, cuda_device };
class cuda_selector : public cl::sycl::device_selector {
public:
int operator()(const cl::sycl::device & device) const override {
std::string const& name = device.get_info<cl::sycl::info::device::name>();
std::string const& vendor = device.get_info<cl::sycl::info::device::vendor>();
if (device.is_gpu() and (name.find("NVIDIA") != std::string::npos or vendor.find("NVIDIA") != std::string::npos)) {
return 1000;
};
return -1;
}
};
template <typename T>
cl::sycl::vector_class<cl::sycl::device> get_devices(T selector) {
auto const& all_devices = cl::sycl::device::get_devices();
cl::sycl::vector_class<cl::sycl::device> devices;
auto size = std::count_if(all_devices.begin(), all_devices.end(), [selector](cl::sycl::device device){ return selector(device) > 0; });
devices.reserve(size);
std::copy_if(all_devices.begin(), all_devices.end(), std::back_inserter(devices), [selector](cl::sycl::device device){ return selector(device) > 0; });
return devices;
}
int main(int argc, char **argv) {
DeviceType device_type = DeviceType::all_devices;
if (argc > 1) {
if (std::strcmp(argv[1], "--all") == 0)
device_type = DeviceType::all_devices;
else if (std::strcmp(argv[1], "--default") == 0)
device_type = DeviceType::default_device;
else if (std::strcmp(argv[1], "--host") == 0)
device_type = DeviceType::host_device;
else if (std::strcmp(argv[1], "--cpu") == 0)
device_type = DeviceType::cpu_device;
else if (std::strcmp(argv[1], "--gpu") == 0)
device_type = DeviceType::gpu_device;
else if (std::strcmp(argv[1], "--cuda") == 0)
device_type = DeviceType::cuda_device;
else
std::cout << "Ignoring unknown option " << argv[1] << std::endl;
}
cl::sycl::vector_class<cl::sycl::device> devices;
switch (device_type) {
case DeviceType::all_devices: {
devices = cl::sycl::device::get_devices();
break;
}
case DeviceType::default_device: {
cl::sycl::default_selector selector;
devices.push_back(cl::sycl::device{selector});
break;
}
case DeviceType::host_device: {
cl::sycl::host_selector selector;
devices.push_back(cl::sycl::device{selector});
break;
}
case DeviceType::cpu_device: {
cl::sycl::cpu_selector selector;
devices = ::get_devices(selector);
break;
}
case DeviceType::gpu_device: {
cl::sycl::gpu_selector selector;
devices = ::get_devices(selector);
break;
}
case DeviceType::cuda_device: {
cuda_selector selector;
devices = ::get_devices(selector);
break;
}
}
Input input = read_input();
std::cout << "Got " << input.cablingMap.size << " for cabling, wordCounter " << input.wordCounter << std::endl;
std::unique_ptr<Output> output = std::make_unique<Output>();
double totaltime = 0;
for (auto & device: devices) {
std::cout << std::endl;
std::cout << "Running on SYCL device " << device.get_info<cl::sycl::info::device::name>() << ", driver version "
<< device.get_info<cl::sycl::info::device::driver_version>() << std::endl;
oneapi::analyze(device, input, *output, totaltime);
std::cout << "Output: " << countModules(output->moduleInd, input.wordCounter) << " modules in "
<< (static_cast<double>(totaltime) / NLOOPS) << " us" << std::endl;
}
return 0;
}