Skip to content

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

[GPU] ZE sub_buffer_base_alignment (#39829)

Michal Miotkb44d02165f42
diff --git a/src/plugins/intel_gpu/src/runtime/ze/ze_device.cpp b/src/plugins/intel_gpu/src/runtime/ze/ze_device.cpp
index 5084dbd7087..13926850df8 100644
--- a/src/plugins/intel_gpu/src/runtime/ze/ze_device.cpp
+++ b/src/plugins/intel_gpu/src/runtime/ze/ze_device.cpp
@@ -182,6 +182,22 @@ device_info init_device_info(ze_driver_handle_t driver, ze_device_handle_t devic
if (ze::zeDeviceGetCacheProperties(device, &count, &devCacheProps) == ZE_RESULT_SUCCESS) {
info.cacheline_size = static_cast<uint32_t>(devCacheLineSize.cacheLineSize);
}
+
+ // Level Zero has no CL_DEVICE_MEM_BASE_ADDR_ALIGN equivalent; query it through the OCL interop
+ // device when available, same as ocl_device.cpp. Falls back to 128 otherwise.
+ // Compute Runtime currently defines memBaseAddressAlign as 1024 bits: https://github.com/intel/compute-runtime/blob/master/level_zero/api/opencl/source/cl_device/leo_cl_device_caps.cpp#L242
+ // Its sub-buffer check converts the bit count to bytes by dividing by 8: https://github.com/intel/compute-runtime/blob/master/level_zero/api/opencl/source/mem_obj/leo_buffer.cpp#L260
+ auto& ocl_interop = ze_ocl_interop::get_instance();
+ if (ocl_interop.check_support(device)) {
+ cl_uint bits = 0;
+ if (clGetDeviceInfo(ocl_interop.find_ocl_device(device), CL_DEVICE_MEM_BASE_ADDR_ALIGN, sizeof(bits), &bits, nullptr) == CL_SUCCESS) {
+ info.sub_buffer_base_alignment = std::max<uint32_t>(1, bits / 8);
+ }
+ }
+ if (!info.sub_buffer_base_alignment.has_value()) {
+ GPU_DEBUG_LOG << "WARNING: Failed to query sub-buffer base alignment through OCL interop; using 128 bytes" << std::endl;
+ info.sub_buffer_base_alignment = 128;
+ }
info.execution_units_count = device_properties.numEUsPerSubslice * device_properties.numSubslicesPerSlice * device_properties.numSlices;
diff --git a/src/plugins/intel_gpu/src/runtime/ze/ze_engine.cpp b/src/plugins/intel_gpu/src/runtime/ze/ze_engine.cpp
index 643ce9c7013..542d951a1f4 100644
--- a/src/plugins/intel_gpu/src/runtime/ze/ze_engine.cpp
+++ b/src/plugins/intel_gpu/src/runtime/ze/ze_engine.cpp
@@ -170,6 +170,14 @@ memory_ptr ze_engine::create_subbuffer(const memory& memory, const layout& new_l
OPENVINO_NOT_IMPLEMENTED;
}
OPENVINO_ASSERT(memory_capabilities::is_usm_type(memory.get_allocation_type()), "[GPU] Trying to create subbuffer for non usm memory");
+ OPENVINO_ASSERT(byte_offset <= memory.size() && new_layout.bytes_count() <= memory.size() - byte_offset,
+ "[GPU] Sub-buffer size (",
+ new_layout.bytes_count(),
+ ") + offset (",
+ byte_offset,
+ ") exceeds parent buffer size (",
+ memory.size(),
+ ")");
const auto& new_buf = reinterpret_cast<const ze::gpu_usm&>(memory);
auto* ptr = new_buf.buffer_ptr();
auto ctx = get_context();
diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/behavior/ov_plugin/caching_tests.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/behavior/ov_plugin/caching_tests.cpp
index 378ab71ba92..1a1e91f873f 100644
--- a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/behavior/ov_plugin/caching_tests.cpp
+++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/behavior/ov_plugin/caching_tests.cpp
@@ -4,11 +4,17 @@
#include "behavior/ov_plugin/caching_tests.hpp"
+#include <cmath>
#include <cstdlib>
#include <filesystem>
+#include "openvino/op/constant.hpp"
+#include "openvino/op/matmul.hpp"
+#include "openvino/op/parameter.hpp"
#include "openvino/pass/manager.hpp"
#include "openvino/pass/serialize.hpp"
+#include "openvino/util/native_streambuf.hpp"
+#include "openvino/util/parallel_io.hpp"
#include "common_test_utils/file_utils.hpp"
#include "functional_test_utils/skip_tests_config.hpp"
#include "common_test_utils/subgraph_builders/conv_pool_relu.hpp"
@@ -106,16 +112,21 @@ INSTANTIATE_TEST_SUITE_P(smoke_CachingSupportCase_GPU,
::testing::ValuesIn(GPULoadFromFileConfigs)),
CompileModelLoadFromCacheTest::getTestCaseName);
-class CompileModelZeroCopySingleFileCacheLoadTest : public testing::WithParamInterface<CompileModelLoadFromCacheParams>,
+// Minimal exported blob size; 0 selects the small conv_pool_relu model.
+using ZeroCopySingleFileCacheLoadParams = std::tuple<std::string, ov::AnyMap, size_t>;
+
+class CompileModelZeroCopySingleFileCacheLoadTest : public testing::WithParamInterface<ZeroCopySingleFileCacheLoadParams>,
virtual public ov::test::SubgraphBaseTest,
virtual public OVPluginTestBase {
public:
- static std::string getTestCaseName(testing::TestParamInfo<CompileModelLoadFromCacheParams> obj) {
- return CompileModelLoadFromCacheTest::getTestCaseName(obj);
+ static std::string getTestCaseName(testing::TestParamInfo<ZeroCopySingleFileCacheLoadParams> obj) {
+ const auto& [device, config, min_blob_size] = obj.param;
+ return CompileModelLoadFromCacheTest::getTestCaseName({{device, config}, obj.index}) +
+ "_MinBlobSize=" + std::to_string(min_blob_size);
}
void SetUp() override {
- std::tie(targetDevice, configuration) = this->GetParam();
+ std::tie(targetDevice, configuration, m_minBlobSize) = this->GetParam();
target_device = targetDevice;
APIBaseTest::SetUp();
set_env("OV_GPU_ENABLE_ZERO_COPY_CACHE_LOAD", "YES");
@@ -131,7 +142,23 @@ public:
core->set_property(ov::cache_dir());
ov::pass::Manager manager;
manager.register_pass<ov::pass::Serialize>(m_modelName, m_weightsName);
- manager.run_passes(ov::test::utils::make_conv_pool_relu({1, 3, 227, 227}, ov::element::f32));
+ std::shared_ptr<ov::Model> model;
+ if (m_minBlobSize > 0) {
+ // Smallest square matrix whose FP16 weights (2 B per element) exceed m_minBlobSize,
+ // plus a small margin, so the blob lands slightly above the selected I/O threshold.
+ const auto channels = static_cast<size_t>(std::ceil(std::sqrt(m_minBlobSize / 2.0))) + 16;
+ auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, channels});
+ std::vector<float> values(channels * channels);
+ for (size_t i = 0; i < values.size(); ++i) {
+ values[i] = static_cast<float>(i % 251) / 251.f;
+ }
+ auto weights = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{channels, channels}, values);
+ auto matmul = std::make_shared<ov::op::v0::MatMul>(input, weights, false, true);
+ model = std::make_shared<ov::Model>(ov::OutputVector{matmul}, ov::ParameterVector{input});
+ } else {
+ model = ov::test::utils::make_conv_pool_relu({1, 3, 227, 227}, ov::element::f32);
+ }
+ manager.run_passes(model);
}
void TearDown() override {
@@ -152,17 +179,44 @@ public:
core->set_property(ov::cache_dir(m_cacheFilePath));
compiledModel = core->compile_model(m_modelName, targetDevice, configuration);
EXPECT_EQ(false, compiledModel.get_property(ov::loaded_from_cache.name()).as<bool>());
+ const auto expected_output = infer(compiledModel);
std::stringstream strm;
compiledModel.export_model(strm);
+ if (m_minBlobSize > 0) {
+ ASSERT_GT(strm.tellp(), std::streampos(m_minBlobSize));
+ }
ov::CompiledModel importedCompiledModel = core->import_model(strm, target_device, configuration);
EXPECT_EQ(false, importedCompiledModel.get_property(ov::loaded_from_cache.name()).as<bool>());
compiledModel = core->compile_model(m_modelName, targetDevice, configuration);
EXPECT_EQ(true, compiledModel.get_property(ov::loaded_from_cache.name()).as<bool>());
+
+ const auto actual_output = infer(compiledModel);
+ ASSERT_EQ(expected_output.size(), actual_output.size());
+ for (size_t i = 0; i < expected_output.size(); ++i) {
+ EXPECT_NEAR(expected_output[i], actual_output[i], 1e-4f) << "Output mismatch at index " << i;
+ }
}
private:
+ static std::vector<float> infer(ov::CompiledModel& model) {
+ auto request = model.create_infer_request();
+ auto input = request.get_input_tensor();
+ for (size_t i = 0; i < input.get_size(); ++i) {
+ input.data<float>()[i] = static_cast<float>(static_cast<int>(i % 17) - 8) * 0.01f;
+ }
+ request.infer();
+
+ auto output = request.get_output_tensor();
+ std::vector<float> values(output.get_size());
+ for (size_t i = 0; i < output.get_size(); ++i) {
+ values[i] = output.data<const float>()[i];
+ }
+ return values;
+ }
+
+ size_t m_minBlobSize = 0;
std::string m_modelName;
std::string m_weightsName;
std::string m_cacheFilePath;
@@ -175,7 +229,13 @@ TEST_P(CompileModelZeroCopySingleFileCacheLoadTest, CanLoadFromSingleFileCache)
INSTANTIATE_TEST_SUITE_P(smoke_ZeroCopySingleFileCacheLoad_GPU,
CompileModelZeroCopySingleFileCacheLoadTest,
::testing::Combine(::testing::Values(ov::test::utils::DEVICE_GPU),
- ::testing::Values(ov::AnyMap{})),
+ ::testing::Values(ov::AnyMap{}),
+ // Small model, then slightly above: NativeStreamBuf window bypass (2 MiB),
+ // ParallelMemStreamBuf file-backed path (4 MiB), NativeStreamBuf parallel reads (8 MiB).
+ ::testing::Values(size_t{0},
+ ov::util::default_native_threshold,
+ ov::util::default_parallel_io_threshold,
+ ov::util::default_native_window)),
CompileModelZeroCopySingleFileCacheLoadTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_CachingSupportCase_GPU,
CompileModelWithCacheEncryptionTest,
diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/skip_tests_config.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/skip_tests_config.cpp
index bb647c22a19..d228e90384e 100644
--- a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/skip_tests_config.cpp
+++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/skip_tests_config.cpp
@@ -39,6 +39,17 @@ bool is_xe2_or_newer() {
return false;
}
}
+
+// Mirrors engine::can_use_host_usm_zero_copy(): integrated Xe2+ GPU with USM support.
+bool canUseHostUsmZeroCopy() {
+ ov::Core ie = ov::test::utils::create_core();
+ if (ie.get_property(ov::test::utils::DEVICE_GPU, ov::device::type) != ov::device::Type::INTEGRATED)
+ return false;
+ auto caps = ie.get_property(ov::test::utils::DEVICE_GPU, ov::device::capabilities);
+ if (std::find(caps.begin(), caps.end(), ov::intel_gpu::capability::USM_MEMORY) == caps.end())
+ return false;
+ return is_xe2_or_newer();
+}
} // namespace
const std::vector<std::regex>& disabled_test_patterns() {
@@ -174,6 +185,10 @@ const std::vector<std::regex>& disabled_test_patterns() {
patterns.push_back(std::regex(R"(.*nightly_OVClassSetDefaultDeviceIDPropTest/OVClassSetDefaultDeviceIDPropTest.SetDefaultDeviceIDNoThrow/0.*)"));
patterns.push_back(std::regex(R"(.*nightly_OVClassSeveralDevicesTest/OVClassSeveralDevicesTestCompileModel.CompileModelActualSeveralDevicesNoThrow/0.*)"));
}
+ if (!canUseHostUsmZeroCopy()) {
+ // The suite only exercises the USM host zero-copy cache-load path.
+ patterns.push_back(std::regex(R"(.*smoke_ZeroCopySingleFileCacheLoad_GPU/.*)"));
+ }
if (immadSupported()) {
// Failure list
// Case (first 20 chars) Fail Count, Pass Count