Skip to content

Commit

Permalink
[IR]Polish BFloat16Type code and Add related UT (#54440)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aurelius84 authored Jun 8, 2023
1 parent 950a29b commit 78fc636
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
13 changes: 3 additions & 10 deletions paddle/ir/core/builtin_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,8 @@ namespace ir {
/// \endcode
///

// NOTE(dev): Currently BF16 and Int8 are not considered as a cached member
// in IrContextImpl because they are not widely used.
class BFloat16Type : public Type {
public:
using Type::Type;

DECLARE_TYPE_UTILITY_FUNCTOR(BFloat16Type, TypeStorage);

static BFloat16Type get(IrContext *context);
};
// NOTE(dev): Currently Int8 are not considered as a cached member
// in IrContextImpl because it is not widely used.

class Int8Type : public Type {
public:
Expand Down Expand Up @@ -79,6 +71,7 @@ class VectorType : public Type {
};

#define FOREACH_BUILTIN_TYPE(__macro) \
__macro(BFloat16); \
__macro(Float16); \
__macro(Float32); \
__macro(Float64); \
Expand Down
8 changes: 8 additions & 0 deletions test/cpp/ir/core/type_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ TEST(type_test, built_in_type) {
ir::IrContext *ctx = ir::IrContext::Instance();

// Test 1: Test the parameterless built-in type of IrContext.
ir::Type bfp16_1 = ir::BFloat16Type::get(ctx);
ir::Type bfp16_2 = ir::BFloat16Type::get(ctx);
EXPECT_EQ(bfp16_1, bfp16_2);
EXPECT_EQ(bfp16_1.type_id(), bfp16_2.type_id());
EXPECT_EQ(&bfp16_1.abstract_type(),
&ir::AbstractType::lookup(bfp16_1.type_id(), ctx));
EXPECT_EQ(ir::BFloat16Type::classof(bfp16_1), 1);

ir::Type fp16_1 = ir::Float16Type::get(ctx);
ir::Type fp16_2 = ir::Float16Type::get(ctx);
EXPECT_EQ(fp16_1, fp16_2);
Expand Down

0 comments on commit 78fc636

Please sign in to comment.