forked from taichi-dev/taichi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[gui] GGUI 7.5/n: Avoid requiring CUDA toolchains to compile GGUI (ta…
…ichi-dev#2821) * fix windows * fix setup.py * resolve convo * format
- Loading branch information
1 parent
d71cee2
commit ab88e21
Showing
20 changed files
with
672 additions
and
542 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#include <memory> | ||
|
||
#include "llvm/ADT/StringRef.h" | ||
#include "llvm/Support/DynamicLibrary.h" | ||
#include "llvm/Support/raw_ostream.h" | ||
#include "llvm/Target/TargetMachine.h" | ||
#include "llvm/IR/DataLayout.h" | ||
#include "llvm/IR/LLVMContext.h" | ||
#include "llvm/IR/LegacyPassManager.h" | ||
#include "llvm/IR/Verifier.h" | ||
#include "llvm/Transforms/InstCombine/InstCombine.h" | ||
#include "llvm/Transforms/Scalar.h" | ||
#include "llvm/Transforms/Scalar/GVN.h" | ||
#include "llvm/Transforms/IPO.h" | ||
#include "llvm/Transforms/IPO/PassManagerBuilder.h" | ||
#include "llvm/Analysis/TargetTransformInfo.h" | ||
#include "llvm/Support/TargetRegistry.h" | ||
#include "llvm/Target/TargetMachine.h" | ||
#include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h" | ||
|
||
#include "taichi/backends/cuda/cuda_context.h" | ||
#include "taichi/backends/cuda/cuda_driver.h" | ||
#include "taichi/jit/jit_session.h" | ||
#include "taichi/lang_util.h" | ||
#include "taichi/program/program.h" | ||
#include "taichi/system/timer.h" | ||
#include "taichi/util/file_sequence_writer.h" | ||
|
||
#define TI_RUNTIME_HOST | ||
#include "taichi/program/context.h" | ||
#undef TI_RUNTIME_HOST | ||
|
||
TLANG_NAMESPACE_BEGIN | ||
|
||
#if defined(TI_WITH_CUDA) | ||
class JITModuleCUDA : public JITModule { | ||
private: | ||
void *module; | ||
|
||
public: | ||
explicit JITModuleCUDA(void *module) : module(module) { | ||
} | ||
|
||
void *lookup_function(const std::string &name) override { | ||
// TODO: figure out why using the guard leads to wrong tests results | ||
// auto context_guard = CUDAContext::get_instance().get_guard(); | ||
CUDAContext::get_instance().make_current(); | ||
void *func = nullptr; | ||
auto t = Time::get_time(); | ||
auto err = CUDADriver::get_instance().module_get_function.call_with_warning( | ||
&func, module, name.c_str()); | ||
if (err) { | ||
TI_ERROR("Cannot look up function {}", name); | ||
} | ||
t = Time::get_time() - t; | ||
TI_TRACE("CUDA module_get_function {} costs {} ms", name, t * 1000); | ||
TI_ASSERT(func != nullptr); | ||
return func; | ||
} | ||
|
||
void call(const std::string &name, | ||
const std::vector<void *> &arg_pointers) override { | ||
launch(name, 1, 1, 0, arg_pointers); | ||
} | ||
|
||
virtual void launch(const std::string &name, | ||
std::size_t grid_dim, | ||
std::size_t block_dim, | ||
std::size_t shared_mem_bytes, | ||
const std::vector<void *> &arg_pointers) override { | ||
auto func = lookup_function(name); | ||
CUDAContext::get_instance().launch(func, name, arg_pointers, grid_dim, | ||
block_dim, shared_mem_bytes); | ||
} | ||
|
||
bool direct_dispatch() const override { | ||
return false; | ||
} | ||
}; | ||
|
||
class JITSessionCUDA : public JITSession { | ||
public: | ||
llvm::DataLayout data_layout; | ||
|
||
explicit JITSessionCUDA(llvm::DataLayout data_layout) | ||
: data_layout(data_layout) { | ||
} | ||
|
||
virtual JITModule *add_module(std::unique_ptr<llvm::Module> M, | ||
int max_reg) override; | ||
|
||
virtual llvm::DataLayout get_data_layout() override { | ||
return data_layout; | ||
} | ||
|
||
static std::string compile_module_to_ptx( | ||
std::unique_ptr<llvm::Module> &module); | ||
}; | ||
|
||
#endif | ||
|
||
std::unique_ptr<JITSession> create_llvm_jit_session_cuda(Arch arch); | ||
|
||
TLANG_NAMESPACE_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
extern "C" { | ||
|
||
int thread_idx() { | ||
return 0; | ||
} | ||
|
||
int warp_size() { | ||
return 32; | ||
} | ||
|
||
int warp_idx() { | ||
return thread_idx() % warp_size(); | ||
} | ||
|
||
int block_idx() { | ||
return 0; | ||
} | ||
|
||
int block_dim() { | ||
return 0; | ||
} | ||
|
||
int grid_dim() { | ||
return 0; | ||
} | ||
} |
Oops, something went wrong.