Blender V4.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
7#include "util/log.h"
8
9#ifdef WITH_ONEAPI
10# include "device/device.h"
13
14# include "util/path.h"
15# include "util/string.h"
16
17# ifdef __linux__
18# include <dlfcn.h>
19# endif
20#endif /* WITH_ONEAPI */
21
23
25{
26#if !defined(WITH_ONEAPI)
27 return false;
28#else
29
30 /* NOTE(@nsirgien): we need to enable JIT cache from here and
31 * right now this cache policy is controlled by env. variables. */
32 /* NOTE(hallade) we also disable use of copy engine as it
33 * improves stability as of intel/LLVM SYCL-nightly/20220529.
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_TRESHOLD") == 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("SYCL_PI_LEVEL_ZERO_USE_COPY_ENGINE") == nullptr) {
58 _putenv_s("SYCL_PI_LEVEL_ZERO_USE_COPY_ENGINE", "0");
59 }
60# elif __linux__
61 setenv("SYCL_CACHE_PERSISTENT", "1", false);
62 setenv("SYCL_CACHE_THRESHOLD", "0", false);
63 if (getenv("CYCLES_ONEAPI_ALL_DEVICES") == nullptr) {
64 setenv("ONEAPI_DEVICE_SELECTOR", "level_zero:*", false);
65 }
66 else {
67 setenv("ONEAPI_DEVICE_SELECTOR", "!opencl:*", false);
68 }
69 /* SYSMAN is needed for free_memory queries. However, it leads to runtime driver issues on Linux
70 * when using it with JEMALLOC, so we set it to 0 by default until it's fixed. */
71 setenv("ZES_ENABLE_SYSMAN", "0", false);
72 setenv("SYCL_PI_LEVEL_ZERO_USE_COPY_ENGINE", "0", false);
73# endif
74
75 return true;
76#endif
77}
78
80 Stats &stats,
81 Profiler &profiler,
82 bool headless)
83{
84#ifdef WITH_ONEAPI
85 return new OneapiDevice(info, stats, profiler, headless);
86#else
87 (void)info;
88 (void)stats;
89 (void)profiler;
90
91 LOG(FATAL) << "Requested to create oneAPI device while not enabled for this build.";
92
93 return nullptr;
94#endif
95}
96
97#ifdef WITH_ONEAPI
98static void device_iterator_cb(const char *id,
99 const char *name,
100 int num,
101 bool hwrt_support,
102 bool oidn_support,
103 void *user_ptr)
104{
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 devices->push_back(info);
145 VLOG_INFO << "Added device \"" << info.description << "\" with id \"" << info.id << "\".";
146
148 VLOG_INFO << "Device with id \"" << info.id << "\" supports "
150}
151#endif
152
154{
155#ifdef WITH_ONEAPI
156 OneapiDevice::iterate_devices(device_iterator_cb, &devices);
157#else /* WITH_ONEAPI */
158 (void)devices;
159#endif /* WITH_ONEAPI */
160}
161
163{
164 string capabilities;
165#ifdef WITH_ONEAPI
166 char *c_capabilities = OneapiDevice::device_capabilities();
167 if (c_capabilities) {
168 capabilities = c_capabilities;
169 free(c_capabilities);
170 }
171#endif
172 return capabilities;
173}
174
void BLI_kdtree_nd_ free(KDTree *tree)
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:15
#define CCL_NAMESPACE_END
@ DEVICE_ONEAPI
void device_oneapi_info(vector< DeviceInfo > &devices)
CCL_NAMESPACE_BEGIN bool device_oneapi_init()
Device * device_oneapi_create(const DeviceInfo &info, Stats &stats, Profiler &profiler, bool headless)
string device_oneapi_capabilities()
#define VLOG_INFO
Definition log.h:72
#define LOG(severity)
Definition log.h:33
Vector< CPUDevice > devices
list of all CPUDevices. for every hardware thread an instance of CPUDevice is created