Skip to content

Commit f011892

Browse files
authored
[SYCL][NATIVECPU] Support specialization constants on Native CPU (#14446)
Adds support to specialization constants by scheduling the `SpecConstantsPass` in the Native CPU pass pipeline. A small change is needed in that pass since, due to ABI, the return type of the spec const builtins can't be used to determine the type of the spec constant, so for Native CPU we use the default value instead. UR PR: oneapi-src/unified-runtime#1821
1 parent 7fc3ac2 commit f011892

File tree

6 files changed

+15
-8
lines changed

6 files changed

+15
-8
lines changed

llvm/lib/SYCLLowerIR/SpecConstants.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,8 +951,9 @@ PreservedAnalyses SpecConstantsPass::run(Module &M,
951951
updatePaddingInLastMDNode(Ctx, SCMetadata, Padding);
952952
}
953953

954+
auto *DefValTy = DefaultValue->getType();
954955
SCMetadata[SymID] = generateSpecConstantMetadata(
955-
M, SymID, SCTy, NextID, /* is native spec constant */ false);
956+
M, SymID, DefValTy, NextID, /* is native spec constant */ false);
956957

957958
++NextID.ID;
958959
NextOffset += Size;

llvm/lib/SYCLNativeCPUUtils/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ add_llvm_component_library(LLVMSYCLNativeCPUUtils
1313
Core
1414
Support
1515
Passes
16+
SYCLLowerIR
1617
Target
1718
TargetParser
1819
TransformUtils

llvm/lib/SYCLNativeCPUUtils/PipelineSYCLNativeCPU.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "llvm/SYCLLowerIR/ConvertToMuxBuiltinsSYCLNativeCPU.h"
1515
#include "llvm/SYCLLowerIR/PrepareSYCLNativeCPU.h"
1616
#include "llvm/SYCLLowerIR/RenameKernelSYCLNativeCPU.h"
17+
#include "llvm/SYCLLowerIR/SpecConstants.h"
1718
#include "llvm/SYCLLowerIR/UtilsSYCLNativeCPU.h"
1819
#include "llvm/Support/CommandLine.h"
1920

@@ -60,6 +61,7 @@ static cl::opt<bool>
6061
void llvm::sycl::utils::addSYCLNativeCPUBackendPasses(
6162
llvm::ModulePassManager &MPM, ModuleAnalysisManager &MAM,
6263
OptimizationLevel OptLevel) {
64+
MPM.addPass(SpecConstantsPass(SpecConstantsPass::HandlingMode::emulation));
6365
MPM.addPass(ConvertToMuxBuiltinsSYCLNativeCPUPass());
6466
#ifdef NATIVECPU_USE_OCK
6567
MPM.addPass(compiler::utils::TransferKernelMetadataPass());

sycl/cmake/modules/FetchUnifiedRuntime.cmake

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,13 @@ if(SYCL_UR_USE_FETCH_CONTENT)
117117
endfunction()
118118

119119
set(UNIFIED_RUNTIME_REPO "https://github.com/oneapi-src/unified-runtime.git")
120-
# commit f31160dea6d142014f441bc4ca5e58e48827490e
121-
# Merge: 2bbe9526 64068799
122-
# Author: Piotr Balcer <piotr.balcer@intel.com>
123-
# Date: Thu Sep 12 14:19:48 2024 +0200
124-
# Merge pull request #2083 from kswiecicki/xpti-init-fix
125-
# Fix XPTI initialization bug
126-
set(UNIFIED_RUNTIME_TAG f31160dea6d142014f441bc4ca5e58e48827490e)
120+
# commit fa9ebe7bd3d9bd11dd5ea8a59eff12f5746411d3
121+
# Merge: 92638b2a 9eb1c74f
122+
# Author: Omar Ahmed <omar.ahmed@codeplay.com>
123+
# Date: Fri Sep 13 14:44:27 2024 +0100
124+
# Merge pull request #1821 from PietroGhg/pietro/native_cpu_specconstants
125+
# [NATIVECPU] Initial support for spec constants on Native CPU
126+
set(UNIFIED_RUNTIME_TAG fa9ebe7bd3d9bd11dd5ea8a59eff12f5746411d3)
127127

128128
set(UMF_BUILD_EXAMPLES OFF CACHE INTERNAL "EXAMPLES")
129129
# Due to the use of dependentloadflag and no installer for UMF and hwloc we need

sycl/source/kernel_bundle.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,8 @@ bool is_compatible(const std::vector<kernel_id> &KernelIDs, const device &Dev) {
329329
return BE == sycl::backend::ext_oneapi_cuda;
330330
} else if (strcmp(Target, __SYCL_DEVICE_BINARY_TARGET_AMDGCN) == 0) {
331331
return BE == sycl::backend::ext_oneapi_hip;
332+
} else if (strcmp(Target, __SYCL_DEVICE_BINARY_TARGET_NATIVE_CPU) == 0) {
333+
return BE == sycl::backend::ext_oneapi_native_cpu;
332334
}
333335

334336
return false;

sycl/test-e2e/SpecConstants/2020/kernel-bundle-api.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// RUN: %{run} %t.out
1212
//
1313
// UNSUPPORTED: hip
14+
// UNSUPPORTED: native_cpu
1415

1516
#include <cstdlib>
1617
#include <iostream>

0 commit comments

Comments
 (0)