Elffuss BraidHub

kikocis/ncnn public

master · 6.0 KiBRawPermalink
1// Tencent is pleased to support the open source community by making ncnn available.
2//
3// Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
4//
5// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6// in compliance with the License. You may obtain a copy of the License at
7//
8// https://opensource.org/licenses/BSD-3-Clause
9//
10// Unless required by applicable law or agreed to in writing, software distributed
11// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12// CONDITIONS OF ANY KIND, either express or implied. See the License for the
13// specific language governing permissions and limitations under the License.
14
15#ifndef TESTUTIL_H
16#define TESTUTIL_H
17
18#include "cpu.h"
19#include "layer.h"
20#include "mat.h"
21
22#include <stdio.h>
23#include <stdint.h>
24#include <stdlib.h>
25
26#define TEST_LAYER_DISABLE_AUTO_INPUT_PACKING (1 << 0)
27#define TEST_LAYER_DISABLE_AUTO_INPUT_CASTING (1 << 1)
28#define TEST_LAYER_DISABLE_GPU_TESTING (1 << 2)
29#define TEST_LAYER_ENABLE_FORCE_INPUT_PACK8 (1 << 3)
30
31void SRAND(int seed);
32
33uint64_t RAND();
34
35float RandomFloat(float a = -1.2f, float b = 1.2f);
36
37int RandomInt(int a = -10000, int b = 10000);
38
39signed char RandomS8();
40
41void Randomize(ncnn::Mat& m, float a = -1.2f, float b = 1.2f);
42
43void RandomizeInt(ncnn::Mat& m, int a = -10000, int b = 10000);
44
45void RandomizeS8(ncnn::Mat& m);
46
47ncnn::Mat RandomMat(int w, float a = -1.2f, float b = 1.2f);
48
49ncnn::Mat RandomMat(int w, int h, float a = -1.2f, float b = 1.2f);
50
51ncnn::Mat RandomMat(int w, int h, int c, float a = -1.2f, float b = 1.2f);
52
53ncnn::Mat RandomMat(int w, int h, int d, int c, float a = -1.2f, float b = 1.2f);
54
55ncnn::Mat RandomIntMat(int w);
56
57ncnn::Mat RandomIntMat(int w, int h);
58
59ncnn::Mat RandomIntMat(int w, int h, int c);
60
61ncnn::Mat RandomIntMat(int w, int h, int d, int c);
62
63ncnn::Mat RandomS8Mat(int w);
64
65ncnn::Mat RandomS8Mat(int w, int h);
66
67ncnn::Mat RandomS8Mat(int w, int h, int c);
68
69ncnn::Mat RandomS8Mat(int w, int h, int d, int c);
70
71ncnn::Mat scales_mat(const ncnn::Mat& mat, int m, int k, int ldx);
72
73bool NearlyEqual(float a, float b, float epsilon);
74
75int Compare(const ncnn::Mat& a, const ncnn::Mat& b, float epsilon = 0.001);
76
77int CompareMat(const ncnn::Mat& a, const ncnn::Mat& b, float epsilon = 0.001);
78
79int CompareMat(const std::vector<ncnn::Mat>& a, const std::vector<ncnn::Mat>& b, float epsilon = 0.001);
80
81int test_layer_naive(int typeindex, const ncnn::ParamDict& pd, const std::vector<ncnn::Mat>& weights, const std::vector<ncnn::Mat>& a, int top_blob_count, std::vector<ncnn::Mat>& b, void (*func)(ncnn::Layer*), int flag);
82
83int test_layer_cpu(int typeindex, const ncnn::ParamDict& pd, const std::vector<ncnn::Mat>& weights, const ncnn::Option& _opt, const std::vector<ncnn::Mat>& a, int top_blob_count, std::vector<ncnn::Mat>& c, const std::vector<ncnn::Mat>& top_shapes, void (*func)(ncnn::Layer*), int flag);
84
85#if NCNN_VULKAN
86int test_layer_gpu(int typeindex, const ncnn::ParamDict& pd, const std::vector<ncnn::Mat>& weights, const ncnn::Option& _opt, const std::vector<ncnn::Mat>& a, int top_blob_count, std::vector<ncnn::Mat>& d, const std::vector<ncnn::Mat>& top_shapes, void (*func)(ncnn::Layer*), int flag);
87#endif // NCNN_VULKAN
88
89int test_layer(int typeindex, const ncnn::ParamDict& pd, const std::vector<ncnn::Mat>& weights, const ncnn::Option& _opt, const std::vector<ncnn::Mat>& a, int top_blob_count, const std::vector<ncnn::Mat>& top_shapes = std::vector<ncnn::Mat>(), float epsilon = 0.001, void (*func)(ncnn::Layer*) = 0, int flag = 0);
90
91int test_layer_naive(int typeindex, const ncnn::ParamDict& pd, const std::vector<ncnn::Mat>& weights, const ncnn::Mat& a, ncnn::Mat& b, void (*func)(ncnn::Layer*), int flag);
92
93int test_layer_cpu(int typeindex, const ncnn::ParamDict& pd, const std::vector<ncnn::Mat>& weights, const ncnn::Option& _opt, const ncnn::Mat& a, ncnn::Mat& c, const ncnn::Mat& top_shape, void (*func)(ncnn::Layer*), int flag);
94
95#if NCNN_VULKAN
96int test_layer_gpu(int typeindex, const ncnn::ParamDict& pd, const std::vector<ncnn::Mat>& weights, const ncnn::Option& _opt, const ncnn::Mat& a, ncnn::Mat& d, const ncnn::Mat& top_shape, void (*func)(ncnn::Layer*), int flag);
97#endif // NCNN_VULKAN
98
99int test_layer(int typeindex, const ncnn::ParamDict& pd, const std::vector<ncnn::Mat>& weights, const ncnn::Option& _opt, const ncnn::Mat& a, const ncnn::Mat& top_shape = ncnn::Mat(), float epsilon = 0.001, void (*func)(ncnn::Layer*) = 0, int flag = 0);
100
101int test_layer_opt(const char* layer_type, const ncnn::ParamDict& pd, const std::vector<ncnn::Mat>& weights, const ncnn::Option& opt, const std::vector<ncnn::Mat>& a, int top_blob_count = 1, float epsilon = 0.001, void (*func)(ncnn::Layer*) = 0, int flag = 0);
102
103int test_layer_opt(const char* layer_type, const ncnn::ParamDict& pd, const std::vector<ncnn::Mat>& weights, const ncnn::Option& opt, const ncnn::Mat& a, float epsilon = 0.001, void (*func)(ncnn::Layer*) = 0, int flag = 0);
104
105int test_layer(const char* layer_type, const ncnn::ParamDict& pd, const std::vector<ncnn::Mat>& weights, const std::vector<ncnn::Mat>& a, int top_blob_count = 1, float epsilon = 0.001, void (*func)(ncnn::Layer*) = 0, int flag = 0);
106
107int test_layer(const char* layer_type, const ncnn::ParamDict& pd, const std::vector<ncnn::Mat>& weights, const ncnn::Mat& a, float epsilon = 0.001, void (*func)(ncnn::Layer*) = 0, int flag = 0);
108
109// oom test
110
111int test_layer_oom_opt(const char* layer_type, const ncnn::ParamDict& pd, const std::vector<ncnn::Mat>& weights, const ncnn::Option& opt, const std::vector<ncnn::Mat>& a, int top_blob_count = 1, int flag = 0);
112
113int test_layer_oom_opt(const char* layer_type, const ncnn::ParamDict& pd, const std::vector<ncnn::Mat>& weights, const ncnn::Option& opt, const ncnn::Mat& a, int flag = 0);
114
115int test_layer_oom(const char* layer_type, const ncnn::ParamDict& pd, const std::vector<ncnn::Mat>& weights, const std::vector<ncnn::Mat>& a, int top_blob_count = 1, int flag = 0);
116
117int test_layer_oom(const char* layer_type, const ncnn::ParamDict& pd, const std::vector<ncnn::Mat>& weights, const ncnn::Mat& a, int flag = 0);
118
119#endif // TESTUTIL_H