32 return opencl_create_split_device(info, stats, profiler, background);
38 static bool result =
false;
45 if (OpenCLInfo::device_type() != 0) {
46 int clew_result = clewInit();
47 if (clew_result == CLEW_SUCCESS) {
48 VLOG(1) <<
"CLEW initialization succeeded.";
52 VLOG(1) <<
"CLEW initialization failed: "
53 << ((clew_result == CLEW_ERROR_ATEXIT_FAILED) ?
"Error setting up atexit() handler" :
54 "Error opening the library");
58 VLOG(1) <<
"Skip initializing CLEW, platform is force disabled.";
65 static cl_int device_opencl_get_num_platforms_safe(cl_uint *num_platforms)
69 return clGetPlatformIDs(0,
NULL, num_platforms);
71 __except (EXCEPTION_EXECUTE_HANDLER) {
74 fprintf(stderr,
"Cycles OpenCL: driver crashed, continuing without OpenCL.\n");
78 return CL_DEVICE_NOT_FOUND;
80 return clGetPlatformIDs(0,
NULL, num_platforms);
86 cl_uint num_platforms = 0;
87 device_opencl_get_num_platforms_safe(&num_platforms);
88 if (num_platforms == 0) {
93 OpenCLInfo::get_usable_devices(&usable_devices);
96 set<string> unique_ids;
97 foreach (OpenCLPlatformDevice &platform_device, usable_devices) {
99 const string &platform_name = platform_device.platform_name;
100 const string &device_name = platform_device.device_name;
101 string hardware_id = platform_device.hardware_id;
102 if (hardware_id ==
"") {
105 string id = string(
"OPENCL_") + platform_name +
"_" + device_name +
"_" + hardware_id;
108 if (unique_ids.find(
id) != unique_ids.end()) {
111 unique_ids.insert(
id);
117 info.
num = num_devices;
127 info.
has_half_images = platform_device.device_extensions.find(
"cl_khr_fp16") != string::npos;
130 info.
has_nanovdb = platform_name !=
"AMD Accelerated Parallel Processing";
139 if (OpenCLInfo::device_type() == 0) {
140 return "All OpenCL devices are forced to be OFF";
143 string error_msg =
"";
146 cl_uint num_platforms = 0;
147 opencl_assert(device_opencl_get_num_platforms_safe(&num_platforms));
148 if (num_platforms == 0) {
149 return "No OpenCL platforms found\n";
154 platform_ids.resize(num_platforms);
155 opencl_assert(clGetPlatformIDs(num_platforms, &platform_ids[0],
NULL));
157 # define APPEND_INFO(func, id, name, what, type) \
160 memset(&data, 0, sizeof(data)); \
161 opencl_assert(func(id, what, sizeof(data), &data, NULL)); \
162 result += string_printf("%s: %s\n", name, to_string(data).c_str()); \
164 # define APPEND_STRING_INFO_IMPL(func, id, name, what, is_optional) \
168 if (func(id, what, 0, NULL, &length) == CL_SUCCESS) { \
169 vector<char> buffer(length + 1); \
170 if (func(id, what, buffer.size(), buffer.data(), NULL) == CL_SUCCESS) { \
171 value = string(buffer.data()); \
174 if (is_optional && !(length != 0 && value[0] != '\0')) { \
177 result += string_printf("%s: %s\n", name, value.c_str()); \
179 # define APPEND_PLATFORM_STRING_INFO(id, name, what) \
180 APPEND_STRING_INFO_IMPL(clGetPlatformInfo, id, "\tPlatform " name, what, false)
181 # define APPEND_STRING_EXTENSION_INFO(func, id, name, what) \
182 APPEND_STRING_INFO_IMPL(clGetPlatformInfo, id, "\tPlatform " name, what, true)
183 # define APPEND_PLATFORM_INFO(id, name, what, type) \
184 APPEND_INFO(clGetPlatformInfo, id, "\tPlatform " name, what, type)
185 # define APPEND_DEVICE_INFO(id, name, what, type) \
186 APPEND_INFO(clGetDeviceInfo, id, "\t\t\tDevice " name, what, type)
187 # define APPEND_DEVICE_STRING_INFO(id, name, what) \
188 APPEND_STRING_INFO_IMPL(clGetDeviceInfo, id, "\t\t\tDevice " name, what, false)
189 # define APPEND_DEVICE_STRING_EXTENSION_INFO(id, name, what) \
190 APPEND_STRING_INFO_IMPL(clGetDeviceInfo, id, "\t\t\tDevice " name, what, true)
193 for (cl_uint platform = 0; platform < num_platforms; ++platform) {
194 cl_platform_id platform_id = platform_ids[platform];
198 APPEND_PLATFORM_STRING_INFO(platform_id,
"Name", CL_PLATFORM_NAME);
199 APPEND_PLATFORM_STRING_INFO(platform_id,
"Vendor", CL_PLATFORM_VENDOR);
200 APPEND_PLATFORM_STRING_INFO(platform_id,
"Version", CL_PLATFORM_VERSION);
201 APPEND_PLATFORM_STRING_INFO(platform_id,
"Profile", CL_PLATFORM_PROFILE);
202 APPEND_PLATFORM_STRING_INFO(platform_id,
"Extensions", CL_PLATFORM_EXTENSIONS);
204 cl_uint num_devices = 0;
206 clGetDeviceIDs(platform_ids[platform], CL_DEVICE_TYPE_ALL, 0,
NULL, &num_devices));
209 device_ids.resize(num_devices);
210 opencl_assert(clGetDeviceIDs(
211 platform_ids[platform], CL_DEVICE_TYPE_ALL, num_devices, &device_ids[0],
NULL));
212 for (cl_uint device = 0; device < num_devices; ++device) {
213 cl_device_id device_id = device_ids[device];
217 APPEND_DEVICE_STRING_INFO(device_id,
"Name", CL_DEVICE_NAME);
218 APPEND_DEVICE_STRING_EXTENSION_INFO(device_id,
"Board Name", CL_DEVICE_BOARD_NAME_AMD);
219 APPEND_DEVICE_STRING_INFO(device_id,
"Vendor", CL_DEVICE_VENDOR);
220 APPEND_DEVICE_STRING_INFO(device_id,
"OpenCL C Version", CL_DEVICE_OPENCL_C_VERSION);
221 APPEND_DEVICE_STRING_INFO(device_id,
"Profile", CL_DEVICE_PROFILE);
222 APPEND_DEVICE_STRING_INFO(device_id,
"Version", CL_DEVICE_VERSION);
223 APPEND_DEVICE_STRING_INFO(device_id,
"Extensions", CL_DEVICE_EXTENSIONS);
225 device_id,
"Max clock frequency (MHz)", CL_DEVICE_MAX_CLOCK_FREQUENCY, cl_uint);
226 APPEND_DEVICE_INFO(device_id,
"Max compute units", CL_DEVICE_MAX_COMPUTE_UNITS, cl_uint);
227 APPEND_DEVICE_INFO(device_id,
"Max work group size", CL_DEVICE_MAX_WORK_GROUP_SIZE,
size_t);
232 # undef APPEND_STRING_INFO_IMPL
233 # undef APPEND_PLATFORM_STRING_INFO
234 # undef APPEND_STRING_EXTENSION_INFO
235 # undef APPEND_PLATFORM_INFO
236 # undef APPEND_DEVICE_INFO
237 # undef APPEND_DEVICE_STRING_INFO
238 # undef APPEND_DEVICE_STRING_EXTENSION_INFO
DenoiserTypeMask denoisers
bool has_adaptive_stop_per_sample
bool has_volume_decoupled
bool device_opencl_init()
void device_opencl_info(vector< DeviceInfo > &devices)
Device * device_opencl_create(DeviceInfo &info, Stats &stats, Profiler &profiler, bool background)
string device_opencl_capabilities()
#define CCL_NAMESPACE_END
Vector< CPUDevice > devices
list of all CPUDevices. for every hardware thread an instance of CPUDevice is created
string string_remove_trademark(const string &s)
CCL_NAMESPACE_BEGIN string string_printf(const char *format,...)