Browse Source

fix innerproduct vulkan pack8 and arm neon, disable packing_layout for int8 test

tags/20200413
nihuini 6 years ago
parent
commit
85d5e5d3e4
6 changed files with 69 additions and 38 deletions
  1. +1
    -0
      src/layer/arm/innerproduct_arm.cpp
  2. +1
    -1
      src/layer/vulkan/shader/innerproduct_pack1to8.comp
  3. +1
    -1
      src/layer/vulkan/shader/innerproduct_pack4to8.comp
  4. +1
    -1
      src/layer/vulkan/shader/innerproduct_pack8to4.comp
  5. +61
    -32
      tests/test_innerproduct.cpp
  6. +4
    -3
      tests/testutil.h

+ 1
- 0
src/layer/arm/innerproduct_arm.cpp View File

@@ -106,6 +106,7 @@ int InnerProduct_arm::forward(const Mat& bottom_blob, Mat& top_blob, const Optio
// pack1
{
bottom_blob_flattened.w *= bottom_blob_flattened.elempack;
bottom_blob_flattened.cstep = bottom_blob_flattened.w;
bottom_blob_flattened.elemsize = 4u;
bottom_blob_flattened.elempack = 1;
}


+ 1
- 1
src/layer/vulkan/shader/innerproduct_pack1to8.comp View File

@@ -77,7 +77,7 @@ void main()

if (bias_term == 1)
{
sum = buffer_ld8(bias_data, gz);
sum = buffer_ld8(bias_data, gx);
}
else
{


+ 1
- 1
src/layer/vulkan/shader/innerproduct_pack4to8.comp View File

@@ -77,7 +77,7 @@ void main()

if (bias_term == 1)
{
sum = buffer_ld8(bias_data, gz);
sum = buffer_ld8(bias_data, gx);
}
else
{


+ 1
- 1
src/layer/vulkan/shader/innerproduct_pack8to4.comp View File

@@ -77,7 +77,7 @@ void main()

if (bias_term == 1)
{
sum = buffer_ld4(bias_data, gz);
sum = buffer_ld4(bias_data, gx);
}
else
{


+ 61
- 32
tests/test_innerproduct.cpp View File

@@ -16,17 +16,15 @@

#include "layer/innerproduct.h"

static int test_innerproduct(int w, int h, int c, int outch, int bias)
static int test_innerproduct(const ncnn::Mat& a, int outch, int bias)
{
ncnn::Mat a = RandomMat(w, h, c);

ncnn::ParamDict pd;
pd.set(0, outch);// num_output
pd.set(1, bias);// bias_term
pd.set(2, outch*w*h*c);
pd.set(2, outch*a.w*a.h*a.c);

std::vector<ncnn::Mat> weights(bias ? 2 : 1);
weights[0] = RandomMat(outch*w*h*c);
weights[0] = RandomMat(outch*a.w*a.h*a.c);
if (bias)
weights[1] = RandomMat(outch);

@@ -43,7 +41,7 @@ static int test_innerproduct(int w, int h, int c, int outch, int bias)
int ret = test_layer<ncnn::InnerProduct>("InnerProduct", pd, weights, opt, a);
if (ret != 0)
{
fprintf(stderr, "test_innerproduct failed w=%d h=%d c=%d outch=%d bias=%d\n", w, h, c, outch, bias);
fprintf(stderr, "test_innerproduct failed a.dims=%d a=(%d %d %d) outch=%d bias=%d\n", a.dims, a.w, a.h, a.c, outch, bias);
}

return ret;
@@ -52,29 +50,55 @@ static int test_innerproduct(int w, int h, int c, int outch, int bias)
static int test_innerproduct_0()
{
return 0
|| test_innerproduct(7, 3, 1, 1, 1)
|| test_innerproduct(7, 3, 2, 2, 1)
|| test_innerproduct(7, 3, 3, 3, 1)
|| test_innerproduct(7, 3, 4, 4, 1)
|| test_innerproduct(7, 3, 7, 7, 1)
|| test_innerproduct(7, 3, 8, 8, 1)
|| test_innerproduct(7, 3, 15, 15, 1)
|| test_innerproduct(7, 3, 16, 16, 1)
|| test_innerproduct(RandomMat(1, 3, 1), 1, 1)
|| test_innerproduct(RandomMat(3, 2, 2), 2, 1)
|| test_innerproduct(RandomMat(9, 3, 8), 7, 1)
|| test_innerproduct(RandomMat(2, 2, 8), 8, 1)
|| test_innerproduct(RandomMat(4, 3, 15), 8, 1)
|| test_innerproduct(RandomMat(6, 2, 16), 16, 1)
|| test_innerproduct(RandomMat(6, 2, 16), 7, 1)
|| test_innerproduct(RandomMat(6, 2, 5), 16, 1)
;
}

static int test_innerproduct_1()
{
return 0
|| test_innerproduct(RandomMat(1, 1), 1, 1)
|| test_innerproduct(RandomMat(3, 2), 2, 1)
|| test_innerproduct(RandomMat(9, 8), 7, 1)
|| test_innerproduct(RandomMat(2, 8), 8, 1)
|| test_innerproduct(RandomMat(4, 15), 8, 1)
|| test_innerproduct(RandomMat(6, 16), 16, 1)
|| test_innerproduct(RandomMat(6, 16), 7, 1)
|| test_innerproduct(RandomMat(6, 5), 16, 1)
;
}

static int test_innerproduct_int8(int w, int h, int c, int outch, int bias)
static int test_innerproduct_2()
{
ncnn::Mat a = RandomMat(w, h, c);
return 0
|| test_innerproduct(RandomMat(1), 1, 1)
|| test_innerproduct(RandomMat(2), 2, 1)
|| test_innerproduct(RandomMat(8), 7, 1)
|| test_innerproduct(RandomMat(8), 8, 1)
|| test_innerproduct(RandomMat(15), 8, 1)
|| test_innerproduct(RandomMat(16), 16, 1)
|| test_innerproduct(RandomMat(16), 7, 1)
|| test_innerproduct(RandomMat(5), 16, 1)
;
}

static int test_innerproduct_int8(const ncnn::Mat& a, int outch, int bias)
{
ncnn::ParamDict pd;
pd.set(0, outch);// num_output
pd.set(1, bias);// bias_term
pd.set(2, outch*w*h*c);
pd.set(2, outch*a.w*a.h*a.c);
pd.set(8, 1);// int8_scale_term

std::vector<ncnn::Mat> weights(bias ? 4 : 3);
weights[0] = RandomMat(outch*w*h*c);
weights[0] = RandomMat(outch*a.w*a.h*a.c);
if (bias)
{
weights[1] = RandomMat(outch);
@@ -100,26 +124,26 @@ static int test_innerproduct_int8(int w, int h, int c, int outch, int bias)
int ret = test_layer<ncnn::InnerProduct>("InnerProduct", pd, weights, opt, a);
if (ret != 0)
{
fprintf(stderr, "test_innerproduct_int8 failed w=%d h=%d c=%d outch=%d bias=%d\n", w, h, c, outch, bias);
fprintf(stderr, "test_innerproduct_int8 failed a.dims=%d a=(%d %d %d) outch=%d bias=%d\n", a.dims, a.w, a.h, a.c, outch, bias);
}

return 0;
}

static int test_innerproduct_1()
static int test_innerproduct_3()
{
return 0
|| test_innerproduct_int8(7, 3, 1, 1, 1)
|| test_innerproduct_int8(7, 3, 2, 2, 1)
|| test_innerproduct_int8(7, 3, 3, 3, 1)
|| test_innerproduct_int8(7, 3, 3, 12, 1)
|| test_innerproduct_int8(7, 3, 4, 4, 1)
|| test_innerproduct_int8(7, 3, 7, 7, 1)
|| test_innerproduct_int8(7, 3, 8, 3, 1)
|| test_innerproduct_int8(7, 3, 8, 8, 1)
|| test_innerproduct_int8(7, 3, 15, 15, 1)
|| test_innerproduct_int8(7, 3, 16, 4, 1)
|| test_innerproduct_int8(7, 3, 16, 16, 1)
|| test_innerproduct_int8(RandomMat(1, 3, 1), 1, 1)
|| test_innerproduct_int8(RandomMat(3, 2, 2), 2, 1)
|| test_innerproduct_int8(RandomMat(5, 3, 3), 3, 1)
|| test_innerproduct_int8(RandomMat(7, 2, 3), 12, 1)
|| test_innerproduct_int8(RandomMat(9, 3, 4), 4, 1)
|| test_innerproduct_int8(RandomMat(2, 2, 7), 7, 1)
|| test_innerproduct_int8(RandomMat(4, 3, 8), 3, 1)
|| test_innerproduct_int8(RandomMat(6, 2, 8), 8, 1)
|| test_innerproduct_int8(RandomMat(8, 3, 15), 15, 1)
|| test_innerproduct_int8(RandomMat(7, 2, 16), 4, 1)
|| test_innerproduct_int8(RandomMat(6, 3, 16), 16, 1)
;
}

@@ -127,5 +151,10 @@ int main()
{
SRAND(7767517);

return test_innerproduct_0() || test_innerproduct_1();
return 0
|| test_innerproduct_0()
|| test_innerproduct_1()
|| test_innerproduct_2()
|| test_innerproduct_3()
;
}

+ 4
- 3
tests/testutil.h View File

@@ -215,6 +215,7 @@ int test_layer(int typeindex, const ncnn::ParamDict& pd, const std::vector<ncnn:
if (!op->support_bf16_storage) opt.use_bf16_storage = false;

if (opt.use_int8_inference) opt.use_bf16_storage = false;
if (opt.use_int8_inference) opt.use_packing_layout = false;

#if NCNN_VULKAN
ncnn::VulkanDevice* vkdev = ncnn::get_gpu_device();
@@ -467,6 +468,7 @@ int test_layer(int typeindex, const ncnn::ParamDict& pd, const std::vector<ncnn:
if (!op->support_bf16_storage) opt.use_bf16_storage = false;

if (opt.use_int8_inference) opt.use_bf16_storage = false;
if (opt.use_int8_inference) opt.use_packing_layout = false;

#if NCNN_VULKAN
ncnn::VulkanDevice* vkdev = ncnn::get_gpu_device();
@@ -732,8 +734,7 @@ int test_layer(const char* layer_type, const ncnn::ParamDict& pd, const std::vec
int ret = test_layer<T>(ncnn::layer_to_index(layer_type), pd, weights_fp16, opt, a_fp16, top_blob_count, top_shapes, epsilon_fp16, func);
if (ret != 0)
{
fprintf(stderr, "test_layer %s failed use_packing_layout=%d use_bf16_storage=%d\n", layer_type, opt.use_packing_layout, opt.use_bf16_storage);
return ret;
fprintf(stderr, "test_layer %s failed use_packing_layout=%d use_fp16_packed=%d use_shader_pack8=%d use_bf16_storage=%d\n", layer_type, opt.use_packing_layout, opt.use_fp16_packed, opt.use_shader_pack8, opt.use_bf16_storage);
}
}

@@ -810,7 +811,7 @@ int test_layer(const char* layer_type, const ncnn::ParamDict& pd, const std::vec
int ret = test_layer<T>(ncnn::layer_to_index(layer_type), pd, weights_fp16, opt, a_fp16, top_shape, epsilon_fp16, func);
if (ret != 0)
{
fprintf(stderr, "test_layer %s failed use_packing_layout=%d use_bf16_storage=%d\n", layer_type, opt.use_packing_layout, opt.use_bf16_storage);
fprintf(stderr, "test_layer %s failed use_packing_layout=%d use_fp16_packed=%d use_shader_pack8=%d use_bf16_storage=%d\n", layer_type, opt.use_packing_layout, opt.use_fp16_packed, opt.use_shader_pack8, opt.use_bf16_storage);
return ret;
}
}


Loading…
Cancel
Save