Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature](mluOpTest): access variable in tensor struct through function in mlu_op_gtest #1152

Merged
merged 4 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ 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;
}
PARAM_CHECK("[cnnlTransposeCpu]", x != NULL);
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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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(
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
56 changes: 28 additions & 28 deletions test/mlu_op_gtest/pb_gtest/src/zoo/dcn_forward/dcn_forward.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Loading