diff --git a/level_zero/core/source/device/device_imp.cpp b/level_zero/core/source/device/device_imp.cpp index 16233db088..1ef8f4c80b 100644 --- a/level_zero/core/source/device/device_imp.cpp +++ b/level_zero/core/source/device/device_imp.cpp @@ -1166,7 +1166,8 @@ ze_result_t DeviceImp::getCacheProperties(uint32_t *pCount, ze_device_cache_prop } ze_result_t DeviceImp::reserveCache(size_t cacheLevel, size_t cacheReservationSize) { - if (getOsInterface().getDriverModel()->getDriverModelType() != NEO::DriverModelType::drm) { + auto osInterface = neoDevice->getRootDeviceEnvironment().osInterface.get(); + if (!osInterface || osInterface->getDriverModel()->getDriverModelType() != NEO::DriverModelType::drm) { return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; } @@ -1187,7 +1188,8 @@ ze_result_t DeviceImp::reserveCache(size_t cacheLevel, size_t cacheReservationSi } ze_result_t DeviceImp::setCacheAdvice(void *ptr, size_t regionSize, ze_cache_ext_region_t cacheRegion) { - if (getOsInterface().getDriverModel()->getDriverModelType() != NEO::DriverModelType::drm) { + auto osInterface = neoDevice->getRootDeviceEnvironment().osInterface.get(); + if (!osInterface || osInterface->getDriverModel()->getDriverModelType() != NEO::DriverModelType::drm) { return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; } diff --git a/level_zero/core/test/unit_tests/sources/device/test_l0_device.cpp b/level_zero/core/test/unit_tests/sources/device/test_l0_device.cpp index af192b8d42..b7cd53bed2 100644 --- a/level_zero/core/test/unit_tests/sources/device/test_l0_device.cpp +++ b/level_zero/core/test/unit_tests/sources/device/test_l0_device.cpp @@ -840,6 +840,12 @@ TEST_F(DeviceTest, givenNonEmptyAllocationsListAndUnproperAllocationTypeWhenRequ EXPECT_FALSE(deviceImp->allocationsForReuse->peekIsEmpty()); } +TEST_F(DeviceTest, givenNoOsInterfaceWhenUseCacheReservationApiThenUnsupportedFeatureErrorIsReturned) { + EXPECT_EQ(nullptr, neoDevice->getRootDeviceEnvironment().osInterface.get()); + EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, device->reserveCache(0, 0)); + EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, device->setCacheAdvice(nullptr, 0, ze_cache_ext_region_t::ZE_CACHE_EXT_REGION_ZE_CACHE_REGION_DEFAULT)); +} + struct DeviceHostPointerTest : public ::testing::Test { void SetUp() override { executionEnvironment = new NEO::ExecutionEnvironment();