已合并
fix(cleancode): AICPU算子告警整改(第二批) #10662
liu-wei创建于 9月17日
fix(cleancode): AICPU算子告警整改(第二批) #10662
已合并
共 7 个文件变更+70-65
| @@ -91,17 +91,19 @@ aicpu::KernelStatus ComputeSequential(T* input, T* output, T* dims_exp_sum, T* d | |||
| 91 | Eigen::array<int, 1> softmax_axes{{1}}; | 91 | Eigen::array<int, 1> softmax_axes{{1}}; |
| 92 | dims_max = logits.maximum(softmax_axes); | 92 | dims_max = logits.maximum(softmax_axes); |
| 93 | 93 | ||
| 94 | - IterateBatches(info.total, info.inner_size, info.dims[info.pivot], [&](int64_t index, int64_t index_dst) { | 94 | + IterateBatches(info.total, info.inner_size, info.dims[info.pivot], |
| 95 | - *(output + index) = Eigen::numext::exp(*(input + index) - dims_maximum[index_dst]); | 95 | + [&input, &output, &dims_maximum, &dims_exp_sum](int64_t index, int64_t index_dst) { |
| 96 | - dims_exp_sum[index_dst] += (*(output + index)); | 96 | + *(output + index) = Eigen::numext::exp(*(input + index) - dims_maximum[index_dst]); |
| 97 | - }); | 97 | + dims_exp_sum[index_dst] += (*(output + index)); |
| 98 | + }); | ||
| 98 | 99 | ||
| 99 | dims_sum = dims_sum.inverse(); | 100 | dims_sum = dims_sum.inverse(); |
| 100 | 101 | ||
| 101 | - IterateBatches(info.total, info.inner_size, info.dims[info.pivot], [&](int64_t index, int64_t index_dst) { | 102 | + IterateBatches(info.total, info.inner_size, info.dims[info.pivot], |
| 102 | - *(output + index) = (*(output + index)) * (dims_exp_sum[index_dst]); | 103 | + [&output, &dims_exp_sum](int64_t index, int64_t index_dst) { |
| 103 | - *(output + index) = Eigen::numext::log(*(output + index)); | 104 | + *(output + index) = (*(output + index)) * (dims_exp_sum[index_dst]); |
| 104 | - }); | 105 | + *(output + index) = Eigen::numext::log(*(output + index)); |
| 106 | + }); | ||
| 105 | 107 | ||
| 106 | return aicpu::KERNEL_STATUS_OK; | 108 | return aicpu::KERNEL_STATUS_OK; |
| 107 | } | 109 | } |
| @@ -144,7 +146,8 @@ aicpu::KernelStatus ComputeParallel(const aicpu::CpuKernelContext& ctx, T* input | |||
| 144 | { | 146 | { |
| 145 | std::int64_t per_unit_size{info.length / std::min(std::max(1L, static_cast<int64_t>(cores) - 2L), info.length)}; | 147 | std::int64_t per_unit_size{info.length / std::min(std::max(1L, static_cast<int64_t>(cores) - 2L), info.length)}; |
| 146 | std::atomic<bool> failed{false}; | 148 | std::atomic<bool> failed{false}; |
| 147 | - auto sharder = [&](std::int64_t begin, std::int64_t end) { | 149 | + auto sharder = [&input, &output, &dims_exp_sum, &dims_maximum, &info, &failed](std::int64_t begin, |
| 150 | + std::int64_t end) { | ||
| 148 | for (int64_t index = begin; index < end; ++index) { | 151 | for (int64_t index = begin; index < end; ++index) { |
| 149 | ComputeOneBatch<T>(input, output, dims_exp_sum, dims_maximum, index, info.inner_size, info.dims[info.pivot], | 152 | ComputeOneBatch<T>(input, output, dims_exp_sum, dims_maximum, index, info.inner_size, info.dims[info.pivot], |
| 150 | failed); | 153 | failed); |
| @@ -17,7 +17,7 @@ namespace aicpu { | |||
| 17 | class IndexToAddrCpuKernel : public CpuKernel { | 17 | class IndexToAddrCpuKernel : public CpuKernel { |
| 18 | public: | 18 | public: |
| 19 | IndexToAddrCpuKernel() = default; | 19 | IndexToAddrCpuKernel() = default; |
| 20 | - ~IndexToAddrCpuKernel() = default; | 20 | + ~IndexToAddrCpuKernel() override = default; |
| 21 | uint32_t Compute(CpuKernelContext& ctx) override; | 21 | uint32_t Compute(CpuKernelContext& ctx) override; |
| 22 | 22 | ||
| 23 | private: | 23 | private: |
| @@ -27,15 +27,15 @@ const char* const kScatterNdMax = "ScatterNdMax"; | |||
| 27 | const int64_t kParallelDataNum = 32 * 1024; | 27 | const int64_t kParallelDataNum = 32 * 1024; |
| 28 | const int32_t kSplitSize = 64 * 1024; | 28 | const int32_t kSplitSize = 64 * 1024; |
| 29 | 29 | ||
| 30 | -#define DO_SCATTER_ND_MAX_COMPUTE_CASE(DTYPE, TYPE, ITYPE, CTX) \ | 30 | +#define DO_SCATTER_ND_MAX_COMPUTE_CASE(DTYPE, TYPE, ITYPE, CTX) \ |
| 31 | - case (DTYPE): \ | 31 | + case (DTYPE): \ |
| 32 | - do { \ | 32 | + do { \ |
| 33 | - if ((ITYPE) == DT_INT32) { \ | 33 | + if ((ITYPE) == DT_INT32) { \ |
| 34 | - return DoScatterNdMaxCompute<TYPE, int32_t>(CTX); \ | 34 | + return DoScatterNdMaxCompute<TYPE, int32_t>(CTX); \ |
| 35 | - } else { \ | 35 | + } else { \ |
| 36 | - return DoScatterNdMaxCompute<TYPE, int64_t>(CTX); \ | 36 | + return DoScatterNdMaxCompute<TYPE, int64_t>(CTX); \ |
| 37 | - } \ | 37 | + } \ |
| 38 | - } while (0) | 38 | + } while (0) |
| 39 | } // namespace | 39 | } // namespace |
| 40 | 40 | ||
| 41 | namespace aicpu { | 41 | namespace aicpu { |
| @@ -74,8 +74,8 @@ uint32_t ScatterNdMaxCpuKernel::Compute(CpuKernelContext& ctx) | |||
| 74 | template <typename T> | 74 | template <typename T> |
| 75 | uint32_t ScatterNdMaxCpuKernel::InitScatterNdMaxOutput(const CpuKernelContext& ctx) | 75 | uint32_t ScatterNdMaxCpuKernel::InitScatterNdMaxOutput(const CpuKernelContext& ctx) |
| 76 | { | 76 | { |
| 77 | - auto input_ref = reinterpret_cast<T*>(ctx.Input(0)->GetData()); | 77 | + auto input_ref = PtrToPtr<void, T>(ctx.Input(0)->GetData()); |
| 78 | - auto output_ref = reinterpret_cast<T*>(ctx.Output(0)->GetData()); | 78 | + auto output_ref = PtrToPtr<void, T>(ctx.Output(0)->GetData()); |
| 79 | std::atomic<uint32_t> work_ret(KERNEL_STATUS_OK); | 79 | std::atomic<uint32_t> work_ret(KERNEL_STATUS_OK); |
| 80 | int64_t total_value_num = ctx.Input(0)->NumElements(); | 80 | int64_t total_value_num = ctx.Input(0)->NumElements(); |
| 81 | if (total_value_num >= kParallelDataNum) { | 81 | if (total_value_num >= kParallelDataNum) { |
| @@ -88,10 +88,11 @@ uint32_t ScatterNdMaxCpuKernel::InitScatterNdMaxOutput(const CpuKernelContext& c | |||
| 88 | "max_thread_num must not be equal to zero."); | 88 | "max_thread_num must not be equal to zero."); |
| 89 | size_t chunk_bytes = static_cast<size_t>(total_value_num / max_thread_num) * sizeof(T); | 89 | size_t chunk_bytes = static_cast<size_t>(total_value_num / max_thread_num) * sizeof(T); |
| 90 | size_t final_chunk_bytes = static_cast<size_t>(total_value_num % max_thread_num) * sizeof(T) + chunk_bytes; | 90 | size_t final_chunk_bytes = static_cast<size_t>(total_value_num % max_thread_num) * sizeof(T) + chunk_bytes; |
| 91 | - auto copy_output_shard = [&](size_t begin_idx, size_t end_idx) { | 91 | + auto copy_output_shard = [&max_thread_num, &final_chunk_bytes, &chunk_bytes, &total_value_num, &work_ret, |
| 92 | + &output_ref, &input_ref](size_t begin_idx, size_t end_idx) { | ||
| 92 | for (size_t shard_id = begin_idx; shard_id < end_idx; ++shard_id) { | 93 | for (size_t shard_id = begin_idx; shard_id < end_idx; ++shard_id) { |
| 93 | - size_t copy_bytes = | 94 | + size_t copy_bytes = (shard_id == static_cast<size_t>(max_thread_num - 1)) ? final_chunk_bytes : |
| 94 | - (shard_id == static_cast<size_t>(max_thread_num - 1)) ? final_chunk_bytes : chunk_bytes; | 95 | + chunk_bytes; |
| 95 | int64_t data_base = static_cast<int64_t>(shard_id) * (total_value_num / max_thread_num); | 96 | int64_t data_base = static_cast<int64_t>(shard_id) * (total_value_num / max_thread_num); |
| 96 | if (data_base >= total_value_num) { | 97 | if (data_base >= total_value_num) { |
| 97 | work_ret = KERNEL_STATUS_PARAM_INVALID; | 98 | work_ret = KERNEL_STATUS_PARAM_INVALID; |
| @@ -127,7 +128,7 @@ uint32_t ScatterNdMaxCpuKernel::CheckScatterNdMaxShapeAndData(const CpuKernelCon | |||
| 127 | { | 128 | { |
| 128 | auto shape_ref = ctx.Input(0)->GetTensorShape(); | 129 | auto shape_ref = ctx.Input(0)->GetTensorShape(); |
| 129 | auto shape_output = ctx.Output(0)->GetTensorShape(); | 130 | auto shape_output = ctx.Output(0)->GetTensorShape(); |
| 130 | - auto input_indices = reinterpret_cast<TI*>(ctx.Input(1)->GetData()); | 131 | + auto input_indices = PtrToPtr<void, TI>(ctx.Input(1)->GetData()); |
| 131 | size_t value_dim_num_ref = static_cast<size_t>(shape_ref->GetDims()); | 132 | size_t value_dim_num_ref = static_cast<size_t>(shape_ref->GetDims()); |
| 132 | std::vector<int64_t> value_dim_ref = shape_ref->GetDimSizes(); | 133 | std::vector<int64_t> value_dim_ref = shape_ref->GetDimSizes(); |
| 133 | std::vector<int64_t> value_dim_output = shape_output->GetDimSizes(); | 134 | std::vector<int64_t> value_dim_output = shape_output->GetDimSizes(); |
| @@ -151,9 +152,9 @@ uint32_t ScatterNdMaxCpuKernel::CheckScatterNdMaxShapeAndData(const CpuKernelCon | |||
| 151 | template <typename T, typename TI> | 152 | template <typename T, typename TI> |
| 152 | uint32_t ScatterNdMaxCpuKernel::DoScatterNdMaxCompute(CpuKernelContext& ctx) | 153 | uint32_t ScatterNdMaxCpuKernel::DoScatterNdMaxCompute(CpuKernelContext& ctx) |
| 153 | { | 154 | { |
| 154 | - auto input_ref = reinterpret_cast<T*>(ctx.Input(0)->GetData()); | 155 | + auto input_ref = PtrToPtr<void, T>(ctx.Input(0)->GetData()); |
| 155 | - auto input_indices = reinterpret_cast<TI*>(ctx.Input(1)->GetData()); | 156 | + auto input_indices = PtrToPtr<void, TI>(ctx.Input(1)->GetData()); |
| 156 | - auto input_updates = reinterpret_cast<T*>(ctx.Input(2)->GetData()); | 157 | + auto input_updates = PtrToPtr<void, T>(ctx.Input(2)->GetData()); |
| 157 | auto shape_ref = ctx.Input(0)->GetTensorShape(); | 158 | auto shape_ref = ctx.Input(0)->GetTensorShape(); |
| 158 | auto shape_indices = ctx.Input(1)->GetTensorShape(); | 159 | auto shape_indices = ctx.Input(1)->GetTensorShape(); |
| 159 | auto shape_updates = ctx.Input(2)->GetTensorShape(); | 160 | auto shape_updates = ctx.Input(2)->GetTensorShape(); |
| @@ -201,7 +202,8 @@ uint32_t ScatterNdMaxCpuKernel::DoScatterNdMaxCompute(CpuKernelContext& ctx) | |||
| 201 | } | 202 | } |
| 202 | } | 203 | } |
| 203 | } | 204 | } |
| 204 | - KERNEL_CHECK_FALSE((InitScatterNdMaxOutput<T>(ctx) == KERNEL_STATUS_OK), KERNEL_STATUS_PARAM_INVALID, "InitOutput failed."); | 205 | + KERNEL_CHECK_FALSE((InitScatterNdMaxOutput<T>(ctx) == KERNEL_STATUS_OK), KERNEL_STATUS_PARAM_INVALID, |
| 206 | + "InitOutput failed."); | ||
| 205 | return KERNEL_STATUS_OK; | 207 | return KERNEL_STATUS_OK; |
| 206 | } | 208 | } |
| 207 | 209 | ||
| @@ -27,15 +27,15 @@ const char* const kScatterNdMin = "ScatterNdMin"; | |||
| 27 | const int64_t kParallelDataNum = 32 * 1024; | 27 | const int64_t kParallelDataNum = 32 * 1024; |
| 28 | const int32_t kSplitSize = 64 * 1024; | 28 | const int32_t kSplitSize = 64 * 1024; |
| 29 | 29 | ||
| 30 | -#define DO_SCATTER_ND_MIN_COMPUTE_CASE(DTYPE, TYPE, ITYPE, CTX) \ | 30 | +#define DO_SCATTER_ND_MIN_COMPUTE_CASE(DTYPE, TYPE, ITYPE, CTX) \ |
| 31 | - case (DTYPE): \ | 31 | + case (DTYPE): \ |
| 32 | - do { \ | 32 | + do { \ |
| 33 | - if ((ITYPE) == DT_INT32) { \ | 33 | + if ((ITYPE) == DT_INT32) { \ |
| 34 | - return DoScatterNdMinCompute<TYPE, int32_t>(CTX); \ | 34 | + return DoScatterNdMinCompute<TYPE, int32_t>(CTX); \ |
| 35 | - } else { \ | 35 | + } else { \ |
| 36 | - return DoScatterNdMinCompute<TYPE, int64_t>(CTX); \ | 36 | + return DoScatterNdMinCompute<TYPE, int64_t>(CTX); \ |
| 37 | - } \ | 37 | + } \ |
| 38 | - } while (0) | 38 | + } while (0) |
| 39 | } // namespace | 39 | } // namespace |
| 40 | 40 | ||
| 41 | namespace aicpu { | 41 | namespace aicpu { |
| @@ -74,8 +74,8 @@ uint32_t ScatterNdMinCpuKernel::Compute(CpuKernelContext& ctx) | |||
| 74 | template <typename T> | 74 | template <typename T> |
| 75 | uint32_t ScatterNdMinCpuKernel::InitScatterNdMinOutput(const CpuKernelContext& ctx) | 75 | uint32_t ScatterNdMinCpuKernel::InitScatterNdMinOutput(const CpuKernelContext& ctx) |
| 76 | { | 76 | { |
| 77 | - auto src_ref = reinterpret_cast<T*>(ctx.Input(0)->GetData()); | 77 | + auto src_ref = PtrToPtr<void, T>(ctx.Input(0)->GetData()); |
| 78 | - auto dst_ref = reinterpret_cast<T*>(ctx.Output(0)->GetData()); | 78 | + auto dst_ref = PtrToPtr<void, T>(ctx.Output(0)->GetData()); |
| 79 | std::atomic<uint32_t> copy_status(KERNEL_STATUS_OK); | 79 | std::atomic<uint32_t> copy_status(KERNEL_STATUS_OK); |
| 80 | int64_t output_num = ctx.Input(0)->NumElements(); | 80 | int64_t output_num = ctx.Input(0)->NumElements(); |
| 81 | if (output_num >= kParallelDataNum) { | 81 | if (output_num >= kParallelDataNum) { |
| @@ -88,8 +88,7 @@ uint32_t ScatterNdMinCpuKernel::InitScatterNdMinOutput(const CpuKernelContext& c | |||
| 88 | size_t tail_block_size = static_cast<size_t>(output_num % thread_num) * sizeof(T) + block_size; | 88 | size_t tail_block_size = static_cast<size_t>(output_num % thread_num) * sizeof(T) + block_size; |
| 89 | auto copy_by_shard = [&](size_t start, size_t end) { | 89 | auto copy_by_shard = [&](size_t start, size_t end) { |
| 90 | for (size_t shard_idx = start; shard_idx < end; ++shard_idx) { | 90 | for (size_t shard_idx = start; shard_idx < end; ++shard_idx) { |
| 91 | - size_t copy_size = | 91 | + size_t copy_size = (shard_idx == static_cast<size_t>(thread_num - 1)) ? tail_block_size : block_size; |
| 92 | - (shard_idx == static_cast<size_t>(thread_num - 1)) ? tail_block_size : block_size; | ||
| 93 | int64_t data_offset = static_cast<int64_t>(shard_idx) * (output_num / thread_num); | 92 | int64_t data_offset = static_cast<int64_t>(shard_idx) * (output_num / thread_num); |
| 94 | if (data_offset >= output_num) { | 93 | if (data_offset >= output_num) { |
| 95 | copy_status = KERNEL_STATUS_PARAM_INVALID; | 94 | copy_status = KERNEL_STATUS_PARAM_INVALID; |
| @@ -125,7 +124,7 @@ uint32_t ScatterNdMinCpuKernel::CheckScatterNdMinShapeAndData(const CpuKernelCon | |||
| 125 | { | 124 | { |
| 126 | auto x_shape = ctx.Input(0)->GetTensorShape(); | 125 | auto x_shape = ctx.Input(0)->GetTensorShape(); |
| 127 | auto y_shape = ctx.Output(0)->GetTensorShape(); | 126 | auto y_shape = ctx.Output(0)->GetTensorShape(); |
| 128 | - auto indices_data = reinterpret_cast<TI*>(ctx.Input(1)->GetData()); | 127 | + auto indices_data = PtrToPtr<void, TI>(ctx.Input(1)->GetData()); |
| 129 | size_t x_rank = static_cast<size_t>(x_shape->GetDims()); | 128 | size_t x_rank = static_cast<size_t>(x_shape->GetDims()); |
| 130 | std::vector<int64_t> x_dims = x_shape->GetDimSizes(); | 129 | std::vector<int64_t> x_dims = x_shape->GetDimSizes(); |
| 131 | std::vector<int64_t> y_dims = y_shape->GetDimSizes(); | 130 | std::vector<int64_t> y_dims = y_shape->GetDimSizes(); |
| @@ -149,9 +148,9 @@ uint32_t ScatterNdMinCpuKernel::CheckScatterNdMinShapeAndData(const CpuKernelCon | |||
| 149 | template <typename T, typename TI> | 148 | template <typename T, typename TI> |
| 150 | uint32_t ScatterNdMinCpuKernel::DoScatterNdMinCompute(CpuKernelContext& ctx) | 149 | uint32_t ScatterNdMinCpuKernel::DoScatterNdMinCompute(CpuKernelContext& ctx) |
| 151 | { | 150 | { |
| 152 | - auto ref_data = reinterpret_cast<T*>(ctx.Input(0)->GetData()); | 151 | + auto ref_data = PtrToPtr<void, T>(ctx.Input(0)->GetData()); |
| 153 | - auto indices_ptr = reinterpret_cast<TI*>(ctx.Input(1)->GetData()); | 152 | + auto indices_ptr = PtrToPtr<void, TI>(ctx.Input(1)->GetData()); |
| 154 | - auto updates_ptr = reinterpret_cast<T*>(ctx.Input(2)->GetData()); | 153 | + auto updates_ptr = PtrToPtr<void, T>(ctx.Input(2)->GetData()); |
| 155 | auto ref_shape = ctx.Input(0)->GetTensorShape(); | 154 | auto ref_shape = ctx.Input(0)->GetTensorShape(); |
| 156 | auto indices_shape = ctx.Input(1)->GetTensorShape(); | 155 | auto indices_shape = ctx.Input(1)->GetTensorShape(); |
| 157 | auto updates_shape = ctx.Input(2)->GetTensorShape(); | 156 | auto updates_shape = ctx.Input(2)->GetTensorShape(); |
| @@ -199,7 +198,8 @@ uint32_t ScatterNdMinCpuKernel::DoScatterNdMinCompute(CpuKernelContext& ctx) | |||
| 199 | } | 198 | } |
| 200 | } | 199 | } |
| 201 | } | 200 | } |
| 202 | - KERNEL_CHECK_FALSE((InitScatterNdMinOutput<T>(ctx) == KERNEL_STATUS_OK), KERNEL_STATUS_PARAM_INVALID, "InitOutput failed."); | 201 | + KERNEL_CHECK_FALSE((InitScatterNdMinOutput<T>(ctx) == KERNEL_STATUS_OK), KERNEL_STATUS_PARAM_INVALID, |
| 202 | + "InitOutput failed."); | ||
| 203 | return KERNEL_STATUS_OK; | 203 | return KERNEL_STATUS_OK; |
| 204 | } | 204 | } |
| 205 | 205 | ||
| @@ -90,9 +90,9 @@ KernelStatus SparseFillEmptyRowsCpuKernel::ComputeSparseFillEmptyRows(const CpuK | |||
| 90 | Tensor* emptyRowIndicator = ctx.Output(kEmptyRowIndicatorOutput); | 90 | Tensor* emptyRowIndicator = ctx.Output(kEmptyRowIndicatorOutput); |
| 91 | Tensor* reverseIndexMap = ctx.Output(kReverseIndexMapOutput); | 91 | Tensor* reverseIndexMap = ctx.Output(kReverseIndexMapOutput); |
| 92 | 92 | ||
| 93 | - const T defaultValue = reinterpret_cast<T*>(defaultValueTensor->GetData())[0]; | 93 | + const T defaultValue = PtrToPtr<void, T>(defaultValueTensor->GetData())[0]; |
| 94 | const int64_t n = indices->GetTensorShape()->GetDimSize(0); | 94 | const int64_t n = indices->GetTensorShape()->GetDimSize(0); |
| 95 | - const int64_t denseRows = reinterpret_cast<int64_t*>(denseShape->GetData())[0]; | 95 | + const int64_t denseRows = PtrToPtr<void, int64_t>(denseShape->GetData())[0]; |
| 96 | const int64_t rank = indices->GetTensorShape()->GetDimSize(1); | 96 | const int64_t rank = indices->GetTensorShape()->GetDimSize(1); |
| 97 | if (denseRows < 0) { | 97 | if (denseRows < 0) { |
| 98 | KERNEL_LOG_ERROR("dense_shape[0] must be non-negative, but got %ld.", denseRows); | 98 | KERNEL_LOG_ERROR("dense_shape[0] must be non-negative, but got %ld.", denseRows); |
| @@ -114,13 +114,13 @@ KernelStatus SparseFillEmptyRowsCpuKernel::ComputeSparseFillEmptyRows(const CpuK | |||
| 114 | 114 | ||
| 115 | EigenTensor indicesEigen(indices, indices->GetData()); | 115 | EigenTensor indicesEigen(indices, indices->GetData()); |
| 116 | const auto indicesMatrix = indicesEigen.matrix<int64_t>(); | 116 | const auto indicesMatrix = indicesEigen.matrix<int64_t>(); |
| 117 | - auto* valuesData = reinterpret_cast<T*>(values->GetData()); | 117 | + auto* valuesData = PtrToPtr<void, T>(values->GetData()); |
| 118 | - auto* emptyRowIndicatorData = reinterpret_cast<bool*>(emptyRowIndicator->GetData()); | 118 | + auto* emptyRowIndicatorData = PtrToPtr<void, bool>(emptyRowIndicator->GetData()); |
| 119 | - auto* reverseIndexMapData = reinterpret_cast<int64_t*>(reverseIndexMap->GetData()); | 119 | + auto* reverseIndexMapData = PtrToPtr<void, int64_t>(reverseIndexMap->GetData()); |
| 120 | 120 | ||
| 121 | EigenTensor outputIndicesEigen(outputIndices, outputIndices->GetData()); | 121 | EigenTensor outputIndicesEigen(outputIndices, outputIndices->GetData()); |
| 122 | auto outputIndicesMatrix = outputIndicesEigen.matrix<int64_t>(); | 122 | auto outputIndicesMatrix = outputIndicesEigen.matrix<int64_t>(); |
| 123 | - auto* outputValuesData = reinterpret_cast<T*>(outputValues->GetData()); | 123 | + auto* outputValuesData = PtrToPtr<void, T>(outputValues->GetData()); |
| 124 | for (int64_t i = 0; i < n; ++i) { | 124 | for (int64_t i = 0; i < n; ++i) { |
| 125 | const int64_t row = indicesMatrix(i, 0); | 125 | const int64_t row = indicesMatrix(i, 0); |
| 126 | if (row < 0 || row >= denseRows) { | 126 | if (row < 0 || row >= denseRows) { |
| @@ -53,8 +53,8 @@ KernelStatus SparseSegmentSumCpuKernel::SparseSegmentCheck(const CpuKernelContex | |||
| 53 | template <typename T1, typename T2> | 53 | template <typename T1, typename T2> |
| 54 | KernelStatus SparseSegmentSumCpuKernel::SparseSegmentDataCheckWithType(const CpuKernelContext& ctx) const | 54 | KernelStatus SparseSegmentSumCpuKernel::SparseSegmentDataCheckWithType(const CpuKernelContext& ctx) const |
| 55 | { | 55 | { |
| 56 | - auto indices_ptr = reinterpret_cast<T1*>(ctx.Input(1)->GetData()); | 56 | + auto indices_ptr = PtrToPtr<void, T1>(ctx.Input(1)->GetData()); |
| 57 | - auto segment_ids_ptr = reinterpret_cast<T2*>(ctx.Input(2)->GetData()); | 57 | + auto segment_ids_ptr = PtrToPtr<void, T2>(ctx.Input(2)->GetData()); |
| 58 | size_t m = ctx.Input(2)->GetTensorShape()->NumElements(); | 58 | size_t m = ctx.Input(2)->GetTensorShape()->NumElements(); |
| 59 | auto x_dim0 = ctx.Input(0)->GetTensorShape()->GetDimSize(0); | 59 | auto x_dim0 = ctx.Input(0)->GetTensorShape()->GetDimSize(0); |
| 60 | 60 | ||
| @@ -176,10 +176,10 @@ KernelStatus SparseSegmentSumCpuKernel::ComputeKernelWithType(const CpuKernelCon | |||
| 176 | { | 176 | { |
| 177 | size_t n = ctx.Input(0)->GetTensorShape()->NumElements() / ctx.Input(0)->GetTensorShape()->GetDimSize(0); | 177 | size_t n = ctx.Input(0)->GetTensorShape()->NumElements() / ctx.Input(0)->GetTensorShape()->GetDimSize(0); |
| 178 | size_t num_indices = ctx.Input(2)->GetTensorShape()->NumElements(); | 178 | size_t num_indices = ctx.Input(2)->GetTensorShape()->NumElements(); |
| 179 | - auto x_ptr = reinterpret_cast<T*>(ctx.Input(0)->GetData()); | 179 | + auto x_ptr = PtrToPtr<void, T>(ctx.Input(0)->GetData()); |
| 180 | - auto indices_ptr = reinterpret_cast<T1*>(ctx.Input(1)->GetData()); | 180 | + auto indices_ptr = PtrToPtr<void, T1>(ctx.Input(1)->GetData()); |
| 181 | - auto segment_ids_ptr = reinterpret_cast<T2*>(ctx.Input(2)->GetData()); | 181 | + auto segment_ids_ptr = PtrToPtr<void, T2>(ctx.Input(2)->GetData()); |
| 182 | - auto y_ptr = reinterpret_cast<T*>(ctx.Output(0)->GetData()); | 182 | + auto y_ptr = PtrToPtr<void, T>(ctx.Output(0)->GetData()); |
| 183 | if (num_indices == 0) { | 183 | if (num_indices == 0) { |
| 184 | return KERNEL_STATUS_OK; | 184 | return KERNEL_STATUS_OK; |
| 185 | } | 185 | } |
| @@ -498,8 +498,8 @@ uint32_t SparseToDenseCpuKernel::ParallelSetDefaultValue(const CpuKernelContext& | |||
| 498 | const Tensor* outputTensor, int64_t outputSize) | 498 | const Tensor* outputTensor, int64_t outputSize) |
| 499 | { | 499 | { |
| 500 | auto typeSize = GetSizeByDataType(static_cast<DataType>(outputTensor->GetDataType())); | 500 | auto typeSize = GetSizeByDataType(static_cast<DataType>(outputTensor->GetDataType())); |
| 501 | - char* defaultValueAddr = reinterpret_cast<char*>(defaultValueTensor->GetData()); | 501 | + char* defaultValueAddr = PtrToPtr<void, char>(defaultValueTensor->GetData()); |
| 502 | - char* outputAddr = reinterpret_cast<char*>(outputTensor->GetData()); | 502 | + char* outputAddr = PtrToPtr<void, char>(outputTensor->GetData()); |
| 503 | uint32_t minCoreNum = 1; | 503 | uint32_t minCoreNum = 1; |
| 504 | const uint32_t curCoreNum = aicpu::CpuKernelUtils::GetCPUNum(ctx); | 504 | const uint32_t curCoreNum = aicpu::CpuKernelUtils::GetCPUNum(ctx); |
| 505 | const uint32_t availCoreNum = (curCoreNum > kResvCpuNum) ? (curCoreNum - kResvCpuNum) : 0U; | 505 | const uint32_t availCoreNum = (curCoreNum > kResvCpuNum) ? (curCoreNum - kResvCpuNum) : 0U; |
| @@ -541,8 +541,8 @@ uint32_t SparseToDenseCpuKernel::SetDefaultValue(const CpuKernelContext& ctx, co | |||
| 541 | KERNEL_LOG_ERROR("Don't support output tensor types"); | 541 | KERNEL_LOG_ERROR("Don't support output tensor types"); |
| 542 | return KERNEL_STATUS_PARAM_INVALID; | 542 | return KERNEL_STATUS_PARAM_INVALID; |
| 543 | } | 543 | } |
| 544 | - char* defaultValueAddr = reinterpret_cast<char*>(defaultValueTensor->GetData()); | 544 | + char* defaultValueAddr = PtrToPtr<void, char>(defaultValueTensor->GetData()); |
| 545 | - char* outputAddr = reinterpret_cast<char*>(outputTensor->GetData()); | 545 | + char* outputAddr = PtrToPtr<void, char>(outputTensor->GetData()); |
| 546 | if (outputSize < kParallelDataSize) { | 546 | if (outputSize < kParallelDataSize) { |
| 547 | int64_t remainder = outputSize % kCopyDataSize; | 547 | int64_t remainder = outputSize % kCopyDataSize; |
| 548 | int64_t piece = outputSize / kCopyDataSize; | 548 | int64_t piece = outputSize / kCopyDataSize; |
| @@ -596,10 +596,10 @@ uint32_t SparseToDenseCpuKernel::Compute(CpuKernelContext& ctx) | |||
| 596 | size_t outputZeroDimSize = static_cast<size_t>(outputShape->GetDimSize(0)); | 596 | size_t outputZeroDimSize = static_cast<size_t>(outputShape->GetDimSize(0)); |
| 597 | for (size_t index = 0; index < outputZeroDimSize; ++index) { | 597 | for (size_t index = 0; index < outputZeroDimSize; ++index) { |
| 598 | if (shapeTensor->GetDataType() == DT_INT32) { | 598 | if (shapeTensor->GetDataType() == DT_INT32) { |
| 599 | - int32_t* tempDim = reinterpret_cast<int32_t*>(shapeTensor->GetData()); | 599 | + int32_t* tempDim = PtrToPtr<void, int32_t>(shapeTensor->GetData()); |
| 600 | denseShape.emplace_back(static_cast<int64_t>(tempDim[index])); | 600 | denseShape.emplace_back(static_cast<int64_t>(tempDim[index])); |
| 601 | } else { | 601 | } else { |
| 602 | - int64_t* tempDim = reinterpret_cast<int64_t*>(shapeTensor->GetData()); | 602 | + int64_t* tempDim = PtrToPtr<void, int64_t>(shapeTensor->GetData()); |
| 603 | denseShape.emplace_back(tempDim[index]); | 603 | denseShape.emplace_back(tempDim[index]); |
| 604 | } | 604 | } |
| 605 | if (denseShape[index] < 0) { | 605 | if (denseShape[index] < 0) { |