---
title: 函数：load_from_mem
description: "从内存加载离线模型数据，由系统内部管理模型运行的内存。"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/API/ascendgraphapi/aclpythondevg_01_0140.html
sourcePath: /source/zh/canncommercial/900/API/ascendgraphapi/aclpythondevg_01_0140.html
indexId: 17913c22c5cb1fdef719233dcd6039e1e8e803d468d32b5818e8a0254847f40a75
---
# 函数：load_from_mem

#### 功能说明

从内存加载离线模型数据，由系统内部管理模型运行的内存。

系统完成模型加载后，返回的模型ID，作为后续操作时用于识别模型的标志。


#### 函数原型

- C函数原型
  1 aclError aclmdlLoadFromMem(const void* model, size_t modelSize, uint32_t* modelId)

- python函数
  1 model_id, ret = acl.mdl.load_from_mem(model, model_size)


#### 参数说明

| 参数名 | 说明 |
| --- | --- |
| model | int，模型数据的内存地址对应的指针地址。 应用运行在Host时，此处需申请Host上的内存。 应用运行在Device时，此处需申请Device上的内存。 内存申请接口请参见内存管理(https://www.hiascend.comdocument/detail/zh/canncommercial/900/API/runtimeapi/aclpythondevg\_01\_0108.html)。 |
| model\_size | int，内存中的模型数据长度，单位Byte。 |


#### 返回值说明

| 返回值 | 说明 |
| --- | --- |
| model\_id | int，系统完成模型加载后生成的模型ID对应的指针地址。 |
| ret | int，错误码，返回0表示成功，返回其它值表示失败。 |


#### 约束说明

模型加载、模型执行、模型卸载的操作必须在同一个Context下（关于Context的创建请参见acl.rt.set_device(https://www.hiascend.comdocument/detail/zh/canncommercial/900/API/runtimeapi/aclpythondevg_01_0062.html)、acl.rt.create_context(https://www.hiascend.comdocument/detail/zh/canncommercial/900/API/runtimeapi/aclpythondevg_01_0072.html)）。


#### 资源参考

接口调用流程，参见模型加载(https://www.hiascend.comdocument/detail/zh/canncommercial/900/programug/acldevg/aclpythondevg_0031.html)。
