已合并
【bugfix】修复math仓cleancode #3925
majiajian_hw创建于 7月8日
【bugfix】修复math仓cleancode #3925
已合并
共 5 个文件变更+101-110
| @@ -19,26 +19,29 @@ | |||
| 19 | 19 | ||
| 20 | namespace optiling { | 20 | namespace optiling { |
| 21 | 21 | ||
| 22 | -constexpr uint32_t UB_BLOCK_SIZE = 32; // UB块大小 | 22 | +constexpr uint32_t UB_BLOCK_SIZE = 32; // UB块大小 |
| 23 | -constexpr uint32_t TRANS_BLOCK = 16; // 转置行数 | 23 | +constexpr uint32_t TRANS_BLOCK = 16; // 转置行数 |
| 24 | -constexpr uint32_t RESERVE_UB = 256; // 接口获取UB的预留空间 | 24 | +constexpr uint32_t RESERVE_UB = 256; // 接口获取UB的预留空间 |
| 25 | -constexpr uint32_t HALF = 2; // 半对齐/UB对半切分 | 25 | +constexpr uint32_t HALF = 2; // 半对齐/UB对半切分 |
| 26 | -constexpr uint32_t ONETHIRD = 3; // UB对三切分 | 26 | +constexpr uint32_t ONETHIRD = 3; // UB对三切分 |
| 27 | constexpr uint32_t DEFAUL_TILING_KEY = 0; // 默认tiling key | 27 | constexpr uint32_t DEFAUL_TILING_KEY = 0; // 默认tiling key |
| 28 | +constexpr uint32_t NUM_THIRTY_TWO = 32; | ||
| 28 | 29 | ||
| 29 | -static const std::set<ge::DataType> supportedDtype = | 30 | +static const std::set<ge::DataType> supportedDtype = {ge::DT_FLOAT, ge::DT_FLOAT16, ge::DT_BF16}; |
| 30 | - {ge::DT_FLOAT, ge::DT_FLOAT16, ge::DT_BF16}; | ||
| 31 | 31 | ||
| 32 | -std::string ChunkCatTiling::TilingDataToString() const { | 32 | +std::string ChunkCatTiling::TilingDataToString() const |
| 33 | +{ | ||
| 33 | return "blockRowNum = " + std::to_string(blockRowNum_) + ", blockColNum = " + std::to_string(blockColNum_) + | 34 | return "blockRowNum = " + std::to_string(blockRowNum_) + ", blockColNum = " + std::to_string(blockColNum_) + |
| 34 | - ", dim = " + std::to_string(dim_) + ", numChunk = " + std::to_string(numChunk_) + | 35 | + ", dim = " + std::to_string(dim_) + ", numChunk = " + std::to_string(numChunk_) + |
| 35 | - ", outputRow = " + std::to_string(outputRow_) + ", outputCol = " + std::to_string(outputCol_) + | 36 | + ", outputRow = " + std::to_string(outputRow_) + ", outputCol = " + std::to_string(outputCol_) + |
| 36 | - ", blockRowFactor = " + std::to_string(blockRowFactor_) + ", blockColFactor = " + std::to_string(blockColFactor_) + | 37 | + ", blockRowFactor = " + std::to_string(blockRowFactor_) + |
| 37 | - ", tailBlockRowFactor = " + std::to_string(tailBlockRowFactor_) + ", tailBlockColFactor = " + std::to_string(tailBlockColFactor_) + | 38 | + ", blockColFactor = " + std::to_string(blockColFactor_) + |
| 38 | - ", ubRowFactor = " + std::to_string(ubRowFactor_) + ", ubColFactor = " + std::to_string(ubColFactor_) + | 39 | + ", tailBlockRowFactor = " + std::to_string(tailBlockRowFactor_) + |
| 39 | - ", inputNum = " + std::to_string(inputNum_) + ", inUbSize = " + std::to_string(inUbSize_) + | 40 | + ", tailBlockColFactor = " + std::to_string(tailBlockColFactor_) + |
| 40 | - ", outUbSize = " + std::to_string(outUbSize_) + ", isAllAlign = " + std::to_string(isAllAlign_) + | 41 | + ", ubRowFactor = " + std::to_string(ubRowFactor_) + ", ubColFactor = " + std::to_string(ubColFactor_) + |
| 41 | - ", isHalfAlign = " + std::to_string(isHalfAlign_) + ", isOneConcat = " + std::to_string(isOneConcat_); | 42 | + ", inputNum = " + std::to_string(inputNum_) + ", inUbSize = " + std::to_string(inUbSize_) + |
| 43 | + ", outUbSize = " + std::to_string(outUbSize_) + ", isAllAlign = " + std::to_string(isAllAlign_) + | ||
| 44 | + ", isHalfAlign = " + std::to_string(isHalfAlign_) + ", isOneConcat = " + std::to_string(isOneConcat_); | ||
| 42 | } | 45 | } |
| 43 | 46 | ||
| 44 | // 获取硬件信息 | 47 | // 获取硬件信息 |
| @@ -83,8 +86,10 @@ ge::graphStatus ChunkCatTiling::GetInputInfo() | |||
| 83 | auto outputDesc = context_->GetOutputDesc(0); | 86 | auto outputDesc = context_->GetOutputDesc(0); |
| 84 | OP_CHECK_NULL_WITH_CONTEXT(context_, outputDesc); | 87 | OP_CHECK_NULL_WITH_CONTEXT(context_, outputDesc); |
| 85 | auto outputDataType = outputDesc->GetDataType(); | 88 | auto outputDataType = outputDesc->GetDataType(); |
| 86 | - OP_CHECK_IF(supportedDtype.count(inputDataType) == 0, OP_LOGE(context_, "input dtype is invalid"), return ge::GRAPH_FAILED); | 89 | + OP_CHECK_IF(supportedDtype.count(inputDataType) == 0, OP_LOGE(context_, "input dtype is invalid"), |
| 87 | - OP_CHECK_IF(supportedDtype.count(outputDataType) == 0, OP_LOGE(context_, "output dtype is invalid"), return ge::GRAPH_FAILED); | 90 | + return ge::GRAPH_FAILED); |
| 91 | + OP_CHECK_IF(supportedDtype.count(outputDataType) == 0, OP_LOGE(context_, "output dtype is invalid"), | ||
| 92 | + return ge::GRAPH_FAILED); | ||
| 88 | if (inputDataType == ge::DT_FLOAT && outputDataType != ge::DT_FLOAT) { | 93 | if (inputDataType == ge::DT_FLOAT && outputDataType != ge::DT_FLOAT) { |
| 89 | OP_LOGE(context_, "output dtype must be float when input dtype is float"); | 94 | OP_LOGE(context_, "output dtype must be float when input dtype is float"); |
| 90 | return ge::GRAPH_FAILED; | 95 | return ge::GRAPH_FAILED; |
| @@ -144,30 +149,30 @@ void ChunkCatTiling::DoUbSplit() | |||
| 144 | if (isRegBase) { | 149 | if (isRegBase) { |
| 145 | // 列切 | 150 | // 列切 |
| 146 | uint32_t colLimit = inUbSize_ / srcDtypeSize_; | 151 | uint32_t colLimit = inUbSize_ / srcDtypeSize_; |
| 147 | - colLimit = colLimit - 32 * srcEleUbBlock_; | 152 | + colLimit = colLimit - NUM_THIRTY_TWO * srcEleUbBlock_; |
| 148 | - int64_t ubColLoop = (outputCol_ + colLimit - 1) / colLimit ; | 153 | + int64_t ubColLoop = (outputCol_ + colLimit - 1) / colLimit; |
| 149 | ubColFactor_ = (outputCol_ + ubColLoop - 1) / ubColLoop; | 154 | ubColFactor_ = (outputCol_ + ubColLoop - 1) / ubColLoop; |
| 150 | ubColFactor_ = (ubColFactor_ + srcEleUbBlock_ - 1) / srcEleUbBlock_ * srcEleUbBlock_; | 155 | ubColFactor_ = (ubColFactor_ + srcEleUbBlock_ - 1) / srcEleUbBlock_ * srcEleUbBlock_; |
| 151 | ubColFactor_ = ubColFactor_ > colLimit ? colLimit : ubColFactor_; | 156 | ubColFactor_ = ubColFactor_ > colLimit ? colLimit : ubColFactor_; |
| 152 | // 行切 | 157 | // 行切 |
| 153 | uint32_t rowLimit = ubColLoop == 1 ? colLimit / ubColFactor_ : 1; | 158 | uint32_t rowLimit = ubColLoop == 1 ? colLimit / ubColFactor_ : 1; |
| 154 | - int64_t ubRowLoop = (outputRow_ + rowLimit - 1) / rowLimit ; | 159 | + int64_t ubRowLoop = (outputRow_ + rowLimit - 1) / rowLimit; |
| 155 | ubRowFactor_ = (outputRow_ + ubRowLoop - 1) / ubRowLoop; | 160 | ubRowFactor_ = (outputRow_ + ubRowLoop - 1) / ubRowLoop; |
| 156 | } else if (isAllAlign_ || isOneConcat_) { | 161 | } else if (isAllAlign_ || isOneConcat_) { |
| 157 | // 列切 | 162 | // 列切 |
| 158 | uint32_t colLimit = inUbSize_ / srcDtypeSize_; | 163 | uint32_t colLimit = inUbSize_ / srcDtypeSize_; |
| 159 | colLimit = (isOneConcat_) ? colLimit - 32 * (srcEleUbBlock_ - 1) : colLimit; | 164 | colLimit = (isOneConcat_) ? colLimit - 32 * (srcEleUbBlock_ - 1) : colLimit; |
| 160 | - int64_t ubColLoop = (outputCol_ + colLimit - 1) / colLimit ; | 165 | + int64_t ubColLoop = (outputCol_ + colLimit - 1) / colLimit; |
| 161 | ubColFactor_ = (outputCol_ + ubColLoop - 1) / ubColLoop; | 166 | ubColFactor_ = (outputCol_ + ubColLoop - 1) / ubColLoop; |
| 162 | ubColFactor_ = (ubColFactor_ + srcEleUbBlock_ - 1) / srcEleUbBlock_ * srcEleUbBlock_; | 167 | ubColFactor_ = (ubColFactor_ + srcEleUbBlock_ - 1) / srcEleUbBlock_ * srcEleUbBlock_; |
| 163 | ubColFactor_ = ubColFactor_ > colLimit ? colLimit : ubColFactor_; | 168 | ubColFactor_ = ubColFactor_ > colLimit ? colLimit : ubColFactor_; |
| 164 | // 行切 | 169 | // 行切 |
| 165 | uint32_t rowLimit = ubColLoop == 1 ? colLimit / ubColFactor_ : 1; | 170 | uint32_t rowLimit = ubColLoop == 1 ? colLimit / ubColFactor_ : 1; |
| 166 | - int64_t ubRowLoop = (outputRow_ + rowLimit - 1) / rowLimit ; | 171 | + int64_t ubRowLoop = (outputRow_ + rowLimit - 1) / rowLimit; |
| 167 | ubRowFactor_ = (outputRow_ + ubRowLoop - 1) / ubRowLoop; | 172 | ubRowFactor_ = (outputRow_ + ubRowLoop - 1) / ubRowLoop; |
| 168 | } else { | 173 | } else { |
| 169 | // 行切 | 174 | // 行切 |
| 170 | - uint32_t rowLimit = isHalfAlign_ ? TRANS_BLOCK * HALF: TRANS_BLOCK * srcEleUbBlock_; | 175 | + uint32_t rowLimit = isHalfAlign_ ? TRANS_BLOCK * HALF : TRANS_BLOCK * srcEleUbBlock_; |
| 171 | int64_t ubRowLoop = (outputRow_ + rowLimit - 1) / rowLimit; | 176 | int64_t ubRowLoop = (outputRow_ + rowLimit - 1) / rowLimit; |
| 172 | ubRowFactor_ = (outputRow_ + ubRowLoop - 1) / ubRowLoop; | 177 | ubRowFactor_ = (outputRow_ + ubRowLoop - 1) / ubRowLoop; |
| 173 | // 列切 | 178 | // 列切 |
| @@ -228,23 +233,19 @@ static ge::graphStatus Tiling4ChunkCat(gert::TilingContext* context) | |||
| 228 | { | 233 | { |
| 229 | OP_LOGD(context, "ChunkCatTiling"); | 234 | OP_LOGD(context, "ChunkCatTiling"); |
| 230 | ChunkCatTiling tiling(context); | 235 | ChunkCatTiling tiling(context); |
| 231 | - OP_CHECK_IF( | 236 | + OP_CHECK_IF(tiling.GetPlatformInfo() != ge::GRAPH_SUCCESS, OP_LOGE(context, "GetPlatformInfo error"), |
| 232 | - tiling.GetPlatformInfo() != ge::GRAPH_SUCCESS, OP_LOGE(context, "GetPlatformInfo error"), | 237 | + return ge::GRAPH_FAILED); |
| 233 | - return ge::GRAPH_FAILED); | 238 | + OP_CHECK_IF(tiling.GetInputInfo() != ge::GRAPH_SUCCESS, OP_LOGE(context, "GetInputInfo error"), |
| 234 | - OP_CHECK_IF( | 239 | + return ge::GRAPH_FAILED); |
| 235 | - tiling.GetInputInfo() != ge::GRAPH_SUCCESS, OP_LOGE(context, "GetInputInfo error"), | 240 | + OP_CHECK_IF(tiling.CalculateOutputInfo() != ge::GRAPH_SUCCESS, OP_LOGE(context, "CalculateOutputInfo error"), |
| 236 | - return ge::GRAPH_FAILED); | 241 | + return ge::GRAPH_FAILED); |
| 237 | - OP_CHECK_IF( | ||
| 238 | - tiling.CalculateOutputInfo() != ge::GRAPH_SUCCESS, OP_LOGE(context, "CalculateOutputInfo error"), | ||
| 239 | - return ge::GRAPH_FAILED); | ||
| 240 | tiling.DoUbSplit(); | 242 | tiling.DoUbSplit(); |
| 241 | tiling.DoBlockSplit(); | 243 | tiling.DoBlockSplit(); |
| 242 | - | 244 | + |
| 243 | ChunkCatTilingData* tilingData = context->GetTilingData<ChunkCatTilingData>(); | 245 | ChunkCatTilingData* tilingData = context->GetTilingData<ChunkCatTilingData>(); |
| 244 | OP_CHECK_NULL_WITH_CONTEXT(context, tilingData); | 246 | OP_CHECK_NULL_WITH_CONTEXT(context, tilingData); |
| 245 | - OP_CHECK_IF( | 247 | + OP_CHECK_IF(memset_s(tilingData, sizeof(ChunkCatTilingData), 0, sizeof(ChunkCatTilingData)) != EOK, |
| 246 | - memset_s(tilingData, sizeof(ChunkCatTilingData), 0, sizeof(ChunkCatTilingData)) != EOK, | 248 | + OP_LOGE(context, "set tiling data error"), return ge::GRAPH_FAILED); |
| 247 | - OP_LOGE(context, "set tiling data error"), return ge::GRAPH_FAILED); | ||
| 248 | tiling.SetTilingData(tilingData); | 249 | tiling.SetTilingData(tilingData); |
| 249 | OP_LOGD(context, "tiling data: %s", tiling.TilingDataToString().c_str()); | 250 | OP_LOGD(context, "tiling data: %s", tiling.TilingDataToString().c_str()); |
| 250 | return ge::GRAPH_SUCCESS; | 251 | return ge::GRAPH_SUCCESS; |
| @@ -255,7 +256,5 @@ static ge::graphStatus TilingPrepare4ChunkCat([[maybe_unused]] gert::TilingParse | |||
| 255 | return ge::GRAPH_SUCCESS; | 256 | return ge::GRAPH_SUCCESS; |
| 256 | } | 257 | } |
| 257 | 258 | ||
| 258 | -IMPL_OP_OPTILING(ChunkCat) | 259 | +IMPL_OP_OPTILING(ChunkCat).Tiling(Tiling4ChunkCat).TilingParse<ChunkCatCompileInfo>(TilingPrepare4ChunkCat); |
| 259 | - .Tiling(Tiling4ChunkCat) | ||
| 260 | - .TilingParse<ChunkCatCompileInfo>(TilingPrepare4ChunkCat); | ||
| 261 | } // namespace optiling | 260 | } // namespace optiling |
| @@ -40,7 +40,7 @@ public: | |||
| 40 | 40 | ||
| 41 | private: | 41 | private: |
| 42 | gert::TilingContext* context_; | 42 | gert::TilingContext* context_; |
| 43 | - bool isRegBase; | 43 | + bool isRegBase{false}; |
| 44 | int32_t coreNum_{0}; | 44 | int32_t coreNum_{0}; |
| 45 | uint64_t ubSize_{0}; | 45 | uint64_t ubSize_{0}; |
| 46 | uint64_t sysWorkspaceSize_{0}; | 46 | uint64_t sysWorkspaceSize_{0}; |
| @@ -186,7 +186,7 @@ static const aclTensor* normalDavidPath(const aclTensor* selfContiguous, int64_t | |||
| 186 | 186 | ||
| 187 | // 调用normal_算子kernel function(AI Cpu算子) | 187 | // 调用normal_算子kernel function(AI Cpu算子) |
| 188 | int64_t alg = 1; | 188 | int64_t alg = 1; |
| 189 | - auto algScalar = executor->AllocScalar((void*)&alg, DataType::DT_INT32); | 189 | + auto algScalar = executor->AllocScalar(reinterpret_cast<void*>(&alg), DataType::DT_INT32); |
| 190 | const aclTensor* algTensor = executor->ConvertToTensor(algScalar, op::ToOpDataType(ACL_INT32)); | 190 | const aclTensor* algTensor = executor->ConvertToTensor(algScalar, op::ToOpDataType(ACL_INT32)); |
| 191 | auto stateLessOut = l0op::StatelessRandomNormalV2(selfContiguous, keyArr, counterArr, algTensor, executor); | 191 | auto stateLessOut = l0op::StatelessRandomNormalV2(selfContiguous, keyArr, counterArr, algTensor, executor); |
| 192 | return normalDoublePath(selfContiguous, stateLessOut, mean, std, executor); | 192 | return normalDoublePath(selfContiguous, stateLessOut, mean, std, executor); |
| @@ -237,7 +237,7 @@ static const aclTensor* normalTensorDavidPath(const aclTensor* selfContiguous, c | |||
| 237 | CHECK_RET(resultAddOut != nullptr, nullptr); | 237 | CHECK_RET(resultAddOut != nullptr, nullptr); |
| 238 | 238 | ||
| 239 | int64_t alg = 1; | 239 | int64_t alg = 1; |
| 240 | - auto algScalar = executor->AllocScalar((void*)&alg, DataType::DT_INT32); | 240 | + auto algScalar = executor->AllocScalar(reinterpret_cast<void*>(&alg), DataType::DT_INT32); |
| 241 | const aclTensor* algTensor = executor->ConvertToTensor(algScalar, op::ToOpDataType(ACL_INT32)); | 241 | const aclTensor* algTensor = executor->ConvertToTensor(algScalar, op::ToOpDataType(ACL_INT32)); |
| 242 | auto stateLessOut = l0op::StatelessRandomNormalV2(selfContiguous, normalSeedU64, resultAddOut, algTensor, | 242 | auto stateLessOut = l0op::StatelessRandomNormalV2(selfContiguous, normalSeedU64, resultAddOut, algTensor, |
| 243 | executor); | 243 | executor); |
| @@ -131,18 +131,17 @@ ge::graphStatus SimThreadExponentialTiling::GetInputTensorInfo() | |||
| 131 | { | 131 | { |
| 132 | auto nodeName = context->GetNodeName(); | 132 | auto nodeName = context->GetNodeName(); |
| 133 | 133 | ||
| 134 | - OP_CHECK_IF( | 134 | + OP_CHECK_IF(count < 0, OP_LOGE(nodeName, "Count %ld must be greater than or equal to 0.", count), |
| 135 | - count < 0, OP_LOGE(nodeName, "Count %ld must be greater than or equal to 0.", count), return ge::GRAPH_FAILED); | 135 | + return ge::GRAPH_FAILED); |
| 136 | - OP_CHECK_IF( | 136 | + OP_CHECK_IF(threadPerProcessor <= 0, |
| 137 | - threadPerProcessor <= 0, OP_LOGE(nodeName, "ThreadPerProcessor %d must be greater than 0.", threadPerProcessor), | 137 | + OP_LOGE(nodeName, "ThreadPerProcessor %d must be greater than 0.", threadPerProcessor), |
| 138 | - return ge::GRAPH_FAILED); | 138 | + return ge::GRAPH_FAILED); |
| 139 | - OP_CHECK_IF( | 139 | + OP_CHECK_IF(streamProcessorCount <= 0, |
| 140 | - streamProcessorCount <= 0, | 140 | + OP_LOGE(nodeName, "StreamProcessorCount %d must be greater than 0.", streamProcessorCount), |
| 141 | - OP_LOGE(nodeName, "StreamProcessorCount %d must be greater than 0.", streamProcessorCount), | 141 | + return ge::GRAPH_FAILED); |
| 142 | - return ge::GRAPH_FAILED); | 142 | + OP_CHECK_IF(start > end, // 如何获取start、end? |
| 143 | - OP_CHECK_IF( | 143 | + OP_LOGE(nodeName, "Start %f must be less than or equal to end %f.", start, end), |
| 144 | - start > end, // 如何获取start、end? | 144 | + return ge::GRAPH_FAILED); |
| 145 | - OP_LOGE(nodeName, "Start %f must be less than or equal to end %f.", start, end), return ge::GRAPH_FAILED); | ||
| 146 | 145 | ||
| 147 | // 获取第一个输入gradOut的信息 | 146 | // 获取第一个输入gradOut的信息 |
| 148 | auto selfShapePtr = context->GetInputShape(INPUT_SELF_IDX); | 147 | auto selfShapePtr = context->GetInputShape(INPUT_SELF_IDX); |
| @@ -152,10 +151,9 @@ ge::graphStatus SimThreadExponentialTiling::GetInputTensorInfo() | |||
| 152 | for (size_t i = 0; i < selfShape.GetDimNum(); ++i) { | 151 | for (size_t i = 0; i < selfShape.GetDimNum(); ++i) { |
| 153 | usrWorkspaceSize *= selfShape[i]; | 152 | usrWorkspaceSize *= selfShape[i]; |
| 154 | } | 153 | } |
| 155 | - OP_CHECK_IF( | 154 | + OP_CHECK_IF(usrWorkspaceSize != count, |
| 156 | - usrWorkspaceSize != count, | 155 | + OP_LOGE(nodeName, "Count %ld must be equal to the product of the elements in selfShape.", count), |
| 157 | - OP_LOGE(nodeName, "Count %ld must be equal to the product of the elements in selfShape.", count), | 156 | + return ge::GRAPH_FAILED); |
| 158 | - return ge::GRAPH_FAILED); | ||
| 159 | usrWorkspaceSize = Ceil(usrWorkspaceSize, BATCHNUMPERHANDLE * BLOCKSIZE); | 157 | usrWorkspaceSize = Ceil(usrWorkspaceSize, BATCHNUMPERHANDLE * BLOCKSIZE); |
| 160 | usrWorkspaceSize *= FP32_TYPESIZE; | 158 | usrWorkspaceSize *= FP32_TYPESIZE; |
| 161 | 159 | ||
| @@ -163,9 +161,9 @@ ge::graphStatus SimThreadExponentialTiling::GetInputTensorInfo() | |||
| 163 | OP_CHECK_NULL_WITH_CONTEXT(context, selfDesc); | 161 | OP_CHECK_NULL_WITH_CONTEXT(context, selfDesc); |
| 164 | selfDType = selfDesc->GetDataType(); | 162 | selfDType = selfDesc->GetDataType(); |
| 165 | GetDataTypeKey(selfDType); | 163 | GetDataTypeKey(selfDType); |
| 166 | - OP_CHECK_IF( | 164 | + OP_CHECK_IF(GetDataTypeKey(selfDType) == false, |
| 167 | - GetDataTypeKey(selfDType) == false, | 165 | + OP_LOGE(nodeName, "The dtype of input self must be in [float32, float16, bfloat16]."), |
| 168 | - OP_LOGE(nodeName, "The dtype of input self must be in [float32, float16, bfloat16]."), return ge::GRAPH_FAILED); | 166 | + return ge::GRAPH_FAILED); |
| 169 | 167 | ||
| 170 | return ge::GRAPH_SUCCESS; | 168 | return ge::GRAPH_SUCCESS; |
| 171 | } | 169 | } |
| @@ -195,8 +193,10 @@ ge::graphStatus SimThreadExponentialTiling::Tiling4Block() | |||
| 195 | offset_t_high = static_cast<uint32_t>(offset_t >> SHIFT_LEFT_32); | 193 | offset_t_high = static_cast<uint32_t>(offset_t >> SHIFT_LEFT_32); |
| 196 | 194 | ||
| 197 | // 分核计算 | 195 | // 分核计算 |
| 198 | - useCoreNum = | 196 | + useCoreNum = static_cast<int64_t>( |
| 199 | - static_cast<int64_t>(Ops::Base::CeilDiv(batchNumTotal, Ops::Base::CeilDiv(batchNumTotal, totalCoreNum))); | 197 | + Ops::Base::CeilDiv(batchNumTotal, Ops::Base::CeilDiv(batchNumTotal, totalCoreNum))); |
| 198 | + OP_CHECK_IF(useCoreNum == 0, OP_LOGE(nodeName, "useCoreNum %u must be not equal to 0.", useCoreNum), | ||
| 199 | + return ge::GRAPH_FAILED); | ||
| 200 | // useCoreNum = static_cast<int64_t>(CeilDiv(batchNumTotal, CeilDiv(batchNumTotal, totalCoreNum))); | 200 | // useCoreNum = static_cast<int64_t>(CeilDiv(batchNumTotal, CeilDiv(batchNumTotal, totalCoreNum))); |
| 201 | batchNumPerCore = (batchNumTotal + useCoreNum - 1) / useCoreNum; | 201 | batchNumPerCore = (batchNumTotal + useCoreNum - 1) / useCoreNum; |
| 202 | batchNumTailCore = batchNumTotal - (useCoreNum - 1) * batchNumPerCore; | 202 | batchNumTailCore = batchNumTotal - (useCoreNum - 1) * batchNumPerCore; |
| @@ -204,9 +204,8 @@ ge::graphStatus SimThreadExponentialTiling::Tiling4Block() | |||
| 204 | handleNumLoop = batchNumPerCore / BATCHNUMPERHANDLE; | 204 | handleNumLoop = batchNumPerCore / BATCHNUMPERHANDLE; |
| 205 | handleNumTail = batchNumPerCore - handleNumLoop * BATCHNUMPERHANDLE; | 205 | handleNumTail = batchNumPerCore - handleNumLoop * BATCHNUMPERHANDLE; |
| 206 | 206 | ||
| 207 | - OP_CHECK_IF( | 207 | + OP_CHECK_IF(batchNumPerCore <= 0, OP_LOGE(nodeName, "batchNumPerCore %u must be greater than 0.", batchNumPerCore), |
| 208 | - batchNumPerCore <= 0, OP_LOGE(nodeName, "batchNumPerCore %u must be greater than 0.", batchNumPerCore), | 208 | + return ge::GRAPH_FAILED); |
| 209 | - return ge::GRAPH_FAILED); | ||
| 210 | 209 | ||
| 211 | return ge::GRAPH_SUCCESS; | 210 | return ge::GRAPH_SUCCESS; |
| 212 | } | 211 | } |
| @@ -223,10 +222,9 @@ ge::graphStatus SimThreadExponentialTiling::SetAttrParams() | |||
| 223 | const float* lambdaPtr = attrs->GetAttrPointer<float>(ATTR_1); | 222 | const float* lambdaPtr = attrs->GetAttrPointer<float>(ATTR_1); |
| 224 | OP_CHECK_NULL_WITH_CONTEXT(context, lambdaPtr); | 223 | OP_CHECK_NULL_WITH_CONTEXT(context, lambdaPtr); |
| 225 | lambda = static_cast<float>(*lambdaPtr); | 224 | lambda = static_cast<float>(*lambdaPtr); |
| 226 | - OP_CHECK_IF( | 225 | + OP_CHECK_IF(lambda == 0, |
| 227 | - lambda == 0, | 226 | + OP_LOGE(context->GetNodeName(), "lambda is the denominator and cannot be zero, but get %f.", lambda), |
| 228 | - OP_LOGE(context->GetNodeName(), "lambda is the denominator and cannot be zero, but get %f.", lambda), | 227 | + return ge::GRAPH_FAILED); |
| 229 | - return ge::GRAPH_FAILED); | ||
| 230 | const int64_t* seedPtr = attrs->GetAttrPointer<int64_t>(ATTR_2); | 228 | const int64_t* seedPtr = attrs->GetAttrPointer<int64_t>(ATTR_2); |
| 231 | OP_CHECK_NULL_WITH_CONTEXT(context, seedPtr); | 229 | OP_CHECK_NULL_WITH_CONTEXT(context, seedPtr); |
| 232 | seed = static_cast<uint64_t>(*seedPtr); | 230 | seed = static_cast<uint64_t>(*seedPtr); |
| @@ -240,29 +238,22 @@ ge::graphStatus SimThreadExponentialTiling::SetAttrParams() | |||
| 240 | return ge::GRAPH_SUCCESS; | 238 | return ge::GRAPH_SUCCESS; |
| 241 | } | 239 | } |
| 242 | 240 | ||
| 243 | -void SimThreadExponentialTiling::SetTilingKey() | 241 | +void SimThreadExponentialTiling::SetTilingKey() { tilingKey_ = dataSizeType; } |
| 244 | -{ | ||
| 245 | - tilingKey_ = dataSizeType; | ||
| 246 | -} | ||
| 247 | 242 | ||
| 248 | -uint64_t SimThreadExponentialTiling::GetTilingKey() | 243 | +uint64_t SimThreadExponentialTiling::GetTilingKey() { return tilingKey_; } |
| 249 | -{ | ||
| 250 | - return tilingKey_; | ||
| 251 | -} | ||
| 252 | 244 | ||
| 253 | ge::graphStatus SimThreadExponentialTiling::DoTiling() | 245 | ge::graphStatus SimThreadExponentialTiling::DoTiling() |
| 254 | { | 246 | { |
| 255 | auto nodeName = context->GetNodeName(); | 247 | auto nodeName = context->GetNodeName(); |
| 256 | 248 | ||
| 257 | - OP_CHECK_IF( | 249 | + OP_CHECK_IF(SetAttrParams() != ge::GRAPH_SUCCESS, OP_LOGE(nodeName, "SetAttrParams failed."), |
| 258 | - SetAttrParams() != ge::GRAPH_SUCCESS, OP_LOGE(nodeName, "SetAttrParams failed."), return ge::GRAPH_FAILED); | 250 | + return ge::GRAPH_FAILED); |
| 259 | - OP_CHECK_IF( | 251 | + OP_CHECK_IF(GetInputTensorInfo() != ge::GRAPH_SUCCESS, OP_LOGE(nodeName, "GetInputTensorInfo failed."), |
| 260 | - GetInputTensorInfo() != ge::GRAPH_SUCCESS, OP_LOGE(nodeName, "GetInputTensorInfo failed."), | 252 | + return ge::GRAPH_FAILED); |
| 261 | - return ge::GRAPH_FAILED); | 253 | + OP_CHECK_IF(GetPlatformInfo() != ge::GRAPH_SUCCESS, OP_LOGE(nodeName, "GetPlatformInfo failed."), |
| 262 | - OP_CHECK_IF( | 254 | + return ge::GRAPH_FAILED); |
| 263 | - GetPlatformInfo() != ge::GRAPH_SUCCESS, OP_LOGE(nodeName, "GetPlatformInfo failed."), return ge::GRAPH_FAILED); | 255 | + OP_CHECK_IF(Tiling4Block() != ge::GRAPH_SUCCESS, OP_LOGE(nodeName, "Tiling4Block failed."), |
| 264 | - OP_CHECK_IF( | 256 | + return ge::GRAPH_FAILED); |
| 265 | - Tiling4Block() != ge::GRAPH_SUCCESS, OP_LOGE(nodeName, "Tiling4Block failed."), return ge::GRAPH_FAILED); | ||
| 266 | SetTilingData(); | 257 | SetTilingData(); |
| 267 | 258 | ||
| 268 | SetTilingKey(); | 259 | SetTilingKey(); |
| @@ -275,10 +266,11 @@ ge::graphStatus SimThreadExponentialTiling::DoTiling() | |||
| 275 | 266 | ||
| 276 | auto ascendcPlatform = platform_ascendc::PlatformAscendC(context->GetPlatformInfo()); | 267 | auto ascendcPlatform = platform_ascendc::PlatformAscendC(context->GetPlatformInfo()); |
| 277 | size_t* currentWorkspace = context->GetWorkspaceSizes(1); | 268 | size_t* currentWorkspace = context->GetWorkspaceSizes(1); |
| 278 | - currentWorkspace[0] = | 269 | + currentWorkspace |
| 279 | - usrWorkspaceSize + | 270 | + [0] = usrWorkspaceSize + |
| 280 | - ascendcPlatform.GetLibApiWorkSpaceSize(); // 设置总的workspace的数值大小,总的workspace空间由框架来申请并管理。 | 271 | + ascendcPlatform |
| 281 | - // 该workspace作为中转空间用来放T2类型数据 | 272 | + .GetLibApiWorkSpaceSize(); // 设置总的workspace的数值大小,总的workspace空间由框架来申请并管理。 |
| 273 | + // 该workspace作为中转空间用来放T2类型数据 | ||
| 282 | 274 | ||
| 283 | return ge::GRAPH_SUCCESS; | 275 | return ge::GRAPH_SUCCESS; |
| 284 | } | 276 | } |
| @@ -303,4 +295,4 @@ ge::graphStatus TilingPrepare4SimThreadExponential(gert::TilingParseContext* con | |||
| 303 | IMPL_OP_OPTILING(SimThreadExponential) | 295 | IMPL_OP_OPTILING(SimThreadExponential) |
| 304 | .Tiling(Tiling4SimThreadExponential) | 296 | .Tiling(Tiling4SimThreadExponential) |
| 305 | .TilingParse<Tiling4SimThreadExponentialCompileInfo>(TilingPrepare4SimThreadExponential); | 297 | .TilingParse<Tiling4SimThreadExponentialCompileInfo>(TilingPrepare4SimThreadExponential); |
| 306 | -} // namespace optiling | 298 | +} // namespace optiling |
| @@ -86,15 +86,15 @@ private: | |||
| 86 | uint32_t batchNumTotal = 864; | 86 | uint32_t batchNumTotal = 864; |
| 87 | int64_t numel = 250000; | 87 | int64_t numel = 250000; |
| 88 | 88 | ||
| 89 | - uint32_t stepNum; | 89 | + uint32_t stepNum = 0; |
| 90 | - uint32_t stepBlock; | 90 | + uint32_t stepBlock = 0; |
| 91 | - uint32_t roundedSizeNum; | 91 | + uint32_t roundedSizeNum = 0; |
| 92 | - uint32_t roundedSizeBlock; | 92 | + uint32_t roundedSizeBlock = 0; |
| 93 | - float range; | 93 | + float range = 0; |
| 94 | - uint32_t handleNumLoop; | 94 | + uint32_t handleNumLoop = 0; |
| 95 | - uint32_t handleNumTail; | 95 | + uint32_t handleNumTail = 0; |
| 96 | - uint32_t totalCoreNum; | 96 | + uint32_t totalCoreNum = 0; |
| 97 | - uint32_t ubSize; | 97 | + uint32_t ubSize = 0; |
| 98 | 98 | ||
| 99 | uint64_t state = 0; | 99 | uint64_t state = 0; |
| 100 | 100 | ||
| @@ -102,15 +102,15 @@ private: | |||
| 102 | float end = 1; | 102 | float end = 1; |
| 103 | 103 | ||
| 104 | uint32_t dataSizeType = 3; | 104 | uint32_t dataSizeType = 3; |
| 105 | - int64_t count; | 105 | + int64_t count = 0; |
| 106 | - float lambda; | 106 | + float lambda = 0; |
| 107 | - uint64_t seed; | 107 | + uint64_t seed = 0; |
| 108 | - uint64_t offset; | 108 | + uint64_t offset = 0; |
| 109 | - int threadPerProcessor; | 109 | + int threadPerProcessor = 0; |
| 110 | - int streamProcessorCount; | 110 | + int streamProcessorCount = 0; |
| 111 | 111 | ||
| 112 | - ge::DataType selfDType; | 112 | + ge::DataType selfDType = ge::DT_UNDEFINED; |
| 113 | }; | 113 | }; |
| 114 | } // namespace optiling | 114 | } // namespace optiling |
| 115 | 115 | ||
| 116 | -#endif // OPS_BUILD_IN_OP_TILING_RUNTIME_SIM_THREAD_EXPONENTIAL_ARCH32_H_ | 116 | +#endif // OPS_BUILD_IN_OP_TILING_RUNTIME_SIM_THREAD_EXPONENTIAL_ARCH32_H_ |