Skip to content

Commit

Permalink
[IE CLDNN] Add sub-device support to GPU plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Letavin committed Apr 6, 2021
1 parent 91a8de1 commit fc3299d
Showing 1 changed file with 58 additions and 2 deletions.
60 changes: 58 additions & 2 deletions inference-engine/thirdparty/clDNN/src/gpu/ocl_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,49 @@ namespace cldnn {
namespace gpu {
static constexpr auto INTEL_PLATFORM_VENDOR = "Intel(R) Corporation";

static std::vector<cl::Device> getSubDevices(cl::Device& rootDevice) {
cl_uint maxSubDevices;
size_t maxSubDevicesSize;
const auto err = clGetDeviceInfo(rootDevice(),
CL_DEVICE_PARTITION_MAX_SUB_DEVICES,
sizeof(maxSubDevices),
&maxSubDevices, &maxSubDevicesSize);

if (err != CL_SUCCESS || maxSubDevicesSize != sizeof(maxSubDevices)) {
throw cl::Error(err, "clGetDeviceInfo(..., CL_DEVICE_PARTITION_MAX_SUB_DEVICES,...)");
}

if (maxSubDevices == 0) {
return {};
}

const auto partitionProperties = rootDevice.getInfo<CL_DEVICE_PARTITION_PROPERTIES>();
const auto partitionable = std::any_of(partitionProperties.begin(), partitionProperties.end(),
[](const decltype(partitionProperties)::value_type& prop) {
return prop == CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN;
});

if (!partitionable) {
return {};
}

const auto partitionAffinityDomain = rootDevice.getInfo<CL_DEVICE_PARTITION_AFFINITY_DOMAIN>();
const decltype(partitionAffinityDomain) expectedFlags =
CL_DEVICE_AFFINITY_DOMAIN_NUMA | CL_DEVICE_AFFINITY_DOMAIN_NEXT_PARTITIONABLE;

if ((partitionAffinityDomain & expectedFlags) != expectedFlags) {
return {};
}

std::vector<cl::Device> subDevices;
cl_device_partition_property partitionProperty[] = {CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN,
CL_DEVICE_AFFINITY_DOMAIN_NUMA, 0};

rootDevice.createSubDevices(partitionProperty, &subDevices);

return subDevices;
}

std::map<std::string, device_impl::ptr> ocl_builder::get_available_devices(void* user_context, void* user_device) const {
bool host_out_of_order = true; // Change to false, if debug requires in-order queue.
std::vector<device_impl::ptr> dev_orig, dev_sorted;
Expand All @@ -45,7 +88,20 @@ std::map<std::string, device_impl::ptr> ocl_builder::get_available_devices(void*
}
uint32_t idx = 0;
for (auto& dptr : dev_sorted) {
ret[std::to_string(idx++)] = dptr;
auto map_id = std::to_string(idx++);
ret[map_id] = dptr;

auto rootDevice = dptr->get_device();
auto subDevices = getSubDevices(rootDevice);
if (!subDevices.empty()) {
uint32_t sub_idx = 0;
for (auto& subdevice : subDevices) {
auto subdPtr = device_impl::ptr(new device_impl(subdevice, cl::Context(subdevice),
dptr->get_platform(),
device_info_internal(subdevice)), false);
ret[map_id+"."+std::to_string(sub_idx++)] = subdPtr;
}
}
}
return ret;
}
Expand Down Expand Up @@ -77,7 +133,7 @@ std::vector<device_impl::ptr> ocl_builder::build_device_list(bool out_out_order)
for (auto& device : devices) {
if (!does_device_match_config(out_out_order, device)) continue;
ret.emplace_back(device_impl::ptr{ new device_impl(device, cl::Context(device),
id, device_info_internal(device)), false});
id, device_info_internal(device)), false});
}
}
if (ret.empty()) {
Expand Down

0 comments on commit fc3299d

Please sign in to comment.