-
Notifications
You must be signed in to change notification settings - Fork 31
Adds Out-Of-Process JIT execution for CppInterOp #635
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?
Conversation
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.
clang-tidy made some suggestions
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.
Nice work. I guess there will be multiple rounds of review on this.
string(REGEX REPLACE "/build/lib/cmake/llvm$" "" LLVM_SOURCE_DIR "${LLVM_DIR}") | ||
add_definitions(-DLLVM_SOURCE_DIR="${LLVM_SOURCE_DIR}") |
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.
string(REGEX REPLACE "/build/lib/cmake/llvm$" "" LLVM_SOURCE_DIR "${LLVM_DIR}") | |
add_definitions(-DLLVM_SOURCE_DIR="${LLVM_SOURCE_DIR}") | |
string(REGEX REPLACE "/build/lib/cmake/llvm$" "" LLVM_BINARY_DIR "${LLVM_DIR}") | |
add_definitions(-DLLVM_SOURCE_DIR="${LLVM_BINARY_DIR}") |
I guess is a better name.
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.
LLVM_BINARY_DIR is already an env variable
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.
Can we reuse LLVM_BINARY_DIR
?
#ifdef CPPINTEROP_WITH_OOP_JIT | ||
TEST(InterpreterTest, OopJITProcess) { | ||
#ifdef _WIN32 | ||
GTEST_SKIP() << "Disabled on Windows. Needs fixing."; | ||
#endif | ||
if (llvm::sys::RunningOnValgrind()) | ||
GTEST_SKIP() << "XFAIL due to Valgrind report"; | ||
std::vector<const char*> interpreter_args = { "-include", "new" }; | ||
auto* I = Cpp::CreateInterpreter(interpreter_args, {}, true); | ||
EXPECT_TRUE(Cpp::Process("") == 0); | ||
EXPECT_TRUE(Cpp::Process("int a = 12;") == 0); | ||
EXPECT_FALSE(Cpp::Process("error_here;") == 0); | ||
// Linker/JIT error. | ||
EXPECT_FALSE(Cpp::Process("int f(); int res = f();") == 0); | ||
} | ||
#endif | ||
|
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.
According to this, we only run one test with out-of-process, but we should run all the tests with out-of-process. This should be done through the CI matrix.
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.
yes, i added only this for now to test it out. In the future, all the tests should be ran against out-of-process JIT.
lib/CppInterOp/Compatibility.h
Outdated
std::unique_ptr<llvm::orc::LLJITBuilder> JB; | ||
|
||
if(outOfProcess) { | ||
std::string OOPExecutor = std::string(LLVM_SOURCE_DIR) + "/build/bin/llvm-jitlink-executor"; |
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.
Will this work if LLVM is installed with conda or is installed with the system's package installer.
Could you make sure if working in the other cases too.
You can first check if the file exists; if not, try other paths like the CONDA_PREFIX
or /usr/bin
.
I would prefer if we could keep this as a draft PR. |
clang-tidy review says "All clean, LGTM! 👍" |
clang-tidy review says "All clean, LGTM! 👍" |
elif [[ "${{ runner.os }}" == "macOS" ]]; then | ||
ninja clang clang-repl llvm-jitlink-executor orc_rt_osx -j ${{ env.ncpus }} | ||
fi | ||
fi |
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.
Why do we have target name for orc_rt difference for MacOS? The target name should be independent of the system your building on.
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.
It is different in LLVM itself. I guess it might have to do with cross-compiling.
if [[ "${{ matrix.oop-jit }}" == "On" ]]; then | ||
git apply -v ../patches/llvm/clang20-1-out-of-process-jit-execution.patch | ||
echo "Apply out-of-process-jit-execution.patch:" | ||
fi |
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.
We should apply this patch regardless of whether matrix.oop-jit=on. If you only apply it if CPPINTEROP_WITH_OOP_JIT=ON , this would imply if you apply the patch, DCPPINTEROP_WITH_OOP_JIT=OFF, then somehow something will go wrong.
Also, why are we not applying this patch on Windows, and testing CPPINTEROP_WITH_OOP_JIT=ON/OFF?
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.
Ok. The thing is, I would want CppInterOp to be compatible with upstream LLVM as well as the patched LLVM. Therefore, I was thinking about having 2 different CI workflows for version 20 with OOP-JIT and without OOP-JIT.
OOP-JIT is not supported on Windows.
Ideally, this is temporary till the patch is directly merged into LLVM and a new version is released.
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.
I could be wrong, and @vgvassilev can correct me if I am wrong, but for such large patches, we have had them merged into llvm first, before applying them to previous versions in CppInterOp.
You could have a new llvm cache like you want. One where you build OOP-JIT and without OOP-JIT. This could only really be done after I find a way to make space in the cache, since we currently are unlikely to have enough space for all these new llvm cache builds. I have an idea on how to free up some space, and just need to find some time to do. I will try and do it tomorrow, as I am busy today.
-DCODE_COVERAGE=${{ env.CODE_COVERAGE }} \ | ||
-DCMAKE_INSTALL_PREFIX=$CPPINTEROP_DIR \ | ||
-DLLVM_ENABLE_WERROR=On \ | ||
-DCPPINTEROP_WITH_OOP_JIT=OFF \ |
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.
Feels like CPPINTEROP_WITH_OOP_JIT should have a default value, like we have for cppinterop_use_repl/cppinterop_use_cling
@@ -0,0 +1,710 @@ | |||
diff --git a/clang/include/clang/Interpreter/Interpreter.h b/clang/include/clang/Interpreter/Interpreter.h |
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.
This is quite a large patch. Can you confirm that it has been upsteamed so will appear in llvm 21?
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.
clang-tidy made some suggestions
clang-tidy review says "All clean, LGTM! 👍" |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #635 +/- ##
==========================================
- Coverage 78.69% 78.59% -0.10%
==========================================
Files 9 9
Lines 3835 3841 +6
==========================================
+ Hits 3018 3019 +1
- Misses 817 822 +5
🚀 New features to boost your workflow:
|
+launchExecutor(llvm::StringRef ExecutablePath, bool UseSharedMemory, | ||
+ llvm::StringRef SlabAllocateSizeString); |
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.
+launchExecutor(llvm::StringRef ExecutablePath, bool UseSharedMemory, | |
+ llvm::StringRef SlabAllocateSizeString); | |
+launchExecutor(llvm::StringRef ExecutablePath, bool UseSharedMemory, | |
+ llvm::StringRef SlabAllocateSizeString, int stdin_fd = 0, int stdout_fd = 1, int stderr_fd = 2); |
+ dup2(StdoutPipe[WriteEnd], STDOUT_FILENO); | ||
+ dup2(StderrPipe[WriteEnd], STDERR_FILENO); |
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.
+ dup2(StdoutPipe[WriteEnd], STDOUT_FILENO); | |
+ dup2(StderrPipe[WriteEnd], STDERR_FILENO); | |
+ if (stdout_fd != 1) ... | |
+ dup2(stdout_fd, STDOUT_FILENO); | |
+ dup2(StderrPipe[WriteEnd], STDERR_FILENO); |
Description
Please include a summary of changes, motivation and context for this PR.
Fixes # (issue)
Type of change
Please tick all options which are relevant.
Testing
Please describe the test(s) that you added and ran to verify your changes.
Checklist