From 5408913d387a97c47f2e65fc36a7ea97300b230e Mon Sep 17 00:00:00 2001 From: "Dunajski, Bartosz" Date: Thu, 28 Jun 2018 13:38:15 +0200 Subject: [PATCH] Set HwInfo to GmmHelper on Device creation This allows querying HwInfo from code that doesnt have access to Device Change-Id: I0084f824f557cd85c2fdfbf0ff2ec71118e9af2e --- runtime/device/device.cpp | 2 ++ runtime/gmm_helper/gmm.cpp | 10 +++---- runtime/gmm_helper/gmm.h | 6 ++--- runtime/gmm_helper/gmm_helper.cpp | 5 ++-- runtime/gmm_helper/gmm_helper.h | 3 ++- runtime/gmm_helper/gmm_utils.cpp | 2 +- runtime/mem_obj/image.cpp | 10 +++---- runtime/sharings/d3d/d3d_surface.cpp | 2 +- runtime/sharings/d3d/d3d_texture.cpp | 2 +- runtime/sharings/va/va_surface.cpp | 4 +-- unit_tests/gmm_helper/gmm_helper_tests.cpp | 7 +++++ unit_tests/libult/CMakeLists.txt | 2 ++ unit_tests/main.cpp | 2 ++ unit_tests/mem_obj/image_set_arg_tests.cpp | 2 +- unit_tests/mocks/mock_gmm.h | 8 ++---- unit_tests/ult_config_listener.cpp | 30 +++++++++++++++++++++ unit_tests/ult_config_listener.h | 31 ++++++++++++++++++++++ 17 files changed, 98 insertions(+), 30 deletions(-) create mode 100644 unit_tests/ult_config_listener.cpp create mode 100644 unit_tests/ult_config_listener.h diff --git a/runtime/device/device.cpp b/runtime/device/device.cpp index a14654eb13..2e14c89437 100644 --- a/runtime/device/device.cpp +++ b/runtime/device/device.cpp @@ -31,6 +31,7 @@ #include "runtime/device/device_vector.h" #include "runtime/device/driver_info.h" #include "runtime/execution_environment/execution_environment.h" +#include "runtime/gmm_helper/gmm_helper.h" #include "runtime/helpers/built_ins_helper.h" #include "runtime/helpers/debug_helpers.h" #include "runtime/helpers/options.h" @@ -85,6 +86,7 @@ Device::Device(const HardwareInfo &hwInfo, memset(&deviceInfo, 0, sizeof(deviceInfo)); deviceExtensions.reserve(1000); name.reserve(100); + GmmHelper::hwInfo = &hwInfo; preemptionMode = PreemptionHelper::getDefaultPreemptionMode(hwInfo); engineType = DebugManager.flags.NodeOrdinal.get() == -1 ? hwInfo.capabilityTable.defaultEngineType diff --git a/runtime/gmm_helper/gmm.cpp b/runtime/gmm_helper/gmm.cpp index 1582cbc463..d3369b8527 100644 --- a/runtime/gmm_helper/gmm.cpp +++ b/runtime/gmm_helper/gmm.cpp @@ -38,7 +38,7 @@ void Gmm::create() { gmmResourceInfo.reset(GmmResourceInfo::create(&resourceParams)); } -void Gmm::queryImageParams(ImageInfo &imgInfo, const HardwareInfo &hwInfo) { +void Gmm::queryImageParams(ImageInfo &imgInfo) { uint32_t imageWidth = static_cast(imgInfo.imgDesc->image_width); uint32_t imageHeight = 1; uint32_t imageDepth = 1; @@ -90,7 +90,7 @@ void Gmm::queryImageParams(ImageInfo &imgInfo, const HardwareInfo &hwInfo) { this->resourceParams.Flags.Info.AllowVirtualPadding = true; } - applyAuxFlags(imgInfo, hwInfo); + applyAuxFlags(imgInfo); this->gmmResourceInfo.reset(GmmResourceInfo::create(&this->resourceParams)); @@ -143,12 +143,12 @@ void Gmm::queryImageParams(ImageInfo &imgInfo, const HardwareInfo &hwInfo) { imgInfo.yOffsetForUVPlane = reqOffsetInfo.Lock.Offset / reqOffsetInfo.Lock.Pitch; } - imgInfo.qPitch = queryQPitch(hwInfo.pPlatform->eRenderCoreFamily, this->resourceParams.Type); + imgInfo.qPitch = queryQPitch(this->resourceParams.Type); return; } -uint32_t Gmm::queryQPitch(GFXCORE_FAMILY gfxFamily, GMM_RESOURCE_TYPE resType) { - if (gfxFamily == IGFX_GEN8_CORE && resType == GMM_RESOURCE_TYPE::RESOURCE_3D) { +uint32_t Gmm::queryQPitch(GMM_RESOURCE_TYPE resType) { + if (GmmHelper::hwInfo->pPlatform->eRenderCoreFamily == IGFX_GEN8_CORE && resType == GMM_RESOURCE_TYPE::RESOURCE_3D) { return 0; } return gmmResourceInfo->getQPitch(); diff --git a/runtime/gmm_helper/gmm.h b/runtime/gmm_helper/gmm.h index 93be9cbb7a..d094b06511 100644 --- a/runtime/gmm_helper/gmm.h +++ b/runtime/gmm_helper/gmm.h @@ -38,15 +38,15 @@ class Gmm { virtual ~Gmm() = default; void create(); - void queryImageParams(ImageInfo &imgInfo, const HardwareInfo &hwInfo); + void queryImageParams(ImageInfo &imgInfo); uint32_t getRenderHAlignment(); uint32_t getRenderVAlignment(); - void applyAuxFlags(ImageInfo &imgInfo, const HardwareInfo &hwInfo); + void applyAuxFlags(ImageInfo &imgInfo); bool unifiedAuxTranslationCapable() const; - uint32_t queryQPitch(GFXCORE_FAMILY gfxFamily, GMM_RESOURCE_TYPE resType); + uint32_t queryQPitch(GMM_RESOURCE_TYPE resType); void updateImgInfo(ImageInfo &imgInfo, cl_image_desc &imgDesc, cl_uint arrayIndex); uint8_t resourceCopyBlt(void *sys, void *gpu, uint32_t pitch, uint32_t height, unsigned char upload, OCLPlane plane); diff --git a/runtime/gmm_helper/gmm_helper.cpp b/runtime/gmm_helper/gmm_helper.cpp index ecb50e56c5..70fa8d803c 100644 --- a/runtime/gmm_helper/gmm_helper.cpp +++ b/runtime/gmm_helper/gmm_helper.cpp @@ -107,9 +107,9 @@ Gmm *GmmHelper::create(GMM_RESOURCE_INFO *inputGmm) { return gmm; } -Gmm *GmmHelper::createGmmAndQueryImgParams(ImageInfo &imgInfo, const HardwareInfo &hwInfo) { +Gmm *GmmHelper::createGmmAndQueryImgParams(ImageInfo &imgInfo) { Gmm *gmm = new Gmm(); - gmm->queryImageParams(imgInfo, hwInfo); + gmm->queryImageParams(imgInfo); return gmm; } @@ -202,6 +202,7 @@ GMM_YUV_PLANE GmmHelper::convertPlane(OCLPlane oclPlane) { bool GmmHelper::useSimplifiedMocsTable = false; GMM_CLIENT_CONTEXT *GmmHelper::gmmClientContext = nullptr; +const HardwareInfo *GmmHelper::hwInfo = nullptr; bool GmmHelper::isLoaded = false; } // namespace OCLRT diff --git a/runtime/gmm_helper/gmm_helper.h b/runtime/gmm_helper/gmm_helper.h index e13568ce61..7f75b507c0 100644 --- a/runtime/gmm_helper/gmm_helper.h +++ b/runtime/gmm_helper/gmm_helper.h @@ -43,7 +43,7 @@ class GmmHelper { static constexpr uint32_t cacheEnabledIndex = 4; static constexpr uint32_t maxPossiblePitch = 2147483648; - static Gmm *createGmmAndQueryImgParams(ImageInfo &imgInfo, const HardwareInfo &hwInfo); + static Gmm *createGmmAndQueryImgParams(ImageInfo &imgInfo); static Gmm *create(const void *alignedPtr, size_t alignedSize, bool uncacheable); static Gmm *create(GMM_RESOURCE_INFO *inputGmm); @@ -70,6 +70,7 @@ class GmmHelper { static bool useSimplifiedMocsTable; static GMM_CLIENT_CONTEXT *gmmClientContext; + static const HardwareInfo *hwInfo; static bool isLoaded; }; } // namespace OCLRT diff --git a/runtime/gmm_helper/gmm_utils.cpp b/runtime/gmm_helper/gmm_utils.cpp index 909ef496ae..50fe67f0f5 100644 --- a/runtime/gmm_helper/gmm_utils.cpp +++ b/runtime/gmm_helper/gmm_utils.cpp @@ -24,5 +24,5 @@ #include "runtime/helpers/hw_info.h" #include "runtime/helpers/surface_formats.h" -void OCLRT::Gmm::applyAuxFlags(ImageInfo &imgInfo, const HardwareInfo &hwInfo) { +void OCLRT::Gmm::applyAuxFlags(ImageInfo &imgInfo) { } diff --git a/runtime/mem_obj/image.cpp b/runtime/mem_obj/image.cpp index 0903b89df8..79f15e58bb 100644 --- a/runtime/mem_obj/image.cpp +++ b/runtime/mem_obj/image.cpp @@ -126,7 +126,6 @@ Image *Image::create(Context *context, UNRECOVERABLE_IF(surfaceFormat == nullptr); Image *image = nullptr; GraphicsAllocation *memory = nullptr; - const auto &hwInfo = context->getDevice(0)->getHardwareInfo(); MemoryManager *memoryManager = context->getMemoryManager(); Buffer *parentBuffer = castToObject(imageDesc->mem_object); Image *parentImage = castToObject(imageDesc->mem_object); @@ -214,7 +213,7 @@ Image *Image::create(Context *context, if (memoryManager->peekVirtualPaddingSupport() && (imageDesc->image_type == CL_MEM_OBJECT_IMAGE2D)) { // Retrieve sizes from GMM and apply virtual padding if buffer storage is not big enough auto queryGmmImgInfo(imgInfo); - std::unique_ptr gmm(GmmHelper::createGmmAndQueryImgParams(queryGmmImgInfo, hwInfo)); + std::unique_ptr gmm(GmmHelper::createGmmAndQueryImgParams(queryGmmImgInfo)); auto gmmAllocationSize = gmm->gmmResourceInfo->getSizeAllocation(); if (gmmAllocationSize > memory->getUnderlyingBufferSize()) { memory = memoryManager->createGraphicsAllocationWithPadding(memory, gmmAllocationSize); @@ -222,11 +221,11 @@ Image *Image::create(Context *context, } } else if (parentImage != nullptr) { memory = parentImage->getGraphicsAllocation(); - memory->gmm->queryImageParams(imgInfo, hwInfo); + memory->gmm->queryImageParams(imgInfo); isTilingAllowed = parentImage->allowTiling(); } else { gmm = new Gmm(); - gmm->queryImageParams(imgInfo, hwInfo); + gmm->queryImageParams(imgInfo); errcodeRet = CL_OUT_OF_HOST_MEMORY; if (flags & CL_MEM_USE_HOST_PTR) { @@ -651,7 +650,6 @@ cl_int Image::getImageParams(Context *context, size_t *imageRowPitch, size_t *imageSlicePitch) { cl_int retVal = CL_SUCCESS; - const auto &hwInfo = context->getDevice(0)->getHardwareInfo(); ImageInfo imgInfo = {0}; cl_image_desc imageDescriptor = *imageDesc; @@ -660,7 +658,7 @@ cl_int Image::getImageParams(Context *context, Gmm *gmm = nullptr; gmm = new Gmm(); - gmm->queryImageParams(imgInfo, hwInfo); + gmm->queryImageParams(imgInfo); delete gmm; *imageRowPitch = imgInfo.rowPitch; diff --git a/runtime/sharings/d3d/d3d_surface.cpp b/runtime/sharings/d3d/d3d_surface.cpp index bcfcd8d0d2..5210d301d0 100644 --- a/runtime/sharings/d3d/d3d_surface.cpp +++ b/runtime/sharings/d3d/d3d_surface.cpp @@ -102,7 +102,7 @@ Image *D3DSurface::create(Context *context, cl_dx9_surface_info_khr *surfaceInfo imgDesc.image_width /= 2; imgDesc.image_height /= 2; } - Gmm *gmm = GmmHelper::createGmmAndQueryImgParams(imgInfo, context->getDevice(0)->getHardwareInfo()); + Gmm *gmm = GmmHelper::createGmmAndQueryImgParams(imgInfo); imgDesc.image_row_pitch = imgInfo.rowPitch; imgDesc.image_slice_pitch = imgInfo.slicePitch; diff --git a/runtime/sharings/d3d/d3d_texture.cpp b/runtime/sharings/d3d/d3d_texture.cpp index e5a75f8204..414e3ea6f3 100644 --- a/runtime/sharings/d3d/d3d_texture.cpp +++ b/runtime/sharings/d3d/d3d_texture.cpp @@ -147,7 +147,7 @@ Image *D3DTexture::create3d(Context *context, D3DTexture3d *d3dTexture, cl_ auto d3dTextureObj = new D3DTexture(context, d3dTexture, subresource, textureStaging, sharedResource); - imgInfo.qPitch = alloc->gmm->queryQPitch(context->getDevice(0)->getHardwareInfo().pPlatform->eRenderCoreFamily, GMM_RESOURCE_TYPE::RESOURCE_3D); + imgInfo.qPitch = alloc->gmm->queryQPitch(GMM_RESOURCE_TYPE::RESOURCE_3D); imgInfo.surfaceFormat = findSurfaceFormatInfo(alloc->gmm->gmmResourceInfo->getResourceFormat(), flags); diff --git a/runtime/sharings/va/va_surface.cpp b/runtime/sharings/va/va_surface.cpp index 117968b604..1f6d4a3b1c 100644 --- a/runtime/sharings/va/va_surface.cpp +++ b/runtime/sharings/va/va_surface.cpp @@ -26,7 +26,6 @@ #include "runtime/mem_obj/image.h" #include "runtime/memory_manager/memory_manager.h" #include "runtime/helpers/get_info.h" -#include "runtime/helpers/hw_info.h" #include "runtime/gmm_helper/gmm.h" #include "runtime/gmm_helper/gmm_helper.h" @@ -36,7 +35,6 @@ Image *VASurface::createSharedVaSurface(Context *context, VASharingFunctions *sh cl_uint plane, cl_int *errcodeRet) { ErrorCodeHelper errorCode(errcodeRet, CL_SUCCESS); - const auto &hwInfo = context->getDevice(0)->getHardwareInfo(); auto memoryManager = context->getMemoryManager(); unsigned int sharedHandle = 0; VAImage vaImage = {}; @@ -76,7 +74,7 @@ Image *VASurface::createSharedVaSurface(Context *context, VASharingFunctions *sh auto alloc = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, false, true); - Gmm *gmm = GmmHelper::createGmmAndQueryImgParams(imgInfo, hwInfo); + Gmm *gmm = GmmHelper::createGmmAndQueryImgParams(imgInfo); DEBUG_BREAK_IF(alloc->gmm != nullptr); alloc->gmm = gmm; diff --git a/unit_tests/gmm_helper/gmm_helper_tests.cpp b/unit_tests/gmm_helper/gmm_helper_tests.cpp index 49ce46a44f..58af171aa6 100644 --- a/unit_tests/gmm_helper/gmm_helper_tests.cpp +++ b/unit_tests/gmm_helper/gmm_helper_tests.cpp @@ -620,6 +620,13 @@ TEST(GmmTest, whenContextIsDestroyedMultimpleTimesThenDontCrash) { EXPECT_TRUE(GmmHelper::initContext(hwinfo->pPlatform, hwinfo->pSkuTable, hwinfo->pWaTable, hwinfo->pSysInfo)); } +TEST(GmmTest, givenHwInfoWhenDeviceIsCreatedTheSetThisHwInfoToGmmHelper) { + HardwareInfo localHwInfo = **platformDevices; + + std::unique_ptr device(Device::create(&localHwInfo)); + EXPECT_EQ(&localHwInfo, GmmHelper::hwInfo); +} + TEST(GmmTest, whenResourceIsCreatedThenHandleItsOwnership) { struct MyMockResourecInfo : public GmmResourceInfo { using GmmResourceInfo::resourceInfo; diff --git a/unit_tests/libult/CMakeLists.txt b/unit_tests/libult/CMakeLists.txt index 12c2ab8dab..6c51d5fc7a 100644 --- a/unit_tests/libult/CMakeLists.txt +++ b/unit_tests/libult/CMakeLists.txt @@ -100,6 +100,8 @@ set(IGDRCL_SRCS_LIB_ULT_ENV ${IGDRCL_SOURCE_DIR}/unit_tests/helpers/kernel_binary_helper.h ${IGDRCL_SOURCE_DIR}/unit_tests/indirect_heap/indirect_heap_fixture.cpp ${IGDRCL_SOURCE_DIR}/unit_tests/indirect_heap/indirect_heap_fixture.h + ${IGDRCL_SOURCE_DIR}/unit_tests/ult_config_listener.cpp + ${IGDRCL_SOURCE_DIR}/unit_tests/ult_config_listener.h ) add_library (igdrcl_libult_env OBJECT ${IGDRCL_SRCS_LIB_ULT_ENV} diff --git a/unit_tests/main.cpp b/unit_tests/main.cpp index 839e2707f5..db94a3480c 100644 --- a/unit_tests/main.cpp +++ b/unit_tests/main.cpp @@ -25,6 +25,7 @@ #include "runtime/helpers/options.h" #include "unit_tests/custom_event_listener.h" #include "helpers/test_files.h" +#include "unit_tests/ult_config_listener.h" #include "unit_tests/memory_leak_listener.h" #include "unit_tests/mocks/mock_gmm.h" #include "unit_tests/mocks/mock_program.h" @@ -366,6 +367,7 @@ int main(int argc, char **argv) { } listeners.Append(new MemoryLeakListener); + listeners.Append(new UltConfigListener); gEnvironment = reinterpret_cast(::testing::AddGlobalTestEnvironment(new TestEnvironment)); diff --git a/unit_tests/mem_obj/image_set_arg_tests.cpp b/unit_tests/mem_obj/image_set_arg_tests.cpp index 7fefd59895..b1f259a801 100644 --- a/unit_tests/mem_obj/image_set_arg_tests.cpp +++ b/unit_tests/mem_obj/image_set_arg_tests.cpp @@ -393,7 +393,7 @@ HWTEST_F(ImageSetArgTest, clSetKernelArgImage1Darray) { EXPECT_EQ(image1Darray->getImageDesc().image_array_size, surfaceState->getRenderTargetViewExtent()); EXPECT_EQ(image1Darray->getImageDesc().image_row_pitch, surfaceState->getSurfacePitch()); EXPECT_EQ(0u, surfaceState->getSurfaceQpitch() % 4); - EXPECT_EQ(image1Darray->getGraphicsAllocation()->gmm->queryQPitch(::renderCoreFamily, GMM_RESOURCE_TYPE::RESOURCE_1D), surfaceState->getSurfaceQpitch()); + EXPECT_EQ(image1Darray->getGraphicsAllocation()->gmm->queryQPitch(GMM_RESOURCE_TYPE::RESOURCE_1D), surfaceState->getSurfaceQpitch()); EXPECT_EQ(image1Darray->getSurfaceFormatInfo().GenxSurfaceFormat, (GFX3DSTATE_SURFACEFORMAT)surfaceState->getSurfaceFormat()); EXPECT_EQ(RENDER_SURFACE_STATE::SURFACE_TYPE_SURFTYPE_1D, surfaceState->getSurfaceType()); diff --git a/unit_tests/mocks/mock_gmm.h b/unit_tests/mocks/mock_gmm.h index a5915e3783..c86f2ccfbd 100644 --- a/unit_tests/mocks/mock_gmm.h +++ b/unit_tests/mocks/mock_gmm.h @@ -35,12 +35,8 @@ static SurfaceFormatInfo mockSurfaceFormat; class MockGmm : public Gmm { public: - static std::unique_ptr queryImgParams(ImageInfo &imgInfo, const HardwareInfo *hwInfo = nullptr) { - auto queryHwInfo = hwInfo; - if (!queryHwInfo) { - queryHwInfo = *platformDevices; - } - return std::unique_ptr(GmmHelper::createGmmAndQueryImgParams(imgInfo, *queryHwInfo)); + static std::unique_ptr queryImgParams(ImageInfo &imgInfo) { + return std::unique_ptr(GmmHelper::createGmmAndQueryImgParams(imgInfo)); } static ImageInfo initImgInfo(cl_image_desc &imgDesc, int baseMipLevel, const SurfaceFormatInfo *surfaceFormat) { diff --git a/unit_tests/ult_config_listener.cpp b/unit_tests/ult_config_listener.cpp new file mode 100644 index 0000000000..3a97ad5897 --- /dev/null +++ b/unit_tests/ult_config_listener.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2018, Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "runtime/gmm_helper/gmm_helper.h" +#include "runtime/helpers/options.h" +#include "unit_tests/ult_config_listener.h" + +void OCLRT::UltConfigListener::OnTestStart(const ::testing::TestInfo &testInfo) { + // Set default HardwareInfo for all ULTs that dont want to create Device and test initialization path + GmmHelper::hwInfo = platformDevices[0]; +} diff --git a/unit_tests/ult_config_listener.h b/unit_tests/ult_config_listener.h new file mode 100644 index 0000000000..19f2e5997b --- /dev/null +++ b/unit_tests/ult_config_listener.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2018, Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#pragma once +#include "gtest/gtest.h" + +namespace OCLRT { +class UltConfigListener : public ::testing::EmptyTestEventListener { + private: + void OnTestStart(const ::testing::TestInfo &) override; +}; +} // namespace OCLRT