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

[refactor] Get rid of unnecessary snodes map in Program class. #3234

Merged
merged 1 commit into from
Oct 20, 2021
Merged
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
1 change: 0 additions & 1 deletion taichi/backends/cc/cc_program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ void CCProgramImpl::materialize_runtime(MemoryPool *memory_pool,
void CCProgramImpl::materialize_snode_tree(
SNodeTree *tree,
std::vector<std::unique_ptr<SNodeTree>> &,
std::unordered_map<int, SNode *> &,
uint64 *result_buffer) {
auto *const root = tree->root();
CCLayoutGen gen(this, root);
Expand Down
1 change: 0 additions & 1 deletion taichi/backends/cc/cc_program.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class CCProgramImpl : public ProgramImpl {

void materialize_snode_tree(SNodeTree *tree,
std::vector<std::unique_ptr<SNodeTree>> &,
std::unordered_map<int, SNode *> &,
uint64 *result_buffer) override;

void synchronize() override {
Expand Down
1 change: 0 additions & 1 deletion taichi/backends/metal/metal_program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ void MetalProgramImpl::materialize_runtime(MemoryPool *memory_pool,
void MetalProgramImpl::materialize_snode_tree(
SNodeTree *tree,
std::vector<std::unique_ptr<SNodeTree>> &,
std::unordered_map<int, SNode *> &,
uint64 *result_buffer) {
// TODO: support materializing multiple snode trees
TI_ASSERT_INFO(config->use_llvm,
Expand Down
1 change: 0 additions & 1 deletion taichi/backends/metal/metal_program.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class MetalProgramImpl : public ProgramImpl {
void materialize_snode_tree(
SNodeTree *tree,
std::vector<std::unique_ptr<SNodeTree>> &snode_trees_,
std::unordered_map<int, SNode *> &snodes,
uint64 *result_buffer) override;

void synchronize() override {
Expand Down
1 change: 0 additions & 1 deletion taichi/backends/opengl/opengl_program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ void OpenglProgramImpl::compile_snode_tree_types(SNodeTree *tree) {
void OpenglProgramImpl::materialize_snode_tree(
SNodeTree *tree,
std::vector<std::unique_ptr<SNodeTree>> &,
std::unordered_map<int, SNode *> &,
uint64 *result_buffer) {
#ifdef TI_WITH_OPENGL
compile_snode_tree_types(tree);
Expand Down
1 change: 0 additions & 1 deletion taichi/backends/opengl/opengl_program.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class OpenglProgramImpl : public ProgramImpl {
void materialize_snode_tree(
SNodeTree *tree,
std::vector<std::unique_ptr<SNodeTree>> &snode_trees_,
std::unordered_map<int, SNode *> &snodes,
uint64 *result_buffer) override;

void synchronize() override {
Expand Down
1 change: 0 additions & 1 deletion taichi/backends/vulkan/vulkan_program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ void VulkanProgramImpl::materialize_runtime(MemoryPool *memory_pool,
void VulkanProgramImpl::materialize_snode_tree(
SNodeTree *tree,
std::vector<std::unique_ptr<SNodeTree>> &,
std::unordered_map<int, SNode *> &,
uint64 *result_buffer) {
vulkan_runtime_->materialize_snode_tree(tree);
}
Expand Down
1 change: 0 additions & 1 deletion taichi/backends/vulkan/vulkan_program.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class VulkanProgramImpl : public ProgramImpl {

void materialize_snode_tree(SNodeTree *tree,
std::vector<std::unique_ptr<SNodeTree>> &,
std::unordered_map<int, SNode *> &,
uint64 *result_buffer) override;

void synchronize() override {
Expand Down
18 changes: 7 additions & 11 deletions taichi/llvm/llvm_program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,20 +218,16 @@ void LlvmProgramImpl::initialize_llvm_runtime_snodes(const SNodeTree *tree,
void LlvmProgramImpl::materialize_snode_tree(
SNodeTree *tree,
std::vector<std::unique_ptr<SNodeTree>> &snode_trees_,
std::unordered_map<int, SNode *> &snodes,
uint64 *result_buffer) {
auto *const root = tree->root();
auto host_module = clone_struct_compiler_initial_context(
snode_trees_, llvm_context_host.get());
std::unique_ptr<StructCompiler> scomp = std::make_unique<StructCompilerLLVM>(
host_arch(), this, std::move(host_module));
scomp->run(*root);

for (auto snode : scomp->snodes) {
snodes[snode->id] = snode;
}

if (arch_is_cpu(config->arch)) {
auto host_module = clone_struct_compiler_initial_context(
snode_trees_, llvm_context_host.get());
std::unique_ptr<StructCompiler> scomp =
std::make_unique<StructCompilerLLVM>(host_arch(), this,
std::move(host_module));
scomp->run(*root);

initialize_llvm_runtime_snodes(tree, scomp.get(), result_buffer);
} else if (config->arch == Arch::cuda) {
auto device_module = clone_struct_compiler_initial_context(
Expand Down
1 change: 0 additions & 1 deletion taichi/llvm/llvm_program.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ class LlvmProgramImpl : public ProgramImpl {
void materialize_snode_tree(
SNodeTree *tree,
std::vector<std::unique_ptr<SNodeTree>> &snode_trees_,
std::unordered_map<int, SNode *> &snodes,
uint64 *result_buffer) override;

template <typename T>
Expand Down
3 changes: 1 addition & 2 deletions taichi/program/async_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,10 @@ ExecutionQueue::ExecutionQueue(
}

AsyncEngine::AsyncEngine(const CompileConfig *const config,
const std::unordered_map<int, SNode *> &snodes,
const BackendExecCompilationFunc &compile_to_backend)
: queue(&ir_bank_, compile_to_backend),
config_(config),
sfg(std::make_unique<StateFlowGraph>(this, &ir_bank_, config, snodes)) {
sfg(std::make_unique<StateFlowGraph>(this, &ir_bank_, config)) {
Timeline::get_this_thread_instance().set_name("host");
ir_bank_.set_sfg(sfg.get());
}
Expand Down
1 change: 0 additions & 1 deletion taichi/program/async_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ class AsyncEngine {
std::unique_ptr<StateFlowGraph> sfg;

explicit AsyncEngine(const CompileConfig *const config,
const std::unordered_map<int, SNode *> &snodes,
const BackendExecCompilationFunc &compile_to_backend);

void clear_cache() {
Expand Down
4 changes: 2 additions & 2 deletions taichi/program/program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ Program::Program(Arch desired_arch)
TI_WARN("Running in async mode. This is experimental.");
TI_ASSERT(is_extension_supported(config.arch, Extension::async_mode));
async_engine = std::make_unique<AsyncEngine>(
&config, snodes, [this](Kernel &kernel, OffloadedStmt *offloaded) {
&config, [this](Kernel &kernel, OffloadedStmt *offloaded) {
return this->compile(kernel, offloaded);
});
}
Expand Down Expand Up @@ -201,7 +201,7 @@ SNodeTree *Program::add_snode_tree(std::unique_ptr<SNode> root,
if (compile_only) {
program_impl_->compile_snode_tree_types(tree.get());
} else {
program_impl_->materialize_snode_tree(tree.get(), snode_trees_, snodes,
program_impl_->materialize_snode_tree(tree.get(), snode_trees_,
result_buffer);
}
snode_trees_.push_back(std::move(tree));
Expand Down
3 changes: 0 additions & 3 deletions taichi/program/program.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ class Program {

uint64 *result_buffer{nullptr}; // Note result_buffer is used by all backends

std::unordered_map<int, SNode *>
snodes; // TODO: seems LLVM specific but used by state_flow_graph.cpp.

std::unique_ptr<AsyncEngine> async_engine{nullptr};

std::vector<std::unique_ptr<Kernel>> kernels;
Expand Down
1 change: 0 additions & 1 deletion taichi/program/program_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class ProgramImpl {
virtual void materialize_snode_tree(
SNodeTree *tree,
std::vector<std::unique_ptr<SNodeTree>> &snode_trees_,
std::unordered_map<int, SNode *> &snodes,
uint64 *result_buffer_ptr) = 0;

virtual void destroy_snode_tree(SNodeTree *snode_tree) = 0;
Expand Down
7 changes: 1 addition & 6 deletions taichi/program/state_flow_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,7 @@ void StateFlowGraph::Node::disconnect_with(StateFlowGraph::Node *other) {

StateFlowGraph::StateFlowGraph(AsyncEngine *engine,
IRBank *ir_bank,
const CompileConfig *const config,
const std::unordered_map<int, SNode *> &snodes)
const CompileConfig *const config)
: first_pending_task_index_(1 /*after initial node*/),
ir_bank_(ir_bank),
engine_(engine),
Expand All @@ -255,10 +254,6 @@ StateFlowGraph::StateFlowGraph(AsyncEngine *engine,
initial_node_->input_edges.node_id = 0;
initial_node_->output_edges.node_id = 0;
initial_node_->mark_executed();

for (const auto snode : snodes) {
list_up_to_date_[snode.second] = false;
}
}

std::vector<StateFlowGraph::Node *> StateFlowGraph::get_pending_tasks() const {
Expand Down
3 changes: 1 addition & 2 deletions taichi/program/state_flow_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,7 @@ class StateFlowGraph {

StateFlowGraph(AsyncEngine *engine,
IRBank *ir_bank,
const CompileConfig *const config,
const std::unordered_map<int, SNode *> &snodes);
const CompileConfig *const config);

std::vector<Node *> get_pending_tasks() const;

Expand Down