# Reduction APIs

Reduction APIs are used to reduce the data of a dimension and perform operations such as accumulation and multiplication on the data in a specified direction. The operation output has one less tensor in a dimension than the input data.

## General Restrictions

Due to the data arrangement restriction on the computing platform, the data after the reduction operation needs to be rearranged for subsequent operations. Therefore, when different types of APIs are used, no vector operation can be performed after the reduction operation.

## sum

### Description

Computes the sum along an axis to reduce dimensions.

The API is defined in **python/site-packages/te/lang/cce/te_compute/reduction_compute.py** in the ATC installation path.

### Restrictions

Ascend 310 AI Processor: float16, float32

### Prototype

te.lang.cce.sum(raw_tensor, axis, keepdims=False)

### Parameters

**raw_tensor**: a tvm.tensor for the input**axis**: an int or a list of ints for the axis to reduce. The value range is [–d, d – 1], where**d**indicates the dimension count of**raw_tensor**.**keepdims**: Defaults to**False**, indicating that the axis length is**0**after reduction. For example, if the original shape is**(10, 10, 10)**and**keepdims**is set to**False**, the shape after reduction is**(10, 10)**. If this parameter is set to**True**, the axis length is set to**1**after reduction. For example, if the original shape is**(10, 10, 10)**and**keepdims**is set to**True**, the shape after reduction is**(10, 10, 1)**.

### Returns

**res_tensor**: a tvm.tensor for the result

### Example

shape = (1024,1024) input_dtype = "float16" data = tvm.placeholder(shape, name="data", dtype=input_dtype) res = te.lang.cce.sum(data, axis=1)

## reduce_min

### Description

Computes the minimum along an axis to reduce dimensions.

The API is defined in **python/site-packages/te/lang/cce/te_compute/reduction_compute.py** in the ATC installation path.

### Restrictions

Ascend 310 AI Processor: float16, float32

### Prototype

te.lang.cce.reduce_min(raw_tensor, axis, keepdims=False,priority_flag=False)

### Parameters

**raw_tensor**: a tvm.tensor for the input tensor**axis**: an int or a list for the axis to reduce. The value range is [–d, d – 1], where**d**indicates the dimension count of**raw_tensor**.**keepdims**: Defaults to**False**, indicating that the axis length is**0**after reduction. For example, if the original shape is**(10, 10, 10)**and**keepdims**is set to**False**, the shape after reduction is**(10, 10)**. If this parameter is set to**True**, the axis length is set to**1**after reduction. For example, if the original shape is**(10, 10, 10)**and**keepdims**is set to**True**, the shape after reduction is**(10, 10, 1)**.**priority_flag**: high-accuracy mode or high-performance mode select.**True**: high-accuracy mode;**False**: high-performance mode.

### Returns

**res_tensor**: a tvm.tensor for the result tensor

### Example

shape = (1024,1024) input_dtype = "float16" data = tvm.placeholder(shape, name="data", dtype=input_dtype) res = te.lang.cce.reduce_min(data, axis=1)

## reduce_max

### Description

Computes the maximum along an axis to reduce dimensions.

The API is defined in **python/site-packages/te/lang/cce/te_compute/reduction_compute.py** in the ATC installation path.

### Restrictions

Ascend 310 AI Processor: float16, float32

### Prototype

te.lang.cce.reduce_max(raw_tensor, axis, keepdims=False, priority_flag=False)

### Parameters

**raw_tensor**: a tvm.tensor for the input tensor**axis**: an int or a list for the axis to reduce. The value range is [–d, d – 1], where**d**indicates the dimension count of**raw_tensor**.**keepdims**: Defaults to**False**, indicating that the axis length is**0**after reduction. For example, if the original shape is**(10, 10, 10)**and**keepdims**is set to**False**, the shape after reduction is**(10, 10)**. If this parameter is set to**True**, the axis length is set to**1**after reduction. For example, if the original shape is**(10, 10, 10)**and**keepdims**is set to**True**, the shape after reduction is**(10, 10, 1)**.**priority_flag**: high-accuracy mode or high-performance mode select.**True**: high-accuracy mode;**False**: high-performance mode.

### Returns

**res_tensor**: a tvm.tensor for the result tensor

### Example

shape = (1024,1024) input_dtype = "float16" data = tvm.placeholder(shape, name="data", dtype=input_dtype) res = te.lang.cce.reduce_max(data, axis=1)

## reduce_prod

### Description

Computes the product along an axis to reduce dimensions.

**python/site-packages/te/lang/cce/te_compute/reduction_compute.py** in the ATC installation path.

### Restrictions

Ascend 310 AI Processor: float16, float32

### Prototype

te.lang.cce.reduce_prod(raw_tensor, axis, keepdims=False)

### Parameters

**raw_tensor**: a tvm.tensor for the input tensor**axis**: an int or a list for the axis to reduce. The value range is [–d, d – 1], where**d**indicates the dimension count of**raw_tensor**.**keepdims**: Defaults to**False**, indicating that the axis length is**0**after reduction. For example, if the original shape is**(10, 10, 10)**and**keepdims**is set to**False**, the shape after reduction is**(10, 10)**. If this parameter is set to**True**, the axis length is set to**1**after reduction. For example, if the original shape is**(10, 10, 10)**and**keepdims**is set to**True**, the shape after reduction is**(10, 10, 1)**.

### Returns

**res_tensor**: a tvm.tensor for the result tensor

### Example

shape = (1024,1024) input_dtype = "float16" data = tvm.placeholder(shape, name="data", dtype=input_dtype) res = te.lang.cce.reduce_prod(data, axis=1)