Skip to content

Commit fea2553

Browse files
committed
Adapt project to work on windows with L0 and GPU
1 parent 13d7b52 commit fea2553

File tree

4 files changed

+36
-28
lines changed

4 files changed

+36
-28
lines changed

src/libumf.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ EXPORTS
1414
umfFree
1515
umfGetIPCHandle
1616
umfGetLastFailedMemoryProvider
17+
umfLevelZeroMemoryProviderOps
1718
umfMemoryProviderAlloc
1819
umfMemoryProviderAllocationMerge
1920
umfMemoryProviderAllocationSplit

src/utils/utils_load_library.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,15 @@ static inline void *util_open_library(const char *filename) {
3939
static inline int util_close_library(void *handle) {
4040
// If the FreeLibrary function succeeds, the return value is nonzero.
4141
// If the FreeLibrary function fails, the return value is zero.
42-
return (FreeLibrary(handle) == 0);
42+
return (FreeLibrary((HMODULE)handle) == 0);
4343
}
4444

4545
static inline void *util_get_symbol_addr(void *handle, const char *symbol) {
46-
return GetProcAddress(handle, symbol);
46+
if (handle == NULL) {
47+
// handle can't be null
48+
handle = GetModuleHandle("ze_loader.dll");
49+
}
50+
return GetProcAddress((HMODULE)handle, symbol);
4751
}
4852

4953
#else /* Linux */

test/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function(add_umf_test)
5858
NAME ${TEST_TARGET_NAME}
5959
SRCS ${ARG_SRCS}
6060
LIBS ${TEST_LIBS})
61-
61+
6262
target_link_directories(${TEST_TARGET_NAME} PRIVATE ${LIB_DIRS})
6363

6464
target_include_directories(
@@ -183,8 +183,7 @@ endif()
183183

184184
# TODO add support for Windows
185185
if(UMF_BUILD_GPU_TESTS
186-
AND UMF_BUILD_LEVEL_ZERO_PROVIDER
187-
AND LINUX)
186+
AND UMF_BUILD_LEVEL_ZERO_PROVIDER)
188187
# we have two test binaries here that use the same sources, but differ in
189188
# the way they are linked to the Level Zero (statically or at runtime using
190189
# dlopen)

test/providers/provider_level_zero.cpp

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
// Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
33
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

5-
#include <dlfcn.h>
6-
#include <level_zero/ze_api.h>
5+
#define NOMINMAX
6+
#include <ze_api.h>
77

88
#include "pool.hpp"
99
#include "umf/providers/provider_level_zero.h"
10+
#include "utils_load_library.h"
1011

1112
using umf_test::test;
1213
using namespace umf_test;
@@ -66,63 +67,66 @@ struct umfLevelZeroProviderTest : umf_test::test {
6667
// NOTE that we use RTLD_GLOBAL which add all loaded symbols to the
6768
// global symbol table. These symbols would be used by the Level Zero
6869
// provider later
69-
zeDlHandle = dlopen("libze_loader.so", RTLD_GLOBAL | RTLD_LAZY);
70-
71-
*(void **)&libze_ops.zeInit = dlsym(zeDlHandle, "zeInit");
70+
#ifdef _WIN32
71+
zeDlHandle = util_open_library("ze_loader.dll");
72+
#else
73+
zeDlHandle = util_open_library("libze_loader.so");
74+
#endif
75+
*(void **)&libze_ops.zeInit = util_get_symbol_addr(zeDlHandle, "zeInit");
7276
ASSERT_NE(libze_ops.zeInit, nullptr);
73-
*(void **)&libze_ops.zeDriverGet = dlsym(zeDlHandle, "zeDriverGet");
77+
*(void **)&libze_ops.zeDriverGet = util_get_symbol_addr(zeDlHandle, "zeDriverGet");
7478
ASSERT_NE(libze_ops.zeDriverGet, nullptr);
75-
*(void **)&libze_ops.zeDeviceGet = dlsym(zeDlHandle, "zeDeviceGet");
79+
*(void **)&libze_ops.zeDeviceGet = util_get_symbol_addr(zeDlHandle, "zeDeviceGet");
7680
ASSERT_NE(libze_ops.zeDeviceGet, nullptr);
7781
*(void **)&libze_ops.zeDeviceGetProperties =
78-
dlsym(zeDlHandle, "zeDeviceGetProperties");
82+
util_get_symbol_addr(zeDlHandle, "zeDeviceGetProperties");
7983
ASSERT_NE(libze_ops.zeDeviceGetProperties, nullptr);
8084
*(void **)&libze_ops.zeContextCreate =
81-
dlsym(zeDlHandle, "zeContextCreate");
85+
util_get_symbol_addr(zeDlHandle, "zeContextCreate");
8286
ASSERT_NE(libze_ops.zeContextCreate, nullptr);
8387
*(void **)&libze_ops.zeContextDestroy =
84-
dlsym(zeDlHandle, "zeContextDestroy");
88+
util_get_symbol_addr(zeDlHandle, "zeContextDestroy");
8589
ASSERT_NE(libze_ops.zeContextDestroy, nullptr);
8690
*(void **)&libze_ops.zeCommandQueueCreate =
87-
dlsym(zeDlHandle, "zeCommandQueueCreate");
91+
util_get_symbol_addr(zeDlHandle, "zeCommandQueueCreate");
8892
ASSERT_NE(libze_ops.zeCommandQueueCreate, nullptr);
8993
*(void **)&libze_ops.zeCommandQueueDestroy =
90-
dlsym(zeDlHandle, "zeCommandQueueDestroy");
94+
util_get_symbol_addr(zeDlHandle, "zeCommandQueueDestroy");
9195
ASSERT_NE(libze_ops.zeCommandQueueDestroy, nullptr);
9296
*(void **)&libze_ops.zeCommandQueueExecuteCommandLists =
93-
dlsym(zeDlHandle, "zeCommandQueueExecuteCommandLists");
97+
util_get_symbol_addr(zeDlHandle, "zeCommandQueueExecuteCommandLists");
9498
ASSERT_NE(libze_ops.zeCommandQueueExecuteCommandLists, nullptr);
9599
*(void **)&libze_ops.zeCommandQueueSynchronize =
96-
dlsym(zeDlHandle, "zeCommandQueueSynchronize");
100+
util_get_symbol_addr(zeDlHandle, "zeCommandQueueSynchronize");
97101
ASSERT_NE(libze_ops.zeCommandQueueSynchronize, nullptr);
98102
*(void **)&libze_ops.zeCommandListCreate =
99-
dlsym(zeDlHandle, "zeCommandListCreate");
103+
util_get_symbol_addr(zeDlHandle, "zeCommandListCreate");
100104
ASSERT_NE(libze_ops.zeCommandListCreate, nullptr);
101105
*(void **)&libze_ops.zeCommandListDestroy =
102-
dlsym(zeDlHandle, "zeCommandListDestroy");
106+
util_get_symbol_addr(zeDlHandle, "zeCommandListDestroy");
103107
ASSERT_NE(libze_ops.zeCommandListDestroy, nullptr);
104108
*(void **)&libze_ops.zeCommandListClose =
105-
dlsym(zeDlHandle, "zeCommandListClose");
109+
util_get_symbol_addr(zeDlHandle, "zeCommandListClose");
106110
ASSERT_NE(libze_ops.zeCommandListClose, nullptr);
107111
*(void **)&libze_ops.zeCommandListAppendMemoryCopy =
108-
dlsym(zeDlHandle, "zeCommandListAppendMemoryCopy");
112+
util_get_symbol_addr(zeDlHandle, "zeCommandListAppendMemoryCopy");
109113
ASSERT_NE(libze_ops.zeCommandListAppendMemoryCopy, nullptr);
110114
*(void **)&libze_ops.zeCommandListAppendMemoryFill =
111-
dlsym(zeDlHandle, "zeCommandListAppendMemoryFill");
115+
util_get_symbol_addr(zeDlHandle, "zeCommandListAppendMemoryFill");
112116
ASSERT_NE(libze_ops.zeCommandListAppendMemoryFill, nullptr);
113117
*(void **)&libze_ops.zeMemGetAllocProperties =
114-
dlsym(zeDlHandle, "zeMemGetAllocProperties");
118+
util_get_symbol_addr(zeDlHandle, "zeMemGetAllocProperties");
115119
ASSERT_NE(libze_ops.zeMemGetAllocProperties, nullptr);
116120
*(void **)&libze_ops.zeMemAllocDevice =
117-
dlsym(zeDlHandle, "zeMemAllocDevice");
121+
util_get_symbol_addr(zeDlHandle, "zeMemAllocDevice");
118122
ASSERT_NE(libze_ops.zeMemAllocDevice, nullptr);
119-
*(void **)&libze_ops.zeMemFree = dlsym(zeDlHandle, "zeMemFree");
123+
*(void **)&libze_ops.zeMemFree = util_get_symbol_addr(zeDlHandle, "zeMemFree");
120124
ASSERT_NE(libze_ops.zeMemFree, nullptr);
121125
}
122126

123127
void DestroyLevelZeroOps() {
124128
// Just close the handle here
125-
dlclose(zeDlHandle);
129+
util_close_library(zeDlHandle);
126130
}
127131
#else // USE_DLOPEN
128132
void InitLevelZeroOps() {

0 commit comments

Comments
 (0)