MCPcopy Create free account
hub / github.com/OAID/Tengine / create_scale_node

Function create_scale_node

internal/tests/executor/tests/test_scale.cpp:71–156  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69float op_fops;
70
71Node* create_scale_node(int n, int c, int h, int w)
72{
73 Operator* op = OpManager::CreateOp("Scale");
74 Scale* scale_op = dynamic_cast<Scale*>(op);
75
76 ScaleParam* param = scale_op->GetParam();
77 param->axis = 1;
78 param->bias_term = 1;
79 param->num_axes = 1;
80 /* input shape */
81 int input_h = h;
82 int input_w = w;
83 int input_c = c;
84 int input_n = n;
85
86 std::vector<int> input_dims = {input_n, input_c, input_h, input_w};
87 std::vector<int> channel_dims = {input_c};
88
89 Node* node = new Node("test Scale");
90
91 node->SetOp(scale_op);
92
93 // prepare tensor: input/gmma/beta
94 Tensor* tensor;
95 int mem_size;
96 void* addr;
97
98 tensor = new Tensor("input");
99
100 tensor->SetDataType("float32");
101 tensor->SetType(kVarTensor);
102 TShape* shape = &tensor->GetShape();
103 shape->SetDataLayout("NCHW");
104 shape->SetDim(input_dims);
105 node->SetInputPort(0, tensor);
106 mem_size = tensor->GetTotalSize();
107 addr = std::malloc(mem_size);
108 init_tensor_data(( float* )addr, mem_size / sizeof(float), -1);
109 set_tensor_mem(tensor, addr, mem_size, std::free);
110
111 tensor = new Tensor("gamma");
112 tensor->SetDataType("float32");
113 tensor->SetType(kVarTensor);
114 shape = &tensor->GetShape();
115 shape->SetDataLayout("W");
116 shape->SetDim(channel_dims);
117 node->SetInputPort(1, tensor);
118 mem_size = tensor->GetTotalSize();
119 addr = std::malloc(mem_size);
120 init_tensor_data(( float* )addr, mem_size / sizeof(float), -3);
121 set_tensor_mem(tensor, addr, mem_size, std::free);
122 /*** beta ***/
123
124 tensor = new Tensor("beta");
125 tensor->SetDataType("float32");
126 tensor->SetType(kVarTensor);
127 shape = &tensor->GetShape();
128 shape->SetDataLayout("W");

Callers 1

test_new_operatorFunction · 0.85

Calls 11

set_tensor_memFunction · 0.85
GetParamMethod · 0.80
SetOpMethod · 0.80
SetDataTypeMethod · 0.80
SetTypeMethod · 0.80
SetDataLayoutMethod · 0.80
SetDimMethod · 0.80
SetInputPortMethod · 0.80
GetTotalSizeMethod · 0.80
SetOutputPortMethod · 0.80
init_tensor_dataFunction · 0.70

Tested by

no test coverage detected