Skip to content

Commit

Permalink
[Feature](bangc-ops) add platform check (Cambricon#450)
Browse files Browse the repository at this point in the history
Co-authored-by: dujun <[email protected]>
  • Loading branch information
Devin-D-U and dujun authored Feb 23, 2023
1 parent 877c1c9 commit c42e26d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
29 changes: 20 additions & 9 deletions bangc-ops/kernels/get_indice_pairs/get_indice_pairs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ static mluOpStatus_t internalGetIndicePairs(
PARAM_CHECK(interface_name, indice_pairs_desc != NULL);
PARAM_CHECK(interface_name, out_indices_desc != NULL);
PARAM_CHECK(interface_name, indice_num_desc != NULL);

// check platform
if (handle->arch < 372) {
LOG(ERROR) << interface_name
<< " Only mlu300 and above devices are supported."
<< " Please check the device version!";
return MLUOP_STATUS_ARCH_MISMATCH;
}

// sparse_conv_desc dimNb check
int sparse_conv_dimNb = sparse_conv_desc->dimNb;

Expand All @@ -100,10 +109,11 @@ static mluOpStatus_t internalGetIndicePairs(
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);

// check shape
PARAM_CHECK(interface_name,
indice_pairs_desc->dims[2] == indices_desc->dims[0]);
PARAM_CHECK(interface_name,
Expand All @@ -119,7 +129,6 @@ static mluOpStatus_t internalGetIndicePairs(
input_spaces *= sparse_conv_desc->input_space[i];
}
PARAM_CHECK_LE(interface_name, indices_desc->dims[0], input_spaces);

for (int i = 0; i < sparse_conv_dimNb - 2; i++) {
PARAM_CHECK_GE(interface_name, sparse_conv_desc->pad[i], 0);
PARAM_CHECK_GE(interface_name, sparse_conv_desc->dilation[i], 1);
Expand All @@ -129,6 +138,9 @@ static mluOpStatus_t internalGetIndicePairs(
return MLUOP_STATUS_BAD_PARAM;
}
}
PARAM_CHECK(interface_name, indice_pairs_desc->dims[0] == kernel_volume);
PARAM_CHECK_LE(interface_name, kernel_volume, 4096);
PARAM_CHECK_LE(interface_name, out_indices_desc->dims[0], output_spaces);

// large tensor
if (mluOpGetTensorElementNum(indices_desc) >= LARGE_TENSOR_NUM ||
Expand All @@ -140,9 +152,6 @@ static mluOpStatus_t internalGetIndicePairs(
return MLUOP_STATUS_NOT_SUPPORTED;
}

PARAM_CHECK(interface_name, indice_pairs_desc->dims[0] == kernel_volume);
PARAM_CHECK_LE(interface_name, kernel_volume, 4096);
PARAM_CHECK_LE(interface_name, out_indices_desc->dims[0], output_spaces);
// 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);
Expand All @@ -158,13 +167,17 @@ static mluOpStatus_t internalGetIndicePairs(
PARAM_CHECK_EQ(interface_name, sparse_conv_desc->dilation[i], 1);
}
}

// check zero elment
if (mluOpGetTensorElementNum(indices_desc) == 0 ||
mluOpGetTensorElementNum(indice_pairs_desc) == 0 ||
mluOpGetTensorElementNum(out_indices_desc) == 0 ||
mluOpGetTensorElementNum(indice_num_desc) == 0) {
sparse_conv_desc->num_act_out = 0;
return MLUOP_STATUS_SUCCESS;
}

// check nullptr
if (!is_get_workspace) {
PARAM_CHECK(interface_name, indices != NULL);
PARAM_CHECK(interface_name, indice_pairs != NULL);
Expand Down Expand Up @@ -196,8 +209,7 @@ static mluOpStatus_t internalGetIndicePairs(
}

mluOpStatus_t MLUOP_WIN_API mluOpGetIndicePairs(
mluOpHandle_t handle,
mluOpSparseConvolutionDescriptor_t sparse_conv_desc,
mluOpHandle_t handle, mluOpSparseConvolutionDescriptor_t sparse_conv_desc,
const mluOpTensorDescriptor_t indices_desc, const void *indices,
void *workspace, const size_t workspace_size,
const mluOpTensorDescriptor_t indice_pairs_desc, void *indice_pairs,
Expand All @@ -211,8 +223,7 @@ mluOpStatus_t MLUOP_WIN_API mluOpGetIndicePairs(
}

mluOpStatus_t MLUOP_WIN_API mluOpGetIndicePairsWorkspaceSize(
mluOpHandle_t handle,
mluOpSparseConvolutionDescriptor_t sparse_conv_desc,
mluOpHandle_t handle, mluOpSparseConvolutionDescriptor_t sparse_conv_desc,
const mluOpTensorDescriptor_t indices_desc,
const mluOpTensorDescriptor_t indice_pairs_desc,
const mluOpTensorDescriptor_t out_indices_desc,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ static mluOpStatus_t baseParamCheck(
PARAM_CHECK(api_name, inverse == 0);

// check mlu platform
if (handle->arch != MLUOP_MLU370 && handle->arch != MLUOP_MLU590) {
if (handle->arch < 372) {
LOG(ERROR) << api_name << " Only mlu300 and above devices are supported."
<< " Please check the device version!";
return MLUOP_STATUS_ARCH_MISMATCH;
Expand Down

0 comments on commit c42e26d

Please sign in to comment.