# MindSpore报错Kernel launch failed, msg: Acl compile and execute failed, op\_type\_:AvgPool3D

**1. 系统环境**

硬件环境\(Ascend/GPU/CPU\): Ascend

软件环境: MindSpore 版本: 2.3.0

执行模式（静态图/动态图）： 不限

Python 版本: 3.8

操作系统平台: linux

**2. 报错信息**

2.1 问题描述

执行如下脚本时报错。

2.2 报错信息

```
[ERROR] KERNEL (110510, ffff9e802ebe, python) :2024-@9-19-10:20:53.977.250 [mindspore/ccsrc/plugin/device/ascend/kernel/acl/acl_kernel_mod.cc:261] Launch] Kernel launch failed, msg: Acl compile and execute failed, op_type_:AvgPoo0l13D
```

2.3 脚本信息

```
    x = ops.randn((1,216,64,64), dtype=ms.float32)
    out = ops.avg_pool2d(x, 2, stride=2, ceil_mode=True)
    print(out.shape)
```

**3. 根因分析**

报错详细信息如下

```
[ERROR] KERNEL(100,fffe38f9f120,python):2024-10-28-14:49:50.966.185 [mindspore/ccsrc/plugin/device/ascend/kernel/acl/acl_kernel_mod.cc:260] Launch] Kernel launch failed, msg: Acl compile and execute failed, op_type_:AvgPool3D
```

上面的报错是调用cann的AvgPool3D报错。这该是和cann对接的问题，是mindspore实现的问题。

avg\_pool2d的实现如下，最终调用了AvgPool3D算子。而avg\_pool3d在Ascend下同样存在问题。在CPU下是正常的。

```
    if not isinstance(input_x, (Tensor, Tensor_)):
        raise TypeError("For avg_pool2d, the input input_x must be tensor")

    kernel_size = _check_avgpool_2d_kernel_size(kernel_size)
    stride = _check_avgpool_2d_stride(stride)
    padding = _check_avgpool_2d_padding(padding)
    _check_avg_pool2d_type_and_value(ceil_mode, count_include_pad, divisor_override)
    squeeze_op = _get_cache_prim(P.Squeeze)(2)
    avg_pool_op = _get_cache_prim(P.AvgPool3D)(kernel_size=kernel_size,
                                               strides=stride,
                                               pad_mode='pad',
                                               pad=padding,
                                               ceil_mode=ceil_mode,
                                               count_include_pad=count_include_pad,
                                               divisor_override=divisor_override)
    input_x = expand_dims_(input_x, 2)
    input_x = avg_pool_op(input_x)
    input_x = squeeze_op(input_x)
    return input_x
```

**4. 解决方案**

除了ops的avg\_pool2d，nn层也同样有mindspore.nn.AvgPool2d的实现。

https://www.mindspore.cn/docs/zh-CN/r2.3.1/api\_python/nn/mindspore.nn.AvgPool2d.html?highlight=avgpool2d

注意ceil\_mode=True也不能设置。因为底层对应cann只支持输入为NCHW格式。

```
import mindspore as ms
from mindspore import ops
import numpy as np
pool = ms.nn.AvgPool2d(kernel_size=2, stride=2)
x = ops.randn((1,216,64,64), dtype=ms.float32)
output = pool(x)
print(output.shape)
```

