mirror of
https://github.com/Tencent/ncnn.git
synced 2026-10-17 04:41:47 +08:00
41f031e045
* adjust tests * opt shader coverage op * update gpu_coverage.cpp atomicor coalesce
666 lines
25 KiB
C++
666 lines
25 KiB
C++
// Copyright 2020 Tencent
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
#include "testutil.h"
|
|
|
|
#include "layer_type.h"
|
|
|
|
static int test_interp(const ncnn::Mat& a, int resize_type, float height_scale, float width_scale, int output_height, int output_width, int flag = 0)
|
|
{
|
|
ncnn::ParamDict pd;
|
|
pd.set(0, resize_type);
|
|
pd.set(1, height_scale);
|
|
pd.set(2, width_scale);
|
|
pd.set(3, output_height);
|
|
pd.set(4, output_width);
|
|
|
|
std::vector<ncnn::Mat> weights(0);
|
|
|
|
int ret = test_layer("Interp", pd, weights, a, 0.001, flag);
|
|
if (ret != 0)
|
|
{
|
|
fprintf(stderr, "test_interp failed a.dims=%d a=(%d %d %d) resize_type=%d height_scale=%f width_scale=%f output_height=%d output_width=%d\n", a.dims, a.w, a.h, a.c, resize_type, height_scale, width_scale, output_height, output_width);
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int test_interp_ref(const ncnn::Mat& a, int resize_type, int output_height, int output_width, int flag = 0)
|
|
{
|
|
ncnn::ParamDict pd;
|
|
pd.set(0, resize_type);
|
|
pd.set(5, 1);
|
|
|
|
std::vector<ncnn::Mat> as(2);
|
|
as[0] = a;
|
|
as[1] = ncnn::Mat(output_width, output_height, 1);
|
|
|
|
std::vector<ncnn::Mat> weights(0);
|
|
|
|
int ret = test_layer("Interp", pd, weights, as, 1, 0.001, flag);
|
|
if (ret != 0)
|
|
{
|
|
fprintf(stderr, "test_interp_ref failed a.dims=%d a=(%d %d %d) resize_type=%d output_height=%d output_width=%d\n", a.dims, a.w, a.h, a.c, resize_type, output_height, output_width);
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int test_interp_align_corner(const ncnn::Mat& a, int resize_type, float height_scale, float width_scale, int output_height, int output_width, int align_corner, int flag = 0)
|
|
{
|
|
ncnn::ParamDict pd;
|
|
pd.set(0, resize_type);
|
|
pd.set(1, height_scale);
|
|
pd.set(2, width_scale);
|
|
pd.set(3, output_height);
|
|
pd.set(4, output_width);
|
|
pd.set(6, align_corner);
|
|
|
|
std::vector<ncnn::Mat> weights(0);
|
|
|
|
int ret = test_layer("Interp", pd, weights, a, 0.001, flag);
|
|
if (ret != 0)
|
|
{
|
|
fprintf(stderr, "test_interp failed a.dims=%d a=(%d %d %d) resize_type=%d height_scale=%f width_scale=%f output_height=%d output_width=%d align_corner=%d\n", a.dims, a.w, a.h, a.c, resize_type, height_scale, width_scale, output_height, output_width, align_corner);
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int test_interp(const ncnn::Mat& a, int resize_type, float width_scale, int output_width)
|
|
{
|
|
ncnn::ParamDict pd;
|
|
pd.set(0, resize_type);
|
|
pd.set(1, 1.f);
|
|
pd.set(2, width_scale);
|
|
pd.set(3, 0);
|
|
pd.set(4, output_width);
|
|
|
|
std::vector<ncnn::Mat> weights(0);
|
|
|
|
int ret = test_layer("Interp", pd, weights, a);
|
|
if (ret != 0)
|
|
{
|
|
fprintf(stderr, "test_interp failed a.dims=%d a=(%d %d %d) resize_type=%d width_scale=%f output_width=%d\n", a.dims, a.w, a.h, a.c, resize_type, width_scale, output_width);
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int test_interp_ref(const ncnn::Mat& a, int resize_type, int output_width)
|
|
{
|
|
ncnn::ParamDict pd;
|
|
pd.set(0, resize_type);
|
|
pd.set(5, 1);
|
|
|
|
std::vector<ncnn::Mat> as(2);
|
|
as[0] = a;
|
|
as[1] = ncnn::Mat(output_width, 1);
|
|
|
|
std::vector<ncnn::Mat> weights(0);
|
|
|
|
int ret = test_layer("Interp", pd, weights, as);
|
|
if (ret != 0)
|
|
{
|
|
fprintf(stderr, "test_interp_ref failed a.dims=%d a=(%d %d %d) resize_type=%d output_width=%d\n", a.dims, a.w, a.h, a.c, resize_type, output_width);
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int test_interp_align_corner(const ncnn::Mat& a, int resize_type, float width_scale, int output_width, int align_corner)
|
|
{
|
|
ncnn::ParamDict pd;
|
|
pd.set(0, resize_type);
|
|
pd.set(1, 1.f);
|
|
pd.set(2, width_scale);
|
|
pd.set(3, 0);
|
|
pd.set(4, output_width);
|
|
pd.set(6, align_corner);
|
|
|
|
std::vector<ncnn::Mat> weights(0);
|
|
|
|
int ret = test_layer("Interp", pd, weights, a);
|
|
if (ret != 0)
|
|
{
|
|
fprintf(stderr, "test_interp failed a.dims=%d a=(%d %d %d) resize_type=%d width_scale=%f output_width=%d align_corner=%d\n", a.dims, a.w, a.h, a.c, resize_type, width_scale, output_width, align_corner);
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int test_interp_nearest_3d()
|
|
{
|
|
ncnn::Mat a = RandomMat(15, 16, 7);
|
|
ncnn::Mat b = RandomMat(14, 17, 12);
|
|
ncnn::Mat c = RandomMat(13, 14, 32);
|
|
|
|
// scalar geometry covers all scale, output-size and reference interface boundaries
|
|
return 0
|
|
|| test_interp(a, 1, 2.f, 2.f, 0, 0)
|
|
|| test_interp(a, 1, 4.f, 0.5f, 0, 0)
|
|
|| test_interp(a, 1, 1.2f, 1.2f, 0, 0)
|
|
|| test_interp(a, 1, 0.8f, 0.8f, 0, 0)
|
|
|| test_interp(a, 1, 1.f, 1.f, 10, 12)
|
|
|| test_interp(a, 1, 1.f, 1.f, 2, 2)
|
|
|| test_interp(a, 1, 1.f, 1.f, 15, 16)
|
|
|| test_interp_ref(a, 1, 10, 12)
|
|
|| test_interp_ref(a, 1, 2, 2)
|
|
|| test_interp_ref(a, 1, 15, 16)
|
|
|
|
// pack4 retains resize, alignment and reference interface representatives
|
|
|| test_interp(b, 1, 2.f, 2.f, 0, 0)
|
|
|| test_interp(b, 1, 1.f, 1.f, 10, 12)
|
|
|| test_interp(b, 1, 1.f, 1.f, 14, 17)
|
|
|| test_interp_ref(b, 1, 10, 12)
|
|
|| test_interp_ref(b, 1, 14, 17)
|
|
|
|
// pack16 retains resize, alignment and reference interface representatives
|
|
|| test_interp(c, 1, 2.f, 2.f, 0, 0)
|
|
|| test_interp(c, 1, 1.f, 1.f, 10, 12)
|
|
|| test_interp(c, 1, 1.f, 1.f, 14, 17)
|
|
|| test_interp_ref(c, 1, 10, 12)
|
|
|| test_interp_ref(c, 1, 14, 17);
|
|
}
|
|
|
|
static int test_interp_bilinear_3d()
|
|
{
|
|
ncnn::Mat a = RandomMat(15, 16, 7);
|
|
ncnn::Mat b = RandomMat(14, 17, 12);
|
|
ncnn::Mat c = RandomMat(13, 14, 32);
|
|
|
|
// scalar geometry covers all scale, output-size and reference interface boundaries
|
|
return 0
|
|
|| test_interp(a, 2, 2.f, 2.f, 0, 0)
|
|
|| test_interp(a, 2, 4.f, 0.5f, 0, 0)
|
|
|| test_interp(a, 2, 1.2f, 1.2f, 0, 0)
|
|
|| test_interp(a, 2, 0.8f, 0.8f, 0, 0)
|
|
|| test_interp(a, 2, 1.f, 1.f, 10, 12)
|
|
|| test_interp(a, 2, 1.f, 1.f, 2, 2)
|
|
|| test_interp(a, 2, 1.f, 1.f, 15, 16)
|
|
|| test_interp_align_corner(a, 2, 2.f, 2.f, 0, 0, 1)
|
|
|| test_interp_align_corner(a, 2, 4.f, 0.5f, 0, 0, 1)
|
|
|| test_interp_align_corner(a, 2, 1.2f, 1.2f, 0, 0, 1)
|
|
|| test_interp_align_corner(a, 2, 0.8f, 0.8f, 0, 0, 1)
|
|
|| test_interp_align_corner(a, 2, 1.f, 1.f, 10, 12, 1)
|
|
|| test_interp_align_corner(a, 2, 1.f, 1.f, 2, 2, 1)
|
|
|| test_interp_align_corner(a, 2, 1.f, 1.f, 15, 16, 1)
|
|
|| test_interp_ref(a, 2, 10, 12)
|
|
|| test_interp_ref(a, 2, 2, 2)
|
|
|| test_interp_ref(a, 2, 15, 16)
|
|
|
|
// pack4 retains resize, alignment and reference interface representatives
|
|
|| test_interp(b, 2, 2.f, 2.f, 0, 0)
|
|
// fractional downscale retains two-column and scalar horizontal tails
|
|
|| test_interp(b, 2, 0.8f, 0.8f, 0, 0)
|
|
|| test_interp(b, 2, 1.f, 1.f, 10, 12)
|
|
|| test_interp(b, 2, 1.f, 1.f, 14, 17)
|
|
|| test_interp_align_corner(b, 2, 2.f, 2.f, 0, 0, 1)
|
|
|| test_interp_align_corner(b, 2, 1.f, 1.f, 10, 12, 1)
|
|
|| test_interp_align_corner(b, 2, 1.f, 1.f, 14, 17, 1)
|
|
|| test_interp_ref(b, 2, 10, 12)
|
|
|| test_interp_ref(b, 2, 14, 17)
|
|
|
|
// pack16 retains resize, alignment and reference interface representatives
|
|
|| test_interp(c, 2, 2.f, 2.f, 0, 0)
|
|
|| test_interp(c, 2, 1.f, 1.f, 10, 12)
|
|
|| test_interp(c, 2, 1.f, 1.f, 14, 17)
|
|
|| test_interp_align_corner(c, 2, 2.f, 2.f, 0, 0, 1)
|
|
|| test_interp_align_corner(c, 2, 1.f, 1.f, 10, 12, 1)
|
|
|| test_interp_align_corner(c, 2, 1.f, 1.f, 14, 17, 1)
|
|
|| test_interp_ref(c, 2, 10, 12)
|
|
|| test_interp_ref(c, 2, 14, 17);
|
|
}
|
|
|
|
static int test_interp_bicubic_3d()
|
|
{
|
|
ncnn::Mat a = RandomMat(16, 17, 13);
|
|
ncnn::Mat b = RandomMat(18, 19, 12);
|
|
ncnn::Mat c = RandomMat(13, 14, 32);
|
|
|
|
// scalar geometry covers all scale, output-size and reference interface boundaries
|
|
return 0
|
|
|| test_interp(a, 3, 2.f, 2.f, 0, 0)
|
|
|| test_interp(a, 3, 4.f, 0.5f, 0, 0)
|
|
|| test_interp(a, 3, 1.2f, 1.2f, 0, 0)
|
|
|| test_interp(a, 3, 0.8f, 0.8f, 0, 0)
|
|
|| test_interp(a, 3, 1.f, 1.f, 10, 12)
|
|
|| test_interp(a, 3, 1.f, 1.f, 2, 2)
|
|
|| test_interp(a, 3, 1.f, 1.f, 6, 7)
|
|
|| test_interp(a, 3, 1.f, 1.f, 16, 17)
|
|
|| test_interp_align_corner(a, 3, 2.f, 2.f, 0, 0, 1)
|
|
|| test_interp_align_corner(a, 3, 4.f, 0.5f, 0, 0, 1)
|
|
|| test_interp_align_corner(a, 3, 1.2f, 1.2f, 0, 0, 1)
|
|
|| test_interp_align_corner(a, 3, 0.8f, 0.8f, 0, 0, 1)
|
|
|| test_interp_align_corner(a, 3, 1.f, 1.f, 10, 12, 1)
|
|
|| test_interp_align_corner(a, 3, 1.f, 1.f, 2, 2, 1)
|
|
|| test_interp_align_corner(a, 3, 1.f, 1.f, 6, 7, 1)
|
|
|| test_interp_align_corner(a, 3, 1.f, 1.f, 16, 17, 1)
|
|
|| test_interp_ref(a, 3, 2, 2)
|
|
|| test_interp_ref(a, 3, 6, 7)
|
|
|| test_interp_ref(a, 3, 16, 17)
|
|
|
|
// pack4 retains resize, alignment and reference interface representatives
|
|
|| test_interp(b, 3, 2.f, 2.f, 0, 0)
|
|
|| test_interp(b, 3, 0.8f, 0.8f, 0, 0)
|
|
|| test_interp(b, 3, 1.f, 1.f, 10, 12)
|
|
|| test_interp(b, 3, 1.f, 1.f, 2, 2)
|
|
|| test_interp(b, 3, 1.f, 1.f, 6, 7)
|
|
|| test_interp(b, 3, 1.f, 1.f, 18, 19)
|
|
|| test_interp_align_corner(b, 3, 2.f, 2.f, 0, 0, 1)
|
|
|| test_interp_align_corner(b, 3, 0.8f, 0.8f, 0, 0, 1)
|
|
|| test_interp_align_corner(b, 3, 1.f, 1.f, 2, 2, 1)
|
|
// the final two-row reuse includes an odd horizontal tail
|
|
|| test_interp_align_corner(b, 3, 1.f, 1.f, 6, 7, 1)
|
|
|| test_interp_align_corner(b, 3, 1.f, 1.f, 18, 19, 1)
|
|
|| test_interp_ref(b, 3, 2, 2)
|
|
|| test_interp_ref(b, 3, 18, 19)
|
|
|
|
// pack16 retains resize, alignment and reference interface representatives
|
|
|| test_interp(c, 3, 2.f, 2.f, 0, 0)
|
|
|| test_interp(c, 3, 0.8f, 0.8f, 0, 0)
|
|
|| test_interp(c, 3, 1.f, 1.f, 10, 12)
|
|
|| test_interp(c, 3, 1.f, 1.f, 2, 2)
|
|
|| test_interp(c, 3, 1.f, 1.f, 6, 7)
|
|
|| test_interp(c, 3, 1.f, 1.f, 18, 19)
|
|
|| test_interp_align_corner(c, 3, 2.f, 2.f, 0, 0, 1)
|
|
|| test_interp_align_corner(c, 3, 0.8f, 0.8f, 0, 0, 1)
|
|
|| test_interp_align_corner(c, 3, 1.f, 1.f, 2, 2, 1)
|
|
|| test_interp_align_corner(c, 3, 1.f, 1.f, 18, 19, 1)
|
|
|| test_interp_ref(c, 3, 2, 2)
|
|
|| test_interp_ref(c, 3, 18, 19);
|
|
}
|
|
|
|
static int test_interp_nearest_2d()
|
|
{
|
|
ncnn::Mat a = RandomMat(15, 7);
|
|
ncnn::Mat b = RandomMat(14, 12);
|
|
ncnn::Mat c = RandomMat(13, 32);
|
|
|
|
// scalar geometry covers all scale, output-size and reference interface boundaries
|
|
return 0
|
|
|| test_interp(a, 1, 2.f, 0)
|
|
|| test_interp(a, 1, 0.5f, 0)
|
|
|| test_interp(a, 1, 1.2f, 0)
|
|
|| test_interp(a, 1, 0.8f, 0)
|
|
|| test_interp(a, 1, 1.f, 12)
|
|
|| test_interp(a, 1, 1.f, 2)
|
|
|| test_interp(a, 1, 1.f, 16)
|
|
|| test_interp_ref(a, 1, 12)
|
|
|| test_interp_ref(a, 1, 2)
|
|
|| test_interp_ref(a, 1, 16)
|
|
|
|
// pack4 retains resize, alignment and reference interface representatives
|
|
|| test_interp(b, 1, 2.f, 0)
|
|
|| test_interp(b, 1, 1.f, 12)
|
|
|| test_interp(b, 1, 1.f, 17)
|
|
|| test_interp_ref(b, 1, 12)
|
|
|| test_interp_ref(b, 1, 17)
|
|
|
|
// pack16 retains resize, alignment and reference interface representatives
|
|
|| test_interp(c, 1, 2.f, 0)
|
|
|| test_interp(c, 1, 1.f, 12)
|
|
|| test_interp(c, 1, 1.f, 17)
|
|
|| test_interp_ref(c, 1, 12)
|
|
|| test_interp_ref(c, 1, 17);
|
|
}
|
|
|
|
static int test_interp_bilinear_2d()
|
|
{
|
|
ncnn::Mat a = RandomMat(15, 7);
|
|
ncnn::Mat b = RandomMat(14, 12);
|
|
ncnn::Mat c = RandomMat(13, 32);
|
|
|
|
// scalar geometry covers all scale, output-size and reference interface boundaries
|
|
return 0
|
|
|| test_interp(a, 2, 2.f, 0)
|
|
|| test_interp(a, 2, 0.5f, 0)
|
|
|| test_interp(a, 2, 1.2f, 0)
|
|
|| test_interp(a, 2, 0.8f, 0)
|
|
|| test_interp(a, 2, 1.f, 12)
|
|
|| test_interp(a, 2, 1.f, 2)
|
|
|| test_interp(a, 2, 1.f, 16)
|
|
|| test_interp_align_corner(a, 2, 2.f, 0, 1)
|
|
|| test_interp_align_corner(a, 2, 0.5f, 0, 1)
|
|
|| test_interp_align_corner(a, 2, 1.2f, 0, 1)
|
|
|| test_interp_align_corner(a, 2, 0.8f, 0, 1)
|
|
|| test_interp_align_corner(a, 2, 1.f, 12, 1)
|
|
|| test_interp_align_corner(a, 2, 1.f, 2, 1)
|
|
|| test_interp_align_corner(a, 2, 1.f, 16, 1)
|
|
|| test_interp_ref(a, 2, 12)
|
|
|| test_interp_ref(a, 2, 2)
|
|
|| test_interp_ref(a, 2, 16)
|
|
|
|
// pack4 retains resize, alignment and reference interface representatives
|
|
|| test_interp(b, 2, 2.f, 0)
|
|
|| test_interp(b, 2, 1.f, 12)
|
|
|| test_interp(b, 2, 1.f, 17)
|
|
|| test_interp_align_corner(b, 2, 2.f, 0, 1)
|
|
|| test_interp_align_corner(b, 2, 1.f, 12, 1)
|
|
|| test_interp_align_corner(b, 2, 1.f, 17, 1)
|
|
|| test_interp_ref(b, 2, 12)
|
|
|| test_interp_ref(b, 2, 17)
|
|
|
|
// pack16 retains resize, alignment and reference interface representatives
|
|
|| test_interp(c, 2, 2.f, 0)
|
|
|| test_interp(c, 2, 1.f, 12)
|
|
|| test_interp(c, 2, 1.f, 17)
|
|
|| test_interp_align_corner(c, 2, 2.f, 0, 1)
|
|
|| test_interp_align_corner(c, 2, 1.f, 12, 1)
|
|
|| test_interp_align_corner(c, 2, 1.f, 17, 1)
|
|
|| test_interp_ref(c, 2, 12)
|
|
|| test_interp_ref(c, 2, 17);
|
|
}
|
|
|
|
static int test_interp_bicubic_2d()
|
|
{
|
|
ncnn::Mat a = RandomMat(16, 13);
|
|
ncnn::Mat b = RandomMat(18, 12);
|
|
ncnn::Mat c = RandomMat(13, 32);
|
|
|
|
// scalar geometry covers all scale, output-size and reference interface boundaries
|
|
return 0
|
|
|| test_interp(a, 3, 2.f, 0)
|
|
|| test_interp(a, 3, 0.5f, 0)
|
|
|| test_interp(a, 3, 1.2f, 0)
|
|
|| test_interp(a, 3, 0.8f, 0)
|
|
|| test_interp(a, 3, 1.f, 12)
|
|
|| test_interp(a, 3, 1.f, 2)
|
|
|| test_interp(a, 3, 1.f, 7)
|
|
|| test_interp(a, 3, 1.f, 17)
|
|
|| test_interp_align_corner(a, 3, 2.f, 0, 1)
|
|
|| test_interp_align_corner(a, 3, 0.5f, 0, 1)
|
|
|| test_interp_align_corner(a, 3, 1.2f, 0, 1)
|
|
|| test_interp_align_corner(a, 3, 0.8f, 0, 1)
|
|
|| test_interp_align_corner(a, 3, 1.f, 12, 1)
|
|
|| test_interp_align_corner(a, 3, 1.f, 2, 1)
|
|
|| test_interp_align_corner(a, 3, 1.f, 7, 1)
|
|
|| test_interp_align_corner(a, 3, 1.f, 17, 1)
|
|
|| test_interp_ref(a, 3, 2)
|
|
|| test_interp_ref(a, 3, 7)
|
|
|| test_interp_ref(a, 3, 17)
|
|
|
|
// pack4 retains resize, alignment and reference interface representatives
|
|
|| test_interp(b, 3, 2.f, 0)
|
|
|| test_interp(b, 3, 0.8f, 0)
|
|
|| test_interp(b, 3, 1.f, 12)
|
|
|| test_interp(b, 3, 1.f, 2)
|
|
|| test_interp(b, 3, 1.f, 7)
|
|
|| test_interp(b, 3, 1.f, 19)
|
|
|| test_interp_align_corner(b, 3, 2.f, 0, 1)
|
|
|| test_interp_align_corner(b, 3, 0.8f, 0, 1)
|
|
|| test_interp_align_corner(b, 3, 1.f, 2, 1)
|
|
|| test_interp_align_corner(b, 3, 1.f, 19, 1)
|
|
|| test_interp_ref(b, 3, 2)
|
|
|| test_interp_ref(b, 3, 19)
|
|
|
|
// pack16 retains resize, alignment and reference interface representatives
|
|
|| test_interp(c, 3, 2.f, 0)
|
|
|| test_interp(c, 3, 0.8f, 0)
|
|
|| test_interp(c, 3, 1.f, 12)
|
|
|| test_interp(c, 3, 1.f, 2)
|
|
|| test_interp(c, 3, 1.f, 7)
|
|
|| test_interp(c, 3, 1.f, 19)
|
|
|| test_interp_align_corner(c, 3, 2.f, 0, 1)
|
|
|| test_interp_align_corner(c, 3, 0.8f, 0, 1)
|
|
|| test_interp_align_corner(c, 3, 1.f, 2, 1)
|
|
|| test_interp_align_corner(c, 3, 1.f, 19, 1)
|
|
|| test_interp_ref(c, 3, 2)
|
|
|| test_interp_ref(c, 3, 19);
|
|
}
|
|
|
|
static int test_interp_6()
|
|
{
|
|
ncnn::Mat a = RandomMat(17);
|
|
ncnn::Mat b = RandomMat(20);
|
|
ncnn::Mat c = RandomMat(48);
|
|
|
|
return 0
|
|
|| test_interp(a, 1, 2.f, 3.f, 0, 0)
|
|
|| test_interp(a, 1, 1.f, 1.f, 10, 12)
|
|
|| test_interp(a, 1, 1.f, 1.f, 15, 16)
|
|
|| test_interp_ref(a, 1, 10, 12)
|
|
|| test_interp_ref(a, 1, 4, 4)
|
|
|| test_interp_ref(a, 1, 15, 16)
|
|
|
|
|| test_interp(b, 1, 4.f, 5.f, 0, 0)
|
|
|| test_interp(b, 1, 1.f, 1.f, 10, 12)
|
|
|| test_interp(b, 1, 1.f, 1.f, 14, 17)
|
|
|| test_interp_ref(b, 1, 5, 5)
|
|
|| test_interp_ref(b, 1, 14, 17)
|
|
|
|
|| test_interp(c, 1, 6.f, 7.f, 0, 0)
|
|
|| test_interp(c, 1, 1.f, 1.f, 10, 12)
|
|
|| test_interp(c, 1, 1.f, 1.f, 14, 17)
|
|
|| test_interp_ref(c, 1, 6, 6)
|
|
|| test_interp_ref(c, 1, 14, 17);
|
|
}
|
|
|
|
// dims=3, nearest, pack8 channels (c%8==0 && c%16!=0) and pack1 channels (c%4!=0)
|
|
static int test_interp_7()
|
|
{
|
|
ncnn::Mat a = RandomMat(15, 16, 8);
|
|
ncnn::Mat b = RandomMat(14, 17, 24);
|
|
ncnn::Mat c = RandomMat(13, 14, 3);
|
|
|
|
return 0
|
|
|| test_interp(a, 1, 2.f, 2.f, 0, 0)
|
|
|| test_interp(a, 1, 4.f, 0.5f, 0, 0)
|
|
|| test_interp(a, 1, 1.2f, 1.2f, 0, 0)
|
|
|| test_interp(a, 1, 0.8f, 0.8f, 0, 0)
|
|
|| test_interp(a, 1, 1.f, 1.f, 10, 12)
|
|
|| test_interp(a, 1, 1.f, 1.f, 15, 16)
|
|
|| test_interp_ref(a, 1, 10, 12)
|
|
|| test_interp_ref(a, 1, 15, 16)
|
|
|
|
|| test_interp(b, 1, 2.f, 2.f, 0, 0, TEST_LAYER_DISABLE_GPU_TESTING)
|
|
|| test_interp(b, 1, 0.5f, 0.5f, 0, 0)
|
|
|| test_interp(b, 1, 1.f, 1.f, 10, 12, TEST_LAYER_DISABLE_GPU_TESTING)
|
|
|| test_interp(b, 1, 1.f, 1.f, 14, 17, TEST_LAYER_DISABLE_GPU_TESTING)
|
|
|| test_interp_ref(b, 1, 10, 12, TEST_LAYER_DISABLE_GPU_TESTING)
|
|
|| test_interp_ref(b, 1, 14, 17, TEST_LAYER_DISABLE_GPU_TESTING)
|
|
|
|
|| test_interp(c, 1, 2.f, 2.f, 0, 0)
|
|
|| test_interp(c, 1, 0.5f, 0.5f, 0, 0)
|
|
|| test_interp(c, 1, 1.f, 1.f, 10, 12)
|
|
|| test_interp_ref(c, 1, 10, 12);
|
|
}
|
|
|
|
// dims=3, bilinear, pack8 channels and pack1 channels
|
|
static int test_interp_8()
|
|
{
|
|
ncnn::Mat a = RandomMat(15, 16, 8);
|
|
ncnn::Mat b = RandomMat(14, 17, 24);
|
|
ncnn::Mat c = RandomMat(13, 14, 3);
|
|
|
|
return 0
|
|
|| test_interp(a, 2, 2.f, 2.f, 0, 0)
|
|
|| test_interp(a, 2, 4.f, 0.5f, 0, 0)
|
|
|| test_interp(a, 2, 1.2f, 1.2f, 0, 0)
|
|
|| test_interp(a, 2, 0.8f, 0.8f, 0, 0)
|
|
|| test_interp(a, 2, 1.f, 1.f, 10, 12)
|
|
|| test_interp(a, 2, 1.f, 1.f, 15, 16)
|
|
|| test_interp_align_corner(a, 2, 2.f, 2.f, 0, 0, 1)
|
|
|| test_interp_align_corner(a, 2, 0.8f, 0.8f, 0, 0, 1)
|
|
|| test_interp_align_corner(a, 2, 1.f, 1.f, 10, 12, 1)
|
|
|| test_interp_ref(a, 2, 10, 12)
|
|
|| test_interp_ref(a, 2, 15, 16)
|
|
|
|
|| test_interp(b, 2, 2.f, 2.f, 0, 0, TEST_LAYER_DISABLE_GPU_TESTING)
|
|
|| test_interp(b, 2, 0.5f, 0.5f, 0, 0)
|
|
|| test_interp(b, 2, 1.f, 1.f, 10, 12, TEST_LAYER_DISABLE_GPU_TESTING)
|
|
|| test_interp_align_corner(b, 2, 2.f, 2.f, 0, 0, 1, TEST_LAYER_DISABLE_GPU_TESTING)
|
|
|| test_interp_ref(b, 2, 10, 12, TEST_LAYER_DISABLE_GPU_TESTING)
|
|
|
|
|| test_interp(c, 2, 2.f, 2.f, 0, 0)
|
|
|| test_interp(c, 2, 0.5f, 0.5f, 0, 0)
|
|
|| test_interp(c, 2, 1.f, 1.f, 10, 12)
|
|
|| test_interp_align_corner(c, 2, 2.f, 2.f, 0, 0, 1)
|
|
|| test_interp_ref(c, 2, 10, 12);
|
|
}
|
|
|
|
// dims=3, bicubic, pack8 channels and pack1 channels
|
|
// Uses large output sizes (>= 16) to exercise AVX512 gather-based hresize loops in pack1 path
|
|
// Uses various downscale ratios to trigger sy row-reuse cases (+1/+2/+3/full)
|
|
static int test_interp_9()
|
|
{
|
|
ncnn::Mat a = RandomMat(16, 17, 8);
|
|
ncnn::Mat b = RandomMat(18, 19, 24);
|
|
ncnn::Mat c = RandomMat(13, 14, 3);
|
|
ncnn::Mat d = RandomMat(32, 32, 5);
|
|
|
|
return 0
|
|
|| test_interp(a, 3, 2.f, 2.f, 0, 0)
|
|
|| test_interp(a, 3, 4.f, 0.5f, 0, 0)
|
|
|| test_interp(a, 3, 1.2f, 1.2f, 0, 0)
|
|
|| test_interp(a, 3, 0.8f, 0.8f, 0, 0)
|
|
|| test_interp(a, 3, 1.f, 1.f, 10, 12)
|
|
|| test_interp(a, 3, 1.f, 1.f, 6, 7)
|
|
|| test_interp(a, 3, 1.f, 1.f, 16, 17)
|
|
|| test_interp_align_corner(a, 3, 2.f, 2.f, 0, 0, 1)
|
|
|| test_interp_align_corner(a, 3, 0.8f, 0.8f, 0, 0, 1)
|
|
|| test_interp_align_corner(a, 3, 1.f, 1.f, 10, 12, 1)
|
|
|| test_interp_ref(a, 3, 6, 7)
|
|
|| test_interp_ref(a, 3, 16, 17)
|
|
|
|
|| test_interp(b, 3, 2.f, 2.f, 0, 0)
|
|
|| test_interp(b, 3, 0.5f, 0.5f, 0, 0)
|
|
|| test_interp(b, 3, 1.f, 1.f, 10, 12)
|
|
|| test_interp_align_corner(b, 3, 2.f, 2.f, 0, 0, 1)
|
|
|| test_interp_ref(b, 3, 10, 12)
|
|
|
|
// pack1, large output width to hit AVX512 gather loops
|
|
|| test_interp(c, 3, 2.f, 2.f, 0, 0)
|
|
|| test_interp(c, 3, 0.5f, 0.5f, 0, 0)
|
|
|| test_interp(c, 3, 1.f, 1.f, 10, 12)
|
|
|| test_interp(c, 3, 1.f, 1.f, 20, 20)
|
|
|| test_interp_align_corner(c, 3, 2.f, 2.f, 0, 0, 1)
|
|
|| test_interp_align_corner(c, 3, 1.f, 1.f, 20, 20, 1)
|
|
|| test_interp_ref(c, 3, 10, 12)
|
|
|| test_interp_ref(c, 3, 20, 20)
|
|
|
|
// pack1, large input downscaled to trigger sy jumps of +2 and +3
|
|
|| test_interp(d, 3, 0.25f, 0.25f, 0, 0)
|
|
|| test_interp(d, 3, 0.3f, 0.3f, 0, 0)
|
|
|| test_interp(d, 3, 1.f, 1.f, 8, 20)
|
|
|| test_interp(d, 3, 1.f, 1.f, 10, 24)
|
|
|| test_interp(d, 3, 1.f, 1.f, 16, 20)
|
|
|| test_interp_align_corner(d, 3, 0.25f, 0.25f, 0, 0, 1)
|
|
|| test_interp_align_corner(d, 3, 1.f, 1.f, 8, 20, 1)
|
|
|| test_interp_align_corner(d, 3, 1.f, 1.f, 16, 20, 1)
|
|
|| test_interp_ref(d, 3, 8, 20)
|
|
|| test_interp_ref(d, 3, 16, 20);
|
|
}
|
|
|
|
// dims=2, all resize types, pack8 (h=8) and pack1 (h=3)
|
|
static int test_interp_10()
|
|
{
|
|
ncnn::Mat a = RandomMat(15, 8);
|
|
ncnn::Mat b = RandomMat(14, 24);
|
|
ncnn::Mat c = RandomMat(13, 3);
|
|
|
|
return 0
|
|
// nearest
|
|
|| test_interp(a, 1, 2.f, 0)
|
|
|| test_interp(a, 1, 0.5f, 0)
|
|
|| test_interp(a, 1, 1.f, 12)
|
|
|| test_interp_ref(a, 1, 12)
|
|
|
|
|| test_interp(b, 1, 2.f, 0)
|
|
|| test_interp(b, 1, 1.f, 12)
|
|
|| test_interp_ref(b, 1, 12)
|
|
|
|
|| test_interp(c, 1, 2.f, 0)
|
|
|| test_interp(c, 1, 1.f, 12)
|
|
|| test_interp_ref(c, 1, 12)
|
|
|
|
// bilinear
|
|
|| test_interp(a, 2, 2.f, 0)
|
|
|| test_interp(a, 2, 0.5f, 0)
|
|
|| test_interp(a, 2, 1.f, 12)
|
|
|| test_interp_align_corner(a, 2, 2.f, 0, 1)
|
|
|| test_interp_align_corner(a, 2, 1.f, 12, 1)
|
|
|| test_interp_ref(a, 2, 12)
|
|
|
|
|| test_interp(b, 2, 2.f, 0)
|
|
|| test_interp(b, 2, 1.f, 12)
|
|
|| test_interp_align_corner(b, 2, 2.f, 0, 1)
|
|
|| test_interp_ref(b, 2, 12)
|
|
|
|
|| test_interp(c, 2, 2.f, 0)
|
|
|| test_interp(c, 2, 1.f, 12)
|
|
|| test_interp_align_corner(c, 2, 2.f, 0, 1)
|
|
|| test_interp_ref(c, 2, 12)
|
|
|
|
// bicubic
|
|
|| test_interp(a, 3, 2.f, 0)
|
|
|| test_interp(a, 3, 0.5f, 0)
|
|
|| test_interp(a, 3, 1.f, 12)
|
|
|| test_interp(a, 3, 1.f, 7)
|
|
|| test_interp_align_corner(a, 3, 2.f, 0, 1)
|
|
|| test_interp_align_corner(a, 3, 1.f, 12, 1)
|
|
|| test_interp_ref(a, 3, 12)
|
|
|
|
|| test_interp(b, 3, 2.f, 0)
|
|
|| test_interp(b, 3, 1.f, 12)
|
|
|| test_interp_align_corner(b, 3, 2.f, 0, 1)
|
|
|| test_interp_ref(b, 3, 12)
|
|
|
|
|| test_interp(c, 3, 2.f, 0)
|
|
|| test_interp(c, 3, 1.f, 12)
|
|
|| test_interp_align_corner(c, 3, 2.f, 0, 1)
|
|
|| test_interp_ref(c, 3, 12);
|
|
}
|
|
|
|
// dims=1, pack8 (w=8, w=24)
|
|
static int test_interp_11()
|
|
{
|
|
ncnn::Mat a = RandomMat(8);
|
|
ncnn::Mat b = RandomMat(24);
|
|
|
|
return 0
|
|
|| test_interp(a, 1, 2.f, 3.f, 0, 0)
|
|
|| test_interp(a, 1, 1.f, 1.f, 10, 12)
|
|
|| test_interp(a, 1, 1.f, 1.f, 4, 4)
|
|
|| test_interp_ref(a, 1, 10, 12)
|
|
|| test_interp_ref(a, 1, 4, 4)
|
|
|
|
|| test_interp(b, 1, 4.f, 5.f, 0, 0)
|
|
|| test_interp(b, 1, 1.f, 1.f, 10, 12)
|
|
|| test_interp_ref(b, 1, 10, 12)
|
|
|| test_interp_ref(b, 1, 5, 5);
|
|
}
|
|
|
|
#if NCNN_VALIDATION
|
|
static int test_interp_load_param()
|
|
{
|
|
// reject unsupported interpolation modes before creating any pipeline
|
|
ncnn::ParamDict base;
|
|
return test_layer_param(ncnn::LayerType::Interp, base, 0, -1, -1)
|
|
|| test_layer_param(ncnn::LayerType::Interp, base, 0, 4, -1);
|
|
}
|
|
#endif // NCNN_VALIDATION
|
|
|
|
int main()
|
|
{
|
|
SRAND(7767517);
|
|
|
|
return 0
|
|
|| test_interp_nearest_3d()
|
|
|| test_interp_bilinear_3d()
|
|
|| test_interp_bicubic_3d()
|
|
|| test_interp_nearest_2d()
|
|
|| test_interp_bilinear_2d()
|
|
|| test_interp_bicubic_2d()
|
|
|| test_interp_6()
|
|
|| test_interp_7()
|
|
|| test_interp_8()
|
|
|| test_interp_9()
|
|
|| test_interp_10()
|
|
|| test_interp_11()
|
|
#if NCNN_VALIDATION
|
|
|| test_interp_load_param()
|
|
#endif // NCNN_VALIDATION
|
|
;
|
|
}
|