Blender V5.3
oneapi/device_impl.h
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# include "device/device.h"
8# include "device/oneapi/queue.h"
10
11# include "util/map.h"
12# include "util/unique_ptr.h"
13
15
16class DeviceQueue;
17
18using OneAPIDeviceIteratorCallback =
19 void (*)(const char *, const char *, const int, bool, bool, bool, bool, void *);
20
21class OneapiDevice : public GPUDevice {
22 private:
23 SyclQueue *device_queue_ = nullptr;
24# ifdef WITH_EMBREE_GPU
25 RTCDevice embree_device = nullptr;
26# if RTC_VERSION >= 40400
27 RTCTraversable embree_traversable = nullptr;
28# else
29 RTCScene embree_traversable = nullptr;
30# endif
31# if RTC_VERSION >= 40302
32 thread_mutex scene_data_mutex;
33 vector<RTCScene> all_embree_scenes;
34# endif
35# endif
36 using ConstMemMap = map<string, unique_ptr<device_vector<uchar>>>;
37 ConstMemMap const_mem_map_;
38 void *kg_memory_ = nullptr;
39 void *kg_memory_device_ = nullptr;
40 size_t kg_memory_size_ = 0;
41 size_t max_memory_on_device_ = 0;
42 std::string oneapi_error_string_;
43 bool use_hardware_raytracing = false;
44 uint64_t kernel_features = 0;
45 int scene_max_shaders_ = 0;
46 /* On some driver versions, usage of Intel oneAPI extension for host->GPU copy optimization
47 * is causing crashes and failures. As a result, to ensure functionality, we disable
48 * this extension as a workaround. This class member variable is controlling this behavior
49 * and is set appropriately during device enumeration, based on the presented devices
50 * and their driver version (at the moment not checked, no public driver with a fix exists yet).
51 */
52 bool use_intel_copy_optimization = true;
53
54 size_t get_free_mem() const;
55
56 public:
57 BVHLayoutMask get_bvh_layout_mask(const uint64_t requested_features) const override;
58
59 OneapiDevice(const DeviceInfo &info, Stats &stats, Profiler &profiler, bool headless);
60
61 ~OneapiDevice() override;
62# ifdef WITH_EMBREE_GPU
63 void build_bvh(BVH *bvh, Progress &progress, bool refit) override;
64# endif
65 bool check_peer_access(Device *peer_device) override;
66
67 bool load_kernels(uint64_t requested_features) override;
68
69 void reserve_private_memory(uint64_t kernel_features);
70
71 string oneapi_error_message();
72
73 int scene_max_shaders();
74
75 void *kernel_globals_device_pointer();
76
77 /* All memory types. */
78 void mem_alloc(device_memory &mem) override;
79 void mem_copy_to(device_memory &mem) override;
80 void mem_move_to_host(device_memory &mem) override;
81 void mem_copy_from(device_memory &mem,
82 const size_t y,
83 size_t w,
84 const size_t h,
85 size_t elem,
86 void *host_pointer);
87 void mem_copy_from(
88 device_memory &mem, const size_t y, size_t w, const size_t h, size_t elem) override;
89 void mem_copy_from(device_memory &mem);
90 void mem_zero(device_memory &mem) override;
91 void mem_free(device_memory &mem) override;
92
93 device_ptr mem_alloc_sub_ptr(device_memory &mem, const size_t offset, size_t /*size*/) override;
94
95 /* Global memory. */
96 void global_alloc(device_memory &mem);
97 void global_copy_to(device_memory &mem);
98 void global_free(device_memory &mem);
99
100 /* Image memory. */
101 void image_alloc(device_image &mem);
102 void image_copy_to(device_image &mem);
103 void image_free(device_image &mem);
104
105 /* Host side memory, override for more efficient copies. */
106 void *host_alloc(const MemoryType type, const size_t size) override;
107 void host_free(const MemoryType type, void *host_pointer, const size_t size) override;
108
109 /* Device side memory. */
110 void get_device_memory_info(size_t &total, size_t &free) override;
111 bool alloc_device(void *&device_pointer, const size_t size) override;
112 void free_device(void *device_pointer) override;
113
114 /* Shared memory. */
115 bool shared_alloc(void *&shared_pointer, const size_t size) override;
116 void shared_free(void *shared_pointer, const size_t size) override;
117 void *shared_to_device_pointer(const void *shared_pointer) override;
118
119 /* Memory copy. */
120 void copy_host_to_device(void *device_pointer, void *host_pointer, const size_t size) override;
121 void const_copy_to(const char *name, void *host, const size_t size) override;
122
123 /* Graphics resources interoperability. */
124 bool should_use_graphics_interop(const GraphicsInteropDevice &interop_device,
125 const bool log) override;
126
127 unique_ptr<DeviceQueue> gpu_queue_create() override;
128
129 /* NOTE(@nsirgien): Create this methods to avoid some compilation problems on Windows with host
130 * side compilation (MSVC). */
131 void *usm_aligned_alloc_host(const size_t memory_size, const size_t alignment);
132 void usm_free(void *usm_ptr);
133
134 static void architecture_information(const SyclDevice *device, string &name, bool &is_optimized);
135 static char *device_capabilities();
136 static void iterate_devices(OneAPIDeviceIteratorCallback cb, void *user_ptr);
137
138 size_t get_memcapacity();
139 int get_num_multiprocessors();
140 int get_max_num_threads_per_multiprocessor();
141 bool queue_synchronize(SyclQueue *queue);
142 bool kernel_globals_size(size_t &kernel_global_size);
143 void set_global_memory(SyclQueue *queue,
144 void *kernel_globals,
145 const char *memory_name,
146 void *memory_device_pointer);
147 bool enqueue_kernel(KernelContext *kernel_context,
148 const int kernel,
149 const size_t global_size,
150 const size_t local_size,
151 void **args);
152 void get_adjusted_global_and_local_sizes(SyclQueue *queue,
153 const DeviceKernel kernel,
154 size_t &kernel_global_size,
155 size_t &kernel_local_size);
156 SyclQueue *sycl_queue();
157
158 protected:
159 bool can_use_hardware_raytracing_for_features(uint64_t requested_features) const;
160 void check_usm(SyclQueue *queue, const void *usm_ptr, bool allow_host);
161 bool create_queue(SyclQueue *&external_queue,
162 const int device_index,
163 void *embree_device,
164 bool *multiple_level_zero_platforms_detected_pointer);
165 void free_queue(SyclQueue *queue);
166 void *usm_aligned_alloc_host(SyclQueue *queue, const size_t memory_size, const size_t alignment);
167 void *usm_alloc_device(SyclQueue *queue, const size_t memory_size);
168 void usm_free(SyclQueue *queue, void *usm_ptr);
169 bool usm_memcpy(SyclQueue *queue, void *dest, void *src, const size_t num_bytes);
170 bool usm_memset(SyclQueue *queue, void *usm_ptr, unsigned char value, const size_t num_bytes);
171};
172
174
175#endif
unsigned long long int uint64_t
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
#define CCL_NAMESPACE_END
#define local_size(...)
#define log
#define RTCTraversable
DeviceKernel
ccl_device bool BVH_FUNCTION_FULL_NAME BVH(KernelGlobals kg, const ccl_private Ray *ray, ccl_private LocalIntersection *local_isect, const int local_object, ccl_private uint *lcg_state, const int max_hits)
Definition local.h:27
int BVHLayoutMask
Definition params.h:50
std::mutex thread_mutex
Definition thread.h:27
uint64_t device_ptr
Definition types_base.h:44