Blender V5.0
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(hallade) we also disable use of copy engine as it
32 * improves stability as of intel/LLVM SYCL-nightly/20220529.
33 * All these env variable can be set beforehand by end-users and
34 * will in that case -not- be overwritten. */
35 /* By default, enable only Level-Zero and if all devices are allowed, also CUDA and HIP.
36 * OpenCL backend isn't currently well supported. */
37# ifdef _WIN32
38 if (getenv("SYCL_CACHE_PERSISTENT") == nullptr) {
39 _putenv_s("SYCL_CACHE_PERSISTENT", "1");
40 }
41 if (getenv("SYCL_CACHE_TRESHOLD") == nullptr) {
42 _putenv_s("SYCL_CACHE_THRESHOLD", "0");
43 }
44 if (getenv("ONEAPI_DEVICE_SELECTOR") == nullptr) {
45 if (getenv("CYCLES_ONEAPI_ALL_DEVICES") == nullptr) {
46 _putenv_s("ONEAPI_DEVICE_SELECTOR", "level_zero:*");
47 }
48 else {
49 _putenv_s("ONEAPI_DEVICE_SELECTOR", "!opencl:*");
50 }
51 }
52 /* SYSMAN is needed for free_memory queries. */
53 if (getenv("ZES_ENABLE_SYSMAN") == nullptr) {
54 _putenv_s("ZES_ENABLE_SYSMAN", "1");
55 }
56 if (getenv("SYCL_PI_LEVEL_ZERO_USE_COPY_ENGINE") == nullptr) {
57 _putenv_s("SYCL_PI_LEVEL_ZERO_USE_COPY_ENGINE", "0");
58 }
59# elif __linux__
60 setenv("SYCL_CACHE_PERSISTENT", "1", false);
61 setenv("SYCL_CACHE_THRESHOLD", "0", false);
62 if (getenv("CYCLES_ONEAPI_ALL_DEVICES") == nullptr) {
63 setenv("ONEAPI_DEVICE_SELECTOR", "level_zero:*", false);
64 }
65 else {
66 setenv("ONEAPI_DEVICE_SELECTOR", "!opencl:*", false);
67 }
68 /* SYSMAN is needed for free_memory queries. */
69 setenv("ZES_ENABLE_SYSMAN", "1", false);
70 setenv("SYCL_PI_LEVEL_ZERO_USE_COPY_ENGINE", "0", false);
71# endif
72
73 return true;
74#endif
75}
76
78 Stats &stats,
79 Profiler &profiler,
80 bool headless)
81{
82#ifdef WITH_ONEAPI
83 return make_unique<OneapiDevice>(info, stats, profiler, headless);
84#else
85 (void)info;
86 (void)stats;
87 (void)profiler;
88 (void)headless;
89
90 LOG_FATAL << "Requested to create oneAPI device while not enabled for this build.";
91
92 return nullptr;
93#endif
94}
95
96#ifdef WITH_ONEAPI
97static void device_iterator_cb(const char *id,
98 const char *name,
99 const int num,
100 bool hwrt_support,
101 bool oidn_support,
102 bool has_execution_optimization,
103 void *user_ptr)
104{
105 vector<DeviceInfo> *devices = (vector<DeviceInfo> *)user_ptr;
106
107 DeviceInfo info;
108
109 info.type = DEVICE_ONEAPI;
110 info.description = name;
111 info.num = num;
112
113 /* NOTE(@nsirgien): Should be unique at least on proper oneapi installation. */
114 info.id = id;
115
116 info.has_nanovdb = true;
117# if defined(WITH_OPENIMAGEDENOISE)
118# if OIDN_VERSION >= 20300
119 if (oidn_support) {
120# else
121 if (OIDNDenoiserGPU::is_device_supported(info)) {
122# endif
124 }
125# endif
126 (void)oidn_support;
127
128 info.has_gpu_queue = true;
129
130 /* NOTE(@nsirgien): oneAPI right now is focused on one device usage. In future it maybe will
131 * change, but right now peer access from one device to another device is not supported. */
132 info.has_peer_memory = false;
133
134 /* NOTE(@nsirgien): Seems not possible to know from SYCL/oneAPI or Level0. */
135 info.display_device = false;
136
137# ifdef WITH_EMBREE_GPU
138 info.use_hardware_raytracing = hwrt_support;
139# else
140 info.use_hardware_raytracing = false;
141 (void)hwrt_support;
142# endif
143
144 info.has_execution_optimization = has_execution_optimization;
145
146 devices->push_back(info);
147 LOG_INFO << "Added device \"" << info.description << "\" with id \"" << info.id << "\".";
148
150 LOG_INFO << "Device with id \"" << info.id << "\" supports "
152 }
153}
154#endif
155
157{
158#ifdef WITH_ONEAPI
159 OneapiDevice::iterate_devices(device_iterator_cb, &devices);
160#else /* WITH_ONEAPI */
161 (void)devices;
162#endif /* WITH_ONEAPI */
163}
164
166{
167 string capabilities;
168#ifdef WITH_ONEAPI
169 char *c_capabilities = OneapiDevice::device_capabilities();
170 if (c_capabilities) {
171 capabilities = c_capabilities;
172 free(c_capabilities);
173 }
174#endif
175 return capabilities;
176}
177
void BLI_kdtree_nd_ free(KDTree *tree)
ATTR_WARN_UNUSED_RESULT const size_t num
bool has_execution_optimization
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
const char * name