Skip to content

Commit a0d0942

Browse files
authored
[SYCL][UR] Link UR PI against UR Loader (#8637)
Compile UR L0 adapter as a standalone library Signed-off-by: Brandon Yates <[email protected]>
1 parent 25d0475 commit a0d0942

File tree

5 files changed

+329
-24
lines changed

5 files changed

+329
-24
lines changed

sycl/plugins/unified_runtime/CMakeLists.txt

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ if (NOT DEFINED UNIFIED_RUNTIME_LIBRARY OR NOT DEFINED UNIFIED_RUNTIME_INCLUDE_D
44
include(FetchContent)
55

66
set(UNIFIED_RUNTIME_REPO "https://github.com/oneapi-src/unified-runtime.git")
7-
set(UNIFIED_RUNTIME_TAG 6fb8e2620f1474428a539ef46d6dd47043c7d59b)
7+
set(UNIFIED_RUNTIME_TAG d6af758779db6eebdc419fd5e249302f566eb5de)
88

99
message(STATUS "Will fetch Unified Runtime from ${UNIFIED_RUNTIME_REPO}")
1010
FetchContent_Declare(unified-runtime
@@ -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,19 @@ 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+
LIBRARIES
103109
UnifiedRuntime-Headers
104110
LevelZeroLoader-Headers
105111
LevelZeroLoader
106112
)
107113

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

sycl/plugins/unified_runtime/pi2ur.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static pi_result ur2piResult(ur_result_t urResult) {
2929
{UR_RESULT_ERROR_INVALID_FUNCTION_NAME, PI_ERROR_BUILD_PROGRAM_FAILURE},
3030
{UR_RESULT_ERROR_INVALID_WORK_GROUP_SIZE,
3131
PI_ERROR_INVALID_WORK_GROUP_SIZE},
32-
{UR_RESULT_ERROR_MODULE_BUILD_FAILURE, PI_ERROR_BUILD_PROGRAM_FAILURE},
32+
{UR_RESULT_ERROR_PROGRAM_BUILD_FAILURE, PI_ERROR_BUILD_PROGRAM_FAILURE},
3333
{UR_RESULT_ERROR_OUT_OF_DEVICE_MEMORY, PI_ERROR_OUT_OF_RESOURCES},
3434
{UR_RESULT_ERROR_OUT_OF_HOST_MEMORY, PI_ERROR_OUT_OF_HOST_MEMORY}};
3535

@@ -252,6 +252,7 @@ namespace pi2ur {
252252
inline pi_result piPlatformsGet(pi_uint32 num_entries, pi_platform *platforms,
253253
pi_uint32 *num_platforms) {
254254

255+
urInit(0);
255256
uint32_t Count = num_entries;
256257
auto phPlatforms = reinterpret_cast<ur_platform_handle_t *>(platforms);
257258
HANDLE_ERRORS(urPlatformGet(Count, phPlatforms, num_platforms));

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ ur_result_t _ur_platform_handle_t::initialize() {
286286
return UR_RESULT_SUCCESS;
287287
}
288288

289-
UR_APIEXPORT ur_result_t UR_APICALL urPlatformGet(
289+
ur_result_t urPlatformGet(
290290
uint32_t NumEntries, ///< [in] the number of platforms to be added to
291291
///< phPlatforms. If phPlatforms is not NULL, then
292292
///< NumEntries should be greater than zero, otherwise
@@ -403,7 +403,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urPlatformGet(
403403
return UR_RESULT_SUCCESS;
404404
}
405405

406-
UR_APIEXPORT ur_result_t UR_APICALL urPlatformGetInfo(
406+
ur_result_t urPlatformGetInfo(
407407
ur_platform_handle_t Platform, ///< [in] handle of the platform
408408
ur_platform_info_t ParamName, ///< [in] type of the info to retrieve
409409
size_t Size, ///< [in] the number of bytes pointed to by pPlatformInfo.
@@ -457,7 +457,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urPlatformGetInfo(
457457
return UR_RESULT_SUCCESS;
458458
}
459459

460-
UR_APIEXPORT ur_result_t UR_APICALL urDeviceGet(
460+
ur_result_t urDeviceGet(
461461
ur_platform_handle_t Platform, ///< [in] handle of the platform instance
462462
ur_device_type_t DeviceType, ///< [in] the type of the devices.
463463
uint32_t NumEntries, ///< [in] the number of devices to be added to
@@ -534,7 +534,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGet(
534534
return UR_RESULT_SUCCESS;
535535
}
536536

537-
UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(
537+
ur_result_t urDeviceGetInfo(
538538
ur_device_handle_t Device, ///< [in] handle of the device instance
539539
ur_device_info_t ParamName, ///< [in] type of the info to retrieve
540540
size_t propSize, ///< [in] the number of bytes pointed to by pDeviceInfo.
@@ -1660,7 +1660,7 @@ void ZeUSMImportExtension::doZeUSMRelease(ze_driver_handle_t DriverHandle,
16601660
ZE_CALL_NOCHECK(zexDriverReleaseImportedPointer, (DriverHandle, HostPtr));
16611661
}
16621662

1663-
UR_APIEXPORT ur_result_t UR_APICALL urDevicePartition(
1663+
ur_result_t urDevicePartition(
16641664
ur_device_handle_t Device, ///< [in] handle of the device to partition.
16651665
const ur_device_partition_property_t
16661666
*Properties, ///< [in] null-terminated array of <$_device_partition_t
@@ -1741,3 +1741,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDevicePartition(
17411741
}
17421742
return UR_RESULT_SUCCESS;
17431743
}
1744+
1745+
ur_result_t urInit(ur_device_init_flags_t device_flags) {
1746+
return UR_RESULT_SUCCESS;
1747+
}
1748+
1749+
ur_result_t urTearDown(void *pParams) { return UR_RESULT_SUCCESS; }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ std::unordered_map<ze_result_t, ur_result_t> Ze2UrErrorMapping = {
3333
{ZE_RESULT_ERROR_INVALID_GROUP_SIZE_DIMENSION,
3434
UR_RESULT_ERROR_INVALID_WORK_GROUP_SIZE},
3535
{ZE_RESULT_ERROR_MODULE_BUILD_FAILURE,
36-
UR_RESULT_ERROR_MODULE_BUILD_FAILURE},
36+
UR_RESULT_ERROR_PROGRAM_BUILD_FAILURE},
3737
{ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY,
3838
UR_RESULT_ERROR_OUT_OF_DEVICE_MEMORY},
3939
{ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY, UR_RESULT_ERROR_OUT_OF_HOST_MEMORY}};

0 commit comments

Comments
 (0)