Skip to content

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

[GPU] Add data range check log for validate_output_buffer (#32254)

Mingyu Kimb834f3cbf581
diff --git a/src/plugins/intel_gpu/include/intel_gpu/graph/network.hpp b/src/plugins/intel_gpu/include/intel_gpu/graph/network.hpp
index 38e4e4e55c7..ce7b0bbd79f 100644
--- a/src/plugins/intel_gpu/include/intel_gpu/graph/network.hpp
+++ b/src/plugins/intel_gpu/include/intel_gpu/graph/network.hpp
@@ -206,9 +206,9 @@ public:
void set_shape_predictor(std::shared_ptr<ShapePredictor> shape_predictor) { _shape_predictor = shape_predictor; }
#ifdef GPU_DEBUG_CONFIG
- int64_t get_current_iteration_num() { return iteration; }
+ int64_t get_current_iteration_num() const { return iteration; }
#else
- int64_t get_current_iteration_num() { const int64_t NOT_AVAILABLE=-112233; return NOT_AVAILABLE; }
+ int64_t get_current_iteration_num() const { const int64_t NOT_AVAILABLE=-112233; return NOT_AVAILABLE; }
#endif
private:
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 536eda8e7b0..7fafeffbd55 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
@@ -173,7 +173,7 @@ static constexpr Property<ShapePredictor::Settings, ov::PropertyMutability::RW>
static constexpr Property<std::vector<std::string>, ov::PropertyMutability::RW> load_dump_raw_binary{"GPU_LOAD_DUMP_RAW_BINARY"};
static constexpr Property<bool, ov::PropertyMutability::RW> could_use_flashattn_v2{"GPU_COULD_USE_FLASHATTN_V2"};
static constexpr Property<uint64_t, PropertyMutability::RW> dynamic_quantization_group_size_max{"GPU_DYNAMIC_QUANTIZATION_GROUP_SIZE_MAX"};
-static constexpr Property<bool, ov::PropertyMutability::RW> validate_output_buffer{"VALIDATE_OUTPUT_BUFFER"};
+static constexpr Property<bool, ov::PropertyMutability::RW> validate_output_buffer{"GPU_VALIDATE_OUTPUT_BUFFER"};
} // namespace ov::intel_gpu
namespace cldnn {
diff --git a/src/plugins/intel_gpu/src/graph/debug_helper.cpp b/src/plugins/intel_gpu/src/graph/debug_helper.cpp
index a32a44b3fa1..78072a28381 100644
--- a/src/plugins/intel_gpu/src/graph/debug_helper.cpp
+++ b/src/plugins/intel_gpu/src/graph/debug_helper.cpp
@@ -43,6 +43,63 @@ size_t get_x_pitch(const layout& layout) {
}
}
+template <class T>
+void __validate_data_range(memory::ptr mem, stream& stream, std::string &info) {
+ auto&& size = mem->get_layout().get_tensor();
+
+ mem_lock<T, mem_lock_type::read> lock(mem, stream);
+ auto mem_ptr = lock.data();
+ auto x_pitch = get_x_pitch(mem->get_layout());
+ std::stringstream buffer;
+ float val_min = std::numeric_limits<float>::max();
+ float val_max = std::numeric_limits<float>::lowest();
+
+
+ for (ov::Dimension::value_type g = 0; g < size.group[0]; ++g) {
+ for (ov::Dimension::value_type b = 0; b < size.batch[0]; ++b) {
+ for (ov::Dimension::value_type f = 0; f < size.feature[0]; ++f) {
+ for (ov::Dimension::value_type w = 0; w < size.spatial[3]; ++w) {
+ for (ov::Dimension::value_type z = 0; z < size.spatial[2]; ++z) {
+ for (ov::Dimension::value_type y = 0; y < size.spatial[1]; ++y) {
+ cldnn::tensor t(cldnn::group(g), cldnn::batch(b), cldnn::feature(f), cldnn::spatial(0, y, z, w));
+ size_t input_it = mem->get_layout().get_linear_offset(t);
+
+ for (ov::Dimension::value_type x = 0; x < size.spatial[0]; ++x, input_it += x_pitch) {
+ auto val = convert_element(mem_ptr[input_it]);
+ if (std::isinf(val) || std::isnan(val)) {
+ std::string err_str = std::isinf(val) ? "inf " : "nan ";
+ GPU_DEBUG_COUT << "===============================================" << std::endl;
+ GPU_DEBUG_COUT << err_str << " WAS FOUND: " << info << std::endl;
+ GPU_DEBUG_COUT << "===============================================" << std::endl;
+ return;
+ }
+ if (val > val_max)
+ val_max = val;
+ if (val < val_min)
+ val_min = val;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ GPU_DEBUG_INFO << "min, max = " << val_min << ", " << val_max << " : " << info << std::endl;
+}
+
+void validate_data_range(memory::ptr mem, stream& stream, ov::element::Type_t data_type, std::string &info) {
+ if (data_type == ov::element::Type_t::f32)
+ __validate_data_range<float>(mem, stream, info);
+ else if (data_type == ov::element::Type_t::f16)
+ __validate_data_range<ov::float16>(mem, stream, info);
+ else if (data_type == ov::element::Type_t::i8)
+ __validate_data_range<int8_t>(mem, stream, info);
+ else if (data_type == ov::element::Type_t::u8)
+ __validate_data_range<uint8_t>(mem, stream, info);
+ else
+ GPU_DEBUG_INFO << "Unsupport data type for validating data range " << data_type << std::endl;
+}
+
template <class T>
void dump(memory::ptr mem, stream& stream, std::ofstream& file_stream, bool dump_raw) {
auto&& size = mem->get_layout().get_tensor();
@@ -427,6 +484,16 @@ NodeDebugHelper::NodeDebugHelper(const primitive_inst& inst)
NodeDebugHelper::~NodeDebugHelper() {
const auto& config = m_network.get_config();
+
+ if (config.get_validate_output_buffer()) {
+ m_stream.finish(); // Wait for stream completion before checking output buffers
+ for (size_t i = 0; i < m_inst.outputs_memory_count(); i++) {
+ auto output_mem = m_inst.output_memory_ptr(i);
+ std::string info = m_inst.id() + "(" + std::to_string(i) + ") at iteration " + std::to_string(m_network.get_current_iteration_num());
+ validate_data_range(output_mem, m_stream, m_inst.get_output_layout(i).data_type, info);
+ }
+ }
+
// Dump output buffers of 'inst'
if (config.get_dump_tensors_path().length() > 0) {
const std::string layer_name = m_inst.id();
diff --git a/src/plugins/intel_gpu/src/graph/primitive_inst.cpp b/src/plugins/intel_gpu/src/graph/primitive_inst.cpp
index 7030c1baed7..b45813329c9 100644
--- a/src/plugins/intel_gpu/src/graph/primitive_inst.cpp
+++ b/src/plugins/intel_gpu/src/graph/primitive_inst.cpp
@@ -2118,22 +2118,6 @@ void primitive_inst::execute() {
set_out_event(_impl->execute(_impl_params->dep_events, *this));
- GPU_DEBUG_IF(get_config().get_validate_output_buffer()) {
- get_network().get_stream().finish();
- auto &layout = _impl_params->get_output_layout(0);
- auto output_mem = output_memory_ptr(0);
- if (output_mem && layout.data_type == data_types::f16) {
- mem_lock<ov::float16, mem_lock_type::read> lock(output_mem, get_network().get_stream());
- for (size_t k = 0; k < lock.size(); k++) {
- if (std::isinf(lock[k]) || std::isnan(lock[k])) {
- std::string iter = "at iteration " + std::to_string(get_network().get_current_iteration_num());
- std::string err_str = std::isinf(lock[k]) ? "inf " : "nan ";
- OPENVINO_THROW(id() + " has " + err_str + iter);
- }
- }
- }
- }
-
GPU_DEBUG_IF(!get_config().get_dump_profiling_data_path().empty()) {
auto ev = _impl_params->out_event;
get_network().get_stream().wait_for_events({ev});