Skip to content

Commit 98b8b4b

Browse files
Prepare to use gmm as dll on Windows
Since this commit neo on Windows can use static or shared gmm lib Change-Id: I7db70d7f9bc969e8193ac77e8b6d65ecc57d0093
1 parent c1782b8 commit 98b8b4b

34 files changed

+1022
-87
lines changed

CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,27 @@ if(NOT GMMUMD_LIB_NAME)
240240
endif()
241241
endif()
242242
endif()
243+
get_target_property(target_type ${GMMUMD_LIB_NAME} TYPE)
244+
245+
if(target_type STREQUAL "STATIC_LIBRARY")
246+
set(USE_STATIC_GMM TRUE)
247+
endif()
248+
243249
set(UMKM_SHAREDDATA_INCLUDE_PATHS $<TARGET_PROPERTY:${GMMUMD_LIB_NAME},INTERFACE_INCLUDE_DIRECTORIES>)
244250

251+
set(GMM_LIB_FILENAME "igdgmm${NEO_BITS}${CMAKE_SHARED_LIBRARY_SUFFIX}")
252+
253+
macro(copy_gmm_dll_for target)
254+
if(WIN32 AND NOT USE_STATIC_GMM)
255+
add_dependencies(${target} ${GMMUMD_LIB_NAME})
256+
add_custom_command(
257+
TARGET ${target}
258+
POST_BUILD
259+
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:${GMMUMD_LIB_NAME}> $<TARGET_FILE_DIR:${target}>
260+
)
261+
endif()
262+
endmacro()
263+
245264
# Instrumentation detection
246265
if(NOT INSTRUMENTATION_LIB_NAME)
247266
if(INSTRUMENTATION_SOURCE_DIR)
@@ -534,3 +553,4 @@ include(package.cmake)
534553
configure_file(config.h.in ${IGDRCL_BUILD_DIR}/config.h)
535554
configure_file(compiler.config.h.in ${IGDRCL_BUILD_DIR}/compiler.config.h)
536555
configure_file(driver_version.h.in ${IGDRCL_BUILD_DIR}/driver_version.h) # Put Driver version into define
556+
configure_file(lib_names.h.in ${IGDRCL_BUILD_DIR}/lib_names.h)

lib_names.h.in

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
#ifndef LIB_NAMES_H
24+
#define LIB_NAMES_H
25+
26+
#cmakedefine GMM_LIB_FILENAME "${GMM_LIB_FILENAME}"
27+
28+
#endif /* LIB_NAMES_H */

runtime/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ target_compile_definitions(${NEO_STATIC_LIB_NAME} PUBLIC DEFAULT_PLATFORM=${DEFA
100100

101101
link_directories(${GMM_LIB_PATHS})
102102

103-
target_link_libraries(${NEO_STATIC_LIB_NAME} ${GMMUMD_LIB_NAME})
103+
if(UNIX OR USE_STATIC_GMM)
104+
target_link_libraries(${NEO_STATIC_LIB_NAME} ${GMMUMD_LIB_NAME})
105+
else()
106+
target_compile_definitions(${NEO_STATIC_LIB_NAME} PUBLIC GMM_LIB_DLL)
107+
endif()
104108

105109
if(INSTRUMENTATION_LIB_NAME)
106110
add_dependencies(${NEO_STATIC_LIB_NAME} ${INSTRUMENTATION_LIB_NAME})
@@ -134,6 +138,7 @@ if(${GENERATE_EXECUTABLE})
134138
add_library(${NEO_DYNAMIC_LIB_NAME} SHARED
135139
${NEO_DYNAMIC_LIB__TARGET_OBJECTS}
136140
)
141+
add_dependencies(${NEO_DYNAMIC_LIB_NAME} ${GMMUMD_LIB_NAME})
137142

138143
if(GTPIN_HEADERS_DIR)
139144
macro(macro_for_each_gen)

runtime/dll/windows/options.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2020
* OTHER DEALINGS IN THE SOFTWARE.
2121
*/
22+
#include "lib_names.h"
2223

2324
namespace Os {
2425
#if defined(_WIN64)
@@ -30,4 +31,5 @@ const char *igcDllName = "igc32.dll";
3031
#endif
3132

3233
const char *gdiDllName = "gdi32.dll";
34+
const char *gmmDllName = GMM_LIB_FILENAME;
3335
} // namespace Os

runtime/gmm_helper/gmm_helper.cpp

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,6 @@
3131
#include "runtime/helpers/hw_info.h"
3232
#include "runtime/sku_info/operations/sku_info_transfer.h"
3333

34-
extern "C" {
35-
36-
void GMMDebugBreak(const char *file, const char *function, const int line) {
37-
}
38-
39-
void GMMPrintMessage(uint32_t debugLevel, const char *debugMessageFmt, ...) {
40-
}
41-
42-
typedef struct GfxDebugControlRec {
43-
uint32_t Version;
44-
uint32_t Size;
45-
uint32_t AssertEnableMask;
46-
uint32_t EnableDebugFileDump;
47-
uint32_t DebugEnableMask;
48-
uint32_t RingBufDbgMask;
49-
uint32_t ReportAssertEnable;
50-
uint32_t AssertBreakDisable;
51-
52-
} GFX_DEBUG_CONTROL, *PGFX_DEBUG_CONTROL;
53-
PGFX_DEBUG_CONTROL pDebugControl;
54-
}
55-
5634
namespace OCLRT {
5735
void Gmm::create() {
5836
if (resourceParams.BaseWidth >= maxPossiblePitch) {
@@ -71,19 +49,21 @@ bool Gmm::initContext(const PLATFORM *pPlatform,
7149
_WA_TABLE gmmWaTable = {};
7250
SkuInfoTransfer::transferFtrTableForGmm(&gmmFtrTable, pSkuTable);
7351
SkuInfoTransfer::transferWaTableForGmm(&gmmWaTable, pWaTable);
74-
75-
bool success = GMM_SUCCESS == GmmInitGlobalContext(*pPlatform, &gmmFtrTable, &gmmWaTable, pGtSysInfo, GMM_CLIENT::GMM_OCL_VISTA);
52+
if (!isLoaded) {
53+
loadLib();
54+
}
55+
bool success = GMM_SUCCESS == initGlobalContextFunc(*pPlatform, &gmmFtrTable, &gmmWaTable, pGtSysInfo, GMM_CLIENT::GMM_OCL_VISTA);
7656
UNRECOVERABLE_IF(!success);
77-
Gmm::gmmClientContext = GmmCreateClientContext(GMM_CLIENT::GMM_OCL_VISTA);
57+
Gmm::gmmClientContext = createClientContextFunc(GMM_CLIENT::GMM_OCL_VISTA);
7858
}
7959
return Gmm::gmmClientContext != nullptr;
8060
}
8161

8262
void Gmm::destroyContext() {
8363
if (Gmm::gmmClientContext) {
84-
GmmDeleteClientContext(Gmm::gmmClientContext);
64+
deleteClientContextFunc(Gmm::gmmClientContext);
8565
Gmm::gmmClientContext = nullptr;
86-
GmmDestroyGlobalContext();
66+
destroyGlobalContextFunc();
8767
}
8868
}
8969

@@ -414,5 +394,6 @@ bool Gmm::unifiedAuxTranslationCapable() const {
414394

415395
bool Gmm::useSimplifiedMocsTable = false;
416396
GMM_CLIENT_CONTEXT *Gmm::gmmClientContext = nullptr;
397+
bool Gmm::isLoaded = false;
417398

418399
} // namespace OCLRT

runtime/gmm_helper/gmm_helper.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@
2727
#include "runtime/gmm_helper/gmm_lib.h"
2828
#include "runtime/api/cl_types.h"
2929

30-
extern "C" {
31-
void GMMDebugBreak(const char *file, const char *function, const int line);
32-
33-
void GMMPrintMessage(uint32_t debugLevel, const char *debugMessageFmt, ...);
34-
}
35-
3630
namespace OCLRT {
3731
struct HardwareInfo;
3832
struct FeatureTable;
@@ -63,6 +57,7 @@ class Gmm {
6357
static Gmm *create(GMM_RESOURCE_INFO *inputGmm);
6458

6559
static bool initContext(const PLATFORM *pPlatform, const FeatureTable *pSkuTable, const WorkaroundTable *pWaTable, const GT_SYSTEM_INFO *pGtSysInfo);
60+
static void loadLib();
6661
static void destroyContext();
6762

6863
static uint32_t getMOCS(uint32_t type);
@@ -97,8 +92,14 @@ class Gmm {
9792
GMM_RESCREATE_PARAMS resourceParams = {};
9893
std::unique_ptr<GmmResourceInfo> gmmResourceInfo;
9994

95+
static decltype(&GmmInitGlobalContext) initGlobalContextFunc;
96+
static decltype(&GmmDestroyGlobalContext) destroyGlobalContextFunc;
97+
static decltype(&GmmCreateClientContext) createClientContextFunc;
98+
static decltype(&GmmDeleteClientContext) deleteClientContextFunc;
99+
100100
bool isRenderCompressed = false;
101101
static bool useSimplifiedMocsTable;
102102
static GMM_CLIENT_CONTEXT *gmmClientContext;
103+
static bool isLoaded;
103104
};
104105
} // namespace OCLRT

runtime/gmm_helper/gmm_memory_base.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ bool GmmMemoryBase::configureDeviceAddressSpace(GMM_ESCAPE_HANDLE hAdapter,
4646
}
4747

4848
uintptr_t GmmMemoryBase::getInternalGpuVaRangeLimit() {
49-
return static_cast<uintptr_t>(pGmmGlobalContext->GetInternalGpuVaRangeLimit());
49+
return static_cast<uintptr_t>(Gmm::gmmClientContext->GetInternalGpuVaRangeLimit());
5050
}
5151

5252
}; // namespace OCLRT

runtime/gmm_helper/page_table_mngr.cpp

Lines changed: 2 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"),
@@ -24,7 +24,7 @@
2424
#include "runtime/gmm_helper/page_table_mngr.h"
2525

2626
namespace OCLRT {
27-
GmmPageTableMngr *GmmPageTableMngr::create(GMM_DEVICE_CALLBACKS *deviceCb, unsigned int translationTableFlags, GMM_TRANSLATIONTABLE_CALLBACKS *translationTableCb) {
27+
GmmPageTableMngr *GmmPageTableMngr::create(GMM_DEVICE_CALLBACKS_INT *deviceCb, unsigned int translationTableFlags, GMM_TRANSLATIONTABLE_CALLBACKS *translationTableCb) {
2828
return new GmmPageTableMngr(deviceCb, translationTableFlags, translationTableCb);
2929
}
3030

runtime/gmm_helper/page_table_mngr.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class GmmPageTableMngr {
3030
public:
3131
MOCKABLE_VIRTUAL ~GmmPageTableMngr() = default;
3232

33-
static GmmPageTableMngr *create(GMM_DEVICE_CALLBACKS *deviceCb, unsigned int translationTableFlags, GMM_TRANSLATIONTABLE_CALLBACKS *translationTableCb);
33+
static GmmPageTableMngr *create(GMM_DEVICE_CALLBACKS_INT *deviceCb, unsigned int translationTableFlags, GMM_TRANSLATIONTABLE_CALLBACKS *translationTableCb);
3434

3535
MOCKABLE_VIRTUAL GMM_STATUS initContextAuxTableRegister(HANDLE initialBBHandle, GMM_ENGINE_TYPE engineType) {
3636
return pageTableManager->InitContextAuxTableRegister(initialBBHandle, engineType);
@@ -50,7 +50,7 @@ class GmmPageTableMngr {
5050

5151
GmmPageTableMngr() = default;
5252

53-
GmmPageTableMngr(GMM_DEVICE_CALLBACKS *deviceCb, unsigned int translationTableFlags, GMM_TRANSLATIONTABLE_CALLBACKS *translationTableCb);
53+
GmmPageTableMngr(GMM_DEVICE_CALLBACKS_INT *deviceCb, unsigned int translationTableFlags, GMM_TRANSLATIONTABLE_CALLBACKS *translationTableCb);
5454

5555
UniquePtrType pageTableManager;
5656
};

runtime/gmm_helper/page_table_mngr_impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void GmmPageTableMngr::customDeleter(GMM_PAGETABLE_MGR *gmmPageTableManager) {
2828
Gmm::gmmClientContext->DestroyPageTblMgrObject(gmmPageTableManager);
2929
}
3030

31-
GmmPageTableMngr::GmmPageTableMngr(GMM_DEVICE_CALLBACKS *deviceCb, unsigned int translationTableFlags, GMM_TRANSLATIONTABLE_CALLBACKS *translationTableCb) {
31+
GmmPageTableMngr::GmmPageTableMngr(GMM_DEVICE_CALLBACKS_INT *deviceCb, unsigned int translationTableFlags, GMM_TRANSLATIONTABLE_CALLBACKS *translationTableCb) {
3232
auto pageTableMngrPtr = Gmm::gmmClientContext->CreatePageTblMgrObject(deviceCb, translationTableCb, translationTableFlags);
3333
this->pageTableManager = UniquePtrType(pageTableMngrPtr, GmmPageTableMngr::customDeleter);
3434
}

runtime/os_interface/linux/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ set(RUNTIME_SRCS_OS_INTERFACE_LINUX
4343
${CMAKE_CURRENT_SOURCE_DIR}/drm_neo.h
4444
${CMAKE_CURRENT_SOURCE_DIR}/drm_neo_create.cpp
4545
${CMAKE_CURRENT_SOURCE_DIR}/drm_null_device.h
46+
${CMAKE_CURRENT_SOURCE_DIR}/gmm_interface_linux.cpp
4647
${CMAKE_CURRENT_SOURCE_DIR}/hw_info_config.cpp
4748
${CMAKE_CURRENT_SOURCE_DIR}/linux_inc.cpp
4849
${CMAKE_CURRENT_SOURCE_DIR}/os_thread_linux.cpp
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
25+
namespace OCLRT {
26+
27+
decltype(Gmm::initGlobalContextFunc) Gmm::initGlobalContextFunc = nullptr;
28+
decltype(Gmm::destroyGlobalContextFunc) Gmm::destroyGlobalContextFunc = nullptr;
29+
decltype(Gmm::createClientContextFunc) Gmm::createClientContextFunc = nullptr;
30+
decltype(Gmm::deleteClientContextFunc) Gmm::deleteClientContextFunc = nullptr;
31+
32+
void Gmm::loadLib() {
33+
Gmm::initGlobalContextFunc = GmmInitGlobalContext;
34+
Gmm::destroyGlobalContextFunc = GmmDestroyGlobalContext;
35+
Gmm::createClientContextFunc = GmmCreateClientContext;
36+
Gmm::deleteClientContextFunc = GmmDeleteClientContext;
37+
isLoaded = true;
38+
}
39+
}

runtime/os_interface/windows/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ else()
2424
set(KMDAF_FILE_SUFFIX "_stub")
2525
endif()
2626

27+
if(USE_STATIC_GMM)
28+
set(GMM_INTERFACE_FILE_WINDOWS ${CMAKE_CURRENT_SOURCE_DIR}/gmm_interface_static_win.cpp)
29+
else()
30+
set(GMM_INTERFACE_FILE_WINDOWS ${CMAKE_CURRENT_SOURCE_DIR}/gmm_interface_dynamic_win.cpp)
31+
endif()
32+
set_property(GLOBAL PROPERTY GMM_INTERFACE_FILE_WINDOWS ${GMM_INTERFACE_FILE_WINDOWS})
33+
2734
set(RUNTIME_SRCS_OS_INTERFACE_WINDOWS
2835
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
2936
${CMAKE_CURRENT_SOURCE_DIR}/api_win.cpp
@@ -39,6 +46,7 @@ set(RUNTIME_SRCS_OS_INTERFACE_WINDOWS
3946
${CMAKE_CURRENT_SOURCE_DIR}/driver_info.h
4047
${CMAKE_CURRENT_SOURCE_DIR}/gdi_interface.cpp
4148
${CMAKE_CURRENT_SOURCE_DIR}/gdi_interface.h
49+
${GMM_INTERFACE_FILE_WINDOWS}
4250
${CMAKE_CURRENT_SOURCE_DIR}/kmdaf_listener${KMDAF_FILE_SUFFIX}.cpp
4351
${CMAKE_CURRENT_SOURCE_DIR}/kmdaf_listener.h
4452
${CMAKE_CURRENT_SOURCE_DIR}/os_inc.h

runtime/os_interface/windows/gdi_interface.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,5 @@ class Gdi {
9999

100100
private:
101101
OCLRT::Windows::OsLibrary gdiDll;
102-
static const std::string gdiDllName;
103-
static const std::string gdiMockDllName;
104102
};
105103
} // namespace OCLRT
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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/helpers/debug_helpers.h"
25+
#include "runtime/os_interface/os_library.h"
26+
27+
namespace Os {
28+
extern const char *gmmDllName;
29+
}
30+
31+
namespace OCLRT {
32+
GMM_STATUS(GMM_STDCALL *myPfnCreateSingletonContext)
33+
(const PLATFORM Platform, const SKU_FEATURE_TABLE *pSkuTable, const WA_TABLE *pWaTable, const GT_SYSTEM_INFO *pGtSysInfo);
34+
GMM_STATUS GMM_STDCALL myGmmInitGlobalContext(const PLATFORM Platform, const SKU_FEATURE_TABLE *pSkuTable, const WA_TABLE *pWaTable, const GT_SYSTEM_INFO *pGtSysInfo, GMM_CLIENT ClientType) {
35+
return myPfnCreateSingletonContext(Platform, pSkuTable, pWaTable, pGtSysInfo);
36+
}
37+
decltype(Gmm::initGlobalContextFunc) Gmm::initGlobalContextFunc = &myGmmInitGlobalContext;
38+
decltype(Gmm::destroyGlobalContextFunc) Gmm::destroyGlobalContextFunc = nullptr;
39+
decltype(Gmm::createClientContextFunc) Gmm::createClientContextFunc = nullptr;
40+
decltype(Gmm::deleteClientContextFunc) Gmm::deleteClientContextFunc = nullptr;
41+
42+
std::unique_ptr<OsLibrary> gmmLib;
43+
void Gmm::loadLib() {
44+
gmmLib.reset(OsLibrary::load(Os::gmmDllName));
45+
46+
UNRECOVERABLE_IF(!gmmLib);
47+
if (gmmLib->isLoaded()) {
48+
auto openGmmFunc = reinterpret_cast<decltype(&OpenGmm)>(gmmLib->getProcAddress(GMM_ENTRY_NAME));
49+
GmmExportEntries entries;
50+
auto status = openGmmFunc(&entries);
51+
if (status == GMM_SUCCESS) {
52+
myPfnCreateSingletonContext = entries.pfnCreateSingletonContext;
53+
Gmm::destroyGlobalContextFunc = entries.pfnDestroySingletonContext;
54+
Gmm::createClientContextFunc = entries.pfnCreateClientContext;
55+
Gmm::deleteClientContextFunc = entries.pfnDeleteClientContext;
56+
isLoaded = myPfnCreateSingletonContext && Gmm::destroyGlobalContextFunc && Gmm::createClientContextFunc && Gmm::deleteClientContextFunc;
57+
}
58+
}
59+
UNRECOVERABLE_IF(!isLoaded);
60+
}
61+
}

0 commit comments

Comments
 (0)