OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[GPU] Added support of unlimited buffer allocations (#32189)
Roman Lyamind833d613a78e
diff --git a/src/inference/include/openvino/runtime/intel_gpu/properties.hpp b/src/inference/include/openvino/runtime/intel_gpu/properties.hppindex 326451712c5..60fbb4d5f3f 100644--- a/src/inference/include/openvino/runtime/intel_gpu/properties.hpp+++ b/src/inference/include/openvino/runtime/intel_gpu/properties.hpp@@ -158,6 +158,15 @@ static constexpr Property<bool> enable_kernels_reuse{"GPU_ENABLE_KERNELS_REUSE"}static constexpr Property<uint64_t, PropertyMutability::RW> dynamic_quantization_group_size_max{"GPU_DYNAMIC_QUANTIZATION_GROUP_SIZE_MAX"};+/**+ * @brief Turning on this key switches addressing mode to allow allocations larger than 4GB+ * as described here:+ * https://github.com/intel/compute-runtime/blob/master/programmers-guide/ALLOCATIONS_GREATER_THAN_4GB.md#creating-allocations-greater-than-4GB+ * Note: Performance may be lower with this option enabled.+ * @ingroup ov_runtime_ocl_gpu_prop_cpp_api+ */+static constexpr Property<bool> enable_large_allocations{"GPU_ENABLE_LARGE_ALLOCATIONS"};+} // namespace hint/**diff --git a/src/plugins/intel_gpu/include/intel_gpu/runtime/engine.hpp b/src/plugins/intel_gpu/include/intel_gpu/runtime/engine.hppindex e70c7e4a979..67648d15fe9 100644--- a/src/plugins/intel_gpu/include/intel_gpu/runtime/engine.hpp+++ b/src/plugins/intel_gpu/include/intel_gpu/runtime/engine.hpp@@ -145,6 +145,10 @@ public:virtual allocation_type detect_usm_allocation_type(const void* memory) const = 0;+ void set_enable_large_allocations(bool enable_large_allocations);++ bool get_enable_large_allocations() const;+#ifdef ENABLE_ONEDNN_FOR_GPU/// Creates onednn engine object which shares device and context with current enginevirtual void create_onednn_engine(const ExecutionConfig& config) = 0;@@ -161,20 +165,19 @@ public:/// @param engine_type requested engine type/// @param runtime_type requested execution runtime for the engine. @note some runtime/engine types configurations might be unsupported/// @param device specifies the device which the engine is created for- /// @param configuration options for the enginestatic std::shared_ptr<cldnn::engine> create(engine_types engine_type, runtime_types runtime_type, const device::ptr device);/// Factory method which creates engine object with impl configured by @p engine_type/// @param engine_type requested engine type/// @param runtime_type requested execution runtime for the engine. @note some runtime/engine types configurations might be unsupported- /// @param configuration options for the engine/// @note engine is created for the first device returned by devices querystatic std::shared_ptr<cldnn::engine> create(engine_types engine_type, runtime_types runtime_type);protected:- /// Create engine for given @p device and @p configuration+ /// Create engine for given @p deviceengine(const device::ptr device);const device::ptr _device;+ bool enable_large_allocations;std::array<std::atomic<uint64_t>, static_cast<size_t>(allocation_type::max_value)> _memory_usage_data{};std::array<std::atomic<uint64_t>, static_cast<size_t>(allocation_type::max_value)> _peak_memory_usage_data{};diff --git a/src/plugins/intel_gpu/include/intel_gpu/runtime/options.inl b/src/plugins/intel_gpu/include/intel_gpu/runtime/options.inlindex 1546ea2a7c7..9bd1040846b 100644--- a/src/plugins/intel_gpu/include/intel_gpu/runtime/options.inl+++ b/src/plugins/intel_gpu/include/intel_gpu/runtime/options.inl@@ -19,7 +19,8 @@ OV_CONFIG_RELEASE_OPTION(ov::intel_gpu::hint, host_task_priority, ov::hint::PrioOV_CONFIG_RELEASE_OPTION(ov::intel_gpu::hint, queue_throttle, ov::intel_gpu::hint::ThrottleLevel::MEDIUM, "Low-level hint that controls the queue throttle level")OV_CONFIG_RELEASE_OPTION(ov::intel_gpu::hint, queue_priority, ov::hint::Priority::MEDIUM, "Low-level hint that controls queue priority property")OV_CONFIG_RELEASE_OPTION(ov::intel_gpu::hint, enable_sdpa_optimization, true, "Enable/Disable fused SDPA primitive execution")-OV_CONFIG_RELEASE_OPTION(ov::intel_gpu::hint, enable_lora_operation, true, "Enable/Disable LoRA operation. The separate operation is less versatile, but has better performance.")+OV_CONFIG_RELEASE_OPTION(ov::intel_gpu::hint, enable_lora_operation, true, "Enable/Disable LoRA operation. The separate operation is less versatile, but has better performance")+OV_CONFIG_RELEASE_OPTION(ov::intel_gpu::hint, enable_large_allocations, false, "Enable/Disable large buffer allocations (>4gb). Enabling this option may lead to performance degradation")OV_CONFIG_RELEASE_OPTION(ov::intel_gpu, enable_loop_unrolling, true, "Enable/Disable Loop/TensorIterator operation unrolling")OV_CONFIG_RELEASE_OPTION(ov::intel_gpu, disable_winograd_convolution, false, "Enable/Disable winograd convolution implementation if available")OV_CONFIG_RELEASE_OPTION(ov::internal, exclusive_async_requests, false, "")diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl/kernel_selector_helper.cpp b/src/plugins/intel_gpu/src/graph/impls/ocl/kernel_selector_helper.cppindex 462479b8615..5c746a85c34 100644--- a/src/plugins/intel_gpu/src/graph/impls/ocl/kernel_selector_helper.cpp+++ b/src/plugins/intel_gpu/src/graph/impls/ocl/kernel_selector_helper.cpp@@ -1164,6 +1164,7 @@ void set_params(const kernel_impl_params& param_info, kernel_selector::params& pparams.engineInfo.supports_imad = device_info.supports_imad;params.engineInfo.supports_immad = device_info.supports_immad;params.engineInfo.enable_sub_groups_emulation = true;+ params.engineInfo.enable_large_allocations = config.get_enable_large_allocations();params.engineInfo.bOptHintsSupport = false;params.engineInfo.supports_microkernels = query_microkernels_supported(engine, config);diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/utils/kernel_generator.cpp b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/utils/kernel_generator.cppindex 3c098ff5c6a..e28b42cccf7 100644--- a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/utils/kernel_generator.cpp+++ b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/utils/kernel_generator.cpp@@ -119,9 +119,13 @@ std::string KernelGenerator::get_entry_point(const RuntimeParams& params) conststd::string KernelGenerator::get_build_options(const RuntimeParams& params) const {std::string options;- const auto& device_info = params.get_program().get_engine().get_device_info();+ const auto& prog = params.get_program();+ const auto& device_info = prog.get_engine().get_device_info();if (device_info.vendor_id == cldnn::INTEL_VENDOR_ID) {options = " -cl-mad-enable";++ if (prog.get_config().get_enable_large_allocations())+ options += " -cl-intel-greater-than-4GB-buffer-required";}if (device_info.supports_work_group_collective_functions)diff --git a/src/plugins/intel_gpu/src/graph/program.cpp b/src/plugins/intel_gpu/src/graph/program.cppindex 91ba502977a..151da9aae1a 100644--- a/src/plugins/intel_gpu/src/graph/program.cpp+++ b/src/plugins/intel_gpu/src/graph/program.cpp@@ -161,6 +161,7 @@ program::program(engine& engine_ref,_compilation_context(compilation_context) {init_primitives();_config.finalize(_engine);+ _engine.set_enable_large_allocations(_config.get_enable_large_allocations());GPU_DEBUG_INFO << "Program config\n" << _config.to_string();init_program();prepare_nodes(topology);@@ -203,6 +204,7 @@ program::program(engine& engine_ref,processing_order(),is_internal(is_internal) {_config.finalize(_engine);+ _engine.set_enable_large_allocations(_config.get_enable_large_allocations());init_primitives();init_program();prepare_nodes(nodes);@@ -216,6 +218,7 @@ program::program(engine& engine, const ExecutionConfig& config)processing_order() {init_primitives();_config.finalize(_engine);+ _engine.set_enable_large_allocations(_config.get_enable_large_allocations());new_shape_infer = _config.get_allow_new_shape_infer();_layout_optimizer = std::make_unique<layout_optimizer>();}@@ -488,6 +491,7 @@ void program::set_options() {void program::build_program(bool is_internal) {init_graph();_config.finalize(_engine);+ _engine.set_enable_large_allocations(_config.get_enable_large_allocations());{ pre_optimize_graph(is_internal); }run_graph_compilation();{ post_optimize_graph(is_internal); }@@ -1691,7 +1695,7 @@ std::pair<int64_t, int64_t> program::get_estimated_device_mem_usage() {std::unordered_set<memory::ptr> allocated_mem_ptrs;for (const auto& node : nodes_to_allocate) {auto out_size = node->get_output_layout().bytes_count();- if (out_size > max_alloc_size) {+ if (out_size > max_alloc_size && !get_config().get_enable_large_allocations()) {// to consider: if the base batch size is > 1, should we allow this single output allocation to host?host_alloc += out_size;continue;diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernel_base_opencl.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernel_base_opencl.cppindex df34709483b..f66e7eeae8c 100644--- a/src/plugins/intel_gpu/src/kernel_selector/kernel_base_opencl.cpp+++ b/src/plugins/intel_gpu/src/kernel_selector/kernel_base_opencl.cpp@@ -175,6 +175,8 @@ std::shared_ptr<KernelString> KernelBaseOpenCL::GetKernelString(const std::strinkernel_string->options = exe_mode + " -cl-mad-enable";if (engine_info.bOptHintsSupport)kernel_string->options += " -DOPT_HINTS_SUPPORTED=1";+ if (engine_info.enable_large_allocations)+ kernel_string->options += " -cl-intel-greater-than-4GB-buffer-required";}if (engine_info.supports_work_group_collective_functions)diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_params.h b/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_params.hindex 37a483a1751..c0381d6e1e3 100644--- a/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_params.h+++ b/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_params.h@@ -386,6 +386,7 @@ struct EngineInfo {bool supports_imad = false;bool supports_immad = false;bool enable_sub_groups_emulation = false;+ bool enable_large_allocations = false;bool bOptHintsSupport = false;bool supports_microkernels = false;bool supports_work_group_collective_functions = false;diff --git a/src/plugins/intel_gpu/src/runtime/engine.cpp b/src/plugins/intel_gpu/src/runtime/engine.cppindex 3af715d2ccc..7cbf0ed7e77 100644--- a/src/plugins/intel_gpu/src/runtime/engine.cpp+++ b/src/plugins/intel_gpu/src/runtime/engine.cpp@@ -246,6 +246,14 @@ void engine::subtract_memory_used(uint64_t bytes, allocation_type type) {_memory_usage_data[idx] -= bytes;}+void engine::set_enable_large_allocations(bool enable_large_allocations) {+ this->enable_large_allocations = enable_large_allocations;+}++bool engine::get_enable_large_allocations() const {+ return enable_large_allocations;+}+std::shared_ptr<cldnn::engine> engine::create(engine_types engine_type, runtime_types runtime_type, const device::ptr device) {std::shared_ptr<cldnn::engine> ret;switch (engine_type) {diff --git a/src/plugins/intel_gpu/src/runtime/ocl/ocl_engine.cpp b/src/plugins/intel_gpu/src/runtime/ocl/ocl_engine.cppindex 3c9d8a61f89..35cef4bafb8 100644--- a/src/plugins/intel_gpu/src/runtime/ocl/ocl_engine.cpp+++ b/src/plugins/intel_gpu/src/runtime/ocl/ocl_engine.cpp@@ -100,19 +100,21 @@ allocation_type ocl_engine::detect_usm_allocation_type(const void* memory) constbool ocl_engine::check_allocatable(const layout& layout, allocation_type type) {OPENVINO_ASSERT(supports_allocation(type) || type == allocation_type::cl_mem, "[GPU] Unsupported allocation type: ", type);- bool exceed_allocatable_mem_size = (layout.bytes_count() > get_device_info().max_alloc_mem_size);+ if (!get_enable_large_allocations()) {+ bool exceed_allocatable_mem_size = (layout.bytes_count() > get_device_info().max_alloc_mem_size);- // When dynamic shape upper bound makes bigger buffer, then return false.- if (exceed_allocatable_mem_size && layout.is_dynamic()) {- OPENVINO_ASSERT(layout.has_upper_bound(), "[GPU] Dynamic shape without upper bound tries to allocate");- return false;- }+ // When dynamic shape upper bound makes bigger buffer, then return false.+ if (exceed_allocatable_mem_size && layout.is_dynamic()) {+ OPENVINO_ASSERT(layout.has_upper_bound(), "[GPU] Dynamic shape without upper bound tries to allocate");+ return false;+ }- OPENVINO_ASSERT(!exceed_allocatable_mem_size,- "[GPU] Exceeded max size of memory object allocation: ",- "requested ", layout.bytes_count(), " bytes, "- "but max alloc size supported by device is ", get_device_info().max_alloc_mem_size, " bytes.",- "Please try to reduce batch size or use lower precision.");+ OPENVINO_ASSERT(!exceed_allocatable_mem_size,+ "[GPU] Exceeded max size of memory object allocation: ",+ "requested ", layout.bytes_count(), " bytes, "+ "but max alloc size supported by device is ", get_device_info().max_alloc_mem_size, " bytes.",+ "Please try to reduce batch size or use lower precision.");+ }auto used_mem = get_used_device_memory(allocation_type::usm_device) + get_used_device_memory(allocation_type::usm_host);auto exceed_available_mem_size = (layout.bytes_count() + used_mem > get_max_memory_size());diff --git a/src/plugins/intel_gpu/src/runtime/ocl/ocl_ext.hpp b/src/plugins/intel_gpu/src/runtime/ocl/ocl_ext.hppindex 76c2b3ddfcb..a1a74c65eda 100644--- a/src/plugins/intel_gpu/src/runtime/ocl/ocl_ext.hpp+++ b/src/plugins/intel_gpu/src/runtime/ocl/ocl_ext.hpp@@ -326,6 +326,8 @@ CL_HPP_PARAM_NAME_CL_INTEL_COMMAND_QUEUE_FAMILIES_(CL_HPP_DECLARE_PARAM_TRAITS_)#endif // OPENVINO_CLHPP_HEADERS_ARE_OLDER_THAN_V2024_10_24+#define CL_MEM_ALLOW_UNRESTRICTED_SIZE_INTEL (1 << 23)+#include <memory>namespace {@@ -972,23 +974,23 @@ public:// Get methods returns original pointer allocated by openCL.void* get() const { return _usm_pointer->ptr(); }- void allocateHost(size_t size) {+ void allocateHost(size_t size, const cl_mem_properties_intel* properties = nullptr) {cl_int error = CL_SUCCESS;- auto ptr = _usmHelper.allocate_host(nullptr, size, 0, &error);+ auto ptr = _usmHelper.allocate_host(properties, size, 0, &error);_check_error(size, ptr, error, "Host");_allocate(ptr);}- void allocateShared(size_t size) {+ void allocateShared(size_t size, const cl_mem_properties_intel* properties = nullptr) {cl_int error = CL_SUCCESS;- auto ptr = _usmHelper.allocate_shared(nullptr, size, 0, &error);+ auto ptr = _usmHelper.allocate_shared(properties, size, 0, &error);_check_error(size, ptr, error, "Shared");_allocate(ptr);}- void allocateDevice(size_t size) {+ void allocateDevice(size_t size, const cl_mem_properties_intel* properties = nullptr) {cl_int error = CL_SUCCESS;- auto ptr = _usmHelper.allocate_device(nullptr, size, 0, &error);+ auto ptr = _usmHelper.allocate_device(properties, size, 0, &error);_check_error(size, ptr, error, "Device");_allocate(ptr);}diff --git a/src/plugins/intel_gpu/src/runtime/ocl/ocl_memory.cpp b/src/plugins/intel_gpu/src/runtime/ocl/ocl_memory.cppindex 1528f546181..636939dca7e 100644--- a/src/plugins/intel_gpu/src/runtime/ocl/ocl_memory.cpp+++ b/src/plugins/intel_gpu/src/runtime/ocl/ocl_memory.cpp@@ -499,19 +499,24 @@ gpu_usm::gpu_usm(ocl_engine* engine, const layout& layout, allocation_type type)auto actual_bytes_count = _bytes_count;if (actual_bytes_count == 0)actual_bytes_count = 1;++ std::vector<cl_mem_properties_intel> properties = {0};+ if (engine->get_enable_large_allocations()) {+ properties = {CL_MEM_FLAGS, CL_MEM_ALLOW_UNRESTRICTED_SIZE_INTEL, 0};+ }+switch (get_allocation_type()) {case allocation_type::usm_host:- _buffer.allocateHost(actual_bytes_count);+ _buffer.allocateHost(actual_bytes_count, &properties[0]);break;case allocation_type::usm_shared:- _buffer.allocateShared(actual_bytes_count);+ _buffer.allocateShared(actual_bytes_count, &properties[0]);break;case allocation_type::usm_device:- _buffer.allocateDevice(actual_bytes_count);+ _buffer.allocateDevice(actual_bytes_count, &properties[0]);break;default:- CLDNN_ERROR_MESSAGE("gpu_usm allocation type",- "Unknown unified shared memory type!");+ OPENVINO_THROW("[GPU] gpu_usm allocation type: unknown unified shared memory type!");}m_mem_tracker = std::make_shared<MemoryTracker>(engine, _buffer.get(), actual_bytes_count, type);diff --git a/src/plugins/intel_gpu/tests/unit/module_tests/engine_test.cpp b/src/plugins/intel_gpu/tests/unit/module_tests/engine_test.cppindex 45d9df9b744..c79399cc427 100644--- a/src/plugins/intel_gpu/tests/unit/module_tests/engine_test.cpp+++ b/src/plugins/intel_gpu/tests/unit/module_tests/engine_test.cpp@@ -53,3 +53,24 @@ TEST(engine, memory_creation) {ASSERT_FALSE(mem->is_allocated_by(engine));ASSERT_EQ(std::dynamic_pointer_cast<simple_attached_memory>(mem)->lock(get_test_stream(), mem_lock_type::read), host_data.data());}++TEST(engine, large_allocation) {+ // This test is used for manual testing only.+ GTEST_SKIP();++ auto& engine = get_test_engine();++ std::shared_ptr<memory> mem = nullptr;+ ov::Shape sz_6gb = {6, 1024, 1024, 1024};+ layout layout_to_allocate = {sz_6gb, data_types::u8, format::bfyx};++ engine.set_enable_large_allocations(true);++ if (engine.supports_allocation(allocation_type::usm_device) && ov::shape_size(sz_6gb) < engine.get_device_info().max_global_mem_size) {+ OV_ASSERT_NO_THROW(mem = engine.allocate_memory(layout_to_allocate, allocation_type::usm_host));+ ASSERT_NE(mem, nullptr);+ ASSERT_EQ(mem->get_layout(), layout_to_allocate);+ ASSERT_NE(std::dynamic_pointer_cast<ocl::gpu_usm>(mem), nullptr);+ ASSERT_TRUE(mem->is_allocated_by(engine));+ }+}diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/reduce_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/reduce_gpu_test.cppindex b5368ba3122..192f919ff5e 100644--- a/src/plugins/intel_gpu/tests/unit/test_cases/reduce_gpu_test.cpp+++ b/src/plugins/intel_gpu/tests/unit/test_cases/reduce_gpu_test.cpp@@ -2291,3 +2291,62 @@ INSTANTIATE_TEST_SUITE_P(reduce_scalar_output_f16_f16,TestParamType_general_reduce_gpu(1, 1, 1, 1, 1024, 1, format::bfyx, reduce_mode::min, {3, 2, 1, 0}, "reduce_simple_to_scalar", false, data_types::f16, false, data_types::f16),TestParamType_general_reduce_gpu(1, 1, 1, 1, 1025, 1, format::bfyx, reduce_mode::min, {3, 2, 1, 0}, "reduce_simple_to_scalar", false, data_types::f16, false, data_types::f16)), general_reduce_gpu::PrintToStringParamName);++TEST(reduce_f32_fw_gpu, large_buffer) {+ // This test is used for manual testing only.+ GTEST_SKIP();++ auto engine = create_test_engine();+ engine->set_enable_large_allocations(true);++ size_t s0 = 16384;+ size_t s1 = 256 * (256 + 128);+ ov::Shape sz_6gb = { 1, 1, s1, s0 }; // *4 bytes;+ size_t peak_mem_usage = (ov::shape_size(sz_6gb) + s0) * sizeof(float);+ if (engine->get_device_info().max_global_mem_size < peak_mem_usage)+ GTEST_SKIP();++ layout in_l = { sz_6gb, data_types::f32, format::bfyx };++ auto config = get_test_default_config(*engine);+ ov::intel_gpu::ImplementationDesc reduce_impl = {format::bfyx, "", impl_types::any};+ if (engine->get_device_info().supports_immad) {+ reduce_impl.impl_type = impl_types::onednn;+ } else {+ reduce_impl.impl_type = impl_types::ocl;+ }+ config.set_property(ov::intel_gpu::force_implementations(ov::intel_gpu::ImplForcingMap{{"reduce", reduce_impl}}));++ topology topology(input_layout("input", in_l),+ reduce("reduce", input_info("input"), reduce_mode::mean, {2}, true));+ network network(*engine, topology, config);+ auto input = network.get_output_memory("input");+ {+ mem_lock<float, mem_lock_type::write> l(input, get_test_stream());+ const size_t test_size = ov::shape_size(sz_6gb);+ for (size_t i = 0; i < test_size; i++) {+ l[i] = static_cast<float>(i) / s0;+ }+ }++ network.set_input_data("input", input);+ auto outputs = network.execute();+ ASSERT_EQ(outputs.size(), size_t(1));+ ASSERT_EQ(outputs.begin()->first, "reduce");++ auto output_memory = outputs.at("reduce").get_memory();+ auto output_layout = output_memory->get_layout();+ cldnn::mem_lock<float, mem_lock_type::read> output_ptr(output_memory, get_test_stream());++ ASSERT_EQ(output_layout.format, format::bfyx);+ ASSERT_EQ(output_layout.get_linear_size(), s0);++ // ensure that single 6GB buffer is allocated+ ASSERT_EQ(engine->get_max_used_device_memory(), peak_mem_usage);++ size_t sum = s1 * (s1 - 1) / 2;+ float mean = static_cast<float>(sum) / static_cast<float>(s1);+ for (size_t i = 0; i < s0; i++) {+ ASSERT_NEAR(mean, output_ptr[i], 1.0f);+ }+}diff --git a/src/plugins/intel_gpu/tests/unit/test_utils/test_utils.cpp b/src/plugins/intel_gpu/tests/unit/test_utils/test_utils.cppindex 4e3942cf578..e4fbb1f3d3b 100644--- a/src/plugins/intel_gpu/tests/unit/test_utils/test_utils.cpp+++ b/src/plugins/intel_gpu/tests/unit/test_utils/test_utils.cpp@@ -298,6 +298,10 @@ cldnn::ExecutionConfig get_test_default_config(const cldnn::engine& engine,config.set_property(ov::intel_gpu::queue_type(QueueTypes::in_order));}+ if (engine.get_enable_large_allocations()) {+ config.set_property(ov::intel_gpu::hint::enable_large_allocations(true));+ }+return config;}