Skip to content

Commit 55c155c

Browse files
committed
[SYCL] Fix kernel name mangling for CUDA/HIP with Microsoft ABI host
SYCL kernel names are generated during template instantiation using MangleContext, which produces different encodings based on target ABI. When host compilation uses Microsoft ABI and device compilation targets Itanium ABI (CUDA/HIP), this caused runtime kernel lookup failures: No kernel named _ZTSZZ21performIncrementationENK... was found The issue occurred because Sema::PerformPendingInstantiations() used ASTContext::createMangleContext(), which creates an ABI-specific context for the primary target. In cross-ABI scenarios (Microsoft host + Itanium device), this produced inconsistent names between host and device. Solution: - Added createSYCLMangleContext() helper that detects Microsoft-to-Itanium ABI scenarios - When detected, uses createDeviceMangleContext() for host compilation to ensure Itanium mangling on both sides - Applied to both host and device compilation phases via (LangOpts.SYCLIsHost || LangOpts.SYCLIsDevice) guard This ensures identical kernel names across compilations, allowing runtime lookup to succeed. Fixes CMPLRLLVM-69642
1 parent 8c614ad commit 55c155c

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7733,9 +7733,31 @@ static void processFunctionInstantiation(Sema &S,
77337733
FD->setInstantiationIsPending(false);
77347734
}
77357735

7736+
static std::unique_ptr<MangleContext> createSYCLMangleContext(ASTContext &Ctx) {
7737+
// For SYCL compilation, ensure kernel name mangling is consistent between
7738+
// host and device compilations when targeting CUDA/HIP backends.
7739+
// When the host uses Microsoft ABI and device uses Itanium ABI, we need
7740+
// to use device-aware mangling context on the host side.
7741+
const TargetInfo *AuxTarget = Ctx.getAuxTargetInfo();
7742+
if (AuxTarget && Ctx.getTargetInfo().getCXXABI().isMicrosoft() &&
7743+
AuxTarget->getCXXABI().isItaniumFamily()) {
7744+
// Host compilation with Microsoft ABI targeting Itanium device
7745+
return std::unique_ptr<MangleContext>(
7746+
Ctx.createDeviceMangleContext(*AuxTarget));
7747+
}
7748+
// All other cases: use standard mangling for the primary target
7749+
return std::unique_ptr<MangleContext>(Ctx.createMangleContext());
7750+
}
7751+
77367752
void Sema::PerformPendingInstantiations(bool LocalOnly, bool AtEndOfTU) {
7753+
// For SYCL compilation (both host and device), use device-aware mangle
7754+
// context to ensure consistent kernel name mangling across different
7755+
// backends (CUDA/HIP) and between host and device compilations.
77377756
std::unique_ptr<MangleContext> MangleCtx(
7738-
getASTContext().createMangleContext());
7757+
(LangOpts.SYCLIsHost || LangOpts.SYCLIsDevice)
7758+
? createSYCLMangleContext(getASTContext())
7759+
: std::unique_ptr<MangleContext>(
7760+
getASTContext().createMangleContext()));
77397761
std::deque<PendingImplicitInstantiation> DelayedImplicitInstantiations;
77407762
while (!PendingLocalImplicitInstantiations.empty() ||
77417763
(!LocalOnly && !PendingInstantiations.empty())) {

sycl/test-e2e/IntermediateLib/multi_lib_app.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// UNSUPPORTED: cuda || hip
2-
// UNSUPPORTED-TRACKER: CMPLRLLVM-69415
3-
41
// DEFINE: %{fPIC_flag} = %if windows %{%} %else %{-fPIC%}
52
// DEFINE: %{shared_lib_ext} = %if windows %{dll%} %else %{so%}
63

0 commit comments

Comments
 (0)