Skip to content

[SYCL][UR] Add support ur_loader #8423

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

Closed
wants to merge 2 commits into from
Closed
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
1 change: 1 addition & 0 deletions sycl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ set( SYCL_TOOLCHAIN_DEPLOY_COMPONENTS
sycl
libsycldevice
level-zero-sycl-dev
unified-runtime-sycl-dev
${XPTIFW_LIBS}
${SYCL_TOOLCHAIN_DEPS}
)
Expand Down
8 changes: 4 additions & 4 deletions sycl/plugins/level_zero/pi_level_zero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ pi_result _pi_context::initialize() {
// Prefer to use copy engine for initialization copies,
// if available and allowed (main copy engine with index 0).
ZeStruct<ze_command_queue_desc_t> ZeCommandQueueDesc;
const auto &Range = getRangeOfAllowedCopyEngines((zer_device_handle_t)Device);
const auto &Range = getRangeOfAllowedCopyEngines((ur_device_handle_t)Device);
ZeCommandQueueDesc.ordinal =
Device->QueueGroup[_pi_device::queue_group_info_t::Compute].ZeOrdinal;
if (Range.first >= 0 &&
Expand Down Expand Up @@ -932,7 +932,7 @@ _pi_queue::_pi_queue(std::vector<ze_command_queue_handle_t> &ComputeQueues,

// Copy group initialization.
pi_queue_group_t CopyQueueGroup{this, queue_type::MainCopy};
const auto &Range = getRangeOfAllowedCopyEngines((zer_device_handle_t)Device);
const auto &Range = getRangeOfAllowedCopyEngines((ur_device_handle_t)Device);
if (Range.first < 0 || Range.second < 0) {
// We are asked not to use copy engines, just do nothing.
// Leave CopyQueueGroup.ZeQueues empty, and it won't be used.
Expand Down Expand Up @@ -7801,7 +7801,7 @@ pi_result piextEnqueueDeviceGlobalVariableWrite(
(Program->ZeModule, Name, &GlobalVarSize, &GlobalVarPtr));
if (GlobalVarSize < Offset + Count) {
setErrorMessage("Write device global variable is out of range.",
ZER_RESULT_INVALID_VALUE);
UR_RESULT_ERROR_INVALID_VALUE);
return PI_ERROR_PLUGIN_SPECIFIC_ERROR;
}

Expand Down Expand Up @@ -7846,7 +7846,7 @@ pi_result piextEnqueueDeviceGlobalVariableRead(
(Program->ZeModule, Name, &GlobalVarSize, &GlobalVarPtr));
if (GlobalVarSize < Offset + Count) {
setErrorMessage("Read from device global variable is out of range.",
ZER_RESULT_INVALID_VALUE);
UR_RESULT_ERROR_INVALID_VALUE);
return PI_ERROR_PLUGIN_SPECIFIC_ERROR;
}

Expand Down
6 changes: 3 additions & 3 deletions sycl/plugins/level_zero/ur_bindings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
#pragma once

#include "pi_level_zero.hpp"
#include <zer_api.h>
#include <ur_api.h>

// Make the Unified Runtime handles definition complete.
// This is used in various "create" API where new handles are allocated.
struct _zer_platform_handle_t : public _pi_platform {
struct ur_platform_handle_t_ : public _pi_platform {
using _pi_platform::_pi_platform;
};

struct _zer_device_handle_t : public _pi_device {
struct ur_device_handle_t_ : public _pi_device {
using _pi_device::_pi_device;
};
61 changes: 57 additions & 4 deletions sycl/plugins/unified_runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,66 @@
# PI Unified Runtime plugin library
#
if (NOT DEFINED UNIFIED_RUNTIME_INCLUDE_DIR)
if (NOT DEFINED UNIFIED_RUNTIME_LIBRARY OR NOT DEFINED UNIFIED_RUNTIME_INCLUDE_DIR)
include(FetchContent)

set(UNIFIED_RUNTIME_REPO "https://github.com/oneapi-src/unified-runtime.git")
set(UNIFIED_RUNTIME_TAG fd711c920acc4434cb52ff18b078c082d9d7f44d)
set(UNIFIED_RUNTIME_TAG 61cb864b3a73918124bff11f9ad58dafb8c7769a)

message(STATUS "Will fetch Unified Runtime from ${UNIFIED_RUNTIME_REPO}")
FetchContent_Declare(unified-runtime
GIT_REPOSITORY ${UNIFIED_RUNTIME_REPO}
GIT_TAG ${UNIFIED_RUNTIME_TAG}
)

FetchContent_MakeAvailable(unified-runtime)
# Disable some compilation options to avoid errors while building the UR
if (UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-but-set-variable")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-pedantic")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-stringop-truncation")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-suggest-override")
endif()

FetchContent_GetProperties(unified-runtime)
FetchContent_MakeAvailable(unified-runtime)

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

set(UNIFIED_RUNTIME_LIBRARY ${PROJECT_NAME}::ur_loader)

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

add_library (UnifiedRuntimeLoader INTERFACE)
get_filename_component(UNIFIED_RUNTIME_LIBRARY_SRC "${UNIFIED_RUNTIME_LOADER_SOURCE_DIR}" DIRECTORY)
get_filename_component(UNIFIED_RUNTIME_LIB_NAME "${UNIFIED_RUNTIME_LIBRARY}" NAME)

message(STATUS "UNIFIED_RUNTIME_LIB_NAME ${UNIFIED_RUNTIME_LIB_NAME}")

add_library (UnifiedRuntime-Headers INTERFACE)
add_library (UnifiedRuntimeLoader-Headers INTERFACE)

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

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

target_include_directories(UnifiedRuntimeLoader
INTERFACE "${UNIFIED_RUNTIME_INCLUDE_DIR}"
)

target_link_libraries(UnifiedRuntimeLoader
INTERFACE "${UNIFIED_RUNTIME_LIB_NAME}"
)

find_package(Threads REQUIRED)

#
Expand All @@ -52,9 +87,27 @@ add_sycl_plugin(unified_runtime
# These below belong to Unified Runtime PI Plugin only
"pi_unified_runtime.hpp"
"pi_unified_runtime.cpp"
LIBRARIES
LIBRARIES
Threads::Threads
UnifiedRuntime-Headers
UnifiedRuntimeLoader-Headers
UnifiedRuntimeLoader
LevelZeroLoader-Headers
LevelZeroLoader
)

if (TARGET ${PROJECT_NAME}::ur_loader)
set_target_properties(hello_world PROPERTIES EXCLUDE_FROM_ALL 1 EXCLUDE_FROM_DEFAULT_BUILD 1)
set_target_properties(ur_null PROPERTIES EXCLUDE_FROM_ALL 1 EXCLUDE_FROM_DEFAULT_BUILD 1)
install(TARGETS loader
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT unified-runtime-sycl-dev
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT unified-runtime-sycl-dev
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT unified-runtime-sycl-dev
)
file(GLOB UNIFIED_RUNTIME_API_HEADERS "${UNIFIED_RUNTIME_INCLUDE_DIR}/*.h")
install(FILES ${UNIFIED_RUNTIME_API_HEADERS}
DESTINATION ${CMAKE_INSTALL_PREFIX}/include/sycl/unified_runtime/
COMPONENT unified-runtime-sycl-dev
)
endif()

Loading