未验证 提交 78fc636e 编写于 作者: A Aurelius84 提交者: GitHub

[IR]Polish BFloat16Type code and Add related UT (#54440)

上级 950a29b2
...@@ -35,16 +35,8 @@ namespace ir { ...@@ -35,16 +35,8 @@ namespace ir {
/// \endcode /// \endcode
/// ///
// NOTE(dev): Currently BF16 and Int8 are not considered as a cached member // NOTE(dev): Currently Int8 are not considered as a cached member
// in IrContextImpl because they are not widely used. // in IrContextImpl because it is not widely used.
class BFloat16Type : public Type {
public:
using Type::Type;
DECLARE_TYPE_UTILITY_FUNCTOR(BFloat16Type, TypeStorage);
static BFloat16Type get(IrContext *context);
};
class Int8Type : public Type { class Int8Type : public Type {
public: public:
...@@ -79,6 +71,7 @@ class VectorType : public Type { ...@@ -79,6 +71,7 @@ class VectorType : public Type {
}; };
#define FOREACH_BUILTIN_TYPE(__macro) \ #define FOREACH_BUILTIN_TYPE(__macro) \
__macro(BFloat16); \
__macro(Float16); \ __macro(Float16); \
__macro(Float32); \ __macro(Float32); \
__macro(Float64); \ __macro(Float64); \
......
...@@ -77,6 +77,14 @@ TEST(type_test, built_in_type) { ...@@ -77,6 +77,14 @@ TEST(type_test, built_in_type) {
ir::IrContext *ctx = ir::IrContext::Instance(); ir::IrContext *ctx = ir::IrContext::Instance();
// Test 1: Test the parameterless built-in type of IrContext. // 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_1 = ir::Float16Type::get(ctx);
ir::Type fp16_2 = ir::Float16Type::get(ctx); ir::Type fp16_2 = ir::Float16Type::get(ctx);
EXPECT_EQ(fp16_1, fp16_2); EXPECT_EQ(fp16_1, fp16_2);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册