Merged
fix(Pass): Revise the tile expansion logic of index_add #1898
CatherieAdd on Mar 23
fix(Pass): Revise the tile expansion logic of index_add #1898
Merged
Merged fromCatherie/pyptomy_index_addintocann/pyptomaster
Total: 1 files changed+33-18
| @@ -122,8 +122,12 @@ void IndexAddExpandFunc(Function &function, const IndexAddPara indexaddPara, Ind | |||
| 122 | } | 122 | } |
| 123 | } | 123 | } |
| 124 | 124 | ||
| 125 | -void InnerTiledIndexAdd(size_t cur, Function &function, const TileShape &tileShape, const IndexAddPara indexaddPara, | 125 | +void InnerTiledIndexAdd(size_t cur, |
| 126 | + Function &function, | ||
| 127 | + const TileShape &tileShape, | ||
| 128 | + const IndexAddPara indexaddPara, | ||
| 126 | IndexAddTileInfoPara &indexaddTileInfo) { | 129 | IndexAddTileInfoPara &indexaddTileInfo) { |
| 130 | + | ||
| 127 | if (cur == indexaddPara.dstTensor->shape.size()) { | 131 | if (cur == indexaddPara.dstTensor->shape.size()) { |
| 128 | IndexAddExpandFunc(function, indexaddPara, indexaddTileInfo); | 132 | IndexAddExpandFunc(function, indexaddPara, indexaddTileInfo); |
| 129 | return; | 133 | return; |
| @@ -131,26 +135,37 @@ void InnerTiledIndexAdd(size_t cur, Function &function, const TileShape &tileSha | |||
| 131 | 135 | ||
| 132 | auto &vecTile = tileShape.GetVecTile(); | 136 | auto &vecTile = tileShape.GetVecTile(); |
| 133 | int64_t tmpTile = vecTile[cur]; | 137 | int64_t tmpTile = vecTile[cur]; |
| 134 | - // axis所在轴按照dstShape[axis]进行切分 | 138 | + |
| 139 | + // axis 维度不参与切分,也不循环 | ||
| 135 | if (static_cast<int>(cur) == indexaddPara.axis) { | 140 | if (static_cast<int>(cur) == indexaddPara.axis) { |
| 136 | - tmpTile = indexaddPara.dstTensor->GetShape()[cur]; | 141 | + indexaddTileInfo.dstTileInfo.offset[cur] = 0; |
| 142 | + indexaddTileInfo.dstTileInfo.shape[cur] = indexaddPara.dstTensor->GetShape()[cur]; | ||
| 143 | + | ||
| 144 | + indexaddTileInfo.selfTileInfo.offset[cur] = 0; | ||
| 145 | + indexaddTileInfo.selfTileInfo.shape[cur] = indexaddPara.selfInput->GetShape()[cur]; | ||
| 146 | + | ||
| 147 | + indexaddTileInfo.srcTileInfo.offset[cur] = 0; | ||
| 148 | + indexaddTileInfo.srcTileInfo.shape[cur] = indexaddPara.srcInput->GetShape()[cur]; | ||
| 149 | + | ||
| 150 | + InnerTiledIndexAdd(cur + 1, function, tileShape, indexaddPara, indexaddTileInfo); | ||
| 151 | + return; | ||
| 137 | } | 152 | } |
| 138 | - // srcInput在axis的维度=indicesInput的维度,且可能比selfInput.shape[axis]大 | 153 | + |
| 139 | - for (int i = 0; i < indexaddPara.srcInput->GetShape()[cur]; i += tmpTile) { | 154 | + // 非 axis 维度正常切分 |
| 140 | - if (static_cast<int>(cur) == indexaddPara.axis) { | 155 | + for (int64_t i = 0; i < indexaddPara.srcInput->GetShape()[cur]; i += tmpTile) { |
| 141 | - // self和dst不切 | 156 | + |
| 142 | - indexaddTileInfo.dstTileInfo.offset[cur] = 0; | 157 | + indexaddTileInfo.dstTileInfo.offset[cur] = i; |
| 143 | - indexaddTileInfo.dstTileInfo.shape[cur] = indexaddPara.dstTensor->shape[cur]; | 158 | + indexaddTileInfo.dstTileInfo.shape[cur] = |
| 144 | - indexaddTileInfo.selfTileInfo.offset[cur] = 0; | 159 | + std::min(indexaddPara.dstTensor->GetShape()[cur] - i, tmpTile); |
| 145 | - indexaddTileInfo.selfTileInfo.shape[cur] = indexaddPara.selfInput->shape[cur]; | 160 | + |
| 146 | - } else { | 161 | + indexaddTileInfo.selfTileInfo.offset[cur] = i; |
| 147 | - indexaddTileInfo.dstTileInfo.offset[cur] = i; | 162 | + indexaddTileInfo.selfTileInfo.shape[cur] = |
| 148 | - indexaddTileInfo.dstTileInfo.shape[cur] = std::min(indexaddPara.dstTensor->shape[cur] - i, tmpTile); | 163 | + std::min(indexaddPara.selfInput->GetShape()[cur] - i, tmpTile); |
| 149 | - indexaddTileInfo.selfTileInfo.offset[cur] = i; | 164 | + |
| 150 | - indexaddTileInfo.selfTileInfo.shape[cur] = std::min(indexaddPara.selfInput->shape[cur] - i, tmpTile); | ||
| 151 | - } | ||
| 152 | indexaddTileInfo.srcTileInfo.offset[cur] = i; | 165 | indexaddTileInfo.srcTileInfo.offset[cur] = i; |
| 153 | - indexaddTileInfo.srcTileInfo.shape[cur] = std::min(indexaddPara.srcInput->GetShape()[cur] - i, tmpTile); | 166 | + indexaddTileInfo.srcTileInfo.shape[cur] = |
| 167 | + std::min(indexaddPara.srcInput->GetShape()[cur] - i, tmpTile); | ||
| 168 | + | ||
| 154 | InnerTiledIndexAdd(cur + 1, function, tileShape, indexaddPara, indexaddTileInfo); | 169 | InnerTiledIndexAdd(cur + 1, function, tileShape, indexaddPara, indexaddTileInfo); |
| 155 | } | 170 | } |
| 156 | } | 171 | } |