BroadcastOpUT
Overview
Inherits the capabilities of OpUT.
BroadcastOpUT defines test cases for Broadcast operators with dual inputs and single output, for example, the Add and Mul operators. It also provides more convenient APIs for these operators. For example, when creating the test case file for operator build, you do not need to set the format in some simple scenarios.
Definition of the BroadcastOpUT Test Class
- Prototype
BroadcastOpUT(op_type, op_module_name=None, op_func_name=None)
- Parameters
- op_type: operator type.
- op_module_name: operator module name, that is, the name and path of the operator implementation file, for example, impl.add (the file path is impl/add.py). The default value is None. The argument is generated automatically based on op_type. For example, for a BiasAdd operator, the generated module name is impl.bias_add. For details about how the argument of op_module_name is generated based on op_type, see 4.
- op_func_name: operator function name in the operator implementation file. The default value is None. The argument is generated automatically based on op_type. For details about how the argument of op_func_name is generated based on op_type, see 4. For example, for an Add operator, the corresponding API must exist in impl/add.py. The API definition is as follows:
@check_op_params(REQUIRED_INPUT, REQUIRED_INPUT, REQUIRED_OUTPUT, KERNEL_NAME) def add(input_x, input_y, output_z, kernel_name="add"):
add_broadcast_case
- Prototype
BroadcastOpUT.add_broadcast_case(self, soc, input_1_info, input_2_info, output_info=None,expect=op_status.SUCCESS, case_name=None)
- Description
Adds test cases for operator build, tests whether an operator meets the related specifications, and builds an .o file.
- Parameters
- soc: used to test whether the test case file supports the Ascend AI Processor. The value is the name of the corresponding .ini file in the compiler/data/platform_config directory. support_soc can be a string or a tuple or list of strings (indicating multiple SoCs are supported). If this parameter is set to all or None, all SoCs are supported.
- input_1_info: information about the first input of the operator, coming in either of the following format:
- [dtype, shape, format, ori_shape, ori_format]
- [dtype, shape, format]: In this format, the values of ori_shape and ori_format are the same as those of shape and format.
- input_2_info: information about the second input of the operator, with the same information of input_1_info.
- output_info: defaults to None. This parameter does not need to be set.
- expect: expected build result. Defaults to op_status.SUCCESS. It can also be set to RuntimeError, indicating an expected exception.
- case_name: defaults to None. The test framework automatically generates the argument of case_name.
Example
ut_case.add_broadcast_case("all", ["float16", (32, 32), "ND"], ["float16", (32, 32), "ND"]) ut_case.add_broadcast_case("all", ["float16", (32, 32), "ND", (32, 32), "ND"], ["float16", (32, 32), "ND", (32, 32), "ND"]) # Expected exception UT case ut_case.add_broadcast_case("all", ["float16", (31, 32), "ND"], ["float16", (32, 32), "ND"], expect=RuntimeError)
add_broadcast_case_simple
- Prototype
BroadcastOpUT.add_broadcast_case_simple(self, soc, dtypes, shape1, shape2, expect=op_status.SUCCESS, case_name=None)
- Description
Adds test cases for operator build, tests whether an operator meets the related specifications, and builds an .o file. This API is simpler than add_broadcast_case.
- Parameters
- soc: used to test whether the test case file supports the Ascend AI Processor. The value is the name of the corresponding .ini file in the Ascend-CANN-Toolkit installation directory/ascend-toolkit/latest/compiler/data/platform_config directory. support_soc can be a string or a tuple or list of strings (indicating multiple SoCs are supported). If this parameter is set to all or None, all SoCs are supported.
- dtypes: types of the data to be tested. If multiple data types are set, multiple test cases are added at a time.
- shape1: shape of the first input of the operator.
- shape2: shape of the second input of the operator.
- expect: expected build result. Defaults to op_status.SUCCESS. It can also be set to RuntimeError, indicating an expected exception.
- case_name: defaults to None. The test framework automatically generates the argument of case_name.
Compared with the add_broadcast_case API, this API sets the formats of all inputs to ND.
Example
ut_case.add_broadcast_case_simple(["Ascendxxx", "Ascendxxx"], ["float16", "float32"], (32, 32), (32, 32))
The preceding test case implements the same function as calling the add_case API.
ut_case.add_case(support_soc=["Ascendxxx", "Ascendxxx"], case={ "params": [{ "shape": (32, 32), "ori_shape": (32, 32), "format": "ND", "ori_format": "ND", "dtype": "float16" }, { "shape": (32, 32), "ori_shape": (32, 32), "format": "ND", "ori_format": "ND", "dtype": "float16" }, { "shape": (32, 32), "ori_shape": (32, 32), "format": "ND", "ori_format": "ND", "dtype": "float16" }] }) ut_case.add_case(support_soc=["Ascendxxx", "Ascendxxx"], case={ "params": [{ "shape": (32, 32), "ori_shape": (32, 32), "format": "ND", "ori_format": "ND", "dtype": "float32" }, { "shape": (32, 32), "ori_shape": (32, 32), "format": "ND", "ori_format": "ND", "dtype": "float32" }, { "shape": (32, 32), "ori_shape": (32, 32), "format": "ND", "ori_format": "ND", "dtype": "float32" }] })