Skip to content

Commit

Permalink
add REGISTER_PIANO_OP_WITHOUT_MAKER (PaddlePaddle#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
thisjiang authored Sep 16, 2021
1 parent e7f279f commit a8bc997
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
5 changes: 5 additions & 0 deletions paddle/fluid/compiler/paddle2piano/piano_op_registry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ limitations under the License. */
namespace paddle {
namespace piano {

PianoOpRegistry& PianoOpRegistry::Instance() {
static PianoOpRegistry r;
return r;
}

void PianoOpRegistry::RegisterBackend(
const std::string& backend_name,
const std::unordered_set<note::ElementTypeProto>& supported_types,
Expand Down
11 changes: 6 additions & 5 deletions paddle/fluid/compiler/paddle2piano/piano_op_registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,7 @@ class PianoOpRegistry final {
template <typename OpMakeType, typename KernelType>
friend class PianoOpRegistrar;

static PianoOpRegistry& Instance() {
static PianoOpRegistry r;
return r;
}
static PianoOpRegistry& Instance();

PianoOpRegistry() = default;
~PianoOpRegistry() = default;
Expand Down Expand Up @@ -158,7 +155,7 @@ class PianoOpMakerBase {

class PianoOpMaker : public PianoOpMakerBase {
public:
virtual void Make() = 0;
virtual void Make() {}

virtual ~PianoOpMaker() = default;

Expand Down Expand Up @@ -231,6 +228,10 @@ class PianoOpRegistrar final : public framework::Registrar {
#define REGISTER_PIANO_OP(op_type, op_maker, op_kernel) \
REGISTER_PIANO_OP_EX(op_type, PLAIN, op_maker, op_kernel)

#define REGISTER_PIANO_OP_WITHOUT_MAKER(op_type, op_kernel) \
class op_type##PianoOpMaker : public ::paddle::piano::PianoOpMaker {}; \
REGISTER_PIANO_OP(op_type, op_type##PianoOpMaker, op_kernel)

#define REGISTER_PIANO_OP_EX(TYPE, LIB, MAKER, KERNEL) \
STATIC_ASSERT_GLOBAL_NAMESPACE( \
__reg_piano_op__##TYPE##_##LIB, \
Expand Down
7 changes: 6 additions & 1 deletion paddle/fluid/compiler/paddle2piano/piano_op_registry_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ REGISTER_OP_WITHOUT_GRADIENT(op_not_piano, paddle::piano::TestOp,
paddle::piano::TestOpMaker);
REGISTER_OP_WITHOUT_GRADIENT(test_limit_backend, paddle::piano::TestOp,
paddle::piano::TestOpMaker);
REGISTER_OP_WITHOUT_GRADIENT(test_without_maker, paddle::piano::TestOp,
paddle::piano::TestOpMaker);

// register backend which support some datetype but all op
REGISTER_PIANO_BACKEND(PIANO_JIT_TEST_TYPE, paddle::piano::TestDatatypes())
Expand Down Expand Up @@ -120,6 +122,8 @@ REGISTER_PIANO_OP(test, paddle::piano::TestPianoOpMaker,
REGISTER_PIANO_OP(test_limit_backend,
paddle::piano::TestPianoOpWithAllowBackendMaker,
paddle::piano::TestPianoOpKernel)
REGISTER_PIANO_OP_WITHOUT_MAKER(test_without_maker,
paddle::piano::TestPianoOpKernel)

namespace paddle {
namespace piano {
Expand Down Expand Up @@ -147,7 +151,8 @@ TEST(TestPianoOpRegistry, CheckPianoOpRegistered) {
// check register store OK
auto ops = PianoOpRegistry::AllPianoOps();
std::stable_sort(ops.begin(), ops.end());
ASSERT_EQ(ops, std::vector<std::string>({"test", "test_limit_backend"}));
ASSERT_EQ(ops, std::vector<std::string>(
{"test", "test_limit_backend", "test_without_maker"}));

// check piano op's attribute OK
const auto& attrs = PianoOpRegistry::Attrs("test");
Expand Down

0 comments on commit a8bc997

Please sign in to comment.