21#include <unordered_map>
28auto check_queue_is_valid(sycl::queue &q) {
30 auto test_kernel = [](sycl::queue &q) {
31 sycl::buffer<u32> b{10};
33 q.submit([&](sycl::handler &cgh) {
34 sycl::accessor acc{b, cgh, sycl::write_only, sycl::no_init};
36 cgh.parallel_for(sycl::range<1>{1}, [=](sycl::item<1> i) {
37 acc[i] = i.get_linear_id();
44 std::exception_ptr eptr;
50 q.get_device().get_info<sycl::info::device::name>(),
53 eptr = std::current_exception();
60 q.get_device().get_info<sycl::info::device::name>(),
61 "does not function properly");
62 std::rethrow_exception(eptr);
66auto exception_handler = [](sycl::exception_list exceptions) {
67 for (std::exception_ptr
const &e : exceptions) {
69 std::rethrow_exception(e);
70 }
catch (sycl::exception
const &e) {
71 printf(
"Caught synchronous SYCL exception: %s\n", e.what());
76std::string getDeviceTypeName(
const sycl::device &Device) {
77 auto DeviceType = Device.get_info<sycl::info::device::device_type>();
79 case sycl::info::device_type::cpu :
return "CPU";
80 case sycl::info::device_type::gpu :
return "GPU";
81 case sycl::info::device_type::host :
return "HOST";
82 case sycl::info::device_type::accelerator:
return "ACCELERATOR";
83 default :
return "UNKNOWN";
87void print_device_info(
const sycl::device &Device) {
88 std::cout <<
" - " << Device.get_info<sycl::info::device::name>() <<
" "
93namespace sycl_handler {
94 bool already_on =
false;
96 std::unique_ptr<sycl::queue> compute_queue;
97 std::unique_ptr<sycl::queue> alt_queue;
103 return *compute_queue;
120 shambase::term_colors::col8b_cyan() +
" >>> init SYCL instances <<< "
121 + shambase::term_colors::reset());
126 logger::normal_ln(
"SYCL Handler",
"chosen sycl config :", sycl_cfg);
128 size_t split_alt_comp = 0;
129 split_alt_comp = sycl_cfg.find(
":");
131 if (split_alt_comp == std::string::npos) {
132 logger::err_ln(
"SYCL Handler",
"sycl-cfg layout should be x:x");
136 std::string alt_cfg = sycl_cfg.substr(0, split_alt_comp);
137 std::string comp_cfg = sycl_cfg.substr(split_alt_comp + 1, sycl_cfg.length());
142 ialt = std::stoi(alt_cfg);
143 }
catch (
const std::invalid_argument &a) {
144 logger::err_ln(
"SYCL Handler",
"alt config is not an int");
147 }
catch (
const std::out_of_range &a) {
148 logger::err_ln(
"SYCL Handler",
"alt config is to big for an integer");
154 icomp = std::stoi(comp_cfg);
155 }
catch (
const std::invalid_argument &a) {
156 logger::err_ln(
"SYCL Handler",
"compute config is not an int");
159 }
catch (
const std::out_of_range &a) {
160 logger::err_ln(
"SYCL Handler",
"compute config is to big for an integer");
164 const auto &Platforms = sycl::platform::get_platforms();
167 "--------------------------------------------------------------------------------");
169 "| sel | id | Device name | Platform name | Type |");
171 "--------------------------------------------------------------------------------");
174 for (
const auto &Platform : Platforms) {
175 const auto &Devices = Platform.get_devices();
177 auto PlatformName = Platform.get_info<sycl::info::platform::name>();
178 for (
const auto &Device : Devices) {
179 auto DeviceName = Device.get_info<sycl::info::device::name>();
181 auto selected_k = [&](
i32 k) {
182 std::string ret =
"";
195 std::string selected = selected_k(key_global);
203 "| %-3s | %02d | %-29s | %-24s | %-6s |",
210 if (key_global == ialt) {
211 alt_queue = std::make_unique<sycl::queue>(Device, exception_handler);
214 if (key_global == icomp) {
215 compute_queue = std::make_unique<sycl::queue>(Device, exception_handler);
223 "--------------------------------------------------------------------------------");
226 for (
const auto &Platform : Platforms) {
227 auto PlatformName = Platform.get_info<sycl::info::platform::name>();
228 for (
const auto &Device : Platform.get_devices()) {
229 auto DeviceName = Device.get_info<sycl::info::device::name>();
231 if (key_global == ialt) {
240 getDeviceTypeName(Device),
242 alt_queue = std::make_unique<sycl::queue>(Device, exception_handler);
245 if (key_global == icomp) {
248 "init comp queue : ",
254 getDeviceTypeName(Device),
256 compute_queue = std::make_unique<sycl::queue>(Device, exception_handler);
263 check_queue_is_valid(*compute_queue);
264 check_queue_is_valid(*alt_queue);
266 logger::info_ln(
"SYCL Handler",
"init done");
268 logger::info_ln(
"SYCL Handler",
"creating MPI type for interop");
269 create_sycl_mpi_types();
271 logger::info_ln(
"SYCL Handler",
"MPI type for interop created");
275 logger::err_ln(
"SYCL Handler",
"Please specify a sycl configuration (--sycl-cfg x:x)");
sycl::queue & get_compute_queue(u32 id=0)
sycl::queue & get_alt_queue(u32 id=0)
Get the alternative queue.
std::uint32_t u32
32 bit unsigned integer
std::int32_t i32
32 bit integer
DeviceType
The type of a device.
std::string readable_sizeof(double size)
given a sizeof value return a readble string Example : readable_sizeof(1024*1024*1024) -> "1....
std::string trunc_str(std::string s, u32 max_len)
Truncate a string to a specified length, adding an ellipsis if necessary.
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
bool has_option(const std::string_view &option_name)
Check if an option is present.
std::string_view get_option(const std::string_view &option_name)
Get the value of an option.
header file to manage sycl