---
title: 函数：execute_v2
description: "| C函数原型 | aclError aclmdlExecuteV2(uint32\_t modelId, const aclmdlDataset \*input, aclmdlDataset \*output, aclrtStream stream，const aclmdlExecConfigHandle\* handle) |"
url: https://www.hiascend.com/document/detail/zh/Atlas200IDKA2DeveloperKit/latest/Application%20Development%20Guide/aadgp/aclpythondevg_01_0134.html
sourcePath: /source/zh/Atlas200IDKA2DeveloperKit/23.0.RC2/Application Development Guide/aadgp/aclpythondevg_01_0134.html
indexId: d464bbdbb3bfa0c391d698a61ef5c40bcff034fee100d98d13a8883c9fda0a88108
---
# 函数：execute_v2

| C函数原型 | aclError aclmdlExecuteV2(uint32\_t modelId, const aclmdlDataset \*input, aclmdlDataset \*output, aclrtStream stream，const aclmdlExecConfigHandle\* handle) |
| --- | --- |
| Python函数 | ret = acl.mdl.execute\_v2(model\_id, input, output, stream, handle) |
| 函数功能 | 根据acl.mdl.set\_exec\_config\_opt接口所配置的属性，执行模型推理，直到返回推理结果。该接口是在acl.mdl.execute接口基础上进行了增强，支持在执行模型推理时控制Stream任务的超时时间、Event任务的超时时间。 |
| 输入说明 | model\_id：int，指定需要执行推理的模型的ID。调用acl.mdl.load\_from\_file接口/acl.mdl.load\_from\_mem接口/acl.mdl.load\_from\_file\_with\_mem接口/acl.mdl.load\_from\_mem\_with\_mem接口加载模型成功后，会返回模型ID。 input：int，模型推理的输入数据的指针地址。 output：int，模型推理的输出数据的指针地址。 stream：int，指定已创建的Stream指针地址，如需指定新的Stream，可通过acl.rt.create\_stream等接口创建并获取Stream指针地址。 handle：int，模型执行的配置对象的指针地址。与acl.mdl.set\_exec\_config\_opt中的handle保持一致。 |
| 返回值说明 | ret：int，错误码。 返回0表示成功。 返回其它值表示失败。 |
| 约束说明 | 本接口需要配合其它接口一起使用，实现模型执行，接口调用顺序如下： 调用acl.mdl.create\_exec\_config\_handle接口创建模型执行的配置对象的指针地址。 多次调用acl.mdl.set\_exec\_config\_opt接口设置配置对象中每个属性的值。 调用acl.mdl.execute\_v2接口指定模型执行时需要的配置信息，并进行模型执行。 模型加载成功后，调用acl.mdl.destroy\_exec\_config\_handle接口销毁。 其他约束与acl.mdl.execute一致。 |
| 参考资源 | 接口调用流程及示例代码，参见模型执行。 Stream创建与管理，请参见Stream管理。 |
