-
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.
[Refactor] Add a class Callable to unify Kernel and Function (#2338)
* Add Callable and change Kernel::program to Program * * [skip ci] enforce code format * Add Program::current_callable * cleanup * add get_name() and fix tests * Rename: TaichiCallableTemplateMapper * code format * fix test * Update taichi/program/callable.h Co-authored-by: Ye Kuang <[email protected]> * Remove the implementation of the pure virtual function Co-authored-by: Taichi Gardener <[email protected]> Co-authored-by: Ye Kuang <[email protected]>
- Loading branch information
1 parent
22e33a6
commit aabd87c
Showing
28 changed files
with
198 additions
and
205 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
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
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
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,29 @@ | ||
#include "taichi/program/callable.h" | ||
#include "taichi/program/program.h" | ||
|
||
namespace taichi { | ||
namespace lang { | ||
|
||
int Callable::insert_arg(const DataType &dt, bool is_external_array) { | ||
args.emplace_back(dt->get_compute_type(), is_external_array, /*size=*/0); | ||
return (int)args.size() - 1; | ||
} | ||
|
||
int Callable::insert_ret(const DataType& dt) { | ||
rets.emplace_back(dt->get_compute_type()); | ||
return (int)rets.size() - 1; | ||
} | ||
|
||
Callable::CurrentCallableGuard::CurrentCallableGuard(Program *program, | ||
Callable *callable) | ||
: program(program) { | ||
old_callable = program->current_callable; | ||
program->current_callable = callable; | ||
} | ||
|
||
Callable::CurrentCallableGuard::~CurrentCallableGuard() { | ||
program->current_callable = old_callable; | ||
} | ||
|
||
} // 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#pragma once | ||
|
||
#include "taichi/lang_util.h" | ||
|
||
namespace taichi { | ||
namespace lang { | ||
|
||
class Program; | ||
class IRNode; | ||
|
||
class Callable { | ||
public: | ||
Program *program; | ||
std::unique_ptr<IRNode> ir; | ||
|
||
struct Arg { | ||
DataType dt; | ||
bool is_external_array; | ||
std::size_t size; | ||
|
||
explicit Arg(const DataType &dt = PrimitiveType::unknown, | ||
bool is_external_array = false, | ||
std::size_t size = 0) | ||
: dt(dt), is_external_array(is_external_array), size(size) { | ||
} | ||
}; | ||
|
||
struct Ret { | ||
DataType dt; | ||
|
||
explicit Ret(const DataType &dt = PrimitiveType::unknown) : dt(dt) { | ||
} | ||
}; | ||
|
||
std::vector<Arg> args; | ||
std::vector<Ret> rets; | ||
|
||
virtual ~Callable() = default; | ||
|
||
int insert_arg(const DataType &dt, bool is_external_array); | ||
|
||
int insert_ret(const DataType &dt); | ||
|
||
[[nodiscard]] virtual std::string get_name() const = 0; | ||
|
||
class CurrentCallableGuard { | ||
Callable *old_callable; | ||
Program *program; | ||
|
||
public: | ||
CurrentCallableGuard(Program *program, Callable *callable); | ||
|
||
~CurrentCallableGuard(); | ||
}; | ||
}; | ||
|
||
} // 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
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
Oops, something went wrong.