forked from plaidml/plaidml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevice_set.cc
400 lines (375 loc) · 18.1 KB
/
device_set.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
// Copyright 2017-2018 Intel Corporation.
#include "tile/hal/opencl/device_set.h"
#include <string>
#include <utility>
#include <boost/regex.hpp>
#include "base/util/compat.h"
#include "base/util/error.h"
#include "tile/hal/opencl/info.h"
namespace vertexai {
namespace tile {
namespace hal {
namespace opencl {
namespace {
void OnErr(const char* errinfo, const void* priv_info, size_t cb, void* user_data) {
std::string err{errinfo};
IVLOG(1, "OpenCL: " << err << " (cb=" << cb << ")");
}
proto::PlatformInfo GetPlatformInfo(cl_platform_id pid) {
proto::PlatformInfo info;
info.set_profile(CLInfo<CL_PLATFORM_PROFILE>(pid));
info.set_version(CLInfo<CL_PLATFORM_VERSION>(pid));
info.set_name("OpenCL: " + CLInfo<CL_PLATFORM_NAME>(pid));
info.set_vendor(CLInfo<CL_PLATFORM_VENDOR>(pid));
ForEachElt(CLInfo<CL_PLATFORM_EXTENSIONS>(pid), [&info](std::string ext) { info.add_extension(ext); });
#ifndef __APPLE__
info.set_host_timer_resolution_ns(CLInfo<CL_PLATFORM_HOST_TIMER_RESOLUTION>(pid));
#endif
return info;
}
proto::DeviceInfo GetDeviceInfo(cl_device_id did, std::uint32_t pidx, const proto::PlatformInfo& pinfo) {
proto::DeviceInfo info;
switch (CLInfo<CL_DEVICE_TYPE>(did)) {
case CL_DEVICE_TYPE_CPU:
info.set_type(hal::proto::HardwareType::CPU);
break;
case CL_DEVICE_TYPE_GPU:
info.set_type(hal::proto::HardwareType::GPU);
break;
case CL_DEVICE_TYPE_ACCELERATOR:
info.set_type(hal::proto::HardwareType::Accelerator);
break;
case CL_DEVICE_TYPE_CUSTOM:
info.set_type(hal::proto::HardwareType::Custom);
break;
}
info.set_vendor_id(CLInfo<CL_DEVICE_VENDOR_ID>(did));
info.set_max_compute_units(CLInfo<CL_DEVICE_MAX_COMPUTE_UNITS>(did));
std::vector<size_t> sizes(CLInfo<CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS>(did));
Err::Check(ocl::GetDeviceInfo(did, CL_DEVICE_MAX_WORK_ITEM_SIZES, sizeof(size_t) * sizes.size(),
reinterpret_cast<char*>(sizes.data()), nullptr),
"reading OpenCL device info");
for (size_t size : sizes) {
info.add_work_item_dimension_size(size);
}
info.set_max_work_group_size(CLInfo<CL_DEVICE_MAX_WORK_GROUP_SIZE>(did));
info.set_preferred_vector_width_char(CLInfo<CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR>(did));
info.set_preferred_vector_width_short(CLInfo<CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT>(did));
info.set_preferred_vector_width_int(CLInfo<CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT>(did));
info.set_preferred_vector_width_long(CLInfo<CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG>(did));
info.set_preferred_vector_width_float(CLInfo<CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT>(did));
info.set_preferred_vector_width_double(CLInfo<CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE>(did));
info.set_preferred_vector_width_half(CLInfo<CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF>(did));
info.set_native_vector_width_char(CLInfo<CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR>(did));
info.set_native_vector_width_short(CLInfo<CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT>(did));
info.set_native_vector_width_int(CLInfo<CL_DEVICE_NATIVE_VECTOR_WIDTH_INT>(did));
info.set_native_vector_width_long(CLInfo<CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG>(did));
info.set_native_vector_width_float(CLInfo<CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT>(did));
info.set_native_vector_width_double(CLInfo<CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE>(did));
info.set_native_vector_width_half(CLInfo<CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF>(did));
info.set_max_clock_frequency_mhz(CLInfo<CL_DEVICE_MAX_CLOCK_FREQUENCY>(did));
info.set_address_bits(CLInfo<CL_DEVICE_ADDRESS_BITS>(did));
info.set_max_mem_alloc_size(CLInfo<CL_DEVICE_MAX_MEM_ALLOC_SIZE>(did));
info.set_image_support(CLInfo<CL_DEVICE_IMAGE_SUPPORT>(did));
#ifndef __APPLE__
info.set_max_read_image_args(CLInfo<CL_DEVICE_MAX_READ_IMAGE_ARGS>(did));
info.set_max_write_image_args(CLInfo<CL_DEVICE_MAX_WRITE_IMAGE_ARGS>(did));
info.set_max_read_write_image_args(CLInfo<CL_DEVICE_MAX_READ_WRITE_IMAGE_ARGS>(did));
ForEachElt(CLInfo<CL_DEVICE_IL_VERSION>(did), [&info](std::string il) { info.add_il_version(il); });
#endif
info.set_image2d_max_width(CLInfo<CL_DEVICE_IMAGE2D_MAX_WIDTH>(did));
info.set_image2d_max_height(CLInfo<CL_DEVICE_IMAGE2D_MAX_HEIGHT>(did));
info.set_image3d_max_width(CLInfo<CL_DEVICE_IMAGE3D_MAX_WIDTH>(did));
info.set_image3d_max_height(CLInfo<CL_DEVICE_IMAGE3D_MAX_HEIGHT>(did));
info.set_image3d_max_depth(CLInfo<CL_DEVICE_IMAGE3D_MAX_DEPTH>(did));
info.set_image_max_buffer_size(CLInfo<CL_DEVICE_IMAGE_MAX_BUFFER_SIZE>(did));
info.set_image_max_array_size(CLInfo<CL_DEVICE_IMAGE_MAX_ARRAY_SIZE>(did));
info.set_max_samplers(CLInfo<CL_DEVICE_MAX_SAMPLERS>(did));
info.set_image_pitch_alignment(CLInfo<CL_DEVICE_IMAGE_PITCH_ALIGNMENT>(did));
info.set_image_base_address_alignment(CLInfo<CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT>(did));
#ifndef __APPLE__
info.set_max_pipe_args(CLInfo<CL_DEVICE_MAX_PIPE_ARGS>(did));
info.set_pipe_max_active_reservations(CLInfo<CL_DEVICE_PIPE_MAX_ACTIVE_RESERVATIONS>(did));
#endif
info.set_max_parameter_size(CLInfo<CL_DEVICE_MAX_PARAMETER_SIZE>(did));
info.set_mem_base_addr_align(CLInfo<CL_DEVICE_MEM_BASE_ADDR_ALIGN>(did));
auto fpc = CLInfo<CL_DEVICE_SINGLE_FP_CONFIG>(did);
if (fpc & CL_FP_DENORM) {
info.add_single_fp_config(proto::DeviceFPConfig::Denorm);
}
if (fpc & CL_FP_INF_NAN) {
info.add_single_fp_config(proto::DeviceFPConfig::InfNan);
}
if (fpc & CL_FP_ROUND_TO_NEAREST) {
info.add_single_fp_config(proto::DeviceFPConfig::RoundToNearest);
}
if (fpc & CL_FP_ROUND_TO_ZERO) {
info.add_single_fp_config(proto::DeviceFPConfig::RoundToZero);
}
if (fpc & CL_FP_ROUND_TO_INF) {
info.add_single_fp_config(proto::DeviceFPConfig::RoundToInf);
}
if (fpc & CL_FP_FMA) {
info.add_single_fp_config(proto::DeviceFPConfig::FusedMultiplyAdd);
}
if (fpc & CL_FP_CORRECTLY_ROUNDED_DIVIDE_SQRT) {
info.add_single_fp_config(proto::DeviceFPConfig::CorrectlyRoundedDivideSqrt);
}
if (fpc & CL_FP_SOFT_FLOAT) {
info.add_single_fp_config(proto::DeviceFPConfig::SoftFloat);
}
fpc = CLInfo<CL_DEVICE_DOUBLE_FP_CONFIG>(did);
if (fpc & CL_FP_DENORM) {
info.add_double_fp_config(proto::DeviceFPConfig::Denorm);
}
if (fpc & CL_FP_INF_NAN) {
info.add_double_fp_config(proto::DeviceFPConfig::InfNan);
}
if (fpc & CL_FP_ROUND_TO_NEAREST) {
info.add_double_fp_config(proto::DeviceFPConfig::RoundToNearest);
}
if (fpc & CL_FP_ROUND_TO_ZERO) {
info.add_double_fp_config(proto::DeviceFPConfig::RoundToZero);
}
if (fpc & CL_FP_ROUND_TO_INF) {
info.add_double_fp_config(proto::DeviceFPConfig::RoundToInf);
}
if (fpc & CL_FP_FMA) {
info.add_double_fp_config(proto::DeviceFPConfig::FusedMultiplyAdd);
}
if (fpc & CL_FP_CORRECTLY_ROUNDED_DIVIDE_SQRT) {
info.add_double_fp_config(proto::DeviceFPConfig::CorrectlyRoundedDivideSqrt);
}
if (fpc & CL_FP_SOFT_FLOAT) {
info.add_double_fp_config(proto::DeviceFPConfig::SoftFloat);
}
switch (CLInfo<CL_DEVICE_GLOBAL_MEM_CACHE_TYPE>(did)) {
case CL_NONE:
info.set_global_mem_cache_type(proto::MemCacheType::None);
break;
case CL_READ_ONLY_CACHE:
info.set_global_mem_cache_type(proto::MemCacheType::ReadOnly);
break;
case CL_READ_WRITE_CACHE:
info.set_global_mem_cache_type(proto::MemCacheType::ReadWrite);
break;
}
info.set_global_mem_cacheline_size(CLInfo<CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE>(did));
info.set_global_mem_cache_size(CLInfo<CL_DEVICE_GLOBAL_MEM_CACHE_SIZE>(did));
info.set_global_mem_size(CLInfo<CL_DEVICE_GLOBAL_MEM_SIZE>(did));
info.set_max_constant_buffer_size(CLInfo<CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE>(did));
info.set_max_constant_args(CLInfo<CL_DEVICE_MAX_CONSTANT_ARGS>(did));
#ifndef __APPLE__
info.set_max_global_variable_size(CLInfo<CL_DEVICE_MAX_GLOBAL_VARIABLE_SIZE>(did));
info.set_global_variable_preferred_total_size(CLInfo<CL_DEVICE_GLOBAL_VARIABLE_PREFERRED_TOTAL_SIZE>(did));
#endif
switch (CLInfo<CL_DEVICE_LOCAL_MEM_TYPE>(did)) {
case CL_NONE:
info.set_local_mem_type(proto::LocalMemType::None);
break;
case CL_LOCAL:
info.set_local_mem_type(proto::LocalMemType::Local);
break;
case CL_GLOBAL:
info.set_local_mem_type(proto::LocalMemType::Global);
break;
}
info.set_local_mem_size(CLInfo<CL_DEVICE_LOCAL_MEM_SIZE>(did));
info.set_host_unified_memory(CLInfo<CL_DEVICE_HOST_UNIFIED_MEMORY>(did));
info.set_error_correction_support(CLInfo<CL_DEVICE_ERROR_CORRECTION_SUPPORT>(did));
info.set_profiling_timer_resolution_ns(CLInfo<CL_DEVICE_PROFILING_TIMER_RESOLUTION>(did));
info.set_endian_little(CLInfo<CL_DEVICE_ENDIAN_LITTLE>(did));
info.set_available(CLInfo<CL_DEVICE_AVAILABLE>(did));
info.set_compiler_available(CLInfo<CL_DEVICE_COMPILER_AVAILABLE>(did));
info.set_linker_available(CLInfo<CL_DEVICE_LINKER_AVAILABLE>(did));
auto exec_cap = CLInfo<CL_DEVICE_EXECUTION_CAPABILITIES>(did);
if (exec_cap & CL_EXEC_KERNEL) {
info.add_execution_capability(proto::DeviceExecutionCapability::Kernel);
}
if (exec_cap & CL_EXEC_NATIVE_KERNEL) {
info.add_execution_capability(proto::DeviceExecutionCapability::NativeKernel);
}
#ifndef __APPLE__
auto cqprop = CLInfo<CL_DEVICE_QUEUE_ON_HOST_PROPERTIES>(did);
if (cqprop & CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE) {
info.add_queue_on_host_property(proto::CommandQueueProperty::OutOfOrderExecModeEnable);
}
if (cqprop & CL_QUEUE_PROFILING_ENABLE) {
info.add_queue_on_host_property(proto::CommandQueueProperty::ProfilingEnable);
}
cqprop = CLInfo<CL_DEVICE_QUEUE_ON_DEVICE_PROPERTIES>(did);
if (cqprop & CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE) {
info.add_queue_on_device_property(proto::CommandQueueProperty::OutOfOrderExecModeEnable);
}
if (cqprop & CL_QUEUE_PROFILING_ENABLE) {
info.add_queue_on_device_property(proto::CommandQueueProperty::ProfilingEnable);
}
info.set_queue_on_device_preferred_size(CLInfo<CL_DEVICE_QUEUE_ON_DEVICE_PREFERRED_SIZE>(did));
info.set_queue_on_device_max_size(CLInfo<CL_DEVICE_QUEUE_ON_DEVICE_MAX_SIZE>(did));
info.set_max_on_device_queues(CLInfo<CL_DEVICE_MAX_ON_DEVICE_QUEUES>(did));
info.set_max_on_device_events(CLInfo<CL_DEVICE_MAX_ON_DEVICE_EVENTS>(did));
ForEachElt(
CLInfo<CL_DEVICE_BUILT_IN_KERNELS>(did),
[&info](std::string kernel) { info.add_built_in_kernel(std::move(kernel)); }, boost::regex{R"([^;]+)"});
#endif
info.set_platform_index(pidx);
{
// Strip leading and trailing whitespace, because some vendors want to include it in their device names.
std::string name = CLInfo<CL_DEVICE_NAME>(did);
if (info.type() == hal::proto::HardwareType::CPU) {
name = "CPU";
}
auto name_begin = name.begin();
auto name_end = name.end();
while (name_begin != name_end && std::isspace(*name_begin)) {
++name_begin;
}
while (name_begin != name_end && std::isspace(name_end[-1])) {
--name_end;
}
info.set_name(std::string(name_begin, name_end));
}
info.set_vendor(CLInfo<CL_DEVICE_VENDOR>(did));
info.set_driver_version(CLInfo<CL_DRIVER_VERSION>(did));
info.set_profile(CLInfo<CL_DEVICE_PROFILE>(did));
info.set_version(CLInfo<CL_DEVICE_VERSION>(did));
info.set_opencl_c_version(CLInfo<CL_DEVICE_OPENCL_C_VERSION>(did));
std::set<std::string> exts;
ForEachElt(CLInfo<CL_DEVICE_EXTENSIONS>(did), [&info, &exts](std::string ext) {
info.add_extension(ext);
exts.emplace(std::move(ext));
});
info.set_printf_buffer_size(CLInfo<CL_DEVICE_PRINTF_BUFFER_SIZE>(did));
info.set_preferred_interop_user_sync(CLInfo<CL_DEVICE_PREFERRED_INTEROP_USER_SYNC>(did));
info.set_partition_max_sub_devices(CLInfo<CL_DEVICE_PARTITION_MAX_SUB_DEVICES>(did));
for (auto prop : CLInfo<CL_DEVICE_PARTITION_PROPERTIES>(did)) {
switch (prop) {
case CL_DEVICE_PARTITION_EQUALLY:
info.add_device_partition_property(proto::DevicePartitionProperty::Equally);
break;
case CL_DEVICE_PARTITION_BY_COUNTS:
info.add_device_partition_property(proto::DevicePartitionProperty::ByCounts);
break;
case CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN:
info.add_device_partition_property(proto::DevicePartitionProperty::ByAffinityDomain);
break;
}
}
info.set_partition_affinity_domain(CLInfo<CL_DEVICE_PARTITION_AFFINITY_DOMAIN>(did));
for (auto ptype : CLInfo<CL_DEVICE_PARTITION_TYPE>(did)) {
switch (ptype) {
case CL_DEVICE_AFFINITY_DOMAIN_NUMA:
info.add_device_partition_type(proto::DevicePartitionType::NUMA);
break;
case CL_DEVICE_AFFINITY_DOMAIN_L4_CACHE:
info.add_device_partition_type(proto::DevicePartitionType::L4Cache);
break;
case CL_DEVICE_AFFINITY_DOMAIN_L3_CACHE:
info.add_device_partition_type(proto::DevicePartitionType::L3Cache);
break;
case CL_DEVICE_AFFINITY_DOMAIN_L2_CACHE:
info.add_device_partition_type(proto::DevicePartitionType::L2Cache);
break;
case CL_DEVICE_AFFINITY_DOMAIN_L1_CACHE:
info.add_device_partition_type(proto::DevicePartitionType::L1Cache);
break;
case CL_DEVICE_AFFINITY_DOMAIN_NEXT_PARTITIONABLE:
info.add_device_partition_type(proto::DevicePartitionType::NextPartitionable);
break;
}
}
#ifndef __APPLE__
auto svm_cap = CLInfo<CL_DEVICE_SVM_CAPABILITIES>(did);
if (svm_cap & CL_DEVICE_SVM_COARSE_GRAIN_BUFFER) {
info.add_svm_capability(proto::SvmCapability::CoarseGrainBuffer);
}
if (svm_cap & CL_DEVICE_SVM_FINE_GRAIN_BUFFER) {
info.add_svm_capability(proto::SvmCapability::FineGrainBuffer);
}
if (svm_cap & CL_DEVICE_SVM_FINE_GRAIN_SYSTEM) {
info.add_svm_capability(proto::SvmCapability::FineGrainSystem);
}
if (svm_cap & CL_DEVICE_SVM_ATOMICS) {
info.add_svm_capability(proto::SvmCapability::Atomics);
}
info.set_preferred_platform_atomic_alignment(CLInfo<CL_DEVICE_PREFERRED_PLATFORM_ATOMIC_ALIGNMENT>(did));
info.set_preferred_global_atomic_alignment(CLInfo<CL_DEVICE_PREFERRED_GLOBAL_ATOMIC_ALIGNMENT>(did));
info.set_preferred_local_atomic_alignment(CLInfo<CL_DEVICE_PREFERRED_LOCAL_ATOMIC_ALIGNMENT>(did));
info.set_max_num_sub_groups(CLInfo<CL_DEVICE_MAX_NUM_SUB_GROUPS>(did));
info.set_sub_group_independent_forward_progress(CLInfo<CL_DEVICE_SUB_GROUP_INDEPENDENT_FORWARD_PROGRESS>(did));
#endif
info.set_platform_name(pinfo.name());
#ifdef CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV
if (exts.find("cl_nv_device_attribute_query") != exts.end()) {
info.set_nv_cuda_major_rev(CLInfo<CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV>(did));
info.set_nv_cuda_minor_rev(CLInfo<CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV>(did));
info.set_nv_registers_per_block(CLInfo<CL_DEVICE_REGISTERS_PER_BLOCK_NV>(did));
info.set_nv_warp_size(CLInfo<CL_DEVICE_WARP_SIZE_NV>(did));
info.set_nv_gpu_overlap(CLInfo<CL_DEVICE_GPU_OVERLAP_NV>(did));
info.set_nv_kernel_exec_timeout(CLInfo<CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV>(did));
info.set_nv_integrated_memory(CLInfo<CL_DEVICE_INTEGRATED_MEMORY_NV>(did));
}
#endif
#ifdef CL_DEVICE_BOARD_NAME_AMD
if (exts.find("cl_amd_device_attribute_query") != exts.end()) {
info.set_amd_board_name(CLInfo<CL_DEVICE_BOARD_NAME_AMD>(did));
info.set_amd_simd_per_compute_unit(CLInfo<CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD>(did));
info.set_amd_simd_instruction_width(CLInfo<CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD>(did));
info.set_amd_wavefront_width(CLInfo<CL_DEVICE_WAVEFRONT_WIDTH_AMD>(did));
info.set_amd_global_mem_channels(CLInfo<CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD>(did));
info.set_amd_global_mem_channel_banks(CLInfo<CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD>(did));
info.set_amd_global_mem_channel_bank_width(CLInfo<CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD>(did));
info.set_amd_local_mem_size_per_compute_unit(CLInfo<CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD>(did));
info.set_amd_local_mem_banks(CLInfo<CL_DEVICE_LOCAL_MEM_BANKS_AMD>(did));
}
#endif
return info;
}
} // namespace
DeviceSet::DeviceSet(const context::Context& ctx, std::uint32_t pidx, cl_platform_id pid) {
context::Activity platform_activity{ctx, "tile::hal::opencl::Platform"};
auto pinfo = GetPlatformInfo(pid);
LogInfo(std::string("Platform[") + std::to_string(pidx) + "]", pinfo);
platform_activity.AddMetadata(pinfo);
cl_uint device_count;
ocl::GetDeviceIDs(pid, CL_DEVICE_TYPE_ALL, 0, nullptr, &device_count);
std::vector<cl_device_id> devices(device_count);
ocl::GetDeviceIDs(pid, CL_DEVICE_TYPE_ALL, devices.size(), devices.data(), nullptr);
// Remove OpenCL devices that are older than PLAIDML_MIN_OPENCL_VERSION
devices.erase(std::remove_if(devices.begin(), devices.end(),
[](const cl_device_id& did) {
auto device_version = CLInfoType<CL_DEVICE_VERSION>::Read(did);
return (device_version.compare(PLAIDML_MIN_OPENCL_VERSION) < 0);
}),
devices.end());
cl_context_properties props[3] = {CL_CONTEXT_PLATFORM, reinterpret_cast<cl_context_properties>(pid), 0};
Err err;
CLObj<cl_context> cl_ctx = ocl::CreateContext(props, devices.size(), devices.data(), &OnErr, nullptr, err.ptr());
if (!cl_ctx) {
throw std::runtime_error(std::string("failed to create a context for OpenCL devices on platform ") +
CLInfo<CL_PLATFORM_NAME>(pid) + ": " + err.str());
}
std::shared_ptr<Device> first_dev;
for (std::uint32_t didx = 0; didx < devices.size(); ++didx) {
context::Activity device_activity{platform_activity.ctx(), "tile::hal::opencl::Device"};
auto did = devices[didx];
auto dinfo = GetDeviceInfo(did, pidx, pinfo);
*dinfo.mutable_platform_id() = platform_activity.ctx().activity_id();
LogInfo(std::string("Platform[") + std::to_string(pidx) + "].Device[" + std::to_string(didx) + "]", dinfo);
device_activity.AddMetadata(dinfo);
auto dev = std::make_shared<Device>(device_activity.ctx(), cl_ctx, did, std::move(dinfo));
if (!first_dev) {
first_dev = dev;
}
devices_.emplace_back(std::move(dev));
}
if (first_dev) {
host_memory_ = std::make_unique<HostMemory>(first_dev->device_state());
}
}
const std::vector<std::shared_ptr<hal::Device>>& DeviceSet::devices() { return devices_; }
Memory* DeviceSet::host_memory() { return host_memory_.get(); }
} // namespace opencl
} // namespace hal
} // namespace tile
} // namespace vertexai