Skip to content

Commit 7a91ede

Browse files
committed
Refactor platform discovery function
Merge different implemetations of the discoverEnabledPlatforms() functions. Use ur_getenv() util function as a common getter of the environment variable for linux and Windows.
1 parent fe66f55 commit 7a91ede

File tree

4 files changed

+53
-95
lines changed

4 files changed

+53
-95
lines changed

source/loader/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ target_sources(loader
7979
${CMAKE_CURRENT_SOURCE_DIR}/ur_libddi.cpp
8080
${CMAKE_CURRENT_SOURCE_DIR}/ur_lib.hpp
8181
${CMAKE_CURRENT_SOURCE_DIR}/ur_lib.cpp
82+
${CMAKE_CURRENT_SOURCE_DIR}/platform_discovery.cpp
8283
${CMAKE_CURRENT_SOURCE_DIR}/layers/validation/ur_valddi.cpp
8384
${CMAKE_CURRENT_SOURCE_DIR}/layers/validation/ur_validation_layer.cpp
8485
)
@@ -95,14 +96,12 @@ if(WIN32)
9596
target_sources(loader
9697
PRIVATE
9798
${CMAKE_CURRENT_SOURCE_DIR}/windows/lib_init.cpp
98-
${CMAKE_CURRENT_SOURCE_DIR}/windows/platform_discovery_win.cpp
9999
${CMAKE_CURRENT_SOURCE_DIR}/windows/loader_init.cpp
100100
)
101101
else()
102102
target_sources(loader
103103
PRIVATE
104104
${CMAKE_CURRENT_SOURCE_DIR}/linux/lib_init.cpp
105-
${CMAKE_CURRENT_SOURCE_DIR}/linux/platform_discovery_lin.cpp
106105
${CMAKE_CURRENT_SOURCE_DIR}/linux/loader_init.cpp
107106
)
108107
endif()

source/loader/linux/platform_discovery_lin.cpp

Lines changed: 0 additions & 43 deletions
This file was deleted.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
*
3+
* Copyright (C) 2022-2023 Intel Corporation
4+
*
5+
* SPDX-License-Identifier: MIT
6+
*
7+
*/
8+
9+
#include "platform_discovery.hpp"
10+
#include "ur_util.hpp"
11+
12+
#include <array>
13+
14+
namespace loader {
15+
16+
static constexpr std::array<const char *, 1> knownPlatformNames{
17+
MAKE_LIBRARY_NAME("ur_adapter_level_zero", "0")};
18+
19+
static auto getKnownPlatforms() {
20+
std::vector<PlatformLibraryPath> enabledPlatforms;
21+
22+
for (auto path : knownPlatformNames) {
23+
enabledPlatforms.emplace_back(path);
24+
}
25+
return enabledPlatforms;
26+
}
27+
28+
std::vector<PlatformLibraryPath> discoverEnabledPlatforms() {
29+
std::optional<std::string> altPlatforms;
30+
31+
// UR_ADAPTERS_FORCE_LOAD is for development/debug only
32+
try {
33+
altPlatforms = ur_getenv("UR_ADAPTERS_FORCE_LOAD");
34+
} catch (const std::invalid_argument &e) {
35+
std::cerr << e.what();
36+
return getKnownPlatforms();
37+
}
38+
if (!altPlatforms) {
39+
return getKnownPlatforms();
40+
}
41+
42+
std::vector<PlatformLibraryPath> enabledPlatforms;
43+
std::stringstream ss(*altPlatforms);
44+
while (ss.good()) {
45+
std::string substr;
46+
getline(ss, substr, ',');
47+
enabledPlatforms.emplace_back(substr);
48+
}
49+
return enabledPlatforms;
50+
}
51+
52+
} // namespace loader

source/loader/windows/platform_discovery_win.cpp

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)