---
title: 函数：set_tensor_const
description: "| 产品 | 是否支持 |"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/API/ascendgraphapi/aclpythondevg_01_0041.html
sourcePath: /source/zh/canncommercial/900/API/ascendgraphapi/aclpythondevg_01_0041.html
indexId: 579352ab1805287d028c64e8d5542f1b8b2687d433c182f4df68000b784087f375
---
# 函数：set_tensor_const

#### 产品支持情况

| 产品 | 是否支持 |
| --- | --- |
| Atlas 350 加速卡 | √ |
| Atlas A3 训练系列产品 / Atlas A3 推理系列产品 | √ |
| Atlas A2 训练系列产品 / Atlas A2 推理系列产品 | √ |
| Atlas 训练系列产品 | √ |
| Atlas 推理系列产品 | √ |
| Atlas 200I/500 A2 推理产品 | √ |


#### 功能说明

为算子设置constant输入，指定存放输入Tensor数据的内存地址和地址长度。


#### 函数原型

- C函数原型
  1 aclError aclSetTensorConst(aclTensorDesc *desc, void *dataBuffer, size_t length)

- python函数
  1 ret = acl.set_tensor_const(desc, dataBuffer, length)


#### 参数说明

| 参数名 | 说明 |
| --- | --- |
| desc | int，aclTensorDesc类型的指针地址。 需提前调用acl.create\_tensor\_desc接口创建aclTensorDesc类型。 |
| dataBuffer | int，存放constant输入Tensor数据的内存地址。 此处算子输入Tensor数据的内存必须根据应用运行模式来确定。内存申请接口请参见内存管理(https://www.hiascend.comdocument/detail/zh/canncommercial/900/API/runtimeapi/aclpythondevg\_01\_0108.html)。 应用运行在Host时，此处需申请Host上的内存。 应用运行在Device时，此处需申请Device上的内存。 |
| length | int，内存地址的长度，单位是Byte。 |


#### 返回值说明

| 返回值 | 说明 |
| --- | --- |
| ret | int，错误码。 返回0表示成功。 返回其它值(https://www.hiascend.comdocument/detail/zh/canncommercial/900/API/runtimeapi/aclpythondevg\_01\_0911.html)表示失败。 |
