Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PTen] Unify MetaFunctionMap naming style #39481

Merged
merged 2 commits into from
Feb 12, 2022
Merged
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
4 changes: 2 additions & 2 deletions paddle/pten/core/infermeta_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ MetaTensor* InferMetaContext::MutableOutputAt(size_t idx) {
return outputs_.at(idx).get();
}

MetaFunctionMap& MetaFunctionMap::Instance() {
static MetaFunctionMap g_meta_fn_map;
MetaFnFactory& MetaFnFactory::Instance() {
static MetaFnFactory g_meta_fn_map;
return g_meta_fn_map;
}

Expand Down
12 changes: 6 additions & 6 deletions paddle/pten/core/infermeta_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ struct InferMetaFnImpl<Return (*)(Args...), infer_meta_fn> {
};
};

class MetaFunctionMap {
class MetaFnFactory {
public:
static MetaFunctionMap& Instance();
static MetaFnFactory& Instance();

bool Contains(const std::string& kernel_name_prefix) const {
return meta_fn_map_.count(kernel_name_prefix) > 0;
Expand Down Expand Up @@ -225,7 +225,7 @@ class MetaFunctionMap {
}

private:
MetaFunctionMap() = default;
MetaFnFactory() = default;

/**
* [ Why use kernel name prefix? ]
Expand All @@ -243,14 +243,14 @@ class MetaFunctionMap {
*/
paddle::flat_hash_map<std::string, InferMetaFn> meta_fn_map_;

DISABLE_COPY_AND_ASSIGN(MetaFunctionMap);
DISABLE_COPY_AND_ASSIGN(MetaFnFactory);
};

struct InferMetaFnRegistrar {
InferMetaFnRegistrar(const char* kernel_name_prefix,
InferMetaFn infer_meta_fn) {
MetaFunctionMap::Instance().Insert(kernel_name_prefix,
std::move(infer_meta_fn));
MetaFnFactory::Instance().Insert(kernel_name_prefix,
std::move(infer_meta_fn));
}
};

Expand Down
4 changes: 2 additions & 2 deletions paddle/pten/tests/core/test_meta_fn_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ limitations under the License. */
namespace pten {
namespace tests {

TEST(MetaFunctionMap, InferMetaFnExists) {
TEST(MetaFnFactory, InferMetaFnExists) {
pten::DenseTensor dense_x;
dense_x.Resize(pten::framework::make_ddim({3, 4}));

Expand All @@ -38,7 +38,7 @@ TEST(MetaFunctionMap, InferMetaFnExists) {
ctx.EmplaceBackInput(shared_meat_x);
ctx.EmplaceBackOutput(shared_meta_out);
ctx.SetMetaConfig(/*is_runtime=*/true);
pten::MetaFunctionMap::Instance().Get("sign")(&ctx);
pten::MetaFnFactory::Instance().Get("sign")(&ctx);

EXPECT_EQ(dense_out1.dims().size(), dense_out2.dims().size());
EXPECT_EQ(dense_out1.dims()[0], dense_out2.dims()[0]);
Expand Down