| 105 | } |
| 106 | |
| 107 | mluOpStatus_t binaryOpParamCheck( |
| 108 | const std::string &op_name, const mluOpHandle_t handle, |
| 109 | const mluOpTensorDescriptor_t input1_desc, const void *input1, |
| 110 | const mluOpTensorDescriptor_t input2_desc, const void *input2, |
| 111 | const mluOpTensorDescriptor_t output_desc, const void *output, |
| 112 | const mluOpDataType_t support_type[], const int len, bool &zero_element, |
| 113 | bool isSupportBroadcast) { |
| 114 | // check descriptor |
| 115 | PARAM_CHECK(op_name, handle != NULL); |
| 116 | PARAM_CHECK(op_name, input1_desc != NULL); |
| 117 | PARAM_CHECK(op_name, input2_desc != NULL); |
| 118 | PARAM_CHECK(op_name, output_desc != NULL); |
| 119 | |
| 120 | // check dtype equal |
| 121 | PARAM_CHECK_EQ(op_name, input1_desc->getDtype(), input2_desc->getDtype()); |
| 122 | PARAM_CHECK_EQ(op_name, input1_desc->getDtype(), output_desc->getDtype()); |
| 123 | |
| 124 | // check dim less than MLUOP_DIM_MAX |
| 125 | PARAM_CHECK_LE(op_name, input1_desc->getDim(), MLUOP_DIM_MAX); |
| 126 | PARAM_CHECK_LE(op_name, input2_desc->getDim(), MLUOP_DIM_MAX); |
| 127 | PARAM_CHECK_LE(op_name, output_desc->getDim(), MLUOP_DIM_MAX); |
| 128 | PARAM_CHECK_GT(op_name, input1_desc->getDim(), 0); |
| 129 | PARAM_CHECK_GT(op_name, input2_desc->getDim(), 0); |
| 130 | PARAM_CHECK_GT(op_name, output_desc->getDim(), 0); |
| 131 | |
| 132 | // check data type support |
| 133 | if (!isSupportType(input1_desc->getDtype(), support_type, len)) { |
| 134 | LOG(ERROR) << op_name << ":input1_desc's data type is not supported."; |
| 135 | return MLUOP_STATUS_BAD_PARAM; |
| 136 | } |
| 137 | |
| 138 | if (isSupportBroadcast) { |
| 139 | int32_t left_dim_num = input1_desc->getDim(); |
| 140 | int32_t right_dim_num = input2_desc->getDim(); |
| 141 | int32_t max_dim = std::max(left_dim_num, right_dim_num); |
| 142 | std::vector<int> left_aligned_dims( |
| 143 | input1_desc->getDims(), input1_desc->getDims() + input1_desc->getDim()); |
| 144 | std::vector<int> right_aligned_dims( |
| 145 | input2_desc->getDims(), input2_desc->getDims() + input2_desc->getDim()); |
| 146 | |
| 147 | // aligning dimensions to max_dim |
| 148 | if (left_dim_num < max_dim) { |
| 149 | left_aligned_dims.insert(left_aligned_dims.begin(), |
| 150 | max_dim - left_dim_num, 1); |
| 151 | } |
| 152 | |
| 153 | if (right_dim_num < max_dim) { |
| 154 | right_aligned_dims.insert(right_aligned_dims.begin(), |
| 155 | max_dim - right_dim_num, 1); |
| 156 | } |
| 157 | |
| 158 | if (output_desc->getDim() != max_dim) { |
| 159 | LOG(ERROR) |
| 160 | << op_name |
| 161 | << " The dimension size of the output tensors does not meet the " |
| 162 | "requirements of broadcast."; |
| 163 | return MLUOP_STATUS_BAD_PARAM; |
| 164 | } |
no test coverage detected