Skip to content

Commit

Permalink
Refactor2023: Remove dependencies on Program::this_thread_config() in…
Browse files Browse the repository at this point in the history
… codegen_cc.cpp
  • Loading branch information
PGZXB committed Dec 7, 2022
1 parent 79b4b9a commit 19d6e11
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion taichi/codegen/cc/cc_program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ CCProgramImpl::CCProgramImpl(CompileConfig &config) : ProgramImpl(config) {
}

FunctionType CCProgramImpl::compile(Kernel *kernel) {
CCKernelGen codegen(kernel, this);
CCKernelGen codegen(*config, kernel, this);
auto ker = codegen.compile();
auto ker_ptr = ker.get();
this->add_kernel(std::move(ker));
Expand Down
21 changes: 10 additions & 11 deletions taichi/codegen/cc/codegen_cc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ namespace {
std::string get_node_ptr_name(SNode *snode) {
return fmt::format("struct Ti_{} *", snode->get_node_type_name_hinted());
}

static void lower_ast(const CompileConfig &config, Kernel *kernel) {
auto ir = kernel->ir.get();
irpass::compile_to_executable(ir, config, kernel,
/*autodiff_mode=*/kernel->autodiff_mode,
/*ad_use_stack=*/true, config.print_ir,
/*lower_global_access*/ true);
}

} // namespace

class CCTransformer : public IRVisitor {
Expand All @@ -38,22 +47,11 @@ class CCTransformer : public IRVisitor {
}

void run() {
this->lower_ast();
emit_header("void Tk_{}(struct Ti_Context *ti_ctx) {{", kernel_->name);
kernel_->ir->accept(this);
emit("}}");
}

void lower_ast() {
auto ir = kernel_->ir.get();
auto config = kernel_->program->this_thread_config();
config.demote_dense_struct_fors = true;
irpass::compile_to_executable(ir, config, kernel_,
/*autodiff_mode=*/kernel_->autodiff_mode,
/*ad_use_stack=*/true, config.print_ir,
/*lower_global_access*/ true);
}

std::string get_source() {
return line_appender_header_.lines() + line_appender_.lines();
}
Expand Down Expand Up @@ -593,6 +591,7 @@ class CCTransformer : public IRVisitor {
}; // namespace cccp

std::unique_ptr<CCKernel> CCKernelGen::compile() {
lower_ast(compile_config_, kernel_);
auto layout = cc_program_impl_->get_layout();
CCTransformer tran(kernel_, layout);

Expand Down
9 changes: 7 additions & 2 deletions taichi/codegen/cc/codegen_cc.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ class CCKernel;
class CCKernelGen {
// Generate corresponding C Source Code for a Taichi Kernel
public:
CCKernelGen(Kernel *kernel, CCProgramImpl *cc_program_impl)
: cc_program_impl_(cc_program_impl), kernel_(kernel) {
CCKernelGen(const CompileConfig &compile_config,
Kernel *kernel,
CCProgramImpl *cc_program_impl)
: compile_config_(compile_config),
cc_program_impl_(cc_program_impl),
kernel_(kernel) {
}

std::unique_ptr<CCKernel> compile();

private:
const CompileConfig &compile_config_;
CCProgramImpl *cc_program_impl_{nullptr};
Kernel *kernel_;
};
Expand Down

0 comments on commit 19d6e11

Please sign in to comment.