Skip to content

Commit 5645c88

Browse files
authored
[SYCL][UR] Link UR PI against UR Loader (#8865)
Compile UR L0 adapter as a standalone library Signed-off-by: Brandon Yates <[email protected]>
1 parent 8a49660 commit 5645c88

File tree

4 files changed

+330
-21
lines changed

4 files changed

+330
-21
lines changed

sycl/plugins/unified_runtime/CMakeLists.txt

+30-16
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,23 @@ if (NOT DEFINED UNIFIED_RUNTIME_LIBRARY OR NOT DEFINED UNIFIED_RUNTIME_INCLUDE_D
3737
# Restore original flags
3838
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_BAK}")
3939

40-
add_library(${PROJECT_NAME}::ur_loader ALIAS loader)
41-
42-
set(UNIFIED_RUNTIME_LIBRARY ${PROJECT_NAME}::ur_loader)
40+
add_library(UnifiedRuntimeLoader ALIAS loader)
4341

4442
set(UNIFIED_RUNTIME_SOURCE_DIR
4543
${unified-runtime_SOURCE_DIR} CACHE PATH "Path to Unified Runtime Headers")
4644
set(UNIFIED_RUNTIME_INCLUDE_DIR "${UNIFIED_RUNTIME_SOURCE_DIR}/include")
4745
endif()
4846

47+
4948
add_library (UnifiedRuntime-Headers INTERFACE)
49+
5050
target_include_directories(UnifiedRuntime-Headers
5151
INTERFACE
5252
"${UNIFIED_RUNTIME_INCLUDE_DIR}"
5353
)
5454

5555
find_package(Threads REQUIRED)
5656

57-
#
58-
# NOTE: the Unified Runtime doesn't have the loader [yet].
59-
# So what we really build is the Unified Runtime with Level Zero Adapter
60-
# together.
61-
#
6257
add_sycl_plugin(unified_runtime
6358
SOURCES
6459
# These are short-term shared with Unified Runtime
@@ -69,9 +64,25 @@ add_sycl_plugin(unified_runtime
6964
"ur_bindings.hpp"
7065
"pi2ur.hpp"
7166
"pi2ur.cpp"
67+
# These below belong to Unified Runtime PI Plugin only
68+
"pi_unified_runtime.hpp"
69+
"pi_unified_runtime.cpp"
70+
LIBRARIES
71+
Threads::Threads
72+
UnifiedRuntimeLoader
73+
UnifiedRuntime-Headers
74+
)
75+
76+
# Build level zero adapter
77+
add_sycl_library("ur_adapter_level_zero" SHARED
78+
SOURCES
7279
"ur/ur.hpp"
7380
"ur/ur.cpp"
81+
"ur/usm_allocator.hpp"
82+
"ur/usm_allocator.cpp"
7483
"ur/adapters/level_zero/ur_level_zero.hpp"
84+
"ur/adapters/level_zero/ur_level_zero.cpp"
85+
"ur/adapters/level_zero/ur_loader_interface.cpp"
7586
"ur/adapters/level_zero/ur_level_zero_common.hpp"
7687
"ur/adapters/level_zero/ur_level_zero_context.hpp"
7788
"ur/adapters/level_zero/ur_level_zero_device.hpp"
@@ -93,18 +104,21 @@ add_sycl_plugin(unified_runtime
93104
"ur/adapters/level_zero/ur_level_zero_program.cpp"
94105
"ur/adapters/level_zero/ur_level_zero_queue.cpp"
95106
"ur/adapters/level_zero/ur_level_zero_sampler.cpp"
96-
"ur/usm_allocator.hpp"
97-
"ur/usm_allocator.cpp"
98-
# These below belong to Unified Runtime PI Plugin only
99-
"pi_unified_runtime.hpp"
100-
"pi_unified_runtime.cpp"
101-
LIBRARIES
102-
Threads::Threads
107+
INCLUDE_DIRS
108+
${sycl_inc_dir}
109+
LIBRARIES
103110
UnifiedRuntime-Headers
104111
LevelZeroLoader-Headers
105112
LevelZeroLoader
113+
Threads::Threads
106114
)
107115

108-
if (TARGET ${PROJECT_NAME}::ur_loader)
116+
set_target_properties("ur_adapter_level_zero" PROPERTIES
117+
VERSION "0.0.0"
118+
SOVERSION "0"
119+
)
120+
121+
122+
if (TARGET UnifiedRuntimeLoader)
109123
set_target_properties(hello_world PROPERTIES EXCLUDE_FROM_ALL 1 EXCLUDE_FROM_DEFAULT_BUILD 1)
110124
endif()

sycl/plugins/unified_runtime/pi2ur.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ namespace pi2ur {
279279
inline pi_result piPlatformsGet(pi_uint32 num_entries, pi_platform *platforms,
280280
pi_uint32 *num_platforms) {
281281

282+
urInit(0);
282283
uint32_t Count = num_entries;
283284
auto phPlatforms = reinterpret_cast<ur_platform_handle_t *>(platforms);
284285
HANDLE_ERRORS(urPlatformGet(Count, phPlatforms, num_platforms));

sycl/plugins/unified_runtime/ur/adapters/level_zero/ur_level_zero.cpp

+13-5
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ ur_result_t _ur_platform_handle_t::initialize() {
8484
return UR_RESULT_SUCCESS;
8585
}
8686

87-
UR_APIEXPORT ur_result_t UR_APICALL urPlatformGet(
87+
ur_result_t urPlatformGet(
8888
uint32_t NumEntries, ///< [in] the number of platforms to be added to
8989
///< phPlatforms. If phPlatforms is not NULL, then
9090
///< NumEntries should be greater than zero, otherwise
@@ -201,7 +201,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urPlatformGet(
201201
return UR_RESULT_SUCCESS;
202202
}
203203

204-
UR_APIEXPORT ur_result_t UR_APICALL urPlatformGetInfo(
204+
ur_result_t urPlatformGetInfo(
205205
ur_platform_handle_t Platform, ///< [in] handle of the platform
206206
ur_platform_info_t ParamName, ///< [in] type of the info to retrieve
207207
size_t Size, ///< [in] the number of bytes pointed to by pPlatformInfo.
@@ -255,7 +255,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urPlatformGetInfo(
255255
return UR_RESULT_SUCCESS;
256256
}
257257

258-
UR_APIEXPORT ur_result_t UR_APICALL urDeviceGet(
258+
ur_result_t urDeviceGet(
259259
ur_platform_handle_t Platform, ///< [in] handle of the platform instance
260260
ur_device_type_t DeviceType, ///< [in] the type of the devices.
261261
uint32_t NumEntries, ///< [in] the number of devices to be added to
@@ -332,7 +332,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGet(
332332
return UR_RESULT_SUCCESS;
333333
}
334334

335-
UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(
335+
ur_result_t urDeviceGetInfo(
336336
ur_device_handle_t Device, ///< [in] handle of the device instance
337337
ur_device_info_t ParamName, ///< [in] type of the info to retrieve
338338
size_t propSize, ///< [in] the number of bytes pointed to by pDeviceInfo.
@@ -1482,7 +1482,7 @@ void ZeUSMImportExtension::doZeUSMRelease(ze_driver_handle_t DriverHandle,
14821482
ZE_CALL_NOCHECK(zexDriverReleaseImportedPointer, (DriverHandle, HostPtr));
14831483
}
14841484

1485-
UR_APIEXPORT ur_result_t UR_APICALL urDevicePartition(
1485+
ur_result_t urDevicePartition(
14861486
ur_device_handle_t Device, ///< [in] handle of the device to partition.
14871487
const ur_device_partition_property_t
14881488
*Properties, ///< [in] null-terminated array of <$_device_partition_t
@@ -1563,3 +1563,11 @@ UR_APIEXPORT ur_result_t UR_APICALL urDevicePartition(
15631563
}
15641564
return UR_RESULT_SUCCESS;
15651565
}
1566+
1567+
ur_result_t urInit([[maybe_unused]] ur_device_init_flags_t device_flags) {
1568+
return UR_RESULT_SUCCESS;
1569+
}
1570+
1571+
ur_result_t urTearDown([[maybe_unused]] void *pParams) {
1572+
return UR_RESULT_SUCCESS;
1573+
}

0 commit comments

Comments
 (0)