Blender V5.3
device/oneapi/device.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021-2022 Intel Corporation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
6#include "device/device.h"
7
8#include "util/log.h"
9
10#ifdef WITH_ONEAPI
12# include "integrator/denoiser_oidn_gpu.h" // IWYU pragma: keep
13
14# include "util/string.h"
15
16# ifdef __linux__
17# include <dlfcn.h>
18# endif
19#endif /* WITH_ONEAPI */
20
22
24{
25#if !defined(WITH_ONEAPI)
26 return false;
27#else
28
29 /* NOTE(@nsirgien): we need to enable JIT cache from here and
30 * right now this cache policy is controlled by env. variables. */
31 /* NOTE(@xavierh-intel) we enable the use of copy engine, incl. for fill
32 * operations as it lowers the overhead from zeCommandListAppendMemoryFill
33 * when running paths_array kernels on Linux+A750.
34 * All these env variable can be set beforehand by end-users and
35 * will in that case -not- be overwritten. */
36 /* By default, enable only Level-Zero and if all devices are allowed, also CUDA and HIP.
37 * OpenCL backend isn't currently well supported. */
38# ifdef _WIN32
39 if (getenv("SYCL_CACHE_PERSISTENT") == nullptr) {
40 _putenv_s("SYCL_CACHE_PERSISTENT", "1");
41 }
42 if (getenv("SYCL_CACHE_THRESHOLD") == nullptr) {
43 _putenv_s("SYCL_CACHE_THRESHOLD", "0");
44 }
45 if (getenv("ONEAPI_DEVICE_SELECTOR") == nullptr) {
46 if (getenv("CYCLES_ONEAPI_ALL_DEVICES") == nullptr) {
47 _putenv_s("ONEAPI_DEVICE_SELECTOR", "level_zero:*");
48 }
49 else {
50 _putenv_s("ONEAPI_DEVICE_SELECTOR", "!opencl:*");
51 }
52 }
53 /* SYSMAN is needed for free_memory queries. */
54 if (getenv("ZES_ENABLE_SYSMAN") == nullptr) {
55 _putenv_s("ZES_ENABLE_SYSMAN", "1");
56 }
57 if (getenv("UR_L0_USE_COPY_ENGINE") == nullptr) {
58 _putenv_s("UR_L0_USE_COPY_ENGINE", "1");
59 }
60 if (getenv("UR_L0_USE_COPY_ENGINE_FOR_FILL") == nullptr) {
61 _putenv_s("UR_L0_USE_COPY_ENGINE_FOR_FILL", "1");
62 }
63 /* As a fix for #163040, the v1 Level Zero adapter is not included. */
64 if (getenv("SYCL_UR_USE_LEVEL_ZERO_V2") == nullptr) {
65 _putenv_s("SYCL_UR_USE_LEVEL_ZERO_V2", "1");
66 }
67# elif __linux__
68 setenv("SYCL_CACHE_PERSISTENT", "1", false);
69 setenv("SYCL_CACHE_THRESHOLD", "0", false);
70 if (getenv("CYCLES_ONEAPI_ALL_DEVICES") == nullptr) {
71 setenv("ONEAPI_DEVICE_SELECTOR", "level_zero:*", false);
72 }
73 else {
74 setenv("ONEAPI_DEVICE_SELECTOR", "!opencl:*", false);
75 }
76 /* SYSMAN is needed for free_memory queries. */
77 setenv("ZES_ENABLE_SYSMAN", "1", false);
78 setenv("UR_L0_USE_COPY_ENGINE", "1", false);
79 setenv("UR_L0_USE_COPY_ENGINE_FOR_FILL", "1", false);
80 /* As a fix for #159584, the v1 Level Zero adapter is not included. */
81 setenv("SYCL_UR_USE_LEVEL_ZERO_V2", "1", false);
82# endif
83
84 return true;
85#endif
86}
87
89 Stats &stats,
90 Profiler &profiler,
91 bool headless)
92{
93#ifdef WITH_ONEAPI
94 return make_unique<OneapiDevice>(info, stats, profiler, headless);
95#else
96 (void)info;
97 (void)stats;
98 (void)profiler;
99 (void)headless;
100
101 LOG_FATAL << "Requested to create oneAPI device while not enabled for this build.";
102
103 return nullptr;
104#endif
105}
106
107#ifdef WITH_ONEAPI
108static void device_iterator_cb(const char *id,
109 const char *name,
110 const int num,
111 bool hwrt_support,
112 bool oidn_support,
113 bool has_execution_optimization,
114 bool meets_driver_requirement,
115 void *user_ptr)
116{
117 vector<DeviceInfo> *devices = (vector<DeviceInfo> *)user_ptr;
118
119 DeviceInfo info;
120
121 info.type = DEVICE_ONEAPI;
122 info.description = name;
123 info.num = num;
124
125 /* NOTE(@nsirgien): Should be unique at least on proper oneapi installation. */
126 info.id = id;
127
128 info.has_nanovdb = true;
129# if defined(WITH_OPENIMAGEDENOISE)
130# if OIDN_VERSION >= 20300
131 if (oidn_support) {
132# else
133 if (OIDNDenoiserGPU::is_device_supported(info)) {
134# endif
136 }
137# endif
138 (void)oidn_support;
139
140 info.has_gpu_queue = true;
141
142 /* NOTE(@nsirgien): oneAPI right now is focused on one device usage. In future it maybe will
143 * change, but right now peer access from one device to another device is not supported. */
144 info.has_peer_memory = false;
145
146 /* NOTE(@nsirgien): Seems not possible to know from SYCL/oneAPI or Level0. */
147 info.display_device = false;
148
149# ifdef WITH_EMBREE_GPU
150 info.use_hardware_raytracing = hwrt_support;
151# else
152 info.use_hardware_raytracing = false;
153 (void)hwrt_support;
154# endif
155
156 info.has_execution_optimization = has_execution_optimization;
157 info.meets_driver_requirement = meets_driver_requirement;
158
159 devices->push_back(info);
160 LOG_INFO << "Added device \"" << info.description << "\" with id \"" << info.id << "\".";
161
163 LOG_INFO << "Device with id \"" << info.id << "\" supports "
165 }
166}
167#endif
168
170{
171#ifdef WITH_ONEAPI
172 OneapiDevice::iterate_devices(device_iterator_cb, &devices);
173#else /* WITH_ONEAPI */
174 (void)devices;
175#endif /* WITH_ONEAPI */
176}
177
179{
180 string capabilities;
181#ifdef WITH_ONEAPI
182 char *c_capabilities = OneapiDevice::device_capabilities();
183 if (c_capabilities) {
184 capabilities = c_capabilities;
185 free(c_capabilities);
186 }
187#endif
188 return capabilities;
189}
190
bool has_execution_optimization
bool meets_driver_requirement
DenoiserTypeMask denoisers
bool display_device
bool has_peer_memory
bool has_gpu_queue
DeviceType type
string description
bool use_hardware_raytracing
CCL_NAMESPACE_BEGIN const char * denoiserTypeToHumanReadable(DenoiserType type)
Definition denoise.cpp:9
@ DENOISER_OPENIMAGEDENOISE
Definition denoise.h:13
#define CCL_NAMESPACE_END
@ DEVICE_ONEAPI
unique_ptr< Device > device_oneapi_create(const DeviceInfo &info, Stats &stats, Profiler &profiler, bool headless)
void device_oneapi_info(vector< DeviceInfo > &devices)
CCL_NAMESPACE_BEGIN bool device_oneapi_init()
string device_oneapi_capabilities()
#define LOG_FATAL
Definition log.h:99
#define LOG_INFO
Definition log.h:106
ATTR_WARN_UNUSED_RESULT const size_t num