mask_conv.cpp 1.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 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
/**
 * \file dnn/test/cuda/mask_conv.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
 * "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 */
#include "test/cuda/fixture.h"

#include "megdnn/oprs.h"
#include "test/common/benchmarker.h"
#include "test/common/checker.h"
#include "test/common/mask_conv.h"
#include "test/common/rng.h"

using namespace megdnn;
using namespace test;

TEST_F(CUDA, MASK_CONV) {
    mask_conv_test(handle_cuda());
}

TEST_F(CUDA, MASK_CONV_BENCHMARK) {
    mask_conv_benchmark(handle_cuda());
}

TEST_F(CUDA, MASK_PROPAGATE) {
    Checker<MaskPropagate> checker(handle_cuda());
    auto run = [&](size_t IH, size_t IW, size_t FH, size_t FW, size_t SH = 1,
                   size_t SW = 1, size_t PH = 0, size_t PW = 0, size_t DH = 1,
                   size_t DW = 1) {
        using Param = param::MaskPropagate;
        Param param(PH, PW, SH, SW, FH, FW, DH, DW);
        TensorShape src_shape({IH, IW}), dst({});
        auto rng = std::make_unique<BernoulliRNG>(0.5);
        checker.set_param(param).set_rng(0, rng.get()).execs({src_shape, dst});
#undef test
    };
#define cb(DType)                        \
    checker.set_dtype(0, DType());       \
    run(3, 3, 1, 1);                     \
    run(5, 5, 2, 3, 2, 2);               \
    run(5, 5, 3, 3, 2, 2, 1, 2);         \
    run(5, 5, 3, 3, 2, 1, 1, 2);         \
    run(5, 5, 3, 3, 1, 2, 2, 2);         \
    run(24, 23, 4, 4, 1, 1, 3, 2);       \
    run(24, 23, 4, 4, 1, 1, 3, 2, 2, 2); \
    run(24, 23, 4, 4, 1, 1, 3, 2, 2, 3); \
    run(24, 23, 4, 4, 1, 1, 3, 2, 3, 3);

    // cb(dtype::Int32)
    MEGDNN_FOREACH_COMPUTING_DTYPE_INT(cb);
#undef cb
}