Skip to content
Open
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
27 changes: 27 additions & 0 deletions taichi/program/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,33 @@ Kernel::Kernel(Program &program,
this->init(program, [&] { return func(this); }, primal_name, autodiff_mode);
}

Kernel::Kernel(Program &program,
Block *block,
const std::string &primal_name,
AutodiffMode autodiff_mode) {
this->arch = program.compile_config().arch;
this->autodiff_mode = autodiff_mode;
this->ir = std::unique_ptr<IRNode>(block);
this->program = &program;
is_accessor = false;
ir_is_ast_ = false; // CHI IR

TI_ASSERT(this->ir->is<Block>());
this->ir->as<Block>()->set_parent_callable(this);

if (autodiff_mode == AutodiffMode::kNone) {
name = primal_name;
} else if (autodiff_mode == AutodiffMode::kForward) {
name = primal_name + "_forward_grad";
} else if (autodiff_mode == AutodiffMode::kReverse) {
name = primal_name + "_reverse_grad";
} else if (autodiff_mode == AutodiffMode::kCheckAutodiffValid) {
name = primal_name + "_validate_grad";
} else {
TI_ERROR("Unsupported autodiff mode");
}
}

Kernel::Kernel(Program &program,
std::unique_ptr<IRNode> &&ir,
const std::string &primal_name,
Expand Down
5 changes: 5 additions & 0 deletions taichi/program/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ class TI_DLL_EXPORT Kernel : public Callable {
const std::string &name = "",
AutodiffMode autodiff_mode = AutodiffMode::kNone);

Kernel(Program &program,
Block *block,
const std::string &name = "",
AutodiffMode autodiff_mode = AutodiffMode::kNone);

bool ir_is_ast() const {
return ir_is_ast_;
}
Expand Down
Loading