From 692abcbcb53a6038d0db9d9d606e50ac656905cc Mon Sep 17 00:00:00 2001 From: nizhijie Date: Wed, 6 Nov 2024 14:24:03 +0800 Subject: [PATCH 1/3] [Fix](mluOPTensor) Fix double free memory error in tensor.cpp --- core/tensor.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/tensor.cpp b/core/tensor.cpp index ad7234c68..72af32672 100644 --- a/core/tensor.cpp +++ b/core/tensor.cpp @@ -313,7 +313,7 @@ struct mluOpTensorDescriptorQueueStruct { // cleanup headers ~mluOpTensorDescriptorQueueStruct() { for (auto header : headers) { - delete[] header; + free(header); } } @@ -323,15 +323,15 @@ struct mluOpTensorDescriptorQueueStruct { } inline void unlock() { flag.clear(std::memory_order_release); } inline void extend(size_t n) { - mluOpTensorStruct *header = new (std::nothrow) mluOpTensorStruct[n]; + auto header = malloc(sizeof(mluOpTensorStruct) * n); for (size_t i = 0; i < n; ++i) { - queue.push_front(header + i); + queue.push_front((mluOpTensorDescriptor_t)header + i); } headers.push_back(header); } size_t extend_num = 128; std::deque queue; - std::vector headers; + std::vector headers; std::atomic_flag flag = ATOMIC_FLAG_INIT; }; From 9d0ff6a7b224d5c13ce464261ed5ed80bd7efab5 Mon Sep 17 00:00:00 2001 From: nizhijie Date: Tue, 19 Nov 2024 11:01:47 +0800 Subject: [PATCH 2/3] [Feature](mluOpTest): access variable in tensor struct through function in test/* --- .../transpose_cpu/transpose_cpu.cpp | 10 +-- .../src/zoo/bbox_overlaps/bbox_overlaps.cpp | 4 +- .../border_align_backward.cpp | 30 ++++----- .../border_align_forward.cpp | 16 ++--- .../zoo/box_iou_rotated/box_iou_rotated.cpp | 14 ++-- .../dcn_backward_data/dcn_backward_data.cpp | 8 +-- .../dcn_backward_weight.cpp | 58 ++++++++--------- .../src/zoo/dcn_forward/dcn_forward.cpp | 56 ++++++++-------- .../deform_roi_pool_backward.cpp | 10 +-- .../deform_roi_pool_forward.cpp | 14 ++-- ...diff_iou_rotated_sort_vertices_forward.cpp | 6 +- .../mlu_op_gtest/pb_gtest/src/zoo/div/div.cpp | 8 +-- .../dynamic_point_to_voxel_backward.cpp | 4 +- .../dynamic_point_to_voxel_forward.cpp | 8 +-- .../mlu_op_gtest/pb_gtest/src/zoo/fft/fft.cpp | 8 +-- .../generate_proposals_v2.cpp | 18 +++--- .../zoo/get_indice_pairs/get_indice_pairs.cpp | 12 ++-- .../indice_convolution_backward_data.cpp | 64 +++++++++---------- .../indice_convolution_backward_filter.cpp | 44 ++++++------- .../indice_convolution_forward.cpp | 54 ++++++++-------- .../pb_gtest/src/zoo/logspace/logspace.cpp | 2 +- .../masked_col2im_forward.cpp | 10 +-- .../masked_im2col_forward.cpp | 10 +-- .../moe_dispatch_backward_data.cpp | 10 +-- .../moe_dispatch_forward.cpp | 10 +-- .../ms_deform_attn_backward.cpp | 26 ++++---- .../ms_deform_attn_forward.cpp | 36 +++++------ .../mutual_information_backward.cpp | 6 +- .../mutual_information_forward.cpp | 6 +- .../mlu_op_gtest/pb_gtest/src/zoo/nms/nms.cpp | 58 ++++++++--------- .../src/zoo/nms_rotated/nms_rotated.cpp | 6 +- .../zoo/points_in_boxes/points_in_boxes.cpp | 14 ++-- .../pb_gtest/src/zoo/poly_nms/poly_nms.cpp | 4 +- .../pb_gtest/src/zoo/prior_box/prior_box.cpp | 12 ++-- .../zoo/psamask_backward/psamask_backward.cpp | 12 ++-- .../zoo/psamask_forward/psamask_forward.cpp | 12 ++-- .../psroipool_backward/psroipool_backward.cpp | 12 ++-- .../psroipool_forward/psroipool_forward.cpp | 12 ++-- .../roi_align_backward/roi_align_backward.cpp | 36 +++++------ .../roi_align_rotated_backward.cpp | 18 +++--- .../roi_align_rotated_forward.cpp | 18 +++--- .../roi_crop_backward/roi_crop_backward.cpp | 14 ++-- .../zoo/roi_crop_forward/roi_crop_forward.cpp | 14 ++-- .../roi_pooling_backward.cpp | 46 ++++++------- .../roi_pooling_forward.cpp | 2 +- .../zoo/roialign_forward/roialign_forward.cpp | 56 ++++++++-------- .../roiaware_pool3d_backward.cpp | 2 +- .../zoo/roipoint_pool3d/roipoint_pool3d.cpp | 38 +++++------ .../rotated_feature_align_backward.cpp | 10 +-- .../rotated_feature_align_forward.cpp | 10 +-- .../sync_batch_norm_backward_elemt.cpp | 4 +- .../sync_batchnorm_backward_elemt_v2.cpp | 6 +- .../sync_batchnorm_backward_reduce.cpp | 2 +- .../sync_batchnorm_elemt.cpp | 2 +- ...ync_batchnorm_gather_stats_with_counts.cpp | 28 ++++---- .../sync_batchnorm_stats.cpp | 8 +-- .../three_interpolate_backward.cpp | 8 +-- .../three_interpolate_forward.cpp | 8 +-- .../tin_shift_backward/tin_shift_backward.cpp | 12 ++-- .../tin_shift_forward/tin_shift_forward.cpp | 12 ++-- .../src/zoo/voxelization/voxelization.cpp | 10 +-- .../pb_gtest/src/zoo/yolo_box/yolo_box.cpp | 6 +- 62 files changed, 537 insertions(+), 537 deletions(-) diff --git a/test/mlu_op_gtest/pb_gtest/src/internal_kernel/transpose_cpu/transpose_cpu.cpp b/test/mlu_op_gtest/pb_gtest/src/internal_kernel/transpose_cpu/transpose_cpu.cpp index 3a807147d..8065cea76 100644 --- a/test/mlu_op_gtest/pb_gtest/src/internal_kernel/transpose_cpu/transpose_cpu.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/internal_kernel/transpose_cpu/transpose_cpu.cpp @@ -89,7 +89,7 @@ mluOpStatus_t mluOpTransposeCpu(const int64_t dim_desc, PARAM_CHECK("[cnnlTransposeCpu]", y_desc != NULL); uint64_t sum = mluOpGetTensorElementNum(x_desc); // zero elements, return success - if (sum == 0 || x_desc->dim == 0 || y_desc->dim == 0) { + if (sum == 0 || x_desc->getDim() == 0 || y_desc->getDim() == 0) { VLOG(5) << "cnnlTransposeCpu:: zero elements, return success."; return MLUOP_STATUS_SUCCESS; } @@ -97,7 +97,7 @@ mluOpStatus_t mluOpTransposeCpu(const int64_t dim_desc, PARAM_CHECK("[cnnlTransposeCpu]", y != NULL); const uint64_t dim_all = dim_desc; - auto data_type = x_desc->dtype; + auto data_type = x_desc->getDtype(); int loop_d = 1; if (data_type == MLUOP_DTYPE_INT31) { loop_d = 2; @@ -112,17 +112,17 @@ mluOpStatus_t mluOpTransposeCpu(const int64_t dim_desc, uint64_t DIM[TRANSPOSE_MAX_DIM + 1] = {1, 1, 1, 1, 1, 1, 1, 1, 1}; uint64_t dim[TRANSPOSE_MAX_DIM + 1] = {0}; - if (x_desc->dim != dim_all || y_desc->dim != dim_all) { + if (x_desc->getDim() != dim_all || y_desc->getDim() != dim_all) { LOG(ERROR) << "cnnlTransposeCpu: dimension information mismatch, dim of x: " - << x_desc->dim << ", dim of y: " << y_desc->dim + << x_desc->getDim() << ", dim of y: " << y_desc->getDim() << ", dim of descriptor: " << dim_all; return MLUOP_STATUS_BAD_PARAM; } for (int i = 0; i < dim_all; i++) { permute[i] = permute_desc[i]; - DIM[i] = x_desc->dims[i]; + DIM[i] = x_desc->getDimIndex(i); } if (MLUOP_DTYPE_INT31 == data_type) { transposeCpuNd(loop_d, (int16_t *)x, (int16_t *)y, sum, dim, DIM, permute); diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/bbox_overlaps/bbox_overlaps.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/bbox_overlaps/bbox_overlaps.cpp index 696e702c8..8998017fd 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/bbox_overlaps/bbox_overlaps.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/bbox_overlaps/bbox_overlaps.cpp @@ -152,8 +152,8 @@ void BboxOverlapsExecutor::cpuCompute() { auto bbox1_desc = tensor_desc_[0].tensor; auto bbox2_desc = tensor_desc_[1].tensor; - int rows = bbox1_desc->dims[0]; - int cols = bbox2_desc->dims[0]; + int rows = bbox1_desc->getDimIndex(0); + int cols = bbox2_desc->getDimIndex(0); // get struct param int mode = parser_->getProtoNode()->bbox_overlaps_param().mode(); diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/border_align_backward/border_align_backward.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/border_align_backward/border_align_backward.cpp index b68137b24..c76b03475 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/border_align_backward/border_align_backward.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/border_align_backward/border_align_backward.cpp @@ -113,19 +113,19 @@ void BorderAlignBackwardExecutor::cpuCompute() { float *boxes = cpu_fp32_input_[1]; float *argmax_idx = cpu_fp32_input_[2]; float *grad_input = cpu_fp32_output_[0]; - const int32_t box_size = boxes_desc->dims[1]; - const int32_t channels = grad_output_desc->dims[3]; - const int32_t height = grad_input_desc->dims[1]; - const int32_t width = grad_input_desc->dims[2]; - const int32_t N = grad_output_desc->dims[0]; - const int32_t H = grad_output_desc->dims[1]; - const int32_t W = grad_output_desc->dims[2]; - const int32_t C = grad_output_desc->dims[3]; + const int32_t box_size = boxes_desc->getDimIndex(1); + const int32_t channels = grad_output_desc->getDimIndex(3); + const int32_t height = grad_input_desc->getDimIndex(1); + const int32_t width = grad_input_desc->getDimIndex(2); + const int32_t N = grad_output_desc->getDimIndex(0); + const int32_t H = grad_output_desc->getDimIndex(1); + const int32_t W = grad_output_desc->getDimIndex(2); + const int32_t C = grad_output_desc->getDimIndex(3); - const int32_t N1 = grad_input_desc->dims[0]; - const int32_t H1 = grad_input_desc->dims[1]; - const int32_t W1 = grad_input_desc->dims[2]; - const int32_t C1 = grad_input_desc->dims[3]; + const int32_t N1 = grad_input_desc->getDimIndex(0); + const int32_t H1 = grad_input_desc->getDimIndex(1); + const int32_t W1 = grad_input_desc->getDimIndex(2); + const int32_t C1 = grad_input_desc->getDimIndex(3); float x_stride = 0; float y_stride = 0; float stride = 0; @@ -260,9 +260,9 @@ void BorderAlignBackwardExecutor::cpuCompute() { int64_t BorderAlignBackwardExecutor::getTheoryOps() { auto input_desc = parser_->getMetaTensor(0).tensor; auto boxes_desc = parser_->getMetaTensor(1).tensor; - const int32_t N = input_desc->dims[0]; - const int32_t C = input_desc->dims[3] / 4; - const int32_t K = boxes_desc->dims[1]; + const int32_t N = input_desc->getDimIndex(0); + const int32_t C = input_desc->getDimIndex(3) / 4; + const int32_t K = boxes_desc->getDimIndex(1); const int64_t theory_ops = N * K * 4 * C * 3; return theory_ops; diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/border_align_forward/border_align_forward.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/border_align_forward/border_align_forward.cpp index 04560c592..652f87a88 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/border_align_forward/border_align_forward.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/border_align_forward/border_align_forward.cpp @@ -113,11 +113,11 @@ float bilinear_interpolate(const float *input, const int32_t H, const int32_t W, void BorderAlignForwardExecutor::cpuCompute() { auto input_desc = parser_->getMetaTensor(0).tensor; auto boxes_desc = parser_->getMetaTensor(1).tensor; - const int32_t N = input_desc->dims[0]; - const int32_t H = input_desc->dims[1]; - const int32_t W = input_desc->dims[2]; - const int32_t C = input_desc->dims[3] / 4; - const int32_t K = boxes_desc->dims[1]; + const int32_t N = input_desc->getDimIndex(0); + const int32_t H = input_desc->getDimIndex(1); + const int32_t W = input_desc->getDimIndex(2); + const int32_t C = input_desc->getDimIndex(3) / 4; + const int32_t K = boxes_desc->getDimIndex(1); float x1, x2, y1, y2; float x_stride = 0; float y_stride = 0; @@ -195,9 +195,9 @@ void BorderAlignForwardExecutor::cpuCompute() { int64_t BorderAlignForwardExecutor::getTheoryOps() { auto input_desc = parser_->getMetaTensor(0).tensor; auto boxes_desc = parser_->getMetaTensor(1).tensor; - const int32_t N = input_desc->dims[0]; - const int32_t C = input_desc->dims[3] / 4; - const int32_t K = boxes_desc->dims[1]; + const int32_t N = input_desc->getDimIndex(0); + const int32_t C = input_desc->getDimIndex(3) / 4; + const int32_t K = boxes_desc->getDimIndex(1); const int64_t theory_ops = N * K * 4 * C * 14; return theory_ops; diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/box_iou_rotated/box_iou_rotated.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/box_iou_rotated/box_iou_rotated.cpp index f413b8184..c69585364 100755 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/box_iou_rotated/box_iou_rotated.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/box_iou_rotated/box_iou_rotated.cpp @@ -62,8 +62,8 @@ void BoxIouRotatedExecutor::cpuCompute() { auto box1_desc = tensor_desc_[0].tensor; auto box2_desc = tensor_desc_[1].tensor; - auto num_box1 = box1_desc->dims[0]; - auto num_box2 = box2_desc->dims[0]; + auto num_box1 = box1_desc->getDimIndex(0); + auto num_box2 = box2_desc->getDimIndex(0); int mode = parser_->getProtoNode()->box_iou_rotated_param().mode(); bool aligned = parser_->getProtoNode()->box_iou_rotated_param().aligned(); @@ -85,17 +85,17 @@ void BoxIouRotatedExecutor::cpuBoxIouRotated(const T *box1_raw, VLOG(4) << "num box1: " << num_box1; VLOG(4) << "num box2: " << num_box2; if (aligned) { - int num_ious = tensor_desc_[2].tensor->dims[0]; + int num_ious = tensor_desc_[2].tensor->getDimIndex(0); VLOG(4) << "num_ious: " << num_ious; GTEST_CHECK(num_box1 == num_ious, "when aligned, num_box1 should equal to num_ious."); } else { - int num_ious = tensor_desc_[2].tensor->dims[0]; + int num_ious = tensor_desc_[2].tensor->getDimIndex(0); VLOG(4) << "num_ious[0]: " << num_ious; - num_ious = tensor_desc_[2].tensor->dims[1]; + num_ious = tensor_desc_[2].tensor->getDimIndex(1); VLOG(4) << "num_ious[1]: " << num_ious; - GTEST_CHECK(((num_box1 == tensor_desc_[2].tensor->dims[0]) || - (num_box2 == tensor_desc_[2].tensor->dims[1])), + GTEST_CHECK(((num_box1 == tensor_desc_[2].tensor->getDimIndex(0)) || + (num_box2 == tensor_desc_[2].tensor->getDimIndex(1))), "when not aligned, num_ious should equal to num_box1*num_box2"); } diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/dcn_backward_data/dcn_backward_data.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/dcn_backward_data/dcn_backward_data.cpp index 4c3b52779..c601e8c55 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/dcn_backward_data/dcn_backward_data.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/dcn_backward_data/dcn_backward_data.cpp @@ -101,8 +101,8 @@ void DcnBackwardDataExecutor::workspaceMalloc() { grad_offset_desc_ = parser_->outputs()[1].tensor; grad_mask_desc_ = use_grad_mask_ ? parser_->outputs()[2].tensor : nullptr; - grad_output_desc_->onchip_dtype = grad_output_oc_dt_; - weight_desc_->onchip_dtype = weight_oc_dt_; + grad_output_desc_->setOnchipDtype(grad_output_oc_dt_); + weight_desc_->setOnchipDtype(weight_oc_dt_); dcn_desc_ = cpu_runtime_.allocate(mluOpCreateDCNDescriptor, mluOpDestroyDCNDescriptor); @@ -153,8 +153,8 @@ void DcnBackwardDataExecutor::compute() { void *dev_grad_mask = use_mask_ ? data_vector_[6 + use_mask_].device_ptr : nullptr; - grad_output_desc_->onchip_dtype = grad_output_oc_dt_; - weight_desc_->onchip_dtype = weight_oc_dt_; + grad_output_desc_->setOnchipDtype(grad_output_oc_dt_); + weight_desc_->setOnchipDtype(weight_oc_dt_); VLOG(4) << "call mluOpDCNBackwardData()"; interface_timer_.start(); diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/dcn_backward_weight/dcn_backward_weight.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/dcn_backward_weight/dcn_backward_weight.cpp index f8a89520e..647568dc0 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/dcn_backward_weight/dcn_backward_weight.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/dcn_backward_weight/dcn_backward_weight.cpp @@ -163,8 +163,8 @@ void DcnBackwardWeightExecutor::workspaceMalloc() { parser_->getOutputNum() == 1 ? nullptr : tensor_desc_[5].tensor; } - input_desc->onchip_dtype = input_onchip_dtype; - grad_output_desc->onchip_dtype = grad_output_onchip_dtype; + input_desc->setOnchipDtype(input_onchip_dtype); + grad_output_desc->setOnchipDtype(grad_output_onchip_dtype); MLUOP_CHECK(mluOpGetDCNBackwardWeightWorkspaceSize( handle_, dcn_desc, input_desc, offset_desc, mask_desc, grad_output_desc, grad_weight_desc, grad_bias_desc, &workspace_size)); @@ -191,7 +191,7 @@ void DcnBackwardWeightExecutor::compute() { if (dcn_param.has_compute_type()) { compute_type = cvtProtoDtypeToMluOp(dcn_param.compute_type()); } else { - compute_type = input_desc->dtype; + compute_type = input_desc->getDtype(); } mluOpDCNDescriptor_t dcn_desc = cpu_runtime_.allocate( @@ -226,8 +226,8 @@ void DcnBackwardWeightExecutor::compute() { parser_->getOutputNum() == 1 ? nullptr : data_vector_[5].device_ptr; } - input_desc->onchip_dtype = input_onchip_dtype; - grad_output_desc->onchip_dtype = grad_output_onchip_dtype; + input_desc->setOnchipDtype(input_onchip_dtype); + grad_output_desc->setOnchipDtype(grad_output_onchip_dtype); VLOG(4) << "call mluOpDCNBackwardWeight()"; interface_timer_.start(); @@ -444,15 +444,15 @@ void DcnBackwardWeightExecutor::computeDCNBackwardWeightCPU( const mluOpTensorDescriptor_t grad_bias_desc, void *cpu_grad_bias, float *buffer, int pad[], int stride[], int dilation[], int64_t &theory_ops) { - const int N = input_desc->dims[0]; - const int hi = input_desc->dims[1]; - const int wi = input_desc->dims[2]; - const int ci = input_desc->dims[3]; - const int ho = offset_desc->dims[1]; - const int wo = offset_desc->dims[2]; - const int co = grad_output_desc->dims[3]; - const int kh = grad_weight_desc->dims[1]; - const int kw = grad_weight_desc->dims[2]; + const int N = input_desc->getDimIndex(0); + const int hi = input_desc->getDimIndex(1); + const int wi = input_desc->getDimIndex(2); + const int ci = input_desc->getDimIndex(3); + const int ho = offset_desc->getDimIndex(1); + const int wo = offset_desc->getDimIndex(2); + const int co = grad_output_desc->getDimIndex(3); + const int kh = grad_weight_desc->getDimIndex(1); + const int kw = grad_weight_desc->getDimIndex(2); const int pt = pad[0]; const int pb = pad[1]; const int pl = pad[2]; @@ -579,12 +579,12 @@ void DcnBackwardWeightExecutor::cpuCompute() { parser_->getOutputNum() == 1 ? nullptr : cpu_fp32_output_[1]; } - const int ho = offset_desc->dims[1]; - const int wo = offset_desc->dims[2]; - const int kh = grad_weight_desc->dims[1]; - const int kw = grad_weight_desc->dims[2]; - const int ci = input_desc->dims[3]; - const int co = grad_output_desc->dims[3]; + const int ho = offset_desc->getDimIndex(1); + const int wo = offset_desc->getDimIndex(2); + const int kh = grad_weight_desc->getDimIndex(1); + const int kw = grad_weight_desc->getDimIndex(2); + const int ci = input_desc->getDimIndex(3); + const int co = grad_output_desc->getDimIndex(3); size_t cpu_buffer_size = 0; if (g == 1) { @@ -634,15 +634,15 @@ int64_t DcnBackwardWeightExecutor::getTheoryOps() { grad_bias_desc = parser_->getOutputNum() == 1 ? nullptr : tensor_desc_[5].tensor; } - const int N = input_desc->dims[0]; - const int hi = input_desc->dims[1]; - const int wi = input_desc->dims[2]; - const int ci = input_desc->dims[3]; - const int ho = offset_desc->dims[1]; - const int wo = offset_desc->dims[2]; - const int co = grad_output_desc->dims[3]; - const int kh = grad_weight_desc->dims[1]; - const int kw = grad_weight_desc->dims[2]; + const int N = input_desc->getDimIndex(0); + const int hi = input_desc->getDimIndex(1); + const int wi = input_desc->getDimIndex(2); + const int ci = input_desc->getDimIndex(3); + const int ho = offset_desc->getDimIndex(1); + const int wo = offset_desc->getDimIndex(2); + const int co = grad_output_desc->getDimIndex(3); + const int kh = grad_weight_desc->getDimIndex(1); + const int kw = grad_weight_desc->getDimIndex(2); int coeff = getCoefficientOfLT2CT(); const int k = im2col_step * ho * wo; const int m = co / g; diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/dcn_forward/dcn_forward.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/dcn_forward/dcn_forward.cpp index 39d56f13e..47803de4a 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/dcn_forward/dcn_forward.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/dcn_forward/dcn_forward.cpp @@ -158,8 +158,8 @@ void DcnForwardExecutor::workspaceMalloc() { output_desc = tensor_desc_[5].tensor; } - input_desc->onchip_dtype = input_onchip_dtype; - weight_desc->onchip_dtype = weight_onchip_dtype; + input_desc->setOnchipDtype(input_onchip_dtype); + weight_desc->setOnchipDtype(weight_onchip_dtype); MLUOP_CHECK(mluOpGetDCNForwardWorkspaceSize( handle_, dcn_desc, input_desc, offset_desc, mask_desc, weight_desc, @@ -236,8 +236,8 @@ void DcnForwardExecutor::compute() { output = data_vector_[5].device_ptr; } - input_desc->onchip_dtype = input_onchip_dtype; - weight_desc->onchip_dtype = weight_onchip_dtype; + input_desc->setOnchipDtype(input_onchip_dtype); + weight_desc->setOnchipDtype(weight_onchip_dtype); VLOG(4) << "call mluOpDCNForward()"; interface_timer_.start(); @@ -447,15 +447,15 @@ void DcnForwardExecutor::computeDCNForwardCPU( const mluOpTensorDescriptor_t output_desc, const void *cpu_output, float *buffer, int pad[], int stride[], int dilation[], int64_t &theory_ops) { - const int N = input_desc->dims[0]; - const int hi = input_desc->dims[1]; - const int wi = input_desc->dims[2]; - const int ci = input_desc->dims[3]; - const int ho = offset_desc->dims[1]; - const int wo = offset_desc->dims[2]; - const int co = output_desc->dims[3]; - const int kh = weight_desc->dims[1]; - const int kw = weight_desc->dims[2]; + const int N = input_desc->getDimIndex(0); + const int hi = input_desc->getDimIndex(1); + const int wi = input_desc->getDimIndex(2); + const int ci = input_desc->getDimIndex(3); + const int ho = offset_desc->getDimIndex(1); + const int wo = offset_desc->getDimIndex(2); + const int co = output_desc->getDimIndex(3); + const int kh = weight_desc->getDimIndex(1); + const int kw = weight_desc->getDimIndex(2); const int pt = pad[0]; const int pb = pad[1]; const int pl = pad[2]; @@ -594,12 +594,12 @@ void DcnForwardExecutor::cpuCompute() { cpu_output = cpu_fp32_output_[0]; } - const int ho = offset_desc->dims[1]; - const int wo = offset_desc->dims[2]; - const int kh = weight_desc->dims[1]; - const int kw = weight_desc->dims[2]; - const int ci = input_desc->dims[3]; - const int co = output_desc->dims[3]; + const int ho = offset_desc->getDimIndex(1); + const int wo = offset_desc->getDimIndex(2); + const int kh = weight_desc->getDimIndex(1); + const int kw = weight_desc->getDimIndex(2); + const int ci = input_desc->getDimIndex(3); + const int co = output_desc->getDimIndex(3); size_t cpu_buffer_size = 0; if (g == 1) { @@ -652,15 +652,15 @@ int64_t DcnForwardExecutor::getTheoryOps() { output_desc = tensor_desc_[5].tensor; } - const int N = input_desc->dims[0]; - const int hi = input_desc->dims[1]; - const int wi = input_desc->dims[2]; - const int ci = input_desc->dims[3]; - const int ho = offset_desc->dims[1]; - const int wo = offset_desc->dims[2]; - const int co = output_desc->dims[3]; - const int kh = weight_desc->dims[1]; - const int kw = weight_desc->dims[2]; + const int N = input_desc->getDimIndex(0); + const int hi = input_desc->getDimIndex(1); + const int wi = input_desc->getDimIndex(2); + const int ci = input_desc->getDimIndex(3); + const int ho = offset_desc->getDimIndex(1); + const int wo = offset_desc->getDimIndex(2); + const int co = output_desc->getDimIndex(3); + const int kh = weight_desc->getDimIndex(1); + const int kw = weight_desc->getDimIndex(2); int coeff = getCoefficientOfLT2CT(); const int k = kh * kw * ci / g; const int m = im2col_step * ho * wo; diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/deform_roi_pool_backward/deform_roi_pool_backward.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/deform_roi_pool_backward/deform_roi_pool_backward.cpp index b69975e44..47af02fb2 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/deform_roi_pool_backward/deform_roi_pool_backward.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/deform_roi_pool_backward/deform_roi_pool_backward.cpp @@ -58,11 +58,11 @@ void DeformRoiPoolBackwardExecutor::initData() { grad_input_desc = tensor_desc_[3].tensor; } - batchs = input_desc->dims[0]; - height = input_desc->dims[1]; - width = input_desc->dims[2]; - channels = input_desc->dims[3]; - rois_num = rois_desc->dims[0]; + batchs = input_desc->getDimIndex(0); + height = input_desc->getDimIndex(1); + width = input_desc->getDimIndex(2); + channels = input_desc->getDimIndex(3); + rois_num = rois_desc->getDimIndex(0); // get params auto deform_roi_pool_backward_proto_desc = diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/deform_roi_pool_forward/deform_roi_pool_forward.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/deform_roi_pool_forward/deform_roi_pool_forward.cpp index 8b16e5161..cd4b7f99c 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/deform_roi_pool_forward/deform_roi_pool_forward.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/deform_roi_pool_forward/deform_roi_pool_forward.cpp @@ -52,13 +52,13 @@ void DeformRoiPoolForwardExecutor::initData() { output_desc = tensor_desc_[2].tensor; } - batchs = input_desc->dims[0]; - height = input_desc->dims[1]; - width = input_desc->dims[2]; - channels = input_desc->dims[3]; - rois_num = rois_desc->dims[0]; - pooled_height = output_desc->dims[1]; - pooled_width = output_desc->dims[2]; + batchs = input_desc->getDimIndex(0); + height = input_desc->getDimIndex(1); + width = input_desc->getDimIndex(2); + channels = input_desc->getDimIndex(3); + rois_num = rois_desc->getDimIndex(0); + pooled_height = output_desc->getDimIndex(1); + pooled_width = output_desc->getDimIndex(2); // get params auto deform_roi_pool_forward_proto_desc = parser_->getProtoNode()->deform_roi_pool_forward_param(); diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/diff_iou_rotated_sort_vertices_forward/diff_iou_rotated_sort_vertices_forward.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/diff_iou_rotated_sort_vertices_forward/diff_iou_rotated_sort_vertices_forward.cpp index 41bfbd9e0..1e8fe8a9f 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/diff_iou_rotated_sort_vertices_forward/diff_iou_rotated_sort_vertices_forward.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/diff_iou_rotated_sort_vertices_forward/diff_iou_rotated_sort_vertices_forward.cpp @@ -98,9 +98,9 @@ void DiffIouRotatedSortVerticesForwardExecutor::cpuCompute() { float *data_idx = (float *)cpu_fp32_output_[0]; auto vertices_desc = tensor_desc_[0].tensor; - int dim_b = vertices_desc->dims[0]; - int dim_n = vertices_desc->dims[1]; - int dim_m = vertices_desc->dims[2]; + int dim_b = vertices_desc->getDimIndex(0); + int dim_n = vertices_desc->getDimIndex(1); + int dim_m = vertices_desc->getDimIndex(2); memset(data_idx, 0, dim_b*dim_n*9 * sizeof(int)); for (int bi = 0; bi < dim_b; ++bi) { diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/div/div.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/div/div.cpp index e54ea793a..d8648bdd5 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/div/div.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/div/div.cpp @@ -63,11 +63,11 @@ void DivExecutor::cpuCompute() { auto c_desc = tensor_desc_[2].tensor; float *a_broadcast = (float *)cpu_runtime_.allocate(count3 * sizeof(float)); float *b_broadcast = (float *)cpu_runtime_.allocate(count3 * sizeof(float)); - expand_compute_cpu(std::vector(a_desc->dims, a_desc->dims + a_desc->dim), - std::vector(c_desc->dims, c_desc->dims + c_desc->dim), + expand_compute_cpu(std::vector(a_desc->getDims(), a_desc->getDims() + a_desc->getDim()), + std::vector(c_desc->getDims(), c_desc->getDims() + c_desc->getDim()), cpu_fp32_input_[0], a_broadcast); - expand_compute_cpu(std::vector(b_desc->dims, b_desc->dims + b_desc->dim), - std::vector(c_desc->dims, c_desc->dims + c_desc->dim), + expand_compute_cpu(std::vector(b_desc->getDims(), b_desc->getDims() + b_desc->getDim()), + std::vector(c_desc->getDims(), c_desc->getDims() + c_desc->getDim()), cpu_fp32_input_[1], b_broadcast); for (size_t i = 0; i < count3; ++i) { diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/dynamic_point_to_voxel_backward/dynamic_point_to_voxel_backward.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/dynamic_point_to_voxel_backward/dynamic_point_to_voxel_backward.cpp index efc852b34..cc8d1fb04 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/dynamic_point_to_voxel_backward/dynamic_point_to_voxel_backward.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/dynamic_point_to_voxel_backward/dynamic_point_to_voxel_backward.cpp @@ -119,8 +119,8 @@ void DynamicPointToVoxelBackwardExecutor::cpuCompute() { auto feats_desc = tensor_desc_[1].tensor; int M = voxel_num[0]; - int C = feats_desc->dims[1]; - int N = feats_desc->dims[0]; + int C = feats_desc->getDimIndex(1); + int N = feats_desc->getDimIndex(0); VLOG(5) << "M=" << M; VLOG(5) << "C=" << C; VLOG(5) << "N=" << N; diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/dynamic_point_to_voxel_forward/dynamic_point_to_voxel_forward.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/dynamic_point_to_voxel_forward/dynamic_point_to_voxel_forward.cpp index fa65a5b27..81dcef23a 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/dynamic_point_to_voxel_forward/dynamic_point_to_voxel_forward.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/dynamic_point_to_voxel_forward/dynamic_point_to_voxel_forward.cpp @@ -117,9 +117,9 @@ void DynamicPointToVoxelForwardExecutor::cpuCompute() { auto coors = cpu_fp32_input_[1]; auto feats_desc = tensor_desc_[0].tensor; auto coors_desc = tensor_desc_[1].tensor; - const int32_t N = coors_desc->dims[0]; - const int32_t num_coors = coors_desc->dims[1]; - const int32_t num_features = feats_desc->dims[1]; + const int32_t N = coors_desc->getDimIndex(0); + const int32_t num_coors = coors_desc->getDimIndex(1); + const int32_t num_features = feats_desc->getDimIndex(1); // Get output auto voxel_feats = cpu_fp32_output_[0]; @@ -224,7 +224,7 @@ void DynamicPointToVoxelForwardExecutor::cpuCompute() { // 5. Calculate voxel_feats const float fill_value = reduce_mode == REDUCE_MODE_MAX ? -1.17549e038 : 0x0; - for (int32_t i = 0; i < voxel_feats_desc->dims[0] * num_features; ++i) { + for (int32_t i = 0; i < voxel_feats_desc->getDimIndex(0) * num_features; ++i) { voxel_feats[i] = fill_value; } diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/fft/fft.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/fft/fft.cpp index d623ce2c5..56e5608a6 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/fft/fft.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/fft/fft.cpp @@ -96,8 +96,8 @@ int64_t FftExecutor::getTheoryOps() { auto fft_param = parser_->getProtoNode()->fft_param(); int rank = fft_param.rank(); int bc = 1; - if (input_tensor->dim != rank) { - bc = input_tensor->dims[0]; + if (input_tensor->getDim() != rank) { + bc = input_tensor->getDimIndex(0); } int n = fft_param.n(0); @@ -129,8 +129,8 @@ int64_t FftExecutor::getTheoryIoSize() { auto fft_param = parser_->getProtoNode()->fft_param(); int rank = fft_param.rank(); int bc = 1; - if (input_tensor->dim != rank) { - bc = input_tensor->dims[0]; + if (input_tensor->getDim() != rank) { + bc = input_tensor->getDimIndex(0); } int n = fft_param.n(0); diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/generate_proposals_v2/generate_proposals_v2.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/generate_proposals_v2/generate_proposals_v2.cpp index da8a3d91a..d75cd7605 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/generate_proposals_v2/generate_proposals_v2.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/generate_proposals_v2/generate_proposals_v2.cpp @@ -156,10 +156,10 @@ void GenerateProposalsV2Executor::cpuCompute() { auto tensor_scores = parser_->getMetaTensor("input1").tensor; - const int N = tensor_scores->dims[0]; - const int H = tensor_scores->dims[1]; - const int W = tensor_scores->dims[2]; - const int A = tensor_scores->dims[3]; + const int N = tensor_scores->getDimIndex(0); + const int H = tensor_scores->getDimIndex(1); + const int W = tensor_scores->getDimIndex(2); + const int A = tensor_scores->getDimIndex(3); auto scores_ptr = parser_->getMetaTensor("input1").cpu_ptr; auto deltas_ptr = parser_->getMetaTensor("input2").cpu_ptr; @@ -183,12 +183,12 @@ void GenerateProposalsV2Executor::cpuCompute() { int64_t GenerateProposalsV2Executor::getTheoryOps() { VLOG(4) << "getTheoryOps"; - // int dims = parser_->getMetaTensor("input1").tensor->dims[0]; + // int dims = parser_->getMetaTensor("input1").tensor->getDimIndex(0); auto tensor_scores = parser_->getMetaTensor("input1").tensor; - const int N = tensor_scores->dims[0]; - const int H = tensor_scores->dims[1]; - const int W = tensor_scores->dims[2]; - const int A = tensor_scores->dims[3]; + const int N = tensor_scores->getDimIndex(0); + const int H = tensor_scores->getDimIndex(1); + const int W = tensor_scores->getDimIndex(2); + const int A = tensor_scores->getDimIndex(3); int64_t theory_ops = 39 * N * A * H * W; VLOG(4) << "getTheoryOps: " << theory_ops << " ops"; return theory_ops; diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/get_indice_pairs/get_indice_pairs.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/get_indice_pairs/get_indice_pairs.cpp index f86bd82a3..51e2bcafd 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/get_indice_pairs/get_indice_pairs.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/get_indice_pairs/get_indice_pairs.cpp @@ -139,7 +139,7 @@ void GetIndicePairsExecutor::castIn() { void GetIndicePairsExecutor::diffPreprocess() { float *cpu_input = (float *)cpu_fp32_output_[1]; - int32_t input_active_in = indice_pairs_desc_->dims[2]; + int32_t input_active_in = indice_pairs_desc_->getDimIndex(2); int32_t kernel_volume = 1; for (int i = 0; i < filter_space_.size(); i++) { kernel_volume *= filter_space_[i]; @@ -294,7 +294,7 @@ void GetIndicePairsExecutor::cpuGetIndicePairs( std::vector out_spatail_shape, const int32_t dimNb, const int32_t sub_m, const int32_t batch_size) { int32_t num_act = 0; - int32_t num_act_in = indice_in_desc->dims[0]; + int32_t num_act_in = indice_in_desc->getDimIndex(0); int32_t batch_idx = 0; int32_t spatail_volume = 1; int32_t NDim = dimNb - 2; @@ -406,8 +406,8 @@ void GetIndicePairsExecutor::cpuGetIndicePairs( } int64_t GetIndicePairsExecutor::getTheoryOps() { - int64_t kernel_volume = indice_pairs_desc_->dims[0]; - int64_t active_input_in = indice_pairs_desc_->dims[2]; + int64_t kernel_volume = indice_pairs_desc_->getDimIndex(0); + int64_t active_input_in = indice_pairs_desc_->getDimIndex(2); int64_t dims = dimNb_ - 2 + 1; int64_t total_op_size = 0; int64_t kernel1_op_size = 0, kernel2_op_size = 0, kernel3_op_size = 0, @@ -450,8 +450,8 @@ int64_t GetIndicePairsExecutor::getTheoryOps() { } int64_t GetIndicePairsExecutor::getTheoryIoSize() { - int64_t kernel_volume = indice_pairs_desc_->dims[0]; - int64_t active_input_in = indice_pairs_desc_->dims[2]; + int64_t kernel_volume = indice_pairs_desc_->getDimIndex(0); + int64_t active_input_in = indice_pairs_desc_->getDimIndex(2); int64_t dims = dimNb_ - 2 + 1; int64_t total_io_size = 0; int64_t kernel1_io_size = 0, kernel2_io_size = 0, kernel3_io_size = 0, diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/indice_convolution_backward_data/indice_convolution_backward_data.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/indice_convolution_backward_data/indice_convolution_backward_data.cpp index 2e3aa4930..12903b56e 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/indice_convolution_backward_data/indice_convolution_backward_data.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/indice_convolution_backward_data/indice_convolution_backward_data.cpp @@ -30,44 +30,44 @@ namespace mluoptest { void IndiceConvolutionBackwardDataExecutor::getFilterDims() { const mluOpTensorDescriptor_t filters_desc = tensor_desc_[1].tensor; - const mluOpTensorLayout_t layout = filters_desc->layout; + const mluOpTensorLayout_t layout = filters_desc->getLayout(); kd = 1; filter_4d = true; if (layout == MLUOP_LAYOUT_NCHW) { - dyc = filters_desc->dims[0]; - dxc = filters_desc->dims[1]; - kh = filters_desc->dims[2]; - kw = filters_desc->dims[3]; + dyc = filters_desc->getDimIndex(0); + dxc = filters_desc->getDimIndex(1); + kh = filters_desc->getDimIndex(2); + kw = filters_desc->getDimIndex(3); } else if (layout == MLUOP_LAYOUT_NHWC) { - dyc = filters_desc->dims[0]; - dxc = filters_desc->dims[3]; - kh = filters_desc->dims[1]; - kw = filters_desc->dims[2]; + dyc = filters_desc->getDimIndex(0); + dxc = filters_desc->getDimIndex(3); + kh = filters_desc->getDimIndex(1); + kw = filters_desc->getDimIndex(2); } else if (layout == MLUOP_LAYOUT_HWCN) { - dyc = filters_desc->dims[3]; - dxc = filters_desc->dims[2]; - kh = filters_desc->dims[0]; - kw = filters_desc->dims[1]; + dyc = filters_desc->getDimIndex(3); + dxc = filters_desc->getDimIndex(2); + kh = filters_desc->getDimIndex(0); + kw = filters_desc->getDimIndex(1); } else if (layout == MLUOP_LAYOUT_NDHWC) { - dyc = filters_desc->dims[0]; - dxc = filters_desc->dims[4]; - kd = filters_desc->dims[1]; - kh = filters_desc->dims[2]; - kw = filters_desc->dims[3]; + dyc = filters_desc->getDimIndex(0); + dxc = filters_desc->getDimIndex(4); + kd = filters_desc->getDimIndex(1); + kh = filters_desc->getDimIndex(2); + kw = filters_desc->getDimIndex(3); filter_4d = false; } else if (layout == MLUOP_LAYOUT_NCDHW) { - dyc = filters_desc->dims[0]; - dxc = filters_desc->dims[1]; - kd = filters_desc->dims[2]; - kh = filters_desc->dims[3]; - kw = filters_desc->dims[4]; + dyc = filters_desc->getDimIndex(0); + dxc = filters_desc->getDimIndex(1); + kd = filters_desc->getDimIndex(2); + kh = filters_desc->getDimIndex(3); + kw = filters_desc->getDimIndex(4); filter_4d = false; } else if (layout == MLUOP_LAYOUT_ARRAY) { - dyc = filters_desc->dims[4]; - dxc = filters_desc->dims[3]; - kd = filters_desc->dims[0]; - kh = filters_desc->dims[1]; - kw = filters_desc->dims[2]; + dyc = filters_desc->getDimIndex(4); + dxc = filters_desc->getDimIndex(3); + kd = filters_desc->getDimIndex(0); + kh = filters_desc->getDimIndex(1); + kw = filters_desc->getDimIndex(2); filter_4d = false; } } @@ -262,7 +262,7 @@ void IndiceConvolutionBackwardDataExecutor::cpuCompute() { int K = kd * kh * kw; int filter_num = K * dyc * dxc; const mluOpTensorDescriptor_t filters_desc = tensor_desc_[1].tensor; - const mluOpTensorLayout_t layout = filters_desc->layout; + const mluOpTensorLayout_t layout = filters_desc->getLayout(); float *filter_transpose_cpu; if (!(layout == MLUOP_LAYOUT_HWCN)) { filter_transpose_cpu = @@ -282,17 +282,17 @@ void IndiceConvolutionBackwardDataExecutor::cpuCompute() { // get index pair param const mluOpTensorDescriptor_t indice_pairs_desc = tensor_desc_[2].tensor; - int L = indice_pairs_desc->dims[2]; + int L = indice_pairs_desc->getDimIndex(2); // main calculation // set input data to 0 int input_grad_data_count = parser_->getOutputDataCount(0); memset(cpu_fp32_output_[0], 0x00, - mluOpDataTypeBytes(indice_pairs_desc->dtype) * input_grad_data_count); + mluOpDataTypeBytes(indice_pairs_desc->getDtype()) * input_grad_data_count); float *output_grad = cpu_fp32_input_[0]; float *indice_pairs = cpu_fp32_input_[2]; float *input_grad = cpu_fp32_output_[0]; - bool is_float = (filters_desc->dtype == MLUOP_DTYPE_FLOAT); + bool is_float = (filters_desc->getDtype() == MLUOP_DTYPE_FLOAT); for (int i = 0; i < input_grad_data_count; ++i) { input_grad[i] = 0; } diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/indice_convolution_backward_filter/indice_convolution_backward_filter.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/indice_convolution_backward_filter/indice_convolution_backward_filter.cpp index e38c7e602..c35aa7229 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/indice_convolution_backward_filter/indice_convolution_backward_filter.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/indice_convolution_backward_filter/indice_convolution_backward_filter.cpp @@ -42,7 +42,7 @@ void IndiceConvolutionBackwardFilterExecutor::initParam() { subm_ = op_param.sub_m(); diffw_trans_ = false; - // if (MLUOP_LAYOUT_HWCN != diffw_desc_->layout) { + // if (MLUOP_LAYOUT_HWCN != diffw_desc_->getLayout()) { // diffw_trans_ = true; // } } @@ -131,14 +131,14 @@ void IndiceConvolutionBackwardFilterExecutor::cpuCompute() { } if (diffw_trans_) { - temp_diffw = (float *)cpu_runtime_.allocate(diffw_desc_->total_element_num * + temp_diffw = (float *)cpu_runtime_.allocate(diffw_desc_->getTotalElementNum() * sizeof(float)); } - int64_t in_active_num = input_indice_desc_->dims[0]; - int64_t ci = input_indice_desc_->dims[1]; - int64_t co = diffy_indice_desc_->dims[1]; - int64_t kd = diffw_desc_->dim == 4 ? 1 : mluOpGetTensordimD(diffw_desc_); + int64_t in_active_num = input_indice_desc_->getDimIndex(0); + int64_t ci = input_indice_desc_->getDimIndex(1); + int64_t co = diffy_indice_desc_->getDimIndex(1); + int64_t kd = diffw_desc_->getDim() == 4 ? 1 : mluOpGetTensordimD(diffw_desc_); int64_t kh = mluOpGetTensordimH(diffw_desc_); int64_t kw = mluOpGetTensordimH(diffw_desc_); int64_t kernel_volume = kd * kh * kw; @@ -169,7 +169,7 @@ void IndiceConvolutionBackwardFilterExecutor::cpuCompute() { } // trans if (diffw_trans_) { - cpuTranspose(diffw, temp_diffw, kernel_volume, ci, co, diffw_desc_->layout); + cpuTranspose(diffw, temp_diffw, kernel_volume, ci, co, diffw_desc_->getLayout()); cpu_runtime_.deallocate(temp_diffw); } @@ -177,13 +177,13 @@ void IndiceConvolutionBackwardFilterExecutor::cpuCompute() { } int64_t IndiceConvolutionBackwardFilterExecutor::getTheoryOps() { - int64_t ci = input_indice_desc_->dims[1]; - int64_t co = diffy_indice_desc_->dims[1]; - int64_t kernel_volume = indice_pair_desc_->dims[0]; + int64_t ci = input_indice_desc_->getDimIndex(1); + int64_t co = diffy_indice_desc_->getDimIndex(1); + int64_t kernel_volume = indice_pair_desc_->getDimIndex(0); int64_t total_ops = 0; // fill theory ops - total_ops += diffw_desc_->total_tensor_size; + total_ops += diffw_desc_->getTotalTensorSize(); for (int64_t i = 0; i < kernel_volume; ++i) { if (indice_num_[0] <= 0) { continue; @@ -194,27 +194,27 @@ int64_t IndiceConvolutionBackwardFilterExecutor::getTheoryOps() { } // transpose theory ops if (diffw_trans_) { - total_ops += diffw_desc_->total_element_num; + total_ops += diffw_desc_->getTotalElementNum(); } return total_ops; } int64_t IndiceConvolutionBackwardFilterExecutor::getTheoryIoSize() { int32_t *indice_pair = (int32_t *)(data_vector_[2].host_ptr); - int64_t ci = input_indice_desc_->dims[1]; - int64_t co = diffy_indice_desc_->dims[1]; - int64_t in_active_num = input_indice_desc_->dims[0]; - int64_t kernel_volume = indice_pair_desc_->dims[0]; + int64_t ci = input_indice_desc_->getDimIndex(1); + int64_t co = diffy_indice_desc_->getDimIndex(1); + int64_t in_active_num = input_indice_desc_->getDimIndex(0); + int64_t kernel_volume = indice_pair_desc_->getDimIndex(0); int64_t theory_ios = 0; size_t input_indice_dwidth, diffy_indice_dwidth, indice_pair_dwidth, diffw_dwidth; MLUOP_CHECK( - mluOpGetSizeOfDataType(input_indice_desc_->dtype, &input_indice_dwidth)); + mluOpGetSizeOfDataType(input_indice_desc_->getDtype(), &input_indice_dwidth)); MLUOP_CHECK( - mluOpGetSizeOfDataType(diffy_indice_desc_->dtype, &diffy_indice_dwidth)); + mluOpGetSizeOfDataType(diffy_indice_desc_->getDtype(), &diffy_indice_dwidth)); MLUOP_CHECK( - mluOpGetSizeOfDataType(indice_pair_desc_->dtype, &indice_pair_dwidth)); - MLUOP_CHECK(mluOpGetSizeOfDataType(diffw_desc_->dtype, &diffw_dwidth)); + mluOpGetSizeOfDataType(indice_pair_desc_->getDtype(), &indice_pair_dwidth)); + MLUOP_CHECK(mluOpGetSizeOfDataType(diffw_desc_->getDtype(), &diffw_dwidth)); auto gather_nd_ios = [&](const int64_t kernel_index, const int64_t gather_num, const int64_t channel, @@ -237,7 +237,7 @@ int64_t IndiceConvolutionBackwardFilterExecutor::getTheoryIoSize() { }; // fill theory ios - theory_ios += diffw_desc_->total_tensor_size; + theory_ios += diffw_desc_->getTotalTensorSize(); for (int64_t i = 0; i < kernel_volume; ++i) { if (indice_num_[i] <= 0) { @@ -254,7 +254,7 @@ int64_t IndiceConvolutionBackwardFilterExecutor::getTheoryIoSize() { } // transpose theory ios if (diffw_trans_) { - theory_ios += diffw_desc_->total_tensor_size * 2; + theory_ios += diffw_desc_->getTotalTensorSize() * 2; } return theory_ios; diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/indice_convolution_forward/indice_convolution_forward.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/indice_convolution_forward/indice_convolution_forward.cpp index 61a80277e..70e39733a 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/indice_convolution_forward/indice_convolution_forward.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/indice_convolution_forward/indice_convolution_forward.cpp @@ -95,10 +95,10 @@ void IndiceConvolutionForwardExecutor::cpuCompute() { return; // skip zero element } - int64_t num_active_in = features_desc_->dims[0]; - int64_t ci = features_desc_->dims[1]; - int64_t co = features_out_desc_->dims[1]; - bool filters_need_transpose = filters_desc_->layout != MLUOP_LAYOUT_ARRAY; + int64_t num_active_in = features_desc_->getDimIndex(0); + int64_t ci = features_desc_->getDimIndex(1); + int64_t co = features_out_desc_->getDimIndex(1); + bool filters_need_transpose = filters_desc_->getLayout() != MLUOP_LAYOUT_ARRAY; int64_t kd = 0; int64_t kh = 0; int64_t kw = 0; @@ -107,9 +107,9 @@ void IndiceConvolutionForwardExecutor::cpuCompute() { kh = mluOpGetTensordimH(filters_desc_); kw = mluOpGetTensordimW(filters_desc_); } else { - kd = filters_desc_->dims[0]; - kh = filters_desc_->dims[1]; - kw = filters_desc_->dims[2]; + kd = filters_desc_->getDimIndex(0); + kh = filters_desc_->getDimIndex(1); + kw = filters_desc_->getDimIndex(2); } int64_t num_filters = kd * kh * kw; @@ -117,12 +117,12 @@ void IndiceConvolutionForwardExecutor::cpuCompute() { float *filters_transed = filters; if (filters_need_transpose) { filters_transed = (float *)cpu_runtime_.allocate( - filters_desc_->total_element_num * sizeof(float)); - if (filters_desc_->layout == MLUOP_LAYOUT_NCDHW) { + filters_desc_->getTotalElementNum() * sizeof(float)); + if (filters_desc_->getLayout() == MLUOP_LAYOUT_NCDHW) { stride[0] = 1; stride[1] = num_filters; stride[2] = num_filters * ci; - } else if (filters_desc_->layout == MLUOP_LAYOUT_NDHWC) { + } else if (filters_desc_->getLayout() == MLUOP_LAYOUT_NDHWC) { stride[0] = ci; stride[1] = 1; stride[2] = ci * num_filters; @@ -142,7 +142,7 @@ void IndiceConvolutionForwardExecutor::cpuCompute() { int32_t features_out_data_count = parser_->getOutputDataCount(0); memset( cpu_fp32_output_[0], 0x00, - mluOpDataTypeBytes(features_out_desc_->dtype) * features_out_data_count); + mluOpDataTypeBytes(features_out_desc_->getDtype()) * features_out_data_count); for (int64_t kdi = 0; kdi < kd; ++kdi) { for (int64_t khi = 0; khi < kh; ++khi) { @@ -175,13 +175,13 @@ void IndiceConvolutionForwardExecutor::cpuCompute() { } int64_t IndiceConvolutionForwardExecutor::getTheoryOps() { - int64_t ci = features_desc_->dims[1]; - int64_t co = features_out_desc_->dims[1]; - int64_t num_filters = indice_pairs_desc_->dims[0]; + int64_t ci = features_desc_->getDimIndex(1); + int64_t co = features_out_desc_->getDimIndex(1); + int64_t num_filters = indice_pairs_desc_->getDimIndex(0); int64_t total_ops = 0; // initialize output to 0 - total_ops += features_out_desc_->total_element_num; + total_ops += features_out_desc_->getTotalElementNum(); for (int64_t i = 0; i < num_filters; ++i) { if (indice_num_[i] < 0) { continue; @@ -196,27 +196,27 @@ int64_t IndiceConvolutionForwardExecutor::getTheoryOps() { // transpose filters ops bool filters_need_transpose = true; if (filters_need_transpose) { - total_ops += filters_desc_->total_element_num; + total_ops += filters_desc_->getTotalElementNum(); } return total_ops; } int64_t IndiceConvolutionForwardExecutor::getTheoryIoSize() { int32_t *indice_pair = (int32_t *)(data_vector_[2].host_ptr); - int64_t ci = features_desc_->dims[1]; - int64_t co = features_out_desc_->dims[2]; - int64_t num_active_in = features_desc_->dims[0]; - int64_t num_active_out = features_out_desc_->dims[0]; - int64_t num_filters = indice_pairs_desc_->dims[0]; + int64_t ci = features_desc_->getDimIndex(1); + int64_t co = features_out_desc_->getDimIndex(2); + int64_t num_active_in = features_desc_->getDimIndex(0); + int64_t num_active_out = features_out_desc_->getDimIndex(0); + int64_t num_filters = indice_pairs_desc_->getDimIndex(0); int64_t theory_ios = 0; size_t features_dwidth, filters_dwidth, indice_pairs_dwith, features_out_dwith; - MLUOP_CHECK(mluOpGetSizeOfDataType(features_desc_->dtype, &features_dwidth)); - MLUOP_CHECK(mluOpGetSizeOfDataType(filters_desc_->dtype, &filters_dwidth)); + MLUOP_CHECK(mluOpGetSizeOfDataType(features_desc_->getDtype(), &features_dwidth)); + MLUOP_CHECK(mluOpGetSizeOfDataType(filters_desc_->getDtype(), &filters_dwidth)); MLUOP_CHECK( - mluOpGetSizeOfDataType(indice_pairs_desc_->dtype, &indice_pairs_dwith)); + mluOpGetSizeOfDataType(indice_pairs_desc_->getDtype(), &indice_pairs_dwith)); MLUOP_CHECK( - mluOpGetSizeOfDataType(features_out_desc_->dtype, &features_out_dwith)); + mluOpGetSizeOfDataType(features_out_desc_->getDtype(), &features_out_dwith)); auto gather_scatter_ios = [&](const int64_t index, const int64_t num, const int64_t channel, @@ -234,10 +234,10 @@ int64_t IndiceConvolutionForwardExecutor::getTheoryIoSize() { }; // fill ios - theory_ios += filters_desc_->total_tensor_size; + theory_ios += filters_desc_->getTotalTensorSize(); // transpose ios - theory_ios += filters_desc_->total_element_num * 2; + theory_ios += filters_desc_->getTotalElementNum() * 2; for (int64_t i = 0; i < num_filters; ++i) { if (indice_num_[i] <= 0) { diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/logspace/logspace.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/logspace/logspace.cpp index cbf8b12a0..6661129e7 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/logspace/logspace.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/logspace/logspace.cpp @@ -57,7 +57,7 @@ void LogspaceExecutor::cpuCompute() { auto count = parser_->output(0)->shape_count; float step = (end_num_ - start_num_) / (steps_num_ - 1); - switch (tensor_desc_[1].tensor->dtype) { + switch (tensor_desc_[1].tensor->getDtype()) { case MLUOP_DTYPE_FLOAT: { for (int i = 0; i < count; ++i) { cpu_fp32_output_[0][i] = ::powf(base_num_, start_num_ + step * i); diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/masked_col2im_forward/masked_col2im_forward.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/masked_col2im_forward/masked_col2im_forward.cpp index 582803a15..e851f845a 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/masked_col2im_forward/masked_col2im_forward.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/masked_col2im_forward/masked_col2im_forward.cpp @@ -43,11 +43,11 @@ void MaskedCol2imForwardExecutor::paramCheck() { void MaskedCol2imForwardExecutor::init() { auto col_desc = tensor_desc_[0].tensor; auto im_desc = tensor_desc_[3].tensor; - batchs_ = im_desc->dims[0]; - channels_ = im_desc->dims[1]; - height_ = im_desc->dims[2]; - width_ = im_desc->dims[3]; - mask_cnt_ = col_desc->dims[1]; + batchs_ = im_desc->getDimIndex(0); + channels_ = im_desc->getDimIndex(1); + height_ = im_desc->getDimIndex(2); + width_ = im_desc->getDimIndex(3); + mask_cnt_ = col_desc->getDimIndex(1); } void MaskedCol2imForwardExecutor::workspaceMalloc() { diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/masked_im2col_forward/masked_im2col_forward.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/masked_im2col_forward/masked_im2col_forward.cpp index 7f4ce97b3..84271721f 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/masked_im2col_forward/masked_im2col_forward.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/masked_im2col_forward/masked_im2col_forward.cpp @@ -47,11 +47,11 @@ void MaskedIm2colForwardExecutor::paramCheck() { void MaskedIm2colForwardExecutor::init() { auto input_desc = tensor_desc_[0].tensor; auto mask_desc = tensor_desc_[1].tensor; - batchs_ = input_desc->dims[0]; - channels_ = input_desc->dims[1]; - height_ = input_desc->dims[2]; - width_ = input_desc->dims[3]; - mask_cnt_ = mask_desc->dims[0]; + batchs_ = input_desc->getDimIndex(0); + channels_ = input_desc->getDimIndex(1); + height_ = input_desc->getDimIndex(2); + width_ = input_desc->getDimIndex(3); + mask_cnt_ = mask_desc->getDimIndex(0); auto masked_im2col_forward_proto_desc = parser_->getProtoNode()->masked_im2col_forward_param(); kernel_h = masked_im2col_forward_proto_desc.kernel_h(); diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/moe_dispatch_backward_data/moe_dispatch_backward_data.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/moe_dispatch_backward_data/moe_dispatch_backward_data.cpp index d605d83b4..fc5394708 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/moe_dispatch_backward_data/moe_dispatch_backward_data.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/moe_dispatch_backward_data/moe_dispatch_backward_data.cpp @@ -140,13 +140,13 @@ int64_t MoeDispatchBackwardDataExecutor::getTheoryOps() { int64_t MoeDispatchBackwardDataExecutor::getTheoryIoSize() { size_t gates_dwidth, indices_dwidth, locations_dwidth, dispatch_dwidth, grad_input_dwidth; - MLUOP_CHECK(mluOpGetSizeOfDataType(desc_gates_->dtype, &gates_dwidth)); - MLUOP_CHECK(mluOpGetSizeOfDataType(desc_indices_->dtype, &indices_dwidth)); + MLUOP_CHECK(mluOpGetSizeOfDataType(desc_gates_->getDtype(), &gates_dwidth)); + MLUOP_CHECK(mluOpGetSizeOfDataType(desc_indices_->getDtype(), &indices_dwidth)); MLUOP_CHECK( - mluOpGetSizeOfDataType(desc_locations_->dtype, &locations_dwidth)); - MLUOP_CHECK(mluOpGetSizeOfDataType(desc_dispatch_->dtype, &dispatch_dwidth)); + mluOpGetSizeOfDataType(desc_locations_->getDtype(), &locations_dwidth)); + MLUOP_CHECK(mluOpGetSizeOfDataType(desc_dispatch_->getDtype(), &dispatch_dwidth)); MLUOP_CHECK( - mluOpGetSizeOfDataType(desc_grad_input_->dtype, &grad_input_dwidth)); + mluOpGetSizeOfDataType(desc_grad_input_->getDtype(), &grad_input_dwidth)); int64_t gates_theory_ios = samples_mask_num_ * gates_dwidth; int64_t indices_theory_ios = samples_mask_num_ * indices_dwidth; diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/moe_dispatch_forward/moe_dispatch_forward.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/moe_dispatch_forward/moe_dispatch_forward.cpp index cea466c02..e499e5376 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/moe_dispatch_forward/moe_dispatch_forward.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/moe_dispatch_forward/moe_dispatch_forward.cpp @@ -115,12 +115,12 @@ int64_t MoeDispatchForwardExecutor::getTheoryOps() { int64_t MoeDispatchForwardExecutor::getTheoryIoSize() { size_t gates_dwidth, indices_dwidth, locations_dwidth, input_dwidth, dispatch_dwidth; - MLUOP_CHECK(mluOpGetSizeOfDataType(desc_gates_->dtype, &gates_dwidth)); - MLUOP_CHECK(mluOpGetSizeOfDataType(desc_indices_->dtype, &indices_dwidth)); + MLUOP_CHECK(mluOpGetSizeOfDataType(desc_gates_->getDtype(), &gates_dwidth)); + MLUOP_CHECK(mluOpGetSizeOfDataType(desc_indices_->getDtype(), &indices_dwidth)); MLUOP_CHECK( - mluOpGetSizeOfDataType(desc_locations_->dtype, &locations_dwidth)); - MLUOP_CHECK(mluOpGetSizeOfDataType(desc_input_->dtype, &input_dwidth)); - MLUOP_CHECK(mluOpGetSizeOfDataType(desc_input_->dtype, &dispatch_dwidth)); + mluOpGetSizeOfDataType(desc_locations_->getDtype(), &locations_dwidth)); + MLUOP_CHECK(mluOpGetSizeOfDataType(desc_input_->getDtype(), &input_dwidth)); + MLUOP_CHECK(mluOpGetSizeOfDataType(desc_input_->getDtype(), &dispatch_dwidth)); int64_t gates_theory_ios = samples_ * gates_dwidth; int64_t indices_theory_ios = samples_ * indices_dwidth; diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/ms_deform_attn_backward/ms_deform_attn_backward.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/ms_deform_attn_backward/ms_deform_attn_backward.cpp index b42aaa096..693591ab4 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/ms_deform_attn_backward/ms_deform_attn_backward.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/ms_deform_attn_backward/ms_deform_attn_backward.cpp @@ -152,15 +152,15 @@ void MsDeformAttnBackwardExecutor::cpuCompute() { mluOpTensorDescriptor_t value_desc = tensor_desc_[0].tensor; mluOpTensorDescriptor_t sampling_loc_desc = tensor_desc_[3].tensor; - const int32_t batch = value_desc->dims[0]; - const int32_t channels = value_desc->dims[3]; + const int32_t batch = value_desc->getDimIndex(0); + const int32_t channels = value_desc->getDimIndex(3); - const int32_t num_query = sampling_loc_desc->dims[1]; - const int32_t num_heads = sampling_loc_desc->dims[2]; - const int32_t num_levels = sampling_loc_desc->dims[3]; - const int32_t num_point = sampling_loc_desc->dims[4]; + const int32_t num_query = sampling_loc_desc->getDimIndex(1); + const int32_t num_heads = sampling_loc_desc->getDimIndex(2); + const int32_t num_levels = sampling_loc_desc->getDimIndex(3); + const int32_t num_point = sampling_loc_desc->getDimIndex(4); const int32_t qid_stride = num_heads * channels; - const int32_t spatial_size = value_desc->dims[1]; + const int32_t spatial_size = value_desc->getDimIndex(1); const int32_t grad_weight_stride = 1; const int32_t grad_loc_stride = 2; @@ -226,12 +226,12 @@ int64_t MsDeformAttnBackwardExecutor::getTheoryOps() { auto grad_value_desc = tensor_desc_[6].tensor; auto grad_sampling_loc_desc = tensor_desc_[7].tensor; - const int32_t batch = grad_value_desc->dims[0]; - const int32_t channels = grad_value_desc->dims[3]; - const int32_t num_query = grad_sampling_loc_desc->dims[1]; - const int32_t num_heads = grad_sampling_loc_desc->dims[2]; - const int32_t num_levels = grad_sampling_loc_desc->dims[3]; - const int32_t num_point = grad_sampling_loc_desc->dims[4]; + const int32_t batch = grad_value_desc->getDimIndex(0); + const int32_t channels = grad_value_desc->getDimIndex(3); + const int32_t num_query = grad_sampling_loc_desc->getDimIndex(1); + const int32_t num_heads = grad_sampling_loc_desc->getDimIndex(2); + const int32_t num_levels = grad_sampling_loc_desc->getDimIndex(3); + const int32_t num_point = grad_sampling_loc_desc->getDimIndex(4); const int64_t count = 48; const int64_t theory_ops = diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/ms_deform_attn_forward/ms_deform_attn_forward.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/ms_deform_attn_forward/ms_deform_attn_forward.cpp index 351717e18..cb1bfe02a 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/ms_deform_attn_forward/ms_deform_attn_forward.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/ms_deform_attn_forward/ms_deform_attn_forward.cpp @@ -184,13 +184,13 @@ void MsDeformAttnForwardExecutor::cpuCompute() { auto tensor_data_sampling_loc = tensor_desc_[3].tensor; auto tensor_data_attn_weight = tensor_desc_[4].tensor; auto tensor_data_col = tensor_desc_[5].tensor; - int batch_size = tensor_data_value->dims[0]; - int num_keys = tensor_data_value->dims[1]; - int num_heads = tensor_data_value->dims[2]; - int channels = tensor_data_value->dims[3]; - int num_levels = tensor_data_spatial_shapes->dims[0]; - int num_query = tensor_data_sampling_loc->dims[1]; - int num_point = tensor_data_sampling_loc->dims[4]; + int batch_size = tensor_data_value->getDimIndex(0); + int num_keys = tensor_data_value->getDimIndex(1); + int num_heads = tensor_data_value->getDimIndex(2); + int channels = tensor_data_value->getDimIndex(3); + int num_levels = tensor_data_spatial_shapes->getDimIndex(0); + int num_query = tensor_data_sampling_loc->getDimIndex(1); + int num_point = tensor_data_sampling_loc->getDimIndex(4); auto data_value = cpu_fp32_input_[0]; auto data_spatial_shapes = cpu_fp32_input_[1]; auto data_level_start_index = cpu_fp32_input_[2]; @@ -214,12 +214,12 @@ int64_t MsDeformAttnForwardExecutor::getTheoryIoSize() { auto tensor_data_value = tensor_desc_[0].tensor; auto tensor_data_spatial_shapes = tensor_desc_[1].tensor; auto tensor_data_sampling_loc = tensor_desc_[3].tensor; - size_t batch_size = tensor_data_value->dims[0]; - size_t num_heads = tensor_data_value->dims[2]; - size_t channels = tensor_data_value->dims[3]; - size_t num_levels = tensor_data_spatial_shapes->dims[0]; - size_t num_query = tensor_data_sampling_loc->dims[1]; - size_t num_point = tensor_data_sampling_loc->dims[4]; + size_t batch_size = tensor_data_value->getDimIndex(0); + size_t num_heads = tensor_data_value->getDimIndex(2); + size_t channels = tensor_data_value->getDimIndex(3); + size_t num_levels = tensor_data_spatial_shapes->getDimIndex(0); + size_t num_query = tensor_data_sampling_loc->getDimIndex(1); + size_t num_point = tensor_data_sampling_loc->getDimIndex(4); size_t total_size = 0; total_size += 4 * batch_size * num_query * num_heads * num_levels * num_point * channels * @@ -240,11 +240,11 @@ int64_t MsDeformAttnForwardExecutor::getTheoryOps() { auto tensor_data_value = tensor_desc_[0].tensor; auto tensor_data_spatial_shapes = tensor_desc_[1].tensor; auto tensor_data_sampling_loc = tensor_desc_[3].tensor; - size_t batch_size = tensor_data_value->dims[0]; - size_t num_heads = tensor_data_value->dims[2]; - size_t num_levels = tensor_data_spatial_shapes->dims[0]; - size_t num_query = tensor_data_sampling_loc->dims[1]; - size_t num_point = tensor_data_sampling_loc->dims[4]; + size_t batch_size = tensor_data_value->getDimIndex(0); + size_t num_heads = tensor_data_value->getDimIndex(2); + size_t num_levels = tensor_data_spatial_shapes->getDimIndex(0); + size_t num_query = tensor_data_sampling_loc->getDimIndex(1); + size_t num_point = tensor_data_sampling_loc->getDimIndex(4); int64_t count = 11; int64_t theory_ops = batch_size * num_query * num_heads * num_levels * num_point * count; diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/mutual_information_backward/mutual_information_backward.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/mutual_information_backward/mutual_information_backward.cpp index 7555d9010..751bbb231 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/mutual_information_backward/mutual_information_backward.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/mutual_information_backward/mutual_information_backward.cpp @@ -49,9 +49,9 @@ void MutualInformationBackwardExecutor::initParam() { host_ans_grad_in = (float *)data_vector_[3].host_ptr; } - B_ = px_desc_->dims[0]; - S_ = px_desc_->dims[1]; - T_ = py_desc_->dims[2]; + B_ = px_desc_->getDimIndex(0); + S_ = px_desc_->getDimIndex(1); + T_ = py_desc_->getDimIndex(2); px_index_ = Index3D(S_, T_ + 1); py_index_ = Index3D(S_ + 1, T_); diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/mutual_information_forward/mutual_information_forward.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/mutual_information_forward/mutual_information_forward.cpp index cb8bd68f6..785932959 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/mutual_information_forward/mutual_information_forward.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/mutual_information_forward/mutual_information_forward.cpp @@ -41,9 +41,9 @@ void MutualInformationForwardExecutor::initParam() { host_p_in = (float *)data_vector_[2].host_ptr; } - B_ = px_desc_->dims[0]; - S_ = px_desc_->dims[1]; - T_ = py_desc_->dims[2]; + B_ = px_desc_->getDimIndex(0); + S_ = px_desc_->getDimIndex(1); + T_ = py_desc_->getDimIndex(2); px_index_ = MutualInformationForward::Index3D(S_, T_ + 1); py_index_ = MutualInformationForward::Index3D(S_ + 1, T_); diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/nms/nms.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/nms/nms.cpp index 0eb97444e..30fdbec1a 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/nms/nms.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/nms/nms.cpp @@ -41,11 +41,11 @@ void NmsExecutor::workspaceMalloc() { auto tensor_boxes = parser_->getMetaTensor("input1").tensor; auto tensor_confi = parser_->getMetaTensor("input2").tensor; auto input_layout = parser_->getProtoNode()->nms_param().input_layout(); - if (tensor_boxes->dim == 2) { + if (tensor_boxes->getDim() == 2) { if (input_layout == 0) { - box_dim_ = tensor_boxes->dims[1]; + box_dim_ = tensor_boxes->getDimIndex(1); } else { - box_dim_ = tensor_boxes->dims[0]; + box_dim_ = tensor_boxes->getDimIndex(0); } } VLOG(4) << "box_dim_: " << box_dim_; @@ -70,7 +70,7 @@ void NmsExecutor::workspaceMalloc() { // this op will modify input data. // when repeat != 1, after second compute(), input data has been modified. // input data changed, the result of this op ("result_num", - // aka output->dims[0]) is changed. + // aka output->getDimIndex(0)) is changed. // so we don't know result_num when repeat finished. // so ignore what result_num(valid data number in output0) is, // set all data in output0 as 0. @@ -134,7 +134,7 @@ void NmsExecutor::compute() { nms_desc = cpu_runtime_.allocate(mluOpCreateNmsDescriptor, mluOpDestroyNmsDescriptor); - VLOG(5) << "tensor_boxes->dim: " << tensor_boxes->dim; + VLOG(5) << "tensor_boxes->getDim(): " << tensor_boxes->getDim(); MLUOP_CHECK(mluOpSetNmsDescriptor( nms_desc, box_mode, mode, algo, method_mode, iou_threshold, soft_nms_sigma, max_output_size, confidence_threshold, offset, @@ -439,29 +439,29 @@ void NmsExecutor::cpuCompute() { int input_batches_num = 1; int input_classes_num = 1; int box_dim = 4; - if (input_box_desc->dim == 2) { + if (input_box_desc->getDim() == 2) { if (input_layout == 0) { // when layout is [boxes_num, 4], dims[0] represets the input number. - input_boxes_num = input_box_desc->dims[0]; - box_dim = input_box_desc->dims[1]; + input_boxes_num = input_box_desc->getDimIndex(0); + box_dim = input_box_desc->getDimIndex(1); } else if (input_layout == 1) { - input_boxes_num = input_box_desc->dims[1]; - box_dim = input_box_desc->dims[0]; + input_boxes_num = input_box_desc->getDimIndex(1); + box_dim = input_box_desc->getDimIndex(0); } else { VLOG(4) << "unsupport input layout now."; } } else { - // assert input_box_desc->dim == 3 - input_batches_num = input_box_desc->dims[0]; - input_classes_num = input_conf_desc->dims[1]; + // assert input_box_desc->getDim() == 3 + input_batches_num = input_box_desc->getDimIndex(0); + input_classes_num = input_conf_desc->getDimIndex(1); // keep content of algo and offset, algo is deprecated at // setNmsDescriptor_v4 algo = mluOpNmsAlgo_t::MLUOP_NMS_ALGO_INCLUDE_BOUNDARY; if (input_layout == 0) { // when layout is [boxes_num, 4], dims[0] represets the input number. - input_boxes_num = input_box_desc->dims[1]; + input_boxes_num = input_box_desc->getDimIndex(1); } else if (input_layout == 1) { - input_boxes_num = input_box_desc->dims[2]; + input_boxes_num = input_box_desc->getDimIndex(2); } else { VLOG(4) << "unsupport input layout now."; } @@ -525,8 +525,8 @@ void NmsExecutor::diffPreprocess() { parser_->getProtoNode()->nms_param().pad_to_max_output_size(); int output_mode_num = 1; int box_dim = 4; - if (tensor_boxes->dim == 2) { - box_dim = input_layout == 0 ? tensor_boxes->dims[1] : tensor_boxes->dims[0]; + if (tensor_boxes->getDim() == 2) { + box_dim = input_layout == 0 ? tensor_boxes->getDimIndex(1) : tensor_boxes->getDimIndex(0); } if (box_dim == 7) { mode = static_cast(0); @@ -661,25 +661,25 @@ int64_t NmsExecutor::getTheoryOps() { int input_batches_num = 0; int input_classes_num = 0; int box_dim = 4; - if (input_desc->dim == 2) { + if (input_desc->getDim() == 2) { if (input_layout == 0) { - input_boxes_num = input_desc->dims[0]; - box_dim = input_desc->dims[1]; + input_boxes_num = input_desc->getDimIndex(0); + box_dim = input_desc->getDimIndex(1); } else if (input_layout == 1) { - input_boxes_num = input_desc->dims[1]; - box_dim = input_desc->dims[0]; + input_boxes_num = input_desc->getDimIndex(1); + box_dim = input_desc->getDimIndex(0); } else { VLOG(4) << "unsupport input layout now."; } } else { - // assert input_desc->dim == 3 - input_batches_num = input_desc->dims[0]; - input_classes_num = input_conf_desc->dims[1]; + // assert input_desc->getDim() == 3 + input_batches_num = input_desc->getDimIndex(0); + input_classes_num = input_conf_desc->getDimIndex(1); if (input_layout == 0) { // when layout is [boxes_num, 4], dims[0] represets the input number. - input_boxes_num = input_desc->dims[1]; + input_boxes_num = input_desc->getDimIndex(1); } else if (input_layout == 1) { - input_boxes_num = input_desc->dims[2]; + input_boxes_num = input_desc->getDimIndex(2); } else { VLOG(4) << "unsupport input layout now."; } @@ -688,8 +688,8 @@ int64_t NmsExecutor::getTheoryOps() { float *input_boxes = NULL; float *input_conf = NULL; if (device == Device::GPU) { - auto boxes_dtype = input_desc->dtype; - auto conf_dtype = input_conf_desc->dtype; + auto boxes_dtype = input_desc->getDtype(); + auto conf_dtype = input_conf_desc->getDtype(); int boxes_count_num = mluOpGetTensorElementNum(input_desc); int conf_count_num = mluOpGetTensorElementNum(input_conf_desc); float *boxes_host = diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/nms_rotated/nms_rotated.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/nms_rotated/nms_rotated.cpp index 8fc555ecd..1171ae821 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/nms_rotated/nms_rotated.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/nms_rotated/nms_rotated.cpp @@ -105,7 +105,7 @@ void NmsRotatedExecutor::compute() { GTEST_CHECK(cnrtSuccess == cnrtMemset(result_num, 0, sizeof(int32_t))); // GTEST_CHECK(cnrtSuccess == cnrtMemset(dev_output, 0, - // output->dims[0] * sizeof(int64_t))); + // output->getDimIndex(0) * sizeof(int64_t))); VLOG(4) << "call mluOpNmsRotated()"; interface_timer_.start(); MLUOP_CHECK(mluOpGetNmsRotatedWorkspaceSize( @@ -124,8 +124,8 @@ void NmsRotatedExecutor::cpuCompute() { return; } - auto num_box = tensor_desc_[0].tensor->dims[0]; - auto box_dim = tensor_desc_[0].tensor->dims[1]; + auto num_box = tensor_desc_[0].tensor->getDimIndex(0); + auto box_dim = tensor_desc_[0].tensor->getDimIndex(1); float iou_threshold = parser_->getProtoNode()->nms_rotated_param().iou_threshold(); diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/points_in_boxes/points_in_boxes.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/points_in_boxes/points_in_boxes.cpp index 5b71a72d3..f5907c1b0 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/points_in_boxes/points_in_boxes.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/points_in_boxes/points_in_boxes.cpp @@ -52,19 +52,19 @@ static void points_in_boxes_cpu( const mluOpTensorDescriptor_t boxes_desc, const void *boxes, const mluOpTensorDescriptor_t points_indices_desc, void *points_indices) { for (int64_t i = 0; - i < points_indices_desc->dims[0] * points_indices_desc->dims[1]; i++) { + i < points_indices_desc->getDimIndex(0) * points_indices_desc->getDimIndex(1); i++) { *((float *)points_indices + i) = -1.0; } - for (int64_t i = 0; i < points_desc->dims[0]; i++) { - for (int64_t j = 0; j < points_desc->dims[1]; j++) { - for (int64_t m = 0; m < boxes_desc->dims[1]; m++) { + for (int64_t i = 0; i < points_desc->getDimIndex(0); i++) { + for (int64_t j = 0; j < points_desc->getDimIndex(1); j++) { + for (int64_t m = 0; m < boxes_desc->getDimIndex(1); m++) { float local_x, local_y; int cur_in_flag = check_pt_in_box3d_cpu( - (float *)points + (i * points_desc->dims[1] + j) * 3, - (float *)boxes + (i * boxes_desc->dims[1] + m) * 7, local_x, + (float *)points + (i * points_desc->getDimIndex(1) + j) * 3, + (float *)boxes + (i * boxes_desc->getDimIndex(1) + m) * 7, local_x, local_y); if (cur_in_flag) { - *((float *)points_indices + i * points_desc->dims[1] + j) = (float)m; + *((float *)points_indices + i * points_desc->getDimIndex(1) + j) = (float)m; break; } } diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/poly_nms/poly_nms.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/poly_nms/poly_nms.cpp index 01dd4acd5..645782a21 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/poly_nms/poly_nms.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/poly_nms/poly_nms.cpp @@ -114,7 +114,7 @@ void PolyNmsExecutor::pnmsComputeCPU(float *output_data, int *output_box_num, void PolyNmsExecutor::cpuCompute() { float iou_thresh = parser_->getProtoNode()->poly_nms_param().iou_threshold(); auto input_box_desc = tensor_desc_[0].tensor; - int input_boxes_num = input_box_desc->dims[0]; + int input_boxes_num = input_box_desc->getDimIndex(0); VLOG(4) << "[mluOpPolyNms] cpu compute start, input_boxes_num: " << input_boxes_num; @@ -133,7 +133,7 @@ void PolyNmsExecutor::cpuCompute() { int64_t PolyNmsExecutor::getTheoryOps() { VLOG(4) << "getTheoryOps"; int64_t theory_ops = 21650; - int dims = parser_->getMetaTensor("input1").tensor->dims[0]; + int dims = parser_->getMetaTensor("input1").tensor->getDimIndex(0); theory_ops = theory_ops * dims * dims; int64_t sort_ops = dims * dims - dims; theory_ops += sort_ops; diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/prior_box/prior_box.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/prior_box/prior_box.cpp index 0643cccff..b5a8354e7 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/prior_box/prior_box.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/prior_box/prior_box.cpp @@ -192,12 +192,12 @@ void PriorBoxExecutor::cpuCompute() { float* variances = cpu_fp32_input_[2]; float* max_sizes = cpu_fp32_input_[3]; - const int min_sizes_num = min_sizes_desc_->total_element_num; - const int aspect_ratios_num = aspect_ratios_desc_->total_element_num; - const int variances_num = variances_desc_->total_element_num; - const int max_sizes_num = max_sizes_desc_->total_element_num; - const int output_num = output_desc_->total_element_num; - const int var_num = var_desc_->total_element_num; + const int min_sizes_num = min_sizes_desc_->getTotalElementNum(); + const int aspect_ratios_num = aspect_ratios_desc_->getTotalElementNum(); + const int variances_num = variances_desc_->getTotalElementNum(); + const int max_sizes_num = max_sizes_desc_->getTotalElementNum(); + const int output_num = output_desc_->getTotalElementNum(); + const int var_num = var_desc_->getTotalElementNum(); const float step_h = step_h_; const float step_w = step_w_; const float offset = offset_; diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/psamask_backward/psamask_backward.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/psamask_backward/psamask_backward.cpp index ab07fb416..6b7382791 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/psamask_backward/psamask_backward.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/psamask_backward/psamask_backward.cpp @@ -163,15 +163,15 @@ void PsamaskBackwardExecutor::cpuCompute() { int w_mask = parser_->getProtoNode()->psamask_backward_param().w_mask(); int psa_type = parser_->getProtoNode()->psamask_backward_param().psa_type(); - auto batch = input_desc->dims[0]; - auto buffer_c = input_desc->dims[3]; - auto h_feature = input_desc->dims[1]; - auto w_feature = input_desc->dims[2]; - auto mask_c = output_desc->dims[3]; + auto batch = input_desc->getDimIndex(0); + auto buffer_c = input_desc->getDimIndex(3); + auto h_feature = input_desc->getDimIndex(1); + auto w_feature = input_desc->getDimIndex(2); + auto mask_c = output_desc->getDimIndex(3); int half_h_mask = (h_mask - 1) / 2; int half_w_mask = (w_mask - 1) / 2; - auto input_data_type = input_desc->dtype; + auto input_data_type = input_desc->getDtype(); psamaskType_t psamask_type = (psamaskType_t)psa_type; void *input = (void *)cpu_fp32_input_[0]; diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/psamask_forward/psamask_forward.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/psamask_forward/psamask_forward.cpp index 349703f18..334dcbee2 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/psamask_forward/psamask_forward.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/psamask_forward/psamask_forward.cpp @@ -162,15 +162,15 @@ void PsamaskForwardExecutor::cpuCompute() { psamaskType_t psa_type = (psamaskType_t)parser_->getProtoNode() ->psamask_forward_param() .psa_type(); - auto batch = input_desc->dims[0]; - auto input_c = input_desc->dims[3]; - auto h_feature = input_desc->dims[1]; - auto w_feature = input_desc->dims[2]; - auto output_c = output_desc->dims[3]; + auto batch = input_desc->getDimIndex(0); + auto input_c = input_desc->getDimIndex(3); + auto h_feature = input_desc->getDimIndex(1); + auto w_feature = input_desc->getDimIndex(2); + auto output_c = output_desc->getDimIndex(3); int half_h_mask = (h_mask - 1) / 2; int half_w_mask = (w_mask - 1) / 2; - auto input_data_type = input_desc->dtype; + auto input_data_type = input_desc->getDtype(); psamaskType_t psamask_type = (psamaskType_t)psa_type; void *input = (void *)cpu_fp32_input_[0]; diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/psroipool_backward/psroipool_backward.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/psroipool_backward/psroipool_backward.cpp index 5a961a3a6..993c9036f 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/psroipool_backward/psroipool_backward.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/psroipool_backward/psroipool_backward.cpp @@ -77,13 +77,13 @@ void PsroipoolBackwardExecutor::cpuCompute() { auto rois_cpu = cpu_fp32_input_[2]; auto bottom_output_cpu = cpu_fp32_output_[0]; - const int bottom_n = bottom_output_desc->dims[0]; - const int bottom_h = bottom_output_desc->dims[1]; - const int bottom_w = bottom_output_desc->dims[2]; - const int bottom_c = bottom_output_desc->dims[3]; + const int bottom_n = bottom_output_desc->getDimIndex(0); + const int bottom_h = bottom_output_desc->getDimIndex(1); + const int bottom_w = bottom_output_desc->getDimIndex(2); + const int bottom_c = bottom_output_desc->getDimIndex(3); - const int rois_n = rois_desc->dims[0]; - const int rois_offset = rois_desc->dims[1]; + const int rois_n = rois_desc->getDimIndex(0); + const int rois_offset = rois_desc->getDimIndex(1); for (int roi_id = 0; roi_id < rois_n; roi_id++) { int top_batch_offset = diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/psroipool_forward/psroipool_forward.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/psroipool_forward/psroipool_forward.cpp index dc3667e94..469479b57 100755 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/psroipool_forward/psroipool_forward.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/psroipool_forward/psroipool_forward.cpp @@ -95,13 +95,13 @@ void PsroipoolForwardExecutor::cpuCompute() { auto output_cpu = cpu_fp32_output_[0]; auto mapping_channel_cpu = cpu_fp32_output_[1]; - const int input_n = input_desc->dims[0]; - const int input_h = input_desc->dims[1]; - const int input_w = input_desc->dims[2]; - const int input_c = input_desc->dims[3]; + const int input_n = input_desc->getDimIndex(0); + const int input_h = input_desc->getDimIndex(1); + const int input_w = input_desc->getDimIndex(2); + const int input_c = input_desc->getDimIndex(3); - const int rois_n = rois_desc->dims[0]; - const int rois_offset = rois_desc->dims[1]; + const int rois_n = rois_desc->getDimIndex(0); + const int rois_offset = rois_desc->getDimIndex(1); for (int roi_id = 0; roi_id < rois_n; roi_id++) { int out_batch_offset = diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/roi_align_backward/roi_align_backward.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/roi_align_backward/roi_align_backward.cpp index 86cc8aa9e..4defcad30 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/roi_align_backward/roi_align_backward.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/roi_align_backward/roi_align_backward.cpp @@ -159,20 +159,20 @@ void RoiAlignBackwardExecutor::cpuCompute() { parser_->getProtoNode()->roi_align_backward_param().pool_mode(); int version = parser_->getProtoNode()->roi_align_backward_param().version(); - size_t input_n = input_desc->dims[0]; - size_t input_h = input_desc->dims[1]; - size_t input_w = input_desc->dims[2]; - size_t input_c = input_desc->dims[3]; + size_t input_n = input_desc->getDimIndex(0); + size_t input_h = input_desc->getDimIndex(1); + size_t input_w = input_desc->getDimIndex(2); + size_t input_c = input_desc->getDimIndex(3); size_t input_offset_n = input_h * input_w * input_c; size_t input_offset_h = input_w * input_c; auto output = parser_->getMetaTensor(2).cpu_ptr; auto output_desc = parser_->getMetaTensor(2).tensor; if (pool_mode == 1) { - int output_n = output_desc->dims[0]; - int output_h = output_desc->dims[1]; - int output_w = output_desc->dims[2]; - int output_c = output_desc->dims[3]; + int output_n = output_desc->getDimIndex(0); + int output_h = output_desc->getDimIndex(1); + int output_w = output_desc->getDimIndex(2); + int output_c = output_desc->getDimIndex(3); std::memset(output, 0.0, parser_->getMetaTensor(2).size_in_bytes); size_t output_offset_n = output_h * output_w * output_c; @@ -253,10 +253,10 @@ void RoiAlignBackwardExecutor::cpuCompute() { output = parser_->getMetaTensor(4).cpu_ptr; output_desc = parser_->getMetaTensor(4).tensor; - size_t output_n = output_desc->dims[0]; - size_t output_h = output_desc->dims[1]; - size_t output_w = output_desc->dims[2]; - size_t output_c = output_desc->dims[3]; + size_t output_n = output_desc->getDimIndex(0); + size_t output_h = output_desc->getDimIndex(1); + size_t output_w = output_desc->getDimIndex(2); + size_t output_c = output_desc->getDimIndex(3); size_t output_offset_n = output_h * output_w * output_c; size_t output_offset_h = output_w * output_c; @@ -318,7 +318,7 @@ int64_t RoiAlignBackwardExecutor::getTheoryOps() { Device device = parser_->device(); if (device != Device::CPU) { auto boxes_desc = tensor_desc_[1].tensor; - auto boxes_dtype = boxes_desc->dtype; + auto boxes_dtype = boxes_desc->getDtype(); size_t boxes_num = parser_->getInputDataCount(1); float *boxes_ptr = (float *)cpu_runtime_.allocate(boxes_num * sizeof(float)); @@ -344,11 +344,11 @@ int64_t RoiAlignBackwardExecutor::getTheoryOps() { output_desc = parser_->getMetaTensor(4).tensor; } - size_t input_n = input_desc->dims[0]; - size_t input_h = input_desc->dims[1]; - size_t input_w = input_desc->dims[2]; - size_t input_c = input_desc->dims[3]; - size_t output_n = output_desc->dims[0]; + size_t input_n = input_desc->getDimIndex(0); + size_t input_h = input_desc->getDimIndex(1); + size_t input_w = input_desc->getDimIndex(2); + size_t input_c = input_desc->getDimIndex(3); + size_t output_n = output_desc->getDimIndex(0); for (int idx_n = 0; idx_n < input_n; idx_n++) { // check whether box_idx is valid diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/roi_align_rotated_backward/roi_align_rotated_backward.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/roi_align_rotated_backward/roi_align_rotated_backward.cpp index 919f74500..b155b1e37 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/roi_align_rotated_backward/roi_align_rotated_backward.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/roi_align_rotated_backward/roi_align_rotated_backward.cpp @@ -191,11 +191,11 @@ void RoiAlignRotatedBackwardExecutor::cpuCompute() { float *rois = cpu_fp32_input_[1]; // (n, 6) [batch_id, x, y, w, h, Θ] float *bottom_grad = cpu_fp32_output_[0]; - const int channel = top_grad_desc->dims[3]; - const int width = bottom_grad_desc->dims[2]; - const int height = bottom_grad_desc->dims[1]; - const int batch = bottom_grad_desc->dims[0]; - const int rois_nums = rois_desc->dims[0]; + const int channel = top_grad_desc->getDimIndex(3); + const int width = bottom_grad_desc->getDimIndex(2); + const int height = bottom_grad_desc->getDimIndex(1); + const int batch = bottom_grad_desc->getDimIndex(0); + const int rois_nums = rois_desc->getDimIndex(0); if (mluOpGetTensorElementNum(bottom_grad_desc) == 0) { return; @@ -300,7 +300,7 @@ int64_t RoiAlignRotatedBackwardExecutor::getTheoryOps() { if (unlikely(ts->empty())) { return 0; } - if (ts->dtype == MLUOP_DTYPE_FLOAT) { + if (ts->getDtype() == MLUOP_DTYPE_FLOAT) { ts->cpu_ptr = (float *)cpu_runtime_.allocate(ts->shape_count * ts->sizeof_dtype); parser_->getInputTensorValue(i, (void *)ts->cpu_ptr, ts->shape_count); @@ -309,7 +309,7 @@ int64_t RoiAlignRotatedBackwardExecutor::getTheoryOps() { parser_->getInputTensorValue(i, temp, ts->shape_count); ts->cpu_ptr = (float *)cpu_runtime_.allocate(ts->shape_count * sizeof(float)); - castDataOut(temp, ts->dtype, ts->cpu_ptr, MLUOP_DTYPE_FLOAT, + castDataOut(temp, ts->getDtype(), ts->cpu_ptr, MLUOP_DTYPE_FLOAT, ts->shape_count, NO_QUANT); } cpu_fp32_input_.push_back(ts->cpu_ptr); @@ -319,7 +319,7 @@ int64_t RoiAlignRotatedBackwardExecutor::getTheoryOps() { if (unlikely(ts->empty())) { return 0; } - if (ts->dtype == MLUOP_DTYPE_FLOAT) { + if (ts->getDtype() == MLUOP_DTYPE_FLOAT) { ts->cpu_ptr = (float *)cpu_runtime_.allocate(ts->shape_count * ts->sizeof_dtype); parser_->getOutputTensorValue(i, (void *)ts->cpu_ptr, ts->shape_count); @@ -328,7 +328,7 @@ int64_t RoiAlignRotatedBackwardExecutor::getTheoryOps() { parser_->getOutputTensorValue(i, temp, ts->shape_count); ts->cpu_ptr = (float *)cpu_runtime_.allocate(ts->shape_count * sizeof(float)); - castDataOut(temp, ts->dtype, ts->cpu_ptr, MLUOP_DTYPE_FLOAT, + castDataOut(temp, ts->getDtype(), ts->cpu_ptr, MLUOP_DTYPE_FLOAT, ts->shape_count, NO_QUANT); } cpu_fp32_output_.push_back(ts->cpu_ptr); diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/roi_align_rotated_forward/roi_align_rotated_forward.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/roi_align_rotated_forward/roi_align_rotated_forward.cpp index b17c99fb3..33e6cca99 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/roi_align_rotated_forward/roi_align_rotated_forward.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/roi_align_rotated_forward/roi_align_rotated_forward.cpp @@ -184,11 +184,11 @@ void RoiAlignRotatedForwardExecutor::cpuCompute() { float *rois = cpu_fp32_input_[1]; // (n, 6) [batch_id, x, y, w, h, Θ] float *output = cpu_fp32_output_[0]; - const int channel = features_desc->dims[3]; - const int width = features_desc->dims[2]; - const int height = features_desc->dims[1]; - const int batch = features_desc->dims[0]; - const int rois_nums = rois_desc->dims[0]; + const int channel = features_desc->getDimIndex(3); + const int width = features_desc->getDimIndex(2); + const int height = features_desc->getDimIndex(1); + const int batch = features_desc->getDimIndex(0); + const int rois_nums = rois_desc->getDimIndex(0); if (mluOpGetTensorElementNum(features_desc) == 0) { return; @@ -288,7 +288,7 @@ int64_t RoiAlignRotatedForwardExecutor::getTheoryOps() { if (unlikely(ts->empty())) { return 0; } - if (ts->dtype == MLUOP_DTYPE_FLOAT) { + if (ts->getDtype() == MLUOP_DTYPE_FLOAT) { ts->cpu_ptr = (float *)cpu_runtime_.allocate(ts->shape_count * ts->sizeof_dtype); parser_->getInputTensorValue(i, (void *)ts->cpu_ptr, ts->shape_count); @@ -297,7 +297,7 @@ int64_t RoiAlignRotatedForwardExecutor::getTheoryOps() { parser_->getInputTensorValue(i, temp, ts->shape_count); ts->cpu_ptr = (float *)cpu_runtime_.allocate(ts->shape_count * sizeof(float)); - castDataOut(temp, ts->dtype, ts->cpu_ptr, MLUOP_DTYPE_FLOAT, + castDataOut(temp, ts->getDtype(), ts->cpu_ptr, MLUOP_DTYPE_FLOAT, ts->shape_count, NO_QUANT); } cpu_fp32_input_.push_back(ts->cpu_ptr); @@ -307,7 +307,7 @@ int64_t RoiAlignRotatedForwardExecutor::getTheoryOps() { if (unlikely(ts->empty())) { return 0; } - if (ts->dtype == MLUOP_DTYPE_FLOAT) { + if (ts->getDtype() == MLUOP_DTYPE_FLOAT) { ts->cpu_ptr = (float *)cpu_runtime_.allocate(ts->shape_count * ts->sizeof_dtype); parser_->getOutputTensorValue(i, (void *)ts->cpu_ptr, ts->shape_count); @@ -316,7 +316,7 @@ int64_t RoiAlignRotatedForwardExecutor::getTheoryOps() { parser_->getOutputTensorValue(i, temp, ts->shape_count); ts->cpu_ptr = (float *)cpu_runtime_.allocate(ts->shape_count * sizeof(float)); - castDataOut(temp, ts->dtype, ts->cpu_ptr, MLUOP_DTYPE_FLOAT, + castDataOut(temp, ts->getDtype(), ts->cpu_ptr, MLUOP_DTYPE_FLOAT, ts->shape_count, NO_QUANT); } cpu_fp32_output_.push_back(ts->cpu_ptr); diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/roi_crop_backward/roi_crop_backward.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/roi_crop_backward/roi_crop_backward.cpp index 4acf5d3af..672d51f18 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/roi_crop_backward/roi_crop_backward.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/roi_crop_backward/roi_crop_backward.cpp @@ -40,13 +40,13 @@ void RoiCropBackwardExecutor::initData() { grad_output_desc_ = tensor_desc_[0].tensor; grid_desc_ = tensor_desc_[1].tensor; grad_input_desc_ = tensor_desc_[2].tensor; - grad_output_h_ = grad_output_desc_->dims[1]; - grad_output_w_ = grad_output_desc_->dims[2]; - grid_batch_roi_ = grid_desc_->dims[0]; - grad_input_batch_ = grad_input_desc_->dims[0]; - grad_input_h_ = grad_input_desc_->dims[1]; - grad_input_w_ = grad_input_desc_->dims[2]; - grad_input_c_ = grad_input_desc_->dims[3]; + grad_output_h_ = grad_output_desc_->getDimIndex(1); + grad_output_w_ = grad_output_desc_->getDimIndex(2); + grid_batch_roi_ = grid_desc_->getDimIndex(0); + grad_input_batch_ = grad_input_desc_->getDimIndex(0); + grad_input_h_ = grad_input_desc_->getDimIndex(1); + grad_input_w_ = grad_input_desc_->getDimIndex(2); + grad_input_c_ = grad_input_desc_->getDimIndex(3); VLOG(4) << "[RoiCropBackwardExecutor] call initData() end."; } diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/roi_crop_forward/roi_crop_forward.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/roi_crop_forward/roi_crop_forward.cpp index a4c6bd0ba..a475d7467 100755 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/roi_crop_forward/roi_crop_forward.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/roi_crop_forward/roi_crop_forward.cpp @@ -40,13 +40,13 @@ void RoiCropForwardExecutor::initData() { input_desc_ = tensor_desc_[0].tensor; grid_desc_ = tensor_desc_[1].tensor; output_desc_ = tensor_desc_[2].tensor; - input_batch_ = input_desc_->dims[0]; - input_h_ = input_desc_->dims[1]; - input_w_ = input_desc_->dims[2]; - input_c_ = input_desc_->dims[3]; - grid_batch_roi_ = grid_desc_->dims[0]; - output_h_ = output_desc_->dims[1]; - output_w_ = output_desc_->dims[2]; + input_batch_ = input_desc_->getDimIndex(0); + input_h_ = input_desc_->getDimIndex(1); + input_w_ = input_desc_->getDimIndex(2); + input_c_ = input_desc_->getDimIndex(3); + grid_batch_roi_ = grid_desc_->getDimIndex(0); + output_h_ = output_desc_->getDimIndex(1); + output_w_ = output_desc_->getDimIndex(2); VLOG(4) << "[RoiCropForwardExecutor] call initData() End."; } diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/roi_pooling_backward/roi_pooling_backward.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/roi_pooling_backward/roi_pooling_backward.cpp index df34ac217..97a24d360 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/roi_pooling_backward/roi_pooling_backward.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/roi_pooling_backward/roi_pooling_backward.cpp @@ -78,20 +78,20 @@ void RoiPoolingBackwardExecutor::cpuCompute() { PoolingForwardMode mode = parser_->getProtoNode()->roi_pooling_backward_param().mode(); - size_t grads_n = grads_desc->dims[0]; - size_t grads_h = grads_desc->dims[1]; - size_t grads_w = grads_desc->dims[2]; - size_t grads_c = grads_desc->dims[3]; - size_t num1 = rois_desc->dims[0]; - size_t num2 = rois_desc->dims[1]; - size_t argmax_n = argmax_desc->dims[0]; - size_t argmax_h = argmax_desc->dims[1]; - size_t argmax_w = argmax_desc->dims[2]; - size_t argmax_c = argmax_desc->dims[3]; - size_t grads_image_n = grads_image_desc->dims[0]; - size_t grads_image_h = grads_image_desc->dims[1]; - size_t grads_image_w = grads_image_desc->dims[2]; - size_t grads_image_c = grads_image_desc->dims[3]; + size_t grads_n = grads_desc->getDimIndex(0); + size_t grads_h = grads_desc->getDimIndex(1); + size_t grads_w = grads_desc->getDimIndex(2); + size_t grads_c = grads_desc->getDimIndex(3); + size_t num1 = rois_desc->getDimIndex(0); + size_t num2 = rois_desc->getDimIndex(1); + size_t argmax_n = argmax_desc->getDimIndex(0); + size_t argmax_h = argmax_desc->getDimIndex(1); + size_t argmax_w = argmax_desc->getDimIndex(2); + size_t argmax_c = argmax_desc->getDimIndex(3); + size_t grads_image_n = grads_image_desc->getDimIndex(0); + size_t grads_image_h = grads_image_desc->getDimIndex(1); + size_t grads_image_w = grads_image_desc->getDimIndex(2); + size_t grads_image_c = grads_image_desc->getDimIndex(3); const int batch_size = grads_image_n; const int channels = grads_image_c; @@ -192,7 +192,7 @@ int64_t RoiPoolingBackwardExecutor::getTheoryOps() { Device device = parser_->device(); if (device != Device::CPU) { auto argmax_desc = tensor_desc_[2].tensor; - auto argmax_dtype = argmax_desc->dtype; + auto argmax_dtype = argmax_desc->getDtype(); size_t argmax_num = parser_->getInputDataCount(2); float *argmax = (float *)cpu_runtime_.allocate(argmax_num * sizeof(float)); castDataOut(data_vector_[2].host_ptr, argmax_dtype, (float *)argmax, @@ -205,14 +205,14 @@ int64_t RoiPoolingBackwardExecutor::getTheoryOps() { auto grads_desc = parser_->getMetaTensor(0).tensor; auto grads_image_desc = parser_->getMetaTensor(3).tensor; - size_t grads_n = grads_desc->dims[0]; - size_t grads_h = grads_desc->dims[1]; - size_t grads_w = grads_desc->dims[2]; - size_t grads_c = grads_desc->dims[3]; - size_t grads_image_n = grads_image_desc->dims[0]; - size_t grads_image_h = grads_image_desc->dims[1]; - size_t grads_image_w = grads_image_desc->dims[2]; - size_t grads_image_c = grads_image_desc->dims[3]; + size_t grads_n = grads_desc->getDimIndex(0); + size_t grads_h = grads_desc->getDimIndex(1); + size_t grads_w = grads_desc->getDimIndex(2); + size_t grads_c = grads_desc->getDimIndex(3); + size_t grads_image_n = grads_image_desc->getDimIndex(0); + size_t grads_image_h = grads_image_desc->getDimIndex(1); + size_t grads_image_w = grads_image_desc->getDimIndex(2); + size_t grads_image_c = grads_image_desc->getDimIndex(3); theory_ops += grads_image_n * grads_image_h * grads_image_w * grads_image_c; for (size_t i = 0; i < grads_n * grads_h * grads_w * grads_c; i++) { diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/roi_pooling_forward/roi_pooling_forward.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/roi_pooling_forward/roi_pooling_forward.cpp index 19eadd31b..bbcee5475 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/roi_pooling_forward/roi_pooling_forward.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/roi_pooling_forward/roi_pooling_forward.cpp @@ -27,7 +27,7 @@ #define getParam(ty, ctx) \ (ty) parser_->getProtoNode()->roi_pooling_forward_param().ctx() -#define getTensorDims(x, y) tensor_desc_[x].tensor->dims[y] +#define getTensorDims(x, y) tensor_desc_[x].tensor->getDimIndex(y) #define getTensorDesc(x) tensor_desc_[x].tensor #define getDevicePtr(x) data_vector_[x].device_ptr diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/roialign_forward/roialign_forward.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/roialign_forward/roialign_forward.cpp index 6ea61953d..b84da7fb8 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/roialign_forward/roialign_forward.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/roialign_forward/roialign_forward.cpp @@ -51,8 +51,8 @@ void RoialignForwardExecutor::compute() { auto input_desc = parser_->getMetaTensor(0).tensor; auto input_rois_desc = parser_->getMetaTensor(1).tensor; auto output_desc = parser_->getMetaTensor(2).tensor; - int pooled_height = output_desc->dims[1]; - int pooled_width = output_desc->dims[2]; + int pooled_height = output_desc->getDimIndex(1); + int pooled_width = output_desc->getDimIndex(2); mluOpRoiAlignForwardDescriptor_t roialign_desc; mluOpCreateRoiAlignForwardDescriptor(&roialign_desc); @@ -136,14 +136,14 @@ void RoialignForwardExecutor::cpuCompute() { int verison = parser_->getProtoNode()->roialign_param().version(); int pool_mode = parser_->getProtoNode()->roialign_param().pool_mode(); - int input_height = input_desc->dims[1]; - int input_width = input_desc->dims[2]; - int pooled_height = output_desc->dims[1]; - int pooled_width = output_desc->dims[2]; - int channels = input_desc->dims[3]; - int num_rois = input_rois_desc->dims[0]; - int roi_offset = input_rois_desc->dims[1]; - int input_n = input_desc->dims[0]; + int input_height = input_desc->getDimIndex(1); + int input_width = input_desc->getDimIndex(2); + int pooled_height = output_desc->getDimIndex(1); + int pooled_width = output_desc->getDimIndex(2); + int channels = input_desc->getDimIndex(3); + int num_rois = input_rois_desc->getDimIndex(0); + int roi_offset = input_rois_desc->getDimIndex(1); + int input_n = input_desc->getDimIndex(0); float *input = cpu_fp32_input_[0]; float *input_rois = cpu_fp32_input_[1]; // (n, 5) { n, x0, y0, x1, y1} @@ -383,20 +383,20 @@ int64_t RoialignForwardExecutor::getTheoryOps() { auto input_rois_desc = parser_->getMetaTensor(1).tensor; auto output_desc = parser_->getMetaTensor(2).tensor; - int input_height = input_desc->dims[1]; - int input_width = input_desc->dims[2]; - int pooled_height = output_desc->dims[1]; - int pooled_width = output_desc->dims[2]; - int channels = input_desc->dims[3]; - int num_rois = input_rois_desc->dims[0]; - int roi_offset = input_rois_desc->dims[1]; + int input_height = input_desc->getDimIndex(1); + int input_width = input_desc->getDimIndex(2); + int pooled_height = output_desc->getDimIndex(1); + int pooled_width = output_desc->getDimIndex(2); + int channels = input_desc->getDimIndex(3); + int num_rois = input_rois_desc->getDimIndex(0); + int roi_offset = input_rois_desc->getDimIndex(1); int64_t theory_ops = 0; Device device = parser_->device(); float *input_rois = NULL; - auto rois_dtype = input_rois_desc->dtype; - int rois_count_num = num_rois * input_rois_desc->dims[1]; + auto rois_dtype = input_rois_desc->getDtype(); + int rois_count_num = num_rois * input_rois_desc->getDimIndex(1); float *rois_host = (float *)cpu_runtime_.allocate(rois_count_num * sizeof(float)); castDataOut(data_vector_[1].host_ptr, rois_dtype, (float *)rois_host, @@ -465,20 +465,20 @@ int64_t RoialignForwardExecutor::getTheoryIoSize() { auto output_desc = parser_->getMetaTensor(2).tensor; int pool_mode = parser_->getProtoNode()->roialign_param().pool_mode(); - int input_height = input_desc->dims[1]; - int input_width = input_desc->dims[2]; - int pooled_height = output_desc->dims[1]; - int pooled_width = output_desc->dims[2]; - int channels = input_desc->dims[3]; - int num_rois = input_rois_desc->dims[0]; - int roi_offset = input_rois_desc->dims[1]; + int input_height = input_desc->getDimIndex(1); + int input_width = input_desc->getDimIndex(2); + int pooled_height = output_desc->getDimIndex(1); + int pooled_width = output_desc->getDimIndex(2); + int channels = input_desc->getDimIndex(3); + int num_rois = input_rois_desc->getDimIndex(0); + int roi_offset = input_rois_desc->getDimIndex(1); int64_t theory_io_size = 0; Device device = parser_->device(); float *input_rois = NULL; - auto rois_dtype = input_rois_desc->dtype; - int rois_count_num = num_rois * input_rois_desc->dims[1]; + auto rois_dtype = input_rois_desc->getDtype(); + int rois_count_num = num_rois * input_rois_desc->getDimIndex(1); float *rois_host = (float *)cpu_runtime_.allocate(rois_count_num * sizeof(float)); castDataOut(data_vector_[1].host_ptr, rois_dtype, (float *)rois_host, diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/roiaware_pool3d_backward/roiaware_pool3d_backward.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/roiaware_pool3d_backward/roiaware_pool3d_backward.cpp index 55e85b38d..165a1d73c 100755 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/roiaware_pool3d_backward/roiaware_pool3d_backward.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/roiaware_pool3d_backward/roiaware_pool3d_backward.cpp @@ -154,7 +154,7 @@ void RoiawarePool3dBackwardExecutor::initData() { max_pts_each_voxel_ = roiaware_pool3d_backward_proto_desc.max_pts_each_voxel(); - pts_num_ = desc_grad_in_->dims[0]; + pts_num_ = desc_grad_in_->getDimIndex(0); VLOG(4) << "RoiawarePool3dBackwardExecutor::initData() End."; } diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/roipoint_pool3d/roipoint_pool3d.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/roipoint_pool3d/roipoint_pool3d.cpp index 1637d5e6e..56a0dfba5 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/roipoint_pool3d/roipoint_pool3d.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/roipoint_pool3d/roipoint_pool3d.cpp @@ -191,11 +191,11 @@ void RoipointPool3dExecutor::workspaceMalloc() { auto tensor_pooled_features = tensor_desc_[3].tensor; auto tensor_pooled_empty_flag = tensor_desc_[4].tensor; - int batch_size = tensor_points->dims[0]; - int pts_num = tensor_points->dims[1]; - int boxes_num = tensor_boxes3d->dims[1]; - int feature_len = tensor_point_features->dims[2]; - int sampled_pts_num = tensor_pooled_features->dims[2]; + int batch_size = tensor_points->getDimIndex(0); + int pts_num = tensor_points->getDimIndex(1); + int boxes_num = tensor_boxes3d->getDimIndex(1); + int feature_len = tensor_point_features->getDimIndex(2); + int sampled_pts_num = tensor_pooled_features->getDimIndex(2); void *workspace_ptr = nullptr; MLUOP_CHECK(mluOpGetRoiPointPool3dWorkspaceSize( @@ -223,10 +223,10 @@ void RoipointPool3dExecutor::compute() { auto tensor_pooled_features = tensor_desc_[3].tensor; auto tensor_pooled_empty_flag = tensor_desc_[4].tensor; - int batch_size = tensor_points->dims[0]; - int pts_num = tensor_points->dims[1]; - int boxes_num = tensor_boxes3d->dims[1]; - int feature_len = tensor_point_features->dims[2]; + int batch_size = tensor_points->getDimIndex(0); + int pts_num = tensor_points->getDimIndex(1); + int boxes_num = tensor_boxes3d->getDimIndex(1); + int feature_len = tensor_point_features->getDimIndex(2); auto dev_points = data_vector_[0].device_ptr; auto dev_point_features = data_vector_[1].device_ptr; @@ -253,11 +253,11 @@ void RoipointPool3dExecutor::cpuCompute() { auto tensor_pooled_features = tensor_desc_[3].tensor; auto tensor_pooled_empty_flag = tensor_desc_[4].tensor; - int batch_size = tensor_points->dims[0]; - int pts_num = tensor_points->dims[1]; - int boxes_num = tensor_boxes3d->dims[1]; - int feature_len = tensor_point_features->dims[2]; - int sampled_pts_num = tensor_pooled_features->dims[2]; + int batch_size = tensor_points->getDimIndex(0); + int pts_num = tensor_points->getDimIndex(1); + int boxes_num = tensor_boxes3d->getDimIndex(1); + int feature_len = tensor_point_features->getDimIndex(2); + int sampled_pts_num = tensor_pooled_features->getDimIndex(2); auto points = cpu_fp32_input_[0]; auto point_features = cpu_fp32_input_[1]; @@ -299,11 +299,11 @@ int64_t RoipointPool3dExecutor::getTheoryOps() { auto tensor_pooled_features = tensor_desc_[3].tensor; auto tensor_pooled_empty_flag = tensor_desc_[4].tensor; - int64_t batch_size = tensor_points->dims[0]; - int64_t pts_num = tensor_points->dims[1]; - int64_t boxes_num = tensor_boxes3d->dims[1]; - int64_t feature_len = tensor_point_features->dims[2]; - int64_t sampled_pts_num = tensor_pooled_features->dims[2]; + int64_t batch_size = tensor_points->getDimIndex(0); + int64_t pts_num = tensor_points->getDimIndex(1); + int64_t boxes_num = tensor_boxes3d->getDimIndex(1); + int64_t feature_len = tensor_point_features->getDimIndex(2); + int64_t sampled_pts_num = tensor_pooled_features->getDimIndex(2); int64_t count = 21 + feature_len; int64_t theory_ops = batch_size * pts_num * count * boxes_num; diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/rotated_feature_align_backward/rotated_feature_align_backward.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/rotated_feature_align_backward/rotated_feature_align_backward.cpp index 306f23c66..54c0d74f6 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/rotated_feature_align_backward/rotated_feature_align_backward.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/rotated_feature_align_backward/rotated_feature_align_backward.cpp @@ -103,11 +103,11 @@ void RotatedFeatureAlignBackwardExecutor::cpuCompute() { const int output_size = parser_->getOutputDataCount(0); auto top_output_desc = tensor_desc_[0].tensor; auto bboxes_desc = tensor_desc_[1].tensor; - const int batch = top_output_desc->dims[0]; - const int height = top_output_desc->dims[1]; - const int width = top_output_desc->dims[2]; - const int channels = top_output_desc->dims[3]; - const int bboxes_offset = bboxes_desc->dims[3]; + const int batch = top_output_desc->getDimIndex(0); + const int height = top_output_desc->getDimIndex(1); + const int width = top_output_desc->getDimIndex(2); + const int channels = top_output_desc->getDimIndex(3); + const int bboxes_offset = bboxes_desc->getDimIndex(3); float px[5] = {0, 0, 0, 0, 0}; float py[5] = {0, 0, 0, 0, 0}; for (int index = 0; index < output_size; index++) { diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/rotated_feature_align_forward/rotated_feature_align_forward.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/rotated_feature_align_forward/rotated_feature_align_forward.cpp index df0b085dd..e2217444c 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/rotated_feature_align_forward/rotated_feature_align_forward.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/rotated_feature_align_forward/rotated_feature_align_forward.cpp @@ -109,11 +109,11 @@ void RotatedFeatureAlignForwardExecutor::cpuCompute() { auto input_desc = tensor_desc_[0].tensor; auto bboxes_desc = tensor_desc_[1].tensor; - const int batch = input_desc->dims[0]; - const int height = input_desc->dims[1]; - const int width = input_desc->dims[2]; - const int channels = input_desc->dims[3]; - const int bboxes_offset = bboxes_desc->dims[3]; + const int batch = input_desc->getDimIndex(0); + const int height = input_desc->getDimIndex(1); + const int width = input_desc->getDimIndex(2); + const int channels = input_desc->getDimIndex(3); + const int bboxes_offset = bboxes_desc->getDimIndex(3); float px[5] = {0, 0, 0, 0, 0}; float py[5] = {0, 0, 0, 0, 0}; diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/sync_batch_norm_backward_elemt/sync_batch_norm_backward_elemt.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/sync_batch_norm_backward_elemt/sync_batch_norm_backward_elemt.cpp index 8334dd344..ccd77e265 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/sync_batch_norm_backward_elemt/sync_batch_norm_backward_elemt.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/sync_batch_norm_backward_elemt/sync_batch_norm_backward_elemt.cpp @@ -108,7 +108,7 @@ void SyncBatchNormBackwardElemtExecutor::compute() { void SyncBatchNormBackwardElemtExecutor::cpuCompute() { int len_x = parser_->getInputDataCount(0); - int len_c = tensor_desc_[0].tensor->dims[tensor_desc_[0].tensor->dim - 1]; + int len_c = tensor_desc_[0].tensor->getDimIndex(tensor_desc_[0].tensor->getDim() - 1); if (len_x == 0 || len_c == 0) { VLOG(4) << "SyncBatchNormBackwardElemtExecutor: cpu compute zero elemt"; @@ -143,7 +143,7 @@ void SyncBatchNormBackwardElemtExecutor::cpuCompute() { int64_t SyncBatchNormBackwardElemtExecutor::getTheoryOps() { int64_t theory_ops = 0; int len_x = parser_->getInputDataCount(0); - int len_c = tensor_desc_[0].tensor->dims[tensor_desc_[0].tensor->dim - 1]; + int len_c = tensor_desc_[0].tensor->getDimIndex(tensor_desc_[0].tensor->getDim() - 1); if (parser_->getInputNum() == 7) { theory_ops = 5 * len_x + 3 * len_c; } else { diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/sync_batchnorm_backward_elemt_v2/sync_batchnorm_backward_elemt_v2.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/sync_batchnorm_backward_elemt_v2/sync_batchnorm_backward_elemt_v2.cpp index 0c67b8520..bcabded1b 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/sync_batchnorm_backward_elemt_v2/sync_batchnorm_backward_elemt_v2.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/sync_batchnorm_backward_elemt_v2/sync_batchnorm_backward_elemt_v2.cpp @@ -115,8 +115,8 @@ void SyncBatchnormBackwardElemtV2Executor::compute() { void SyncBatchnormBackwardElemtV2Executor::cpuCompute() { int len_x = parser_->getInputDataCount(0); - int len_c = tensor_desc_[0].tensor->dims[tensor_desc_[0].tensor->dim - 1]; - int len_n = tensor_desc_[0].tensor->dims[0]; + int len_c = tensor_desc_[0].tensor->getDimIndex(tensor_desc_[0].tensor->getDim() - 1); + int len_n = tensor_desc_[0].tensor->getDimIndex(0); if (len_x == 0 || len_c == 0) { VLOG(4) << "SyncBatchnormBackwardElemtV2Executor: cpu compute zero elemt"; @@ -158,7 +158,7 @@ void SyncBatchnormBackwardElemtV2Executor::cpuCompute() { int64_t SyncBatchnormBackwardElemtV2Executor::getTheoryOps() { int64_t theory_ops = 0; int len_x = parser_->getInputDataCount(0); - int len_c = tensor_desc_[0].tensor->dims[tensor_desc_[0].tensor->dim - 1]; + int len_c = tensor_desc_[0].tensor->getDimIndex(tensor_desc_[0].tensor->getDim() - 1); if (parser_->getInputNum() == 7) { theory_ops = 5 * len_x + 3 * len_c; } else { diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/sync_batchnorm_backward_reduce/sync_batchnorm_backward_reduce.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/sync_batchnorm_backward_reduce/sync_batchnorm_backward_reduce.cpp index b0b415fd2..b4072bc31 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/sync_batchnorm_backward_reduce/sync_batchnorm_backward_reduce.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/sync_batchnorm_backward_reduce/sync_batchnorm_backward_reduce.cpp @@ -230,7 +230,7 @@ void cpuGetSyncBnBkwReduceOuput( } void SyncBatchnormBackwardReduceExecutor::cpuCompute() { - int len_c = tensor_desc_[0].tensor->dims[tensor_desc_[0].tensor->dim - 1]; + int len_c = tensor_desc_[0].tensor->getDimIndex(tensor_desc_[0].tensor->getDim() - 1); int len_x = parser_->getInputDataCount(0); const bool needs_input_grad0 = parser_->getProtoNode() ->sync_batchnorm_backward_reduce_param() diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/sync_batchnorm_elemt/sync_batchnorm_elemt.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/sync_batchnorm_elemt/sync_batchnorm_elemt.cpp index c1db5a4a6..b19cb78da 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/sync_batchnorm_elemt/sync_batchnorm_elemt.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/sync_batchnorm_elemt/sync_batchnorm_elemt.cpp @@ -80,7 +80,7 @@ void cpuSyncBNElemt(const float *x, const float *mean, const float *invstd, } void SyncBatchnormElemtExecutor::cpuCompute() { - int len_c = tensor_desc_[0].tensor->dims[tensor_desc_[0].tensor->dim - 1]; + int len_c = tensor_desc_[0].tensor->getDimIndex(tensor_desc_[0].tensor->getDim() - 1); int len_x = parser_->getInputDataCount(0); VLOG(4) << "SyncBatchnormElemtExecutor: cpu compute begin"; diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/sync_batchnorm_gather_stats_with_counts/sync_batchnorm_gather_stats_with_counts.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/sync_batchnorm_gather_stats_with_counts/sync_batchnorm_gather_stats_with_counts.cpp index 72832d21e..7c568f323 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/sync_batchnorm_gather_stats_with_counts/sync_batchnorm_gather_stats_with_counts.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/sync_batchnorm_gather_stats_with_counts/sync_batchnorm_gather_stats_with_counts.cpp @@ -222,33 +222,33 @@ void SyncBatchnormGatherStatsWithCountsExecutor::cpuCompute() { ->sync_batchnorm_gather_stats_with_counts_param() .momentum(); - int idx_c = tensor_desc_[0].tensor->dim - 1; - int len_c = tensor_desc_[0].tensor->dims[idx_c]; + int idx_c = tensor_desc_[0].tensor->getDim() - 1; + int len_c = tensor_desc_[0].tensor->getDimIndex(idx_c); int len_count_all = 1; int len_mean_all = 1; int len_invstd_all = 1; if (parser_->getInputNum() == 3) { - len_count_all = tensor_desc_[2].tensor->dims[0]; + len_count_all = tensor_desc_[2].tensor->getDimIndex(0); } else if (parser_->getInputNum() == 4) { - len_count_all = tensor_desc_[3].tensor->dims[0]; + len_count_all = tensor_desc_[3].tensor->getDimIndex(0); } else if (parser_->getInputNum() == 5) { - len_count_all = tensor_desc_[4].tensor->dims[0]; + len_count_all = tensor_desc_[4].tensor->getDimIndex(0); } else if (parser_->getInputNum() == 6) { - len_count_all = tensor_desc_[5].tensor->dims[0]; + len_count_all = tensor_desc_[5].tensor->getDimIndex(0); } if (parser_->getInputNum() == 3 || parser_->getInputNum() == 5) { - for (int i = 0; i < tensor_desc_[0].tensor->dim; ++i) { - len_mean_all *= tensor_desc_[0].tensor->dims[i]; + for (int i = 0; i < tensor_desc_[0].tensor->getDim(); ++i) { + len_mean_all *= tensor_desc_[0].tensor->getDimIndex(i); } - for (int i = 0; i < tensor_desc_[1].tensor->dim; ++i) { - len_invstd_all *= tensor_desc_[1].tensor->dims[i]; + for (int i = 0; i < tensor_desc_[1].tensor->getDim(); ++i) { + len_invstd_all *= tensor_desc_[1].tensor->getDimIndex(i); } } else { - for (int i = 0; i < tensor_desc_[1].tensor->dim; ++i) { - len_mean_all *= tensor_desc_[1].tensor->dims[i]; + for (int i = 0; i < tensor_desc_[1].tensor->getDim(); ++i) { + len_mean_all *= tensor_desc_[1].tensor->getDimIndex(i); } - for (int i = 0; i < tensor_desc_[2].tensor->dim; ++i) { - len_invstd_all *= tensor_desc_[2].tensor->dims[i]; + for (int i = 0; i < tensor_desc_[2].tensor->getDim(); ++i) { + len_invstd_all *= tensor_desc_[2].tensor->getDimIndex(i); } } if (len_mean_all == 0 || len_c == 0 || len_count_all == 0 || diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/sync_batchnorm_stats/sync_batchnorm_stats.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/sync_batchnorm_stats/sync_batchnorm_stats.cpp index e32d9d211..4a2e02644 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/sync_batchnorm_stats/sync_batchnorm_stats.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/sync_batchnorm_stats/sync_batchnorm_stats.cpp @@ -117,11 +117,11 @@ void cpuSyncBatchNormStats(const float *x, const float eps, float *mean, void SyncBatchnormStatsExecutor::cpuCompute() { float eps = parser_->getProtoNode()->sync_batchnorm_stats_param().eps(); - int idx_c = tensor_desc_[0].tensor->dim - 1; - int len_c = tensor_desc_[0].tensor->dims[idx_c]; + int idx_c = tensor_desc_[0].tensor->getDim() - 1; + int len_c = tensor_desc_[0].tensor->getDimIndex(idx_c); int len_x = 1; - for (int i = 0; i < tensor_desc_[0].tensor->dim; ++i) { - len_x *= tensor_desc_[0].tensor->dims[i]; + for (int i = 0; i < tensor_desc_[0].tensor->getDim(); ++i) { + len_x *= tensor_desc_[0].tensor->getDimIndex(i); } if (len_x == 0 || len_c == 0) { return; diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/three_interpolate_backward/three_interpolate_backward.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/three_interpolate_backward/three_interpolate_backward.cpp index d71e68098..50ffb33b9 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/three_interpolate_backward/three_interpolate_backward.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/three_interpolate_backward/three_interpolate_backward.cpp @@ -41,10 +41,10 @@ void ThreeInterpolateBackwardExecutor::compute() { auto indices_data_ptr = data_vector_[1].device_ptr; auto weights_data_ptr = data_vector_[2].device_ptr; auto grad_features_data_ptr = data_vector_[3].device_ptr; - b_ = grad_output_desc->dims[0]; - c_ = grad_output_desc->dims[1]; - n_ = grad_output_desc->dims[2]; - m_ = grad_features_desc->dims[2]; + b_ = grad_output_desc->getDimIndex(0); + c_ = grad_output_desc->getDimIndex(1); + n_ = grad_output_desc->getDimIndex(2); + m_ = grad_features_desc->getDimIndex(2); VLOG(4) << "call mluOpThreeInterpolateBackward()"; interface_timer_.start(); MLUOP_CHECK(mluOpThreeInterpolateBackward( diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/three_interpolate_forward/three_interpolate_forward.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/three_interpolate_forward/three_interpolate_forward.cpp index c428fcb35..0b6038c4b 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/three_interpolate_forward/three_interpolate_forward.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/three_interpolate_forward/three_interpolate_forward.cpp @@ -41,10 +41,10 @@ void ThreeInterpolateForwardExecutor::compute() { auto indices_data_ptr = data_vector_[1].device_ptr; auto weights_data_ptr = data_vector_[2].device_ptr; auto output_data_ptr = data_vector_[3].device_ptr; - b_ = features_desc->dims[0]; - c_ = features_desc->dims[1]; - m_ = features_desc->dims[2]; - n_ = output_desc->dims[2]; + b_ = features_desc->getDimIndex(0); + c_ = features_desc->getDimIndex(1); + m_ = features_desc->getDimIndex(2); + n_ = output_desc->getDimIndex(2); VLOG(4) << "call mluOpThreeInterpolateForward()"; interface_timer_.start(); MLUOP_CHECK(mluOpThreeInterpolateForward( diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/tin_shift_backward/tin_shift_backward.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/tin_shift_backward/tin_shift_backward.cpp index c74834c02..6e0d0e627 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/tin_shift_backward/tin_shift_backward.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/tin_shift_backward/tin_shift_backward.cpp @@ -55,12 +55,12 @@ void TinShiftBackwardExecutor::cpuCompute() { auto x = tensor_desc_[0].tensor; auto x1 = tensor_desc_[1].tensor; auto count1 = parser_->getInputDataCount(0); - int batch_size = x->dims[0]; - int t_size = x->dims[1]; - int channels = x->dims[2]; - int hw_size = x->dims[3]; - int group_batch = x1->dims[0]; - int group_size = x1->dims[1]; + int batch_size = x->getDimIndex(0); + int t_size = x->getDimIndex(1); + int channels = x->getDimIndex(2); + int hw_size = x->getDimIndex(3); + int group_batch = x1->getDimIndex(0); + int group_size = x1->getDimIndex(1); int group_channel = channels / group_size; for (int index = 0; index < count1; index++) { diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/tin_shift_forward/tin_shift_forward.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/tin_shift_forward/tin_shift_forward.cpp index 4c65b8f88..ddcccc2f4 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/tin_shift_forward/tin_shift_forward.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/tin_shift_forward/tin_shift_forward.cpp @@ -55,12 +55,12 @@ void TinShiftForwardExecutor::cpuCompute() { auto x = tensor_desc_[0].tensor; auto x1 = tensor_desc_[1].tensor; auto count1 = parser_->getInputDataCount(0); - int batch_size = x->dims[0]; - int t_size = x->dims[1]; - int channels = x->dims[2]; - int hw_size = x->dims[3]; - int group_batch = x1->dims[0]; - int group_size = x1->dims[1]; + int batch_size = x->getDimIndex(0); + int t_size = x->getDimIndex(1); + int channels = x->getDimIndex(2); + int hw_size = x->getDimIndex(3); + int group_batch = x1->getDimIndex(0); + int group_size = x1->getDimIndex(1); int group_channel = channels / group_size; for (int index = 0; index < count1; index++) { diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/voxelization/voxelization.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/voxelization/voxelization.cpp index f8338257a..8b99c7f22 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/voxelization/voxelization.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/voxelization/voxelization.cpp @@ -329,8 +329,8 @@ void VoxelizationExecutor::cpuCompute() { parser_->getProtoNode()->voxelization_param().deterministic(); auto tensor_points = tensor_desc_[0].tensor; - size_t num_points = tensor_points->dims[0]; - size_t num_features = tensor_points->dims[1]; + size_t num_points = tensor_points->getDimIndex(0); + size_t num_features = tensor_points->getDimIndex(1); float *points = cpu_fp32_input_[0]; float *voxel_size = cpu_fp32_input_[1]; @@ -359,8 +359,8 @@ int64_t VoxelizationExecutor::getTheoryIoSize() { parser_->getProtoNode()->voxelization_param().max_voxels(); auto tensor_points = tensor_desc_[0].tensor; - size_t num_points = tensor_points->dims[0]; - size_t num_features = tensor_points->dims[1]; + size_t num_points = tensor_points->getDimIndex(0); + size_t num_features = tensor_points->getDimIndex(1); int64_t total_size = 0; // mluOpUnionKernelDynamicVoxelize @@ -387,7 +387,7 @@ int64_t VoxelizationExecutor::getTheoryIoSize() { int64_t VoxelizationExecutor::getTheoryOps() { auto tensor_points = tensor_desc_[0].tensor; - size_t num_points = tensor_points->dims[0]; + size_t num_points = tensor_points->getDimIndex(0); int64_t theory_ops = 0; int32_t cp_count = 31; diff --git a/test/mlu_op_gtest/pb_gtest/src/zoo/yolo_box/yolo_box.cpp b/test/mlu_op_gtest/pb_gtest/src/zoo/yolo_box/yolo_box.cpp index f86e06dac..f62ce9814 100644 --- a/test/mlu_op_gtest/pb_gtest/src/zoo/yolo_box/yolo_box.cpp +++ b/test/mlu_op_gtest/pb_gtest/src/zoo/yolo_box/yolo_box.cpp @@ -164,9 +164,9 @@ void YoloBoxExecutor::cpuCompute() { memset(boxes_data, 0, boxes_size); memset(scores_data, 0, scores_size); - const int n = x_desc->dims[0]; - const int h = x_desc->dims[2]; - const int w = x_desc->dims[3]; + const int n = x_desc->getDimIndex(0); + const int h = x_desc->getDimIndex(2); + const int w = x_desc->getDimIndex(3); auto anchors_desc = tensor_desc_[2].tensor; uint64_t anchors_tensor_num = mluOpGetTensorElementNum(anchors_desc); const int an_num = anchors_tensor_num / 2; From bfb78fde7632d46a3be144de134250a00b24cc81 Mon Sep 17 00:00:00 2001 From: nizhijie Date: Tue, 26 Nov 2024 15:20:35 +0800 Subject: [PATCH 3/3] [Feature](mluOpKernels): access variable in tensor struct through function in kernels --- core/gen_case.cpp | 2 +- core/gen_case.h | 2 +- core/tensor.cpp | 806 ++++++++++-------- core/tensor.h | 212 ++++- kernels/abs/abs.cpp | 32 +- .../active_rotated_filter.cpp | 68 +- kernels/adam_w/adam_w.cpp | 10 +- kernels/ball_query/ball_query.cpp | 46 +- kernels/bbox_overlaps/bbox_overlaps.cpp | 70 +- kernels/binary_op/binary_op_host.cpp | 64 +- .../border_align_backward.cpp | 84 +- .../border_align_forward.cpp | 76 +- kernels/box_iou_rotated/box_iou_rotated.cpp | 68 +- kernels/carafe/carafe.cpp | 76 +- kernels/deform_roi_pool/deform_roi_pool.cpp | 152 ++-- ...diff_iou_rotated_sort_vertices_forward.cpp | 64 +- kernels/div/div.cpp | 4 +- .../dynamic_point_to_voxel_backward.cpp | 66 +- .../dynamic_point_to_voxel_forward.cpp | 56 +- kernels/fft/c2c_fft/c2c_fft_host.cpp | 6 +- kernels/fft/common/fft_basic_ops.cpp | 10 +- kernels/fft/fft.cpp | 46 +- kernels/fft/irfft/irfft_host.cpp | 6 +- kernels/fft/rfft/rfft_host.cpp | 6 +- .../focal_loss_sigmoid/focal_loss_sigmoid.cpp | 130 +-- .../generate_proposals_v2.cpp | 150 ++-- kernels/lgamma/lgamma.cpp | 6 +- kernels/log/log.cpp | 2 +- kernels/logspace/logspace.cpp | 4 +- .../masked_col2im_forward.cpp | 80 +- .../masked_im2col_forward.cpp | 66 +- .../moe_dispatch_backward_data.cpp | 42 +- .../moe_dispatch_backward_gate.cpp | 46 +- .../moe_dispatch_forward.cpp | 42 +- .../ms_deform_attn_backward.cpp | 134 +-- .../ms_deform_attn_forward.mlu | 74 +- .../mutual_information_backward.cpp | 146 ++-- .../mutual_information_forward.cpp | 104 +-- kernels/nms_rotated/nms_rotated.cpp | 36 +- kernels/points_in_boxes/points_in_boxes.cpp | 62 +- kernels/poly_nms/poly_nms.cpp | 26 +- kernels/prior_box/prior_box.cpp | 72 +- kernels/psamask/psamask.cpp | 52 +- kernels/psroipool/psroipool.cpp | 130 +-- .../roi_align_rotated/roi_align_rotated.cpp | 108 +-- kernels/roi_crop/roi_crop.cpp | 92 +- kernels/roiaware_pool3d/roiaware_pool3d.cpp | 168 ++-- kernels/roipoint_pool3d/roipoint_pool3d.cpp | 82 +- .../rotated_feature_align.cpp | 92 +- .../get_indice_pairs/get_indice_pairs.cpp | 34 +- .../normal_get_indice_pairs.cpp | 26 +- .../indice_convolution_backward_data.cpp | 176 ++-- .../indice_convolution_backward_filter.cpp | 112 +-- .../indice_convolution_forward.cpp | 106 +-- kernels/sqrt/sqrt.cpp | 12 +- .../tensor_stride_process_host.cpp | 52 +- .../three_interpolate/three_interpolate.cpp | 136 +-- kernels/three_nn_forward/three_nn_forward.cpp | 64 +- kernels/tin_shift/tin_shift.cpp | 80 +- kernels/unary_op/unary_op_host.cpp | 26 +- .../voxel_pooling_forward.cpp | 42 +- kernels/voxelization/voxelization.cpp | 56 +- kernels/yolo_box/yolo_box.cpp | 58 +- 63 files changed, 2623 insertions(+), 2335 deletions(-) diff --git a/core/gen_case.cpp b/core/gen_case.cpp index dfc103e58..2ad7dbf4d 100644 --- a/core/gen_case.cpp +++ b/core/gen_case.cpp @@ -761,7 +761,7 @@ std::string descToString(mluOpTensorDescriptor_t desc, char delimiter) { tensor_info << " layout: " << mluop::getNameOfTensorLayout(layout) << delimiter; tensor_info << " dtype: " << mluop::getNameOfDataType(dtype) << delimiter; - if (desc->pointer_mode == MLUOP_POINTER_MODE_HOST) { + if (desc->getPointerMode() == MLUOP_POINTER_MODE_HOST) { tensor_info << " pointer_mode: POINTER_MODE_HOST" << delimiter; if ((total_element_num != 1) || (dim != 0)) { LOG(WARNING) << "[gen_case] Tensor has been set to POINTER_MODE_HOST, " diff --git a/core/gen_case.h b/core/gen_case.h index 7e60c9de7..0bfe6c405 100644 --- a/core/gen_case.h +++ b/core/gen_case.h @@ -492,7 +492,7 @@ class PbNode { uint64_t data_size = total_num * mluop::getSizeOfDataType(dtype); void *data = malloc(data_size); auto memcpy_dir = - (tensors[index].desc->pointer_mode == MLUOP_POINTER_MODE_HOST + (tensors[index].desc->getPointerMode() == MLUOP_POINTER_MODE_HOST ? cnrtMemcpyHostToHost : cnrtMemcpyDevToHost); if (cnrtSuccess == cnrtMemcpy(data, diff --git a/core/tensor.cpp b/core/tensor.cpp index 72af32672..8f6207760 100644 --- a/core/tensor.cpp +++ b/core/tensor.cpp @@ -40,6 +40,41 @@ } /* mluOpTensorStruct */ +static inline mluOpStatus_t mluOpSetTensorDescriptorZeroDim( + mluOpTensorDescriptor_t desc) { + if (desc->getPointerMode() == MLUOP_POINTER_MODE_HOST) { + desc->setDim(0); + desc->setTotalElementNum(1); + desc->setTotalTensorSize(mluop::getSizeOfDataType(desc->getDtype())); + return MLUOP_STATUS_SUCCESS; + } else { + LOG(ERROR) + << "[mluOpSetTensorDescriptorDim]: Currently, the dim can be set to 0" + << " only when the pointer mode of desc is MLUOP_POINTER_MODE_HOST. " + << "Please use [mluOpSetTensorDescriptorPointerMode] to set the " + "pointer " + << "mode of desc."; + return MLUOP_STATUS_BAD_PARAM; + } +} + +static inline void mluOpSetTensorDescriptorDimBase(mluOpTensorDescriptor_t desc, + int dimNb) { + if (dimNb != desc->getDim()) { + if MLUOP_PREDICT_FALSE (desc->getDims() != desc->getNormalDims()) { + desc->releaseDims(); + desc->releaseStrides(); + } + if MLUOP_PREDICT_FALSE (dimNb > MLUOP_DIM_MAX) { + desc->setDims(new (std::nothrow) int64_t[dimNb]); + desc->setStrides(new (std::nothrow) int64_t[dimNb]); + } else { + desc->setDims(desc->getNormalDims()); + desc->setStrides(desc->getNormalStrides()); + } + desc->setDim(dimNb); + } +} mluOpStatus_t mluOpTensorStruct::tensorDimN(size_t &dim_out) { size_t index; @@ -339,139 +374,53 @@ static mluOpTensorDescriptorQueueStruct queue_array; #endif } // anonymous namespace -/* MLUOP interface */ -mluOpStatus_t MLUOP_WIN_API -mluOpCreateTensorDescriptor(mluOpTensorDescriptor_t *desc) { - PARAM_CHECK("[mluOpCreateTensorDescriptor]", desc != NULL); - -#if MLUOP_TENSOR_QUEUE_ENABLE - queue_array.lock(); - if MLUOP_PREDICT_FALSE (queue_array.queue.empty()) { - queue_array.extend(queue_array.extend_num); - queue_array.extend_num *= 2; - } - *desc = ::new (queue_array.queue.front()) mluOpTensorStruct; - queue_array.queue.pop_front(); - queue_array.unlock(); -#else - mluOpTensorStruct *ts = new (std::nothrow) mluOpTensorStruct; - *desc = ts; -#endif - - return MLUOP_STATUS_SUCCESS; -} - -mluOpStatus_t MLUOP_WIN_API mluOpCreateGroupTensorDescriptors( - mluOpTensorDescriptor_t **group_desc, const int desc_num) { - PARAM_CHECK("[mluOpCreateGroupTensorDescriptors]", group_desc != NULL); - PARAM_CHECK("[mluOpCreateGroupTensorDescriptors]", desc_num > 0); - -#if MLUOP_TENSOR_QUEUE_ENABLE - queue_array.lock(); - if MLUOP_PREDICT_FALSE (queue_array.queue.size() < desc_num) { - queue_array.extend(std::max(queue_array.extend_num, (size_t)desc_num)); - queue_array.extend_num = - 2 * std::max(queue_array.extend_num, (size_t)desc_num); - } - for (int i = 0; i < desc_num; ++i) { - *(group_desc[i]) = queue_array.queue.front(); - queue_array.queue.pop_front(); - } - queue_array.unlock(); -#else - for (int i = 0; i < desc_num; ++i) { - mluOpTensorStruct *ts = new (std::nothrow) mluOpTensorStruct; - group_desc[i][0] = ts; - } -#endif - - return MLUOP_STATUS_SUCCESS; -} - -static inline mluOpStatus_t mluOpSetTensorDescriptorZeroDim( - mluOpTensorDescriptor_t desc) { - if (desc->pointer_mode == MLUOP_POINTER_MODE_HOST) { - desc->dim = 0; - desc->total_element_num = 1; - desc->total_tensor_size = mluop::getSizeOfDataType(desc->dtype); - return MLUOP_STATUS_SUCCESS; - } else { - LOG(ERROR) - << "[mluOpSetTensorDescriptorDim]: Currently, the dim can be set to 0" - << " only when the pointer mode of desc is MLUOP_POINTER_MODE_HOST. " - << "Please use [mluOpSetTensorDescriptorPointerMode] to set the " - "pointer " - << "mode of desc."; - return MLUOP_STATUS_BAD_PARAM; - } -} - -mluOpStatus_t MLUOP_WIN_API mluOpSetTensorDescriptor( - mluOpTensorDescriptor_t desc, mluOpTensorLayout_t layout, - mluOpDataType_t dtype, int dimNb, const int *dimSize) { - PARAM_CHECK("[mluOpSetTensorDescriptor]", desc != NULL); +mluOpStatus_t mluOpTensorStruct::setTensorDescriptor(mluOpTensorLayout_t layout, + mluOpDataType_t dtype, + int dimNb, + const int *dimSize) { PARAM_CHECK("[mluOpSetTensorDescriptor]", layout >= 0); PARAM_CHECK("[mluOpSetTensorDescriptor]", dtype >= 0); - desc->dtype = dtype; - desc->layout = layout; + this->dtype = dtype; + this->layout = layout; if (dimNb == 0) { - return mluOpSetTensorDescriptorZeroDim(desc); + return mluOpSetTensorDescriptorZeroDim(this); } else { PARAM_CHECK("[mluOpSetTensorDescriptor]", dimNb > 0); PARAM_CHECK("[mluOpSetTensorDescriptor]", dimSize != NULL); - return mluOpSetTensorDescriptorDim(desc, dimNb, dimSize); + return mluOpSetTensorDescriptorDim(this, dimNb, dimSize); } } -mluOpStatus_t MLUOP_WIN_API mluOpSetTensorDescriptor_v2( - mluOpTensorDescriptor_t desc, mluOpTensorLayout_t layout, - mluOpDataType_t dtype, int dimNb, const int64_t *dimSize) { - PARAM_CHECK("[mluOpSetTensorDescriptor]", desc != NULL); +mluOpStatus_t mluOpTensorStruct::setTensorDescriptor_v2( + mluOpTensorLayout_t layout, mluOpDataType_t dtype, int dimNb, + const int64_t *dimSize) { PARAM_CHECK("[mluOpSetTensorDescriptor]", layout >= 0); PARAM_CHECK("[mluOpSetTensorDescriptor]", dtype >= 0); - desc->dtype = dtype; - desc->layout = layout; + this->dtype = dtype; + this->layout = layout; if (dimNb == 0) { - return mluOpSetTensorDescriptorZeroDim(desc); + return mluOpSetTensorDescriptorZeroDim(this); } else { PARAM_CHECK("[mluOpSetTensorDescriptor]", dimNb > 0); PARAM_CHECK("[mluOpSetTensorDescriptor]", dimSize != NULL); - return mluOpSetTensorDescriptorDim_v2(desc, dimNb, dimSize); + return mluOpSetTensorDescriptorDim_v2(this, dimNb, dimSize); } } // Internal interface. Caller should guarantee parameter validity. -static inline void mluOpSetTensorDescriptorDimBase(mluOpTensorDescriptor_t desc, - int dimNb) { - if (dimNb != desc->dim) { - if MLUOP_PREDICT_FALSE (desc->dims != desc->normal_dims) { - delete[] desc->dims; - delete[] desc->strides; - } - if MLUOP_PREDICT_FALSE (dimNb > MLUOP_DIM_MAX) { - desc->dims = new (std::nothrow) int64_t[dimNb]; - desc->strides = new (std::nothrow) int64_t[dimNb]; - } else { - desc->dims = desc->normal_dims; - desc->strides = desc->normal_strides; - } - desc->dim = dimNb; - } -} - -mluOpStatus_t MLUOP_WIN_API mluOpSetTensorDescriptorDim( - mluOpTensorDescriptor_t desc, int dimNb, const int *dimSize) { +mluOpStatus_t mluOpTensorStruct::setTensorDescriptorDim(int dimNb, + const int *dimSize) { if (dimNb == 0) { CHECK_RETURN("[mluOpSetTensorDescriptorDim]", - mluOpSetTensorDescriptorZeroDim(desc)); + mluOpSetTensorDescriptorZeroDim(this)); } else { - mluOpSetTensorDescriptorDimBase(desc, dimNb); - std::copy(dimSize, dimSize + dimNb, desc->dims); + mluOpSetTensorDescriptorDimBase(this, dimNb); + std::copy(dimSize, dimSize + dimNb, this->dims); } // infer strides of dimNb dimensions and compute total_num & total_size @@ -479,13 +428,13 @@ mluOpStatus_t MLUOP_WIN_API mluOpSetTensorDescriptorDim( bool is_overflow = false; int tmp_num = 0; for (int i = dimNb - 1; i >= 0; --i) { - desc->strides[i] = stride_base; + this->strides[i] = stride_base; is_overflow |= __builtin_smul_overflow(stride_base, dimSize[i], &tmp_num); stride_base *= dimSize[i]; } - desc->total_element_num = stride_base; - desc->total_tensor_size = - desc->total_element_num * mluop::getSizeOfDataType(desc->dtype); + this->total_element_num = stride_base; + this->total_tensor_size = + this->total_element_num * mluop::getSizeOfDataType(this->dtype); // judge int overflow situation if (MLUOP_PREDICT_FALSE(is_overflow)) { std::stringstream tensor_info; @@ -495,7 +444,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpSetTensorDescriptorDim( } tensor_info << dimSize[dimNb - 1] - << "), data width:" << mluop::getSizeOfDataType(desc->dtype) + << "), data width:" << mluop::getSizeOfDataType(this->dtype) << "."; LOG(WARNING) << "[mluOpSetTensorDescriptor]: overflow max tensor num. " << "Currently, mluop supports tensor num smaller than 2^31, " @@ -504,24 +453,23 @@ mluOpStatus_t MLUOP_WIN_API mluOpSetTensorDescriptorDim( return MLUOP_STATUS_SUCCESS; } -mluOpStatus_t MLUOP_WIN_API mluOpSetTensorDescriptorDim_v2( - mluOpTensorDescriptor_t desc, int dimNb, const int64_t *dimSize) { - mluOpSetTensorDescriptorDimBase(desc, dimNb); - - memcpy(desc->dims, dimSize, dimNb * sizeof(int64_t)); +mluOpStatus_t mluOpTensorStruct::setTensorDescriptorDim_v2( + int dimNb, const int64_t *dimSize) { + mluOpSetTensorDescriptorDimBase(this, dimNb); + memcpy(this->dims, dimSize, dimNb * sizeof(int64_t)); // infer strides of dimNb dimensions and compute total_num & total_size uint64_t stride_base = 1; bool is_overflow = false; int64_t tmp_num = 0; for (int i = dimNb - 1; i >= 0; --i) { - desc->strides[i] = stride_base; + this->strides[i] = stride_base; is_overflow |= __builtin_smull_overflow(stride_base, dimSize[i], &tmp_num); stride_base *= dimSize[i]; } - desc->total_element_num = stride_base; - desc->total_tensor_size = - desc->total_element_num * mluop::getSizeOfDataType(desc->dtype); + this->total_element_num = stride_base; + this->total_tensor_size = + this->total_element_num * mluop::getSizeOfDataType(this->dtype); // judge int overflow situation if (MLUOP_PREDICT_FALSE(is_overflow)) { std::stringstream tensor_info; @@ -531,7 +479,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpSetTensorDescriptorDim_v2( } tensor_info << dimSize[dimNb - 1] - << "), data width:" << mluop::getSizeOfDataType(desc->dtype) + << "), data width:" << mluop::getSizeOfDataType(this->dtype) << "."; LOG(WARNING) << "[mluOpSetTensorDescriptor_v2]: overflow max tensor num. " << "Currently, mluop supports tensor num smaller than 2^63, " @@ -540,6 +488,359 @@ mluOpStatus_t MLUOP_WIN_API mluOpSetTensorDescriptorDim_v2( return MLUOP_STATUS_SUCCESS; } +mluOpStatus_t mluOpTensorStruct::resetTensorDescriptor() { + if MLUOP_PREDICT_FALSE (this->dims != this->normal_dims) { + delete[] this->dims; + this->dims = this->normal_dims; + } + if MLUOP_PREDICT_FALSE (this->strides != this->normal_strides) { + delete[] this->strides; + this->strides = this->normal_strides; + } + + this->dim = 0; + this->dtype = MLUOP_DTYPE_FLOAT; + this->onchip_dtype = MLUOP_DTYPE_INVALID; + this->layout = MLUOP_LAYOUT_ARRAY; + this->pointer_mode = MLUOP_POINTER_MODE_DEVICE; + + this->total_element_num = 0; + this->total_tensor_size = 0; + + this->position = 0; + this->scale = 1.0f; + this->offset = 0; + + return MLUOP_STATUS_SUCCESS; +} + +mluOpStatus_t mluOpTensorStruct::setTensorDescriptorEx( + mluOpTensorLayout_t layout, mluOpDataType_t dtype, int dimNb, + const int *dimSize, const int *dimStride) { + PARAM_CHECK("[mluOpSetTensorDescriptorEx]", layout >= 0); + PARAM_CHECK("[mluOpSetTensorDescriptorEx]", dtype >= 0); + + this->dtype = dtype; + this->layout = layout; + + if (dimNb == 0) { + return mluOpSetTensorDescriptorZeroDim(this); + } else { + PARAM_CHECK("[mluOpSetTensorDescriptorEx]", dimSize != NULL); + PARAM_CHECK("[mluOpSetTensorDescriptorEx]", dimStride != NULL); + PARAM_CHECK("[mluOpSetTensorDescriptorEx]", dimNb > 0); + + mluOpSetTensorDescriptorDimBase(this, dimNb); + std::copy(dimSize, dimSize + dimNb, this->dims); + std::copy(dimStride, dimStride + dimNb, this->strides); + + // assign total_element_num and total_tensor_size + this->total_element_num = 1; + for (int i = 0; i < dimNb; ++i) { + this->total_element_num *= dimSize[i]; + } + this->total_tensor_size = + this->total_element_num * mluop::getSizeOfDataType(dtype); + + return MLUOP_STATUS_SUCCESS; + } +} + +mluOpStatus_t mluOpTensorStruct::setTensorDescriptorEx_v2( + mluOpTensorLayout_t layout, mluOpDataType_t dtype, int dimNb, + const int64_t *dimSize, const int64_t *dimStride) { + PARAM_CHECK("[mluOpSetTensorDescriptorEx]", layout >= 0); + PARAM_CHECK("[mluOpSetTensorDescriptorEx]", dtype >= 0); + + this->dtype = dtype; + this->layout = layout; + + if MLUOP_PREDICT_FALSE (dimNb == 0) { + return mluOpSetTensorDescriptorZeroDim(this); + } else { + PARAM_CHECK("[mluOpSetTensorDescriptorEx]", dimSize != NULL); + PARAM_CHECK("[mluOpSetTensorDescriptorEx]", dimStride != NULL); + + mluOpSetTensorDescriptorDimBase(this, dimNb); + memcpy(this->dims, dimSize, dimNb * sizeof(int64_t)); + memcpy(this->strides, dimStride, dimNb * sizeof(int64_t)); + + // assign total_element_num and total_tensor_size + this->total_element_num = 1; + for (int i = 0; i < dimNb; ++i) { + this->total_element_num *= dimSize[i]; + } + this->total_tensor_size = + this->total_element_num * mluop::getSizeOfDataType(dtype); + + return MLUOP_STATUS_SUCCESS; + } +} + +mluOpStatus_t mluOpTensorStruct::setTensorDescriptorOnchipDataType( + mluOpDataType_t onchip_dtype) { + this->onchip_dtype = onchip_dtype; + return MLUOP_STATUS_SUCCESS; +} + +mluOpStatus_t mluOpTensorStruct::setTensorDescriptorPosition(int position) { + this->position = position; + return MLUOP_STATUS_SUCCESS; +} + +mluOpStatus_t mluOpTensorStruct::setTensorDescriptorPositionAndScale( + int position, float scale) { + this->position = position; + this->scale = scale; + return MLUOP_STATUS_SUCCESS; +} + +mluOpStatus_t mluOpTensorStruct::setTensorDescriptorPositionScaleAndOffset( + int position, float scale, int offset) { + this->position = position; + this->scale = scale; + this->offset = offset; + return MLUOP_STATUS_SUCCESS; +} + +mluOpStatus_t mluOpTensorStruct::setTensorDescriptorPointerMode( + mluOpPointerMode_t pointer_mode) { + PARAM_CHECK("[mluOpSetTensorDescriptorPointerMode]", pointer_mode >= 0); + + this->pointer_mode = pointer_mode; + return MLUOP_STATUS_SUCCESS; +} + +mluOpStatus_t mluOpTensorStruct::getTensorDescriptorEx( + mluOpTensorLayout_t *layout, mluOpDataType_t *dtype, int *dimNb, + int *dimSize, int *dimStride) { + PARAM_CHECK("[mluOpGetTensorDescriptorEx]", layout != NULL); + PARAM_CHECK("[mluOpGetTensorDescriptorEx]", dtype != NULL); + PARAM_CHECK("[mluOpGetTensorDescriptorEx]", dimNb != NULL); + PARAM_CHECK("[mluOpGetTensorDescriptorEx]", dimSize != NULL); + PARAM_CHECK("[mluOpGetTensorDescriptorEx]", dimStride != NULL); + + *layout = this->layout; + *dtype = this->dtype; + *dimNb = this->dim; + for (int i = 0; i < *dimNb; ++i) { + dimSize[i] = static_cast(this->dims[i]); + dimStride[i] = static_cast(this->strides[i]); + } + + return MLUOP_STATUS_SUCCESS; +} + +mluOpStatus_t mluOpTensorStruct::getTensorDescriptorEx_v2( + mluOpTensorLayout_t *layout, mluOpDataType_t *dtype, int *dimNb, + int64_t *dimSize, int64_t *dimStride) { + PARAM_CHECK("[mluOpGetTensorDescriptorEx]", layout != NULL); + PARAM_CHECK("[mluOpGetTensorDescriptorEx]", dtype != NULL); + PARAM_CHECK("[mluOpGetTensorDescriptorEx]", dimNb != NULL); + PARAM_CHECK("[mluOpGetTensorDescriptorEx]", dimSize != NULL); + PARAM_CHECK("[mluOpGetTensorDescriptorEx]", dimStride != NULL); + + *layout = this->layout; + *dtype = this->dtype; + *dimNb = this->dim; + for (int i = 0; i < *dimNb; ++i) { + dimSize[i] = this->dims[i]; + dimStride[i] = this->strides[i]; + } + + return MLUOP_STATUS_SUCCESS; +} + +mluOpStatus_t mluOpTensorStruct::getTensorDescriptor( + mluOpTensorLayout_t *layout, mluOpDataType_t *dtype, int *dimNb, + int *dimSize) { + SET_PARAM_FOR_POINTER(layout, this->layout); + SET_PARAM_FOR_POINTER(dtype, this->dtype); + SET_PARAM_FOR_POINTER(dimNb, this->dim); + SET_ARRAY_PARAM_FOR_POINTER(dimSize, this->dims, this->dim); + + return MLUOP_STATUS_SUCCESS; +} + +mluOpStatus_t mluOpTensorStruct::getTensorDescriptor_v2( + mluOpTensorLayout_t *layout, mluOpDataType_t *dtype, int *dimNb, + int64_t *dimSize) { + SET_PARAM_FOR_POINTER(layout, this->layout); + SET_PARAM_FOR_POINTER(dtype, this->dtype); + SET_PARAM_FOR_POINTER(dimNb, this->dim); + SET_ARRAY_PARAM_FOR_POINTER(dimSize, this->dims, this->dim); + + return MLUOP_STATUS_SUCCESS; +} + +mluOpStatus_t mluOpTensorStruct::getTensorDescriptorOnchipDataType( + mluOpDataType_t *onchip_dtype) { + PARAM_CHECK("[mluOpGetTensorDescriptorOnchipDataType]", onchip_dtype != NULL); + + *onchip_dtype = this->onchip_dtype; + return MLUOP_STATUS_SUCCESS; +} + +mluOpStatus_t mluOpTensorStruct::getTensorDescriptorPosition(int *position) { + PARAM_CHECK("[mluOpGetTensorDescriptorPosition]", position != NULL); + + *position = this->position; + return MLUOP_STATUS_SUCCESS; +} + +mluOpStatus_t mluOpTensorStruct::getTensorDescriptorPositionAndScale( + int *position, float *scale) { + PARAM_CHECK("[mluOpGetTensorDescriptorPositionAndScale]", position != NULL); + PARAM_CHECK("[mluOpGetTensorDescriptorPositionAndScale]", scale != NULL); + + *position = this->position; + *scale = this->scale; + return MLUOP_STATUS_SUCCESS; +} + +mluOpStatus_t mluOpTensorStruct::getTensorDescriptorPositionScaleAndOffset( + int *position, float *scale, int *offset) { + PARAM_CHECK("[mluOpGetTensorDescriptorPositionScaleAndOffset]", + position != NULL); + PARAM_CHECK("[mluOpGetTensorDescriptorPositionScaleAndOffset]", + scale != NULL); + PARAM_CHECK("[mluOpGetTensorDescriptorPositionScaleAndOffset]", + offset != NULL); + + *position = this->position; + *scale = this->scale; + *offset = this->offset; + return MLUOP_STATUS_SUCCESS; +} + +mluOpStatus_t mluOpTensorStruct::getTensorDescriptorPointerMode( + mluOpPointerMode_t *pointer_mode) { + PARAM_CHECK("[mluOpGetTensorDescriptorPointerMode]", pointer_mode != NULL); + + SET_PARAM_FOR_POINTER(pointer_mode, this->pointer_mode); + return MLUOP_STATUS_SUCCESS; +} + +mluOpStatus_t mluOpTensorStruct::destroyTensorDescriptor() { +#if MLUOP_TENSOR_QUEUE_ENABLE + queue_array.lock(); + this->~mluOpTensorStruct(); + queue_array.queue.push_front(this); + queue_array.unlock(); +#else + delete this; +#endif + + return MLUOP_STATUS_SUCCESS; +} + +/* MLUOP interface */ +mluOpStatus_t MLUOP_WIN_API +mluOpCreateTensorDescriptor(mluOpTensorDescriptor_t *desc) { + PARAM_CHECK("[mluOpCreateTensorDescriptor]", desc != NULL); +#if MLUOP_TENSOR_QUEUE_ENABLE + queue_array.lock(); + if MLUOP_PREDICT_FALSE (queue_array.queue.empty()) { + queue_array.extend(queue_array.extend_num); + queue_array.extend_num *= 2; + } + *desc = ::new (queue_array.queue.front()) mluOpTensorStruct; + queue_array.queue.pop_front(); + queue_array.unlock(); +#else + mluOpTensorStruct *ts = new (std::nothrow) mluOpTensorStruct; + *desc = ts; +#endif + return MLUOP_STATUS_SUCCESS; +} +mluOpStatus_t MLUOP_WIN_API mluOpCreateGroupTensorDescriptors( + mluOpTensorDescriptor_t **group_desc, const int desc_num) { + PARAM_CHECK("[mluOpCreateGroupTensorDescriptors]", group_desc != NULL); + PARAM_CHECK("[mluOpCreateGroupTensorDescriptors]", desc_num > 0); +#if MLUOP_TENSOR_QUEUE_ENABLE + queue_array.lock(); + if MLUOP_PREDICT_FALSE (queue_array.queue.size() < desc_num) { + queue_array.extend(std::max(queue_array.extend_num, (size_t)desc_num)); + queue_array.extend_num = + 2 * std::max(queue_array.extend_num, (size_t)desc_num); + } + for (int i = 0; i < desc_num; ++i) { + *(group_desc[i]) = queue_array.queue.front(); + queue_array.queue.pop_front(); + } + queue_array.unlock(); +#else + for (int i = 0; i < desc_num; ++i) { + mluOpTensorStruct *ts = new (std::nothrow) mluOpTensorStruct; + group_desc[i][0] = ts; + } +#endif + return MLUOP_STATUS_SUCCESS; +} + +// static inline mluOpStatus_t mluOpSetTensorDescriptorZeroDim( +// mluOpTensorDescriptor_t desc) { +// if (desc->getPointerMode() == MLUOP_POINTER_MODE_HOST) { +// desc->getDim(); +// desc->getTotalElementNum(1); +// desc->getTotalTensorSize(mluop::getSizeOfDataType(desc->getDtype())); +// return MLUOP_STATUS_SUCCESS; +// } else { +// LOG(ERROR) +// << "[mluOpSetTensorDescriptorDim]: Currently, the dim can be set to +// 0" +// << " only when the pointer mode of desc is MLUOP_POINTER_MODE_HOST. " +// << "Please use [mluOpSetTensorDescriptorPointerMode] to set the " +// "pointer " +// << "mode of desc."; +// return MLUOP_STATUS_BAD_PARAM; +// } +// } + +mluOpStatus_t MLUOP_WIN_API mluOpSetTensorDescriptor( + mluOpTensorDescriptor_t desc, mluOpTensorLayout_t layout, + mluOpDataType_t dtype, int dimNb, const int *dimSize) { + PARAM_CHECK("[mluOpSetTensorDescriptor]", desc != NULL); + return desc->setTensorDescriptor(layout, dtype, dimNb, dimSize); +} + +mluOpStatus_t MLUOP_WIN_API mluOpSetTensorDescriptor_v2( + mluOpTensorDescriptor_t desc, mluOpTensorLayout_t layout, + mluOpDataType_t dtype, int dimNb, const int64_t *dimSize) { + PARAM_CHECK("[mluOpSetTensorDescriptor]", desc != NULL); + return desc->setTensorDescriptor_v2(layout, dtype, dimNb, dimSize); +} + +// Internal interface. Caller should guarantee parameter validity. +// static inline void mluOpSetTensorDescriptorDimBase(mluOpTensorDescriptor_t +// desc, +// int dimNb) { +// if (dimNb != desc->getDim()) { +// if MLUOP_PREDICT_FALSE (desc->getDims() != desc->getNormalDims()) { +// delete[] desc->getDims(); +// delete[] desc->getStrides(); +// } +// if MLUOP_PREDICT_FALSE (dimNb > MLUOP_DIM_MAX) { +// desc->setDims(new (std::nothrow) int64_t[dimNb]); +// desc->setStrides(new (std::nothrow) int64_t[dimNb]); +// } else { +// desc->setDims(desc->getNormalDims()); +// desc->setStrides(desc->getNormalStrides()); +// } +// desc->setDim(dimNb); +// } +// } + +mluOpStatus_t MLUOP_WIN_API mluOpSetTensorDescriptorDim( + mluOpTensorDescriptor_t desc, int dimNb, const int *dimSize) { + return desc->setTensorDescriptorDim(dimNb, dimSize); +} + +mluOpStatus_t MLUOP_WIN_API mluOpSetTensorDescriptorDim_v2( + mluOpTensorDescriptor_t desc, int dimNb, const int64_t *dimSize) { + return desc->setTensorDescriptorDim_v2(dimNb, dimSize); +} + mluOpStatus_t MLUOP_WIN_API mluOpSetGroupTensorDescriptors( mluOpTensorDescriptor_t **group_desc, const mluOpTensorLayout_t *group_layout, const mluOpDataType_t *group_dtype, @@ -553,31 +854,31 @@ mluOpStatus_t MLUOP_WIN_API mluOpSetGroupTensorDescriptors( int group_dimSize_iterator = 0; for (int i = 0; i < desc_num; ++i) { - group_desc[i][0]->dim = group_dimNb[i]; - group_desc[i][0]->dtype = group_dtype[i]; - group_desc[i][0]->layout = group_layout[i]; + group_desc[i][0]->setDim(group_dimNb[i]); + group_desc[i][0]->setDtype(group_dtype[i]); + group_desc[i][0]->setLayout(group_layout[i]); if (MLUOP_PREDICT_FALSE(group_dimNb[i] > MLUOP_DIM_MAX)) { - group_desc[i][0]->dims = new (std::nothrow) int64_t[group_dimNb[i]]; - group_desc[i][0]->strides = new (std::nothrow) int64_t[group_dimNb[i]]; + group_desc[i][0]->setDims(new (std::nothrow) int64_t[group_dimNb[i]]); + group_desc[i][0]->setStrides(new (std::nothrow) int64_t[group_dimNb[i]]); } else { - group_desc[i][0]->dims = group_desc[i][0]->normal_dims; - group_desc[i][0]->strides = group_desc[i][0]->normal_strides; + group_desc[i][0]->setDims(group_desc[i][0]->getNormalDims()); + group_desc[i][0]->setStrides(group_desc[i][0]->getNormalStrides()); } std::copy(group_dimSize + group_dimSize_iterator, group_dimSize + group_dimSize_iterator + group_dimNb[i], - group_desc[i][0]->dims); + group_desc[i][0]->getDims()); // infer strides of dimNb dimensions and compute total_num and total_size int strideBase = 1; for (int j = group_dimNb[i] - 1; j >= 0; --j) { - group_desc[i][0]->strides[j] = strideBase; - strideBase *= group_desc[i][0]->dims[j]; + group_desc[i][0]->setStrideIndex(j, strideBase); + strideBase *= group_desc[i][0]->getDimIndex(j); } - group_desc[i][0]->total_element_num = strideBase; - group_desc[i][0]->total_tensor_size = - group_desc[i][0]->total_element_num * - mluop::getSizeOfDataType(group_dtype[i]); + group_desc[i][0]->setTotalElementNum(strideBase); + group_desc[i][0]->setTotalTensorSize( + group_desc[i][0]->getTotalElementNum() * + mluop::getSizeOfDataType(group_dtype[i])); // compute new iterator for next loop. group_dimSize_iterator += group_dimNb[i]; @@ -599,30 +900,30 @@ mluOpStatus_t MLUOP_WIN_API mluOpSetGroupTensorDescriptors_v2( int group_dimSize_iterator = 0; for (int i = 0; i < desc_num; ++i) { - group_desc[i][0]->dim = group_dimNb[i]; - group_desc[i][0]->dtype = group_dtype[i]; - group_desc[i][0]->layout = group_layout[i]; + group_desc[i][0]->setDim(group_dimNb[i]); + group_desc[i][0]->setDtype(group_dtype[i]); + group_desc[i][0]->setLayout(group_layout[i]); if (MLUOP_PREDICT_FALSE(group_dimNb[i] > MLUOP_DIM_MAX)) { - group_desc[i][0]->dims = new (std::nothrow) int64_t[group_dimNb[i]]; - group_desc[i][0]->strides = new (std::nothrow) int64_t[group_dimNb[i]]; + group_desc[i][0]->setDims(new (std::nothrow) int64_t[group_dimNb[i]]); + group_desc[i][0]->setStrides(new (std::nothrow) int64_t[group_dimNb[i]]); } else { - group_desc[i][0]->dims = group_desc[i][0]->normal_dims; - group_desc[i][0]->strides = group_desc[i][0]->normal_strides; + group_desc[i][0]->setDims(group_desc[i][0]->getNormalDims()); + group_desc[i][0]->setStrides(group_desc[i][0]->getNormalStrides()); } - memcpy(group_desc[i][0]->dims, group_dimSize + group_dimSize_iterator, + memcpy(group_desc[i][0]->getDims(), group_dimSize + group_dimSize_iterator, group_dimNb[i] * sizeof(int64_t)); // infer strides of dimNb dimensions and compute total_num and total_size int strideBase = 1; for (int j = group_dimNb[i] - 1; j >= 0; --j) { - group_desc[i][0]->strides[j] = strideBase; - strideBase *= group_desc[i][0]->dims[j]; + group_desc[i][0]->setStrideIndex(j, strideBase); + strideBase *= group_desc[i][0]->getDimIndex(j); } - group_desc[i][0]->total_element_num = strideBase; - group_desc[i][0]->total_tensor_size = - group_desc[i][0]->total_element_num * - mluop::getSizeOfDataType(group_dtype[i]); + group_desc[i][0]->setTotalElementNum(strideBase); + group_desc[i][0]->setTotalTensorSize( + group_desc[i][0]->getTotalElementNum() * + mluop::getSizeOfDataType(group_dtype[i])); // compute new iterator for next loop. group_dimSize_iterator += group_dimNb[i]; @@ -634,30 +935,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpSetGroupTensorDescriptors_v2( mluOpStatus_t MLUOP_WIN_API mluOpResetTensorDescriptor(mluOpTensorDescriptor_t desc) { PARAM_CHECK("[mluOpResetTensorDescriptor]", desc != NULL); - - if MLUOP_PREDICT_FALSE (desc->dims != desc->normal_dims) { - delete[] desc->dims; - desc->dims = desc->normal_dims; - } - if MLUOP_PREDICT_FALSE (desc->strides != desc->normal_strides) { - delete[] desc->strides; - desc->strides = desc->normal_strides; - } - - desc->dim = 0; - desc->dtype = MLUOP_DTYPE_FLOAT; - desc->onchip_dtype = MLUOP_DTYPE_INVALID; - desc->layout = MLUOP_LAYOUT_ARRAY; - desc->pointer_mode = MLUOP_POINTER_MODE_DEVICE; - - desc->total_element_num = 0; - desc->total_tensor_size = 0; - - desc->position = 0; - desc->scale = 1.0f; - desc->offset = 0; - - return MLUOP_STATUS_SUCCESS; + return desc->resetTensorDescriptor(); } mluOpStatus_t MLUOP_WIN_API mluOpSetTensorDescriptorEx( @@ -665,33 +943,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpSetTensorDescriptorEx( mluOpDataType_t dtype, int dimNb, const int *dimSize, const int *dimStride) { PARAM_CHECK("[mluOpSetTensorDescriptorEx]", desc != NULL); - PARAM_CHECK("[mluOpSetTensorDescriptorEx]", layout >= 0); - PARAM_CHECK("[mluOpSetTensorDescriptorEx]", dtype >= 0); - - desc->dtype = dtype; - desc->layout = layout; - - if (dimNb == 0) { - return mluOpSetTensorDescriptorZeroDim(desc); - } else { - PARAM_CHECK("[mluOpSetTensorDescriptorEx]", dimSize != NULL); - PARAM_CHECK("[mluOpSetTensorDescriptorEx]", dimStride != NULL); - PARAM_CHECK("[mluOpSetTensorDescriptorEx]", dimNb > 0); - - mluOpSetTensorDescriptorDimBase(desc, dimNb); - std::copy(dimSize, dimSize + dimNb, desc->dims); - std::copy(dimStride, dimStride + dimNb, desc->strides); - - // assign total_element_num and total_tensor_size - desc->total_element_num = 1; - for (int i = 0; i < dimNb; ++i) { - desc->total_element_num *= dimSize[i]; - } - desc->total_tensor_size = - desc->total_element_num * mluop::getSizeOfDataType(dtype); - - return MLUOP_STATUS_SUCCESS; - } + return desc->setTensorDescriptorEx(layout, dtype, dimNb, dimSize, dimStride); } mluOpStatus_t MLUOP_WIN_API mluOpSetTensorDescriptorEx_v2( @@ -699,214 +951,105 @@ mluOpStatus_t MLUOP_WIN_API mluOpSetTensorDescriptorEx_v2( mluOpDataType_t dtype, int dimNb, const int64_t *dimSize, const int64_t *dimStride) { PARAM_CHECK("[mluOpSetTensorDescriptorEx]", desc != NULL); - PARAM_CHECK("[mluOpSetTensorDescriptorEx]", layout >= 0); - PARAM_CHECK("[mluOpSetTensorDescriptorEx]", dtype >= 0); - - desc->dtype = dtype; - desc->layout = layout; - - if MLUOP_PREDICT_FALSE (dimNb == 0) { - return mluOpSetTensorDescriptorZeroDim(desc); - } else { - PARAM_CHECK("[mluOpSetTensorDescriptorEx]", dimSize != NULL); - PARAM_CHECK("[mluOpSetTensorDescriptorEx]", dimStride != NULL); - - mluOpSetTensorDescriptorDimBase(desc, dimNb); - memcpy(desc->dims, dimSize, dimNb * sizeof(int64_t)); - memcpy(desc->strides, dimStride, dimNb * sizeof(int64_t)); - - // assign total_element_num and total_tensor_size - desc->total_element_num = 1; - for (int i = 0; i < dimNb; ++i) { - desc->total_element_num *= dimSize[i]; - } - desc->total_tensor_size = - desc->total_element_num * mluop::getSizeOfDataType(dtype); - - return MLUOP_STATUS_SUCCESS; - } + return desc->setTensorDescriptorEx_v2(layout, dtype, dimNb, dimSize, + dimStride); } mluOpStatus_t MLUOP_WIN_API mluOpSetTensorDescriptorOnchipDataType( mluOpTensorDescriptor_t desc, mluOpDataType_t onchip_dtype) { PARAM_CHECK("[mluOpSetTensorDescriptorOnchipDataType]", desc != NULL); - - desc->onchip_dtype = onchip_dtype; - return MLUOP_STATUS_SUCCESS; + return desc->setTensorDescriptorOnchipDataType(onchip_dtype); } mluOpStatus_t MLUOP_WIN_API mluOpSetTensorDescriptorPosition(mluOpTensorDescriptor_t desc, int position) { PARAM_CHECK("[mluOpSetTensorDescriptorPosition]", desc != NULL); - - desc->position = position; - return MLUOP_STATUS_SUCCESS; + return desc->setTensorDescriptorPosition(position); } mluOpStatus_t MLUOP_WIN_API mluOpSetTensorDescriptorPositionAndScale( mluOpTensorDescriptor_t desc, int position, float scale) { PARAM_CHECK("[mluOpSetTensorDescriptorPositionAndScale]", desc != NULL); - - desc->position = position; - desc->scale = scale; - return MLUOP_STATUS_SUCCESS; + return desc->setTensorDescriptorPositionAndScale(position, scale); } mluOpStatus_t MLUOP_WIN_API mluOpSetTensorDescriptorPositionScaleAndOffset( mluOpTensorDescriptor_t desc, int position, float scale, int offset) { PARAM_CHECK("[mluOpSetTensorDescriptorPositionScaleAndOffset]", desc != NULL); - - desc->position = position; - desc->scale = scale; - desc->offset = offset; - return MLUOP_STATUS_SUCCESS; + return desc->setTensorDescriptorPositionScaleAndOffset(position, scale, + offset); } mluOpStatus_t MLUOP_WIN_API mluOpSetTensorDescriptorPointerMode( mluOpTensorDescriptor_t desc, mluOpPointerMode_t pointer_mode) { PARAM_CHECK("[mluOpSetTensorDescriptorPointerMode]", desc != NULL); - PARAM_CHECK("[mluOpSetTensorDescriptorPointerMode]", pointer_mode >= 0); - - desc->pointer_mode = pointer_mode; - return MLUOP_STATUS_SUCCESS; + return desc->setTensorDescriptorPointerMode(pointer_mode); } mluOpStatus_t MLUOP_WIN_API mluOpGetTensorDescriptorEx( - const mluOpTensorDescriptor_t desc, mluOpTensorLayout_t *layout, + mluOpTensorDescriptor_t desc, mluOpTensorLayout_t *layout, mluOpDataType_t *dtype, int *dimNb, int *dimSize, int *dimStride) { PARAM_CHECK("[mluOpGetTensorDescriptorEx]", desc != NULL); - PARAM_CHECK("[mluOpGetTensorDescriptorEx]", layout != NULL); - PARAM_CHECK("[mluOpGetTensorDescriptorEx]", dtype != NULL); - PARAM_CHECK("[mluOpGetTensorDescriptorEx]", dimNb != NULL); - PARAM_CHECK("[mluOpGetTensorDescriptorEx]", dimSize != NULL); - PARAM_CHECK("[mluOpGetTensorDescriptorEx]", dimStride != NULL); - - *layout = desc->layout; - *dtype = desc->dtype; - *dimNb = desc->dim; - for (int i = 0; i < *dimNb; ++i) { - dimSize[i] = static_cast(desc->dims[i]); - dimStride[i] = static_cast(desc->strides[i]); - } - - return MLUOP_STATUS_SUCCESS; + return desc->getTensorDescriptorEx(layout, dtype, dimNb, dimSize, dimStride); } mluOpStatus_t MLUOP_WIN_API mluOpGetTensorDescriptorEx_v2( const mluOpTensorDescriptor_t desc, mluOpTensorLayout_t *layout, mluOpDataType_t *dtype, int *dimNb, int64_t *dimSize, int64_t *dimStride) { PARAM_CHECK("[mluOpGetTensorDescriptorEx]", desc != NULL); - PARAM_CHECK("[mluOpGetTensorDescriptorEx]", layout != NULL); - PARAM_CHECK("[mluOpGetTensorDescriptorEx]", dtype != NULL); - PARAM_CHECK("[mluOpGetTensorDescriptorEx]", dimNb != NULL); - PARAM_CHECK("[mluOpGetTensorDescriptorEx]", dimSize != NULL); - PARAM_CHECK("[mluOpGetTensorDescriptorEx]", dimStride != NULL); - - *layout = desc->layout; - *dtype = desc->dtype; - *dimNb = desc->dim; - for (int i = 0; i < *dimNb; ++i) { - dimSize[i] = desc->dims[i]; - dimStride[i] = desc->strides[i]; - } - - return MLUOP_STATUS_SUCCESS; + return desc->getTensorDescriptorEx_v2(layout, dtype, dimNb, dimSize, + dimStride); } mluOpStatus_t MLUOP_WIN_API mluOpGetTensorDescriptor( const mluOpTensorDescriptor_t desc, mluOpTensorLayout_t *layout, mluOpDataType_t *dtype, int *dimNb, int *dimSize) { PARAM_CHECK("[mluOpGetTensorDescriptor]", desc != NULL); - - SET_PARAM_FOR_POINTER(layout, desc->layout); - SET_PARAM_FOR_POINTER(dtype, desc->dtype); - SET_PARAM_FOR_POINTER(dimNb, desc->dim); - SET_ARRAY_PARAM_FOR_POINTER(dimSize, desc->dims, desc->dim); - - return MLUOP_STATUS_SUCCESS; + return desc->getTensorDescriptor(layout, dtype, dimNb, dimSize); } mluOpStatus_t MLUOP_WIN_API mluOpGetTensorDescriptor_v2( const mluOpTensorDescriptor_t desc, mluOpTensorLayout_t *layout, mluOpDataType_t *dtype, int *dimNb, int64_t *dimSize) { PARAM_CHECK("[mluOpGetTensorDescriptor]", desc != NULL); - - SET_PARAM_FOR_POINTER(layout, desc->layout); - SET_PARAM_FOR_POINTER(dtype, desc->dtype); - SET_PARAM_FOR_POINTER(dimNb, desc->dim); - SET_ARRAY_PARAM_FOR_POINTER(dimSize, desc->dims, desc->dim); - - return MLUOP_STATUS_SUCCESS; + return desc->getTensorDescriptor_v2(layout, dtype, dimNb, dimSize); } mluOpStatus_t MLUOP_WIN_API mluOpGetTensorDescriptorOnchipDataType( const mluOpTensorDescriptor_t desc, mluOpDataType_t *onchip_dtype) { PARAM_CHECK("[mluOpGetTensorDescriptorOnchipDataType]", desc != NULL); - PARAM_CHECK("[mluOpGetTensorDescriptorOnchipDataType]", onchip_dtype != NULL); - - *onchip_dtype = desc->onchip_dtype; - return MLUOP_STATUS_SUCCESS; + return desc->getTensorDescriptorOnchipDataType(onchip_dtype); } mluOpStatus_t MLUOP_WIN_API mluOpGetTensorDescriptorPosition(mluOpTensorDescriptor_t desc, int *position) { PARAM_CHECK("[mluOpGetTensorDescriptorPosition]", desc != NULL); - PARAM_CHECK("[mluOpGetTensorDescriptorPosition]", position != NULL); - - *position = desc->position; - return MLUOP_STATUS_SUCCESS; + return desc->getTensorDescriptorPosition(position); } mluOpStatus_t MLUOP_WIN_API mluOpGetTensorDescriptorPositionAndScale( mluOpTensorDescriptor_t desc, int *position, float *scale) { PARAM_CHECK("[mluOpGetTensorDescriptorPositionAndScale]", desc != NULL); - PARAM_CHECK("[mluOpGetTensorDescriptorPositionAndScale]", position != NULL); - PARAM_CHECK("[mluOpGetTensorDescriptorPositionAndScale]", scale != NULL); - - *position = desc->position; - *scale = desc->scale; - return MLUOP_STATUS_SUCCESS; + return desc->getTensorDescriptorPositionAndScale(position, scale); } mluOpStatus_t MLUOP_WIN_API mluOpGetTensorDescriptorPositionScaleAndOffset( mluOpTensorDescriptor_t desc, int *position, float *scale, int *offset) { PARAM_CHECK("[mluOpGetTensorDescriptorPositionScaleAndOffset]", desc != NULL); - PARAM_CHECK("[mluOpGetTensorDescriptorPositionScaleAndOffset]", - position != NULL); - PARAM_CHECK("[mluOpGetTensorDescriptorPositionScaleAndOffset]", - scale != NULL); - PARAM_CHECK("[mluOpGetTensorDescriptorPositionScaleAndOffset]", - offset != NULL); - - *position = desc->position; - *scale = desc->scale; - *offset = desc->offset; - return MLUOP_STATUS_SUCCESS; + return desc->getTensorDescriptorPositionScaleAndOffset(position, scale, + offset); } mluOpStatus_t MLUOP_WIN_API mluOpGetTensorDescriptorPointerMode( mluOpTensorDescriptor_t desc, mluOpPointerMode_t *pointer_mode) { PARAM_CHECK("[mluOpGetTensorDescriptorPointerMode]", desc != NULL); - PARAM_CHECK("[mluOpGetTensorDescriptorPointerMode]", pointer_mode != NULL); - - SET_PARAM_FOR_POINTER(pointer_mode, desc->pointer_mode); - return MLUOP_STATUS_SUCCESS; + return desc->getTensorDescriptorPointerMode(pointer_mode); } mluOpStatus_t MLUOP_WIN_API mluOpDestroyTensorDescriptor(mluOpTensorDescriptor_t desc) { PARAM_CHECK("[mluOpDestroyTensorDescriptor]", desc != NULL); - -#if MLUOP_TENSOR_QUEUE_ENABLE - queue_array.lock(); - desc->~mluOpTensorStruct(); - queue_array.queue.push_front(desc); - queue_array.unlock(); -#else - delete desc; -#endif - - return MLUOP_STATUS_SUCCESS; + return desc->destroyTensorDescriptor(); } mluOpStatus_t MLUOP_WIN_API mluOpDestroyGroupTensorDescriptors( @@ -926,7 +1069,6 @@ mluOpStatus_t MLUOP_WIN_API mluOpDestroyGroupTensorDescriptors( delete group_desc[i][0]; } #endif - return MLUOP_STATUS_SUCCESS; } @@ -934,7 +1076,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpDestroyGroupTensorDescriptors( uint64_t MLUOP_WIN_API mluOpGetTensorElementNum(const mluOpTensorDescriptor_t desc) { CHECK(desc != NULL); - return desc->total_element_num; + return desc->getTensorElementNum(); } uint64_t mluOpGetSeqDataElementNum(mluOpSeqDataDescriptor_t desc) { diff --git a/core/tensor.h b/core/tensor.h index 38fba2a67..461a36c5d 100644 --- a/core/tensor.h +++ b/core/tensor.h @@ -107,6 +107,152 @@ struct alignas(64) mluOpTensorStruct { inline bool isSameDims(const mluOpTensorStruct *other) const; inline bool isCpuScalar() const; + public: + inline float getOffset() const { return this->offset; } + inline void setOffset(float newOffset) { this->offset = newOffset; } + + inline float getScale() const { return this->scale; } + inline void setScale(float newScale) { this->scale = newScale; } + + inline mluOpTensorLayout_t getLayout() const { return this->layout; } + inline void setLayout(mluOpTensorLayout_t newLayout) { + this->layout = newLayout; + } + + inline uint64_t getTotalTensorSize() const { return this->total_tensor_size; } + inline void setTotalTensorSize(uint64_t newSize) { + this->total_tensor_size = newSize; + } + inline uint64_t getTotalElementNum() const { return this->total_element_num; } + inline void setTotalElementNum(uint64_t newNum) { + this->total_element_num = newNum; + } + + inline int getPosition() const { return this->position; } + inline void setPosition(int newPosition) { this->position = newPosition; } + + inline mluOpDataType_t getDtype() const { return this->dtype; } + inline void setDtype(mluOpDataType_t newDtype) { this->dtype = newDtype; } + inline mluOpDataType_t getOnchipDtype() const { return this->onchip_dtype; } + inline void setOnchipDtype(mluOpDataType_t newDtype) { + this->onchip_dtype = newDtype; + } + + inline int getDim() const { return this->dim; } + inline void setDim(int newDim) { this->dim = newDim; } + inline void releaseDims() { delete[] this->dims; } + inline int64_t *getDims() const { return this->dims; } + inline int64_t getDimIndex(size_t index) { return (this->dims)[index]; } + inline void setDims(int64_t *newDims) { this->dims = newDims; } + + inline void releaseStrides() { delete[] this->strides; } + inline int64_t *getStrides() const { return this->strides; } + inline int64_t getStrideIndex(size_t index) const { + return (this->strides)[index]; + } + inline void setStrideIndex(size_t index, int64_t newStride) { + this->strides[index] = newStride; + } + + inline void setStrides(int64_t *newStrides) { this->strides = newStrides; } + + inline mluOpPointerMode_t getPointerMode() const { + return this->pointer_mode; + } + inline void setPointerMode(mluOpPointerMode_t new_pointer_mode) { + this->pointer_mode = new_pointer_mode; + } + + inline int64_t *getNormalDims() { return this->normal_dims; } + inline int64_t *getNormalStrides() { return this->normal_strides; } + // Definition of function in tensor.cpp + mluOpStatus_t setTensorDescriptor(mluOpTensorLayout_t layout, + mluOpDataType_t dtype, int dimNb, + const int *dimSize); + + mluOpStatus_t setTensorDescriptor_v2(mluOpTensorLayout_t layout, + mluOpDataType_t dtype, int dimNb, + const int64_t *dimSize); + + mluOpStatus_t setTensorDescriptorDim(int dimNb, const int *dimSize); + + mluOpStatus_t setTensorDescriptorDim_v2(int dimNb, const int64_t *dimSize); + + mluOpStatus_t resetTensorDescriptor(); + + mluOpStatus_t setTensorDescriptorEx(mluOpTensorLayout_t layout, + mluOpDataType_t dtype, int dimNb, + const int *dimSize, const int *dimStride); + + mluOpStatus_t setTensorDescriptorEx_v2(mluOpTensorLayout_t layout, + mluOpDataType_t dtype, int dimNb, + const int64_t *dimSize, + const int64_t *dimStride); + + mluOpStatus_t setTensorDescriptorOnchipDataType(mluOpDataType_t onchip_dtype); + + mluOpStatus_t setTensorDescriptorPosition(int position); + + mluOpStatus_t setTensorDescriptorPositionAndScale(int position, float scale); + + mluOpStatus_t setTensorDescriptorPositionScaleAndOffset(int position, + float scale, + int offset); + + mluOpStatus_t setTensorDescriptorPointerMode(mluOpPointerMode_t pointer_mode); + + mluOpStatus_t getTensorDescriptorEx(mluOpTensorLayout_t *layout, + mluOpDataType_t *dtype, int *dimNb, + int *dimSize, int *dimStride); + + mluOpStatus_t getTensorDescriptorEx_v2(mluOpTensorLayout_t *layout, + mluOpDataType_t *dtype, int *dimNb, + int64_t *dimSize, int64_t *dimStride); + + mluOpStatus_t getTensorDescriptor(mluOpTensorLayout_t *layout, + mluOpDataType_t *dtype, int *dimNb, + int *dimSize); + + mluOpStatus_t getTensorDescriptor_v2(mluOpTensorLayout_t *layout, + mluOpDataType_t *dtype, int *dimNb, + int64_t *dimSize); + + mluOpStatus_t getTensorDescriptorOnchipDataType( + mluOpDataType_t *onchip_dtype); + + mluOpStatus_t getTensorDescriptorPosition(int *position); + + mluOpStatus_t getTensorDescriptorPositionAndScale(int *position, + float *scale); + + mluOpStatus_t getTensorDescriptorPositionScaleAndOffset(int *position, + float *scale, + int *offset); + + mluOpStatus_t getTensorDescriptorPointerMode( + mluOpPointerMode_t *pointer_mode); + + mluOpStatus_t destroyTensorDescriptor(); + + mluOpStatus_t destroyGroupTensorDescriptors( + mluOpTensorDescriptor_t **group_desc, const int desc_num); + + uint64_t getTensorElementNum(mluOpTensorDescriptor_t desc); + + mluOpStatus_t setGroupTensorDescriptors( + mluOpTensorDescriptor_t **group_desc, + const mluOpTensorLayout_t *group_layout, + const mluOpDataType_t *group_dtype, const int *group_dimNb, + const int *group_dimSize, const int desc_num); + + mluOpStatus_t setGroupTensorDescriptors_v2( + mluOpTensorDescriptor_t **group_desc, + const mluOpTensorLayout_t *group_layout, + const mluOpDataType_t *group_dtype, const int *group_dimNb, + const int64_t *group_dimSize, const int desc_num); + + uint64_t getTensorElementNum() { return this->total_element_num; } + private: /* Try to pack and align the struct */ /* ------------------- 64 Bytes - 1 -------------------*/ int64_t normal_dims[MLUOP_DIM_MAX]; @@ -158,7 +304,7 @@ struct mluOpTensorSetStruct { CHECK(!this->tensor_set.empty()); size_t tensor_set_size = 0; for (int i = 0; i < tensor_set.size(); i++) { - tensor_set_size += tensor_set[i]->total_tensor_size; + tensor_set_size += tensor_set[i]->getTotalTensorSize(); } return tensor_set_size; } @@ -175,7 +321,7 @@ struct mluOpTensorSetStruct { int64_t offset = 0; int index = this->getIndex(tensorIndex); for (int i = 0; i < index; i++) { - offset += tensor_set[i]->total_tensor_size; + offset += tensor_set[i]->getTotalTensorSize(); } data_offset[index] = offset; return offset; @@ -189,12 +335,12 @@ struct mluOpTensorSetStruct { inline mluOpDataType_t getDatatype() const { CHECK(!this->tensor_set.empty()); - return this->tensor_set[0]->dtype; + return this->tensor_set[0]->getDtype(); } inline mluOpTensorLayout_t getLayout() const { CHECK(!this->tensor_set.empty()); - return this->tensor_set[0]->layout; + return this->tensor_set[0]->getLayout(); } inline void checkDataOffset() const { @@ -218,7 +364,7 @@ struct mluOpTensorSetStruct { int offset = 0; data_offset[0] = offset; for (int i = 0; i < tensor_num - 1; i++) { - offset += tensor_set[i]->total_tensor_size; + offset += tensor_set[i]->getTotalTensorSize(); data_offset[i + 1] = offset; } return data_offset; @@ -288,16 +434,16 @@ inline int mluOpDataTypeBytes(const mluOpDataType_t dt) { } inline int64_t mluOpGetTensordimN(const mluOpTensorDescriptor_t desc) { - switch (desc->layout) { + switch (desc->getLayout()) { case MLUOP_LAYOUT_NCHW: case MLUOP_LAYOUT_NHWC: case MLUOP_LAYOUT_NDHWC: case MLUOP_LAYOUT_NLC: - return desc->dims[0]; + return desc->getDimIndex(0); case MLUOP_LAYOUT_NCDHW: - return desc->dims[0]; + return desc->getDimIndex(0); case MLUOP_LAYOUT_HWCN: - return desc->dims[3]; + return desc->getDimIndex(3); default: LOG(ERROR) << "Failed to call dimN, illegal layout in TensorDescriptor.\n"; @@ -306,11 +452,11 @@ inline int64_t mluOpGetTensordimN(const mluOpTensorDescriptor_t desc) { } inline int64_t mluOpGetTensordimD(const mluOpTensorDescriptor_t desc) { - switch (desc->layout) { + switch (desc->getLayout()) { case MLUOP_LAYOUT_NDHWC: - return desc->dims[1]; + return desc->getDimIndex(1); case MLUOP_LAYOUT_NCDHW: - return desc->dims[2]; + return desc->getDimIndex(2); default: LOG(ERROR) << "Failed to call dimD, illegal layout in TensorDescriptor.\n"; @@ -319,18 +465,18 @@ inline int64_t mluOpGetTensordimD(const mluOpTensorDescriptor_t desc) { } inline int64_t mluOpGetTensordimC(const mluOpTensorDescriptor_t desc) { - switch (desc->layout) { + switch (desc->getLayout()) { case MLUOP_LAYOUT_NCHW: - return desc->dims[1]; + return desc->getDimIndex(1); case MLUOP_LAYOUT_NHWC: - return desc->dims[3]; + return desc->getDimIndex(3); case MLUOP_LAYOUT_NDHWC: - return desc->dims[4]; + return desc->getDimIndex(4); case MLUOP_LAYOUT_NCDHW: - return desc->dims[1]; + return desc->getDimIndex(1); case MLUOP_LAYOUT_HWCN: case MLUOP_LAYOUT_NLC: - return desc->dims[2]; + return desc->getDimIndex(2); default: LOG(ERROR) << "Failed to call dimC, illegal layout in TensorDescriptor.\n"; @@ -339,17 +485,17 @@ inline int64_t mluOpGetTensordimC(const mluOpTensorDescriptor_t desc) { } inline int64_t mluOpGetTensordimH(const mluOpTensorDescriptor_t desc) { - switch (desc->layout) { + switch (desc->getLayout()) { case MLUOP_LAYOUT_NCHW: - return desc->dims[2]; + return desc->getDimIndex(2); case MLUOP_LAYOUT_NHWC: - return desc->dims[1]; + return desc->getDimIndex(1); case MLUOP_LAYOUT_NDHWC: - return desc->dims[2]; + return desc->getDimIndex(2); case MLUOP_LAYOUT_NCDHW: - return desc->dims[3]; + return desc->getDimIndex(3); case MLUOP_LAYOUT_HWCN: - return desc->dims[0]; + return desc->getDimIndex(0); default: LOG(ERROR) << "Failed to call dimH, illegal layout in TensorDescriptor.\n"; @@ -358,18 +504,18 @@ inline int64_t mluOpGetTensordimH(const mluOpTensorDescriptor_t desc) { } inline int64_t mluOpGetTensordimW(const mluOpTensorDescriptor_t desc) { - switch (desc->layout) { + switch (desc->getLayout()) { case MLUOP_LAYOUT_NCHW: - return desc->dims[3]; + return desc->getDimIndex(3); case MLUOP_LAYOUT_NHWC: - return desc->dims[2]; + return desc->getDimIndex(2); case MLUOP_LAYOUT_NDHWC: - return desc->dims[3]; + return desc->getDimIndex(3); case MLUOP_LAYOUT_NCDHW: - return desc->dims[4]; + return desc->getDimIndex(4); case MLUOP_LAYOUT_HWCN: case MLUOP_LAYOUT_NLC: - return desc->dims[1]; + return desc->getDimIndex(1); default: LOG(ERROR) << "Failed to call dimW, illegal layout in TensorDescriptor.\n"; @@ -466,12 +612,12 @@ inline int64_t mluOpGetSeqDataDimC(const mluOpSeqDataDescriptor_t desc) { inline uint64_t shapeStrideCount(const mluOpTensorDescriptor_t desc) { uint64_t total = 1; - for (int i = 0; i < desc->dim; ++i) { - if (desc->dims[i] == 0) { + for (int i = 0; i < desc->getDim(); ++i) { + if (desc->getDimIndex(i) == 0) { total = 0; break; } - total += (desc->dims[i] - 1) * desc->strides[i]; + total += (desc->getDimIndex(i) - 1) * desc->getStrideIndex(i); } return total; } diff --git a/kernels/abs/abs.cpp b/kernels/abs/abs.cpp index bc3ebe34f..c9e214851 100644 --- a/kernels/abs/abs.cpp +++ b/kernels/abs/abs.cpp @@ -45,19 +45,19 @@ static mluOpStatus_t mluOpAbsParamCheck(mluOpHandle_t handle, PARAM_CHECK(op_name, x_desc != NULL); PARAM_CHECK(op_name, y_desc != NULL); // check dim and dtype - if (x_desc->dtype == MLUOP_DTYPE_COMPLEX_FLOAT) { - PARAM_CHECK_EQ(op_name, y_desc->dtype, MLUOP_DTYPE_FLOAT); + if (x_desc->getDtype() == MLUOP_DTYPE_COMPLEX_FLOAT) { + PARAM_CHECK_EQ(op_name, y_desc->getDtype(), MLUOP_DTYPE_FLOAT); } else { - PARAM_CHECK_EQ(op_name, x_desc->dtype, y_desc->dtype); + PARAM_CHECK_EQ(op_name, x_desc->getDtype(), y_desc->getDtype()); } - PARAM_CHECK_EQ(op_name, x_desc->dim, y_desc->dim); + PARAM_CHECK_EQ(op_name, x_desc->getDim(), y_desc->getDim()); // check data type mluOpStatus_t param_check; if (handle->arch >= MLUOP_MLU590) { mluOpDataType_t support_type[5] = {MLUOP_DTYPE_HALF, MLUOP_DTYPE_BFLOAT16, MLUOP_DTYPE_FLOAT, MLUOP_DTYPE_INT32, MLUOP_DTYPE_COMPLEX_FLOAT}; - if (!isAbsSupportType(x_desc->dtype, support_type, 5)) { + if (!isAbsSupportType(x_desc->getDtype(), support_type, 5)) { LOG(ERROR) << op_name << ":x_desc's data type is not supported."; return MLUOP_STATUS_BAD_PARAM; } @@ -65,20 +65,20 @@ static mluOpStatus_t mluOpAbsParamCheck(mluOpHandle_t handle, mluOpDataType_t support_type[4] = {MLUOP_DTYPE_HALF, MLUOP_DTYPE_FLOAT, MLUOP_DTYPE_INT32, MLUOP_DTYPE_COMPLEX_FLOAT}; - if (!isAbsSupportType(x_desc->dtype, support_type, 4)) { + if (!isAbsSupportType(x_desc->getDtype(), support_type, 4)) { LOG(ERROR) << op_name << ":x_desc's data type is not supported."; return MLUOP_STATUS_BAD_PARAM; } } - PARAM_CHECK_GT(op_name, x_desc->dim, 0); - PARAM_CHECK_GT(op_name, y_desc->dim, 0); - for (int i = 0; i < x_desc->dim; i++) { - if (x_desc->dims[i] != y_desc->dims[i]) { + PARAM_CHECK_GT(op_name, x_desc->getDim(), 0); + PARAM_CHECK_GT(op_name, y_desc->getDim(), 0); + for (int i = 0; i < x_desc->getDim(); i++) { + if (x_desc->getDimIndex(i) != y_desc->getDimIndex(i)) { LOG(ERROR) << op_name << ":The shape of x should be equal to y" << ". But now x_desc's shape[" << i << "] is " - << x_desc->dims[i] << ", y_desc's shape[" << i << "] is " - << y_desc->dims[i] << "."; + << x_desc->getDimIndex(i) << ", y_desc's shape[" << i << "] is " + << y_desc->getDimIndex(i) << "."; return MLUOP_STATUS_BAD_PARAM; } } @@ -98,7 +98,7 @@ static mluOpStatus_t mluOpAbsParamCheck(mluOpHandle_t handle, } if (needStrideProcess(x_desc, y_desc)) { - PARAM_CHECK(op_name, x_desc->dim <= MLUOP_DIM_MAX); + PARAM_CHECK(op_name, x_desc->getDim() <= MLUOP_DIM_MAX); if (handle->arch < MLUOP_MLU590) { // num_with_stride affects offset (related with mul op, which cannot // exceed 32-bit on MLU300) @@ -154,18 +154,18 @@ mluOpStatus_t MLUOP_WIN_API mluOpAbs(mluOpHandle_t handle, } if (if_stride_kernel) { VLOG(5) << "kernel Kernel3StagePipelineWithStrideAbs"; - PARAM_CHECK(op_name, x_desc->dim <= MLUOP_DIM_MAX); + PARAM_CHECK(op_name, x_desc->getDim() <= MLUOP_DIM_MAX); mluop::TensorShape x_shape; mluop::TensorShape y_shape; mluop::getTensorShape(x_desc, &x_shape); mluop::getTensorShape(y_desc, &y_shape); CHECK_RETURN(op_name, Kernel3StagePipelineWithStrideAbs( - k_dim, k_type, handle->queue, x_desc->dtype, x, + k_dim, k_type, handle->queue, x_desc->getDtype(), x, x_shape, y, y_shape, dim_x)); } else { VLOG(5) << "kernel Kernel3StagePipelineAbs"; CHECK_RETURN(op_name, Kernel3StagePipelineAbs(k_dim, k_type, handle->queue, - x_desc->dtype, x, y, dim_x)); + x_desc->getDtype(), x, y, dim_x)); } GEN_CASE_END(); return MLUOP_STATUS_SUCCESS; diff --git a/kernels/active_rotated_filter/active_rotated_filter.cpp b/kernels/active_rotated_filter/active_rotated_filter.cpp index 8f68a3609..be0c2870d 100644 --- a/kernels/active_rotated_filter/active_rotated_filter.cpp +++ b/kernels/active_rotated_filter/active_rotated_filter.cpp @@ -42,7 +42,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpGetActiveRotatedFilterForwardWorkspaceSize( PARAM_CHECK(api_name, input_desc != NULL); PARAM_CHECK(api_name, workspace_size != NULL); - *workspace_size = input_desc->total_tensor_size; + *workspace_size = input_desc->getTotalTensorSize(); return MLUOP_STATUS_SUCCESS; } @@ -59,31 +59,31 @@ static mluOpStatus_t activeRotatedFilterForwardParamCheck( PARAM_CHECK(api_name, output_desc != NULL); // check tensor dim - PARAM_CHECK(api_name, input_desc->dim == 5); - PARAM_CHECK(api_name, indices_desc->dim == 4); - PARAM_CHECK(api_name, output_desc->dim == 4); + PARAM_CHECK(api_name, input_desc->getDim() == 5); + PARAM_CHECK(api_name, indices_desc->getDim() == 4); + PARAM_CHECK(api_name, output_desc->getDim() == 4); // check dim - PARAM_CHECK(api_name, input_desc->dims[2] == indices_desc->dims[0]); - PARAM_CHECK(api_name, input_desc->dims[3] == input_desc->dims[4]); - PARAM_CHECK(api_name, input_desc->dims[3] == indices_desc->dims[1]); - PARAM_CHECK(api_name, input_desc->dims[3] == output_desc->dims[2]); - PARAM_CHECK(api_name, input_desc->dims[4] == indices_desc->dims[2]); - PARAM_CHECK(api_name, input_desc->dims[4] == output_desc->dims[3]); + PARAM_CHECK(api_name, input_desc->getDimIndex(2) == indices_desc->getDimIndex(0)); + PARAM_CHECK(api_name, input_desc->getDimIndex(3) == input_desc->getDimIndex(4)); + PARAM_CHECK(api_name, input_desc->getDimIndex(3) == indices_desc->getDimIndex(1)); + PARAM_CHECK(api_name, input_desc->getDimIndex(3) == output_desc->getDimIndex(2)); + PARAM_CHECK(api_name, input_desc->getDimIndex(4) == indices_desc->getDimIndex(2)); + PARAM_CHECK(api_name, input_desc->getDimIndex(4) == output_desc->getDimIndex(3)); PARAM_CHECK(api_name, - (input_desc->dims[2] > 0 && input_desc->dims[2] <= 128)); + (input_desc->getDimIndex(2) > 0 && input_desc->getDimIndex(2) <= 128)); PARAM_CHECK_V2(api_name, - int(log(float(input_desc->dims[2])) / log(2.0f)) == - log(float(input_desc->dims[2])) / log(2.0f), - "input_desc->dims[2] should be the power of 2."); - PARAM_CHECK(api_name, (input_desc->dims[3] == 3 || input_desc->dims[3] == 1)); + int(log(float(input_desc->getDimIndex(2))) / log(2.0f)) == + log(float(input_desc->getDimIndex(2))) / log(2.0f), + "input_desc->getDimIndex(2) should be the power of 2."); + PARAM_CHECK(api_name, (input_desc->getDimIndex(3) == 3 || input_desc->getDimIndex(3) == 1)); PARAM_CHECK(api_name, - (indices_desc->dims[3] == 2 || indices_desc->dims[3] == 4 || - indices_desc->dims[3] == 8)); - PARAM_CHECK(api_name, (output_desc->dims[0] == - input_desc->dims[0] * indices_desc->dims[3])); - PARAM_CHECK(api_name, (output_desc->dims[1] == - input_desc->dims[1] * input_desc->dims[2])); + (indices_desc->getDimIndex(3) == 2 || indices_desc->getDimIndex(3) == 4 || + indices_desc->getDimIndex(3) == 8)); + PARAM_CHECK(api_name, (output_desc->getDimIndex(0) == + input_desc->getDimIndex(0) * indices_desc->getDimIndex(3))); + PARAM_CHECK(api_name, (output_desc->getDimIndex(1) == + input_desc->getDimIndex(1) * input_desc->getDimIndex(2))); // check stride STRIDE_TENSOR_CHECK(api_name + ":", input_desc, @@ -95,17 +95,17 @@ static mluOpStatus_t activeRotatedFilterForwardParamCheck( // check tensor datatype, support float16 and float32 PARAM_CHECK_V2(api_name, - (input_desc->dtype == MLUOP_DTYPE_HALF) || - (input_desc->dtype == MLUOP_DTYPE_FLOAT), + (input_desc->getDtype() == MLUOP_DTYPE_HALF) || + (input_desc->getDtype() == MLUOP_DTYPE_FLOAT), "Only half and float are supported in input tensor, but the " "data type of tensor is " - << mluOpGetNameOfDataType(input_desc->dtype) << "."); - PARAM_CHECK(api_name, input_desc->dtype == output_desc->dtype); + << mluOpGetNameOfDataType(input_desc->getDtype()) << "."); + PARAM_CHECK(api_name, input_desc->getDtype() == output_desc->getDtype()); PARAM_CHECK_V2( - api_name, (indices_desc->dtype == MLUOP_DTYPE_INT32), + api_name, (indices_desc->getDtype() == MLUOP_DTYPE_INT32), "Only int32 are supported in indices idx, but the data type of tensor is " - << mluOpGetNameOfDataType(indices_desc->dtype) << "."); + << mluOpGetNameOfDataType(indices_desc->getDtype()) << "."); const size_t input_element_num = mluOpGetTensorElementNum(input_desc); const size_t indices_element_num = mluOpGetTensorElementNum(indices_desc); @@ -149,12 +149,12 @@ mluOpStatus_t MLUOP_WIN_API mluOpActiveRotatedFilterForward( if (status_paramcheck != MLUOP_STATUS_SUCCESS) { return status_paramcheck; } - const int output_planes = input_desc->dims[0]; - const int input_planes = input_desc->dims[1]; - const int orientations = input_desc->dims[2]; - const int kH = input_desc->dims[3]; - const int kW = input_desc->dims[4]; - const int rotations = indices_desc->dims[3]; + const int output_planes = input_desc->getDimIndex(0); + const int input_planes = input_desc->getDimIndex(1); + const int orientations = input_desc->getDimIndex(2); + const int kH = input_desc->getDimIndex(3); + const int kW = input_desc->getDimIndex(4); + const int rotations = indices_desc->getDimIndex(3); // generate mluOpActiveRotatedFilterForward prototxt start! if (MLUOP_GEN_CASE_ON_NEW) { @@ -168,7 +168,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpActiveRotatedFilterForward( GEN_CASE_TEST_PARAM_NEW(false, false, true, 0.003, 0.003, 0); } - mluOpDataType_t input_dtype = input_desc->dtype; + mluOpDataType_t input_dtype = input_desc->getDtype(); // start UX task, occupy all available clusters cnrtDim3_t k_dims; diff --git a/kernels/adam_w/adam_w.cpp b/kernels/adam_w/adam_w.cpp index d996fe3b3..ea6d6dea6 100644 --- a/kernels/adam_w/adam_w.cpp +++ b/kernels/adam_w/adam_w.cpp @@ -97,11 +97,11 @@ mluOpAdamW(mluOpHandle_t handle, const mluOpAdamWDescriptor_t adamw_desc, PARAM_CHECK("[mluOpAdamW]", momentum_desc != nullptr); PARAM_CHECK("[mluOpAdamW]", velocity_desc != nullptr); PARAM_CHECK("[mluOpAdamW]", grad_desc != nullptr); - PARAM_CHECK("[mluOpAdamW]", param_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK("[mluOpAdamW]", paramh_desc->dtype == MLUOP_DTYPE_BFLOAT16); - PARAM_CHECK("[mluOpAdamW]", momentum_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK("[mluOpAdamW]", velocity_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK("[mluOpAdamW]", grad_desc->dtype == MLUOP_DTYPE_BFLOAT16); + PARAM_CHECK("[mluOpAdamW]", param_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK("[mluOpAdamW]", paramh_desc->getDtype() == MLUOP_DTYPE_BFLOAT16); + PARAM_CHECK("[mluOpAdamW]", momentum_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK("[mluOpAdamW]", velocity_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK("[mluOpAdamW]", grad_desc->getDtype() == MLUOP_DTYPE_BFLOAT16); PARAM_CHECK_LE("[mluOpAdamW]", beta1, 1.0); PARAM_CHECK_GE("[mluOpAdamW]", beta1, 0.0); diff --git a/kernels/ball_query/ball_query.cpp b/kernels/ball_query/ball_query.cpp index fb6ddebde..5f14bc40a 100644 --- a/kernels/ball_query/ball_query.cpp +++ b/kernels/ball_query/ball_query.cpp @@ -51,7 +51,7 @@ void policyFuncBallQuery(const mluOpHandle_t &handle, size_t core_in_cluster = handle->core_num_per_cluster; VLOG(5) << "In current device, core_in_cluster:" << core_in_cluster; - size_t total_data_num = desc->total_element_num; + size_t total_data_num = desc->getTotalElementNum(); // On a core, a lot of new_xyz data element can be stored; but only one data // element can be processed at a time. So a cluster can only process four data @@ -84,21 +84,21 @@ mluOpStatus_t MLUOP_WIN_API mluOpBallQuery( PARAM_CHECK("[mluOpBallQuery]", idx_desc != NULL); // check dims - PARAM_CHECK("[mluOpBallQuery]", new_xyz_desc->dim == 3); - PARAM_CHECK("[mluOpBallQuery]", xyz_desc->dim == 3); - PARAM_CHECK("[mluOpBallQuery]", idx_desc->dim == 3); + PARAM_CHECK("[mluOpBallQuery]", new_xyz_desc->getDim() == 3); + PARAM_CHECK("[mluOpBallQuery]", xyz_desc->getDim() == 3); + PARAM_CHECK("[mluOpBallQuery]", idx_desc->getDim() == 3); // check dim0 - PARAM_CHECK("[mluOpBallQuery]", new_xyz_desc->dims[0] == xyz_desc->dims[0]); - PARAM_CHECK("[mluOpBallQuery]", new_xyz_desc->dims[0] == idx_desc->dims[0]); + PARAM_CHECK("[mluOpBallQuery]", new_xyz_desc->getDimIndex(0) == xyz_desc->getDimIndex(0)); + PARAM_CHECK("[mluOpBallQuery]", new_xyz_desc->getDimIndex(0) == idx_desc->getDimIndex(0)); // check dim1 - PARAM_CHECK("[mluOpBallQuery]", new_xyz_desc->dims[1] == idx_desc->dims[1]); + PARAM_CHECK("[mluOpBallQuery]", new_xyz_desc->getDimIndex(1) == idx_desc->getDimIndex(1)); // check dim2 - PARAM_CHECK("[mluOpBallQuery]", new_xyz_desc->dims[2] == 3); - PARAM_CHECK("[mluOpBallQuery]", xyz_desc->dims[2] == 3); - PARAM_CHECK("[mluOpBallQuery]", idx_desc->dims[2] == nsample); + PARAM_CHECK("[mluOpBallQuery]", new_xyz_desc->getDimIndex(2) == 3); + PARAM_CHECK("[mluOpBallQuery]", xyz_desc->getDimIndex(2) == 3); + PARAM_CHECK("[mluOpBallQuery]", idx_desc->getDimIndex(2) == nsample); // check stride STRIDE_TENSOR_CHECK("[mluOpBallQuery]:", new_xyz_desc, @@ -109,18 +109,18 @@ mluOpStatus_t MLUOP_WIN_API mluOpBallQuery( "idx_desc must be contiguous"); // check dtype - if (!isSupportType(new_xyz_desc->dtype, support_type, 2)) { + if (!isSupportType(new_xyz_desc->getDtype(), support_type, 2)) { LOG(ERROR) << "[mluOpBallQuery]:Only half and float are supported in input " "new_xyz tensor, but the data type of tensor is " - << mluOpGetNameOfDataType(new_xyz_desc->dtype) << "."; + << mluOpGetNameOfDataType(new_xyz_desc->getDtype()) << "."; return MLUOP_STATUS_BAD_PARAM; } - PARAM_CHECK_EQ("[mluOpBallQuery]", new_xyz_desc->dtype, xyz_desc->dtype); + PARAM_CHECK_EQ("[mluOpBallQuery]", new_xyz_desc->getDtype(), xyz_desc->getDtype()); - if (idx_desc->dtype != MLUOP_DTYPE_INT32) { + if (idx_desc->getDtype() != MLUOP_DTYPE_INT32) { LOG(ERROR) << "[mluOpBallQuery]:Only int32 is supportedin output idx, but " "data type of tensor is " - << mluOpGetNameOfDataType(idx_desc->dtype) << "."; + << mluOpGetNameOfDataType(idx_desc->getDtype()) << "."; return MLUOP_STATUS_BAD_PARAM; } @@ -155,17 +155,17 @@ mluOpStatus_t MLUOP_WIN_API mluOpBallQuery( if (mluOpGetTensorElementNum(new_xyz_desc) == 0) { VLOG(5) << "[mluOpBallQuery] new_xyz tensor is a zero element tensor. The " "shape of new_xyz tensor is [" - << new_xyz_desc->dims[0] << ", " << new_xyz_desc->dims[1] << ", " - << new_xyz_desc->dims[2] << "]."; + << new_xyz_desc->getDimIndex(0) << ", " << new_xyz_desc->getDimIndex(1) << ", " + << new_xyz_desc->getDimIndex(2) << "]."; return MLUOP_STATUS_BAD_PARAM; } // the shape of xyz is [b, n, 3]. currently only n equal to 0 is supported - if (xyz_desc->dims[1] == 0) { + if (xyz_desc->getDimIndex(1) == 0) { return MLUOP_STATUS_SUCCESS; } // the shape of idx is [b, m, nsample]. currently only nsample equal to 0 is // supported - if (idx_desc->dims[2] == 0) { + if (idx_desc->getDimIndex(2) == 0) { return MLUOP_STATUS_SUCCESS; } @@ -191,10 +191,10 @@ mluOpStatus_t MLUOP_WIN_API mluOpBallQuery( policyFuncBallQuery(handle, new_xyz_desc, &k_dim, &k_type); // launch kernel - uint32_t b = new_xyz_desc->dims[0]; - uint32_t m = new_xyz_desc->dims[1]; - uint32_t n = xyz_desc->dims[1]; - mluOpDataType_t d_type = new_xyz_desc->dtype; + uint32_t b = new_xyz_desc->getDimIndex(0); + uint32_t m = new_xyz_desc->getDimIndex(1); + uint32_t n = xyz_desc->getDimIndex(1); + mluOpDataType_t d_type = new_xyz_desc->getDtype(); VLOG(5) << "[mluOpBallQuery] launch kernel KernelBallQuery[" << k_dim.x << ", " << k_dim.y << ", " << k_dim.z << "]"; CHECK_RETURN( diff --git a/kernels/bbox_overlaps/bbox_overlaps.cpp b/kernels/bbox_overlaps/bbox_overlaps.cpp index 3a82bdae0..a6af493f6 100644 --- a/kernels/bbox_overlaps/bbox_overlaps.cpp +++ b/kernels/bbox_overlaps/bbox_overlaps.cpp @@ -63,12 +63,12 @@ mluOpStatus_t MLUOP_WIN_API mluOpBboxOverlaps( PARAM_CHECK(API, bbox2_desc != NULL); PARAM_CHECK(API, ious_desc != NULL); - PARAM_CHECK(API, bbox1_desc->dtype == MLUOP_DTYPE_FLOAT || - bbox1_desc->dtype == MLUOP_DTYPE_HALF); - PARAM_CHECK(API, bbox1_desc->dtype == bbox2_desc->dtype); - PARAM_CHECK(API, bbox1_desc->dtype == ious_desc->dtype); - PARAM_CHECK(API, bbox1_desc->dim == 2); - PARAM_CHECK(API, bbox2_desc->dim == 2); + PARAM_CHECK(API, bbox1_desc->getDtype() == MLUOP_DTYPE_FLOAT || + bbox1_desc->getDtype() == MLUOP_DTYPE_HALF); + PARAM_CHECK(API, bbox1_desc->getDtype() == bbox2_desc->getDtype()); + PARAM_CHECK(API, bbox1_desc->getDtype() == ious_desc->getDtype()); + PARAM_CHECK(API, bbox1_desc->getDim() == 2); + PARAM_CHECK(API, bbox2_desc->getDim() == 2); // stride check STRIDE_TENSOR_CHECK(API + ":", bbox1_desc, "bbox1_desc must be contiguous"); @@ -83,23 +83,23 @@ mluOpStatus_t MLUOP_WIN_API mluOpBboxOverlaps( return MLUOP_STATUS_BAD_PARAM; } - if (bbox1_desc->dims[bbox1_desc->dim - 1] != 4 && bbox1_desc->dims[0] != 0) { + if (bbox1_desc->getDimIndex(bbox1_desc->getDim() - 1) != 4 && bbox1_desc->getDimIndex(0) != 0) { LOG(ERROR) << "[mluOpBboxOverlaps] Check failed: The Boxes' last dimenstion " "should be 4 or " << "the first dimension should be 0. But now bbox1's last dimension is " - << bbox1_desc->dims[bbox1_desc->dim - 1] - << ", bbox1's first dimension is " << bbox1_desc->dims[0] << "."; + << bbox1_desc->getDimIndex(bbox1_desc->getDim() - 1) + << ", bbox1's first dimension is " << bbox1_desc->getDimIndex(0) << "."; return MLUOP_STATUS_BAD_PARAM; } - if (bbox2_desc->dims[bbox2_desc->dim - 1] != 4 && bbox2_desc->dims[0] != 0) { + if (bbox2_desc->getDimIndex(bbox2_desc->getDim() - 1) != 4 && bbox2_desc->getDimIndex(0) != 0) { LOG(ERROR) << "[mluOpBboxOverlaps] Check failed: The Boxes' last dimenstion " "should be 4 or " << "the first dimension should be 0. But now bbox2's last dimension is " - << bbox2_desc->dims[bbox2_desc->dim - 1] - << ", bbox2's first dimension is " << bbox2_desc->dims[0] << "."; + << bbox2_desc->getDimIndex(bbox2_desc->getDim() - 1) + << ", bbox2's first dimension is " << bbox2_desc->getDimIndex(0) << "."; return MLUOP_STATUS_BAD_PARAM; } @@ -111,67 +111,67 @@ mluOpStatus_t MLUOP_WIN_API mluOpBboxOverlaps( } // param check - size_t rows = bbox1_desc->dims[0]; - size_t cols = bbox2_desc->dims[0]; + size_t rows = bbox1_desc->getDimIndex(0); + size_t cols = bbox2_desc->getDimIndex(0); size_t batch_num_all = rows; - if (ious_desc->dims[0] != rows) { + if (ious_desc->getDimIndex(0) != rows) { LOG(ERROR) << "[mluOpBboxOverlaps] Check failed: Whether it is aligned " "mode or not," - << "ious_desc->dims[0] == bbox1_desc->dims[0]. But now " - << "ious_desc->dims[0] is " << ious_desc->dims[0] - << ", bbox1_desc->dims[0] is " << rows << "."; + << "ious_desc->getDimIndex(0) == bbox1_desc->getDimIndex(0). But now " + << "ious_desc->getDimIndex(0) is " << ious_desc->getDimIndex(0) + << ", bbox1_desc->getDimIndex(0) is " << rows << "."; return MLUOP_STATUS_BAD_PARAM; } if (aligned) { if (rows != cols) { LOG(ERROR) << "[mluOpBboxOverlaps] Check failed: If it is aligned mode, " - << "bbox1_desc->dims[0] == bbox2_desc->dims[0]. But now " - << "bbox1_desc->dims[0] is " << rows - << ", bbox2_desc->dims[0] is " << cols << "."; + << "bbox1_desc->getDimIndex(0) == bbox2_desc->getDimIndex(0). But now " + << "bbox1_desc->getDimIndex(0) is " << rows + << ", bbox2_desc->getDimIndex(0) is " << cols << "."; return MLUOP_STATUS_BAD_PARAM; } if (rows * cols == 0) { - if ((ious_desc->dims[0] == rows) && - (ious_desc->dims[ious_desc->dim - 1] == 1)) { + if ((ious_desc->getDimIndex(0) == rows) && + (ious_desc->getDimIndex(ious_desc->getDim() - 1) == 1)) { return MLUOP_STATUS_SUCCESS; } else { LOG(ERROR) << "[mluOpBboxOverlaps] Check failed: If it is aligned mode and " << "rows * cols = 0, ious_desc's first dim should be 0, " << "and ious_desc's last dim should be 1. " - << "But now ious_desc's first dim is " << ious_desc->dims[0] + << "But now ious_desc's first dim is " << ious_desc->getDimIndex(0) << ", and ious_desc's last dim is " - << ious_desc->dims[ious_desc->dim - 1] << "."; + << ious_desc->getDimIndex(ious_desc->getDim() - 1) << "."; return MLUOP_STATUS_BAD_PARAM; } - } else if ((ious_desc->dims[0] != rows || ious_desc->dim != 1)) { + } else if ((ious_desc->getDimIndex(0) != rows || ious_desc->getDim() != 1)) { LOG(ERROR) << "[mluOpBboxOverlaps] Check failed: If it is aligned mode, " << "ious_desc's first dim should equal to bbox1's first dim, " "ious_desc's dim " << "should be 1. But now ious_desc's first dim is " - << ious_desc->dims[0] << ", bbox1's first dim is " << rows - << ", and ious_desc's dim is " << ious_desc->dim << "."; + << ious_desc->getDimIndex(0) << ", bbox1's first dim is " << rows + << ", and ious_desc's dim is " << ious_desc->getDim() << "."; return MLUOP_STATUS_BAD_PARAM; } } else { - if (ious_desc->dim != 2) { + if (ious_desc->getDim() != 2) { LOG(ERROR) << "[mluOpBboxOverlaps] Check failed: If it is non-aligned mode, " - << "ious_desc->dim == 2. But now ious_desc->dim is " << ious_desc->dim + << "ious_desc->getDim() == 2. But now ious_desc->getDim() is " << ious_desc->getDim() << "."; return MLUOP_STATUS_BAD_PARAM; } - if (ious_desc->dims[0] != rows || - ious_desc->dims[ious_desc->dim - 1] != cols) { + if (ious_desc->getDimIndex(0) != rows || + ious_desc->getDimIndex(ious_desc->getDim() - 1) != cols) { LOG(ERROR) << "[mluOpBboxOverlaps] Check failed: If it is non-aligned mode, " << "ious_desc's first dim should be " << rows << ", ious_desc's last " << "dim should be " << cols << "." - << "But now ious_desc's first dim is " << ious_desc->dims[0] + << "But now ious_desc's first dim is " << ious_desc->getDimIndex(0) << ", and ious_desc's last dim is " - << ious_desc->dims[ious_desc->dim - 1] << "."; + << ious_desc->getDimIndex(ious_desc->getDim() - 1) << "."; return MLUOP_STATUS_BAD_PARAM; } if (rows * cols == 0) { @@ -206,7 +206,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpBboxOverlaps( } // generate mluOpBboxOverlaps prototxt end! - mluOpDataType_t k_datatype = bbox1_desc->dtype; + mluOpDataType_t k_datatype = bbox1_desc->getDtype(); cnrtDim3_t k_dim; cnrtFunctionType_t k_type; diff --git a/kernels/binary_op/binary_op_host.cpp b/kernels/binary_op/binary_op_host.cpp index 195db20c2..7cb121898 100644 --- a/kernels/binary_op/binary_op_host.cpp +++ b/kernels/binary_op/binary_op_host.cpp @@ -45,7 +45,7 @@ void binaryOpPolicyFunc(mluOpHandle_t handle, const int pad_up_size, const uint64_t core_number = union_number * core_dim; const uint64_t dim = mluOpGetTensorElementNum(desc); - uint64_t size = dim * mluop::getSizeOfDataType(desc->dtype); + uint64_t size = dim * mluop::getSizeOfDataType(desc->getDtype()); size = PAD_UP(size, pad_up_size); // Union1 policyFunc @@ -70,7 +70,7 @@ void binaryOpBlockPolicyFunc(mluOpHandle_t handle, const uint32_t core_number = mluop::runtime::getMaxParallelJobNum(handle, k_type); const size_t element_num = mluOpGetTensorElementNum(desc); - const uint32_t dtype_size = mluop::getSizeOfDataType(desc->dtype); + const uint32_t dtype_size = mluop::getSizeOfDataType(desc->getDtype()); if (MLUOP_MLU590 == handle->arch) { const uint32_t llc_pending_size = 512; pad_up_size = std::max(llc_pending_size, pad_up_size); @@ -118,31 +118,31 @@ mluOpStatus_t binaryOpParamCheck( PARAM_CHECK(op_name, output_desc != NULL); // check dtype equal - PARAM_CHECK_EQ(op_name, input1_desc->dtype, input2_desc->dtype); - PARAM_CHECK_EQ(op_name, input1_desc->dtype, output_desc->dtype); + PARAM_CHECK_EQ(op_name, input1_desc->getDtype(), input2_desc->getDtype()); + PARAM_CHECK_EQ(op_name, input1_desc->getDtype(), output_desc->getDtype()); // check dim less than MLUOP_DIM_MAX - PARAM_CHECK_LE(op_name, input1_desc->dim, MLUOP_DIM_MAX); - PARAM_CHECK_LE(op_name, input2_desc->dim, MLUOP_DIM_MAX); - PARAM_CHECK_LE(op_name, output_desc->dim, MLUOP_DIM_MAX); - PARAM_CHECK_GT(op_name, input1_desc->dim, 0); - PARAM_CHECK_GT(op_name, input2_desc->dim, 0); - PARAM_CHECK_GT(op_name, output_desc->dim, 0); + PARAM_CHECK_LE(op_name, input1_desc->getDim(), MLUOP_DIM_MAX); + PARAM_CHECK_LE(op_name, input2_desc->getDim(), MLUOP_DIM_MAX); + PARAM_CHECK_LE(op_name, output_desc->getDim(), MLUOP_DIM_MAX); + PARAM_CHECK_GT(op_name, input1_desc->getDim(), 0); + PARAM_CHECK_GT(op_name, input2_desc->getDim(), 0); + PARAM_CHECK_GT(op_name, output_desc->getDim(), 0); // check data type support - if (!isSupportType(input1_desc->dtype, support_type, len)) { + if (!isSupportType(input1_desc->getDtype(), support_type, len)) { LOG(ERROR) << op_name << ":input1_desc's data type is not supported."; return MLUOP_STATUS_BAD_PARAM; } if (isSupportBroadcast) { - int32_t left_dim_num = input1_desc->dim; - int32_t right_dim_num = input2_desc->dim; + int32_t left_dim_num = input1_desc->getDim(); + int32_t right_dim_num = input2_desc->getDim(); int32_t max_dim = std::max(left_dim_num, right_dim_num); - std::vector left_aligned_dims(input1_desc->dims, - input1_desc->dims + input1_desc->dim); - std::vector right_aligned_dims(input2_desc->dims, - input2_desc->dims + input2_desc->dim); + std::vector left_aligned_dims(input1_desc->getDims(), + input1_desc->getDims() + input1_desc->getDim()); + std::vector right_aligned_dims(input2_desc->getDims(), + input2_desc->getDims() + input2_desc->getDim()); // aligning dimensions to max_dim if (left_dim_num < max_dim) { @@ -155,7 +155,7 @@ mluOpStatus_t binaryOpParamCheck( max_dim - right_dim_num, 1); } - if (output_desc->dim != max_dim) { + if (output_desc->getDim() != max_dim) { LOG(ERROR) << op_name << " The dimension size of the output tensors does not meet the " @@ -175,17 +175,17 @@ mluOpStatus_t binaryOpParamCheck( } int max_dim_value = std::max(left_aligned_dims[i], right_aligned_dims[i]); int min_dim_value = std::min(left_aligned_dims[i], right_aligned_dims[i]); - if ((min_dim_value > 0 && max_dim_value != output_desc->dims[i]) || - (min_dim_value == 0 && output_desc->dims[i] != 0)) { + if ((min_dim_value > 0 && max_dim_value != output_desc->getDimIndex(i)) || + (min_dim_value == 0 && output_desc->getDimIndex(i) != 0)) { LOG(ERROR) << op_name << " The shape of the inferred tensors is not equal" << " to the output tensor. In the broadcast shape" << ", the shape of x is " - << array2String(input1_desc->dim, input1_desc->dims) + << array2String(input1_desc->getDim(), input1_desc->getDims()) << ", the shape of y is " - << array2String(input2_desc->dim, input2_desc->dims) + << array2String(input2_desc->getDim(), input2_desc->getDims()) << ", the shape of z is " - << array2String(output_desc->dim, output_desc->dims); + << array2String(output_desc->getDim(), output_desc->getDims()); return MLUOP_STATUS_BAD_PARAM; } } @@ -238,23 +238,23 @@ mluOpStatus_t binaryOpParamSameShapeCheck( const mluOpTensorDescriptor_t input2_desc, const mluOpTensorDescriptor_t output_desc) { // check dim - PARAM_CHECK_EQ("[" + op_name + "]", input1_desc->dim, input2_desc->dim); - PARAM_CHECK_EQ("[" + op_name + "]", input1_desc->dim, output_desc->dim); + PARAM_CHECK_EQ("[" + op_name + "]", input1_desc->getDim(), input2_desc->getDim()); + PARAM_CHECK_EQ("[" + op_name + "]", input1_desc->getDim(), output_desc->getDim()); // check shape - for (int i = 0; i < input1_desc->dim; i++) { - if (input1_desc->dims[i] != input2_desc->dims[i]) { + for (int i = 0; i < input1_desc->getDim(); i++) { + if (input1_desc->getDimIndex(i) != input2_desc->getDimIndex(i)) { LOG(ERROR) << op_name << ":The shape of input1 should be equal to input2" << ". But now input1's shape[" << i << "] is " - << input1_desc->dims[i] << ", input2's shape[" << i << "] is " - << input2_desc->dims[i] << "."; + << input1_desc->getDimIndex(i) << ", input2's shape[" << i << "] is " + << input2_desc->getDimIndex(i) << "."; return MLUOP_STATUS_BAD_PARAM; } - if (input1_desc->dims[i] != output_desc->dims[i]) { + if (input1_desc->getDimIndex(i) != output_desc->getDimIndex(i)) { LOG(ERROR) << op_name << ":The shape of input1 should be equal to output" << ". But now input1's shape[" << i << "] is " - << input1_desc->dims[i] << ", output's shape[" << i << "] is " - << output_desc->dims[i] << "."; + << input1_desc->getDimIndex(i) << ", output's shape[" << i << "] is " + << output_desc->getDimIndex(i) << "."; return MLUOP_STATUS_BAD_PARAM; } } diff --git a/kernels/border_align/border_align_backward/border_align_backward.cpp b/kernels/border_align/border_align_backward/border_align_backward.cpp index c507de17a..68145a34b 100644 --- a/kernels/border_align/border_align_backward/border_align_backward.cpp +++ b/kernels/border_align/border_align_backward/border_align_backward.cpp @@ -56,10 +56,10 @@ mluOpStatus_t mluOpBorderAlignBackward( PARAM_CHECK(API, argmax_idx_desc != nullptr); PARAM_CHECK(API, grad_input_desc != nullptr); - PARAM_CHECK(API, grad_output_desc->dim == 4); - PARAM_CHECK(API, boxes_desc->dim == 3); - PARAM_CHECK(API, argmax_idx_desc->dim == 4); - PARAM_CHECK(API, grad_input_desc->dim == 4); + PARAM_CHECK(API, grad_output_desc->getDim() == 4); + PARAM_CHECK(API, boxes_desc->getDim() == 3); + PARAM_CHECK(API, argmax_idx_desc->getDim() == 4); + PARAM_CHECK(API, grad_input_desc->getDim() == 4); // stride check STRIDE_TENSOR_CHECK("[mluOpBorderAlignBackward]:", grad_output_desc, @@ -73,52 +73,52 @@ mluOpStatus_t mluOpBorderAlignBackward( const int32_t border_num = 4; const int32_t coord_num = 4; - const int32_t origin_n = grad_input_desc->dims[0]; - const int32_t origin_h = grad_input_desc->dims[1]; - const int32_t origin_w = grad_input_desc->dims[2]; - const int32_t origin_c = grad_input_desc->dims[3] / border_num; - const int32_t origin_k = boxes_desc->dims[1]; - - PARAM_CHECK(API, grad_output_desc->dtype == MLUOP_DTYPE_FLOAT || - grad_output_desc->dtype == MLUOP_DTYPE_HALF); - PARAM_CHECK(API, argmax_idx_desc->dtype == MLUOP_DTYPE_INT32); - PARAM_CHECK(API, boxes_desc->dtype == grad_output_desc->dtype); - PARAM_CHECK(API, grad_input_desc->dtype == grad_output_desc->dtype); - - PARAM_CHECK(API, grad_output_desc->layout == MLUOP_LAYOUT_NHWC); - PARAM_CHECK(API, argmax_idx_desc->layout == MLUOP_LAYOUT_NHWC); - PARAM_CHECK(API, grad_input_desc->layout == MLUOP_LAYOUT_NHWC); - - PARAM_CHECK(API, grad_input_desc->dims[3] % 4 == 0, + const int32_t origin_n = grad_input_desc->getDimIndex(0); + const int32_t origin_h = grad_input_desc->getDimIndex(1); + const int32_t origin_w = grad_input_desc->getDimIndex(2); + const int32_t origin_c = grad_input_desc->getDimIndex(3) / border_num; + const int32_t origin_k = boxes_desc->getDimIndex(1); + + PARAM_CHECK(API, grad_output_desc->getDtype() == MLUOP_DTYPE_FLOAT || + grad_output_desc->getDtype() == MLUOP_DTYPE_HALF); + PARAM_CHECK(API, argmax_idx_desc->getDtype() == MLUOP_DTYPE_INT32); + PARAM_CHECK(API, boxes_desc->getDtype() == grad_output_desc->getDtype()); + PARAM_CHECK(API, grad_input_desc->getDtype() == grad_output_desc->getDtype()); + + PARAM_CHECK(API, grad_output_desc->getLayout() == MLUOP_LAYOUT_NHWC); + PARAM_CHECK(API, argmax_idx_desc->getLayout() == MLUOP_LAYOUT_NHWC); + PARAM_CHECK(API, grad_input_desc->getLayout() == MLUOP_LAYOUT_NHWC); + + PARAM_CHECK(API, grad_input_desc->getDimIndex(3) % 4 == 0, "(4 represents the number of borders)."); - PARAM_CHECK_NE(API, grad_input_desc->dims[0], 0); - PARAM_CHECK_NE(API, grad_input_desc->dims[3] / 4, 0, + PARAM_CHECK_NE(API, grad_input_desc->getDimIndex(0), 0); + PARAM_CHECK_NE(API, grad_input_desc->getDimIndex(3) / 4, 0, "(4 represents the number of borders)."); - PARAM_CHECK_NE(API, grad_input_desc->dims[1], 0); - PARAM_CHECK_NE(API, grad_input_desc->dims[2], 0); - PARAM_CHECK(API, grad_input_desc->dims[1] * grad_input_desc->dims[2] == - boxes_desc->dims[1]); - PARAM_CHECK(API, boxes_desc->dim == 3); - PARAM_CHECK(API, boxes_desc->dims[2] == border_num, "(border_num = 4)."); - PARAM_CHECK_NE(API, boxes_desc->dims[1], 0); + PARAM_CHECK_NE(API, grad_input_desc->getDimIndex(1), 0); + PARAM_CHECK_NE(API, grad_input_desc->getDimIndex(2), 0); + PARAM_CHECK(API, grad_input_desc->getDimIndex(1) * grad_input_desc->getDimIndex(2) == + boxes_desc->getDimIndex(1)); + PARAM_CHECK(API, boxes_desc->getDim() == 3); + PARAM_CHECK(API, boxes_desc->getDimIndex(2) == border_num, "(border_num = 4)."); + PARAM_CHECK_NE(API, boxes_desc->getDimIndex(1), 0); PARAM_CHECK_GT(API, pool_size, 0); - PARAM_CHECK_EQ(API, grad_output_desc->dims[0], grad_input_desc->dims[0]); - PARAM_CHECK_EQ(API, grad_output_desc->dims[1], boxes_desc->dims[1]); - PARAM_CHECK_EQ(API, grad_output_desc->dims[2], border_num, + PARAM_CHECK_EQ(API, grad_output_desc->getDimIndex(0), grad_input_desc->getDimIndex(0)); + PARAM_CHECK_EQ(API, grad_output_desc->getDimIndex(1), boxes_desc->getDimIndex(1)); + PARAM_CHECK_EQ(API, grad_output_desc->getDimIndex(2), border_num, "(border_num = 4)."); - PARAM_CHECK_EQ(API, grad_output_desc->dims[3], grad_input_desc->dims[3] / 4, + PARAM_CHECK_EQ(API, grad_output_desc->getDimIndex(3), grad_input_desc->getDimIndex(3) / 4, "(4 represents the number of borders)."); - PARAM_CHECK_EQ(API, boxes_desc->dims[0], grad_input_desc->dims[0]); - PARAM_CHECK_EQ(API, boxes_desc->dims[1], boxes_desc->dims[1]); - PARAM_CHECK_EQ(API, boxes_desc->dims[2], border_num, "(border_num = 4)."); + PARAM_CHECK_EQ(API, boxes_desc->getDimIndex(0), grad_input_desc->getDimIndex(0)); + PARAM_CHECK_EQ(API, boxes_desc->getDimIndex(1), boxes_desc->getDimIndex(1)); + PARAM_CHECK_EQ(API, boxes_desc->getDimIndex(2), border_num, "(border_num = 4)."); - PARAM_CHECK_EQ(API, argmax_idx_desc->dims[0], grad_input_desc->dims[0]); - PARAM_CHECK_EQ(API, argmax_idx_desc->dims[1], boxes_desc->dims[1]); - PARAM_CHECK_EQ(API, argmax_idx_desc->dims[2], border_num, + PARAM_CHECK_EQ(API, argmax_idx_desc->getDimIndex(0), grad_input_desc->getDimIndex(0)); + PARAM_CHECK_EQ(API, argmax_idx_desc->getDimIndex(1), boxes_desc->getDimIndex(1)); + PARAM_CHECK_EQ(API, argmax_idx_desc->getDimIndex(2), border_num, "(border_num = 4)."); - PARAM_CHECK_EQ(API, argmax_idx_desc->dims[3], grad_input_desc->dims[3] / 4, + PARAM_CHECK_EQ(API, argmax_idx_desc->getDimIndex(3), grad_input_desc->getDimIndex(3) / 4, "(4 represents the number of borders)."); TENSOR_NUM_CHECK(API, mluOpGetTensorElementNum(grad_output_desc), @@ -161,7 +161,7 @@ mluOpStatus_t mluOpBorderAlignBackward( DESTROY_CNNL_HANDLE(cnnl_handle); } VLOG(5) << "[mluOpBorderAlignBackward] cnnlFill_v3 end."; - mluOpDataType_t input_dtype = grad_output_desc->dtype; + mluOpDataType_t input_dtype = grad_output_desc->getDtype(); VLOG(5) << "Launch Kernel KernelBorderAlignBackward<<dim == 4); - PARAM_CHECK(API, boxes_desc->dim == 3); - PARAM_CHECK(API, output_desc->dim == 4); - PARAM_CHECK(API, argmax_idx_desc->dim == 4); + PARAM_CHECK(API, input_desc->getDim() == 4); + PARAM_CHECK(API, boxes_desc->getDim() == 3); + PARAM_CHECK(API, output_desc->getDim() == 4); + PARAM_CHECK(API, argmax_idx_desc->getDim() == 4); // stride check STRIDE_TENSOR_CHECK("[mluOpBorderAlignForward]:", input_desc, @@ -70,44 +70,44 @@ mluOpStatus_t mluOpBorderAlignForward( const int32_t border_num = 4; const int32_t coord_num = 4; - const int32_t origin_n = input_desc->dims[0]; - const int32_t origin_h = input_desc->dims[1]; - const int32_t origin_w = input_desc->dims[2]; - const int32_t origin_c = input_desc->dims[3] / border_num; - const int32_t origin_k = boxes_desc->dims[1]; + const int32_t origin_n = input_desc->getDimIndex(0); + const int32_t origin_h = input_desc->getDimIndex(1); + const int32_t origin_w = input_desc->getDimIndex(2); + const int32_t origin_c = input_desc->getDimIndex(3) / border_num; + const int32_t origin_k = boxes_desc->getDimIndex(1); - PARAM_CHECK(API, input_desc->dtype == boxes_desc->dtype); - PARAM_CHECK(API, input_desc->dtype == MLUOP_DTYPE_FLOAT || - input_desc->dtype == MLUOP_DTYPE_HALF); - PARAM_CHECK(API, boxes_desc->dtype == MLUOP_DTYPE_FLOAT || - boxes_desc->dtype == MLUOP_DTYPE_HALF); - PARAM_CHECK(API, output_desc->dtype == input_desc->dtype); - PARAM_CHECK(API, argmax_idx_desc->dtype == MLUOP_DTYPE_INT32); + PARAM_CHECK(API, input_desc->getDtype() == boxes_desc->getDtype()); + PARAM_CHECK(API, input_desc->getDtype() == MLUOP_DTYPE_FLOAT || + input_desc->getDtype() == MLUOP_DTYPE_HALF); + PARAM_CHECK(API, boxes_desc->getDtype() == MLUOP_DTYPE_FLOAT || + boxes_desc->getDtype() == MLUOP_DTYPE_HALF); + PARAM_CHECK(API, output_desc->getDtype() == input_desc->getDtype()); + PARAM_CHECK(API, argmax_idx_desc->getDtype() == MLUOP_DTYPE_INT32); - PARAM_CHECK(API, input_desc->layout == MLUOP_LAYOUT_NHWC); - PARAM_CHECK(API, output_desc->layout == MLUOP_LAYOUT_NHWC); - PARAM_CHECK(API, argmax_idx_desc->layout == MLUOP_LAYOUT_NHWC); + PARAM_CHECK(API, input_desc->getLayout() == MLUOP_LAYOUT_NHWC); + PARAM_CHECK(API, output_desc->getLayout() == MLUOP_LAYOUT_NHWC); + PARAM_CHECK(API, argmax_idx_desc->getLayout() == MLUOP_LAYOUT_NHWC); - PARAM_CHECK(API, input_desc->dims[3] % 4 == 0); - PARAM_CHECK_NE(API, input_desc->dims[0], 0); - PARAM_CHECK_NE(API, input_desc->dims[3] / 4, 0); - PARAM_CHECK_NE(API, input_desc->dims[1], 0); - PARAM_CHECK_NE(API, input_desc->dims[2], 0); - PARAM_CHECK_NE(API, boxes_desc->dims[1], 0); - PARAM_CHECK(API, boxes_desc->dim == 3); - PARAM_CHECK(API, boxes_desc->dims[2] == 4); + PARAM_CHECK(API, input_desc->getDimIndex(3) % 4 == 0); + PARAM_CHECK_NE(API, input_desc->getDimIndex(0), 0); + PARAM_CHECK_NE(API, input_desc->getDimIndex(3) / 4, 0); + PARAM_CHECK_NE(API, input_desc->getDimIndex(1), 0); + PARAM_CHECK_NE(API, input_desc->getDimIndex(2), 0); + PARAM_CHECK_NE(API, boxes_desc->getDimIndex(1), 0); + PARAM_CHECK(API, boxes_desc->getDim() == 3); + PARAM_CHECK(API, boxes_desc->getDimIndex(2) == 4); - PARAM_CHECK(API, input_desc->dims[0] == boxes_desc->dims[0]); + PARAM_CHECK(API, input_desc->getDimIndex(0) == boxes_desc->getDimIndex(0)); PARAM_CHECK(API, - input_desc->dims[1] * input_desc->dims[2] == boxes_desc->dims[1]); - PARAM_CHECK_EQ(API, output_desc->dims[0], input_desc->dims[0]); - PARAM_CHECK_EQ(API, output_desc->dims[1], boxes_desc->dims[1]); - PARAM_CHECK_EQ(API, output_desc->dims[2], 4); - PARAM_CHECK_EQ(API, output_desc->dims[3], input_desc->dims[3] / 4); - PARAM_CHECK_EQ(API, argmax_idx_desc->dims[0], input_desc->dims[0]); - PARAM_CHECK_EQ(API, argmax_idx_desc->dims[1], boxes_desc->dims[1]); - PARAM_CHECK_EQ(API, argmax_idx_desc->dims[2], 4); - PARAM_CHECK_EQ(API, argmax_idx_desc->dims[3], input_desc->dims[3] / 4); + input_desc->getDimIndex(1) * input_desc->getDimIndex(2) == boxes_desc->getDimIndex(1)); + PARAM_CHECK_EQ(API, output_desc->getDimIndex(0), input_desc->getDimIndex(0)); + PARAM_CHECK_EQ(API, output_desc->getDimIndex(1), boxes_desc->getDimIndex(1)); + PARAM_CHECK_EQ(API, output_desc->getDimIndex(2), 4); + PARAM_CHECK_EQ(API, output_desc->getDimIndex(3), input_desc->getDimIndex(3) / 4); + PARAM_CHECK_EQ(API, argmax_idx_desc->getDimIndex(0), input_desc->getDimIndex(0)); + PARAM_CHECK_EQ(API, argmax_idx_desc->getDimIndex(1), boxes_desc->getDimIndex(1)); + PARAM_CHECK_EQ(API, argmax_idx_desc->getDimIndex(2), 4); + PARAM_CHECK_EQ(API, argmax_idx_desc->getDimIndex(3), input_desc->getDimIndex(3) / 4); const size_t input_num = mluOpGetTensorElementNum(input_desc); const size_t boxes_num = mluOpGetTensorElementNum(boxes_desc); @@ -139,7 +139,7 @@ mluOpStatus_t mluOpBorderAlignForward( << k_type / CORE_DIM << ", " << k_dim.x << ", " << k_dim.y << ", " << k_dim.z << ">>>"; CHECK_RETURN(API, KernelBorderAlignForward( - k_dim, k_type, handle->queue, input_desc->dtype, input, + k_dim, k_type, handle->queue, input_desc->getDtype(), input, boxes, pool_size, origin_n, origin_h, origin_w, origin_c, origin_k, output, (int32_t *)argmax_idx)); GEN_CASE_END(); diff --git a/kernels/box_iou_rotated/box_iou_rotated.cpp b/kernels/box_iou_rotated/box_iou_rotated.cpp index f10044d5e..afad59c7e 100644 --- a/kernels/box_iou_rotated/box_iou_rotated.cpp +++ b/kernels/box_iou_rotated/box_iou_rotated.cpp @@ -91,9 +91,9 @@ mluOpBoxIouRotated(mluOpHandle_t handle, const int mode, const bool aligned, PARAM_CHECK("[mluOpBoxIouRotated]", ious_desc != NULL); // datatype check - PARAM_CHECK("[mluOpBoxIouRotated]", box1_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK_EQ("[mluOpBoxIouRotated]", box1_desc->dtype, box2_desc->dtype); - PARAM_CHECK_EQ("[mluOpBoxIouRotated]", box1_desc->dtype, ious_desc->dtype); + PARAM_CHECK("[mluOpBoxIouRotated]", box1_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK_EQ("[mluOpBoxIouRotated]", box1_desc->getDtype(), box2_desc->getDtype()); + PARAM_CHECK_EQ("[mluOpBoxIouRotated]", box1_desc->getDtype(), ious_desc->getDtype()); // param check if (mode != 0 && mode != 1) { @@ -104,71 +104,71 @@ mluOpBoxIouRotated(mluOpHandle_t handle, const int mode, const bool aligned, } // dims and shape check - PARAM_CHECK_EQ("[mluOpBoxIouRotated]", box1_desc->dim, 2); - PARAM_CHECK_EQ("[mluOpBoxIouRotated]", box2_desc->dim, 2); - if (box1_desc->dims[box1_desc->dim - 1] != SINGLE_BOX_DIM && - box1_desc->dims[0] != 0) { + PARAM_CHECK_EQ("[mluOpBoxIouRotated]", box1_desc->getDim(), 2); + PARAM_CHECK_EQ("[mluOpBoxIouRotated]", box2_desc->getDim(), 2); + if (box1_desc->getDimIndex(box1_desc->getDim() - 1) != SINGLE_BOX_DIM && + box1_desc->getDimIndex(0) != 0) { LOG(ERROR) << "[mluOpBoxIouRotated] Check failed: The Boxes' last dimenstion " "should be 5 or " << "the first dimension should be 0. But now box1's last dimension is " - << box1_desc->dims[box1_desc->dim - 1] << ", box1's first dimension is " - << box1_desc->dims[0] << "."; + << box1_desc->getDimIndex(box1_desc->getDim() - 1) << ", box1's first dimension is " + << box1_desc->getDimIndex(0) << "."; return MLUOP_STATUS_BAD_PARAM; } - if (box2_desc->dims[box2_desc->dim - 1] != SINGLE_BOX_DIM && - box2_desc->dims[0] != 0) { + if (box2_desc->getDimIndex(box2_desc->getDim() - 1) != SINGLE_BOX_DIM && + box2_desc->getDimIndex(0) != 0) { LOG(ERROR) << "[mluOpBoxIouRotated] Check failed: The Boxes' last dimenstion " "should be 5 or " << "the first dimension should be 0. But now box2's last dimension is " - << box2_desc->dims[box2_desc->dim - 1] << ", box2's first dimension is " - << box2_desc->dims[0] << "."; + << box2_desc->getDimIndex(box2_desc->getDim() - 1) << ", box2's first dimension is " + << box2_desc->getDimIndex(0) << "."; return MLUOP_STATUS_BAD_PARAM; } - if (ious_desc->dims[0] != box1_desc->dims[0]) { + if (ious_desc->getDimIndex(0) != box1_desc->getDimIndex(0)) { LOG(ERROR) << "[mluOpBoxIouRotated] Check failed: Whether it is aligned or not," - << "ious_desc->dims[0] should equal to box1_desc->dims[0]. But now " - << "ious_desc->dims[0] is " << ious_desc->dims[0] - << ", box1_desc->dims[0] is " << box1_desc->dims[0] << "."; + << "ious_desc->getDimIndex(0) should equal to box1_desc->getDimIndex(0). But now " + << "ious_desc->getDimIndex(0) is " << ious_desc->getDimIndex(0) + << ", box1_desc->getDimIndex(0) is " << box1_desc->getDimIndex(0) << "."; return MLUOP_STATUS_BAD_PARAM; } if (aligned) { - if (ious_desc->dim != 1) { + if (ious_desc->getDim() != 1) { LOG(ERROR) << "[mluOpBoxIouRotated] Check failed: If it is aligned mode, " - << "ious_desc->dim should equal to 1. But now is " - << ious_desc->dim << "."; + << "ious_desc->getDim() should equal to 1. But now is " + << ious_desc->getDim() << "."; return MLUOP_STATUS_BAD_PARAM; } - if (box1_desc->dims[0] != box2_desc->dims[0]) { + if (box1_desc->getDimIndex(0) != box2_desc->getDimIndex(0)) { LOG(ERROR) << "[mluOpBoxIouRotated] Check failed: If it is aligned mode, " - << "box1_desc->dims[0] should equal to box2_desc->dims[0]. But now " - << "box1_desc->dims[0] is " << box1_desc->dims[0] - << ", box2_desc->dims[0] is " << box2_desc->dims[0] << "."; + << "box1_desc->getDimIndex(0) should equal to box2_desc->getDimIndex(0). But now " + << "box1_desc->getDimIndex(0) is " << box1_desc->getDimIndex(0) + << ", box2_desc->getDimIndex(0) is " << box2_desc->getDimIndex(0) << "."; return MLUOP_STATUS_BAD_PARAM; } - if (handle->arch < 592 && box1_desc->dims[0] > MAX_BOX_NUM) { + if (handle->arch < 592 && box1_desc->getDimIndex(0) > MAX_BOX_NUM) { LOG(ERROR) << "[mluOpBoxIouRotated] Check failed: If it is aligned mode, " - << "on MLU300 box1_desc->dims[0] should less than or equal to " - << "10,000,000 . But now is " << box1_desc->dims[0] << "."; + << "on MLU300 box1_desc->getDimIndex(0) should less than or equal to " + << "10,000,000 . But now is " << box1_desc->getDimIndex(0) << "."; return MLUOP_STATUS_NOT_SUPPORTED; } } else { - if (ious_desc->dim != 2) { + if (ious_desc->getDim() != 2) { LOG(ERROR) << "[mluOpBoxIouRotated] Check failed: If it is non-aligned mode, " - << "ious_desc->dim should equal to 2. But now is " << ious_desc->dim + << "ious_desc->getDim() should equal to 2. But now is " << ious_desc->getDim() << "."; return MLUOP_STATUS_BAD_PARAM; } - if (ious_desc->dims[1] != box2_desc->dims[0]) { + if (ious_desc->getDimIndex(1) != box2_desc->getDimIndex(0)) { LOG(ERROR) << "[mluOpBoxIouRotated] Check failed: If it is non-aligned mode, " << "ious_desc's last dim should equal to box2_desc's first dim " - << box2_desc->dims[0] << ", But now ious_desc's last dim is " - << ious_desc->dims[1] << "."; + << box2_desc->getDimIndex(0) << ", But now ious_desc's last dim is " + << ious_desc->getDimIndex(1) << "."; return MLUOP_STATUS_BAD_PARAM; } } @@ -182,7 +182,7 @@ mluOpBoxIouRotated(mluOpHandle_t handle, const int mode, const bool aligned, "ious_desc must be contiguous"); // 0-element check, after dim and shape check - if (box1_desc->dims[0] * box2_desc->dims[0] == 0) { + if (box1_desc->getDimIndex(0) * box2_desc->getDimIndex(0) == 0) { VLOG(5) << "[mluOpBoxIouRotated] Skip zero element boxes."; return MLUOP_STATUS_SUCCESS; } @@ -228,7 +228,7 @@ mluOpBoxIouRotated(mluOpHandle_t handle, const int mode, const bool aligned, << k_dim.y << ", " << k_dim.z << "]."; CHECK_RETURN( "[mluOpBoxIouRotated]", - (KernelBoxIouRotated(k_dim, k_type, handle->queue, box1_desc->dtype, box1, + (KernelBoxIouRotated(k_dim, k_type, handle->queue, box1_desc->getDtype(), box1, box2, ious, num_box1, num_box2, mode, aligned))); GEN_CASE_END(); return MLUOP_STATUS_SUCCESS; diff --git a/kernels/carafe/carafe.cpp b/kernels/carafe/carafe.cpp index e4cc09b03..b5f906c8c 100644 --- a/kernels/carafe/carafe.cpp +++ b/kernels/carafe/carafe.cpp @@ -140,7 +140,7 @@ mluOpStatus_t genPolicy(mluOpHandle_t handle, const int group_size = carafe_desc->group_size; const int scale_factor = carafe_desc->scale_factor; - const int dtype_size = mluop::getSizeOfDataType(input_desc->dtype); + const int dtype_size = mluop::getSizeOfDataType(input_desc->getDtype()); const int align_size_NRAM = WRAM_ALIGN_SIZE / dtype_size; const int align_size_NFU = NFU_ALIGN_SIZE / dtype_size; @@ -326,16 +326,16 @@ mluOpStatus_t CarafeForwardParamCheck( * dim check */ VLOG(5) << CARAFE_FORWARD_API << "Check dimNb."; - PARAM_CHECK_EQ(CARAFE_FORWARD_API, input_desc->dim, carafe_desc->dimNb); - PARAM_CHECK_EQ(CARAFE_FORWARD_API, mask_desc->dim, carafe_desc->dimNb); - PARAM_CHECK_EQ(CARAFE_FORWARD_API, output_desc->dim, carafe_desc->dimNb); + PARAM_CHECK_EQ(CARAFE_FORWARD_API, input_desc->getDim(), carafe_desc->dimNb); + PARAM_CHECK_EQ(CARAFE_FORWARD_API, mask_desc->getDim(), carafe_desc->dimNb); + PARAM_CHECK_EQ(CARAFE_FORWARD_API, output_desc->getDim(), carafe_desc->dimNb); /* * layout check */ VLOG(5) << CARAFE_FORWARD_API << "Check tensor layout."; - PARAM_CHECK_EQ(CARAFE_FORWARD_API, input_desc->layout, MLUOP_LAYOUT_NHWC); - PARAM_CHECK_EQ(CARAFE_FORWARD_API, mask_desc->layout, MLUOP_LAYOUT_NHWC); - PARAM_CHECK_EQ(CARAFE_FORWARD_API, output_desc->layout, MLUOP_LAYOUT_NHWC); + PARAM_CHECK_EQ(CARAFE_FORWARD_API, input_desc->getLayout(), MLUOP_LAYOUT_NHWC); + PARAM_CHECK_EQ(CARAFE_FORWARD_API, mask_desc->getLayout(), MLUOP_LAYOUT_NHWC); + PARAM_CHECK_EQ(CARAFE_FORWARD_API, output_desc->getLayout(), MLUOP_LAYOUT_NHWC); /* * tensor contiguousness check */ @@ -353,18 +353,18 @@ mluOpStatus_t CarafeForwardParamCheck( VLOG(5) << CARAFE_FORWARD_API << "Check off-chip data type."; PARAM_CHECK_V2( CARAFE_FORWARD_API, - (input_desc->dtype == MLUOP_DTYPE_HALF) || - (input_desc->dtype == MLUOP_DTYPE_FLOAT), + (input_desc->getDtype() == MLUOP_DTYPE_HALF) || + (input_desc->getDtype() == MLUOP_DTYPE_FLOAT), "only half and float are supported, but the data type of input tensor is " - << mluOpGetNameOfDataType(input_desc->dtype) << "."); + << mluOpGetNameOfDataType(input_desc->getDtype()) << "."); PARAM_CHECK_V2(CARAFE_FORWARD_API, - (input_desc->dtype == mask_desc->dtype) && - (input_desc->dtype == output_desc->dtype), + (input_desc->getDtype() == mask_desc->getDtype()) && + (input_desc->getDtype() == output_desc->getDtype()), "The input, mask and output tensors should have the same data " "type, but the data types are: " - << mluOpGetNameOfDataType(input_desc->dtype) << ", " - << mluOpGetNameOfDataType(mask_desc->dtype) << ", " - << mluOpGetNameOfDataType(output_desc->dtype) << "."); + << mluOpGetNameOfDataType(input_desc->getDtype()) << ", " + << mluOpGetNameOfDataType(mask_desc->getDtype()) << ", " + << mluOpGetNameOfDataType(output_desc->getDtype()) << "."); /* * shape param check * @@ -486,25 +486,25 @@ mluOpStatus_t CarafeBackwardParamCheck( /* * dim check */ - PARAM_CHECK_EQ(CARAFE_BACKWARD_API, input_desc->dim, carafe_desc->dimNb); - PARAM_CHECK_EQ(CARAFE_BACKWARD_API, mask_desc->dim, carafe_desc->dimNb); - PARAM_CHECK_EQ(CARAFE_BACKWARD_API, grad_output_desc->dim, + PARAM_CHECK_EQ(CARAFE_BACKWARD_API, input_desc->getDim(), carafe_desc->dimNb); + PARAM_CHECK_EQ(CARAFE_BACKWARD_API, mask_desc->getDim(), carafe_desc->dimNb); + PARAM_CHECK_EQ(CARAFE_BACKWARD_API, grad_output_desc->getDim(), carafe_desc->dimNb); - PARAM_CHECK_EQ(CARAFE_BACKWARD_API, grad_input_desc->dim, carafe_desc->dimNb); - PARAM_CHECK_EQ(CARAFE_BACKWARD_API, grad_mask_desc->dim, carafe_desc->dimNb); + PARAM_CHECK_EQ(CARAFE_BACKWARD_API, grad_input_desc->getDim(), carafe_desc->dimNb); + PARAM_CHECK_EQ(CARAFE_BACKWARD_API, grad_mask_desc->getDim(), carafe_desc->dimNb); VLOG(5) << CARAFE_BACKWARD_API << "dim check end."; /* * layout check */ if (carafe_desc->dimNb == 4) { - PARAM_CHECK_EQ(CARAFE_BACKWARD_API, input_desc->layout, MLUOP_LAYOUT_NHWC); - PARAM_CHECK_EQ(CARAFE_BACKWARD_API, mask_desc->layout, MLUOP_LAYOUT_NHWC); - PARAM_CHECK_EQ(CARAFE_BACKWARD_API, grad_output_desc->layout, + PARAM_CHECK_EQ(CARAFE_BACKWARD_API, input_desc->getLayout(), MLUOP_LAYOUT_NHWC); + PARAM_CHECK_EQ(CARAFE_BACKWARD_API, mask_desc->getLayout(), MLUOP_LAYOUT_NHWC); + PARAM_CHECK_EQ(CARAFE_BACKWARD_API, grad_output_desc->getLayout(), MLUOP_LAYOUT_NHWC); - PARAM_CHECK_EQ(CARAFE_BACKWARD_API, grad_input_desc->layout, + PARAM_CHECK_EQ(CARAFE_BACKWARD_API, grad_input_desc->getLayout(), MLUOP_LAYOUT_NHWC); - PARAM_CHECK_EQ(CARAFE_BACKWARD_API, grad_mask_desc->layout, + PARAM_CHECK_EQ(CARAFE_BACKWARD_API, grad_mask_desc->getLayout(), MLUOP_LAYOUT_NHWC); } VLOG(5) << CARAFE_BACKWARD_API << "layout check end."; @@ -641,36 +641,36 @@ mluOpStatus_t CarafeBackwardParamCheck( */ bool dtype_is_invalid = false; dtype_is_invalid = - dtype_is_invalid || (input_desc->dtype != MLUOP_DTYPE_HALF && - input_desc->dtype != MLUOP_DTYPE_FLOAT); + dtype_is_invalid || (input_desc->getDtype() != MLUOP_DTYPE_HALF && + input_desc->getDtype() != MLUOP_DTYPE_FLOAT); if (dtype_is_invalid) { LOG(ERROR) << CARAFE_BACKWARD_API << "the data type of input only support half and float"; return MLUOP_STATUS_BAD_PARAM; } dtype_is_invalid = - dtype_is_invalid || (input_desc->dtype != mask_desc->dtype); + dtype_is_invalid || (input_desc->getDtype() != mask_desc->getDtype()); dtype_is_invalid = - dtype_is_invalid || (input_desc->dtype != grad_output_desc->dtype); + dtype_is_invalid || (input_desc->getDtype() != grad_output_desc->getDtype()); dtype_is_invalid = - dtype_is_invalid || (input_desc->dtype != grad_input_desc->dtype); + dtype_is_invalid || (input_desc->getDtype() != grad_input_desc->getDtype()); dtype_is_invalid = - dtype_is_invalid || (input_desc->dtype != grad_mask_desc->dtype); + dtype_is_invalid || (input_desc->getDtype() != grad_mask_desc->getDtype()); if (dtype_is_invalid) { LOG(ERROR) << CARAFE_BACKWARD_API << "the data type of input, mask, grad_output, " "grad_input, grad_mask should be the same. " << "The data type of input is: " - << mluOpGetNameOfDataType(input_desc->dtype) << ", " + << mluOpGetNameOfDataType(input_desc->getDtype()) << ", " << "The data type of mask is: " - << mluOpGetNameOfDataType(mask_desc->dtype) << ", " + << mluOpGetNameOfDataType(mask_desc->getDtype()) << ", " << "The data type of grad output is: " - << mluOpGetNameOfDataType(grad_output_desc->dtype) << ", " + << mluOpGetNameOfDataType(grad_output_desc->getDtype()) << ", " << "The data type of grad input is: " - << mluOpGetNameOfDataType(grad_input_desc->dtype) << ", " + << mluOpGetNameOfDataType(grad_input_desc->getDtype()) << ", " << "The data type of grad mask is: " - << mluOpGetNameOfDataType(grad_mask_desc->dtype) << "."; + << mluOpGetNameOfDataType(grad_mask_desc->getDtype()) << "."; return MLUOP_STATUS_BAD_PARAM; } VLOG(5) << CARAFE_BACKWARD_API << "offchip data type check end."; @@ -820,7 +820,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpCarafeForward( CHECK_RETURN( "[mluOpCarafeForward]", KernelCarafeForward( - k_dim, k_type, handle->queue, input_desc->dtype, input, mask, output, + k_dim, k_type, handle->queue, input_desc->getDtype(), input, mask, output, input_dimN, input_dimH, input_dimW, input_dimC, kernel_size, group_size, scale_factor, block_dimH, block_dimW, block_dimG, block_dimC, grid_dimH, grid_dimW, grid_dimG, grid_dimC)); @@ -902,7 +902,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpCarafeBackward( << k_dim.x << ", " << k_dim.y << ", " << k_dim.z << ">>>"; CHECK_RETURN("[mluOpCarafeBackward]", (KernelCarafeBackward( - k_dim, k_type, handle->queue, input_desc->dtype, + k_dim, k_type, handle->queue, input_desc->getDtype(), (void *)input, (void *)mask, (void *)grad_output, grad_input, grad_mask, n, hi, wi, c, k_up, group, scale))); GEN_CASE_END(); diff --git a/kernels/deform_roi_pool/deform_roi_pool.cpp b/kernels/deform_roi_pool/deform_roi_pool.cpp index 1c1201306..c3e88a53d 100644 --- a/kernels/deform_roi_pool/deform_roi_pool.cpp +++ b/kernels/deform_roi_pool/deform_roi_pool.cpp @@ -39,9 +39,9 @@ void policyFunc(const mluOpHandle_t handle, mluop::runtime::getClusterLimitCapability(handle); const size_t core_limit = mluop::runtime::getCoreNumOfEachUnionCapability(handle); - const size_t num_rois = output_desc->dims[0]; - const size_t pooled_height = output_desc->dims[1]; - const size_t pooled_width = output_desc->dims[2]; + const size_t num_rois = output_desc->getDimIndex(0); + const size_t pooled_height = output_desc->getDimIndex(1); + const size_t pooled_width = output_desc->getDimIndex(2); const size_t num_bins = CEIL_ALIGN(num_rois * pooled_height * pooled_width, core_limit); k_dim->x = core_limit; @@ -58,9 +58,9 @@ static mluOpStatus_t DeformRoiPoolForwardPreCheck( const mluOpTensorDescriptor_t output_desc, const int pooled_height, const int pooled_width) { PARAM_CHECK("[mluOpDeformRoiPoolForward]", - input_desc->layout == MLUOP_LAYOUT_NHWC); + input_desc->getLayout() == MLUOP_LAYOUT_NHWC); PARAM_CHECK("[mluOpDeformRoiPoolForward]", - output_desc->layout == MLUOP_LAYOUT_NHWC); + output_desc->getLayout() == MLUOP_LAYOUT_NHWC); STRIDE_TENSOR_CHECK("[mluOpDeformRoiPoolForward]:", input_desc, "input_desc must be contiguous"); @@ -72,49 +72,49 @@ static mluOpStatus_t DeformRoiPoolForwardPreCheck( "output_desc must be contiguous"); PARAM_CHECK("[mluOpDeformRoiPoolForward]", - input_desc->dtype == MLUOP_DTYPE_FLOAT || - input_desc->dtype == MLUOP_DTYPE_HALF); + input_desc->getDtype() == MLUOP_DTYPE_FLOAT || + input_desc->getDtype() == MLUOP_DTYPE_HALF); PARAM_CHECK("[mluOpDeformRoiPoolForward]", - input_desc->dtype == rois_desc->dtype); + input_desc->getDtype() == rois_desc->getDtype()); PARAM_CHECK("[mluOpDeformRoiPoolForward]", - input_desc->dtype == output_desc->dtype); + input_desc->getDtype() == output_desc->getDtype()); - PARAM_CHECK("[mluOpDeformRoiPoolForward]", rois_desc->dim == 2); - PARAM_CHECK("[mluOpDeformRoiPoolForward]", rois_desc->dims[1] == 5); + PARAM_CHECK("[mluOpDeformRoiPoolForward]", rois_desc->getDim() == 2); + PARAM_CHECK("[mluOpDeformRoiPoolForward]", rois_desc->getDimIndex(1) == 5); PARAM_CHECK("[mluOpDeformRoiPoolForward]", pooled_height > 0); PARAM_CHECK("[mluOpDeformRoiPoolForward]", pooled_width > 0); PARAM_CHECK("[mluOpDeformRoiPoolForward]", - output_desc->dims[1] == pooled_height); + output_desc->getDimIndex(1) == pooled_height); PARAM_CHECK("[mluOpDeformRoiPoolForward]", - output_desc->dims[2] == pooled_width); + output_desc->getDimIndex(2) == pooled_width); if (offset_desc != NULL) { PARAM_CHECK("[mluOpDeformRoiPoolForward]", - offset_desc->dtype == input_desc->dtype); - PARAM_CHECK("[mluOpDeformRoiPoolForward]", offset_desc->dim == 4); + offset_desc->getDtype() == input_desc->getDtype()); + PARAM_CHECK("[mluOpDeformRoiPoolForward]", offset_desc->getDim() == 4); PARAM_CHECK("[mluOpDeformRoiPoolForward]", - offset_desc->dims[0] == rois_desc->dims[0]); - PARAM_CHECK("[mluOpDeformRoiPoolForward]", offset_desc->dims[1] == 2); + offset_desc->getDimIndex(0) == rois_desc->getDimIndex(0)); + PARAM_CHECK("[mluOpDeformRoiPoolForward]", offset_desc->getDimIndex(1) == 2); PARAM_CHECK("[mluOpDeformRoiPoolForward]", - offset_desc->dims[2] == pooled_height); + offset_desc->getDimIndex(2) == pooled_height); PARAM_CHECK("[mluOpDeformRoiPoolForward]", - offset_desc->dims[3] == pooled_width); + offset_desc->getDimIndex(3) == pooled_width); const size_t offset_element_num = mluOpGetTensorElementNum(offset_desc); TENSOR_NUM_CHECK("[mluOpDeformRoiPoolForward]", offset_element_num, LARGE_TENSOR_NUM, ""); } - if (rois_desc->dims[0] != output_desc->dims[0]) { + if (rois_desc->getDimIndex(0) != output_desc->getDimIndex(0)) { LOG(ERROR) << "[mluOpDeformRoiPoolForward] rois number = " - << rois_desc->dims[0] - << ", output batch = " << output_desc->dims[0] + << rois_desc->getDimIndex(0) + << ", output batch = " << output_desc->getDimIndex(0) << ", they should be equal."; return MLUOP_STATUS_BAD_PARAM; } - if (input_desc->dims[3] != output_desc->dims[3]) { + if (input_desc->getDimIndex(3) != output_desc->getDimIndex(3)) { LOG(ERROR) << "[mluOpDeformRoiPoolForward] input channel = " - << input_desc->dims[3] - << ", output channel = " << output_desc->dims[3] + << input_desc->getDimIndex(3) + << ", output channel = " << output_desc->getDimIndex(3) << ", they should be equal."; return MLUOP_STATUS_BAD_PARAM; } @@ -139,11 +139,11 @@ static mluOpStatus_t DeformRoiPoolBackwardPreCheck( const mluOpTensorDescriptor_t grad_offset_desc, const int pooled_height, const int pooled_width) { PARAM_CHECK("[mluOpDeformRoiPoolBackward]", - grad_output_desc->layout == MLUOP_LAYOUT_NHWC); + grad_output_desc->getLayout() == MLUOP_LAYOUT_NHWC); PARAM_CHECK("[mluOpDeformRoiPoolBackward]", - input_desc->layout == MLUOP_LAYOUT_NHWC); + input_desc->getLayout() == MLUOP_LAYOUT_NHWC); PARAM_CHECK("[mluOpDeformRoiPoolBackward]", - grad_input_desc->layout == MLUOP_LAYOUT_NHWC); + grad_input_desc->getLayout() == MLUOP_LAYOUT_NHWC); STRIDE_TENSOR_CHECK("[mluOpDeformRoiPoolBackward]:", input_desc, "input_desc must be contiguous"); @@ -159,33 +159,33 @@ static mluOpStatus_t DeformRoiPoolBackwardPreCheck( "grad_offset_desc must be contiguous"); PARAM_CHECK("[mluOpDeformRoiPoolBackward]", - input_desc->dtype == MLUOP_DTYPE_FLOAT || - input_desc->dtype == MLUOP_DTYPE_HALF); + input_desc->getDtype() == MLUOP_DTYPE_FLOAT || + input_desc->getDtype() == MLUOP_DTYPE_HALF); PARAM_CHECK("[mluOpDeformRoiPoolBackward]", - input_desc->dtype == grad_output_desc->dtype); + input_desc->getDtype() == grad_output_desc->getDtype()); PARAM_CHECK("[mluOpDeformRoiPoolBackward]", - input_desc->dtype == rois_desc->dtype); + input_desc->getDtype() == rois_desc->getDtype()); PARAM_CHECK("[mluOpDeformRoiPoolBackward]", - input_desc->dtype == grad_input_desc->dtype); + input_desc->getDtype() == grad_input_desc->getDtype()); - PARAM_CHECK("[mluOpDeformRoiPoolBackward]", rois_desc->dim == 2); - PARAM_CHECK("[mluOpDeformRoiPoolBackward]", rois_desc->dims[1] == 5); + PARAM_CHECK("[mluOpDeformRoiPoolBackward]", rois_desc->getDim() == 2); + PARAM_CHECK("[mluOpDeformRoiPoolBackward]", rois_desc->getDimIndex(1) == 5); PARAM_CHECK("[mluOpDeformRoiPoolBackward]", pooled_height > 0); PARAM_CHECK("[mluOpDeformRoiPoolBackward]", pooled_width > 0); PARAM_CHECK("[mluOpDeformRoiPoolBackward]", - grad_output_desc->dims[1] == pooled_height); + grad_output_desc->getDimIndex(1) == pooled_height); PARAM_CHECK("[mluOpDeformRoiPoolBackward]", - grad_output_desc->dims[2] == pooled_width); + grad_output_desc->getDimIndex(2) == pooled_width); - for (int i = 0; i < input_desc->dim; ++i) { - if (input_desc->dims[i] != grad_input_desc->dims[i]) { + for (int i = 0; i < input_desc->getDim(); ++i) { + if (input_desc->getDimIndex(i) != grad_input_desc->getDimIndex(i)) { LOG(ERROR) << "[mluOpDeformRoiPoolBackward] input's shape is [" - << input_desc->dims[0] << " " << input_desc->dims[1] << " " - << input_desc->dims[2] << " " << input_desc->dims[3] - << "], grad_input's shape is [" << grad_input_desc->dims[0] - << " " << grad_input_desc->dims[1] << " " - << grad_input_desc->dims[2] << " " << grad_input_desc->dims[3] + << input_desc->getDimIndex(0) << " " << input_desc->getDimIndex(1) << " " + << input_desc->getDimIndex(2) << " " << input_desc->getDimIndex(3) + << "], grad_input's shape is [" << grad_input_desc->getDimIndex(0) + << " " << grad_input_desc->getDimIndex(1) << " " + << grad_input_desc->getDimIndex(2) << " " << grad_input_desc->getDimIndex(3) << "]. They should be the same."; return MLUOP_STATUS_BAD_PARAM; } @@ -226,25 +226,25 @@ static mluOpStatus_t DeformRoiPoolBackwardPreCheck( return MLUOP_STATUS_BAD_PARAM; } PARAM_CHECK("[mluOpDeformRoiPoolBackward]", - offset_desc->dtype == input_desc->dtype); - PARAM_CHECK("[mluOpDeformRoiPoolBackward]", offset_desc->dim == 4); + offset_desc->getDtype() == input_desc->getDtype()); + PARAM_CHECK("[mluOpDeformRoiPoolBackward]", offset_desc->getDim() == 4); PARAM_CHECK("[mluOpDeformRoiPoolBackward]", - offset_desc->dims[0] == rois_desc->dims[0]); - PARAM_CHECK("[mluOpDeformRoiPoolBackward]", offset_desc->dims[1] == 2); + offset_desc->getDimIndex(0) == rois_desc->getDimIndex(0)); + PARAM_CHECK("[mluOpDeformRoiPoolBackward]", offset_desc->getDimIndex(1) == 2); PARAM_CHECK("[mluOpDeformRoiPoolBackward]", - offset_desc->dims[2] == pooled_height); + offset_desc->getDimIndex(2) == pooled_height); PARAM_CHECK("[mluOpDeformRoiPoolBackward]", - offset_desc->dims[3] == pooled_width); + offset_desc->getDimIndex(3) == pooled_width); PARAM_CHECK("[mluOpDeformRoiPoolBackward]", - grad_offset_desc->dtype == input_desc->dtype); - PARAM_CHECK("[mluOpDeformRoiPoolBackward]", grad_offset_desc->dim == 4); + grad_offset_desc->getDtype() == input_desc->getDtype()); + PARAM_CHECK("[mluOpDeformRoiPoolBackward]", grad_offset_desc->getDim() == 4); PARAM_CHECK("[mluOpDeformRoiPoolBackward]", - grad_offset_desc->dims[0] == rois_desc->dims[0]); - PARAM_CHECK("[mluOpDeformRoiPoolBackward]", grad_offset_desc->dims[1] == 2); + grad_offset_desc->getDimIndex(0) == rois_desc->getDimIndex(0)); + PARAM_CHECK("[mluOpDeformRoiPoolBackward]", grad_offset_desc->getDimIndex(1) == 2); PARAM_CHECK("[mluOpDeformRoiPoolBackward]", - grad_offset_desc->dims[2] == pooled_height); + grad_offset_desc->getDimIndex(2) == pooled_height); PARAM_CHECK("[mluOpDeformRoiPoolBackward]", - grad_offset_desc->dims[3] == pooled_width); + grad_offset_desc->getDimIndex(3) == pooled_width); const size_t offset_element_num = mluOpGetTensorElementNum(offset_desc); const size_t grad_offset_element_num = mluOpGetTensorElementNum(grad_offset_desc); @@ -259,17 +259,17 @@ static mluOpStatus_t DeformRoiPoolBackwardPreCheck( return MLUOP_STATUS_BAD_PARAM; } } - if (rois_desc->dims[0] != grad_output_desc->dims[0]) { + if (rois_desc->getDimIndex(0) != grad_output_desc->getDimIndex(0)) { LOG(ERROR) << "[mluOpDeformRoiPoolBackward] rois number = " - << rois_desc->dims[0] - << ", grad_output batch = " << grad_output_desc->dims[0] + << rois_desc->getDimIndex(0) + << ", grad_output batch = " << grad_output_desc->getDimIndex(0) << ", they should be equal."; return MLUOP_STATUS_BAD_PARAM; } - if (input_desc->dims[3] != grad_output_desc->dims[3]) { + if (input_desc->getDimIndex(3) != grad_output_desc->getDimIndex(3)) { LOG(ERROR) << "[mluOpDeformRoiPoolBackward] input channel = " - << input_desc->dims[3] - << ", output channel = " << grad_output_desc->dims[3] + << input_desc->getDimIndex(3) + << ", output channel = " << grad_output_desc->getDimIndex(3) << ", they should be equal."; return MLUOP_STATUS_BAD_PARAM; } @@ -321,7 +321,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpDeformRoiPoolForward( "offset is NULL."; return MLUOP_STATUS_BAD_PARAM; } - if (input_desc->dims[0] == 0 || mluOpGetTensorElementNum(rois_desc) == 0 || + if (input_desc->getDimIndex(0) == 0 || mluOpGetTensorElementNum(rois_desc) == 0 || mluOpGetTensorElementNum(output_desc) == 0) { LOG(ERROR) << "[mluOpDeformRoiPoolForward] Zero element tensor failure"; return MLUOP_STATUS_BAD_PARAM; @@ -363,12 +363,12 @@ mluOpStatus_t MLUOP_WIN_API mluOpDeformRoiPoolForward( policyFunc(handle, output_desc, &k_dim, &k_type); - const int batches = input_desc->dims[0]; - const int height = input_desc->dims[1]; - const int width = input_desc->dims[2]; - const int channels = input_desc->dims[3]; - const int num_rois = output_desc->dims[0]; - mluOpDataType_t data_dtype = input_desc->dtype; + const int batches = input_desc->getDimIndex(0); + const int height = input_desc->getDimIndex(1); + const int width = input_desc->getDimIndex(2); + const int channels = input_desc->getDimIndex(3); + const int num_rois = output_desc->getDimIndex(0); + mluOpDataType_t data_dtype = input_desc->getDtype(); VLOG(5) << "[mluOpDeformRoiPoolForward] Launch kernel policyFunc[" << k_dim.x << ", " << k_dim.y << ", " << k_dim.z << "]."; CHECK_RETURN( @@ -407,7 +407,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpDeformRoiPoolBackward( } if (mluOpGetTensorElementNum(grad_output_desc) == 0 || - input_desc->dims[0] == 0 || mluOpGetTensorElementNum(rois_desc) == 0) { + input_desc->getDimIndex(0) == 0 || mluOpGetTensorElementNum(rois_desc) == 0) { LOG(ERROR) << "[mluOpDeformRoiPoolBackward] Zero element tensor failure"; return MLUOP_STATUS_BAD_PARAM; } @@ -473,12 +473,12 @@ mluOpStatus_t MLUOP_WIN_API mluOpDeformRoiPoolBackward( policyFunc(handle, grad_output_desc, &k_dim, &k_type); - const int batches = input_desc->dims[0]; - const int height = input_desc->dims[1]; - const int width = input_desc->dims[2]; - const int channels = input_desc->dims[3]; - const int num_rois = rois_desc->dims[0]; - mluOpDataType_t data_dtype = input_desc->dtype; + const int batches = input_desc->getDimIndex(0); + const int height = input_desc->getDimIndex(1); + const int width = input_desc->getDimIndex(2); + const int channels = input_desc->getDimIndex(3); + const int num_rois = rois_desc->getDimIndex(0); + mluOpDataType_t data_dtype = input_desc->getDtype(); VLOG(5) << "[mluOpDeformRoiPoolBackward] Launch kernel policyFunc[" << k_dim.x << ", " << k_dim.y << ", " << k_dim.z << "]."; CHECK_RETURN("[mluOpDeformRoiPoolBackward]", diff --git a/kernels/diff_iou_rotated_sort_vertices_forward/diff_iou_rotated_sort_vertices_forward.cpp b/kernels/diff_iou_rotated_sort_vertices_forward/diff_iou_rotated_sort_vertices_forward.cpp index 1f669d49a..ddd66975c 100644 --- a/kernels/diff_iou_rotated_sort_vertices_forward/diff_iou_rotated_sort_vertices_forward.cpp +++ b/kernels/diff_iou_rotated_sort_vertices_forward/diff_iou_rotated_sort_vertices_forward.cpp @@ -66,10 +66,10 @@ static mluOpStatus_t diffIouRotatedSortVerticesForwardParamCheck( PARAM_CHECK(op_name, idx_desc != NULL); // check shape - PARAM_CHECK(op_name, vertices_desc->dim == 4); - PARAM_CHECK(op_name, mask_desc->dim == 3); - PARAM_CHECK(op_name, num_valid_desc->dim == 2); - PARAM_CHECK(op_name, idx_desc->dim == 3); + PARAM_CHECK(op_name, vertices_desc->getDim() == 4); + PARAM_CHECK(op_name, mask_desc->getDim() == 3); + PARAM_CHECK(op_name, num_valid_desc->getDim() == 2); + PARAM_CHECK(op_name, idx_desc->getDim() == 3); // check stride STRIDE_TENSOR_CHECK(op_name + ":", vertices_desc, @@ -81,47 +81,47 @@ static mluOpStatus_t diffIouRotatedSortVerticesForwardParamCheck( // check data type // check tensor datatype, support float32 - PARAM_CHECK_V2(op_name, (vertices_desc->dtype == MLUOP_DTYPE_FLOAT), + PARAM_CHECK_V2(op_name, (vertices_desc->getDtype() == MLUOP_DTYPE_FLOAT), "Only float are supported in vertices tensor, but the " "data type of tensor is " - << mluOpGetNameOfDataType(vertices_desc->dtype) << "."); + << mluOpGetNameOfDataType(vertices_desc->getDtype()) << "."); - PARAM_CHECK_V2(op_name, (mask_desc->dtype == MLUOP_DTYPE_BOOL), + PARAM_CHECK_V2(op_name, (mask_desc->getDtype() == MLUOP_DTYPE_BOOL), "Only bool are supported in mask tensor, but the data " "type of tensor is " - << mluOpGetNameOfDataType(mask_desc->dtype) << "."); + << mluOpGetNameOfDataType(mask_desc->getDtype()) << "."); - PARAM_CHECK_V2(op_name, (num_valid_desc->dtype == MLUOP_DTYPE_INT32), + PARAM_CHECK_V2(op_name, (num_valid_desc->getDtype() == MLUOP_DTYPE_INT32), "Only int32 are supported in num_valid tensor, but the data " "type of tensor is " - << mluOpGetNameOfDataType(num_valid_desc->dtype) << "."); + << mluOpGetNameOfDataType(num_valid_desc->getDtype()) << "."); - PARAM_CHECK_V2(op_name, (idx_desc->dtype == MLUOP_DTYPE_INT32), + PARAM_CHECK_V2(op_name, (idx_desc->getDtype() == MLUOP_DTYPE_INT32), "Only int32 are supported in idx tensor, but the data " "type of tensor is " - << mluOpGetNameOfDataType(idx_desc->dtype) << "."); + << mluOpGetNameOfDataType(idx_desc->getDtype()) << "."); // check dim - // int dim_b = vertices_desc->dims[0]; - // int dim_n = vertices_desc->dims[1]; - // int dim_m = vertices_desc->dims[2]; - PARAM_CHECK(op_name, (vertices_desc->dims[0] == mask_desc->dims[0])); - PARAM_CHECK(op_name, (vertices_desc->dims[0] == num_valid_desc->dims[0])); - PARAM_CHECK(op_name, (vertices_desc->dims[0] == idx_desc->dims[0])); - PARAM_CHECK(op_name, (vertices_desc->dims[1] == mask_desc->dims[1])); - PARAM_CHECK(op_name, (vertices_desc->dims[1] == num_valid_desc->dims[1])); - PARAM_CHECK(op_name, (vertices_desc->dims[1] == idx_desc->dims[1])); - PARAM_CHECK(op_name, (vertices_desc->dims[2] == mask_desc->dims[2])); + // int dim_b = vertices_desc->getDimIndex(0); + // int dim_n = vertices_desc->getDimIndex(1); + // int dim_m = vertices_desc->getDimIndex(2); + PARAM_CHECK(op_name, (vertices_desc->getDimIndex(0) == mask_desc->getDimIndex(0))); + PARAM_CHECK(op_name, (vertices_desc->getDimIndex(0) == num_valid_desc->getDimIndex(0))); + PARAM_CHECK(op_name, (vertices_desc->getDimIndex(0) == idx_desc->getDimIndex(0))); + PARAM_CHECK(op_name, (vertices_desc->getDimIndex(1) == mask_desc->getDimIndex(1))); + PARAM_CHECK(op_name, (vertices_desc->getDimIndex(1) == num_valid_desc->getDimIndex(1))); + PARAM_CHECK(op_name, (vertices_desc->getDimIndex(1) == idx_desc->getDimIndex(1))); + PARAM_CHECK(op_name, (vertices_desc->getDimIndex(2) == mask_desc->getDimIndex(2))); PARAM_CHECK_V2( - op_name, (vertices_desc->dims[2] == 24), + op_name, (vertices_desc->getDimIndex(2) == 24), "vertices and mask tensors dims[2] should be 24, but the input value is " - << vertices_desc->dims[2] << "."); - PARAM_CHECK_V2(op_name, (vertices_desc->dims[3] == 2), + << vertices_desc->getDimIndex(2) << "."); + PARAM_CHECK_V2(op_name, (vertices_desc->getDimIndex(3) == 2), "vertices tensor dims[3] should be 2, but the input value is " - << vertices_desc->dims[3] << "."); - PARAM_CHECK_V2(op_name, (idx_desc->dims[2] == 9), + << vertices_desc->getDimIndex(3) << "."); + PARAM_CHECK_V2(op_name, (idx_desc->getDimIndex(2) == 9), "idx tensor dims[2] should be 9, but the input value is " - << idx_desc->dims[2] << "."); + << idx_desc->getDimIndex(2) << "."); const size_t vertices_element_num = mluOpGetTensorElementNum(vertices_desc); const size_t mask_element_num = mluOpGetTensorElementNum(mask_desc); @@ -136,7 +136,7 @@ static mluOpStatus_t diffIouRotatedSortVerticesForwardParamCheck( // check element num zero if (vertices_element_num == 0) { - if (vertices_desc->dims[1] == 0) { + if (vertices_desc->getDimIndex(1) == 0) { *zero_element = true; return MLUOP_STATUS_SUCCESS; } else { @@ -187,9 +187,9 @@ mluOpStatus_t MLUOP_WIN_API mluOpDiffIouRotatedSortVerticesForward( GEN_CASE_TEST_PARAM_NEW(false, false, true, 0, 0, 0); } - const int dim_b = vertices_desc->dims[0]; - const int dim_n = vertices_desc->dims[1]; - const int dim_m = vertices_desc->dims[2]; + const int dim_b = vertices_desc->getDimIndex(0); + const int dim_n = vertices_desc->getDimIndex(1); + const int dim_m = vertices_desc->getDimIndex(2); const int bn_num = dim_b * dim_n; cnrtDim3_t k_dim; cnrtFunctionType_t k_type; diff --git a/kernels/div/div.cpp b/kernels/div/div.cpp index 6f9cf773c..16a33910d 100644 --- a/kernels/div/div.cpp +++ b/kernels/div/div.cpp @@ -77,12 +77,12 @@ mluOpDiv(mluOpHandle_t handle, const mluOpComputationPreference_t prefer, if (handle->arch == MLUOP_MLU370) { CHECK_RETURN("mluOpDiv", Kernel3StagePipelineDiv(k_dim, k_type, handle->queue, - x_desc->dtype, prefer, (void *)x, + x_desc->getDtype(), prefer, (void *)x, (void *)y, (void *)z, element_num)); } else { CHECK_RETURN("mluOpDiv", Kernel5StagePipelineDiv(k_dim, k_type, handle->queue, - x_desc->dtype, prefer, (void *)x, + x_desc->getDtype(), prefer, (void *)x, (void *)y, (void *)z, element_num)); } GEN_CASE_END(); diff --git a/kernels/dynamic_point_to_voxel/dynamic_point_to_voxel_backward/dynamic_point_to_voxel_backward.cpp b/kernels/dynamic_point_to_voxel/dynamic_point_to_voxel_backward/dynamic_point_to_voxel_backward.cpp index da589c8ba..40691120b 100644 --- a/kernels/dynamic_point_to_voxel/dynamic_point_to_voxel_backward/dynamic_point_to_voxel_backward.cpp +++ b/kernels/dynamic_point_to_voxel/dynamic_point_to_voxel_backward/dynamic_point_to_voxel_backward.cpp @@ -86,41 +86,41 @@ static mluOpStatus_t DynamicPointToVoxelBackwardParamCheck( // check data type PARAM_CHECK(interface_name, - grad_voxel_feats_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(interface_name, feats_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(interface_name, voxel_feats_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(interface_name, grad_feats_desc->dtype == MLUOP_DTYPE_FLOAT); + grad_voxel_feats_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(interface_name, feats_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(interface_name, voxel_feats_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(interface_name, grad_feats_desc->getDtype() == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(interface_name, point2voxel_map_desc->dtype == MLUOP_DTYPE_INT32); + PARAM_CHECK(interface_name, point2voxel_map_desc->getDtype() == MLUOP_DTYPE_INT32); PARAM_CHECK(interface_name, - voxel_points_count_desc->dtype == MLUOP_DTYPE_INT32); - PARAM_CHECK(interface_name, voxel_num_desc->dtype == MLUOP_DTYPE_INT32); + voxel_points_count_desc->getDtype() == MLUOP_DTYPE_INT32); + PARAM_CHECK(interface_name, voxel_num_desc->getDtype() == MLUOP_DTYPE_INT32); // check shape - PARAM_CHECK(interface_name, grad_voxel_feats_desc->dim == 2); - PARAM_CHECK(interface_name, feats_desc->dim == 2); - PARAM_CHECK(interface_name, voxel_feats_desc->dim == 2); - PARAM_CHECK(interface_name, point2voxel_map_desc->dim == 1); - PARAM_CHECK(interface_name, voxel_points_count_desc->dim == 1); - PARAM_CHECK(interface_name, voxel_num_desc->dim == 1); - PARAM_CHECK(interface_name, grad_feats_desc->dim == 2); + PARAM_CHECK(interface_name, grad_voxel_feats_desc->getDim() == 2); + PARAM_CHECK(interface_name, feats_desc->getDim() == 2); + PARAM_CHECK(interface_name, voxel_feats_desc->getDim() == 2); + PARAM_CHECK(interface_name, point2voxel_map_desc->getDim() == 1); + PARAM_CHECK(interface_name, voxel_points_count_desc->getDim() == 1); + PARAM_CHECK(interface_name, voxel_num_desc->getDim() == 1); + PARAM_CHECK(interface_name, grad_feats_desc->getDim() == 2); PARAM_CHECK(interface_name, - feats_desc->dims[1] == grad_voxel_feats_desc->dims[1]); + feats_desc->getDimIndex(1) == grad_voxel_feats_desc->getDimIndex(1)); PARAM_CHECK(interface_name, - voxel_feats_desc->dims[0] == grad_voxel_feats_desc->dims[0]); + voxel_feats_desc->getDimIndex(0) == grad_voxel_feats_desc->getDimIndex(0)); PARAM_CHECK(interface_name, - voxel_feats_desc->dims[1] == grad_voxel_feats_desc->dims[1]); + voxel_feats_desc->getDimIndex(1) == grad_voxel_feats_desc->getDimIndex(1)); PARAM_CHECK(interface_name, - point2voxel_map_desc->dims[0] == feats_desc->dims[0]); - PARAM_CHECK(interface_name, voxel_points_count_desc->dims[0] == - grad_voxel_feats_desc->dims[0]); - PARAM_CHECK(interface_name, voxel_num_desc->dims[0] == 1); - PARAM_CHECK(interface_name, grad_feats_desc->dims[0] == feats_desc->dims[0]); + point2voxel_map_desc->getDimIndex(0) == feats_desc->getDimIndex(0)); + PARAM_CHECK(interface_name, voxel_points_count_desc->getDimIndex(0) == + grad_voxel_feats_desc->getDimIndex(0)); + PARAM_CHECK(interface_name, voxel_num_desc->getDimIndex(0) == 1); + PARAM_CHECK(interface_name, grad_feats_desc->getDimIndex(0) == feats_desc->getDimIndex(0)); PARAM_CHECK(interface_name, - grad_feats_desc->dims[1] == grad_voxel_feats_desc->dims[1]); + grad_feats_desc->getDimIndex(1) == grad_voxel_feats_desc->getDimIndex(1)); PARAM_CHECK(interface_name, - feats_desc->dims[0] >= grad_voxel_feats_desc->dims[0]); + feats_desc->getDimIndex(0) >= grad_voxel_feats_desc->getDimIndex(0)); // param check if (reduce_type != MLUOP_REDUCE_DMAX) { @@ -138,11 +138,11 @@ static mluOpStatus_t DynamicPointToVoxelBackwardParamCheck( TENSOR_NUM_CHECK(interface_name, feats_element_num, LARGE_TENSOR_NUM, ""); // kernel size check - const int N = feats_desc->dims[0]; - const int C = feats_desc->dims[1]; - const size_t dtype_bytes = mluop::getSizeOfDataType(feats_desc->dtype); + const int N = feats_desc->getDimIndex(0); + const int C = feats_desc->getDimIndex(1); + const size_t dtype_bytes = mluop::getSizeOfDataType(feats_desc->getDtype()); const size_t idx_dtype_bytes = - mluop::getSizeOfDataType(point2voxel_map_desc->dtype); + mluop::getSizeOfDataType(point2voxel_map_desc->getDtype()); if (N * (idx_dtype_bytes + 1) + C * (2 * dtype_bytes + 3 * idx_dtype_bytes) + idx_dtype_bytes > handle->nram_size) { @@ -153,7 +153,7 @@ static mluOpStatus_t DynamicPointToVoxelBackwardParamCheck( "shape is [" << N << ", " << C << "]" << ", should meet constraint : " - "5*feats_desc->dims[0]+20*feats_desc->dims[1]+sizeof(int) <= " + "5*feats_desc->getDimIndex(0)+20*feats_desc->getDimIndex(1)+sizeof(int) <= " << handle->nram_size; return MLUOP_STATUS_BAD_PARAM; } @@ -266,8 +266,8 @@ mluOpStatus_t MLUOP_WIN_API mluOpDynamicPointToVoxelBackward( GEN_CASE_TEST_PARAM_NEW(false, false, true, 0.003, 0.003, 0); } - const int N = feats_desc->dims[0]; - const int C = feats_desc->dims[1]; + const int N = feats_desc->getDimIndex(0); + const int C = feats_desc->getDimIndex(1); const auto grad_voxel_feats_element_num = mluOpGetTensorElementNum(grad_voxel_feats_desc); const auto grad_feats_element_num = mluOpGetTensorElementNum(grad_feats_desc); @@ -376,8 +376,8 @@ mluOpStatus_t MLUOP_WIN_API mluOpGetDynamicPointToVoxelBackwardWorkspaceSize( PARAM_CHECK(interface_name, voxel_points_count_desc != NULL); PARAM_CHECK(interface_name, voxel_num_desc != NULL); PARAM_CHECK(interface_name, workspace_size != NULL); - const int N = feats_desc->dims[0]; - const int C = feats_desc->dims[1]; + const int N = feats_desc->getDimIndex(0); + const int C = feats_desc->getDimIndex(1); *workspace_size = N * C * sizeof(int); return MLUOP_STATUS_SUCCESS; } diff --git a/kernels/dynamic_point_to_voxel/dynamic_point_to_voxel_forward/dynamic_point_to_voxel_forward.cpp b/kernels/dynamic_point_to_voxel/dynamic_point_to_voxel_forward/dynamic_point_to_voxel_forward.cpp index 4c8fcc9ef..4a1ae7a27 100644 --- a/kernels/dynamic_point_to_voxel/dynamic_point_to_voxel_forward/dynamic_point_to_voxel_forward.cpp +++ b/kernels/dynamic_point_to_voxel/dynamic_point_to_voxel_forward/dynamic_point_to_voxel_forward.cpp @@ -97,13 +97,13 @@ static mluOpStatus_t DynamicPointToVoxelForwardParamCheck( PARAM_CHECK(api, voxel_points_count_desc != NULL); PARAM_CHECK(api, voxel_num_desc != NULL); // check shape - PARAM_CHECK(api, feats_desc->dim == 2); - PARAM_CHECK(api, coors_desc->dim == 2); - PARAM_CHECK(api, voxel_feats_desc->dim == 2); - PARAM_CHECK(api, voxel_coors_desc->dim == 2); - PARAM_CHECK(api, point2voxel_map_desc->dim == 1); - PARAM_CHECK(api, voxel_points_count_desc->dim == 1); - PARAM_CHECK(api, voxel_num_desc->dim == 1); + PARAM_CHECK(api, feats_desc->getDim() == 2); + PARAM_CHECK(api, coors_desc->getDim() == 2); + PARAM_CHECK(api, voxel_feats_desc->getDim() == 2); + PARAM_CHECK(api, voxel_coors_desc->getDim() == 2); + PARAM_CHECK(api, point2voxel_map_desc->getDim() == 1); + PARAM_CHECK(api, voxel_points_count_desc->getDim() == 1); + PARAM_CHECK(api, voxel_num_desc->getDim() == 1); // check stride STRIDE_TENSOR_CHECK(api + ":", feats_desc, "feats_desc must be contiguous"); STRIDE_TENSOR_CHECK(api + ":", coors_desc, "coors_desc must be contiguous"); @@ -118,25 +118,25 @@ static mluOpStatus_t DynamicPointToVoxelForwardParamCheck( STRIDE_TENSOR_CHECK(api + ":", voxel_num_desc, "voxel_num_desc must be contiguous"); // check data type - PARAM_CHECK_V2(api, (feats_desc->dtype == MLUOP_DTYPE_FLOAT), + PARAM_CHECK_V2(api, (feats_desc->getDtype() == MLUOP_DTYPE_FLOAT), "Only float are supported in feats tensor, but the data " "type of tensor is " - << mluOpGetNameOfDataType(feats_desc->dtype) << "."); - PARAM_CHECK_V2(api, (coors_desc->dtype == MLUOP_DTYPE_INT32), + << mluOpGetNameOfDataType(feats_desc->getDtype()) << "."); + PARAM_CHECK_V2(api, (coors_desc->getDtype() == MLUOP_DTYPE_INT32), "Only int32 are supported in coors tensor, but the data " "type of tensor is " - << mluOpGetNameOfDataType(coors_desc->dtype) << "."); + << mluOpGetNameOfDataType(coors_desc->getDtype()) << "."); PARAM_CHECK_V2( - api, (point2voxel_map_desc->dtype == MLUOP_DTYPE_INT32), + api, (point2voxel_map_desc->getDtype() == MLUOP_DTYPE_INT32), "Only int32 are supported in point2voxel_map tensor, but the data " "type of tensor is " - << mluOpGetNameOfDataType(point2voxel_map_desc->dtype) << "."); + << mluOpGetNameOfDataType(point2voxel_map_desc->getDtype()) << "."); - PARAM_CHECK(api, voxel_feats_desc->dtype == feats_desc->dtype); - PARAM_CHECK(api, voxel_coors_desc->dtype == coors_desc->dtype); + PARAM_CHECK(api, voxel_feats_desc->getDtype() == feats_desc->getDtype()); + PARAM_CHECK(api, voxel_coors_desc->getDtype() == coors_desc->getDtype()); PARAM_CHECK(api, - voxel_points_count_desc->dtype == point2voxel_map_desc->dtype); - PARAM_CHECK(api, voxel_num_desc->dtype == point2voxel_map_desc->dtype); + voxel_points_count_desc->getDtype() == point2voxel_map_desc->getDtype()); + PARAM_CHECK(api, voxel_num_desc->getDtype() == point2voxel_map_desc->getDtype()); if (reduce_type != MLUOP_REDUCE_DMAX && reduce_type != MLUOP_REDUCE_DMEAN) { LOG(ERROR) << api << "Only support max and mean. " @@ -145,16 +145,16 @@ static mluOpStatus_t DynamicPointToVoxelForwardParamCheck( } // check dim - PARAM_CHECK(api, feats_desc->dims[0] == coors_desc->dims[0]); - PARAM_CHECK(api, feats_desc->dims[0] == point2voxel_map_desc->dims[0]); - PARAM_CHECK(api, voxel_feats_desc->dims[0] == voxel_coors_desc->dims[0]); + PARAM_CHECK(api, feats_desc->getDimIndex(0) == coors_desc->getDimIndex(0)); + PARAM_CHECK(api, feats_desc->getDimIndex(0) == point2voxel_map_desc->getDimIndex(0)); + PARAM_CHECK(api, voxel_feats_desc->getDimIndex(0) == voxel_coors_desc->getDimIndex(0)); PARAM_CHECK(api, - voxel_feats_desc->dims[0] == voxel_points_count_desc->dims[0]); - PARAM_CHECK(api, voxel_num_desc->dims[0] == 1); - PARAM_CHECK(api, feats_desc->dims[1] == voxel_feats_desc->dims[1]); - PARAM_CHECK(api, coors_desc->dims[1] == voxel_coors_desc->dims[1]); - PARAM_CHECK(api, coors_desc->dims[1] == 3); - PARAM_CHECK(api, feats_desc->dims[0] >= voxel_feats_desc->dims[0]); + voxel_feats_desc->getDimIndex(0) == voxel_points_count_desc->getDimIndex(0)); + PARAM_CHECK(api, voxel_num_desc->getDimIndex(0) == 1); + PARAM_CHECK(api, feats_desc->getDimIndex(1) == voxel_feats_desc->getDimIndex(1)); + PARAM_CHECK(api, coors_desc->getDimIndex(1) == voxel_coors_desc->getDimIndex(1)); + PARAM_CHECK(api, coors_desc->getDimIndex(1) == 3); + PARAM_CHECK(api, feats_desc->getDimIndex(0) >= voxel_feats_desc->getDimIndex(0)); // check large tensor const size_t feats_element_num = mluOpGetTensorElementNum(feats_desc); @@ -273,8 +273,8 @@ mluOpStatus_t MLUOP_WIN_API mluOpDynamicPointToVoxelForward( GEN_CASE_TEST_PARAM_NEW(true, true, false, 0.003, 0.003, 0); } - const int num_points = feats_desc->dims[0]; - const int num_feats = feats_desc->dims[1]; + const int num_points = feats_desc->getDimIndex(0); + const int num_feats = feats_desc->getDimIndex(1); cnrtDim3_t k_dim; cnrtFunctionType_t k_type; policyFuncDynamicPointToVoxelForward(handle, &k_dim, &k_type, num_points); diff --git a/kernels/fft/c2c_fft/c2c_fft_host.cpp b/kernels/fft/c2c_fft/c2c_fft_host.cpp index 29c53d61f..9ac894fd4 100644 --- a/kernels/fft/c2c_fft/c2c_fft_host.cpp +++ b/kernels/fft/c2c_fft/c2c_fft_host.cpp @@ -2165,7 +2165,7 @@ mluOpStatus_t computeFFT2dMatMulColumn(mluOpHandle_t handle, DEFINE_CREATE_AND_SET_CNNL_TENSOR_DESCRIPTOR(b_desc, cnnl_b_desc); DEFINE_CREATE_AND_SET_CNNL_TENSOR_DESCRIPTOR(c_desc, cnnl_c_desc); DEFINE_CREATE_AND_SET_CNNL_TENSOR_DESCRIPTOR(c_desc, cnnl_d_desc); - c_desc->onchip_dtype = in_e_dtype; + c_desc->setOnchipDtype(in_e_dtype); CALL_CNNL(cnnlGetMatMulAlgoHeuristic(cnnl_handle, matmul_desc, cnnl_a_desc, cnnl_b_desc, cnnl_c_desc, cnnl_d_desc, nullptr, requested_algo_count, @@ -2280,8 +2280,8 @@ mluOpStatus_t computeFFT2dMatMulRow(mluOpHandle_t handle, DEFINE_CREATE_AND_SET_CNNL_TENSOR_DESCRIPTOR(b_desc, cnnl_b_desc); DEFINE_CREATE_AND_SET_CNNL_TENSOR_DESCRIPTOR(c_desc, cnnl_c_desc); - // c_desc->onchip_dtype = MLUOP_DTYPE_FLOAT; - c_desc->onchip_dtype = in_e_dtype; + // c_desc->setOnchipDtype(MLUOP_DTYPE_FLOAT); + c_desc->setOnchipDtype(in_e_dtype); float alpha = 1.0; float beta = 0.0; diff --git a/kernels/fft/common/fft_basic_ops.cpp b/kernels/fft/common/fft_basic_ops.cpp index fd56557d3..1ae1b0a88 100644 --- a/kernels/fft/common/fft_basic_ops.cpp +++ b/kernels/fft/common/fft_basic_ops.cpp @@ -170,7 +170,7 @@ mluOpStatus_t fftGetQuantizeMatMulWorkspaceSize( status = mluOpSetTensorDescriptorOnchipDataType(c_desc, MLUOP_DTYPE_FLOAT); INTERNAL_CHECK(api, status == MLUOP_STATUS_SUCCESS); } else if (fftIsIntDtype(a_compute_type) && fftIsIntDtype(b_compute_type) && - c_desc->dtype == MLUOP_DTYPE_HALF) { + c_desc->getDtype() == MLUOP_DTYPE_HALF) { status = mluOpSetTensorDescriptorOnchipDataType(c_desc, MLUOP_DTYPE_FLOAT); INTERNAL_CHECK(api, status == MLUOP_STATUS_SUCCESS); } else { @@ -312,7 +312,7 @@ mluOpStatus_t fftQuantMatMul(mluOpHandle_t handle, int m, int k, int n, status = mluOpSetTensorDescriptorOnchipDataType(c_desc, MLUOP_DTYPE_FLOAT); INTERNAL_CHECK(api, status == MLUOP_STATUS_SUCCESS); } else if (fftIsIntDtype(a_compute_type) && fftIsIntDtype(b_compute_type) && - c_desc->dtype == MLUOP_DTYPE_HALF) { + c_desc->getDtype() == MLUOP_DTYPE_HALF) { status = mluOpSetTensorDescriptorOnchipDataType(c_desc, MLUOP_DTYPE_FLOAT); INTERNAL_CHECK(api, status == MLUOP_STATUS_SUCCESS); } else { @@ -363,7 +363,7 @@ mluOpStatus_t fftQuantMatMul(mluOpHandle_t handle, int m, int k, int n, CALL_CNNL(cnnlMatMulDescDestroy(matmul_desc)); CALL_CNNL(cnnlMatMulAlgoDestroy(matmul_algo)); } else { - c_desc->onchip_dtype = MLUOP_DTYPE_FLOAT; + c_desc->setOnchipDtype(MLUOP_DTYPE_FLOAT); cnnlMatMulDescriptor_t matmul_desc; cnnlMatMulAlgo_t matmul_algo; cnnlMatMulHeuristicResult_t heuristic_result; @@ -465,7 +465,7 @@ mluOpStatus_t fftGetBatchMatMulBcastWorkspaceSize( status = mluOpSetTensorDescriptor_v2(c_desc, MLUOP_LAYOUT_ARRAY, data_type, 3, c_dims); INTERNAL_CHECK(api, status == MLUOP_STATUS_SUCCESS); - c_desc->onchip_dtype = MLUOP_DTYPE_FLOAT; + c_desc->setOnchipDtype(MLUOP_DTYPE_FLOAT); DEFINE_CREATE_AND_SET_CNNL_HANDLE(handle, cnnl_handle); // convert to cnnl_handle @@ -559,7 +559,7 @@ mluOpStatus_t fftBatchMatMulBcast( status = mluOpSetTensorDescriptor_v2(c_desc, MLUOP_LAYOUT_ARRAY, data_type, 3, c_dims); INTERNAL_CHECK(api, status == MLUOP_STATUS_SUCCESS); - c_desc->onchip_dtype = MLUOP_DTYPE_FLOAT; + c_desc->setOnchipDtype(MLUOP_DTYPE_FLOAT); DEFINE_CREATE_AND_SET_CNNL_HANDLE(handle, cnnl_handle); // convert to cnnl_handle diff --git a/kernels/fft/fft.cpp b/kernels/fft/fft.cpp index 4d4ab9ef1..3e9f24104 100644 --- a/kernels/fft/fft.cpp +++ b/kernels/fft/fft.cpp @@ -2342,11 +2342,11 @@ mluOpStatus_t MLUOP_WIN_API mluOpMakeFFTPlanMany( } // dimension check - fft_plan->idim = input_desc->dim; - fft_plan->odim = output_desc->dim; + fft_plan->idim = input_desc->getDim(); + fft_plan->odim = output_desc->getDim(); fft_plan->inum = mluOpGetTensorElementNum(input_desc); fft_plan->onum = mluOpGetTensorElementNum(output_desc); - PARAM_CHECK_GT(make_plan_api, input_desc->dim, 0); + PARAM_CHECK_GT(make_plan_api, input_desc->getDim(), 0); PARAM_CHECK_EQ(make_plan_api, fft_plan->idim, fft_plan->odim, ": input and output dimension mismatch."); @@ -2361,8 +2361,8 @@ mluOpStatus_t MLUOP_WIN_API mluOpMakeFFTPlanMany( if (fft_plan->idim == rank) { fft_plan->batch = 1; } else { // idim == rank + 1 - fft_plan->batch = input_desc->dims[0]; - PARAM_CHECK_EQ(make_plan_api, fft_plan->batch, output_desc->dims[0], + fft_plan->batch = input_desc->getDimIndex(0); + PARAM_CHECK_EQ(make_plan_api, fft_plan->batch, output_desc->getDimIndex(0), ": batch size mismatch."); } @@ -2382,8 +2382,8 @@ mluOpStatus_t MLUOP_WIN_API mluOpMakeFFTPlanMany( // data layout with tensor dim strides. 2-D and 3-D should pay attention. // stride check, if an in-place fft is adopted check, `istride` should be // equal to `ostride`. - fft_plan->istride = input_desc->strides[fft_plan->idim - 1]; - fft_plan->ostride = output_desc->strides[fft_plan->odim - 1]; + fft_plan->istride = input_desc->getStrideIndex(fft_plan->idim - 1); + fft_plan->ostride = output_desc->getStrideIndex(fft_plan->odim - 1); PARAM_CHECK_GE(make_plan_api, fft_plan->istride, 0, ": input stride should be greater than or equal to 0."); @@ -2391,12 +2391,12 @@ mluOpStatus_t MLUOP_WIN_API mluOpMakeFFTPlanMany( ": output stride should be greater than or equal to 0."); for (auto i = 0; i < fft_plan->rank; i++) { - fft_plan->inembed[i] = input_desc->dims[fft_plan->idim - rank + i]; - fft_plan->onembed[i] = output_desc->dims[fft_plan->odim - rank + i]; + fft_plan->inembed[i] = input_desc->getDimIndex(fft_plan->idim - rank + i); + fft_plan->onembed[i] = output_desc->getDimIndex(fft_plan->odim - rank + i); } if (fft_plan->idim == rank + 1) { - fft_plan->idist = input_desc->strides[0]; - fft_plan->odist = output_desc->strides[0]; + fft_plan->idist = input_desc->getStrideIndex(0); + fft_plan->odist = output_desc->getStrideIndex(0); } else { // batch == 1 fft_plan->idist = mluOpGetTensorElementNum(input_desc) / fft_plan->batch; fft_plan->odist = mluOpGetTensorElementNum(output_desc) / fft_plan->batch; @@ -2406,8 +2406,8 @@ mluOpStatus_t MLUOP_WIN_API mluOpMakeFFTPlanMany( !mluop::ifNeedTensorStrideProcess(output_desc); // dtype check - mluOpDataType_t input_dtype = input_desc->dtype; - mluOpDataType_t output_dtype = output_desc->dtype; + mluOpDataType_t input_dtype = input_desc->getDtype(); + mluOpDataType_t output_dtype = output_desc->getDtype(); const mluOpDataType_t f_c_dtype = MLUOP_DTYPE_COMPLEX_FLOAT; const mluOpDataType_t f_r_dtype = MLUOP_DTYPE_FLOAT; const mluOpDataType_t hf_c_dtype = MLUOP_DTYPE_COMPLEX_HALF; @@ -2433,9 +2433,9 @@ mluOpStatus_t MLUOP_WIN_API mluOpMakeFFTPlanMany( return MLUOP_STATUS_BAD_PARAM; } - fft_plan->input_dtype = input_desc->dtype; - fft_plan->output_dtype = output_desc->dtype; - fft_plan->execution_dtype = input_desc->onchip_dtype; + fft_plan->input_dtype = input_desc->getDtype(); + fft_plan->output_dtype = output_desc->getDtype(); + fft_plan->execution_dtype = input_desc->getOnchipDtype(); VLOG(5) << "input data type: " << mluOpGetNameOfDataType(fft_plan->input_dtype); @@ -2553,17 +2553,17 @@ mluOpStatus_t MLUOP_WIN_API mluOpMakeFFTPlanMany( MLUOP_STATUS_SUCCESS); INTERNAL_CHECK(make_plan_api, mluOpSetTensorDescriptorEx_v2( - fft_input_desc, input_desc->layout, input_desc->dtype, - input_desc->dim, input_desc->dims, - input_desc->strides) == MLUOP_STATUS_SUCCESS); + fft_input_desc, input_desc->getLayout(), input_desc->getDtype(), + input_desc->getDim(), input_desc->getDims(), + input_desc->getStrides()) == MLUOP_STATUS_SUCCESS); INTERNAL_CHECK(make_plan_api, mluOpSetTensorDescriptorOnchipDataType( - fft_input_desc, input_desc->onchip_dtype) == + fft_input_desc, input_desc->getOnchipDtype()) == MLUOP_STATUS_SUCCESS); INTERNAL_CHECK(make_plan_api, mluOpSetTensorDescriptorEx_v2( - fft_output_desc, output_desc->layout, output_desc->dtype, - output_desc->dim, output_desc->dims, - output_desc->strides) == MLUOP_STATUS_SUCCESS); + fft_output_desc, output_desc->getLayout(), output_desc->getDtype(), + output_desc->getDim(), output_desc->getDims(), + output_desc->getStrides()) == MLUOP_STATUS_SUCCESS); fft_plan->input_desc = fft_input_desc; fft_plan->output_desc = fft_output_desc; diff --git a/kernels/fft/irfft/irfft_host.cpp b/kernels/fft/irfft/irfft_host.cpp index b065028e1..5bddc050c 100644 --- a/kernels/fft/irfft/irfft_host.cpp +++ b/kernels/fft/irfft/irfft_host.cpp @@ -1718,7 +1718,7 @@ mluOpStatus_t computeFFT2dMatMulColumnC2R(mluOpHandle_t handle, DEFINE_CREATE_AND_SET_CNNL_TENSOR_DESCRIPTOR(b_desc, cnnl_b_desc); DEFINE_CREATE_AND_SET_CNNL_TENSOR_DESCRIPTOR(c_desc, cnnl_c_desc); DEFINE_CREATE_AND_SET_CNNL_TENSOR_DESCRIPTOR(c_desc, cnnl_d_desc); - c_desc->onchip_dtype = in_e_dtype; + c_desc->setOnchipDtype(in_e_dtype); CALL_CNNL(cnnlGetMatMulAlgoHeuristic(cnnl_handle, matmul_desc, cnnl_a_desc, cnnl_b_desc, cnnl_c_desc, cnnl_d_desc, nullptr, requested_algo_count, @@ -1812,8 +1812,8 @@ mluOpStatus_t computeFFT2dMatMulRowC2R(mluOpHandle_t handle, DEFINE_CREATE_AND_SET_CNNL_TENSOR_DESCRIPTOR(b_desc, cnnl_b_desc); DEFINE_CREATE_AND_SET_CNNL_TENSOR_DESCRIPTOR(c_desc, cnnl_c_desc); - // c_desc->onchip_dtype = MLUOP_DTYPE_FLOAT; - c_desc->onchip_dtype = in_e_dtype; + // c_desc->setOnchipDtype(MLUOP_DTYPE_FLOAT); + c_desc->setOnchipDtype(in_e_dtype); float alpha = 1.0; float beta = 0.0; diff --git a/kernels/fft/rfft/rfft_host.cpp b/kernels/fft/rfft/rfft_host.cpp index d0755e8be..6f6a8e91f 100644 --- a/kernels/fft/rfft/rfft_host.cpp +++ b/kernels/fft/rfft/rfft_host.cpp @@ -1399,7 +1399,7 @@ mluOpStatus_t computeFFT2dMatMulColumnR2C(mluOpHandle_t handle, DEFINE_CREATE_AND_SET_CNNL_TENSOR_DESCRIPTOR(b_desc, cnnl_b_desc); DEFINE_CREATE_AND_SET_CNNL_TENSOR_DESCRIPTOR(c_desc, cnnl_c_desc); DEFINE_CREATE_AND_SET_CNNL_TENSOR_DESCRIPTOR(c_desc, cnnl_d_desc); - c_desc->onchip_dtype = in_e_dtype; + c_desc->setOnchipDtype(in_e_dtype); CALL_CNNL(cnnlGetMatMulAlgoHeuristic(cnnl_handle, matmul_desc, cnnl_a_desc, cnnl_b_desc, cnnl_c_desc, cnnl_d_desc, nullptr, requested_algo_count, @@ -1495,8 +1495,8 @@ mluOpStatus_t computeFFT2dMatMulRowR2C(mluOpHandle_t handle, DEFINE_CREATE_AND_SET_CNNL_TENSOR_DESCRIPTOR(b_desc, cnnl_b_desc); DEFINE_CREATE_AND_SET_CNNL_TENSOR_DESCRIPTOR(c_desc, cnnl_c_desc); - // c_desc->onchip_dtype = MLUOP_DTYPE_FLOAT; - c_desc->onchip_dtype = in_e_dtype; + // c_desc->setOnchipDtype(MLUOP_DTYPE_FLOAT); + c_desc->setOnchipDtype(in_e_dtype); float alpha = 1.0; float beta = 0.0; diff --git a/kernels/focal_loss_sigmoid/focal_loss_sigmoid.cpp b/kernels/focal_loss_sigmoid/focal_loss_sigmoid.cpp index cb014c8fb..eef192445 100644 --- a/kernels/focal_loss_sigmoid/focal_loss_sigmoid.cpp +++ b/kernels/focal_loss_sigmoid/focal_loss_sigmoid.cpp @@ -50,39 +50,39 @@ static mluOpStatus_t checkFocalLossSigmoidForwardValidation( const mluOpTensorDescriptor_t weight_desc, const mluOpTensorDescriptor_t output_desc) { const std::string interface_name = "[mluOpFocalLossSigmoidForward] "; - const mluOpDataType_t input_dtype = input_desc->dtype; - const mluOpDataType_t target_dtype = target_desc->dtype; - const mluOpDataType_t output_dtype = output_desc->dtype; + const mluOpDataType_t input_dtype = input_desc->getDtype(); + const mluOpDataType_t target_dtype = target_desc->getDtype(); + const mluOpDataType_t output_dtype = output_desc->getDtype(); // check shape - if (input_desc->dim != 2) { + if (input_desc->getDim() != 2) { LOG(ERROR) << interface_name << "Dimension num of input should be 2. " - << "But now it is " << input_desc->dim << "."; + << "But now it is " << input_desc->getDim() << "."; return MLUOP_STATUS_BAD_PARAM; } - if (target_desc->dim != 1) { + if (target_desc->getDim() != 1) { LOG(ERROR) << interface_name << "Dimension num of target should be 1. " - << "But now it is " << target_desc->dim << "."; + << "But now it is " << target_desc->getDim() << "."; return MLUOP_STATUS_BAD_PARAM; } - if (target_desc->dims[0] != input_desc->dims[0]) { + if (target_desc->getDimIndex(0) != input_desc->getDimIndex(0)) { LOG(ERROR) << interface_name << "Element num of target should be " - << input_desc->dims[0] << ", But now it is " - << target_desc->dims[0] << "."; + << input_desc->getDimIndex(0) << ", But now it is " + << target_desc->getDimIndex(0) << "."; return MLUOP_STATUS_BAD_PARAM; } - if (output_desc->dim != 2) { + if (output_desc->getDim() != 2) { LOG(ERROR) << interface_name << "Dimension num of output should be 2. " - << "But now it is " << output_desc->dim << "."; + << "But now it is " << output_desc->getDim() << "."; return MLUOP_STATUS_BAD_PARAM; } - if (output_desc->dims[0] != input_desc->dims[0] || - output_desc->dims[1] != input_desc->dims[1]) { + if (output_desc->getDimIndex(0) != input_desc->getDimIndex(0) || + output_desc->getDimIndex(1) != input_desc->getDimIndex(1)) { LOG(ERROR) << interface_name << "Shape of output and input must be euqal. " - << "But now output.shape is [" << output_desc->dims[0] << ", " - << output_desc->dims[1] << "], " - << "and input.shape is [" << input_desc->dims[0] << ", " - << input_desc->dims[1] << "]. "; + << "But now output.shape is [" << output_desc->getDimIndex(0) << ", " + << output_desc->getDimIndex(1) << "], " + << "and input.shape is [" << input_desc->getDimIndex(0) << ", " + << input_desc->getDimIndex(1) << "]. "; return MLUOP_STATUS_BAD_PARAM; } @@ -112,24 +112,24 @@ static mluOpStatus_t checkFocalLossSigmoidForwardValidation( // check weight if (weight_desc != NULL && mluOpGetTensorElementNum(weight_desc) != 0) { - if (weight_desc->dtype != input_dtype) { + if (weight_desc->getDtype() != input_dtype) { LOG(ERROR) << interface_name << "Both data types of weight and input should be equal. " << "But now input_dtype is " << mluOpGetNameOfDataType(input_dtype) << ", " << "weight_dtype is " - << mluOpGetNameOfDataType(weight_desc->dtype) << "."; + << mluOpGetNameOfDataType(weight_desc->getDtype()) << "."; return MLUOP_STATUS_BAD_PARAM; } - if (weight_desc->dim != 1) { + if (weight_desc->getDim() != 1) { LOG(ERROR) << interface_name << "Dimension num of weight should be 1. " - << "But now it is " << weight_desc->dim << "."; + << "But now it is " << weight_desc->getDim() << "."; return MLUOP_STATUS_BAD_PARAM; } - if (weight_desc->dims[0] != input_desc->dims[1]) { + if (weight_desc->getDimIndex(0) != input_desc->getDimIndex(1)) { LOG(ERROR) << interface_name << "Element num of weight should be " - << input_desc->dims[1] << ", But now it is " - << weight_desc->dims[0] << "."; + << input_desc->getDimIndex(1) << ", But now it is " + << weight_desc->getDimIndex(0) << "."; return MLUOP_STATUS_BAD_PARAM; } } else { @@ -204,8 +204,8 @@ mluOpStatus_t MLUOP_WIN_API mluOpFocalLossSigmoidForward( "output_desc must be contiguous"); // generate case prototxt. - const int32_t N = static_cast(input_desc->dims[0]); - const int32_t C = static_cast(input_desc->dims[1]); + const int32_t N = static_cast(input_desc->getDimIndex(0)); + const int32_t C = static_cast(input_desc->getDimIndex(1)); if (MLUOP_GEN_CASE_ON_NEW) { GEN_CASE_START("focal_loss_sigmoid_forward", "FOCAL_LOSS_SIGMOID_FORWARD"); @@ -235,7 +235,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpFocalLossSigmoidForward( VLOG(5) << "Launch Kernel MLUKernelFocalLossSigmoidForward<<>>"; - if (input_desc->dtype == MLUOP_DTYPE_HALF) { + if (input_desc->getDtype() == MLUOP_DTYPE_HALF) { CHECK_RETURN("[mluOpBlockKernelFocalLossSigmoidForwardHalf]", mluOpBlockKernelFocalLossSigmoidForwardHalf( k_dim, k_type, handle->queue, @@ -327,34 +327,34 @@ static mluOpStatus_t checkParams(const mluOpTensorDescriptor_t input_desc, const std::string interface_name = "[mluOpFocalLossSigmoidBackward]: "; // check shape - PARAM_CHECK(interface_name, input_desc->dim == output_desc->dim); - if (input_desc->dim != 2) { - LOG(ERROR) << interface_name << "input_desc->dim shoule be 2" - << "but now input_desc->dim is " << input_desc->dim << "."; + PARAM_CHECK(interface_name, input_desc->getDim() == output_desc->getDim()); + if (input_desc->getDim() != 2) { + LOG(ERROR) << interface_name << "input_desc->getDim() shoule be 2" + << "but now input_desc->getDim() is " << input_desc->getDim() << "."; return MLUOP_STATUS_BAD_PARAM; } - if (target_desc->dim != 1) { - LOG(ERROR) << interface_name << "target_desc->dim shoule be 1" - << "but now target_desc->dim is " << target_desc->dim << "."; + if (target_desc->getDim() != 1) { + LOG(ERROR) << interface_name << "target_desc->getDim() shoule be 1" + << "but now target_desc->getDim() is " << target_desc->getDim() << "."; return MLUOP_STATUS_BAD_PARAM; } - for (int i = 0; i < input_desc->dim; ++i) { - if (input_desc->dims[i] != output_desc->dims[i]) { + for (int i = 0; i < input_desc->getDim(); ++i) { + if (input_desc->getDimIndex(i) != output_desc->getDimIndex(i)) { LOG(ERROR) << interface_name << "input_desc->dims[" << i << "] should be equal to " - << "output_desc->dims[" << i << "]. But now " - << "input_desc->dims[" << i << "] is " << input_desc->dims[i] + << "output_desc->getDimIndex(" << i << "). But now " + << "input_desc->getDimIndex(" << i << ") is " << input_desc->getDimIndex(i) << ", " - << "output_desc->dims[" << i << "] is " << output_desc->dims[i] + << "output_desc->getDimIndex(" << i << ") is " << output_desc->getDimIndex(i) << "."; return MLUOP_STATUS_BAD_PARAM; } } - if (input_desc->dims[0] != target_desc->dims[0]) { - LOG(ERROR) << interface_name << "input_desc->dims[0] should be equal to " - << "target_desc->dim[0]. But now " - << "input_desc->dims[0] is " << input_desc->dims[0] << ", " - << "target_desc->dims[0] is " << target_desc->dims[0] << "."; + if (input_desc->getDimIndex(0) != target_desc->getDimIndex(0)) { + LOG(ERROR) << interface_name << "input_desc->getDimIndex(0) should be equal to " + << "target_desc->getDim()[0]. But now " + << "input_desc->getDimIndex(0) is " << input_desc->getDimIndex(0) << ", " + << "target_desc->getDimIndex(0) is " << target_desc->getDimIndex(0) << "."; return MLUOP_STATUS_BAD_PARAM; } @@ -371,16 +371,16 @@ static mluOpStatus_t checkParams(const mluOpTensorDescriptor_t input_desc, } // check data type - auto input_dtype = input_desc->dtype; - auto target_dtype = target_desc->dtype; - PARAM_CHECK(interface_name, input_desc->dtype == output_desc->dtype); + auto input_dtype = input_desc->getDtype(); + auto target_dtype = target_desc->getDtype(); + PARAM_CHECK(interface_name, input_desc->getDtype() == output_desc->getDtype()); if (input_dtype != MLUOP_DTYPE_FLOAT && input_dtype != MLUOP_DTYPE_HALF) { LOG(ERROR) << interface_name << "Types of input should be HALF or FLOAT. " << "But now input_dtype is " << mluOpGetNameOfDataType(input_dtype) << "."; return MLUOP_STATUS_BAD_PARAM; } - if (target_desc->dtype != MLUOP_DTYPE_INT32) { + if (target_desc->getDtype() != MLUOP_DTYPE_INT32) { LOG(ERROR) << interface_name << "The data type of target should be int32, " << "but now target dtype is " << mluOpGetNameOfDataType(target_dtype) << "."; @@ -389,25 +389,25 @@ static mluOpStatus_t checkParams(const mluOpTensorDescriptor_t input_desc, // check weight if (weight_desc != NULL && mluOpGetTensorElementNum(weight_desc) != 0) { - if (weight_desc->dim != 1) { - LOG(ERROR) << interface_name << "weight_desc->dim shoule be 1" - << "but now weight_desc->dim is " << weight_desc->dim << "."; + if (weight_desc->getDim() != 1) { + LOG(ERROR) << interface_name << "weight_desc->getDim() shoule be 1" + << "but now weight_desc->getDim() is " << weight_desc->getDim() << "."; return MLUOP_STATUS_BAD_PARAM; } - if (input_desc->dims[1] != weight_desc->dims[0]) { - LOG(ERROR) << interface_name << "input_desc->dims[1] should be equal to " - << "weight_desc->dims[0]. But now " - << "input_desc->dims[1] is " << input_desc->dims[1] << ", " - << "weight_desc->dims[0] is " << weight_desc->dims[0] << "."; + if (input_desc->getDimIndex(1) != weight_desc->getDimIndex(0)) { + LOG(ERROR) << interface_name << "input_desc->getDimIndex(1) should be equal to " + << "weight_desc->getDimIndex(0). But now " + << "input_desc->getDimIndex(1) is " << input_desc->getDimIndex(1) << ", " + << "weight_desc->getDimIndex(0) is " << weight_desc->getDimIndex(0) << "."; return MLUOP_STATUS_BAD_PARAM; } - if (weight_desc->dtype != input_dtype) { + if (weight_desc->getDtype() != input_dtype) { LOG(ERROR) << interface_name << "Both types of weight and output should be equal. " << "But now input_dtype is " << mluOpGetNameOfDataType(input_dtype) << ", " << "weight_dtype is " - << mluOpGetNameOfDataType(weight_desc->dtype) << "."; + << mluOpGetNameOfDataType(weight_desc->getDtype()) << "."; return MLUOP_STATUS_BAD_PARAM; } } else { @@ -461,12 +461,12 @@ mluOpStatus_t MLUOP_WIN_API mluOpFocalLossSigmoidBackward( int deal_n = 0; int compute_data_bytes = sizeof(float); - int target_data_bytes = mluOpDataTypeBytes(target_desc->dtype); + int target_data_bytes = mluOpDataTypeBytes(target_desc->getDtype()); int threshold_c = 0; - int dim_n = input_desc->dims[0]; - int dim_c = input_desc->dims[1]; + int dim_n = input_desc->getDimIndex(0); + int dim_c = input_desc->getDimIndex(1); - bool is_half = input_desc->dtype == MLUOP_DTYPE_HALF; + bool is_half = input_desc->getDtype() == MLUOP_DTYPE_HALF; // calculate deal_n and threshold_c getDealNAndThresholdC(handle, compute_data_bytes, target_data_bytes, dim_c, &deal_n, &threshold_c, has_weight, is_half); @@ -484,9 +484,9 @@ mluOpStatus_t MLUOP_WIN_API mluOpFocalLossSigmoidBackward( // check C if (dim_c > threshold_c) { LOG(ERROR) << interface_name - << " input_desc->dims[1] should be in the range of " + << " input_desc->getDimIndex(1) should be in the range of " << "[0, " << threshold_c << "]. " - << "but now input_desc->dims[1] is " << dim_c; + << "but now input_desc->getDimIndex(1) is " << dim_c; return MLUOP_STATUS_NOT_SUPPORTED; } diff --git a/kernels/generate_proposals_v2/generate_proposals_v2.cpp b/kernels/generate_proposals_v2/generate_proposals_v2.cpp index dac9a9abb..17f33a00b 100644 --- a/kernels/generate_proposals_v2/generate_proposals_v2.cpp +++ b/kernels/generate_proposals_v2/generate_proposals_v2.cpp @@ -72,21 +72,21 @@ mluOpStatus_t MLUOP_WIN_API mluOpGetGenerateProposalsV2WorkspaceSize( PARAM_CHECK(API, scores_desc != NULL); PARAM_CHECK(API, size != NULL); - PARAM_CHECK(API, scores_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(API, scores_desc->layout == MLUOP_LAYOUT_ARRAY); + PARAM_CHECK(API, scores_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(API, scores_desc->getLayout() == MLUOP_LAYOUT_ARRAY); - PARAM_CHECK_EQ(API, scores_desc->dim, 4); - PARAM_CHECK_NE(API, scores_desc->dims[1], 0); - PARAM_CHECK_NE(API, scores_desc->dims[2], 0); - PARAM_CHECK_NE(API, scores_desc->dims[3], 0); + PARAM_CHECK_EQ(API, scores_desc->getDim(), 4); + PARAM_CHECK_NE(API, scores_desc->getDimIndex(1), 0); + PARAM_CHECK_NE(API, scores_desc->getDimIndex(2), 0); + PARAM_CHECK_NE(API, scores_desc->getDimIndex(3), 0); const size_t scores_num = mluOpGetTensorElementNum(scores_desc); TENSOR_NUM_CHECK(API, scores_num, LARGE_TENSOR_NUM, ""); - const int64_t n = scores_desc->dims[0]; - const int64_t h = scores_desc->dims[1]; - const int64_t w = scores_desc->dims[2]; - const int64_t a = scores_desc->dims[3]; + const int64_t n = scores_desc->getDimIndex(0); + const int64_t h = scores_desc->getDimIndex(1); + const int64_t w = scores_desc->getDimIndex(2); + const int64_t a = scores_desc->getDimIndex(3); const int64_t hwa = h * w * a; if (handle->arch >= 592) { DEFINE_CREATE_AND_SET_CNNL_HANDLE(handle, cnnl_handle); @@ -126,7 +126,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpGetGenerateProposalsV2WorkspaceSize( CALL_CNNL(cnnlDestroyTensorDescriptor(sorted_index_desc)); DESTROY_CNNL_HANDLE(cnnl_handle); size_t data_size = 0; - mluOpGetSizeOfDataType(scores_desc->dtype, &data_size); + mluOpGetSizeOfDataType(scores_desc->getDtype(), &data_size); const size_t topk_workspace_size_align = PAD_UP(topk_workspace_size, GDRAM_ALIGN_SIZE); @@ -157,21 +157,21 @@ mluOpStatus_t MLUOP_WIN_API mluOpGetGenerateProposalsV2WorkspaceSize_v2( PARAM_CHECK(API, scores_desc != NULL); PARAM_CHECK(API, size != NULL); - PARAM_CHECK(API, scores_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(API, scores_desc->layout == MLUOP_LAYOUT_ARRAY); + PARAM_CHECK(API, scores_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(API, scores_desc->getLayout() == MLUOP_LAYOUT_ARRAY); - PARAM_CHECK_EQ(API, scores_desc->dim, 4); - PARAM_CHECK_NE(API, scores_desc->dims[1], 0); - PARAM_CHECK_NE(API, scores_desc->dims[2], 0); - PARAM_CHECK_NE(API, scores_desc->dims[3], 0); + PARAM_CHECK_EQ(API, scores_desc->getDim(), 4); + PARAM_CHECK_NE(API, scores_desc->getDimIndex(1), 0); + PARAM_CHECK_NE(API, scores_desc->getDimIndex(2), 0); + PARAM_CHECK_NE(API, scores_desc->getDimIndex(3), 0); const size_t scores_num = mluOpGetTensorElementNum(scores_desc); TENSOR_NUM_CHECK(API, scores_num, LARGE_TENSOR_NUM, ""); - const int64_t n = scores_desc->dims[0]; - const int64_t h = scores_desc->dims[1]; - const int64_t w = scores_desc->dims[2]; - const int64_t a = scores_desc->dims[3]; + const int64_t n = scores_desc->getDimIndex(0); + const int64_t h = scores_desc->getDimIndex(1); + const int64_t w = scores_desc->getDimIndex(2); + const int64_t a = scores_desc->getDimIndex(3); const int64_t hwa = h * w * a; if (handle->arch >= 592) { DEFINE_CREATE_AND_SET_CNNL_HANDLE(handle, cnnl_handle); @@ -213,7 +213,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpGetGenerateProposalsV2WorkspaceSize_v2( CALL_CNNL(cnnlDestroyTensorDescriptor(sorted_index_desc)); DESTROY_CNNL_HANDLE(cnnl_handle); size_t data_size = 0; - mluOpGetSizeOfDataType(scores_desc->dtype, &data_size); + mluOpGetSizeOfDataType(scores_desc->getDtype(), &data_size); const size_t topk_workspace_size_align = PAD_UP(topk_workspace_size, GDRAM_ALIGN_SIZE); @@ -263,77 +263,77 @@ mluOpStatus_t MLUOP_WIN_API mluOpGenerateProposalsV2( PARAM_CHECK(API, rpn_rois_num_desc != NULL); // check inputs/outputs data type - PARAM_CHECK(API, scores_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(API, bbox_deltas_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(API, im_shape_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(API, anchors_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(API, variances_desc->dtype == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(API, scores_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(API, bbox_deltas_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(API, im_shape_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(API, anchors_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(API, variances_desc->getDtype() == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(API, rpn_rois_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(API, rpn_roi_probs_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(API, rpn_rois_num_desc->dtype == MLUOP_DTYPE_INT32); + PARAM_CHECK(API, rpn_rois_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(API, rpn_roi_probs_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(API, rpn_rois_num_desc->getDtype() == MLUOP_DTYPE_INT32); // check inputs layout - PARAM_CHECK(API, scores_desc->layout == MLUOP_LAYOUT_ARRAY); - PARAM_CHECK(API, bbox_deltas_desc->layout == MLUOP_LAYOUT_ARRAY); - PARAM_CHECK(API, im_shape_desc->layout == MLUOP_LAYOUT_ARRAY); - PARAM_CHECK(API, anchors_desc->layout == MLUOP_LAYOUT_ARRAY); - PARAM_CHECK(API, variances_desc->layout == MLUOP_LAYOUT_ARRAY); + PARAM_CHECK(API, scores_desc->getLayout() == MLUOP_LAYOUT_ARRAY); + PARAM_CHECK(API, bbox_deltas_desc->getLayout() == MLUOP_LAYOUT_ARRAY); + PARAM_CHECK(API, im_shape_desc->getLayout() == MLUOP_LAYOUT_ARRAY); + PARAM_CHECK(API, anchors_desc->getLayout() == MLUOP_LAYOUT_ARRAY); + PARAM_CHECK(API, variances_desc->getLayout() == MLUOP_LAYOUT_ARRAY); - PARAM_CHECK(API, rpn_rois_desc->layout == MLUOP_LAYOUT_ARRAY); - PARAM_CHECK(API, rpn_roi_probs_desc->layout == MLUOP_LAYOUT_ARRAY); - PARAM_CHECK(API, rpn_rois_num_desc->layout == MLUOP_LAYOUT_ARRAY); + PARAM_CHECK(API, rpn_rois_desc->getLayout() == MLUOP_LAYOUT_ARRAY); + PARAM_CHECK(API, rpn_roi_probs_desc->getLayout() == MLUOP_LAYOUT_ARRAY); + PARAM_CHECK(API, rpn_rois_num_desc->getLayout() == MLUOP_LAYOUT_ARRAY); // check inputs shape - PARAM_CHECK_EQ(API, scores_desc->dim, 4); - const int64_t n = scores_desc->dims[0]; - const int64_t h = scores_desc->dims[1]; - const int64_t w = scores_desc->dims[2]; - const int64_t a = scores_desc->dims[3]; + PARAM_CHECK_EQ(API, scores_desc->getDim(), 4); + const int64_t n = scores_desc->getDimIndex(0); + const int64_t h = scores_desc->getDimIndex(1); + const int64_t w = scores_desc->getDimIndex(2); + const int64_t a = scores_desc->getDimIndex(3); // [N,H,W,A4] - PARAM_CHECK_EQ(API, bbox_deltas_desc->dim, 4); - PARAM_CHECK_EQ(API, bbox_deltas_desc->dims[0], scores_desc->dims[0]); - PARAM_CHECK_EQ(API, bbox_deltas_desc->dims[1], scores_desc->dims[1]); - PARAM_CHECK_EQ(API, bbox_deltas_desc->dims[2], scores_desc->dims[2]); - PARAM_CHECK_EQ(API, bbox_deltas_desc->dims[3], 4 * scores_desc->dims[3]); + PARAM_CHECK_EQ(API, bbox_deltas_desc->getDim(), 4); + PARAM_CHECK_EQ(API, bbox_deltas_desc->getDimIndex(0), scores_desc->getDimIndex(0)); + PARAM_CHECK_EQ(API, bbox_deltas_desc->getDimIndex(1), scores_desc->getDimIndex(1)); + PARAM_CHECK_EQ(API, bbox_deltas_desc->getDimIndex(2), scores_desc->getDimIndex(2)); + PARAM_CHECK_EQ(API, bbox_deltas_desc->getDimIndex(3), 4 * scores_desc->getDimIndex(3)); // [N, 2] - PARAM_CHECK_EQ(API, im_shape_desc->dim, 2); - PARAM_CHECK_EQ(API, im_shape_desc->dims[0], scores_desc->dims[0]); - PARAM_CHECK_EQ(API, im_shape_desc->dims[1], 2); + PARAM_CHECK_EQ(API, im_shape_desc->getDim(), 2); + PARAM_CHECK_EQ(API, im_shape_desc->getDimIndex(0), scores_desc->getDimIndex(0)); + PARAM_CHECK_EQ(API, im_shape_desc->getDimIndex(1), 2); // [H, W, A, 4] - PARAM_CHECK_EQ(API, anchors_desc->dim, 4); - PARAM_CHECK_EQ(API, anchors_desc->dims[0], scores_desc->dims[1]); - PARAM_CHECK_EQ(API, anchors_desc->dims[1], scores_desc->dims[2]); - PARAM_CHECK_EQ(API, anchors_desc->dims[2], scores_desc->dims[3]); - PARAM_CHECK_EQ(API, anchors_desc->dims[3], 4); + PARAM_CHECK_EQ(API, anchors_desc->getDim(), 4); + PARAM_CHECK_EQ(API, anchors_desc->getDimIndex(0), scores_desc->getDimIndex(1)); + PARAM_CHECK_EQ(API, anchors_desc->getDimIndex(1), scores_desc->getDimIndex(2)); + PARAM_CHECK_EQ(API, anchors_desc->getDimIndex(2), scores_desc->getDimIndex(3)); + PARAM_CHECK_EQ(API, anchors_desc->getDimIndex(3), 4); // [H, W, A, 4] - PARAM_CHECK_EQ(API, variances_desc->dim, 4); - PARAM_CHECK_EQ(API, variances_desc->dims[0], scores_desc->dims[1]); - PARAM_CHECK_EQ(API, variances_desc->dims[1], scores_desc->dims[2]); - PARAM_CHECK_EQ(API, variances_desc->dims[2], scores_desc->dims[3]); - PARAM_CHECK_EQ(API, variances_desc->dims[3], 4); + PARAM_CHECK_EQ(API, variances_desc->getDim(), 4); + PARAM_CHECK_EQ(API, variances_desc->getDimIndex(0), scores_desc->getDimIndex(1)); + PARAM_CHECK_EQ(API, variances_desc->getDimIndex(1), scores_desc->getDimIndex(2)); + PARAM_CHECK_EQ(API, variances_desc->getDimIndex(2), scores_desc->getDimIndex(3)); + PARAM_CHECK_EQ(API, variances_desc->getDimIndex(3), 4); // check output shape - PARAM_CHECK_EQ(API, rpn_rois_desc->dim, 2); - PARAM_CHECK_EQ(API, rpn_rois_desc->dims[0], - scores_desc->dims[0] * post_nms_top_n); - PARAM_CHECK_EQ(API, rpn_rois_desc->dims[1], 4); + PARAM_CHECK_EQ(API, rpn_rois_desc->getDim(), 2); + PARAM_CHECK_EQ(API, rpn_rois_desc->getDimIndex(0), + scores_desc->getDimIndex(0) * post_nms_top_n); + PARAM_CHECK_EQ(API, rpn_rois_desc->getDimIndex(1), 4); - PARAM_CHECK_EQ(API, rpn_roi_probs_desc->dim, 2); - PARAM_CHECK_EQ(API, rpn_roi_probs_desc->dims[0], - scores_desc->dims[0] * post_nms_top_n); - PARAM_CHECK_EQ(API, rpn_roi_probs_desc->dims[1], 1); + PARAM_CHECK_EQ(API, rpn_roi_probs_desc->getDim(), 2); + PARAM_CHECK_EQ(API, rpn_roi_probs_desc->getDimIndex(0), + scores_desc->getDimIndex(0) * post_nms_top_n); + PARAM_CHECK_EQ(API, rpn_roi_probs_desc->getDimIndex(1), 1); - PARAM_CHECK_EQ(API, rpn_rois_num_desc->dim, 1); - PARAM_CHECK_EQ(API, rpn_rois_num_desc->dims[0], scores_desc->dims[0]); + PARAM_CHECK_EQ(API, rpn_rois_num_desc->getDim(), 1); + PARAM_CHECK_EQ(API, rpn_rois_num_desc->getDimIndex(0), scores_desc->getDimIndex(0)); - PARAM_CHECK_NE(API, scores_desc->dims[1], 0); - PARAM_CHECK_NE(API, scores_desc->dims[2], 0); - PARAM_CHECK_NE(API, scores_desc->dims[3], 0); + PARAM_CHECK_NE(API, scores_desc->getDimIndex(1), 0); + PARAM_CHECK_NE(API, scores_desc->getDimIndex(2), 0); + PARAM_CHECK_NE(API, scores_desc->getDimIndex(3), 0); // check stride STRIDE_TENSOR_CHECK(API + ":", scores_desc, "scores_desc must be contiguous"); @@ -472,7 +472,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpGenerateProposalsV2( size_t tok_workspace_align_size = PAD_UP(topk_workspace_size, GDRAM_ALIGN_SIZE); size_t data_size = 0; - mluOpGetSizeOfDataType(scores_desc->dtype, &data_size); + mluOpGetSizeOfDataType(scores_desc->getDtype(), &data_size); const size_t indices_size = PAD_UP(n * max_k * data_size, GDRAM_ALIGN_SIZE); void *sorted_score = diff --git a/kernels/lgamma/lgamma.cpp b/kernels/lgamma/lgamma.cpp index cc5e97879..7de9c7f0d 100644 --- a/kernels/lgamma/lgamma.cpp +++ b/kernels/lgamma/lgamma.cpp @@ -76,20 +76,20 @@ mluOpStatus_t MLUOP_WIN_API mluOpLgamma(mluOpHandle_t handle, } if (if_stride_kernel) { VLOG(5) << "kernel Kernel3StagePipelineWithStrideLgamma"; - PARAM_CHECK("[mluOpLgamma]", x_desc->dim <= MLUOP_DIM_MAX); + PARAM_CHECK("[mluOpLgamma]", x_desc->getDim() <= MLUOP_DIM_MAX); mluop::TensorShape x_shape; mluop::TensorShape y_shape; mluop::getTensorShape(x_desc, &x_shape); mluop::getTensorShape(y_desc, &y_shape); CHECK_RETURN("[mluOpLgamma]", Kernel3StagePipelineWithStrideLgamma( - k_dim, k_type, handle->queue, x_desc->dtype, x, x_shape, y, + k_dim, k_type, handle->queue, x_desc->getDtype(), x, x_shape, y, y_shape, element_num)); } else { VLOG(5) << "kernel Kernel3StagePipelineLgamma."; CHECK_RETURN("[mluOpLgamma]", Kernel3StagePipelineLgamma(k_dim, k_type, handle->queue, - x_desc->dtype, x, y, element_num)); + x_desc->getDtype(), x, y, element_num)); } GEN_CASE_END(); diff --git a/kernels/log/log.cpp b/kernels/log/log.cpp index b27a2e535..3be31632c 100644 --- a/kernels/log/log.cpp +++ b/kernels/log/log.cpp @@ -99,7 +99,7 @@ mluOpLog(mluOpHandle_t handle, const mluOpComputationPreference_t prefer, size_t element_num = mluOpGetTensorElementNum(x_desc); VLOG(5) << "kernel Kernel3StagePipelineLog."; CHECK_RETURN("[mluOpLog] ", (Kernel3StagePipelineLog( - k_dim, k_type, handle->queue, x_desc->dtype, + k_dim, k_type, handle->queue, x_desc->getDtype(), prefer, x, y, element_num, coef))); GEN_CASE_END(); return MLUOP_STATUS_SUCCESS; diff --git a/kernels/logspace/logspace.cpp b/kernels/logspace/logspace.cpp index d898dd65f..86ae562c1 100644 --- a/kernels/logspace/logspace.cpp +++ b/kernels/logspace/logspace.cpp @@ -65,7 +65,7 @@ mluOpStatus_t LogspaceParamCheck(const mluOpHandle_t &handle, const float start, PARAM_CHECK("[mluOpLogspace]", steps <= element_num); mluOpDataType_t support_type[3] = {MLUOP_DTYPE_FLOAT, MLUOP_DTYPE_HALF, MLUOP_DTYPE_INT32}; - if (!isSupportType(res_desc->dtype, support_type, 3)) { + if (!isSupportType(res_desc->getDtype(), support_type, 3)) { LOG(ERROR) << "[mluOpLogspace]" << ":res_desc's data type is not supported."; return MLUOP_STATUS_BAD_PARAM; @@ -110,7 +110,7 @@ mluOpLogspace(mluOpHandle_t handle, const float start, const float end, VLOG(5) << "kernel KernelLogspace."; CHECK_RETURN("[mluOpLogspace] ", - KernelLogspace(k_dim, k_type, handle->queue, res_desc->dtype, + KernelLogspace(k_dim, k_type, handle->queue, res_desc->getDtype(), start, end, steps, base, res)); GEN_CASE_END(); return MLUOP_STATUS_SUCCESS; diff --git a/kernels/masked_im2col/masked_col2im_forward/masked_col2im_forward.cpp b/kernels/masked_im2col/masked_col2im_forward/masked_col2im_forward.cpp index f36668071..656895dbf 100644 --- a/kernels/masked_im2col/masked_col2im_forward/masked_col2im_forward.cpp +++ b/kernels/masked_im2col/masked_col2im_forward/masked_col2im_forward.cpp @@ -54,28 +54,28 @@ static mluOpStatus_t maskedCol2imForwardPreCheck( PARAM_CHECK("[mluOpMaskedCol2imForward]", mask_h_idx_desc != NULL); PARAM_CHECK("[mluOpMaskedCol2imForward]", mask_w_idx_desc != NULL); PARAM_CHECK("[mluOpMaskedCol2imForward]", im_desc != NULL); - PARAM_CHECK("[mluOpMaskedCol2imForward]", col_desc->dim == 2); - PARAM_CHECK("[mluOpMaskedCol2imForward]", im_desc->dim == 4); - PARAM_CHECK("[mluOpMaskedCol2imForward]", mask_h_idx_desc->dim == 1); - PARAM_CHECK("[mluOpMaskedCol2imForward]", mask_w_idx_desc->dim == 1); + PARAM_CHECK("[mluOpMaskedCol2imForward]", col_desc->getDim() == 2); + PARAM_CHECK("[mluOpMaskedCol2imForward]", im_desc->getDim() == 4); + PARAM_CHECK("[mluOpMaskedCol2imForward]", mask_h_idx_desc->getDim() == 1); + PARAM_CHECK("[mluOpMaskedCol2imForward]", mask_w_idx_desc->getDim() == 1); PARAM_CHECK("[mluOpMaskedCol2imForward]", - im_desc->layout == MLUOP_LAYOUT_NCHW); + im_desc->getLayout() == MLUOP_LAYOUT_NCHW); PARAM_CHECK("[mluOpMaskedCol2imForward]", - col_desc->dtype == MLUOP_DTYPE_FLOAT || - col_desc->dtype == MLUOP_DTYPE_HALF); - PARAM_CHECK("[mluOpMaskedCol2imForward]", col_desc->dtype == im_desc->dtype); + col_desc->getDtype() == MLUOP_DTYPE_FLOAT || + col_desc->getDtype() == MLUOP_DTYPE_HALF); + PARAM_CHECK("[mluOpMaskedCol2imForward]", col_desc->getDtype() == im_desc->getDtype()); PARAM_CHECK("[mluOpMaskedCol2imForward]", - mask_h_idx_desc->dtype == MLUOP_DTYPE_INT32); + mask_h_idx_desc->getDtype() == MLUOP_DTYPE_INT32); PARAM_CHECK("[mluOpMaskedCol2imForward]", - mask_w_idx_desc->dtype == MLUOP_DTYPE_INT32); - PARAM_CHECK("[mluOpMaskedCol2imForward]", im_desc->dims[0] == 1); + mask_w_idx_desc->getDtype() == MLUOP_DTYPE_INT32); + PARAM_CHECK("[mluOpMaskedCol2imForward]", im_desc->getDimIndex(0) == 1); PARAM_CHECK("[mluOpMaskedCol2imForward]", - mask_h_idx_desc->dims[0] == mask_w_idx_desc->dims[0]); + mask_h_idx_desc->getDimIndex(0) == mask_w_idx_desc->getDimIndex(0)); PARAM_CHECK("[mluOpMaskedCol2imForward]", - col_desc->dims[1] == mask_h_idx_desc->dims[0]); + col_desc->getDimIndex(1) == mask_h_idx_desc->getDimIndex(0)); PARAM_CHECK("[mluOpMaskedCol2imForward]", - col_desc->dims[0] == im_desc->dims[1]); + col_desc->getDimIndex(0) == im_desc->getDimIndex(1)); // stride check STRIDE_TENSOR_CHECK("[mluOpMaskedCol2imForward]:", col_desc, "col_desc must be contiguous"); @@ -112,7 +112,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpGetMaskedCol2imForwardWorkspaceSize( if (MLUOP_STATUS_SUCCESS != status) { return status; } - if (mluOpGetTensorElementNum(im_desc) == 0 || col_desc->dims[0] == 0) { + if (mluOpGetTensorElementNum(im_desc) == 0 || col_desc->getDimIndex(0) == 0) { LOG(ERROR) << "[mluOpMaskedCol2imForward] Zero element tensor failure."; return MLUOP_STATUS_BAD_PARAM; } @@ -120,16 +120,16 @@ mluOpStatus_t MLUOP_WIN_API mluOpGetMaskedCol2imForwardWorkspaceSize( VLOG(5) << "[mluOpMaskedCol2imForward] Skip zero element tensor."; return MLUOP_STATUS_SUCCESS; } - *workspace_size = col_desc->total_tensor_size; - *workspace_size += im_desc->total_tensor_size; + *workspace_size = col_desc->getTotalTensorSize(); + *workspace_size += im_desc->getTotalTensorSize(); cnnlTransposeDescriptor_t trans_desc; size_t col_transpose_workspace_size = 0; - int col_dim = col_desc->dim; + int col_dim = col_desc->getDim(); int col_permute[2] = {1, 0}; int col_MC_dims[2] = {0, 0}; - col_MC_dims[0] = col_desc->dims[1]; - col_MC_dims[1] = col_desc->dims[0]; + col_MC_dims[0] = col_desc->getDimIndex(1); + col_MC_dims[1] = col_desc->getDimIndex(0); mluOpTensorDescriptor_t col_MC_desc_tmp; CHECK_RETURN("[mluOpGetMaskedCol2imForwardWorkspaceSize]", mluOpCreateTensorDescriptor(&col_MC_desc_tmp)); @@ -138,7 +138,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpGetMaskedCol2imForwardWorkspaceSize( "[mluOpMaskedCol2imForward]", MLUOP_STATUS_SUCCESS == mluOpSetTensorDescriptor(col_MC_desc_tmp, MLUOP_LAYOUT_ARRAY, - col_desc->dtype, col_dim, col_MC_dims)); + col_desc->getDtype(), col_dim, col_MC_dims)); CALL_CNNL(cnnlCreateTransposeDescriptor(&trans_desc)); CALL_CNNL(cnnlSetTransposeDescriptor(trans_desc, col_dim, col_permute)); { @@ -149,12 +149,12 @@ mluOpStatus_t MLUOP_WIN_API mluOpGetMaskedCol2imForwardWorkspaceSize( DESTROY_CNNL_TENSOR_DESCRIPTOR(cnnl_x_desc); DESTROY_CNNL_HANDLE(cnnl_handle); } - int im_dim = im_desc->dim; + int im_dim = im_desc->getDim(); int im_permute[4] = {0, 3, 1, 2}; int NCHW2NHWC_permute[4] = {0, 2, 3, 1}; int im_NHWC_dims[4] = {0, 0, 0, 0}; for (int i = 0; i < im_dim; ++i) { - im_NHWC_dims[i] = im_desc->dims[NCHW2NHWC_permute[i]]; + im_NHWC_dims[i] = im_desc->getDimIndex(NCHW2NHWC_permute[i]); } size_t im_transpose_workspace_size = 0; mluOpTensorDescriptor_t im_NHWC_desc_tmp; @@ -163,7 +163,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpGetMaskedCol2imForwardWorkspaceSize( CHECK_RETURN("[mluOpMaskedCol2imForward]", mluOpSetTensorDescriptor(im_NHWC_desc_tmp, MLUOP_LAYOUT_ARRAY, - im_desc->dtype, im_dim, im_NHWC_dims)); + im_desc->getDtype(), im_dim, im_NHWC_dims)); CALL_CNNL(cnnlSetTransposeDescriptor(trans_desc, im_dim, im_permute)); { DEFINE_CREATE_AND_SET_CNNL_HANDLE(handle, cnnl_handle); @@ -189,7 +189,7 @@ static mluOpStatus_t transposeTensor( const void *input, const int *permute, const mluOpTensorDescriptor_t workspace_dst_desc, void *workspace_dst, void *transpose_workspace) { - const int input_dim = input_desc->dim; + const int input_dim = input_desc->getDim(); cnnlTransposeDescriptor_t trans_desc; size_t transpose_workspace_size = 0; CALL_CNNL(cnnlCreateTransposeDescriptor(&trans_desc)); @@ -231,7 +231,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpMaskedCol2imForward( if (MLUOP_STATUS_SUCCESS != status) { return status; } - if (mluOpGetTensorElementNum(im_desc) == 0 || col_desc->dims[0] == 0) { + if (mluOpGetTensorElementNum(im_desc) == 0 || col_desc->getDimIndex(0) == 0) { LOG(ERROR) << "[mluOpMaskedCol2imForward] Zero element tensor failure."; return MLUOP_STATUS_BAD_PARAM; } @@ -254,8 +254,8 @@ mluOpStatus_t MLUOP_WIN_API mluOpMaskedCol2imForward( PARAM_CHECK("[mluOpMaskedCol2imForward]", mask_w_idx != NULL); PARAM_CHECK("[mluOpMaskedCol2imForward]", im != NULL); - const int height = im_desc->dims[2]; - const int width = im_desc->dims[3]; + const int height = im_desc->getDimIndex(2); + const int width = im_desc->getDimIndex(3); // generate mluOpMaskedCol2imForward prototxt start! if (MLUOP_GEN_CASE_ON_NEW) { GEN_CASE_START("masked_col2im_forward", "MASKED_COL2IM_FORWARD"); @@ -267,30 +267,30 @@ mluOpStatus_t MLUOP_WIN_API mluOpMaskedCol2imForward( GEN_CASE_TEST_PARAM_NEW(false, false, true, 0, 0, 0); } // generate mluOpMaskedCol2imForward prototxt end! - mluOpDataType_t input_dtype = col_desc->dtype; + mluOpDataType_t input_dtype = col_desc->getDtype(); void *col_workspace = workspace; - void *im_workspace = (int8_t *)workspace + col_desc->total_tensor_size; + void *im_workspace = (int8_t *)workspace + col_desc->getTotalTensorSize(); void *transpose_workspace = - (int8_t *)im_workspace + im_desc->total_tensor_size; + (int8_t *)im_workspace + im_desc->getTotalTensorSize(); cnrtDim3_t k_dim; cnrtFunctionType_t k_type; - const int mask_cnt = mask_h_idx_desc->dims[0]; + const int mask_cnt = mask_h_idx_desc->getDimIndex(0); policyFunc(handle, mask_cnt, &k_dim, &k_type); VLOG(5) << "[mluOpMaskedCol2imForward] cnnlFill_v3 start."; - const int im_dim = im_desc->dim; + const int im_dim = im_desc->getDim(); int NCHW2NHWC_permute[4] = {0, 2, 3, 1}; int im_NHWC_dims[4] = {0, 0, 0, 0}; for (int i = 0; i < im_dim; ++i) { - im_NHWC_dims[i] = im_desc->dims[NCHW2NHWC_permute[i]]; + im_NHWC_dims[i] = im_desc->getDimIndex(NCHW2NHWC_permute[i]); } mluOpTensorDescriptor_t im_NHWC_desc_tmp; CHECK_RETURN("[mluOpMaskedCol2imForward]", mluOpCreateTensorDescriptor(&im_NHWC_desc_tmp)); CHECK_RETURN("[mluOpMaskedCol2imForward]", mluOpSetTensorDescriptor(im_NHWC_desc_tmp, MLUOP_LAYOUT_ARRAY, - im_desc->dtype, im_dim, im_NHWC_dims)); + im_desc->getDtype(), im_dim, im_NHWC_dims)); uint64_t fill_value = 0x0; { DEFINE_CREATE_AND_SET_CNNL_HANDLE(handle, cnnl_handle); @@ -305,17 +305,17 @@ mluOpStatus_t MLUOP_WIN_API mluOpMaskedCol2imForward( VLOG(5) << "[mluOpMaskedCol2imForward] cnnlTranspose_v2 col start."; - int col_dim = col_desc->dim; + int col_dim = col_desc->getDim(); int col_permute[2] = {1, 0}; int col_MC_dims[2] = {0, 0}; - col_MC_dims[0] = col_desc->dims[1]; - col_MC_dims[1] = col_desc->dims[0]; + col_MC_dims[0] = col_desc->getDimIndex(1); + col_MC_dims[1] = col_desc->getDimIndex(0); mluOpTensorDescriptor_t col_MC_desc_tmp; CHECK_RETURN("[mluOpMaskedCol2imForward]", mluOpCreateTensorDescriptor(&col_MC_desc_tmp)); CHECK_RETURN("[mluOpMaskedCol2imForward]", mluOpSetTensorDescriptor(col_MC_desc_tmp, MLUOP_LAYOUT_ARRAY, - col_desc->dtype, col_dim, col_MC_dims)); + col_desc->getDtype(), col_dim, col_MC_dims)); CHECK_RETURN( "[mluOpMaskedCol2imForward]", transposeTensor(handle, col_desc, col, col_permute, col_MC_desc_tmp, @@ -324,7 +324,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpMaskedCol2imForward( mluOpDestroyTensorDescriptor(col_MC_desc_tmp)); VLOG(5) << "[mluOpMaskedCol2imForward] cnnlTranspose_v2 col end."; - const int channels = im_desc->dims[1]; + const int channels = im_desc->getDimIndex(1); VLOG(5) << "Launch kernel MLUUnion1MaskedCol2imForward<<<" << k_dim.x << ", " << k_dim.y << ", " << k_dim.z << ">>>."; CHECK_RETURN("[mluOpMaskedCol2imForward]", diff --git a/kernels/masked_im2col/masked_im2col_forward/masked_im2col_forward.cpp b/kernels/masked_im2col/masked_im2col_forward/masked_im2col_forward.cpp index d1bd663a7..c01a9bb48 100644 --- a/kernels/masked_im2col/masked_im2col_forward/masked_im2col_forward.cpp +++ b/kernels/masked_im2col/masked_im2col_forward/masked_im2col_forward.cpp @@ -56,28 +56,28 @@ static mluOpStatus_t maskedIm2colForwardPreCheck( PARAM_CHECK("[mluOpMaskedIm2colForward]", data_col_desc != NULL); PARAM_CHECK("[mluOpMaskedIm2colForward]", - feature_desc->layout == MLUOP_LAYOUT_NCHW); - PARAM_CHECK("[mluOpMaskedIm2colForward]", feature_desc->dim == 4); + feature_desc->getLayout() == MLUOP_LAYOUT_NCHW); + PARAM_CHECK("[mluOpMaskedIm2colForward]", feature_desc->getDim() == 4); PARAM_CHECK("[mluOpMaskedIm2colForward]", - feature_desc->dtype == MLUOP_DTYPE_FLOAT || - feature_desc->dtype == MLUOP_DTYPE_HALF); + feature_desc->getDtype() == MLUOP_DTYPE_FLOAT || + feature_desc->getDtype() == MLUOP_DTYPE_HALF); PARAM_CHECK("[mluOpMaskedIm2colForward]", - feature_desc->dtype == data_col_desc->dtype); + feature_desc->getDtype() == data_col_desc->getDtype()); PARAM_CHECK("[mluOpMaskedIm2colForward]", - mask_h_idx_desc->dtype == MLUOP_DTYPE_INT32); + mask_h_idx_desc->getDtype() == MLUOP_DTYPE_INT32); PARAM_CHECK("[mluOpMaskedIm2colForward]", - mask_w_idx_desc->dtype == MLUOP_DTYPE_INT32); - PARAM_CHECK("[mluOpMaskedIm2colForward]", feature_desc->dims[0] == 1); - PARAM_CHECK("[mluOpMaskedIm2colForward]", mask_h_idx_desc->dim == 1); - PARAM_CHECK("[mluOpMaskedIm2colForward]", mask_w_idx_desc->dim == 1); + mask_w_idx_desc->getDtype() == MLUOP_DTYPE_INT32); + PARAM_CHECK("[mluOpMaskedIm2colForward]", feature_desc->getDimIndex(0) == 1); + PARAM_CHECK("[mluOpMaskedIm2colForward]", mask_h_idx_desc->getDim() == 1); + PARAM_CHECK("[mluOpMaskedIm2colForward]", mask_w_idx_desc->getDim() == 1); PARAM_CHECK("[mluOpMaskedIm2colForward]", - mask_h_idx_desc->dims[0] == mask_w_idx_desc->dims[0]); - PARAM_CHECK("[mluOpMaskedIm2colForward]", data_col_desc->dim == 2); + mask_h_idx_desc->getDimIndex(0) == mask_w_idx_desc->getDimIndex(0)); + PARAM_CHECK("[mluOpMaskedIm2colForward]", data_col_desc->getDim() == 2); PARAM_CHECK( "[mluOpMaskedIm2colForward]", - data_col_desc->dims[0] == feature_desc->dims[1] * kernel_h * kernel_w); + data_col_desc->getDimIndex(0) == feature_desc->getDimIndex(1) * kernel_h * kernel_w); PARAM_CHECK("[mluOpMaskedIm2colForward]", - data_col_desc->dims[1] == mask_h_idx_desc->dims[0]); + data_col_desc->getDimIndex(1) == mask_h_idx_desc->getDimIndex(0)); PARAM_CHECK("[mluOpMaskedIm2colForward]", kernel_h > 0); PARAM_CHECK("[mluOpMaskedIm2colForward]", kernel_w > 0); @@ -119,7 +119,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpGetMaskedIm2colForwardWorkspaceSize( return status; } if (mluOpGetTensorElementNum(feature_desc) == 0 || - data_col_desc->dims[0] == 0) { + data_col_desc->getDimIndex(0) == 0) { LOG(ERROR) << "[mluOpMaskedIm2colForward] Zero element tensor failure."; return MLUOP_STATUS_BAD_PARAM; } @@ -127,12 +127,12 @@ mluOpStatus_t MLUOP_WIN_API mluOpGetMaskedIm2colForwardWorkspaceSize( VLOG(5) << "[mluOpMaskedIm2colForward] Skip zero element tensor."; return MLUOP_STATUS_SUCCESS; } - *workspace_size = feature_desc->total_tensor_size; - *workspace_size += data_col_desc->total_tensor_size; + *workspace_size = feature_desc->getTotalTensorSize(); + *workspace_size += data_col_desc->getTotalTensorSize(); cnnlTransposeDescriptor_t trans_desc; size_t feature_transpose_workspace_size = 0; - int feature_dim = feature_desc->dim; + int feature_dim = feature_desc->getDim(); int feature_permute[4] = {0, 3, 1, 2}; CALL_CNNL(cnnlCreateTransposeDescriptor(&trans_desc)); @@ -148,7 +148,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpGetMaskedIm2colForwardWorkspaceSize( DESTROY_CNNL_HANDLE(cnnl_handle); } if (mluOpGetTensorElementNum(feature_desc) == 0 || - data_col_desc->dims[0] == 0) { + data_col_desc->getDimIndex(0) == 0) { VLOG(5) << "[mluOpMaskedIm2colForward] Zero element tensor failure."; return MLUOP_STATUS_BAD_PARAM; } @@ -156,9 +156,9 @@ mluOpStatus_t MLUOP_WIN_API mluOpGetMaskedIm2colForwardWorkspaceSize( int data_col_permute[3] = {2, 1, 0}; int data_col_HWC_dims[3] = {0, 0, 0}; int data_col_CHW_dims[3] = {0, 0, 0}; - data_col_HWC_dims[0] = mask_h_idx_desc->dims[0]; + data_col_HWC_dims[0] = mask_h_idx_desc->getDimIndex(0); data_col_HWC_dims[1] = kernel_h * kernel_w; - data_col_HWC_dims[2] = feature_desc->dims[1]; + data_col_HWC_dims[2] = feature_desc->getDimIndex(1); for (int i = 0; i < data_col_dim; ++i) { data_col_CHW_dims[i] = data_col_HWC_dims[data_col_permute[i]]; } @@ -169,7 +169,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpGetMaskedIm2colForwardWorkspaceSize( CHECK_RETURN("[mluOpMaskedIm2colForward]", mluOpSetTensorDescriptor(data_col_HWC_desc_tmp, - MLUOP_LAYOUT_ARRAY, feature_desc->dtype, + MLUOP_LAYOUT_ARRAY, feature_desc->getDtype(), data_col_dim, data_col_HWC_dims)); CALL_CNNL( cnnlSetTransposeDescriptor(trans_desc, data_col_dim, data_col_permute)); @@ -198,7 +198,7 @@ static mluOpStatus_t transposeTensor( const void *input, const int *permute, const mluOpTensorDescriptor_t workspace_dst_desc, void *workspace_dst, void *transpose_workspace) { - int input_dim = input_desc->dim; + int input_dim = input_desc->getDim(); cnnlTransposeDescriptor_t trans_desc; size_t transpose_workspace_size = 0; CALL_CNNL(cnnlCreateTransposeDescriptor(&trans_desc)); @@ -244,7 +244,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpMaskedIm2colForward( } if (mluOpGetTensorElementNum(feature_desc) == 0 || - data_col_desc->dims[0] == 0) { + data_col_desc->getDimIndex(0) == 0) { LOG(ERROR) << "[mluOpMaskedIm2colForward] Zero element tensor failure."; return MLUOP_STATUS_BAD_PARAM; } @@ -260,8 +260,8 @@ mluOpStatus_t MLUOP_WIN_API mluOpMaskedIm2colForward( PARAM_CHECK("[mluOpMaskedIm2colForward]", mask_w_idx != NULL); PARAM_CHECK("[mluOpMaskedIm2colForward]", data_col != NULL); - const int height = feature_desc->dims[2]; - const int width = feature_desc->dims[3]; + const int height = feature_desc->getDimIndex(2); + const int width = feature_desc->getDimIndex(3); // generate mluOpMaskedIm2colForward prototxt start! if (MLUOP_GEN_CASE_ON_NEW) { @@ -280,16 +280,16 @@ mluOpStatus_t MLUOP_WIN_API mluOpMaskedIm2colForward( GEN_CASE_TEST_PARAM_NEW(false, false, true, 0, 0, 0); } // generate mluOpMaskedIm2colForward prototxt end! - mluOpDataType_t input_dtype = feature_desc->dtype; + mluOpDataType_t input_dtype = feature_desc->getDtype(); void *feature_workspace = workspace; void *data_col_workspace = - (int8_t *)workspace + feature_desc->total_tensor_size; + (int8_t *)workspace + feature_desc->getTotalTensorSize(); void *transpose_workspace = - (int8_t *)data_col_workspace + data_col_desc->total_tensor_size; + (int8_t *)data_col_workspace + data_col_desc->getTotalTensorSize(); cnrtDim3_t k_dim; cnrtFunctionType_t k_type; - const int mask_cnt = mask_h_idx_desc->dims[0]; + const int mask_cnt = mask_h_idx_desc->getDimIndex(0); policyFunc(handle, mask_cnt, &k_dim, &k_type); VLOG(5) << "[mluOpMaskedIm2colForward] cnnlFill_v3 start."; @@ -306,12 +306,12 @@ mluOpStatus_t MLUOP_WIN_API mluOpMaskedIm2colForward( VLOG(5) << "[mluOpMaskedIm2colForward] cnnlTranspose_v2 feature start."; - int feature_dim = feature_desc->dim; + int feature_dim = feature_desc->getDim(); int feature_permute[4] = {0, 2, 3, 1}; int feature_tmp_dims[4] = {0, 0, 0, 0}; for (int i = 0; i < feature_dim; ++i) { - feature_tmp_dims[i] = feature_desc->dims[feature_permute[i]]; + feature_tmp_dims[i] = feature_desc->getDimIndex(feature_permute[i]); } mluOpTensorDescriptor_t feature_desc_tmp; @@ -329,7 +329,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpMaskedIm2colForward( CHECK_RETURN("[mluOpMaskedIm2colForward]", mluOpDestroyTensorDescriptor(feature_desc_tmp)); - const int channels = feature_desc->dims[1]; + const int channels = feature_desc->getDimIndex(1); VLOG(5) << "Launch kernel MLUUnion1MaskedIm2colForward<<<" << k_dim.x << ", " << k_dim.y << ", " << k_dim.z << ">>>."; CHECK_RETURN("[mluOpMaskedIm2colForward]", diff --git a/kernels/moe_dispatch/moe_dispatch_backward_data/moe_dispatch_backward_data.cpp b/kernels/moe_dispatch/moe_dispatch_backward_data/moe_dispatch_backward_data.cpp index 67d4328b0..ac1ba186d 100644 --- a/kernels/moe_dispatch/moe_dispatch_backward_data/moe_dispatch_backward_data.cpp +++ b/kernels/moe_dispatch/moe_dispatch_backward_data/moe_dispatch_backward_data.cpp @@ -74,36 +74,36 @@ mluOpStatus_t MLUOP_WIN_API mluOpMoeDispatchBackwardData( PARAM_CHECK(API, grad_input_desc != NULL); // check dim - PARAM_CHECK_EQ(API, gates_desc->dim, 1); - PARAM_CHECK_EQ(API, indices_desc->dim, 1); - PARAM_CHECK_EQ(API, locations_desc->dim, 1); - PARAM_CHECK_EQ(API, dispatch_desc->dim, 2); - PARAM_CHECK_EQ(API, grad_input_desc->dim, 2); + PARAM_CHECK_EQ(API, gates_desc->getDim(), 1); + PARAM_CHECK_EQ(API, indices_desc->getDim(), 1); + PARAM_CHECK_EQ(API, locations_desc->getDim(), 1); + PARAM_CHECK_EQ(API, dispatch_desc->getDim(), 2); + PARAM_CHECK_EQ(API, grad_input_desc->getDim(), 2); // check shape - PARAM_CHECK_EQ(API, gates_desc->dims[0], samples); - PARAM_CHECK_EQ(API, indices_desc->dims[0], samples); - PARAM_CHECK_EQ(API, locations_desc->dims[0], samples); - PARAM_CHECK_EQ(API, dispatch_desc->dims[0], (num_experts * capacity)); - PARAM_CHECK_EQ(API, dispatch_desc->dims[1], hidden); - PARAM_CHECK_EQ(API, grad_input_desc->dims[0], samples); - PARAM_CHECK_EQ(API, grad_input_desc->dims[1], hidden); + PARAM_CHECK_EQ(API, gates_desc->getDimIndex(0), samples); + PARAM_CHECK_EQ(API, indices_desc->getDimIndex(0), samples); + PARAM_CHECK_EQ(API, locations_desc->getDimIndex(0), samples); + PARAM_CHECK_EQ(API, dispatch_desc->getDimIndex(0), (num_experts * capacity)); + PARAM_CHECK_EQ(API, dispatch_desc->getDimIndex(1), hidden); + PARAM_CHECK_EQ(API, grad_input_desc->getDimIndex(0), samples); + PARAM_CHECK_EQ(API, grad_input_desc->getDimIndex(1), hidden); // check dtype - PARAM_CHECK_V2(API, (gates_desc->dtype == MLUOP_DTYPE_FLOAT), + PARAM_CHECK_V2(API, (gates_desc->getDtype() == MLUOP_DTYPE_FLOAT), "Only float are supported in input tensor, but the " "data type of tensor is " - << mluOpGetNameOfDataType(gates_desc->dtype) << "."); - PARAM_CHECK_V2(API, (indices_desc->dtype == MLUOP_DTYPE_INT32), + << mluOpGetNameOfDataType(gates_desc->getDtype()) << "."); + PARAM_CHECK_V2(API, (indices_desc->getDtype() == MLUOP_DTYPE_INT32), "Only int32 are supported in indices tensor, but the data " "type of tensor is " - << mluOpGetNameOfDataType(indices_desc->dtype) << "."); - PARAM_CHECK_V2(API, (locations_desc->dtype == MLUOP_DTYPE_INT32), + << mluOpGetNameOfDataType(indices_desc->getDtype()) << "."); + PARAM_CHECK_V2(API, (locations_desc->getDtype() == MLUOP_DTYPE_INT32), "Only int32 are supported in locations tensor, but the data " "type of tensor is " - << mluOpGetNameOfDataType(locations_desc->dtype) << "."); - PARAM_CHECK(API, dispatch_desc->dtype == gates_desc->dtype); - PARAM_CHECK(API, grad_input_desc->dtype == gates_desc->dtype); + << mluOpGetNameOfDataType(locations_desc->getDtype()) << "."); + PARAM_CHECK(API, dispatch_desc->getDtype() == gates_desc->getDtype()); + PARAM_CHECK(API, grad_input_desc->getDtype() == gates_desc->getDtype()); // check tensor dim PARAM_CHECK(API, samples >= 0); @@ -207,7 +207,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpMoeDispatchBackwardData( << ", " << k_dim.x << ", " << k_dim.y << ", " << k_dim.z << ">>>" << "core num per cluster: " << core_num_per_cluster; - mluOpDataType_t data_type = grad_input_desc->dtype; + mluOpDataType_t data_type = grad_input_desc->getDtype(); uint32_t taskNum = k_dim.x * k_dim.y * k_dim.z; if (samples <= taskNum) { diff --git a/kernels/moe_dispatch/moe_dispatch_backward_gate/moe_dispatch_backward_gate.cpp b/kernels/moe_dispatch/moe_dispatch_backward_gate/moe_dispatch_backward_gate.cpp index 776c8b9e8..485345d1f 100644 --- a/kernels/moe_dispatch/moe_dispatch_backward_gate/moe_dispatch_backward_gate.cpp +++ b/kernels/moe_dispatch/moe_dispatch_backward_gate/moe_dispatch_backward_gate.cpp @@ -60,14 +60,14 @@ mluOpStatus_t MLUOP_WIN_API mluOpGetMoeDispatchBackwardGateWorkspaceSize( PARAM_CHECK("[mluOpMoeDispatchBackwardGate]", input_desc != NULL); PARAM_CHECK("[mluOpMoeDispatchBackwardGate]", workspace_size != NULL); - int samples = input_desc->dims[0]; + int samples = input_desc->getDimIndex(0); *workspace_size = 0; cnrtDim3_t k_dim; cnrtFunctionType_t k_type; policyFunc(handle, samples, &k_dim, &k_type); int taskNum = k_dim.x * k_dim.y * k_dim.z; if ((samples > 0) && (samples < taskNum)) { - *workspace_size = taskNum * mluop::getSizeOfDataType(input_desc->dtype); + *workspace_size = taskNum * mluop::getSizeOfDataType(input_desc->getDtype()); } return MLUOP_STATUS_SUCCESS; @@ -99,42 +99,42 @@ static mluOpStatus_t moeDispatchBackwardGateParamCheck( PARAM_CHECK(op_name, grad_gates_desc != NULL); // check shape - PARAM_CHECK(op_name, indices_desc->dim == 1); - PARAM_CHECK(op_name, locations_desc->dim == 1); - PARAM_CHECK(op_name, input_desc->dim == 2); - PARAM_CHECK(op_name, dispatch_desc->dim == 2); - PARAM_CHECK(op_name, grad_gates_desc->dim == 1); + PARAM_CHECK(op_name, indices_desc->getDim() == 1); + PARAM_CHECK(op_name, locations_desc->getDim() == 1); + PARAM_CHECK(op_name, input_desc->getDim() == 2); + PARAM_CHECK(op_name, dispatch_desc->getDim() == 2); + PARAM_CHECK(op_name, grad_gates_desc->getDim() == 1); // check data type - PARAM_CHECK_V2(op_name, (indices_desc->dtype == MLUOP_DTYPE_INT32), + PARAM_CHECK_V2(op_name, (indices_desc->getDtype() == MLUOP_DTYPE_INT32), "Only int32 are supported in indices tensor, but the data " "type of tensor is " - << mluOpGetNameOfDataType(indices_desc->dtype) << "."); - PARAM_CHECK_V2(op_name, (locations_desc->dtype == MLUOP_DTYPE_INT32), + << mluOpGetNameOfDataType(indices_desc->getDtype()) << "."); + PARAM_CHECK_V2(op_name, (locations_desc->getDtype() == MLUOP_DTYPE_INT32), "Only int32 are supported in locations tensor, but the data " "type of tensor is " - << mluOpGetNameOfDataType(locations_desc->dtype) << "."); + << mluOpGetNameOfDataType(locations_desc->getDtype()) << "."); // check tensor datatype, support float32 - PARAM_CHECK_V2(op_name, (input_desc->dtype == MLUOP_DTYPE_FLOAT), + PARAM_CHECK_V2(op_name, (input_desc->getDtype() == MLUOP_DTYPE_FLOAT), "Only float are supported in input tensor, but the " "data type of tensor is " - << mluOpGetNameOfDataType(input_desc->dtype) << "."); - PARAM_CHECK(op_name, input_desc->dtype == dispatch_desc->dtype); - PARAM_CHECK(op_name, input_desc->dtype == grad_gates_desc->dtype); + << mluOpGetNameOfDataType(input_desc->getDtype()) << "."); + PARAM_CHECK(op_name, input_desc->getDtype() == dispatch_desc->getDtype()); + PARAM_CHECK(op_name, input_desc->getDtype() == grad_gates_desc->getDtype()); // check dim PARAM_CHECK(op_name, samples >= 0); PARAM_CHECK(op_name, capacity >= 0); PARAM_CHECK(op_name, hidden >= 0); PARAM_CHECK(op_name, num_experts >= 0); - PARAM_CHECK(op_name, (samples == indices_desc->dims[0])); - PARAM_CHECK(op_name, (samples == locations_desc->dims[0])); - PARAM_CHECK(op_name, (samples == input_desc->dims[0])); - PARAM_CHECK(op_name, (samples == grad_gates_desc->dims[0])); - PARAM_CHECK(op_name, ((num_experts * capacity) == dispatch_desc->dims[0])); - PARAM_CHECK(op_name, (hidden == input_desc->dims[1])); - PARAM_CHECK(op_name, (hidden == dispatch_desc->dims[1])); + PARAM_CHECK(op_name, (samples == indices_desc->getDimIndex(0))); + PARAM_CHECK(op_name, (samples == locations_desc->getDimIndex(0))); + PARAM_CHECK(op_name, (samples == input_desc->getDimIndex(0))); + PARAM_CHECK(op_name, (samples == grad_gates_desc->getDimIndex(0))); + PARAM_CHECK(op_name, ((num_experts * capacity) == dispatch_desc->getDimIndex(0))); + PARAM_CHECK(op_name, (hidden == input_desc->getDimIndex(1))); + PARAM_CHECK(op_name, (hidden == dispatch_desc->getDimIndex(1))); // check stride STRIDE_TENSOR_CHECK(op_name + ":", indices_desc, @@ -249,7 +249,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpMoeDispatchBackwardGate( VLOG(5) << "Launch Kernel mluOpMoeDispatchBackwardGate<<>>"; - mluOpDataType_t data_type = input_desc->dtype; + mluOpDataType_t data_type = input_desc->getDtype(); uint32_t taskNum = k_dim.x * k_dim.y * k_dim.z; if (samples <= taskNum) { VLOG(5) << "[mluOpMoeDispatchBackwardGate] launch " diff --git a/kernels/moe_dispatch/moe_dispatch_forward/moe_dispatch_forward.cpp b/kernels/moe_dispatch/moe_dispatch_forward/moe_dispatch_forward.cpp index b1e3384fd..b981fa9e6 100644 --- a/kernels/moe_dispatch/moe_dispatch_forward/moe_dispatch_forward.cpp +++ b/kernels/moe_dispatch/moe_dispatch_forward/moe_dispatch_forward.cpp @@ -67,42 +67,42 @@ static mluOpStatus_t MoeDispatchForwardParamCheck( PARAM_CHECK(op_name, dispatch_desc != NULL); // check shape - PARAM_CHECK(op_name, gates_desc->dim == 1); - PARAM_CHECK(op_name, indices_desc->dim == 1); - PARAM_CHECK(op_name, locations_desc->dim == 1); - PARAM_CHECK(op_name, input_desc->dim == 2); - PARAM_CHECK(op_name, dispatch_desc->dim == 2); + PARAM_CHECK(op_name, gates_desc->getDim() == 1); + PARAM_CHECK(op_name, indices_desc->getDim() == 1); + PARAM_CHECK(op_name, locations_desc->getDim() == 1); + PARAM_CHECK(op_name, input_desc->getDim() == 2); + PARAM_CHECK(op_name, dispatch_desc->getDim() == 2); // check data type - PARAM_CHECK_V2(op_name, (indices_desc->dtype == MLUOP_DTYPE_INT32), + PARAM_CHECK_V2(op_name, (indices_desc->getDtype() == MLUOP_DTYPE_INT32), "Only int32 are supported in indices tensor, but the data " "type of tensor is " - << mluOpGetNameOfDataType(indices_desc->dtype) << "."); - PARAM_CHECK_V2(op_name, (locations_desc->dtype == MLUOP_DTYPE_INT32), + << mluOpGetNameOfDataType(indices_desc->getDtype()) << "."); + PARAM_CHECK_V2(op_name, (locations_desc->getDtype() == MLUOP_DTYPE_INT32), "Only int32 are supported in locations tensor, but the data " "type of tensor is " - << mluOpGetNameOfDataType(locations_desc->dtype) << "."); + << mluOpGetNameOfDataType(locations_desc->getDtype()) << "."); // check tensor datatype, support float32 - PARAM_CHECK_V2(op_name, input_desc->dtype == MLUOP_DTYPE_FLOAT, + PARAM_CHECK_V2(op_name, input_desc->getDtype() == MLUOP_DTYPE_FLOAT, "Only float are supported in input tensor, but the " "data type of tensor is " - << mluOpGetNameOfDataType(input_desc->dtype) << "."); - PARAM_CHECK(op_name, input_desc->dtype == dispatch_desc->dtype); - PARAM_CHECK(op_name, input_desc->dtype == gates_desc->dtype); + << mluOpGetNameOfDataType(input_desc->getDtype()) << "."); + PARAM_CHECK(op_name, input_desc->getDtype() == dispatch_desc->getDtype()); + PARAM_CHECK(op_name, input_desc->getDtype() == gates_desc->getDtype()); // check dim PARAM_CHECK(op_name, samples >= 0); PARAM_CHECK(op_name, capacity >= 0); PARAM_CHECK(op_name, hidden >= 0); PARAM_CHECK(op_name, num_experts >= 0); - PARAM_CHECK(op_name, (samples == gates_desc->dims[0])); - PARAM_CHECK(op_name, (samples == indices_desc->dims[0])); - PARAM_CHECK(op_name, (samples == locations_desc->dims[0])); - PARAM_CHECK(op_name, (samples == input_desc->dims[0])); - PARAM_CHECK(op_name, ((num_experts * capacity) == dispatch_desc->dims[0])); - PARAM_CHECK(op_name, (hidden == input_desc->dims[1])); - PARAM_CHECK(op_name, (hidden == dispatch_desc->dims[1])); + PARAM_CHECK(op_name, (samples == gates_desc->getDimIndex(0))); + PARAM_CHECK(op_name, (samples == indices_desc->getDimIndex(0))); + PARAM_CHECK(op_name, (samples == locations_desc->getDimIndex(0))); + PARAM_CHECK(op_name, (samples == input_desc->getDimIndex(0))); + PARAM_CHECK(op_name, ((num_experts * capacity) == dispatch_desc->getDimIndex(0))); + PARAM_CHECK(op_name, (hidden == input_desc->getDimIndex(1))); + PARAM_CHECK(op_name, (hidden == dispatch_desc->getDimIndex(1))); // check stride STRIDE_TENSOR_CHECK(op_name + ":", gates_desc, @@ -201,7 +201,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpMoeDispatchForward( VLOG(5) << "Launch kernel mluOpMoeDispatchForward<<>>"; - mluOpDataType_t data_type = input_desc->dtype; + mluOpDataType_t data_type = input_desc->getDtype(); VLOG(5) << "[mluOpMoeDispatchForward] launch " "KernelMoeDispatchForward"; CHECK_RETURN( diff --git a/kernels/ms_deform_attn/ms_deform_attn_backward/ms_deform_attn_backward.cpp b/kernels/ms_deform_attn/ms_deform_attn_backward/ms_deform_attn_backward.cpp index 778535274..b2e21aa46 100644 --- a/kernels/ms_deform_attn/ms_deform_attn_backward/ms_deform_attn_backward.cpp +++ b/kernels/ms_deform_attn/ms_deform_attn_backward/ms_deform_attn_backward.cpp @@ -120,15 +120,15 @@ static mluOpStatus_t msDeformAttnBackwardParamCheck( PARAM_CHECK(API, grad_attn_weight_desc != NULL); // check dim - PARAM_CHECK(API, value_desc->dim == 4); - PARAM_CHECK(API, spatial_shapes_desc->dim == 2); - PARAM_CHECK(API, level_start_index_desc->dim == 1); - PARAM_CHECK(API, sampling_loc_desc->dim == 6); - PARAM_CHECK(API, attn_weight_desc->dim == 5); - PARAM_CHECK(API, grad_output_desc->dim == 4); - PARAM_CHECK(API, grad_value_desc->dim == 4); - PARAM_CHECK(API, grad_sampling_loc_desc->dim == 6); - PARAM_CHECK(API, grad_attn_weight_desc->dim == 5); + PARAM_CHECK(API, value_desc->getDim() == 4); + PARAM_CHECK(API, spatial_shapes_desc->getDim() == 2); + PARAM_CHECK(API, level_start_index_desc->getDim() == 1); + PARAM_CHECK(API, sampling_loc_desc->getDim() == 6); + PARAM_CHECK(API, attn_weight_desc->getDim() == 5); + PARAM_CHECK(API, grad_output_desc->getDim() == 4); + PARAM_CHECK(API, grad_value_desc->getDim() == 4); + PARAM_CHECK(API, grad_sampling_loc_desc->getDim() == 6); + PARAM_CHECK(API, grad_attn_weight_desc->getDim() == 5); // check stride STRIDE_TENSOR_CHECK("[mluOpMsDeformAttnBackward]:", value_desc, @@ -151,86 +151,86 @@ static mluOpStatus_t msDeformAttnBackwardParamCheck( "grad_attn_weight_desc must be contiguous"); // check datatype - PARAM_CHECK(API, value_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(API, spatial_shapes_desc->dtype == MLUOP_DTYPE_INT32); - PARAM_CHECK(API, level_start_index_desc->dtype == MLUOP_DTYPE_INT32); - PARAM_CHECK(API, sampling_loc_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(API, attn_weight_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(API, grad_output_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(API, grad_value_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(API, grad_sampling_loc_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(API, grad_attn_weight_desc->dtype == MLUOP_DTYPE_FLOAT); - - const int32_t num_key = value_desc->dims[1]; - const int32_t channels = value_desc->dims[3]; - const int32_t batch = attn_weight_desc->dims[0]; - const int32_t num_query = attn_weight_desc->dims[1]; - const int32_t num_heads = attn_weight_desc->dims[2]; - const int32_t num_levels = attn_weight_desc->dims[3]; - const int32_t num_points = attn_weight_desc->dims[4]; + PARAM_CHECK(API, value_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(API, spatial_shapes_desc->getDtype() == MLUOP_DTYPE_INT32); + PARAM_CHECK(API, level_start_index_desc->getDtype() == MLUOP_DTYPE_INT32); + PARAM_CHECK(API, sampling_loc_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(API, attn_weight_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(API, grad_output_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(API, grad_value_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(API, grad_sampling_loc_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(API, grad_attn_weight_desc->getDtype() == MLUOP_DTYPE_FLOAT); + + const int32_t num_key = value_desc->getDimIndex(1); + const int32_t channels = value_desc->getDimIndex(3); + const int32_t batch = attn_weight_desc->getDimIndex(0); + const int32_t num_query = attn_weight_desc->getDimIndex(1); + const int32_t num_heads = attn_weight_desc->getDimIndex(2); + const int32_t num_levels = attn_weight_desc->getDimIndex(3); + const int32_t num_points = attn_weight_desc->getDimIndex(4); // check input param const int32_t im2col_step_ = MIN(batch, im2col_step); std::string im2col_step_str = - "batch = attn_weight_desc->dims[0], " + "batch = attn_weight_desc->getDimIndex(0), " "im2col_step_ = MIN(batch, im2col_step)."; PARAM_CHECK_V2(API, im2col_step_ > 0, << im2col_step_str); PARAM_CHECK_V2(API, batch % im2col_step_ == 0, << im2col_step_str); // check all the input relationship - for (int32_t i = 0; i < value_desc->dim; ++i) { - if (value_desc->dims[i] != grad_value_desc->dims[i]) { + for (int32_t i = 0; i < value_desc->getDim(); ++i) { + if (value_desc->getDimIndex(i) != grad_value_desc->getDimIndex(i)) { LOG(ERROR) << "[mluOpMsDeformAttnBackward] The shape of value should be " "the same as grad_value." - << " But now value_desc->dims[" << i << "] is " - << value_desc->dims[i] << ", and grad_value_desc->dims[" << i - << "] is " << grad_value_desc->dims[i] << "."; + << " But now value_desc->getDimIndex(" << i << ") is " + << value_desc->getDimIndex(i) << ", and grad_value_desc->dims[" << i + << "] is " << grad_value_desc->getDimIndex(i) << "."; return MLUOP_STATUS_BAD_PARAM; } } - for (int32_t i = 0; i < sampling_loc_desc->dim; ++i) { - if (sampling_loc_desc->dims[i] != grad_sampling_loc_desc->dims[i]) { + for (int32_t i = 0; i < sampling_loc_desc->getDim(); ++i) { + if (sampling_loc_desc->getDimIndex(i) != grad_sampling_loc_desc->getDimIndex(i)) { LOG(ERROR) << "[mluOpMsDeformAttnBackward] The shape of " "sampling_loc_desc should be the " "same as grad_sampling_loc_desc." - << " But now sampling_loc_desc->dims[" << i << "] is " - << sampling_loc_desc->dims[i] - << ", and grad_sampling_loc_desc->dims[" << i << "] is " - << grad_sampling_loc_desc->dims[i] << "."; + << " But now sampling_loc_desc->getDimIndex(" << i << ") is " + << sampling_loc_desc->getDimIndex(i) + << ", and grad_sampling_loc_desc->getDimIndex(" << i << ") is " + << grad_sampling_loc_desc->getDimIndex(i) << "."; return MLUOP_STATUS_BAD_PARAM; } } - for (int32_t i = 0; i < attn_weight_desc->dim; ++i) { - if (attn_weight_desc->dims[i] != grad_attn_weight_desc->dims[i]) { + for (int32_t i = 0; i < attn_weight_desc->getDim(); ++i) { + if (attn_weight_desc->getDimIndex(i) != grad_attn_weight_desc->getDimIndex(i)) { LOG(ERROR) << "[mluOpMsDeformAttnBackward] The shape of " "attn_weight_desc should be the " "same as grad_attn_weight_desc." - << " But now attn_weight_desc->dims[" << i << "] is " - << attn_weight_desc->dims[i] - << ", and grad_attn_weight_desc->dims[" << i << "] is " - << grad_attn_weight_desc->dims[i] << "."; + << " But now attn_weight_desc->getDimIndex(" << i << ") is " + << attn_weight_desc->getDimIndex(i) + << ", and grad_attn_weight_desc->getDimIndex(" << i << ") is " + << grad_attn_weight_desc->getDimIndex(i) << "."; return MLUOP_STATUS_BAD_PARAM; } } - PARAM_CHECK_EQ(API, value_desc->dims[0], attn_weight_desc->dims[0]); - PARAM_CHECK_EQ(API, value_desc->dims[2], attn_weight_desc->dims[2]); + PARAM_CHECK_EQ(API, value_desc->getDimIndex(0), attn_weight_desc->getDimIndex(0)); + PARAM_CHECK_EQ(API, value_desc->getDimIndex(2), attn_weight_desc->getDimIndex(2)); - PARAM_CHECK_EQ(API, spatial_shapes_desc->dims[0], attn_weight_desc->dims[3]); - PARAM_CHECK_EQ(API, spatial_shapes_desc->dims[1], 2); + PARAM_CHECK_EQ(API, spatial_shapes_desc->getDimIndex(0), attn_weight_desc->getDimIndex(3)); + PARAM_CHECK_EQ(API, spatial_shapes_desc->getDimIndex(1), 2); - PARAM_CHECK_EQ(API, level_start_index_desc->dims[0], - attn_weight_desc->dims[3]); + PARAM_CHECK_EQ(API, level_start_index_desc->getDimIndex(0), + attn_weight_desc->getDimIndex(3)); - PARAM_CHECK_EQ(API, sampling_loc_desc->dims[0], attn_weight_desc->dims[0]); - PARAM_CHECK_EQ(API, sampling_loc_desc->dims[1], attn_weight_desc->dims[1]); - PARAM_CHECK_EQ(API, sampling_loc_desc->dims[2], attn_weight_desc->dims[2]); - PARAM_CHECK_EQ(API, sampling_loc_desc->dims[3], attn_weight_desc->dims[3]); - PARAM_CHECK_EQ(API, sampling_loc_desc->dims[4], attn_weight_desc->dims[4]); - PARAM_CHECK_EQ(API, sampling_loc_desc->dims[5], 2); + PARAM_CHECK_EQ(API, sampling_loc_desc->getDimIndex(0), attn_weight_desc->getDimIndex(0)); + PARAM_CHECK_EQ(API, sampling_loc_desc->getDimIndex(1), attn_weight_desc->getDimIndex(1)); + PARAM_CHECK_EQ(API, sampling_loc_desc->getDimIndex(2), attn_weight_desc->getDimIndex(2)); + PARAM_CHECK_EQ(API, sampling_loc_desc->getDimIndex(3), attn_weight_desc->getDimIndex(3)); + PARAM_CHECK_EQ(API, sampling_loc_desc->getDimIndex(4), attn_weight_desc->getDimIndex(4)); + PARAM_CHECK_EQ(API, sampling_loc_desc->getDimIndex(5), 2); - PARAM_CHECK_EQ(API, grad_output_desc->dims[0], attn_weight_desc->dims[0]); - PARAM_CHECK_EQ(API, grad_output_desc->dims[1], attn_weight_desc->dims[1]); - PARAM_CHECK_EQ(API, grad_output_desc->dims[2], attn_weight_desc->dims[2]); - PARAM_CHECK_EQ(API, grad_output_desc->dims[3], value_desc->dims[3]); + PARAM_CHECK_EQ(API, grad_output_desc->getDimIndex(0), attn_weight_desc->getDimIndex(0)); + PARAM_CHECK_EQ(API, grad_output_desc->getDimIndex(1), attn_weight_desc->getDimIndex(1)); + PARAM_CHECK_EQ(API, grad_output_desc->getDimIndex(2), attn_weight_desc->getDimIndex(2)); + PARAM_CHECK_EQ(API, grad_output_desc->getDimIndex(3), value_desc->getDimIndex(3)); TENSOR_NUM_CHECK(API, mluOpGetTensorElementNum(value_desc), LARGE_TENSOR_NUM, ""); @@ -396,13 +396,13 @@ mluOpStatus_t MLUOP_WIN_API mluOpMsDeformAttnBackward( VLOG(5) << "[mluOpMsDeformAttnBackward] cnnlFill_v3 end."; cnrtDim3_t k_dim; cnrtFunctionType_t k_type; - const int32_t spatial_size = value_desc->dims[1]; - const int32_t batch = attn_weight_desc->dims[0]; - const int32_t channels = value_desc->dims[3]; - const int32_t num_query = attn_weight_desc->dims[1]; - const int32_t num_heads = attn_weight_desc->dims[2]; - const int32_t num_levels = attn_weight_desc->dims[3]; - const int32_t num_points = attn_weight_desc->dims[4]; + const int32_t spatial_size = value_desc->getDimIndex(1); + const int32_t batch = attn_weight_desc->getDimIndex(0); + const int32_t channels = value_desc->getDimIndex(3); + const int32_t num_query = attn_weight_desc->getDimIndex(1); + const int32_t num_heads = attn_weight_desc->getDimIndex(2); + const int32_t num_levels = attn_weight_desc->getDimIndex(3); + const int32_t num_points = attn_weight_desc->getDimIndex(4); // generate mluOpMsDeformAttnBackward prototxt start! VLOG(5) << "[mluOpMsDeformAttnBackward] batch: " << batch; diff --git a/kernels/ms_deform_attn/ms_deform_attn_forward/ms_deform_attn_forward.mlu b/kernels/ms_deform_attn/ms_deform_attn_forward/ms_deform_attn_forward.mlu index 6e77c53a4..7db9fc82c 100644 --- a/kernels/ms_deform_attn/ms_deform_attn_forward/ms_deform_attn_forward.mlu +++ b/kernels/ms_deform_attn/ms_deform_attn_forward/ms_deform_attn_forward.mlu @@ -84,54 +84,54 @@ static mluOpStatus_t paramcheck( const mluOpTensorDescriptor_t data_col_desc) { // check tensor dim // params data_value: [bs, num_keys, num_heads, channels] - PARAM_CHECK_EQ("[mluOpMsDeformAttnForward]", data_value_desc->dim, 4); + PARAM_CHECK_EQ("[mluOpMsDeformAttnForward]", data_value_desc->getDim(), 4); // params data_spatial_shapes: [num_levels, 2] - PARAM_CHECK_EQ("[mluOpMsDeformAttnForward]", data_spatial_shapes_desc->dim, + PARAM_CHECK_EQ("[mluOpMsDeformAttnForward]", data_spatial_shapes_desc->getDim(), 2); PARAM_CHECK_EQ("[mluOpMsDeformAttnForward]", - data_spatial_shapes_desc->dims[1], 2); + data_spatial_shapes_desc->getDimIndex(1), 2); // params data_level_start_index: [num_levels] - PARAM_CHECK_EQ("[mluOpMsDeformAttnForward]", data_level_start_index_desc->dim, + PARAM_CHECK_EQ("[mluOpMsDeformAttnForward]", data_level_start_index_desc->getDim(), 1); // params data_sampling_loc: // [bs, num_queries, num_heads, num_levels, num_points, 2] - PARAM_CHECK_EQ("[mluOpMsDeformAttnForward]", data_sampling_loc_desc->dim, 6); - PARAM_CHECK_EQ("[mluOpMsDeformAttnForward]", data_sampling_loc_desc->dims[5], + PARAM_CHECK_EQ("[mluOpMsDeformAttnForward]", data_sampling_loc_desc->getDim(), 6); + PARAM_CHECK_EQ("[mluOpMsDeformAttnForward]", data_sampling_loc_desc->getDimIndex(5), 2); // params data_attn_weight: // [bs, num_queries, num_heads, num_levels, num_points] - PARAM_CHECK_EQ("[mluOpMsDeformAttnForward]", data_attn_weight_desc->dim, 5); + PARAM_CHECK_EQ("[mluOpMsDeformAttnForward]", data_attn_weight_desc->getDim(), 5); // params data_col: [bs, num_queries, num_heads, channels] - PARAM_CHECK_EQ("[mluOpMsDeformAttnForward]", data_col_desc->dim, 4); + PARAM_CHECK_EQ("[mluOpMsDeformAttnForward]", data_col_desc->getDim(), 4); // check tensor shape PARAM_CHECK("[mluOpMsDeformAttnForward]", - data_value_desc->dims[0] == data_col_desc->dims[0]); + data_value_desc->getDimIndex(0) == data_col_desc->getDimIndex(0)); PARAM_CHECK("[mluOpMsDeformAttnForward]", - data_sampling_loc_desc->dims[0] == data_col_desc->dims[0]); + data_sampling_loc_desc->getDimIndex(0) == data_col_desc->getDimIndex(0)); PARAM_CHECK("[mluOpMsDeformAttnForward]", - data_attn_weight_desc->dims[0] == data_col_desc->dims[0]); + data_attn_weight_desc->getDimIndex(0) == data_col_desc->getDimIndex(0)); PARAM_CHECK("[mluOpMsDeformAttnForward]", - data_value_desc->dims[2] == data_col_desc->dims[2]); + data_value_desc->getDimIndex(2) == data_col_desc->getDimIndex(2)); PARAM_CHECK("[mluOpMsDeformAttnForward]", - data_sampling_loc_desc->dims[2] == data_col_desc->dims[2]); + data_sampling_loc_desc->getDimIndex(2) == data_col_desc->getDimIndex(2)); PARAM_CHECK("[mluOpMsDeformAttnForward]", - data_attn_weight_desc->dims[2] == data_col_desc->dims[2]); + data_attn_weight_desc->getDimIndex(2) == data_col_desc->getDimIndex(2)); PARAM_CHECK("[mluOpMsDeformAttnForward]", - data_value_desc->dims[3] == data_col_desc->dims[3]); + data_value_desc->getDimIndex(3) == data_col_desc->getDimIndex(3)); PARAM_CHECK("[mluOpMsDeformAttnForward]", - data_spatial_shapes_desc->dims[0] == - data_level_start_index_desc->dims[0]); + data_spatial_shapes_desc->getDimIndex(0) == + data_level_start_index_desc->getDimIndex(0)); PARAM_CHECK( "[mluOpMsDeformAttnForward]", - data_spatial_shapes_desc->dims[0] == data_sampling_loc_desc->dims[3]); - PARAM_CHECK("[mluOpMsDeformAttnForward]", data_spatial_shapes_desc->dims[0] == - data_attn_weight_desc->dims[3]); + data_spatial_shapes_desc->getDimIndex(0) == data_sampling_loc_desc->getDimIndex(3)); + PARAM_CHECK("[mluOpMsDeformAttnForward]", data_spatial_shapes_desc->getDimIndex(0) == + data_attn_weight_desc->getDimIndex(3)); PARAM_CHECK("[mluOpMsDeformAttnForward]", - data_sampling_loc_desc->dims[1] == data_col_desc->dims[1]); + data_sampling_loc_desc->getDimIndex(1) == data_col_desc->getDimIndex(1)); PARAM_CHECK("[mluOpMsDeformAttnForward]", - data_attn_weight_desc->dims[1] == data_col_desc->dims[1]); - PARAM_CHECK("[mluOpMsDeformAttnForward]", data_sampling_loc_desc->dims[4] == - data_attn_weight_desc->dims[4]); + data_attn_weight_desc->getDimIndex(1) == data_col_desc->getDimIndex(1)); + PARAM_CHECK("[mluOpMsDeformAttnForward]", data_sampling_loc_desc->getDimIndex(4) == + data_attn_weight_desc->getDimIndex(4)); // check stride STRIDE_TENSOR_CHECK("[mluOpMsDeformAttnForward]:", data_value_desc, "data_value_desc must be contiguous"); @@ -148,19 +148,19 @@ static mluOpStatus_t paramcheck( "data_col_desc must be contiguous"); // check tensor datatype PARAM_CHECK("[mluOpMsDeformAttnForward]", - data_value_desc->dtype == MLUOP_DTYPE_FLOAT); + data_value_desc->getDtype() == MLUOP_DTYPE_FLOAT); PARAM_CHECK("[mluOpMsDeformAttnForward]", - data_spatial_shapes_desc->dtype == MLUOP_DTYPE_INT32); + data_spatial_shapes_desc->getDtype() == MLUOP_DTYPE_INT32); PARAM_CHECK("[mluOpMsDeformAttnForward]", - data_level_start_index_desc->dtype == MLUOP_DTYPE_INT32); + data_level_start_index_desc->getDtype() == MLUOP_DTYPE_INT32); // data_value, data_sampling_loc, data_attn_weight, // data_col datatype must be the same PARAM_CHECK("[mluOpMsDeformAttnForward]", - data_value_desc->dtype == data_col_desc->dtype); + data_value_desc->getDtype() == data_col_desc->getDtype()); PARAM_CHECK("[mluOpMsDeformAttnForward]", - data_sampling_loc_desc->dtype == data_col_desc->dtype); + data_sampling_loc_desc->getDtype() == data_col_desc->getDtype()); PARAM_CHECK("[mluOpMsDeformAttnForward]", - data_attn_weight_desc->dtype == data_col_desc->dtype); + data_attn_weight_desc->getDtype() == data_col_desc->getDtype()); return MLUOP_STATUS_SUCCESS; } @@ -203,13 +203,13 @@ mluOpStatus_t MLUOP_WIN_API mluOpMsDeformAttnForward( LARGE_TENSOR_NUM, ""); TENSOR_NUM_CHECK("[mluOpMsDeformAttnForward]", data_col_element_num, LARGE_TENSOR_NUM, ""); - const int32_t batch_size = data_value_desc->dims[0]; - const int32_t num_keys = data_value_desc->dims[1]; - const int32_t num_heads = data_value_desc->dims[2]; - const int32_t channels = data_value_desc->dims[3]; - const int32_t num_levels = data_spatial_shapes_desc->dims[0]; - const int32_t num_queries = data_sampling_loc_desc->dims[1]; - const int32_t num_points = data_sampling_loc_desc->dims[4]; + const int32_t batch_size = data_value_desc->getDimIndex(0); + const int32_t num_keys = data_value_desc->getDimIndex(1); + const int32_t num_heads = data_value_desc->getDimIndex(2); + const int32_t channels = data_value_desc->getDimIndex(3); + const int32_t num_levels = data_spatial_shapes_desc->getDimIndex(0); + const int32_t num_queries = data_sampling_loc_desc->getDimIndex(1); + const int32_t num_points = data_sampling_loc_desc->getDimIndex(4); // check element num zero if (batch_size == 0 || num_heads == 0 || channels == 0 || num_queries == 0) { LOG(ERROR) << "[mluOpMsDeformAttnForward] Check failed: element num zero."; diff --git a/kernels/mutual_information/mutual_information_backward/mutual_information_backward.cpp b/kernels/mutual_information/mutual_information_backward/mutual_information_backward.cpp index 68e1e145e..ff76f1dd1 100644 --- a/kernels/mutual_information/mutual_information_backward/mutual_information_backward.cpp +++ b/kernels/mutual_information/mutual_information_backward/mutual_information_backward.cpp @@ -61,42 +61,42 @@ static mluOpStatus_t checkTensorDim( const mluOpTensorDescriptor_t ans_grad_desc, const mluOpTensorDescriptor_t px_grad_desc, const mluOpTensorDescriptor_t py_grad_desc) { - if (3 != px_desc->dim) { + if (3 != px_desc->getDim()) { LOG(ERROR) << API_NAME << " The dim of px must be 3. " - << "But now the dim of px is " << px_desc->dim << "."; + << "But now the dim of px is " << px_desc->getDim() << "."; return MLUOP_STATUS_BAD_PARAM; } - if (3 != py_desc->dim) { + if (3 != py_desc->getDim()) { LOG(ERROR) << API_NAME << " The dim of py must be 3. " - << "But now the dim of py is " << py_desc->dim << "."; + << "But now the dim of py is " << py_desc->getDim() << "."; return MLUOP_STATUS_BAD_PARAM; } - if (nullptr != opt_boundary_desc && 2 != opt_boundary_desc->dim) { + if (nullptr != opt_boundary_desc && 2 != opt_boundary_desc->getDim()) { LOG(ERROR) << API_NAME << " The dim of opt_boundary must be 2 when opt_boundary is " << "not NULL. But now the dim of opt_boundary is " - << opt_boundary_desc->dim << "."; + << opt_boundary_desc->getDim() << "."; return MLUOP_STATUS_BAD_PARAM; } - if (3 != p_desc->dim) { + if (3 != p_desc->getDim()) { LOG(ERROR) << API_NAME << " The dim of p must be 3. " - << "But now the dim of p is " << p_desc->dim << "."; + << "But now the dim of p is " << p_desc->getDim() << "."; return MLUOP_STATUS_BAD_PARAM; } - if (1 != ans_grad_desc->dim) { + if (1 != ans_grad_desc->getDim()) { LOG(ERROR) << API_NAME << " The dim of ans_grad must be 1. " - << "But now the dim of ans_grad is " << ans_grad_desc->dim + << "But now the dim of ans_grad is " << ans_grad_desc->getDim() << "."; return MLUOP_STATUS_BAD_PARAM; } - if (3 != px_grad_desc->dim) { + if (3 != px_grad_desc->getDim()) { LOG(ERROR) << API_NAME << " The dim of px_grad must be 3. " - << "But now the dim of px_grad is " << px_grad_desc->dim << "."; + << "But now the dim of px_grad is " << px_grad_desc->getDim() << "."; return MLUOP_STATUS_BAD_PARAM; } - if (3 != py_grad_desc->dim) { + if (3 != py_grad_desc->getDim()) { LOG(ERROR) << API_NAME << " The dim of py_grad must be 3. " - << "But now the dim of py_grad is " << py_grad_desc->dim << "."; + << "But now the dim of py_grad is " << py_grad_desc->getDim() << "."; return MLUOP_STATUS_BAD_PARAM; } @@ -111,83 +111,83 @@ static mluOpStatus_t checkTensorShape( const mluOpTensorDescriptor_t ans_grad_desc, const mluOpTensorDescriptor_t px_grad_desc, const mluOpTensorDescriptor_t py_grad_desc) { - const int B = px_desc->dims[0]; - const int S = px_desc->dims[1]; - const int T = py_desc->dims[2]; - if (B != py_desc->dims[0] || B != p_desc->dims[0] || - B != ans_grad_desc->dims[0] || B != px_grad_desc->dims[0] || - B != py_grad_desc->dims[0]) { + const int B = px_desc->getDimIndex(0); + const int S = px_desc->getDimIndex(1); + const int T = py_desc->getDimIndex(2); + if (B != py_desc->getDimIndex(0) || B != p_desc->getDimIndex(0) || + B != ans_grad_desc->getDimIndex(0) || B != px_grad_desc->getDimIndex(0) || + B != py_grad_desc->getDimIndex(0)) { LOG(ERROR) << API_NAME << " px.shape[0], py.shape[0], p.shape[0], ans_grad.shape[0], " << "px_grad.shape[0] and py_grad.shape[0] must be same. But now " - << "px.shape[0] is " << px_desc->dims[0] << ", py.shape[0] is " - << py_desc->dims[0] << ", p.shape[0] is " << p_desc->dims[0] - << ", ans_grad.shape[0] is " << ans_grad_desc->dims[0] - << ", px_grad.shape[0] is " << px_grad_desc->dims[0] - << ", py_grad.shape[0] is " << py_grad_desc->dims[0] << "."; + << "px.shape[0] is " << px_desc->getDimIndex(0) << ", py.shape[0] is " + << py_desc->getDimIndex(0) << ", p.shape[0] is " << p_desc->getDimIndex(0) + << ", ans_grad.shape[0] is " << ans_grad_desc->getDimIndex(0) + << ", px_grad.shape[0] is " << px_grad_desc->getDimIndex(0) + << ", py_grad.shape[0] is " << py_grad_desc->getDimIndex(0) << "."; return MLUOP_STATUS_BAD_PARAM; } // Currently only supports !modified, so the shape of px must be [B, S, T+1] - if (T + 1 != px_desc->dims[2]) { + if (T + 1 != px_desc->getDimIndex(2)) { LOG(ERROR) << API_NAME << " Currently only supports the case that " << "px.shape[2] must be equal to py.shape[2] + 1. But now " - << "px.shape[2] is " << px_desc->dims[2] << ", py.shape[2] is " - << py_desc->dims[2] << "."; + << "px.shape[2] is " << px_desc->getDimIndex(2) << ", py.shape[2] is " + << py_desc->getDimIndex(2) << "."; return MLUOP_STATUS_NOT_SUPPORTED; } // The shape of py must be [B, S+1, T] - if (S + 1 != py_desc->dims[1]) { + if (S + 1 != py_desc->getDimIndex(1)) { LOG(ERROR) << API_NAME << " py.shape[1] must be equal to px.shape[1] + 1. " - << "But now px.shape[1] is " << px_desc->dims[1] - << ", py.shape[1] is " << py_desc->dims[1] << "."; + << "But now px.shape[1] is " << px_desc->getDimIndex(1) + << ", py.shape[1] is " << py_desc->getDimIndex(1) << "."; return MLUOP_STATUS_BAD_PARAM; } // The shape of opt_boundary must be [B, 4] if (nullptr != opt_boundary_desc && - (B != opt_boundary_desc->dims[0] || 4 != opt_boundary_desc->dims[1])) { + (B != opt_boundary_desc->getDimIndex(0) || 4 != opt_boundary_desc->getDimIndex(1))) { LOG(ERROR) << API_NAME << " When opt_boundary is not NULL, " << "opt_boundary.shape[0] and px.shape[0] must be same, and " << "opt_boundary.shape[1] must be 4. But now " - << "px.shape[0] is " << px_desc->dims[0] - << ", opt_boundary.shape[0] is " << opt_boundary_desc->dims[0] - << ", opt_boundary.shape[1] is " << opt_boundary_desc->dims[1] + << "px.shape[0] is " << px_desc->getDimIndex(0) + << ", opt_boundary.shape[0] is " << opt_boundary_desc->getDimIndex(0) + << ", opt_boundary.shape[1] is " << opt_boundary_desc->getDimIndex(1) << "."; return MLUOP_STATUS_BAD_PARAM; } // The shape of p must be [B, S+1, T+1] - if (S + 1 != p_desc->dims[1] || T + 1 != p_desc->dims[2]) { + if (S + 1 != p_desc->getDimIndex(1) || T + 1 != p_desc->getDimIndex(2)) { LOG(ERROR) << API_NAME << " p.shape[1] and py.shape[1] must be same, and " << "p.shape[2] must be equal to py.shape[2] + 1. " - << "But now p.shape[1] is " << p_desc->dims[1] - << ", py.shape[1] is " << py_desc->dims[1] << ", p.shape[2] is " - << p_desc->dims[2] << ", py.shape[2] is " << py_desc->dims[2] + << "But now p.shape[1] is " << p_desc->getDimIndex(1) + << ", py.shape[1] is " << py_desc->getDimIndex(1) << ", p.shape[2] is " + << p_desc->getDimIndex(2) << ", py.shape[2] is " << py_desc->getDimIndex(2) << "."; return MLUOP_STATUS_BAD_PARAM; } // The shape of px and px_grad must be same: [B, S, T+1] - for (int i = 1; i < px_grad_desc->dim; ++i) { - if (px_grad_desc->dims[i] != px_desc->dims[i]) { + for (int i = 1; i < px_grad_desc->getDim(); ++i) { + if (px_grad_desc->getDimIndex(i) != px_desc->getDimIndex(i)) { LOG(ERROR) << API_NAME << " The shape of px and px_grad must be same. But now " - << "px.shape[" << i << "] is " << px_desc->dims[i] - << ", px_grad.shape[" << i << "] is " << px_grad_desc->dims[i] + << "px.shape[" << i << "] is " << px_desc->getDimIndex(i) + << ", px_grad.shape[" << i << "] is " << px_grad_desc->getDimIndex(i) << "."; return MLUOP_STATUS_BAD_PARAM; } } // The shape of py and py_grad must be same: [B, S+1, T] - for (int i = 1; i < py_grad_desc->dim; ++i) { - if (py_grad_desc->dims[i] != py_desc->dims[i]) { + for (int i = 1; i < py_grad_desc->getDim(); ++i) { + if (py_grad_desc->getDimIndex(i) != py_desc->getDimIndex(i)) { LOG(ERROR) << API_NAME << " The shape of py and py_grad must be same. But now " - << "py.shape[" << i << "] is " << py_desc->dims[i] - << ", py_grad.shape[" << i << "] is " << py_grad_desc->dims[i] + << "py.shape[" << i << "] is " << py_desc->getDimIndex(i) + << ", py_grad.shape[" << i << "] is " << py_grad_desc->getDimIndex(i) << "."; return MLUOP_STATUS_BAD_PARAM; } @@ -204,54 +204,54 @@ static mluOpStatus_t checkTensorDatatype( const mluOpTensorDescriptor_t ans_grad_desc, const mluOpTensorDescriptor_t px_grad_desc, const mluOpTensorDescriptor_t py_grad_desc) { - if (MLUOP_DTYPE_FLOAT != px_desc->dtype) { + if (MLUOP_DTYPE_FLOAT != px_desc->getDtype()) { LOG(ERROR) << API_NAME << "The data type of px currently only support float. But now " << "the data type of px is " - << mluOpGetNameOfDataType(px_desc->dtype) << "."; + << mluOpGetNameOfDataType(px_desc->getDtype()) << "."; return MLUOP_STATUS_NOT_SUPPORTED; } - if (MLUOP_DTYPE_FLOAT != py_desc->dtype) { + if (MLUOP_DTYPE_FLOAT != py_desc->getDtype()) { LOG(ERROR) << API_NAME << "The data type of py currently only support float. But now " << "the data type of py is " - << mluOpGetNameOfDataType(py_desc->dtype) << "."; + << mluOpGetNameOfDataType(py_desc->getDtype()) << "."; return MLUOP_STATUS_NOT_SUPPORTED; } if (nullptr != opt_boundary_desc && - MLUOP_DTYPE_INT64 != opt_boundary_desc->dtype) { + MLUOP_DTYPE_INT64 != opt_boundary_desc->getDtype()) { LOG(ERROR) << API_NAME << "The data type of opt_boundary currently only support int64." << " But now the data type of opt_boundary is " - << mluOpGetNameOfDataType(opt_boundary_desc->dtype) << "."; + << mluOpGetNameOfDataType(opt_boundary_desc->getDtype()) << "."; return MLUOP_STATUS_NOT_SUPPORTED; } - if (MLUOP_DTYPE_FLOAT != p_desc->dtype) { + if (MLUOP_DTYPE_FLOAT != p_desc->getDtype()) { LOG(ERROR) << API_NAME << "The data type of p currently only support float. But now " << "the data type of p is " - << mluOpGetNameOfDataType(p_desc->dtype) << "."; + << mluOpGetNameOfDataType(p_desc->getDtype()) << "."; return MLUOP_STATUS_NOT_SUPPORTED; } - if (MLUOP_DTYPE_FLOAT != ans_grad_desc->dtype) { + if (MLUOP_DTYPE_FLOAT != ans_grad_desc->getDtype()) { LOG(ERROR) << API_NAME << "The data type of ans_grad currently only support float. " << "But now the data type of ans_grad is " - << mluOpGetNameOfDataType(ans_grad_desc->dtype) << "."; + << mluOpGetNameOfDataType(ans_grad_desc->getDtype()) << "."; return MLUOP_STATUS_NOT_SUPPORTED; } - if (MLUOP_DTYPE_FLOAT != px_grad_desc->dtype) { + if (MLUOP_DTYPE_FLOAT != px_grad_desc->getDtype()) { LOG(ERROR) << API_NAME << "The data type of px_grad currently only support float. " << "But now the data type of px_grad is " - << mluOpGetNameOfDataType(px_grad_desc->dtype) << "."; + << mluOpGetNameOfDataType(px_grad_desc->getDtype()) << "."; return MLUOP_STATUS_NOT_SUPPORTED; } - if (MLUOP_DTYPE_FLOAT != py_grad_desc->dtype) { + if (MLUOP_DTYPE_FLOAT != py_grad_desc->getDtype()) { LOG(ERROR) << API_NAME << "The data type of py_grad currently only support float. " << "But now the data type of py_grad is " - << mluOpGetNameOfDataType(py_grad_desc->dtype) << "."; + << mluOpGetNameOfDataType(py_grad_desc->getDtype()) << "."; return MLUOP_STATUS_NOT_SUPPORTED; } @@ -393,9 +393,9 @@ static mluOpStatus_t mutualInformationBackwardParamCheck( return check_status; } - const int B = px_desc->dims[0]; - const int S = px_desc->dims[1]; - const int T = py_desc->dims[2]; + const int B = px_desc->getDimIndex(0); + const int S = px_desc->getDimIndex(1); + const int T = py_desc->getDimIndex(2); // 8. check zero element. if (0 == B || (0 == S && 0 == T)) { @@ -464,9 +464,9 @@ static mluOpStatus_t launchMutualInformationBackward3PipelineKernel( const bool has_boundary, const void *opt_boundary, const void *p, const bool overwrite_ans_grad, void *ans_grad, void *px_grad, void *py_grad) { - const int B = px_desc->dims[0]; - const int S = px_desc->dims[1]; - const int T = py_desc->dims[2]; + const int B = px_desc->getDimIndex(0); + const int S = px_desc->getDimIndex(1); + const int T = py_desc->getDimIndex(2); cnrtDim3_t k_dim; cnrtFunctionType_t k_type; @@ -741,9 +741,9 @@ static mluOpStatus_t launchMutualInformationBackwardDefaultKernel( // diagonal number // 3. Launch default kernels by diagonal in parallel, with check of MaxDimX - const int B = px_desc->dims[0]; - const int S = px_desc->dims[1]; - const int T = py_desc->dims[2]; + const int B = px_desc->getDimIndex(0); + const int S = px_desc->getDimIndex(1); + const int T = py_desc->getDimIndex(2); cnrtDim3_t k_dim; cnrtFunctionType_t k_type; @@ -842,9 +842,9 @@ mluOpStatus_t MLUOP_WIN_API mluOpMutualInformationBackward( } // Choose to launch 3pipeline or default kernel - const int B = px_desc->dims[0]; - const int S = px_desc->dims[1]; - const int T = py_desc->dims[2]; + const int B = px_desc->getDimIndex(0); + const int S = px_desc->getDimIndex(1); + const int T = py_desc->getDimIndex(2); bool is_launch_3pipeline = true; // check 3pipeline scale limit for computing term1 and term2 diff --git a/kernels/mutual_information/mutual_information_forward/mutual_information_forward.cpp b/kernels/mutual_information/mutual_information_forward/mutual_information_forward.cpp index b655237df..0e7da4b39 100644 --- a/kernels/mutual_information/mutual_information_forward/mutual_information_forward.cpp +++ b/kernels/mutual_information/mutual_information_forward/mutual_information_forward.cpp @@ -57,31 +57,31 @@ static mluOpStatus_t checkTensorDim( const mluOpTensorDescriptor_t opt_boundary_desc, const mluOpTensorDescriptor_t p_desc, const mluOpTensorDescriptor_t ans_desc) { - if (3 != px_desc->dim) { + if (3 != px_desc->getDim()) { LOG(ERROR) << API_NAME << " The dim of px must be 3. " - << "But now the dim of px is " << px_desc->dim << "."; + << "But now the dim of px is " << px_desc->getDim() << "."; return MLUOP_STATUS_BAD_PARAM; } - if (3 != py_desc->dim) { + if (3 != py_desc->getDim()) { LOG(ERROR) << API_NAME << " The dim of py must be 3. " - << "But now the dim of py is " << py_desc->dim << "."; + << "But now the dim of py is " << py_desc->getDim() << "."; return MLUOP_STATUS_BAD_PARAM; } - if (nullptr != opt_boundary_desc && 2 != opt_boundary_desc->dim) { + if (nullptr != opt_boundary_desc && 2 != opt_boundary_desc->getDim()) { LOG(ERROR) << API_NAME << " The dim of opt_boundary must be 2 when opt_boundary is " << "not NULL. But now the dim of opt_boundary is " - << opt_boundary_desc->dim << "."; + << opt_boundary_desc->getDim() << "."; return MLUOP_STATUS_BAD_PARAM; } - if (3 != p_desc->dim) { + if (3 != p_desc->getDim()) { LOG(ERROR) << API_NAME << " The dim of p must be 3. " - << "But now the dim of p is " << p_desc->dim << "."; + << "But now the dim of p is " << p_desc->getDim() << "."; return MLUOP_STATUS_BAD_PARAM; } - if (1 != ans_desc->dim) { + if (1 != ans_desc->getDim()) { LOG(ERROR) << API_NAME << " The dim of ans must be 1. " - << "But now the dim of ans is " << ans_desc->dim << "."; + << "But now the dim of ans is " << ans_desc->getDim() << "."; return MLUOP_STATUS_BAD_PARAM; } @@ -94,56 +94,56 @@ static mluOpStatus_t checkTensorShape( const mluOpTensorDescriptor_t opt_boundary_desc, const mluOpTensorDescriptor_t p_desc, const mluOpTensorDescriptor_t ans_desc) { - const int B = px_desc->dims[0]; - const int S = px_desc->dims[1]; - const int T = py_desc->dims[2]; - if (B != py_desc->dims[0] || B != p_desc->dims[0] || B != ans_desc->dims[0]) { + const int B = px_desc->getDimIndex(0); + const int S = px_desc->getDimIndex(1); + const int T = py_desc->getDimIndex(2); + if (B != py_desc->getDimIndex(0) || B != p_desc->getDimIndex(0) || B != ans_desc->getDimIndex(0)) { LOG(ERROR) << API_NAME << " px.shape[0], py.shape[0], p.shape[0], ans.shape[0], " << "must be same. But now " - << "px.shape[0] is " << px_desc->dims[0] << ", py.shape[0] is " - << py_desc->dims[0] << ", p.shape[0] is " << p_desc->dims[0] - << ", ans.shape[0] is " << ans_desc->dims[0] << "."; + << "px.shape[0] is " << px_desc->getDimIndex(0) << ", py.shape[0] is " + << py_desc->getDimIndex(0) << ", p.shape[0] is " << p_desc->getDimIndex(0) + << ", ans.shape[0] is " << ans_desc->getDimIndex(0) << "."; return MLUOP_STATUS_BAD_PARAM; } // Currently only supports !modified, so the shape of px must be [B, S, T+1] - if (T + 1 != px_desc->dims[2]) { + if (T + 1 != px_desc->getDimIndex(2)) { LOG(ERROR) << API_NAME << " Currently only supports the case that " << "px.shape[2] must be equal to py.shape[2] + 1. But now " - << "px.shape[2] is " << px_desc->dims[2] << ", py.shape[2] is " - << py_desc->dims[2] << "."; + << "px.shape[2] is " << px_desc->getDimIndex(2) << ", py.shape[2] is " + << py_desc->getDimIndex(2) << "."; return MLUOP_STATUS_NOT_SUPPORTED; } // The shape of py must be [B, S+1, T] - if (S + 1 != py_desc->dims[1]) { + if (S + 1 != py_desc->getDimIndex(1)) { LOG(ERROR) << API_NAME << " py.shape[1] must be equal to px.shape[1] + 1. " - << "But now px.shape[1] is " << px_desc->dims[1] - << ", py.shape[1] is " << py_desc->dims[1] << "."; + << "But now px.shape[1] is " << px_desc->getDimIndex(1) + << ", py.shape[1] is " << py_desc->getDimIndex(1) << "."; return MLUOP_STATUS_BAD_PARAM; } // The shape of opt_boundary must be [B, 4] if (nullptr != opt_boundary_desc && - (B != opt_boundary_desc->dims[0] || 4 != opt_boundary_desc->dims[1])) { + (B != opt_boundary_desc->getDimIndex(0) || 4 != opt_boundary_desc->getDimIndex(1))) { LOG(ERROR) << API_NAME << " When opt_boundary is not NULL, " << "opt_boundary.shape[0] and px.shape[0] must be same, and " << "opt_boundary.shape[1] must be 4. But now " - << "px.shape[0] is " << px_desc->dims[0] - << ", opt_boundary.shape[0] is " << opt_boundary_desc->dims[0] - << ", opt_boundary.shape[1] is " << opt_boundary_desc->dims[1] + << "px.shape[0] is " << px_desc->getDimIndex(0) + << ", opt_boundary.shape[0] is " << opt_boundary_desc->getDimIndex(0) + << ", opt_boundary.shape[1] is " << opt_boundary_desc->getDimIndex(1) << "."; return MLUOP_STATUS_BAD_PARAM; } // The shape of p must be [B, S+1, T+1] - if (S + 1 != p_desc->dims[1] || T + 1 != p_desc->dims[2]) { + if (S + 1 != p_desc->getDimIndex(1) || T + 1 != p_desc->getDimIndex(2)) { LOG(ERROR) << API_NAME << " p.shape[1] and py.shape[1] must be same, and " << "p.shape[2] must be equal to py.shape[2] + 1. " - << "But now p.shape[1] is " << p_desc->dims[1] - << ", py.shape[1] is " << py_desc->dims[1] << ", p.shape[2] is " - << p_desc->dims[2] << ", py.shape[2] is " << py_desc->dims[2] + << "But now p.shape[1] is " << p_desc->getDimIndex(1) + << ", py.shape[1] is " << py_desc->getDimIndex(1) << ", p.shape[2] is " + << p_desc->getDimIndex(2) << ", py.shape[2] is " << py_desc->getDimIndex(2) << "."; return MLUOP_STATUS_BAD_PARAM; } @@ -157,40 +157,40 @@ static mluOpStatus_t checkTensorDatatype( const mluOpTensorDescriptor_t opt_boundary_desc, const mluOpTensorDescriptor_t p_desc, const mluOpTensorDescriptor_t ans_desc) { - if (MLUOP_DTYPE_FLOAT != px_desc->dtype) { + if (MLUOP_DTYPE_FLOAT != px_desc->getDtype()) { LOG(ERROR) << API_NAME << "The data type of px currently only support float. But now " << "the data type of px is " - << mluOpGetNameOfDataType(px_desc->dtype) << "."; + << mluOpGetNameOfDataType(px_desc->getDtype()) << "."; return MLUOP_STATUS_NOT_SUPPORTED; } - if (MLUOP_DTYPE_FLOAT != py_desc->dtype) { + if (MLUOP_DTYPE_FLOAT != py_desc->getDtype()) { LOG(ERROR) << API_NAME << "The data type of py currently only support float. But now " << "the data type of py is " - << mluOpGetNameOfDataType(py_desc->dtype) << "."; + << mluOpGetNameOfDataType(py_desc->getDtype()) << "."; return MLUOP_STATUS_NOT_SUPPORTED; } if (nullptr != opt_boundary_desc && - MLUOP_DTYPE_INT64 != opt_boundary_desc->dtype) { + MLUOP_DTYPE_INT64 != opt_boundary_desc->getDtype()) { LOG(ERROR) << API_NAME << "The data type of opt_boundary currently only support int64." << " But now the data type of opt_boundary is " - << mluOpGetNameOfDataType(opt_boundary_desc->dtype) << "."; + << mluOpGetNameOfDataType(opt_boundary_desc->getDtype()) << "."; return MLUOP_STATUS_NOT_SUPPORTED; } - if (MLUOP_DTYPE_FLOAT != p_desc->dtype) { + if (MLUOP_DTYPE_FLOAT != p_desc->getDtype()) { LOG(ERROR) << API_NAME << "The data type of p currently only support float. But now " << "the data type of p is " - << mluOpGetNameOfDataType(p_desc->dtype) << "."; + << mluOpGetNameOfDataType(p_desc->getDtype()) << "."; return MLUOP_STATUS_NOT_SUPPORTED; } - if (MLUOP_DTYPE_FLOAT != ans_desc->dtype) { + if (MLUOP_DTYPE_FLOAT != ans_desc->getDtype()) { LOG(ERROR) << API_NAME << "The data type of ans currently only support float. " << "But now the data type of ans is " - << mluOpGetNameOfDataType(ans_desc->dtype) << "."; + << mluOpGetNameOfDataType(ans_desc->getDtype()) << "."; return MLUOP_STATUS_NOT_SUPPORTED; } @@ -314,9 +314,9 @@ static mluOpStatus_t mutualInformationForwardParamCheck( return check_status; } - const int B = px_desc->dims[0]; - const int S = px_desc->dims[1]; - const int T = py_desc->dims[2]; + const int B = px_desc->getDimIndex(0); + const int S = px_desc->getDimIndex(1); + const int T = py_desc->getDimIndex(2); // 8. check zero element. if (0 == B) { @@ -375,9 +375,9 @@ static mluOpStatus_t launchMutualInformationForward3PipelineKernel( mluOpHandle_t handle, const mluOpTensorDescriptor_t px_desc, const void *px, const mluOpTensorDescriptor_t py_desc, const void *py, const bool has_boundary, const void *opt_boundary, void *p, void *ans) { - const int B = px_desc->dims[0]; - const int S = px_desc->dims[1]; - const int T = py_desc->dims[2]; + const int B = px_desc->getDimIndex(0); + const int S = px_desc->getDimIndex(1); + const int T = py_desc->getDimIndex(2); cnrtDim3_t k_dim; cnrtFunctionType_t k_type; @@ -628,9 +628,9 @@ static mluOpStatus_t launchMutualInformationForwardDefaultKernel( // diagonal number // 3. Launch default kernels by diagonal in parallel, with check of MaxDimX - const int B = px_desc->dims[0]; - const int S = px_desc->dims[1]; - const int T = py_desc->dims[2]; + const int B = px_desc->getDimIndex(0); + const int S = px_desc->getDimIndex(1); + const int T = py_desc->getDimIndex(2); cnrtDim3_t k_dim; cnrtFunctionType_t k_type; @@ -723,8 +723,8 @@ mluOpStatus_t MLUOP_WIN_API mluOpMutualInformationForward( } // Choose to launch 3pipeline kernel or default kernel - const int S = px_desc->dims[1]; - const int T = py_desc->dims[2]; + const int S = px_desc->getDimIndex(1); + const int T = py_desc->getDimIndex(2); bool is_launch_3pipeline = true; // Check 3pipeline kernel scale limit for computing p diff --git a/kernels/nms_rotated/nms_rotated.cpp b/kernels/nms_rotated/nms_rotated.cpp index 7575e5a18..454bdd0af 100644 --- a/kernels/nms_rotated/nms_rotated.cpp +++ b/kernels/nms_rotated/nms_rotated.cpp @@ -57,10 +57,10 @@ mluOpStatus_t MLUOP_WIN_API mluOpGetNmsRotatedWorkspaceSize( PARAM_CHECK("[mluOpGetNmsRotatedWorkspaceSize]", handle != nullptr); PARAM_CHECK("[mluOpGetNmsRotatedWorkspaceSize]", boxes_desc != nullptr); PARAM_CHECK("[mluOpGetNmsRotatedWorkspaceSize]", workspace_size != nullptr); - const uint64_t box_num = boxes_desc->dims[0]; - const uint64_t box_dim = boxes_desc->dims[1]; + const uint64_t box_num = boxes_desc->getDimIndex(0); + const uint64_t box_dim = boxes_desc->getDimIndex(1); uint64_t total_num = box_num * box_dim + box_num; - *workspace_size = total_num * mluop::getSizeOfDataType(boxes_desc->dtype); + *workspace_size = total_num * mluop::getSizeOfDataType(boxes_desc->getDtype()); return MLUOP_STATUS_SUCCESS; } @@ -78,14 +78,14 @@ mluOpNmsRotated(mluOpHandle_t handle, const float iou_threshold, PARAM_CHECK("[mluOpNmsRotated]", output_desc != NULL); // datatype check - PARAM_CHECK("[mluOpNmsRotated]", boxes_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK_EQ("[mluOpNmsRotated]", boxes_desc->dtype, scores_desc->dtype); - PARAM_CHECK("[mluOpNmsRotated]", output_desc->dtype == MLUOP_DTYPE_INT32); + PARAM_CHECK("[mluOpNmsRotated]", boxes_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK_EQ("[mluOpNmsRotated]", boxes_desc->getDtype(), scores_desc->getDtype()); + PARAM_CHECK("[mluOpNmsRotated]", output_desc->getDtype() == MLUOP_DTYPE_INT32); // dims and shape check - PARAM_CHECK_EQ("[mluOpNmsRotated]", boxes_desc->dim, 2); - PARAM_CHECK_EQ("[mluOpNmsRotated]", scores_desc->dim, 1); - PARAM_CHECK_EQ("[mluOpNmsRotated]", output_desc->dim, 1); + PARAM_CHECK_EQ("[mluOpNmsRotated]", boxes_desc->getDim(), 2); + PARAM_CHECK_EQ("[mluOpNmsRotated]", scores_desc->getDim(), 1); + PARAM_CHECK_EQ("[mluOpNmsRotated]", output_desc->getDim(), 1); // stride check STRIDE_TENSOR_CHECK("[mluOpNmsRotated]:", boxes_desc, @@ -95,20 +95,20 @@ mluOpNmsRotated(mluOpHandle_t handle, const float iou_threshold, STRIDE_TENSOR_CHECK("[mluOpNmsRotated]:", output_desc, "output_desc must be contiguous"); - PARAM_CHECK("[mluOpNmsRotated]", boxes_desc->dims[0] == scores_desc->dims[0]); - PARAM_CHECK("[mluOpNmsRotated]", boxes_desc->dims[0] == output_desc->dims[0]); - if (boxes_desc->dims[1] != SINGLE_BOX_DIM && - boxes_desc->dims[1] != (SINGLE_BOX_DIM + 1)) { + PARAM_CHECK("[mluOpNmsRotated]", boxes_desc->getDimIndex(0) == scores_desc->getDimIndex(0)); + PARAM_CHECK("[mluOpNmsRotated]", boxes_desc->getDimIndex(0) == output_desc->getDimIndex(0)); + if (boxes_desc->getDimIndex(1) != SINGLE_BOX_DIM && + boxes_desc->getDimIndex(1) != (SINGLE_BOX_DIM + 1)) { LOG(ERROR) << "[mluOpNmsRotated] Check failed: The Boxes' last dimenstion " "should be 5 or 6. Now is " - << boxes_desc->dims[1] << "."; + << boxes_desc->getDimIndex(1) << "."; return MLUOP_STATUS_BAD_PARAM; } const uint64_t tensor_boxes_num = mluOpGetTensorElementNum(boxes_desc); TENSOR_NUM_CHECK("[mluOpNmsRotated]", tensor_boxes_num, LARGE_TENSOR_NUM, ""); // 0-element check, after dim and shape check - if (boxes_desc->dims[0] == 0) { + if (boxes_desc->getDimIndex(0) == 0) { VLOG(5) << "[mluOpNmsRotated] Skip zero element boxes."; return MLUOP_STATUS_SUCCESS; } @@ -140,8 +140,8 @@ mluOpNmsRotated(mluOpHandle_t handle, const float iou_threshold, p = INFINITY; } - int32_t box_num = boxes_desc->dims[0]; - int32_t box_dim = boxes_desc->dims[1]; + int32_t box_num = boxes_desc->getDimIndex(0); + int32_t box_dim = boxes_desc->getDimIndex(1); // Choose the best task dimension. cnrtDim3_t k_dim; cnrtFunctionType_t k_type; @@ -151,7 +151,7 @@ mluOpNmsRotated(mluOpHandle_t handle, const float iou_threshold, int8_t *box_workspace = (int8_t *)workspace; int8_t *scores_workspace = box_workspace + - mluop::getSizeOfDataType(boxes_desc->dtype) * box_num * box_dim; + mluop::getSizeOfDataType(boxes_desc->getDtype()) * box_num * box_dim; VLOG(5) << "[mluOpNmsRotated] launch kernel [" << k_dim.x << ", " << k_dim.y << ", " << k_dim.z << "]."; diff --git a/kernels/points_in_boxes/points_in_boxes.cpp b/kernels/points_in_boxes/points_in_boxes.cpp index b6d30a5e7..5191e26cd 100644 --- a/kernels/points_in_boxes/points_in_boxes.cpp +++ b/kernels/points_in_boxes/points_in_boxes.cpp @@ -37,82 +37,82 @@ static mluOpStatus_t pointsInBoxesPreCheck( const mluOpTensorDescriptor_t boxes_desc, const mluOpTensorDescriptor_t points_indices_desc) { // tensor dim check - if (points_desc->dim != 3 || boxes_desc->dim != 3) { + if (points_desc->getDim() != 3 || boxes_desc->getDim() != 3) { LOG(ERROR) << "[mluOpPointsInBoxes] The dim size of the points and boxes" << " tensor must be 3." - << " points dim size is " << points_desc->dim - << ", boxes dim size is " << boxes_desc->dim; + << " points dim size is " << points_desc->getDim() + << ", boxes dim size is " << boxes_desc->getDim(); return MLUOP_STATUS_BAD_PARAM; } - if (points_indices_desc->dim != 2) { + if (points_indices_desc->getDim() != 2) { LOG(ERROR) << "[mluOpPointsInBoxes] The dim size of the points_indices" << " tensor must be 2." - << " points_indices dim size is " << points_indices_desc->dim; + << " points_indices dim size is " << points_indices_desc->getDim(); return MLUOP_STATUS_BAD_PARAM; } // input tensor datatype check - if (points_desc->dtype != MLUOP_DTYPE_FLOAT || - boxes_desc->dtype != MLUOP_DTYPE_FLOAT) { + if (points_desc->getDtype() != MLUOP_DTYPE_FLOAT || + boxes_desc->getDtype() != MLUOP_DTYPE_FLOAT) { LOG(ERROR) << "[mluOpPointsInBoxes] The data type of the points and boxes" << " tensor must be MLUOP_DTYPE_FLOAT."; return MLUOP_STATUS_BAD_PARAM; } // output tensor datatype check - if (points_indices_desc->dtype != MLUOP_DTYPE_INT32) { + if (points_indices_desc->getDtype() != MLUOP_DTYPE_INT32) { LOG(ERROR) << "[mluOpPointsInBoxes] The data type of the points_indices" << " tensor must be MLUOP_DTYPE_INT32."; return MLUOP_STATUS_BAD_PARAM; } // input tensor layout check - if (points_desc->layout != MLUOP_LAYOUT_ARRAY || - boxes_desc->layout != MLUOP_LAYOUT_ARRAY) { + if (points_desc->getLayout() != MLUOP_LAYOUT_ARRAY || + boxes_desc->getLayout() != MLUOP_LAYOUT_ARRAY) { LOG(ERROR) << "[mluOpPointsInBoxes] The layout of the points and boxes" << " tensor must be MLUOP_LAYOUT_ARRAY."; return MLUOP_STATUS_BAD_PARAM; } // output tensor layout check - if (points_indices_desc->layout != MLUOP_LAYOUT_ARRAY) { + if (points_indices_desc->getLayout() != MLUOP_LAYOUT_ARRAY) { LOG(ERROR) << "[mluOpPointsInBoxes] The layout of the points_indices" << " tensor must be MLUOP_LAYOUT_ARRAY."; return MLUOP_STATUS_BAD_PARAM; } // tensor shape check - if ((points_desc->dims[0] != boxes_desc->dims[0]) || - (points_desc->dims[0] != points_indices_desc->dims[0])) { + if ((points_desc->getDimIndex(0) != boxes_desc->getDimIndex(0)) || + (points_desc->getDimIndex(0) != points_indices_desc->getDimIndex(0))) { LOG(ERROR) << "[mluOpPointsInBoxes] The batch size of the points, boxes, " "points_indices " << "tensor must be same." - << " points batch size is " << points_desc->dims[0] - << ", boxes batch size is " << boxes_desc->dims[0] + << " points batch size is " << points_desc->getDimIndex(0) + << ", boxes batch size is " << boxes_desc->getDimIndex(0) << ", points_indices batch size is " - << points_indices_desc->dims[0]; + << points_indices_desc->getDimIndex(0); return MLUOP_STATUS_BAD_PARAM; } - if (points_desc->dims[1] != points_indices_desc->dims[1]) { + if (points_desc->getDimIndex(1) != points_indices_desc->getDimIndex(1)) { LOG(ERROR) << "[mluOpPointsInBoxes] The points num of the points and " "points_indices" << " tensor must be same." - << " num of the points is " << points_desc->dims[1] + << " num of the points is " << points_desc->getDimIndex(1) << ", num of the points_indices is " - << points_indices_desc->dims[1]; + << points_indices_desc->getDimIndex(1); return MLUOP_STATUS_BAD_PARAM; } - if (points_desc->dims[2] != 3) { + if (points_desc->getDimIndex(2) != 3) { LOG(ERROR) << "[mluOpPointsInBoxes] The points " << "must be 3D Coordinate System ie [x, y, z]. vs " - << points_desc->dims[2]; + << points_desc->getDimIndex(2); return MLUOP_STATUS_BAD_PARAM; } - if (boxes_desc->dims[2] != 7) { + if (boxes_desc->getDimIndex(2) != 7) { LOG(ERROR) << "[mluOpPointsInBoxes] The boxes " << "must be 3D Coordinate System ie [x, y, z, dx, dy, dz, heading]. vs " - << boxes_desc->dims[2]; + << boxes_desc->getDimIndex(2); return MLUOP_STATUS_BAD_PARAM; } @@ -143,7 +143,7 @@ static bool isPointsInBoxes(const mluOpHandle_t handle, cnrtDim3_t &k_dim, uint32_t max_nram_size = mluop::runtime::getNramSizeInBytes(handle); uint32_t boxes_size = - boxes_desc->dims[1] * boxes_desc->dims[2] * sizeof(float); + boxes_desc->getDimIndex(1) * boxes_desc->getDimIndex(2) * sizeof(float); uint32_t nram_low_space = 9 * sizeof(float) + boxes_size; if (nram_low_space > max_nram_size) { @@ -152,7 +152,7 @@ static bool isPointsInBoxes(const mluOpHandle_t handle, cnrtDim3_t &k_dim, uint32_t cluster_num = mluop::runtime::getClusterLimitCapability(handle); uint32_t core_dim = mluop::runtime::getCoreNumOfEachUnionCapability(handle); - uint32_t cluster_used = PAD_UP(points_desc->dims[1], core_dim) / core_dim; + uint32_t cluster_used = PAD_UP(points_desc->getDimIndex(1), core_dim) / core_dim; cluster_used = cluster_used > cluster_num ? cluster_num : cluster_used; k_type = cnrtFuncTypeBlock; k_dim.x = 1; @@ -161,9 +161,9 @@ static bool isPointsInBoxes(const mluOpHandle_t handle, cnrtDim3_t &k_dim, uint32_t points_deal_num = (max_nram_size - boxes_size) / (9 * sizeof(float)); - points_in_boxes_info.points_batch_offset = points_desc->dims[1] * 3; - points_in_boxes_info.boxes_batch_offset = boxes_desc->dims[1] * 7; - points_in_boxes_info.idx_batch_offset = points_indices_desc->dims[1]; + points_in_boxes_info.points_batch_offset = points_desc->getDimIndex(1) * 3; + points_in_boxes_info.boxes_batch_offset = boxes_desc->getDimIndex(1) * 7; + points_in_boxes_info.idx_batch_offset = points_indices_desc->getDimIndex(1); points_in_boxes_info.points_deal_num = points_deal_num; points_in_boxes_info.points_deal_offset = points_deal_num * 3; points_in_boxes_info.idx_deal_num = points_deal_num; @@ -211,7 +211,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpPointsInBoxes( points_indices_desc, points_in_boxes_info)) { LOG(ERROR) << "[mluOpPointsInBoxes] The boxes " << "must be not exceed 23404 on MLU370 or 14042 on MLU590. vs " - << boxes_desc->dims[1] << "."; + << boxes_desc->getDimIndex(1) << "."; return MLUOP_STATUS_BAD_PARAM; } // generate points_in_boxes prototxt start! @@ -229,8 +229,8 @@ mluOpStatus_t MLUOP_WIN_API mluOpPointsInBoxes( "KernelPointsInBoxes."; CHECK_RETURN("[mluOpPointsInBoxes]", KernelPointsInBoxes(k_dim, k_type, handle->queue, - points_desc->dims[0], points_desc->dims[1], - boxes_desc->dims[1], (float *)points, + points_desc->getDimIndex(0), points_desc->getDimIndex(1), + boxes_desc->getDimIndex(1), (float *)points, (float *)boxes, (int *)points_indices, points_in_boxes_info.points_batch_offset, points_in_boxes_info.boxes_batch_offset, diff --git a/kernels/poly_nms/poly_nms.cpp b/kernels/poly_nms/poly_nms.cpp index 763a0dbff..a26f0c3be 100644 --- a/kernels/poly_nms/poly_nms.cpp +++ b/kernels/poly_nms/poly_nms.cpp @@ -52,10 +52,10 @@ mluOpStatus_t MLUOP_WIN_API mluOpGetPolyNmsWorkspaceSize( PARAM_CHECK(API, size != NULL); // check inputs shape - PARAM_CHECK_EQ(API, boxes_desc->dim, 2); - PARAM_CHECK_EQ(API, boxes_desc->dims[1], 9); + PARAM_CHECK_EQ(API, boxes_desc->getDim(), 2); + PARAM_CHECK_EQ(API, boxes_desc->getDimIndex(1), 9); - int box_num = boxes_desc->dims[0]; + int box_num = boxes_desc->getDimIndex(0); auto mask_sz = getMaskMatrixByteSize(box_num); auto sort_info_sz = box_num * sizeof(int); auto area_sz = box_num * sizeof(int); @@ -76,19 +76,19 @@ mluOpPolyNms(mluOpHandle_t handle, const mluOpTensorDescriptor_t boxes_desc, PARAM_CHECK(API, output_size != NULL); // check inputs/outputs data type - PARAM_CHECK(API, boxes_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(API, output_desc->dtype == MLUOP_DTYPE_INT32); + PARAM_CHECK(API, boxes_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(API, output_desc->getDtype() == MLUOP_DTYPE_INT32); // check inputs layout - PARAM_CHECK(API, boxes_desc->layout == MLUOP_LAYOUT_ARRAY); + PARAM_CHECK(API, boxes_desc->getLayout() == MLUOP_LAYOUT_ARRAY); // check inputs shape - PARAM_CHECK_EQ(API, boxes_desc->dim, 2); - PARAM_CHECK_EQ(API, boxes_desc->dims[1], 9); + PARAM_CHECK_EQ(API, boxes_desc->getDim(), 2); + PARAM_CHECK_EQ(API, boxes_desc->getDimIndex(1), 9); // check output shape - PARAM_CHECK_EQ(API, output_desc->dim, 1); + PARAM_CHECK_EQ(API, output_desc->getDim(), 1); - PARAM_CHECK(API, boxes_desc->dims[0] == output_desc->dims[0]); + PARAM_CHECK(API, boxes_desc->getDimIndex(0) == output_desc->getDimIndex(0)); // check stride STRIDE_TENSOR_CHECK("[mluOpPolyNms]:", boxes_desc, @@ -96,7 +96,7 @@ mluOpPolyNms(mluOpHandle_t handle, const mluOpTensorDescriptor_t boxes_desc, STRIDE_TENSOR_CHECK("[mluOpPolyNms]:", output_desc, "output_desc must be contiguous"); - int input_boxes_num = boxes_desc->dims[0]; + int input_boxes_num = boxes_desc->getDimIndex(0); if (input_boxes_num == 0) { VLOG(5) << API << " skip zero element tensor."; @@ -111,8 +111,8 @@ mluOpPolyNms(mluOpHandle_t handle, const mluOpTensorDescriptor_t boxes_desc, PARAM_CHECK(API, workspace != NULL); } - int box_num = boxes_desc->dims[0]; - int real_width = boxes_desc->strides[0]; + int box_num = boxes_desc->getDimIndex(0); + int real_width = boxes_desc->getStrideIndex(0); auto mask_col_num = getMaskColNum(box_num); if ((10 * box_num + mask_col_num * 2) > (MAX_NRAM_SIZE / sizeof(float))) { LOG(ERROR) << API << " Too many input boxes, kernel cannot work." diff --git a/kernels/prior_box/prior_box.cpp b/kernels/prior_box/prior_box.cpp index ee6a0ab2f..e74b09d12 100644 --- a/kernels/prior_box/prior_box.cpp +++ b/kernels/prior_box/prior_box.cpp @@ -48,9 +48,9 @@ static void policyFuncPriorBox(const mluOpHandle_t handle, cnrtDim3_t *k_dim, static int getNumPriors(const mluOpTensorDescriptor_t min_sizes_desc, const mluOpTensorDescriptor_t aspect_ratios_desc, const mluOpTensorDescriptor_t max_sizes_desc) { - int num_priors = min_sizes_desc->dims[0] * aspect_ratios_desc->dims[0]; - if (max_sizes_desc->total_element_num != 0) { - num_priors += max_sizes_desc->dims[0]; + int num_priors = min_sizes_desc->getDimIndex(0) * aspect_ratios_desc->getDimIndex(0); + if (max_sizes_desc->getTotalElementNum() != 0) { + num_priors += max_sizes_desc->getDimIndex(0); } return num_priors; } @@ -75,27 +75,27 @@ mluOpStatus_t mluOpPriorBoxParamCheck( PARAM_CHECK(api, output_desc != nullptr); PARAM_CHECK(api, var_desc != nullptr); // check dim - PARAM_CHECK(api, min_sizes_desc->dim == 1); - PARAM_CHECK(api, aspect_ratios_desc->dim == 1); - PARAM_CHECK(api, variances_desc->dim == 1); - PARAM_CHECK(api, max_sizes_desc->dim == 1); - PARAM_CHECK(api, output_desc->dim == 4); - PARAM_CHECK(api, var_desc->dim == 4); + PARAM_CHECK(api, min_sizes_desc->getDim() == 1); + PARAM_CHECK(api, aspect_ratios_desc->getDim() == 1); + PARAM_CHECK(api, variances_desc->getDim() == 1); + PARAM_CHECK(api, max_sizes_desc->getDim() == 1); + PARAM_CHECK(api, output_desc->getDim() == 4); + PARAM_CHECK(api, var_desc->getDim() == 4); // check shape - PARAM_CHECK(api, variances_desc->dims[0] == 4); - PARAM_CHECK(api, output_desc->dims[0] == height); - PARAM_CHECK(api, output_desc->dims[1] == width); - PARAM_CHECK(api, output_desc->dims[3] == 4); - PARAM_CHECK(api, var_desc->dims[3] == 4); + PARAM_CHECK(api, variances_desc->getDimIndex(0) == 4); + PARAM_CHECK(api, output_desc->getDimIndex(0) == height); + PARAM_CHECK(api, output_desc->getDimIndex(1) == width); + PARAM_CHECK(api, output_desc->getDimIndex(3) == 4); + PARAM_CHECK(api, var_desc->getDimIndex(3) == 4); PARAM_CHECK_GE(api, height, 0); PARAM_CHECK_GE(api, width, 0); // check data type - PARAM_CHECK(api, min_sizes_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(api, aspect_ratios_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(api, variances_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(api, max_sizes_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(api, output_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(api, var_desc->dtype == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(api, min_sizes_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(api, aspect_ratios_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(api, variances_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(api, max_sizes_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(api, output_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(api, var_desc->getDtype() == MLUOP_DTYPE_FLOAT); // check scalar param PARAM_CHECK_GT(api, step_h, 0); PARAM_CHECK_GT(api, step_w, 0); @@ -115,19 +115,19 @@ mluOpStatus_t mluOpPriorBoxParamCheck( // check param depand - for (int i = 0; i < output_desc->dim; i++) { + for (int i = 0; i < output_desc->getDim(); i++) { std::string i_str = "i: " + std::to_string(i); - PARAM_CHECK(api, output_desc->dims[i] == var_desc->dims[i], i_str); + PARAM_CHECK(api, output_desc->getDimIndex(i) == var_desc->getDimIndex(i), i_str); } - if (max_sizes_desc->total_element_num != 0) { - PARAM_CHECK(api, max_sizes_desc->dims[0] == min_sizes_desc->dims[0]); + if (max_sizes_desc->getTotalElementNum() != 0) { + PARAM_CHECK(api, max_sizes_desc->getDimIndex(0) == min_sizes_desc->getDimIndex(0)); PARAM_CHECK(api, - max_sizes_desc->dims[0] + - min_sizes_desc->dims[0] * aspect_ratios_desc->dims[0] == - output_desc->dims[2]); + max_sizes_desc->getDimIndex(0) + + min_sizes_desc->getDimIndex(0) * aspect_ratios_desc->getDimIndex(0) == + output_desc->getDimIndex(2)); } else { - PARAM_CHECK(api, min_sizes_desc->dims[0] * aspect_ratios_desc->dims[0] == - output_desc->dims[2]); + PARAM_CHECK(api, min_sizes_desc->getDimIndex(0) * aspect_ratios_desc->getDimIndex(0) == + output_desc->getDimIndex(2)); } const int num_priors = getNumPriors(min_sizes_desc, aspect_ratios_desc, max_sizes_desc); @@ -192,16 +192,16 @@ mluOpStatus_t mluOpPriorBox( PARAM_CHECK(api, variances != nullptr); PARAM_CHECK(api, output != nullptr); PARAM_CHECK(api, var != nullptr); - if (max_sizes_desc->total_element_num > 0) { + if (max_sizes_desc->getTotalElementNum() > 0) { PARAM_CHECK(api, max_sizes != nullptr); } - const int min_sizes_num = min_sizes_desc->dims[0]; - const int aspect_ratios_num = aspect_ratios_desc->dims[0]; - const int variances_num = variances_desc->dims[0]; - const int max_sizes_num = max_sizes_desc->dims[0]; - const int output_size = output_desc->total_element_num; - const int var_size = var_desc->total_element_num; + const int min_sizes_num = min_sizes_desc->getDimIndex(0); + const int aspect_ratios_num = aspect_ratios_desc->getDimIndex(0); + const int variances_num = variances_desc->getDimIndex(0); + const int max_sizes_num = max_sizes_desc->getDimIndex(0); + const int output_size = output_desc->getTotalElementNum(); + const int var_size = var_desc->getTotalElementNum(); const int num_priors = max_sizes_num > 0 ? min_sizes_num * aspect_ratios_num + max_sizes_num : min_sizes_num * aspect_ratios_num; diff --git a/kernels/psamask/psamask.cpp b/kernels/psamask/psamask.cpp index 2ca6c6a18..ef6cde49e 100644 --- a/kernels/psamask/psamask.cpp +++ b/kernels/psamask/psamask.cpp @@ -34,10 +34,10 @@ inline void getNHWC(const mluOpTensorDescriptor_t desc, int *n, int *h, int *w, int *c) { - *n = desc->dims[0]; - *h = desc->dims[1]; - *w = desc->dims[2]; - *c = desc->dims[3]; + *n = desc->getDimIndex(0); + *h = desc->getDimIndex(1); + *w = desc->getDimIndex(2); + *c = desc->getDimIndex(3); } static void policyFunc(mluOpHandle_t handle, cnrtDim3_t *k_dim_ptr, @@ -160,24 +160,24 @@ mluOpStatus_t checkParams(const mluOpTensorDescriptor_t input_desc, const mluOpTensorDescriptor_t output_desc, const int h_mask, const int w_mask, const std::string api) { - PARAM_CHECK(api, input_desc->dim == 4); - PARAM_CHECK(api, output_desc->dim == 4); + PARAM_CHECK(api, input_desc->getDim() == 4); + PARAM_CHECK(api, output_desc->getDim() == 4); int x_n, x_h, x_w, x_c; int y_n, y_h, y_w, y_c; getNHWC(input_desc, &x_n, &x_h, &x_w, &x_c); getNHWC(output_desc, &y_n, &y_h, &y_w, &y_c); - if (input_desc->layout != MLUOP_LAYOUT_NHWC || - output_desc->layout != MLUOP_LAYOUT_NHWC) { + if (input_desc->getLayout() != MLUOP_LAYOUT_NHWC || + output_desc->getLayout() != MLUOP_LAYOUT_NHWC) { LOG(ERROR) << api << " Check failed: Only support MLUOP_LAYOUT_NHWC input and " "output, but now input is " - << mluOpGetNameOfTensorLayout(input_desc->layout) + << mluOpGetNameOfTensorLayout(input_desc->getLayout()) << ", and output is " - << mluOpGetNameOfTensorLayout(output_desc->layout) << "."; + << mluOpGetNameOfTensorLayout(output_desc->getLayout()) << "."; return MLUOP_STATUS_BAD_PARAM; } - if (input_desc->dtype != output_desc->dtype || - input_desc->dtype != MLUOP_DTYPE_FLOAT) { + if (input_desc->getDtype() != output_desc->getDtype() || + input_desc->getDtype() != MLUOP_DTYPE_FLOAT) { LOG(ERROR) << api << " Check failed: The data type of input and output should be float."; @@ -232,18 +232,18 @@ mluOpStatus_t mluOpPsamaskForward(mluOpHandle_t handle, const int psa_type, MLUOP_STATUS_SUCCESS) { return MLUOP_STATUS_BAD_PARAM; } - if (!x_desc->total_element_num) { + if (!x_desc->getTotalElementNum()) { return MLUOP_STATUS_SUCCESS; } PARAM_CHECK(api, x != nullptr); PARAM_CHECK(api, y != nullptr); - auto n = x_desc->dims[0]; - auto h_feature = x_desc->dims[1]; - auto w_feature = x_desc->dims[2]; - auto x_c = x_desc->dims[3]; - auto y_c = y_desc->dims[3]; - auto x_data_type = x_desc->dtype; + auto n = x_desc->getDimIndex(0); + auto h_feature = x_desc->getDimIndex(1); + auto w_feature = x_desc->getDimIndex(2); + auto x_c = x_desc->getDimIndex(3); + auto y_c = y_desc->getDimIndex(3); + auto x_data_type = x_desc->getDtype(); auto half_h_mask = (h_mask - 1) >> 1; auto half_w_mask = (w_mask - 1) >> 1; @@ -302,18 +302,18 @@ mluOpStatus_t mluOpPsamaskBackward(mluOpHandle_t handle, const int psa_type, MLUOP_STATUS_SUCCESS) { return MLUOP_STATUS_BAD_PARAM; } - if (!dy_desc->total_element_num) { + if (!dy_desc->getTotalElementNum()) { return MLUOP_STATUS_SUCCESS; } PARAM_CHECK(api, dy != nullptr); PARAM_CHECK(api, dx != nullptr); - auto n = dy_desc->dims[0]; - auto h_feature = dy_desc->dims[1]; - auto w_feature = dy_desc->dims[2]; - auto dy_c = dy_desc->dims[3]; - auto dx_c = dx_desc->dims[3]; - auto dy_type = dy_desc->dtype; + auto n = dy_desc->getDimIndex(0); + auto h_feature = dy_desc->getDimIndex(1); + auto w_feature = dy_desc->getDimIndex(2); + auto dy_c = dy_desc->getDimIndex(3); + auto dx_c = dx_desc->getDimIndex(3); + auto dy_type = dy_desc->getDtype(); auto half_h_mask = (h_mask - 1) >> 1; auto half_w_mask = (w_mask - 1) >> 1; diff --git a/kernels/psroipool/psroipool.cpp b/kernels/psroipool/psroipool.cpp index 5bba8273c..9ec7669b7 100644 --- a/kernels/psroipool/psroipool.cpp +++ b/kernels/psroipool/psroipool.cpp @@ -59,29 +59,29 @@ static mluOpStatus_t psRoiPoolForwardParamCheck( PARAM_CHECK(api, rois_desc != NULL); PARAM_CHECK(api, output_desc != NULL); PARAM_CHECK(api, mapping_channel_desc != NULL); - PARAM_CHECK(api, input_desc->dim == 4); - PARAM_CHECK(api, rois_desc->dim == 2); - PARAM_CHECK(api, output_desc->dim == 4); - PARAM_CHECK(api, mapping_channel_desc->dim == 4); + PARAM_CHECK(api, input_desc->getDim() == 4); + PARAM_CHECK(api, rois_desc->getDim() == 2); + PARAM_CHECK(api, output_desc->getDim() == 4); + PARAM_CHECK(api, mapping_channel_desc->getDim() == 4); // check the input and output datatype - PARAM_CHECK(api, input_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(api, rois_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(api, output_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(api, mapping_channel_desc->dtype == MLUOP_DTYPE_INT32); + PARAM_CHECK(api, input_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(api, rois_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(api, output_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(api, mapping_channel_desc->getDtype() == MLUOP_DTYPE_INT32); // check layout - PARAM_CHECK(api, input_desc->layout == MLUOP_LAYOUT_NHWC); - PARAM_CHECK(api, output_desc->layout == MLUOP_LAYOUT_NHWC); - PARAM_CHECK(api, mapping_channel_desc->layout == MLUOP_LAYOUT_NHWC); + PARAM_CHECK(api, input_desc->getLayout() == MLUOP_LAYOUT_NHWC); + PARAM_CHECK(api, output_desc->getLayout() == MLUOP_LAYOUT_NHWC); + PARAM_CHECK(api, mapping_channel_desc->getLayout() == MLUOP_LAYOUT_NHWC); // param check - PARAM_CHECK(api, pooled_height == output_desc->dims[1]); - PARAM_CHECK(api, pooled_width == output_desc->dims[2]); - PARAM_CHECK(api, output_dim == output_desc->dims[3]); - PARAM_CHECK(api, group_size == output_desc->dims[1]); - PARAM_CHECK(api, output_desc->dims[1] == output_desc->dims[2]); + PARAM_CHECK(api, pooled_height == output_desc->getDimIndex(1)); + PARAM_CHECK(api, pooled_width == output_desc->getDimIndex(2)); + PARAM_CHECK(api, output_dim == output_desc->getDimIndex(3)); + PARAM_CHECK(api, group_size == output_desc->getDimIndex(1)); + PARAM_CHECK(api, output_desc->getDimIndex(1) == output_desc->getDimIndex(2)); PARAM_CHECK(api, group_size >= 1); - PARAM_CHECK(api, output_desc->dims[3] >= 1); + PARAM_CHECK(api, output_desc->getDimIndex(3) >= 1); PARAM_CHECK(api, spatial_scale > 0); - PARAM_CHECK(api, rois_desc->dims[1] == 5); + PARAM_CHECK(api, rois_desc->getDimIndex(1) == 5); // stride check STRIDE_TENSOR_CHECK("[mluOpPsRoiPoolForward]:", input_desc, "input_desc must be contiguous"); @@ -92,12 +92,12 @@ static mluOpStatus_t psRoiPoolForwardParamCheck( STRIDE_TENSOR_CHECK("[mluOpPsRoiPoolForward]:", mapping_channel_desc, "mapping_channel_desc must be contiguous"); // roi_num check - PARAM_CHECK(api, output_desc->dims[0] == rois_desc->dims[0]); - PARAM_CHECK(api, input_desc->dims[3] == output_desc->dims[1] * - output_desc->dims[2] * - output_desc->dims[3]); - for (int i = 0; i < output_desc->dim; ++i) { - if (output_desc->dims[i] != mapping_channel_desc->dims[i]) { + PARAM_CHECK(api, output_desc->getDimIndex(0) == rois_desc->getDimIndex(0)); + PARAM_CHECK(api, input_desc->getDimIndex(3) == output_desc->getDimIndex(1) * + output_desc->getDimIndex(2) * + output_desc->getDimIndex(3)); + for (int i = 0; i < output_desc->getDim(); ++i) { + if (output_desc->getDimIndex(i) != mapping_channel_desc->getDimIndex(i)) { LOG(ERROR) << api << " Check failed: output_desc->dims[" << i << "] should be equal to mapping_channel_desc->dims[" << i << "]."; @@ -105,16 +105,16 @@ static mluOpStatus_t psRoiPoolForwardParamCheck( } } if ((mluOpGetTensorElementNum(output_desc) * - mluop::getSizeOfDataType(output_desc->dtype) >= + mluop::getSizeOfDataType(output_desc->getDtype()) >= LARGE_TENSOR_SIZE) || (mluOpGetTensorElementNum(input_desc) * - mluop::getSizeOfDataType(input_desc->dtype) >= + mluop::getSizeOfDataType(input_desc->getDtype()) >= LARGE_TENSOR_SIZE) || (mluOpGetTensorElementNum(rois_desc) * - mluop::getSizeOfDataType(rois_desc->dtype) >= + mluop::getSizeOfDataType(rois_desc->getDtype()) >= LARGE_TENSOR_SIZE) || (mluOpGetTensorElementNum(mapping_channel_desc) * - mluop::getSizeOfDataType(mapping_channel_desc->dtype) >= + mluop::getSizeOfDataType(mapping_channel_desc->getDtype()) >= LARGE_TENSOR_SIZE)) { LOG(ERROR) << api << " Overflow max tensor size." << " Currently, MLU-OPS supports tensor size smaller than 2^31."; @@ -158,27 +158,27 @@ static mluOpStatus_t psRoiPoolBackwardParamCheck( PARAM_CHECK(api, rois_desc != NULL); PARAM_CHECK(api, mapping_channel_desc != NULL); PARAM_CHECK(api, bottom_grad_desc != NULL); - PARAM_CHECK(api, top_grad_desc->dim == 4); - PARAM_CHECK(api, rois_desc->dim == 2); - PARAM_CHECK(api, mapping_channel_desc->dim == 4); - PARAM_CHECK(api, bottom_grad_desc->dim == 4); + PARAM_CHECK(api, top_grad_desc->getDim() == 4); + PARAM_CHECK(api, rois_desc->getDim() == 2); + PARAM_CHECK(api, mapping_channel_desc->getDim() == 4); + PARAM_CHECK(api, bottom_grad_desc->getDim() == 4); // check the input and output datatype - PARAM_CHECK(api, top_grad_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(api, rois_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(api, mapping_channel_desc->dtype == MLUOP_DTYPE_INT32); - PARAM_CHECK(api, bottom_grad_desc->dtype == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(api, top_grad_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(api, rois_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(api, mapping_channel_desc->getDtype() == MLUOP_DTYPE_INT32); + PARAM_CHECK(api, bottom_grad_desc->getDtype() == MLUOP_DTYPE_FLOAT); // check layout - PARAM_CHECK(api, top_grad_desc->layout == MLUOP_LAYOUT_NHWC); - PARAM_CHECK(api, mapping_channel_desc->layout == MLUOP_LAYOUT_NHWC); - PARAM_CHECK(api, bottom_grad_desc->layout == MLUOP_LAYOUT_NHWC); + PARAM_CHECK(api, top_grad_desc->getLayout() == MLUOP_LAYOUT_NHWC); + PARAM_CHECK(api, mapping_channel_desc->getLayout() == MLUOP_LAYOUT_NHWC); + PARAM_CHECK(api, bottom_grad_desc->getLayout() == MLUOP_LAYOUT_NHWC); // param check - PARAM_CHECK(api, pooled_height == top_grad_desc->dims[1]); - PARAM_CHECK(api, pooled_width == top_grad_desc->dims[2]); - PARAM_CHECK(api, output_dim == top_grad_desc->dims[3]); - PARAM_CHECK(api, top_grad_desc->dims[1] == top_grad_desc->dims[2]); - PARAM_CHECK(api, top_grad_desc->dims[3] >= 1); + PARAM_CHECK(api, pooled_height == top_grad_desc->getDimIndex(1)); + PARAM_CHECK(api, pooled_width == top_grad_desc->getDimIndex(2)); + PARAM_CHECK(api, output_dim == top_grad_desc->getDimIndex(3)); + PARAM_CHECK(api, top_grad_desc->getDimIndex(1) == top_grad_desc->getDimIndex(2)); + PARAM_CHECK(api, top_grad_desc->getDimIndex(3) >= 1); PARAM_CHECK(api, spatial_scale > 0); - PARAM_CHECK(api, rois_desc->dims[1] == 5); + PARAM_CHECK(api, rois_desc->getDimIndex(1) == 5); // stride check STRIDE_TENSOR_CHECK("[mluOpPsRoiPoolBackward]:", top_grad_desc, "top_grad_desc must be contiguous"); @@ -189,11 +189,11 @@ static mluOpStatus_t psRoiPoolBackwardParamCheck( STRIDE_TENSOR_CHECK("[mluOpPsRoiPoolBackward]:", bottom_grad_desc, "bottom_grad_desc must be contiguous"); // roi_num check - PARAM_CHECK(api, top_grad_desc->dims[0] == rois_desc->dims[0]); - PARAM_CHECK(api, bottom_grad_desc->dims[3] == + PARAM_CHECK(api, top_grad_desc->getDimIndex(0) == rois_desc->getDimIndex(0)); + PARAM_CHECK(api, bottom_grad_desc->getDimIndex(3) == output_dim * pooled_width * pooled_height); - for (int i = 0; i < top_grad_desc->dim; ++i) { - if (top_grad_desc->dims[i] != mapping_channel_desc->dims[i]) { + for (int i = 0; i < top_grad_desc->getDim(); ++i) { + if (top_grad_desc->getDimIndex(i) != mapping_channel_desc->getDimIndex(i)) { LOG(ERROR) << api << " Check failed: top_grad_desc->dims[" << i << "] should be equal to mapping_channel_desc->dims[" << i << "]."; @@ -202,16 +202,16 @@ static mluOpStatus_t psRoiPoolBackwardParamCheck( } if ((mluOpGetTensorElementNum(top_grad_desc) * - mluop::getSizeOfDataType(top_grad_desc->dtype) >= + mluop::getSizeOfDataType(top_grad_desc->getDtype()) >= LARGE_TENSOR_SIZE) || (mluOpGetTensorElementNum(bottom_grad_desc) * - mluop::getSizeOfDataType(bottom_grad_desc->dtype) >= + mluop::getSizeOfDataType(bottom_grad_desc->getDtype()) >= LARGE_TENSOR_SIZE) || (mluOpGetTensorElementNum(rois_desc) * - mluop::getSizeOfDataType(rois_desc->dtype) >= + mluop::getSizeOfDataType(rois_desc->getDtype()) >= LARGE_TENSOR_SIZE) || (mluOpGetTensorElementNum(mapping_channel_desc) * - mluop::getSizeOfDataType(mapping_channel_desc->dtype) >= + mluop::getSizeOfDataType(mapping_channel_desc->getDtype()) >= LARGE_TENSOR_SIZE)) { LOG(ERROR) << api << " Overflow max tensor size." << " Currently, MLU-OPS supports tensor size smaller than 2^31."; @@ -239,12 +239,12 @@ mluOpStatus_t MLUOP_WIN_API mluOpPsRoiPoolForward( return ret; } - const int batch_size = input_desc->dims[0]; - const int height = input_desc->dims[1]; - const int width = input_desc->dims[2]; - const int channels = input_desc->dims[3]; - const int rois_sum = output_desc->dims[0]; - const int rois_offset = rois_desc->dims[1]; + const int batch_size = input_desc->getDimIndex(0); + const int height = input_desc->getDimIndex(1); + const int width = input_desc->getDimIndex(2); + const int channels = input_desc->getDimIndex(3); + const int rois_sum = output_desc->getDimIndex(0); + const int rois_offset = rois_desc->getDimIndex(1); if (MLUOP_GEN_CASE_ON_NEW) { GEN_CASE_START("psroipool_forward", "PSROIPOOL_FORWARD"); @@ -314,12 +314,12 @@ mluOpStatus_t MLUOP_WIN_API mluOpPsRoiPoolBackward( PARAM_CHECK(api, bottom_grad != NULL); PARAM_CHECK(api, mapping_channel != NULL); - const int batch_size = bottom_grad_desc->dims[0]; - const int height = bottom_grad_desc->dims[1]; - const int width = bottom_grad_desc->dims[2]; - const int channels = bottom_grad_desc->dims[3]; - const int rois_sum = rois_desc->dims[0]; - const int rois_offset = rois_desc->dims[1]; + const int batch_size = bottom_grad_desc->getDimIndex(0); + const int height = bottom_grad_desc->getDimIndex(1); + const int width = bottom_grad_desc->getDimIndex(2); + const int channels = bottom_grad_desc->getDimIndex(3); + const int rois_sum = rois_desc->getDimIndex(0); + const int rois_offset = rois_desc->getDimIndex(1); if (MLUOP_GEN_CASE_ON_NEW) { GEN_CASE_START("psroipool_backward", "PSROIPOOL_BACKWARD"); diff --git a/kernels/roi_align_rotated/roi_align_rotated.cpp b/kernels/roi_align_rotated/roi_align_rotated.cpp index 3b4e8a95c..3f7b2a188 100644 --- a/kernels/roi_align_rotated/roi_align_rotated.cpp +++ b/kernels/roi_align_rotated/roi_align_rotated.cpp @@ -57,13 +57,13 @@ mluOpStatus_t MLUOP_WIN_API mluOpRoiAlignRotatedForward( PARAM_CHECK(API, rois_desc != nullptr); PARAM_CHECK(API, output_desc != nullptr); - PARAM_CHECK(API, features_desc->layout == MLUOP_LAYOUT_NHWC); - PARAM_CHECK(API, output_desc->layout == MLUOP_LAYOUT_NHWC); + PARAM_CHECK(API, features_desc->getLayout() == MLUOP_LAYOUT_NHWC); + PARAM_CHECK(API, output_desc->getLayout() == MLUOP_LAYOUT_NHWC); - PARAM_CHECK(API, features_desc->dtype == output_desc->dtype); - PARAM_CHECK(API, output_desc->dtype == rois_desc->dtype); - PARAM_CHECK(API, features_desc->dtype == MLUOP_DTYPE_FLOAT || - features_desc->dtype == MLUOP_DTYPE_HALF); + PARAM_CHECK(API, features_desc->getDtype() == output_desc->getDtype()); + PARAM_CHECK(API, output_desc->getDtype() == rois_desc->getDtype()); + PARAM_CHECK(API, features_desc->getDtype() == MLUOP_DTYPE_FLOAT || + features_desc->getDtype() == MLUOP_DTYPE_HALF); STRIDE_TENSOR_CHECK("[mluOpRoiAlignRotatedForward]:", features_desc, "features_desc must be contiguous"); @@ -72,36 +72,36 @@ mluOpStatus_t MLUOP_WIN_API mluOpRoiAlignRotatedForward( STRIDE_TENSOR_CHECK("[mluOpRoiAlignRotatedForward]:", output_desc, "output_desc must be contiguous"); - PARAM_CHECK_EQ(API, rois_desc->dim, 2); - PARAM_CHECK_EQ(API, output_desc->dim, 4); - PARAM_CHECK_EQ(API, features_desc->dim, 4); - PARAM_CHECK_EQ(API, rois_desc->dims[1], 6); + PARAM_CHECK_EQ(API, rois_desc->getDim(), 2); + PARAM_CHECK_EQ(API, output_desc->getDim(), 4); + PARAM_CHECK_EQ(API, features_desc->getDim(), 4); + PARAM_CHECK_EQ(API, rois_desc->getDimIndex(1), 6); - PARAM_CHECK_EQ(API, output_desc->dims[1], pooled_height); - PARAM_CHECK_EQ(API, output_desc->dims[2], pooled_width); + PARAM_CHECK_EQ(API, output_desc->getDimIndex(1), pooled_height); + PARAM_CHECK_EQ(API, output_desc->getDimIndex(2), pooled_width); - PARAM_CHECK_GT(API, features_desc->dims[3], 0); - PARAM_CHECK_GT(API, rois_desc->dims[0], 0); + PARAM_CHECK_GT(API, features_desc->getDimIndex(3), 0); + PARAM_CHECK_GT(API, rois_desc->getDimIndex(0), 0); - if (output_desc->dims[0] != rois_desc->dims[0]) { - LOG(ERROR) << API << " rois_desc batch = " << rois_desc->dims[0] - << ", output_desc batch = " << output_desc->dims[0] + if (output_desc->getDimIndex(0) != rois_desc->getDimIndex(0)) { + LOG(ERROR) << API << " rois_desc batch = " << rois_desc->getDimIndex(0) + << ", output_desc batch = " << output_desc->getDimIndex(0) << ". They should be the same."; return MLUOP_STATUS_BAD_PARAM; } - if (output_desc->dims[3] != features_desc->dims[3]) { - LOG(ERROR) << API << " features_desc channel = " << features_desc->dims[3] - << ", output_desc channel = " << output_desc->dims[3] + if (output_desc->getDimIndex(3) != features_desc->getDimIndex(3)) { + LOG(ERROR) << API << " features_desc channel = " << features_desc->getDimIndex(3) + << ", output_desc channel = " << output_desc->getDimIndex(3) << ". They should be the same."; return MLUOP_STATUS_BAD_PARAM; } - const int channel = features_desc->dims[3]; - const int width = features_desc->dims[2]; - const int height = features_desc->dims[1]; - const int batch = features_desc->dims[0]; - const int rois_nums = rois_desc->dims[0]; - mluOpDataType_t data_type = features_desc->dtype; + const int channel = features_desc->getDimIndex(3); + const int width = features_desc->getDimIndex(2); + const int height = features_desc->getDimIndex(1); + const int batch = features_desc->getDimIndex(0); + const int rois_nums = rois_desc->getDimIndex(0); + mluOpDataType_t data_type = features_desc->getDtype(); PARAM_CHECK_GT(API, pooled_height, 0); PARAM_CHECK_GT(API, pooled_width, 0); @@ -151,7 +151,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpRoiAlignRotatedForward( VLOG(5) << "[mluOpRoiAlignRotatedForward] launch kernel policyFunc[" << k_dim.x << ", " << k_dim.y << ", " << k_dim.z << "]."; CHECK_RETURN(API, KernelRoiAlignRotatedForward( - k_dim, k_type, handle->queue, features_desc->dtype, + k_dim, k_type, handle->queue, features_desc->getDtype(), features, rois, batch, height, width, channel, rois_nums, roiAlignRotatedParams, output)); VLOG(5) << "Kernel KernelRoiAlignRotatedForward."; @@ -173,13 +173,13 @@ mluOpStatus_t MLUOP_WIN_API mluOpRoiAlignRotatedBackward( PARAM_CHECK(API, rois_desc != nullptr); PARAM_CHECK(API, bottom_grad_desc != nullptr); - PARAM_CHECK(API, top_grad_desc->layout == MLUOP_LAYOUT_NHWC); - PARAM_CHECK(API, bottom_grad_desc->layout == MLUOP_LAYOUT_NHWC); + PARAM_CHECK(API, top_grad_desc->getLayout() == MLUOP_LAYOUT_NHWC); + PARAM_CHECK(API, bottom_grad_desc->getLayout() == MLUOP_LAYOUT_NHWC); - PARAM_CHECK(API, (top_grad_desc->dtype == bottom_grad_desc->dtype) && - (bottom_grad_desc->dtype == rois_desc->dtype)); - PARAM_CHECK(API, bottom_grad_desc->dtype == MLUOP_DTYPE_FLOAT || - bottom_grad_desc->dtype == MLUOP_DTYPE_HALF); + PARAM_CHECK(API, (top_grad_desc->getDtype() == bottom_grad_desc->getDtype()) && + (bottom_grad_desc->getDtype() == rois_desc->getDtype())); + PARAM_CHECK(API, bottom_grad_desc->getDtype() == MLUOP_DTYPE_FLOAT || + bottom_grad_desc->getDtype() == MLUOP_DTYPE_HALF); STRIDE_TENSOR_CHECK("[mluOpRoiAlignRotatedBackward]:", top_grad_desc, "top_grad_desc must be contiguous"); @@ -188,37 +188,37 @@ mluOpStatus_t MLUOP_WIN_API mluOpRoiAlignRotatedBackward( STRIDE_TENSOR_CHECK("[mluOpRoiAlignRotatedBackward]:", bottom_grad_desc, "bottom_grad_desc must be contiguous"); - PARAM_CHECK_EQ(API, rois_desc->dim, 2); - PARAM_CHECK_EQ(API, top_grad_desc->dim, 4); - PARAM_CHECK_EQ(API, bottom_grad_desc->dim, 4); - PARAM_CHECK_EQ(API, rois_desc->dims[1], 6); + PARAM_CHECK_EQ(API, rois_desc->getDim(), 2); + PARAM_CHECK_EQ(API, top_grad_desc->getDim(), 4); + PARAM_CHECK_EQ(API, bottom_grad_desc->getDim(), 4); + PARAM_CHECK_EQ(API, rois_desc->getDimIndex(1), 6); - PARAM_CHECK_EQ(API, top_grad_desc->dims[1], pooled_height); - PARAM_CHECK_EQ(API, top_grad_desc->dims[2], pooled_width); + PARAM_CHECK_EQ(API, top_grad_desc->getDimIndex(1), pooled_height); + PARAM_CHECK_EQ(API, top_grad_desc->getDimIndex(2), pooled_width); - PARAM_CHECK_GT(API, bottom_grad_desc->dims[3], 0); - PARAM_CHECK_GT(API, rois_desc->dims[0], 0); + PARAM_CHECK_GT(API, bottom_grad_desc->getDimIndex(3), 0); + PARAM_CHECK_GT(API, rois_desc->getDimIndex(0), 0); - if (top_grad_desc->dims[0] != rois_desc->dims[0]) { - LOG(ERROR) << API << " rois_desc batch = " << rois_desc->dims[0] - << ", top_grad_desc batch = " << top_grad_desc->dims[0] + if (top_grad_desc->getDimIndex(0) != rois_desc->getDimIndex(0)) { + LOG(ERROR) << API << " rois_desc batch = " << rois_desc->getDimIndex(0) + << ", top_grad_desc batch = " << top_grad_desc->getDimIndex(0) << ". They should be the same."; return MLUOP_STATUS_BAD_PARAM; } - if (top_grad_desc->dims[3] != bottom_grad_desc->dims[3]) { + if (top_grad_desc->getDimIndex(3) != bottom_grad_desc->getDimIndex(3)) { LOG(ERROR) << API - << " bottom_grad_desc channel = " << bottom_grad_desc->dims[3] - << ", top_grad_desc channel = " << top_grad_desc->dims[3] + << " bottom_grad_desc channel = " << bottom_grad_desc->getDimIndex(3) + << ", top_grad_desc channel = " << top_grad_desc->getDimIndex(3) << ". They should be the same."; return MLUOP_STATUS_BAD_PARAM; } - const int channel = bottom_grad_desc->dims[3]; - const int width = bottom_grad_desc->dims[2]; - const int height = bottom_grad_desc->dims[1]; - const int batch = bottom_grad_desc->dims[0]; - const int rois_nums = rois_desc->dims[0]; - mluOpDataType_t data_type = bottom_grad_desc->dtype; + const int channel = bottom_grad_desc->getDimIndex(3); + const int width = bottom_grad_desc->getDimIndex(2); + const int height = bottom_grad_desc->getDimIndex(1); + const int batch = bottom_grad_desc->getDimIndex(0); + const int rois_nums = rois_desc->getDimIndex(0); + mluOpDataType_t data_type = bottom_grad_desc->getDtype(); PARAM_CHECK_GT(API, pooled_height, 0); PARAM_CHECK_GT(API, pooled_width, 0); @@ -283,7 +283,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpRoiAlignRotatedBackward( VLOG(5) << "cnnlFill_v3 end."; CHECK_RETURN(API, KernelRoiAlignRotatedBackward( - k_dim, k_type, handle->queue, top_grad_desc->dtype, + k_dim, k_type, handle->queue, top_grad_desc->getDtype(), top_grad, rois, batch, height, width, channel, rois_nums, roiAlignRotatedParams, bottom_grad)); VLOG(5) << "Kernel KernelRoiAlignRotatedBackward."; diff --git a/kernels/roi_crop/roi_crop.cpp b/kernels/roi_crop/roi_crop.cpp index ffdb6078c..1c749ff21 100644 --- a/kernels/roi_crop/roi_crop.cpp +++ b/kernels/roi_crop/roi_crop.cpp @@ -59,15 +59,15 @@ mluOpStatus_t RoiCropForwardParamCheck( PARAM_CHECK(op_name, grid_desc != NULL); PARAM_CHECK(op_name, output_desc != NULL); // check data type and dim - PARAM_CHECK(op_name, input_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(op_name, input_desc->dim == 4); - PARAM_CHECK(op_name, grid_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(op_name, grid_desc->dim == 4); - PARAM_CHECK(op_name, output_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(op_name, output_desc->dim == 4); + PARAM_CHECK(op_name, input_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(op_name, input_desc->getDim() == 4); + PARAM_CHECK(op_name, grid_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(op_name, grid_desc->getDim() == 4); + PARAM_CHECK(op_name, output_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(op_name, output_desc->getDim() == 4); // check shape and layout - PARAM_CHECK(op_name, input_desc->layout == MLUOP_LAYOUT_NHWC); - PARAM_CHECK(op_name, output_desc->layout == MLUOP_LAYOUT_NHWC); + PARAM_CHECK(op_name, input_desc->getLayout() == MLUOP_LAYOUT_NHWC); + PARAM_CHECK(op_name, output_desc->getLayout() == MLUOP_LAYOUT_NHWC); // check stride STRIDE_TENSOR_CHECK("[mluOpRoiCropForward]:", input_desc, "input_desc must be contiguous"); @@ -76,22 +76,22 @@ mluOpStatus_t RoiCropForwardParamCheck( STRIDE_TENSOR_CHECK("[mluOpRoiCropForward]:", output_desc, "output_desc must be contiguous"); - for (int i = 0; i < output_desc->dim - 1; ++i) { - if (output_desc->dims[i] != grid_desc->dims[i]) { + for (int i = 0; i < output_desc->getDim() - 1; ++i) { + if (output_desc->getDimIndex(i) != grid_desc->getDimIndex(i)) { LOG(ERROR) << op_name << " Check failed: output_desc->dims[" << i - << "] should be equal to grid_desc->dims[" << i << "]."; + << "] should be equal to grid_desc->getDimIndex(" << i << ")."; return MLUOP_STATUS_BAD_PARAM; } } - if (output_desc->dims[3] != input_desc->dims[3]) { + if (output_desc->getDimIndex(3) != input_desc->getDimIndex(3)) { LOG(ERROR) << op_name - << " Check failed: output_desc->dims[3] should be " - "equal to input_desc->dims[3]."; + << " Check failed: output_desc->getDimIndex(3) should be " + "equal to input_desc->getDimIndex(3)."; return MLUOP_STATUS_BAD_PARAM; } - if (grid_desc->dims[3] != 2) { + if (grid_desc->getDimIndex(3) != 2) { LOG(ERROR) << op_name - << " Check failed: grid_desc->dims[3] should be equal to 2."; + << " Check failed: grid_desc->getDimIndex(3) should be equal to 2."; return MLUOP_STATUS_BAD_PARAM; } const size_t max_input_num = 2147483648; // 2^31, 2G num @@ -126,15 +126,15 @@ mluOpStatus_t RoiCropBackwardParamCheck( PARAM_CHECK(op_name, grid_desc != NULL); PARAM_CHECK(op_name, grad_input_desc != NULL); // check data type - PARAM_CHECK(op_name, grad_output_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(op_name, grad_output_desc->dim == 4); - PARAM_CHECK(op_name, grid_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(op_name, grid_desc->dim == 4); - PARAM_CHECK(op_name, grad_input_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(op_name, grad_input_desc->dim == 4); + PARAM_CHECK(op_name, grad_output_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(op_name, grad_output_desc->getDim() == 4); + PARAM_CHECK(op_name, grid_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(op_name, grid_desc->getDim() == 4); + PARAM_CHECK(op_name, grad_input_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(op_name, grad_input_desc->getDim() == 4); // check shape and layout - PARAM_CHECK(op_name, grad_output_desc->layout == MLUOP_LAYOUT_NHWC); - PARAM_CHECK(op_name, grad_input_desc->layout == MLUOP_LAYOUT_NHWC); + PARAM_CHECK(op_name, grad_output_desc->getLayout() == MLUOP_LAYOUT_NHWC); + PARAM_CHECK(op_name, grad_input_desc->getLayout() == MLUOP_LAYOUT_NHWC); // check stride STRIDE_TENSOR_CHECK("[mluOpRoiCropBackward]:", grad_output_desc, "grad_output_desc must be contiguous"); @@ -143,22 +143,22 @@ mluOpStatus_t RoiCropBackwardParamCheck( STRIDE_TENSOR_CHECK("[mluOpRoiCropBackward]:", grad_input_desc, "grad_input_desc must be contiguous"); - for (int i = 0; i < grad_output_desc->dim - 1; ++i) { - if (grad_output_desc->dims[i] != grid_desc->dims[i]) { + for (int i = 0; i < grad_output_desc->getDim() - 1; ++i) { + if (grad_output_desc->getDimIndex(i) != grid_desc->getDimIndex(i)) { LOG(ERROR) << op_name << " Check failed: grad_output_desc->dims[" << i - << "] should be equal to grid_desc->dims[" << i << "]."; + << "] should be equal to grid_desc->getDimIndex(" << i << ")."; return MLUOP_STATUS_BAD_PARAM; } } - if (grad_output_desc->dims[3] != grad_input_desc->dims[3]) { + if (grad_output_desc->getDimIndex(3) != grad_input_desc->getDimIndex(3)) { LOG(ERROR) << op_name - << " Check failed: grad_output_desc->dims[3] should be " - "equal to grad_input_desc->dims[3]."; + << " Check failed: grad_output_desc->getDimIndex(3) should be " + "equal to grad_input_desc->getDimIndex(3)."; return MLUOP_STATUS_BAD_PARAM; } - if (grid_desc->dims[3] != 2) { + if (grid_desc->getDimIndex(3) != 2) { LOG(ERROR) << op_name - << " Check failed: grid_desc->dims[3] should be equal to 2."; + << " Check failed: grid_desc->getDimIndex(3) should be equal to 2."; return MLUOP_STATUS_BAD_PARAM; } const size_t max_input_num = 2147483648; // 2^31 2G num @@ -194,13 +194,13 @@ mluOpStatus_t MLUOP_WIN_API mluOpRoiCropForward( return param_check; } - uint32_t batch = input_desc->dims[0]; - uint32_t height = input_desc->dims[1]; - uint32_t width = input_desc->dims[2]; - uint32_t channels = input_desc->dims[3]; - uint32_t grid_n = grid_desc->dims[0]; - uint32_t output_h = output_desc->dims[1]; - uint32_t output_w = output_desc->dims[2]; + uint32_t batch = input_desc->getDimIndex(0); + uint32_t height = input_desc->getDimIndex(1); + uint32_t width = input_desc->getDimIndex(2); + uint32_t channels = input_desc->getDimIndex(3); + uint32_t grid_n = grid_desc->getDimIndex(0); + uint32_t output_h = output_desc->getDimIndex(1); + uint32_t output_w = output_desc->getDimIndex(2); uint32_t bin_num = grid_n * output_h * output_w; if (MLUOP_GEN_CASE_ON_NEW) { @@ -241,13 +241,13 @@ mluOpStatus_t MLUOP_WIN_API mluOpRoiCropBackward( return param_check; } - uint32_t batch = grad_input_desc->dims[0]; - uint32_t height = grad_input_desc->dims[1]; - uint32_t width = grad_input_desc->dims[2]; - uint32_t channels = grad_input_desc->dims[3]; - uint32_t grid_n = grid_desc->dims[0]; - uint32_t output_h = grad_output_desc->dims[1]; - uint32_t output_w = grad_output_desc->dims[2]; + uint32_t batch = grad_input_desc->getDimIndex(0); + uint32_t height = grad_input_desc->getDimIndex(1); + uint32_t width = grad_input_desc->getDimIndex(2); + uint32_t channels = grad_input_desc->getDimIndex(3); + uint32_t grid_n = grid_desc->getDimIndex(0); + uint32_t output_h = grad_output_desc->getDimIndex(1); + uint32_t output_w = grad_output_desc->getDimIndex(2); uint32_t bin_num = grid_n * output_h * output_w; if (MLUOP_GEN_CASE_ON_NEW) { diff --git a/kernels/roiaware_pool3d/roiaware_pool3d.cpp b/kernels/roiaware_pool3d/roiaware_pool3d.cpp index 117fdcfe4..fdc70f56e 100644 --- a/kernels/roiaware_pool3d/roiaware_pool3d.cpp +++ b/kernels/roiaware_pool3d/roiaware_pool3d.cpp @@ -46,7 +46,7 @@ static mluOpStatus_t kernelPtsIdxOfVoxelsPolicyFunc( const int core_limit = mluop::runtime::getCoreNumOfEachUnionCapability(handle); const int core_num = core_limit * cluster_limit; - const int boxes_num = pts_idx_of_voxels_desc->dims[0]; + const int boxes_num = pts_idx_of_voxels_desc->getDimIndex(0); const int task_dim = boxes_num > core_num ? core_num : boxes_num; k_dim->x = core_limit; k_dim->y = (task_dim / core_limit) > 0 ? (task_dim / core_limit) : 1; @@ -64,10 +64,10 @@ static mluOpStatus_t kernelRoiawarePool3dForwardPolicyFunc( const int core_limit = mluop::runtime::getCoreNumOfEachUnionCapability(handle); const int core_num = core_limit * cluster_limit; - const int boxes_num = pooled_features_desc->dims[0]; - const int out_x = pooled_features_desc->dims[1]; - const int out_y = pooled_features_desc->dims[2]; - const int out_z = pooled_features_desc->dims[3]; + const int boxes_num = pooled_features_desc->getDimIndex(0); + const int out_x = pooled_features_desc->getDimIndex(1); + const int out_y = pooled_features_desc->getDimIndex(2); + const int out_z = pooled_features_desc->getDimIndex(3); const int voxeles_num = boxes_num * out_x * out_y * out_z; const int task_dim = voxeles_num > core_num ? core_num : voxeles_num; k_dim->x = core_limit; @@ -85,10 +85,10 @@ static mluOpStatus_t kernelRoiawarePool3dBackwardPolicyFunc( const int core_limit = mluop::runtime::getCoreNumOfEachUnionCapability(handle); const int core_num = core_limit * cluster_limit; - const int boxes_num = grad_out_desc->dims[0]; - const int out_x = grad_out_desc->dims[1]; - const int out_y = grad_out_desc->dims[2]; - const int out_z = grad_out_desc->dims[3]; + const int boxes_num = grad_out_desc->getDimIndex(0); + const int out_x = grad_out_desc->getDimIndex(1); + const int out_y = grad_out_desc->getDimIndex(2); + const int out_z = grad_out_desc->getDimIndex(3); const int voxels_num = boxes_num * out_x * out_y * out_z; const int task_dim = voxels_num > core_num ? core_num : voxels_num; k_dim->x = core_limit; @@ -103,7 +103,7 @@ static mluOpStatus_t transposeTensor( const void *input, const int *permute, const mluOpTensorDescriptor_t workspace_dst_desc, void *workspace_dst, void *transpose_workspace) { - int input_dim = input_desc->dim; + int input_dim = input_desc->getDim(); cnnlTransposeDescriptor_t trans_desc = NULL; size_t transpose_workspace_size = 0; CALL_CNNL(cnnlCreateTransposeDescriptor(&trans_desc)); @@ -143,8 +143,8 @@ mluOpStatus_t MLUOP_WIN_API mluOpGetRoiAwarePool3dForwardWorkspaceSize( pts_feature_desc != nullptr); PARAM_CHECK("[mluOpGetRoiAwarePool3dForwardWorkspaceSize]", workspace_size != nullptr); - const int pts_num = pts_feature_desc->dims[0]; - const int channels = pts_feature_desc->dims[1]; + const int pts_num = pts_feature_desc->getDimIndex(0); + const int channels = pts_feature_desc->getDimIndex(1); int element_num = pts_num * 3 + pts_num * channels; element_num += (channels > 3) ? (pts_num * channels) : (pts_num * 3); // check zero @@ -153,7 +153,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpGetRoiAwarePool3dForwardWorkspaceSize( return MLUOP_STATUS_SUCCESS; } *workspace_size = - element_num * mluop::getSizeOfDataType(pts_feature_desc->dtype); + element_num * mluop::getSizeOfDataType(pts_feature_desc->getDtype()); return MLUOP_STATUS_SUCCESS; } @@ -186,37 +186,37 @@ mluOpStatus_t MLUOP_WIN_API mluOpRoiAwarePool3dForward( PARAM_CHECK(API, pooled_features_desc != NULL); // check dim - PARAM_CHECK(API, rois_desc->dim == 2); - PARAM_CHECK(API, pts_desc->dim == 2); - PARAM_CHECK(API, pts_feature_desc->dim == 2); - PARAM_CHECK(API, pts_idx_of_voxels_desc->dim == 5); - PARAM_CHECK(API, pooled_features_desc->dim == 5); + PARAM_CHECK(API, rois_desc->getDim() == 2); + PARAM_CHECK(API, pts_desc->getDim() == 2); + PARAM_CHECK(API, pts_feature_desc->getDim() == 2); + PARAM_CHECK(API, pts_idx_of_voxels_desc->getDim() == 5); + PARAM_CHECK(API, pooled_features_desc->getDim() == 5); // check shape - PARAM_CHECK(API, rois_desc->dims[0] == boxes_num); - PARAM_CHECK(API, rois_desc->dims[1] == 7); - PARAM_CHECK(API, pts_desc->dims[0] == pts_num); - PARAM_CHECK(API, pts_desc->dims[1] == 3); - PARAM_CHECK(API, pts_feature_desc->dims[0] == pts_num); - PARAM_CHECK(API, pts_feature_desc->dims[1] == channels); - PARAM_CHECK(API, pts_idx_of_voxels_desc->dims[0] == boxes_num); - PARAM_CHECK(API, pts_idx_of_voxels_desc->dims[1] == out_x); - PARAM_CHECK(API, pts_idx_of_voxels_desc->dims[2] == out_y); - PARAM_CHECK(API, pts_idx_of_voxels_desc->dims[3] == out_z); - PARAM_CHECK(API, pts_idx_of_voxels_desc->dims[4] == max_pts_each_voxel); - PARAM_CHECK(API, pooled_features_desc->dims[0] == boxes_num); - PARAM_CHECK(API, pooled_features_desc->dims[1] == out_x); - PARAM_CHECK(API, pooled_features_desc->dims[2] == out_y); - PARAM_CHECK(API, pooled_features_desc->dims[3] == out_z); - PARAM_CHECK(API, pooled_features_desc->dims[4] == channels); + PARAM_CHECK(API, rois_desc->getDimIndex(0) == boxes_num); + PARAM_CHECK(API, rois_desc->getDimIndex(1) == 7); + PARAM_CHECK(API, pts_desc->getDimIndex(0) == pts_num); + PARAM_CHECK(API, pts_desc->getDimIndex(1) == 3); + PARAM_CHECK(API, pts_feature_desc->getDimIndex(0) == pts_num); + PARAM_CHECK(API, pts_feature_desc->getDimIndex(1) == channels); + PARAM_CHECK(API, pts_idx_of_voxels_desc->getDimIndex(0) == boxes_num); + PARAM_CHECK(API, pts_idx_of_voxels_desc->getDimIndex(1) == out_x); + PARAM_CHECK(API, pts_idx_of_voxels_desc->getDimIndex(2) == out_y); + PARAM_CHECK(API, pts_idx_of_voxels_desc->getDimIndex(3) == out_z); + PARAM_CHECK(API, pts_idx_of_voxels_desc->getDimIndex(4) == max_pts_each_voxel); + PARAM_CHECK(API, pooled_features_desc->getDimIndex(0) == boxes_num); + PARAM_CHECK(API, pooled_features_desc->getDimIndex(1) == out_x); + PARAM_CHECK(API, pooled_features_desc->getDimIndex(2) == out_y); + PARAM_CHECK(API, pooled_features_desc->getDimIndex(3) == out_z); + PARAM_CHECK(API, pooled_features_desc->getDimIndex(4) == channels); // check dtype - PARAM_CHECK(API, rois_desc->dtype == MLUOP_DTYPE_FLOAT || - rois_desc->dtype == MLUOP_DTYPE_HALF); - PARAM_CHECK(API, pts_desc->dtype == rois_desc->dtype); - PARAM_CHECK(API, pts_feature_desc->dtype == rois_desc->dtype); - PARAM_CHECK(API, pts_idx_of_voxels_desc->dtype == MLUOP_DTYPE_INT32); - PARAM_CHECK(API, pooled_features_desc->dtype == rois_desc->dtype); + PARAM_CHECK(API, rois_desc->getDtype() == MLUOP_DTYPE_FLOAT || + rois_desc->getDtype() == MLUOP_DTYPE_HALF); + PARAM_CHECK(API, pts_desc->getDtype() == rois_desc->getDtype()); + PARAM_CHECK(API, pts_feature_desc->getDtype() == rois_desc->getDtype()); + PARAM_CHECK(API, pts_idx_of_voxels_desc->getDtype() == MLUOP_DTYPE_INT32); + PARAM_CHECK(API, pooled_features_desc->getDtype() == rois_desc->getDtype()); // check other parms : pool_method PARAM_CHECK(API, pool_method == 0 || pool_method == 1); @@ -260,7 +260,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpRoiAwarePool3dForward( /* max_pts_each_voxel affects the allocation of NRAM memory space, so it's limited by the size of NRAM memory space. */ - if (rois_desc->dtype == MLUOP_DTYPE_FLOAT) { + if (rois_desc->getDtype() == MLUOP_DTYPE_FLOAT) { if (max_pts_each_voxel > THRESHOLD_OF_MAX_PTS_EACH_VOXEL_FLOAT_FORWARD) { LOG(ERROR) << API << " Check failed: " << "When the data type is float, " @@ -319,13 +319,13 @@ mluOpStatus_t MLUOP_WIN_API mluOpRoiAwarePool3dForward( // pool_method: 0 'max' 1 'avg' if (pool_method == 0) { PARAM_CHECK(API, argmax_desc != NULL); - PARAM_CHECK(API, argmax_desc->dim == 5); - PARAM_CHECK(API, argmax_desc->dims[0] == boxes_num); - PARAM_CHECK(API, argmax_desc->dims[1] == out_x); - PARAM_CHECK(API, argmax_desc->dims[2] == out_y); - PARAM_CHECK(API, argmax_desc->dims[3] == out_z); - PARAM_CHECK(API, argmax_desc->dims[4] == channels); - PARAM_CHECK(API, argmax_desc->dtype == MLUOP_DTYPE_INT32); + PARAM_CHECK(API, argmax_desc->getDim() == 5); + PARAM_CHECK(API, argmax_desc->getDimIndex(0) == boxes_num); + PARAM_CHECK(API, argmax_desc->getDimIndex(1) == out_x); + PARAM_CHECK(API, argmax_desc->getDimIndex(2) == out_y); + PARAM_CHECK(API, argmax_desc->getDimIndex(3) == out_z); + PARAM_CHECK(API, argmax_desc->getDimIndex(4) == channels); + PARAM_CHECK(API, argmax_desc->getDtype() == MLUOP_DTYPE_INT32); const uint64_t tensor_argmax_num = mluOpGetTensorElementNum(argmax_desc); TENSOR_NUM_CHECK(API, tensor_argmax_num, LARGE_TENSOR_NUM, ""); PARAM_CHECK(API, tensor_argmax_num > 0); @@ -367,7 +367,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpRoiAwarePool3dForward( } // generate mluOpRoiAwarePool3dForward prototxt end! - mluOpDataType_t data_dtype = pts_desc->dtype; + mluOpDataType_t data_dtype = pts_desc->getDtype(); uint64_t pts_dtype_size = mluOpGetTensorElementNum(pts_desc) * mluop::getSizeOfDataType(data_dtype); uint64_t pts_feature_dtype_size = mluOpGetTensorElementNum(pts_feature_desc) * @@ -378,11 +378,11 @@ mluOpStatus_t MLUOP_WIN_API mluOpRoiAwarePool3dForward( (int8_t *)pts_feature_workspace + pts_feature_dtype_size; VLOG(5) << "[mluOpRoiAwarePool3dForward] cnnlTranspose pts start."; - int pts_dim = pts_desc->dim; + int pts_dim = pts_desc->getDim(); int pts_permute[2] = {1, 0}; int pts_tmp_dims[2] = {0, 0}; for (int i = 0; i < pts_dim; ++i) { - pts_tmp_dims[i] = pts_desc->dims[pts_permute[i]]; + pts_tmp_dims[i] = pts_desc->getDimIndex(pts_permute[i]); } mluOpTensorDescriptor_t pts_desc_tmp = NULL; CHECK_RETURN("[mluOpRoiAwarePool3dForward]", @@ -402,11 +402,11 @@ mluOpStatus_t MLUOP_WIN_API mluOpRoiAwarePool3dForward( VLOG(5) << "[mluOpRoiAwarePool3dForward] cnnlTranspose pts end."; VLOG(5) << "[mluOpRoiAwarePool3dForward] cnnlTranspose pts_feature start."; - int pts_feature_dim = pts_feature_desc->dim; + int pts_feature_dim = pts_feature_desc->getDim(); int pts_feature_permute[2] = {1, 0}; int pts_feature_tmp_dims[2] = {0, 0}; for (int i = 0; i < pts_feature_dim; ++i) { - pts_feature_tmp_dims[i] = pts_feature_desc->dims[pts_feature_permute[i]]; + pts_feature_tmp_dims[i] = pts_feature_desc->getDimIndex(pts_feature_permute[i]); } mluOpTensorDescriptor_t pts_feature_desc_tmp = NULL; CHECK_RETURN("[mluOpRoiAwarePool3dForward]", @@ -481,7 +481,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpRoiAwarePool3dForward( "KernelPtsIdxOfVoxels()."; CHECK_RETURN("[mluOpRoiAwarePool3dForward]", KernelPtsIdxOfVoxels( - k_dim, k_type, handle->queue, rois_desc->dtype, pool_method, + k_dim, k_type, handle->queue, rois_desc->getDtype(), pool_method, boxes_num, pts_num, max_pts_each_voxel, out_x, out_y, out_z, rois, pts_workspace, pts_idx_of_voxels)); VLOG(5) << "[mluOpRoiAwarePool3dForward] Finish kernel " @@ -504,7 +504,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpRoiAwarePool3dForward( CHECK_RETURN( "[mluOpRoiAwarePool3dForward]", KernelRoiawarePool3dForward( - k_dim, k_type, handle->queue, pooled_features_desc->dtype, + k_dim, k_type, handle->queue, pooled_features_desc->getDtype(), pool_method, boxes_num, pts_num, channels, max_pts_each_voxel, out_x, out_y, out_z, pts_feature_workspace, pts_idx_of_voxels, pooled_features, argmax)); @@ -537,41 +537,41 @@ mluOpStatus_t MLUOP_WIN_API mluOpRoiAwarePool3dBackward( PARAM_CHECK(API, grad_in_desc != NULL); // check dim - PARAM_CHECK_EQ(API, pts_idx_of_voxels_desc->dim, 5); - PARAM_CHECK_EQ(API, argmax_desc->dim, 5); - PARAM_CHECK_EQ(API, grad_out_desc->dim, 5); - PARAM_CHECK_EQ(API, grad_in_desc->dim, 2); + PARAM_CHECK_EQ(API, pts_idx_of_voxels_desc->getDim(), 5); + PARAM_CHECK_EQ(API, argmax_desc->getDim(), 5); + PARAM_CHECK_EQ(API, grad_out_desc->getDim(), 5); + PARAM_CHECK_EQ(API, grad_in_desc->getDim(), 2); // check shape - PARAM_CHECK_EQ(API, pts_idx_of_voxels_desc->dims[0], boxes_num); - PARAM_CHECK_EQ(API, pts_idx_of_voxels_desc->dims[1], out_x); - PARAM_CHECK_EQ(API, pts_idx_of_voxels_desc->dims[2], out_y); - PARAM_CHECK_EQ(API, pts_idx_of_voxels_desc->dims[3], out_z); - PARAM_CHECK_EQ(API, pts_idx_of_voxels_desc->dims[4], max_pts_each_voxel); - PARAM_CHECK_EQ(API, argmax_desc->dims[0], boxes_num); - PARAM_CHECK_EQ(API, argmax_desc->dims[1], out_x); - PARAM_CHECK_EQ(API, argmax_desc->dims[2], out_y); - PARAM_CHECK_EQ(API, argmax_desc->dims[3], out_z); - PARAM_CHECK_EQ(API, argmax_desc->dims[4], channels); - PARAM_CHECK_EQ(API, grad_out_desc->dims[0], boxes_num); - PARAM_CHECK_EQ(API, grad_out_desc->dims[1], out_x); - PARAM_CHECK_EQ(API, grad_out_desc->dims[2], out_y); - PARAM_CHECK_EQ(API, grad_out_desc->dims[3], out_z); - PARAM_CHECK_EQ(API, grad_out_desc->dims[4], channels); - // grad_in_desc->dims[0] == pts_num - PARAM_CHECK_EQ(API, grad_in_desc->dims[1], channels); + PARAM_CHECK_EQ(API, pts_idx_of_voxels_desc->getDimIndex(0), boxes_num); + PARAM_CHECK_EQ(API, pts_idx_of_voxels_desc->getDimIndex(1), out_x); + PARAM_CHECK_EQ(API, pts_idx_of_voxels_desc->getDimIndex(2), out_y); + PARAM_CHECK_EQ(API, pts_idx_of_voxels_desc->getDimIndex(3), out_z); + PARAM_CHECK_EQ(API, pts_idx_of_voxels_desc->getDimIndex(4), max_pts_each_voxel); + PARAM_CHECK_EQ(API, argmax_desc->getDimIndex(0), boxes_num); + PARAM_CHECK_EQ(API, argmax_desc->getDimIndex(1), out_x); + PARAM_CHECK_EQ(API, argmax_desc->getDimIndex(2), out_y); + PARAM_CHECK_EQ(API, argmax_desc->getDimIndex(3), out_z); + PARAM_CHECK_EQ(API, argmax_desc->getDimIndex(4), channels); + PARAM_CHECK_EQ(API, grad_out_desc->getDimIndex(0), boxes_num); + PARAM_CHECK_EQ(API, grad_out_desc->getDimIndex(1), out_x); + PARAM_CHECK_EQ(API, grad_out_desc->getDimIndex(2), out_y); + PARAM_CHECK_EQ(API, grad_out_desc->getDimIndex(3), out_z); + PARAM_CHECK_EQ(API, grad_out_desc->getDimIndex(4), channels); + // grad_in_desc->getDimIndex(0) == pts_num + PARAM_CHECK_EQ(API, grad_in_desc->getDimIndex(1), channels); // check dtype - PARAM_CHECK(API, pts_idx_of_voxels_desc->dtype == MLUOP_DTYPE_INT32); - PARAM_CHECK(API, argmax_desc->dtype == MLUOP_DTYPE_INT32); - PARAM_CHECK(API, grad_out_desc->dtype == MLUOP_DTYPE_FLOAT || - grad_out_desc->dtype == MLUOP_DTYPE_HALF); - PARAM_CHECK(API, grad_in_desc->dtype == grad_out_desc->dtype); + PARAM_CHECK(API, pts_idx_of_voxels_desc->getDtype() == MLUOP_DTYPE_INT32); + PARAM_CHECK(API, argmax_desc->getDtype() == MLUOP_DTYPE_INT32); + PARAM_CHECK(API, grad_out_desc->getDtype() == MLUOP_DTYPE_FLOAT || + grad_out_desc->getDtype() == MLUOP_DTYPE_HALF); + PARAM_CHECK(API, grad_in_desc->getDtype() == grad_out_desc->getDtype()); // check other parms : pool_method PARAM_CHECK(API, pool_method == 0 || pool_method == 1); - const int pts_num = grad_in_desc->dims[0]; + const int pts_num = grad_in_desc->getDimIndex(0); // check tensor dim PARAM_CHECK(API, boxes_num > 0); @@ -649,7 +649,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpRoiAwarePool3dBackward( << ", out_x = " << out_x << ", out_y = " << out_y << ", out_z = " << out_z << ", channels = " << channels << ", max_pts_each_voxel = " << max_pts_each_voxel - << ", points num = " << grad_in_desc->dims[0]; + << ", points num = " << grad_in_desc->getDimIndex(0); // generate mluOpRoiAwarePool3dBackward prototxt start! if (MLUOP_GEN_CASE_ON_NEW) { @@ -709,7 +709,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpRoiAwarePool3dBackward( CHECK_RETURN( "[mluOpRoiAwarePool3dBackward]", KernelRoiawarePool3dBackward( - k_dim, k_type, handle->queue, grad_out_desc->dtype, pool_method, + k_dim, k_type, handle->queue, grad_out_desc->getDtype(), pool_method, boxes_num, out_x, out_y, out_z, channels, max_pts_each_voxel, pts_idx_of_voxels, argmax, grad_out, grad_in)); VLOG(5) << "[mluOpRoiAwarePool3dBackward] Finish kernel " diff --git a/kernels/roipoint_pool3d/roipoint_pool3d.cpp b/kernels/roipoint_pool3d/roipoint_pool3d.cpp index b4d363ae5..1da57f17d 100644 --- a/kernels/roipoint_pool3d/roipoint_pool3d.cpp +++ b/kernels/roipoint_pool3d/roipoint_pool3d.cpp @@ -44,44 +44,44 @@ static mluOpStatus_t paramcheck( const mluOpTensorDescriptor_t pooled_empty_flag_desc) { // check tensor dim // params points: [B, N, 3] - PARAM_CHECK_EQ("[mluOpRoiPointPool3d]", points_desc->dim, 3); - PARAM_CHECK_EQ("[mluOpRoiPointPool3d]", points_desc->dims[2], 3); + PARAM_CHECK_EQ("[mluOpRoiPointPool3d]", points_desc->getDim(), 3); + PARAM_CHECK_EQ("[mluOpRoiPointPool3d]", points_desc->getDimIndex(2), 3); // params point_features: [B, N, C] - PARAM_CHECK_EQ("[mluOpRoiPointPool3d]", point_features_desc->dim, 3); + PARAM_CHECK_EQ("[mluOpRoiPointPool3d]", point_features_desc->getDim(), 3); // params boxes3d: [B, M, 7] - PARAM_CHECK_EQ("[mluOpRoiPointPool3d]", boxes3d_desc->dim, 3); - PARAM_CHECK_EQ("[mluOpRoiPointPool3d]", boxes3d_desc->dims[2], 7); + PARAM_CHECK_EQ("[mluOpRoiPointPool3d]", boxes3d_desc->getDim(), 3); + PARAM_CHECK_EQ("[mluOpRoiPointPool3d]", boxes3d_desc->getDimIndex(2), 7); // params pooled_features: [B, M, sampled_pts_num, 3+C] - PARAM_CHECK_EQ("[mluOpRoiPointPool3d]", pooled_features_desc->dim, 4); + PARAM_CHECK_EQ("[mluOpRoiPointPool3d]", pooled_features_desc->getDim(), 4); // params pooled_empty_flag: [B, M] - PARAM_CHECK_EQ("[mluOpRoiPointPool3d]", pooled_empty_flag_desc->dim, 2); + PARAM_CHECK_EQ("[mluOpRoiPointPool3d]", pooled_empty_flag_desc->getDim(), 2); // check tensor shape PARAM_CHECK("[mluOpRoiPointPool3d]", - points_desc->dims[0] == pooled_features_desc->dims[0]); + points_desc->getDimIndex(0) == pooled_features_desc->getDimIndex(0)); PARAM_CHECK("[mluOpRoiPointPool3d]", - point_features_desc->dims[0] == pooled_features_desc->dims[0]); + point_features_desc->getDimIndex(0) == pooled_features_desc->getDimIndex(0)); PARAM_CHECK("[mluOpRoiPointPool3d]", - boxes3d_desc->dims[0] == pooled_features_desc->dims[0]); + boxes3d_desc->getDimIndex(0) == pooled_features_desc->getDimIndex(0)); PARAM_CHECK("[mluOpRoiPointPool3d]", - pooled_empty_flag_desc->dims[0] == pooled_features_desc->dims[0]); + pooled_empty_flag_desc->getDimIndex(0) == pooled_features_desc->getDimIndex(0)); PARAM_CHECK("[mluOpRoiPointPool3d]", - pooled_features_desc->dims[1] == boxes3d_desc->dims[1]); + pooled_features_desc->getDimIndex(1) == boxes3d_desc->getDimIndex(1)); PARAM_CHECK("[mluOpRoiPointPool3d]", - pooled_empty_flag_desc->dims[1] == boxes3d_desc->dims[1]); + pooled_empty_flag_desc->getDimIndex(1) == boxes3d_desc->getDimIndex(1)); PARAM_CHECK("[mluOpRoiPointPool3d]", - points_desc->dims[1] == point_features_desc->dims[1]); - PARAM_CHECK("[mluOpRoiPointPool3d]", point_features_desc->dims[2] + 3 == - pooled_features_desc->dims[3]); + points_desc->getDimIndex(1) == point_features_desc->getDimIndex(1)); + PARAM_CHECK("[mluOpRoiPointPool3d]", point_features_desc->getDimIndex(2) + 3 == + pooled_features_desc->getDimIndex(3)); // check params - PARAM_CHECK_EQ("[mluOpRoiPointPool3d]", batch_size, points_desc->dims[0]); - PARAM_CHECK_EQ("[mluOpRoiPointPool3d]", pts_num, points_desc->dims[1]); - PARAM_CHECK_EQ("[mluOpRoiPointPool3d]", boxes_num, boxes3d_desc->dims[1]); + PARAM_CHECK_EQ("[mluOpRoiPointPool3d]", batch_size, points_desc->getDimIndex(0)); + PARAM_CHECK_EQ("[mluOpRoiPointPool3d]", pts_num, points_desc->getDimIndex(1)); + PARAM_CHECK_EQ("[mluOpRoiPointPool3d]", boxes_num, boxes3d_desc->getDimIndex(1)); PARAM_CHECK_EQ("[mluOpRoiPointPool3d]", feature_in_len, - point_features_desc->dims[2]); + point_features_desc->getDimIndex(2)); PARAM_CHECK_EQ("[mluOpRoiPointPool3d]", sampled_pts_num, - pooled_features_desc->dims[2]); + pooled_features_desc->getDimIndex(2)); // check stride STRIDE_TENSOR_CHECK("[mluOpRoiPointPool3d]:", points_desc, @@ -97,18 +97,18 @@ static mluOpStatus_t paramcheck( // check tensor datatype PARAM_CHECK("[mluOpRoiPointPool3d]", - (points_desc->dtype == MLUOP_DTYPE_FLOAT) || - (points_desc->dtype == MLUOP_DTYPE_HALF)); + (points_desc->getDtype() == MLUOP_DTYPE_FLOAT) || + (points_desc->getDtype() == MLUOP_DTYPE_HALF)); PARAM_CHECK("[mluOpRoiPointPool3d]", - pooled_empty_flag_desc->dtype == MLUOP_DTYPE_INT32); + pooled_empty_flag_desc->getDtype() == MLUOP_DTYPE_INT32); // points, point_features, boxes3d_desc, pooled_features datatype must be the // same PARAM_CHECK("[mluOpRoiPointPool3d]", - points_desc->dtype == pooled_features_desc->dtype); + points_desc->getDtype() == pooled_features_desc->getDtype()); PARAM_CHECK("[mluOpRoiPointPool3d]", - point_features_desc->dtype == pooled_features_desc->dtype); + point_features_desc->getDtype() == pooled_features_desc->getDtype()); PARAM_CHECK("[mluOpRoiPointPool3d]", - boxes3d_desc->dtype == pooled_features_desc->dtype); + boxes3d_desc->getDtype() == pooled_features_desc->getDtype()); return MLUOP_STATUS_SUCCESS; } @@ -169,10 +169,10 @@ mluOpStatus_t MLUOP_WIN_API mluOpGetRoiPointPool3dWorkspaceSize( } // workspace for points_xyz : [3, B, N] - *size = points_element_num * mluop::getSizeOfDataType(points_desc->dtype); + *size = points_element_num * mluop::getSizeOfDataType(points_desc->getDtype()); // workspace for point_features_transpose : [C, B, N] *size += point_features_element_num * - mluop::getSizeOfDataType(point_features_desc->dtype); + mluop::getSizeOfDataType(point_features_desc->getDtype()); cnnlTransposeDescriptor_t trans_desc; size_t transpose_workspace_size0 = 0; @@ -281,27 +281,27 @@ mluOpStatus_t MLUOP_WIN_API mluOpRoiPointPool3d( // point_features : [B, C, N] void *point_features_transpose = (int8_t *)workspace + - points_element_num * mluop::getSizeOfDataType(points_desc->dtype); + points_element_num * mluop::getSizeOfDataType(points_desc->getDtype()); void *transpose_workspace = (int8_t *)point_features_transpose + point_features_element_num * - mluop::getSizeOfDataType(point_features_desc->dtype); + mluop::getSizeOfDataType(point_features_desc->getDtype()); size_t transpose_workspace_size = 0; mluOpTensorDescriptor_t output_transpose_desc; cnnlTransposeDescriptor_t trans_desc; const int dims = 3; int points_permute[3] = {2, 0, 1}; int points_dims[3]; - points_dims[0] = points_desc->dims[2]; - points_dims[1] = points_desc->dims[0]; - points_dims[2] = points_desc->dims[1]; + points_dims[0] = points_desc->getDimIndex(2); + points_dims[1] = points_desc->getDimIndex(0); + points_dims[2] = points_desc->getDimIndex(1); CHECK_RETURN("[mluOpGetRoiPointPool3d]", mluOpCreateTensorDescriptor(&output_transpose_desc)); CHECK_RETURN( "[mluOpGetRoiPointPool3d]", mluOpSetTensorDescriptor(output_transpose_desc, MLUOP_LAYOUT_ARRAY, - points_desc->dtype, dims, points_dims)); + points_desc->getDtype(), dims, points_dims)); CALL_CNNL(cnnlCreateTransposeDescriptor(&trans_desc)); CALL_CNNL(cnnlSetTransposeDescriptor(trans_desc, dims, points_permute)); { @@ -328,13 +328,13 @@ mluOpStatus_t MLUOP_WIN_API mluOpRoiPointPool3d( int point_features_permute[3] = {0, 2, 1}; int point_features_dims[3]; - point_features_dims[0] = point_features_desc->dims[0]; - point_features_dims[1] = point_features_desc->dims[2]; - point_features_dims[2] = point_features_desc->dims[1]; + point_features_dims[0] = point_features_desc->getDimIndex(0); + point_features_dims[1] = point_features_desc->getDimIndex(2); + point_features_dims[2] = point_features_desc->getDimIndex(1); CHECK_RETURN("[mluOpGetRoiPointPool3d]", mluOpSetTensorDescriptor( output_transpose_desc, MLUOP_LAYOUT_ARRAY, - point_features_desc->dtype, dims, point_features_dims)); + point_features_desc->getDtype(), dims, point_features_dims)); CALL_CNNL( cnnlSetTransposeDescriptor(trans_desc, dims, point_features_permute)); { @@ -378,7 +378,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpRoiPointPool3d( << ">>>"; CHECK_RETURN("[RoipointPool3d]", KernelRoipointPool3d( - k_dims, k_type, handle->queue, points_desc->dtype, + k_dims, k_type, handle->queue, points_desc->getDtype(), batch_size, pts_num, boxes_num, feature_in_len, sampled_pts_num, (int8_t *)points_xyz, (int8_t *)point_features_transpose, (int8_t *)boxes3d, @@ -389,7 +389,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpRoiPointPool3d( << k_dims.z << ">>>"; CHECK_RETURN("[RoipointPool3dLargeBoxesNum]", KernelRoipointPool3dLargeBoxesNum( - k_dims, k_type, handle->queue, points_desc->dtype, + k_dims, k_type, handle->queue, points_desc->getDtype(), batch_size, pts_num, boxes_num, feature_in_len, sampled_pts_num, (int8_t *)points_xyz, (int8_t *)point_features_transpose, (int8_t *)boxes3d, diff --git a/kernels/rotated_feature_align/rotated_feature_align.cpp b/kernels/rotated_feature_align/rotated_feature_align.cpp index c383a3322..e7ac4c9c2 100644 --- a/kernels/rotated_feature_align/rotated_feature_align.cpp +++ b/kernels/rotated_feature_align/rotated_feature_align.cpp @@ -34,9 +34,9 @@ static void policyFunc(const mluOpHandle_t handle, const mluOpTensorDescriptor_t output_desc, cnrtDim3_t *k_dim, cnrtFunctionType_t *k_type) { - const size_t num_rois = output_desc->dims[0]; - const size_t pooled_height = output_desc->dims[1]; - const size_t pooled_width = output_desc->dims[2]; + const size_t num_rois = output_desc->getDimIndex(0); + const size_t pooled_height = output_desc->getDimIndex(1); + const size_t pooled_width = output_desc->getDimIndex(2); const size_t num_bin = num_rois * pooled_height * pooled_width; size_t core_num = handle->core_num_per_cluster; size_t cluster_num = mluop::runtime::getJobLimitCapability(handle) / core_num; @@ -56,22 +56,22 @@ static mluOpStatus_t RotatedFeatureAlignForwardPreCheck( PARAM_CHECK("[mluOpRotatedFeatureAlignForward]", bboxes_desc != NULL); PARAM_CHECK("[mluOpRotatedFeatureAlignForward]", output_desc != NULL); - PARAM_CHECK("[mluOpRotatedFeatureAlignForward]", input_desc->dim == 4); - PARAM_CHECK("[mluOpRotatedFeatureAlignForward]", bboxes_desc->dim == 4); - PARAM_CHECK("[mluOpRotatedFeatureAlignForward]", output_desc->dim == 4); + PARAM_CHECK("[mluOpRotatedFeatureAlignForward]", input_desc->getDim() == 4); + PARAM_CHECK("[mluOpRotatedFeatureAlignForward]", bboxes_desc->getDim() == 4); + PARAM_CHECK("[mluOpRotatedFeatureAlignForward]", output_desc->getDim() == 4); PARAM_CHECK("[mluOpRotatedFeatureAlignForward]", - input_desc->dtype == MLUOP_DTYPE_FLOAT || - input_desc->dtype == MLUOP_DTYPE_HALF); + input_desc->getDtype() == MLUOP_DTYPE_FLOAT || + input_desc->getDtype() == MLUOP_DTYPE_HALF); PARAM_CHECK("[mluOpRotatedFeatureAlignForward]", - input_desc->dtype == bboxes_desc->dtype); + input_desc->getDtype() == bboxes_desc->getDtype()); PARAM_CHECK("[mluOpRotatedFeatureAlignForward]", - input_desc->dtype == output_desc->dtype); + input_desc->getDtype() == output_desc->getDtype()); PARAM_CHECK("[mluOpRotatedFeatureAlignForward]", - input_desc->layout == MLUOP_LAYOUT_NHWC); + input_desc->getLayout() == MLUOP_LAYOUT_NHWC); PARAM_CHECK("[mluOpRotatedFeatureAlignForward]", - output_desc->layout == MLUOP_LAYOUT_NHWC); + output_desc->getLayout() == MLUOP_LAYOUT_NHWC); // check stride STRIDE_TENSOR_CHECK("[mluOpRotatedFeatureAlignForward]:", input_desc, @@ -81,24 +81,24 @@ static mluOpStatus_t RotatedFeatureAlignForwardPreCheck( STRIDE_TENSOR_CHECK("[mluOpRotatedFeatureAlignForward]:", output_desc, "output_desc must be contiguous"); - for (int i = 0; i < input_desc->dim; i++) { - if (input_desc->dims[i] != output_desc->dims[i]) { + for (int i = 0; i < input_desc->getDim(); i++) { + if (input_desc->getDimIndex(i) != output_desc->getDimIndex(i)) { LOG(ERROR) << "[mluOpRotatedFeatureAlignForward] Check failed: input_desc->dims[" - << i << "] should be equal to output_desc->dims[" << i << "]."; + << i << "] should be equal to output_desc->getDimIndex(" << i << ")."; return MLUOP_STATUS_BAD_PARAM; } } - for (int i = 0; i < input_desc->dim - 1; i++) { - if (input_desc->dims[i] != bboxes_desc->dims[i]) { + for (int i = 0; i < input_desc->getDim() - 1; i++) { + if (input_desc->getDimIndex(i) != bboxes_desc->getDimIndex(i)) { LOG(ERROR) << "[mluOpRotatedFeatureAlignForward] Check failed: input_desc->dims[" - << i << "] should be equal to bboxes_desc->dims[" << i << "]."; + << i << "] should be equal to bboxes_desc->getDimIndex(" << i << ")."; return MLUOP_STATUS_BAD_PARAM; } } - PARAM_CHECK("[mluOpRotatedFeatureAlignForward]", bboxes_desc->dims[3] == 5); + PARAM_CHECK("[mluOpRotatedFeatureAlignForward]", bboxes_desc->getDimIndex(3) == 5); const size_t input_element_num = mluOpGetTensorElementNum(input_desc); const size_t output_element_num = mluOpGetTensorElementNum(output_desc); @@ -130,23 +130,23 @@ static mluOpStatus_t RotatedFeatureAlignBackwardPreCheck( PARAM_CHECK("[mluOpRotatedFeatureAlignBackward]", bboxes_desc != NULL); PARAM_CHECK("[mluOpRotatedFeatureAlignBackward]", bottom_input_desc != NULL); - PARAM_CHECK("[mluOpRotatedFeatureAlignBackward]", top_output_desc->dim == 4); - PARAM_CHECK("[mluOpRotatedFeatureAlignBackward]", bboxes_desc->dim == 4); + PARAM_CHECK("[mluOpRotatedFeatureAlignBackward]", top_output_desc->getDim() == 4); + PARAM_CHECK("[mluOpRotatedFeatureAlignBackward]", bboxes_desc->getDim() == 4); PARAM_CHECK("[mluOpRotatedFeatureAlignBackward]", - bottom_input_desc->dim == 4); + bottom_input_desc->getDim() == 4); PARAM_CHECK("[mluOpRotatedFeatureAlignBackward]", - top_output_desc->dtype == MLUOP_DTYPE_FLOAT || - top_output_desc->dtype == MLUOP_DTYPE_HALF); + top_output_desc->getDtype() == MLUOP_DTYPE_FLOAT || + top_output_desc->getDtype() == MLUOP_DTYPE_HALF); PARAM_CHECK("[mluOpRotatedFeatureAlignBackward]", - top_output_desc->dtype == bboxes_desc->dtype); + top_output_desc->getDtype() == bboxes_desc->getDtype()); PARAM_CHECK("[mluOpRotatedFeatureAlignBackward]", - top_output_desc->dtype == bottom_input_desc->dtype); + top_output_desc->getDtype() == bottom_input_desc->getDtype()); PARAM_CHECK("[mluOpRotatedFeatureAlignBackward]", - top_output_desc->layout == MLUOP_LAYOUT_NHWC); + top_output_desc->getLayout() == MLUOP_LAYOUT_NHWC); PARAM_CHECK("[mluOpRotatedFeatureAlignBackward]", - bottom_input_desc->layout == MLUOP_LAYOUT_NHWC); + bottom_input_desc->getLayout() == MLUOP_LAYOUT_NHWC); // check stride STRIDE_TENSOR_CHECK("[mluOpRotatedFeatureAlignBackward]:", top_output_desc, @@ -156,8 +156,8 @@ static mluOpStatus_t RotatedFeatureAlignBackwardPreCheck( STRIDE_TENSOR_CHECK("[mluOpRotatedFeatureAlignBackward]:", bottom_input_desc, "bottom_input_desc must be contiguous"); - for (int i = 0; i < top_output_desc->dim; i++) { - if (top_output_desc->dims[i] != bottom_input_desc->dims[i]) { + for (int i = 0; i < top_output_desc->getDim(); i++) { + if (top_output_desc->getDimIndex(i) != bottom_input_desc->getDimIndex(i)) { LOG(ERROR) << "[mluOpRotatedFeatureAlignBackward] Check failed: " "top_output_desc->dims[" << i << "] should be equal to bottom_input_desc->dims[" << i @@ -166,15 +166,15 @@ static mluOpStatus_t RotatedFeatureAlignBackwardPreCheck( } } - for (int i = 0; i < top_output_desc->dim - 1; i++) { - if (top_output_desc->dims[i] != bboxes_desc->dims[i]) { + for (int i = 0; i < top_output_desc->getDim() - 1; i++) { + if (top_output_desc->getDimIndex(i) != bboxes_desc->getDimIndex(i)) { LOG(ERROR) << "[mluOpRotatedFeatureAlignBackward] Check failed: " "top_output_desc->dims[" - << i << "] should be equal to bboxes_desc->dims[" << i << "]."; + << i << "] should be equal to bboxes_desc->getDimIndex(" << i << ")."; return MLUOP_STATUS_BAD_PARAM; } } - PARAM_CHECK("[mluOpRotatedFeatureAlignBackward]", bboxes_desc->dims[3] == 5); + PARAM_CHECK("[mluOpRotatedFeatureAlignBackward]", bboxes_desc->getDimIndex(3) == 5); PARAM_CHECK("[mluOpRotatedFeatureAlignBackward]", points == 1 || points == 5); PARAM_CHECK("[mluOpRotatedFeatureAlignBackward]", spatial_scale > 0); @@ -241,12 +241,12 @@ mluOpStatus_t MLUOP_WIN_API mluOpRotatedFeatureAlignForward( policyFunc(handle, output_desc, &k_dim, &k_type); - const int batches = input_desc->dims[0]; - const int height = input_desc->dims[1]; - const int width = input_desc->dims[2]; - const int channels = input_desc->dims[3]; - const int offset_rois = bboxes_desc->dims[3]; - mluOpDataType_t data_dtype = input_desc->dtype; + const int batches = input_desc->getDimIndex(0); + const int height = input_desc->getDimIndex(1); + const int width = input_desc->getDimIndex(2); + const int channels = input_desc->getDimIndex(3); + const int offset_rois = bboxes_desc->getDimIndex(3); + mluOpDataType_t data_dtype = input_desc->getDtype(); VLOG(5) << "[mluOpRotatedFeatureAlignForward] launch kernel policyFunc[" << k_dim.x << ", " << k_dim.y << ", " << k_dim.z << "]."; CHECK_RETURN( @@ -309,12 +309,12 @@ mluOpStatus_t MLUOP_WIN_API mluOpRotatedFeatureAlignBackward( cnrtFunctionType_t k_type; policyFunc(handle, top_output_desc, &k_dim, &k_type); - const int batches = top_output_desc->dims[0]; - const int height = top_output_desc->dims[1]; - const int width = top_output_desc->dims[2]; - const int channels = top_output_desc->dims[3]; - const int offset_rois = bboxes_desc->dims[3]; - mluOpDataType_t data_dtype = top_output_desc->dtype; + const int batches = top_output_desc->getDimIndex(0); + const int height = top_output_desc->getDimIndex(1); + const int width = top_output_desc->getDimIndex(2); + const int channels = top_output_desc->getDimIndex(3); + const int offset_rois = bboxes_desc->getDimIndex(3); + mluOpDataType_t data_dtype = top_output_desc->getDtype(); VLOG(5) << "[mluOpRotatedFeatureAlignBackward] launch kernel policyFunc[" << k_dim.x << ", " << k_dim.y << ", " << k_dim.z << "]."; CHECK_RETURN("[mluOpRotatedFeatureAlignBackward]", diff --git a/kernels/sparse_conv/get_indice_pairs/get_indice_pairs.cpp b/kernels/sparse_conv/get_indice_pairs/get_indice_pairs.cpp index 452361e24..53144cffc 100644 --- a/kernels/sparse_conv/get_indice_pairs/get_indice_pairs.cpp +++ b/kernels/sparse_conv/get_indice_pairs/get_indice_pairs.cpp @@ -104,19 +104,19 @@ static mluOpStatus_t internalGetIndicePairs( // indices indice_pairs out_indices indice_num // tensor dim check - PARAM_CHECK(interface_name, indices_desc->dim == 2); - PARAM_CHECK(interface_name, indice_pairs_desc->dim == 3); - PARAM_CHECK(interface_name, out_indices_desc->dim == 2); - PARAM_CHECK(interface_name, indice_num_desc->dim == 1); - PARAM_CHECK(interface_name, indices_desc->dims[1] == 4); - PARAM_CHECK(interface_name, out_indices_desc->dims[1] == 4); - PARAM_CHECK(interface_name, indice_pairs_desc->dims[1] == 2); + PARAM_CHECK(interface_name, indices_desc->getDim() == 2); + PARAM_CHECK(interface_name, indice_pairs_desc->getDim() == 3); + PARAM_CHECK(interface_name, out_indices_desc->getDim() == 2); + PARAM_CHECK(interface_name, indice_num_desc->getDim() == 1); + PARAM_CHECK(interface_name, indices_desc->getDimIndex(1) == 4); + PARAM_CHECK(interface_name, out_indices_desc->getDimIndex(1) == 4); + PARAM_CHECK(interface_name, indice_pairs_desc->getDimIndex(1) == 2); // check shape PARAM_CHECK(interface_name, - indice_pairs_desc->dims[2] == indices_desc->dims[0]); + indice_pairs_desc->getDimIndex(2) == indices_desc->getDimIndex(0)); PARAM_CHECK(interface_name, - indice_pairs_desc->dims[0] == indice_num_desc->dims[0]); + indice_pairs_desc->getDimIndex(0) == indice_num_desc->getDimIndex(0)); int kernel_volume = 1; for (int i = 0; i < sparse_conv_dimNb - 2; i++) { kernel_volume *= sparse_conv_desc->filter_space[i]; @@ -127,7 +127,7 @@ static mluOpStatus_t internalGetIndicePairs( output_spaces *= sparse_conv_desc->output_space[i]; input_spaces *= sparse_conv_desc->input_space[i]; } - PARAM_CHECK_LE(interface_name, indices_desc->dims[0], input_spaces); + PARAM_CHECK_LE(interface_name, indices_desc->getDimIndex(0), input_spaces); for (int i = 0; i < sparse_conv_dimNb - 2; i++) { std::string i_str = "i: " + std::to_string(i) + "."; PARAM_CHECK_V2(interface_name, sparse_conv_desc->pad[i] >= 0, << i_str); @@ -142,9 +142,9 @@ static mluOpStatus_t internalGetIndicePairs( return MLUOP_STATUS_BAD_PARAM; } } - PARAM_CHECK(interface_name, indice_pairs_desc->dims[0] == kernel_volume); + PARAM_CHECK(interface_name, indice_pairs_desc->getDimIndex(0) == kernel_volume); PARAM_CHECK_LE(interface_name, kernel_volume, 4096); - PARAM_CHECK_LE(interface_name, out_indices_desc->dims[0], output_spaces); + PARAM_CHECK_LE(interface_name, out_indices_desc->getDimIndex(0), output_spaces); // check stride STRIDE_TENSOR_CHECK("[mluOpGetIndicesPairs]:", indices_desc, @@ -157,7 +157,7 @@ static mluOpStatus_t internalGetIndicePairs( "indice_num_desc must be contiguous"); // large tensor - PARAM_CHECK_LE(interface_name, indices_desc->dims[0], + PARAM_CHECK_LE(interface_name, indices_desc->getDimIndex(0), INDICE_IN_LARGE_TENSOR_NUM); if (mluOpGetTensorElementNum(indices_desc) >= LARGE_TENSOR_NUM || mluOpGetTensorElementNum(out_indices_desc) >= LARGE_TENSOR_NUM || @@ -169,10 +169,10 @@ static mluOpStatus_t internalGetIndicePairs( } // tensor datatype check - PARAM_CHECK_EQ(interface_name, indices_desc->dtype, MLUOP_DTYPE_INT32); - PARAM_CHECK_EQ(interface_name, indice_pairs_desc->dtype, MLUOP_DTYPE_INT32); - PARAM_CHECK_EQ(interface_name, out_indices_desc->dtype, MLUOP_DTYPE_INT32); - PARAM_CHECK_EQ(interface_name, indice_num_desc->dtype, MLUOP_DTYPE_INT32); + PARAM_CHECK_EQ(interface_name, indices_desc->getDtype(), MLUOP_DTYPE_INT32); + PARAM_CHECK_EQ(interface_name, indice_pairs_desc->getDtype(), MLUOP_DTYPE_INT32); + PARAM_CHECK_EQ(interface_name, out_indices_desc->getDtype(), MLUOP_DTYPE_INT32); + PARAM_CHECK_EQ(interface_name, indice_num_desc->getDtype(), MLUOP_DTYPE_INT32); // special check int sub_m = sparse_conv_desc->sub_m; if (sub_m) { diff --git a/kernels/sparse_conv/get_indice_pairs/normal_get_indice_pairs.cpp b/kernels/sparse_conv/get_indice_pairs/normal_get_indice_pairs.cpp index fd77f94f6..740429643 100644 --- a/kernels/sparse_conv/get_indice_pairs/normal_get_indice_pairs.cpp +++ b/kernels/sparse_conv/get_indice_pairs/normal_get_indice_pairs.cpp @@ -40,7 +40,7 @@ static mluOpStatus_t getIndiceMaskAll( const int input_active_site, size_t *size) { size_t total_size = 0; total_size = kernel_volume * input_active_site * - mluop::getSizeOfDataType(indice_pairs_desc->dtype); + mluop::getSizeOfDataType(indice_pairs_desc->getDtype()); size[0] = total_size; return MLUOP_STATUS_SUCCESS; } @@ -50,7 +50,7 @@ static mluOpStatus_t getIndiceIndexIn( const int input_active_site, size_t *size) { size_t total_size = 0; total_size = kernel_volume * input_active_site * - mluop::getSizeOfDataType(indice_pairs_desc->dtype); + mluop::getSizeOfDataType(indice_pairs_desc->getDtype()); size[0] = total_size; return MLUOP_STATUS_SUCCESS; } @@ -60,7 +60,7 @@ static mluOpStatus_t getIndiceIndexOut( const int input_active_site, size_t *size) { size_t total_size = 0; total_size = kernel_volume * input_active_site * - mluop::getSizeOfDataType(indice_pairs_desc->dtype); + mluop::getSizeOfDataType(indice_pairs_desc->getDtype()); size[0] = total_size; return MLUOP_STATUS_SUCCESS; } @@ -70,7 +70,7 @@ static mluOpStatus_t getIndiceOutExpand( const int input_active_site, size_t *size) { size_t total_size = 0; total_size = kernel_volume * input_active_site * - mluop::getSizeOfDataType(indice_pairs_desc->dtype); + mluop::getSizeOfDataType(indice_pairs_desc->getDtype()); size[0] = total_size; return MLUOP_STATUS_SUCCESS; } @@ -80,7 +80,7 @@ static mluOpStatus_t getIndiceInExpand( const int input_active_site, size_t *size) { size_t total_size = 0; total_size = - input_active_site * mluop::getSizeOfDataType(indice_pairs_desc->dtype); + input_active_site * mluop::getSizeOfDataType(indice_pairs_desc->getDtype()); size[0] = total_size; return MLUOP_STATUS_SUCCESS; } @@ -90,7 +90,7 @@ static mluOpStatus_t getIndiceUnique( const int input_active_site, size_t *size) { size_t total_size = 0; total_size = (kernel_volume * input_active_site + 1) * - mluop::getSizeOfDataType(indice_pairs_desc->dtype); + mluop::getSizeOfDataType(indice_pairs_desc->getDtype()); size[0] = total_size; return MLUOP_STATUS_SUCCESS; } @@ -98,7 +98,7 @@ static mluOpStatus_t getIndiceUnique( static mluOpStatus_t getGridOut(const mluOpTensorDescriptor_t indice_pairs_desc, int output_size, size_t *size) { size_t total_size = 0; - total_size = output_size * mluop::getSizeOfDataType(indice_pairs_desc->dtype); + total_size = output_size * mluop::getSizeOfDataType(indice_pairs_desc->getDtype()); size[0] = total_size; return MLUOP_STATUS_SUCCESS; } @@ -128,7 +128,7 @@ static mluOpStatus_t getReduceOpWS(mluOpHandle_t handle, CALL_CNNL(cnnlCreateReduceDescriptor(&reduce_desc)); CALL_CNNL(cnnlSetReduceDescriptor( reduce_desc, axis, axis_num, CNNL_REDUCE_ADD, - cnnlDataType_t(reduce_in_desc->dtype), CNNL_PROPAGATE_NAN, + cnnlDataType_t(reduce_in_desc->getDtype()), CNNL_PROPAGATE_NAN, CNNL_REDUCE_NO_INDICES, CNNL_16BIT_INDICES)); { DEFINE_CREATE_AND_SET_CNNL_HANDLE(handle, cnnl_handle); @@ -200,8 +200,8 @@ mluOpStatus_t getNormalGetIndicePairsWorkspaceSize( size_t total_size = 0; int sub_m = sparse_conv_desc->sub_m; int batch = sparse_conv_desc->batch; - int kernel_volume = indice_pairs_desc->dims[0]; - int input_active_site = indice_pairs_desc->dims[2]; + int kernel_volume = indice_pairs_desc->getDimIndex(0); + int input_active_site = indice_pairs_desc->getDimIndex(2); int output_size = batch * sparse_conv_desc->output_space[0] * sparse_conv_desc->output_space[1] * sparse_conv_desc->output_space[2] + @@ -459,7 +459,7 @@ mluOpStatus_t launchReduceOp(mluOpHandle_t handle, CALL_CNNL(cnnlCreateReduceDescriptor(&reduce_desc)); CALL_CNNL(cnnlSetReduceDescriptor( reduce_desc, axis, axis_num, CNNL_REDUCE_ADD, - cnnlDataType_t(reduce_in_desc->dtype), CNNL_PROPAGATE_NAN, + cnnlDataType_t(reduce_in_desc->getDtype()), CNNL_PROPAGATE_NAN, CNNL_REDUCE_NO_INDICES, CNNL_16BIT_INDICES)); void *alpha = NULL, *beta = NULL, *indices = NULL; { @@ -836,8 +836,8 @@ mluOpStatus_t NormalGetIndicePairsKernel( void *indice_num) { int sub_m = sparse_conv_desc->sub_m; int batch = sparse_conv_desc->batch; - int kernel_volume = indice_pairs_desc->dims[0]; - int input_active_site = indice_pairs_desc->dims[2]; + int kernel_volume = indice_pairs_desc->getDimIndex(0); + int input_active_site = indice_pairs_desc->getDimIndex(2); int output_size = batch * sparse_conv_desc->output_space[0] * sparse_conv_desc->output_space[1] * sparse_conv_desc->output_space[2] + diff --git a/kernels/sparse_conv/indice_convolution_backward_data/indice_convolution_backward_data.cpp b/kernels/sparse_conv/indice_convolution_backward_data/indice_convolution_backward_data.cpp index 2f714d1b8..0d6b61179 100644 --- a/kernels/sparse_conv/indice_convolution_backward_data/indice_convolution_backward_data.cpp +++ b/kernels/sparse_conv/indice_convolution_backward_data/indice_convolution_backward_data.cpp @@ -52,36 +52,36 @@ static mluOpStatus_t foolCheckNoPtr( } // check dim - PARAM_CHECK_EQ(api, output_grad_desc->dim, 2); - PARAM_CHECK(api, filters_desc->dim == 4 || filters_desc->dim == 5); - PARAM_CHECK_EQ(api, indice_pairs_desc->dim, 3); - PARAM_CHECK_EQ(api, input_grad_desc->dim, 2); + PARAM_CHECK_EQ(api, output_grad_desc->getDim(), 2); + PARAM_CHECK(api, filters_desc->getDim() == 4 || filters_desc->getDim() == 5); + PARAM_CHECK_EQ(api, indice_pairs_desc->getDim(), 3); + PARAM_CHECK_EQ(api, input_grad_desc->getDim(), 2); // check shape - PARAM_CHECK(api, indice_pairs_desc->dims[1] == 2); - if (indice_pairs_desc->dims[2] > INDICE_IN_LARGE_TENSOR_NUM) { + PARAM_CHECK(api, indice_pairs_desc->getDimIndex(1) == 2); + if (indice_pairs_desc->getDimIndex(2) > INDICE_IN_LARGE_TENSOR_NUM) { LOG(ERROR) << api << " Check failed: " - << "indice_pairs_desc->dims[2] cannot be greater than " + << "indice_pairs_desc->getDimIndex(2) cannot be greater than " << INDICE_IN_LARGE_TENSOR_NUM << "."; return MLUOP_STATUS_NOT_SUPPORTED; } // check dtype - PARAM_CHECK(api, output_grad_desc->dtype == MLUOP_DTYPE_FLOAT || - output_grad_desc->dtype == MLUOP_DTYPE_HALF); - PARAM_CHECK(api, filters_desc->dtype == MLUOP_DTYPE_FLOAT || - filters_desc->dtype == MLUOP_DTYPE_HALF); - PARAM_CHECK(api, input_grad_desc->dtype == MLUOP_DTYPE_FLOAT || - input_grad_desc->dtype == MLUOP_DTYPE_HALF); - PARAM_CHECK(api, indice_pairs_desc->dtype == MLUOP_DTYPE_INT32); + PARAM_CHECK(api, output_grad_desc->getDtype() == MLUOP_DTYPE_FLOAT || + output_grad_desc->getDtype() == MLUOP_DTYPE_HALF); + PARAM_CHECK(api, filters_desc->getDtype() == MLUOP_DTYPE_FLOAT || + filters_desc->getDtype() == MLUOP_DTYPE_HALF); + PARAM_CHECK(api, input_grad_desc->getDtype() == MLUOP_DTYPE_FLOAT || + input_grad_desc->getDtype() == MLUOP_DTYPE_HALF); + PARAM_CHECK(api, indice_pairs_desc->getDtype() == MLUOP_DTYPE_INT32); // check layout - bool layout_check = filters_desc->layout == MLUOP_LAYOUT_NHWC || - filters_desc->layout == MLUOP_LAYOUT_NCHW || - filters_desc->layout == MLUOP_LAYOUT_HWCN || - filters_desc->layout == MLUOP_LAYOUT_NCDHW || - filters_desc->layout == MLUOP_LAYOUT_NDHWC || - filters_desc->layout == MLUOP_LAYOUT_ARRAY; + bool layout_check = filters_desc->getLayout() == MLUOP_LAYOUT_NHWC || + filters_desc->getLayout() == MLUOP_LAYOUT_NCHW || + filters_desc->getLayout() == MLUOP_LAYOUT_HWCN || + filters_desc->getLayout() == MLUOP_LAYOUT_NCDHW || + filters_desc->getLayout() == MLUOP_LAYOUT_NDHWC || + filters_desc->getLayout() == MLUOP_LAYOUT_ARRAY; if (!layout_check) { LOG(ERROR) << api << " The filters tensor only supports " @@ -100,23 +100,23 @@ static mluOpStatus_t foolCheckNoPtr( // get filters params int kd = 1, kh = 1, kw = 1, dyc = 1, dxc = 1; - if (filters_desc->layout != MLUOP_LAYOUT_ARRAY) { + if (filters_desc->getLayout() != MLUOP_LAYOUT_ARRAY) { kh = mluOpGetTensordimH(filters_desc); kw = mluOpGetTensordimW(filters_desc); dyc = mluOpGetTensordimN(filters_desc); dxc = mluOpGetTensordimC(filters_desc); - if (filters_desc->dim == 5) { + if (filters_desc->getDim() == 5) { kd = mluOpGetTensordimD(filters_desc); } } else { - if (filters_desc->dim == 5) { - kd = filters_desc->dims[0]; + if (filters_desc->getDim() == 5) { + kd = filters_desc->getDimIndex(0); } - int _dim = filters_desc->dim; - kh = filters_desc->dims[_dim - 4]; - kw = filters_desc->dims[_dim - 3]; - dxc = filters_desc->dims[_dim - 2]; - dyc = filters_desc->dims[_dim - 1]; + int _dim = filters_desc->getDim(); + kh = filters_desc->getDimIndex(_dim - 4); + kw = filters_desc->getDimIndex(_dim - 3); + dxc = filters_desc->getDimIndex(_dim - 2); + dyc = filters_desc->getDimIndex(_dim - 1); } int K = kd * kh * kw; @@ -132,25 +132,25 @@ static mluOpStatus_t foolCheckNoPtr( } // check algorithm, relationship between params - if (K != indice_pairs_desc->dims[0]) { + if (K != indice_pairs_desc->getDimIndex(0)) { LOG(ERROR) << api << " The dims[0] of indice_pairs should be equal to the " "multiple of kd, kh and kw."; return MLUOP_STATUS_BAD_PARAM; } - if (output_grad_desc->dims[1] != dyc) { + if (output_grad_desc->getDimIndex(1) != dyc) { LOG(ERROR) << api << " The dims[1] of output_grad should be equal to dyc of " "filters tensor."; return MLUOP_STATUS_BAD_PARAM; } - if (input_grad_desc->dims[1] != dxc) { + if (input_grad_desc->getDimIndex(1) != dxc) { LOG(ERROR) << api << " The dims[1] of input_grad should be equal to dxc of " "filters tensor."; return MLUOP_STATUS_BAD_PARAM; } - if (input_grad_desc->dims[0] != indice_pairs_desc->dims[2]) { + if (input_grad_desc->getDimIndex(0) != indice_pairs_desc->getDimIndex(2)) { LOG(ERROR) << api << " The dims[0] of input_grad should be equal to the dims[2] " "of indice_pairs."; @@ -158,8 +158,8 @@ static mluOpStatus_t foolCheckNoPtr( } int max_indice_num = getMaxNumInArray(indice_num, K); - if (indice_pairs_desc->dims[2] < max_indice_num) { - VLOG(5) << "indice_pairs_desc->dims[2] " << indice_pairs_desc->dims[2] + if (indice_pairs_desc->getDimIndex(2) < max_indice_num) { + VLOG(5) << "indice_pairs_desc->getDimIndex(2) " << indice_pairs_desc->getDimIndex(2) << " max_indice_num " << max_indice_num; LOG(ERROR) << api << " The data in indice_num array should be smaller or equal to" @@ -167,7 +167,7 @@ static mluOpStatus_t foolCheckNoPtr( return MLUOP_STATUS_BAD_PARAM; } if (sub_m == 1) { - if (input_grad_desc->dims[0] != output_grad_desc->dims[0]) { + if (input_grad_desc->getDimIndex(0) != output_grad_desc->getDimIndex(0)) { LOG(ERROR) << api << " The dims[0] of input_grad should be equal to the dims[0]" << " of output_grad when sub_m is 1."; @@ -184,7 +184,7 @@ static mluOpStatus_t foolCheckNoPtr( } } - if (output_grad_desc->dims[0] < max_indice_num) { + if (output_grad_desc->getDimIndex(0) < max_indice_num) { LOG(ERROR) << api << " The dims[0] of output_grad should be larger than or equal to the" @@ -198,8 +198,8 @@ static mluOpStatus_t foolCheckNoPtr( return MLUOP_STATUS_BAD_PARAM; } - PARAM_CHECK(api, output_grad_desc->dtype == input_grad_desc->dtype); - PARAM_CHECK(api, output_grad_desc->dtype == filters_desc->dtype); + PARAM_CHECK(api, output_grad_desc->getDtype() == input_grad_desc->getDtype()); + PARAM_CHECK(api, output_grad_desc->getDtype() == filters_desc->getDtype()); // check constraints: not support large tensor uint64_t input_grad_count = mluOpGetTensorElementNum(input_grad_desc); @@ -325,7 +325,7 @@ static void spconvbpdataGencase( GEN_CASE_OP_PARAM_SINGLE(1, "indice_convolution_backward_data", "sub_m", sub_m); GEN_CASE_OP_PARAM_ARRAY(1, "indice_convolution_backward_data", "indice_num", - indice_num, indice_pairs_desc->dims[0]); + indice_num, indice_pairs_desc->getDimIndex(0)); GEN_CASE_HANDLE_PARAM(); GEN_CASE_TEST_PARAM_NEW(true, true, false, 0.003, 0.003, 0); } @@ -378,23 +378,23 @@ mluOpStatus_t MLUOP_WIN_API mluOpGetIndiceConvolutionBackwardDataWorkspaceSize( } int kd = 1, kh = 1, kw = 1, dyc = 1, dxc = 1; - if (filters_desc->layout != MLUOP_LAYOUT_ARRAY) { + if (filters_desc->getLayout() != MLUOP_LAYOUT_ARRAY) { kh = mluOpGetTensordimH(filters_desc); kw = mluOpGetTensordimW(filters_desc); dyc = mluOpGetTensordimN(filters_desc); dxc = mluOpGetTensordimC(filters_desc); - if (filters_desc->dim == 5) { + if (filters_desc->getDim() == 5) { kd = mluOpGetTensordimD(filters_desc); } } else { - if (filters_desc->dim == 5) { - kd = filters_desc->dims[0]; + if (filters_desc->getDim() == 5) { + kd = filters_desc->getDimIndex(0); } - int _dim = filters_desc->dim; - kh = filters_desc->dims[_dim - 4]; - kw = filters_desc->dims[_dim - 3]; - dxc = filters_desc->dims[_dim - 2]; - dyc = filters_desc->dims[_dim - 1]; + int _dim = filters_desc->getDim(); + kh = filters_desc->getDimIndex(_dim - 4); + kw = filters_desc->getDimIndex(_dim - 3); + dxc = filters_desc->getDimIndex(_dim - 2); + dyc = filters_desc->getDimIndex(_dim - 1); } int K = kd * kh * kw; int max_indice_num = getMaxNumInArray(indice_num, K); @@ -403,18 +403,18 @@ mluOpStatus_t MLUOP_WIN_API mluOpGetIndiceConvolutionBackwardDataWorkspaceSize( uint64_t output_grad_condence_size = 0; uint64_t input_grad_condence_size = 0; uint64_t matmul_workspace_size = 0; - if (!(filters_desc->layout == MLUOP_LAYOUT_HWCN || - filters_desc->layout == MLUOP_LAYOUT_ARRAY)) { + if (!(filters_desc->getLayout() == MLUOP_LAYOUT_HWCN || + filters_desc->getLayout() == MLUOP_LAYOUT_ARRAY)) { filter_transpose_size = mluOpGetTensorElementNum(filters_desc) * - mluOpDataTypeBytes(filters_desc->dtype); + mluOpDataTypeBytes(filters_desc->getDtype()); // get cnnlTranspose_v2 workspace workspace_size size_t transpose_workspace_size_ = 0; cnnlTransposeDescriptor_t trans_desc; CALL_CNNL(cnnlCreateTransposeDescriptor(&trans_desc)); int permute[5] = {0, 1, 2, 3, 4}; - getPermuteArray(filters_desc->layout, permute); + getPermuteArray(filters_desc->getLayout(), permute); CALL_CNNL( - cnnlSetTransposeDescriptor(trans_desc, filters_desc->dim, permute)); + cnnlSetTransposeDescriptor(trans_desc, filters_desc->getDim(), permute)); { DEFINE_CREATE_AND_SET_CNNL_HANDLE(handle, cnnl_handle); DEFINE_CREATE_AND_SET_CNNL_TENSOR_DESCRIPTOR(filters_desc, cnnl_x_desc); @@ -426,10 +426,10 @@ mluOpStatus_t MLUOP_WIN_API mluOpGetIndiceConvolutionBackwardDataWorkspaceSize( CALL_CNNL(cnnlDestroyTransposeDescriptor(trans_desc)); transpose_workspace_size = (uint64_t)transpose_workspace_size_; } - output_grad_condence_size = max_indice_num * output_grad_desc->dims[1] * - mluOpDataTypeBytes(filters_desc->dtype); - input_grad_condence_size = max_indice_num * input_grad_desc->dims[1] * - mluOpDataTypeBytes(filters_desc->dtype); + output_grad_condence_size = max_indice_num * output_grad_desc->getDimIndex(1) * + mluOpDataTypeBytes(filters_desc->getDtype()); + input_grad_condence_size = max_indice_num * input_grad_desc->getDimIndex(1) * + mluOpDataTypeBytes(filters_desc->getDtype()); // matmul workspace { @@ -446,7 +446,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpGetIndiceConvolutionBackwardDataWorkspaceSize( int sub_filter_dims[2] = {(int)(dxc), (int)(dyc)}; CHECK_RETURN(api_name, mluOpSetTensorDescriptor( sub_filters_desc, MLUOP_LAYOUT_ARRAY, - filters_desc->dtype, 2, sub_filter_dims)); + filters_desc->getDtype(), 2, sub_filter_dims)); int is_trans_a = 0, is_trans_b = 1; int tf32_flag_int = 0; CALL_CNNL(cnnlMatMulDescCreate(&cnnl_matmul_desc)); @@ -461,14 +461,14 @@ mluOpStatus_t MLUOP_WIN_API mluOpGetIndiceConvolutionBackwardDataWorkspaceSize( int output_grad_condence_dims[2] = {(int)(max_indice_num), (int)(dyc)}; CHECK_RETURN(api_name, mluOpSetTensorDescriptor(output_grad_condence_desc, MLUOP_LAYOUT_ARRAY, - output_grad_desc->dtype, 2, + output_grad_desc->getDtype(), 2, output_grad_condence_dims)); CHECK_RETURN(api_name, mluOpCreateTensorDescriptor(&input_grad_condence_desc)); int input_grad_condence_dims[2] = {(int)(max_indice_num), (int)(dxc)}; CHECK_RETURN(api_name, mluOpSetTensorDescriptor(input_grad_condence_desc, MLUOP_LAYOUT_ARRAY, - input_grad_desc->dtype, 2, + input_grad_desc->getDtype(), 2, input_grad_condence_dims)); DEFINE_CREATE_AND_SET_CNNL_HANDLE(handle, cnnl_handle); @@ -515,7 +515,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpGetIndiceConvolutionBackwardDataWorkspaceSize( // scatter to input_grad_tmp_workspace_size workspace uint64_t input_grad_tmp_workspace_size = mluOpGetTensorElementNum(input_grad_desc) * - mluOpDataTypeBytes(input_grad_desc->dtype); + mluOpDataTypeBytes(input_grad_desc->getDtype()); // addn workspace uint32_t addn_num = 2; @@ -591,43 +591,43 @@ mluOpStatus_t MLUOP_WIN_API mluOpIndiceConvolutionBackwardData( // get filters params int kd = 1, kh = 1, kw = 1, dyc = 1, dxc = 1; - if (filters_desc->layout != MLUOP_LAYOUT_ARRAY) { + if (filters_desc->getLayout() != MLUOP_LAYOUT_ARRAY) { kh = mluOpGetTensordimH(filters_desc); kw = mluOpGetTensordimW(filters_desc); dyc = mluOpGetTensordimN(filters_desc); dxc = mluOpGetTensordimC(filters_desc); - if (filters_desc->dim == 5) { + if (filters_desc->getDim() == 5) { kd = mluOpGetTensordimD(filters_desc); } } else { - if (filters_desc->dim == 5) { - kd = filters_desc->dims[0]; + if (filters_desc->getDim() == 5) { + kd = filters_desc->getDimIndex(0); } - int _dim = filters_desc->dim; - kh = filters_desc->dims[_dim - 4]; - kw = filters_desc->dims[_dim - 3]; - dxc = filters_desc->dims[_dim - 2]; - dyc = filters_desc->dims[_dim - 1]; + int _dim = filters_desc->getDim(); + kh = filters_desc->getDimIndex(_dim - 4); + kw = filters_desc->getDimIndex(_dim - 3); + dxc = filters_desc->getDimIndex(_dim - 2); + dyc = filters_desc->getDimIndex(_dim - 1); } int K = kd * kh * kw; - int cal_dwidth = mluOpDataTypeBytes(filters_desc->dtype); + int cal_dwidth = mluOpDataTypeBytes(filters_desc->getDtype()); uint64_t filter_transpose_size = 0, output_grad_condence_size = 0, input_grad_condence_size = 0; - if (!(filters_desc->layout == MLUOP_LAYOUT_HWCN)) { + if (!(filters_desc->getLayout() == MLUOP_LAYOUT_HWCN)) { filter_transpose_size = mluOpGetTensorElementNum(filters_desc) * cal_dwidth; VLOG(5) << "host invoke: filter_transpose_size " << filter_transpose_size; } output_grad_condence_size = - getMaxNumInArray(indice_num, K) * output_grad_desc->dims[1] * cal_dwidth; + getMaxNumInArray(indice_num, K) * output_grad_desc->getDimIndex(1) * cal_dwidth; input_grad_condence_size = - getMaxNumInArray(indice_num, K) * input_grad_desc->dims[1] * cal_dwidth; + getMaxNumInArray(indice_num, K) * input_grad_desc->getDimIndex(1) * cal_dwidth; int8_t *filter_transpose = (int8_t *)filters; int8_t *workspace_base = (int8_t *)workspace; // transpose filters to layout XHWCN mluOpTensorDescriptor_t filter_transpose_desc; - if (filters_desc->layout != MLUOP_LAYOUT_HWCN && - filters_desc->layout != MLUOP_LAYOUT_ARRAY) { + if (filters_desc->getLayout() != MLUOP_LAYOUT_HWCN && + filters_desc->getLayout() != MLUOP_LAYOUT_ARRAY) { filter_transpose = (int8_t *)workspace; workspace_base += filter_transpose_size; cnnlTransposeDescriptor_t trans_desc; @@ -635,17 +635,17 @@ mluOpStatus_t MLUOP_WIN_API mluOpIndiceConvolutionBackwardData( CALL_CNNL(cnnlCreateTransposeDescriptor(&trans_desc)); int permute[5] = {0, 1, 2, 3, 4}; int filter_transpose_dims[5]; - getPermuteArray(filters_desc->layout, permute); - for (int i = 0; i < filters_desc->dim; ++i) { - filter_transpose_dims[i] = filters_desc->dims[permute[i]]; + getPermuteArray(filters_desc->getLayout(), permute); + for (int i = 0; i < filters_desc->getDim(); ++i) { + filter_transpose_dims[i] = filters_desc->getDimIndex(permute[i]); VLOG(5) << "permute " << permute[i]; } CHECK_RETURN(api_name, mluOpSetTensorDescriptor( filter_transpose_desc, MLUOP_LAYOUT_ARRAY, - filters_desc->dtype, filters_desc->dim, + filters_desc->getDtype(), filters_desc->getDim(), filter_transpose_dims)); CALL_CNNL( - cnnlSetTransposeDescriptor(trans_desc, filters_desc->dim, permute)); + cnnlSetTransposeDescriptor(trans_desc, filters_desc->getDim(), permute)); size_t transpose_workspace_size = 0; { DEFINE_CREATE_AND_SET_CNNL_HANDLE(handle, cnnl_handle); @@ -685,7 +685,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpIndiceConvolutionBackwardData( int sub_filter_dims[2] = {(int)(dxc), (int)(dyc)}; CHECK_RETURN(api_name, mluOpSetTensorDescriptor( sub_filters_desc, MLUOP_LAYOUT_ARRAY, - filters_desc->dtype, 2, sub_filter_dims)); + filters_desc->getDtype(), 2, sub_filter_dims)); float fill_value = 0; DEFINE_CREATE_AND_SET_CNNL_HANDLE(handle, cnnl_handle); DEFINE_CREATE_AND_SET_CNNL_TENSOR_DESCRIPTOR(input_grad_desc, @@ -722,10 +722,10 @@ mluOpStatus_t MLUOP_WIN_API mluOpIndiceConvolutionBackwardData( int output_grad_condence_dims[2] = {(int)(indice_num[kk]), (int)(dyc)}; CHECK_RETURN(api_name, mluOpSetTensorDescriptor(output_grad_condence_desc, MLUOP_LAYOUT_ARRAY, - output_grad_desc->dtype, 2, + output_grad_desc->getDtype(), 2, output_grad_condence_dims)); uint64_t gather_indices_offset = - (kk * 2 + 1) * int(indice_pairs_desc->dims[2]) * int_dwidth; + (kk * 2 + 1) * int(indice_pairs_desc->getDimIndex(2)) * int_dwidth; int8_t *gather_indices = (int8_t *)(const_cast(indice_pairs)) + gather_indices_offset; { @@ -762,7 +762,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpIndiceConvolutionBackwardData( int input_grad_condence_dims[2] = {(int)(indice_num[kk]), (int)(dxc)}; CHECK_RETURN(api_name, mluOpSetTensorDescriptor(input_grad_condence_desc, MLUOP_LAYOUT_ARRAY, - input_grad_desc->dtype, 2, + input_grad_desc->getDtype(), 2, input_grad_condence_dims)); cnnlMatMulHeuristicResult_t heuristic_result; CALL_CNNL(cnnlCreateMatMulHeuristicResult(&heuristic_result)); @@ -833,7 +833,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpIndiceConvolutionBackwardData( // fill workspace_input_grad_tmp uint64_t input_grad_tmp_workspace_size = mluOpGetTensorElementNum(input_grad_desc) * - mluOpDataTypeBytes(input_grad_desc->dtype); + mluOpDataTypeBytes(input_grad_desc->getDtype()); if (kk_count == 0) { workspace_input_grad_tmp = workspace_base; workspace_base += input_grad_tmp_workspace_size; @@ -848,7 +848,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpIndiceConvolutionBackwardData( // scatter input_grad uint64_t scatter_indices_offset = - (kk * 2) * int(indice_pairs_desc->dims[2]) * int_dwidth; + (kk * 2) * int(indice_pairs_desc->getDimIndex(2)) * int_dwidth; int8_t *scatter_indices = (int8_t *)(const_cast(indice_pairs)) + scatter_indices_offset; { diff --git a/kernels/sparse_conv/indice_convolution_backward_filter/indice_convolution_backward_filter.cpp b/kernels/sparse_conv/indice_convolution_backward_filter/indice_convolution_backward_filter.cpp index 1a464735b..6cdacca22 100644 --- a/kernels/sparse_conv/indice_convolution_backward_filter/indice_convolution_backward_filter.cpp +++ b/kernels/sparse_conv/indice_convolution_backward_filter/indice_convolution_backward_filter.cpp @@ -38,10 +38,10 @@ inline bool isFloatDtype(const mluOpDataType_t &dtype) { inline mluOpDataType_t getOnchipDataType( const mluOpTensorDescriptor_t tensor_desc) { - if (tensor_desc->onchip_dtype != MLUOP_DTYPE_INVALID) { - return tensor_desc->onchip_dtype; + if (tensor_desc->getOnchipDtype() != MLUOP_DTYPE_INVALID) { + return tensor_desc->getOnchipDtype(); } else { - return tensor_desc->dtype; + return tensor_desc->getDtype(); } } @@ -65,10 +65,10 @@ inline mluOpStatus_t setMatmulDescInfo(const std::string api_name, inline std::string getTensorShapeString(const mluOpTensorDescriptor_t desc) { std::string res; res.push_back('['); - for (int32_t i = 0; i < desc->dim - 1; i++) { - res.append(std::to_string(desc->dims[i]) + ','); + for (int32_t i = 0; i < desc->getDim() - 1; i++) { + res.append(std::to_string(desc->getDimIndex(i)) + ','); } - res.append(std::to_string(desc->dims[desc->dim - 1]) + ']'); + res.append(std::to_string(desc->getDimIndex(desc->getDim() - 1)) + ']'); return res; } @@ -91,7 +91,7 @@ static void indiceConvFilterGencase( inverse); GEN_CASE_OP_PARAM_SINGLE(1, "indice_convolution_backward", "subm", subm); GEN_CASE_OP_PARAM_ARRAY(1, "indice_convolution_backward", "indice_num", - indice_num, indice_pairs_desc->dims[0]); + indice_num, indice_pairs_desc->getDimIndex(0)); GEN_CASE_HANDLE_PARAM(); GEN_CASE_TEST_PARAM_NEW(true, true, false, 0.003, 0.003, 0); } @@ -102,10 +102,10 @@ static mluOpStatus_t indiceConvDtypeVaild( const mluOpTensorDescriptor_t output_grad_desc, const mluOpTensorDescriptor_t indice_pairs_desc, const mluOpTensorDescriptor_t filters_grad_desc) { - auto input_dtype = features_desc->dtype; - auto diffy_dtype = output_grad_desc->dtype; - auto filters_grad_dtype = filters_grad_desc->dtype; - auto pairs_dtype = indice_pairs_desc->dtype; + auto input_dtype = features_desc->getDtype(); + auto diffy_dtype = output_grad_desc->getDtype(); + auto filters_grad_dtype = filters_grad_desc->getDtype(); + auto pairs_dtype = indice_pairs_desc->getDtype(); if (pairs_dtype != MLUOP_DTYPE_INT32) { LOG(ERROR) << api_name << " indice_pairs_desc only supports data type int32. " @@ -127,10 +127,10 @@ static mluOpStatus_t indiceConvDtypeVaild( return MLUOP_STATUS_BAD_PARAM; } - auto input_on_dtype = features_desc->onchip_dtype; - auto diffy_on_dtype = output_grad_desc->onchip_dtype; - auto filters_grad_on_dtype = filters_grad_desc->onchip_dtype; - auto pairs_on_dtype = indice_pairs_desc->onchip_dtype; + auto input_on_dtype = features_desc->getOnchipDtype(); + auto diffy_on_dtype = output_grad_desc->getOnchipDtype(); + auto filters_grad_on_dtype = filters_grad_desc->getOnchipDtype(); + auto pairs_on_dtype = indice_pairs_desc->getOnchipDtype(); if ((MLUOP_DTYPE_INVALID != input_on_dtype && input_on_dtype != input_dtype) || (MLUOP_DTYPE_INVALID != diffy_on_dtype && @@ -218,28 +218,28 @@ static mluOpStatus_t baseParamCheck( return MLUOP_STATUS_NOT_SUPPORTED; } bool shape_check = true; - if (2 != features_desc->dim || 2 != output_grad_desc->dim || - 3 != indice_pairs_desc->dim || - (4 != filters_grad_desc->dim && 5 != filters_grad_desc->dim)) { + if (2 != features_desc->getDim() || 2 != output_grad_desc->getDim() || + 3 != indice_pairs_desc->getDim() || + (4 != filters_grad_desc->getDim() && 5 != filters_grad_desc->getDim())) { shape_check = false; // dimension check failed! } // only DHWCN/HWCN layout of filter_grad is supported, currently - int32_t filter_dim_len = filters_grad_desc->dim; - auto ci = filters_grad_desc->dims[filter_dim_len - 2]; - auto co = filters_grad_desc->dims[filter_dim_len - 1]; - auto kd = filter_dim_len == 4 ? 1 : filters_grad_desc->dims[0]; - auto kh = filter_dim_len == 4 ? filters_grad_desc->dims[0] - : filters_grad_desc->dims[1]; - auto kw = filter_dim_len == 4 ? filters_grad_desc->dims[1] - : filters_grad_desc->dims[2]; - if (ci != features_desc->dims[1] || co != output_grad_desc->dims[1] || - features_desc->dims[0] != indice_pairs_desc->dims[2] || - 2 != indice_pairs_desc->dims[1] || - kd * kh * kw != indice_pairs_desc->dims[0]) { + int32_t filter_dim_len = filters_grad_desc->getDim(); + auto ci = filters_grad_desc->getDimIndex(filter_dim_len - 2); + auto co = filters_grad_desc->getDimIndex(filter_dim_len - 1); + auto kd = filter_dim_len == 4 ? 1 : filters_grad_desc->getDimIndex(0); + auto kh = filter_dim_len == 4 ? filters_grad_desc->getDimIndex(0) + : filters_grad_desc->getDimIndex(1); + auto kw = filter_dim_len == 4 ? filters_grad_desc->getDimIndex(1) + : filters_grad_desc->getDimIndex(2); + if (ci != features_desc->getDimIndex(1) || co != output_grad_desc->getDimIndex(1) || + features_desc->getDimIndex(0) != indice_pairs_desc->getDimIndex(2) || + 2 != indice_pairs_desc->getDimIndex(1) || + kd * kh * kw != indice_pairs_desc->getDimIndex(0)) { shape_check = false; // interdependent dimension check failed! } - PARAM_CHECK_LE(api_name, indice_pairs_desc->dims[2], + PARAM_CHECK_LE(api_name, indice_pairs_desc->getDimIndex(2), INDICE_IN_LARGE_TENSOR_NUM); if (!shape_check) { @@ -265,8 +265,8 @@ static mluOpStatus_t insertTranspose( int32_t trans_in_shape[3] = {kernel_volume, ci, co}; int32_t trans_out_shape[3] = {co, kernel_volume, ci}; // NHWC or NDHWC int32_t permute[3] = {2, 0, 1}; - if (MLUOP_LAYOUT_NCHW == filters_grad_desc->layout || - MLUOP_LAYOUT_NCDHW == filters_grad_desc->layout) { + if (MLUOP_LAYOUT_NCHW == filters_grad_desc->getLayout() || + MLUOP_LAYOUT_NCDHW == filters_grad_desc->getLayout()) { trans_out_shape[0] = co; trans_out_shape[1] = ci; trans_out_shape[2] = kernel_volume; @@ -283,10 +283,10 @@ static mluOpStatus_t insertTranspose( CALL_CNNL(cnnlCreateTransposeDescriptor(&trans_desc)); CHECK_RETURN(api_name, mluOpSetTensorDescriptor( trans_in_desc, MLUOP_LAYOUT_ARRAY, - filters_grad_desc->dtype, 3, trans_in_shape)); + filters_grad_desc->getDtype(), 3, trans_in_shape)); CHECK_RETURN(api_name, mluOpSetTensorDescriptor( trans_out_desc, MLUOP_LAYOUT_ARRAY, - filters_grad_desc->dtype, 3, trans_out_shape)); + filters_grad_desc->getDtype(), 3, trans_out_shape)); CALL_CNNL(cnnlSetTransposeDescriptor(trans_desc, 3, permute)); { DEFINE_CREATE_AND_SET_CNNL_HANDLE(handle, cnnl_handle); @@ -329,9 +329,9 @@ static mluOpStatus_t internalIndiceConvBackwardFilter( bool filters_grad_need_trans = false; // call gather_nd and matmul to finish indice conv. - int32_t kernel_volume = indice_pairs_desc->dims[0]; - int32_t ci = features_desc->dims[1]; - int32_t co = output_grad_desc->dims[1]; + int32_t kernel_volume = indice_pairs_desc->getDimIndex(0); + int32_t ci = features_desc->getDimIndex(1); + int32_t co = output_grad_desc->getDimIndex(1); int32_t max_active_num = 0; for (int32_t i = 0; i < kernel_volume; ++i) { max_active_num = @@ -339,11 +339,11 @@ static mluOpStatus_t internalIndiceConvBackwardFilter( } int64_t max_input_size = - max_active_num * ci * mluop::getSizeOfDataType(features_desc->dtype); + max_active_num * ci * mluop::getSizeOfDataType(features_desc->getDtype()); int64_t max_diffy_size = - max_active_num * co * mluop::getSizeOfDataType(features_desc->dtype); + max_active_num * co * mluop::getSizeOfDataType(features_desc->getDtype()); int64_t filters_grad_trans_size = - filters_grad_need_trans ? filters_grad_desc->total_tensor_size : 0; + filters_grad_need_trans ? filters_grad_desc->getTotalTensorSize() : 0; void *filters_grad_temp = filters_grad_need_trans ? workspace : filters_grad; void *input_temp = (int8_t *)workspace + filters_grad_trans_size; @@ -382,11 +382,11 @@ static mluOpStatus_t internalIndiceConvBackwardFilter( DESTROY_CNNL_HANDLE(cnnl_handle); } - int64_t in_active_num = indice_pairs_desc->dims[2]; + int64_t in_active_num = indice_pairs_desc->getDimIndex(2); int64_t cico_size = - ci * co * mluop::getSizeOfDataType(filters_grad_desc->dtype); + ci * co * mluop::getSizeOfDataType(filters_grad_desc->getDtype()); int64_t pair_low_size = - in_active_num * mluop::getSizeOfDataType(indice_pairs_desc->dtype); + in_active_num * mluop::getSizeOfDataType(indice_pairs_desc->getDtype()); for (int32_t i = 0; i < kernel_volume; ++i) { int32_t active_point_num = indice_num[i]; @@ -400,16 +400,16 @@ static mluOpStatus_t internalIndiceConvBackwardFilter( int32_t c_desc_dims[2] = {ci, co}; CHECK_RETURN(api_name, mluOpSetTensorDescriptor( active_indice_desc, MLUOP_LAYOUT_ARRAY, - indice_pairs_desc->dtype, 2, active_indices)); + indice_pairs_desc->getDtype(), 2, active_indices)); CHECK_RETURN(api_name, mluOpSetTensorDescriptor( matmul_a_desc, MLUOP_LAYOUT_ARRAY, - features_desc->dtype, 2, a_desc_dims)); + features_desc->getDtype(), 2, a_desc_dims)); CHECK_RETURN(api_name, mluOpSetTensorDescriptor( matmul_b_desc, MLUOP_LAYOUT_ARRAY, - output_grad_desc->dtype, 2, b_desc_dims)); + output_grad_desc->getDtype(), 2, b_desc_dims)); CHECK_RETURN(api_name, mluOpSetTensorDescriptor( matmul_c_desc, MLUOP_LAYOUT_ARRAY, - filters_grad_desc->dtype, 2, c_desc_dims)); + filters_grad_desc->getDtype(), 2, c_desc_dims)); { DEFINE_CREATE_AND_SET_CNNL_HANDLE(handle, cnnl_handle); DEFINE_CREATE_AND_SET_CNNL_TENSOR_DESCRIPTOR(matmul_a_desc, cnnl_a_desc); @@ -548,10 +548,10 @@ mluOpGetIndiceConvolutionBackwardFilterWorkspaceSize( } // zero element check - if (0 == features_desc->total_element_num || - 0 == output_grad_desc->total_element_num || - 0 == indice_pairs_desc->total_element_num || - 0 == filters_grad_desc->total_element_num) { + if (0 == features_desc->getTotalElementNum() || + 0 == output_grad_desc->getTotalElementNum() || + 0 == indice_pairs_desc->getTotalElementNum() || + 0 == filters_grad_desc->getTotalElementNum()) { VLOG(5) << api_name << " Skip zero element tensor."; return MLUOP_STATUS_SUCCESS; } @@ -581,10 +581,10 @@ mluOpStatus_t MLUOP_WIN_API mluOpIndiceConvolutionBackwardFilter( } // zero element check - if (0 == features_desc->total_element_num || - 0 == output_grad_desc->total_element_num || - 0 == indice_pairs_desc->total_element_num || - 0 == filters_grad_desc->total_element_num) { + if (0 == features_desc->getTotalElementNum() || + 0 == output_grad_desc->getTotalElementNum() || + 0 == indice_pairs_desc->getTotalElementNum() || + 0 == filters_grad_desc->getTotalElementNum()) { VLOG(5) << api_name << " Skip zero element tensor."; return MLUOP_STATUS_SUCCESS; } diff --git a/kernels/sparse_conv/indice_convolution_forward/indice_convolution_forward.cpp b/kernels/sparse_conv/indice_convolution_forward/indice_convolution_forward.cpp index 5022875a5..d0fb269cc 100644 --- a/kernels/sparse_conv/indice_convolution_forward/indice_convolution_forward.cpp +++ b/kernels/sparse_conv/indice_convolution_forward/indice_convolution_forward.cpp @@ -57,15 +57,15 @@ static mluOpStatus_t foolProof( } // data type check - PARAM_CHECK(api_name, features_desc->dtype == MLUOP_DTYPE_FLOAT || - features_desc->dtype == MLUOP_DTYPE_HALF); - PARAM_CHECK(api_name, filters_desc->dtype == MLUOP_DTYPE_FLOAT || - filters_desc->dtype == MLUOP_DTYPE_HALF); - PARAM_CHECK(api_name, indice_pairs_desc->dtype == MLUOP_DTYPE_INT32); - PARAM_CHECK(api_name, features_out_desc->dtype == MLUOP_DTYPE_FLOAT || - features_out_desc->dtype == MLUOP_DTYPE_HALF); - PARAM_CHECK(api_name, features_desc->dtype == features_out_desc->dtype && - features_desc->dtype == filters_desc->dtype); + PARAM_CHECK(api_name, features_desc->getDtype() == MLUOP_DTYPE_FLOAT || + features_desc->getDtype() == MLUOP_DTYPE_HALF); + PARAM_CHECK(api_name, filters_desc->getDtype() == MLUOP_DTYPE_FLOAT || + filters_desc->getDtype() == MLUOP_DTYPE_HALF); + PARAM_CHECK(api_name, indice_pairs_desc->getDtype() == MLUOP_DTYPE_INT32); + PARAM_CHECK(api_name, features_out_desc->getDtype() == MLUOP_DTYPE_FLOAT || + features_out_desc->getDtype() == MLUOP_DTYPE_HALF); + PARAM_CHECK(api_name, features_desc->getDtype() == features_out_desc->getDtype() && + features_desc->getDtype() == filters_desc->getDtype()); // inverse not supported now PARAM_CHECK(api_name, sub_m == 0 || sub_m == 1); @@ -78,30 +78,30 @@ static mluOpStatus_t foolProof( // layout check // DHWCN layout not supported yet, use ARRAY temporarily - // PARAM_CHECK(api_name, filters_desc->layout == MLUOP_LAYOUT_DHWCN); - if (filters_desc->layout != MLUOP_LAYOUT_NDHWC && - filters_desc->layout != MLUOP_LAYOUT_NCDHW && - filters_desc->layout != MLUOP_LAYOUT_ARRAY) { + // PARAM_CHECK(api_name, filters_desc->getLayout() == MLUOP_LAYOUT_DHWCN); + if (filters_desc->getLayout() != MLUOP_LAYOUT_NDHWC && + filters_desc->getLayout() != MLUOP_LAYOUT_NCDHW && + filters_desc->getLayout() != MLUOP_LAYOUT_ARRAY) { LOG(ERROR) << api_name << "The layout of filters is: " - << mluOpGetNameOfTensorLayout(filters_desc->layout) + << mluOpGetNameOfTensorLayout(filters_desc->getLayout()) << ", which is not supported now."; return MLUOP_STATUS_NOT_SUPPORTED; } // shape check - PARAM_CHECK(api_name, features_desc->dim == 2); - PARAM_CHECK(api_name, indice_pairs_desc->dim == 3); - PARAM_CHECK(api_name, features_out_desc->dim == 2); - if (indice_pairs_desc->dims[2] > INDICE_IN_LARGE_TENSOR_NUM) { + PARAM_CHECK(api_name, features_desc->getDim() == 2); + PARAM_CHECK(api_name, indice_pairs_desc->getDim() == 3); + PARAM_CHECK(api_name, features_out_desc->getDim() == 2); + if (indice_pairs_desc->getDimIndex(2) > INDICE_IN_LARGE_TENSOR_NUM) { LOG(ERROR) << api_name << " Check failed: " - << "indice_pairs_desc->dims[2] cannot be greater than " + << "indice_pairs_desc->getDimIndex(2) cannot be greater than " << INDICE_IN_LARGE_TENSOR_NUM << "."; return MLUOP_STATUS_NOT_SUPPORTED; } - if (filters_desc->dim != 5) { + if (filters_desc->getDim() != 5) { LOG(ERROR) << api_name << "The filters dimension number only support 5 currently," - << " but filters dimension number is :" << filters_desc->dim + << " but filters dimension number is :" << filters_desc->getDim() << "."; return MLUOP_STATUS_NOT_SUPPORTED; } @@ -129,11 +129,11 @@ static mluOpStatus_t foolProof( auto ci = 0; auto num_filter = 0; auto co = 0; - if (filters_desc->layout == MLUOP_LAYOUT_ARRAY) { - ci = filters_desc->dims[3]; + if (filters_desc->getLayout() == MLUOP_LAYOUT_ARRAY) { + ci = filters_desc->getDimIndex(3); num_filter = - filters_desc->dims[0] * filters_desc->dims[1] * filters_desc->dims[2]; - co = filters_desc->dims[4]; + filters_desc->getDimIndex(0) * filters_desc->getDimIndex(1) * filters_desc->getDimIndex(2); + co = filters_desc->getDimIndex(4); } else { ci = mluOpGetTensordimC(filters_desc); num_filter = mluOpGetTensordimD(filters_desc) * @@ -143,22 +143,22 @@ static mluOpStatus_t foolProof( } // features shape check - PARAM_CHECK(api_name, features_desc->dims[0] == indice_pairs_desc->dims[2]); - PARAM_CHECK(api_name, features_desc->dims[1] == ci); + PARAM_CHECK(api_name, features_desc->getDimIndex(0) == indice_pairs_desc->getDimIndex(2)); + PARAM_CHECK(api_name, features_desc->getDimIndex(1) == ci); // indice_pairs shape check - PARAM_CHECK(api_name, indice_pairs_desc->dims[0] == num_filter); - PARAM_CHECK(api_name, indice_pairs_desc->dims[1] == 2); + PARAM_CHECK(api_name, indice_pairs_desc->getDimIndex(0) == num_filter); + PARAM_CHECK(api_name, indice_pairs_desc->getDimIndex(1) == 2); // features_out shape check - PARAM_CHECK(api_name, features_out_desc->dims[0] == num_act_out); - PARAM_CHECK(api_name, features_out_desc->dims[1] == co); + PARAM_CHECK(api_name, features_out_desc->getDimIndex(0) == num_act_out); + PARAM_CHECK(api_name, features_out_desc->getDimIndex(1) == co); // indice_num[] check for (int i = 0; i < num_filter; ++i) { std::string i_str = "i: " + std::to_string(i) + "."; PARAM_CHECK_V2( - api_name, indice_num[i] >= 0 && indice_num[i] <= features_desc->dims[0], + api_name, indice_num[i] >= 0 && indice_num[i] <= features_desc->getDimIndex(0), << i_str); } @@ -179,21 +179,21 @@ static mluOpStatus_t mainIndiceConvolutionForward( int32_t ci = 0; int32_t co = 0; // MLUOP_LAYOUT_DHWCN not supported yet. - if (filters_desc->layout == MLUOP_LAYOUT_ARRAY) { + if (filters_desc->getLayout() == MLUOP_LAYOUT_ARRAY) { filters_need_trans = false; - ci = filters_desc->dims[3]; - co = filters_desc->dims[4]; + ci = filters_desc->getDimIndex(3); + co = filters_desc->getDimIndex(4); } else { ci = mluOpGetTensordimC(filters_desc); co = mluOpGetTensordimN(filters_desc); } - int32_t num_filter = indice_pairs_desc->dims[0]; + int32_t num_filter = indice_pairs_desc->getDimIndex(0); - int64_t num_act_in = indice_pairs_desc->dims[2]; + int64_t num_act_in = indice_pairs_desc->getDimIndex(2); int64_t elementSize_filters = - ci * co * mluop::getSizeOfDataType(filters_desc->dtype); + ci * co * mluop::getSizeOfDataType(filters_desc->getDtype()); int64_t elementSize_indice_pairs = - num_act_in * mluop::getSizeOfDataType(indice_pairs_desc->dtype); + num_act_in * mluop::getSizeOfDataType(indice_pairs_desc->getDtype()); int32_t max_indice_num = 0; for (int i = 0; i < num_filter; ++i) { @@ -201,17 +201,17 @@ static mluOpStatus_t mainIndiceConvolutionForward( indice_num[i] > max_indice_num ? indice_num[i] : max_indice_num; } size_t workspaceSize_gather = - max_indice_num * ci * mluop::getSizeOfDataType(features_desc->dtype); + max_indice_num * ci * mluop::getSizeOfDataType(features_desc->getDtype()); size_t workspaceSize_matmul = - max_indice_num * co * mluop::getSizeOfDataType(features_out_desc->dtype); + max_indice_num * co * mluop::getSizeOfDataType(features_out_desc->getDtype()); size_t workspaceSize_transpose = 0; size_t workspaceSize_transposeExtra = 0; if (filters_need_trans) { workspaceSize_transpose = - num_filter * ci * co * mluop::getSizeOfDataType(filters_desc->dtype); + num_filter * ci * co * mluop::getSizeOfDataType(filters_desc->getDtype()); } size_t workspaceSize_scatter = - num_act_out * co * mluop::getSizeOfDataType(features_out_desc->dtype); + num_act_out * co * mluop::getSizeOfDataType(features_out_desc->getDtype()); size_t workspaceSize_matmulExtra = 0; size_t tempSize_matmulExtra = 0; size_t workspaceSize_addNExtra = 0; @@ -225,7 +225,7 @@ static mluOpStatus_t mainIndiceConvolutionForward( int matmul_is_transA = 0; int matmul_is_transB = 0; uint32_t matmul_allow_TF32 = 0; - uint32_t matmul_computetype = (uint32_t)filters_desc->dtype; + uint32_t matmul_computetype = (uint32_t)filters_desc->getDtype(); // allocate workspace segment for intermediate data void *validFilters_ptr = filters_need_trans ? workspace : (void *)filters; @@ -267,7 +267,7 @@ static mluOpStatus_t mainIndiceConvolutionForward( int trans_in_shape[3] = {0, 0, 0}; int trans_out_shape[3] = {num_filter, ci, co}; int permute[3] = {0, 0, 0}; - if (MLUOP_LAYOUT_NDHWC == filters_desc->layout) { + if (MLUOP_LAYOUT_NDHWC == filters_desc->getLayout()) { trans_in_shape[0] = co; trans_in_shape[1] = num_filter; trans_in_shape[2] = ci; @@ -275,7 +275,7 @@ static mluOpStatus_t mainIndiceConvolutionForward( permute[1] = 2; permute[2] = 0; } else { - // MLUOP_LAYOUT_NCDHW == filters_desc->layout + // MLUOP_LAYOUT_NCDHW == filters_desc->getLayout() trans_in_shape[0] = co; trans_in_shape[1] = ci; trans_in_shape[2] = num_filter; @@ -290,10 +290,10 @@ static mluOpStatus_t mainIndiceConvolutionForward( CALL_CNNL(cnnlCreateTransposeDescriptor(&trans_desc)); CHECK_RETURN(api_name, mluOpSetTensorDescriptor( trans_in_desc, MLUOP_LAYOUT_ARRAY, - filters_desc->dtype, 3, trans_in_shape)); + filters_desc->getDtype(), 3, trans_in_shape)); CHECK_RETURN(api_name, mluOpSetTensorDescriptor( trans_out_desc, MLUOP_LAYOUT_ARRAY, - filters_desc->dtype, 3, trans_out_shape)); + filters_desc->getDtype(), 3, trans_out_shape)); CALL_CNNL(cnnlSetTransposeDescriptor(trans_desc, 3, permute)); { DEFINE_CREATE_AND_SET_CNNL_HANDLE(handle, cnnl_handle); @@ -347,16 +347,16 @@ static mluOpStatus_t mainIndiceConvolutionForward( matmul_c_shape[0] = active_point_num; CHECK_RETURN(api_name, mluOpSetTensorDescriptor( active_indice_desc, MLUOP_LAYOUT_ARRAY, - indice_pairs_desc->dtype, 2, active_indice)); + indice_pairs_desc->getDtype(), 2, active_indice)); CHECK_RETURN(api_name, mluOpSetTensorDescriptor( matmul_a_desc, MLUOP_LAYOUT_ARRAY, - features_desc->dtype, 2, matmul_a_shape)); + features_desc->getDtype(), 2, matmul_a_shape)); CHECK_RETURN(api_name, mluOpSetTensorDescriptor( matmul_b_desc, MLUOP_LAYOUT_ARRAY, - features_out_desc->dtype, 2, matmul_b_shape)); + features_out_desc->getDtype(), 2, matmul_b_shape)); CHECK_RETURN(api_name, mluOpSetTensorDescriptor( matmul_c_desc, MLUOP_LAYOUT_ARRAY, - features_desc->dtype, 2, matmul_c_shape)); + features_desc->getDtype(), 2, matmul_c_shape)); { DEFINE_CREATE_AND_SET_CNNL_HANDLE(handle, cnnl_handle); DEFINE_CREATE_AND_SET_CNNL_TENSOR_DESCRIPTOR(matmul_a_desc, cnnl_a_desc); @@ -632,7 +632,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpIndiceConvolutionForward( inverse); GEN_CASE_OP_PARAM_SINGLE(1, "indice_convolution_forward", "sub_m", sub_m); GEN_CASE_OP_PARAM_ARRAY(1, "indice_convolution_forward", "indice_num", - indice_num, indice_pairs_desc->dims[0]); + indice_num, indice_pairs_desc->getDimIndex(0)); GEN_CASE_OP_PARAM_SINGLE(1, "indice_convolution_forward", "num_active_out", num_act_out); GEN_CASE_HANDLE_PARAM(); diff --git a/kernels/sqrt/sqrt.cpp b/kernels/sqrt/sqrt.cpp index 9a1279fdc..e86b03088 100644 --- a/kernels/sqrt/sqrt.cpp +++ b/kernels/sqrt/sqrt.cpp @@ -62,9 +62,9 @@ mluOpStatus_t MLUOP_WIN_API mluOpSqrt(mluOpHandle_t handle, PARAM_CHECK(op_name_forward, x_desc != NULL); PARAM_CHECK(op_name_forward, y_desc != NULL); bool x_dtype_transform = false; - if (x_desc->dtype == MLUOP_DTYPE_INT32 && - y_desc->dtype == MLUOP_DTYPE_FLOAT) { - x_desc->dtype = MLUOP_DTYPE_FLOAT; + if (x_desc->getDtype() == MLUOP_DTYPE_INT32 && + y_desc->getDtype() == MLUOP_DTYPE_FLOAT) { + x_desc->setDtype(MLUOP_DTYPE_FLOAT); x_dtype_transform = true; } @@ -83,7 +83,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpSqrt(mluOpHandle_t handle, } // correct the input's type if (x_dtype_transform) { - x_desc->dtype = MLUOP_DTYPE_INT32; + x_desc->setDtype(MLUOP_DTYPE_INT32); } if (param_check != MLUOP_STATUS_SUCCESS) { @@ -120,7 +120,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpSqrt(mluOpHandle_t handle, VLOG(5) << "kernel Kernel3StagePipelineSqrt."; CHECK_RETURN("[mluOpSqrt] ", Kernel3StagePipelineSqrt(k_dim, k_type, handle->queue, - x_desc->dtype, prefer, x, y, dim_x)); + x_desc->getDtype(), prefer, x, y, dim_x)); GEN_CASE_END(); return MLUOP_STATUS_SUCCESS; @@ -164,7 +164,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpSqrtBackward( VLOG(5) << "Kernel Kernel3StagePipelineSqrtBackward."; CHECK_RETURN("[mluOpSqrtBackward] ", Kernel3StagePipelineSqrtBackward(k_dim, k_type, handle->queue, - y_desc->dtype, y, diff_y, + y_desc->getDtype(), y, diff_y, diff_x, num_elem)); GEN_CASE_END(); return MLUOP_STATUS_SUCCESS; diff --git a/kernels/tensor_stride_process/tensor_stride_process_host.cpp b/kernels/tensor_stride_process/tensor_stride_process_host.cpp index 410112258..b5eb15fbc 100644 --- a/kernels/tensor_stride_process/tensor_stride_process_host.cpp +++ b/kernels/tensor_stride_process/tensor_stride_process_host.cpp @@ -77,11 +77,11 @@ bool strideCaseWithNotConsistentDense(int tensor_num, ...) { } int64_t first_dims[MLUOP_DIM_MAX] = {0}; int64_t first_stride[MLUOP_DIM_MAX] = {0}; - auto first_dim = first_stride_tensor->dim; + auto first_dim = first_stride_tensor->getDim(); // get first stride tensor's shape and stride info for (auto i = 0; i < first_dim; i++) { - first_dims[i] = first_stride_tensor->dims[i]; - first_stride[i] = first_stride_tensor->strides[i]; + first_dims[i] = first_stride_tensor->getDimIndex(i); + first_stride[i] = first_stride_tensor->getStrideIndex(i); } // judge whether shapes and strides of tensors are same, // if not, need stride process @@ -93,14 +93,14 @@ bool strideCaseWithNotConsistentDense(int tensor_num, ...) { // ignore scalar continue; } - if (this_tensor->dim != first_dim) { + if (this_tensor->getDim() != first_dim) { va_end(ap); return true; } for (auto j = 0; j < first_dim; j++) { - if (first_dims[j] != this_tensor->dims[j] || + if (first_dims[j] != this_tensor->getDimIndex(j) || ((first_dims[j] != 1) && - (first_stride[j] != this_tensor->strides[j]))) { + (first_stride[j] != this_tensor->getStrideIndex(j)))) { va_end(ap); return true; } @@ -112,13 +112,13 @@ bool strideCaseWithNotConsistentDense(int tensor_num, ...) { } bool isDenseStrideTensor(const mluOpTensorDescriptor_t tensor_desc) { - int tensor_dim = tensor_desc->dim; + int tensor_dim = tensor_desc->getDim(); std::vector dims; std::vector strides; std::vector perm; for (int i = 0; i < tensor_dim; i++) { - dims.emplace_back(tensor_desc->dims[i]); - strides.emplace_back(tensor_desc->strides[i]); + dims.emplace_back(tensor_desc->getDimIndex(i)); + strides.emplace_back(tensor_desc->getStrideIndex(i)); perm.emplace_back(i); } @@ -151,12 +151,12 @@ bool isDenseStrideTensor(const mluOpTensorDescriptor_t tensor_desc) { // Check if tensor need stride process. bool ifNeedTensorStrideProcess(const mluOpTensorDescriptor_t tensor_desc) { bool needStrideProcess = false; - int tensor_dim = tensor_desc->dim; + int tensor_dim = tensor_desc->getDim(); int64_t stride_base = 1; for (int i = tensor_dim - 1; i >= 0; i--) { - if (tensor_desc->dims[i] != 1) { - if (tensor_desc->strides[i] == stride_base) { - stride_base *= tensor_desc->dims[i]; + if (tensor_desc->getDimIndex(i) != 1) { + if (tensor_desc->getStrideIndex(i) == stride_base) { + stride_base *= tensor_desc->getDimIndex(i); } else { needStrideProcess = true; break; @@ -243,7 +243,7 @@ void getTensorShape(const mluOpTensorDescriptor_t tensor_desc, } else { tensor_shape->is_contiguous = false; } - int tensor_dim = tensor_desc->dim; + int tensor_dim = tensor_desc->getDim(); int64_t tensor_dims[MLUOP_DIM_MAX]; int64_t tensor_strides[MLUOP_DIM_MAX]; int64_t tensor_temp_dims[MLUOP_DIM_MAX]; @@ -256,9 +256,9 @@ void getTensorShape(const mluOpTensorDescriptor_t tensor_desc, tensor_dims[i] = 1; tensor_strides[i] = 1; } else { - total_num *= tensor_desc->dims[i + tensor_dim - MLUOP_DIM_MAX]; - tensor_dims[i] = tensor_desc->dims[i + tensor_dim - MLUOP_DIM_MAX]; - tensor_strides[i] = tensor_desc->strides[i + tensor_dim - MLUOP_DIM_MAX]; + total_num *= tensor_desc->getDimIndex(i + tensor_dim - MLUOP_DIM_MAX); + tensor_dims[i] = tensor_desc->getDimIndex(i + tensor_dim - MLUOP_DIM_MAX); + tensor_strides[i] = tensor_desc->getStrideIndex(i + tensor_dim - MLUOP_DIM_MAX); } } tensor_shape->total_num = total_num; @@ -331,10 +331,10 @@ void getExpandTensorShape(const mluOpTensorDescriptor_t tensor_desc, target_shape[i + tensor_dim - MLUOP_DIM_MAX]; // set shape if (i >= MLUOP_DIM_MAX - - tensor_desc->dim) { // set stride if tensor_desc has this stride - if (tensor_desc->dims[i + tensor_desc->dim - MLUOP_DIM_MAX] != 1) { + tensor_desc->getDim()) { // set stride if tensor_desc has this stride + if (tensor_desc->getDimIndex(i + tensor_desc->getDim() - MLUOP_DIM_MAX) != 1) { tensor_strides[i] = - tensor_desc->strides[i + tensor_desc->dim - MLUOP_DIM_MAX]; + tensor_desc->getStrideIndex(i + tensor_desc->getDim() - MLUOP_DIM_MAX); } } } @@ -417,7 +417,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpTensorStrideIn( mluop::TensorShape input_shape; mluop::getTensorShape(input_desc, &input_shape); - mluOpDataType_t data_type = input_desc->dtype; + mluOpDataType_t data_type = input_desc->getDtype(); cnrtDim3_t k_dim; cnrtFunctionType_t k_type; @@ -445,7 +445,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpTensorStrideOut( "input tensor num with stride is too large. "); } - mluOpDataType_t data_type = input_desc->dtype; + mluOpDataType_t data_type = input_desc->getDtype(); cnrtDim3_t k_dim; cnrtFunctionType_t k_type; @@ -474,12 +474,12 @@ static vector getDefaultStride(int64_t *dims, int dim) { mluOpStatus_t MLUOP_WIN_API mluOpContiguous(mluOpHandle_t handle, const mluOpTensorDescriptor_t input_desc, const void *input, void *output) { - auto default_stride = getDefaultStride(input_desc->dims, input_desc->dim); + auto default_stride = getDefaultStride(input_desc->getDims(), input_desc->getDim()); mluOpTensorDescriptor_t temp_desc = nullptr; mluOpCreateTensorDescriptor(&temp_desc); - mluOpSetTensorDescriptorEx_v2(temp_desc, input_desc->layout, - input_desc->dtype, input_desc->dim, - input_desc->dims, default_stride.data()); + mluOpSetTensorDescriptorEx_v2(temp_desc, input_desc->getLayout(), + input_desc->getDtype(), input_desc->getDim(), + input_desc->getDims(), default_stride.data()); DEFINE_CREATE_AND_SET_CNNL_HANDLE(handle, cnnl_handle); DEFINE_CREATE_AND_SET_CNNL_TENSOR_DESCRIPTOR(input_desc, cnnl_input_desc); DEFINE_CREATE_AND_SET_CNNL_TENSOR_DESCRIPTOR(temp_desc, cnnl_temp_desc); diff --git a/kernels/three_interpolate/three_interpolate.cpp b/kernels/three_interpolate/three_interpolate.cpp index 0b0e3c142..9f29f8c53 100644 --- a/kernels/three_interpolate/three_interpolate.cpp +++ b/kernels/three_interpolate/three_interpolate.cpp @@ -52,7 +52,7 @@ static void policyFuncThreeInterpolate( int64_t core_in_cluster = handle->core_num_per_cluster; int64_t cores_in_device = cluster_num * core_in_cluster; int64_t input_size = sizeof(float); - if (desc->dtype == MLUOP_DTYPE_HALF) { + if (desc->getDtype() == MLUOP_DTYPE_HALF) { input_size /= 2; } int64_t align_base_128 = NFU_ALIGN_SIZE / input_size; @@ -270,51 +270,51 @@ mluOpStatus_t threeInterpolateForwardParamCheck( PARAM_CHECK(op_name, weights_desc != NULL); PARAM_CHECK(op_name, output_desc != NULL); // check dim - PARAM_CHECK(op_name, features_desc->dim == 3); - PARAM_CHECK(op_name, indices_desc->dim == 3); - PARAM_CHECK(op_name, weights_desc->dim == 3); - PARAM_CHECK(op_name, output_desc->dim == 3); + PARAM_CHECK(op_name, features_desc->getDim() == 3); + PARAM_CHECK(op_name, indices_desc->getDim() == 3); + PARAM_CHECK(op_name, weights_desc->getDim() == 3); + PARAM_CHECK(op_name, output_desc->getDim() == 3); // check layout - PARAM_CHECK(op_name, features_desc->layout == MLUOP_LAYOUT_ARRAY); - PARAM_CHECK(op_name, indices_desc->layout == MLUOP_LAYOUT_ARRAY); - PARAM_CHECK(op_name, weights_desc->layout == MLUOP_LAYOUT_ARRAY); - PARAM_CHECK(op_name, output_desc->layout == MLUOP_LAYOUT_ARRAY); + PARAM_CHECK(op_name, features_desc->getLayout() == MLUOP_LAYOUT_ARRAY); + PARAM_CHECK(op_name, indices_desc->getLayout() == MLUOP_LAYOUT_ARRAY); + PARAM_CHECK(op_name, weights_desc->getLayout() == MLUOP_LAYOUT_ARRAY); + PARAM_CHECK(op_name, output_desc->getLayout() == MLUOP_LAYOUT_ARRAY); // check data type - PARAM_CHECK(op_name, features_desc->dtype == weights_desc->dtype); - PARAM_CHECK(op_name, indices_desc->dtype == MLUOP_DTYPE_INT32); - PARAM_CHECK(op_name, weights_desc->dtype == output_desc->dtype); - PARAM_CHECK(op_name, (output_desc->dtype == MLUOP_DTYPE_HALF || - output_desc->dtype == MLUOP_DTYPE_FLOAT)); + PARAM_CHECK(op_name, features_desc->getDtype() == weights_desc->getDtype()); + PARAM_CHECK(op_name, indices_desc->getDtype() == MLUOP_DTYPE_INT32); + PARAM_CHECK(op_name, weights_desc->getDtype() == output_desc->getDtype()); + PARAM_CHECK(op_name, (output_desc->getDtype() == MLUOP_DTYPE_HALF || + output_desc->getDtype() == MLUOP_DTYPE_FLOAT)); // check shape - if (features_desc->dims[0] != indices_desc->dims[0]) { + if (features_desc->getDimIndex(0) != indices_desc->getDimIndex(0)) { LOG(ERROR) << op_name - << "Check failed: features_desc->dims[0] should be " - "equal to indices_desc->dims[0]."; + << "Check failed: features_desc->getDimIndex(0) should be " + "equal to indices_desc->getDimIndex(0)."; return MLUOP_STATUS_BAD_PARAM; } - for (int64_t i = 0; i < indices_desc->dim; ++i) { - if (indices_desc->dims[i] != weights_desc->dims[i]) { + for (int64_t i = 0; i < indices_desc->getDim(); ++i) { + if (indices_desc->getDimIndex(i) != weights_desc->getDimIndex(i)) { LOG(ERROR) << op_name << " Check failed: indices_desc->dims[" << i - << "] should be equal to weightss_desc->dims[" << i << "]."; + << "] should be equal to weightss_desc->getDimIndex(" << i << ")."; return MLUOP_STATUS_BAD_PARAM; } } - if (weights_desc->dims[2] != 3) { + if (weights_desc->getDimIndex(2) != 3) { LOG(ERROR) << op_name - << " Check failed: weights_desc->dims[2] should be equal to 3."; + << " Check failed: weights_desc->getDimIndex(2) should be equal to 3."; return MLUOP_STATUS_BAD_PARAM; } - for (int64_t i = 0; i < output_desc->dim - 1; ++i) { - if (output_desc->dims[i] != features_desc->dims[i]) { + for (int64_t i = 0; i < output_desc->getDim() - 1; ++i) { + if (output_desc->getDimIndex(i) != features_desc->getDimIndex(i)) { LOG(ERROR) << op_name << " Check failed: output_desc->dims[" << i - << "] should be equal to features_desc->dims[" << i << "]."; + << "] should be equal to features_desc->getDimIndex(" << i << ")."; return MLUOP_STATUS_BAD_PARAM; } } - if (output_desc->dims[2] != indices_desc->dims[1]) { + if (output_desc->getDimIndex(2) != indices_desc->getDimIndex(1)) { LOG(ERROR) << op_name - << " Check failed: output_desc->dims[2] should be " - "equal to indices_desc->dims[1]."; + << " Check failed: output_desc->getDimIndex(2) should be " + "equal to indices_desc->getDimIndex(1)."; return MLUOP_STATUS_BAD_PARAM; } // check stride @@ -344,7 +344,7 @@ mluOpStatus_t threeInterpolateForwardParamCheck( } // the shape of features is [B, C, M]. currently only M equal to 0 is // supported - if (features_desc->dims[2] == 0) { + if (features_desc->getDimIndex(2) == 0) { VLOG(5) << op_name << " Skip zero element tensor."; zero_element = true; return MLUOP_STATUS_SUCCESS; @@ -371,52 +371,52 @@ mluOpStatus_t threeInterpolateBackwardParamCheck( PARAM_CHECK(op_name, weights_desc != NULL); PARAM_CHECK(op_name, grad_features_desc != NULL); // check dim - PARAM_CHECK(op_name, grad_output_desc->dim == 3); - PARAM_CHECK(op_name, indices_desc->dim == 3); - PARAM_CHECK(op_name, weights_desc->dim == 3); - PARAM_CHECK(op_name, grad_features_desc->dim == 3); + PARAM_CHECK(op_name, grad_output_desc->getDim() == 3); + PARAM_CHECK(op_name, indices_desc->getDim() == 3); + PARAM_CHECK(op_name, weights_desc->getDim() == 3); + PARAM_CHECK(op_name, grad_features_desc->getDim() == 3); // check layout - PARAM_CHECK(op_name, grad_output_desc->layout == MLUOP_LAYOUT_ARRAY); - PARAM_CHECK(op_name, indices_desc->layout == MLUOP_LAYOUT_ARRAY); - PARAM_CHECK(op_name, weights_desc->layout == MLUOP_LAYOUT_ARRAY); - PARAM_CHECK(op_name, grad_features_desc->layout == MLUOP_LAYOUT_ARRAY); + PARAM_CHECK(op_name, grad_output_desc->getLayout() == MLUOP_LAYOUT_ARRAY); + PARAM_CHECK(op_name, indices_desc->getLayout() == MLUOP_LAYOUT_ARRAY); + PARAM_CHECK(op_name, weights_desc->getLayout() == MLUOP_LAYOUT_ARRAY); + PARAM_CHECK(op_name, grad_features_desc->getLayout() == MLUOP_LAYOUT_ARRAY); // check data type - PARAM_CHECK(op_name, grad_output_desc->dtype == weights_desc->dtype); - PARAM_CHECK(op_name, indices_desc->dtype == MLUOP_DTYPE_INT32); - PARAM_CHECK(op_name, weights_desc->dtype == grad_features_desc->dtype); - PARAM_CHECK(op_name, (grad_output_desc->dtype == MLUOP_DTYPE_HALF || - grad_output_desc->dtype == MLUOP_DTYPE_FLOAT)); + PARAM_CHECK(op_name, grad_output_desc->getDtype() == weights_desc->getDtype()); + PARAM_CHECK(op_name, indices_desc->getDtype() == MLUOP_DTYPE_INT32); + PARAM_CHECK(op_name, weights_desc->getDtype() == grad_features_desc->getDtype()); + PARAM_CHECK(op_name, (grad_output_desc->getDtype() == MLUOP_DTYPE_HALF || + grad_output_desc->getDtype() == MLUOP_DTYPE_FLOAT)); // check shape - if (grad_output_desc->dims[0] != indices_desc->dims[0]) { + if (grad_output_desc->getDimIndex(0) != indices_desc->getDimIndex(0)) { LOG(ERROR) << op_name - << " Check failed: grad_output_desc->dims[0] should be " - "equal to indices_desc->dims[0]."; + << " Check failed: grad_output_desc->getDimIndex(0) should be " + "equal to indices_desc->getDimIndex(0)."; return MLUOP_STATUS_BAD_PARAM; } - for (int64_t i = 0; i < indices_desc->dim; ++i) { - if (indices_desc->dims[i] != weights_desc->dims[i]) { + for (int64_t i = 0; i < indices_desc->getDim(); ++i) { + if (indices_desc->getDimIndex(i) != weights_desc->getDimIndex(i)) { LOG(ERROR) << op_name << " Check failed: indices_desc->dims[" << i - << "] should be equal to weightss_desc->dims[" << i << "]."; + << "] should be equal to weightss_desc->getDimIndex(" << i << ")."; return MLUOP_STATUS_BAD_PARAM; } } - if (weights_desc->dims[2] != 3) { + if (weights_desc->getDimIndex(2) != 3) { LOG(ERROR) << op_name - << " Check failed: weights_desc->dims[2] should be equal to 3."; + << " Check failed: weights_desc->getDimIndex(2) should be equal to 3."; return MLUOP_STATUS_BAD_PARAM; } - for (int64_t i = 0; i < grad_output_desc->dim - 1; ++i) { - if (grad_output_desc->dims[i] != grad_features_desc->dims[i]) { + for (int64_t i = 0; i < grad_output_desc->getDim() - 1; ++i) { + if (grad_output_desc->getDimIndex(i) != grad_features_desc->getDimIndex(i)) { LOG(ERROR) << op_name << " Check failed: grad_output_desc->dims[" << i << "] should be equal to grad_features_desc->dims[" << i << "]."; return MLUOP_STATUS_BAD_PARAM; } } - if (grad_output_desc->dims[2] != indices_desc->dims[1]) { + if (grad_output_desc->getDimIndex(2) != indices_desc->getDimIndex(1)) { LOG(ERROR) << op_name - << " Check failed: grad_output_desc->dims[2] should be " - "equal to indices_desc->dims[1]."; + << " Check failed: grad_output_desc->getDimIndex(2) should be " + "equal to indices_desc->getDimIndex(1)."; return MLUOP_STATUS_BAD_PARAM; } // check stride @@ -446,7 +446,7 @@ mluOpStatus_t threeInterpolateBackwardParamCheck( } // the shape of grad_features is [B, C, M]. currently only M equal to 0 is // supported - if (grad_features_desc->dims[2] == 0) { + if (grad_features_desc->getDimIndex(2) == 0) { VLOG(5) << op_name << " Skip zero element tensor."; zero_element = true; return MLUOP_STATUS_SUCCESS; @@ -476,10 +476,10 @@ mluOpStatus_t MLUOP_WIN_API mluOpThreeInterpolateForward( if (param_check != MLUOP_STATUS_SUCCESS) { return param_check; } - int64_t b = features_desc->dims[0]; - int64_t c = features_desc->dims[1]; - int64_t m = features_desc->dims[2]; - int64_t n = output_desc->dims[2]; + int64_t b = features_desc->getDimIndex(0); + int64_t c = features_desc->getDimIndex(1); + int64_t m = features_desc->getDimIndex(2); + int64_t n = output_desc->getDimIndex(2); if (MLUOP_GEN_CASE_ON_NEW) { GEN_CASE_START("three_interpolate_forward", "THREE_INTERPOLATE_FORWARD"); @@ -494,7 +494,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpThreeInterpolateForward( cnrtDim3_t k_dim; cnrtFunctionType_t k_type; int64_t input_size = sizeof(float); - if (features_desc->dtype == MLUOP_DTYPE_HALF) { + if (features_desc->getDtype() == MLUOP_DTYPE_HALF) { input_size /= 2; } int64_t c_limit_size = NFU_ALIGN_SIZE / input_size; @@ -508,7 +508,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpThreeInterpolateForward( VLOG(5) << "Kernel KernelThreeInterpolateForward"; CHECK_RETURN("[mluOpThreeInterpolateForward]", KernelThreeInterpolateForward( - k_dim, k_type, handle->queue, features_desc->dtype, features, + k_dim, k_type, handle->queue, features_desc->getDtype(), features, indices, weights, b, c, m, n, c_limit_size, m_limit_size, n_limit_size, output)); @@ -533,10 +533,10 @@ mluOpStatus_t MLUOP_WIN_API mluOpThreeInterpolateBackward( if (param_check != MLUOP_STATUS_SUCCESS) { return param_check; } - int64_t b = grad_output_desc->dims[0]; - int64_t c = grad_output_desc->dims[1]; - int64_t n = grad_output_desc->dims[2]; - int64_t m = grad_features_desc->dims[2]; + int64_t b = grad_output_desc->getDimIndex(0); + int64_t c = grad_output_desc->getDimIndex(1); + int64_t n = grad_output_desc->getDimIndex(2); + int64_t m = grad_features_desc->getDimIndex(2); if (MLUOP_GEN_CASE_ON_NEW) { GEN_CASE_START("three_interpolate_backward", "THREE_INTERPOLATE_BACKWARD"); @@ -552,7 +552,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpThreeInterpolateBackward( cnrtDim3_t k_dim; cnrtFunctionType_t k_type; int64_t input_size = sizeof(float); - if (grad_output_desc->dtype == MLUOP_DTYPE_HALF) { + if (grad_output_desc->getDtype() == MLUOP_DTYPE_HALF) { input_size /= 2; } int64_t c_limit_size = NFU_ALIGN_SIZE / input_size; @@ -566,7 +566,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpThreeInterpolateBackward( VLOG(5) << "Kernel KernelThreeInterpolateBackward"; CHECK_RETURN("[mluOpThreeInterpolateBackward]", KernelThreeInterpolateBackward( - k_dim, k_type, handle->queue, grad_output_desc->dtype, + k_dim, k_type, handle->queue, grad_output_desc->getDtype(), grad_output, indices, weights, b, c, m, n, c_limit_size, m_limit_size, n_limit_size, grad_features)); GEN_CASE_END(); diff --git a/kernels/three_nn_forward/three_nn_forward.cpp b/kernels/three_nn_forward/three_nn_forward.cpp index c74c64d71..a874e710d 100644 --- a/kernels/three_nn_forward/three_nn_forward.cpp +++ b/kernels/three_nn_forward/three_nn_forward.cpp @@ -40,10 +40,10 @@ mluOpStatus_t MLUOP_WIN_API mluOpGetThreeNNForwardWorkspaceSize( PARAM_CHECK("[mluOpThreeNNForwardWorkspace]", workspace_size != NULL); // check tensor dim - PARAM_CHECK("[mluOpThreeNNForwardWorkspace]", known_desc->dim == 3); + PARAM_CHECK("[mluOpThreeNNForwardWorkspace]", known_desc->getDim() == 3); - *workspace_size = known_desc->total_tensor_size; - const int known_dim = known_desc->dim; + *workspace_size = known_desc->getTotalTensorSize(); + const int known_dim = known_desc->getDim(); const int known_permute[3] = {0, 2, 1}; size_t known_transpose_workspace_size = 0; @@ -66,7 +66,7 @@ static mluOpStatus_t transposeTensor( const void *input, const int *permute, const mluOpTensorDescriptor_t workspace_dst_desc, void *workspace_dst, void *transpose_workspace, size_t transpose_workspace_size) { - const int input_dim = input_desc->dim; + const int input_dim = input_desc->getDim(); cnnlTransposeDescriptor_t cnnl_trans_desc = NULL; DEFINE_CREATE_AND_SET_CNNL_HANDLE(handle, cnnl_handle); @@ -99,47 +99,47 @@ static mluOpStatus_t threeNNParamCheck( PARAM_CHECK("[mluOpThreeNNForward]", idx_desc != NULL); // check tensor dim - PARAM_CHECK("[mluOpThreeNNForward]", unknown_desc->dim == 3); - PARAM_CHECK("[mluOpThreeNNForward]", known_desc->dim == 3); - PARAM_CHECK("[mluOpThreeNNForward]", dist2_desc->dim == 3); - PARAM_CHECK("[mluOpThreeNNForward]", idx_desc->dim == 3); + PARAM_CHECK("[mluOpThreeNNForward]", unknown_desc->getDim() == 3); + PARAM_CHECK("[mluOpThreeNNForward]", known_desc->getDim() == 3); + PARAM_CHECK("[mluOpThreeNNForward]", dist2_desc->getDim() == 3); + PARAM_CHECK("[mluOpThreeNNForward]", idx_desc->getDim() == 3); // check dim0 PARAM_CHECK("[mluOpThreeNNForward]", - unknown_desc->dims[0] == known_desc->dims[0]); + unknown_desc->getDimIndex(0) == known_desc->getDimIndex(0)); PARAM_CHECK("[mluOpThreeNNForward]", - unknown_desc->dims[0] == dist2_desc->dims[0]); + unknown_desc->getDimIndex(0) == dist2_desc->getDimIndex(0)); PARAM_CHECK("[mluOpThreeNNForward]", - unknown_desc->dims[0] == idx_desc->dims[0]); + unknown_desc->getDimIndex(0) == idx_desc->getDimIndex(0)); // check dim1 PARAM_CHECK("[mluOpThreeNNForward]", - unknown_desc->dims[1] == dist2_desc->dims[1]); + unknown_desc->getDimIndex(1) == dist2_desc->getDimIndex(1)); PARAM_CHECK("[mluOpThreeNNForward]", - unknown_desc->dims[1] == idx_desc->dims[1]); + unknown_desc->getDimIndex(1) == idx_desc->getDimIndex(1)); // check dim2 - PARAM_CHECK("[mluOpThreeNNForward]", unknown_desc->dims[2] == 3); - PARAM_CHECK("[mluOpThreeNNForward]", known_desc->dims[2] == 3); - PARAM_CHECK("[mluOpThreeNNForward]", dist2_desc->dims[2] == 3); - PARAM_CHECK("[mluOpThreeNNForward]", idx_desc->dims[2] == 3); + PARAM_CHECK("[mluOpThreeNNForward]", unknown_desc->getDimIndex(2) == 3); + PARAM_CHECK("[mluOpThreeNNForward]", known_desc->getDimIndex(2) == 3); + PARAM_CHECK("[mluOpThreeNNForward]", dist2_desc->getDimIndex(2) == 3); + PARAM_CHECK("[mluOpThreeNNForward]", idx_desc->getDimIndex(2) == 3); // check tensor datatype,support float16 and float32 PARAM_CHECK_V2("[mluOpThreeNNForward]", - (unknown_desc->dtype == MLUOP_DTYPE_HALF) || - (unknown_desc->dtype == MLUOP_DTYPE_FLOAT), + (unknown_desc->getDtype() == MLUOP_DTYPE_HALF) || + (unknown_desc->getDtype() == MLUOP_DTYPE_FLOAT), "Only half and float are supported in input unknown tensor, " "but the data type of tensor is " - << mluOpGetNameOfDataType(unknown_desc->dtype) << "."); + << mluOpGetNameOfDataType(unknown_desc->getDtype()) << "."); PARAM_CHECK("[mluOpThreeNNForward]", - unknown_desc->dtype == known_desc->dtype); + unknown_desc->getDtype() == known_desc->getDtype()); PARAM_CHECK("[mluOpThreeNNForward]", - unknown_desc->dtype == dist2_desc->dtype); + unknown_desc->getDtype() == dist2_desc->getDtype()); PARAM_CHECK_V2( - "[mluOpThreeNNForward]", (idx_desc->dtype == MLUOP_DTYPE_INT32), + "[mluOpThreeNNForward]", (idx_desc->getDtype() == MLUOP_DTYPE_INT32), "Only int32 are supported in output idx, but the data type of tensor is " - << mluOpGetNameOfDataType(idx_desc->dtype) << "."); + << mluOpGetNameOfDataType(idx_desc->getDtype()) << "."); const size_t unknown_element_num = mluOpGetTensorElementNum(unknown_desc); const size_t known_element_num = mluOpGetTensorElementNum(known_desc); @@ -205,9 +205,9 @@ mluOpStatus_t MLUOP_WIN_API mluOpThreeNNForward( return status_paramcheck; } - const int b = unknown_desc->dims[0]; - const int n = unknown_desc->dims[1]; - const int m = known_desc->dims[1]; + const int b = unknown_desc->getDimIndex(0); + const int n = unknown_desc->getDimIndex(1); + const int m = known_desc->getDimIndex(1); // generate mluOpThreeNNForward prototxt start! if (MLUOP_GEN_CASE_ON_NEW) { @@ -221,10 +221,10 @@ mluOpStatus_t MLUOP_WIN_API mluOpThreeNNForward( GEN_CASE_TEST_PARAM_NEW(true, true, false, 0.003, 0.003, 0); } - mluOpDataType_t input_dtype = unknown_desc->dtype; + mluOpDataType_t input_dtype = unknown_desc->getDtype(); void *known_workspace = workspace; void *transpose_workspace = - (int8_t *)known_workspace + known_desc->total_tensor_size; + (int8_t *)known_workspace + known_desc->getTotalTensorSize(); // start U1 task, occupy all available clusters cnrtDim3_t k_dims; @@ -235,12 +235,12 @@ mluOpStatus_t MLUOP_WIN_API mluOpThreeNNForward( VLOG(5) << "[mluOpThreeNNForward] cnnlTranspose_v2 feature start."; - const int known_dim = known_desc->dim; + const int known_dim = known_desc->getDim(); const int known_permute[3] = {0, 2, 1}; int known_tmp_dims[3] = {0, 0, 0}; for (int i = 0; i < known_dim; ++i) { - known_tmp_dims[i] = known_desc->dims[known_permute[i]]; + known_tmp_dims[i] = known_desc->getDimIndex(known_permute[i]); } mluOpTensorDescriptor_t known_desc_tmp = NULL; @@ -254,7 +254,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpThreeNNForward( "[mluOpThreeNNForward]", transposeTensor(handle, known_desc, known, known_permute, known_desc_tmp, known_workspace, transpose_workspace, - workspace_size - known_desc->total_tensor_size)); + workspace_size - known_desc->getTotalTensorSize())); CHECK_RETURN("[mluOpThreeNNForward]", mluOpDestroyTensorDescriptor(known_desc_tmp)); diff --git a/kernels/tin_shift/tin_shift.cpp b/kernels/tin_shift/tin_shift.cpp index 215d98186..7d490b90c 100644 --- a/kernels/tin_shift/tin_shift.cpp +++ b/kernels/tin_shift/tin_shift.cpp @@ -39,21 +39,21 @@ static void policyFunc(const mluOpHandle_t handle, const int32_t core_limit = mluop::runtime::getCoreNumOfEachUnionCapability(handle); const int core_num = core_limit * cluster_limit; - const size_t batch_size = input_desc->dims[0]; - const size_t time_size = input_desc->dims[1]; - const size_t channel_size = input_desc->dims[2]; - const size_t hw_size = input_desc->dims[3]; + const size_t batch_size = input_desc->getDimIndex(0); + const size_t time_size = input_desc->getDimIndex(1); + const size_t channel_size = input_desc->getDimIndex(2); + const size_t hw_size = input_desc->getDimIndex(3); const size_t size_per_channel = - time_size * hw_size * mluop::getSizeOfDataType(input_desc->dtype); + time_size * hw_size * mluop::getSizeOfDataType(input_desc->getDtype()); *channel_per_core = handle->nram_size / size_per_channel; int task_dim = 0; if (*channel_per_core == 0) { const size_t size_per_hw = - hw_size * mluop::getSizeOfDataType(input_desc->dtype); + hw_size * mluop::getSizeOfDataType(input_desc->getDtype()); *max_number_hw_per_core = handle->nram_size / size_per_hw; if (*max_number_hw_per_core <= 0) { *max_length_per_core = - handle->nram_size / mluop::getSizeOfDataType(input_desc->dtype); + handle->nram_size / mluop::getSizeOfDataType(input_desc->getDtype()); } int tmp_max_number_hw_per_core = *max_number_hw_per_core > 0 ? *max_number_hw_per_core : 1; @@ -78,18 +78,18 @@ static mluOpStatus_t TinShiftPreCheck( const std::string direction, const mluOpTensorDescriptor_t input_desc, const mluOpTensorDescriptor_t shifts_desc, const mluOpTensorDescriptor_t output_desc) { - int input_dims = input_desc->dim; - int output_dims = output_desc->dim; + int input_dims = input_desc->getDim(); + int output_dims = output_desc->getDim(); if (input_dims != 4) { LOG(ERROR) << "[mluOpTinShift " + direction + "] The input dims should be 4. " << "But now the input dims is " << input_dims << "."; return MLUOP_STATUS_BAD_PARAM; } - if (shifts_desc->dim != 2) { + if (shifts_desc->getDim() != 2) { LOG(ERROR) << "[mluOpTinShift " + direction + "] The shifts dims should be 2. " - << "But now the shifts dims is " << shifts_desc->dim << "."; + << "But now the shifts dims is " << shifts_desc->getDim() << "."; return MLUOP_STATUS_BAD_PARAM; } if (input_dims != output_dims) { @@ -99,8 +99,8 @@ static mluOpStatus_t TinShiftPreCheck( << ", and the output dims is " << output_dims << "."; return MLUOP_STATUS_BAD_PARAM; } - const int channel_size = input_desc->dims[2]; - const int group_size = shifts_desc->dims[1]; + const int channel_size = input_desc->getDimIndex(2); + const int group_size = shifts_desc->getDimIndex(1); if (channel_size == 0) { LOG(ERROR) << "[mluOpTinShift " + direction + "] " << "The channel size should not be zero."; @@ -119,47 +119,47 @@ static mluOpStatus_t TinShiftPreCheck( return MLUOP_STATUS_BAD_PARAM; } for (int i = 0; i < input_dims; i++) { - if (input_desc->dims[i] != output_desc->dims[i]) { + if (input_desc->getDimIndex(i) != output_desc->getDimIndex(i)) { LOG(ERROR) << "[mluOpTinShift " + direction + "] The size of input dims[" - << i << "] is " << input_desc->dims[i] + << i << "] is " << input_desc->getDimIndex(i) << ", and the size of output dims[" << i << "] is " - << output_desc->dims[i] << ". They should be the same."; + << output_desc->getDimIndex(i) << ". They should be the same."; return MLUOP_STATUS_BAD_PARAM; } } - if (input_desc->dims[0] != shifts_desc->dims[0]) { + if (input_desc->getDimIndex(0) != shifts_desc->getDimIndex(0)) { LOG(ERROR) << "[mluOpTinShift " + direction + "] " << "The input batch size should be the same as shifts's," - << " input batch size is " << input_desc->dims[0] - << " and shifts batch size is " << shifts_desc->dims[0] << "."; + << " input batch size is " << input_desc->getDimIndex(0) + << " and shifts batch size is " << shifts_desc->getDimIndex(0) << "."; return MLUOP_STATUS_BAD_PARAM; } const std::string api_ = "[mluOpTinShift " + direction + "]:"; STRIDE_TENSOR_CHECK(api_, input_desc, "input_desc must be contiguous"); STRIDE_TENSOR_CHECK(api_, shifts_desc, "shifts_desc must be contiguous"); STRIDE_TENSOR_CHECK(api_, output_desc, "output_desc must be contiguous"); - if (shifts_desc->dtype != MLUOP_DTYPE_INT32) { + if (shifts_desc->getDtype() != MLUOP_DTYPE_INT32) { LOG(ERROR) << "[mluOpTinShift " + direction + "] " << "The data type of the shift tensor should be MLUOP_DTYPE_INT32. " << "Current data type is " - << mluOpGetNameOfDataType(shifts_desc->dtype); + << mluOpGetNameOfDataType(shifts_desc->getDtype()); return MLUOP_STATUS_BAD_PARAM; } - if (input_desc->dtype != MLUOP_DTYPE_HALF && - input_desc->dtype != MLUOP_DTYPE_FLOAT) { + if (input_desc->getDtype() != MLUOP_DTYPE_HALF && + input_desc->getDtype() != MLUOP_DTYPE_FLOAT) { LOG(ERROR) << "[mluOpTinShift " + direction + "] " << "The data type of the input tensor should be half or float."; return MLUOP_STATUS_BAD_PARAM; } - if (input_desc->dtype != output_desc->dtype) { + if (input_desc->getDtype() != output_desc->getDtype()) { LOG(ERROR) << "[mluOpTinShift " + direction + "] " << "The data type of the input tensor and output tensor should " "be the same."; return MLUOP_STATUS_BAD_PARAM; } - const int input_batches_size = input_desc->dims[0]; - const int input_hw_size = input_desc->dims[3]; + const int input_batches_size = input_desc->getDimIndex(0); + const int input_hw_size = input_desc->getDimIndex(3); if (input_batches_size == 0) { LOG(ERROR) << "[mluOpTinShift " + direction + "] " << "The input batch size should not be zero."; @@ -196,7 +196,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpTinShiftForward( if (MLUOP_STATUS_SUCCESS != status) { return status; } - if (input_desc->dims[1] == 0) { + if (input_desc->getDimIndex(1) == 0) { return MLUOP_STATUS_SUCCESS; } PARAM_CHECK("[mluOpTinShift forward]", input != NULL); @@ -221,13 +221,13 @@ mluOpStatus_t MLUOP_WIN_API mluOpTinShiftForward( policyFunc(handle, input_desc, &k_dim, &k_type, &channel_per_core, &max_number_hw_per_core, &max_length_per_core); - const int batch_size = input_desc->dims[0]; - const int time_size = input_desc->dims[1]; - const int channel_size = input_desc->dims[2]; - const int hw_size = input_desc->dims[3]; - const int group_size = shifts_desc->dims[1]; + const int batch_size = input_desc->getDimIndex(0); + const int time_size = input_desc->getDimIndex(1); + const int channel_size = input_desc->getDimIndex(2); + const int hw_size = input_desc->getDimIndex(3); + const int group_size = shifts_desc->getDimIndex(1); int group_channel = channel_size / group_size; - mluOpDataType_t data_dtype = input_desc->dtype; + mluOpDataType_t data_dtype = input_desc->getDtype(); VLOG(5) << "batch_size: " << batch_size << " time_size: " << time_size << " channel_size: " << channel_size << " hw_size: " << hw_size << " group_channel: " << group_channel @@ -260,7 +260,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpTinShiftBackward( if (MLUOP_STATUS_SUCCESS != status) { return status; } - if (grad_output_desc->dims[1] == 0) { + if (grad_output_desc->getDimIndex(1) == 0) { return MLUOP_STATUS_SUCCESS; } PARAM_CHECK("[mluOpTinShift backward]", grad_output != NULL); @@ -286,13 +286,13 @@ mluOpStatus_t MLUOP_WIN_API mluOpTinShiftBackward( policyFunc(handle, grad_output_desc, &k_dim, &k_type, &channel_per_core, &max_number_hw_per_core, &max_length_per_core); - const int batch_size = grad_output_desc->dims[0]; - const int time_size = grad_output_desc->dims[1]; - const int channel_size = grad_output_desc->dims[2]; - const int hw_size = grad_output_desc->dims[3]; - const int group_size = shifts_desc->dims[1]; + const int batch_size = grad_output_desc->getDimIndex(0); + const int time_size = grad_output_desc->getDimIndex(1); + const int channel_size = grad_output_desc->getDimIndex(2); + const int hw_size = grad_output_desc->getDimIndex(3); + const int group_size = shifts_desc->getDimIndex(1); int group_channel = channel_size / group_size; - mluOpDataType_t data_dtype = grad_output_desc->dtype; + mluOpDataType_t data_dtype = grad_output_desc->getDtype(); VLOG(5) << "batch_size: " << batch_size << " time_size: " << time_size << " channel_size: " << channel_size << " hw_size: " << hw_size << " group_channel: " << group_channel diff --git a/kernels/unary_op/unary_op_host.cpp b/kernels/unary_op/unary_op_host.cpp index 2d7ba9c4d..4b1eb2e2c 100644 --- a/kernels/unary_op/unary_op_host.cpp +++ b/kernels/unary_op/unary_op_host.cpp @@ -43,7 +43,7 @@ void unaryOpPolicyFunc(mluOpHandle_t handle, cnrtDim3_t *k_dim, uint64_t core_in_cluster = handle->core_num_per_cluster; uint64_t core_number = union_number * core_in_cluster; uint64_t element_num = mluOpGetTensorElementNum(desc); - uint64_t tensor_size = element_num * mluop::getSizeOfDataType(desc->dtype); + uint64_t tensor_size = element_num * mluop::getSizeOfDataType(desc->getDtype()); tensor_size = CEIL_ALIGN(tensor_size, NFU_ALIGN_SIZE); uint64_t need_core = CEIL_ALIGN(tensor_size / NFU_ALIGN_SIZE, core_in_cluster); @@ -61,7 +61,7 @@ void unaryOpPolicyFunc(mluOpHandle_t handle, cnrtDim3_t *k_dim, void unaryOpPolicyFuncBlock(mluOpHandle_t handle, cnrtDim3_t *k_dim, cnrtFunctionType_t *k_type, mluOpTensorDescriptor_t desc) { - uint64_t data_size = desc->total_tensor_size; + uint64_t data_size = desc->getTotalTensorSize(); uint32_t core_dim = handle->core_num_per_cluster; uint32_t cluster_num = mluop::runtime::getClusterLimitCapability(handle); uint32_t core_num = core_dim * cluster_num; @@ -87,7 +87,7 @@ void unaryOpPolicyFuncBlock_v2(mluOpHandle_t handle, single_core_min_load_size = std::max(llc_pending_size, single_core_min_load_size); } - const size_t dtype_size = mluop::getSizeOfDataType(desc->dtype); + const size_t dtype_size = mluop::getSizeOfDataType(desc->getDtype()); const size_t aligned_num = DIV_UP(single_core_min_load_size, dtype_size); const size_t element_num = mluOpGetTensorElementNum(desc); const size_t core_number = @@ -132,22 +132,22 @@ mluOpStatus_t unaryOpParamCheck(std::string op_name, const mluOpHandle_t handle, PARAM_CHECK(op_name, y_desc != NULL); // check dim and dtype - PARAM_CHECK_EQ(op_name, x_desc->dtype, y_desc->dtype); - PARAM_CHECK_EQ(op_name, x_desc->dim, y_desc->dim); + PARAM_CHECK_EQ(op_name, x_desc->getDtype(), y_desc->getDtype()); + PARAM_CHECK_EQ(op_name, x_desc->getDim(), y_desc->getDim()); // check data type - if (!isSupportType(x_desc->dtype, support_type, len)) { + if (!isSupportType(x_desc->getDtype(), support_type, len)) { LOG(ERROR) << op_name << ":x_desc's data type is not supported."; return MLUOP_STATUS_BAD_PARAM; } - PARAM_CHECK_GT(op_name, x_desc->dim, 0); - PARAM_CHECK_GT(op_name, y_desc->dim, 0); - for (int i = 0; i < x_desc->dim; i++) { - if (x_desc->dims[i] != y_desc->dims[i]) { + PARAM_CHECK_GT(op_name, x_desc->getDim(), 0); + PARAM_CHECK_GT(op_name, y_desc->getDim(), 0); + for (int i = 0; i < x_desc->getDim(); i++) { + if (x_desc->getDimIndex(i) != y_desc->getDimIndex(i)) { LOG(ERROR) << op_name << ":The shape of x should be equal to y" << ". But now x_desc's shape[" << i << "] is " - << x_desc->dims[i] << ", y_desc's shape[" << i << "] is " - << y_desc->dims[i] << "."; + << x_desc->getDimIndex(i) << ", y_desc's shape[" << i << "] is " + << y_desc->getDimIndex(i) << "."; return MLUOP_STATUS_BAD_PARAM; } } @@ -164,7 +164,7 @@ mluOpStatus_t unaryOpParamCheck(std::string op_name, const mluOpHandle_t handle, "input tensor num is too large. "); } if (needStrideProcess(x_desc, y_desc)) { - PARAM_CHECK(op_name, x_desc->dim <= MLUOP_DIM_MAX); + PARAM_CHECK(op_name, x_desc->getDim() <= MLUOP_DIM_MAX); if (handle->arch < MLUOP_MLU590) { // num_with_stride affects offset (related with mul op, which cannot // exceed 32-bit on MLU300) diff --git a/kernels/voxel_pooling_forward/voxel_pooling_forward.cpp b/kernels/voxel_pooling_forward/voxel_pooling_forward.cpp index e9c33167f..ee58c4db3 100644 --- a/kernels/voxel_pooling_forward/voxel_pooling_forward.cpp +++ b/kernels/voxel_pooling_forward/voxel_pooling_forward.cpp @@ -61,28 +61,28 @@ mluOpStatus_t VoxelPoolingForwardParamCheck( PARAM_CHECK(op_name, output_features_desc != NULL); PARAM_CHECK(op_name, pos_memo_desc != NULL); // check data type - PARAM_CHECK(op_name, geom_xyz_desc->dtype == MLUOP_DTYPE_INT32); - PARAM_CHECK(op_name, input_features_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(op_name, output_features_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(op_name, pos_memo_desc->dtype == MLUOP_DTYPE_INT32); + PARAM_CHECK(op_name, geom_xyz_desc->getDtype() == MLUOP_DTYPE_INT32); + PARAM_CHECK(op_name, input_features_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(op_name, output_features_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(op_name, pos_memo_desc->getDtype() == MLUOP_DTYPE_INT32); // check tensor dims and shape - PARAM_CHECK(op_name, geom_xyz_desc->dim == 3); - PARAM_CHECK(op_name, input_features_desc->dim == 3); - PARAM_CHECK(op_name, output_features_desc->dim == 4); - PARAM_CHECK(op_name, pos_memo_desc->dim == 3); - PARAM_CHECK(op_name, geom_xyz_desc->dims[0] == batch_size); - PARAM_CHECK(op_name, geom_xyz_desc->dims[1] == num_points); - PARAM_CHECK(op_name, geom_xyz_desc->dims[2] == 3); - PARAM_CHECK(op_name, input_features_desc->dims[0] == batch_size); - PARAM_CHECK(op_name, input_features_desc->dims[1] == num_points); - PARAM_CHECK(op_name, input_features_desc->dims[2] == num_channels); - PARAM_CHECK(op_name, output_features_desc->dims[0] == batch_size); - PARAM_CHECK(op_name, output_features_desc->dims[1] == num_voxel_y); - PARAM_CHECK(op_name, output_features_desc->dims[2] == num_voxel_x); - PARAM_CHECK(op_name, output_features_desc->dims[3] == num_channels); - PARAM_CHECK(op_name, pos_memo_desc->dims[0] == batch_size); - PARAM_CHECK(op_name, pos_memo_desc->dims[1] == num_points); - PARAM_CHECK(op_name, pos_memo_desc->dims[2] == 3); + PARAM_CHECK(op_name, geom_xyz_desc->getDim() == 3); + PARAM_CHECK(op_name, input_features_desc->getDim() == 3); + PARAM_CHECK(op_name, output_features_desc->getDim() == 4); + PARAM_CHECK(op_name, pos_memo_desc->getDim() == 3); + PARAM_CHECK(op_name, geom_xyz_desc->getDimIndex(0) == batch_size); + PARAM_CHECK(op_name, geom_xyz_desc->getDimIndex(1) == num_points); + PARAM_CHECK(op_name, geom_xyz_desc->getDimIndex(2) == 3); + PARAM_CHECK(op_name, input_features_desc->getDimIndex(0) == batch_size); + PARAM_CHECK(op_name, input_features_desc->getDimIndex(1) == num_points); + PARAM_CHECK(op_name, input_features_desc->getDimIndex(2) == num_channels); + PARAM_CHECK(op_name, output_features_desc->getDimIndex(0) == batch_size); + PARAM_CHECK(op_name, output_features_desc->getDimIndex(1) == num_voxel_y); + PARAM_CHECK(op_name, output_features_desc->getDimIndex(2) == num_voxel_x); + PARAM_CHECK(op_name, output_features_desc->getDimIndex(3) == num_channels); + PARAM_CHECK(op_name, pos_memo_desc->getDimIndex(0) == batch_size); + PARAM_CHECK(op_name, pos_memo_desc->getDimIndex(1) == num_points); + PARAM_CHECK(op_name, pos_memo_desc->getDimIndex(2) == 3); // check dim prams PARAM_CHECK(op_name, batch_size > 0); PARAM_CHECK(op_name, num_points > 0); diff --git a/kernels/voxelization/voxelization.cpp b/kernels/voxelization/voxelization.cpp index 6812bb894..94a3d062f 100644 --- a/kernels/voxelization/voxelization.cpp +++ b/kernels/voxelization/voxelization.cpp @@ -72,30 +72,30 @@ mluOpStatus_t voxelizationParamCheck( if (deterministic == true) { // check tensor shape // params points: [num_points, num_features] - PARAM_CHECK_EQ("[mluOpVoxelization]", points_desc->dim, 2); + PARAM_CHECK_EQ("[mluOpVoxelization]", points_desc->getDim(), 2); // params voxel_size: [3] - PARAM_CHECK_EQ("[mluOpVoxelization]", voxel_size_desc->dim, 1); - PARAM_CHECK_EQ("[mluOpVoxelization]", voxel_size_desc->dims[0], 3); + PARAM_CHECK_EQ("[mluOpVoxelization]", voxel_size_desc->getDim(), 1); + PARAM_CHECK_EQ("[mluOpVoxelization]", voxel_size_desc->getDimIndex(0), 3); // params coors_range: [6] - PARAM_CHECK_EQ("[mluOpVoxelization]", coors_range_desc->dim, 1); - PARAM_CHECK_EQ("[mluOpVoxelization]", coors_range_desc->dims[0], 6); + PARAM_CHECK_EQ("[mluOpVoxelization]", coors_range_desc->getDim(), 1); + PARAM_CHECK_EQ("[mluOpVoxelization]", coors_range_desc->getDimIndex(0), 6); // params voxels: [max_voxels, max_points, num_features] - PARAM_CHECK_EQ("[mluOpVoxelization]", voxels_desc->dim, 3); - PARAM_CHECK_EQ("[mluOpVoxelization]", voxels_desc->dims[0], max_voxels); - PARAM_CHECK_EQ("[mluOpVoxelization]", voxels_desc->dims[1], max_points); - PARAM_CHECK_EQ("[mluOpVoxelization]", voxels_desc->dims[2], - points_desc->dims[1]); + PARAM_CHECK_EQ("[mluOpVoxelization]", voxels_desc->getDim(), 3); + PARAM_CHECK_EQ("[mluOpVoxelization]", voxels_desc->getDimIndex(0), max_voxels); + PARAM_CHECK_EQ("[mluOpVoxelization]", voxels_desc->getDimIndex(1), max_points); + PARAM_CHECK_EQ("[mluOpVoxelization]", voxels_desc->getDimIndex(2), + points_desc->getDimIndex(1)); // params coors: [max_voxels, 3] - PARAM_CHECK_EQ("[mluOpVoxelization]", coors_desc->dim, 2); - PARAM_CHECK_EQ("[mluOpVoxelization]", coors_desc->dims[0], max_voxels); - PARAM_CHECK_EQ("[mluOpVoxelization]", coors_desc->dims[1], 3); + PARAM_CHECK_EQ("[mluOpVoxelization]", coors_desc->getDim(), 2); + PARAM_CHECK_EQ("[mluOpVoxelization]", coors_desc->getDimIndex(0), max_voxels); + PARAM_CHECK_EQ("[mluOpVoxelization]", coors_desc->getDimIndex(1), 3); // params num_points_per_voxel: [max_voxels] - PARAM_CHECK_EQ("[mluOpVoxelization]", num_points_per_voxel_desc->dim, 1); - PARAM_CHECK_EQ("[mluOpVoxelization]", num_points_per_voxel_desc->dims[0], + PARAM_CHECK_EQ("[mluOpVoxelization]", num_points_per_voxel_desc->getDim(), 1); + PARAM_CHECK_EQ("[mluOpVoxelization]", num_points_per_voxel_desc->getDimIndex(0), max_voxels); // params voxel_num: [1] - PARAM_CHECK_EQ("[mluOpVoxelization]", voxel_num_desc->dim, 1); - PARAM_CHECK_EQ("[mluOpVoxelization]", voxel_num_desc->dims[0], 1); + PARAM_CHECK_EQ("[mluOpVoxelization]", voxel_num_desc->getDim(), 1); + PARAM_CHECK_EQ("[mluOpVoxelization]", voxel_num_desc->getDimIndex(0), 1); // check params PARAM_CHECK_EQ("[mluOpVoxelization]", NDim, 3); @@ -117,17 +117,17 @@ mluOpStatus_t voxelizationParamCheck( "voxel_num_desc must be contiguous"); // check tensor datatype - PARAM_CHECK("[mluOpVoxelization]", points_desc->dtype == MLUOP_DTYPE_FLOAT); + PARAM_CHECK("[mluOpVoxelization]", points_desc->getDtype() == MLUOP_DTYPE_FLOAT); PARAM_CHECK("[mluOpVoxelization]", - voxel_size_desc->dtype == MLUOP_DTYPE_FLOAT); + voxel_size_desc->getDtype() == MLUOP_DTYPE_FLOAT); PARAM_CHECK("[mluOpVoxelization]", - coors_range_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK("[mluOpVoxelization]", voxels_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK("[mluOpVoxelization]", coors_desc->dtype == MLUOP_DTYPE_INT32); + coors_range_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK("[mluOpVoxelization]", voxels_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK("[mluOpVoxelization]", coors_desc->getDtype() == MLUOP_DTYPE_INT32); PARAM_CHECK("[mluOpVoxelization]", - num_points_per_voxel_desc->dtype == MLUOP_DTYPE_INT32); + num_points_per_voxel_desc->getDtype() == MLUOP_DTYPE_INT32); PARAM_CHECK("[mluOpVoxelization]", - voxel_num_desc->dtype == MLUOP_DTYPE_INT32); + voxel_num_desc->getDtype() == MLUOP_DTYPE_INT32); size_t points_element_num = mluOpGetTensorElementNum(points_desc); size_t voxel_size_element_num = mluOpGetTensorElementNum(voxel_size_desc); @@ -206,8 +206,8 @@ mluOpStatus_t MLUOP_WIN_API mluOpGetVoxelizationWorkspaceSize( return MLUOP_STATUS_SUCCESS; } - const size_t num_points = points_desc->dims[0]; - const size_t num_features = points_desc->dims[1]; + const size_t num_points = points_desc->getDimIndex(0); + const size_t num_features = points_desc->getDimIndex(1); const size_t temp_coors_size = 3 * num_points * sizeof(int32_t); const size_t point_to_pointidx_size = num_points * sizeof(int32_t); const size_t point_to_voxelidx_size = num_points * sizeof(int32_t); @@ -277,8 +277,8 @@ mluOpStatus_t MLUOP_WIN_API mluOpVoxelization( GEN_CASE_TEST_PARAM_NEW(false, false, true, 0, 0, 0); } - const size_t num_points = points_desc->dims[0]; - const size_t num_features = points_desc->dims[1]; + const size_t num_points = points_desc->getDimIndex(0); + const size_t num_features = points_desc->getDimIndex(1); // temp_coors : [3, num_points] void *temp_coors = workspace; diff --git a/kernels/yolo_box/yolo_box.cpp b/kernels/yolo_box/yolo_box.cpp index 7d1c6d986..6644cef5b 100644 --- a/kernels/yolo_box/yolo_box.cpp +++ b/kernels/yolo_box/yolo_box.cpp @@ -66,18 +66,18 @@ static mluOpStatus_t yoloBoxParamCheck( PARAM_CHECK(op_name, scores_desc != NULL); // check shape - PARAM_CHECK(op_name, x_desc->dim == 4); - PARAM_CHECK(op_name, img_size_desc->dim == 2); - PARAM_CHECK(op_name, anchors_desc->dim == 1); - PARAM_CHECK(op_name, boxes_desc->dim == 4); - PARAM_CHECK(op_name, scores_desc->dim == 4); + PARAM_CHECK(op_name, x_desc->getDim() == 4); + PARAM_CHECK(op_name, img_size_desc->getDim() == 2); + PARAM_CHECK(op_name, anchors_desc->getDim() == 1); + PARAM_CHECK(op_name, boxes_desc->getDim() == 4); + PARAM_CHECK(op_name, scores_desc->getDim() == 4); // check data type - PARAM_CHECK(op_name, x_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(op_name, img_size_desc->dtype == MLUOP_DTYPE_INT32); - PARAM_CHECK(op_name, anchors_desc->dtype == MLUOP_DTYPE_INT32); - PARAM_CHECK(op_name, boxes_desc->dtype == MLUOP_DTYPE_FLOAT); - PARAM_CHECK(op_name, scores_desc->dtype == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(op_name, x_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(op_name, img_size_desc->getDtype() == MLUOP_DTYPE_INT32); + PARAM_CHECK(op_name, anchors_desc->getDtype() == MLUOP_DTYPE_INT32); + PARAM_CHECK(op_name, boxes_desc->getDtype() == MLUOP_DTYPE_FLOAT); + PARAM_CHECK(op_name, scores_desc->getDtype() == MLUOP_DTYPE_FLOAT); // check param except tensor if (iou_aware) { @@ -89,13 +89,13 @@ static mluOpStatus_t yoloBoxParamCheck( } // check dim - PARAM_CHECK(op_name, (x_desc->dims[0] == img_size_desc->dims[0])); - PARAM_CHECK(op_name, (x_desc->dims[0] == boxes_desc->dims[0])); - PARAM_CHECK(op_name, (x_desc->dims[0] == scores_desc->dims[0])); + PARAM_CHECK(op_name, (x_desc->getDimIndex(0) == img_size_desc->getDimIndex(0))); + PARAM_CHECK(op_name, (x_desc->getDimIndex(0) == boxes_desc->getDimIndex(0))); + PARAM_CHECK(op_name, (x_desc->getDimIndex(0) == scores_desc->getDimIndex(0))); - const int anchors_num = anchors_desc->dims[0] / 2; - std::string anchors_num_str = "anchors_num = anchors_desc->dims[0] / 2."; - PARAM_CHECK(op_name, (anchors_desc->dims[0] % 2 == 0)); + const int anchors_num = anchors_desc->getDimIndex(0) / 2; + std::string anchors_num_str = "anchors_num = anchors_desc->getDimIndex(0) / 2."; + PARAM_CHECK(op_name, (anchors_desc->getDimIndex(0) % 2 == 0)); PARAM_CHECK_V2(op_name, anchors_num > 0, << anchors_num_str); PARAM_CHECK(op_name, class_num > 0); @@ -106,18 +106,18 @@ static mluOpStatus_t yoloBoxParamCheck( const int dim_c = iou_aware ? anchors_num * (6 + class_num) : anchors_num * (5 + class_num); - PARAM_CHECK(op_name, (x_desc->dims[1] == dim_c)); - PARAM_CHECK(op_name, (img_size_desc->dims[1] == 2)); - PARAM_CHECK_V2(op_name, (boxes_desc->dims[1] == anchors_num), + PARAM_CHECK(op_name, (x_desc->getDimIndex(1) == dim_c)); + PARAM_CHECK(op_name, (img_size_desc->getDimIndex(1) == 2)); + PARAM_CHECK_V2(op_name, (boxes_desc->getDimIndex(1) == anchors_num), << anchors_num_str); - PARAM_CHECK(op_name, (boxes_desc->dims[2] == 4)); + PARAM_CHECK(op_name, (boxes_desc->getDimIndex(2) == 4)); PARAM_CHECK(op_name, - (boxes_desc->dims[3] == (x_desc->dims[2] * x_desc->dims[3]))); - PARAM_CHECK_V2(op_name, (scores_desc->dims[1] == anchors_num), + (boxes_desc->getDimIndex(3) == (x_desc->getDimIndex(2) * x_desc->getDimIndex(3)))); + PARAM_CHECK_V2(op_name, (scores_desc->getDimIndex(1) == anchors_num), << anchors_num_str); - PARAM_CHECK(op_name, (scores_desc->dims[2] == class_num)); + PARAM_CHECK(op_name, (scores_desc->getDimIndex(2) == class_num)); PARAM_CHECK(op_name, - (scores_desc->dims[3] == (x_desc->dims[2] * x_desc->dims[3]))); + (scores_desc->getDimIndex(3) == (x_desc->getDimIndex(2) * x_desc->getDimIndex(3)))); // large tensor if ((mluOpGetTensorElementNum(x_desc) >= LARGE_TENSOR_NUM) || @@ -199,11 +199,11 @@ mluOpStatus_t MLUOP_WIN_API mluOpYoloBox( GEN_CASE_TEST_PARAM_NEW(true, true, false, 0.003, 0.003, 0); } - const int n_in = x_desc->dims[0]; - const int c_in = x_desc->dims[1]; - const int h_in = x_desc->dims[2]; - const int w_in = x_desc->dims[3]; - const int anchor_s = anchors_desc->dims[0] / 2; + const int n_in = x_desc->getDimIndex(0); + const int c_in = x_desc->getDimIndex(1); + const int h_in = x_desc->getDimIndex(2); + const int w_in = x_desc->getDimIndex(3); + const int anchor_s = anchors_desc->getDimIndex(0) / 2; const int kw_num = h_in * w_in; cnrtDim3_t k_dim;