Set HwInfo to GmmHelper on Device creation

This allows querying HwInfo from code that doesnt have access to Device

Change-Id: I0084f824f557cd85c2fdfbf0ff2ec71118e9af2e
This commit is contained in:
Dunajski, Bartosz 2018-06-28 13:38:15 +02:00 committed by sys_ocldev
parent 5186474ef5
commit 5408913d38
17 changed files with 98 additions and 30 deletions

View File

@ -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

View File

@ -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<uint32_t>(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();

View File

@ -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);

View File

@ -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

View File

@ -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

View File

@ -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) {
}

View File

@ -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<Buffer>(imageDesc->mem_object);
Image *parentImage = castToObject<Image>(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> gmm(GmmHelper::createGmmAndQueryImgParams(queryGmmImgInfo, hwInfo));
std::unique_ptr<Gmm> 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;

View File

@ -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;

View File

@ -147,7 +147,7 @@ Image *D3DTexture<D3D>::create3d(Context *context, D3DTexture3d *d3dTexture, cl_
auto d3dTextureObj = new D3DTexture<D3D>(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);

View File

@ -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;

View File

@ -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<MockDevice> device(Device::create<MockDevice>(&localHwInfo));
EXPECT_EQ(&localHwInfo, GmmHelper::hwInfo);
}
TEST(GmmTest, whenResourceIsCreatedThenHandleItsOwnership) {
struct MyMockResourecInfo : public GmmResourceInfo {
using GmmResourceInfo::resourceInfo;

View File

@ -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}

View File

@ -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<TestEnvironment *>(::testing::AddGlobalTestEnvironment(new TestEnvironment));

View File

@ -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());

View File

@ -35,12 +35,8 @@ static SurfaceFormatInfo mockSurfaceFormat;
class MockGmm : public Gmm {
public:
static std::unique_ptr<Gmm> queryImgParams(ImageInfo &imgInfo, const HardwareInfo *hwInfo = nullptr) {
auto queryHwInfo = hwInfo;
if (!queryHwInfo) {
queryHwInfo = *platformDevices;
}
return std::unique_ptr<Gmm>(GmmHelper::createGmmAndQueryImgParams(imgInfo, *queryHwInfo));
static std::unique_ptr<Gmm> queryImgParams(ImageInfo &imgInfo) {
return std::unique_ptr<Gmm>(GmmHelper::createGmmAndQueryImgParams(imgInfo));
}
static ImageInfo initImgInfo(cl_image_desc &imgDesc, int baseMipLevel, const SurfaceFormatInfo *surfaceFormat) {

View File

@ -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];
}

View File

@ -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