Skip to content

[SYCL][UR] Link UR PI against UR Loader #8637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 29 additions & 17 deletions sycl/plugins/unified_runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ if (NOT DEFINED UNIFIED_RUNTIME_LIBRARY OR NOT DEFINED UNIFIED_RUNTIME_INCLUDE_D
include(FetchContent)

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

message(STATUS "Will fetch Unified Runtime from ${UNIFIED_RUNTIME_REPO}")
FetchContent_Declare(unified-runtime
Expand Down Expand Up @@ -37,28 +37,23 @@ if (NOT DEFINED UNIFIED_RUNTIME_LIBRARY OR NOT DEFINED UNIFIED_RUNTIME_INCLUDE_D
# Restore original flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_BAK}")

add_library(${PROJECT_NAME}::ur_loader ALIAS loader)

set(UNIFIED_RUNTIME_LIBRARY ${PROJECT_NAME}::ur_loader)
add_library(UnifiedRuntimeLoader ALIAS loader)

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


add_library (UnifiedRuntime-Headers INTERFACE)

target_include_directories(UnifiedRuntime-Headers
INTERFACE
"${UNIFIED_RUNTIME_INCLUDE_DIR}"
)

find_package(Threads REQUIRED)

#
# NOTE: the Unified Runtime doesn't have the loader [yet].
# So what we really build is the Unified Runtime with Level Zero Adapter
# together.
#
add_sycl_plugin(unified_runtime
SOURCES
# These are short-term shared with Unified Runtime
Expand All @@ -69,9 +64,25 @@ add_sycl_plugin(unified_runtime
"ur_bindings.hpp"
"pi2ur.hpp"
"pi2ur.cpp"
# These below belong to Unified Runtime PI Plugin only
"pi_unified_runtime.hpp"
"pi_unified_runtime.cpp"
LIBRARIES
Threads::Threads
UnifiedRuntimeLoader
UnifiedRuntime-Headers
)

# Build level zero adapter
add_sycl_library("ur_adapter_level_zero" SHARED
SOURCES
"ur/ur.hpp"
"ur/ur.cpp"
"ur/usm_allocator.hpp"
"ur/usm_allocator.cpp"
"ur/adapters/level_zero/ur_level_zero.hpp"
"ur/adapters/level_zero/ur_level_zero.cpp"
"ur/adapters/level_zero/ur_loader_interface.cpp"
"ur/adapters/level_zero/ur_level_zero_common.hpp"
"ur/adapters/level_zero/ur_level_zero_context.hpp"
"ur/adapters/level_zero/ur_level_zero_device.hpp"
Expand All @@ -93,18 +104,19 @@ add_sycl_plugin(unified_runtime
"ur/adapters/level_zero/ur_level_zero_program.cpp"
"ur/adapters/level_zero/ur_level_zero_queue.cpp"
"ur/adapters/level_zero/ur_level_zero_sampler.cpp"
"ur/usm_allocator.hpp"
"ur/usm_allocator.cpp"
# These below belong to Unified Runtime PI Plugin only
"pi_unified_runtime.hpp"
"pi_unified_runtime.cpp"
LIBRARIES
Threads::Threads
INCLUDE_DIRS
LIBRARIES
UnifiedRuntime-Headers
LevelZeroLoader-Headers
LevelZeroLoader
)

if (TARGET ${PROJECT_NAME}::ur_loader)
set_target_properties("ur_adapter_level_zero" PROPERTIES
VERSION "0.0.0"
SOVERSION "0"
)


if (TARGET UnifiedRuntimeLoader)
set_target_properties(hello_world PROPERTIES EXCLUDE_FROM_ALL 1 EXCLUDE_FROM_DEFAULT_BUILD 1)
endif()
3 changes: 2 additions & 1 deletion sycl/plugins/unified_runtime/pi2ur.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static pi_result ur2piResult(ur_result_t urResult) {
{UR_RESULT_ERROR_INVALID_FUNCTION_NAME, PI_ERROR_BUILD_PROGRAM_FAILURE},
{UR_RESULT_ERROR_INVALID_WORK_GROUP_SIZE,
PI_ERROR_INVALID_WORK_GROUP_SIZE},
{UR_RESULT_ERROR_MODULE_BUILD_FAILURE, PI_ERROR_BUILD_PROGRAM_FAILURE},
{UR_RESULT_ERROR_PROGRAM_BUILD_FAILURE, PI_ERROR_BUILD_PROGRAM_FAILURE},
{UR_RESULT_ERROR_OUT_OF_DEVICE_MEMORY, PI_ERROR_OUT_OF_RESOURCES},
{UR_RESULT_ERROR_OUT_OF_HOST_MEMORY, PI_ERROR_OUT_OF_HOST_MEMORY}};

Expand Down Expand Up @@ -252,6 +252,7 @@ namespace pi2ur {
inline pi_result piPlatformsGet(pi_uint32 num_entries, pi_platform *platforms,
pi_uint32 *num_platforms) {

urInit(0);
uint32_t Count = num_entries;
auto phPlatforms = reinterpret_cast<ur_platform_handle_t *>(platforms);
HANDLE_ERRORS(urPlatformGet(Count, phPlatforms, num_platforms));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ ur_result_t _ur_platform_handle_t::initialize() {
return UR_RESULT_SUCCESS;
}

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

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

UR_APIEXPORT ur_result_t UR_APICALL urDeviceGet(
ur_result_t urDeviceGet(
ur_platform_handle_t Platform, ///< [in] handle of the platform instance
ur_device_type_t DeviceType, ///< [in] the type of the devices.
uint32_t NumEntries, ///< [in] the number of devices to be added to
Expand Down Expand Up @@ -534,7 +534,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGet(
return UR_RESULT_SUCCESS;
}

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

UR_APIEXPORT ur_result_t UR_APICALL urDevicePartition(
ur_result_t urDevicePartition(
ur_device_handle_t Device, ///< [in] handle of the device to partition.
const ur_device_partition_property_t
*Properties, ///< [in] null-terminated array of <$_device_partition_t
Expand Down Expand Up @@ -1706,7 +1706,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDevicePartition(
// Currently supported partitioning (by affinity domain/numa) would always
// partition to all sub-devices.
//
if (NumDevices !=0)
if (NumDevices != 0)
PI_ASSERT(NumDevices == EffectiveNumDevices, UR_RESULT_ERROR_INVALID_VALUE);

for (uint32_t I = 0; I < NumDevices; I++) {
Expand All @@ -1720,3 +1720,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDevicePartition(
}
return UR_RESULT_SUCCESS;
}

ur_result_t urInit(ur_device_init_flags_t device_flags) {
return UR_RESULT_SUCCESS;
}

ur_result_t urTearDown(void *pParams) { return UR_RESULT_SUCCESS; }
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ std::unordered_map<ze_result_t, ur_result_t> Ze2UrErrorMapping = {
{ZE_RESULT_ERROR_INVALID_GROUP_SIZE_DIMENSION,
UR_RESULT_ERROR_INVALID_WORK_GROUP_SIZE},
{ZE_RESULT_ERROR_MODULE_BUILD_FAILURE,
UR_RESULT_ERROR_MODULE_BUILD_FAILURE},
UR_RESULT_ERROR_PROGRAM_BUILD_FAILURE},
{ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY,
UR_RESULT_ERROR_OUT_OF_DEVICE_MEMORY},
{ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY, UR_RESULT_ERROR_OUT_OF_HOST_MEMORY}};
Expand Down
Loading