已合并
fix(cleancode): AICPU算子告警整改(第三批) #10997
liu-wei创建于 9月21日
fix(cleancode): AICPU算子告警整改(第三批) #10997
已合并
共 14 个文件变更+31-29
| @@ -190,7 +190,7 @@ uint32_t LogSoftmaxV2CpuKernel::Compute(CpuKernelContext& ctx) | |||
| 190 | return result; | 190 | return result; |
| 191 | } | 191 | } |
| 192 | 192 | ||
| 193 | -KernelStatus LogSoftmaxV2CpuKernel::LogSoftmaxV2Check(const CpuKernelContext& ctx) | 193 | +KernelStatus LogSoftmaxV2CpuKernel::LogSoftmaxV2Check(const CpuKernelContext& ctx) const |
| 194 | { | 194 | { |
| 195 | KERNEL_CHECK_NULLPTR(ctx.Input(0)->GetData(), KERNEL_STATUS_PARAM_INVALID, "get input failed."); | 195 | KERNEL_CHECK_NULLPTR(ctx.Input(0)->GetData(), KERNEL_STATUS_PARAM_INVALID, "get input failed."); |
| 196 | KERNEL_CHECK_NULLPTR(ctx.Input(0)->GetTensorShape(), KERNEL_STATUS_PARAM_INVALID, "Get input tensor shape failed."); | 196 | KERNEL_CHECK_NULLPTR(ctx.Input(0)->GetTensorShape(), KERNEL_STATUS_PARAM_INVALID, "Get input tensor shape failed."); |
| @@ -213,7 +213,7 @@ KernelStatus LogSoftmaxV2CpuKernel::LogSoftmaxV2Check(const CpuKernelContext& ct | |||
| 213 | } | 213 | } |
| 214 | 214 | ||
| 215 | template <typename T> | 215 | template <typename T> |
| 216 | -KernelStatus LogSoftmaxV2CpuKernel::LogSoftmaxV2Compute(const CpuKernelContext& ctx) | 216 | +KernelStatus LogSoftmaxV2CpuKernel::LogSoftmaxV2Compute(const CpuKernelContext& ctx) const |
| 217 | { | 217 | { |
| 218 | auto input = static_cast<T*>(ctx.Input(0)->GetData()); | 218 | auto input = static_cast<T*>(ctx.Input(0)->GetData()); |
| 219 | auto output = static_cast<T*>(ctx.Output(0)->GetData()); | 219 | auto output = static_cast<T*>(ctx.Output(0)->GetData()); |
| @@ -24,10 +24,10 @@ public: | |||
| 24 | uint32_t Compute(CpuKernelContext& ctx) override; | 24 | uint32_t Compute(CpuKernelContext& ctx) override; |
| 25 | 25 | ||
| 26 | private: | 26 | private: |
| 27 | - KernelStatus LogSoftmaxV2Check(const CpuKernelContext& ctx); | 27 | + KernelStatus LogSoftmaxV2Check(const CpuKernelContext& ctx) const; |
| 28 | 28 | ||
| 29 | template <typename T> | 29 | template <typename T> |
| 30 | - KernelStatus LogSoftmaxV2Compute(const CpuKernelContext& ctx); | 30 | + KernelStatus LogSoftmaxV2Compute(const CpuKernelContext& ctx) const; |
| 31 | }; | 31 | }; |
| 32 | } // namespace aicpu | 32 | } // namespace aicpu |
| 33 | 33 | ||
| @@ -354,8 +354,9 @@ KernelStatus SoftmaxV2ExtraCheck(const CpuKernelContext& ctx) | |||
| 354 | 354 | ||
| 355 | uint32_t SoftmaxV2Check(CpuKernelContext& ctx) | 355 | uint32_t SoftmaxV2Check(CpuKernelContext& ctx) |
| 356 | { | 356 | { |
| 357 | - return NormalCheck(ctx, kSoftmaxV2InputNum, kSoftmaxV2OutputNum, kSoftmaxV2Attr) ? KERNEL_STATUS_PARAM_INVALID : | 357 | + return NormalCheck(ctx, kSoftmaxV2InputNum, kSoftmaxV2OutputNum, kSoftmaxV2Attr) != KERNEL_STATUS_OK ? |
| 358 | - SoftmaxV2ExtraCheck(ctx); | 358 | + KERNEL_STATUS_PARAM_INVALID : |
| 359 | + SoftmaxV2ExtraCheck(ctx); | ||
| 359 | } | 360 | } |
| 360 | 361 | ||
| 361 | // DT_FLOAT16, DT_FLOAT, DT_DOUBLE | 362 | // DT_FLOAT16, DT_FLOAT, DT_DOUBLE |
| @@ -385,7 +386,8 @@ uint32_t SoftmaxV2Compute(const CpuKernelContext& ctx) | |||
| 385 | 386 | ||
| 386 | uint32_t SoftmaxV2CpuKernel::Compute(CpuKernelContext& ctx) | 387 | uint32_t SoftmaxV2CpuKernel::Compute(CpuKernelContext& ctx) |
| 387 | { | 388 | { |
| 388 | - return detail::SoftmaxV2Check(ctx) ? KERNEL_STATUS_PARAM_INVALID : detail::SoftmaxV2Compute(ctx); | 389 | + return detail::SoftmaxV2Check(ctx) != KERNEL_STATUS_OK ? KERNEL_STATUS_PARAM_INVALID : |
| 390 | + detail::SoftmaxV2Compute(ctx); | ||
| 389 | } | 391 | } |
| 390 | 392 | ||
| 391 | OPS_NN_REGISTER_CPU_KERNELV2(kSoftmaxV2, SoftmaxV2CpuKernel); | 393 | OPS_NN_REGISTER_CPU_KERNELV2(kSoftmaxV2, SoftmaxV2CpuKernel); |
| @@ -88,7 +88,7 @@ KernelStatus CalReverseSequence(const std::vector<void*>& ioAddrs, std::vector<i | |||
| 88 | output[i * seqStep + offset] = input[((reverseNum - i) - 1) * seqStep + offset]; | 88 | output[i * seqStep + offset] = input[((reverseNum - i) - 1) * seqStep + offset]; |
| 89 | output[((reverseNum - i) - 1) * seqStep + offset] = input[i * seqStep + offset]; | 89 | output[((reverseNum - i) - 1) * seqStep + offset] = input[i * seqStep + offset]; |
| 90 | } | 90 | } |
| 91 | - if ((i >= reverseNum) || (i == reverseNum / kEven && reverseNum % kEven)) { | 91 | + if ((i >= reverseNum) || (i == reverseNum / kEven && (reverseNum % kEven) != 0)) { |
| 92 | output[i * seqStep + offset] = input[i * seqStep + offset]; | 92 | output[i * seqStep + offset] = input[i * seqStep + offset]; |
| 93 | } | 93 | } |
| 94 | } | 94 | } |
| @@ -234,7 +234,7 @@ uint32_t ScatterElementsCpuKernel::Compute(CpuKernelContext& ctx) | |||
| 234 | } | 234 | } |
| 235 | 235 | ||
| 236 | template <typename T> | 236 | template <typename T> |
| 237 | -uint32_t ScatterElementsCpuKernel::UpdateOutput(const CpuKernelContext& ctx, int64_t total_value_num) | 237 | +uint32_t ScatterElementsCpuKernel::UpdateOutput(const CpuKernelContext& ctx, int64_t total_value_num) const |
| 238 | { | 238 | { |
| 239 | auto* input_data = PtrToPtr<void, T>(ctx.Input(0)->GetData()); | 239 | auto* input_data = PtrToPtr<void, T>(ctx.Input(0)->GetData()); |
| 240 | auto* output_data = PtrToPtr<void, T>(ctx.Output(0)->GetData()); | 240 | auto* output_data = PtrToPtr<void, T>(ctx.Output(0)->GetData()); |
| @@ -275,7 +275,7 @@ uint32_t ScatterElementsCpuKernel::UpdateOutput(const CpuKernelContext& ctx, int | |||
| 275 | } | 275 | } |
| 276 | 276 | ||
| 277 | template <typename TI> | 277 | template <typename TI> |
| 278 | -uint32_t ScatterElementsCpuKernel::DispatchByDataType(CpuKernelContext& ctx) | 278 | +uint32_t ScatterElementsCpuKernel::DispatchByDataType(CpuKernelContext& ctx) const |
| 279 | { | 279 | { |
| 280 | switch (ctx.Input(0)->GetDataType()) { | 280 | switch (ctx.Input(0)->GetDataType()) { |
| 281 | case DT_FLOAT16: | 281 | case DT_FLOAT16: |
| @@ -315,7 +315,7 @@ uint32_t ScatterElementsCpuKernel::DispatchByDataType(CpuKernelContext& ctx) | |||
| 315 | } | 315 | } |
| 316 | 316 | ||
| 317 | template <typename T, typename TI> | 317 | template <typename T, typename TI> |
| 318 | -uint32_t ScatterElementsCpuKernel::DoCompute(const CpuKernelContext& ctx) | 318 | +uint32_t ScatterElementsCpuKernel::DoCompute(const CpuKernelContext& ctx) const |
| 319 | { | 319 | { |
| 320 | ScatterElementsComputeInfo info; | 320 | ScatterElementsComputeInfo info; |
| 321 | auto ret = InitScatterElementsInfo(ctx, info); | 321 | auto ret = InitScatterElementsInfo(ctx, info); |
| @@ -25,13 +25,13 @@ public: | |||
| 25 | 25 | ||
| 26 | private: | 26 | private: |
| 27 | template <typename TI> | 27 | template <typename TI> |
| 28 | - uint32_t DispatchByDataType(CpuKernelContext& ctx); | 28 | + uint32_t DispatchByDataType(CpuKernelContext& ctx) const; |
| 29 | 29 | ||
| 30 | template <typename T> | 30 | template <typename T> |
| 31 | - uint32_t UpdateOutput(const CpuKernelContext& ctx, int64_t total_value_num); | 31 | + uint32_t UpdateOutput(const CpuKernelContext& ctx, int64_t total_value_num) const; |
| 32 | 32 | ||
| 33 | template <typename T, typename TI> | 33 | template <typename T, typename TI> |
| 34 | - uint32_t DoCompute(const CpuKernelContext& ctx); | 34 | + uint32_t DoCompute(const CpuKernelContext& ctx) const; |
| 35 | }; | 35 | }; |
| 36 | } // namespace aicpu | 36 | } // namespace aicpu |
| 37 | 37 | ||
| @@ -84,7 +84,7 @@ uint32_t SparseSegmentMeanCpuKernel::Compute(CpuKernelContext& ctx) | |||
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | template <typename T, typename T1, typename T2> | 86 | template <typename T, typename T1, typename T2> |
| 87 | -KernelStatus SparseSegmentMeanCpuKernel::ComputeKernelWithType(const CpuKernelContext& ctx) | 87 | +KernelStatus SparseSegmentMeanCpuKernel::ComputeKernelWithType(const CpuKernelContext& ctx) const |
| 88 | { | 88 | { |
| 89 | auto xShape = ctx.Input(0)->GetTensorShape(); | 89 | auto xShape = ctx.Input(0)->GetTensorShape(); |
| 90 | T1 xDim0 = static_cast<T1>(xShape->GetDimSize(0)); | 90 | T1 xDim0 = static_cast<T1>(xShape->GetDimSize(0)); |
| @@ -173,7 +173,7 @@ KernelStatus SparseSegmentMeanCpuKernel::ComputeKernelWithType(const CpuKernelCo | |||
| 173 | } | 173 | } |
| 174 | 174 | ||
| 175 | template <typename T> | 175 | template <typename T> |
| 176 | -KernelStatus SparseSegmentMeanCpuKernel::ComputeKernel(const CpuKernelContext& ctx) | 176 | +KernelStatus SparseSegmentMeanCpuKernel::ComputeKernel(const CpuKernelContext& ctx) const |
| 177 | { | 177 | { |
| 178 | auto indicesDataType = ctx.Input(1)->GetDataType(); | 178 | auto indicesDataType = ctx.Input(1)->GetDataType(); |
| 179 | auto segmentIdsDtype = ctx.Input(2)->GetDataType(); | 179 | auto segmentIdsDtype = ctx.Input(2)->GetDataType(); |
| @@ -25,10 +25,10 @@ private: | |||
| 25 | KernelStatus SparseSegmentCheck(const CpuKernelContext& ctx) const; | 25 | KernelStatus SparseSegmentCheck(const CpuKernelContext& ctx) const; |
| 26 | 26 | ||
| 27 | template <typename T> | 27 | template <typename T> |
| 28 | - KernelStatus ComputeKernel(const CpuKernelContext& ctx); | 28 | + KernelStatus ComputeKernel(const CpuKernelContext& ctx) const; |
| 29 | 29 | ||
| 30 | template <typename T, typename T1, typename T2> | 30 | template <typename T, typename T1, typename T2> |
| 31 | - KernelStatus ComputeKernelWithType(const CpuKernelContext& ctx); | 31 | + KernelStatus ComputeKernelWithType(const CpuKernelContext& ctx) const; |
| 32 | }; | 32 | }; |
| 33 | } // namespace aicpu | 33 | } // namespace aicpu |
| 34 | #endif // OPS_BUILT_IN_OP_KERNEL_AICPU_SPARSE_SEGMENT_MEAN_AICPU_H_ | 34 | #endif // OPS_BUILT_IN_OP_KERNEL_AICPU_SPARSE_SEGMENT_MEAN_AICPU_H_ |
| @@ -173,7 +173,7 @@ uint32_t SparseSegmentSumCpuKernel::Compute(CpuKernelContext& ctx) | |||
| 173 | } | 173 | } |
| 174 | 174 | ||
| 175 | template <typename T, typename T1, typename T2> | 175 | template <typename T, typename T1, typename T2> |
| 176 | -KernelStatus SparseSegmentSumCpuKernel::ComputeKernelWithType(const CpuKernelContext& ctx) | 176 | +KernelStatus SparseSegmentSumCpuKernel::ComputeKernelWithType(const CpuKernelContext& ctx) const |
| 177 | { | 177 | { |
| 178 | size_t n = ctx.Input(0)->GetTensorShape()->NumElements() / ctx.Input(0)->GetTensorShape()->GetDimSize(0); | 178 | size_t n = ctx.Input(0)->GetTensorShape()->NumElements() / ctx.Input(0)->GetTensorShape()->GetDimSize(0); |
| 179 | size_t num_indices = ctx.Input(2)->GetTensorShape()->NumElements(); | 179 | size_t num_indices = ctx.Input(2)->GetTensorShape()->NumElements(); |
| @@ -232,7 +232,7 @@ KernelStatus SparseSegmentSumCpuKernel::ComputeKernelWithType(const CpuKernelCon | |||
| 232 | return KERNEL_STATUS_OK; | 232 | return KERNEL_STATUS_OK; |
| 233 | }; | 233 | }; |
| 234 | template <typename T> | 234 | template <typename T> |
| 235 | -KernelStatus SparseSegmentSumCpuKernel::ComputeKernel(const CpuKernelContext& ctx) | 235 | +KernelStatus SparseSegmentSumCpuKernel::ComputeKernel(const CpuKernelContext& ctx) const |
| 236 | { | 236 | { |
| 237 | auto indices_data_type = ctx.Input(1)->GetDataType(); | 237 | auto indices_data_type = ctx.Input(1)->GetDataType(); |
| 238 | auto segment_ids_dtype = ctx.Input(2)->GetDataType(); | 238 | auto segment_ids_dtype = ctx.Input(2)->GetDataType(); |
| @@ -30,10 +30,10 @@ private: | |||
| 30 | KernelStatus ComputeWithType(const CpuKernelContext& ctx); | 30 | KernelStatus ComputeWithType(const CpuKernelContext& ctx); |
| 31 | 31 | ||
| 32 | template <typename T> | 32 | template <typename T> |
| 33 | - KernelStatus ComputeKernel(const CpuKernelContext& ctx); | 33 | + KernelStatus ComputeKernel(const CpuKernelContext& ctx) const; |
| 34 | 34 | ||
| 35 | template <typename T, typename T1, typename T2> | 35 | template <typename T, typename T1, typename T2> |
| 36 | - KernelStatus ComputeKernelWithType(const CpuKernelContext& ctx); | 36 | + KernelStatus ComputeKernelWithType(const CpuKernelContext& ctx) const; |
| 37 | }; | 37 | }; |
| 38 | } // namespace aicpu | 38 | } // namespace aicpu |
| 39 | #endif | 39 | #endif |
| @@ -419,7 +419,7 @@ uint32_t SparseToDense(const CpuKernelContext& ctx, SparseTensor& st, const Tens | |||
| 419 | } | 419 | } |
| 420 | } | 420 | } |
| 421 | 421 | ||
| 422 | -KernelStatus SparseToDenseCpuKernel::ValidParam(const CpuKernelContext& ctx) | 422 | +KernelStatus SparseToDenseCpuKernel::ValidParam(const CpuKernelContext& ctx) const |
| 423 | { | 423 | { |
| 424 | KERNEL_LOG_INFO("Start to execute ValidParam"); | 424 | KERNEL_LOG_INFO("Start to execute ValidParam"); |
| 425 | Tensor* indicesTensor = ctx.Input(0); | 425 | Tensor* indicesTensor = ctx.Input(0); |
| @@ -497,7 +497,7 @@ KernelStatus SparseToDenseCpuKernel::ValidParam(const CpuKernelContext& ctx) | |||
| 497 | } | 497 | } |
| 498 | 498 | ||
| 499 | uint32_t SparseToDenseCpuKernel::ParallelSetDefaultValue(const CpuKernelContext& ctx, const Tensor* defaultValueTensor, | 499 | uint32_t SparseToDenseCpuKernel::ParallelSetDefaultValue(const CpuKernelContext& ctx, const Tensor* defaultValueTensor, |
| 500 | - const Tensor* outputTensor, int64_t outputSize) | 500 | + const Tensor* outputTensor, int64_t outputSize) const |
| 501 | { | 501 | { |
| 502 | auto typeSize = GetSizeByDataType(static_cast<DataType>(outputTensor->GetDataType())); | 502 | auto typeSize = GetSizeByDataType(static_cast<DataType>(outputTensor->GetDataType())); |
| 503 | char* defaultValueAddr = PtrToPtr<void, char>(defaultValueTensor->GetData()); | 503 | char* defaultValueAddr = PtrToPtr<void, char>(defaultValueTensor->GetData()); |
| @@ -21,9 +21,9 @@ public: | |||
| 21 | uint32_t Compute(CpuKernelContext& ctx) override; | 21 | uint32_t Compute(CpuKernelContext& ctx) override; |
| 22 | 22 | ||
| 23 | protected: | 23 | protected: |
| 24 | - KernelStatus ValidParam(const CpuKernelContext& ctx); | 24 | + KernelStatus ValidParam(const CpuKernelContext& ctx) const; |
| 25 | uint32_t ParallelSetDefaultValue(const CpuKernelContext& ctx, const Tensor* defaultValueTensor, | 25 | uint32_t ParallelSetDefaultValue(const CpuKernelContext& ctx, const Tensor* defaultValueTensor, |
| 26 | - const Tensor* outputTensor, int64_t outputSize); | 26 | + const Tensor* outputTensor, int64_t outputSize) const; |
| 27 | uint32_t SetDefaultValue(const CpuKernelContext& ctx, const Tensor* defaultValueTensor, const Tensor* outputTensor, | 27 | uint32_t SetDefaultValue(const CpuKernelContext& ctx, const Tensor* defaultValueTensor, const Tensor* outputTensor, |
| 28 | int64_t outputSize); | 28 | int64_t outputSize); |
| 29 | }; | 29 | }; |
| @@ -62,7 +62,7 @@ inline void GetOuterShape(const CpuKernelContextInfo& info, uint64_t* x_outer_sh | |||
| 62 | } | 62 | } |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | -inline void GetBatchStrides(uint64_t* outer_shape, uint64_t index_depth, uint64_t* batch_strides) | 65 | +inline void GetBatchStrides(const uint64_t* outer_shape, uint64_t index_depth, uint64_t* batch_strides) |
| 66 | { | 66 | { |
| 67 | batch_strides[index_depth - 1] = 1; | 67 | batch_strides[index_depth - 1] = 1; |
| 68 | for (int64_t i = static_cast<int64_t>(index_depth) - 2; i >= 0; --i) { | 68 | for (int64_t i = static_cast<int64_t>(index_depth) - 2; i >= 0; --i) { |
| @@ -297,7 +297,7 @@ uint32_t IndicesCompute(const CpuKernelContextInfo& info) | |||
| 297 | } | 297 | } |
| 298 | } | 298 | } |
| 299 | 299 | ||
| 300 | -uint32_t TensorScatterUpdateCpukernel::GetInputAndCheck(const CpuKernelContextInfo& info) | 300 | +uint32_t TensorScatterUpdateCpukernel::GetInputAndCheck(const CpuKernelContextInfo& info) const |
| 301 | { | 301 | { |
| 302 | KERNEL_CHECK_FALSE((info.indices_dims >= kMinIndicesDims), KERNEL_STATUS_PARAM_INVALID, | 302 | KERNEL_CHECK_FALSE((info.indices_dims >= kMinIndicesDims), KERNEL_STATUS_PARAM_INVALID, |
| 303 | "indices must be at least rank %u but is rank %lu", kMinIndicesDims, info.indices_dims); | 303 | "indices must be at least rank %u but is rank %lu", kMinIndicesDims, info.indices_dims); |
| @@ -50,7 +50,7 @@ public: | |||
| 50 | uint32_t Compute(CpuKernelContext& ctx) override; | 50 | uint32_t Compute(CpuKernelContext& ctx) override; |
| 51 | 51 | ||
| 52 | private: | 52 | private: |
| 53 | - uint32_t GetInputAndCheck(const CpuKernelContextInfo& info); | 53 | + uint32_t GetInputAndCheck(const CpuKernelContextInfo& info) const; |
| 54 | }; | 54 | }; |
| 55 | } // namespace aicpu | 55 | } // namespace aicpu |
| 56 | 56 | ||