diff --git a/level_zero/core/source/context/context_imp_drm/context_imp_drm.cpp b/level_zero/core/source/context/context_imp_drm/context_imp_drm.cpp index bde67c146b..a850cabd76 100644 --- a/level_zero/core/source/context/context_imp_drm/context_imp_drm.cpp +++ b/level_zero/core/source/context/context_imp_drm/context_imp_drm.cpp @@ -24,10 +24,11 @@ bool ContextImp::isShareableMemory(const void *exportDesc, bool exportableMemory void *ContextImp::getMemHandlePtr(ze_device_handle_t hDevice, uint64_t handle, NEO::AllocationType allocationType, ze_ipc_memory_flags_t flags) { auto neoDevice = Device::fromHandle(hDevice)->getNEODevice(); + auto &productHelper = neoDevice->getProductHelper(); + bool pidfdOrSocket = false; - if (NEO::debugManager.flags.EnablePidFdOrSocketsForIpc.get() != -1) { - pidfdOrSocket = !!(NEO::debugManager.flags.EnablePidFdOrSocketsForIpc.get()); - } + pidfdOrSocket = productHelper.isPidFdOrSocketForIpcSupported(); + if (pidfdOrSocket) { // With pidfd approach extract parent pid and target fd before importing handle pid_t exporterPid = 0; diff --git a/shared/source/os_interface/product_helper.h b/shared/source/os_interface/product_helper.h index 0556349025..2257cb57e7 100644 --- a/shared/source/os_interface/product_helper.h +++ b/shared/source/os_interface/product_helper.h @@ -270,6 +270,7 @@ class ProductHelper { virtual bool isExposingSubdevicesAllowed() const = 0; virtual bool useAdditionalBlitProperties() const = 0; virtual bool isNonCoherentTimestampsModeEnabled() const = 0; + virtual bool isPidFdOrSocketForIpcSupported() const = 0; virtual bool getStorageInfoLocalOnlyFlag(LocalMemAllocationMode usmDeviceAllocationMode, bool defaultValue) const = 0; virtual ~ProductHelper() = default; diff --git a/shared/source/os_interface/product_helper_before_xe2.inl b/shared/source/os_interface/product_helper_before_xe2.inl index 9d7da0d887..48e8cb2af5 100644 --- a/shared/source/os_interface/product_helper_before_xe2.inl +++ b/shared/source/os_interface/product_helper_before_xe2.inl @@ -58,4 +58,12 @@ bool ProductHelperHw::isNonCoherentTimestampsModeEnabled() const { return !this->isDcFlushAllowed(); } +template +bool ProductHelperHw::isPidFdOrSocketForIpcSupported() const { + if (debugManager.flags.EnablePidFdOrSocketsForIpc.get() != -1) { + return debugManager.flags.EnablePidFdOrSocketsForIpc.get(); + } + return false; +} + } // namespace NEO diff --git a/shared/source/os_interface/product_helper_hw.h b/shared/source/os_interface/product_helper_hw.h index 4fcfa34593..54c852a63c 100644 --- a/shared/source/os_interface/product_helper_hw.h +++ b/shared/source/os_interface/product_helper_hw.h @@ -208,6 +208,7 @@ class ProductHelperHw : public ProductHelper { bool useAdditionalBlitProperties() const override; bool isNonCoherentTimestampsModeEnabled() const override; bool getStorageInfoLocalOnlyFlag(LocalMemAllocationMode usmDeviceAllocationMode, bool defaultValue) const override; + bool isPidFdOrSocketForIpcSupported() const override; ~ProductHelperHw() override = default; diff --git a/shared/source/os_interface/product_helper_xe2_and_later.inl b/shared/source/os_interface/product_helper_xe2_and_later.inl index 858d8ecf9a..9d8ca84c9e 100644 --- a/shared/source/os_interface/product_helper_xe2_and_later.inl +++ b/shared/source/os_interface/product_helper_xe2_and_later.inl @@ -61,4 +61,12 @@ bool ProductHelperHw::isNonCoherentTimestampsModeEnabled() const { return true; } +template +bool ProductHelperHw::isPidFdOrSocketForIpcSupported() const { + if (debugManager.flags.EnablePidFdOrSocketsForIpc.get() != -1) { + return debugManager.flags.EnablePidFdOrSocketsForIpc.get(); + } + return false; +} + } // namespace NEO diff --git a/shared/test/common/mocks/mock_product_helper.cpp b/shared/test/common/mocks/mock_product_helper.cpp index 69c4f8fc4a..d4da6397d2 100644 --- a/shared/test/common/mocks/mock_product_helper.cpp +++ b/shared/test/common/mocks/mock_product_helper.cpp @@ -488,6 +488,11 @@ bool ProductHelperHw::isNonCoherentTimestampsModeEnabled() const { return false; } +template <> +bool ProductHelperHw::isPidFdOrSocketForIpcSupported() const { + return false; +} + } // namespace NEO #include "shared/source/os_interface/product_helper.inl" diff --git a/shared/test/unit_test/os_interface/product_helper_tests.cpp b/shared/test/unit_test/os_interface/product_helper_tests.cpp index 11660e8d2b..19241e4159 100644 --- a/shared/test/unit_test/os_interface/product_helper_tests.cpp +++ b/shared/test/unit_test/os_interface/product_helper_tests.cpp @@ -1184,3 +1184,21 @@ HWTEST2_F(ProductHelperTest, givenProductHelperWhenCallingIsResourceUncachedForC HWTEST_F(ProductHelperTest, givenProductHelperWhenGettingPreferredWorkgroupCountPerSubsliceThenZeroReturned) { EXPECT_EQ(0u, productHelper->getPreferredWorkgroupCountPerSubslice()); } + +HWTEST_F(ProductHelperTest, givenProductHelperWithDebugKeyWhenPidFdOrSocketForIpcIsSupportedThenExpectedValueReturned) { + DebugManagerStateRestore restore; + + debugManager.flags.EnablePidFdOrSocketsForIpc.set(1); + EXPECT_TRUE(productHelper->isPidFdOrSocketForIpcSupported()); + + debugManager.flags.EnablePidFdOrSocketsForIpc.set(0); + EXPECT_FALSE(productHelper->isPidFdOrSocketForIpcSupported()); +} + +HWTEST2_F(ProductHelperTest, givenProductHelperWhenPidFdOrSocketForIpcIsNotSupportedThenFalseReturned, IsAtLeastXe2HpgCore) { + EXPECT_FALSE(productHelper->isPidFdOrSocketForIpcSupported()); +} + +HWTEST2_F(ProductHelperTest, givenProductHelperWhenPidFdOrSocketForIpcIsNotSupportedThenFalseReturned, IsBeforeXe2HpgCore) { + EXPECT_FALSE(productHelper->isPidFdOrSocketForIpcSupported()); +}