Skip to content

Commit 5d7e86d

Browse files
authored
[SYCL][Fusion] Interface with kernel fusion JIT (#7831)
This is the fifth patch in a series of patches to add an implementation of the [kernel fusion extension](#7098). We have split the implementation into multiple patches to make them more easy to review. This patch connects the JIT compiler for kernel fusion (`sycl-fusion`) with the SYCL runtime. - Enable the feature by default and add an option to `configure.py` to disable it. - Link the runtime against the JIT compiler library as a shared library. - Add logic to retrieve binaries (SPIR-V) and other information (e.g., accessors) from the SYCL RT and invoke the JIT compiler. - Representation to store binaries (SPIR-V) returned by JIT compiler in memory for use as PI device binaries. The integration of the JIT compiler into the SYCL RT is described in [this design document](#7204). Signed-off-by: Lukas Sommer <[email protected]>
1 parent 11f53ad commit 5d7e86d

File tree

16 files changed

+1353
-23
lines changed

16 files changed

+1353
-23
lines changed

buildbot/configure.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ def do_configure(args):
2323
libclc_amd_target_names = ';amdgcn--;amdgcn--amdhsa'
2424
libclc_nvidia_target_names = ';nvptx64--;nvptx64--nvidiacl'
2525

26+
sycl_enable_fusion = "OFF"
27+
if not args.disable_fusion:
28+
llvm_external_projects += ";sycl-fusion"
29+
sycl_enable_fusion = "ON"
30+
2631
if args.llvm_external_projects:
2732
llvm_external_projects += ";" + args.llvm_external_projects.replace(",", ";")
2833

@@ -32,6 +37,7 @@ def do_configure(args):
3237
xpti_dir = os.path.join(abs_src_dir, "xpti")
3338
xptifw_dir = os.path.join(abs_src_dir, "xptifw")
3439
libdevice_dir = os.path.join(abs_src_dir, "libdevice")
40+
fusion_dir = os.path.join(abs_src_dir, "sycl-fusion")
3541
llvm_targets_to_build = args.host_target
3642
llvm_enable_projects = 'clang;' + llvm_external_projects
3743
libclc_targets_to_build = ''
@@ -144,6 +150,7 @@ def do_configure(args):
144150
"-DXPTI_SOURCE_DIR={}".format(xpti_dir),
145151
"-DLLVM_EXTERNAL_XPTIFW_SOURCE_DIR={}".format(xptifw_dir),
146152
"-DLLVM_EXTERNAL_LIBDEVICE_SOURCE_DIR={}".format(libdevice_dir),
153+
"-DLLVM_EXTERNAL_SYCL_FUSION_SOURCE_DIR={}".format(fusion_dir),
147154
"-DLLVM_ENABLE_PROJECTS={}".format(llvm_enable_projects),
148155
"-DLIBCLC_TARGETS_TO_BUILD={}".format(libclc_targets_to_build),
149156
"-DLIBCLC_GENERATE_REMANGLED_VARIANTS={}".format(libclc_gen_remangled_variants),
@@ -159,7 +166,8 @@ def do_configure(args):
159166
"-DLLVM_ENABLE_LLD={}".format(llvm_enable_lld),
160167
"-DXPTI_ENABLE_WERROR={}".format(xpti_enable_werror),
161168
"-DSYCL_CLANG_EXTRA_FLAGS={}".format(sycl_clang_extra_flags),
162-
"-DSYCL_ENABLE_PLUGINS={}".format(';'.join(set(sycl_enabled_plugins)))
169+
"-DSYCL_ENABLE_PLUGINS={}".format(';'.join(set(sycl_enabled_plugins))),
170+
"-DSYCL_ENABLE_KERNEL_FUSION={}".format(sycl_enable_fusion)
163171
]
164172

165173
if args.l0_headers and args.l0_loader:
@@ -238,6 +246,7 @@ def main():
238246
parser.add_argument("--llvm-external-projects", help="Add external projects to build. Add as comma seperated list.")
239247
parser.add_argument("--ci-defaults", action="store_true", help="Enable default CI parameters")
240248
parser.add_argument("--enable-plugin", action='append', help="Enable SYCL plugin")
249+
parser.add_argument("--disable-fusion", action="store_true", help="Disable the kernel fusion JIT compiler")
241250
args = parser.parse_args()
242251

243252
print("args:{}".format(args))

sycl-fusion/CMakeLists.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ set(SYCL_JIT_BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
99
# directories, similar to how clang/CMakeLists.txt does it.
1010
set(LLVM_SPIRV_INCLUDE_DIRS "${LLVM_MAIN_SRC_DIR}/../llvm-spirv/include")
1111

12-
add_subdirectory(jit-compiler)
13-
add_subdirectory(passes)
14-
add_subdirectory(test)
12+
if(WIN32)
13+
message(WARNING "Kernel fusion not yet supported on Windows")
14+
else(WIN32)
15+
add_subdirectory(jit-compiler)
16+
add_subdirectory(passes)
17+
add_subdirectory(test)
18+
endif(WIN32)

sycl-fusion/jit-compiler/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ target_link_libraries(sycl-fusion
3939
${CMAKE_THREAD_LIBS_INIT}
4040
)
4141

42+
if(NOT MSVC AND NOT APPLE)
43+
# Manage symbol visibility through the linker to make sure no LLVM symbols
44+
# are exported and confuse the drivers.
45+
set(linker_script "${CMAKE_CURRENT_SOURCE_DIR}/ld-version-script.txt")
46+
target_link_libraries(
47+
sycl-fusion PRIVATE "-Wl,--version-script=${linker_script}")
48+
set_target_properties(sycl-fusion PROPERTIES LINK_DEPENDS ${linker_script})
49+
endif()
50+
4251
install(TARGETS sycl-fusion
4352
LIBRARY DESTINATION "lib${LLVM_LIBDIR_SUFFIX}" COMPONENT sycl-fusion
4453
RUNTIME DESTINATION "bin" COMPONENT sycl-fusion)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
global:
3+
/* Export everything from jit_compiler namespace */
4+
_ZN12jit_compiler*;
5+
6+
local:
7+
*;
8+
};

sycl-fusion/jit-compiler/lib/fusion/FusionPipeline.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ FusionPipeline::runFusionPasses(Module &Mod, SYCLModuleInfo &InputInfo,
7878
FPM.addPass(createFunctionToLoopPassAdaptor(IndVarSimplifyPass{}));
7979
LoopUnrollOptions UnrollOptions;
8080
FPM.addPass(LoopUnrollPass{UnrollOptions});
81-
FPM.addPass(SROAPass{});
81+
FPM.addPass(SROAPass{SROAOptions::ModifyCFG});
8282
// Run the InferAddressSpace pass to remove as many address-space casts
8383
// to/from generic address-space as possible, because these hinder
8484
// internalization.
@@ -94,11 +94,11 @@ FusionPipeline::runFusionPasses(Module &Mod, SYCLModuleInfo &InputInfo,
9494
// Run additional optimization passes after completing fusion.
9595
{
9696
FunctionPassManager FPM;
97-
FPM.addPass(SROAPass{});
97+
FPM.addPass(SROAPass{SROAOptions::ModifyCFG});
9898
FPM.addPass(SCCPPass{});
9999
FPM.addPass(InstCombinePass{});
100100
FPM.addPass(SimplifyCFGPass{});
101-
FPM.addPass(SROAPass{});
101+
FPM.addPass(SROAPass{SROAOptions::ModifyCFG});
102102
FPM.addPass(InstCombinePass{});
103103
FPM.addPass(SimplifyCFGPass{});
104104
FPM.addPass(ADCEPass{});

sycl/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,12 @@ install(DIRECTORY ${OpenCL_INCLUDE_DIR}/CL
145145
COMPONENT OpenCL-Headers)
146146

147147
# Option to enable online kernel fusion via a JIT compiler
148-
option(SYCL_ENABLE_KERNEL_FUSION "Enable kernel fusion via JIT compiler" OFF)
148+
option(SYCL_ENABLE_KERNEL_FUSION "Enable kernel fusion via JIT compiler" ON)
149+
if(SYCL_ENABLE_KERNEL_FUSION AND WIN32)
150+
message(WARNING "Kernel fusion not yet supported on Windows")
151+
set(SYCL_ENABLE_KERNEL_FUSION OFF CACHE
152+
BOOL "Kernel fusion not yet supported on Windows" FORCE)
153+
endif()
149154

150155
# Needed for feature_test.hpp
151156
if ("cuda" IN_LIST SYCL_ENABLE_PLUGINS)

sycl/cmake/modules/AddSYCLUnitTest.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ macro(add_sycl_unittest test_dirname link_variant)
5656
OpenCL-Headers
5757
${SYCL_LINK_LIBS}
5858
)
59+
60+
if(SYCL_ENABLE_KERNEL_FUSION)
61+
target_link_libraries(${test_dirname} PRIVATE sycl-fusion)
62+
endif(SYCL_ENABLE_KERNEL_FUSION)
63+
5964
target_include_directories(${test_dirname}
6065
PRIVATE SYSTEM
6166
${sycl_inc_dir}

sycl/doc/GetStartedGuide.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and a wide range of compute accelerators such as GPU and FPGA.
1212
- [Build DPC++ toolchain with support for HIP AMD](#build-dpc-toolchain-with-support-for-hip-amd)
1313
- [Build DPC++ toolchain with support for HIP NVIDIA](#build-dpc-toolchain-with-support-for-hip-nvidia)
1414
- [Build DPC++ toolchain with support for ESIMD CPU Emulation](#build-dpc-toolchain-with-support-for-esimd-emulator)
15+
- [Build DPC++ toolchain with support for runtime kernel fusion](#build-dpc-toolchain-with-support-for-runtime-kernel-fusion)
1516
- [Build Doxygen documentation](#build-doxygen-documentation)
1617
- [Deployment](#deployment)
1718
- [Use DPC++ toolchain](#use-dpc-toolchain)
@@ -298,6 +299,16 @@ Enabling this flag requires following packages installed.
298299
Currently, this feature was tested and verified on Ubuntu 20.04
299300
environment.
300301

302+
### Build DPC++ toolchain with support for runtime kernel fusion
303+
304+
Support for the experimental SYCL extension for user-driven kernel fusion
305+
at runtime is enabled by default.
306+
307+
To disable support for this feature, follow the instructions for the
308+
Linux DPC++ toolchain, but add the `--disable-fusion` flag.
309+
310+
Kernel fusion is currently not yet supported on the Windows platform.
311+
301312
### Build Doxygen documentation
302313

303314
Building Doxygen documentation is similar to building the product itself. First,

sycl/include/sycl/detail/cg.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ class CG {
9898

9999
CGTYPE getType() { return MType; }
100100

101+
std::vector<std::vector<char>> &getArgsStorage() { return MArgsStorage; }
102+
103+
std::vector<detail::AccessorImplPtr> &getAccStorage() { return MAccStorage; }
104+
101105
virtual ~CG() = default;
102106

103107
private:

sycl/source/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ function(add_sycl_rt_library LIB_NAME LIB_OBJ_NAME)
8787
PRIVATE OpenCL-Headers
8888
)
8989

90+
if(SYCL_ENABLE_KERNEL_FUSION)
91+
target_link_libraries(${LIB_NAME} PRIVATE sycl-fusion)
92+
target_link_libraries(${LIB_OBJ_NAME} PRIVATE sycl-fusion)
93+
set_property(GLOBAL APPEND PROPERTY SYCL_TOOLCHAIN_INSTALL_COMPONENTS
94+
sycl-fusion)
95+
endif(SYCL_ENABLE_KERNEL_FUSION)
96+
9097
find_package(Threads REQUIRED)
9198

9299
target_link_libraries(${LIB_NAME}
@@ -139,6 +146,8 @@ set(SYCL_SOURCES
139146
"detail/handler_proxy.cpp"
140147
"detail/image_accessor_util.cpp"
141148
"detail/image_impl.cpp"
149+
"detail/jit_compiler.cpp"
150+
"detail/jit_device_binaries.cpp"
142151
"detail/kernel_impl.cpp"
143152
"detail/kernel_program_cache.cpp"
144153
"detail/memory_manager.cpp"

0 commit comments

Comments
 (0)