-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[llvm] [aot] Add LLVM to CAPI part 1: Implemented capi::LlvmRuntime c…
…lass (#5393) * [llvm] [aot] Add LLVM to CAPI part 1: Implement capi::LlvmRuntime class * Added LlvmRuntime initialization to ti_create_runtime() * Fixed issue with use of memory pool * Fixed minor issue
- Loading branch information
1 parent
df63f8f
commit c40e19a
Showing
7 changed files
with
156 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include "taichi_core_impl.h" | ||
#include "taichi_llvm_impl.h" | ||
|
||
#ifdef TI_WITH_LLVM | ||
|
||
#include "taichi/runtime/llvm/llvm_runtime_executor.h" | ||
|
||
namespace capi { | ||
|
||
LlvmRuntime::LlvmRuntime(taichi::Arch arch) : Runtime(arch) { | ||
taichi::lang::CompileConfig cfg; | ||
cfg.arch = arch; | ||
executor_ = std::make_unique<taichi::lang::LlvmRuntimeExecutor>(cfg, nullptr); | ||
|
||
taichi::lang::Device *compute_device = executor_->get_compute_device(); | ||
memory_pool_ = | ||
taichi::arch_is_cpu(arch) | ||
? std::make_unique<taichi::lang::MemoryPool>(arch, compute_device) | ||
: nullptr; | ||
|
||
// materialize_runtime() takes in a uint64_t** (pointer object's address) and | ||
// modifies the address it points to. | ||
// | ||
// Therefore we can't use host_result_buffer_.data() here, | ||
// since it returns a temporary copy of the internal data pointer, | ||
// thus we won't be able to modify the address where the std::array's data | ||
// pointer is pointing to. | ||
executor_->materialize_runtime(memory_pool_.get(), nullptr /*kNoProfiler*/, | ||
&result_buffer); | ||
} | ||
|
||
taichi::lang::Device &LlvmRuntime::get() { | ||
taichi::lang::Device *device = executor_->get_compute_device(); | ||
return *device; | ||
} | ||
|
||
TiAotModule LlvmRuntime::load_aot_module(const char *module_path) { | ||
TI_NOT_IMPLEMENTED; | ||
} | ||
|
||
void LlvmRuntime::buffer_copy(const taichi::lang::DevicePtr &dst, | ||
const taichi::lang::DevicePtr &src, | ||
size_t size) { | ||
TI_NOT_IMPLEMENTED; | ||
} | ||
|
||
void LlvmRuntime::submit() { | ||
TI_NOT_IMPLEMENTED; | ||
} | ||
|
||
void LlvmRuntime::wait() { | ||
TI_NOT_IMPLEMENTED; | ||
} | ||
|
||
} // namespace capi | ||
|
||
#endif // TI_WITH_LLVM |
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,41 @@ | ||
#pragma once | ||
|
||
#ifdef TI_WITH_LLVM | ||
#include "taichi_core_impl.h" | ||
|
||
namespace taichi { | ||
namespace lang { | ||
class LlvmRuntimeExecutor; | ||
class MemoryPool; | ||
} // namespace lang | ||
} // namespace taichi | ||
|
||
namespace capi { | ||
|
||
class LlvmRuntime : public Runtime { | ||
public: | ||
LlvmRuntime(taichi::Arch arch); | ||
|
||
private: | ||
/* Internally used interfaces */ | ||
taichi::lang::Device &get() override; | ||
|
||
TiAotModule load_aot_module(const char *module_path) override; | ||
|
||
void buffer_copy(const taichi::lang::DevicePtr &dst, | ||
const taichi::lang::DevicePtr &src, | ||
size_t size) override; | ||
|
||
void submit() override; | ||
|
||
void wait() override; | ||
|
||
private: | ||
taichi::uint64 *result_buffer{nullptr}; | ||
std::unique_ptr<taichi::lang::LlvmRuntimeExecutor> executor_{nullptr}; | ||
std::unique_ptr<taichi::lang::MemoryPool> memory_pool_{nullptr}; | ||
}; | ||
|
||
} // namespace capi | ||
|
||
#endif // TI_WITH_LLVM |
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,37 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
|
||
#include "llvm/IR/Module.h" | ||
|
||
namespace taichi { | ||
namespace lang { | ||
|
||
class OffloadedTask { | ||
public: | ||
std::string name; | ||
int block_dim{0}; | ||
int grid_dim{0}; | ||
|
||
OffloadedTask(const std::string &name = "", | ||
int block_dim = 0, | ||
int grid_dim = 0) | ||
: name(name), block_dim(block_dim), grid_dim(grid_dim){}; | ||
TI_IO_DEF(name, block_dim, grid_dim); | ||
}; | ||
|
||
struct LLVMCompiledData { | ||
std::vector<OffloadedTask> tasks; | ||
std::unique_ptr<llvm::Module> module{nullptr}; | ||
LLVMCompiledData() = default; | ||
LLVMCompiledData(LLVMCompiledData &&) = default; | ||
LLVMCompiledData(std::vector<OffloadedTask> tasks, | ||
std::unique_ptr<llvm::Module> module) | ||
: tasks(std::move(tasks)), module(std::move(module)) { | ||
} | ||
LLVMCompiledData clone() const; | ||
TI_IO_DEF(tasks); | ||
}; | ||
|
||
} // namespace lang | ||
} // namespace taichi |
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