Skip to content

Commit 6a13dcc

Browse files
authored
fix gather timvx op test & rename savegraph (#946)
* fix timvx op test * change savegraph path Co-authored-by: xlchen <[email protected]>
1 parent 9184b3f commit 6a13dcc

16 files changed

+37
-14
lines changed

tests/op/test_timvx_op_eltwise_mul.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include "graph/tensor.h"
3030
#include "operator/prototype/eltwise_param.h"
3131

32-
int create_test_concat_node(graph_t graph, const char* input_name0, const char* node_name, int data_type, int layout, int n, int c, int h, int w)
32+
int create_test_eltwise_node(graph_t graph, const char* input_name0, const char* node_name, int data_type, int layout, int n, int c, int h, int w)
3333
{
3434
(void)layout;
3535
(void)n;
@@ -149,7 +149,7 @@ int main(int argc, char* argv[])
149149
fprintf(stderr, "Tengine init failed.\n");
150150

151151
// create
152-
struct graph* ir_graph = (struct graph*)create_timvx_test_graph(test_node_name, data_type, layout, n, c, h, w, &create_test_concat_node);
152+
struct graph* ir_graph = (struct graph*)create_timvx_test_graph(test_node_name, data_type, layout, n, c, h, w, &create_test_eltwise_node);
153153
if (NULL == ir_graph)
154154
return -1;
155155

tests/op/test_timvx_op_eltwise_sum.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include "graph/tensor.h"
3030
#include "operator/prototype/eltwise_param.h"
3131

32-
int create_test_concat_node(graph_t graph, const char* input_name0, const char* node_name, int data_type, int layout, int n, int c, int h, int w)
32+
int create_test_eltwise_node(graph_t graph, const char* input_name0, const char* node_name, int data_type, int layout, int n, int c, int h, int w)
3333
{
3434
(void)layout;
3535
(void)n;
@@ -149,7 +149,7 @@ int main(int argc, char* argv[])
149149
fprintf(stderr, "Tengine init failed.\n");
150150

151151
// create
152-
struct graph* ir_graph = (struct graph*)create_timvx_test_graph(test_node_name, data_type, layout, n, c, h, w, &create_test_concat_node);
152+
struct graph* ir_graph = (struct graph*)create_timvx_test_graph(test_node_name, data_type, layout, n, c, h, w, &create_test_eltwise_node);
153153
if (NULL == ir_graph)
154154
return -1;
155155

tests/op/test_timvx_op_flatten.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include "graph/tensor.h"
3030
#include "operator/prototype/flatten_param.h"
3131

32-
int create_test_fc_node(graph_t graph, const char* input_name, const char* node_name, int data_type, int layout, int n, int c, int h, int w)
32+
int create_test_flatten_node(graph_t graph, const char* input_name, const char* node_name, int data_type, int layout, int n, int c, int h, int w)
3333
{
3434
(void)layout;
3535
(void)n;
@@ -113,7 +113,7 @@ int main(int argc, char* argv[])
113113
fprintf(stderr, "Tengine init failed.\n");
114114

115115
// create
116-
struct graph* ir_graph = (struct graph*)create_timvx_test_graph(test_node_name, data_type, layout, n, c, h, w, &create_test_fc_node);
116+
struct graph* ir_graph = (struct graph*)create_timvx_test_graph(test_node_name, data_type, layout, n, c, h, w, &create_test_flatten_node);
117117
if (NULL == ir_graph)
118118
return -1;
119119

tests/op/test_timvx_op_gather.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include "graph/tensor.h"
3030
#include "operator/prototype/gather_param.h"
3131

32-
int create_test_fc_node(graph_t graph, const char* input_name, const char* node_name, int data_type, int layout, int n, int c, int h, int w)
32+
int create_test_gather_node(graph_t graph, const char* input_name, const char* node_name, int data_type, int layout, int n, int c, int h, int w)
3333
{
3434
(void)layout;
3535
(void)n;
@@ -51,6 +51,14 @@ int create_test_fc_node(graph_t graph, const char* input_name, const char* node_
5151
/* input tensors of test node */
5252
set_node_input_tensor(test_node, 0, input_tensor);
5353

54+
/* indices tensor */
55+
node_t indices_node = create_graph_node(graph, "indices", "Const");
56+
tensor_t indices_tensor = create_graph_tensor(graph, "indices", TENGINE_DT_UINT8);
57+
set_node_output_tensor(indices_node, 0, indices_tensor, TENSOR_TYPE_CONST);
58+
int indices_dims[1] = {2}; // channel num
59+
set_tensor_shape(indices_tensor, indices_dims, 1);
60+
set_node_input_tensor(test_node, 1, indices_tensor);
61+
5462
/* output tensors of test node */
5563
tensor_t output_tensor = create_graph_tensor(graph, node_name, data_type);
5664
set_node_output_tensor(test_node, 0, output_tensor, TENSOR_TYPE_VAR);
@@ -82,6 +90,13 @@ float input_fp32[6] = {
8290
float input_scale = 1;
8391
int input_zero_point = 0;
8492

93+
float indices_fp32[2] = {
94+
0.0f,
95+
1.0f,
96+
};
97+
float indices_scale = 1;
98+
int indices_zero_point = 0;
99+
85100
float reference_out[4] = {
86101
3.0f,
87102
7.0f,
@@ -118,7 +133,7 @@ int main(int argc, char* argv[])
118133
fprintf(stderr, "Tengine init failed.\n");
119134

120135
// create
121-
struct graph* ir_graph = (struct graph*)create_timvx_test_graph(test_node_name, data_type, layout, n, c, h, w, &create_test_fc_node);
136+
struct graph* ir_graph = (struct graph*)create_timvx_test_graph(test_node_name, data_type, layout, n, c, h, w, &create_test_gather_node);
122137
if (NULL == ir_graph)
123138
return -1;
124139

@@ -127,17 +142,23 @@ int main(int argc, char* argv[])
127142

128143
// set quantize params
129144
struct tensor* input_tensor = (struct tensor*)get_graph_tensor(ir_graph, "input_node");
145+
struct tensor* indices_tensor = (struct tensor*)get_graph_tensor(ir_graph, "indices");
130146
struct tensor* output_tensor = (struct tensor*)get_graph_tensor(ir_graph, "gather");
131147

132-
// tensor_t weight_tesnor = get_graph_input_tensor(ir_graph, 1, 0);
133148
set_tensor_quant_param(input_tensor, &input_scale, &input_zero_point, 1);
149+
set_tensor_quant_param(indices_tensor, &indices_scale, &indices_zero_point, 1);
134150
set_tensor_quant_param(output_tensor, &output_scale, &output_zero_point, 1);
135151

136152
// set input data
137153
uint8_t input_u8[6] = {0};
138154
get_uint8_data(input_fp32, input_u8, 6, input_scale, input_zero_point);
139155
set_tensor_buffer(input_tensor, input_u8, 6);
140156

157+
// set indices data
158+
uint8_t indices_u8[2] = {0};
159+
get_uint8_data(indices_fp32, indices_u8, 2, indices_scale, indices_zero_point);
160+
set_tensor_buffer(indices_tensor, indices_u8, 2);
161+
141162
// set bias data
142163
// fill_input_uint8_tensor_by_index(graph, 0, 0, 0.0f);
143164

tools/convert_tool/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ file(GLOB_RECURSE NCNN_SERIALIZER_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/ncnn/*.cpp")
6363

6464

6565
# SAVE GRAPH
66-
FILE(GLOB_RECURSE SAVE_GRAPH_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/utils/save_graph/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/utils/save_graph/*.c")
66+
FILE(GLOB_RECURSE SAVE_GRAPH_SRCS "${CMAKE_SOURCE_DIR}/tools/save_graph/*.cpp" "${CMAKE_SOURCE_DIR}/tools/save_graph/*.c")
6767

6868
# GRAPH OPTIMIZER
6969
FILE(GLOB_RECURSE GRAPH_OPT_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/utils/graph_optimizer/*.cpp")
@@ -84,6 +84,7 @@ TARGET_INCLUDE_DIRECTORIES (convert_tool PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
8484
TARGET_INCLUDE_DIRECTORIES (convert_tool PRIVATE "${CMAKE_SOURCE_DIR}/source")
8585
TARGET_INCLUDE_DIRECTORIES (convert_tool PRIVATE "${CMAKE_BINARY_DIR}/source")
8686
TARGET_INCLUDE_DIRECTORIES (convert_tool PRIVATE "${CMAKE_SOURCE_DIR}/source/operator/prototype")
87+
TARGET_INCLUDE_DIRECTORIES (convert_tool PRIVATE "${CMAKE_SOURCE_DIR}/tools")
8788
install(TARGETS convert_tool DESTINATION bin)
8889

8990
# add to a virtual project group

tools/convert_tool/caffe/caffe2tengine.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ extern "C" {
4747
#include "utility/log.h"
4848
#include "utility/sys_port.h"
4949
#include "utility/vector.h"
50-
#include "../utils/save_graph/op_include.h"
50+
#include "save_graph/op_include.h"
5151
}
5252

5353
enum PoolArg

tools/convert_tool/convert_tool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <unistd.h>
2828

2929
#include "tengine/c_api.h"
30-
#include "utils/save_graph/save_graph.hpp"
30+
#include "save_graph/save_graph.hpp"
3131
#include "onnx/onnx2tengine.hpp"
3232
#include "caffe/caffe2tengine.hpp"
3333
#include "ncnn/ncnn2tengine.hpp"

tools/convert_tool/ncnn/ncnn2tengine.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ extern "C" {
4747
#include "utility/log.h"
4848
#include "utility/sys_port.h"
4949
#include "utility/vector.h"
50-
#include "../utils/save_graph/op_include.h"
50+
#include "save_graph/op_include.h"
5151
}
5252
#define NCNN_MAX_PARAM_COUNT 32
5353

tools/convert_tool/onnx/onnx2tengine.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ extern "C" {
4949
#include "utility/log.h"
5050
#include "utility/sys_port.h"
5151
#include "utility/vector.h"
52-
#include "../utils/save_graph/op_include.h"
52+
#include "save_graph/op_include.h"
53+
// #include "../../save_graph/op_include.h"
5354
}
5455

5556
class onnx_serializer

0 commit comments

Comments
 (0)