From 17cf95a937de2a06a92d62031f4125565e3f2952 Mon Sep 17 00:00:00 2001 From: kr-2003 Date: Fri, 13 Jun 2025 18:08:54 +0530 Subject: [PATCH] remote jit execution --- include/CppInterOp/CppInterOp.h | 2 +- lib/CppInterOp/Compatibility.h | 35 ++++++++++++++++++++++++-- lib/CppInterOp/CppInterOp.cpp | 6 ++--- lib/CppInterOp/CppInterOpInterpreter.h | 4 +-- 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/include/CppInterOp/CppInterOp.h b/include/CppInterOp/CppInterOp.h index dd091fdd4..2c6a966a8 100644 --- a/include/CppInterOp/CppInterOp.h +++ b/include/CppInterOp/CppInterOp.h @@ -609,7 +609,7 @@ CPPINTEROP_API void GetOperator(TCppScope_t scope, Operator op, ///\returns nullptr on failure. CPPINTEROP_API TInterp_t CreateInterpreter(const std::vector& Args = {}, - const std::vector& GpuArgs = {}); + const std::vector& GpuArgs = {}, bool is_out_of_process = false); /// Deletes an instance of an interpreter. ///\param[in] I - the interpreter to be deleted, if nullptr, deletes the last. diff --git a/lib/CppInterOp/Compatibility.h b/lib/CppInterOp/Compatibility.h index 977603ea0..6be6ee3ae 100644 --- a/lib/CppInterOp/Compatibility.h +++ b/lib/CppInterOp/Compatibility.h @@ -200,10 +200,20 @@ inline void codeComplete(std::vector& Results, #include "llvm/Support/Error.h" +#include "clang/Interpreter/RemoteJITUtils.h" +#include "clang/Basic/Version.h" +#include "llvm/TargetParser/Host.h" + +#include "llvm/ExecutionEngine/Orc/Debugging/DebuggerSupport.h" + +#include "llvm/Support/CommandLine.h" + +static llvm::ExitOnError ExitOnError; + namespace compat { inline std::unique_ptr -createClangInterpreter(std::vector& args) { +createClangInterpreter(std::vector& args, bool is_out_of_process) { auto has_arg = [](const char* x, llvm::StringRef match = "cuda") { llvm::StringRef Arg = x; Arg = Arg.trim().ltrim('-'); @@ -241,10 +251,31 @@ createClangInterpreter(std::vector& args) { (*ciOrErr)->LoadRequestedPlugins(); if (CudaEnabled) DeviceCI->LoadRequestedPlugins(); + + std::unique_ptr JB; + + if(is_out_of_process) { + std::string OOPExecutor = "/Users/abhinavkumar/Desktop/Coding/CERN_HSF_COMPILER_RESEARCH/llvm-project-test/build/bin/llvm-jitlink-executor"; + bool UseSharedMemory = false; + std::string SlabAllocateSizeString = ""; + std::unique_ptr EPC; + EPC = ExitOnError( + launchExecutor(OOPExecutor, UseSharedMemory, SlabAllocateSizeString)); + + + std::string OrcRuntimePath = "/Users/abhinavkumar/Desktop/Coding/CERN_HSF_COMPILER_RESEARCH/llvm-project-test/build/lib/clang/20/lib/darwin/liborc_rt_osx.a"; + 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)); + : clang::Interpreter::create(std::move(*ciOrErr), std::move(JB)); if (!innerOrErr) { llvm::logAllUnhandledErrors(innerOrErr.takeError(), llvm::errs(), diff --git a/lib/CppInterOp/CppInterOp.cpp b/lib/CppInterOp/CppInterOp.cpp index 78c95a307..67362520f 100755 --- a/lib/CppInterOp/CppInterOp.cpp +++ b/lib/CppInterOp/CppInterOp.cpp @@ -2911,11 +2911,11 @@ static std::string MakeResourcesPath() { } // namespace TInterp_t CreateInterpreter(const std::vector& Args /*={}*/, - const std::vector& GpuArgs /*={}*/) { + const std::vector& GpuArgs /*={}*/, bool is_out_of_process) { std::string MainExecutableName = sys::fs::getMainExecutable(nullptr, nullptr); std::string ResourceDir = MakeResourcesPath(); std::vector ClingArgv = {"-resource-dir", ResourceDir.c_str(), - "-std=c++14"}; + "-std=c++14", "-gdwarf-4", "-O0"}; ClingArgv.insert(ClingArgv.begin(), MainExecutableName.c_str()); #ifdef _WIN32 // FIXME : Workaround Sema::PushDeclContext assert on windows @@ -2955,7 +2955,7 @@ TInterp_t CreateInterpreter(const std::vector& Args /*={}*/, auto I = new compat::Interpreter(ClingArgv.size(), &ClingArgv[0]); #else auto Interp = compat::Interpreter::create(static_cast(ClingArgv.size()), - ClingArgv.data()); + ClingArgv.data(), nullptr, {}, nullptr, true, is_out_of_process); if (!Interp) return nullptr; auto* I = Interp.release(); diff --git a/lib/CppInterOp/CppInterOpInterpreter.h b/lib/CppInterOp/CppInterOpInterpreter.h index d87eb33e1..9577879e7 100644 --- a/lib/CppInterOp/CppInterOpInterpreter.h +++ b/lib/CppInterOp/CppInterOpInterpreter.h @@ -150,7 +150,7 @@ class Interpreter { create(int argc, const char* const* argv, const char* llvmdir = nullptr, const std::vector>& moduleExtensions = {}, - void* extraLibHandle = nullptr, bool noRuntime = true) { + void* extraLibHandle = nullptr, bool noRuntime = true, bool is_out_of_process = false) { // Initialize all targets (required for device offloading) llvm::InitializeAllTargetInfos(); llvm::InitializeAllTargets(); @@ -158,7 +158,7 @@ class Interpreter { llvm::InitializeAllAsmPrinters(); std::vector vargs(argv + 1, argv + argc); - auto CI = compat::createClangInterpreter(vargs); + auto CI = compat::createClangInterpreter(vargs, is_out_of_process); if (!CI) { llvm::errs() << "Interpreter creation failed\n"; return nullptr;