-
Notifications
You must be signed in to change notification settings - Fork 0
Adds out-of-process JIT execution in CppInterOp #4
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
base: main
Are you sure you want to change the base?
Changes from 9 commits
5a1cac3
eea2a1c
3ac5647
cc3f601
4396765
5536edf
fac8d38
9510241
34d5670
e562d13
13a0caf
43220d7
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 | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -205,10 +205,22 @@ inline void codeComplete(std::vector<std::string>& Results, | |||||||
|
|
||||||||
| #include "llvm/Support/Error.h" | ||||||||
|
|
||||||||
| #include <vector> | ||||||||
|
|
||||||||
| #ifdef CPPINTEROP_WITH_OOP_JIT | ||||||||
| #include "clang/Basic/Version.h" | ||||||||
|
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. warning: #includes are not sorted properly [llvm-include-order]
Suggested change
|
||||||||
| #include "clang/Interpreter/RemoteJITUtils.h" | ||||||||
| #include "llvm/TargetParser/Host.h" | ||||||||
|
|
||||||||
| #include "llvm/ExecutionEngine/Orc/Debugging/DebuggerSupport.h" | ||||||||
| #endif | ||||||||
|
|
||||||||
| static const llvm::ExitOnError ExitOnError; | ||||||||
|
|
||||||||
| namespace compat { | ||||||||
|
|
||||||||
| inline std::unique_ptr<clang::Interpreter> | ||||||||
| createClangInterpreter(std::vector<const char*>& args) { | ||||||||
| createClangInterpreter(std::vector<const char*>& args, bool outOfProcess) { | ||||||||
|
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. warning: no header providing "std::vector" is directly included [misc-include-cleaner] lib/CppInterOp/Compatibility.h:10: + #include <vector> |
||||||||
| auto has_arg = [](const char* x, llvm::StringRef match = "cuda") { | ||||||||
| llvm::StringRef Arg = x; | ||||||||
| Arg = Arg.trim().ltrim('-'); | ||||||||
|
|
@@ -246,16 +258,62 @@ createClangInterpreter(std::vector<const char*>& args) { | |||||||
| (*ciOrErr)->LoadRequestedPlugins(); | ||||||||
| if (CudaEnabled) | ||||||||
| DeviceCI->LoadRequestedPlugins(); | ||||||||
|
|
||||||||
| #ifdef CPPINTEROP_WITH_OOP_JIT | ||||||||
| std::unique_ptr<llvm::orc::LLJITBuilder> JB; | ||||||||
|
|
||||||||
| if (outOfProcess) { | ||||||||
| std::string OOPExecutor = | ||||||||
| std::string(LLVM_SOURCE_DIR) + "/build/bin/llvm-jitlink-executor"; | ||||||||
| bool UseSharedMemory = false; | ||||||||
| std::string SlabAllocateSizeString = ""; | ||||||||
| std::unique_ptr<llvm::orc::ExecutorProcessControl> EPC; | ||||||||
| EPC = ExitOnError( | ||||||||
| launchExecutor(OOPExecutor, UseSharedMemory, SlabAllocateSizeString)); | ||||||||
|
|
||||||||
| #ifdef __APPLE__ | ||||||||
| std::string OrcRuntimePath = | ||||||||
| std::string(LLVM_SOURCE_DIR) + | ||||||||
| "/build/lib/clang/20/lib/darwin/liborc_rt_osx.a"; | ||||||||
| #else | ||||||||
| std::string OrcRuntimePath = | ||||||||
| std::string(LLVM_SOURCE_DIR) + | ||||||||
| "/build/lib/x86_64-unknown-linux-gnu/liborc_rt.a"; | ||||||||
| #endif | ||||||||
| if (EPC) { | ||||||||
|
|
||||||||
| CB.SetTargetTriple(EPC->getTargetTriple().getTriple()); | ||||||||
| JB = ExitOnError(clang::Interpreter::createLLJITBuilder(std::move(EPC), | ||||||||
| OrcRuntimePath)); | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| auto innerOrErr = | ||||||||
| CudaEnabled | ||||||||
| ? clang::Interpreter::createWithCUDA(std::move(*ciOrErr), | ||||||||
| std::move(DeviceCI)) | ||||||||
| : clang::Interpreter::create(std::move(*ciOrErr), std::move(JB)); | ||||||||
| #else | ||||||||
| if (outOfProcess) { | ||||||||
| llvm::errs() | ||||||||
| << "[CreateClangInterpreter]: No compatibility with out-of-process JIT" | ||||||||
| << "(To enable recompile CppInterOp with " | ||||||||
| "`-DCPPINTEROP_WITH_OOP_JIT=ON`)" | ||||||||
| << "\n"; | ||||||||
| return nullptr; | ||||||||
| } | ||||||||
| auto innerOrErr = | ||||||||
| CudaEnabled ? clang::Interpreter::createWithCUDA(std::move(*ciOrErr), | ||||||||
| std::move(DeviceCI)) | ||||||||
| : clang::Interpreter::create(std::move(*ciOrErr)); | ||||||||
| #endif | ||||||||
|
|
||||||||
| if (!innerOrErr) { | ||||||||
| llvm::logAllUnhandledErrors(innerOrErr.takeError(), llvm::errs(), | ||||||||
| "Failed to build Interpreter:"); | ||||||||
| return nullptr; | ||||||||
| } | ||||||||
|
|
||||||||
| if (CudaEnabled) { | ||||||||
| if (auto Err = (*innerOrErr)->LoadDynamicLibrary("libcudart.so")) { | ||||||||
| llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), | ||||||||
|
|
@@ -371,6 +429,10 @@ inline void codeComplete(std::vector<std::string>& Results, | |||||||
| #endif | ||||||||
| } | ||||||||
|
|
||||||||
| inline pid_t getExecutorPID() { | ||||||||
|
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. warning: no header providing "pid_t" is directly included [misc-include-cleaner] lib/CppInterOp/Compatibility.h:10: + #include <sched.h> |
||||||||
| return getLastLaunchedExecutorPID(); | ||||||||
|
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. warning: use of undeclared identifier 'getLastLaunchedExecutorPID' [clang-diagnostic-error] return getLastLaunchedExecutorPID();
^ |
||||||||
| } | ||||||||
|
|
||||||||
| } // namespace compat | ||||||||
|
|
||||||||
| #include "CppInterOpInterpreter.h" | ||||||||
|
|
@@ -395,7 +457,7 @@ class SynthesizingCodeRAII { | |||||||
| "Failed to generate PTU:"); | ||||||||
| } | ||||||||
| }; | ||||||||
| } | ||||||||
| } // namespace compat | ||||||||
|
|
||||||||
| #endif // CPPINTEROP_USE_REPL | ||||||||
|
|
||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3031,7 +3031,7 @@ static std::string MakeResourcesPath() { | |
| } // namespace | ||
|
|
||
| TInterp_t CreateInterpreter(const std::vector<const char*>& Args /*={}*/, | ||
| const std::vector<const char*>& GpuArgs /*={}*/) { | ||
| const std::vector<const char*>& GpuArgs /*={}*/, bool outOfProcess) { | ||
| std::string MainExecutableName = sys::fs::getMainExecutable(nullptr, nullptr); | ||
| std::string ResourceDir = MakeResourcesPath(); | ||
| std::vector<const char*> ClingArgv = {"-resource-dir", ResourceDir.c_str(), | ||
|
|
@@ -3075,7 +3075,7 @@ TInterp_t CreateInterpreter(const std::vector<const char*>& Args /*={}*/, | |
| auto I = new compat::Interpreter(ClingArgv.size(), &ClingArgv[0]); | ||
| #else | ||
| auto Interp = compat::Interpreter::create(static_cast<int>(ClingArgv.size()), | ||
| ClingArgv.data()); | ||
| ClingArgv.data(), nullptr, {}, nullptr, true, outOfProcess); | ||
| if (!Interp) | ||
| return nullptr; | ||
| auto* I = Interp.release(); | ||
|
|
@@ -3909,4 +3909,8 @@ int Undo(unsigned N) { | |
| #endif | ||
| } | ||
|
|
||
| pid_t GetExecutorPID() { | ||
|
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. warning: no header providing "pid_t" is directly included [misc-include-cleaner] lib/CppInterOp/CppInterOp.cpp:40: - #if CLANG_VERSION_MAJOR >= 19
+ #include <sys/types.h>
+ #if CLANG_VERSION_MAJOR >= 19 |
||
| return compat::getExecutorPID(); | ||
| } | ||
|
|
||
| } // end namespace Cpp | ||
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.
warning: no header providing "pid_t" is directly included [misc-include-cleaner]
include/CppInterOp/CppInterOp.h:21: