Create wrapper for GmmClientContext

reduce mock gmm to implementation of OpenGmm function

Change-Id: I657412af2d11486c9924cf3ab9a8b4f51e603964
This commit is contained in:
Mateusz Jablonski
2018-06-14 07:50:18 +02:00
committed by sys_ocldev
parent 861d001cba
commit 50c31872d8
26 changed files with 380 additions and 657 deletions

View File

@@ -20,6 +20,10 @@
set(RUNTIME_SRCS_GMM_HELPER_BASE
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/client_context/gmm_client_context_base.cpp
${CMAKE_CURRENT_SOURCE_DIR}/client_context/gmm_client_context_base.h
${CMAKE_CURRENT_SOURCE_DIR}/client_context${BRANCH_DIR_SUFFIX}/gmm_client_context.cpp
${CMAKE_CURRENT_SOURCE_DIR}/client_context${BRANCH_DIR_SUFFIX}/gmm_client_context.h
${CMAKE_CURRENT_SOURCE_DIR}/gmm_helper.cpp
${CMAKE_CURRENT_SOURCE_DIR}/gmm_helper.h
${CMAKE_CURRENT_SOURCE_DIR}/gmm_lib.h

View File

@@ -0,0 +1,27 @@
/*
* 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 "gmm_client_context.h"
namespace OCLRT {
GmmClientContext::GmmClientContext(GMM_CLIENT clientType) : GmmClientContextBase(clientType){};
} // namespace OCLRT

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 "runtime/gmm_helper/client_context/gmm_client_context_base.h"
namespace OCLRT {
class GmmClientContext : public GmmClientContextBase {
public:
GmmClientContext(GMM_CLIENT clientType);
};
} // namespace OCLRT

View File

@@ -0,0 +1,52 @@
/*
* 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/client_context/gmm_client_context_base.h"
namespace OCLRT {
GmmClientContextBase::GmmClientContextBase(GMM_CLIENT clientType) {
clientContext = Gmm::createClientContextFunc(clientType);
}
GmmClientContextBase::~GmmClientContextBase() {
Gmm::deleteClientContextFunc(clientContext);
};
MEMORY_OBJECT_CONTROL_STATE GmmClientContextBase::cachePolicyGetMemoryObject(GMM_RESOURCE_INFO *pResInfo, GMM_RESOURCE_USAGE_TYPE usage) {
return clientContext->CachePolicyGetMemoryObject(pResInfo, usage);
}
GMM_RESOURCE_INFO *GmmClientContextBase::createResInfoObject(GMM_RESCREATE_PARAMS *pCreateParams) {
return clientContext->CreateResInfoObject(pCreateParams);
}
GMM_RESOURCE_INFO *GmmClientContextBase::copyResInfoObject(GMM_RESOURCE_INFO *pSrcRes) {
return clientContext->CopyResInfoObject(pSrcRes);
}
void GmmClientContextBase::destroyResInfoObject(GMM_RESOURCE_INFO *pResInfo) {
return clientContext->DestroyResInfoObject(pResInfo);
}
GMM_CLIENT_CONTEXT *GmmClientContextBase::getHandle() const {
return clientContext;
}
} // namespace OCLRT

View File

@@ -0,0 +1,48 @@
/*
* 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 "runtime/gmm_helper/gmm_helper.h"
#include "runtime/gmm_helper/gmm_lib.h"
#include <memory>
namespace OCLRT {
class GmmClientContext;
class GmmClientContextBase {
public:
virtual ~GmmClientContextBase();
MOCKABLE_VIRTUAL MEMORY_OBJECT_CONTROL_STATE cachePolicyGetMemoryObject(GMM_RESOURCE_INFO *pResInfo, GMM_RESOURCE_USAGE_TYPE usage);
MOCKABLE_VIRTUAL GMM_RESOURCE_INFO *createResInfoObject(GMM_RESCREATE_PARAMS *pCreateParams);
MOCKABLE_VIRTUAL GMM_RESOURCE_INFO *copyResInfoObject(GMM_RESOURCE_INFO *pSrcRes);
MOCKABLE_VIRTUAL void destroyResInfoObject(GMM_RESOURCE_INFO *pResInfo);
GMM_CLIENT_CONTEXT *getHandle() const;
template <typename T>
static std::unique_ptr<GmmClientContext> create(GMM_CLIENT clientType) {
return std::unique_ptr<GmmClientContext>(new T(clientType));
}
protected:
GMM_CLIENT_CONTEXT *clientContext;
GmmClientContextBase(GMM_CLIENT clientType);
};
} // namespace OCLRT

View File

@@ -20,6 +20,7 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "gmm_client_context.h"
#include "runtime/gmm_helper/gmm_helper.h"
#include "runtime/gmm_helper/resource_info.h"
#include "runtime/helpers/get_info.h"
@@ -54,15 +55,14 @@ bool Gmm::initContext(const PLATFORM *pPlatform,
}
bool success = GMM_SUCCESS == initGlobalContextFunc(*pPlatform, &gmmFtrTable, &gmmWaTable, pGtSysInfo, GMM_CLIENT::GMM_OCL_VISTA);
UNRECOVERABLE_IF(!success);
Gmm::gmmClientContext = createClientContextFunc(GMM_CLIENT::GMM_OCL_VISTA);
Gmm::gmmClientContext = Gmm::createGmmContextWrapperFunc(GMM_CLIENT::GMM_OCL_VISTA);
}
return Gmm::gmmClientContext != nullptr;
}
void Gmm::destroyContext() {
if (Gmm::gmmClientContext) {
deleteClientContextFunc(Gmm::gmmClientContext);
Gmm::gmmClientContext = nullptr;
Gmm::gmmClientContext.reset(nullptr);
destroyGlobalContextFunc();
}
}
@@ -76,7 +76,7 @@ uint32_t Gmm::getMOCS(uint32_t type) {
}
}
MEMORY_OBJECT_CONTROL_STATE mocs = Gmm::gmmClientContext->CachePolicyGetMemoryObject(nullptr, static_cast<GMM_RESOURCE_USAGE_TYPE>(type));
MEMORY_OBJECT_CONTROL_STATE mocs = Gmm::gmmClientContext->cachePolicyGetMemoryObject(nullptr, static_cast<GMM_RESOURCE_USAGE_TYPE>(type));
return static_cast<uint32_t>(mocs.DwordValue);
}
@@ -392,8 +392,11 @@ bool Gmm::unifiedAuxTranslationCapable() const {
return gmmFlags->Gpu.CCS && gmmFlags->Gpu.UnifiedAuxSurface && gmmFlags->Info.RenderCompressed;
}
Gmm::~Gmm() {}
std::unique_ptr<GmmClientContext> (*Gmm::createGmmContextWrapperFunc)(GMM_CLIENT) = GmmClientContextBase::create<GmmClientContext>;
bool Gmm::useSimplifiedMocsTable = false;
GMM_CLIENT_CONTEXT *Gmm::gmmClientContext = nullptr;
std::unique_ptr<GmmClientContext> Gmm::gmmClientContext = nullptr;
bool Gmm::isLoaded = false;
} // namespace OCLRT

View File

@@ -34,6 +34,7 @@ struct WorkaroundTable;
struct ImageInfo;
class GraphicsAllocation;
class GmmResourceInfo;
class GmmClientContext;
enum OCLPlane {
NO_PLANE = 0,
@@ -50,7 +51,7 @@ class Gmm {
public:
static const uint32_t maxPossiblePitch = 2147483648;
virtual ~Gmm() = default;
virtual ~Gmm();
void create();
static Gmm *create(const void *alignedPtr, size_t alignedSize, bool uncacheable);
@@ -96,10 +97,11 @@ class Gmm {
static decltype(&GmmDestroyGlobalContext) destroyGlobalContextFunc;
static decltype(&GmmCreateClientContext) createClientContextFunc;
static decltype(&GmmDeleteClientContext) deleteClientContextFunc;
static std::unique_ptr<GmmClientContext> (*createGmmContextWrapperFunc)(GMM_CLIENT);
bool isRenderCompressed = false;
static bool useSimplifiedMocsTable;
static GMM_CLIENT_CONTEXT *gmmClientContext;
static std::unique_ptr<GmmClientContext> gmmClientContext;
static bool isLoaded;
};
} // namespace OCLRT

View File

@@ -20,6 +20,7 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "gmm_client_context.h"
#include "runtime/gmm_helper/gmm_memory_base.h"
#include "runtime/gmm_helper/gmm_helper.h"
@@ -33,7 +34,7 @@ bool GmmMemoryBase::configureDeviceAddressSpace(GMM_ESCAPE_HANDLE hAdapter,
BOOLEAN BDWL3Coherency,
GMM_GFX_SIZE_T SizeOverride,
GMM_GFX_SIZE_T SlmGfxSpaceReserve) {
return Gmm::gmmClientContext->ConfigureDeviceAddressSpace(
return clientContext->ConfigureDeviceAddressSpace(
{hAdapter},
{hDevice},
{pfnEscape},
@@ -46,7 +47,10 @@ bool GmmMemoryBase::configureDeviceAddressSpace(GMM_ESCAPE_HANDLE hAdapter,
}
uintptr_t GmmMemoryBase::getInternalGpuVaRangeLimit() {
return static_cast<uintptr_t>(Gmm::gmmClientContext->GetInternalGpuVaRangeLimit());
return static_cast<uintptr_t>(clientContext->GetInternalGpuVaRangeLimit());
}
GmmMemoryBase::GmmMemoryBase() {
clientContext = Gmm::gmmClientContext->getHandle();
}
}; // namespace OCLRT

View File

@@ -42,6 +42,7 @@ class GmmMemoryBase {
MOCKABLE_VIRTUAL uintptr_t getInternalGpuVaRangeLimit();
protected:
GmmMemoryBase() = default;
GMM_CLIENT_CONTEXT *clientContext = nullptr;
GmmMemoryBase();
};
} // namespace OCLRT

View File

@@ -24,5 +24,7 @@
#include "runtime/helpers/hw_info.h"
#include "runtime/helpers/surface_formats.h"
void OCLRT::Gmm::applyAuxFlags(ImageInfo &imgInfo, const HardwareInfo &hwInfo) {
namespace OCLRT {
void Gmm::applyAuxFlags(ImageInfo &imgInfo, const HardwareInfo &hwInfo) {
}
} // namespace OCLRT

View File

@@ -28,7 +28,7 @@
namespace OCLRT {
class GmmPageTableMngr {
public:
MOCKABLE_VIRTUAL ~GmmPageTableMngr() = default;
MOCKABLE_VIRTUAL ~GmmPageTableMngr();
static GmmPageTableMngr *create(GMM_DEVICE_CALLBACKS_INT *deviceCb, unsigned int translationTableFlags, GMM_TRANSLATIONTABLE_CALLBACKS *translationTableCb);
@@ -45,13 +45,12 @@ class GmmPageTableMngr {
}
protected:
static void customDeleter(GMM_PAGETABLE_MGR *gmmPageTableManager);
using UniquePtrType = std::unique_ptr<GMM_PAGETABLE_MGR, std::function<void(GMM_PAGETABLE_MGR *)>>;
GMM_CLIENT_CONTEXT *clientContext = nullptr;
GmmPageTableMngr() = default;
GmmPageTableMngr(GMM_DEVICE_CALLBACKS_INT *deviceCb, unsigned int translationTableFlags, GMM_TRANSLATIONTABLE_CALLBACKS *translationTableCb);
UniquePtrType pageTableManager;
GMM_PAGETABLE_MGR *pageTableManager = nullptr;
};
} // namespace OCLRT

View File

@@ -20,17 +20,20 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "gmm_client_context.h"
#include "runtime/gmm_helper/gmm_helper.h"
#include "runtime/gmm_helper/page_table_mngr.h"
namespace OCLRT {
void GmmPageTableMngr::customDeleter(GMM_PAGETABLE_MGR *gmmPageTableManager) {
Gmm::gmmClientContext->DestroyPageTblMgrObject(gmmPageTableManager);
GmmPageTableMngr::~GmmPageTableMngr() {
if (clientContext) {
clientContext->DestroyPageTblMgrObject(pageTableManager);
}
}
GmmPageTableMngr::GmmPageTableMngr(GMM_DEVICE_CALLBACKS_INT *deviceCb, unsigned int translationTableFlags, GMM_TRANSLATIONTABLE_CALLBACKS *translationTableCb) {
auto pageTableMngrPtr = Gmm::gmmClientContext->CreatePageTblMgrObject(deviceCb, translationTableCb, translationTableFlags);
this->pageTableManager = UniquePtrType(pageTableMngrPtr, GmmPageTableMngr::customDeleter);
clientContext = Gmm::gmmClientContext->getHandle();
pageTableManager = clientContext->CreatePageTblMgrObject(deviceCb, translationTableCb, translationTableFlags);
}
} // namespace OCLRT

View File

@@ -20,21 +20,22 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "gmm_client_context.h"
#include "runtime/gmm_helper/resource_info.h"
#include "runtime/gmm_helper/gmm_helper.h"
namespace OCLRT {
void GmmResourceInfo::customDeleter(GMM_RESOURCE_INFO *gmmResourceInfo) {
Gmm::gmmClientContext->DestroyResInfoObject(gmmResourceInfo);
Gmm::gmmClientContext->destroyResInfoObject(gmmResourceInfo);
}
GmmResourceInfo::GmmResourceInfo(GMM_RESCREATE_PARAMS *resourceCreateParams) {
auto resourceInfoPtr = Gmm::gmmClientContext->CreateResInfoObject(resourceCreateParams);
auto resourceInfoPtr = Gmm::gmmClientContext->createResInfoObject(resourceCreateParams);
this->resourceInfo = UniquePtrType(resourceInfoPtr, GmmResourceInfo::customDeleter);
}
GmmResourceInfo::GmmResourceInfo(GMM_RESOURCE_INFO *inputGmmResourceInfo) {
auto resourceInfoPtr = Gmm::gmmClientContext->CopyResInfoObject(inputGmmResourceInfo);
auto resourceInfoPtr = Gmm::gmmClientContext->copyResInfoObject(inputGmmResourceInfo);
this->resourceInfo = UniquePtrType(resourceInfoPtr, GmmResourceInfo::customDeleter);
}