diff --git a/level_zero/CMakeLists.txt b/level_zero/CMakeLists.txt index ecd17c68b3..0e4d729b04 100644 --- a/level_zero/CMakeLists.txt +++ b/level_zero/CMakeLists.txt @@ -255,7 +255,6 @@ if(BUILD_WITH_L0) ${NEO_SHARED_DIRECTORY}/dll/devices${BRANCH_DIR_SUFFIX}devices.inl ${NEO_SHARED_DIRECTORY}/dll/devices${BRANCH_DIR_SUFFIX}devices_additional.inl ${NEO_SHARED_DIRECTORY}/dll/devices/devices_base.inl - ${COMPUTE_RUNTIME_DIR}/opencl/source/dll/linux/allocator_helper.cpp ${COMPUTE_RUNTIME_DIR}/opencl/source/dll/linux/options_linux.cpp ${COMPUTE_RUNTIME_DIR}/opencl/source/dll/linux/os_interface.cpp ) diff --git a/level_zero/cmake/l0_tests.cmake b/level_zero/cmake/l0_tests.cmake index edc76f7351..a6eaad2259 100644 --- a/level_zero/cmake/l0_tests.cmake +++ b/level_zero/cmake/l0_tests.cmake @@ -40,11 +40,11 @@ add_library(compute_runtime_mockable_extra ${NEO_SHARED_TEST_DIRECTORY}/common/mocks/mock_deferred_deleter.cpp ${NEO_SHARED_TEST_DIRECTORY}/common/mocks/mock_device.cpp ${NEO_SHARED_TEST_DIRECTORY}/common/mocks/mock_gmm_client_context_base.cpp + ${NEO_SHARED_TEST_DIRECTORY}/common/mocks/mock_gmm_resource_info_common.cpp ${NEO_SHARED_TEST_DIRECTORY}/common/mocks/mock_sip.cpp ${NEO_SHARED_TEST_DIRECTORY}/unit_test/helpers/debug_helpers.cpp ${NEO_SHARED_TEST_DIRECTORY}/unit_test/utilities/cpuintrinsics.cpp ${NEO_SOURCE_DIR}/opencl/test/unit_test/mocks/mock_gmm_page_table_mngr.cpp - ${NEO_SOURCE_DIR}/opencl/test/unit_test/mocks/mock_gmm_resource_info.cpp ${NEO_SOURCE_DIR}/opencl/test/unit_test/mocks/mock_program.cpp ${NEO_SHARED_DIRECTORY}/debug_settings/debug_settings_manager.cpp ) @@ -86,7 +86,8 @@ endif() if(UNIX) target_sources(compute_runtime_mockable_extra PRIVATE - ${NEO_SOURCE_DIR}/opencl/source/dll/linux/allocator_helper.cpp + ${NEO_SHARED_DIRECTORY}/gmm_helper/resource_info_impl.cpp + ${NEO_SHARED_DIRECTORY}/gmm_helper${BRANCH_DIR_SUFFIX}resource_info_${DRIVER_MODEL}.cpp ${NEO_SHARED_DIRECTORY}/tbx/tbx_sockets_imp.cpp ) target_link_libraries(compute_runtime_mockable_extra diff --git a/level_zero/core/test/aub_tests/CMakeLists.txt b/level_zero/core/test/aub_tests/CMakeLists.txt index 5f6dab5b39..416556b744 100644 --- a/level_zero/core/test/aub_tests/CMakeLists.txt +++ b/level_zero/core/test/aub_tests/CMakeLists.txt @@ -61,6 +61,7 @@ target_sources(${TARGET_NAME} PRIVATE ${NEO_SHARED_TEST_DIRECTORY}/common/mocks/mock_deferred_deleter.cpp ${NEO_SHARED_TEST_DIRECTORY}/common/mocks/mock_device.cpp ${NEO_SHARED_TEST_DIRECTORY}/common/mocks/mock_gmm_client_context_base.cpp + ${NEO_SHARED_TEST_DIRECTORY}/common/mocks/mock_gmm_resource_info_common.cpp ${NEO_SHARED_TEST_DIRECTORY}/common/mocks/mock_sip.cpp ${NEO_SHARED_DIRECTORY}/debug_settings/debug_settings_manager.cpp ${NEO_SHARED_DIRECTORY}/aub/aub_stream_interface.cpp @@ -97,7 +98,6 @@ if(UNIX) ${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/linux/drm_neo_create.cpp ${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/linux/options.cpp ${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/linux/sys_calls_linux_ult.cpp - ${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/linux/allocator_helper.cpp ${NEO_SHARED_DIRECTORY}/os_interface/linux/gmm_interface_linux.cpp ) else() diff --git a/level_zero/core/test/unit_tests/mocks/mock_gmm_resource_info_l0.cpp b/level_zero/core/test/unit_tests/mocks/mock_gmm_resource_info_l0.cpp index f652d34131..e70e6e904f 100644 --- a/level_zero/core/test/unit_tests/mocks/mock_gmm_resource_info_l0.cpp +++ b/level_zero/core/test/unit_tests/mocks/mock_gmm_resource_info_l0.cpp @@ -1,88 +1,17 @@ /* - * Copyright (C) 2020 Intel Corporation + * Copyright (C) 2020-2021 Intel Corporation * * SPDX-License-Identifier: MIT * */ -#include "shared/source/helpers/aligned_memory.h" - -#include "opencl/test/unit_test/mocks/mock_gmm_resource_info.h" +#include "shared/test/common/mocks/mock_gmm_resource_info.h" #include "level_zero/core/source/image/image_formats.h" using namespace ::testing; namespace NEO { -GmmResourceInfo *GmmResourceInfo::create(GmmClientContext *clientContext, GMM_RESCREATE_PARAMS *resourceCreateParams) { - if (resourceCreateParams->Type == GMM_RESOURCE_TYPE::RESOURCE_INVALID) { - return nullptr; - } - return new ::testing::NiceMock(resourceCreateParams); -} - -GmmResourceInfo *GmmResourceInfo::create(GmmClientContext *clientContext, GMM_RESOURCE_INFO *inputGmmResourceInfo) { - return new ::testing::NiceMock(inputGmmResourceInfo); -} - -MockGmmResourceInfo::MockGmmResourceInfo(GMM_RESCREATE_PARAMS *resourceCreateParams) { - mockResourceCreateParams = *resourceCreateParams; - setupDefaultActions(); -} - -MockGmmResourceInfo::MockGmmResourceInfo(GMM_RESOURCE_INFO *inputGmmResourceInfo) { - mockResourceCreateParams = reinterpret_cast(inputGmmResourceInfo)->mockResourceCreateParams; - setupDefaultActions(); -}; - -// Simulate GMM behaviour. We dont want to test 3rd party lib -void MockGmmResourceInfo::setupDefaultActions() { - setSurfaceFormat(); - if (surfaceFormatInfo == nullptr) { - ASSERT_TRUE(false); - return; - } - computeRowPitch(); - - size = rowPitch; - size *= static_cast(mockResourceCreateParams.BaseHeight); - - qPitch = alignUp((uint32_t)size, 64); - - size *= mockResourceCreateParams.Depth ? static_cast(mockResourceCreateParams.Depth) : 1; - size *= mockResourceCreateParams.ArraySize ? static_cast(mockResourceCreateParams.ArraySize) : 1; - size = alignUp(size, MemoryConstants::pageSize); -} - -GMM_STATUS MockGmmResourceInfo::getOffset(GMM_REQ_OFFSET_INFO &reqOffsetInfo) { - arrayIndexPassedToGetOffset = reqOffsetInfo.ArrayIndex; - getOffsetCalled++; - - reqOffsetInfo.Lock.Offset = 16; - reqOffsetInfo.Lock.Pitch = 2; - reqOffsetInfo.Render.YOffset = 1; - if (mockResourceCreateParams.Format == GMM_RESOURCE_FORMAT::GMM_FORMAT_NV12) { - reqOffsetInfo.Render.XOffset = 32; - reqOffsetInfo.Render.Offset = 64; - } - if (reqOffsetInfo.Slice == 1) { - reqOffsetInfo.Render.YOffset = mockResourceCreateParams.BaseHeight; - } - if (reqOffsetInfo.MipLevel > 0) { - reqOffsetInfo.Lock.Offset = 32; - } - - return GMM_SUCCESS; -} - -void MockGmmResourceInfo::computeRowPitch() { - if (mockResourceCreateParams.OverridePitch) { - rowPitch = mockResourceCreateParams.OverridePitch; - } else { - rowPitch = static_cast(mockResourceCreateParams.BaseWidth64 * (surfaceFormatInfo->ImageElementSizeInBytes)); - rowPitch = alignUp(rowPitch, 64); - } -} void MockGmmResourceInfo::setSurfaceFormat() { auto iterateL0Formats = [&](const std::array &formats) { @@ -108,41 +37,4 @@ void MockGmmResourceInfo::setSurfaceFormat() { ASSERT_NE(nullptr, surfaceFormatInfo); } - -uint32_t MockGmmResourceInfo::getBitsPerPixel() { - return static_cast(surfaceFormatInfo->ImageElementSizeInBytes * 8); -} - -void MockGmmResourceInfo::setUnifiedAuxTranslationCapable() { - mockResourceCreateParams.Flags.Gpu.CCS = 1; - mockResourceCreateParams.Flags.Gpu.UnifiedAuxSurface = 1; - mockResourceCreateParams.Flags.Info.RenderCompressed = 1; -} - -void MockGmmResourceInfo::setMultisampleControlSurface() { - mockResourceCreateParams.Flags.Gpu.MCS = 1; -} - -void MockGmmResourceInfo::setUnifiedAuxPitchTiles(uint32_t value) { - this->unifiedAuxPitch = value; -} -void MockGmmResourceInfo::setAuxQPitch(uint32_t value) { - this->auxQPitch = value; -} - -uint32_t MockGmmResourceInfo::getTileModeSurfaceState() { - if (mockResourceCreateParams.Flags.Info.Linear == 1) { - return 0; - } - - if (mockResourceCreateParams.Type == GMM_RESOURCE_TYPE::RESOURCE_2D || - mockResourceCreateParams.Type == GMM_RESOURCE_TYPE::RESOURCE_3D) { - return 3; - } else { - return 0; - } -} - -MockGmmResourceInfo::MockGmmResourceInfo() {} -MockGmmResourceInfo::~MockGmmResourceInfo() {} } // namespace NEO diff --git a/opencl/source/dll/CMakeLists.txt b/opencl/source/dll/CMakeLists.txt index 09ea021a95..28be6938b1 100644 --- a/opencl/source/dll/CMakeLists.txt +++ b/opencl/source/dll/CMakeLists.txt @@ -41,7 +41,6 @@ set(RUNTIME_SRCS_DLL_BASE append_sources_from_properties(RUNTIME_SRCS_DLL_BASE NEO_CORE_SRCS_LINK) set(RUNTIME_SRCS_DLL_LINUX - ${CMAKE_CURRENT_SOURCE_DIR}/linux/allocator_helper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/linux/drm_neo_create.cpp ${CMAKE_CURRENT_SOURCE_DIR}/linux/options_linux.cpp ${CMAKE_CURRENT_SOURCE_DIR}/linux/os_interface.cpp diff --git a/opencl/source/dll/create_memory_manager_drm.cpp b/opencl/source/dll/create_memory_manager_drm.cpp index e491877dab..63d660e007 100644 --- a/opencl/source/dll/create_memory_manager_drm.cpp +++ b/opencl/source/dll/create_memory_manager_drm.cpp @@ -11,4 +11,8 @@ namespace NEO { std::unique_ptr MemoryManager::createMemoryManager(ExecutionEnvironment &executionEnvironment, DriverModelType driverModel) { return DrmMemoryManager::create(executionEnvironment); } + +size_t getSizeToReserve() { + return (maxNBitValue(47) + 1) / 4; +} } // namespace NEO diff --git a/opencl/source/dll/create_memory_manager_drm_or_wddm.cpp b/opencl/source/dll/create_memory_manager_drm_or_wddm.cpp index 0bf4a82300..f25424fd9e 100644 --- a/opencl/source/dll/create_memory_manager_drm_or_wddm.cpp +++ b/opencl/source/dll/create_memory_manager_drm_or_wddm.cpp @@ -16,4 +16,7 @@ std::unique_ptr MemoryManager::createMemoryManager(ExecutionEnvir return std::make_unique(executionEnvironment); } } +size_t getSizeToReserve() { + return (maxNBitValue(47) + 1) / 4; +} } // namespace NEO diff --git a/opencl/source/dll/linux/allocator_helper.cpp b/opencl/source/dll/linux/allocator_helper.cpp deleted file mode 100644 index 790aa1115f..0000000000 --- a/opencl/source/dll/linux/allocator_helper.cpp +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (C) 2018-2020 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#include "shared/source/os_interface/linux/allocator_helper.h" - -#include "shared/source/helpers/aligned_memory.h" -#include "shared/source/helpers/basic_math.h" - -namespace NEO { - -size_t getSizeToReserve() { - return (maxNBitValue(47) + 1) / 4; -} - -} // namespace NEO diff --git a/opencl/test/unit_test/aub_mem_dump/aub_alloc_dump_tests.cpp b/opencl/test/unit_test/aub_mem_dump/aub_alloc_dump_tests.cpp index 72ff45c25e..48fc019651 100644 --- a/opencl/test/unit_test/aub_mem_dump/aub_alloc_dump_tests.cpp +++ b/opencl/test/unit_test/aub_mem_dump/aub_alloc_dump_tests.cpp @@ -9,6 +9,7 @@ #include "shared/source/gmm_helper/gmm.h" #include "shared/source/gmm_helper/gmm_helper.h" #include "shared/test/common/helpers/debug_manager_state_restore.h" +#include "shared/test/common/mocks/mock_gmm_resource_info.h" #include "shared/test/common/mocks/mock_memory_manager.h" #include "opencl/source/mem_obj/buffer.h" @@ -16,7 +17,6 @@ #include "opencl/test/unit_test/fixtures/image_fixture.h" #include "opencl/test/unit_test/mocks/mock_allocation_properties.h" #include "opencl/test/unit_test/mocks/mock_gmm.h" -#include "opencl/test/unit_test/mocks/mock_gmm_resource_info.h" #include "test.h" using namespace NEO; diff --git a/opencl/test/unit_test/libult/CMakeLists.txt b/opencl/test/unit_test/libult/CMakeLists.txt index ee21989322..a3aecb6373 100644 --- a/opencl/test/unit_test/libult/CMakeLists.txt +++ b/opencl/test/unit_test/libult/CMakeLists.txt @@ -72,7 +72,6 @@ set(IGDRCL_SRCS_LIB_ULT_ENV_WINDOWS ) set(IGDRCL_SRCS_LIB_ULT_ENV_LINUX - ${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/linux/allocator_helper.cpp ${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/linux/create_drm_memory_manager.cpp ${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/linux/options.cpp ${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/linux/sys_calls_linux_ult.cpp diff --git a/opencl/test/unit_test/linux/CMakeLists.txt b/opencl/test/unit_test/linux/CMakeLists.txt index 2c5fa8d924..3e4f2f7e2e 100644 --- a/opencl/test/unit_test/linux/CMakeLists.txt +++ b/opencl/test/unit_test/linux/CMakeLists.txt @@ -23,14 +23,13 @@ add_executable(igdrcl_${target_name} ${CMAKE_CURRENT_SOURCE_DIR}/test_mode.h ${NEO_SHARED_DIRECTORY}/os_interface/linux/sys_calls_linux.cpp ${NEO_SHARED_TEST_DIRECTORY}/common/aub_stream_mocks/aub_stream_interface_mock.cpp - ${NEO_SOURCE_DIR}/opencl/source/dll/linux/allocator_helper.cpp + ${NEO_SOURCE_DIR}/opencl/source/dll/create_memory_manager_drm.cpp ${NEO_SOURCE_DIR}/opencl/source/dll/linux/drm_neo_create.cpp ${NEO_SOURCE_DIR}/opencl/source/dll/linux/options_linux.cpp ${NEO_SOURCE_DIR}/opencl/source/dll/linux/os_interface.cpp ${NEO_SOURCE_DIR}/opencl/source/helpers/api_specific_config_ocl.cpp ${NEO_SOURCE_DIR}/opencl/source/os_interface/linux/platform_teardown_linux.cpp ${NEO_SOURCE_DIR}/opencl/test/unit_test/linux${BRANCH_DIR_SUFFIX}drm_other_requests.cpp - ${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/linux/create_drm_memory_manager.cpp ${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/linux/device_command_stream_fixture.cpp ) if(NEO__LIBVA_FOUND) diff --git a/opencl/test/unit_test/mem_obj/image_set_arg_tests.cpp b/opencl/test/unit_test/mem_obj/image_set_arg_tests.cpp index 17e0fd995b..cb250cbd93 100644 --- a/opencl/test/unit_test/mem_obj/image_set_arg_tests.cpp +++ b/opencl/test/unit_test/mem_obj/image_set_arg_tests.cpp @@ -12,6 +12,7 @@ #include "shared/source/helpers/ptr_math.h" #include "shared/source/memory_manager/graphics_allocation.h" #include "shared/source/memory_manager/surface.h" +#include "shared/test/common/mocks/mock_gmm_resource_info.h" #include "shared/test/common/mocks/mock_graphics_allocation.h" #include "opencl/source/helpers/surface_formats.h" @@ -21,7 +22,6 @@ #include "opencl/test/unit_test/fixtures/image_fixture.h" #include "opencl/test/unit_test/mocks/mock_allocation_properties.h" #include "opencl/test/unit_test/mocks/mock_gmm.h" -#include "opencl/test/unit_test/mocks/mock_gmm_resource_info.h" #include "opencl/test/unit_test/mocks/mock_kernel.h" #include "opencl/test/unit_test/mocks/mock_program.h" #include "test.h" diff --git a/opencl/test/unit_test/mem_obj/nv12_image_tests.cpp b/opencl/test/unit_test/mem_obj/nv12_image_tests.cpp index ab379b0e62..bdbce4f111 100644 --- a/opencl/test/unit_test/mem_obj/nv12_image_tests.cpp +++ b/opencl/test/unit_test/mem_obj/nv12_image_tests.cpp @@ -9,6 +9,7 @@ #include "shared/source/helpers/aligned_memory.h" #include "shared/test/common/helpers/debug_manager_state_restore.h" #include "shared/test/common/helpers/kernel_binary_helper.h" +#include "shared/test/common/mocks/mock_gmm_resource_info.h" #include "opencl/source/cl_device/cl_device_get_cap.inl" #include "opencl/source/helpers/cl_memory_properties_helpers.h" @@ -19,7 +20,6 @@ #include "opencl/test/unit_test/mocks/mock_buffer.h" #include "opencl/test/unit_test/mocks/mock_command_queue.h" #include "opencl/test/unit_test/mocks/mock_context.h" -#include "opencl/test/unit_test/mocks/mock_gmm_resource_info.h" #include "opencl/test/unit_test/test_macros/test_checks_ocl.h" #include "test.h" diff --git a/opencl/test/unit_test/mocks/CMakeLists.txt b/opencl/test/unit_test/mocks/CMakeLists.txt index 125f77ec34..2cacf06a65 100644 --- a/opencl/test/unit_test/mocks/CMakeLists.txt +++ b/opencl/test/unit_test/mocks/CMakeLists.txt @@ -29,8 +29,7 @@ set(IGDRCL_SRCS_tests_mocks ${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm_page_table_mngr.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm_page_table_mngr.h - ${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm_resource_info.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm_resource_info.h + ${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm_resource_info_ocl.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mock_image.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_internal_allocation_storage.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_kernel.cpp diff --git a/opencl/test/unit_test/mocks/mock_gmm.h b/opencl/test/unit_test/mocks/mock_gmm.h index 291ab339dc..26d6dc0110 100644 --- a/opencl/test/unit_test/mocks/mock_gmm.h +++ b/opencl/test/unit_test/mocks/mock_gmm.h @@ -9,11 +9,11 @@ #include "shared/source/gmm_helper/gmm.h" #include "shared/source/memory_manager/memory_manager.h" #include "shared/test/common/mocks/mock_device.h" +#include "shared/test/common/mocks/mock_gmm_resource_info.h" #include "shared/test/common/mocks/mock_graphics_allocation.h" #include "opencl/source/helpers/surface_formats.h" #include "opencl/source/mem_obj/image.h" -#include "opencl/test/unit_test/mocks/mock_gmm_resource_info.h" namespace NEO { namespace MockGmmParams { diff --git a/opencl/test/unit_test/mocks/mock_gmm_resource_info_ocl.cpp b/opencl/test/unit_test/mocks/mock_gmm_resource_info_ocl.cpp new file mode 100644 index 0000000000..fc55383f33 --- /dev/null +++ b/opencl/test/unit_test/mocks/mock_gmm_resource_info_ocl.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2018-2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/test/common/mocks/mock_gmm_resource_info.h" + +#include "opencl/source/helpers/surface_formats.h" + +namespace NEO { + +void MockGmmResourceInfo::setSurfaceFormat() { + auto iterate = [&](ArrayRef formats) { + if (!surfaceFormatInfo) { + for (auto &format : formats) { + if (mockResourceCreateParams.Format == format.surfaceFormat.GMMSurfaceFormat) { + surfaceFormatInfo = &format.surfaceFormat; + break; + } + } + } + }; + + if (mockResourceCreateParams.Format == GMM_RESOURCE_FORMAT::GMM_FORMAT_P010 || mockResourceCreateParams.Format == GMM_RESOURCE_FORMAT::GMM_FORMAT_P016) { + tempSurface.GMMSurfaceFormat = mockResourceCreateParams.Format; + tempSurface.NumChannels = 1; + tempSurface.ImageElementSizeInBytes = 16; + tempSurface.PerChannelSizeInBytes = 16; + + surfaceFormatInfo = &tempSurface; + } + + if (mockResourceCreateParams.Format == GMM_RESOURCE_FORMAT::GMM_FORMAT_RGBP) { + tempSurface.GMMSurfaceFormat = GMM_RESOURCE_FORMAT::GMM_FORMAT_RGBP; + tempSurface.NumChannels = 1; + tempSurface.ImageElementSizeInBytes = 8; + tempSurface.PerChannelSizeInBytes = 8; + + surfaceFormatInfo = &tempSurface; + } + + iterate(SurfaceFormats::readOnly12()); + iterate(SurfaceFormats::readOnly20()); + iterate(SurfaceFormats::writeOnly()); + iterate(SurfaceFormats::readWrite()); + + iterate(SurfaceFormats::packedYuv()); + iterate(SurfaceFormats::planarYuv()); + iterate(SurfaceFormats::packed()); + + iterate(SurfaceFormats::readOnlyDepth()); + iterate(SurfaceFormats::readWriteDepth()); + + ASSERT_NE(nullptr, surfaceFormatInfo); +} +} // namespace NEO diff --git a/opencl/test/unit_test/os_interface/linux/allocator_helper.cpp b/opencl/test/unit_test/os_interface/linux/allocator_helper.cpp deleted file mode 100644 index b1c769b8cf..0000000000 --- a/opencl/test/unit_test/os_interface/linux/allocator_helper.cpp +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (C) 2018-2020 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#include "shared/source/os_interface/linux/allocator_helper.h" - -#include "shared/source/helpers/constants.h" - -namespace NEO { - -size_t getSizeToReserve() { - // 4 x sizeof(Heap32) + 2 x sizeof(Standard/Standard64k) - return (4 * 4 + 2 * 4) * GB; -} - -} // namespace NEO diff --git a/opencl/test/unit_test/os_interface/linux/create_drm_memory_manager.cpp b/opencl/test/unit_test/os_interface/linux/create_drm_memory_manager.cpp index 67ab25d15b..9a695a4744 100644 --- a/opencl/test/unit_test/os_interface/linux/create_drm_memory_manager.cpp +++ b/opencl/test/unit_test/os_interface/linux/create_drm_memory_manager.cpp @@ -19,4 +19,8 @@ std::unique_ptr MemoryManager::createMemoryManager(ExecutionEnvir } return DrmMemoryManager::create(executionEnvironment); } +size_t getSizeToReserve() { + // 4 x sizeof(Heap32) + 2 x sizeof(Standard/Standard64k) + return (4 * 4 + 2 * 4) * GB; +} } // namespace NEO diff --git a/opencl/test/unit_test/os_interface/windows/wddm20_tests.cpp b/opencl/test/unit_test/os_interface/windows/wddm20_tests.cpp index aea6bad13b..0591bed8da 100644 --- a/opencl/test/unit_test/os_interface/windows/wddm20_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/wddm20_tests.cpp @@ -26,12 +26,12 @@ #include "shared/test/common/helpers/variable_backup.h" #include "shared/test/common/mocks/mock_execution_environment.h" #include "shared/test/common/mocks/mock_gfx_partition.h" +#include "shared/test/common/mocks/mock_gmm_resource_info.h" #include "shared/test/common/mocks/mock_io_functions.h" #include "shared/test/common/mocks/mock_memory_manager.h" #include "shared/test/common/mocks/mock_wddm_residency_logger.h" #include "shared/test/common/os_interface/windows/wddm_fixture.h" -#include "opencl/test/unit_test/mocks/mock_gmm_resource_info.h" #include "opencl/test/unit_test/os_interface/windows/mock_wddm_allocation.h" #include "opencl/test/unit_test/os_interface/windows/ult_dxcore_factory.h" diff --git a/opencl/test/unit_test/sharings/gl/windows/gl_sharing_tests.cpp b/opencl/test/unit_test/sharings/gl/windows/gl_sharing_tests.cpp index 9b719ec99b..f9441ba483 100644 --- a/opencl/test/unit_test/sharings/gl/windows/gl_sharing_tests.cpp +++ b/opencl/test/unit_test/sharings/gl/windows/gl_sharing_tests.cpp @@ -11,6 +11,7 @@ #include "shared/source/os_interface/os_interface.h" #include "shared/test/common/helpers/debug_manager_state_restore.h" #include "shared/test/common/mocks/mock_device.h" +#include "shared/test/common/mocks/mock_gmm_resource_info.h" #include "shared/test/common/mocks/mock_memory_manager.h" #include "opencl/source/command_queue/command_queue.h" @@ -34,7 +35,6 @@ #include "opencl/test/unit_test/mocks/mock_context.h" #include "opencl/test/unit_test/mocks/mock_event.h" #include "opencl/test/unit_test/mocks/mock_gmm.h" -#include "opencl/test/unit_test/mocks/mock_gmm_resource_info.h" #include "test.h" #include "gl_types.h" diff --git a/opencl/test/unit_test/sharings/unified/unified_sharing_image_tests.cpp b/opencl/test/unit_test/sharings/unified/unified_sharing_image_tests.cpp index a50d095226..9568d6847d 100644 --- a/opencl/test/unit_test/sharings/unified/unified_sharing_image_tests.cpp +++ b/opencl/test/unit_test/sharings/unified/unified_sharing_image_tests.cpp @@ -6,10 +6,10 @@ */ #include "shared/source/gmm_helper/gmm.h" +#include "shared/test/common/mocks/mock_gmm_resource_info.h" #include "opencl/source/mem_obj/image.h" #include "opencl/source/sharings/unified/unified_image.h" -#include "opencl/test/unit_test/mocks/mock_gmm_resource_info.h" #include "opencl/test/unit_test/os_interface/raii_hw_info_config.h" #include "opencl/test/unit_test/sharings/unified/unified_sharing_fixtures.h" #include "opencl/test/unit_test/sharings/unified/unified_sharing_mocks.h" diff --git a/shared/test/common/mocks/CMakeLists.txt b/shared/test/common/mocks/CMakeLists.txt index a3c5bf2bb9..499236d2ae 100644 --- a/shared/test/common/mocks/CMakeLists.txt +++ b/shared/test/common/mocks/CMakeLists.txt @@ -45,6 +45,8 @@ set(NEO_CORE_tests_mocks ${CMAKE_CURRENT_SOURCE_DIR}/mock_gfx_partition.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm_client_context_base.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm_client_context_base.h + ${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm_resource_info_common.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm_resource_info.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_graphics_allocation.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_host_ptr_manager.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_hw_info_config.cpp diff --git a/opencl/test/unit_test/mocks/mock_gmm_resource_info.h b/shared/test/common/mocks/mock_gmm_resource_info.h similarity index 100% rename from opencl/test/unit_test/mocks/mock_gmm_resource_info.h rename to shared/test/common/mocks/mock_gmm_resource_info.h diff --git a/opencl/test/unit_test/mocks/mock_gmm_resource_info.cpp b/shared/test/common/mocks/mock_gmm_resource_info_common.cpp similarity index 68% rename from opencl/test/unit_test/mocks/mock_gmm_resource_info.cpp rename to shared/test/common/mocks/mock_gmm_resource_info_common.cpp index 6039fa825c..0777c9811c 100644 --- a/opencl/test/unit_test/mocks/mock_gmm_resource_info.cpp +++ b/shared/test/common/mocks/mock_gmm_resource_info_common.cpp @@ -1,15 +1,12 @@ /* - * Copyright (C) 2018-2021 Intel Corporation + * Copyright (C) 2020-2021 Intel Corporation * * SPDX-License-Identifier: MIT * */ -#include "opencl/test/unit_test/mocks/mock_gmm_resource_info.h" - #include "shared/source/helpers/aligned_memory.h" - -#include "opencl/source/helpers/surface_formats.h" +#include "shared/test/common/mocks/mock_gmm_resource_info.h" using namespace ::testing; @@ -38,6 +35,9 @@ MockGmmResourceInfo::MockGmmResourceInfo(GMM_RESOURCE_INFO *inputGmmResourceInfo // Simulate GMM behaviour. We dont want to test 3rd party lib void MockGmmResourceInfo::setupDefaultActions() { setSurfaceFormat(); + if (surfaceFormatInfo == nullptr) { + return; + } computeRowPitch(); size = rowPitch; @@ -80,51 +80,6 @@ void MockGmmResourceInfo::computeRowPitch() { } } -void MockGmmResourceInfo::setSurfaceFormat() { - auto iterate = [&](ArrayRef formats) { - if (!surfaceFormatInfo) { - for (auto &format : formats) { - if (mockResourceCreateParams.Format == format.surfaceFormat.GMMSurfaceFormat) { - surfaceFormatInfo = &format.surfaceFormat; - break; - } - } - } - }; - - if (mockResourceCreateParams.Format == GMM_RESOURCE_FORMAT::GMM_FORMAT_P010 || mockResourceCreateParams.Format == GMM_RESOURCE_FORMAT::GMM_FORMAT_P016) { - tempSurface.GMMSurfaceFormat = mockResourceCreateParams.Format; - tempSurface.NumChannels = 1; - tempSurface.ImageElementSizeInBytes = 16; - tempSurface.PerChannelSizeInBytes = 16; - - surfaceFormatInfo = &tempSurface; - } - - if (mockResourceCreateParams.Format == GMM_RESOURCE_FORMAT::GMM_FORMAT_RGBP) { - tempSurface.GMMSurfaceFormat = GMM_RESOURCE_FORMAT::GMM_FORMAT_RGBP; - tempSurface.NumChannels = 1; - tempSurface.ImageElementSizeInBytes = 8; - tempSurface.PerChannelSizeInBytes = 8; - - surfaceFormatInfo = &tempSurface; - } - - iterate(SurfaceFormats::readOnly12()); - iterate(SurfaceFormats::readOnly20()); - iterate(SurfaceFormats::writeOnly()); - iterate(SurfaceFormats::readWrite()); - - iterate(SurfaceFormats::packedYuv()); - iterate(SurfaceFormats::planarYuv()); - iterate(SurfaceFormats::packed()); - - iterate(SurfaceFormats::readOnlyDepth()); - iterate(SurfaceFormats::readWriteDepth()); - - ASSERT_NE(nullptr, surfaceFormatInfo); -} - uint32_t MockGmmResourceInfo::getBitsPerPixel() { return static_cast(surfaceFormatInfo->ImageElementSizeInBytes * 8); } diff --git a/shared/test/unit_test/CMakeLists.txt b/shared/test/unit_test/CMakeLists.txt index cdb1ef1a4f..c28a864924 100644 --- a/shared/test/unit_test/CMakeLists.txt +++ b/shared/test/unit_test/CMakeLists.txt @@ -97,6 +97,7 @@ if(NOT SKIP_UNIT_TESTS) endif() add_subdirectory(${NEO_SHARED_TEST_DIRECTORY}/common "${NEO_BUILD_DIR}/shared/test/common") + add_subdirectory_unique(mocks) if(NOT SKIP_SHARED_UNIT_TESTS) add_subdirectories() diff --git a/shared/test/unit_test/gmm_helper/gmm_resource_info_tests.cpp b/shared/test/unit_test/gmm_helper/gmm_resource_info_tests.cpp index a3920cc172..398f85bd06 100644 --- a/shared/test/unit_test/gmm_helper/gmm_resource_info_tests.cpp +++ b/shared/test/unit_test/gmm_helper/gmm_resource_info_tests.cpp @@ -8,8 +8,8 @@ #include "shared/source/gmm_helper/client_context/gmm_handle_allocator.h" #include "shared/source/gmm_helper/resource_info.h" #include "shared/test/common/mocks/mock_gmm_client_context.h" +#include "shared/test/common/mocks/mock_gmm_resource_info.h" -#include "opencl/test/unit_test/mocks/mock_gmm_resource_info.h" #include "opencl/test/unit_test/mocks/mock_hw_helper.h" #include "test.h" diff --git a/shared/test/unit_test/mocks/CMakeLists.txt b/shared/test/unit_test/mocks/CMakeLists.txt new file mode 100644 index 0000000000..cb0fc9be51 --- /dev/null +++ b/shared/test/unit_test/mocks/CMakeLists.txt @@ -0,0 +1,10 @@ +# +# Copyright (C) 2021 Intel Corporation +# +# SPDX-License-Identifier: MIT +# + +target_sources(${TARGET_NAME} PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm_resource_info.cpp +) diff --git a/shared/test/unit_test/mocks/mock_gmm_resource_info.cpp b/shared/test/unit_test/mocks/mock_gmm_resource_info.cpp new file mode 100644 index 0000000000..feaf82015c --- /dev/null +++ b/shared/test/unit_test/mocks/mock_gmm_resource_info.cpp @@ -0,0 +1,14 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/test/common/mocks/mock_gmm_resource_info.h" + +namespace NEO { + +void MockGmmResourceInfo::setSurfaceFormat() { +} +} // namespace NEO