---
title: aclgrphBuildModel
description: "| 产品 | 是否支持 |"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/API/ascendgraphapi/atlasgeapi_07_0078.html
sourcePath: /source/zh/canncommercial/900/API/ascendgraphapi/atlasgeapi_07_0078.html
indexId: 596678292e378b8b77463c71e83097d4ec2a39bca3ddd1cc0b3a3f2e146b009572
---
# aclgrphBuildModel

#### 产品支持情况

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


#### 头文件/库文件

- 头文件：#include <ge/ge_ir_build.h>
- 库文件：libge_compiler.so


#### 功能说明

将输入的Graph编译为适配AI处理器的离线模型，并保存到内存缓冲区。


#### 函数原型

数据类型为string的接口后续版本会废弃，建议使用数据类型为非string的接口。


```
graphStatus aclgrphBuildModel(const ge::Graph &graph, const std::map<std::string, std::string> &build_options, ModelBufferData &model)
graphStatus aclgrphBuildModel(const ge::Graph &graph, const std::map<AscendString, AscendString> &build_options, ModelBufferData &model)
```


#### 参数说明

| 参数名 | 输入/输出 | 说明 |  |  |
| --- | --- | --- | --- | --- |
| graph | 输入 | 待编译的Graph。 |  |  |
| build\_options | 输入 | graph级别配置参数。 配置参数map映射表，key为参数类型，value为参数值，均为字符串格式，用于描述离线模型编译配置信息。 map中的配置参数请参见aclgrphBuildModel支持的配置参数。 |  |  |
| model | 输出 | 编译生成的离线模型缓存，模型保存在内存缓冲区中。详情请参见ModelBufferData。 1 2 3 4 5 struct ModelBufferData { std::shared\_ptr<uint8\_t> data = nullptr; uint64\_t length; }; 其中data指向生成的模型数据，length代表该模型的实际大小。 | 1 2 3 4 5 | struct ModelBufferData { std::shared\_ptr<uint8\_t> data = nullptr; uint64\_t length; }; |
| 1 2 3 4 5 | struct ModelBufferData { std::shared\_ptr<uint8\_t> data = nullptr; uint64\_t length; }; |  |  |  |


#### 返回值说明

| 参数名 | 类型 | 说明 |
| --- | --- | --- |
| \- | graphStatus | GRAPH\_SUCCESS(0)：成功。 其他值：失败，详情请参见"ge::graphStatus(https://www.hiascend.comdocument/detail/zh/canncommercial/900/maintenref/basicdataapi/atlasopapi\_07\_00513.html)"。 |


#### 约束说明

- 对于aclgrphBuildModel和aclgrphBuildInitialize中重复的编译配置参数，建议不要重复配置，如果设置重复，则以aclgrphBuildModel传入的为准。
- 使用aclgrphBuildModel接口传入build_options参数时，多张图场景下，如果传入的参数为ge::ir_option::PRECISION_MODE或者ge::ir_option::PRECISION_MODE_V2，多张图设置的参数值需要相同。
- 使用aclgrphBuildModel接口编译的离线模型，保存在内存缓冲区中：

  - 如果希望将内存缓冲区中的模型保存为离线模型文件xx.om，则需要调用    aclgrphSaveModel
接口，序列化保存离线模型到文件中。后续进行推理业务，需要使用从文件中加载模型的接口，例如aclmdlLoadFromFile，然后使用aclmdlExecute接口执行推理。
  - 如果离线模型保存在内存缓冲区：
    后续进行推理业务时，需要使用从内存中加载模型的接口，例如aclmdlLoadFromMem，然后使用aclmdlExecute接口执行推理。

接口详细使用说明请参见“模型推理(https://www.hiascend.comdocument/detail/zh/canncommercial/900/programug/acldevg/aclcppdevg_000025.html)”章节。
