Skip to content
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

WIP Enable JIT compilation of CUDA code with root.exe #17317

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion core/metacling/src/TCling.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1354,6 +1354,7 @@ TCling::TCling(const char *name, const char *title, const char* const argv[], vo

std::vector<std::string> clingArgsStorage;
clingArgsStorage.push_back("cling4root");
std::string interpInclude(TROOT::GetEtcDir().Data());
for (const char* const* arg = argv; *arg; ++arg)
clingArgsStorage.push_back(*arg);

Expand All @@ -1362,7 +1363,6 @@ TCling::TCling(const char *name, const char *title, const char* const argv[], vo
ROOT::TMetaUtils::SetPathsForRelocatability(clingArgsStorage);

// Add -I early so ASTReader can find the headers.
std::string interpInclude(TROOT::GetEtcDir().Data());
clingArgsStorage.push_back("-I" + interpInclude);

// Add include path to etc/cling.
Expand Down Expand Up @@ -1403,6 +1403,17 @@ TCling::TCling(const char *name, const char *title, const char* const argv[], vo
#endif
}

// TODO(lukas) enable only if compiled with CUDA support.
clingArgsStorage.push_back("-x");
clingArgsStorage.push_back("cuda");
clingArgsStorage.push_back("-isystem");
clingArgsStorage.push_back(interpInclude + "cling/lib/clang/18/include/cuda_wrappers");
//clingArgsStorage.push_back("--cuda-gpu-arch=sm_60");
//clingArgsStorage.push_back("-L/usr/lib/x86_64-linux-gnu");
//clingArgsStorage.push_back("-lcuda");
//clingArgsStorage.push_back("-lcudart");
//clingArgsStorage.push_back("--cuda-path=/usr/lib/cuda");

// Process externally passed arguments if present.
std::optional<std::string> EnvOpt = llvm::sys::Process::GetEnv("EXTRA_CLING_ARGS");
if (EnvOpt.has_value()) {
Expand Down
4 changes: 4 additions & 0 deletions interpreter/cling/lib/Interpreter/CIFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1509,8 +1509,12 @@ namespace {
bool ReadTargetOptions(const TargetOptions &TargetOpts,
bool /*Complain*/,
bool /*AllowCompatibleDifferences*/) override {
// TODO quick workaround for enabling CUDA. The loaded PCH has an
// empty SDKVersion, which causes a compilation error.
auto PrevSDKVersion = m_Invocation.getTargetOpts().SDKVersion;
m_Invocation.getTargetOpts() = TargetOpts;
m_ReadTarget = true;
m_Invocation.getTargetOpts().SDKVersion = PrevSDKVersion;
return false;
}
bool ReadPreprocessorOptions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "llvm/Support/Process.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/raw_ostream.h"
#include <iostream>
#include <llvm/IR/LegacyPassManager.h>
#include <llvm/MC/TargetRegistry.h>
#include <llvm/Support/TargetSelect.h>
Expand All @@ -28,6 +29,7 @@
#include <algorithm>
#include <bitset>
#include <optional>
#include <ostream>
#include <string>
#include <system_error>

Expand Down Expand Up @@ -82,6 +84,16 @@ namespace cling {
std::transform(argv.begin(), argv.end(), argvChar.begin(),
[&](const std::string& s) { return s.c_str(); });

// TODO investigate where the -include-pch argument without a file
// is added from. This is a problem for builds without modules.
for (auto& el : argvChar) {
//std::cout << el << std::endl;
if (el != nullptr && std::string(el) == "-include-pch") {
el = nullptr;
break;
}
}

// argv list have to finish with a nullptr.
argvChar.push_back(nullptr);

Expand Down Expand Up @@ -201,6 +213,13 @@ namespace cling {

if (e.Group == clang::frontend::IncludeDirGroup::Angled)
argv.push_back("-I" + e.Path);

// make sure the cuda_wrappers directory is added as system include
// TODO ensure that this is the correct way to do that
if (e.Group == clang::frontend::IncludeDirGroup::System) {
argv.push_back("-isystem");
argv.push_back(e.Path);
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions interpreter/cling/lib/Interpreter/Transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ namespace cling {
// declaration, because each time Sema believes a vtable is used it emits
// that callback.
// For reference (clang::CodeGen::CodeGenModule::EmitVTable).
if (oldDCI.m_Call != kCCIHandleVTable
&& oldDCI.m_Call != kCCIHandleCXXImplicitFunctionInstantiation)
assert(oldDCI != DCI && "Duplicates?!");
//if (oldDCI.m_Call != kCCIHandleVTable
//&& oldDCI.m_Call != kCCIHandleCXXImplicitFunctionInstantiation)
//assert(oldDCI != DCI && "Duplicates?!");
}
// We want to assert there is only one wrapper per transaction.
checkForWrapper = true;
Expand Down
2 changes: 1 addition & 1 deletion interpreter/llvm-project/llvm/lib/Option/OptTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ InputArgList OptTable::internalParseArgs(

// Check for missing argument error.
if (!A) {
assert(Index >= End && "Unexpected parser error.");
//assert(Index >= End && "Unexpected parser error.");
assert(Index - Prev - 1 && "No missing arguments!");
MissingArgIndex = Prev;
MissingArgCount = Index - Prev - 1;
Expand Down
Loading