-
Notifications
You must be signed in to change notification settings - Fork 0
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
[Clang][SYCL] Introduce clang-sycl-link-wrapper to link SYCL offloading device code #1
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,67 @@ | ||||||||||
==================== | ||||||||||
Clang SYCL link Wrapper | ||||||||||
==================== | ||||||||||
|
||||||||||
.. contents:: | ||||||||||
:local: | ||||||||||
|
||||||||||
.. _clang-sycl-link-wrapper: | ||||||||||
|
||||||||||
Introduction | ||||||||||
============ | ||||||||||
|
||||||||||
This tool works as a wrapper around the SYCL device code linking process. | ||||||||||
Purpose of this wrapper is to provide an interface to link SYCL device bitcode | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to my understanding, the purpose of the tool is to provide standard linker interface and be able to link any object file formats 'compile' step is able to produce for SYCL offload mode. So, I would expect this tool to handle linking of fat objects with device code in other IR like SPIR-V as well as native binary format. |
||||||||||
in LLVM IR format, run some SYCL-specific finalization steps and then use the | ||||||||||
SPIR-V LLVM Translator tool to produce the final output. | ||||||||||
|
||||||||||
Device code linking for SYCL offloading kind has a number of known quirks that | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
makes it difficult to use in a unified offloading setting. Two of the primary | ||||||||||
issues are: | ||||||||||
1. Several finalization steps are required to be run on the fully-linked LLVM | ||||||||||
IR bitcode to gaurantee conformance to SYCL standards. This step is unique to | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
SYCL offloading compilation flow. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
2. SPIR-V LLVM Translator tool is an extenal tool and hence SPIR-V IR code | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
generation cannot be done as part of LTO. This limitation will be lifted once | ||||||||||
SPIR-V backend is available as a viable LLVM backend. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
This tool works around these issues. | ||||||||||
|
||||||||||
Usage | ||||||||||
===== | ||||||||||
|
||||||||||
This tool can be used with the following options. Several of these options will | ||||||||||
be passed down to downstrea tools like 'llvm-link', 'llvm-spirv', etc. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
We should use |
||||||||||
|
||||||||||
.. code-block:: console | ||||||||||
|
||||||||||
OVERVIEW: A utility that wraps around the SYCl device code linking process. | ||||||||||
This enables linking and code generation for SPIR-V JIT targets. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about AOT targets? |
||||||||||
|
||||||||||
USAGE: clang-sycl-link-wrapper [options] | ||||||||||
|
||||||||||
OPTIONS: | ||||||||||
--arch <value> Specify the name of the target architecture. | ||||||||||
--dry-run Print generated commands without running. | ||||||||||
-g Specify that this was a debug compile. | ||||||||||
-help-hidden Display all available options | ||||||||||
-help Display available options (--help-hidden for more) | ||||||||||
--library-path=<dir> Set the library path for SYCL device libraries | ||||||||||
-o <path> Path to file to write output | ||||||||||
--save-temps Save intermediate results | ||||||||||
--triple <value> Specify the target triple. | ||||||||||
--version Display the version number and exit | ||||||||||
-v Print verbose information | ||||||||||
|
||||||||||
Example | ||||||||||
======= | ||||||||||
|
||||||||||
This tool is intended to be invoked when targeting the SPIR-V toolchain. | ||||||||||
When --sycl-link option is passed, clang driver will invoke the linking job of | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please, specify that |
||||||||||
the SPIR-V toolchain, which in turn will invoke this tool. | ||||||||||
This tool can be used to create one or more fully linked SYCL objects that are | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
? |
||||||||||
ready to be wrapped and linked with host code to generate the final executable. | ||||||||||
|
||||||||||
.. code-block:: console | ||||||||||
|
||||||||||
clang --target=spirv64 --sycl-link input.bc |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6728,7 +6728,10 @@ def fsycl : Flag<["-"], "fsycl">, | |
def fno_sycl : Flag<["-"], "fno-sycl">, | ||
Visibility<[ClangOption, CLOption]>, | ||
Group<sycl_Group>, HelpText<"Disables SYCL kernels compilation for device">; | ||
|
||
def sycl_link : Flag<["--"], "sycl-link">, Flags<[HelpHidden]>, | ||
Visibility<[ClangOption, CLOption]>, | ||
Group<sycl_Group>, HelpText<"Perform link through clang-sycl-link-wrapper via the SPIR-V " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. given the description, maybe it should be |
||
"toolchain.">; | ||
// OS-specific options | ||
let Flags = [TargetSpecific] in { | ||
defm android_pad_segment : BooleanFFlag<"android-pad-segment">, Group<f_Group>; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Tests the clang-sycl-link-wrapper tool | ||
// | ||
// Test a simple case without arguments | ||
// RUN: %clangxx -fsycl -emit-llvm -c %s -o %t.bc | ||
// RUN: clang-sycl-link-wrapper --dry-run -triple spirv64 %t.bc --library-path=%S/Inputs -o a.spv 2>&1 \ | ||
// RUN: | FileCheck %s --check-prefix=CMDS | ||
// CMDS: "{{.*}}llvm-link{{.*}}" {{.*}}.bc -o [[FIRSTLLVMLINKOUT:.*]].bc --suppress-warnings | ||
// CMDS-NEXT: "{{.*}}llvm-link{{.*}}" -only-needed [[FIRSTLLVMLINKOUT]].bc {{.*}}libsycl-crt.bc {{.*}}libsycl-complex.bc -o [[SECONDLLVMLINKOUT:.*]].bc --suppress-warnings | ||
// CMDS-NEXT: "{{.*}}llvm-spirv{{.*}}" {{.*}}-o a.spv [[SECONDLLVMLINKOUT]].bc |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Tests the driver when linking LLVM IR bitcode files and targeting SPIR-V | ||
// architecture. | ||
// | ||
// RUN: touch %t.bc | ||
// RUN: %clangxx --target=spirv64 --sycl-link -### %t.bc 2>&1 \ | ||
// RUN: | FileCheck %s -check-prefix=LINK | ||
// LINK: "{{.*}}clang-sycl-link-wrapper{{.*}}" "{{.*}}.bc" "-o" "a.out" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
set(LLVM_LINK_COMPONENTS | ||
${LLVM_TARGETS_TO_BUILD} | ||
Option | ||
) | ||
|
||
set(LLVM_TARGET_DEFINITIONS SYCLLinkOpts.td) | ||
tablegen(LLVM SYCLLinkOpts.inc -gen-opt-parser-defs) | ||
add_public_tablegen_target(SYCLLinkWrapperOpts) | ||
|
||
if(NOT CLANG_BUILT_STANDALONE) | ||
set(tablegen_deps intrinsics_gen SYCLLinkWrapperOpts) | ||
endif() | ||
|
||
add_clang_tool(clang-sycl-link-wrapper | ||
ClangSYCLLinkWrapper.cpp | ||
|
||
DEPENDS | ||
${tablegen_deps} | ||
) | ||
|
||
set(CLANG_SYCL_LINK_WRAPPER_LIB_DEPS | ||
clangBasic | ||
) | ||
|
||
target_link_libraries(clang-sycl-link-wrapper | ||
PRIVATE | ||
${CLANG_SYCL_LINK_WRAPPER_LIB_DEPS} | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.