diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl/primitive_base.hpp b/src/plugins/intel_gpu/src/graph/impls/ocl/primitive_base.hpp index 43646ede56f..d319c27fd7a 100644 --- a/src/plugins/intel_gpu/src/graph/impls/ocl/primitive_base.hpp +++ b/src/plugins/intel_gpu/src/graph/impls/ocl/primitive_base.hpp @@ -35,6 +35,9 @@ struct typed_primitive_impl_ocl : public typed_primitive_impl { std::vector _cached_kernel_ids; std::vector _kernels; + // a pair of batch program hash and kernel entry hash of each ocl impl. + std::pair kernel_dump_info; + typed_primitive_impl_ocl() : _kernel_data({}), _cached_kernel_ids({}), _kernels({}) { _kernel_data.weightsReorderParams.engine = kernel_selector::generic_kernel_params::Engine::NONE; _kernel_data.weightsReorderParams.cpuKernel = nullptr; @@ -142,8 +145,11 @@ protected: if (!_kernel_data.kernels.empty()) { auto compiled_kernels = kernels_cache.get_kernels(params); _kernels.insert(_kernels.begin(), compiled_kernels.begin(), compiled_kernels.end()); + // batch program hash and kernel entry point to find corresponding cl source code + kernel_dump_info = std::make_pair(std::to_string(kernels_cache.get_kernel_batch_hash(params)), + _kernel_data.kernels[0].code.kernelString->entry_point); } - } + } void init_by_cached_kernels(const kernels_cache& kernels_cache) override { if (is_cpu()) { @@ -306,6 +312,10 @@ protected: std::vector get_kernels() override { return _kernels; } + + std::pair get_kernels_dump_info() const override { + return kernel_dump_info; + } }; } // namespace ocl diff --git a/src/plugins/intel_gpu/src/graph/include/primitive_inst.h b/src/plugins/intel_gpu/src/graph/include/primitive_inst.h index 3c393d111ed..3b7d4321d2a 100644 --- a/src/plugins/intel_gpu/src/graph/include/primitive_inst.h +++ b/src/plugins/intel_gpu/src/graph/include/primitive_inst.h @@ -69,6 +69,10 @@ struct primitive_impl { virtual std::vector get_kernels() const { return {}; } virtual void save(cldnn::BinaryOutputBuffer& ob) const {} virtual void load(cldnn::BinaryInputBuffer& ib) {} + // returns a pair of batch program hash and kernel entry of each ocl impl. Returns "" for other impl types. + virtual std::pair get_kernels_dump_info() const { + return std::make_pair("", ""); + } // If this flag is set as false, the memory allocated for this primitive is not allowed to be reused bool can_reuse_memory = true; diff --git a/src/plugins/intel_gpu/src/graph/program_dump_graph.cpp b/src/plugins/intel_gpu/src/graph/program_dump_graph.cpp index ea02db87a66..a21afff32dd 100644 --- a/src/plugins/intel_gpu/src/graph/program_dump_graph.cpp +++ b/src/plugins/intel_gpu/src/graph/program_dump_graph.cpp @@ -207,8 +207,16 @@ void dump_graph_init(std::ofstream& graph, if (!node->is_type()) { graph << "\\n Selected kernel: " << (node->get_selected_impl() == nullptr ? "none" - : node->get_selected_impl()->get_kernel_name()) + " / " + : (node->get_preferred_impl_type() == impl_types::ocl && node->get_selected_impl()->get_kernels_dump_info().second.size()) + ? node->get_selected_impl()->get_kernels_dump_info().second + : node->get_selected_impl()->get_kernel_name()) + " / " << node->get_preferred_impl_type(); + if (node->get_selected_impl()) { + auto dump_info = node->get_selected_impl()->get_kernels_dump_info(); + if (dump_info.first.size()) { + graph << "\\n batch_hash : " << dump_info.first; + } + } } graph << "\n" + dump_mem_info(node); graph << "\""; diff --git a/src/plugins/intel_gpu/src/graph/program_node.cpp b/src/plugins/intel_gpu/src/graph/program_node.cpp index b1caaad5a92..34d3829a690 100644 --- a/src/plugins/intel_gpu/src/graph/program_node.cpp +++ b/src/plugins/intel_gpu/src/graph/program_node.cpp @@ -190,6 +190,13 @@ std::unique_ptr program_node::desc_to_json() const { #pragma clang diagnostic ignored "-Wpotentially-evaluated-expression" #endif impls.push_back(selected_impl->get_kernel_name()); + + if (get_preferred_impl_type() == impl_types::ocl) { + json_composite cl_dump_info; + cl_dump_info.add("batch_hash", selected_impl->get_kernels_dump_info().first); + cl_dump_info.add("kernel_entry", selected_impl->get_kernels_dump_info().second); + node_info->add("cl dump_ info", cl_dump_info); + } #ifdef __clang__ #pragma clang diagnostic pop #endif diff --git a/src/plugins/intel_gpu/src/runtime/kernels_cache.cpp b/src/plugins/intel_gpu/src/runtime/kernels_cache.cpp index 074f1a01aac..a6769887163 100644 --- a/src/plugins/intel_gpu/src/runtime/kernels_cache.cpp +++ b/src/plugins/intel_gpu/src/runtime/kernels_cache.cpp @@ -291,6 +291,9 @@ void kernels_cache::build_batch(const engine& build_engine, const batch_program& } else { compiled_kernels[params] = { std::make_pair(kernel, kernel_part_idx) }; } + if (_kernel_batch_hash.find(params) == _kernel_batch_hash.end()) { + _kernel_batch_hash[params] = batch.hash_value; + } } else { throw std::runtime_error("Could not find entry point"); } @@ -447,6 +450,7 @@ void kernels_cache::build_all() { void kernels_cache::reset() { _kernels.clear(); _kernels_code.clear(); + _kernel_batch_hash.clear(); _pending_compilation = false; } diff --git a/src/plugins/intel_gpu/src/runtime/kernels_cache.hpp b/src/plugins/intel_gpu/src/runtime/kernels_cache.hpp index 9412104d46f..be1d51a7706 100644 --- a/src/plugins/intel_gpu/src/runtime/kernels_cache.hpp +++ b/src/plugins/intel_gpu/src/runtime/kernels_cache.hpp @@ -84,7 +84,7 @@ private: std::map, uint32_t> _cached_binaries; std::unordered_map _cached_kernels; std::vector batch_header_str; - + std::unordered_map _kernel_batch_hash; void get_program_source(const kernels_code& kernels_source_code, std::vector*) const; void build_batch(const engine& build_engine, const batch_program& batch, compiled_kernels& compiled_kernels); @@ -121,6 +121,12 @@ public: std::vector get_cached_kernel_ids(const std::vector& kernels) const; void add_to_cached_kernels(const std::vector& kernels); + size_t get_kernel_batch_hash(const kernel_impl_params params) const { + if (_kernel_batch_hash.find(params) != _kernel_batch_hash.end()) + return _kernel_batch_hash.at(params); + return 0; + } + void save(BinaryOutputBuffer& ob) const; void load(BinaryInputBuffer& ib); };