Skip to content

Commit 4600314

Browse files
Gmm interface update
- Use local gmmClientContext instead of pGMMGlobalContext - ResourceInfo and PTmanager creation from gmmClientContext - Mock Gmm context creation in Wddm to have only one instance per run Change-Id: I67e015c57f0ab5524564760fd9a849615615697f
1 parent 231ad7c commit 4600314

File tree

15 files changed

+248
-49
lines changed

15 files changed

+248
-49
lines changed

runtime/gmm_helper/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@ set(RUNTIME_SRCS_GMM_HELPER_BASE
2424
${CMAKE_CURRENT_SOURCE_DIR}/gmm_helper.h
2525
${CMAKE_CURRENT_SOURCE_DIR}/gmm_lib.h
2626
${CMAKE_CURRENT_SOURCE_DIR}/resource_info.h
27+
${CMAKE_CURRENT_SOURCE_DIR}/resource_info_impl.cpp
2728
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/gmm_utils.cpp
2829
)
2930

3031
set(RUNTIME_SRCS_GMM_HELPER_WINDOWS
3132
${CMAKE_CURRENT_SOURCE_DIR}/page_table_mngr.h
33+
${CMAKE_CURRENT_SOURCE_DIR}/page_table_mngr_impl.cpp
3234
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/gmm_memory.h
3335
${CMAKE_CURRENT_SOURCE_DIR}/gmm_memory_base.h
36+
${CMAKE_CURRENT_SOURCE_DIR}/gmm_memory_base.cpp
3437
)
3538

3639
target_sources(${NEO_STATIC_LIB_NAME} PRIVATE ${RUNTIME_SRCS_GMM_HELPER_BASE})

runtime/gmm_helper/gmm_helper.cpp

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,25 @@ bool Gmm::initContext(const PLATFORM *pPlatform,
6666
const FeatureTable *pSkuTable,
6767
const WorkaroundTable *pWaTable,
6868
const GT_SYSTEM_INFO *pGtSysInfo) {
69-
// fill values Gmmlib requested
70-
_SKU_FEATURE_TABLE gmmFtrTable = {};
71-
_WA_TABLE gmmWaTable = {};
72-
SkuInfoTransfer::transferFtrTableForGmm(&gmmFtrTable, pSkuTable);
73-
SkuInfoTransfer::transferWaTableForGmm(&gmmWaTable, pWaTable);
74-
75-
bool success = GMM_SUCCESS == GmmInitGlobalContext(*pPlatform, &gmmFtrTable, &gmmWaTable, pGtSysInfo, GMM_OGL_VISTA);
76-
DEBUG_BREAK_IF(!success);
77-
return success;
69+
if (!Gmm::gmmClientContext) {
70+
_SKU_FEATURE_TABLE gmmFtrTable = {};
71+
_WA_TABLE gmmWaTable = {};
72+
SkuInfoTransfer::transferFtrTableForGmm(&gmmFtrTable, pSkuTable);
73+
SkuInfoTransfer::transferWaTableForGmm(&gmmWaTable, pWaTable);
74+
75+
bool success = GMM_SUCCESS == GmmInitGlobalContext(*pPlatform, &gmmFtrTable, &gmmWaTable, pGtSysInfo, GMM_CLIENT::GMM_OCL_VISTA);
76+
UNRECOVERABLE_IF(!success);
77+
Gmm::gmmClientContext = GmmCreateClientContext(GMM_CLIENT::GMM_OCL_VISTA);
78+
}
79+
return Gmm::gmmClientContext != nullptr;
80+
}
81+
82+
void Gmm::destroyContext() {
83+
if (Gmm::gmmClientContext) {
84+
GmmDeleteClientContext(Gmm::gmmClientContext);
85+
Gmm::gmmClientContext = nullptr;
86+
GmmDestroyGlobalContext();
87+
}
7888
}
7989

8090
uint32_t Gmm::getMOCS(uint32_t type) {
@@ -86,8 +96,7 @@ uint32_t Gmm::getMOCS(uint32_t type) {
8696
}
8797
}
8898

89-
MEMORY_OBJECT_CONTROL_STATE mocs =
90-
pGmmGlobalContext->GetCachePolicyObj()->CachePolicyGetMemoryObject(nullptr, static_cast<GMM_RESOURCE_USAGE_TYPE>(type));
99+
MEMORY_OBJECT_CONTROL_STATE mocs = Gmm::gmmClientContext->CachePolicyGetMemoryObject(nullptr, static_cast<GMM_RESOURCE_USAGE_TYPE>(type));
91100

92101
return static_cast<uint32_t>(mocs.DwordValue);
93102
}
@@ -404,5 +413,6 @@ bool Gmm::unifiedAuxTranslationCapable() const {
404413
}
405414

406415
bool Gmm::useSimplifiedMocsTable = false;
416+
GMM_CLIENT_CONTEXT *Gmm::gmmClientContext = nullptr;
407417

408418
} // namespace OCLRT

runtime/gmm_helper/gmm_helper.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Intel Corporation
2+
* Copyright (c) 2017 - 2018, Intel Corporation
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a
55
* copy of this software and associated documentation files (the "Software"),
@@ -63,7 +63,7 @@ class Gmm {
6363
static Gmm *create(GMM_RESOURCE_INFO *inputGmm);
6464

6565
static bool initContext(const PLATFORM *pPlatform, const FeatureTable *pSkuTable, const WorkaroundTable *pWaTable, const GT_SYSTEM_INFO *pGtSysInfo);
66-
static void destroyContext() { GmmDestroyGlobalContext(); }
66+
static void destroyContext();
6767

6868
static uint32_t getMOCS(uint32_t type);
6969

@@ -99,5 +99,6 @@ class Gmm {
9999

100100
bool isRenderCompressed = false;
101101
static bool useSimplifiedMocsTable;
102+
static GMM_CLIENT_CONTEXT *gmmClientContext;
102103
};
103104
} // namespace OCLRT
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) 2018, Intel Corporation
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included
12+
* in all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18+
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19+
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20+
* OTHER DEALINGS IN THE SOFTWARE.
21+
*/
22+
23+
#include "runtime/gmm_helper/gmm_memory_base.h"
24+
#include "runtime/gmm_helper/gmm_helper.h"
25+
26+
namespace OCLRT {
27+
bool GmmMemoryBase::configureDeviceAddressSpace(GMM_ESCAPE_HANDLE hAdapter,
28+
GMM_ESCAPE_HANDLE hDevice,
29+
GMM_ESCAPE_FUNC_TYPE pfnEscape,
30+
GMM_GFX_SIZE_T SvmSize,
31+
BOOLEAN FaultableSvm,
32+
BOOLEAN SparseReady,
33+
BOOLEAN BDWL3Coherency,
34+
GMM_GFX_SIZE_T SizeOverride,
35+
GMM_GFX_SIZE_T SlmGfxSpaceReserve) {
36+
return Gmm::gmmClientContext->ConfigureDeviceAddressSpace(
37+
{hAdapter},
38+
{hDevice},
39+
{pfnEscape},
40+
SvmSize,
41+
FaultableSvm,
42+
SparseReady,
43+
BDWL3Coherency,
44+
SizeOverride,
45+
SlmGfxSpaceReserve) != 0;
46+
}
47+
48+
uintptr_t GmmMemoryBase::getInternalGpuVaRangeLimit() {
49+
return static_cast<uintptr_t>(pGmmGlobalContext->GetInternalGpuVaRangeLimit());
50+
}
51+
52+
}; // namespace OCLRT

runtime/gmm_helper/gmm_memory_base.h

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,9 @@ class GmmMemoryBase {
3737
BOOLEAN SparseReady,
3838
BOOLEAN BDWL3Coherency,
3939
GMM_GFX_SIZE_T SizeOverride,
40-
GMM_GFX_SIZE_T SlmGfxSpaceReserve) {
41-
return GmmConfigureDeviceAddressSpace(
42-
hAdapter,
43-
hDevice,
44-
pfnEscape,
45-
SvmSize,
46-
FaultableSvm,
47-
SparseReady,
48-
BDWL3Coherency,
49-
SizeOverride,
50-
SlmGfxSpaceReserve) != 0
51-
? true
52-
: false;
53-
}
40+
GMM_GFX_SIZE_T SlmGfxSpaceReserve);
5441

55-
MOCKABLE_VIRTUAL uintptr_t getInternalGpuVaRangeLimit() {
56-
return static_cast<uintptr_t>(pGmmGlobalContext->GetInternalGpuVaRangeLimit());
57-
}
42+
MOCKABLE_VIRTUAL uintptr_t getInternalGpuVaRangeLimit();
5843

5944
protected:
6045
GmmMemoryBase() = default;

runtime/gmm_helper/page_table_mngr.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Intel Corporation
2+
* Copyright (c) 2017 - 2018, Intel Corporation
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a
55
* copy of this software and associated documentation files (the "Software"),
@@ -23,11 +23,12 @@
2323
#pragma once
2424
#include "runtime/gmm_helper/gmm_lib.h"
2525
#include <memory>
26+
#include <functional>
2627

2728
namespace OCLRT {
2829
class GmmPageTableMngr {
2930
public:
30-
virtual ~GmmPageTableMngr() = default;
31+
MOCKABLE_VIRTUAL ~GmmPageTableMngr() = default;
3132

3233
static GmmPageTableMngr *create(GMM_DEVICE_CALLBACKS *deviceCb, unsigned int translationTableFlags, GMM_TRANSLATIONTABLE_CALLBACKS *translationTableCb);
3334

@@ -44,12 +45,13 @@ class GmmPageTableMngr {
4445
}
4546

4647
protected:
48+
static void customDeleter(GMM_PAGETABLE_MGR *gmmPageTableManager);
49+
using UniquePtrType = std::unique_ptr<GMM_PAGETABLE_MGR, std::function<void(GMM_PAGETABLE_MGR *)>>;
50+
4751
GmmPageTableMngr() = default;
4852

49-
GmmPageTableMngr(GMM_DEVICE_CALLBACKS *deviceCb, unsigned int translationTableFlags, GMM_TRANSLATIONTABLE_CALLBACKS *translationTableCb) {
50-
pageTableManager.reset(new GMM_PAGETABLE_MGR(deviceCb, translationTableFlags, translationTableCb));
51-
}
53+
GmmPageTableMngr(GMM_DEVICE_CALLBACKS *deviceCb, unsigned int translationTableFlags, GMM_TRANSLATIONTABLE_CALLBACKS *translationTableCb);
5254

53-
std::unique_ptr<GMM_PAGETABLE_MGR> pageTableManager;
55+
UniquePtrType pageTableManager;
5456
};
5557
} // namespace OCLRT
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) 2018, Intel Corporation
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included
12+
* in all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18+
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19+
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20+
* OTHER DEALINGS IN THE SOFTWARE.
21+
*/
22+
23+
#include "runtime/gmm_helper/gmm_helper.h"
24+
#include "runtime/gmm_helper/page_table_mngr.h"
25+
26+
namespace OCLRT {
27+
void GmmPageTableMngr::customDeleter(GMM_PAGETABLE_MGR *gmmPageTableManager) {
28+
Gmm::gmmClientContext->DestroyPageTblMgrObject(gmmPageTableManager);
29+
}
30+
31+
GmmPageTableMngr::GmmPageTableMngr(GMM_DEVICE_CALLBACKS *deviceCb, unsigned int translationTableFlags, GMM_TRANSLATIONTABLE_CALLBACKS *translationTableCb) {
32+
auto pageTableMngrPtr = Gmm::gmmClientContext->CreatePageTblMgrObject(deviceCb, translationTableCb, translationTableFlags);
33+
this->pageTableManager = UniquePtrType(pageTableMngrPtr, GmmPageTableMngr::customDeleter);
34+
}
35+
36+
} // namespace OCLRT

runtime/gmm_helper/resource_info.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Intel Corporation
2+
* Copyright (c) 2017 - 2018, Intel Corporation
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a
55
* copy of this software and associated documentation files (the "Software"),
@@ -23,6 +23,7 @@
2323
#pragma once
2424
#include "runtime/gmm_helper/gmm_lib.h"
2525
#include <memory>
26+
#include <functional>
2627

2728
namespace OCLRT {
2829
class GmmResourceInfo {
@@ -31,11 +32,7 @@ class GmmResourceInfo {
3132

3233
static GmmResourceInfo *create(GMM_RESOURCE_INFO *inputGmmResourceInfo);
3334

34-
virtual ~GmmResourceInfo() {
35-
if (resourceInfo) {
36-
GmmResFree(resourceInfo);
37-
}
38-
}
35+
MOCKABLE_VIRTUAL ~GmmResourceInfo() = default;
3936

4037
MOCKABLE_VIRTUAL size_t getSizeAllocation() { return static_cast<size_t>(resourceInfo->GetSizeAllocation()); }
4138

@@ -81,15 +78,18 @@ class GmmResourceInfo {
8178

8279
MOCKABLE_VIRTUAL uint64_t getUnifiedAuxSurfaceOffset(GMM_UNIFIED_AUX_TYPE auxType) { return resourceInfo->GetUnifiedAuxSurfaceOffset(auxType); }
8380

84-
MOCKABLE_VIRTUAL GMM_RESOURCE_INFO *peekHandle() const { return resourceInfo; }
81+
MOCKABLE_VIRTUAL GMM_RESOURCE_INFO *peekHandle() const { return resourceInfo.get(); }
8582

8683
protected:
84+
static void customDeleter(GMM_RESOURCE_INFO *gmmResourceInfoHandle);
85+
using UniquePtrType = std::unique_ptr<GMM_RESOURCE_INFO, std::function<void(GMM_RESOURCE_INFO *)>>;
86+
8787
GmmResourceInfo() = default;
8888

89-
GmmResourceInfo(GMM_RESCREATE_PARAMS *resourceCreateParams) { resourceInfo = GmmResCreate(resourceCreateParams); }
89+
GmmResourceInfo(GMM_RESCREATE_PARAMS *resourceCreateParams);
9090

91-
GmmResourceInfo(GMM_RESOURCE_INFO *inputGmmResourceInfo) { resourceInfo = GmmResCopy(inputGmmResourceInfo); }
91+
GmmResourceInfo(GMM_RESOURCE_INFO *inputGmmResourceInfo);
9292

93-
GMM_RESOURCE_INFO *resourceInfo = nullptr;
93+
UniquePtrType resourceInfo;
9494
};
9595
} // namespace OCLRT
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2018, Intel Corporation
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included
12+
* in all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18+
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19+
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20+
* OTHER DEALINGS IN THE SOFTWARE.
21+
*/
22+
23+
#include "runtime/gmm_helper/resource_info.h"
24+
#include "runtime/gmm_helper/gmm_helper.h"
25+
26+
namespace OCLRT {
27+
void GmmResourceInfo::customDeleter(GMM_RESOURCE_INFO *gmmResourceInfo) {
28+
Gmm::gmmClientContext->DestroyResInfoObject(gmmResourceInfo);
29+
}
30+
31+
GmmResourceInfo::GmmResourceInfo(GMM_RESCREATE_PARAMS *resourceCreateParams) {
32+
auto resourceInfoPtr = Gmm::gmmClientContext->CreateResInfoObject(resourceCreateParams);
33+
this->resourceInfo = UniquePtrType(resourceInfoPtr, GmmResourceInfo::customDeleter);
34+
}
35+
36+
GmmResourceInfo::GmmResourceInfo(GMM_RESOURCE_INFO *inputGmmResourceInfo) {
37+
auto resourceInfoPtr = Gmm::gmmClientContext->CopyResInfoObject(inputGmmResourceInfo);
38+
this->resourceInfo = UniquePtrType(resourceInfoPtr, GmmResourceInfo::customDeleter);
39+
}
40+
41+
} // namespace OCLRT

runtime/os_interface/windows/wddm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Wddm::Wddm() : Wddm(new Gdi()) {
9090
Wddm::~Wddm() {
9191
resetPageTableManager(nullptr);
9292
if (initialized)
93-
Gmm::destroyContext();
93+
destroyGmmContext();
9494
destroyContext(context);
9595
destroyPagingQueue();
9696
destroyDevice();

0 commit comments

Comments
 (0)