Merged
fix(operation): Fix Remainder Temp Workspace #6345
刘奕哲Add on Sep 15
fix(operation): Fix Remainder Temp Workspace #6345
Merged
刘奕哲Add on Sep 15
Total: 4 files changed+8-4
@@ -68,6 +68,9 @@ remainder(
68 <!-- npu="910b" id9 -->68 <!-- npu="910b" id9 -->
69 - Atlas A2 训练系列产品/Atlas A2 推理系列产品:DT_FP32,DT_FP16,DT_BF16,DT_INT32,DT_INT16。69 - Atlas A2 训练系列产品/Atlas A2 推理系列产品:DT_FP32,DT_FP16,DT_BF16,DT_INT32,DT_INT16。
70 <!-- end id9 -->70 <!-- end id9 -->
71+7. 由于存在临时内存使用,设置TileShape时需保证输入Tile、输出Tile及临时空间的总占用小于可用UB。记TileShape的最后两维为H和W(一维TileShape取H为1),记align为256/sizeof\(output\),W对齐到align记为WAlign:
72+ - 若input和other均为Tensor,则使用临时空间大小为`(WAlign + CeilAlign(WAlign / 8, 256) / sizeof(output) + 256) * sizeof(output)`字节
73+ - 若input和other之一不为Tensor,则使用临时空间大小为`(H + 1) * (WAlign + CeilAlign(WAlign / 8, 256) / sizeof(output) + 256) * sizeof(output)`字节
71 74 
72## 调用示例75## 调用示例
73 76 
@@ -55,6 +55,7 @@ constexpr int32_t NUM_VALUE_32 = 32;
55constexpr int32_t NUM_VALUE_46 = 46;55constexpr int32_t NUM_VALUE_46 = 46;
56constexpr int32_t NUM_VALUE_64 = 64;56constexpr int32_t NUM_VALUE_64 = 64;
57constexpr int32_t NUM_VALUE_128 = 128;57constexpr int32_t NUM_VALUE_128 = 128;
58+constexpr int32_t NUM_VALUE_256 = 256;
58constexpr double NUM_VALUE_0_5 = 0.5;59constexpr double NUM_VALUE_0_5 = 0.5;
59constexpr double NUM_VALUE_EPS = 1e-9;60constexpr double NUM_VALUE_EPS = 1e-9;
60 61 
@@ -258,10 +258,10 @@ void TiledRemainderSOperation(Function& function, const TileShape& tileShape, si
258 auto inputTile1 = input1.tensor->View(function, input1.tileInfo.shape, input1.tileInfo.offset);258 auto inputTile1 = input1.tensor->View(function, input1.tileInfo.shape, input1.tileInfo.offset);
259 auto resultTile = result->View(function, resultTileInfo.shape, resultTileInfo.offset);259 auto resultTile = result->View(function, resultTileInfo.shape, resultTileInfo.offset);
260 int64_t shapeSize = resultTileInfo.shape.size();260 int64_t shapeSize = resultTileInfo.shape.size();
261- int64_t alignSize = static_cast<int64_t>(BLOCK_SIZE / BytesOf(result->Datatype()));261+ int64_t alignSize = static_cast<int64_t>(NUM_VALUE_256 / BytesOf(result->Datatype()));
262 int64_t alignedLast = AlignUp(resultTileInfo.shape[shapeSize - 1], alignSize);262 int64_t alignedLast = AlignUp(resultTileInfo.shape[shapeSize - 1], alignSize);
263 int64_t maskBytes = (alignedLast + NUM_VALUE_8 - 1) / NUM_VALUE_8;263 int64_t maskBytes = (alignedLast + NUM_VALUE_8 - 1) / NUM_VALUE_8;
264- int64_t maskFloats = AlignUp(maskBytes, BLOCK_SIZE) / static_cast<int64_t>(BytesOf(result->Datatype()));264+ int64_t maskFloats = AlignUp(maskBytes, NUM_VALUE_256) / static_cast<int64_t>(BytesOf(result->Datatype()));
265 int64_t tmpCols = alignedLast + maskFloats + alignSize;265 int64_t tmpCols = alignedLast + maskFloats + alignSize;
266 std::vector<int64_t> tmpShape{1, tmpCols};266 std::vector<int64_t> tmpShape{1, tmpCols};
267 if (opNameCode == Opcode::OP_REMRS) {267 if (opNameCode == Opcode::OP_REMRS) {
@@ -48,10 +48,10 @@ void AddTiledBinaryOperation(Function& function, const TileShape& tileShape, Log
48 op = &function.AddOperation(GetBinaryOpNameCode<T, false, false>(), {inputTile1, inputTile2},48 op = &function.AddOperation(GetBinaryOpNameCode<T, false, false>(), {inputTile1, inputTile2},
49 {resultTile, tempTensor});49 {resultTile, tempTensor});
50 } else if (opName == "REM") {50 } else if (opName == "REM") {
51- int64_t alignSize = static_cast<int64_t>(BLOCK_SIZE / BytesOf(result->Datatype()));51+ int64_t alignSize = static_cast<int64_t>(NUM_VALUE_256 / BytesOf(result->Datatype()));
52 int64_t alignedLast = AlignUp(resultTileInfo.shape[shapeSize - 1], alignSize);52 int64_t alignedLast = AlignUp(resultTileInfo.shape[shapeSize - 1], alignSize);
53 int64_t maskBytes = (alignedLast + NUM_VALUE_8 - 1) / NUM_VALUE_8;53 int64_t maskBytes = (alignedLast + NUM_VALUE_8 - 1) / NUM_VALUE_8;
54- int64_t maskFloats = AlignUp(maskBytes, BLOCK_SIZE) / static_cast<int64_t>(BytesOf(result->Datatype()));54+ int64_t maskFloats = AlignUp(maskBytes, NUM_VALUE_256) / static_cast<int64_t>(BytesOf(result->Datatype()));
55 int64_t tmpCols = alignedLast + maskFloats + alignSize;55 int64_t tmpCols = alignedLast + maskFloats + alignSize;
56 std::vector<int64_t> tmpShape{1, tmpCols};56 std::vector<int64_t> tmpShape{1, tmpCols};
57 auto tmpTensor = std::make_shared<LogicalTensor>(function, result->Datatype(), tmpShape);57 auto tmpTensor = std::make_shared<LogicalTensor>(function, result->Datatype(), tmpShape);