24 #ifdef BUILD_SYCL_MODULE
25 #include <sycl/sycl.hpp>
35 #ifdef BUILD_SYCL_MODULE
38 sycl::buffer<int, 1> buffer(4);
44 sycl::range<1> num_workloads{buffer.size()};
47 q.submit([&](sycl::handler &cgh) {
49 auto accessor = buffer.get_access<sycl::access::mode::write>(cgh);
51 cgh.parallel_for<
class FillBuffer>(
52 num_workloads, [=](sycl::id<1> WIid) {
54 accessor[WIid] = (int)WIid.get(0);
60 const auto host_accessor = buffer.get_host_access();
63 bool mismatch_found =
false;
64 for (
size_t i = 0; i < buffer.size(); ++i) {
65 if (host_accessor[i] != i) {
67 i, i, host_accessor[i]);
68 mismatch_found =
true;
85 #ifdef BUILD_SYCL_MODULE
88 const sycl::device &device) {
89 auto device_type = device.get_info<sycl::info::device::device_type>();
90 switch (device_type) {
91 case sycl::info::device_type::cpu:
93 case sycl::info::device_type::gpu:
95 case sycl::info::device_type::host:
97 case sycl::info::device_type::accelerator:
99 case sycl::info::device_type::custom:
106 static std::string GetBackendName(
const sycl::device &device) {
107 sycl::platform platform = device.get_info<sycl::info::device::platform>();
108 sycl::backend backend = platform.get_backend();
109 std::ostringstream os;
114 static std::string SYCLDeviceToString(
const sycl::device &device) {
115 std::ostringstream os;
123 #ifdef BUILD_SYCL_MODULE
124 const char *filter = std::getenv(
"ONEAPI_DEVICE_SELECTOR");
127 "ONEAPI_DEVICE_SELECTOR environment variable is set to {}. To "
128 "see the correct device id, please unset "
129 "ONEAPI_DEVICE_SELECTOR.",
136 auto dev = sycl::device(sycl::gpu_selector_v);
138 SYCLDeviceToString(dev));
140 }
catch (
const sycl::exception &e) {
143 auto dev = sycl::device(sycl::cpu_selector_v);
146 SYCLDeviceToString(dev));
147 }
catch (
const sycl::exception &e) {
152 const std::vector<sycl::platform> &platforms =
153 sycl::platform::get_platforms();
154 for (
const sycl::platform &platform : platforms) {
155 sycl::backend backend = platform.get_backend();
156 const std::vector<sycl::device> &devices = platform.get_devices();
157 for (
const sycl::device &device : devices) {
164 const sycl::device &device = sycl::device(sycl::default_selector_v);
166 SYCLDeviceToString(device));
167 }
catch (
const sycl::exception &e) {
171 const sycl::device &device = sycl::device(sycl::cpu_selector_v);
173 SYCLDeviceToString(device));
174 }
catch (
const sycl::exception &e) {
178 const sycl::device &device = sycl::device(sycl::gpu_selector_v);
180 SYCLDeviceToString(device));
181 }
catch (
const sycl::exception &e) {
185 const sycl::device &device =
186 sycl::device(sycl::accelerator_selector_v);
188 SYCLDeviceToString(device));
189 }
catch (
const sycl::exception &e) {
196 "PrintSYCLDevices is not compiled with BUILD_SYCL_MODULE=ON.");
201 #ifdef BUILD_SYCL_MODULE
209 #ifdef BUILD_SYCL_MODULE
217 #ifdef BUILD_SYCL_MODULE
231 #ifdef BUILD_SYCL_MODULE
239 #ifdef BUILD_SYCL_MODULE
241 _putenv_s(
"SYCL_CACHE_PERSISTENT",
"1");
243 setenv(
"SYCL_CACHE_PERSISTENT",
"1", 1);
247 "enablePersistentJITCache is not compiled with "
248 "BUILD_SYCL_MODULE=ON.");
#define CLOUDVIEWER_DLL_LOCAL
bool IsDeviceAvailable(const Device &device)
Returns true if the specified SYCL device is available.
static SYCLContext & GetInstance()
Get singleton instance.
bool IsAvailable()
Returns true if there is at least one SYCL devices.
SYCLDevice GetDeviceProperties(const Device &device)
Get SYCL device properties given an CloudViewer device.
std::vector< Device > GetAvailableSYCLDevices()
Returns a list of all available SYCL devices.
CLOUDVIEWER_DLL_LOCAL std::string GetDeviceTypeName(const sycl::device &device)
void enablePersistentJITCache()
bool IsAvailable()
Returns true if there is at least one SYCL device available.
std::string GetDeviceType(const Device &device)
bool IsDeviceAvailable(const Device &device)
Returns true if the specified SYCL device is available.
std::vector< Device > GetAvailableSYCLDevices()
Return a list of available SYCL devices.
void PrintSYCLDevices(bool print_all)
Generic file read and write utility for python interface.
std::string device_type
cpu, gpu, host, acc, custom, unknown.