已合并
fix(opration): Repair Alerts #6371
zhangchen创建于 9月16日
fix(opration): Repair Alerts #6371
已合并
共 2 个文件变更+266-187
| @@ -142,6 +142,31 @@ Tensor GetFinalResTensorNZ2NZ(std::vector<LogicalTensorPtr> operandVecIn, const | |||
| 142 | return finalResTensor; | 142 | return finalResTensor; |
| 143 | } | 143 | } |
| 144 | 144 | ||
| 145 | +static Tensor ConstructConv1DResTensor(Function* functionPtr, const Operation& op, | ||
| 146 | + const std::vector<LogicalTensorPtr>& operandVecIn, const Tensor& resTensor, | ||
| 147 | + const Tensor& finalResTensor, const ConvAttrParam& convAttrParam) | ||
| 148 | +{ | ||
| 149 | + auto vecTiles = Conv::InferConvVecTileShapes(op, operandVecIn[INPUT_FMAP_IDX]->Datatype()); | ||
| 150 | + std::vector<int64_t> orgOutShape = {resTensor.GetShape()[NC1HWC0_N_IDX], | ||
| 151 | + operandVecIn[INPUT_WEIGHT_IDX]->GetShape()[NCHW_N_IDX], | ||
| 152 | + resTensor.GetShape()[NC1HWC0_W_IDX]}; | ||
| 153 | + Tensor finalRes3DimTensor(resTensor.GetStorage()->Datatype(), orgOutShape, "TensorOut3Dim"); | ||
| 154 | + std::vector<SymbolicScalar> resValidShape = resTensor.GetValidShape(); | ||
| 155 | + finalRes3DimTensor.GetStorage()->UpdateDynValidShape( | ||
| 156 | + {resValidShape[NC1HWC0_N_IDX], operandVecIn[INPUT_WEIGHT_IDX]->GetDynValidShape()[NCHW_N_IDX], | ||
| 157 | + resValidShape[NC1HWC0_W_IDX]}); | ||
| 158 | + VecTile savedVecTile = TileShape::Current().GetVecTile(); | ||
| 159 | + TileShape::Current().SetVecTile(Conv::GetReshapeVecTile(vecTiles.outVecTile, false)); | ||
| 160 | + auto& reshapeResOp = functionPtr->AddOperation(Opcode::OP_RESHAPE, {finalResTensor.GetStorage()}, | ||
| 161 | + {finalRes3DimTensor.GetStorage()}); | ||
| 162 | + TileShape::Current().SetVecTile(savedVecTile); | ||
| 163 | + reshapeResOp.SetAttribute(OpAttributeKey::isConv, true); | ||
| 164 | + if (convAttrParam.groups > 1) { | ||
| 165 | + reshapeResOp.SetAttribute(OpAttributeKey::groupReshapeNoSplit, true); | ||
| 166 | + } | ||
| 167 | + return finalRes3DimTensor; | ||
| 168 | +} | ||
| 169 | + | ||
| 145 | Tensor ConstructTensorGraphNZ2NZ(Function* functionPtr, std::vector<LogicalTensorPtr> operandVecIn, | 170 | Tensor ConstructTensorGraphNZ2NZ(Function* functionPtr, std::vector<LogicalTensorPtr> operandVecIn, |
| 146 | const Tensor& resTensor, const ConvAttrParam& convAttrParam) | 171 | const Tensor& resTensor, const ConvAttrParam& convAttrParam) |
| 147 | { | 172 | { |
| @@ -168,14 +193,6 @@ Tensor ConstructTensorGraphNZ2NZ(Function* functionPtr, std::vector<LogicalTenso | |||
| 168 | Opcode convOpCode = convAttrParam.isConv3D ? Opcode::OP_CONV3D : Opcode::OP_CONV2D; | 193 | Opcode convOpCode = convAttrParam.isConv3D ? Opcode::OP_CONV3D : Opcode::OP_CONV2D; |
| 169 | auto& op = functionPtr->AddOperation(convOpCode, operandVecInNZ, operandVecOut); | 194 | auto& op = functionPtr->AddOperation(convOpCode, operandVecInNZ, operandVecOut); |
| 170 | 195 | ||
| 171 | - std::vector<int64_t> orgOutShape = {resTensor.GetShape()[NC1HWC0_N_IDX], | ||
| 172 | - operandVecIn[INPUT_WEIGHT_IDX]->GetShape()[NCHW_N_IDX], | ||
| 173 | - resTensor.GetShape()[NC1HWC0_H_IDX], resTensor.GetShape()[NC1HWC0_W_IDX]}; | ||
| 174 | - if (convAttrParam.isConv3D) { | ||
| 175 | - orgOutShape = {resTensor.GetShape()[NDC1HWC0_N_IDX], operandVecIn[INPUT_WEIGHT_IDX]->GetShape()[NCHW_N_IDX], | ||
| 176 | - resTensor.GetShape()[NDC1HWC0_D_IDX], resTensor.GetShape()[NDC1HWC0_H_IDX], | ||
| 177 | - resTensor.GetShape()[NDC1HWC0_W_IDX]}; | ||
| 178 | - } | ||
| 179 | Tensor finalResTensor = GetFinalResTensorNZ2NZ(operandVecIn, resTensor, convAttrParam); | 196 | Tensor finalResTensor = GetFinalResTensorNZ2NZ(operandVecIn, resTensor, convAttrParam); |
| 180 | auto& orgResOp = functionPtr->AddOperation(Opcode::OP_FAKE_TRANS, operandVecOut, {finalResTensor.GetStorage()}); | 197 | auto& orgResOp = functionPtr->AddOperation(Opcode::OP_FAKE_TRANS, operandVecOut, {finalResTensor.GetStorage()}); |
| 181 | orgResOp.SetAttribute(FAKE_TRANS_IN_FORMAT_ATTR, static_cast<int64_t>(resTensor.Format())); | 198 | orgResOp.SetAttribute(FAKE_TRANS_IN_FORMAT_ATTR, static_cast<int64_t>(resTensor.Format())); |
| @@ -184,28 +201,72 @@ Tensor ConstructTensorGraphNZ2NZ(Function* functionPtr, std::vector<LogicalTenso | |||
| 184 | convAttrParam); | 201 | convAttrParam); |
| 185 | 202 | ||
| 186 | if (convAttrParam.isConv1D) { | 203 | if (convAttrParam.isConv1D) { |
| 187 | - auto vecTiles = Conv::InferConvVecTileShapes(op, operandVecIn[INPUT_FMAP_IDX]->Datatype()); | 204 | + return ConstructConv1DResTensor(functionPtr, op, operandVecIn, resTensor, finalResTensor, convAttrParam); |
| 188 | - orgOutShape = {resTensor.GetShape()[NC1HWC0_N_IDX], operandVecIn[INPUT_WEIGHT_IDX]->GetShape()[NCHW_N_IDX], | ||
| 189 | - resTensor.GetShape()[NC1HWC0_W_IDX]}; | ||
| 190 | - Tensor finalRes3DimTensor(resTensor.GetStorage()->Datatype(), orgOutShape, "TensorOut3Dim"); | ||
| 191 | - std::vector<SymbolicScalar> resValidShape = resTensor.GetValidShape(); | ||
| 192 | - finalRes3DimTensor.GetStorage()->UpdateDynValidShape( | ||
| 193 | - {resValidShape[NC1HWC0_N_IDX], operandVecIn[INPUT_WEIGHT_IDX]->GetDynValidShape()[NCHW_N_IDX], | ||
| 194 | - resValidShape[NC1HWC0_W_IDX]}); | ||
| 195 | - VecTile savedVecTile = TileShape::Current().GetVecTile(); | ||
| 196 | - TileShape::Current().SetVecTile(Conv::GetReshapeVecTile(vecTiles.outVecTile, false)); | ||
| 197 | - auto& reshapeResOp = functionPtr->AddOperation(Opcode::OP_RESHAPE, {finalResTensor.GetStorage()}, | ||
| 198 | - {finalRes3DimTensor.GetStorage()}); | ||
| 199 | - TileShape::Current().SetVecTile(savedVecTile); | ||
| 200 | - reshapeResOp.SetAttribute(OpAttributeKey::isConv, true); | ||
| 201 | - if (convAttrParam.groups > 1) { | ||
| 202 | - reshapeResOp.SetAttribute(OpAttributeKey::groupReshapeNoSplit, true); | ||
| 203 | - } | ||
| 204 | - return finalRes3DimTensor; | ||
| 205 | } | 205 | } |
| 206 | return finalResTensor; | 206 | return finalResTensor; |
| 207 | } | 207 | } |
| 208 | 208 | ||
| 209 | +static void ConstructConv1DOperandReshape(Function* functionPtr, const Tensor& inputTensor, const Tensor& weightTensor, | ||
| 210 | + const Tensor& resTensor, const ConvAttrParam& convAttrParam, | ||
| 211 | + std::vector<LogicalTensorPtr>& operandVecIn, | ||
| 212 | + std::vector<LogicalTensorPtr>& operandVecOut) | ||
| 213 | +{ | ||
| 214 | + auto convTile = TileShape::Current().GetConvTile(); | ||
| 215 | + auto vecTiles = Conv::InferConvVecTileShapes(convTile, inputTensor.GetStorage()->Datatype(), inputTensor.GetShape(), | ||
| 216 | + weightTensor.GetShape(), convAttrParam.isConv3D, true, | ||
| 217 | + convAttrParam.groups); | ||
| 218 | + VecTile savedVecTile = TileShape::Current().GetVecTile(); | ||
| 219 | + | ||
| 220 | + std::vector<int64_t> fmap4DimShape{inputTensor.GetShape()[NCHW_N_IDX], inputTensor.GetShape()[NCHW_C_IDX], 1, | ||
| 221 | + inputTensor.GetShape()[NCHW_H_IDX]}; | ||
| 222 | + Tensor fmap4DimTensor(inputTensor.GetStorage()->Datatype(), fmap4DimShape, "", inputTensor.Format()); | ||
| 223 | + TileShape::Current().SetVecTile(Conv::GetReshapeVecTile(vecTiles.fmapVecTile, true)); | ||
| 224 | + auto& reshapeFmapOp = functionPtr->AddOperation(Opcode::OP_RESHAPE, {inputTensor.GetStorage()}, | ||
| 225 | + {fmap4DimTensor.GetStorage()}); | ||
| 226 | + | ||
| 227 | + std::vector<int64_t> weight4DimShape{weightTensor.GetShape()[NCHW_N_IDX], weightTensor.GetShape()[NCHW_C_IDX], 1, | ||
| 228 | + weightTensor.GetShape()[NCHW_H_IDX]}; | ||
| 229 | + Tensor weigth4DimTensor(weightTensor.GetStorage()->Datatype(), weight4DimShape, "", weightTensor.Format()); | ||
| 230 | + std::vector<SymbolicScalar> weightValidShape = weightTensor.GetValidShape(); | ||
| 231 | + weigth4DimTensor.GetStorage()->UpdateDynValidShape( | ||
| 232 | + {weightValidShape[NCL_N_IDX], weightValidShape[NCL_C_IDX], 1, weightValidShape[NCL_L_IDX]}); | ||
| 233 | + TileShape::Current().SetVecTile(Conv::GetReshapeVecTile(vecTiles.weightVecTile, true)); | ||
| 234 | + auto& reshapeWeightOp = functionPtr->AddOperation(Opcode::OP_RESHAPE, {weightTensor.GetStorage()}, | ||
| 235 | + {weigth4DimTensor.GetStorage()}); | ||
| 236 | + TileShape::Current().SetVecTile(savedVecTile); | ||
| 237 | + | ||
| 238 | + reshapeFmapOp.SetAttribute(OpAttributeKey::isConv, true); | ||
| 239 | + reshapeWeightOp.SetAttribute(OpAttributeKey::isConv, true); | ||
| 240 | + if (convAttrParam.groups > 1) { | ||
| 241 | + reshapeFmapOp.SetAttribute(OpAttributeKey::groupReshapeNoSplit, true); | ||
| 242 | + reshapeWeightOp.SetAttribute(OpAttributeKey::groupReshapeNoSplit, true); | ||
| 243 | + } | ||
| 244 | + operandVecIn = {fmap4DimTensor.GetStorage(), weigth4DimTensor.GetStorage()}; | ||
| 245 | + // conv1d case, squeeze output to NCL | ||
| 246 | + std::vector<int64_t> res4DimShape{inputTensor.GetShape()[NCHW_N_IDX], weightTensor.GetShape()[NCHW_N_IDX], 1, | ||
| 247 | + resTensor.GetShape()[NCHW_H_IDX]}; | ||
| 248 | + Tensor res4DimTensor(resTensor.GetStorage()->Datatype(), res4DimShape, "", resTensor.Format()); | ||
| 249 | + operandVecOut = {res4DimTensor.GetStorage()}; | ||
| 250 | +} | ||
| 251 | + | ||
| 252 | +static void AddConv1DOutReshapeOp(Function* functionPtr, const Tensor& inputTensor, const Tensor& weightTensor, | ||
| 253 | + const std::vector<LogicalTensorPtr>& operandVecOut, const Tensor& resTensor, | ||
| 254 | + const ConvAttrParam& convAttrParam) | ||
| 255 | +{ | ||
| 256 | + auto convTile = TileShape::Current().GetConvTile(); | ||
| 257 | + auto vecTiles = Conv::InferConvVecTileShapes(convTile, inputTensor.GetStorage()->Datatype(), inputTensor.GetShape(), | ||
| 258 | + weightTensor.GetShape(), convAttrParam.isConv3D, true, | ||
| 259 | + convAttrParam.groups); | ||
| 260 | + VecTile savedVecTile = TileShape::Current().GetVecTile(); | ||
| 261 | + TileShape::Current().SetVecTile(Conv::GetReshapeVecTile(vecTiles.outVecTile, false)); | ||
| 262 | + auto& reshapeResOp = functionPtr->AddOperation(Opcode::OP_RESHAPE, operandVecOut, {resTensor.GetStorage()}); | ||
| 263 | + TileShape::Current().SetVecTile(savedVecTile); | ||
| 264 | + reshapeResOp.SetAttribute(OpAttributeKey::isConv, true); | ||
| 265 | + if (convAttrParam.groups > 1) { | ||
| 266 | + reshapeResOp.SetAttribute(OpAttributeKey::groupReshapeNoSplit, true); | ||
| 267 | + } | ||
| 268 | +} | ||
| 269 | + | ||
| 209 | Tensor ConstructTensorGraph(const Tensor& inputTensor, const Tensor& weightTensor, const Tensor& biasTensor, | 270 | Tensor ConstructTensorGraph(const Tensor& inputTensor, const Tensor& weightTensor, const Tensor& biasTensor, |
| 210 | const Tensor& resTensor, ConvAttrParam& convAttrParam) | 271 | const Tensor& resTensor, ConvAttrParam& convAttrParam) |
| 211 | { | 272 | { |
| @@ -216,42 +277,8 @@ Tensor ConstructTensorGraph(const Tensor& inputTensor, const Tensor& weightTenso | |||
| 216 | std::vector<LogicalTensorPtr> operandVecOut = {resTensor.GetStorage()}; | 277 | std::vector<LogicalTensorPtr> operandVecOut = {resTensor.GetStorage()}; |
| 217 | if (convAttrParam.isConv1D) { | 278 | if (convAttrParam.isConv1D) { |
| 218 | // conv1d case, unsqueeze input to NC1W | 279 | // conv1d case, unsqueeze input to NC1W |
| 219 | - auto convTile = TileShape::Current().GetConvTile(); | 280 | + ConstructConv1DOperandReshape(functionPtr, inputTensor, weightTensor, resTensor, convAttrParam, operandVecIn, |
| 220 | - auto vecTiles = Conv::InferConvVecTileShapes(convTile, inputTensor.GetStorage()->Datatype(), | 281 | + operandVecOut); |
| 221 | - inputTensor.GetShape(), weightTensor.GetShape(), | ||
| 222 | - convAttrParam.isConv3D, true, convAttrParam.groups); | ||
| 223 | - VecTile savedVecTile = TileShape::Current().GetVecTile(); | ||
| 224 | - | ||
| 225 | - std::vector<int64_t> fmap4DimShape{inputTensor.GetShape()[NCHW_N_IDX], inputTensor.GetShape()[NCHW_C_IDX], 1, | ||
| 226 | - inputTensor.GetShape()[NCHW_H_IDX]}; | ||
| 227 | - Tensor fmap4DimTensor(inputTensor.GetStorage()->Datatype(), fmap4DimShape, "", inputTensor.Format()); | ||
| 228 | - TileShape::Current().SetVecTile(Conv::GetReshapeVecTile(vecTiles.fmapVecTile, true)); | ||
| 229 | - auto& reshapeFmapOp = functionPtr->AddOperation(Opcode::OP_RESHAPE, {inputTensor.GetStorage()}, | ||
| 230 | - {fmap4DimTensor.GetStorage()}); | ||
| 231 | - | ||
| 232 | - std::vector<int64_t> weight4DimShape{weightTensor.GetShape()[NCHW_N_IDX], weightTensor.GetShape()[NCHW_C_IDX], | ||
| 233 | - 1, weightTensor.GetShape()[NCHW_H_IDX]}; | ||
| 234 | - Tensor weigth4DimTensor(weightTensor.GetStorage()->Datatype(), weight4DimShape, "", weightTensor.Format()); | ||
| 235 | - std::vector<SymbolicScalar> weightValidShape = weightTensor.GetValidShape(); | ||
| 236 | - weigth4DimTensor.GetStorage()->UpdateDynValidShape( | ||
| 237 | - {weightValidShape[NCL_N_IDX], weightValidShape[NCL_C_IDX], 1, weightValidShape[NCL_L_IDX]}); | ||
| 238 | - TileShape::Current().SetVecTile(Conv::GetReshapeVecTile(vecTiles.weightVecTile, true)); | ||
| 239 | - auto& reshapeWeightOp = functionPtr->AddOperation(Opcode::OP_RESHAPE, {weightTensor.GetStorage()}, | ||
| 240 | - {weigth4DimTensor.GetStorage()}); | ||
| 241 | - TileShape::Current().SetVecTile(savedVecTile); | ||
| 242 | - | ||
| 243 | - reshapeFmapOp.SetAttribute(OpAttributeKey::isConv, true); | ||
| 244 | - reshapeWeightOp.SetAttribute(OpAttributeKey::isConv, true); | ||
| 245 | - if (convAttrParam.groups > 1) { | ||
| 246 | - reshapeFmapOp.SetAttribute(OpAttributeKey::groupReshapeNoSplit, true); | ||
| 247 | - reshapeWeightOp.SetAttribute(OpAttributeKey::groupReshapeNoSplit, true); | ||
| 248 | - } | ||
| 249 | - operandVecIn = {fmap4DimTensor.GetStorage(), weigth4DimTensor.GetStorage()}; | ||
| 250 | - // conv1d case, squeeze output to NCL | ||
| 251 | - std::vector<int64_t> res4DimShape{inputTensor.GetShape()[NCHW_N_IDX], weightTensor.GetShape()[NCHW_N_IDX], 1, | ||
| 252 | - resTensor.GetShape()[NCHW_H_IDX]}; | ||
| 253 | - Tensor res4DimTensor(resTensor.GetStorage()->Datatype(), res4DimShape, "", resTensor.Format()); | ||
| 254 | - operandVecOut = {res4DimTensor.GetStorage()}; | ||
| 255 | } | 282 | } |
| 256 | if (!biasTensor.IsEmpty()) { | 283 | if (!biasTensor.IsEmpty()) { |
| 257 | convAttrParam.hasBias = true; | 284 | convAttrParam.hasBias = true; |
| @@ -270,18 +297,7 @@ Tensor ConstructTensorGraph(const Tensor& inputTensor, const Tensor& weightTenso | |||
| 270 | SetTensorOpAttr(op, operandVecIn[INPUT_FMAP_IDX], operandVecIn[INPUT_WEIGHT_IDX], operandVecOut[0], convAttrParam); | 297 | SetTensorOpAttr(op, operandVecIn[INPUT_FMAP_IDX], operandVecIn[INPUT_WEIGHT_IDX], operandVecOut[0], convAttrParam); |
| 271 | 298 | ||
| 272 | if (convAttrParam.isConv1D) { | 299 | if (convAttrParam.isConv1D) { |
| 273 | - auto convTile = TileShape::Current().GetConvTile(); | 300 | + AddConv1DOutReshapeOp(functionPtr, inputTensor, weightTensor, operandVecOut, resTensor, convAttrParam); |
| 274 | - auto vecTiles = Conv::InferConvVecTileShapes(convTile, inputTensor.GetStorage()->Datatype(), | ||
| 275 | - inputTensor.GetShape(), weightTensor.GetShape(), | ||
| 276 | - convAttrParam.isConv3D, true, convAttrParam.groups); | ||
| 277 | - VecTile savedVecTile = TileShape::Current().GetVecTile(); | ||
| 278 | - TileShape::Current().SetVecTile(Conv::GetReshapeVecTile(vecTiles.outVecTile, false)); | ||
| 279 | - auto& reshapeResOp = functionPtr->AddOperation(Opcode::OP_RESHAPE, operandVecOut, {resTensor.GetStorage()}); | ||
| 280 | - TileShape::Current().SetVecTile(savedVecTile); | ||
| 281 | - reshapeResOp.SetAttribute(OpAttributeKey::isConv, true); | ||
| 282 | - if (convAttrParam.groups > 1) { | ||
| 283 | - reshapeResOp.SetAttribute(OpAttributeKey::groupReshapeNoSplit, true); | ||
| 284 | - } | ||
| 285 | } | 301 | } |
| 286 | return resTensor; | 302 | return resTensor; |
| 287 | } | 303 | } |
| @@ -485,15 +501,11 @@ void SetImg2ColAttr(Operation& load3dOpAl0, const ConvAttrParam& convAttrParam, | |||
| 485 | load3dOpAl0.SetAttribute(Conv::LoadStoreConvOpAttributeKey::isConv3D, convAttrParam.isConv3D); | 501 | load3dOpAl0.SetAttribute(Conv::LoadStoreConvOpAttributeKey::isConv3D, convAttrParam.isConv3D); |
| 486 | } | 502 | } |
| 487 | 503 | ||
| 488 | -void SetCopyInAL1Op(Operation& copyInOpAl1, const ConvTileInfo& convTileInfo, ConvIterInfo& iterInfo, | 504 | +static void CalFmapSrcGmInfo(const ConvTileInfo& convTileInfo, ConvIterInfo& iterInfo, |
| 489 | - const ConvAttrParam& convAttrParam, const std::vector<int64_t>& dstAL1Shape, | 505 | + const ConvAttrParam& convAttrParam, const std::vector<int64_t>& srcGmValidShape, |
| 490 | - const std::vector<int64_t>& srcGmValidShape, const int64_t& srcCinOffset, bool hasTransFormatL1) | 506 | + const int64_t& srcCinOffset, std::vector<int64_t>& srcGmOffset, |
| 507 | + std::vector<int64_t>& srcGmShape) | ||
| 491 | { | 508 | { |
| 492 | - copyInOpAl1.SetAttribute(OpAttributeKey::isConv, true); | ||
| 493 | - copyInOpAl1.SetAttribute(OpAttributeKey::filterH, convTileInfo.orgKh); | ||
| 494 | - copyInOpAl1.SetAttribute(OpAttributeKey::filterW, convTileInfo.orgKw); | ||
| 495 | - copyInOpAl1.SetAttribute(LoadStoreConvOpAttributeKey::isFmap, true); | ||
| 496 | - copyInOpAl1.SetAttribute(LoadStoreConvOpAttributeKey::isConv3D, convAttrParam.isConv3D); | ||
| 497 | int64_t src_n_offset = iterInfo.batchOffset; | 509 | int64_t src_n_offset = iterInfo.batchOffset; |
| 498 | int64_t src_c_offset = iterInfo.groupOffset * (convTileInfo.orgCin / convAttrParam.groups) + srcCinOffset; | 510 | int64_t src_c_offset = iterInfo.groupOffset * (convTileInfo.orgCin / convAttrParam.groups) + srcCinOffset; |
| 499 | int64_t src_d_offset = convAttrParam.isConv3D ? | 511 | int64_t src_d_offset = convAttrParam.isConv3D ? |
| @@ -503,13 +515,7 @@ void SetCopyInAL1Op(Operation& copyInOpAl1, const ConvTileInfo& convTileInfo, Co | |||
| 503 | int64_t src_h_offset = iterInfo.hL1InOffset > 0 ? iterInfo.hL1InOffset : 0; | 515 | int64_t src_h_offset = iterInfo.hL1InOffset > 0 ? iterInfo.hL1InOffset : 0; |
| 504 | int64_t src_w_offset = iterInfo.wL1InOffset > 0 ? iterInfo.wL1InOffset : 0; | 516 | int64_t src_w_offset = iterInfo.wL1InOffset > 0 ? iterInfo.wL1InOffset : 0; |
| 505 | 517 | ||
| 506 | - std::vector<int64_t> srcGmOffset; | ||
| 507 | - std::vector<int64_t> srcGmShape; | ||
| 508 | if (IsArch32Platform()) { | 518 | if (IsArch32Platform()) { |
| 509 | - if (!hasTransFormatL1) { | ||
| 510 | - copyInOpAl1.SetAttribute(LoadStoreConvOpAttributeKey::copyInMode, | ||
| 511 | - static_cast<int64_t>(CopyInMode::COPY_MOD_NZ2NZ)); | ||
| 512 | - } | ||
| 513 | int64_t cin1PerGroup = CeilDiv(convTileInfo.orgCin / convAttrParam.groups, convTileInfo.cin0); | 519 | int64_t cin1PerGroup = CeilDiv(convTileInfo.orgCin / convAttrParam.groups, convTileInfo.cin0); |
| 514 | int64_t cin1Offset = iterInfo.groupOffset * cin1PerGroup + srcCinOffset / convTileInfo.cin0; | 520 | int64_t cin1Offset = iterInfo.groupOffset * cin1PerGroup + srcCinOffset / convTileInfo.cin0; |
| 515 | if (convAttrParam.isConv3D) { | 521 | if (convAttrParam.isConv3D) { |
| @@ -526,17 +532,31 @@ void SetCopyInAL1Op(Operation& copyInOpAl1, const ConvTileInfo& convTileInfo, Co | |||
| 526 | convTileInfo.cin0}; | 532 | convTileInfo.cin0}; |
| 527 | } | 533 | } |
| 528 | } else { | 534 | } else { |
| 529 | - if (!hasTransFormatL1) { | ||
| 530 | - copyInOpAl1.SetAttribute(LoadStoreConvOpAttributeKey::copyInMode, | ||
| 531 | - static_cast<int64_t>(CopyInMode::COPY_MOD_DN2NZ)); | ||
| 532 | - } | ||
| 533 | srcGmOffset = {src_n_offset, src_c_offset, src_h_offset, src_w_offset}; | 535 | srcGmOffset = {src_n_offset, src_c_offset, src_h_offset, src_w_offset}; |
| 534 | if (convAttrParam.isConv3D) { | 536 | if (convAttrParam.isConv3D) { |
| 535 | srcGmOffset = {src_n_offset, src_c_offset, src_d_offset, src_h_offset, src_w_offset}; | 537 | srcGmOffset = {src_n_offset, src_c_offset, src_d_offset, src_h_offset, src_w_offset}; |
| 536 | } | 538 | } |
| 537 | srcGmShape = srcGmValidShape; | 539 | srcGmShape = srcGmValidShape; |
| 538 | } | 540 | } |
| 541 | +} | ||
| 539 | 542 | ||
| 543 | +void SetCopyInAL1Op(Operation& copyInOpAl1, const ConvTileInfo& convTileInfo, ConvIterInfo& iterInfo, | ||
| 544 | + const ConvAttrParam& convAttrParam, const std::vector<int64_t>& dstAL1Shape, | ||
| 545 | + const std::vector<int64_t>& srcGmValidShape, const int64_t& srcCinOffset, bool hasTransFormatL1) | ||
| 546 | +{ | ||
| 547 | + copyInOpAl1.SetAttribute(OpAttributeKey::isConv, true); | ||
| 548 | + copyInOpAl1.SetAttribute(OpAttributeKey::filterH, convTileInfo.orgKh); | ||
| 549 | + copyInOpAl1.SetAttribute(OpAttributeKey::filterW, convTileInfo.orgKw); | ||
| 550 | + copyInOpAl1.SetAttribute(LoadStoreConvOpAttributeKey::isFmap, true); | ||
| 551 | + copyInOpAl1.SetAttribute(LoadStoreConvOpAttributeKey::isConv3D, convAttrParam.isConv3D); | ||
| 552 | + if (!hasTransFormatL1) { | ||
| 553 | + copyInOpAl1.SetAttribute( | ||
| 554 | + LoadStoreConvOpAttributeKey::copyInMode, | ||
| 555 | + static_cast<int64_t>(IsArch32Platform() ? CopyInMode::COPY_MOD_NZ2NZ : CopyInMode::COPY_MOD_DN2NZ)); | ||
| 556 | + } | ||
| 557 | + std::vector<int64_t> srcGmOffset; | ||
| 558 | + std::vector<int64_t> srcGmShape; | ||
| 559 | + CalFmapSrcGmInfo(convTileInfo, iterInfo, convAttrParam, srcGmValidShape, srcCinOffset, srcGmOffset, srcGmShape); | ||
| 540 | const auto& viewToShape = hasTransFormatL1 ? srcGmValidShape : dstAL1Shape; | 560 | const auto& viewToShape = hasTransFormatL1 ? srcGmValidShape : dstAL1Shape; |
| 541 | auto viewAttr = std::make_shared<ViewOpAttribute>(srcGmOffset, MemoryType::MEM_L1, | 561 | auto viewAttr = std::make_shared<ViewOpAttribute>(srcGmOffset, MemoryType::MEM_L1, |
| 542 | SymbolicScalar::FromConcrete(srcGmOffset), | 562 | SymbolicScalar::FromConcrete(srcGmOffset), |
| @@ -545,18 +565,17 @@ void SetCopyInAL1Op(Operation& copyInOpAl1, const ConvTileInfo& convTileInfo, Co | |||
| 545 | iterInfo.aL1UpadateFlag = false; | 565 | iterInfo.aL1UpadateFlag = false; |
| 546 | } | 566 | } |
| 547 | 567 | ||
| 548 | -static void ConstructFmapL1Tile(Function& function, const ConvGraphNodes& tensorGraphNodes, | 568 | +static void CalFmapL1Shapes(const ConvTileInfo& convTileInfo, ConvIterInfo& iterInfo, |
| 549 | - const ConvTileInfo& convTileInfo, ConvIterInfo& iterInfo, | 569 | + const ConvAttrParam& convAttrParam, std::vector<int64_t>& dstAL1Shape, |
| 550 | - LogicalTensorPtr& dstAL1TensorPtr, const ConvAttrParam& convAttrParam) | 570 | + std::vector<int64_t>& srcGmValidShape, int64_t& srcCinOffset) |
| 551 | { | 571 | { |
| 552 | iterInfo.kAL1Size = std::min((convTileInfo.kPerGroup * iterInfo.dkL1Size - iterInfo.kL0Offset), convTileInfo.kAL1); | 572 | iterInfo.kAL1Size = std::min((convTileInfo.kPerGroup * iterInfo.dkL1Size - iterInfo.kL0Offset), convTileInfo.kAL1); |
| 553 | int64_t cin1AL1Size = (iterInfo.kAL1Size / convTileInfo.cin0) / (convTileInfo.orgKh * convTileInfo.orgKw); | 573 | int64_t cin1AL1Size = (iterInfo.kAL1Size / convTileInfo.cin0) / (convTileInfo.orgKh * convTileInfo.orgKw); |
| 554 | - std::vector<int64_t> dstAL1Shape = std::vector<int64_t>{1, cin1AL1Size, iterInfo.hinL1Size, iterInfo.winL1Size, | 574 | + dstAL1Shape = std::vector<int64_t>{1, cin1AL1Size, iterInfo.hinL1Size, iterInfo.winL1Size, convTileInfo.cin0}; |
| 555 | - convTileInfo.cin0}; | 575 | + srcCinOffset = (iterInfo.kL0Offset % convTileInfo.kPerGroup) / (convTileInfo.orgKh * convTileInfo.orgKw); |
| 556 | - int64_t srcCinOffset = (iterInfo.kL0Offset % convTileInfo.kPerGroup) / (convTileInfo.orgKh * convTileInfo.orgKw); | ||
| 557 | int64_t srcGmCin = std::min(convTileInfo.orgCin / convAttrParam.groups - srcCinOffset, | 576 | int64_t srcGmCin = std::min(convTileInfo.orgCin / convAttrParam.groups - srcCinOffset, |
| 558 | convTileInfo.kAL1 / (convTileInfo.orgKh * convTileInfo.orgKw)); | 577 | convTileInfo.kAL1 / (convTileInfo.orgKh * convTileInfo.orgKw)); |
| 559 | - std::vector<int64_t> srcGmValidShape = std::vector<int64_t>{1, srcGmCin, iterInfo.hinL1Size, iterInfo.winL1Size}; | 578 | + srcGmValidShape = std::vector<int64_t>{1, srcGmCin, iterInfo.hinL1Size, iterInfo.winL1Size}; |
| 560 | 579 | ||
| 561 | if (convAttrParam.isConv3D) { | 580 | if (convAttrParam.isConv3D) { |
| 562 | iterInfo.dkAL1Size = 1; | 581 | iterInfo.dkAL1Size = 1; |
| @@ -570,6 +589,16 @@ static void ConstructFmapL1Tile(Function& function, const ConvGraphNodes& tensor | |||
| 570 | 1, iterInfo.dkAL1Size, cin1AL1Size, iterInfo.hinL1Size, iterInfo.winL1Size, convTileInfo.cin0}; | 589 | 1, iterInfo.dkAL1Size, cin1AL1Size, iterInfo.hinL1Size, iterInfo.winL1Size, convTileInfo.cin0}; |
| 571 | srcGmValidShape = std::vector<int64_t>{1, srcGmCin, iterInfo.dkAL1Size, iterInfo.hinL1Size, iterInfo.winL1Size}; | 590 | srcGmValidShape = std::vector<int64_t>{1, srcGmCin, iterInfo.dkAL1Size, iterInfo.hinL1Size, iterInfo.winL1Size}; |
| 572 | } | 591 | } |
| 592 | +} | ||
| 593 | + | ||
| 594 | +static void ConstructFmapL1Tile(Function& function, const ConvGraphNodes& tensorGraphNodes, | ||
| 595 | + const ConvTileInfo& convTileInfo, ConvIterInfo& iterInfo, | ||
| 596 | + LogicalTensorPtr& dstAL1TensorPtr, const ConvAttrParam& convAttrParam) | ||
| 597 | +{ | ||
| 598 | + std::vector<int64_t> dstAL1Shape; | ||
| 599 | + std::vector<int64_t> srcGmValidShape; | ||
| 600 | + int64_t srcCinOffset = 0; | ||
| 601 | + CalFmapL1Shapes(convTileInfo, iterInfo, convAttrParam, dstAL1Shape, srcGmValidShape, srcCinOffset); | ||
| 573 | 602 | ||
| 574 | dstAL1TensorPtr = std::make_shared<LogicalTensor>(function, tensorGraphNodes.fmapTensorPtr->Datatype(), dstAL1Shape, | 603 | dstAL1TensorPtr = std::make_shared<LogicalTensor>(function, tensorGraphNodes.fmapTensorPtr->Datatype(), dstAL1Shape, |
| 575 | SymbolicScalar::FromConcrete(dstAL1Shape), | 604 | SymbolicScalar::FromConcrete(dstAL1Shape), |
| @@ -640,18 +669,11 @@ LogicalTensorPtr ConstructFmapTile(Function& function, const ConvGraphNodes& ten | |||
| 640 | return dstAL0TensorPtr; | 669 | return dstAL0TensorPtr; |
| 641 | } | 670 | } |
| 642 | 671 | ||
| 643 | -void SetCopyInBL1Op(Operation& copyInOpBl1, const ConvTileInfo& convTileInfo, ConvIterInfo& iterInfo, | 672 | +static void CalWeightSrcGmInfo(const ConvTileInfo& convTileInfo, ConvIterInfo& iterInfo, |
| 644 | - const ConvAttrParam& convAttrParam, const std::vector<int64_t>& dstBL1Shape, | 673 | + const ConvAttrParam& convAttrParam, const std::vector<int64_t>& srcGmValidShape, |
| 645 | - const std::vector<int64_t>& srcGmValidShape, const int64_t& srcCinOffset, bool hasTransFormatL1) | 674 | + const int64_t& srcCinOffset, std::vector<int64_t>& srcGmOffset, |
| 675 | + std::vector<int64_t>& srcGmShape) | ||
| 646 | { | 676 | { |
| 647 | - copyInOpBl1.SetAttribute(OpAttributeKey::isConv, true); | ||
| 648 | - copyInOpBl1.SetAttribute(OpAttributeKey::filterH, convTileInfo.orgKh); | ||
| 649 | - copyInOpBl1.SetAttribute(OpAttributeKey::filterW, convTileInfo.orgKw); | ||
| 650 | - if (convAttrParam.isConv3D) { | ||
| 651 | - copyInOpBl1.SetAttribute("CONV_DK_L1_SIZE", iterInfo.dkBL1Size); | ||
| 652 | - } | ||
| 653 | - copyInOpBl1.SetAttribute(LoadStoreConvOpAttributeKey::isFmap, false); | ||
| 654 | - copyInOpBl1.SetAttribute(LoadStoreConvOpAttributeKey::isConv3D, convAttrParam.isConv3D); | ||
| 655 | int64_t src_n_offset = iterInfo.groupOffset * convTileInfo.coutPerGroup + iterInfo.nL1Offset; | 677 | int64_t src_n_offset = iterInfo.groupOffset * convTileInfo.coutPerGroup + iterInfo.nL1Offset; |
| 656 | int64_t src_c_offset = srcCinOffset; | 678 | int64_t src_c_offset = srcCinOffset; |
| 657 | int64_t src_d_offset = 0; | 679 | int64_t src_d_offset = 0; |
| @@ -662,13 +684,7 @@ void SetCopyInBL1Op(Operation& copyInOpBl1, const ConvTileInfo& convTileInfo, Co | |||
| 662 | (iterInfo.kL0Offset / convTileInfo.kPerGroup); | 684 | (iterInfo.kL0Offset / convTileInfo.kPerGroup); |
| 663 | } | 685 | } |
| 664 | 686 | ||
| 665 | - std::vector<int64_t> srcGmOffset; | ||
| 666 | - std::vector<int64_t> srcGmShape; | ||
| 667 | if (IsArch32Platform()) { | 687 | if (IsArch32Platform()) { |
| 668 | - if (!hasTransFormatL1) { | ||
| 669 | - copyInOpBl1.SetAttribute(LoadStoreConvOpAttributeKey::copyInMode, | ||
| 670 | - static_cast<int64_t>(CopyInMode::COPY_MOD_NZ2NZ)); | ||
| 671 | - } | ||
| 672 | int64_t cout1Offset = iterInfo.nL1Offset / MKN_N_VALUE; | 688 | int64_t cout1Offset = iterInfo.nL1Offset / MKN_N_VALUE; |
| 673 | int64_t cin1Offset = src_c_offset / convTileInfo.cin0; | 689 | int64_t cin1Offset = src_c_offset / convTileInfo.cin0; |
| 674 | int64_t khxkw = convTileInfo.orgKh * convTileInfo.orgKw; | 690 | int64_t khxkw = convTileInfo.orgKh * convTileInfo.orgKw; |
| @@ -684,16 +700,34 @@ void SetCopyInBL1Op(Operation& copyInOpBl1, const ConvTileInfo& convTileInfo, Co | |||
| 684 | CeilDiv(iterInfo.nL1Size, MKN_N_VALUE), MKN_N_VALUE, convTileInfo.cin0}; | 700 | CeilDiv(iterInfo.nL1Size, MKN_N_VALUE), MKN_N_VALUE, convTileInfo.cin0}; |
| 685 | } | 701 | } |
| 686 | } else { | 702 | } else { |
| 687 | - if (!hasTransFormatL1) { | ||
| 688 | - copyInOpBl1.SetAttribute(LoadStoreConvOpAttributeKey::copyInMode, | ||
| 689 | - static_cast<int64_t>(CopyInMode::COPY_MOD_DN2NZ)); | ||
| 690 | - } | ||
| 691 | srcGmOffset = {src_n_offset, src_c_offset, 0, 0}; | 703 | srcGmOffset = {src_n_offset, src_c_offset, 0, 0}; |
| 692 | if (convAttrParam.isConv3D) { | 704 | if (convAttrParam.isConv3D) { |
| 693 | srcGmOffset = {src_n_offset, src_c_offset, src_d_offset, 0, 0}; | 705 | srcGmOffset = {src_n_offset, src_c_offset, src_d_offset, 0, 0}; |
| 694 | } | 706 | } |
| 695 | srcGmShape = srcGmValidShape; | 707 | srcGmShape = srcGmValidShape; |
| 696 | } | 708 | } |
| 709 | +} | ||
| 710 | + | ||
| 711 | +void SetCopyInBL1Op(Operation& copyInOpBl1, const ConvTileInfo& convTileInfo, ConvIterInfo& iterInfo, | ||
| 712 | + const ConvAttrParam& convAttrParam, const std::vector<int64_t>& dstBL1Shape, | ||
| 713 | + const std::vector<int64_t>& srcGmValidShape, const int64_t& srcCinOffset, bool hasTransFormatL1) | ||
| 714 | +{ | ||
| 715 | + copyInOpBl1.SetAttribute(OpAttributeKey::isConv, true); | ||
| 716 | + copyInOpBl1.SetAttribute(OpAttributeKey::filterH, convTileInfo.orgKh); | ||
| 717 | + copyInOpBl1.SetAttribute(OpAttributeKey::filterW, convTileInfo.orgKw); | ||
| 718 | + if (convAttrParam.isConv3D) { | ||
| 719 | + copyInOpBl1.SetAttribute("CONV_DK_L1_SIZE", iterInfo.dkBL1Size); | ||
| 720 | + } | ||
| 721 | + copyInOpBl1.SetAttribute(LoadStoreConvOpAttributeKey::isFmap, false); | ||
| 722 | + copyInOpBl1.SetAttribute(LoadStoreConvOpAttributeKey::isConv3D, convAttrParam.isConv3D); | ||
| 723 | + if (!hasTransFormatL1) { | ||
| 724 | + copyInOpBl1.SetAttribute( | ||
| 725 | + LoadStoreConvOpAttributeKey::copyInMode, | ||
| 726 | + static_cast<int64_t>(IsArch32Platform() ? CopyInMode::COPY_MOD_NZ2NZ : CopyInMode::COPY_MOD_DN2NZ)); | ||
| 727 | + } | ||
| 728 | + std::vector<int64_t> srcGmOffset; | ||
| 729 | + std::vector<int64_t> srcGmShape; | ||
| 730 | + CalWeightSrcGmInfo(convTileInfo, iterInfo, convAttrParam, srcGmValidShape, srcCinOffset, srcGmOffset, srcGmShape); | ||
| 697 | const auto& viewToShape = hasTransFormatL1 ? srcGmValidShape : dstBL1Shape; | 731 | const auto& viewToShape = hasTransFormatL1 ? srcGmValidShape : dstBL1Shape; |
| 698 | auto viewAttr = std::make_shared<ViewOpAttribute>(srcGmOffset, MemoryType::MEM_L1, | 732 | auto viewAttr = std::make_shared<ViewOpAttribute>(srcGmOffset, MemoryType::MEM_L1, |
| 699 | SymbolicScalar::FromConcrete(srcGmOffset), | 733 | SymbolicScalar::FromConcrete(srcGmOffset), |
| @@ -702,18 +736,17 @@ void SetCopyInBL1Op(Operation& copyInOpBl1, const ConvTileInfo& convTileInfo, Co | |||
| 702 | iterInfo.bL1UpadateFlag = false; | 736 | iterInfo.bL1UpadateFlag = false; |
| 703 | } | 737 | } |
| 704 | 738 | ||
| 705 | -static void ConstructWeightL1Tile(Function& function, const ConvGraphNodes& tensorGraphNodes, | 739 | +static void CalWeightL1Shapes(const ConvTileInfo& convTileInfo, ConvIterInfo& iterInfo, |
| 706 | - const ConvTileInfo& convTileInfo, ConvIterInfo& iterInfo, | 740 | + const ConvAttrParam& convAttrParam, std::vector<int64_t>& dstBL1Shape, |
| 707 | - LogicalTensorPtr& dstBL1TensorPtr, const ConvAttrParam& convAttrParam) | 741 | + std::vector<int64_t>& srcGmValidShape, int64_t& srcCinOffset) |
| 708 | { | 742 | { |
| 709 | iterInfo.kBL1Size = std::min(convTileInfo.kPerGroup * iterInfo.dkL1Size - iterInfo.kL0Offset, convTileInfo.kBL1); | 743 | iterInfo.kBL1Size = std::min(convTileInfo.kPerGroup * iterInfo.dkL1Size - iterInfo.kL0Offset, convTileInfo.kBL1); |
| 710 | - std::vector<int64_t> dstBL1Shape = std::vector<int64_t>{ | 744 | + dstBL1Shape = std::vector<int64_t>{iterInfo.kBL1Size / convTileInfo.cin0, CeilDiv(iterInfo.nL1Size, MKN_N_VALUE), |
| 711 | - iterInfo.kBL1Size / convTileInfo.cin0, CeilDiv(iterInfo.nL1Size, MKN_N_VALUE), MKN_N_VALUE, convTileInfo.cin0}; | 745 | + MKN_N_VALUE, convTileInfo.cin0}; |
| 712 | - int64_t srcCinOffset = (iterInfo.kL0Offset % convTileInfo.kPerGroup) / (convTileInfo.orgKh * convTileInfo.orgKw); | 746 | + srcCinOffset = (iterInfo.kL0Offset % convTileInfo.kPerGroup) / (convTileInfo.orgKh * convTileInfo.orgKw); |
| 713 | int64_t srcGmCin = std::min(convTileInfo.orgCin / convAttrParam.groups - srcCinOffset, | 747 | int64_t srcGmCin = std::min(convTileInfo.orgCin / convAttrParam.groups - srcCinOffset, |
| 714 | convTileInfo.kBL1 / (convTileInfo.orgKh * convTileInfo.orgKw)); | 748 | convTileInfo.kBL1 / (convTileInfo.orgKh * convTileInfo.orgKw)); |
| 715 | - std::vector<int64_t> srcGmValidShape = std::vector<int64_t>{iterInfo.nL1Size, srcGmCin, convTileInfo.orgKh, | 749 | + srcGmValidShape = std::vector<int64_t>{iterInfo.nL1Size, srcGmCin, convTileInfo.orgKh, convTileInfo.orgKw}; |
| 716 | - convTileInfo.orgKw}; | ||
| 717 | if (convAttrParam.isConv3D) { | 750 | if (convAttrParam.isConv3D) { |
| 718 | iterInfo.dkBL1Size = 1; | 751 | iterInfo.dkBL1Size = 1; |
| 719 | if (iterInfo.kBL1Size > convTileInfo.kPerGroup) { | 752 | if (iterInfo.kBL1Size > convTileInfo.kPerGroup) { |
| @@ -725,6 +758,17 @@ static void ConstructWeightL1Tile(Function& function, const ConvGraphNodes& tens | |||
| 725 | srcGmValidShape = std::vector<int64_t>{iterInfo.nL1Size, srcGmCin, iterInfo.dkBL1Size, convTileInfo.orgKh, | 758 | srcGmValidShape = std::vector<int64_t>{iterInfo.nL1Size, srcGmCin, iterInfo.dkBL1Size, convTileInfo.orgKh, |
| 726 | convTileInfo.orgKw}; | 759 | convTileInfo.orgKw}; |
| 727 | } | 760 | } |
| 761 | +} | ||
| 762 | + | ||
| 763 | +static void ConstructWeightL1Tile(Function& function, const ConvGraphNodes& tensorGraphNodes, | ||
| 764 | + const ConvTileInfo& convTileInfo, ConvIterInfo& iterInfo, | ||
| 765 | + LogicalTensorPtr& dstBL1TensorPtr, const ConvAttrParam& convAttrParam) | ||
| 766 | +{ | ||
| 767 | + std::vector<int64_t> dstBL1Shape; | ||
| 768 | + std::vector<int64_t> srcGmValidShape; | ||
| 769 | + int64_t srcCinOffset = 0; | ||
| 770 | + CalWeightL1Shapes(convTileInfo, iterInfo, convAttrParam, dstBL1Shape, srcGmValidShape, srcCinOffset); | ||
| 771 | + | ||
| 728 | dstBL1TensorPtr = std::make_shared<LogicalTensor>(function, tensorGraphNodes.weightTensorPtr->Datatype(), | 772 | dstBL1TensorPtr = std::make_shared<LogicalTensor>(function, tensorGraphNodes.weightTensorPtr->Datatype(), |
| 729 | dstBL1Shape, SymbolicScalar::FromConcrete(dstBL1Shape), | 773 | dstBL1Shape, SymbolicScalar::FromConcrete(dstBL1Shape), |
| 730 | tensorGraphNodes.weightTensorPtr->Format(), "bL1Tensor"); | 774 | tensorGraphNodes.weightTensorPtr->Format(), "bL1Tensor"); |
| @@ -883,25 +927,11 @@ std::vector<int64_t> GetCopyOutDstOffset(const ConvAttrParam& convAttrParam, con | |||
| 883 | return dstResGmOffset; | 927 | return dstResGmOffset; |
| 884 | } | 928 | } |
| 885 | 929 | ||
| 886 | -void ConstrucCopyOutTile(Function& function, const ConvAttrParam& convAttrParam, const ConvGraphNodes& tensorGraphNodes, | 930 | +static void CalL0CTileResShape(const ConvAttrParam& convAttrParam, const ConvTileInfo& convTileInfo, |
| 887 | - const ConvTileInfo& convTileInfo, const ConvIterInfo& iterInfo, | 931 | + const ConvIterInfo& iterInfo, int64_t curH, int64_t curW, bool isArch32, |
| 888 | - const LogicalTensorPtr& resCl0TensorPtr) | 932 | + std::vector<SymbolicScalar>& dstCL0DynValidShape, std::vector<int64_t>& l0CTileResShape, |
| 933 | + std::vector<SymbolicScalar>& l0CTileResDynValidShape) | ||
| 889 | { | 934 | { |
| 890 | - std::vector<SymbolicScalar> dstCL0DynValidShape = std::vector<SymbolicScalar>{ | ||
| 891 | - convTileInfo.dynValidBatchL0 * convTileInfo.dynValidDoutL0 * convTileInfo.dynValidHoutL0 * | ||
| 892 | - convTileInfo.dynValidWoutL0, | ||
| 893 | - convTileInfo.dynValidCoutL0}; | ||
| 894 | - bool isArch32 = IsArch32Platform(); | ||
| 895 | - | ||
| 896 | - resCl0TensorPtr->UpdateDynValidShape(dstCL0DynValidShape); | ||
| 897 | - | ||
| 898 | - int64_t cutW = std::min(iterInfo.woutL1Size - iterInfo.wL0Offset, convTileInfo.wL0); | ||
| 899 | - int64_t copyOutMode = static_cast<int64_t>(isArch32 ? CopyOutMode::COPY_MOD_NZ2NZ : CopyOutMode::COPY_MOD_NZ2DN); | ||
| 900 | - std::vector<int64_t> dstResGmOffset = GetCopyOutDstOffset(convAttrParam, convTileInfo, iterInfo); | ||
| 901 | - int64_t curH = std::min(convTileInfo.hL0, iterInfo.houtL1Size - iterInfo.hL0Offset); | ||
| 902 | - int64_t curW = std::min(convTileInfo.wL0, iterInfo.woutL1Size - iterInfo.wL0Offset); | ||
| 903 | - std::vector<int64_t> l0CTileResShape; | ||
| 904 | - std::vector<SymbolicScalar> l0CTileResDynValidShape; | ||
| 905 | if (isArch32) { | 935 | if (isArch32) { |
| 906 | dstCL0DynValidShape = { | 936 | dstCL0DynValidShape = { |
| 907 | convTileInfo.dynValidBatchL0 * convTileInfo.dynValidDoutL0 * convTileInfo.dynValidHoutL0 * | 937 | convTileInfo.dynValidBatchL0 * convTileInfo.dynValidDoutL0 * convTileInfo.dynValidHoutL0 * |
| @@ -937,6 +967,29 @@ void ConstrucCopyOutTile(Function& function, const ConvAttrParam& convAttrParam, | |||
| 937 | convTileInfo.dynValidBatchL0, convTileInfo.dynValidCoutL0, | 967 | convTileInfo.dynValidBatchL0, convTileInfo.dynValidCoutL0, |
| 938 | convTileInfo.dynValidHoutL0, convTileInfo.dynValidWoutL0}; | 968 | convTileInfo.dynValidHoutL0, convTileInfo.dynValidWoutL0}; |
| 939 | } | 969 | } |
| 970 | +} | ||
| 971 | + | ||
| 972 | +void ConstrucCopyOutTile(Function& function, const ConvAttrParam& convAttrParam, const ConvGraphNodes& tensorGraphNodes, | ||
| 973 | + const ConvTileInfo& convTileInfo, const ConvIterInfo& iterInfo, | ||
| 974 | + const LogicalTensorPtr& resCl0TensorPtr) | ||
| 975 | +{ | ||
| 976 | + std::vector<SymbolicScalar> dstCL0DynValidShape = std::vector<SymbolicScalar>{ | ||
| 977 | + convTileInfo.dynValidBatchL0 * convTileInfo.dynValidDoutL0 * convTileInfo.dynValidHoutL0 * | ||
| 978 | + convTileInfo.dynValidWoutL0, | ||
| 979 | + convTileInfo.dynValidCoutL0}; | ||
| 980 | + bool isArch32 = IsArch32Platform(); | ||
| 981 | + | ||
| 982 | + resCl0TensorPtr->UpdateDynValidShape(dstCL0DynValidShape); | ||
| 983 | + | ||
| 984 | + int64_t cutW = std::min(iterInfo.woutL1Size - iterInfo.wL0Offset, convTileInfo.wL0); | ||
| 985 | + int64_t copyOutMode = static_cast<int64_t>(isArch32 ? CopyOutMode::COPY_MOD_NZ2NZ : CopyOutMode::COPY_MOD_NZ2DN); | ||
| 986 | + std::vector<int64_t> dstResGmOffset = GetCopyOutDstOffset(convAttrParam, convTileInfo, iterInfo); | ||
| 987 | + int64_t curH = std::min(convTileInfo.hL0, iterInfo.houtL1Size - iterInfo.hL0Offset); | ||
| 988 | + int64_t curW = std::min(convTileInfo.wL0, iterInfo.woutL1Size - iterInfo.wL0Offset); | ||
| 989 | + std::vector<int64_t> l0CTileResShape; | ||
| 990 | + std::vector<SymbolicScalar> l0CTileResDynValidShape; | ||
| 991 | + CalL0CTileResShape(convAttrParam, convTileInfo, iterInfo, curH, curW, isArch32, dstCL0DynValidShape, | ||
| 992 | + l0CTileResShape, l0CTileResDynValidShape); | ||
| 940 | auto resRawShape = tensorGraphNodes.resTensorPtr->tensor->GetRawShape(); | 993 | auto resRawShape = tensorGraphNodes.resTensorPtr->tensor->GetRawShape(); |
| 941 | auto resDynRawShape = tensorGraphNodes.resTensorPtr->tensor->GetDynRawShape(); | 994 | auto resDynRawShape = tensorGraphNodes.resTensorPtr->tensor->GetDynRawShape(); |
| 942 | 995 | ||
| @@ -94,8 +94,53 @@ INLINE void TLoadConv2DNZ2NZ(T& dst, U& src, const OffsetInfo& offsetInfo, const | |||
| 94 | * offset4: fmap -> W, weight -> 0 | 94 | * offset4: fmap -> W, weight -> 0 |
| 95 | * isFmap: true -> fmap, false -> weight | 95 | * isFmap: true -> fmap, false -> weight |
| 96 | */ | 96 | */ |
| 97 | -template <bool isFmap, typename T, typename U> | 97 | +/** |
| 98 | -INLINE void TLoadConv3DNZ2NZ(T& dst, U& src, const OffsetInfo& offsetInfo, const ShapeInfo& srcShapeInfo) | 98 | + * Copy conv3d fmap data from DDR to L1 with NZ2NZ (NDC1HWC0) |
| 99 | + */ | ||
| 100 | +template <typename T, typename U> | ||
| 101 | +INLINE void TLoadConv3DFmapNZ2NZ(T& dst, U& src, const OffsetInfo& offsetInfo, const ShapeInfo& srcShapeInfo) | ||
| 102 | +{ | ||
| 103 | + constexpr int64_t c0Size = BLOCK_ALIGN_BYTE / sizeof(typename U::Type); | ||
| 104 | + constexpr auto stcDstShape0 = Std::tuple_element<CONV_IDX_0, typename T::TileShape>::type::value; | ||
| 105 | + constexpr auto stcDstShape1 = Std::tuple_element<CONV_IDX_1, typename T::TileShape>::type::value; | ||
| 106 | + constexpr auto stcDstShape2 = Std::tuple_element<CONV_IDX_2, typename T::TileShape>::type::value; | ||
| 107 | + constexpr auto stcDstShape3 = Std::tuple_element<CONV_IDX_3, typename T::TileShape>::type::value; | ||
| 108 | + constexpr auto stcDstShape4 = Std::tuple_element<CONV_IDX_4, typename T::TileShape>::type::value; | ||
| 109 | + int64_t dstShape0 = GetConvShape<CONV_IDX_0>(dst); | ||
| 110 | + int64_t dstShape1 = GetConvShape<CONV_IDX_1>(dst); | ||
| 111 | + int64_t dstShape2 = GetConvShape<CONV_IDX_2>(dst); | ||
| 112 | + int64_t dstShape3 = GetConvShape<CONV_IDX_3>(dst); | ||
| 113 | + int64_t dstShape4 = GetConvShape<CONV_IDX_4>(dst); | ||
| 114 | + int64_t srcStride0 = GetConvStride<CONV_IDX_0>(src); | ||
| 115 | + int64_t srcStride1 = GetConvStride<CONV_IDX_1>(src); | ||
| 116 | + int64_t srcStride2 = GetConvStride<CONV_IDX_2>(src); | ||
| 117 | + int64_t srcStride3 = GetConvStride<CONV_IDX_3>(src); | ||
| 118 | + int64_t srcStride4 = GetConvStride<CONV_IDX_4>(src); | ||
| 119 | + int64_t gmOffset = offsetInfo.offset0 * srcStride0 + offsetInfo.offset1 * srcStride1 + | ||
| 120 | + offsetInfo.offset2 * srcStride2 + offsetInfo.offset3 * srcStride3 + | ||
| 121 | + offsetInfo.offset4 * srcStride4; | ||
| 122 | + // Shape: N=1, D, C1, H, W, C0(由于Shape只支持5维,且C0可以根据dtype计算得出,所以这里不配置C0) | ||
| 123 | + using shapeDim = pto::Shape<1, -1, -1, -1, -1>; | ||
| 124 | + using strideDim = pto::Stride<-1, -1, -1, -1, -1>; | ||
| 125 | + using globalData = pto::GlobalTensor<typename U::Type, shapeDim, strideDim, pto::Layout::NDC1HWC0>; | ||
| 126 | + globalData srcGlobal((__gm__ typename U::Type*)(src.GetAddr() + gmOffset), | ||
| 127 | + shapeDim(srcShapeInfo.shape1, srcShapeInfo.shape2, srcShapeInfo.shape3, srcShapeInfo.shape4), | ||
| 128 | + strideDim(srcStride0, srcStride1, srcStride2, srcStride3, srcStride4)); | ||
| 129 | + | ||
| 130 | + constexpr auto bufferSize = stcDstShape0 * stcDstShape1 * stcDstShape2 * stcDstShape3 * stcDstShape4 * | ||
| 131 | + BLOCK_ALIGN_BYTE; | ||
| 132 | + using tileData = pto::ConvTile<pto::TileType::Mat, typename T::Type, bufferSize, pto::Layout::NDC1HWC0, | ||
| 133 | + pto::ConvTileShape<-1, -1, -1, -1, -1, c0Size>>; | ||
| 134 | + tileData dstL1(dstShape0, dstShape1, dstShape2, dstShape3, dstShape4); | ||
| 135 | + pto::TASSIGN(dstL1, (uint64_t)dst.GetAddr()); | ||
| 136 | + pto::TLOAD(dstL1, srcGlobal); | ||
| 137 | +} | ||
| 138 | + | ||
| 139 | +/** | ||
| 140 | + * Copy conv3d weight data from DDR to L1 with NZ2NZ (FractalZ_3D) | ||
| 141 | + */ | ||
| 142 | +template <typename T, typename U> | ||
| 143 | +INLINE void TLoadConv3DWeightNZ2NZ(T& dst, U& src, const OffsetInfo& offsetInfo, const ShapeInfo& srcShapeInfo) | ||
| 99 | { | 144 | { |
| 100 | constexpr int64_t c0Size = BLOCK_ALIGN_BYTE / sizeof(typename U::Type); | 145 | constexpr int64_t c0Size = BLOCK_ALIGN_BYTE / sizeof(typename U::Type); |
| 101 | constexpr auto stcDstShape0 = Std::tuple_element<CONV_IDX_0, typename T::TileShape>::type::value; | 146 | constexpr auto stcDstShape0 = Std::tuple_element<CONV_IDX_0, typename T::TileShape>::type::value; |
| @@ -107,48 +152,29 @@ INLINE void TLoadConv3DNZ2NZ(T& dst, U& src, const OffsetInfo& offsetInfo, const | |||
| 107 | int64_t srcStride1 = GetConvStride<CONV_IDX_1>(src); | 152 | int64_t srcStride1 = GetConvStride<CONV_IDX_1>(src); |
| 108 | int64_t srcStride2 = GetConvStride<CONV_IDX_2>(src); | 153 | int64_t srcStride2 = GetConvStride<CONV_IDX_2>(src); |
| 109 | int64_t srcStride3 = GetConvStride<CONV_IDX_3>(src); | 154 | int64_t srcStride3 = GetConvStride<CONV_IDX_3>(src); |
| 155 | + int64_t gmOffset = offsetInfo.offset0 * srcStride0 + offsetInfo.offset1 * srcStride1; | ||
| 156 | + // Shape: 1(占位), dc1hw, cout1, n0=16, c0 | ||
| 157 | + using shapeDim = pto::Shape<1, -1, -1, MKN_N_VALUE, c0Size>; | ||
| 158 | + using strideDim = pto::Stride<1, -1, -1, -1, -1>; | ||
| 159 | + using globalData = pto::GlobalTensor<typename U::Type, shapeDim, strideDim, pto::Layout::FRACTAL_Z_3D>; | ||
| 160 | + globalData srcGlobal((__gm__ typename U::Type*)(src.GetAddr() + gmOffset), | ||
| 161 | + shapeDim(srcShapeInfo.shape0, srcShapeInfo.shape1), | ||
| 162 | + strideDim(srcStride0, srcStride1, srcStride2, srcStride3)); | ||
| 163 | + constexpr auto bufferSize = stcDstShape0 * stcDstShape1 * stcDstShape2 * BLOCK_ALIGN_BYTE; | ||
| 164 | + using tileData = pto::ConvTile<pto::TileType::Mat, typename T::Type, bufferSize, pto::Layout::FRACTAL_Z_3D, | ||
| 165 | + pto::ConvTileShape<-1, -1, MKN_N_VALUE, c0Size>>; | ||
| 166 | + tileData dstL1(dstShape0, dstShape1); | ||
| 167 | + pto::TASSIGN(dstL1, (uint64_t)dst.GetAddr()); | ||
| 168 | + pto::TLOAD(dstL1, srcGlobal); | ||
| 169 | +} | ||
| 110 | 170 | ||
| 171 | +template <bool isFmap, typename T, typename U> | ||
| 172 | +INLINE void TLoadConv3DNZ2NZ(T& dst, U& src, const OffsetInfo& offsetInfo, const ShapeInfo& srcShapeInfo) | ||
| 173 | +{ | ||
| 111 | if constexpr (isFmap) { | 174 | if constexpr (isFmap) { |
| 112 | - constexpr auto stcDstShape3 = Std::tuple_element<CONV_IDX_3, typename T::TileShape>::type::value; | 175 | + TLoadConv3DFmapNZ2NZ(dst, src, offsetInfo, srcShapeInfo); |
| 113 | - constexpr auto stcDstShape4 = Std::tuple_element<CONV_IDX_4, typename T::TileShape>::type::value; | ||
| 114 | - int64_t dstShape2 = GetConvShape<CONV_IDX_2>(dst); | ||
| 115 | - int64_t dstShape3 = GetConvShape<CONV_IDX_3>(dst); | ||
| 116 | - int64_t dstShape4 = GetConvShape<CONV_IDX_4>(dst); | ||
| 117 | - int64_t srcStride4 = GetConvStride<CONV_IDX_4>(src); | ||
| 118 | - int64_t gmOffset = offsetInfo.offset0 * srcStride0 + offsetInfo.offset1 * srcStride1 + | ||
| 119 | - offsetInfo.offset2 * srcStride2 + offsetInfo.offset3 * srcStride3 + | ||
| 120 | - offsetInfo.offset4 * srcStride4; | ||
| 121 | - // Shape: N=1, D, C1, H, W, C0(由于Shape只支持5维,且C0可以根据dtype计算得出,所以这里不配置C0) | ||
| 122 | - using shapeDim = pto::Shape<1, -1, -1, -1, -1>; | ||
| 123 | - using strideDim = pto::Stride<-1, -1, -1, -1, -1>; | ||
| 124 | - using globalData = pto::GlobalTensor<typename U::Type, shapeDim, strideDim, pto::Layout::NDC1HWC0>; | ||
| 125 | - globalData srcGlobal( | ||
| 126 | - (__gm__ typename U::Type*)(src.GetAddr() + gmOffset), | ||
| 127 | - shapeDim(srcShapeInfo.shape1, srcShapeInfo.shape2, srcShapeInfo.shape3, srcShapeInfo.shape4), | ||
| 128 | - strideDim(srcStride0, srcStride1, srcStride2, srcStride3, srcStride4)); | ||
| 129 | - | ||
| 130 | - constexpr auto bufferSize = stcDstShape0 * stcDstShape1 * stcDstShape2 * stcDstShape3 * stcDstShape4 * | ||
| 131 | - BLOCK_ALIGN_BYTE; | ||
| 132 | - using tileData = pto::ConvTile<pto::TileType::Mat, typename T::Type, bufferSize, pto::Layout::NDC1HWC0, | ||
| 133 | - pto::ConvTileShape<-1, -1, -1, -1, -1, c0Size>>; | ||
| 134 | - tileData dstL1(dstShape0, dstShape1, dstShape2, dstShape3, dstShape4); | ||
| 135 | - pto::TASSIGN(dstL1, (uint64_t)dst.GetAddr()); | ||
| 136 | - pto::TLOAD(dstL1, srcGlobal); | ||
| 137 | } else { | 176 | } else { |
| 138 | - int64_t gmOffset = offsetInfo.offset0 * srcStride0 + offsetInfo.offset1 * srcStride1; | 177 | + TLoadConv3DWeightNZ2NZ(dst, src, offsetInfo, srcShapeInfo); |
| 139 | - // Shape: 1(占位), dc1hw, cout1, n0=16, c0 | ||
| 140 | - using shapeDim = pto::Shape<1, -1, -1, MKN_N_VALUE, c0Size>; | ||
| 141 | - using strideDim = pto::Stride<1, -1, -1, -1, -1>; | ||
| 142 | - using globalData = pto::GlobalTensor<typename U::Type, shapeDim, strideDim, pto::Layout::FRACTAL_Z_3D>; | ||
| 143 | - globalData srcGlobal((__gm__ typename U::Type*)(src.GetAddr() + gmOffset), | ||
| 144 | - shapeDim(srcShapeInfo.shape0, srcShapeInfo.shape1), | ||
| 145 | - strideDim(srcStride0, srcStride1, srcStride2, srcStride3)); | ||
| 146 | - constexpr auto bufferSize = stcDstShape0 * stcDstShape1 * stcDstShape2 * BLOCK_ALIGN_BYTE; | ||
| 147 | - using tileData = pto::ConvTile<pto::TileType::Mat, typename T::Type, bufferSize, pto::Layout::FRACTAL_Z_3D, | ||
| 148 | - pto::ConvTileShape<-1, -1, MKN_N_VALUE, c0Size>>; | ||
| 149 | - tileData dstL1(dstShape0, dstShape1); | ||
| 150 | - pto::TASSIGN(dstL1, (uint64_t)dst.GetAddr()); | ||
| 151 | - pto::TLOAD(dstL1, srcGlobal); | ||
| 152 | } | 178 | } |
| 153 | } | 179 | } |
| 154 | 180 | ||