Skip to content

Commit

Permalink
[GPU] Align queue type in engine with shared queue (#8144)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimir-paramuzov authored Oct 22, 2021
1 parent 54daae4 commit 9b61698
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 3 deletions.
7 changes: 5 additions & 2 deletions inference-engine/src/cldnn_engine/cldnn_remote_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,13 @@ CLDNNExecutionContextImpl::CLDNNExecutionContextImpl(const std::shared_ptr<IInfe
(m_config.tuningConfig.mode == cldnn::tuning_mode::tuning_tune_and_cache) ||
(m_config.tuningConfig.mode == cldnn::tuning_mode::tuning_retune_and_cache));
cldnn::queue_types queue_type;
if (dev->get_info().supports_immad)
if (m_external_queue) {
queue_type = cldnn::stream::detect_queue_type(engine_type, m_external_queue);
} else if (dev->get_info().supports_immad) {
queue_type = cldnn::queue_types::in_order;
else
} else {
queue_type = cldnn::queue_types::out_of_order;
}

bool use_unified_shared_memory = true;
m_engine = cldnn::engine::create(engine_type, runtime_type, dev, cldnn::engine_configuration(enable_profiling,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class stream {

queue_types get_queue_type() const { return queue_type; }

static queue_types detect_queue_type(engine_types engine_type, void* queue_handle);

#ifdef ENABLE_ONEDNN_FOR_GPU
virtual dnnl::stream& get_onednn_stream() = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ std::vector<device::ptr> ocl_device_detector::create_device_list_from_user_cont
for (auto& device : all_devices) {
if (!does_device_match_config(out_out_order, device))
continue;
ret.emplace_back(std::make_shared<ocl_device>(device, cl::Context(device), device.getInfo<CL_DEVICE_PLATFORM>()));
ret.emplace_back(std::make_shared<ocl_device>(device, ctx, device.getInfo<CL_DEVICE_PLATFORM>()));
}

if (ret.empty()) {
Expand Down
14 changes: 14 additions & 0 deletions inference-engine/thirdparty/clDNN/runtime/ocl/ocl_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,9 @@ ocl_stream::ocl_stream(const ocl_engine &engine, void *handle)
auto casted_handle = static_cast<cl_command_queue>(handle);
_command_queue = ocl_queue_type(casted_handle, true);

if (ocl_stream::detect_queue_type(handle) != engine.configuration().queue_type)
throw std::runtime_error("Inconsistent engine config and external user queue are passed to ocl_stream");

#ifdef ENABLE_ONEDNN_FOR_GPU
auto config = engine.configuration();
if (config.queue_type == queue_types::in_order) {
Expand All @@ -318,6 +321,17 @@ dnnl::stream& ocl_stream::get_onednn_stream() {
}
#endif

queue_types ocl_stream::detect_queue_type(void *queue_handle) {
cl_command_queue queue = static_cast<cl_command_queue>(queue_handle);
cl_command_queue_properties properties;
auto status = clGetCommandQueueInfo(queue, CL_QUEUE_PROPERTIES, sizeof(cl_command_queue_properties), &properties, nullptr);
if (status != CL_SUCCESS) {
throw std::runtime_error("Can't get queue properties for user handle\n");
}

return (properties & CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE) ? queue_types::out_of_order : queue_types::in_order;
}

void ocl_stream::set_arguments(kernel& kernel, const kernel_arguments_desc& args_desc, const kernel_arguments_data& args) {
static std::mutex m;
std::lock_guard<std::mutex> guard(m);
Expand Down
2 changes: 2 additions & 0 deletions inference-engine/thirdparty/clDNN/runtime/ocl/ocl_stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class ocl_stream : public stream {

const cl::UsmHelper& get_usm_helper() const { return _engine.get_usm_helper(); }

static queue_types detect_queue_type(void* queue_handle);

#ifdef ENABLE_ONEDNN_FOR_GPU
dnnl::stream& get_onednn_stream() override;
#endif
Expand Down
20 changes: 20 additions & 0 deletions inference-engine/thirdparty/clDNN/runtime/stream.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include "cldnn/runtime/stream.hpp"

#include "ocl/ocl_stream.hpp"

#include <stdexcept>

namespace cldnn {

queue_types stream::detect_queue_type(engine_types engine_type, void* queue_handle) {
switch (engine_type) {
case engine_types::ocl: return ocl::ocl_stream::detect_queue_type(queue_handle);
default: throw std::runtime_error("Invalid engine type");
}
}

} // namespace cldnn

0 comments on commit 9b61698

Please sign in to comment.