Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[GPU] Add opt-in per-kernel finish to find CL_OUT_OF_RESOURCES (#38222)

Min, Byungilf333247a5680
diff --git a/src/plugins/intel_gpu/include/intel_gpu/runtime/internal_properties.hpp b/src/plugins/intel_gpu/include/intel_gpu/runtime/internal_properties.hpp
index 08d40fc70e6..def9a0d1e5c 100644
--- a/src/plugins/intel_gpu/include/intel_gpu/runtime/internal_properties.hpp
+++ b/src/plugins/intel_gpu/include/intel_gpu/runtime/internal_properties.hpp
@@ -180,6 +180,7 @@ static constexpr Property<bool, ov::PropertyMutability::RW> verbose_color{"VERBO
static constexpr Property<std::string, ov::PropertyMutability::RW> debug_config{"GPU_DEBUG_CONFIG"};
static constexpr Property<std::string, ov::PropertyMutability::RW> log_to_file{"GPU_LOG_TO_FILE"};
static constexpr Property<bool, ov::PropertyMutability::RW> disable_usm{"GPU_DISABLE_USM"};
+static constexpr Property<bool, ov::PropertyMutability::RW> finish_after_enqueue{"GPU_FINISH_AFTER_ENQUEUE"};
static constexpr Property<bool, ov::PropertyMutability::RW> disable_onednn_post_ops_opt{"GPU_DISABLE_ONEDNN_POST_OPS_OPT"};
static constexpr Property<std::string, PropertyMutability::RW> dump_graphs_path{"GPU_DUMP_GRAPHS_PATH"};
static constexpr Property<std::string, ov::PropertyMutability::RW> dump_profiling_data_path{"GPU_DUMP_PROFILING_DATA_PATH"};
diff --git a/src/plugins/intel_gpu/include/intel_gpu/runtime/options.inl b/src/plugins/intel_gpu/include/intel_gpu/runtime/options.inl
index d8d0d395d02..c06a7e4179b 100644
--- a/src/plugins/intel_gpu/include/intel_gpu/runtime/options.inl
+++ b/src/plugins/intel_gpu/include/intel_gpu/runtime/options.inl
@@ -91,6 +91,7 @@ OV_CONFIG_DEBUG_GLOBAL_OPTION(ov::intel_gpu, verbose_color, true, "Enable colori
OV_CONFIG_DEBUG_GLOBAL_OPTION(ov::intel_gpu, enable_mlir, false, "Enable/Disable MLIR/Graph-Compiler execution for supported subgraphs. Requires ENABLE_MLIR_FOR_GPU=ON at build time [EXPERIMENTAL, NOT PRODUCTION-READY]")
OV_CONFIG_DEBUG_GLOBAL_OPTION(ov::intel_gpu, mlir_debug, false, "Enable verbose logging of the MLIR/Graph-Compiler pipeline")
OV_CONFIG_DEBUG_GLOBAL_OPTION(ov::intel_gpu, disable_usm, false, "Disable USM memory allocations and use only cl_mem")
+OV_CONFIG_DEBUG_GLOBAL_OPTION(ov::intel_gpu, finish_after_enqueue, false, "Diagnostic: call finish() after each kernel enqueue so async errors like CL_OUT_OF_RESOURCES surface at the exact failing kernel/layer")
OV_CONFIG_DEBUG_GLOBAL_OPTION(ov::intel_gpu, usm_policy, 0, "0: default, 1: use usm_host, 2: do not use usm_host")
OV_CONFIG_DEBUG_GLOBAL_OPTION(ov::intel_gpu, dump_batch_limit, std::numeric_limits<int32_t>::max(), "Max number of batch elements to dump")
OV_CONFIG_DEBUG_GLOBAL_OPTION(ov::intel_gpu, dump_profiling_data_per_iter, false, "Save profiling data w/o per-iteration aggregation")
diff --git a/src/plugins/intel_gpu/src/graph/impls/onednn/primitive_onednn_base.h b/src/plugins/intel_gpu/src/graph/impls/onednn/primitive_onednn_base.h
index f7f31ac816e..52018d06af0 100644
--- a/src/plugins/intel_gpu/src/graph/impls/onednn/primitive_onednn_base.h
+++ b/src/plugins/intel_gpu/src/graph/impls/onednn/primitive_onednn_base.h
@@ -595,7 +595,18 @@ protected:
#endif
_prim.execute(stream.get_onednn_stream(), _args[net_id]);
} catch (dnnl::error& err) {
- OPENVINO_THROW(err.what());
+ OPENVINO_THROW("[", instance.id(), "] ", err.what());
+ }
+
+ // Diagnostic: onednn primitives execute directly on the onednn stream and never pass through
+ // ocl_stream::enqueue_kernel, so force completion here too to surface async errors
+ // (e.g. CL_OUT_OF_RESOURCES) at this exact onednn primitive/layer.
+ GPU_DEBUG_IF(network.get_config().get_finish_after_enqueue()) {
+ try {
+ stream.finish();
+ } catch (std::exception& err) {
+ OPENVINO_THROW("[FINISH_AFTER_ENQUEUE][onednn] [", instance.id(), "] ", err.what());
+ }
}
if (_enable_profiling) {
diff --git a/src/plugins/intel_gpu/src/runtime/ocl/ocl_stream.cpp b/src/plugins/intel_gpu/src/runtime/ocl/ocl_stream.cpp
index 59371a65766..fa3749b2f98 100644
--- a/src/plugins/intel_gpu/src/runtime/ocl/ocl_stream.cpp
+++ b/src/plugins/intel_gpu/src/runtime/ocl/ocl_stream.cpp
@@ -7,6 +7,7 @@
#include <cassert>
#include <memory>
#include <string>
+#include <cstdio>
#include <vector>
#include "CL/cl.h"
@@ -316,6 +317,19 @@ event::ptr ocl_stream::enqueue_kernel(kernel& kernel,
ocl::rethrow(err, _engine.get_device_info());
}
+ // Diagnostic: force per-kernel completion so CL_OUT_OF_RESOURCES surfaces at the exact cldnn OCL kernel.
+ GPU_DEBUG_IF(ov::intel_gpu::ExecutionConfig::get_finish_after_enqueue()) {
+ try {
+ _command_queue.finish();
+ } catch (cl::Error const& err) {
+ std::string kname;
+ try { kname = kern.getInfo<CL_KERNEL_FUNCTION_NAME>(); } catch (...) {}
+ std::fprintf(stderr, "[FINISH_AFTER_ENQUEUE][cldnn] kernel='%s' finish err=%d\n", kname.c_str(), err.err());
+ std::fflush(stderr);
+ ocl::rethrow(err, _engine.get_device_info());
+ }
+ }
+
return std::make_shared<ocl_event>(ret_ev, ++_queue_counter);
}
diff --git a/src/plugins/intel_gpu/tests/unit/module_tests/execution_config_test.cpp b/src/plugins/intel_gpu/tests/unit/module_tests/execution_config_test.cpp
index 8ec4fc42463..4a68b5c3e59 100644
--- a/src/plugins/intel_gpu/tests/unit/module_tests/execution_config_test.cpp
+++ b/src/plugins/intel_gpu/tests/unit/module_tests/execution_config_test.cpp
@@ -5,6 +5,7 @@
#include "test_utils.h"
#include "intel_gpu/plugin/remote_context.hpp"
+#include "intel_gpu/runtime/debug_configuration.hpp"
#include "intel_gpu/runtime/execution_config.hpp"
#include "openvino/op/constant.hpp"
@@ -285,3 +286,11 @@ TEST(execution_config, profiling_not_auto_enabled_without_onednn_verbose) {
ASSERT_FALSE(config.get_enable_profiling());
}
#endif // ENABLE_ONEDNN_FOR_GPU
+
+// finish_after_enqueue only works in debug builds and is turned on by an env var.
+// Check that it is set up and stays OFF by default so normal runs are not affected.
+TEST(execution_config, finish_after_enqueue_default_off) {
+ GPU_DEBUG_IF(ov::intel_gpu::ExecutionConfig::get_finish_after_enqueue()) {
+ GTEST_FAIL() << "finish_after_enqueue must default to OFF when OV_GPU_FINISH_AFTER_ENQUEUE is unset";
+ }
+}