Skip to content

Commit 9204d23

Browse files
committed
[interpreter] Add support for SYCL with adaptiveCpp
AdaptiveCpp requires NullDerefProtectionTransformer to be turned off to function properly
1 parent 8a2bba7 commit 9204d23

File tree

14 files changed

+78
-5
lines changed

14 files changed

+78
-5
lines changed

bindings/pyroot/pythonizations/test/import_load_libs.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ class ImportLoadLibs(unittest.TestCase):
2929
"librt",
3030
"libncurses.*",
3131
"libtinfo", # by libncurses (on some older platforms)
32+
# adaptivecpp and dependencies
33+
"libacpp-rt",
34+
"libgomp",
3235
# libTree and dependencies
3336
"libTree",
3437
"libThread",

cmake/modules/SearchInstalledSoftware.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,6 +1649,9 @@ if(experimental_adaptivecpp)
16491649
ROOT_CHECK_CONNECTION_AND_DISABLE_OPTION("experimental_adaptivecpp")
16501650
endif()
16511651
include(SetupAdaptiveCpp)
1652+
1653+
add_compile_definitions(CLING_WITH_ADAPTIVECPP)
1654+
16521655
set(HIPSYCL_NO_FIBERS ON)
16531656
set(WITH_OPENCL_BACKEND OFF)
16541657
set(WITH_LEVEL_ZERO_BACKEND OFF)

core/metacling/src/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ if (clad)
114114
else()
115115
set(CLING_PLUGIN_LINK_LIBS -Wl,--whole-archive cladPlugin cladDifferentiator -Wl,--no-whole-archive)
116116
endif()
117-
if(TARGET clang)
117+
# This will cause a cyclic dependency in adaptiveCpp, as it requires clang to build
118+
if(TARGET clang AND NOT experimental_adaptivecpp)
118119
# Link our clad libraries to clang. If users use the clang from ROOT they will
119120
# also be able to use clad out of the box.
120121
add_dependencies(clang clad)

core/metacling/src/TCling.cxx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,6 +1437,15 @@ TCling::TCling(const char *name, const char *title, const char* const argv[], vo
14371437
clingArgsStorage.push_back("-mllvm");
14381438
clingArgsStorage.push_back("-optimize-regalloc=0");
14391439
#endif
1440+
1441+
#ifdef CLING_WITH_ADAPTIVECPP
1442+
std::string acppInclude(TROOT::GetIncludeDir() + "/AdaptiveCpp");
1443+
1444+
clingArgsStorage.push_back("-isystem");
1445+
clingArgsStorage.push_back(acppInclude);
1446+
clingArgsStorage.push_back("-mllvm");
1447+
clingArgsStorage.push_back("-acpp-sscp");
1448+
#endif
14401449
}
14411450

14421451
// Process externally passed arguments if present.

interpreter/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ set(LLVM_FORCE_USE_OLD_TOOLCHAIN ON CACHE BOOL "")
5353
# found before (because the user turned on cuda or tmva-gpu), this will not have
5454
# an effect, which is fine.
5555
# (Note that the option is very counter-intuitive: We turn *on* disabling it...)
56-
set(CMAKE_DISABLE_FIND_PACKAGE_CUDA ON)
56+
# Except when we want to build cling with adaptiveCpp, in which case adaptiveCpp
57+
# needs to find CUDA in order to build the backend.
58+
if(NOT experimental_adaptivecpp)
59+
set(CMAKE_DISABLE_FIND_PACKAGE_CUDA ON)
60+
endif()
5761

5862
# will be set again in case NOT builtin_llvm
5963
set(LLVM_DIR "${CMAKE_CURRENT_BINARY_DIR}/llvm-project/llvm")

interpreter/cling/lib/Interpreter/BackendPasses.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636

3737
#include <optional>
3838

39+
#ifdef CLING_WITH_ADAPTIVECPP
40+
llvm::PassPluginLibraryInfo getAdaptiveCppPluginInfo();
41+
#endif
42+
3943
using namespace cling;
4044
using namespace clang;
4145
using namespace llvm;
@@ -511,6 +515,10 @@ void BackendPasses::CreatePasses(int OptLevel, llvm::ModulePassManager& MPM,
511515
std::optional<PGOOptions> PGOOpt;
512516
PassBuilder PB(&m_TM, PTO, PGOOpt, &PIC);
513517

518+
#ifdef CLING_WITH_ADAPTIVECPP
519+
getAdaptiveCppPluginInfo().RegisterPassBuilderCallbacks(PB);
520+
#endif
521+
514522
// Attempt to load pass plugins and register their callbacks with PB.
515523
for (auto& PluginFN : m_CGOpts.PassPlugins) {
516524
auto PassPlugin = PassPlugin::Load(PluginFN);

interpreter/cling/lib/Interpreter/CIFactory.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,6 +1391,11 @@ namespace {
13911391
argvCompile.push_back("-fno-omit-frame-pointer");
13921392
}
13931393

1394+
#ifdef CLING_WITH_ADAPTIVECPP
1395+
argvCompile.push_back("-D__ACPP_ENABLE_LLVM_SSCP_TARGET__");
1396+
argvCompile.push_back("-Xclang");
1397+
argvCompile.push_back("-disable-O0-optnone");
1398+
#endif
13941399
// Add host specific includes, -resource-dir if necessary, and -isysroot
13951400
std::string ClingBin = GetExecutablePath(argv[0]);
13961401
AddHostArguments(ClingBin, argvCompile, LLVMDir, COpts);

interpreter/cling/lib/Interpreter/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ set(LIBS
2323
clangLex
2424
)
2525

26+
if(experimental_adaptivecpp)
27+
list(APPEND LIBS AdaptiveCpp acpp-rt)
28+
29+
set(ACPP_EXPORTS acpp-rt acpp-common)
30+
31+
foreach(target IN LISTS ACPP_EXPORTS)
32+
install(TARGETS ${target} EXPORT ClingTargets)
33+
endforeach()
34+
35+
set_property(GLOBAL APPEND PROPERTY CLING_EXPORTS ${ACPP_EXPORTS})
36+
endif()
37+
2638
set(LLVM_LINK_COMPONENTS
2739
analysis
2840
core

interpreter/cling/lib/Interpreter/IncrementalParser.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,9 +1033,11 @@ namespace cling {
10331033
// Don't protect against crashes if we cannot run anything.
10341034
// cling might also be in a PCH-generation mode; don't inject our Sema
10351035
// pointer into the PCH.
1036+
#ifndef CLING_WITH_ADAPTIVECPP
10361037
if (!isCUDADevice && m_Interpreter->getOptions().PtrCheck)
10371038
ASTTransformers.emplace_back(
10381039
new NullDerefProtectionTransformer(m_Interpreter));
1040+
#endif
10391041
if (isCUDADevice)
10401042
ASTTransformers.emplace_back(
10411043
new DeviceKernelInliner(TheSema));

roottest/cling/exception/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
if(NOT MSVC OR win_broken_tests)
1+
if((NOT MSVC OR win_broken_tests) AND NOT experimental_adaptivecpp)
22
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64.*|x86.*|amd64.*|AMD64.*|i686.*|i386.*")
33
# All platforms except of ARM/AARCH64
44
ROOTTEST_ADD_TEST(nullderef-macro
@@ -9,7 +9,7 @@ if(NOT MSVC OR win_broken_tests)
99
endif()
1010
endif()
1111

12-
if(NOT (APPLE AND CMAKE_SYSTEM_PROCESSOR MATCHES arm64) OR M1_BROKEN_TESTS)
12+
if((NOT (APPLE AND CMAKE_SYSTEM_PROCESSOR MATCHES arm64) OR M1_BROKEN_TESTS) AND NOT experimental_adaptivecpp)
1313
ROOTTEST_ADD_TEST(nullderef-e
1414
COMMAND ${ROOT_root_CMD} -l -b -q --ptrcheck -e "int*p=nullptr" -e "*p"
1515
PASSRC 1

0 commit comments

Comments
 (0)