Skip to content

[SYCL][NewOffloadModel] Refactor SYCL pipeline in clang-linker-wrapper#22153

Open
maksimsab wants to merge 2 commits into
intel:syclfrom
maksimsab:sycl-no-rdc-new-offload/refactor-clang-linker-wrapper
Open

[SYCL][NewOffloadModel] Refactor SYCL pipeline in clang-linker-wrapper#22153
maksimsab wants to merge 2 commits into
intel:syclfrom
maksimsab:sycl-no-rdc-new-offload/refactor-clang-linker-wrapper

Conversation

@maksimsab
Copy link
Copy Markdown
Contributor

Extract SYCL offloading steps into named functions within the sycl namespace: runSYCLOffloadingPipeline, postLinkProcessModule, compileAndBundle and compileSYCLDevice.

SYCL modifications of linkDevice function has been extracted to the dedicated function - compileSYCLDevice.

Revert linkDevice function to its upstream state. Side effect of this revert: hipspv tests get resolved. Related tracker: CMPLRLLVM-73247

Functions containerizeRawImage and writeOffloadFile are moved so that their location corresponds to the upstream version.

Extract SYCL offloading steps into named functions within the sycl
namespace: runSYCLOffloadingPipeline, postLinkProcessModule,
compileAndBundle and compileSYCLDevice.

SYCL modifications of linkDevice function has been extracted to the
dedicated function - compileSYCLDevice.

Revert linkDevice function to its upstream state. Side effect of this
revert: hipspv tests get resolved. Related tracker: CMPLRLLVM-73247

Functions containerizeRawImage and writeOffloadFile are moved so that
their location corresponds to the upstream version.
@maksimsab maksimsab requested review from a team as code owners May 28, 2026 12:49
@maksimsab
Copy link
Copy Markdown
Contributor Author

maksimsab commented May 28, 2026

Note: this refactoring is done in scope of the adding the support for -fno-sycl-rdc for NewOffloadModel. The added function postLinkProcessModule is going to be invoked for every input module in the following patch as follows (processSYCLModule is the equivalent of postLinkProcessModule):
https://github.com/maksimsab/llvm/blob/19d314d7db175e6e96a05d048126c7c9a9b3cb51/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp#L2018-L2029

@maksimsab maksimsab added the new-offload-model Enables testing with NewOffloadModel. label May 28, 2026
Comment thread clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp Outdated
/// For spir[v]{32,64} performs SPIRV translation (JIT case) + possible AOT
/// compilation (Intel CPU/GPU).
Expected<StringRef>
compileSYCLDevice(ArrayRef<StringRef> InputFiles, const ArgList &Args,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given this is a departure for linkDevice, should this be named to linkSYCLDevice instead? From a overall compilation standpoint, I see 'compile device' as the device compilation step that is performed earlier and not done during link.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no actual linking happening for SYCL case. The input is always 1 file:
https://github.com/intel/llvm/pull/22153/changes#diff-f7dc51acede945c7c8481147e773e9c09230a93b937bee9eab08ee52826cfa8eR1869

So, the main functionality here is either invoke clang's backend for nvptx, amdgcn or invoke SPIRV translator + possible aot compilation.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's lots of different things going on, so maybe a more generic term like processSYCLDevice?

Copy link
Copy Markdown
Contributor

@YuriPlyakhin YuriPlyakhin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quite a lot of CI failed. Is it caused by this patch?

case Triple::native_cpu:
if (IsSYCLKind)
return generic::clang(InputFiles, Args, IsSYCLKind);
return generic::clang(InputFiles, Args, /*IsSYCLKind*/ true);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now handling looks same as case Triple::amdgcn, can we just add one more case there, instead of duplicating the same line here?

default:
return createStringError(Triple.getArchName() +
" linking is not supported other than for SYCL");
" linking is not supported");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method is called compileSYCLDevice, yet the error message says linking. Should the error message be updated?

}

/// Function invokes device compilation and bundling for NVPTX and AMDGCN cases.
Expected<StringRef> compileDeviceAndBundle(StringRef ModuleFilePath,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment says, this one is specific for NVPTX and AMDGCN, while function name is generic. What is correct: comment or function name? something needs to be updated.

Comment on lines +1890 to +1891
/// given
/// \p WrappedOutputCallback).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// given
/// \p WrappedOutputCallback).
/// given \p WrappedOutputCallback).

SmallVector<StringRef> InputFilesSYCL = {ModuleFilePath};
Expected<std::vector<module_split::SplitModule>> SplitModulesOrErr =
UseSYCLPostLinkTool
? sycl::runSYCLPostLinkTool(InputFilesSYCL, LinkerArgs,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious, what's still missing in PostLinkLibrary, that we have to call PostLinkTool?

}

// TODO: Take into account Arch values considered as JIT: "native",
// "spir64", "spir", "spirv32" and "spirv64" for SPIR targets.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// "spir64", "spir", "spirv32" and "spirv64" for SPIR targets.
// "spir64", "spir", "spirv32" and "spirv64" for SPIR and SPIR-V targets.

@YuriPlyakhin
Copy link
Copy Markdown
Contributor

Revert linkDevice function to its upstream state. Side effect of this revert: hipspv tests get resolved. Related tracker: CMPLRLLVM-73247

Functions containerizeRawImage and writeOffloadFile are moved so that their location corresponds to the upstream version.

thank you for aligning the code to upstream!

bool IsJIT =
Triple.isSPIROrSPIRV() && Triple.getSubArch() == llvm::Triple::NoSubArch;
if (IsJIT)
std::for_each(SplitModules.begin(), SplitModules.end(),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a comment, but a question to help with my understanding:
In the old code, CompileOptions/LinkOptions are set inside the loop after the compile call. New code sets them before the compile (compileDeviceAndBundle). Is this an intentional ordering shift?

}

/// Function invokes device compilation and bundling for NVPTX and AMDGCN cases.
Expected<StringRef> compileDeviceAndBundle(StringRef ModuleFilePath,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is only called from postLinkProcessModule. Should this be marked as 'static'?

case Triple::aarch64_be:
case Triple::ppc64:
case Triple::ppc64le:
case Triple::spirv64:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L1830 handles SPIRV64 for SYCL offload, what is this SPIRV64 for? Non SYCL offload kind?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new-offload-model Enables testing with NewOffloadModel.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants