ReduceOpUT
Overview
Inherits the capabilities of OpUT.
ReduceOpUT defines test cases for Reduce operators, for example, the ReduceSum and ReduceMean 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 ReduceOpUT Test Class
- Prototype
- 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 ReduceSum operator, the generated module name is impl.reduce_sum. 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_reduce_case
- Prototype
ReduceOpUT.add_reduce_case(self, soc, input_info, axes, keep_dim=False, 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 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.
- input_info: information about the operator input, 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.
- axes: dimensions to reduce.
- keep_dims: If True, retains reduced dimensions with length 1. Either True or False.
- 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_reduce_case("Ascend910", ["float16", (32, 32), "ND"], [0,], False)The preceding test case implements the same function as calling the add_case API.
ut_case.add_case(support_soc="Ascend910", case={ "params": [{ "shape": (32, 32), "ori_shape": (32, 32), "format": "ND", "ori_format": "ND", "dtype": "float16" }, { "shape": (32,), "ori_shape": (32,), "format": "ND", "ori_format": "ND", "dtype": "float16" }, [0,], False] })
add_reduce_case_simple
- Prototype
ReduceOpUT.add_reduce_case_simple(self, soc, dtypes, shape, axes, keep_dim=False, 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 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.
- shape: shape of the operator input.
- axes: dimensions to reduce.
- keep_dims: If True, retains reduced dimensions with length 1. Either True or False.
- 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_reduce_case API, this API sets the formats of all inputs to ND.
Example
ut_case.add_reduce_case_simple("Ascend910", ["float16", "float32"], [32, 32], [1,], True)The preceding test case implements the same function as calling the add_case API.
ut_case.add_case(support_soc="Ascend910", case={ "params": [{ "shape": (32, 32), "ori_shape": (32, 32), "format": "ND", "ori_format": "ND", "dtype": "float16" }, { "shape": (32, 1), "ori_shape": (32, 1), "format": "ND", "ori_format": "ND", "dtype": "float16" }, [1,], True] }) ut_case.add_case(support_soc="Ascend910", case={ "params": [{ "shape": (32, 32), "ori_shape": (32, 32), "format": "ND", "ori_format": "ND", "dtype": "float32" }, { "shape": (32, 1), "ori_shape": (32, 1), "format": "ND", "ori_format": "ND", "dtype": "float32" }, [1,], True] })