-
Notifications
You must be signed in to change notification settings - Fork 0
Jit oop exec dummy #5
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 all commits
5a1cac3
eea2a1c
3ac5647
cc3f601
4396765
5536edf
fac8d38
9510241
34d5670
e562d13
13a0caf
43220d7
0f2d6f2
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 | ||||
---|---|---|---|---|---|---|
|
@@ -58,6 +58,15 @@ and | |||||
|
||||||
on Windows. | ||||||
|
||||||
If you want to have out-of-process JIT execution enabled in CppInterOp, then apply this patch on Linux and MacOS environment. | ||||||
.. note:: | ||||||
|
||||||
This patch will not work for Windows because out-of-process JIT execution is currently implemented for Linux and MacOS only. | ||||||
|
||||||
.. code:: bash | ||||||
|
||||||
git apply -v ../CppInterOp/patches/llvm/clang20-2-out-of-process-jit-execution.patch | ||||||
|
||||||
****************** | ||||||
Build Clang-REPL | ||||||
****************** | ||||||
|
@@ -116,6 +125,36 @@ On Windows you execute the following | |||||
$env:LLVM_DIR= $PWD.Path | ||||||
cd ..\ | ||||||
|
||||||
*************************************************** | ||||||
Build Clang-REPL with Out-of-Process JIT Execution | ||||||
*************************************************** | ||||||
|
||||||
To have `Out-of-Process JIT Execution` enabled, run following commands to build clang and clang-repl to support this feature: | ||||||
|
||||||
.. note:: | ||||||
|
||||||
Only for Linux and Macos | ||||||
|
||||||
.. code:: bash | ||||||
|
||||||
mkdir build | ||||||
cd build | ||||||
cmake -DLLVM_ENABLE_PROJECTS="clang;compiler-rt \ | ||||||
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. . |
||||||
-DLLVM_TARGETS_TO_BUILD="host;NVPTX" \ | ||||||
-DCMAKE_BUILD_TYPE=Release \ | ||||||
-DLLVM_ENABLE_ASSERTIONS=ON \ | ||||||
-DCLANG_ENABLE_STATIC_ANALYZER=OFF \ | ||||||
-DCLANG_ENABLE_ARCMT=OFF \ | ||||||
-DCLANG_ENABLE_FORMAT=OFF \ | ||||||
-DCLANG_ENABLE_BOOTSTRAP=OFF \ | ||||||
../llvm | ||||||
|
||||||
# For Linux | ||||||
cmake --build . --target clang clang-repl llvm-jitlink-executor orc_rt --parallel $(nproc --all) | ||||||
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. In my system (Linux - X86-64) the target is:
Suggested change
|
||||||
|
||||||
# For MacOS | ||||||
cmake --build . --target clang clang-repl llvm-jitlink-executor orc_rt_osx --parallel $(sysctl -n hw.ncpu) | ||||||
|
||||||
************************************** | ||||||
Build Cling and related dependencies | ||||||
************************************** | ||||||
|
@@ -280,6 +319,10 @@ commands on Linux and MacOS | |||||
cmake -DBUILD_SHARED_LIBS=ON -DLLVM_DIR=$LLVM_DIR/build/lib/cmake/llvm -DClang_DIR=$LLVM_DIR/build/lib/cmake/clang -DCMAKE_INSTALL_PREFIX=$CPPINTEROP_DIR .. | ||||||
cmake --build . --target install --parallel $(nproc --all) | ||||||
|
||||||
.. note:: | ||||||
|
||||||
Do make sure to add `-DCPPINTEROP_WITH_OOP_JIT=ON`, if you want to have out-of-process JIT execution feature enabled. | ||||||
|
||||||
and | ||||||
|
||||||
.. code:: powershell | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -665,7 +665,7 @@ CPPINTEROP_API void GetOperator(TCppScope_t scope, Operator op, | |
///\returns nullptr on failure. | ||
CPPINTEROP_API TInterp_t | ||
CreateInterpreter(const std::vector<const char*>& Args = {}, | ||
const std::vector<const char*>& GpuArgs = {}); | ||
const std::vector<const char*>& GpuArgs = {}, bool outOfProcess = false); | ||
|
||
/// Deletes an instance of an interpreter. | ||
///\param[in] I - the interpreter to be deleted, if nullptr, deletes the last. | ||
|
@@ -901,6 +901,10 @@ CPPINTEROP_API void CodeComplete(std::vector<std::string>& Results, | |
///\returns 0 on success, non-zero on failure. | ||
CPPINTEROP_API int Undo(unsigned N = 1); | ||
|
||
CPPINTEROP_API 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] include/CppInterOp/CppInterOp.h:21: - #include <vector>
+ #include <sys/types.h>
+ #include <vector> |
||
|
||
// CPPINTEROP_API void SendInputToChild(const std::string& input); | ||
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. If this is not yet implemented, it should not be part of the PR. Even as a comment. |
||
|
||
} // end namespace Cpp | ||
|
||
#endif // CPPINTEROP_CPPINTEROP_H |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -205,10 +205,27 @@ inline void codeComplete(std::vector<std::string>& Results, | |||||
|
||||||
#include "llvm/Support/Error.h" | ||||||
|
||||||
#include <vector> | ||||||
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] #include <vector>
^ this fix will not be applied because it overlaps with another fix |
||||||
#include <unistd.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: included header unistd.h is not used directly [misc-include-cleaner]
Suggested change
|
||||||
#ifdef CPPINTEROP_WITH_OOP_JIT | ||||||
#include "clang/Basic/Version.h" | ||||||
#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 { | ||||||
|
||||||
static int m_child_stdout_fd = -1; | ||||||
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: variable 'm_child_stdout_fd' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables] static int m_child_stdout_fd = -1;
^ |
||||||
static int m_child_stderr_fd = -1; | ||||||
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: variable 'm_child_stderr_fd' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables] static int m_child_stderr_fd = -1;
^ |
||||||
// static int m_child_stdin_fd = -1; | ||||||
|
||||||
inline std::unique_ptr<clang::Interpreter> | ||||||
createClangInterpreter(std::vector<const char*>& args) { | ||||||
createClangInterpreter(std::vector<const char*>& args, bool outOfProcess) { | ||||||
auto has_arg = [](const char* x, llvm::StringRef match = "cuda") { | ||||||
llvm::StringRef Arg = x; | ||||||
Arg = Arg.trim().ltrim('-'); | ||||||
|
@@ -246,16 +263,78 @@ 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; | ||||||
|
||||||
// Create pipes for child process I/O control | ||||||
int stdout_pipe[2], stderr_pipe[2], stdin_pipe[2]; | ||||||
if (pipe(stdout_pipe) != 0 || pipe(stderr_pipe) != 0 || pipe(stdin_pipe)) { | ||||||
llvm::errs() << "Failed to create pipes for child process I/O\n"; | ||||||
return nullptr; | ||||||
} | ||||||
|
||||||
EPC = ExitOnError( | ||||||
launchExecutor(OOPExecutor, UseSharedMemory, SlabAllocateSizeString, | ||||||
/*stdin_pipe[0]*/0, stdout_pipe[1], stderr_pipe[1])); | ||||||
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. Why are you not yet using the stdin pipe? |
||||||
|
||||||
close(stdout_pipe[1]); | ||||||
close(stderr_pipe[1]); | ||||||
// close(stdin_pipe[1]); | ||||||
|
||||||
m_child_stdout_fd = stdout_pipe[0]; | ||||||
m_child_stderr_fd = stderr_pipe[0]; | ||||||
// m_child_stdin_fd = stdin_pipe[1]; | ||||||
|
||||||
#ifdef __APPLE__ | ||||||
std::string OrcRuntimePath = | ||||||
std::string(LLVM_SOURCE_DIR) + | ||||||
"/build/lib/clang/20/lib/darwin/liborc_rt_osx.a"; | ||||||
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.
Suggested change
|
||||||
#else | ||||||
std::string OrcRuntimePath = | ||||||
std::string(LLVM_SOURCE_DIR) + | ||||||
"/build/lib/x86_64-unknown-linux-gnu/liborc_rt.a"; | ||||||
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. The path on my Linux machine is:
Suggested change
|
||||||
#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 +450,12 @@ inline void codeComplete(std::vector<std::string>& Results, | |||||
#endif | ||||||
} | ||||||
|
||||||
#ifdef CPPINTEROP_WITH_OOP_JIT | ||||||
inline pid_t getExecutorPID() { | ||||||
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. Can we specify the namespace to make it clear that |
||||||
} | ||||||
#endif // CPPINTEROP_WITH_OOP_JIT | ||||||
|
||||||
} // namespace compat | ||||||
|
||||||
#include "CppInterOpInterpreter.h" | ||||||
|
@@ -395,7 +480,7 @@ class SynthesizingCodeRAII { | |||||
"Failed to generate PTU:"); | ||||||
} | ||||||
}; | ||||||
} | ||||||
} // namespace compat | ||||||
|
||||||
#endif // CPPINTEROP_USE_REPL | ||||||
|
||||||
|
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.