| 140 | } |
| 141 | |
| 142 | SmallVector<TensorPtr> apply_on_physical_tensor( |
| 143 | const OpDef& def, const SmallVector<TensorPtr>& inputs, |
| 144 | SmallVector<LogicalTensorDesc>& output_descs, const bool& validated) { |
| 145 | auto&& op_def = def.cast_final_safe<BatchNorm>(); |
| 146 | auto&& comp_node = inputs[0]->comp_node(); |
| 147 | |
| 148 | DnnOprCaller<megdnn::BN> dnn_opr(comp_node, op_def.param()); |
| 149 | |
| 150 | auto src_layout = inputs[0]->layout(); |
| 151 | auto scale_layout = inputs[1]->layout(); |
| 152 | bool empty_input = src_layout.is_empty(); |
| 153 | size_t nr_inp = inputs.size(); |
| 154 | |
| 155 | // size_t ws_size = 0, reserve_size = 0; |
| 156 | size_t reserve_size = |
| 157 | empty_input ? (size_t)0 : dnn_opr.op()->get_reserve_in_bytes(src_layout); |
| 158 | |
| 159 | // alloc outputs |
| 160 | auto y = Tensor::make(src_layout, comp_node); |
| 161 | auto save_mean = Tensor::make(scale_layout, comp_node); |
| 162 | auto save_variance = Tensor::make(scale_layout, comp_node); |
| 163 | auto reserve = Tensor::make(TensorLayout{{reserve_size}, dtype::Byte()}, comp_node); |
| 164 | |
| 165 | if (op_def.fwd_mode == ::megdnn::param::BN::FwdMode::INFERENCE) { |
| 166 | if (!empty_input) { |
| 167 | dnn_opr.exec_with_ws( |
| 168 | inputs[0], inputs[1], inputs[2], inputs[3], inputs[4], save_mean, |
| 169 | save_variance, reserve, y); |
| 170 | } |
| 171 | return {inputs[3], inputs[4], reserve, y}; |
| 172 | } else { |
| 173 | if (nr_inp == 5) { |
| 174 | auto mean = Tensor::make(scale_layout, comp_node); |
| 175 | auto variance = Tensor::make(scale_layout, comp_node); |
| 176 | |
| 177 | // FIXME |
| 178 | mean->dev_tensor().copy_from(inputs[3]->dev_tensor()); |
| 179 | variance->dev_tensor().copy_from(inputs[4]->dev_tensor()); |
| 180 | |
| 181 | if (!empty_input) { |
| 182 | dnn_opr.exec_with_ws( |
| 183 | inputs[0], inputs[1], inputs[2], mean, variance, save_mean, |
| 184 | save_variance, reserve, y); |
| 185 | } |
| 186 | |
| 187 | return {mean, variance, save_mean, save_variance, reserve, y}; |
| 188 | } |
| 189 | |
| 190 | TensorLayout m_layout({0}, scale_layout.dtype); |
| 191 | auto mean = Tensor::make(m_layout, comp_node); |
| 192 | auto variance = Tensor::make(m_layout, comp_node); |
| 193 | |
| 194 | if (!empty_input) { |
| 195 | dnn_opr.exec_with_ws( |
| 196 | inputs[0], inputs[1], inputs[2], mean, variance, save_mean, |
| 197 | save_variance, reserve, y); |
| 198 | } |
| 199 |
nothing calls this directly
no test coverage detected