This builds and runs the following model Input-> Pad ->(Pool2D | Conv2D ) -> Output
| 1123 | // Input-> Pad ->(Pool2D | Conv2D ) -> Output |
| 1124 | // |
| 1125 | static bool |
| 1126 | BuildAndRunNetwork |
| 1127 | ( |
| 1128 | FoldOptimizationTestArgs const &arg |
| 1129 | ) |
| 1130 | { |
| 1131 | bool ok{false}; |
| 1132 | try |
| 1133 | { |
| 1134 | auto network = INetwork::Create(); |
| 1135 | |
| 1136 | // add input layer |
| 1137 | auto inputLayer = network->AddInputLayer(0, "input"); |
| 1138 | { |
| 1139 | const uint32_t inputShape[] = {1, arg.tensorH, arg.tensorW, 1}; |
| 1140 | TensorInfo inputInfo(4, inputShape, DataType::Float32); |
| 1141 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputInfo); |
| 1142 | } |
| 1143 | |
| 1144 | // add pad layer |
| 1145 | PadDescriptor padDesc({ {0, 0}, |
| 1146 | {arg.pad.top, arg.pad.bottom}, |
| 1147 | {arg.pad.left, arg.pad.right}, |
| 1148 | {0, 0} |
| 1149 | }); |
| 1150 | auto padLayer = network->AddPadLayer(padDesc, "Pad"); |
| 1151 | |
| 1152 | { |
| 1153 | uint32_t padedH = arg.tensorH + arg.pad.top + arg.pad.bottom; |
| 1154 | uint32_t padedW = arg.tensorW + arg.pad.left + arg.pad.right; |
| 1155 | const uint32_t padShape[] = {1, padedH, padedW, 1}; |
| 1156 | TensorInfo padInfo(4, padShape, DataType::Float32); |
| 1157 | padLayer->GetOutputSlot(0).SetTensorInfo(padInfo); |
| 1158 | } |
| 1159 | |
| 1160 | //create the op layer |
| 1161 | IConnectableLayer *opLayer{ CreateLayer(network, arg, false) }; |
| 1162 | TensorInfo outputInfo(4, arg.outputShape, DataType::Float32); |
| 1163 | opLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 1164 | |
| 1165 | auto outputLayer = network->AddOutputLayer(0,"output"); |
| 1166 | |
| 1167 | // connect the layers |
| 1168 | inputLayer->GetOutputSlot(0).Connect(padLayer->GetInputSlot(0)); |
| 1169 | padLayer->GetOutputSlot(0).Connect(opLayer->GetInputSlot(0)); |
| 1170 | opLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 1171 | |
| 1172 | // init runtime and load net |
| 1173 | IRuntimePtr runTime = IRuntime::Create(IRuntime::CreationOptions()); // default options |
| 1174 | IOptimizedNetworkPtr optimizedNetwork = Optimize(*network, {Compute::TosaRef}, runTime->GetDeviceSpec()); |
| 1175 | NetworkId netid{}; |
| 1176 | CHECK(runTime->LoadNetwork(netid, std::move(optimizedNetwork)) == Status::Success); |
| 1177 | |
| 1178 | // setup input tensor |
| 1179 | TensorInfo inputTensorInfo = runTime->GetInputTensorInfo(netid, 0); |
| 1180 | inputTensorInfo.SetConstant(true); |
| 1181 | InputTensors inTensor{{0, ConstTensor(inputTensorInfo, arg.data.data())}}; |
| 1182 |
no test coverage detected