Blender V5.3
oneapi/device_impl.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021-2025 Intel Corporation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#ifdef WITH_ONEAPI
6
7/* <algorithm> is needed until included upstream in sycl/detail/property_list_base.hpp */
8# include <algorithm>
9# include <sycl/sycl.hpp>
10
12
13# include "util/log.h"
14
15# ifdef WITH_EMBREE_GPU
16# include "bvh/embree.h"
17# endif
18
19# if defined(WITH_OPENIMAGEDENOISE)
20# include <OpenImageDenoise/config.h>
21# if OIDN_VERSION >= 20300
22# include "util/openimagedenoise.h" // IWYU pragma: keep
23# endif
24# endif
25
28
30
31# if defined(WITH_EMBREE_GPU) && defined(EMBREE_SYCL_SUPPORT) && !defined(SYCL_LANGUAGE_VERSION)
32/* These declarations are missing from embree headers when compiling from a compiler that doesn't
33 * support SYCL. */
34extern "C" RTCDevice rtcNewSYCLDevice(sycl::context context, const char *config);
35extern "C" bool rtcIsSYCLDeviceSupported(const sycl::device sycl_device);
36extern "C" void rtcSetDeviceSYCLDevice(RTCDevice device, const sycl::device sycl_device);
37# endif
38
40
41struct SyclDeviceEntry {
42 sycl::device device;
43 bool meets_driver_requirement;
44};
45
46static std::vector<SyclDeviceEntry> available_sycl_devices(
47 bool *multiple_level_zero_platforms_detected);
48static int parse_driver_build_version(const sycl::device &device);
49
50static void queue_error_cb(const char *message, void *user_ptr)
51{
52 if (user_ptr) {
53 *reinterpret_cast<std::string *>(user_ptr) = message;
54 }
55}
56
57OneapiDevice::OneapiDevice(const DeviceInfo &info, Stats &stats, Profiler &profiler, bool headless)
58 : GPUDevice(info, stats, profiler, headless)
59{
60# ifndef WITH_CYCLES_ONEAPI_SOFTWARE_TEXTURING
61 /* Verify that base class types can be used with specific backend types */
62 static_assert(sizeof(texMemObject) ==
63 sizeof(sycl::ext::oneapi::experimental::sampled_image_handle));
64 static_assert(sizeof(arrayMemObject) ==
65 sizeof(sycl::ext::oneapi::experimental::image_mem_handle));
66# endif
67
68 need_image_info = false;
69 use_hardware_raytracing = info.use_hardware_raytracing;
70
71 oneapi_set_error_cb(queue_error_cb, &oneapi_error_string_);
72
73 bool multiple_level_zero_platforms_detected = false;
74
75 bool is_finished_ok = create_queue(device_queue_,
76 info.num,
77# ifdef WITH_EMBREE_GPU
78 use_hardware_raytracing ? (void *)&embree_device : nullptr,
79# else
80 nullptr,
81# endif
82 &multiple_level_zero_platforms_detected);
83
84 /* Currently, multiple level zero is indicating that there are several different Intel
85 * drivers in the system (for example, Intel(R) 11th - 14th Gen Processor Graphics Driver
86 * (legacy) for iGPU and Intel(R) Arc(TM) Graphics Driver for dGPU). In such cases, copy
87 * extension is not working correctly and would lead to crashes, as reported in the Blender bug
88 * report #155964, so in order to ensure functionality we are disabling this extension on such
89 * configuration - in the future, this workaround can be removed, then minimal supported
90 * driver version would be high enough to include all Driver versions with the future fix.
91 */
92 if (multiple_level_zero_platforms_detected) {
93 use_intel_copy_optimization = false;
94 }
95
96# ifdef SYCL_EXT_ONEAPI_COPY_OPTIMIZE
97 if (!use_intel_copy_optimization) {
98 LOG_TRACE << "oneAPI copy optimization extension may have issues on the detected "
99 "configuration, it will be disabled to avoid crashes.";
100 }
101# endif
102
103 if (is_finished_ok == false) {
104 set_error("oneAPI queue initialization error: got runtime exception \"" +
105 oneapi_error_string_ + "\"");
106 }
107 else {
108 LOG_TRACE << "oneAPI queue has been successfully created for the device \"" << info.description
109 << "\"";
110 assert(device_queue_);
111 }
112
113# ifdef WITH_EMBREE_GPU
114 use_hardware_raytracing = use_hardware_raytracing && (embree_device != nullptr);
115# else
116 use_hardware_raytracing = false;
117# endif
118
119 if (use_hardware_raytracing) {
120 LOG_INFO << "oneAPI will use hardware ray tracing for intersection acceleration.";
121 }
122
123 size_t globals_segment_size;
124 is_finished_ok = kernel_globals_size(globals_segment_size);
125 if (is_finished_ok == false) {
126 set_error("oneAPI constant memory initialization got runtime exception \"" +
127 oneapi_error_string_ + "\"");
128 }
129 else {
130 LOG_TRACE << "Successfully created global/constant memory segment (kernel globals object)";
131 }
132
133 kg_memory_ = usm_aligned_alloc_host(device_queue_, globals_segment_size, 16);
134 usm_memset(device_queue_, kg_memory_, 0, globals_segment_size);
135
136 kg_memory_device_ = usm_alloc_device(device_queue_, globals_segment_size);
137
138 kg_memory_size_ = globals_segment_size;
139
140 max_memory_on_device_ = get_memcapacity();
141 init_host_memory();
142 can_map_host = true;
143
144 const char *headroom_str = getenv("CYCLES_ONEAPI_MEMORY_HEADROOM");
145 if (headroom_str != nullptr) {
146 const long long override_headroom = (float)atoll(headroom_str);
147 device_working_headroom = override_headroom;
148 device_image_headroom = override_headroom;
149 }
150 LOG_TRACE << "oneAPI memory headroom size: "
151 << string_human_readable_size(device_working_headroom);
152}
153
154OneapiDevice::~OneapiDevice()
155{
156# ifdef WITH_EMBREE_GPU
157 if (embree_device) {
158 rtcReleaseDevice(embree_device);
159 }
160# endif
161
162 image_info.free();
163 usm_free(device_queue_, kg_memory_);
164 usm_free(device_queue_, kg_memory_device_);
165
166 const_mem_map_.clear();
167
168 if (device_queue_) {
169 free_queue(device_queue_);
170 }
171}
172
173bool OneapiDevice::check_peer_access(Device * /*peer_device*/)
174{
175 return false;
176}
177
178bool OneapiDevice::can_use_hardware_raytracing_for_features(
179 const uint64_t requested_features) const
180{
181 /* MNEE and Ray-trace kernels work correctly with Hardware Ray-tracing starting with Embree 4.1.
182 */
183# if defined(RTC_VERSION) && RTC_VERSION < 40100
184 return !(requested_features & (KERNEL_FEATURE_MNEE | KERNEL_FEATURE_NODE_RAYTRACE));
185# else
186 (void)requested_features;
187 return true;
188# endif
189}
190
191BVHLayoutMask OneapiDevice::get_bvh_layout_mask(const uint64_t requested_features) const
192{
193 return (use_hardware_raytracing &&
194 can_use_hardware_raytracing_for_features(requested_features)) ?
197}
198
199# ifdef WITH_EMBREE_GPU
200void OneapiDevice::build_bvh(BVH *bvh, Progress &progress, bool refit)
201{
202 if (embree_device && bvh->params.bvh_layout == BVH_LAYOUT_EMBREEGPU) {
203 BVHEmbree *const bvh_embree = static_cast<BVHEmbree *>(bvh);
204 if (refit) {
205 bvh_embree->refit(progress);
206 }
207 else {
208 bvh_embree->build(progress, &stats, embree_device, true);
209 }
210
211# if RTC_VERSION >= 40302
212 thread_scoped_lock lock(scene_data_mutex);
213 all_embree_scenes.push_back(bvh_embree->scene);
214# endif
215
216 if (bvh->params.top_level) {
217# if RTC_VERSION >= 40400
218 embree_traversable = rtcGetSceneTraversable(bvh_embree->scene);
219# else
220 embree_traversable = bvh_embree->scene;
221# endif
222# if RTC_VERSION >= 40302
223 RTCError error_code = bvh_embree->offload_scenes_to_gpu(all_embree_scenes);
224 if (error_code != RTC_ERROR_NONE) {
225 set_error(
226 string_printf("BVH failed to migrate to the GPU due to Embree library error (%s)",
227 bvh_embree->get_error_string(error_code)));
228 }
229 all_embree_scenes.clear();
230# endif
231 }
232 }
233 else {
234 Device::build_bvh(bvh, progress, refit);
235 }
236}
237# endif
238
239size_t OneapiDevice::get_free_mem() const
240{
241 size_t free_memory = 0;
242
243 /* Estimate: Capacity - in use. */
244 const size_t resident_memory = stats.mem_used - map_host_used;
245 if (resident_memory < max_memory_on_device_) {
246 free_memory = max_memory_on_device_ - resident_memory;
247 }
248
249 /* Accurate: Use device info.
250 * Some drivers don't update free memory promptly after allocations, so we
251 * clamp to previous estimate to avoid over-reporting. */
252 const sycl::device &device = reinterpret_cast<sycl::queue *>(device_queue_)->get_device();
253 if (device.has(sycl::aspect::ext_intel_free_memory)) {
254 free_memory = min(device.get_info<sycl::ext::intel::info::device::free_memory>(), free_memory);
255 }
256
257 return free_memory;
258}
259
260bool OneapiDevice::load_kernels(const uint64_t requested_features)
261{
262 assert(device_queue_);
263
264 /* Kernel loading is expected to be a cumulative operation; for example, if
265 * a device is asked to load kernel A and then kernel B, then after these
266 * operations, both A and B should be available for use. So we need to store
267 * and use a cumulative mask of the requested kernel features, and not just
268 * the latest requested features.
269 */
270 kernel_features |= requested_features;
271
272 bool is_finished_ok = oneapi_run_test_kernel(device_queue_);
273 if (is_finished_ok == false) {
274 set_error("oneAPI test kernel execution: got a runtime exception \"" + oneapi_error_string_ +
275 "\"");
276 return false;
277 }
278 LOG_INFO << "Test kernel has been executed successfully for \"" << info.description << "\"";
279 assert(device_queue_);
280
281 if (use_hardware_raytracing && !can_use_hardware_raytracing_for_features(requested_features)) {
283 << "Hardware ray tracing disabled, not supported yet by oneAPI for requested features.";
284 use_hardware_raytracing = false;
285 }
286
287 is_finished_ok = oneapi_load_kernels(
288 device_queue_, (const unsigned int)requested_features, use_hardware_raytracing);
289 if (is_finished_ok == false) {
290 set_error("oneAPI kernels loading: got a runtime exception \"" + oneapi_error_string_ + "\"");
291 }
292 else {
293 LOG_INFO << "Kernels loading (compilation) has been done for \"" << info.description << "\"";
294 }
295
296 if (is_finished_ok) {
297 reserve_private_memory(requested_features);
298 is_finished_ok = !have_error();
299 }
300
301 return is_finished_ok;
302}
303
304void OneapiDevice::reserve_private_memory(const uint64_t kernel_features)
305{
306 size_t free_before = get_free_mem();
307
308 /* Use the biggest kernel for estimation. */
309 const DeviceKernel test_kernel = (kernel_features & KERNEL_FEATURE_NODE_RAYTRACE) ?
312
313 {
314 unique_ptr<DeviceQueue> queue = gpu_queue_create();
315
316 device_ptr d_path_index = 0;
317 device_ptr d_render_buffer = 0;
318 int d_work_size = 0;
319 DeviceKernelArguments args(&d_path_index, &d_render_buffer, &d_work_size);
320
321 queue->init_execution();
322 /* Launch of the kernel seems to be sufficient to reserve all
323 * needed memory regardless of the execution global size.
324 * So, the smallest possible size is used here. */
325 queue->enqueue(test_kernel, 1, args);
326 queue->synchronize();
327 }
328
329 size_t free_after = get_free_mem();
330
331 LOG_INFO << "For kernel execution were reserved "
332 << string_human_readable_number(free_before - free_after) << " bytes. ("
333 << string_human_readable_size(free_before - free_after) << ")";
334}
335
336void OneapiDevice::get_device_memory_info(size_t &total, size_t &free)
337{
338 free = get_free_mem();
339 total = max_memory_on_device_;
340}
341
342bool OneapiDevice::alloc_device(void *&device_pointer, const size_t size)
343{
344 bool allocation_success = false;
345 device_pointer = usm_alloc_device(device_queue_, size);
346 if (device_pointer != nullptr) {
347 allocation_success = true;
348 /* Due to lazy memory initialization in GPU runtime we will force memory to
349 * appear in device memory via execution of a kernel using this memory. */
350 if (!oneapi_zero_memory_on_device(device_queue_, device_pointer, size)) {
351 set_error("oneAPI memory operation error: got runtime exception \"" + oneapi_error_string_ +
352 "\"");
353 usm_free(device_queue_, device_pointer);
354
355 device_pointer = nullptr;
356 allocation_success = false;
357 }
358 }
359
360 return allocation_success;
361}
362
363void OneapiDevice::free_device(void *device_pointer)
364{
365 usm_free(device_queue_, device_pointer);
366}
367
368bool OneapiDevice::shared_alloc(void *&shared_pointer, const size_t size)
369{
370 shared_pointer = usm_aligned_alloc_host(device_queue_, size, 64);
371 return shared_pointer != nullptr;
372}
373
374void OneapiDevice::shared_free(void *shared_pointer, const size_t /*size*/)
375{
376 usm_free(device_queue_, shared_pointer);
377}
378
379void *OneapiDevice::shared_to_device_pointer(const void *shared_pointer)
380{
381 /* Device and host pointer are in the same address space
382 * as we're using Unified Shared Memory. */
383 return const_cast<void *>(shared_pointer);
384}
385
386void OneapiDevice::copy_host_to_device(void *device_pointer, void *host_pointer, const size_t size)
387{
388 usm_memcpy(device_queue_, device_pointer, host_pointer, size);
389}
390
391/* TODO: Make sycl::queue part of OneapiQueue and avoid using pointers to sycl::queue. */
392SyclQueue *OneapiDevice::sycl_queue()
393{
394 return device_queue_;
395}
396
397string OneapiDevice::oneapi_error_message()
398{
399 return string(oneapi_error_string_);
400}
401
402int OneapiDevice::scene_max_shaders()
403{
404 return scene_max_shaders_;
405}
406
407void *OneapiDevice::kernel_globals_device_pointer()
408{
409 return kg_memory_device_;
410}
411
412void *OneapiDevice::host_alloc(const MemoryType type, const size_t size)
413{
414 void *host_pointer = GPUDevice::host_alloc(type, size);
415
416# ifdef SYCL_EXT_ONEAPI_COPY_OPTIMIZE
417 if (use_intel_copy_optimization && host_pointer) {
418 /* Import host_pointer into USM memory for faster host<->device data transfers. */
419 if (type == MEM_READ_WRITE || type == MEM_READ_ONLY) {
420 sycl::queue *queue = reinterpret_cast<sycl::queue *>(device_queue_);
421 /* This API is properly implemented only in Level-Zero backend at the moment and we don't
422 * want it to fail at runtime, so we conservatively use it only for L0. */
423 if (queue->get_backend() == sycl::backend::ext_oneapi_level_zero) {
424 sycl::ext::oneapi::experimental::prepare_for_device_copy(host_pointer, size, *queue);
425 }
426 }
427 }
428# endif
429
430 return host_pointer;
431}
432
433void OneapiDevice::host_free(const MemoryType type, void *host_pointer, const size_t size)
434{
435# ifdef SYCL_EXT_ONEAPI_COPY_OPTIMIZE
436 if (use_intel_copy_optimization) {
437 if (type == MEM_READ_WRITE || type == MEM_READ_ONLY) {
438 sycl::queue *queue = reinterpret_cast<sycl::queue *>(device_queue_);
439 /* This API is properly implemented only in Level-Zero backend at the moment and we don't
440 * want it to fail at runtime, so we conservatively use it only for L0. */
441 if (queue->get_backend() == sycl::backend::ext_oneapi_level_zero) {
442 sycl::ext::oneapi::experimental::release_from_device_copy(host_pointer, *queue);
443 }
444 }
445 }
446# endif
447
448 GPUDevice::host_free(type, host_pointer, size);
449}
450
451void OneapiDevice::mem_alloc(device_memory &mem)
452{
453 if (mem.type == MEM_IMAGE_TEXTURE) {
454 assert(!"mem_alloc not supported for images.");
455 }
456 else if (mem.type == MEM_GLOBAL) {
457 assert(!"mem_alloc not supported for global memory.");
458 }
459 else {
460 LOG_TRACE << "OneapiDevice::mem_alloc: \"" << mem.log_name() << "\", "
461 << string_human_readable_number(mem.memory_size()) << " bytes. ("
463 generic_alloc(mem);
464 }
465}
466
467void OneapiDevice::mem_copy_to(device_memory &mem)
468{
469 LOG_TRACE << "OneapiDevice::mem_copy_to: \"" << mem.log_name() << "\", "
470 << string_human_readable_number(mem.memory_size()) << " bytes. ("
472
473 /* After getting runtime errors we need to avoid performing oneAPI runtime operations
474 * because the associated GPU context may be in an invalid state at this point. */
475 if (have_error()) {
476 return;
477 }
478
479 if (mem.type == MEM_GLOBAL) {
480 global_copy_to(mem);
481 }
482 else if (mem.type == MEM_IMAGE_TEXTURE) {
483 image_copy_to((device_image &)mem);
484 }
485 else {
486 if (!mem.device_pointer) {
487 generic_alloc(mem);
488 }
489 generic_copy_to(mem);
490 }
491}
492
493void OneapiDevice::mem_move_to_host(device_memory &mem)
494{
495 LOG_TRACE << "OneapiDevice::mem_move_to_host: \"" << mem.log_name() << "\", "
496 << string_human_readable_number(mem.memory_size()) << " bytes. ("
498
499 /* After getting runtime errors we need to avoid performing oneAPI runtime operations
500 * because the associated GPU context may be in an invalid state at this point. */
501 if (have_error()) {
502 return;
503 }
504
505 if (mem.type == MEM_GLOBAL) {
506 global_free(mem);
507 global_alloc(mem);
508 }
509 else if (mem.type == MEM_IMAGE_TEXTURE) {
510 image_free((device_image &)mem);
511 image_alloc((device_image &)mem);
512 }
513 else {
514 assert(0);
515 }
516}
517
518void OneapiDevice::mem_copy_from(
519 device_memory &mem, const size_t y, size_t w, const size_t h, size_t elem, void *host_pointer)
520{
521 if (mem.type == MEM_IMAGE_TEXTURE) {
522 assert(!"mem_copy_from not supported for images.");
523 }
524 else if (host_pointer) {
525 const size_t size = (w > 0 || h > 0 || elem > 0) ? (elem * w * h) : mem.memory_size();
526 const size_t offset = elem * y * w;
527
528 LOG_TRACE << "OneapiDevice::mem_copy_from: \"" << mem.log_name() << "\" object of "
529 << string_human_readable_number(mem.memory_size()) << " bytes. ("
530 << string_human_readable_size(mem.memory_size()) << ") from offset " << offset
531 << " data " << size << " bytes";
532
533 /* After getting runtime errors we need to avoid performing oneAPI runtime operations
534 * because the associated GPU context may be in an invalid state at this point. */
535 if (have_error()) {
536 return;
537 }
538
539 assert(device_queue_);
540
541 assert(size != 0);
542 if (mem.device_pointer) {
543 char *shifted_host = reinterpret_cast<char *>(host_pointer) + offset;
544 char *shifted_device = reinterpret_cast<char *>(mem.device_pointer) + offset;
545 bool is_finished_ok = usm_memcpy(device_queue_, shifted_host, shifted_device, size);
546 if (is_finished_ok == false) {
547 set_error("oneAPI memory operation error: got runtime exception \"" +
548 oneapi_error_string_ + "\"");
549 }
550 }
551 }
552}
553
554void OneapiDevice::mem_copy_from(
555 device_memory &mem, const size_t y, size_t w, const size_t h, size_t elem)
556{
557 mem_copy_from(mem, y, w, h, elem, mem.host_pointer);
558}
559
560void OneapiDevice::mem_copy_from(device_memory &mem)
561{
562 mem_copy_from(mem, 0, 0, 0, 0);
563}
564
565void OneapiDevice::mem_zero(device_memory &mem)
566{
567 LOG_TRACE << "OneapiDevice::mem_zero: \"" << mem.log_name() << "\", "
568 << string_human_readable_number(mem.memory_size()) << " bytes. ("
570
571 /* After getting runtime errors we need to avoid performing oneAPI runtime operations
572 * because the associated GPU context may be in an invalid state at this point. */
573 if (have_error()) {
574 return;
575 }
576
577 if (!mem.device_pointer) {
578 mem_alloc(mem);
579 }
580 if (!mem.device_pointer) {
581 return;
582 }
583
584 assert(device_queue_);
585 bool is_finished_ok = usm_memset(
586 device_queue_, (void *)mem.device_pointer, 0, mem.memory_size());
587 if (is_finished_ok == false) {
588 set_error("oneAPI memory operation error: got runtime exception \"" + oneapi_error_string_ +
589 "\"");
590 }
591}
592
593void OneapiDevice::mem_free(device_memory &mem)
594{
595 LOG_TRACE << "OneapiDevice::mem_free: \"" << mem.log_name() << "\", "
596 << string_human_readable_number(mem.device_size) << " bytes. ("
598
599 if (mem.type == MEM_GLOBAL) {
600 global_free(mem);
601 }
602 else if (mem.type == MEM_IMAGE_TEXTURE) {
603 image_free((device_image &)mem);
604 }
605 else {
606 generic_free(mem);
607 }
608}
609
610device_ptr OneapiDevice::mem_alloc_sub_ptr(device_memory &mem,
611 const size_t offset,
612 size_t /*size*/)
613{
614 return reinterpret_cast<device_ptr>(reinterpret_cast<char *>(mem.device_pointer) +
615 mem.memory_elements_size(offset));
616}
617
618void OneapiDevice::const_copy_to(const char *name, void *host, const size_t size)
619{
620 assert(name);
621
622 LOG_TRACE << "OneapiDevice::const_copy_to \"" << name << "\" object "
623 << string_human_readable_number(size) << " bytes. ("
625
626 if (strcmp(name, "data") == 0) {
627 assert(size <= sizeof(KernelData));
628 KernelData *const data = static_cast<KernelData *>(host);
629
630 /* We need this value when allocating local memory for integrator_sort_bucket_pass
631 * and integrator_sort_write_pass kernels. */
632 scene_max_shaders_ = data->max_shaders;
633
634# ifdef WITH_EMBREE_GPU
635 if (embree_traversable != nullptr) {
636 /* Update scene handle (since it is different for each device on multi devices).
637 * This must be a raw pointer copy since at some points during scene update this
638 * pointer may be invalid. */
639 data->device_bvh = embree_traversable;
640 }
641# endif
642 }
643
644 ConstMemMap::iterator i = const_mem_map_.find(name);
646
647 if (i == const_mem_map_.end()) {
648 unique_ptr<device_vector<uchar>> data_ptr = make_unique<device_vector<uchar>>(
649 this, name, MEM_READ_ONLY);
650 data_ptr->alloc(size);
651 data = data_ptr.get();
652 const_mem_map_.insert(ConstMemMap::value_type(name, std::move(data_ptr)));
653 }
654 else {
655 data = i->second.get();
656 }
657
658 assert(data->memory_size() <= size);
659 memcpy(data->data(), host, size);
660 data->copy_to_device();
661
662 set_global_memory(device_queue_, kg_memory_, name, (void *)data->device_pointer);
663
664 usm_memcpy(device_queue_, kg_memory_device_, kg_memory_, kg_memory_size_);
665}
666
667void OneapiDevice::global_alloc(device_memory &mem)
668{
669 size_t size = mem.memory_size();
670 LOG_TRACE << "OneapiDevice::global_alloc \"" << mem.log_name() << "\" object "
671 << string_human_readable_number(size) << " bytes. ("
673
674 generic_alloc(mem);
675 generic_copy_to(mem);
676
677 set_global_memory(device_queue_, kg_memory_, mem.global_name(), (void *)mem.device_pointer);
678
679 usm_memcpy(device_queue_, kg_memory_device_, kg_memory_, kg_memory_size_);
680}
681
682void OneapiDevice::global_copy_to(device_memory &mem)
683{
684 if (!mem.device_pointer) {
685 global_alloc(mem);
686 }
687 else {
688 generic_copy_to(mem);
689 }
690}
691
692void OneapiDevice::global_free(device_memory &mem)
693{
694 if (mem.device_pointer) {
695 generic_free(mem);
696 }
697}
698
699# ifndef WITH_CYCLES_ONEAPI_SOFTWARE_TEXTURING
700static sycl::ext::oneapi::experimental::image_descriptor image_desc(const device_image &mem)
701{
702 /* Image Texture Storage */
703 sycl::image_channel_type channel_type;
704
705 switch (mem.data_type) {
706 case TYPE_UCHAR:
707 channel_type = sycl::image_channel_type::unorm_int8;
708 break;
709 case TYPE_UINT16:
710 channel_type = sycl::image_channel_type::unorm_int16;
711 break;
712 case TYPE_FLOAT:
713 channel_type = sycl::image_channel_type::fp32;
714 break;
715 case TYPE_HALF:
716 channel_type = sycl::image_channel_type::fp16;
717 break;
718 default:
719 channel_type = sycl::image_channel_type::unorm_int8;
720 assert(0);
721 break;
722 }
723
724 sycl::ext::oneapi::experimental::image_descriptor param;
725 param.width = mem.data_width;
726 param.height = mem.data_height;
727 param.num_channels = mem.data_elements;
728 param.channel_type = channel_type;
729
730 param.verify();
731
732 return param;
733}
734# endif /* !WITH_CYCLES_ONEAPI_SOFTWARE_TEXTURING */
735
736void OneapiDevice::image_alloc(device_image &mem)
737{
738 assert(device_queue_);
739
740# ifndef WITH_CYCLES_ONEAPI_SOFTWARE_TEXTURING
741 size_t size = mem.memory_size();
742
743 sycl::addressing_mode address_mode = sycl::addressing_mode::none;
744 switch (mem.info.extension) {
745 case EXTENSION_REPEAT:
746 address_mode = sycl::addressing_mode::repeat;
747 break;
748 case EXTENSION_EXTEND:
749 address_mode = sycl::addressing_mode::clamp_to_edge;
750 break;
751 case EXTENSION_CLIP:
752 address_mode = sycl::addressing_mode::clamp;
753 break;
754 case EXTENSION_MIRROR:
755 address_mode = sycl::addressing_mode::mirrored_repeat;
756 break;
757 default:
758 assert(0);
759 break;
760 }
761
762 sycl::filtering_mode filter_mode;
764 filter_mode = sycl::filtering_mode::nearest;
765 }
766 else {
767 filter_mode = sycl::filtering_mode::linear;
768 }
769
770 /* Image Texture Storage */
771 sycl::image_channel_type channel_type;
772
773 switch (mem.data_type) {
774 case TYPE_UCHAR:
775 channel_type = sycl::image_channel_type::unorm_int8;
776 break;
777 case TYPE_UINT16:
778 channel_type = sycl::image_channel_type::unorm_int16;
779 break;
780 case TYPE_FLOAT:
781 channel_type = sycl::image_channel_type::fp32;
782 break;
783 case TYPE_HALF:
784 channel_type = sycl::image_channel_type::fp16;
785 break;
786 default:
787 assert(0);
788 return;
789 }
790
791 sycl::queue *queue = reinterpret_cast<sycl::queue *>(device_queue_);
792
793 try {
794 Mem *cmem = nullptr;
795 sycl::ext::oneapi::experimental::image_mem_handle memHandle{0};
796 sycl::ext::oneapi::experimental::image_descriptor desc{};
797
798 if (mem.data_height > 0) {
799 /* 2D/3D image -- Tile optimized */
800 const sycl::device &device = reinterpret_cast<sycl::queue *>(queue)->get_device();
801 const size_t max_width = device.get_info<sycl::info::device::image2d_max_width>();
802 const size_t max_height = device.get_info<sycl::info::device::image2d_max_height>();
803
804 if (mem.data_width > max_width || mem.data_height > max_height) {
805 set_error(
806 string_printf("Maximum GPU 2D texture size exceeded (max %zux%zu, found %zux%zu)",
807 max_width,
808 max_height,
809 mem.data_width,
810 mem.data_height));
811 return;
812 }
813
814 /* 2D texture -- Tile optimized */
815 desc = sycl::ext::oneapi::experimental::image_descriptor(
816 {mem.data_width, mem.data_height, 0}, mem.data_elements, channel_type);
817
818 LOG_DEBUG << "Array 2D/3D allocate: " << mem.log_name() << ", "
819 << string_human_readable_number(mem.memory_size()) << " bytes. ("
821
822 memHandle = sycl::ext::oneapi::experimental::alloc_image_mem(desc, *queue);
823 if (!memHandle.raw_handle) {
824 set_error("GPU image allocation failed: Raw handle is null");
825 return;
826 }
827
828 /* Copy data from host to the image properly based on the image description */
829 queue->ext_oneapi_copy(mem.host_pointer, memHandle, desc);
830
831 mem.device_pointer = (device_ptr)memHandle.raw_handle;
832 mem.device_size = size;
833 stats.mem_alloc(size);
834
835 thread_scoped_lock lock(device_mem_map_mutex);
836 cmem = &device_mem_map[&mem];
837 cmem->texobject = 0;
838 cmem->array = (arrayMemObject)(memHandle.raw_handle);
839 }
840 else {
841 /* 1D image -- Linear memory */
842 desc = sycl::ext::oneapi::experimental::image_descriptor(
843 {mem.data_width}, mem.data_elements, channel_type);
844 cmem = generic_alloc(mem);
845 if (!cmem) {
846 return;
847 }
848
849 queue->memcpy((void *)mem.device_pointer, mem.host_pointer, size);
850 }
851
852 queue->wait_and_throw();
853
854 /* Set Mapping and tag that we need to (re-)upload to device */
855 KernelImageInfo tex_info = mem.info;
856
857 sycl::ext::oneapi::experimental::bindless_image_sampler samp(
858 address_mode, sycl::coordinate_normalization_mode::normalized, filter_mode);
859
860 if (!is_nanovdb_type(mem.info.data_type)) {
861 sycl::ext::oneapi::experimental::sampled_image_handle imgHandle;
862
863 if (memHandle.raw_handle) {
864 /* Create 2D/3D image handle */
865 imgHandle = sycl::ext::oneapi::experimental::create_image(memHandle, samp, desc, *queue);
866 }
867 else {
868 /* Create 1D image */
869 imgHandle = sycl::ext::oneapi::experimental::create_image(
870 (void *)mem.device_pointer, 0, samp, desc, *queue);
871 }
872
873 thread_scoped_lock lock(device_mem_map_mutex);
874 cmem = &device_mem_map[&mem];
875 cmem->texobject = (texMemObject)(imgHandle.raw_handle);
876
877 tex_info.data = (uint64_t)cmem->texobject;
878 }
879 else {
880 tex_info.data = (uint64_t)mem.device_pointer;
881 }
882
883 /* Update image info. */
884 image_info_update(mem.image_info_id, tex_info);
885 }
886 catch (sycl::exception const &e) {
887 set_error("GPU image allocation failed: runtime exception \"" + string(e.what()) + "\"");
888 }
889# else /* !WITH_CYCLES_ONEAPI_SOFTWARE_TEXTURING */
890 LOG_DEBUG << "Image allocate: " << mem.log_name() << ", "
891 << string_human_readable_number(mem.memory_size()) << " bytes. ("
893
894 generic_alloc(mem);
895 generic_copy_to(mem);
896 /* Update image info; device upload happens lazily in load_image_info(). */
897 KernelImageInfo tex_info = mem.info;
898 tex_info.data = (uint64_t)mem.device_pointer;
899 image_info_update(mem.image_info_id, tex_info);
900# endif /* !WITH_CYCLES_ONEAPI_SOFTWARE_TEXTURING */
901}
902
903void OneapiDevice::image_copy_to(device_image &mem)
904{
905 if (!mem.device_pointer) {
906 image_alloc(mem);
907 }
908 else {
909# ifndef WITH_CYCLES_ONEAPI_SOFTWARE_TEXTURING
910 if (mem.data_height > 0) {
911 /* 2D/3D image -- Tile optimized */
912 sycl::ext::oneapi::experimental::image_descriptor desc = image_desc(mem);
913
914 sycl::queue *queue = reinterpret_cast<sycl::queue *>(device_queue_);
915
916 try {
917 /* Copy data from host to the image properly based on the image description */
918 thread_scoped_lock lock(device_mem_map_mutex);
919 const Mem &cmem = device_mem_map[&mem];
920 sycl::ext::oneapi::experimental::image_mem_handle image_handle{
921 (sycl::ext::oneapi::experimental::image_mem_handle::raw_handle_type)cmem.array};
922 queue->ext_oneapi_copy(mem.host_pointer, image_handle, desc);
923
924# ifdef WITH_CYCLES_DEBUG
925 queue->wait_and_throw();
926# endif
927 }
928 catch (sycl::exception const &e) {
929 set_error("oneAPI image copy error: got runtime exception \"" + string(e.what()) + "\"");
930 }
931 }
932 else {
933 generic_copy_to(mem);
934 }
935# else /* !WITH_CYCLES_ONEAPI_SOFTWARE_TEXTURING */
936 generic_copy_to(mem);
937# endif /* !WITH_CYCLES_ONEAPI_SOFTWARE_TEXTURING */
938 }
939}
940
941void OneapiDevice::image_free(device_image &mem)
942{
943 if (mem.device_pointer) {
944# ifndef WITH_CYCLES_ONEAPI_SOFTWARE_TEXTURING
945 thread_scoped_lock lock(device_mem_map_mutex);
946 DCHECK(device_mem_map.find(&mem) != device_mem_map.end());
947 const Mem &cmem = device_mem_map[&mem];
948
949 sycl::queue *queue = reinterpret_cast<sycl::queue *>(device_queue_);
950
951 if (cmem.texobject) {
952 /* Free bindless image itself. */
953 sycl::ext::oneapi::experimental::sampled_image_handle image(cmem.texobject);
954 sycl::ext::oneapi::experimental::destroy_image_handle(image, *queue);
955 }
956
957 if (cmem.array) {
958 /* Free image memory. */
959 sycl::ext::oneapi::experimental::image_mem_handle imgHandle{
960 (sycl::ext::oneapi::experimental::image_mem_handle::raw_handle_type)cmem.array};
961
962 try {
963 /* We have allocated only standard images, so we also deallocate only them. */
964 sycl::ext::oneapi::experimental::free_image_mem(
965 imgHandle, sycl::ext::oneapi::experimental::image_type::standard, *queue);
966 }
967 catch (sycl::exception const &e) {
968 set_error("oneAPI image deallocation error: got runtime exception \"" + string(e.what()) +
969 "\"");
970 }
971
972 stats.mem_free(mem.memory_size());
973 mem.device_pointer = 0;
974 mem.device_size = 0;
975 device_mem_map.erase(device_mem_map.find(&mem));
976 }
977 else {
978 lock.unlock();
979 generic_free(mem);
980 }
981# else /* !WITH_CYCLES_ONEAPI_SOFTWARE_TEXTURING */
982 generic_free(mem);
983# endif /* !WITH_CYCLES_ONEAPI_SOFTWARE_TEXTURING */
984 }
985}
986
987unique_ptr<DeviceQueue> OneapiDevice::gpu_queue_create()
988{
989 return make_unique<OneapiDeviceQueue>(this);
990}
991
992bool OneapiDevice::should_use_graphics_interop(const GraphicsInteropDevice &interop_device,
993 const bool log)
994{
995# ifdef SYCL_LINEAR_MEMORY_INTEROP_AVAILABLE
996 if (interop_device.type != GraphicsInteropDevice::VULKAN) {
997 /* SYCL only supports interop with Vulkan and D3D. */
998 return false;
999 }
1000
1001 try {
1002 const sycl::device &device = reinterpret_cast<sycl::queue *>(device_queue_)->get_device();
1003 if (!device.has(sycl::aspect::ext_oneapi_external_memory_import)) {
1004 return false;
1005 }
1006
1007 /* This extension is in the namespace "sycl::ext::intel",
1008 * but also available on non-Intel GPUs. */
1009 sycl::detail::uuid_type uuid = device.get_info<sycl::ext::intel::info::device::uuid>();
1010 const bool found = (uuid.size() == interop_device.uuid.size() &&
1011 memcmp(uuid.data(), interop_device.uuid.data(), uuid.size()) == 0);
1012
1013 if (log) {
1014 if (found) {
1015 LOG_INFO << "Graphics interop: found matching Vulkan device for oneAPI";
1016 }
1017 else {
1018 LOG_INFO << "Graphics interop: no matching Vulkan device for oneAPI";
1019 }
1020
1021 LOG_INFO << "Graphics Interop: oneAPI UUID " << string_hex(uuid.data(), uuid.size())
1022 << ", Vulkan UUID "
1023 << string_hex(interop_device.uuid.data(), interop_device.uuid.size());
1024 }
1025
1026 return found;
1027 }
1028 catch (sycl::exception &e) {
1029 LOG_ERROR << "Could not release external Vulkan memory: " << e.what();
1030 }
1031# endif
1032 return false;
1033}
1034
1035void *OneapiDevice::usm_aligned_alloc_host(const size_t memory_size, const size_t alignment)
1036{
1037 assert(device_queue_);
1038 return usm_aligned_alloc_host(device_queue_, memory_size, alignment);
1039}
1040
1041void OneapiDevice::usm_free(void *usm_ptr)
1042{
1043 assert(device_queue_);
1044 usm_free(device_queue_, usm_ptr);
1045}
1046
1047void OneapiDevice::check_usm(SyclQueue *queue_, const void *usm_ptr, bool allow_host = false)
1048{
1049# ifndef NDEBUG
1050 sycl::queue *queue = reinterpret_cast<sycl::queue *>(queue_);
1051 sycl::info::device_type device_type =
1052 queue->get_device().get_info<sycl::info::device::device_type>();
1053 sycl::usm::alloc usm_type = get_pointer_type(usm_ptr, queue->get_context());
1054 (void)usm_type;
1055 const sycl::usm::alloc main_memory_type = sycl::usm::alloc::device;
1056 assert(usm_type == main_memory_type ||
1057 (usm_type == sycl::usm::alloc::host &&
1058 (allow_host || device_type == sycl::info::device_type::cpu)) ||
1059 usm_type == sycl::usm::alloc::unknown);
1060# else
1061 /* Silence warning about unused arguments. */
1062 (void)queue_;
1063 (void)usm_ptr;
1064 (void)allow_host;
1065# endif
1066}
1067
1068bool OneapiDevice::create_queue(SyclQueue *&external_queue,
1069 const int device_index,
1070 void *embree_device_pointer,
1071 bool *multiple_level_zero_platforms_detected_pointer)
1072{
1073 bool finished_correct = true;
1074 *multiple_level_zero_platforms_detected_pointer = false;
1075
1076 try {
1077 std::vector<SyclDeviceEntry> devices = available_sycl_devices(
1078 multiple_level_zero_platforms_detected_pointer);
1079
1080 if (device_index < 0 || device_index >= devices.size()) {
1081 return false;
1082 }
1083
1084 if (devices[device_index].meets_driver_requirement == false) {
1085 oneapi_error_string_ = "The device driver is too old.";
1086 LOG_ERROR << "Internal error: The SYCL device does not meet minimum driver requirement, but "
1087 "it was used anyway. Please report a bug.";
1088 return false;
1089 }
1090
1091 sycl::queue *created_queue = new sycl::queue(devices[device_index].device,
1092 sycl::property::queue::in_order());
1093 external_queue = reinterpret_cast<SyclQueue *>(created_queue);
1094
1095# ifdef WITH_EMBREE_GPU
1096 if (embree_device_pointer) {
1097 RTCDevice *device_object_ptr = reinterpret_cast<RTCDevice *>(embree_device_pointer);
1098 *device_object_ptr = rtcNewSYCLDevice(created_queue->get_context(), "");
1099 if (*device_object_ptr == nullptr) {
1100 finished_correct = false;
1101 oneapi_error_string_ =
1102 "Hardware Raytracing is not available; please install "
1103 "\"intel-level-zero-gpu-raytracing\" to enable it or disable Embree on GPU.";
1104 }
1105 else {
1106 rtcSetDeviceSYCLDevice(*device_object_ptr, devices[device_index].device);
1107 }
1108 }
1109# else
1110 (void)embree_device_pointer;
1111# endif
1112 }
1113 catch (const sycl::exception &e) {
1114 finished_correct = false;
1115 oneapi_error_string_ = e.what();
1116 }
1117 return finished_correct;
1118}
1119
1120void OneapiDevice::free_queue(SyclQueue *queue_)
1121{
1122 assert(queue_);
1123 sycl::queue *queue = reinterpret_cast<sycl::queue *>(queue_);
1124 delete queue;
1125}
1126
1127void *OneapiDevice::usm_aligned_alloc_host(SyclQueue *queue_,
1128 size_t memory_size,
1129 const size_t alignment)
1130{
1131 assert(queue_);
1132 sycl::queue *queue = reinterpret_cast<sycl::queue *>(queue_);
1133 return sycl::aligned_alloc_host(alignment, memory_size, *queue);
1134}
1135
1136void *OneapiDevice::usm_alloc_device(SyclQueue *queue_, size_t memory_size)
1137{
1138 assert(queue_);
1139 sycl::queue *queue = reinterpret_cast<sycl::queue *>(queue_);
1140 /* NOTE(@nsirgien): There are three types of Unified Shared Memory (USM) in oneAPI: host, device
1141 * and shared. For new project it could more beneficial to use USM shared memory, because it
1142 * provides automatic migration mechanism in order to allow to use the same pointer on host and
1143 * on device, without need to worry about explicit memory transfer operations, although usage of
1144 * USM shared imply some documented limitations on the memory usage in regards of parallel access
1145 * from different threads. But for Blender/Cycles this type of memory is not very suitable in
1146 * current application architecture, because Cycles is multi-thread application and already uses
1147 * two different pointer for host activity and device activity, and also has to perform all
1148 * needed memory transfer operations. So, USM device memory type has been used for oneAPI device
1149 * in order to better fit in Cycles architecture. */
1150 return sycl::malloc_device(memory_size, *queue);
1151}
1152
1153void OneapiDevice::usm_free(SyclQueue *queue_, void *usm_ptr)
1154{
1155 assert(queue_);
1156 sycl::queue *queue = reinterpret_cast<sycl::queue *>(queue_);
1157 OneapiDevice::check_usm(queue_, usm_ptr, true);
1158 sycl::free(usm_ptr, *queue);
1159}
1160
1161bool OneapiDevice::usm_memcpy(SyclQueue *queue_, void *dest, void *src, const size_t num_bytes)
1162{
1163 assert(queue_);
1164 /* sycl::queue::memcpy may crash if the queue is in an invalid state due to previous
1165 * runtime errors. It's better to avoid running memory operations in that case.
1166 * The render will be canceled and the queue will be destroyed anyway. */
1167 if (have_error()) {
1168 return false;
1169 }
1170
1171 sycl::queue *queue = reinterpret_cast<sycl::queue *>(queue_);
1172 OneapiDevice::check_usm(queue_, dest, true);
1173 OneapiDevice::check_usm(queue_, src, true);
1174 sycl::usm::alloc dest_type = get_pointer_type(dest, queue->get_context());
1175 sycl::usm::alloc src_type = get_pointer_type(src, queue->get_context());
1176 /* Unknown here means, that this is not an USM allocation, which implies that this is
1177 * some generic C++ allocation, so we could use C++ memcpy directly with USM host. */
1178 if ((dest_type == sycl::usm::alloc::host || dest_type == sycl::usm::alloc::unknown) &&
1179 (src_type == sycl::usm::alloc::host || src_type == sycl::usm::alloc::unknown))
1180 {
1181 memcpy(dest, src, num_bytes);
1182 return true;
1183 }
1184
1185 try {
1186 sycl::event mem_event = queue->memcpy(dest, src, num_bytes);
1187# ifdef WITH_CYCLES_DEBUG
1188 /* NOTE(@nsirgien) Waiting on memory operation may give more precise error
1189 * messages. Due to impact on occupancy, it makes sense to enable it only during Cycles debug.
1190 */
1191 mem_event.wait_and_throw();
1192 return true;
1193# else
1194 bool from_device_to_host = dest_type == sycl::usm::alloc::host &&
1195 src_type == sycl::usm::alloc::device;
1196 bool host_or_device_memop_with_offset = dest_type == sycl::usm::alloc::unknown ||
1197 src_type == sycl::usm::alloc::unknown;
1198 /* NOTE(@sirgienko) Host-side blocking wait on this operation is mandatory, otherwise the host
1199 * may not wait until the end of the transfer before using the memory.
1200 */
1201 if (from_device_to_host || host_or_device_memop_with_offset) {
1202 mem_event.wait();
1203 }
1204 return true;
1205# endif
1206 }
1207 catch (const sycl::exception &e) {
1208 oneapi_error_string_ = e.what();
1209 return false;
1210 }
1211}
1212
1213bool OneapiDevice::usm_memset(SyclQueue *queue_,
1214 void *usm_ptr,
1215 unsigned char value,
1216 const size_t num_bytes)
1217{
1218 assert(queue_);
1219 /* sycl::queue::memset may crash if the queue is in an invalid state due to previous
1220 * runtime errors. It's better to avoid running memory operations in that case.
1221 * The render will be canceled and the queue will be destroyed anyway. */
1222 if (have_error()) {
1223 return false;
1224 }
1225
1226 sycl::queue *queue = reinterpret_cast<sycl::queue *>(queue_);
1227 OneapiDevice::check_usm(queue_, usm_ptr, true);
1228 try {
1229 sycl::event mem_event = queue->memset(usm_ptr, value, num_bytes);
1230# ifdef WITH_CYCLES_DEBUG
1231 /* NOTE(@nsirgien) Waiting on memory operation may give more precise error
1232 * messages. Due to impact on occupancy, it makes sense to enable it only during Cycles debug.
1233 */
1234 mem_event.wait_and_throw();
1235# else
1236 (void)mem_event;
1237# endif
1238 return true;
1239 }
1240 catch (const sycl::exception &e) {
1241 oneapi_error_string_ = e.what();
1242 return false;
1243 }
1244}
1245
1246bool OneapiDevice::queue_synchronize(SyclQueue *queue_)
1247{
1248 assert(queue_);
1249 sycl::queue *queue = reinterpret_cast<sycl::queue *>(queue_);
1250 try {
1251 queue->wait_and_throw();
1252 return true;
1253 }
1254 catch (const sycl::exception &e) {
1255 oneapi_error_string_ = e.what();
1256 return false;
1257 }
1258}
1259
1260bool OneapiDevice::kernel_globals_size(size_t &kernel_global_size)
1261{
1262 kernel_global_size = sizeof(KernelGlobalsGPU);
1263
1264 return true;
1265}
1266
1267void OneapiDevice::set_global_memory(SyclQueue *queue_,
1268 void *kernel_globals,
1269 const char *memory_name,
1270 void *memory_device_pointer)
1271{
1272 assert(queue_);
1273 assert(kernel_globals);
1274 assert(memory_name);
1275 assert(memory_device_pointer);
1276 KernelGlobalsGPU *globals = (KernelGlobalsGPU *)kernel_globals;
1277 OneapiDevice::check_usm(queue_, memory_device_pointer, true);
1278 OneapiDevice::check_usm(queue_, kernel_globals, true);
1279
1280 std::string matched_name(memory_name);
1281
1282/* This macro will change global ptr of KernelGlobals via name matching. */
1283# define KERNEL_DATA_ARRAY(type, name) \
1284 else if (#name == matched_name) \
1285 { \
1286 globals->__##name = (type *)memory_device_pointer; \
1287 return; \
1288 }
1289 if (false) {
1290 }
1291 else if ("integrator_state" == matched_name) {
1292 globals->integrator_state = (IntegratorStateGPU *)memory_device_pointer;
1293 return;
1294 }
1295 KERNEL_DATA_ARRAY(KernelData, data)
1296# include "kernel/data_arrays.h"
1297 else
1298 {
1299 std::cerr << "Can't found global/constant memory with name \"" << matched_name << "\"!"
1300 << std::endl;
1301 assert(false);
1302 }
1303# undef KERNEL_DATA_ARRAY
1304}
1305
1306bool OneapiDevice::enqueue_kernel(KernelContext *kernel_context,
1307 const int kernel,
1308 const size_t global_size,
1309 const size_t local_size,
1310 void **args)
1311{
1312 return oneapi_enqueue_kernel(kernel_context,
1313 kernel,
1314 global_size,
1315 local_size,
1316 kernel_features,
1317 use_hardware_raytracing,
1318 args);
1319}
1320
1321void OneapiDevice::get_adjusted_global_and_local_sizes(SyclQueue *queue,
1322 const DeviceKernel kernel,
1323 size_t &kernel_global_size,
1324 size_t &kernel_local_size)
1325{
1326 assert(queue);
1327 static const size_t preferred_work_group_size_intersect = 128;
1328 static const size_t preferred_work_group_size_shading = 256;
1329 static const size_t preferred_work_group_size_shading_simd8 = 64;
1330 /* Shader evaluation kernels seems to use some amount of shared memory, so better
1331 * to avoid usage of maximum work group sizes for them. */
1332 static const size_t preferred_work_group_size_shader_evaluation = 256;
1333 /* NOTE(@nsirgien): 1024 currently may lead to issues with cryptomatte kernels, so
1334 * for now their work-group size is restricted to 512. */
1335 static const size_t preferred_work_group_size_cryptomatte = 512;
1336 static const size_t preferred_work_group_size_default = 1024;
1337
1338 const sycl::device &device = reinterpret_cast<sycl::queue *>(queue)->get_device();
1339 const size_t max_work_group_size = device.get_info<sycl::info::device::max_work_group_size>();
1340
1341 size_t preferred_work_group_size = 0;
1342 switch (kernel) {
1351 preferred_work_group_size = preferred_work_group_size_intersect;
1352 break;
1353
1363 const bool device_is_simd8 =
1364 (device.has(sycl::aspect::ext_intel_gpu_eu_simd_width) &&
1365 device.get_info<sycl::ext::intel::info::device::gpu_eu_simd_width>() == 8);
1366 preferred_work_group_size = (device_is_simd8) ? preferred_work_group_size_shading_simd8 :
1367 preferred_work_group_size_shading;
1368 } break;
1369
1371 preferred_work_group_size = preferred_work_group_size_cryptomatte;
1372 break;
1373
1378 preferred_work_group_size = preferred_work_group_size_shader_evaluation;
1379 break;
1380
1381 default:
1382 /* Do nothing and keep initial zero value. */
1383 break;
1384 }
1385
1386 /* Such order of logic allow us to override Blender default values, if needed,
1387 * yet respect them otherwise. */
1388 if (preferred_work_group_size == 0) {
1389 preferred_work_group_size = oneapi_suggested_gpu_kernel_size((::DeviceKernel)kernel);
1390 }
1391
1392 /* If there is no recommendation, then use manual default value. */
1393 if (preferred_work_group_size == 0) {
1394 preferred_work_group_size = preferred_work_group_size_default;
1395 }
1396
1397 kernel_local_size = std::min(max_work_group_size, preferred_work_group_size);
1398
1399 /* NOTE(@nsirgien): As for now non-uniform work-groups don't work on most oneAPI devices,
1400 * we extend work size to fit uniformity requirements. */
1401 kernel_global_size = round_up(kernel_global_size, kernel_local_size);
1402
1403 assert(kernel_global_size % kernel_local_size == 0);
1404}
1405
1406/* Compute-runtime (ie. NEO) version is what gets returned by sycl/L0 on Windows
1407 * since Windows driver 101.3268. */
1408/* IMPORTANT: ocloc 101.8424 (compute-runtime version 36246) generates
1409 * AoT binaries that have been manually verified compatible down to
1410 * driver 101.8306 by Intel, matching lowest_supported_driver_version_win.
1411 * If ocloc is upgraded again in future, this compatibility must be re-verified
1412 * or the minimum version bumped. */
1413static const int lowest_supported_driver_version_win = 1018306;
1414# ifdef _WIN32
1415/* For Windows driver 101.8331, compute-runtime version is 35716.
1416 * And for Windows Workstation driver 32.0.101.8306 Q4.25, it is also 35716.
1417 * This information is returned by `ocloc query OCL_DRIVER_VERSION`. */
1418static const int lowest_supported_driver_version_neo = 35716;
1419# else
1420/* For Linux, according to Blender version file
1421 * build_files\build_environment\cmake\versions.cmake we
1422 * at the moment are using Intel Graphics Compiler v2.30.1.
1423 * According to the Intel Linux Driver releases page:
1424 * https://github.com/intel/compute-runtime/releases the first driver
1425 * which supports this IGC version is 26.09.37435.1, which you can
1426 * confirm by checking "Additional components revisions used in build"
1427 * section. Thus, this version is our minimal one. */
1428static const int lowest_supported_driver_version_neo = 37435;
1429# endif
1430
1431int parse_driver_build_version(const sycl::device &device)
1432{
1433 const std::string &driver_version = device.get_info<sycl::info::device::driver_version>();
1434 int driver_build_version = 0;
1435
1436 size_t second_dot_position = driver_version.find('.', driver_version.find('.') + 1);
1437 if (second_dot_position != std::string::npos) {
1438 try {
1439 size_t third_dot_position = driver_version.find('.', second_dot_position + 1);
1440 if (third_dot_position != std::string::npos) {
1441 const std::string &third_number_substr = driver_version.substr(
1442 second_dot_position + 1, third_dot_position - second_dot_position - 1);
1443 const std::string &forth_number_substr = driver_version.substr(third_dot_position + 1);
1444 if (third_number_substr.length() == 3 && forth_number_substr.length() == 4) {
1445 driver_build_version = std::stoi(third_number_substr) * 10000 +
1446 std::stoi(forth_number_substr);
1447 }
1448 /* This is actually not a correct version string (Major.Minor.Patch.Optional), see blender
1449 * bug report #137277, but there are several driver versions with this Intel bug existing
1450 * at this point, so it is worth working around this issue in Blender source code, allowing
1451 * users to actually use Intel GPU when it is possible. */
1452 else if (third_number_substr.length() == 5 && forth_number_substr.length() == 6) {
1453 driver_build_version = std::stoi(third_number_substr);
1454 }
1455 }
1456 else {
1457 const std::string &third_number_substr = driver_version.substr(second_dot_position + 1);
1458 driver_build_version = std::stoi(third_number_substr);
1459 }
1460 }
1461 catch (std::invalid_argument &) {
1462 }
1463 }
1464
1465 if (driver_build_version == 0) {
1466 LOG_WARNING << "Unable to parse unknown Intel GPU driver version. \"" << driver_version
1467 << "\" does not match xx.xx.xxxxx (Linux), x.x.xxxx (L0),"
1468 << " xx.xx.xxx.xxxx (Windows) for device \""
1469 << device.get_info<sycl::info::device::name>() << "\".";
1470 }
1471
1472 return driver_build_version;
1473}
1474
1475std::vector<SyclDeviceEntry> available_sycl_devices(
1476 bool *multiple_level_zero_platforms_detected = nullptr)
1477{
1478 std::vector<SyclDeviceEntry> available_devices;
1479 bool allow_all_devices = false;
1480 if (getenv("CYCLES_ONEAPI_ALL_DEVICES") != nullptr) {
1481 allow_all_devices = true;
1482 }
1483
1484 int level_zero_platform_counter = 0;
1485 try {
1486 const std::vector<sycl::platform> &oneapi_platforms = sycl::platform::get_platforms();
1487
1488 for (const sycl::platform &platform : oneapi_platforms) {
1489 /* ignore OpenCL platforms to avoid using the same devices through both Level-Zero and
1490 * OpenCL.
1491 */
1492 if (platform.get_backend() == sycl::backend::opencl) {
1493 continue;
1494 }
1495
1496 if (platform.get_backend() == sycl::backend::ext_oneapi_level_zero) {
1497 level_zero_platform_counter++;
1498 }
1499
1500 const std::vector<sycl::device> &oneapi_devices =
1501 (allow_all_devices) ? platform.get_devices(sycl::info::device_type::all) :
1502 platform.get_devices(sycl::info::device_type::gpu);
1503
1504 for (const sycl::device &device : oneapi_devices) {
1505 bool filter_out = false;
1506 bool meets_driver_requirement = true;
1507
1508 if (!allow_all_devices) {
1509 /* For now we support all Intel(R) Arc(TM) devices and likely any future GPU,
1510 * assuming they have either more than 96 Execution Units or not 7 threads per EU.
1511 * Official support can be broaden to older and smaller GPUs once ready. */
1512 if (!device.is_gpu() || platform.get_backend() != sycl::backend::ext_oneapi_level_zero) {
1513 filter_out = true;
1514 }
1515 else {
1516 /* Filtered-out defaults in-case these values aren't available. */
1517 int number_of_eus = 96;
1518 int threads_per_eu = 7;
1519 if (device.has(sycl::aspect::ext_intel_gpu_eu_count)) {
1520 number_of_eus = device.get_info<sycl::ext::intel::info::device::gpu_eu_count>();
1521 }
1522 if (device.has(sycl::aspect::ext_intel_gpu_hw_threads_per_eu)) {
1523 threads_per_eu =
1524 device.get_info<sycl::ext::intel::info::device::gpu_hw_threads_per_eu>();
1525 }
1526 /* This filters out all Level-Zero supported GPUs from older generation than Arc. */
1527 if (number_of_eus <= 96 && threads_per_eu == 7) {
1528 filter_out = true;
1529 }
1530# ifndef WITH_CYCLES_ONEAPI_SOFTWARE_TEXTURING
1531 /* If not already filtered out, check support for bindless images. */
1532 if (!filter_out && !device.has(sycl::aspect::ext_oneapi_bindless_images)) {
1533 filter_out = true;
1534
1535 LOG_WARNING << "Device \"" << device.get_info<sycl::info::device::name>()
1536 << "\" does not support bindless images, which Cycles oneAPI"
1537 << " requires. Build Blender with "
1538 << "WITH_CYCLES_ONEAPI_SOFTWARE_TEXTURING to use this device.";
1539 }
1540# endif
1541 /* If not already filtered out, check driver version. */
1542 bool check_driver_version = !filter_out;
1543 /* We don't know how to check driver version strings for non-Intel GPUs. */
1544 if (check_driver_version &&
1545 device.get_info<sycl::info::device::vendor>().find("Intel") == std::string::npos)
1546 {
1547 check_driver_version = false;
1548 }
1549 /* Because of https://github.com/oneapi-src/unified-runtime/issues/1777, future drivers
1550 * may break parsing done by a SYCL runtime from before the fix we expect in major
1551 * version 8. Parsed driver version would start with something different than current
1552 * "1.3.". To avoid blocking a device by mistake in the case of new driver / old SYCL
1553 * runtime, we disable driver version check in case LIBSYCL_MAJOR_VERSION is below 8
1554 * and actual driver version doesn't start with 1.3. */
1555# if __LIBSYCL_MAJOR_VERSION < 8
1556 if (check_driver_version &&
1557 !string_startswith(device.get_info<sycl::info::device::driver_version>(), "1.3."))
1558 {
1559 check_driver_version = false;
1560 }
1561# endif
1562 if (check_driver_version) {
1563 int driver_build_version = parse_driver_build_version(device);
1564 const int lowest_supported_driver_version = (driver_build_version > 100000) ?
1565 lowest_supported_driver_version_win :
1566 lowest_supported_driver_version_neo;
1567 if (driver_build_version < lowest_supported_driver_version) {
1568 meets_driver_requirement = false;
1569
1570 LOG_WARNING << "Driver version for device \""
1571 << device.get_info<sycl::info::device::name>()
1572 << "\" is too old. Expected \"" << lowest_supported_driver_version
1573 << "\" or newer, but got \"" << driver_build_version << "\".";
1574 }
1575 }
1576 }
1577 }
1578
1579 /* NOTE(sirgienko) Due to some changes in the latest Intel Drivers, the currently used
1580 * DPC++ compiler will duplicate devices on some platforms, which have a discrete Intel GPU
1581 * together with 11th-14th Gen CPUs, with iGPU enabled. This will be fixed in upstream
1582 * DPC++ 6.3, but for now, in order to not confuse our Blender end-users with several
1583 * duplicated GPUs, we will avoid adding duplicates into the device list. */
1584 /* The order of adding devices is not important, as both duplicated GPUs are fully
1585 * functional and performant, so we can pick up the first one we find. */
1586 if (!filter_out) {
1587 for (const SyclDeviceEntry &available_entry : available_devices) {
1588 std::array<sycl::device, 2> devices = {available_entry.device, device};
1589 std::vector<sycl::ext::intel::info::device::uuid::return_type> uuids;
1590 for (int i = 0; i < 2; i++) {
1591 /* As this is an Intel-specific enumeration issue - we are collecting Intel UUID
1592 * expecting it to be supported on Intel GPUs. */
1593 if (devices[i].has(sycl::aspect::ext_intel_device_info_uuid)) {
1594 uuids.push_back(devices[i].get_info<sycl::ext::intel::info::device::uuid>());
1595 }
1596 else if (devices[i].get_platform().get_info<sycl::info::platform::vendor>() ==
1597 "Intel(R) Corporation")
1598 {
1599 /* Better to ensure that our expectation that all Intel devices support the UUID
1600 * extension is correct. If one day this is not true, then we will at least have a
1601 * warning message in the log. */
1602 const std::string &device_name = devices[i].get_info<sycl::info::device::name>();
1603 LOG_WARNING << "Despite expectation, Intel oneAPI device '" << device_name
1604 << "' is not supporting Intel SYCL UUID extension.";
1605 }
1606 }
1607 if (uuids.size() == 2) {
1608 if (uuids[0] == uuids[1]) {
1609 const std::string &device_name = device.get_info<sycl::info::device::name>();
1610 const std::string &platform_name =
1611 device.get_platform().get_info<sycl::info::platform::name>();
1612 LOG_DEBUG
1613 << "Detecting that oneAPI device '" << device_name << "' of platform '"
1614 << platform_name
1615 << "' is identical (by UUID comparison) to an already added device in the "
1616 "list of available devices, so it will not be added again.";
1617 filter_out = true;
1618 break;
1619 }
1620 }
1621 }
1622 }
1623
1624 if (!filter_out) {
1625 available_devices.push_back(SyclDeviceEntry{device, meets_driver_requirement});
1626 }
1627 }
1628 }
1629 }
1630 catch (sycl::exception &e) {
1631 LOG_WARNING << "An error has been encountered while enumerating SYCL devices: " << e.what();
1632 }
1633
1634 if (multiple_level_zero_platforms_detected) {
1635 *multiple_level_zero_platforms_detected = level_zero_platform_counter > 1;
1636 }
1637
1638 return available_devices;
1639}
1640
1641void OneapiDevice::architecture_information(const SyclDevice *device,
1642 string &name,
1643 bool &is_optimized)
1644{
1645 const sycl::ext::oneapi::experimental::architecture arch =
1646 reinterpret_cast<const sycl::device *>(device)
1647 ->get_info<sycl::ext::oneapi::experimental::info::device::architecture>();
1648
1649# define FILL_ARCH_INFO(architecture_code, is_arch_optimized) \
1650 case sycl::ext::oneapi::experimental::architecture ::architecture_code: \
1651 name = #architecture_code; \
1652 is_optimized = is_arch_optimized; \
1653 break;
1654
1655 /* List of architectures that have been optimized by Intel and Blender developers.
1656 *
1657 * For example, Intel Rocket Lake iGPU (rkl) is not supported and not optimized,
1658 * while Intel Arc Alchemist dGPU (dg2) was optimized for.
1659 *
1660 * Devices can changed from unoptimized to optimized manually, after DPC++ has
1661 * been upgraded to support the architecture and CYCLES_ONEAPI_INTEL_BINARIES_ARCH
1662 * in CMake includes the architecture. */
1663 switch (arch) {
1664 FILL_ARCH_INFO(intel_gpu_bdw, false)
1665 FILL_ARCH_INFO(intel_gpu_skl, false)
1666 FILL_ARCH_INFO(intel_gpu_kbl, false)
1667 FILL_ARCH_INFO(intel_gpu_cfl, false)
1668 FILL_ARCH_INFO(intel_gpu_apl, false)
1669 /* intel_gpu_bxt == intel_gpu_apl */
1670 FILL_ARCH_INFO(intel_gpu_glk, false)
1671 FILL_ARCH_INFO(intel_gpu_whl, false)
1672 FILL_ARCH_INFO(intel_gpu_aml, false)
1673 FILL_ARCH_INFO(intel_gpu_cml, false)
1674 FILL_ARCH_INFO(intel_gpu_icllp, false)
1675 /* intel_gpu_icl == intel_gpu_icllp */
1676 FILL_ARCH_INFO(intel_gpu_ehl, false)
1677 /* intel_gpu_jsl == intel_gpu_ehl */
1678 FILL_ARCH_INFO(intel_gpu_tgllp, false)
1679 /* intel_gpu_tgl == intel_gpu_tgllp */
1680 FILL_ARCH_INFO(intel_gpu_rkl, false)
1681 FILL_ARCH_INFO(intel_gpu_adl_s, false)
1682 /* intel_gpu_rpl_s == intel_gpu_adl_s */
1683 FILL_ARCH_INFO(intel_gpu_adl_p, false)
1684 FILL_ARCH_INFO(intel_gpu_adl_n, false)
1685 FILL_ARCH_INFO(intel_gpu_dg1, false)
1686 FILL_ARCH_INFO(intel_gpu_acm_g10, true)
1687 /* intel_gpu_dg2_g10 == intel_gpu_acm_g10 */
1688 FILL_ARCH_INFO(intel_gpu_acm_g11, true)
1689 /* intel_gpu_dg2_g11 == intel_gpu_acm_g11 */
1690 FILL_ARCH_INFO(intel_gpu_acm_g12, true)
1691 /* intel_gpu_dg2_g12 == intel_gpu_acm_g12 */
1692 FILL_ARCH_INFO(intel_gpu_pvc, false)
1693 FILL_ARCH_INFO(intel_gpu_pvc_vg, false)
1694 FILL_ARCH_INFO(intel_gpu_mtl_u, true)
1695 /* intel_gpu_mtl_s == intel_gpu_mtl_u */
1696 /* intel_gpu_arl_u == intel_gpu_mtl_u */
1697 /* intel_gpu_arl_s == intel_gpu_mtl_u */
1698 FILL_ARCH_INFO(intel_gpu_mtl_h, true)
1699 FILL_ARCH_INFO(intel_gpu_arl_h, true)
1700 FILL_ARCH_INFO(intel_gpu_bmg_g21, true)
1701 FILL_ARCH_INFO(intel_gpu_bmg_g31, true)
1702 FILL_ARCH_INFO(intel_gpu_lnl_m, true)
1703 FILL_ARCH_INFO(intel_gpu_ptl_h, true)
1704 FILL_ARCH_INFO(intel_gpu_ptl_u, true)
1705 FILL_ARCH_INFO(intel_gpu_wcl, true)
1706
1707 default:
1708 name = "unknown";
1709 is_optimized = false;
1710 break;
1711 }
1712}
1713
1714char *OneapiDevice::device_capabilities()
1715{
1716 std::stringstream capabilities;
1717
1718 const std::vector<SyclDeviceEntry> &entries = available_sycl_devices();
1719 for (const SyclDeviceEntry &entry : entries) {
1720 const sycl::device &device = entry.device;
1721
1722 const std::string &name = device.get_info<sycl::info::device::name>();
1723
1724 capabilities << std::string("\t") << name << "\n";
1725 capabilities << "\t\tsycl::info::platform::name\t\t\t"
1726 << device.get_platform().get_info<sycl::info::platform::name>() << "\n";
1727
1728 string arch_name;
1729 bool is_optimized_for_arch;
1730 architecture_information(
1731 reinterpret_cast<const SyclDevice *>(&device), arch_name, is_optimized_for_arch);
1732 capabilities << "\t\tsycl::info::device::architecture\t\t\t";
1733 capabilities << arch_name << "\n";
1734 capabilities << "\t\tsycl::info::device::is_cycles_optimized\t\t\t";
1735 capabilities << is_optimized_for_arch << "\n";
1736 capabilities << "\t\tsycl::info::device::meets_driver_requirement\t\t\t";
1737 capabilities << entry.meets_driver_requirement << "\n";
1738
1739# define WRITE_ATTR(attribute_name, attribute_variable) \
1740 capabilities << "\t\tsycl::info::device::" #attribute_name "\t\t\t" << attribute_variable \
1741 << "\n";
1742# define GET_ATTR(attribute) \
1743 { \
1744 capabilities << "\t\tsycl::info::device::" #attribute "\t\t\t" \
1745 << device.get_info<sycl::info::device ::attribute>() << "\n"; \
1746 }
1747# define GET_INTEL_ATTR(attribute) \
1748 { \
1749 if (device.has(sycl::aspect::ext_intel_##attribute)) { \
1750 capabilities << "\t\tsycl::ext::intel::info::device::" #attribute "\t\t\t" \
1751 << device.get_info<sycl::ext::intel::info::device ::attribute>() << "\n"; \
1752 } \
1753 }
1754# define GET_ASPECT(aspect_) \
1755 { \
1756 capabilities << "\t\tdevice::has(" #aspect_ ")\t\t\t" << device.has(sycl::aspect ::aspect_) \
1757 << "\n"; \
1758 }
1759
1760 GET_ATTR(vendor)
1761 GET_ATTR(driver_version)
1762 GET_ATTR(max_compute_units)
1763 GET_ATTR(max_clock_frequency)
1764 GET_ATTR(global_mem_size)
1765 GET_INTEL_ATTR(pci_address)
1766 GET_INTEL_ATTR(gpu_eu_simd_width)
1767 GET_INTEL_ATTR(gpu_eu_count)
1768 GET_INTEL_ATTR(gpu_slices)
1769 GET_INTEL_ATTR(gpu_subslices_per_slice)
1770 GET_INTEL_ATTR(gpu_eu_count_per_subslice)
1771 GET_INTEL_ATTR(gpu_hw_threads_per_eu)
1772 GET_INTEL_ATTR(max_mem_bandwidth)
1773 GET_ATTR(max_work_group_size)
1774 GET_ATTR(max_work_item_dimensions)
1775 sycl::id<3> max_work_item_sizes =
1776 device.get_info<sycl::info::device::max_work_item_sizes<3>>();
1777 WRITE_ATTR(max_work_item_sizes[0], max_work_item_sizes.get(0))
1778 WRITE_ATTR(max_work_item_sizes[1], max_work_item_sizes.get(1))
1779 WRITE_ATTR(max_work_item_sizes[2], max_work_item_sizes.get(2))
1780
1781 GET_ATTR(max_num_sub_groups)
1782 for (size_t sub_group_size : device.get_info<sycl::info::device::sub_group_sizes>()) {
1783 WRITE_ATTR(sub_group_size[], sub_group_size)
1784 }
1785 GET_ATTR(sub_group_independent_forward_progress)
1786
1787 GET_ATTR(preferred_vector_width_char)
1788 GET_ATTR(preferred_vector_width_short)
1789 GET_ATTR(preferred_vector_width_int)
1790 GET_ATTR(preferred_vector_width_long)
1791 GET_ATTR(preferred_vector_width_float)
1792 GET_ATTR(preferred_vector_width_double)
1793 GET_ATTR(preferred_vector_width_half)
1794
1795 GET_ATTR(address_bits)
1796 GET_ATTR(max_mem_alloc_size)
1797 GET_ATTR(mem_base_addr_align)
1798 GET_ATTR(error_correction_support)
1799 GET_ATTR(is_available)
1800 GET_ATTR(host_unified_memory)
1801
1802 GET_ASPECT(cpu)
1803 GET_ASPECT(gpu)
1804 GET_ASPECT(fp16)
1805 GET_ASPECT(atomic64)
1806 GET_ASPECT(usm_host_allocations)
1807 GET_ASPECT(usm_device_allocations)
1808 GET_ASPECT(usm_shared_allocations)
1809 GET_ASPECT(usm_system_allocations)
1810
1811# ifdef __SYCL_ANY_DEVICE_HAS_ext_oneapi_non_uniform_groups__
1812 GET_ASPECT(ext_oneapi_non_uniform_groups)
1813# endif
1814# ifdef __SYCL_ANY_DEVICE_HAS_ext_oneapi_bindless_images__
1815 GET_ASPECT(ext_oneapi_bindless_images)
1816# endif
1817# ifdef __SYCL_ANY_DEVICE_HAS_ext_oneapi_interop_semaphore_import__
1818 GET_ASPECT(ext_oneapi_interop_semaphore_import)
1819# endif
1820# ifdef __SYCL_ANY_DEVICE_HAS_ext_oneapi_interop_semaphore_export__
1821 GET_ASPECT(ext_oneapi_interop_semaphore_export)
1822# endif
1823
1824# undef GET_INTEL_ATTR
1825# undef GET_ASPECT
1826# undef GET_ATTR
1827# undef WRITE_ATTR
1828 capabilities << "\n";
1829 }
1830
1831 return ::strdup(capabilities.str().c_str());
1832}
1833
1834void OneapiDevice::iterate_devices(OneAPIDeviceIteratorCallback cb, void *user_ptr)
1835{
1836 int num = 0;
1837 std::vector<SyclDeviceEntry> entries = available_sycl_devices();
1838 for (const SyclDeviceEntry &entry : entries) {
1839 const sycl::device &device = entry.device;
1840
1841 const std::string &platform_name =
1842 device.get_platform().get_info<sycl::info::platform::name>();
1843 std::string name = device.get_info<sycl::info::device::name>();
1844# ifdef WITH_EMBREE_GPU
1845 bool hwrt_support = rtcIsSYCLDeviceSupported(device);
1846# else
1847 bool hwrt_support = false;
1848# endif
1849# if defined(WITH_OPENIMAGEDENOISE) && OIDN_VERSION >= 20300
1850 bool oidn_support = oidnIsSYCLDeviceSupported(&device);
1851# else
1852 bool oidn_support = false;
1853# endif
1854 std::string id = "ONEAPI_" + platform_name + "_" + name;
1855
1856 string arch_name;
1857 bool is_optimized_for_arch;
1858 architecture_information(
1859 reinterpret_cast<const SyclDevice *>(&device), arch_name, is_optimized_for_arch);
1860
1861 if (device.has(sycl::aspect::ext_intel_pci_address)) {
1862 id.append("_" + device.get_info<sycl::ext::intel::info::device::pci_address>());
1863 }
1864 (cb)(id.c_str(),
1865 name.c_str(),
1866 num,
1867 hwrt_support,
1868 oidn_support,
1869 is_optimized_for_arch,
1870 entry.meets_driver_requirement,
1871 user_ptr);
1872 num++;
1873 }
1874}
1875
1876size_t OneapiDevice::get_memcapacity()
1877{
1878 return reinterpret_cast<sycl::queue *>(device_queue_)
1879 ->get_device()
1880 .get_info<sycl::info::device::global_mem_size>();
1881}
1882
1883int OneapiDevice::get_num_multiprocessors()
1884{
1885 const sycl::device &device = reinterpret_cast<sycl::queue *>(device_queue_)->get_device();
1886 if (device.has(sycl::aspect::ext_intel_gpu_eu_count)) {
1887 return device.get_info<sycl::ext::intel::info::device::gpu_eu_count>();
1888 }
1889 return device.get_info<sycl::info::device::max_compute_units>();
1890}
1891
1892int OneapiDevice::get_max_num_threads_per_multiprocessor()
1893{
1894 const sycl::device &device = reinterpret_cast<sycl::queue *>(device_queue_)->get_device();
1895 if (device.has(sycl::aspect::ext_intel_gpu_eu_simd_width) &&
1896 device.has(sycl::aspect::ext_intel_gpu_hw_threads_per_eu))
1897 {
1898 return device.get_info<sycl::ext::intel::info::device::gpu_eu_simd_width>() *
1899 device.get_info<sycl::ext::intel::info::device::gpu_hw_threads_per_eu>();
1900 }
1901 /* We'd want sycl::info::device::max_threads_per_compute_unit which doesn't exist yet.
1902 * max_work_group_size is the closest approximation but it can still be several times off. */
1903 return device.get_info<sycl::info::device::max_work_group_size>();
1904}
1905
1907
1908#endif
volatile int lock
unsigned long long int uint64_t
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
void refit(btStridingMeshInterface *triangles, const btVector3 &aabbMin, const btVector3 &aabbMax)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
BVHLayout bvh_layout
Definition params.h:83
bool top_level
Definition params.h:80
Definition bvh/bvh.h:67
BVHParams params
Definition bvh/bvh.h:69
string description
bool use_hardware_raytracing
virtual void host_free(const MemoryType type, void *host_pointer, const size_t size)
virtual void build_bvh(BVH *bvh, Progress &progress, bool refit)
virtual void * host_alloc(const MemoryType type, const size_t size)
size_t mem_used
Definition util/stats.h:30
void mem_alloc(const size_t size)
Definition util/stats.h:18
void mem_free(const size_t size)
Definition util/stats.h:24
KernelImageInfo info
string log_name() const override
Definition memory.cpp:280
size_t memory_elements_size(const int elements)
const char * global_name() const
Definition memory.cpp:83
virtual string log_name() const
Definition memory.cpp:88
@ MEM_IMAGE_TEXTURE
@ MEM_READ_WRITE
@ MEM_READ_ONLY
@ TYPE_UINT16
#define KERNEL_DATA_ARRAY(type, name)
Definition data_arrays.h:8
#define KERNEL_FEATURE_NODE_RAYTRACE
#define KERNEL_FEATURE_MNEE
#define CCL_NAMESPACE_END
#define assert(assertion)
#define image(slot, qualifiers, format)
#define local_size(...)
#define log
@ BVH_LAYOUT_BVH2
@ BVH_LAYOUT_EMBREEGPU
DeviceKernel
@ DEVICE_KERNEL_INTEGRATOR_SHADE_DEDICATED_LIGHT
@ DEVICE_KERNEL_INTEGRATOR_SHADE_SURFACE
@ DEVICE_KERNEL_SHADER_EVAL_DISPLACE
@ DEVICE_KERNEL_INTEGRATOR_INTERSECT_MNEE
@ DEVICE_KERNEL_SHADER_EVAL_VOLUME_DENSITY
@ DEVICE_KERNEL_INTEGRATOR_INTERSECT_SUBSURFACE
@ DEVICE_KERNEL_INTEGRATOR_SHADE_SHADOW
@ DEVICE_KERNEL_INTEGRATOR_INTERSECT_VOLUME_STACK
@ DEVICE_KERNEL_SHADER_EVAL_BACKGROUND
@ DEVICE_KERNEL_INTEGRATOR_SHADE_SURFACE_RAYTRACE
@ DEVICE_KERNEL_INTEGRATOR_INTERSECT_DEDICATED_LIGHT
@ DEVICE_KERNEL_INTEGRATOR_INIT_FROM_CAMERA
@ DEVICE_KERNEL_INTEGRATOR_SHADE_LIGHT_FORWARD
@ DEVICE_KERNEL_INTEGRATOR_SHADE_VOLUME_RAY_MARCHING
@ DEVICE_KERNEL_INTEGRATOR_SHADE_LIGHT_NEE
@ DEVICE_KERNEL_CRYPTOMATTE_POSTPROCESS
@ DEVICE_KERNEL_INTEGRATOR_INIT_FROM_BAKE
@ DEVICE_KERNEL_SHADER_EVAL_CURVE_SHADOW_TRANSPARENCY
@ DEVICE_KERNEL_INTEGRATOR_SHADE_VOLUME
@ DEVICE_KERNEL_INTEGRATOR_INTERSECT_SHADOW
@ DEVICE_KERNEL_INTEGRATOR_INTERSECT_CLOSEST
@ DEVICE_KERNEL_INTEGRATOR_SHADE_BACKGROUND
#define DCHECK(expression)
Definition log.h:135
#define LOG_DEBUG
Definition log.h:107
#define LOG_ERROR
Definition log.h:101
#define LOG_WARNING
Definition log.h:103
#define LOG_INFO
Definition log.h:106
#define LOG_TRACE
Definition log.h:108
void free(struct bMotionPath *mpath)
BMesh const char void * data
ATTR_WARN_UNUSED_RESULT const size_t num
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
int BVHLayoutMask
Definition params.h:50
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
#define min(a, b)
Definition sort.cc:38
string string_human_readable_size(size_t size)
Definition string.cpp:333
string string_hex(const uint8_t *data, const size_t size)
Definition string.cpp:193
string string_human_readable_number(size_t num)
Definition string.cpp:352
bool string_startswith(const string_view s, const string_view start)
Definition string.cpp:106
CCL_NAMESPACE_BEGIN string string_printf(const char *format,...)
Definition string.cpp:25
CCL_NAMESPACE_END IntegratorStateGPU * integrator_state
std::unique_lock< std::mutex > thread_scoped_lock
Definition thread.h:28
ccl_device_inline size_t round_up(const size_t x, const size_t multiple)
Definition types_base.h:66
uint64_t device_ptr
Definition types_base.h:44
@ INTERPOLATION_CLOSEST
Definition types_image.h:27
@ EXTENSION_REPEAT
Definition types_image.h:82
@ EXTENSION_CLIP
Definition types_image.h:86
@ EXTENSION_EXTEND
Definition types_image.h:84
@ EXTENSION_MIRROR
Definition types_image.h:88
ccl_device_inline bool is_nanovdb_type(int type)
Definition types_image.h:54