feature: add support for cl_khr_external_memory extension

Related-To: NEO-7069
Signed-off-by: Warchulski, Jaroslaw <jaroslaw.warchulski@intel.com>
This commit is contained in:
Warchulski, Jaroslaw
2023-05-02 13:46:25 +00:00
committed by Compute-Runtime-Automation
parent 769a9e515e
commit 7fdf4985a3
13 changed files with 83 additions and 2 deletions

View File

@@ -94,6 +94,7 @@ cl_int ClDevice::getDeviceInfo(cl_device_info paramName,
case CL_DEVICE_ERROR_CORRECTION_SUPPORT: getCap<CL_DEVICE_ERROR_CORRECTION_SUPPORT >(src, srcSize, retSize); break;
case CL_DEVICE_EXECUTION_CAPABILITIES: getCap<CL_DEVICE_EXECUTION_CAPABILITIES >(src, srcSize, retSize); break;
case CL_DEVICE_EXTENSIONS: getStr<CL_DEVICE_EXTENSIONS >(src, srcSize, retSize); break;
case CL_DEVICE_EXTERNAL_MEMORY_IMPORT_HANDLE_TYPES_KHR: getCap<CL_DEVICE_EXTERNAL_MEMORY_IMPORT_HANDLE_TYPES_KHR >(src, srcSize, retSize); break;
case CL_DEVICE_GENERIC_ADDRESS_SPACE_SUPPORT: getCap<CL_DEVICE_GENERIC_ADDRESS_SPACE_SUPPORT >(src, srcSize, retSize); break;
case CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE: getCap<CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE >(src, srcSize, retSize); break;
case CL_DEVICE_GLOBAL_MEM_CACHE_SIZE: getCap<CL_DEVICE_GLOBAL_MEM_CACHE_SIZE >(src, srcSize, retSize); break;

View File

@@ -135,6 +135,7 @@ struct ClDeviceInfo {
bool vmeExtension;
bool platformLP;
bool packedYuvExtension;
cl_uint externalMemorySharing;
/*Unified Shared Memory Capabilites*/
cl_unified_shared_memory_capabilities_intel hostMemCapabilities;
cl_unified_shared_memory_capabilities_intel deviceMemCapabilities;

View File

@@ -93,6 +93,7 @@ template<> struct Map<CL_DEVICE_DRIVER_VERSION_INTEL > :
template<> struct Map<CL_DEVICE_ENDIAN_LITTLE > : public ClMapBase<CL_DEVICE_ENDIAN_LITTLE, uint32_t, &ClDeviceInfo::endianLittle> {};
template<> struct Map<CL_DEVICE_EXECUTION_CAPABILITIES > : public ClMapBase<CL_DEVICE_EXECUTION_CAPABILITIES, uint64_t, &ClDeviceInfo::executionCapabilities> {};
template<> struct Map<CL_DEVICE_EXTENSIONS > : public ClMapBase<CL_DEVICE_EXTENSIONS, const char *, &ClDeviceInfo::deviceExtensions> {};
template<> struct Map<CL_DEVICE_EXTERNAL_MEMORY_IMPORT_HANDLE_TYPES_KHR > : public ClMapBase<CL_DEVICE_EXTERNAL_MEMORY_IMPORT_HANDLE_TYPES_KHR, uint32_t, &ClDeviceInfo::externalMemorySharing> {};
template<> struct Map<CL_DEVICE_GENERIC_ADDRESS_SPACE_SUPPORT > : public ClMapBase<CL_DEVICE_GENERIC_ADDRESS_SPACE_SUPPORT, uint32_t, &ClDeviceInfo::genericAddressSpaceSupport> {};
template<> struct Map<CL_DEVICE_GLOBAL_MEM_CACHE_SIZE > : public ClMapBase<CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, uint64_t, &ClDeviceInfo::globalMemCacheSize> {};
template<> struct Map<CL_DEVICE_GLOBAL_MEM_CACHE_TYPE > : public ClMapBase<CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, uint32_t, &ClDeviceInfo::globalMemCacheType> {};

View File

@@ -1,14 +1,20 @@
/*
* Copyright (C) 2020 Intel Corporation
* Copyright (C) 2020-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/debug_settings/debug_settings_manager.h"
#include "opencl/source/cl_device/cl_device.h"
namespace NEO {
void ClDevice::initializeOsSpecificCaps() {
if (enabledClVersion >= 30 && DebugManager.flags.ClKhrExternalMemoryExtension.get()) {
deviceInfo.externalMemorySharing = CL_EXTERNAL_MEMORY_HANDLE_DMA_BUF_KHR;
}
}
} // namespace NEO

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Intel Corporation
* Copyright (C) 2020-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -7,6 +7,7 @@
#ifdef _WIN32
#include "shared/source/debug_settings/debug_settings_manager.h"
#include "shared/source/device/device.h"
#include "opencl/source/cl_device/cl_device.h"
@@ -14,6 +15,10 @@
namespace NEO {
void ClDevice::initializeOsSpecificCaps() {
if (enabledClVersion >= 30 && DebugManager.flags.ClKhrExternalMemoryExtension.get()) {
deviceInfo.externalMemorySharing = CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR;
}
deviceExtensions += "cl_intel_simultaneous_sharing ";
deviceInfo.deviceExtensions = deviceExtensions.c_str();

View File

@@ -1745,3 +1745,10 @@ TEST_F(DeviceGetCapsTest, givenRootDeviceWithSubDevicesWhenQueriedForCacheSizeTh
}
}
}
TEST_F(DeviceGetCapsTest, givenClKhrExternalMemoryExtensionEnabledWhenCapsAreCreatedThenDeviceInfoReportsSupportOfExternalMemorySharing) {
DebugManagerStateRestore dbgRestorer;
DebugManager.flags.ClKhrExternalMemoryExtension.set(1);
auto device = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(defaultHwInfo.get()));
EXPECT_TRUE(device->deviceInfo.externalMemorySharing);
}

View File

@@ -902,6 +902,7 @@ cl_device_info deviceInfoParams[] = {
CL_DEVICE_ENDIAN_LITTLE,
CL_DEVICE_ERROR_CORRECTION_SUPPORT,
CL_DEVICE_EXECUTION_CAPABILITIES,
CL_DEVICE_EXTERNAL_MEMORY_IMPORT_HANDLE_TYPES_KHR,
CL_DEVICE_EXTENSIONS,
CL_DEVICE_EXTENSIONS_WITH_VERSION,
CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE,

View File

@@ -47,6 +47,22 @@ TEST(DeviceOsTest, GivenDefaultClDeviceWhenCheckingForOsSpecificExtensionsThenCo
delete pClDevice;
}
TEST(DeviceOsTest, GivenDefaultClDeviceWhenCheckingForOsSpecificExtensionsThenDeviceInfoReportsSupportOfExternalMemorySharing) {
VariableBackup<UltHwConfig> backup(&ultHwConfig);
DebugManagerStateRestore stateRestore;
DebugManager.flags.ClKhrExternalMemoryExtension.set(1);
ultHwConfig.useMockedPrepareDeviceEnvironmentsFunc = false;
auto hwInfo = defaultHwInfo.get();
auto pDevice = MockDevice::createWithNewExecutionEnvironment<Device>(hwInfo);
DeviceFactory::prepareDeviceEnvironments(*pDevice->getExecutionEnvironment());
auto pClDevice = new ClDevice{*pDevice, platform()};
EXPECT_EQ(pClDevice->getDeviceInfo().externalMemorySharing, static_cast<cl_uint>(CL_EXTERNAL_MEMORY_HANDLE_DMA_BUF_KHR));
delete pClDevice;
}
TEST(DeviceOsTest, WhenDeviceIsCreatedThenSimultaneousInteropsIsSupported) {
auto pDevice = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(defaultHwInfo.get()));

View File

@@ -44,6 +44,22 @@ TEST(DeviceOsTest, GivenDefaultClDeviceWhenCheckingForOsSpecificExtensionsThenCo
delete pClDevice;
}
TEST(DeviceOsTest, GivenDefaultClDeviceWhenCheckingForOsSpecificExtensionsThenDeviceInfoReportsSupportOfExternalMemorySharing) {
VariableBackup<UltHwConfig> backup(&ultHwConfig);
DebugManagerStateRestore stateRestore;
DebugManager.flags.ClKhrExternalMemoryExtension.set(1);
ultHwConfig.useMockedPrepareDeviceEnvironmentsFunc = false;
auto hwInfo = defaultHwInfo.get();
auto pDevice = MockDevice::createWithNewExecutionEnvironment<Device>(hwInfo);
DeviceFactory::prepareDeviceEnvironments(*pDevice->getExecutionEnvironment());
auto pClDevice = new ClDevice{*pDevice, platform()};
EXPECT_EQ(pClDevice->getDeviceInfo().externalMemorySharing, static_cast<cl_uint>(CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR));
delete pClDevice;
}
TEST(DeviceOsTest, WhenCreatingDeviceThenSimultaneousInteropsIsSupported) {
auto pDevice = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(defaultHwInfo.get()));

View File

@@ -80,6 +80,7 @@ DECLARE_DEBUG_VARIABLE(bool, ForceTheoreticalMaxWorkGroupCount, false, "Do not a
DECLARE_DEBUG_VARIABLE(bool, DontDisableZebinIfVmeUsed, false, "When enabled, driver will not add -cl-intel-disable-zebin internal option when vme is used")
DECLARE_DEBUG_VARIABLE(bool, AppendMemoryPrefetchForKmdMigratedSharedAllocations, true, "Allow prefetching shared memory to the device associated with the specified command list")
DECLARE_DEBUG_VARIABLE(bool, ForceMemoryPrefetchForKmdMigratedSharedAllocations, false, "Force prefetch of shared memory in command queue execute command lists")
DECLARE_DEBUG_VARIABLE(bool, ClKhrExternalMemoryExtension, false, "Enable cl_khr_external_memory extension")
DECLARE_DEBUG_VARIABLE(std::string, ForceDeviceId, std::string("unk"), "Override device id in AUB/TBX mode")
DECLARE_DEBUG_VARIABLE(std::string, FilterDeviceId, std::string("unk"), "Device id filter, adapter matching device id will be opened; ignored when unk")
DECLARE_DEBUG_VARIABLE(std::string, FilterBdfPath, std::string("unk"), "Linux-only, BDF path filter, only matching paths will be opened; ignored when unk")

View File

@@ -107,6 +107,10 @@ std::string CompilerProductHelperHw<gfxProduct>::getDeviceExtensions(const Hardw
extensions += "cl_ext_float_atomics ";
}
if (enabledClVersion >= 30 && DebugManager.flags.ClKhrExternalMemoryExtension.get()) {
extensions += "cl_khr_external_memory ";
}
if (DebugManager.flags.EnableNV12.get() && hwInfo.capabilityTable.supportsImages) {
extensions += "cl_intel_planar_yuv ";
}

View File

@@ -439,6 +439,7 @@ LimitEngineCountForVirtualCcs = -1
ForceRunAloneContext = -1
AppendMemoryPrefetchForKmdMigratedSharedAllocations = 1
ForceMemoryPrefetchForKmdMigratedSharedAllocations = 0
ClKhrExternalMemoryExtension = 0
KMDSupportForCrossTileMigrationPolicy = -1
CreateContextWithAccessCounters = -1
AccessCountersTrigger = -1

View File

@@ -239,6 +239,27 @@ TEST_F(CompilerProductHelperFixture, givenHwInfoWithCLVersionAtLeast20ThenReport
EXPECT_FALSE(hasSubstr(extensions, std::string("cl_ext_float_atomics")));
}
TEST_F(CompilerProductHelperFixture, givenHwInfoWithCLVersion30ThenReportsClKhrExternalMemoryExtension) {
auto &compilerProductHelper = pDevice->getCompilerProductHelper();
auto *releaseHelper = getReleaseHelper();
auto hwInfo = *defaultHwInfo;
hwInfo.capabilityTable.clVersionSupport = 30;
auto extensions = compilerProductHelper.getDeviceExtensions(hwInfo, releaseHelper);
EXPECT_FALSE(hasSubstr(extensions, std::string("cl_khr_external_memory")));
DebugManagerStateRestore dbgRestorer;
DebugManager.flags.ClKhrExternalMemoryExtension.set(1);
hwInfo.capabilityTable.clVersionSupport = 21;
extensions = compilerProductHelper.getDeviceExtensions(hwInfo, releaseHelper);
EXPECT_FALSE(hasSubstr(extensions, std::string("cl_khr_external_memory")));
hwInfo.capabilityTable.clVersionSupport = 30;
extensions = compilerProductHelper.getDeviceExtensions(hwInfo, releaseHelper);
EXPECT_TRUE(hasSubstr(extensions, std::string("cl_khr_external_memory")));
}
HWTEST2_F(CompilerProductHelperFixture, GivenAtMostGen11DeviceWhenCheckingIfIntegerDotExtensionIsSupportedThenFalseReturned, IsAtMostGen11) {
auto &compilerProductHelper = pDevice->getCompilerProductHelper();