From 1690c9362966b1e26f722148243f5e67519bd47c Mon Sep 17 00:00:00 2001 From: Mikhail Letavin Date: Thu, 27 Aug 2020 21:25:24 +0300 Subject: [PATCH] [IE CLDNN] Move iGPU to first position in GPU device map (#1828) --- .../thirdparty/clDNN/src/gpu/ocl_builder.cpp | 88 +++++++++---------- .../thirdparty/clDNN/src/gpu/ocl_builder.h | 10 +-- 2 files changed, 44 insertions(+), 54 deletions(-) diff --git a/inference-engine/thirdparty/clDNN/src/gpu/ocl_builder.cpp b/inference-engine/thirdparty/clDNN/src/gpu/ocl_builder.cpp index 98228ace611..bb5227c3980 100644 --- a/inference-engine/thirdparty/clDNN/src/gpu/ocl_builder.cpp +++ b/inference-engine/thirdparty/clDNN/src/gpu/ocl_builder.cpp @@ -38,16 +38,31 @@ static constexpr auto INTEL_PLATFORM_VENDOR = "Intel(R) Corporation"; std::map 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 dev_orig, dev_sorted; if (user_context != nullptr) { - return build_device_list_from_user_context(host_out_of_order, user_context); + dev_orig = build_device_list_from_user_context(host_out_of_order, user_context); } else if (user_device != nullptr) { - return build_device_list_from_user_device(host_out_of_order, user_device); + dev_orig = build_device_list_from_user_device(host_out_of_order, user_device); } else { - return build_device_list(host_out_of_order); + dev_orig = build_device_list(host_out_of_order); } + + std::map ret; + for (auto& dptr : dev_orig) { + auto flag = dptr->get_device().getInfo(); + if (flag != 0) + dev_sorted.insert(dev_sorted.begin(), dptr); + else + dev_sorted.push_back(dptr); + } + uint32_t idx = 0; + for (auto& dptr : dev_sorted) { + ret[std::to_string(idx++)] = dptr; + } + return ret; } -std::map ocl_builder::build_device_list(bool out_out_order) const { +std::vector ocl_builder::build_device_list(bool out_out_order) const { cl_uint n = 0; // Get number of platforms availible cl_int err = clGetPlatformIDs(0, NULL, &n); @@ -62,8 +77,7 @@ std::map ocl_builder::build_device_list(bool out_ throw std::runtime_error("[CLDNN ERROR]. clGetPlatformIDs error " + std::to_string(err)); } - uint32_t idx = 0; - std::map ret; + std::vector ret; for (auto& id : platform_ids) { cl::Platform platform = cl::Platform(id); @@ -74,7 +88,8 @@ std::map ocl_builder::build_device_list(bool out_ platform.getDevices(CL_DEVICE_TYPE_ALL, &devices); for (auto& device : devices) { if (!does_device_match_config(out_out_order, device)) continue; - ret.insert(get_device(idx++, device, id)); + ret.emplace_back(device_impl::ptr{ new device_impl(device, cl::Context(device), + id, device_info_internal(device)), false}); } } if (ret.empty()) { @@ -83,15 +98,16 @@ std::map ocl_builder::build_device_list(bool out_ return ret; } -std::map ocl_builder::build_device_list_from_user_context(bool out_out_order, void* user_context) const { +std::vector ocl_builder::build_device_list_from_user_context(bool out_out_order, void* user_context) const { cl::Context ctx = cl::Context(static_cast(user_context), true); auto all_devices = ctx.getInfo(); - std::map ret; - uint32_t idx = 0; + std::vector ret; for (auto& device : all_devices) { if (!does_device_match_config(out_out_order, device)) continue; - ret.insert(get_device(idx++, device, device.getInfo())); + ret.emplace_back(device_impl::ptr{ new device_impl(device, cl::Context(device), + device.getInfo(), + device_info_internal(device)), false}); } if (ret.empty()) { @@ -100,7 +116,7 @@ std::map ocl_builder::build_device_list_from_use return ret; } -std::map ocl_builder::build_device_list_from_user_device(bool out_out_order, void* user_device) const { +std::vector ocl_builder::build_device_list_from_user_device(bool out_out_order, void* user_device) const { cl_uint n = 0; // Get number of platforms availible cl_int err = clGetPlatformIDs(0, NULL, &n); @@ -115,8 +131,7 @@ std::map ocl_builder::build_device_list_from_use throw std::runtime_error("[CLDNN ERROR]. clGetPlatformIDs error " + std::to_string(err)); } - uint32_t idx = 0; - std::map ret; + std::vector ret; for (auto& id : platform_ids) { cl::PlatformVA platform = cl::PlatformVA(id); @@ -137,7 +152,18 @@ std::map ocl_builder::build_device_list_from_use for (auto& device : devices) { if (!does_device_match_config(out_out_order, device)) continue; - ret.insert(get_device_shared(idx++, device, id, user_device)); + cl_context_properties props[] = { + #ifdef WIN32 + CL_CONTEXT_D3D11_DEVICE_KHR, + #else + CL_CONTEXT_VA_API_DISPLAY_INTEL, + #endif + (intptr_t)user_device, + CL_CONTEXT_INTEROP_USER_SYNC, CL_FALSE, + CL_CONTEXT_PLATFORM, (cl_context_properties)id, + 0 }; + ret.emplace_back(device_impl::ptr{ new device_impl(device, cl::Context(device, props), + id, device_info_internal(device)), false }); } } if (ret.empty()) { @@ -146,38 +172,6 @@ std::map ocl_builder::build_device_list_from_use return ret; } -std::pair ocl_builder::get_device(const uint32_t index, - const cl::Device& dev_to_add, - const cl_platform_id platform) const { - return { - std::to_string(index), - device_impl::ptr{ new device_impl(dev_to_add, cl::Context(dev_to_add), platform, device_info_internal(dev_to_add)), - false} - }; -} - -std::pair ocl_builder::get_device_shared(const uint32_t index, - const cl::Device& dev_to_add, - const cl_platform_id platform, - void* user_device) const { - cl_context_properties props[] = { -#ifdef WIN32 - CL_CONTEXT_D3D11_DEVICE_KHR, -#else - CL_CONTEXT_VA_API_DISPLAY_INTEL, -#endif - (intptr_t)user_device, - CL_CONTEXT_INTEROP_USER_SYNC, CL_FALSE, - CL_CONTEXT_PLATFORM, (cl_context_properties)platform, - 0 }; - - return { - std::to_string(index), - device_impl::ptr{ new device_impl(dev_to_add, cl::Context(dev_to_add, props), platform, device_info_internal(dev_to_add)), - false } - }; -} - bool ocl_builder::does_device_match_config(bool out_of_order, const cl::Device& device) const { // Is it intel gpu if (device.getInfo() != device_type || diff --git a/inference-engine/thirdparty/clDNN/src/gpu/ocl_builder.h b/inference-engine/thirdparty/clDNN/src/gpu/ocl_builder.h index c17f69c6532..d013d0e7856 100644 --- a/inference-engine/thirdparty/clDNN/src/gpu/ocl_builder.h +++ b/inference-engine/thirdparty/clDNN/src/gpu/ocl_builder.h @@ -43,14 +43,10 @@ public: uint32_t get_device_type() const { return device_type; } uint32_t get_device_vendor() const { return device_vendor; } private: - std::pair get_device(const uint32_t index, - const cl::Device& dev_to_add, const cl_platform_id platform) const; - std::pair get_device_shared(const uint32_t index, - const cl::Device& dev_to_add, const cl_platform_id platform, void* user_device) const; bool does_device_match_config(bool out_of_order, const cl::Device& device) const; - std::map build_device_list(bool out_out_order) const; - std::map build_device_list_from_user_context(bool out_out_order, void* user_context) const; - std::map build_device_list_from_user_device(bool out_out_order, void* user_device) const; + std::vector build_device_list(bool out_out_order) const; + std::vector build_device_list_from_user_context(bool out_out_order, void* user_context) const; + std::vector build_device_list_from_user_device(bool out_out_order, void* user_device) const; }; } // namespace gpu