提交 96d90be1 编写于 作者: M Megvii Engine Team

feat(dnn): fallback support int4 relayout

GitOrigin-RevId: 3625f5847055940e646358654f296922f05afa93
上级 eef0308b
......@@ -615,16 +615,17 @@ struct log<1> {
// begin define DTypeTrait impls {
#if MEGDNN_CC_HOST
#define MEGDNN_DEF_DT_BASIC_FIELDS(_name, _ctype, _cat, _sign, _bits, _has_param) \
static MEGDNN_CONSTEXPR const char* name = #_name; \
using ctype = _ctype; \
using dtype = ::megdnn::dtype::_name; \
static MEGDNN_CONSTEXPR DTypeCategory category = DTypeCategory::_cat; \
static MEGDNN_CONSTEXPR DTypeSignedness signedness = DTypeSignedness::_sign; \
static MEGDNN_CONSTEXPR uint16_t size_log = \
::megdnn::dtype::log<sizeof(ctype)>::value; \
static MEGDNN_CONSTEXPR DTypeEnum enumv = DTypeEnum::_name; \
static MEGDNN_CONSTEXPR uint16_t low_bit = _bits; \
#define MEGDNN_DEF_DT_BASIC_FIELDS(_name, _ctype, _cat, _sign, _bits, _has_param) \
static MEGDNN_CONSTEXPR const char* name = #_name; \
using ctype = _ctype; \
using dtype = ::megdnn::dtype::_name; \
static MEGDNN_CONSTEXPR DTypeCategory category = DTypeCategory::_cat; \
static MEGDNN_CONSTEXPR DTypeSignedness signedness = DTypeSignedness::_sign; \
static MEGDNN_CONSTEXPR uint16_t size_log = \
::megdnn::dtype::log<sizeof(ctype)>::value; \
static MEGDNN_CONSTEXPR DTypeEnum enumv = DTypeEnum::_name; \
static MEGDNN_CONSTEXPR uint16_t low_bit = _bits; \
static MEGDNN_CONSTEXPR uint16_t bits = _bits == 0 ? sizeof(_ctype) * 8 : _bits; \
static MEGDNN_CONSTEXPR bool has_param = _has_param
#else
#define MEGDNN_DEF_DT_BASIC_FIELDS(_name, _ctype, _cat, _sign, _bits, _has_param) \
......@@ -632,7 +633,8 @@ struct log<1> {
typedef ::megdnn::dtype::_name dtype; \
static const uint16_t size_log = ::megdnn::dtype::log<sizeof(ctype)>::value; \
static MEGDNN_CONSTEXPR int enumv = DTypeEnum::_name; \
static MEGDNN_CONSTEXPR uint16_t low_bit = _bits
static MEGDNN_CONSTEXPR uint16_t low_bit = _bits; \
static MEGDNN_CONSTEXPR uint16_t bits = _bits == 0 ? sizeof(_ctype) * 8 : _bits;
#endif // MEGDNN_CC_HOST
#define MEGDNN_DEF_DT(_name, _ctype, _cat, _sign, _minval, _maxval) \
......
......@@ -98,7 +98,7 @@ template <typename Impl>
void copy_tensors(
const CheckerHelper::TensorValueArray& dest,
const CheckerHelper::TensorValueArray& src, const Impl& copy_impl) {
megdnn_assert(dest.size() == src.size());
megdnn_assert(dest.size() == src.size(), "%zu != %zu", dest.size(), src.size());
for (size_t i = 0; i < src.size(); i++) {
auto&& tensor = src[i];
if (tensor.layout.ndim == 0)
......
......@@ -34,6 +34,60 @@ TEST_F(FALLBACK, RELAYOUT_RECORD) {
checker.exec({{2, 2, 2}, {2, 2, 2}});
}
TEST_F(FALLBACK, RELAYOUT_Q4) {
Checker<Relayout> checker(handle());
UniformIntRNG rng_int4{-7, 7};
checker.set_rng(0, &rng_int4)
.set_rng(1, &rng_int4)
.set_dtype(0, dtype::QuantizedS4(1.f))
.set_dtype(1, dtype::QuantizedS4(1.f))
.execs({{2, 2, 1, 1}, {1, 1, 2, 2}})
.execs({{1, 64, 15, 15}, {1, 15, 15, 64}})
.execs({{1, 5, 9, 32}, {1, 5, 32, 9}})
.execl(TensorLayoutArray{
{{6400}, {1}, dtype::QuantizedS4{1.f}},
{{20, 320}, {1024, 1}, dtype::QuantizedS4{1.f}}})
.execl(TensorLayoutArray{
{{156}, {1}, dtype::QuantizedS4{1.f}},
{{13, 3, 4}, {16, 1, 4}, dtype::QuantizedS4{1.f}}})
.execl(TensorLayoutArray{
{{48}, {1}, dtype::QuantizedS4{1.f}},
{{3, 4, 4}, {16, 1, 4}, dtype::QuantizedS4{1.f}}})
.execl(TensorLayoutArray{
{{84}, {1}, dtype::QuantizedS4{1.f}},
{{3, 4, 7}, {28, 1, 4}, dtype::QuantizedS4{1.f}}})
.execl(TensorLayoutArray{
{{336}, {1}, dtype::QuantizedS4{1.f}},
{{3, 4, 7, 4}, {112, 4, 16, 1}, dtype::QuantizedS4{1.f}}})
.execl(TensorLayoutArray{
{{54}, {1}, dtype::QuantizedS4{1.f}},
{{6, 3, 3}, {16, 4, 1}, dtype::QuantizedS4{1.f}}})
.execl(TensorLayoutArray{
{{1200, 3}, {4, 1}, dtype::QuantizedS4{1.f}},
{{20, 60, 3}, {256, 4, 1}, dtype::QuantizedS4{1.f}}})
.execl(TensorLayoutArray{
{{20, 20, 3, 3}, {256, 12, 4, 1}, dtype::QuantizedS4{1.f}},
{{1200, 3}, {4, 1}, dtype::QuantizedS4{1.f}}})
.execl(TensorLayoutArray{
{{5, 16, 7, 7, 4}, {3136, 196, 28, 4, 1}, dtype::QuantizedS4{1.f}},
{{5, 16, 7, 7, 4}, {3136, 4, 448, 64, 1}, dtype::QuantizedS4{1.f}}})
.execl(TensorLayoutArray{
{{5, 7, 7, 16, 4}, {3136, 448, 64, 4, 1}, dtype::QuantizedS4{1.f}},
{{5, 7, 7, 16, 4}, {3136, 28, 4, 196, 1}, dtype::QuantizedS4{1.f}}})
.execl(TensorLayoutArray{
{{5, 2, 7, 7, 32},
{3136, 1568, 224, 32, 1},
dtype::QuantizedS4{1.f}},
{{5, 2, 7, 7, 32},
{3136, 32, 448, 64, 1},
dtype::QuantizedS4{1.f}}})
.execl(TensorLayoutArray{
{{5, 7, 7, 2, 32}, {3136, 448, 64, 32, 1}, dtype::QuantizedS4{1.f}},
{{5, 7, 7, 2, 32},
{3136, 224, 32, 1568, 1},
dtype::QuantizedS4{1.f}}});
}
#if MEGDNN_WITH_BENCHMARK
TEST_F(FALLBACK, BENCHMARK_RELAYOUT_CV) {
relayout::run_cv_benchmark(handle());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册