Skip to content

Commit

Permalink
[refactor] Remove offloaded parameter of Program::compile() (#7045)
Browse files Browse the repository at this point in the history
Issue: #7002
  • Loading branch information
PGZXB authored Jan 5, 2023
1 parent a7b7a2f commit 875c14a
Show file tree
Hide file tree
Showing 16 changed files with 18 additions and 26 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 @@ -15,7 +15,7 @@ CCProgramImpl::CCProgramImpl(CompileConfig &config) : ProgramImpl(config) {
context_ = std::make_unique<CCContext>();
}

FunctionType CCProgramImpl::compile(Kernel *kernel, OffloadedStmt *) {
FunctionType CCProgramImpl::compile(Kernel *kernel) {
CCKernelGen codegen(kernel, this);
auto ker = codegen.compile();
auto ker_ptr = ker.get();
Expand Down
2 changes: 1 addition & 1 deletion taichi/codegen/cc/cc_program.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CCProgramImpl : public ProgramImpl {
public:
explicit CCProgramImpl(CompileConfig &config);

FunctionType compile(Kernel *kernel, OffloadedStmt *) override;
FunctionType compile(Kernel *kernel) override;

std::size_t get_snode_num_dynamically_allocated(
SNode *snode,
Expand Down
4 changes: 2 additions & 2 deletions taichi/program/program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,10 @@ Function *Program::create_function(const FunctionKey &func_key) {
return functions_.back().get();
}

FunctionType Program::compile(Kernel &kernel, OffloadedStmt *offloaded) {
FunctionType Program::compile(Kernel &kernel) {
auto start_t = Time::get_time();
TI_AUTO_PROF;
auto ret = program_impl_->compile(&kernel, offloaded);
auto ret = program_impl_->compile(&kernel);
TI_ASSERT(ret);
total_compilation_time_ += Time::get_time() - start_t;
return ret;
Expand Down
3 changes: 1 addition & 2 deletions taichi/program/program.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ class TI_DLL_EXPORT Program {

// TODO: This function is doing two things: 1) compiling CHI IR, and 2)
// offloading them to each backend. We should probably separate the logic?
// TODO(Lin): remove the offloaded parameter
FunctionType compile(Kernel &kernel, OffloadedStmt *offloaded = nullptr);
FunctionType compile(Kernel &kernel);

void check_runtime_error();

Expand Down
2 changes: 1 addition & 1 deletion taichi/program/program_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ProgramImpl {
/**
* Codegen to specific backend
*/
virtual FunctionType compile(Kernel *kernel, OffloadedStmt *offloaded) = 0;
virtual FunctionType compile(Kernel *kernel) = 0;

/**
* Allocate runtime buffer, e.g result_buffer or backend specific runtime
Expand Down
3 changes: 1 addition & 2 deletions taichi/runtime/program_impls/dx/dx_program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ FunctionType compile_to_executable(Kernel *kernel,
Dx11ProgramImpl::Dx11ProgramImpl(CompileConfig &config) : ProgramImpl(config) {
}

FunctionType Dx11ProgramImpl::compile(Kernel *kernel,
OffloadedStmt *offloaded) {
FunctionType Dx11ProgramImpl::compile(Kernel *kernel) {
spirv::lower(kernel);
return directx11::compile_to_executable(kernel, runtime_.get(),
snode_tree_mgr_.get());
Expand Down
2 changes: 1 addition & 1 deletion taichi/runtime/program_impls/dx/dx_program.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace taichi::lang {
class Dx11ProgramImpl : public ProgramImpl {
public:
Dx11ProgramImpl(CompileConfig &config);
FunctionType compile(Kernel *kernel, OffloadedStmt *offloaded) override;
FunctionType compile(Kernel *kernel) override;

std::size_t get_snode_num_dynamically_allocated(
SNode *snode,
Expand Down
5 changes: 2 additions & 3 deletions taichi/runtime/program_impls/llvm/llvm_program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ LlvmProgramImpl::LlvmProgramImpl(CompileConfig &config_,
}
}

FunctionType LlvmProgramImpl::compile(Kernel *kernel,
OffloadedStmt *offloaded) {
auto codegen = KernelCodeGen::create(kernel->arch, kernel, offloaded);
FunctionType LlvmProgramImpl::compile(Kernel *kernel) {
auto codegen = KernelCodeGen::create(kernel->arch, kernel);
return codegen->compile_to_function();
}

Expand Down
2 changes: 1 addition & 1 deletion taichi/runtime/program_impls/llvm/llvm_program.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class LlvmProgramImpl : public ProgramImpl {

// TODO(zhanlue): compile-time runtime split for LLVM::CodeGen
// For now, compile = codegen + convert
FunctionType compile(Kernel *kernel, OffloadedStmt *offloaded) override;
FunctionType compile(Kernel *kernel) override;

void compile_snode_tree_types(SNodeTree *tree) override;

Expand Down
4 changes: 1 addition & 3 deletions taichi/runtime/program_impls/metal/metal_program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ MetalProgramImpl::MetalProgramImpl(CompileConfig &config_)
: ProgramImpl(config_) {
}

FunctionType MetalProgramImpl::compile(Kernel *kernel,
OffloadedStmt *offloaded) {
TI_ASSERT(offloaded == nullptr);
FunctionType MetalProgramImpl::compile(Kernel *kernel) {
return metal::compiled_kernel_to_metal_executable(
get_cache_manager()->load_or_compile(config, kernel),
metal_kernel_mgr_.get());
Expand Down
2 changes: 1 addition & 1 deletion taichi/runtime/program_impls/metal/metal_program.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class MetalProgramImpl : public ProgramImpl {
public:
explicit MetalProgramImpl(CompileConfig &config);

FunctionType compile(Kernel *kernel, OffloadedStmt *offloaded) override;
FunctionType compile(Kernel *kernel) override;

std::size_t get_snode_num_dynamically_allocated(
SNode *snode,
Expand Down
3 changes: 1 addition & 2 deletions taichi/runtime/program_impls/opengl/opengl_program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ OpenglProgramImpl::OpenglProgramImpl(CompileConfig &config)
: ProgramImpl(config) {
}

FunctionType OpenglProgramImpl::compile(Kernel *kernel,
OffloadedStmt *offloaded) {
FunctionType OpenglProgramImpl::compile(Kernel *kernel) {
return register_params_to_executable(
get_cache_manager()->load_or_compile(config, kernel), runtime_.get());
}
Expand Down
3 changes: 1 addition & 2 deletions taichi/runtime/program_impls/opengl/opengl_program.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ class OpenglProgramImpl : public ProgramImpl {
public:
explicit OpenglProgramImpl(CompileConfig &config);
~OpenglProgramImpl() override;

FunctionType compile(Kernel *kernel, OffloadedStmt *offloaded) override;
FunctionType compile(Kernel *kernel) override;

std::size_t get_snode_num_dynamically_allocated(
SNode *snode,
Expand Down
3 changes: 1 addition & 2 deletions taichi/runtime/program_impls/vulkan/vulkan_program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ VulkanProgramImpl::VulkanProgramImpl(CompileConfig &config)
: ProgramImpl(config) {
}

FunctionType VulkanProgramImpl::compile(Kernel *kernel,
OffloadedStmt *offloaded) {
FunctionType VulkanProgramImpl::compile(Kernel *kernel) {
return register_params_to_executable(
get_cache_manager()->load_or_compile(config, kernel),
vulkan_runtime_.get());
Expand Down
2 changes: 1 addition & 1 deletion taichi/runtime/program_impls/vulkan/vulkan_program.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class VulkanDeviceCreator;
class VulkanProgramImpl : public ProgramImpl {
public:
explicit VulkanProgramImpl(CompileConfig &config);
FunctionType compile(Kernel *kernel, OffloadedStmt *offloaded) override;
FunctionType compile(Kernel *kernel) override;

std::size_t get_snode_num_dynamically_allocated(
SNode *snode,
Expand Down
2 changes: 1 addition & 1 deletion tests/cpp/backends/dx11_device_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ TEST(Dx11ProgramTest, MaterializeRuntimeTest) {
auto block = builder.extract_ir();
test_prog.prog()->this_thread_config().arch = Arch::dx11;
auto ker = std::make_unique<Kernel>(*test_prog.prog(), std::move(block));
program->compile(ker.get(), nullptr);
program->compile(ker.get());
}

} // namespace directx11
Expand Down

0 comments on commit 875c14a

Please sign in to comment.