Skip to content

[SYCL] Inegrate pi_unified_runtime with UR loader #7755

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 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e564a89
update build system to add pi_unified_runtime
smaslov-intel Nov 23, 2022
0277188
[SYCL] Next redesign step
Nov 28, 2022
461327b
Few build fixes
Nov 30, 2022
d3f344a
move more stuff and build true pi_unified_runtime plugin
smaslov-intel Dec 2, 2022
b83e9b2
repair incorrect merge
smaslov-intel Dec 2, 2022
216b48e
Fix remaining build issues
Dec 2, 2022
58a7883
Makefiles cleanup
Dec 2, 2022
f5e4d15
further re-org
smaslov-intel Dec 6, 2022
6f4eae7
clang-format
smaslov-intel Dec 6, 2022
aebe943
suppress warnign for L0 build
smaslov-intel Dec 6, 2022
ede937c
disable some warnings
smaslov-intel Dec 6, 2022
8584031
spell
smaslov-intel Dec 6, 2022
c2ca1ae
more warnings
smaslov-intel Dec 6, 2022
9217bd4
more warnings
smaslov-intel Dec 6, 2022
d9ce270
update l0 includes
smaslov-intel Dec 6, 2022
d7c0a33
add L0 includes
smaslov-intel Dec 6, 2022
c3985bc
chmod
smaslov-intel Dec 6, 2022
368ba2a
Update sycl/plugins/unified_runtime/pi2ur.hpp
smaslov-intel Dec 6, 2022
0ed43b7
Update sycl/plugins/unified_runtime/pi_unified_runtime.cpp
smaslov-intel Dec 6, 2022
a7b366a
Update sycl/plugins/unified_runtime/ur/adapters/level_zero/ur_level_z…
smaslov-intel Dec 6, 2022
ab0dd24
Update sycl/plugins/unified_runtime/ur/adapters/level_zero/ur_level_z…
smaslov-intel Dec 6, 2022
ae24c64
test
smaslov-intel Dec 6, 2022
413f366
suppress unknown option
smaslov-intel Dec 6, 2022
d5c468e
allow custom L0 and UR
smaslov-intel Dec 7, 2022
7a49b7c
add proper L0 loader lib
smaslov-intel Dec 7, 2022
7f81531
fix wrong logic
smaslov-intel Dec 8, 2022
08efaed
restore flags
smaslov-intel Dec 9, 2022
7031ac0
Replace global cmake flags override with target_compile_options
Dec 9, 2022
421c225
Additional options for other level_zero targets
Dec 9, 2022
0ae0226
more fixes
Dec 9, 2022
d74d079
Revert back to CMAKE_CXX_FLAGS override
Dec 9, 2022
0bae52d
Integrate llvm with unified-runtime loader
igchor Dec 9, 2022
15f27dc
Add new sycl backend for unified-runtime
igchor Dec 13, 2022
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
4 changes: 4 additions & 0 deletions buildbot/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ def do_configure(args):
sycl_build_pi_hip_platform = args.hip_platform
sycl_enabled_plugins.append("hip")

if args.unified_runtime:
sycl_enabled_plugins.append("unified_runtime")

# all llvm compiler targets don't require 3rd party dependencies, so can be
# built/tested even if specific runtimes are not available
if args.enable_all_llvm_targets:
Expand Down Expand Up @@ -220,6 +223,7 @@ def main():
metavar="BUILD_TYPE", default="Release", help="build type: Debug, Release")
parser.add_argument("--cuda", action='store_true', help="switch from OpenCL to CUDA")
parser.add_argument("--hip", action='store_true', help="switch from OpenCL to HIP")
parser.add_argument("--unified_runtime", action='store_true', help="switch from OpenCL to Unified Runtime")
parser.add_argument("--hip-platform", type=str, choices=['AMD', 'NVIDIA'], default='AMD', help="choose hardware platform for HIP backend")
parser.add_argument("--host-target", default='X86',
help="host LLVM target architecture, defaults to X86, multiple targets may be provided as a semi-colon separated string")
Expand Down
4 changes: 4 additions & 0 deletions sycl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ endif()
if ("esimd_emulator" IN_LIST SYCL_ENABLE_PLUGINS)
set(SYCL_BUILD_PI_ESIMD_EMULATOR ON)
endif()
if ("unified_runtime" IN_LIST SYCL_ENABLE_PLUGINS)
set(SYCL_BUILD_UNIFIED_RUNTIME ON)
endif()

# Configure SYCL version macro
set(sycl_inc_dir ${CMAKE_CURRENT_SOURCE_DIR}/include)
Expand Down Expand Up @@ -360,6 +363,7 @@ set( SYCL_TOOLCHAIN_DEPLOY_COMPONENTS
file-table-tform
level-zero-loader
level-zero-headers
unified-runtime # TODO: is this needed?
llc
llvm-ar
llvm-foreach
Expand Down
4 changes: 4 additions & 0 deletions sycl/include/sycl/backend_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ enum class backend : char {
ext_intel_esimd_emulator,
ext_oneapi_hip = 6,
hip __SYCL2020_DEPRECATED("use 'ext_oneapi_hip' instead") = ext_oneapi_hip,
unified_runtime = 7,
};

template <backend Backend> class backend_traits;
Expand Down Expand Up @@ -63,6 +64,9 @@ inline std::ostream &operator<<(std::ostream &Out, backend be) {
case backend::ext_oneapi_hip:
Out << "ext_oneapi_hip";
break;
case backend::unified_runtime:
Out << "unified_runtime";
break;
case backend::all:
Out << "all";
}
Expand Down
3 changes: 3 additions & 0 deletions sycl/include/sycl/detail/pi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,21 @@ bool trace(TraceLevel level);
#define __SYCL_CUDA_PLUGIN_NAME "pi_cuda.dll"
#define __SYCL_ESIMD_EMULATOR_PLUGIN_NAME "pi_esimd_emulator.dll"
#define __SYCL_HIP_PLUGIN_NAME "libpi_hip.dll"
#define __SYCL_UNFIED_RUNTIME_PLUGIN_NAME "TODO.dll"
#elif defined(__SYCL_RT_OS_LINUX)
#define __SYCL_OPENCL_PLUGIN_NAME "libpi_opencl.so"
#define __SYCL_LEVEL_ZERO_PLUGIN_NAME "libpi_level_zero.so"
#define __SYCL_CUDA_PLUGIN_NAME "libpi_cuda.so"
#define __SYCL_ESIMD_EMULATOR_PLUGIN_NAME "libpi_esimd_emulator.so"
#define __SYCL_HIP_PLUGIN_NAME "libpi_hip.so"
#define __SYCL_UNFIED_RUNTIME_PLUGIN_NAME "libpi_unified_runtime.so"
#elif defined(__SYCL_RT_OS_DARWIN)
#define __SYCL_OPENCL_PLUGIN_NAME "libpi_opencl.dylib"
#define __SYCL_LEVEL_ZERO_PLUGIN_NAME "libpi_level_zero.dylib"
#define __SYCL_CUDA_PLUGIN_NAME "libpi_cuda.dylib"
#define __SYCL_ESIMD_EMULATOR_PLUGIN_NAME "libpi_esimd_emulator.dylib"
#define __SYCL_HIP_PLUGIN_NAME "libpi_hip.dylib"
#define __SYCL_UNFIED_RUNTIME_PLUGIN_NAME "TODO.dylib"
#else
#error "Unsupported OS"
#endif
Expand Down
5 changes: 0 additions & 5 deletions sycl/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,3 @@ foreach(plugin ${SYCL_ENABLE_PLUGINS})
add_subdirectory(${plugin})
endforeach()

# level_zero plugin depends today on unified_runtime plugin
# and unified_runtime plugin is not an independent plugin, adding it explicitly
if ("level_zero" IN_LIST SYCL_ENABLE_PLUGINS)
add_subdirectory(unified_runtime)
endif()
176 changes: 69 additions & 107 deletions sycl/plugins/level_zero/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,143 +1,105 @@
# PI Level Zero plugin library

if(MSVC)
set(LEVEL_ZERO_LOADER
"${LLVM_LIBRARY_OUTPUT_INTDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}ze_loader${CMAKE_STATIC_LIBRARY_SUFFIX}")
else()
set(LEVEL_ZERO_LOADER
"${LLVM_LIBRARY_OUTPUT_INTDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}ze_loader${CMAKE_SHARED_LIBRARY_SUFFIX}")
endif()

if (NOT DEFINED LEVEL_ZERO_LIBRARY OR NOT DEFINED LEVEL_ZERO_INCLUDE_DIR)
message(STATUS "Download Level Zero loader and headers from github.com")
if (CMAKE_C_COMPILER)
list(APPEND AUX_CMAKE_FLAGS -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER})
endif()
if (CMAKE_CXX_COMPILER)
list(APPEND AUX_CMAKE_FLAGS -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER})
endif()
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/level_zero_loader_build)
set(LEVEL_ZERO_LOADER_SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/level_zero/level_zero_loader")
if (NOT DEFINED SYCL_EP_LEVEL_ZERO_LOADER_SKIP_AUTO_UPDATE)
set(SYCL_EP_LEVEL_ZERO_LOADER_SKIP_AUTO_UPDATE ${SYCL_EXTERNAL_PROJECTS_SKIP_AUTO_UPDATE})
endif()
set(LEVEL_ZERO_LOADER_SOURCE_VERSION v1.8.8)

#TODO: Replace ExternalProject with FetchContent for better maintainance and
# cmake files simplification
include(ExternalProject)
ExternalProject_Add(level-zero-loader
GIT_REPOSITORY https://github.com/oneapi-src/level-zero.git
GIT_TAG ${LEVEL_ZERO_LOADER_SOURCE_VERSION}
UPDATE_DISCONNECTED ${SYCL_EP_LEVEL_ZERO_LOADER_SKIP_AUTO_UPDATE}
SOURCE_DIR ${LEVEL_ZERO_LOADER_SOURCE_DIR}
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/level_zero_loader_build"
INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/level_zero_loader_install"
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
-DCMAKE_INSTALL_LIBDIR:PATH=lib${LLVM_LIBDIR_SUFFIX}
${AUX_CMAKE_FLAGS}
LOG_DOWNLOAD 1
LOG_UPDATE 1
LOG_CONFIGURE 1
LOG_BUILD 1
LOG_INSTALL 1
STEP_TARGETS configure,build,install
DEPENDS OpenCL-Headers
BUILD_BYPRODUCTS ${LEVEL_ZERO_LOADER}
)
ExternalProject_Add_Step(level-zero-loader llvminstall
COMMAND ${CMAKE_COMMAND} -E copy_directory <INSTALL_DIR>/lib/ ${LLVM_BINARY_DIR}/lib
COMMAND ${CMAKE_COMMAND} -E copy_directory <INSTALL_DIR>/include/ ${LLVM_BINARY_DIR}/include/sycl
COMMENT "Installing level-zero-loader into the LLVM binary directory"
DEPENDEES install
)

install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/level_zero_loader_install/"
DESTINATION "."
COMPONENT level-zero-loader
)
set(LEVEL_ZERO_LOADER_REPO "https://github.com/oneapi-src/level-zero.git")
set(LEVEL_ZERO_LOADER_TAG v1.8.8)

set(LEVEL_ZERO_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/level_zero_loader_install/include/
CACHE INTERNAL "Path containing Level_Zero header files.")
else()
file(GLOB LEVEL_ZERO_LIBRARY_SRC "${LEVEL_ZERO_LIBRARY}*")
get_filename_component(LEVEL_ZERO_LIB_NAME ${LEVEL_ZERO_LIBRARY} NAME)
add_custom_target(level-zero-loader
DEPENDS
${LLVM_LIBRARY_OUTPUT_INTDIR}/${LEVEL_ZERO_LIB_NAME}
${LLVM_BINARY_DIR}/include/sycl/level_zero
)
add_custom_command(
OUTPUT
${LLVM_LIBRARY_OUTPUT_INTDIR}/${LEVEL_ZERO_LIB_NAME}
${LLVM_BINARY_DIR}/include/sycl/level_zero
COMMENT
"Copying Level Zero loader and headers"
COMMAND
${CMAKE_COMMAND} -E copy ${LEVEL_ZERO_LIBRARY_SRC} ${LLVM_LIBRARY_OUTPUT_INTDIR}
COMMAND
${CMAKE_COMMAND} -E copy_directory ${LEVEL_ZERO_INCLUDE_DIR} ${LLVM_BINARY_DIR}/include/sycl
DEPENDS
${LEVEL_ZERO_LIBRARY}
${LEVEL_ZERO_INCLUDE_DIR}
# Disable due to a bug https://github.com/oneapi-src/level-zero/issues/104
set(CMAKE_INCLUDE_CURRENT_DIR OFF)

message(STATUS "Will fetch Level Zero Loader from ${LEVEL_ZERO_LOADER_REPO}")
include(FetchContent)
FetchContent_Declare(level-zero-loader
GIT_REPOSITORY ${LEVEL_ZERO_LOADER_REPO}
GIT_TAG ${LEVEL_ZERO_LOADER_TAG}
)
endif()

list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS level-zero-loader level-zero-headers)
# Suppress some pedantic warnings for Level Zero build
set(CMAKE_CXX_FLAGS_BAK "${CMAKE_CXX_FLAGS}")
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")

include_directories("${LEVEL_ZERO_INCLUDE_DIR}")
FetchContent_MakeAvailable(level-zero-loader)
FetchContent_GetProperties(level-zero-loader)

# Restore original flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_BAK}")

set(LEVEL_ZERO_LIBRARY ze_loader)
set(LEVEL_ZERO_INCLUDE_DIR
${level-zero-loader_SOURCE_DIR}/include CACHE PATH "Path to Level Zero Headers")
endif()

add_library (LevelZeroLoader INTERFACE)
target_link_libraries(LevelZeroLoader
INTERFACE "${LEVEL_ZERO_LIBRARY}"
)

add_library (LevelZeroLoader-Headers INTERFACE)
add_library (LevelZeroLoader::Headers ALIAS LevelZeroLoader-Headers)
target_include_directories(LevelZeroLoader-Headers
INTERFACE "${LEVEL_ZERO_INCLUDE_DIR}"
)

if (SYCL_ENABLE_XPTI_TRACING)
set(XPTI_PROXY_SRC "${CMAKE_SOURCE_DIR}/../xpti/src/xpti_proxy.cpp")
set(XPTI_INCLUDE "${CMAKE_SOURCE_DIR}/../xpti/include")
set(XPTI_LIBS "${CMAKE_DL_LIBS}")
endif()

find_package(Python3 REQUIRED)

add_custom_target(ze-api
COMMAND ${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/ze_api_generator.py
${LEVEL_ZERO_INCLUDE_DIR}/ze_api.h
BYPRODUCTS
${CMAKE_CURRENT_BINARY_DIR}/ze_api.def
)

find_package(Threads REQUIRED)

add_sycl_plugin(level_zero
SOURCES
"${sycl_inc_dir}/sycl/detail/pi.h"
"${CMAKE_CURRENT_SOURCE_DIR}/pi_level_zero.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/pi_level_zero.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/usm_allocator.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/usm_allocator.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/tracing.cpp"
# These are short-term shared with Unified Runtime
# The two plugins define a few things differrently so must
# be built separately. This difference is spelled in
# their "ur_bindings.hpp" files.
#
"ur_bindings.hpp"
"../unified_runtime/pi2ur.hpp"
"../unified_runtime/pi2ur.cpp"
"../unified_runtime/ur/ur.hpp"
"../unified_runtime/ur/ur.cpp"
"../unified_runtime/ur/adapters/level_zero/ur_level_zero.hpp"
"../unified_runtime/ur/adapters/level_zero/ur_level_zero.cpp"
# Following are the PI Level-Zero Plugin only codes.
"pi_level_zero.cpp"
"pi_level_zero.hpp"
"usm_allocator.cpp"
"usm_allocator.hpp"
"tracing.cpp"
${XPTI_PROXY_SRC}
INCLUDE_DIRS
${CMAKE_CURRENT_BINARY_DIR} # for ze_api.def
${CMAKE_CURRENT_SOURCE_DIR} # for Level-Zero Plugin "ur_bindings.hpp"
${CMAKE_CURRENT_SOURCE_DIR}/../unified_runtime # for Unified Runtime
${XPTI_INCLUDE}
LIBRARIES
"${LEVEL_ZERO_LOADER}"
LevelZeroLoader-Headers
UnifiedRuntime-Headers
LevelZeroLoader
Threads::Threads
unified_runtime
${XPTI_LIBS}
)

find_package(Python3 REQUIRED)

add_custom_target(ze-api
COMMAND ${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/ze_api_generator.py
${LEVEL_ZERO_INCLUDE_DIR}/level_zero/ze_api.h
BYPRODUCTS
${CMAKE_CURRENT_BINARY_DIR}/ze_api.def
)
target_include_directories(pi_level_zero PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
add_dependencies(pi_level_zero ze-api)

if (SYCL_ENABLE_XPTI_TRACING)
target_compile_definitions(pi_level_zero PRIVATE
XPTI_ENABLE_INSTRUMENTATION
XPTI_STATIC_LIBRARY
)
target_include_directories(pi_level_zero PRIVATE "${CMAKE_SOURCE_DIR}/../xpti/include")
target_link_libraries(pi_level_zero PRIVATE ${CMAKE_DL_LIBS})
endif()

if (TARGET level-zero-loader)
add_dependencies(ze-api level-zero-loader)
add_dependencies(pi_level_zero level-zero-loader)
endif()
Loading