diff --git a/level_zero/core/source/context/CMakeLists.txt b/level_zero/core/source/context/CMakeLists.txt index 6e03e0da69..355c9c1af3 100644 --- a/level_zero/core/source/context/CMakeLists.txt +++ b/level_zero/core/source/context/CMakeLists.txt @@ -7,7 +7,8 @@ target_sources(${L0_STATIC_LIB_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt - ${CMAKE_CURRENT_SOURCE_DIR}/context_imp_${DRIVER_MODEL}.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/context_imp_${DRIVER_MODEL}/context_imp.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/context_imp_${DRIVER_MODEL}${BRANCH_DIR_SUFFIX}context_imp_helper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/context_imp.cpp ${CMAKE_CURRENT_SOURCE_DIR}/context_imp.h ${CMAKE_CURRENT_SOURCE_DIR}/context.h diff --git a/level_zero/core/source/context/context.h b/level_zero/core/source/context/context.h index ad0a50f1cc..d5828eee51 100644 --- a/level_zero/core/source/context/context.h +++ b/level_zero/core/source/context/context.h @@ -159,6 +159,10 @@ struct Context : _ze_context_handle_t { virtual ze_result_t createImage(ze_device_handle_t hDevice, const ze_image_desc_t *desc, ze_image_handle_t *phImage) = 0; + virtual ze_result_t getVirtualAddressSpaceIpcHandle(ze_device_handle_t hDevice, + ze_ipc_mem_handle_t *pIpcHandle) = 0; + virtual ze_result_t putVirtualAddressSpaceIpcHandle(ze_ipc_mem_handle_t ipcHandle) = 0; + virtual bool isShareableMemory(const void *exportDesc, bool exportableMemory, NEO::Device *neoDevice) = 0; virtual void *getMemHandlePtr(ze_device_handle_t hDevice, uint64_t handle, NEO::AllocationType allocationType, ze_ipc_memory_flags_t flags) = 0; diff --git a/level_zero/core/source/context/context_imp.h b/level_zero/core/source/context/context_imp.h index b65428e19e..8d572de804 100644 --- a/level_zero/core/source/context/context_imp.h +++ b/level_zero/core/source/context/context_imp.h @@ -142,6 +142,9 @@ struct ContextImp : Context { ze_result_t createImage(ze_device_handle_t hDevice, const ze_image_desc_t *desc, ze_image_handle_t *phImage) override; + ze_result_t getVirtualAddressSpaceIpcHandle(ze_device_handle_t hDevice, + ze_ipc_mem_handle_t *pIpcHandle) override; + ze_result_t putVirtualAddressSpaceIpcHandle(ze_ipc_mem_handle_t ipcHandle) override; std::map &getDevices() { return devices; diff --git a/level_zero/core/source/context/context_imp_drm.cpp b/level_zero/core/source/context/context_imp_drm/context_imp.cpp similarity index 99% rename from level_zero/core/source/context/context_imp_drm.cpp rename to level_zero/core/source/context/context_imp_drm/context_imp.cpp index 736adfa5c4..282528639d 100644 --- a/level_zero/core/source/context/context_imp_drm.cpp +++ b/level_zero/core/source/context/context_imp_drm/context_imp.cpp @@ -5,10 +5,11 @@ * */ +#include "level_zero/core/source/context/context_imp.h" + #include "shared/source/device/device.h" #include "shared/source/memory_manager/unified_memory_manager.h" -#include "level_zero/core/source/context/context_imp.h" #include "level_zero/core/source/device/device.h" #include "level_zero/core/source/driver/driver_handle_imp.h" namespace L0 { diff --git a/level_zero/core/source/context/context_imp_drm/context_imp_helper.cpp b/level_zero/core/source/context/context_imp_drm/context_imp_helper.cpp new file mode 100644 index 0000000000..08585fe140 --- /dev/null +++ b/level_zero/core/source/context/context_imp_drm/context_imp_helper.cpp @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2023 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "level_zero/core/source/context/context_imp.h" +#include "level_zero/core/source/driver/driver_handle_imp.h" + +namespace L0 { + +ze_result_t ContextImp::getVirtualAddressSpaceIpcHandle(ze_device_handle_t hDevice, + ze_ipc_mem_handle_t *pIpcHandle) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +ze_result_t ContextImp::putVirtualAddressSpaceIpcHandle(ze_ipc_mem_handle_t ipcHandle) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +} // namespace L0 diff --git a/level_zero/core/source/context/context_imp_drm_or_wddm.cpp b/level_zero/core/source/context/context_imp_drm_or_wddm/context_imp.cpp similarity index 99% rename from level_zero/core/source/context/context_imp_drm_or_wddm.cpp rename to level_zero/core/source/context/context_imp_drm_or_wddm/context_imp.cpp index ae8917f795..36a6920a34 100644 --- a/level_zero/core/source/context/context_imp_drm_or_wddm.cpp +++ b/level_zero/core/source/context/context_imp_drm_or_wddm/context_imp.cpp @@ -5,6 +5,8 @@ * */ +#include "level_zero/core/source/context/context_imp.h" + #include "shared/source/device/device.h" #include "shared/source/execution_environment/root_device_environment.h" #include "shared/source/helpers/driver_model_type.h" @@ -12,7 +14,6 @@ #include "shared/source/memory_manager/unified_memory_manager.h" #include "shared/source/os_interface/os_interface.h" -#include "level_zero/core/source/context/context_imp.h" #include "level_zero/core/source/device/device.h" #include "level_zero/core/source/driver/driver_handle_imp.h" diff --git a/level_zero/core/source/context/context_imp_drm_or_wddm/context_imp_helper.cpp b/level_zero/core/source/context/context_imp_drm_or_wddm/context_imp_helper.cpp new file mode 100644 index 0000000000..08585fe140 --- /dev/null +++ b/level_zero/core/source/context/context_imp_drm_or_wddm/context_imp_helper.cpp @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2023 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "level_zero/core/source/context/context_imp.h" +#include "level_zero/core/source/driver/driver_handle_imp.h" + +namespace L0 { + +ze_result_t ContextImp::getVirtualAddressSpaceIpcHandle(ze_device_handle_t hDevice, + ze_ipc_mem_handle_t *pIpcHandle) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +ze_result_t ContextImp::putVirtualAddressSpaceIpcHandle(ze_ipc_mem_handle_t ipcHandle) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +} // namespace L0 diff --git a/level_zero/core/source/context/context_imp_wddm.cpp b/level_zero/core/source/context/context_imp_wddm/context_imp.cpp similarity index 99% rename from level_zero/core/source/context/context_imp_wddm.cpp rename to level_zero/core/source/context/context_imp_wddm/context_imp.cpp index 7bfe6561e8..ee8da091cd 100644 --- a/level_zero/core/source/context/context_imp_wddm.cpp +++ b/level_zero/core/source/context/context_imp_wddm/context_imp.cpp @@ -6,6 +6,7 @@ */ #include "level_zero/core/source/context/context_imp.h" + #include "level_zero/core/source/driver/driver_handle_imp.h" namespace L0 { diff --git a/level_zero/core/source/context/context_imp_wddm/context_imp_helper.cpp b/level_zero/core/source/context/context_imp_wddm/context_imp_helper.cpp new file mode 100644 index 0000000000..7cd84abacb --- /dev/null +++ b/level_zero/core/source/context/context_imp_wddm/context_imp_helper.cpp @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2023 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "level_zero/core/source/context/context_imp.h" +#include "level_zero/core/source/driver/driver_handle_imp.h" + +namespace L0 { + +ze_result_t ContextImp::getVirtualAddressSpaceIpcHandle(ze_device_handle_t hDevice, + ze_ipc_mem_handle_t *pIpcHandle) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +ze_result_t ContextImp::putVirtualAddressSpaceIpcHandle(ze_ipc_mem_handle_t ipcHandle) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} +} // namespace L0 diff --git a/level_zero/core/source/driver/CMakeLists.txt b/level_zero/core/source/driver/CMakeLists.txt index 7f8f6f32e0..f00bbf2d0d 100644 --- a/level_zero/core/source/driver/CMakeLists.txt +++ b/level_zero/core/source/driver/CMakeLists.txt @@ -9,6 +9,7 @@ target_sources(${L0_STATIC_LIB_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/driver_handle.h ${CMAKE_CURRENT_SOURCE_DIR}/driver_handle_imp.cpp + ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}driver_handle_imp_helper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/driver_handle_imp.h ${CMAKE_CURRENT_SOURCE_DIR}/driver.cpp ${CMAKE_CURRENT_SOURCE_DIR}/driver.h diff --git a/level_zero/core/source/driver/driver_handle_imp.h b/level_zero/core/source/driver/driver_handle_imp.h index 73234cc4a7..8b9dd8a6ef 100644 --- a/level_zero/core/source/driver/driver_handle_imp.h +++ b/level_zero/core/source/driver/driver_handle_imp.h @@ -139,28 +139,7 @@ struct DriverHandleImp : public DriverHandle { std::mutex rtasLock; // Spec extensions - const std::vector> extensionsSupported = { - {ZE_FLOAT_ATOMICS_EXT_NAME, ZE_FLOAT_ATOMICS_EXT_VERSION_CURRENT}, - {ZE_RELAXED_ALLOCATION_LIMITS_EXP_NAME, ZE_RELAXED_ALLOCATION_LIMITS_EXP_VERSION_CURRENT}, - {ZE_MODULE_PROGRAM_EXP_NAME, ZE_MODULE_PROGRAM_EXP_VERSION_CURRENT}, - {ZE_KERNEL_SCHEDULING_HINTS_EXP_NAME, ZE_SCHEDULING_HINTS_EXP_VERSION_CURRENT}, - {ZE_GLOBAL_OFFSET_EXP_NAME, ZE_GLOBAL_OFFSET_EXP_VERSION_CURRENT}, - {ZE_PCI_PROPERTIES_EXT_NAME, ZE_PCI_PROPERTIES_EXT_VERSION_CURRENT}, - {ZE_MEMORY_COMPRESSION_HINTS_EXT_NAME, ZE_MEMORY_COMPRESSION_HINTS_EXT_VERSION_CURRENT}, - {ZE_MEMORY_FREE_POLICIES_EXT_NAME, ZE_MEMORY_FREE_POLICIES_EXT_VERSION_CURRENT}, - {ZE_DEVICE_MEMORY_PROPERTIES_EXT_NAME, ZE_DEVICE_MEMORY_PROPERTIES_EXT_VERSION_CURRENT}, - {ZE_RAYTRACING_EXT_NAME, ZE_RAYTRACING_EXT_VERSION_CURRENT}, - {ZE_CONTEXT_POWER_SAVING_HINT_EXP_NAME, ZE_POWER_SAVING_HINT_EXP_VERSION_CURRENT}, - {ZE_DEVICE_LUID_EXT_NAME, ZE_DEVICE_LUID_EXT_VERSION_CURRENT}, - {ZE_DEVICE_IP_VERSION_EXT_NAME, ZE_DEVICE_IP_VERSION_VERSION_CURRENT}, - {ZE_CACHE_RESERVATION_EXT_NAME, ZE_CACHE_RESERVATION_EXT_VERSION_CURRENT}, - {ZE_IMAGE_VIEW_EXT_NAME, ZE_IMAGE_VIEW_EXP_VERSION_CURRENT}, - {ZE_IMAGE_VIEW_PLANAR_EXT_NAME, ZE_IMAGE_VIEW_PLANAR_EXP_VERSION_CURRENT}, - {ZE_EVENT_QUERY_KERNEL_TIMESTAMPS_EXT_NAME, ZE_EVENT_QUERY_KERNEL_TIMESTAMPS_EXT_VERSION_CURRENT}, - {ZE_RTAS_BUILDER_EXP_NAME, ZE_RTAS_BUILDER_EXP_VERSION_CURRENT}, - - // Driver experimental extensions - {ZE_INTEL_DEVICE_MODULE_DP_PROPERTIES_EXP_NAME, ZE_INTEL_DEVICE_MODULE_DP_PROPERTIES_EXP_VERSION_CURRENT}}; + static const std::vector> extensionsSupported; uint64_t uuidTimestamp = 0u; diff --git a/level_zero/core/source/driver/driver_handle_imp_helper.cpp b/level_zero/core/source/driver/driver_handle_imp_helper.cpp new file mode 100644 index 0000000000..fc2e3e9bd8 --- /dev/null +++ b/level_zero/core/source/driver/driver_handle_imp_helper.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2023 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "level_zero/core/source/driver/driver_handle_imp.h" +#include "level_zero/include/ze_intel_gpu.h" + +namespace L0 { +const std::vector> DriverHandleImp::extensionsSupported = { + {ZE_FLOAT_ATOMICS_EXT_NAME, ZE_FLOAT_ATOMICS_EXT_VERSION_CURRENT}, + {ZE_RELAXED_ALLOCATION_LIMITS_EXP_NAME, ZE_RELAXED_ALLOCATION_LIMITS_EXP_VERSION_CURRENT}, + {ZE_MODULE_PROGRAM_EXP_NAME, ZE_MODULE_PROGRAM_EXP_VERSION_CURRENT}, + {ZE_KERNEL_SCHEDULING_HINTS_EXP_NAME, ZE_SCHEDULING_HINTS_EXP_VERSION_CURRENT}, + {ZE_GLOBAL_OFFSET_EXP_NAME, ZE_GLOBAL_OFFSET_EXP_VERSION_CURRENT}, + {ZE_PCI_PROPERTIES_EXT_NAME, ZE_PCI_PROPERTIES_EXT_VERSION_CURRENT}, + {ZE_MEMORY_COMPRESSION_HINTS_EXT_NAME, ZE_MEMORY_COMPRESSION_HINTS_EXT_VERSION_CURRENT}, + {ZE_MEMORY_FREE_POLICIES_EXT_NAME, ZE_MEMORY_FREE_POLICIES_EXT_VERSION_CURRENT}, + {ZE_DEVICE_MEMORY_PROPERTIES_EXT_NAME, ZE_DEVICE_MEMORY_PROPERTIES_EXT_VERSION_CURRENT}, + {ZE_RAYTRACING_EXT_NAME, ZE_RAYTRACING_EXT_VERSION_CURRENT}, + {ZE_CONTEXT_POWER_SAVING_HINT_EXP_NAME, ZE_POWER_SAVING_HINT_EXP_VERSION_CURRENT}, + {ZE_DEVICE_LUID_EXT_NAME, ZE_DEVICE_LUID_EXT_VERSION_CURRENT}, + {ZE_DEVICE_IP_VERSION_EXT_NAME, ZE_DEVICE_IP_VERSION_VERSION_CURRENT}, + {ZE_CACHE_RESERVATION_EXT_NAME, ZE_CACHE_RESERVATION_EXT_VERSION_CURRENT}, + {ZE_IMAGE_VIEW_EXT_NAME, ZE_IMAGE_VIEW_EXP_VERSION_CURRENT}, + {ZE_IMAGE_VIEW_PLANAR_EXT_NAME, ZE_IMAGE_VIEW_PLANAR_EXP_VERSION_CURRENT}, + {ZE_EVENT_QUERY_KERNEL_TIMESTAMPS_EXT_NAME, ZE_EVENT_QUERY_KERNEL_TIMESTAMPS_EXT_VERSION_CURRENT}, + {ZE_RTAS_BUILDER_EXP_NAME, ZE_RTAS_BUILDER_EXP_VERSION_CURRENT}, + + // Driver experimental extensions + {ZE_INTEL_DEVICE_MODULE_DP_PROPERTIES_EXP_NAME, ZE_INTEL_DEVICE_MODULE_DP_PROPERTIES_EXP_VERSION_CURRENT}}; +} // namespace L0 diff --git a/level_zero/core/test/unit_tests/sources/context/CMakeLists.txt b/level_zero/core/test/unit_tests/sources/context/CMakeLists.txt index 4576c4a8ba..e7dfd94d3c 100644 --- a/level_zero/core/test/unit_tests/sources/context/CMakeLists.txt +++ b/level_zero/core/test/unit_tests/sources/context/CMakeLists.txt @@ -9,3 +9,5 @@ target_sources(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test_context.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_context_${DRIVER_MODEL}.cpp ) + +add_subdirectories() diff --git a/level_zero/core/test/unit_tests/sources/context/linux/CMakeLists.txt b/level_zero/core/test/unit_tests/sources/context/linux/CMakeLists.txt new file mode 100644 index 0000000000..028f1a7170 --- /dev/null +++ b/level_zero/core/test/unit_tests/sources/context/linux/CMakeLists.txt @@ -0,0 +1,15 @@ +# +# Copyright (C) 2023 Intel Corporation +# +# SPDX-License-Identifier: MIT +# + +if(UNIX) + target_sources(${TARGET_NAME} PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}test_context_helper.cpp + ) +endif() + +add_subdirectories() + diff --git a/level_zero/core/test/unit_tests/sources/context/linux/test_context_helper.cpp b/level_zero/core/test/unit_tests/sources/context/linux/test_context_helper.cpp new file mode 100644 index 0000000000..b3c24281ae --- /dev/null +++ b/level_zero/core/test/unit_tests/sources/context/linux/test_context_helper.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2023 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/execution_environment/root_device_environment.h" +#include "shared/source/os_interface/os_interface.h" +#include "shared/test/common/mocks/mock_builtins.h" +#include "shared/test/common/mocks/mock_device.h" +#include "shared/test/common/mocks/mock_driver_model.h" +#include "shared/test/common/test_macros/test.h" + +#include "level_zero/core/source/context/context_imp.h" +#include "level_zero/core/source/driver/driver_handle_imp.h" +#include "level_zero/core/source/driver/driver_imp.h" +#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h" +#include "level_zero/core/test/unit_tests/mocks/mock_driver_handle.h" + +#include "gtest/gtest.h" +namespace L0 { +namespace ult { + +using ContextGetVirtualAddressSpaceTests = Test; +TEST_F(ContextGetVirtualAddressSpaceTests, givenDrmDriverModelWhenCallingGetVirtualAddressSpaceIpcHandleThenUnsupportedErrorIsReturned) { + neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[0]->osInterface.reset(new NEO::OSInterface()); + neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::make_unique()); + + ze_context_handle_t hContext; + ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0}; + + ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + + ContextImp *contextImp = static_cast(L0::Context::fromHandle(hContext)); + + ze_ipc_mem_handle_t ipcHandle{}; + EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, contextImp->getVirtualAddressSpaceIpcHandle(static_cast(device)->toHandle(), &ipcHandle)); + EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, contextImp->putVirtualAddressSpaceIpcHandle(ipcHandle)); + res = contextImp->destroy(); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); +} +} // namespace ult +} // namespace L0 diff --git a/level_zero/core/test/unit_tests/sources/context/windows/CMakeLists.txt b/level_zero/core/test/unit_tests/sources/context/windows/CMakeLists.txt new file mode 100644 index 0000000000..3243baad55 --- /dev/null +++ b/level_zero/core/test/unit_tests/sources/context/windows/CMakeLists.txt @@ -0,0 +1,12 @@ +# +# Copyright (C) 2023 Intel Corporation +# +# SPDX-License-Identifier: MIT +# + +if(WIN32) + target_sources(${TARGET_NAME} PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}test_context_helper.cpp + ) +endif() diff --git a/level_zero/core/test/unit_tests/sources/context/windows/test_context_helper.cpp b/level_zero/core/test/unit_tests/sources/context/windows/test_context_helper.cpp new file mode 100644 index 0000000000..bd853e52e9 --- /dev/null +++ b/level_zero/core/test/unit_tests/sources/context/windows/test_context_helper.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2023 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/execution_environment/root_device_environment.h" +#include "shared/source/os_interface/os_interface.h" +#include "shared/test/common/mocks/mock_builtins.h" +#include "shared/test/common/mocks/mock_device.h" +#include "shared/test/common/mocks/mock_driver_model.h" +#include "shared/test/common/test_macros/test.h" + +#include "level_zero/core/source/context/context_imp.h" +#include "level_zero/core/source/driver/driver_handle_imp.h" +#include "level_zero/core/source/driver/driver_imp.h" +#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h" +#include "level_zero/core/test/unit_tests/mocks/mock_driver_handle.h" + +#include "gtest/gtest.h" +namespace L0 { +namespace ult { + +using ContextGetVirtualAddressSpaceTests = Test; +TEST_F(ContextGetVirtualAddressSpaceTests, givenWddmDriverModelWhenCallingGetVirtualAddressSpaceIpcHandleThenUnsupportedErrorIsReturned) { + neoDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(new NEO::OSInterface()); + neoDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::make_unique()); + ze_context_handle_t hContext; + ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0}; + + ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + + ContextImp *contextImp = static_cast(L0::Context::fromHandle(hContext)); + + ze_ipc_mem_handle_t ipcHandle{}; + EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, contextImp->getVirtualAddressSpaceIpcHandle(device, &ipcHandle)); + res = contextImp->destroy(); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); +} + +TEST_F(ContextGetVirtualAddressSpaceTests, givenWddmDriverModelWhenCallingPutVirtualAddressSpaceIpcHandleThenUnsupportedErrorIsReturned) { + neoDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(new NEO::OSInterface()); + neoDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::make_unique()); + ze_context_handle_t hContext; + ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0}; + + ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + + ContextImp *contextImp = static_cast(L0::Context::fromHandle(hContext)); + + ze_ipc_mem_handle_t ipcHandle{}; + EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, contextImp->putVirtualAddressSpaceIpcHandle(ipcHandle)); + res = contextImp->destroy(); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); +} + +} // namespace ult +} // namespace L0 diff --git a/shared/source/os_interface/linux/drm_wrappers.h b/shared/source/os_interface/linux/drm_wrappers.h index 5ed9e07726..8b5e828ea7 100644 --- a/shared/source/os_interface/linux/drm_wrappers.h +++ b/shared/source/os_interface/linux/drm_wrappers.h @@ -261,6 +261,7 @@ enum class DrmIoctl { GemClosFree, GemCacheReserve, Version, + VmExport, }; enum class DrmParam { diff --git a/shared/source/os_interface/linux/ioctl_helper.cpp b/shared/source/os_interface/linux/ioctl_helper.cpp index c6bd6cb049..d182946310 100644 --- a/shared/source/os_interface/linux/ioctl_helper.cpp +++ b/shared/source/os_interface/linux/ioctl_helper.cpp @@ -561,6 +561,10 @@ std::unique_ptr IoctlHelper::createEngineInfo(bool isSysmanEnabled) void IoctlHelper::fillBindInfoForIpcHandle(uint32_t handle, size_t size) {} +bool IoctlHelper::getFdFromVmExport(uint32_t vmId, uint32_t flags, int32_t *fd) { + return false; +} + uint32_t IoctlHelper::createGem(uint64_t size, uint32_t memoryBanks) { GemCreate gemCreate = {}; gemCreate.size = size; diff --git a/shared/source/os_interface/linux/ioctl_helper.h b/shared/source/os_interface/linux/ioctl_helper.h index 3866493567..c278eb3351 100644 --- a/shared/source/os_interface/linux/ioctl_helper.h +++ b/shared/source/os_interface/linux/ioctl_helper.h @@ -164,6 +164,7 @@ class IoctlHelper { virtual bool getTopologyDataAndMap(const HardwareInfo &hwInfo, DrmQueryTopologyData &topologyData, TopologyMap &topologyMap); bool translateTopologyInfo(const QueryTopologyInfo *queryTopologyInfo, DrmQueryTopologyData &topologyData, TopologyMapping &mapping); virtual void fillBindInfoForIpcHandle(uint32_t handle, size_t size); + virtual bool getFdFromVmExport(uint32_t vmId, uint32_t flags, int32_t *fd); virtual void initializeGetGpuTimeFunction(); virtual bool setGpuCpuTimes(TimeStampData *pGpuCpuTime, OSTime *osTime); diff --git a/shared/source/os_interface/linux/xe/CMakeLists.txt b/shared/source/os_interface/linux/xe/CMakeLists.txt index e1b10a8d23..c44df137ff 100644 --- a/shared/source/os_interface/linux/xe/CMakeLists.txt +++ b/shared/source/os_interface/linux/xe/CMakeLists.txt @@ -9,6 +9,8 @@ if(NEO_ENABLE_XE_DRM_DETECTION) ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/drm_version_xe.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ioctl_helper_xe.cpp + ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}ioctl_helper_xe_string_value_getter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}ioctl_helper_xe_vm_export.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ioctl_helper_xe.h ) diff --git a/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp b/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp index 38ce27de15..66abf4de97 100644 --- a/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp +++ b/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp @@ -8,7 +8,6 @@ #include "shared/source/os_interface/linux/xe/ioctl_helper_xe.h" #include "shared/source/command_stream/csr_definitions.h" -#include "shared/source/debug_settings/debug_settings_manager.h" #include "shared/source/execution_environment/root_device_environment.h" #include "shared/source/gmm_helper/gmm_helper.h" #include "shared/source/helpers/basic_math.h" @@ -883,41 +882,6 @@ bool IoctlHelperXe::isDebugAttachAvailable() { return false; } -unsigned int IoctlHelperXe::getIoctlRequestValue(DrmIoctl ioctlRequest) const { - xeLog(" -> IoctlHelperXe::%s 0x%x\n", __FUNCTION__, ioctlRequest); - switch (ioctlRequest) { - case DrmIoctl::GemClose: - RETURN_ME(DRM_IOCTL_GEM_CLOSE); - case DrmIoctl::GemVmCreate: - RETURN_ME(DRM_IOCTL_XE_VM_CREATE); - case DrmIoctl::GemVmDestroy: - RETURN_ME(DRM_IOCTL_XE_VM_DESTROY); - case DrmIoctl::GemMmapOffset: - RETURN_ME(DRM_IOCTL_XE_GEM_MMAP_OFFSET); - case DrmIoctl::GemCreate: - RETURN_ME(DRM_IOCTL_XE_GEM_CREATE); - case DrmIoctl::GemExecbuffer2: - RETURN_ME(DRM_IOCTL_XE_EXEC); - case DrmIoctl::GemVmBind: - RETURN_ME(DRM_IOCTL_XE_VM_BIND); - case DrmIoctl::Query: - RETURN_ME(DRM_IOCTL_XE_DEVICE_QUERY); - case DrmIoctl::GemContextCreateExt: - RETURN_ME(DRM_IOCTL_XE_EXEC_QUEUE_CREATE); - case DrmIoctl::GemContextDestroy: - RETURN_ME(DRM_IOCTL_XE_EXEC_QUEUE_DESTROY); - case DrmIoctl::GemWaitUserFence: - RETURN_ME(DRM_IOCTL_XE_WAIT_USER_FENCE); - case DrmIoctl::PrimeFdToHandle: - RETURN_ME(DRM_IOCTL_PRIME_FD_TO_HANDLE); - case DrmIoctl::PrimeHandleToFd: - RETURN_ME(DRM_IOCTL_PRIME_HANDLE_TO_FD); - default: - UNRECOVERABLE_IF(true); - return 0; - } -} - int IoctlHelperXe::getDrmParamValue(DrmParam drmParam) const { xeLog(" -> IoctlHelperXe::%s 0x%x %s\n", __FUNCTION__, drmParam, getDrmParamString(drmParam).c_str()); @@ -948,44 +912,6 @@ int IoctlHelperXe::getDrmParamValueBase(DrmParam drmParam) const { return static_cast(drmParam); } -template -void IoctlHelperXe::xeLog(XeLogArgs &&...args) const { - PRINT_DEBUG_STRING(DebugManager.flags.PrintDebugMessages.get(), stderr, args...); -} - -std::string IoctlHelperXe::getIoctlString(DrmIoctl ioctlRequest) const { - switch (ioctlRequest) { - case DrmIoctl::GemClose: - STRINGIFY_ME(DRM_IOCTL_GEM_CLOSE); - case DrmIoctl::GemVmCreate: - STRINGIFY_ME(DRM_IOCTL_XE_VM_CREATE); - case DrmIoctl::GemVmDestroy: - STRINGIFY_ME(DRM_IOCTL_XE_VM_DESTROY); - case DrmIoctl::GemMmapOffset: - STRINGIFY_ME(DRM_IOCTL_XE_GEM_MMAP_OFFSET); - case DrmIoctl::GemCreate: - STRINGIFY_ME(DRM_IOCTL_XE_GEM_CREATE); - case DrmIoctl::GemExecbuffer2: - STRINGIFY_ME(DRM_IOCTL_XE_EXEC); - case DrmIoctl::GemVmBind: - STRINGIFY_ME(DRM_IOCTL_XE_VM_BIND); - case DrmIoctl::Query: - STRINGIFY_ME(DRM_IOCTL_XE_DEVICE_QUERY); - case DrmIoctl::GemContextCreateExt: - STRINGIFY_ME(DRM_IOCTL_XE_EXEC_QUEUE_CREATE); - case DrmIoctl::GemContextDestroy: - STRINGIFY_ME(DRM_IOCTL_XE_EXEC_QUEUE_DESTROY); - case DrmIoctl::GemWaitUserFence: - STRINGIFY_ME(DRM_IOCTL_XE_WAIT_USER_FENCE); - case DrmIoctl::PrimeFdToHandle: - STRINGIFY_ME(DRM_IOCTL_PRIME_FD_TO_HANDLE); - case DrmIoctl::PrimeHandleToFd: - STRINGIFY_ME(DRM_IOCTL_PRIME_HANDLE_TO_FD); - default: - return "???"; - } -} - int IoctlHelperXe::ioctl(DrmIoctl request, void *arg) { int ret = -1; xeLog(" => IoctlHelperXe::%s 0x%x\n", __FUNCTION__, request); @@ -1527,4 +1453,4 @@ void IoctlHelperXe::fillBindInfoForIpcHandle(uint32_t handle, size_t size) { bool IoctlHelperXe::isImmediateVmBindRequired() const { return true; } -} // namespace NEO \ No newline at end of file +} // namespace NEO diff --git a/shared/source/os_interface/linux/xe/ioctl_helper_xe.h b/shared/source/os_interface/linux/xe/ioctl_helper_xe.h index 81ae4dcb7c..366450062f 100644 --- a/shared/source/os_interface/linux/xe/ioctl_helper_xe.h +++ b/shared/source/os_interface/linux/xe/ioctl_helper_xe.h @@ -6,6 +6,7 @@ */ #pragma once +#include "shared/source/debug_settings/debug_settings_manager.h" #include "shared/source/os_interface/linux/ioctl_helper.h" #include @@ -115,6 +116,7 @@ class IoctlHelperXe : public IoctlHelper { bool getTimestampFrequency(uint64_t &frequency); void fillBindInfoForIpcHandle(uint32_t handle, size_t size) override; + bool getFdFromVmExport(uint32_t vmId, uint32_t flags, int32_t *fd) override; bool isImmediateVmBindRequired() const override; private: @@ -164,4 +166,9 @@ class IoctlHelperXe : public IoctlHelper { drm_xe_engine_class_instance *defaultEngine = nullptr; }; -} // namespace NEO \ No newline at end of file +template +void IoctlHelperXe::xeLog(XeLogArgs &&...args) const { + PRINT_DEBUG_STRING(DebugManager.flags.PrintDebugMessages.get(), stderr, args...); +} + +} // namespace NEO diff --git a/shared/source/os_interface/linux/xe/ioctl_helper_xe_string_value_getter.cpp b/shared/source/os_interface/linux/xe/ioctl_helper_xe_string_value_getter.cpp new file mode 100644 index 0000000000..d9c973175b --- /dev/null +++ b/shared/source/os_interface/linux/xe/ioctl_helper_xe_string_value_getter.cpp @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2023 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/os_interface/linux/xe/ioctl_helper_xe.h" + +#include "drm/xe_drm.h" + +#define STRINGIFY_ME(X) return #X +#define RETURN_ME(X) return X + +namespace NEO { +unsigned int IoctlHelperXe::getIoctlRequestValue(DrmIoctl ioctlRequest) const { + xeLog(" -> IoctlHelperXe::%s 0x%x\n", __FUNCTION__, ioctlRequest); + switch (ioctlRequest) { + case DrmIoctl::GemClose: + RETURN_ME(DRM_IOCTL_GEM_CLOSE); + case DrmIoctl::GemVmCreate: + RETURN_ME(DRM_IOCTL_XE_VM_CREATE); + case DrmIoctl::GemVmDestroy: + RETURN_ME(DRM_IOCTL_XE_VM_DESTROY); + case DrmIoctl::GemMmapOffset: + RETURN_ME(DRM_IOCTL_XE_GEM_MMAP_OFFSET); + case DrmIoctl::GemCreate: + RETURN_ME(DRM_IOCTL_XE_GEM_CREATE); + case DrmIoctl::GemExecbuffer2: + RETURN_ME(DRM_IOCTL_XE_EXEC); + case DrmIoctl::GemVmBind: + RETURN_ME(DRM_IOCTL_XE_VM_BIND); + case DrmIoctl::Query: + RETURN_ME(DRM_IOCTL_XE_DEVICE_QUERY); + case DrmIoctl::GemContextCreateExt: + RETURN_ME(DRM_IOCTL_XE_EXEC_QUEUE_CREATE); + case DrmIoctl::GemContextDestroy: + RETURN_ME(DRM_IOCTL_XE_EXEC_QUEUE_DESTROY); + case DrmIoctl::GemWaitUserFence: + RETURN_ME(DRM_IOCTL_XE_WAIT_USER_FENCE); + case DrmIoctl::PrimeFdToHandle: + RETURN_ME(DRM_IOCTL_PRIME_FD_TO_HANDLE); + case DrmIoctl::PrimeHandleToFd: + RETURN_ME(DRM_IOCTL_PRIME_HANDLE_TO_FD); + default: + UNRECOVERABLE_IF(true); + return 0; + } +} + +std::string IoctlHelperXe::getIoctlString(DrmIoctl ioctlRequest) const { + switch (ioctlRequest) { + case DrmIoctl::GemClose: + STRINGIFY_ME(DRM_IOCTL_GEM_CLOSE); + case DrmIoctl::GemVmCreate: + STRINGIFY_ME(DRM_IOCTL_XE_VM_CREATE); + case DrmIoctl::GemVmDestroy: + STRINGIFY_ME(DRM_IOCTL_XE_VM_DESTROY); + case DrmIoctl::GemMmapOffset: + STRINGIFY_ME(DRM_IOCTL_XE_GEM_MMAP_OFFSET); + case DrmIoctl::GemCreate: + STRINGIFY_ME(DRM_IOCTL_XE_GEM_CREATE); + case DrmIoctl::GemExecbuffer2: + STRINGIFY_ME(DRM_IOCTL_XE_EXEC); + case DrmIoctl::GemVmBind: + STRINGIFY_ME(DRM_IOCTL_XE_VM_BIND); + case DrmIoctl::Query: + STRINGIFY_ME(DRM_IOCTL_XE_DEVICE_QUERY); + case DrmIoctl::GemContextCreateExt: + STRINGIFY_ME(DRM_IOCTL_XE_EXEC_QUEUE_CREATE); + case DrmIoctl::GemContextDestroy: + STRINGIFY_ME(DRM_IOCTL_XE_EXEC_QUEUE_DESTROY); + case DrmIoctl::GemWaitUserFence: + STRINGIFY_ME(DRM_IOCTL_XE_WAIT_USER_FENCE); + case DrmIoctl::PrimeFdToHandle: + STRINGIFY_ME(DRM_IOCTL_PRIME_FD_TO_HANDLE); + case DrmIoctl::PrimeHandleToFd: + STRINGIFY_ME(DRM_IOCTL_PRIME_HANDLE_TO_FD); + default: + return "???"; + } +} +} // namespace NEO diff --git a/shared/source/os_interface/linux/xe/ioctl_helper_xe_vm_export.cpp b/shared/source/os_interface/linux/xe/ioctl_helper_xe_vm_export.cpp new file mode 100644 index 0000000000..a4b056ca63 --- /dev/null +++ b/shared/source/os_interface/linux/xe/ioctl_helper_xe_vm_export.cpp @@ -0,0 +1,14 @@ +/* + * Copyright (C) 2023 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/os_interface/linux/xe/ioctl_helper_xe.h" + +namespace NEO { +bool IoctlHelperXe::getFdFromVmExport(uint32_t vmId, uint32_t flags, int32_t *fd) { + return false; +} +} // namespace NEO diff --git a/shared/source/unified_memory/unified_memory.h b/shared/source/unified_memory/unified_memory.h index f30cef5ebb..be1416dfde 100644 --- a/shared/source/unified_memory/unified_memory.h +++ b/shared/source/unified_memory/unified_memory.h @@ -20,7 +20,8 @@ enum InternalMemoryType : uint32_t { enum class InternalIpcMemoryType : uint32_t { IPC_DEVICE_UNIFIED_MEMORY = 0, - IPC_HOST_UNIFIED_MEMORY = 1 + IPC_HOST_UNIFIED_MEMORY = 1, + IPC_DEVICE_VIRTUAL_ADDRESS = 2 }; enum TransferType : uint32_t { diff --git a/shared/test/common/os_interface/linux/sys_calls_linux_ult.h b/shared/test/common/os_interface/linux/sys_calls_linux_ult.h index 208d95a7fb..70bc97ef0d 100644 --- a/shared/test/common/os_interface/linux/sys_calls_linux_ult.h +++ b/shared/test/common/os_interface/linux/sys_calls_linux_ult.h @@ -20,6 +20,7 @@ namespace SysCalls { extern int (*sysCallsMkdir)(const std::string &dir); extern int (*sysCallsOpen)(const char *pathname, int flags); +extern int (*sysCallsClose)(int fileDescriptor); extern int (*sysCallsOpenWithMode)(const char *pathname, int flags, int mode); extern int (*sysCallsDlinfo)(void *handle, int request, void *info); extern ssize_t (*sysCallsPread)(int fd, void *buf, size_t count, off_t offset); diff --git a/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_dg1.cpp b/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_dg1.cpp index 8c5374ee32..131e7bfa7c 100644 --- a/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_dg1.cpp +++ b/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_dg1.cpp @@ -171,3 +171,12 @@ DG1TEST_F(IoctlHelperTestsDg1, whenGettingDrmParamStringThenProperStringIsReturn EXPECT_STREQ(ioctlHelper.getDrmParamString(DrmParam::ParamMinEuInPool).c_str(), "I915_PARAM_MIN_EU_IN_POOL"); EXPECT_STREQ(ioctlHelper.getDrmParamString(DrmParam::ParamCsTimestampFrequency).c_str(), "I915_PARAM_CS_TIMESTAMP_FREQUENCY"); } + +DG1TEST_F(IoctlHelperTestsDg1, givenUpstreamWhenGetFdFromVmExportIsCalledThenFalseIsReturned) { + auto executionEnvironment = std::make_unique(); + auto drm = std::make_unique(*executionEnvironment->rootDeviceEnvironments[0]); + auto &ioctlHelper = *drm->getIoctlHelper(); + uint32_t vmId = 0, flags = 0; + int32_t fd = 0; + EXPECT_FALSE(ioctlHelper.getFdFromVmExport(vmId, flags, &fd)); +} diff --git a/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_prelim.cpp b/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_prelim.cpp index 68a8ae1f99..9bd7549540 100644 --- a/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_prelim.cpp +++ b/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_prelim.cpp @@ -683,3 +683,9 @@ TEST_F(IoctlPrelimHelperTests, givenInitializeGetGpuTimeFunctionNotCalledWhenSet auto ret = ioctlHelper.setGpuCpuTimes(&pGpuCpuTime, osTime.get()); EXPECT_EQ(false, ret); } + +TEST_F(IoctlPrelimHelperTests, givenUpstreamWhenGetFdFromVmExportIsCalledThenFalseIsReturned) { + uint32_t vmId = 0, flags = 0; + int32_t fd = 0; + EXPECT_FALSE(ioctlHelper.getFdFromVmExport(vmId, flags, &fd)); +} diff --git a/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_upstream.cpp b/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_upstream.cpp index 59d0496dae..d403bf9609 100644 --- a/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_upstream.cpp +++ b/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_upstream.cpp @@ -793,3 +793,12 @@ TEST(IoctlHelperTestsUpstream, givenInitializeGetGpuTimeFunctionNotCalledWhenSet auto ret = ioctlHelper.setGpuCpuTimes(&pGpuCpuTime, osTime.get()); EXPECT_EQ(false, ret); } + +TEST(IoctlHelperTestsUpstream, givenUpstreamWhenGetFdFromVmExportIsCalledThenFalseIsReturned) { + auto executionEnvironment = std::make_unique(); + auto drm = std::make_unique(*executionEnvironment->rootDeviceEnvironments[0]); + IoctlHelperUpstream ioctlHelper{*drm}; + uint32_t vmId = 0, flags = 0; + int32_t fd = 0; + EXPECT_FALSE(ioctlHelper.getFdFromVmExport(vmId, flags, &fd)); +} diff --git a/shared/test/unit_test/os_interface/linux/xe/CMakeLists.txt b/shared/test/unit_test/os_interface/linux/xe/CMakeLists.txt index 13e6c6aa43..8c58f1f11a 100644 --- a/shared/test/unit_test/os_interface/linux/xe/CMakeLists.txt +++ b/shared/test/unit_test/os_interface/linux/xe/CMakeLists.txt @@ -8,6 +8,8 @@ if(NEO_ENABLE_XE_DRM_DETECTION) set(NEO_CORE_OS_INTERFACE_TESTS_LINUX_XE ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/ioctl_helper_xe_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/ioctl_helper_xe_vm_export_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/ioctl_helper_xe_tests.h ) set_property(GLOBAL APPEND PROPERTY NEO_CORE_OS_INTERFACE_TESTS_LINUX ${NEO_CORE_OS_INTERFACE_TESTS_LINUX_XE}) diff --git a/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.cpp b/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.cpp index f3b3dad0e0..48e838c7e5 100644 --- a/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.cpp @@ -5,38 +5,10 @@ * */ -#include "shared/source/helpers/common_types.h" -#include "shared/source/helpers/compiler_product_helper.h" -#include "shared/source/helpers/register_offsets.h" -#include "shared/source/os_interface/linux/engine_info.h" -#include "shared/source/os_interface/linux/i915_prelim.h" -#include "shared/source/os_interface/linux/ioctl_helper.h" -#include "shared/source/os_interface/linux/memory_info.h" -#include "shared/source/os_interface/linux/xe/ioctl_helper_xe.h" -#include "shared/source/os_interface/product_helper.h" -#include "shared/test/common/helpers/debug_manager_state_restore.h" -#include "shared/test/common/helpers/default_hw_info.h" -#include "shared/test/common/libult/linux/drm_mock.h" -#include "shared/test/common/mocks/linux/mock_os_time_linux.h" -#include "shared/test/common/mocks/mock_execution_environment.h" -#include "shared/test/common/test_macros/test.h" - -#include "drm/xe_drm.h" +#include "shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.h" using namespace NEO; -struct MockIoctlHelperXe : IoctlHelperXe { - using IoctlHelperXe::bindInfo; - using IoctlHelperXe::defaultEngine; - using IoctlHelperXe::IoctlHelperXe; - using IoctlHelperXe::setDefaultEngine; - using IoctlHelperXe::xeGetBindFlagsName; - using IoctlHelperXe::xeGetBindOperationName; - using IoctlHelperXe::xeGetClassName; - using IoctlHelperXe::xeGetengineClassName; - using IoctlHelperXe::xeShowBindTable; -}; - TEST(IoctlHelperXeTest, givenXeDrmVersionsWhenGettingIoctlHelperThenValidIoctlHelperIsReturned) { auto executionEnvironment = std::make_unique(); DrmMock drm{*executionEnvironment->rootDeviceEnvironments[0]}; @@ -114,241 +86,6 @@ TEST(IoctlHelperXeTest, givenIoctlHelperXeWhenCallingGemCreateExtWithRegionsAndV EXPECT_FALSE(xeIoctlHelper->bindInfo.empty()); } -inline constexpr int testValueVmId = 0x5764; -inline constexpr int testValueMapOff = 0x7788; -inline constexpr int testValuePrime = 0x4321; -inline constexpr uint32_t testValueGemCreate = 0x8273; -class DrmMockXe : public DrmMockCustom { - public: - DrmMockXe(RootDeviceEnvironment &rootDeviceEnvironment) : DrmMockCustom(rootDeviceEnvironment) { - auto xeQueryMemUsage = reinterpret_cast(queryMemUsage); - xeQueryMemUsage->num_regions = 3; - xeQueryMemUsage->regions[0] = { - XE_MEM_REGION_CLASS_VRAM, // class - 1, // instance - 0, // padding - MemoryConstants::pageSize, // min page size - 2 * MemoryConstants::gigaByte, // total size - MemoryConstants::megaByte // used size - }; - xeQueryMemUsage->regions[1] = { - XE_MEM_REGION_CLASS_SYSMEM, // class - 0, // instance - 0, // padding - MemoryConstants::pageSize, // min page size - MemoryConstants::gigaByte, // total size - MemoryConstants::kiloByte // used size - }; - xeQueryMemUsage->regions[2] = { - XE_MEM_REGION_CLASS_VRAM, // class - 2, // instance - 0, // padding - MemoryConstants::pageSize, // min page size - 4 * MemoryConstants::gigaByte, // total size - MemoryConstants::gigaByte // used size - }; - - auto xeQueryGtList = reinterpret_cast(queryGtList.begin()); - xeQueryGtList->num_gt = 3; - xeQueryGtList->gt_list[0] = { - XE_QUERY_GT_TYPE_MAIN, // type - 0, // gt_id - 12500000, // clock_freq - 0b100, // native mem regions - 0x011, // slow mem regions - 0 // inaccessible mem regions - }; - xeQueryGtList->gt_list[1] = { - XE_QUERY_GT_TYPE_MEDIA, // type - 1, // gt_id - 12500000, // clock freq - 0b001, // native mem regions - 0x110, // slow mem regions - 0 // inaccessible mem regions - }; - xeQueryGtList->gt_list[2] = { - XE_QUERY_GT_TYPE_MAIN, // type - 0, // gt_id - 12500000, // clock freq - 0b010, // native mem regions - 0x101, // slow mem regions - 0 // inaccessible mem regions - }; - } - - void testMode(int f, int a = 0) { - forceIoctlAnswer = f; - setIoctlAnswer = a; - } - int ioctl(DrmIoctl request, void *arg) override { - int ret = -1; - ioctlCalled = true; - if (forceIoctlAnswer) { - return setIoctlAnswer; - } - switch (request) { - case DrmIoctl::GemVmCreate: { - struct drm_xe_vm_create *v = static_cast(arg); - v->vm_id = testValueVmId; - ret = 0; - } break; - case DrmIoctl::GemUserptr: - case DrmIoctl::GemClose: - ret = 0; - break; - case DrmIoctl::GemVmDestroy: { - struct drm_xe_vm_destroy *v = static_cast(arg); - if (v->vm_id == testValueVmId) - ret = 0; - } break; - case DrmIoctl::GemMmapOffset: { - struct drm_xe_gem_mmap_offset *v = static_cast(arg); - if (v->handle == testValueMapOff) { - v->offset = v->handle; - ret = 0; - } - } break; - case DrmIoctl::PrimeFdToHandle: { - PrimeHandle *v = static_cast(arg); - if (v->fileDescriptor == testValuePrime) { - v->handle = testValuePrime; - ret = 0; - } - } break; - case DrmIoctl::PrimeHandleToFd: { - PrimeHandle *v = static_cast(arg); - if (v->handle == testValuePrime) { - v->fileDescriptor = testValuePrime; - ret = 0; - } - } break; - case DrmIoctl::GemCreate: { - ioctlCnt.gemCreate++; - auto createParams = static_cast(arg); - this->createParamsSize = createParams->size; - this->createParamsFlags = createParams->flags; - this->createParamsHandle = createParams->handle = testValueGemCreate; - if (0 == this->createParamsSize || 0 == this->createParamsFlags) { - return EINVAL; - } - ret = 0; - } break; - case DrmIoctl::Getparam: - case DrmIoctl::GetResetStats: - ret = -2; - break; - case DrmIoctl::Query: { - struct drm_xe_device_query *deviceQuery = static_cast(arg); - switch (deviceQuery->query) { - case DRM_XE_DEVICE_QUERY_ENGINES: - if (deviceQuery->data) { - memcpy_s(reinterpret_cast(deviceQuery->data), deviceQuery->size, queryEngines, sizeof(queryEngines)); - } - deviceQuery->size = sizeof(queryEngines); - break; - case DRM_XE_DEVICE_QUERY_MEM_USAGE: - if (deviceQuery->data) { - memcpy_s(reinterpret_cast(deviceQuery->data), deviceQuery->size, queryMemUsage, sizeof(queryMemUsage)); - } - deviceQuery->size = sizeof(queryMemUsage); - break; - case DRM_XE_DEVICE_QUERY_GT_LIST: - if (deviceQuery->data) { - memcpy_s(reinterpret_cast(deviceQuery->data), deviceQuery->size, queryGtList.begin(), sizeof(queryGtList)); - } - deviceQuery->size = sizeof(queryGtList); - break; - case DRM_XE_DEVICE_QUERY_GT_TOPOLOGY: - if (deviceQuery->data) { - memcpy_s(reinterpret_cast(deviceQuery->data), deviceQuery->size, queryTopology.data(), queryTopology.size()); - } - deviceQuery->size = static_cast(queryTopology.size()); - break; - case DRM_XE_DEVICE_QUERY_ENGINE_CYCLES: - if (deviceQuery->data) { - memcpy_s(reinterpret_cast(deviceQuery->data), deviceQuery->size, queryEngineCycles, sizeof(queryEngineCycles)); - } - deviceQuery->size = sizeof(queryEngineCycles); - break; - }; - ret = 0; - } break; - case DrmIoctl::GemVmBind: { - ret = gemVmBindReturn; - auto vmBindInput = static_cast(arg); - vmBindInputs.push_back(*vmBindInput); - - EXPECT_EQ(1u, vmBindInput->num_syncs); - - auto &syncInput = reinterpret_cast(vmBindInput->syncs)[0]; - syncInputs.push_back(syncInput); - } break; - - case DrmIoctl::GemWaitUserFence: { - ret = waitUserFenceReturn; - auto waitUserFenceInput = static_cast(arg); - waitUserFenceInputs.push_back(*waitUserFenceInput); - } break; - - case DrmIoctl::GemContextSetparam: - case DrmIoctl::GemContextGetparam: - - default: - break; - } - return ret; - } - - void addMockedQueryTopologyData(uint16_t tileId, uint16_t maskType, uint32_t nBytes, const std::vector &mask) { - - ASSERT_EQ(nBytes, mask.size()); - - auto additionalSize = 8u + nBytes; - auto oldSize = queryTopology.size(); - auto newSize = oldSize + additionalSize; - queryTopology.resize(newSize, 0u); - - uint8_t *dataPtr = queryTopology.data() + oldSize; - - drm_xe_query_topology_mask *topo = reinterpret_cast(dataPtr); - topo->gt_id = tileId; - topo->type = maskType; - topo->num_bytes = nBytes; - - memcpy_s(reinterpret_cast(topo->mask), nBytes, mask.data(), nBytes); - } - - int forceIoctlAnswer = 0; - int setIoctlAnswer = 0; - int gemVmBindReturn = 0; - const drm_xe_engine_class_instance queryEngines[11] = { - {DRM_XE_ENGINE_CLASS_RENDER, 0, 0}, - {DRM_XE_ENGINE_CLASS_COPY, 1, 0}, - {DRM_XE_ENGINE_CLASS_COPY, 2, 0}, - {DRM_XE_ENGINE_CLASS_COMPUTE, 3, 0}, - {DRM_XE_ENGINE_CLASS_COMPUTE, 4, 0}, - {DRM_XE_ENGINE_CLASS_COMPUTE, 5, 1}, - {DRM_XE_ENGINE_CLASS_COMPUTE, 6, 1}, - {DRM_XE_ENGINE_CLASS_COMPUTE, 7, 1}, - {DRM_XE_ENGINE_CLASS_COMPUTE, 8, 1}, - {DRM_XE_ENGINE_CLASS_VIDEO_DECODE, 9, 1}, - {DRM_XE_ENGINE_CLASS_VIDEO_ENHANCE, 10, 0}}; - - static_assert(sizeof(drm_xe_query_mem_region) == 12 * sizeof(uint64_t), ""); - uint64_t queryMemUsage[37]{}; // 1 qword for num regions and 12 qwords per region - static_assert(sizeof(drm_xe_query_gt) == 12 * sizeof(uint64_t), ""); - StackVec queryGtList{}; // 1 qword for num gts and 12 qwords per gt - alignas(64) std::vector queryTopology; - static_assert(sizeof(drm_xe_query_engine_cycles) == 6 * sizeof(uint64_t), ""); - uint64_t queryEngineCycles[6]{}; // 1 qword for eci and 5 qwords - StackVec waitUserFenceInputs; - StackVec vmBindInputs; - StackVec syncInputs; - int waitUserFenceReturn = 0; - uint32_t createParamsFlags = 0u; - bool ioctlCalled = false; -}; - TEST(IoctlHelperXeTest, givenIoctlHelperXeWhenCallGemCreateAndNoLocalMemoryThenProperValuesSet) { DebugManagerStateRestore restorer; DebugManager.flags.EnableLocalMemory.set(0); @@ -648,6 +385,8 @@ TEST(IoctlHelperXeTest, givenIoctlHelperXeWhenCallingAnyMethodThenDummyValueIsRe verifyIoctlString(DrmIoctl::PrimeFdToHandle, "DRM_IOCTL_PRIME_FD_TO_HANDLE"); verifyIoctlString(DrmIoctl::PrimeHandleToFd, "DRM_IOCTL_PRIME_HANDLE_TO_FD"); + verifyIoctlString(DrmIoctl::DebuggerOpen, "???"); + EXPECT_TRUE(xeIoctlHelper->completionFenceExtensionSupported(true)); EXPECT_EQ(static_cast(XE_NEO_VMCREATE_DISABLESCRATCH_FLAG | @@ -1920,4 +1659,4 @@ TEST(IoctlHelperXeTest, givenXeIoctlHelperWhenInitializeGetGpuTimeFunctionIsCall xeIoctlHelper->initializeGetGpuTimeFunction(); EXPECT_EQ(xeIoctlHelper->getGpuTime, nullptr); -} \ No newline at end of file +} diff --git a/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.h b/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.h new file mode 100644 index 0000000000..f16c04b29e --- /dev/null +++ b/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.h @@ -0,0 +1,276 @@ +/* + * Copyright (C) 2023 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once + +#include "shared/source/helpers/common_types.h" +#include "shared/source/helpers/compiler_product_helper.h" +#include "shared/source/helpers/register_offsets.h" +#include "shared/source/os_interface/linux/engine_info.h" +#include "shared/source/os_interface/linux/i915_prelim.h" +#include "shared/source/os_interface/linux/ioctl_helper.h" +#include "shared/source/os_interface/linux/memory_info.h" +#include "shared/source/os_interface/linux/xe/ioctl_helper_xe.h" +#include "shared/source/os_interface/product_helper.h" +#include "shared/test/common/helpers/debug_manager_state_restore.h" +#include "shared/test/common/helpers/default_hw_info.h" +#include "shared/test/common/libult/linux/drm_mock.h" +#include "shared/test/common/mocks/linux/mock_os_time_linux.h" +#include "shared/test/common/mocks/mock_execution_environment.h" +#include "shared/test/common/test_macros/test.h" + +#include "drm/xe_drm.h" + +using namespace NEO; + +struct MockIoctlHelperXe : IoctlHelperXe { + using IoctlHelperXe::bindInfo; + using IoctlHelperXe::defaultEngine; + using IoctlHelperXe::getFdFromVmExport; + using IoctlHelperXe::IoctlHelperXe; + using IoctlHelperXe::setDefaultEngine; + using IoctlHelperXe::xeGetBindFlagsName; + using IoctlHelperXe::xeGetBindOperationName; + using IoctlHelperXe::xeGetClassName; + using IoctlHelperXe::xeGetengineClassName; + using IoctlHelperXe::xeShowBindTable; +}; + +inline constexpr int testValueVmId = 0x5764; +inline constexpr int testValueMapOff = 0x7788; +inline constexpr int testValuePrime = 0x4321; +inline constexpr uint32_t testValueGemCreate = 0x8273; +class DrmMockXe : public DrmMockCustom { + public: + DrmMockXe(RootDeviceEnvironment &rootDeviceEnvironment) : DrmMockCustom(rootDeviceEnvironment) { + auto xeQueryMemUsage = reinterpret_cast(queryMemUsage); + xeQueryMemUsage->num_regions = 3; + xeQueryMemUsage->regions[0] = { + XE_MEM_REGION_CLASS_VRAM, // class + 1, // instance + 0, // padding + MemoryConstants::pageSize, // min page size + 2 * MemoryConstants::gigaByte, // total size + MemoryConstants::megaByte // used size + }; + xeQueryMemUsage->regions[1] = { + XE_MEM_REGION_CLASS_SYSMEM, // class + 0, // instance + 0, // padding + MemoryConstants::pageSize, // min page size + MemoryConstants::gigaByte, // total size + MemoryConstants::kiloByte // used size + }; + xeQueryMemUsage->regions[2] = { + XE_MEM_REGION_CLASS_VRAM, // class + 2, // instance + 0, // padding + MemoryConstants::pageSize, // min page size + 4 * MemoryConstants::gigaByte, // total size + MemoryConstants::gigaByte // used size + }; + + auto xeQueryGtList = reinterpret_cast(queryGtList.begin()); + xeQueryGtList->num_gt = 3; + xeQueryGtList->gt_list[0] = { + XE_QUERY_GT_TYPE_MAIN, // type + 0, // gt_id + 12500000, // clock_freq + 0b100, // native mem regions + 0x011, // slow mem regions + 0 // inaccessible mem regions + }; + xeQueryGtList->gt_list[1] = { + XE_QUERY_GT_TYPE_MEDIA, // type + 1, // gt_id + 12500000, // clock freq + 0b001, // native mem regions + 0x110, // slow mem regions + 0 // inaccessible mem regions + }; + xeQueryGtList->gt_list[2] = { + XE_QUERY_GT_TYPE_MAIN, // type + 0, // gt_id + 12500000, // clock freq + 0b010, // native mem regions + 0x101, // slow mem regions + 0 // inaccessible mem regions + }; + } + + void testMode(int f, int a = 0) { + forceIoctlAnswer = f; + setIoctlAnswer = a; + } + int ioctl(DrmIoctl request, void *arg) override { + int ret = -1; + ioctlCalled = true; + if (forceIoctlAnswer) { + return setIoctlAnswer; + } + switch (request) { + case DrmIoctl::GemVmCreate: { + struct drm_xe_vm_create *v = static_cast(arg); + v->vm_id = testValueVmId; + ret = 0; + } break; + case DrmIoctl::GemUserptr: + case DrmIoctl::GemClose: + ret = 0; + break; + case DrmIoctl::GemVmDestroy: { + struct drm_xe_vm_destroy *v = static_cast(arg); + if (v->vm_id == testValueVmId) + ret = 0; + } break; + case DrmIoctl::GemMmapOffset: { + struct drm_xe_gem_mmap_offset *v = static_cast(arg); + if (v->handle == testValueMapOff) { + v->offset = v->handle; + ret = 0; + } + } break; + case DrmIoctl::PrimeFdToHandle: { + PrimeHandle *v = static_cast(arg); + if (v->fileDescriptor == testValuePrime) { + v->handle = testValuePrime; + ret = 0; + } + } break; + case DrmIoctl::PrimeHandleToFd: { + PrimeHandle *v = static_cast(arg); + if (v->handle == testValuePrime) { + v->fileDescriptor = testValuePrime; + ret = 0; + } + } break; + case DrmIoctl::GemCreate: { + ioctlCnt.gemCreate++; + auto createParams = static_cast(arg); + this->createParamsSize = createParams->size; + this->createParamsFlags = createParams->flags; + this->createParamsHandle = createParams->handle = testValueGemCreate; + if (0 == this->createParamsSize || 0 == this->createParamsFlags) { + return EINVAL; + } + ret = 0; + } break; + case DrmIoctl::Getparam: + case DrmIoctl::GetResetStats: + ret = -2; + break; + case DrmIoctl::Query: { + struct drm_xe_device_query *deviceQuery = static_cast(arg); + switch (deviceQuery->query) { + case DRM_XE_DEVICE_QUERY_ENGINES: + if (deviceQuery->data) { + memcpy_s(reinterpret_cast(deviceQuery->data), deviceQuery->size, queryEngines, sizeof(queryEngines)); + } + deviceQuery->size = sizeof(queryEngines); + break; + case DRM_XE_DEVICE_QUERY_MEM_USAGE: + if (deviceQuery->data) { + memcpy_s(reinterpret_cast(deviceQuery->data), deviceQuery->size, queryMemUsage, sizeof(queryMemUsage)); + } + deviceQuery->size = sizeof(queryMemUsage); + break; + case DRM_XE_DEVICE_QUERY_GT_LIST: + if (deviceQuery->data) { + memcpy_s(reinterpret_cast(deviceQuery->data), deviceQuery->size, queryGtList.begin(), sizeof(queryGtList)); + } + deviceQuery->size = sizeof(queryGtList); + break; + case DRM_XE_DEVICE_QUERY_GT_TOPOLOGY: + if (deviceQuery->data) { + memcpy_s(reinterpret_cast(deviceQuery->data), deviceQuery->size, queryTopology.data(), queryTopology.size()); + } + deviceQuery->size = static_cast(queryTopology.size()); + break; + case DRM_XE_DEVICE_QUERY_ENGINE_CYCLES: + if (deviceQuery->data) { + memcpy_s(reinterpret_cast(deviceQuery->data), deviceQuery->size, queryEngineCycles, sizeof(queryEngineCycles)); + } + deviceQuery->size = sizeof(queryEngineCycles); + break; + }; + ret = 0; + } break; + case DrmIoctl::GemVmBind: { + ret = gemVmBindReturn; + auto vmBindInput = static_cast(arg); + vmBindInputs.push_back(*vmBindInput); + + EXPECT_EQ(1u, vmBindInput->num_syncs); + + auto &syncInput = reinterpret_cast(vmBindInput->syncs)[0]; + syncInputs.push_back(syncInput); + } break; + + case DrmIoctl::GemWaitUserFence: { + ret = waitUserFenceReturn; + auto waitUserFenceInput = static_cast(arg); + waitUserFenceInputs.push_back(*waitUserFenceInput); + } break; + + case DrmIoctl::GemContextSetparam: + case DrmIoctl::GemContextGetparam: + + default: + break; + } + return ret; + } + + void addMockedQueryTopologyData(uint16_t tileId, uint16_t maskType, uint32_t nBytes, const std::vector &mask) { + + ASSERT_EQ(nBytes, mask.size()); + + auto additionalSize = 8u + nBytes; + auto oldSize = queryTopology.size(); + auto newSize = oldSize + additionalSize; + queryTopology.resize(newSize, 0u); + + uint8_t *dataPtr = queryTopology.data() + oldSize; + + drm_xe_query_topology_mask *topo = reinterpret_cast(dataPtr); + topo->gt_id = tileId; + topo->type = maskType; + topo->num_bytes = nBytes; + + memcpy_s(reinterpret_cast(topo->mask), nBytes, mask.data(), nBytes); + } + + int forceIoctlAnswer = 0; + int setIoctlAnswer = 0; + int gemVmBindReturn = 0; + const drm_xe_engine_class_instance queryEngines[11] = { + {DRM_XE_ENGINE_CLASS_RENDER, 0, 0}, + {DRM_XE_ENGINE_CLASS_COPY, 1, 0}, + {DRM_XE_ENGINE_CLASS_COPY, 2, 0}, + {DRM_XE_ENGINE_CLASS_COMPUTE, 3, 0}, + {DRM_XE_ENGINE_CLASS_COMPUTE, 4, 0}, + {DRM_XE_ENGINE_CLASS_COMPUTE, 5, 1}, + {DRM_XE_ENGINE_CLASS_COMPUTE, 6, 1}, + {DRM_XE_ENGINE_CLASS_COMPUTE, 7, 1}, + {DRM_XE_ENGINE_CLASS_COMPUTE, 8, 1}, + {DRM_XE_ENGINE_CLASS_VIDEO_DECODE, 9, 1}, + {DRM_XE_ENGINE_CLASS_VIDEO_ENHANCE, 10, 0}}; + + static_assert(sizeof(drm_xe_query_mem_region) == 12 * sizeof(uint64_t), ""); + uint64_t queryMemUsage[37]{}; // 1 qword for num regions and 12 qwords per region + static_assert(sizeof(drm_xe_query_gt) == 12 * sizeof(uint64_t), ""); + StackVec queryGtList{}; // 1 qword for num gts and 12 qwords per gt + alignas(64) std::vector queryTopology; + static_assert(sizeof(drm_xe_query_engine_cycles) == 6 * sizeof(uint64_t), ""); + uint64_t queryEngineCycles[6]{}; // 1 qword for eci and 5 qwords + StackVec waitUserFenceInputs; + StackVec vmBindInputs; + StackVec syncInputs; + int waitUserFenceReturn = 0; + uint32_t createParamsFlags = 0u; + bool ioctlCalled = false; +}; diff --git a/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_vm_export_tests.cpp b/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_vm_export_tests.cpp new file mode 100644 index 0000000000..44a7f62c14 --- /dev/null +++ b/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_vm_export_tests.cpp @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2023 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.h" + +using namespace NEO; + +TEST(IoctlHelperXeTest, whenGetFdFromVmExportIsCalledThenFalseIsReturned) { + auto executionEnvironment = std::make_unique(); + DrmMockXe drm{*executionEnvironment->rootDeviceEnvironments[0]}; + auto xeIoctlHelper = std::make_unique(drm); + uint32_t vmId = 0, flags = 0; + int32_t fd = 0; + EXPECT_FALSE(xeIoctlHelper->getFdFromVmExport(vmId, flags, &fd)); +}