algos.cpp 20.9 KB
Newer Older
1 2 3 4 5 6 7 8
/**
 * \file dnn/src/fallback/convolution/algos.cpp
 * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
 *
 * Copyright (c) 2014-2020 Megvii Inc. All rights reserved.
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
9 10
 * "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
 */

#include "src/fallback/convolution/algos.h"
#include "src/common/opr_delegate.h"
#include "src/fallback/convolution/col2img_helper.h"
#include "src/fallback/convolution/run_conv.h"

#include "midout.h"

using namespace megdnn;
using namespace fallback;

MIDOUT_DECL(megdnn_fallback_conv)

namespace {

template <typename T>
void incr_ptr(T*& dst, ptrdiff_t delta) {
    dst = reinterpret_cast<T*>(reinterpret_cast<uintptr_t>(dst) + delta);
}

using NCBKernSizeParam = ConvolutionBackwardDataImpl::NCBKernSizeParam;
using NCBKernParam = ConvolutionBackwardDataImpl::NCBKernParam;

Relayout* get_relayout_opr() {
    static CpuOprDelegationStorage<> storage;
    return storage.get<Relayout>();
}

MatrixMul* get_matmul_opr(const NCBKernSizeParam& param) {
    using ConvCM = param::Convolution::ComputeMode;
    using MmCM = param::MatrixMul::ComputeMode;
    static CpuOprDelegationStorage<2> storage;
    switch (param.compute_mode) {
        default:
            return storage.get<MatrixMul, 0>({});
        case ConvCM::FLOAT32: {
            MatrixMul::Param p;
            p.compute_mode = MmCM::FLOAT32;
            return storage.get<MatrixMul, 1>(p);
        }
    }
}

WorkspaceBundle get_bundle(const NCBKernSizeParam& param) {
    UNPACK_CONV_F32_NCB_KERN_SIZES(param);
    MEGDNN_MARK_USED_VAR(N);
    MEGDNN_MARK_USED_VAR(OH);
    MEGDNN_MARK_USED_VAR(OW);
    bool can_matrix_mul_direct =
            (FH == 1 && FW == 1 && SH == 1 && SW == 1 && PH == 0 && PW == 0);
    // temp space to store unrolled matrix
    // workspace for matrix mul opr
    // workspace for relayout opr
    size_t part0, part1, part2;
    if (can_matrix_mul_direct) {
        part0 = 0;
    } else {
        part0 = (IC * FH * FW * IH * IW) * param.grad_type.size();
    }
    part2 = (OC * IC * FH * FW) * param.filter_type.size();
    {
        TensorLayout A_, B_, C_;
        A_ = TensorLayout({IC * FH * FW, OC}, param.filter_type);
        B_ = TensorLayout({OC, IH * IW}, param.diff_type);
        C_ = TensorLayout({IC * FH * FW, IH * IW}, param.grad_type);
        part1 = get_matmul_opr(param)->get_workspace_in_bytes(A_, B_, C_);
    }
    return {nullptr, {part0, part1, part2}};
}

template <typename ftype, typename dtype, typename gtype>
void kern_matmul(const NCBKernParam& param) {
    bool is_xcorr = !param.filter_meta.should_flip;
    UNPACK_CONV_F32_NCB_KERN_SIZES(param);
    auto bundle = get_bundle(param);
    bundle.set(param.workspace_ptr);
    bool is1X1 =
            (FH == 1 && FW == 1 && SH == 1 && SW == 1 && PH == 0 && PW == 0);

    typedef void (*Func1)(const gtype*, gtype*, int, int, int, int, int, int,
                          int);
    typedef void (*Func2)(const gtype*, gtype*, int, int, int, int, int, int,
                          int, int, int, int, int);
    Func1 f1 = nullptr;
    Func2 f2 = nullptr;
    if (is_xcorr) {
        f1 = col2img<true>;
        f2 = col2img_stride_padding<true>;
    } else {
        f1 = col2img<false>;
        f2 = col2img_stride_padding<false>;
    }
    ftype* filter = const_cast<ftype*>(param.filter<ftype>());
    TensorND A_src, A_dst;
    {
        A_src.layout = TensorLayout({IC * FH * FW, OC},
                                    {static_cast<std::ptrdiff_t>(1),
                                     static_cast<std::ptrdiff_t>(IC * FH * FW)},
                                    param.filter_type);
        A_src.raw_ptr = static_cast<void*>(filter);
        A_dst.layout = TensorLayout({IC * FH * FW, OC}, param.filter_type);
        A_dst.raw_ptr = static_cast<void*>(bundle.get(2));
        // TODO Should be removed once armv8 convolution support transpose.
        get_relayout_opr()->exec(A_src, A_dst, inplace_cpu_handle().get());
    }
    for (size_t n = 0; n < N; ++n) {
        gtype *C_src, *C_dst;
        dtype* diff =
                const_cast<dtype*>(param.diff<dtype>() + n * param.inp_bs);
        gtype* grad = param.grad<gtype>() + n * param.out_bs;
        if (is1X1) {
            C_src = grad;
        } else {
            C_src = static_cast<gtype*>(bundle.get(0));
        }
        {
            TensorND B_, C_;
            B_.layout = TensorLayout({OC, IH * IW}, param.diff_type);
            B_.raw_ptr = static_cast<void*>(diff);
            C_.layout = TensorLayout({IC * FH * FW, IH * IW}, param.grad_type);
            C_.raw_ptr = C_src;
            Workspace workspace(static_cast<dt_byte*>(bundle.get(1)),
                                bundle.get_size(1));
            get_matmul_opr(param)->exec(A_dst, B_, C_, workspace);
        }

        if (!is1X1) {
            C_dst = grad;
            std::memset(C_dst, 0, param.grad_type.size() * IC * OH * OW);
            if (PH == 0 && PW == 0 && SH == 1 && SW == 1) {
                f1(C_src, C_dst, OH, OW, IC, IH, IW, FH, FW);
            } else {
                f2(C_src, C_dst, OH, OW, IC, IH, IW, FH, FW, SH, SW, PH, PW);
            }
        }
    }
}

void kern_direct(const NCBKernParam& param) {
    UNPACK_CONV_F32_NCB_KERN_SIZES(param);
    auto diff = param.diff<float>(), filter = param.filter<float>();
    auto grad = param.grad<float>();
    for (size_t n = 0; n < N; ++n) {
        convolution::run_conv_backward_data(
                diff + n * param.inp_bs, filter, grad + n * param.out_bs,
                param.workspace_ptr, IH, IW, IC, FH, FW, OH, OW, OC, PH, PW, SH,
                SW, !param.filter_meta.should_flip);
    }
}

}  // namespace

/* ===================== fallback algo ===================== */

bool ConvolutionImpl::AlgoFallback::usable(
167
         const NCBKernSizeParam& param,
168 169 170 171 172 173 174 175 176 177
        AlgoSelectionStrategy /*algo_selection_strategy*/) const {
    auto&& fm = param.filter_meta;
    return fm.format == param::Convolution::Format::NCHW &&
           param.src_type.enumv() == DTypeEnum::Float32 &&
           param.filter_type.enumv() == DTypeEnum::Float32 &&
           param.dst_type.enumv() == DTypeEnum::Float32 &&
           fm.spatial_ndim == 2 && fm.dilation[0] == 1 && fm.dilation[1] == 1;
}

size_t ConvolutionImpl::AlgoFallback::get_workspace(
178
         const NCBKernSizeParam& param) const {
179 180 181 182 183 184 185 186 187 188 189 190 191 192
    auto FH = param.filter_meta.spatial[0], FW = param.filter_meta.spatial[1];
    size_t nr_threads = param.nr_threads;
    if (param.filter_meta.should_flip) {
        // need transpose filter
        return WorkspaceBundle{nullptr, {FH * FW * sizeof(float)}}
                       .total_size_in_bytes() *
               nr_threads;
    } else {
        return 0;
    }
}

SmallVector<ConvolutionImpl::NCBKern>
ConvolutionImpl::AlgoFallback::dispatch_kern(
193
         const NCBKernSizeParam& param) const {
194 195 196
    size_t group = param.filter_meta.group;
    size_t N = param.n;
    size_t nr_threads = param.nr_threads;
197
    size_t workspace_per_thread = get_workspace( param) / nr_threads;
198 199 200
    auto kern_fallback = [workspace_per_thread](const NCBKernParam& p,
                                                const NCBKernIndex& ncb_index) {
        UNPACK_CONV_F32_NCB_KERN_SIZES(p);
201 202
        size_t batch_id = ncb_index.ndrange_id[1];
        size_t group_id = ncb_index.ndrange_id[0];
203
        MEGDNN_MARK_USED_VAR(N);
204 205 206
        auto src = p.src<float>(batch_id, group_id),
             filter = p.filter<float>(group_id);
        auto dst = p.dst<float>(batch_id, group_id);
207 208 209 210 211 212 213 214 215 216 217 218 219 220
        size_t thread_id = ncb_index.thread_id;
        void* workspace_ptr = reinterpret_cast<void*>(
                reinterpret_cast<ptrdiff_t>(p.workspace_ptr) +
                workspace_per_thread * thread_id);
        convolution::run_conv(src, filter, dst, workspace_ptr, IH, IW, IC, FH,
                              FW, OH, OW, OC, PH, PW, SH, SW,
                              !p.filter_meta.should_flip);
    };
    return {{kern_fallback, {group, N, 1_z}}};
}

/* ===================== naive algo ===================== */

bool ConvolutionImpl::AlgoNaive::usable(
221
         const NCBKernSizeParam& param,
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
        AlgoSelectionStrategy /*algo_selection_strategy*/) const {
    bool ret = false;

#define cb(dt) ret |= (param.src_type.enumv() == DTypeTrait<dt>::enumv);
    MEGDNN_FOREACH_COMPUTING_DTYPE_FLOAT(cb);
#undef cb
#define cb(dt_src, dt_dst)                                            \
    ret |= (param.src_type.enumv() == DTypeTrait<dt_src>::enumv &&    \
            param.filter_type.enumv() == DTypeTrait<dt_src>::enumv && \
            param.dst_type.enumv() == DTypeTrait<dt_dst>::enumv)
    cb(dtype::Int8, dtype::Int16);
    cb(dtype::Int8, dtype::Int32);
    cb(dtype::Quantized8Asymm, dtype::QuantizedS32);
    cb(dtype::QuantizedS8, dtype::QuantizedS32);
#undef cb
    ret = ret &&
          (param.filter_meta.format == param::Convolution::Format::NCHW ||
           param.filter_meta.format == param::Convolution::Format::NHWC);
    return ret;
}

SmallVector<ConvolutionImpl::NCBKern> ConvolutionImpl::AlgoNaive::dispatch_kern(
244
         const NCBKernSizeParam& param) const {
245 246 247 248 249 250 251 252
    size_t N = param.n;
    size_t group = param.filter_meta.group;
#define cb(dt, cmode, compute_type)                                      \
    do {                                                                 \
        if (param.src_type.enumv() == DTypeTrait<dt>::enumv &&           \
            param.compute_mode == param::ConvBias::ComputeMode::cmode) { \
            using ctype = DTypeTrait<dt>::ctype;                         \
            using comp_type = DTypeTrait<compute_type>::ctype;           \
253 254 255 256 257
            MIDOUT_BEGIN(megdnn_fallback_conv, midout_iv(1)) {           \
                return {{kern_naive_forward<ctype, ctype, comp_type>,    \
                         {group, N, 1_z}}};                              \
            }                                                            \
            MIDOUT_END();                                                \
258 259 260 261 262 263 264 265 266 267
        }                                                                \
    } while (0)

    cb(dtype::Float32, DEFAULT, dtype::Float32);
#if !MEGDNN_DISABLE_FLOAT16
    cb(dtype::Float16, DEFAULT, dtype::Float16);
    cb(dtype::Float16, FLOAT32, dtype::Float32);
#endif
#undef cb

268 269 270 271 272 273 274 275 276 277 278 279 280
#define cb(dt_src, dt_dst)                                              \
    do {                                                                \
        if (param.src_type.enumv() == DTypeTrait<dt_src>::enumv &&      \
            param.filter_type.enumv() == DTypeTrait<dt_src>::enumv &&   \
            param.dst_type.enumv() == DTypeTrait<dt_dst>::enumv) {      \
            MIDOUT_BEGIN(megdnn_fallback_conv, midout_iv(2)) {          \
                return {{kern_naive_forward<DTypeTrait<dt_src>::ctype,  \
                                            DTypeTrait<dt_dst>::ctype,  \
                                            DTypeTrait<dt_dst>::ctype>, \
                         {group, N, 1_z}}};                             \
            }                                                           \
            MIDOUT_END();                                               \
        }                                                               \
281 282 283 284 285 286 287 288 289 290 291
    } while (0)
    cb(dtype::Int8, dtype::Int16);
    cb(dtype::Int8, dtype::Int32);
    cb(dtype::Quantized8Asymm, dtype::QuantizedS32);
    cb(dtype::QuantizedS8, dtype::QuantizedS32);
    megdnn_throw(megdnn_mangle("unknown convolution data type"));
#undef cb
}

/* ===================== default algo ===================== */

292 293
ConvolutionImpl::AlgoDefault::AlgoDefault(ConvBiasImpl::AlgoBase* algorithm)
        : m_algorithm(algorithm) {
294 295 296 297 298
    megdnn_assert_internal(algorithm);
    m_name = ssprintf("CONVOLUTION_DEFAULT_%s", m_algorithm->name());
}

ConvBiasImpl::NCBKernSizeParam
299 300
ConvolutionImpl::AlgoDefault::init_conv_bias_param(
        const NCBKernSizeParam& param) {
301 302 303 304 305
    DType bias_type = param.dst_type;
    if (bias_type.category() == DTypeCategory::QUANTIZED) {
        bias_type = dtype::QuantizedS32(
                mul_scale(param.src_type, param.filter_type));
    }
306 307 308 309 310 311 312
    return {param,
            0,
            param::MatrixMul::Format::DEFAULT,
            bias_type,
            0,
            BiasMode::NO_BIAS,
            param::ConvBias::NonlineMode::IDENTITY};
313 314 315
}

bool ConvolutionImpl::AlgoDefault::is_preferred(
316
         const NCBKernSizeParam& param) const {
317
    ::ConvBiasImpl::NCBKernSizeParam conv_bias_param =
318 319
            init_conv_bias_param(param);
    return m_algorithm->is_preferred(conv_bias_param);
320 321 322
}

bool ConvolutionImpl::AlgoDefault::usable(
323
         const NCBKernSizeParam& param,
324 325
        AlgoSelectionStrategy algo_selection_strategy) const {
    ::ConvBiasImpl::NCBKernSizeParam conv_bias_param =
326 327
            init_conv_bias_param(param);
    return m_algorithm->usable(conv_bias_param,
328 329 330 331 332 333 334
                               static_cast<ConvBiasImpl::AlgoSelectionStrategy>(
                                       algo_selection_strategy));
}

WorkspaceBundle ConvolutionImpl::AlgoDefault::get_bundle(
        const NCBKernSizeParam& param) const {
    ::ConvBiasImpl::NCBKernSizeParam conv_bias_param =
335
            init_conv_bias_param(param);
336
    return WorkspaceBundle(nullptr, {m_algorithm->get_workspace(
337
                                            conv_bias_param)});
338 339 340
}

size_t ConvolutionImpl::AlgoDefault::get_workspace(
341
         const NCBKernSizeParam& param) const {
342 343 344
    return get_bundle(param).total_size_in_bytes();
}

345
size_t ConvolutionImpl::AlgoDefault::get_preprocess_workspace(
346
         const NCBKernSizeParam& param) const {
347
    ::ConvBiasImpl::NCBKernSizeParam conv_bias_param =
348 349
            init_conv_bias_param(param);
    return m_algorithm->get_preprocess_workspace(conv_bias_param);
350 351 352 353
}

SmallVector<TensorLayout>
ConvolutionImpl::AlgoDefault::deduce_preprocessed_filter_layout(
354
         const NCBKernSizeParam& param) const {
355
    ::ConvBiasImpl::NCBKernSizeParam conv_bias_param =
356 357
            init_conv_bias_param( param);
    return m_algorithm->deduce_preprocessed_filter_layout(conv_bias_param);
358 359 360 361 362
}

//! Return the implement preprocess kernel
SmallVector<ConvolutionImpl::NCBKern>
ConvolutionImpl::AlgoDefault::get_preprocess_kimpl(
363
         ConvBiasImpl::AlgoBase* algo,
364 365 366 367 368
        const NCBKernSizeParam& param) {
    MIDOUT_BEGIN(megdnn_fallback_conv, midout_iv("get_preprocess_kimpl"_hash)) {
        // construct the conv_bias kern param
        ::ConvBiasImpl::NCBKernParam conv_bias_param;
        static_cast<::ConvBiasImpl::NCBKernSizeParam&>(conv_bias_param) =
369
                init_conv_bias_param(param);
370
        auto conv_bias_preprocess_kerns =
371
                algo->dispatch_preprocess_kerns(conv_bias_param);
372 373 374
        SmallVector<ConvolutionImpl::NCBKern> convolution_preprocess_kerns;

        //! Set the conv_bias param using convolution param
375
        auto set_param_filter_workspace_ptr =
376
                [](const NCBKernParam& conv_param,
377 378 379 380
                   ::ConvBiasImpl::NCBKernParam& conv_bias_param) {
                    conv_bias_param.filter_ptr = conv_param.filter_ptr;
                    conv_bias_param.workspace_ptr = conv_param.workspace_ptr;
                    conv_bias_param.workspace_size = conv_param.workspace_size;
381 382 383 384
                };
        for (size_t i = 0; i < conv_bias_preprocess_kerns.size(); i++) {
            auto kernel = conv_bias_preprocess_kerns[i];
            //! If the kerenl batch parallel
385 386 387 388 389 390
            auto run = [param = conv_bias_param, kernel,
                        &set_param_filter_workspace_ptr](
                               const NCBKernParam& p,
                               const NCBKernIndex& ncb_index) mutable {
                set_param_filter_workspace_ptr(p, param);
                kernel.kern(param, {ncb_index.thread_id, ncb_index.ndrange_id});
391 392 393 394 395 396 397 398 399
            };
            convolution_preprocess_kerns.push_back({run, kernel.global_size});
        }
        return convolution_preprocess_kerns;
    }
    MIDOUT_END();
}

//! Return the implement kernel
400
SmallVector<ConvolutionImpl::NCBKern> ConvolutionImpl::AlgoDefault::get_kimpl(
401
        ConvBiasImpl::AlgoBase* algo,
402 403 404 405 406
        const NCBKernSizeParam& param) {
    MIDOUT_BEGIN(megdnn_fallback_conv, midout_iv(0)) {
        // construct the conv_bias kern param
        ::ConvBiasImpl::NCBKernParam conv_bias_param;
        static_cast<::ConvBiasImpl::NCBKernSizeParam&>(conv_bias_param) =
407 408
                init_conv_bias_param(param);
        auto&& conv_bias_kerns = algo->dispatch_kerns(conv_bias_param);
409 410 411
        SmallVector<ConvolutionImpl::NCBKern> convolution_kerns;

        //! Set the conv_bias param using convolution param
412
        auto set_copy_param_compute_address =
413
                [](const NCBKernParam& conv_param,
414 415 416 417 418 419
                   ::ConvBiasImpl::NCBKernParam& conv_bias_param) {
                    conv_bias_param.src_ptr = conv_param.src_ptr;
                    conv_bias_param.filter_ptr = conv_param.filter_ptr;
                    conv_bias_param.dst_ptr = conv_param.dst_ptr;
                    conv_bias_param.workspace_ptr = conv_param.workspace_ptr;
                    conv_bias_param.workspace_size = conv_param.workspace_size;
420 421
                };
        for (size_t i = 0; i < conv_bias_kerns.size(); i++) {
422
            auto&& kernel = conv_bias_kerns[i];
423
            //! If the kerenl batch parallel
424 425 426 427 428 429
            auto run = [param = conv_bias_param, kernel,
                        &set_copy_param_compute_address](
                               const NCBKernParam& p,
                               const NCBKernIndex& ncb_index) mutable {
                set_copy_param_compute_address(p, param);
                kernel.kern(param, {ncb_index.thread_id, ncb_index.ndrange_id});
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513
            };
            convolution_kerns.push_back({run, kernel.global_size});
        }
        return convolution_kerns;
    }
    MIDOUT_END();
}

/* ===================== direct algo ===================== */

bool ConvolutionBackwardDataImpl::AlgoDirect::usable(
        ConvolutionBackwardDataImpl*, const NCBKernSizeParam& param) const {
    auto&& fm = param.filter_meta;
    return fm.format == param::Convolution::Format::NCHW &&
           param.diff_type.enumv() == DTypeEnum::Float32 &&
           param.filter_type.enumv() == DTypeEnum::Float32 &&
           param.grad_type.enumv() == DTypeEnum::Float32 &&
           fm.spatial_ndim == 2 && fm.group == 1 && fm.dilation[0] == 1 &&
           fm.dilation[1] == 1;
}

size_t ConvolutionBackwardDataImpl::AlgoDirect::get_workspace(
        ConvolutionBackwardDataImpl*, const NCBKernSizeParam& param) const {
    auto FH = param.filter_meta.spatial[0], FW = param.filter_meta.spatial[1];
    if (param.filter_meta.should_flip) {
        // need transpose filter
        return FH * FW * sizeof(float);
    } else {
        return 0;
    }
}

ConvolutionBackwardDataImpl::ncb_kern_t
ConvolutionBackwardDataImpl::AlgoDirect::dispatch_kern(
        ConvolutionBackwardDataImpl*, const NCBKernSizeParam&) const {
    return kern_direct;
}

/* ===================== Matrix mul algo ===================== */

bool ConvolutionBackwardDataImpl::AlgoMatrixMul::usable(
        ConvolutionBackwardDataImpl*, const NCBKernSizeParam& param) const {
    auto&& fm = param.filter_meta;
    return fm.format == param::Convolution::Format::NCHW &&
           fm.spatial_ndim == 2 && fm.group == 1 && fm.dilation[0] == 1 &&
           fm.dilation[1] == 1;
}

size_t ConvolutionBackwardDataImpl::AlgoMatrixMul::get_workspace(
        ConvolutionBackwardDataImpl*, const NCBKernSizeParam& param) const {
    return get_bundle(param).total_size_in_bytes();
}

ConvolutionBackwardDataImpl::ncb_kern_t
ConvolutionBackwardDataImpl::AlgoMatrixMul::dispatch_kern(
        ConvolutionBackwardDataImpl*, const NCBKernSizeParam& param) const {
#define cb(dt)                                                    \
    do {                                                          \
        if (param.filter_type.enumv() == DTypeTrait<dt>::enumv) { \
            using ctype = DTypeTrait<dt>::ctype;                  \
            return kern_matmul<ctype, ctype, ctype>;              \
        }                                                         \
    } while (0);
    MEGDNN_FOREACH_COMPUTING_DTYPE_FLOAT(cb);
#undef cb

#define cb(dt_src, dt_dst)                                            \
    do {                                                              \
        if (param.diff_type.enumv() == DTypeTrait<dt_src>::enumv &&   \
            param.filter_type.enumv() == DTypeTrait<dt_src>::enumv && \
            param.grad_type.enumv() == DTypeTrait<dt_dst>::enumv) {   \
            return kern_matmul<DTypeTrait<dt_src>::ctype,             \
                               DTypeTrait<dt_src>::ctype,             \
                               DTypeTrait<dt_dst>::ctype>;            \
        }                                                             \
    } while (0)
    cb(dtype::Int8, dtype::Int32);
    cb(dtype::QuantizedS8, dtype::QuantizedS32);
    cb(dtype::Quantized8Asymm, dtype::QuantizedS32);
    megdnn_throw("unsupported data type on matrix mul");
#undef cb
}

// vim: syntax=cpp.doxygen