提交 91c3efb2 编写于 作者: A AGroupofProbiotocs

add Mindspore Lite API docs in Chinese, fix some errors in English API docs and tutorials

上级 e2dfa137
......@@ -9,6 +9,7 @@ Here is a list of all classes with links to the namespace documentation for each
| mindspore::lite | [ModelImpl](https://www.mindspore.cn/lite/docs/en/master/apicc/lite.html#modelimpl) | ModelImpl defines the implement class of Model in MindSpore Lite. |
| mindspore::lite | [PrimitiveC](https://www.mindspore.cn/lite/docs/en/master/apicc/lite.html#primitivec) | Primitive defines as prototype of operator. |
| mindspore::lite | [Model](https://www.mindspore.cn/lite/docs/en/master/apicc/lite.html#model) | Model defines model in MindSpore Lite for managing graph. |
| mindspore::lite | [ModelBuilder](https://www.mindspore.cn/lite/docs/en/master/apicc/lite.html#modelbuilder) | ModelBuilder is defined by MindSpore Lite. |
| mindspore::lite | [ModelBuilder](https://www.mindspore.cn/lite/docs/en/master/apicc/lite.html#modelbuilder) | ModelBuilder is defined to build the model. |
| mindspore::session | [LiteSession](https://www.mindspore.cn/lite/docs/en/master/apicc/session.html#litesession) | LiteSession defines session in MindSpore Lite for compiling Model and forwarding model. |
| mindspore::tensor | [MSTensor](https://www.mindspore.cn/lite/docs/en/master/apicc/tensor.html#mstensor) | MSTensor defines tensor in MindSpore Lite. |
\ No newline at end of file
| mindspore::tensor | [MSTensor](https://www.mindspore.cn/lite/docs/en/master/apicc/tensor.html#mstensor) | MSTensor defines tensor in MindSpore Lite. |
......@@ -28,54 +28,23 @@ Description of error code and meta type supported in MindSpore Lite.
## MetaType
An **enum** type.
| Type Name | Definition | Value | Description |
| --- | --- | --- | --- |
| Type type |kTypeUnknown| 0 | Unknown type. |
| |kMetaTypeBegin| 0 | The beginning of meta type. |
| |kMetaTypeType | 1 | * |
| |kMetaTypeAnything| 2 | * |
| |kMetaTypeObject| 3 | Indicating an object. |
| |kMetaTypeTypeType| 4 | * |
| |kMetaTypeProblem| 5 | Indicating Problem. |
| |kMetaTypeExternal| 6 | Indicating External. |
| |kMetaTypeNone| 7 | Indicating None. |
| |kMetaTypeNull| 8 | Indicating Null. |
| |kMetaTypeEllipsis| 9 | Indicating Ellipsis. |
| |kMetaTypeEnd| 10 | The end of meta type. |
| Object types |kObjectTypeBegin| 10 | The beginning of object type. |
| |kObjectTypeNumber| 11 | Indicating a number. |
| |kObjectTypeString| 12 | Indicating a string. |
| |kObjectTypeList| 13 | Indicating a list. |
| |kObjectTypeTuple| 14 | Indicating a tuple. |
| |kObjectTypeSlice| 15 | Indicating a slice. |
| |kObjectTypeKeyword| 16 | Indicating a keyword. |
| |kObjectTypeTensorType| 17 | Indicating a tensor type. |
| |kObjectTypeRowTensorType| 18 | Indicating a row tensor type. |
| |kObjectTypeSparseTensorType| 19 | Indicating a sparse tensor type. |
| |kObjectTypeUndeterminedType| 20 | Indicating a undetermined type. |
| |kObjectTypeClass| 21 | Indicating a class. |
| |kObjectTypeDictionary| 22 | Indicating a dictionary. |
| |kObjectTypeFunction| 23 | Indicating a function. |
| |kObjectTypeJTagged| 24 | Indicating a JTagged. |
| |kObjectTypeSymbolicKeyType| 25 | Indicating a symbolic key type.|
| |kObjectTypeEnvType| 26 | Indicating an Env type.|
| |kObjectTypeRefKey| 27 | Indicating a Ref key. |
| |kObjectTypeRef| 28 | Indicating Ref. |
| |kObjectTypeEnd| 29 | The end of object type. |
| Number Types |kNumberTypeBegin| 29 | The beginning of number type. |
| |kNumberTypeBool| 30 | Indicating a data type of bool. |
| |kNumberTypeInt| 31 | Indicating a data type of int. |
| |kNumberTypeInt8| 32 | Indicating a data type of int8. |
| |kNumberTypeInt16| 33 | Indicating a data type of int16. |
| |kNumberTypeInt32| 34 | Indicating a data type of int32. |
| |kNumberTypeInt64| 35 | Indicating a data type of int64. |
| |kNumberTypeUInt| 36 | Indicating a data type of unit. |
| |kNumberTypeUInt8| 37 | Indicating a data type of unit8. |
| |kNumberTypeUInt16| 38 | Indicating a data type of uint16. |
| |kNumberTypeUInt32| 39 | Indicating a data type of uint32. |
| |kNumberTypeUInt64| 40 | Indicating a data type of uint64. |
| |kNumberTypeFloat| 41 | Indicating a data type of float. |
| |kNumberTypeFloat16| 42 | Indicating a data type of float16. |
| |kNumberTypeFloat32| 43 | Indicating a data type of float32. |
| |kNumberTypeFloat64| 44 | Indicating a data type of float64.|
| |kNumberTypeEnd| 45 | The end of number type. |
\ No newline at end of file
| Type Definition | Value | Description |
| --- | --- | --- |
|kNumberTypeBegin| 29 | The beginning of number type. |
|kNumberTypeBool| 30 | Indicating a data type of bool. |
|kNumberTypeInt| 31 | Indicating a data type of int. |
|kNumberTypeInt8| 32 | Indicating a data type of int8. |
|kNumberTypeInt16| 33 | Indicating a data type of int16. |
|kNumberTypeInt32| 34 | Indicating a data type of int32. |
|kNumberTypeInt64| 35 | Indicating a data type of int64. |
|kNumberTypeUInt| 36 | Indicating a data type of unit. |
|kNumberTypeUInt8| 37 | Indicating a data type of unit8. |
|kNumberTypeUInt16| 38 | Indicating a data type of uint16. |
|kNumberTypeUInt32| 39 | Indicating a data type of uint32. |
|kNumberTypeUInt64| 40 | Indicating a data type of uint64. |
|kNumberTypeFloat| 41 | Indicating a data type of float. |
|kNumberTypeFloat16| 42 | Indicating a data type of float16. |
|kNumberTypeFloat32| 43 | Indicating a data type of float32. |
|kNumberTypeFloat64| 44 | Indicating a data type of float64.|
|kNumberTypeEnd| 45 | The end of number type. |
# mindspore::lite context
# mindspore::lite
#include <[context.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/context.h)>
#include <[model.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/model.h)>
#include <[version.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/version.h)>
## Allocator
......@@ -17,7 +24,7 @@ Context()
Constructor of MindSpore Lite Context using default value for parameters.
```
Context(int thread_num, std::shared_ptr< Allocator > allocator, DeviceContext device_ctx)
Context(int thread_num, std::shared_ptr<Allocator> allocator, DeviceContext device_ctx)
```
Constructor of MindSpore Lite Context using input value for parameters.
......@@ -42,31 +49,31 @@ Destructor of MindSpore Lite Context.
```
float16_priority
```
```
A **bool** value. Defaults to **false**. Prior enable float16 inference.
```
device_ctx_{DT_CPU}
```
A **DeviceContext** struct.
A [**DeviceContext**](https://www.mindspore.cn/lite/docs/en/master/apicc/lite.html#devicecontext) struct defined at the bottom of the text. Using to specify the device.
```
thread_num_
```
```
An **int** value. Defaults to **2**. Thread number config for thread pool.
```
allocator
```
```
A **std::shared_ptr<Allocator>** pointer.
A **pointer** pointing to [**Allocator**](https://www.mindspore.cn/lite/docs/en/master/apicc/lite.html#allocator).
```
cpu_bind_mode_
```
```
A **CpuBindMode** enum variable. Defaults to **MID_CPU**.
A [**CpuBindMode**](https://www.mindspore.cn/lite/docs/en/master/apicc/lite.html#cpubindmode) enum variable. Defaults to **MID_CPU**.
## ModelImpl
ModelImpl defines the implement class of Model in MindSpore Lite.
......@@ -98,7 +105,7 @@ Get MindSpore Lite Primitive by name.
- Parameters
- `name`: Define name of primitive to be returned.
- `name`: Define name of Primitive to be returned.
- Returns
......@@ -134,6 +141,7 @@ Static method to create a Model pointer.
Pointer of MindSpore Lite Model.
**Public Attributes**
```
model_impl_
......@@ -141,7 +149,7 @@ Static method to create a Model pointer.
The **pointer** of implement of model in MindSpore Lite. Defaults to **nullptr**.
## ModelBuilder
ModelBuilder is defined by MindSpore Lite.
ModelBuilder is defined to build the model.
**Constructors & Destructors**
```
......@@ -161,17 +169,17 @@ Destructor of MindSpore Lite ModelBuilder.
virtual std::string AddOp(const PrimitiveC &op, const std::vector<OutEdge> &inputs)
```
Add primitive into model builder for model building.
Add Primitive into model builder for model building.
- Parameters
- `op`: Define the primitive to be added.
- `op`: Define the Primitive to be added.
- `inputs`: Define input edge of primitive to be added.
- `inputs`: A vector of [**OutEdge**](https://www.mindspore.cn/lite/docs/en/master/apicc/lite.html#outedge). Define input edge of Primitive to be added.
- Returns
ID of the added primitive.
ID of the added Primitive.
```
const schema::MetaGraph* GetMetaGraph() const
......@@ -188,7 +196,11 @@ virtual Model *Construct()
Finish constructing the model.
## OutEdge
A **struct**. OutEdge defines the edge in the gragh.
**Attributes**
```
nodeId
```
......@@ -205,55 +217,53 @@ An **enum** type. CpuBindMode defined for holding bind cpu strategy argument.
**Attributes**
```
MID_CPU = -1
```
```
Bind middle cpu first.
```
HIGHER_CPU = 1
```
```
Bind higher cpu first.
```
NO_BIND = 0
```
```
No bind.
## DeviceType
An **enum** type. DeviceType defined for holding user's preferred backend.
**Attributes**
```
DT_CPU = -1
```
```
CPU device type.
```
DT_GPU = 1
```
```
GPU device type.
```
DT_NPU = 0
```
```
NPU device type, not supported yet.
## DeviceContext
A **struct** . DeviceContext defined for holding DeviceType.
A **struct**. DeviceContext defined for holding DeviceType.
**Attributes**
```
type
```
A **DeviceType** variable. The device type.
```
A [**DeviceType**](https://www.mindspore.cn/lite/docs/en/master/apicc/lite.html#devicetype) variable. The device type.
## Version
```
std::string Version()
```
```
Global method to get a version string.
- Returns
The version string of MindSpore Lite.
\ No newline at end of file
The version string of MindSpore Lite.
# mindspore::session
#include &lt;[lite_session.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/lite_session.h)&gt;
## LiteSession
LiteSession defines session in MindSpore Lite for compiling Model and forwarding model.
**Constructors & Destructors**
```
LiteSession()
```
Constructor of MindSpore Lite LiteSession using default value for parameters.
```
~LiteSession()
```
......@@ -38,7 +41,7 @@ Compile MindSpore Lite model.
- Returns
STATUS as an error code of compiling graph, STATUS is defined in errorcode.h.
STATUS as an error code of compiling graph, STATUS is defined in [errorcode.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/errorcode.h).
```
virtual std::vector <tensor::MSTensor *> GetInputs() const
......@@ -66,18 +69,17 @@ Get input MindSpore Lite MSTensors of model by node name.
virtual int RunGraph(const KernelCallBack &before = nullptr, const KernelCallBack &after = nullptr)
```
Run session with callback.
> Note: RunGraph should be called after CompileGraph.
- Parameters
- `before`: Define a call_back_function to be called before running each node.
- `before`: A [**KernelCallBack**](https://www.mindspore.cn/lite/docs/en/master/apicc/session.html#kernelcallback) function. Define a callback function to be called before running each node.
- `after`: Define a call_back_function called after running each node.
- `after`: A [**KernelCallBack**](https://www.mindspore.cn/lite/docs/en/master/apicc/session.html#kernelcallback) function. Define a callback function to be called after running each node.
- Returns
STATUS as an error code of running graph, STATUS is defined in errorcode.h.
STATUS as an error code of running graph, STATUS is defined in [errorcode.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/errorcode.h).
```
virtual std::unordered_map<std::string, std::vector<mindspore::tensor::MSTensor *>> GetOutputMapByNode() const
......@@ -157,7 +159,7 @@ Resize inputs shape.
- Returns
STATUS as an error code of resize inputs, STATUS is defined in errorcode.h.
STATUS as an error code of resize inputs, STATUS is defined in [errorcode.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/errorcode.h).
**Static Public Member Functions**
......@@ -173,13 +175,20 @@ Static method to create a LiteSession pointer.
- Returns
Pointer of MindSpore Lite LiteSession.
## KernelCallBack
```
using KernelCallBack = std::function<bool(std::vector<tensor::MSTensor *> inputs, std::vector<tensor::MSTensor *> outputs, const CallBackParam &opInfo)>
```
A function wrapper. KernelCallBack defined the function pointer for callback.
## CallBackParam
CallBackParam defines input arguments for callBack function.
A **struct**. CallBackParam defines input arguments for callback function.
**Attributes**
```
name_callback_param
```
......
# mindspore::tensor
#include &lt;[ms_tensor.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/ms_tensor.h)&gt;
## MSTensor
MSTensor defined tensor in MindSpore Lite.
......@@ -7,19 +10,19 @@ MSTensor defined tensor in MindSpore Lite.
**Constructors & Destructors**
```
MSTensor()
```
```
Constructor of MindSpore Lite MSTensor.
- Returns
Instance of MindSpore Lite MSTensor.
```
virtual ~MSTensor()
```
```
Destructor of MindSpore Lite Model.
**Public Member Functions**
```
......@@ -27,7 +30,7 @@ virtual TypeId data_type() const
```
Get data type of the MindSpore Lite MSTensor.
> Note: TypeId is defined in mindspore/mindspore/core/ir/dtype/type_id.h. Only number types in TypeId enum are suitable for MSTensor.
> Note: TypeId is defined in [mindspore/mindspore/core/ir/dtype/type_id.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/core/ir/dtype/type_id.h). Only number types in TypeId enum are suitable for MSTensor.
- Returns
......@@ -135,7 +138,7 @@ static MSTensor *CreateTensor(TypeId data_type, const std::vector<int> &shape)
Static method to create a MSTensor pointer.
> Note: TypeId is defined in mindspore/mindspore/core/ir/dtype/type_id.h. Only number types in TypeId enum are suitable for MSTensor.
> Note: TypeId is defined in [mindspore/mindspore/core/ir/dtype/type_id.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/core/ir/dtype/type_id.h). Only number types in TypeId enum are suitable for MSTensor.
- Parameters
......
C++ API
=======
.. toctree::
:maxdepth: 1
class_list
lite
session
tensor
errorcode_and_metatype
\ No newline at end of file
# 类列表
MindSpore Lite中的类定义及其所属命名空间和描述:
| 命名空间 | 类 | 描述 |
| --- | --- | --- |
| mindspore::lite | [Allocator](https://www.mindspore.cn/lite/docs/zh-CN/master/api/context.html#allocator) | Allocator定义了一个内存池,用于动态地分配和释放内存。 |
| mindspore::lite | [Context](https://www.mindspore.cn/lite/docs/zh-CN/master/api/context.html#context) | Context用于保存执行期间的环境变量。 |
| mindspore::lite | [ModelImpl](https://www.mindspore.cn/lite/docs/zh-CN/master/api/model.html#modelimpl) | ModelImpl定义了MindSpore Lite中的Model的实现类。 |
| mindspore::lite | [PrimitiveC](https://www.mindspore.cn/lite/docs/zh-CN/master/api/model.html#primitivec) | PrimitiveC定义为算子的原型。 |
| mindspore::lite | [Model](https://www.mindspore.cn/lite/docs/zh-CN/master/api/model.html#model) | Model定义了MindSpore Lite中的模型,便于计算图管理。 |
| mindspore::lite | [ModelBuilder](https://www.mindspore.cn/lite/docs/zh-CN/master/api/model.html#modelbuilder) | ModelBuilder定义了MindSpore Lite中的模型构建器。 |
| mindspore::session | [LiteSession](https://www.mindspore.cn/lite/docs/zh-CN/master/api/lite_session.html#litesession) | LiteSession定义了MindSpore Lite中的会话,用于进行Model的编译和前向推理。 |
| mindspore::tensor | [MSTensor](https://www.mindspore.cn/lite/docs/zh-CN/master/api/ms_tensor.html#mstensor) | MSTensor定义了MindSpore Lite中的张量。 |
# 错误码及元类型
以下表格描述了MindSpore Lite中支持的错误码和元类型。
## ErrorCode
| 定义 | 值 | 描述 |
| --- | --- | --- |
| RET_OK | 0 | 执行成功。 |
| RET_ERROR | -1 | 通用错误码。 |
| RET_NULL_PTR | -2 | 返回空指针。 |
| RET_PARAM_INVALID | -3 | 无效参数。 |
| RET_NO_CHANGE | -4 | 无改变。 |
| RET_SUCCESS_EXIT | -5 | 无错误退出。 |
| RET_MEMORY_FAILED | -6 | 创建内存失败。 |
| RET_OUT_OF_TENSOR_RANGE | -101 | 输出检查越界。 |
| RET_INPUT_TENSOR_ERROR | -102 | 输入检查越界。 |
| RET_REENTRANT_ERROR | -103 | 存在运行中的执行器。 |
| RET_GRAPH_FILE_ERR | -201 | 图文件识别失败。 |
| RET_NOT_FIND_OP | -301 | 无法找到算子。 |
| RET_INVALID_OP_NAME | -302 | 无效算子名。 |
| RET_INVALID_OP_ATTR | -303 | 无效算子属性。 |
| RET_OP_EXECUTE_FAILURE | -304 | 算子执行失败。 |
| RET_FORMAT_ERR | -401 | 张量格式检查失败。 |
| RET_INFER_ERR | -501 | 维度推理失败。 |
| RET_INFER_INVALID | -502 | 无效的维度推理。 |
## MetaType
**enum**类型变量。
| 类型定义 | 值 | 描述 |
| --- | --- | --- |
|kNumberTypeBegin| 29 | 表示Number类型的起始。 |
|kNumberTypeBool| 30 | 表示Bool数据类型。 |
|kNumberTypeInt| 31 | 表示Int数据类型。 |
|kNumberTypeInt8| 32 | 表示Int8数据类型。 |
|kNumberTypeInt16| 33 | 表示Int16数据类型。 |
|kNumberTypeInt32| 34 | 表示Int32数据类型。 |
|kNumberTypeInt64| 35 | 表示Int64数据类型。 |
|kNumberTypeUInt| 36 | 表示UInt数据类型。 |
|kNumberTypeUInt8| 37 | 表示UInt8数据类型。 |
|kNumberTypeUInt16| 38 | 表示UInt16数据类型。 |
|kNumberTypeUInt32| 39 | 表示UInt32数据类型。 |
|kNumberTypeUInt64| 40 | 表示UInt64数据类型。 |
|kNumberTypeFloat| 41 | 表示Float数据类型。 |
|kNumberTypeFloat16| 42 | 表示Float16数据类型。 |
|kNumberTypeFloat32| 43 | 表示Float32数据类型。 |
|kNumberTypeFloat64| 44 | 表示Float64数据类型。|
|kNumberTypeEnd| 45 | 表示Number类型的结尾。 |
# mindspore::lite
#include &lt;[context.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/context.h)&gt;
#include &lt;[model.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/model.h)&gt;
#include &lt;[version.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/version.h)&gt;
## Allocator
Allocator类定义了一个内存池,用于动态地分配和释放内存。
## Context
Context类用于保存执行中的环境变量。
**构造函数和析构函数**
```
Context()
```
用默认参数构造MindSpore Lite Context 对象。
```
Context(int thread_num, std::shared_ptr<Allocator> allocator, DeviceContext device_ctx)
```
根据输入参数构造MindSpore Lite Context 对象。
- 参数
- `thread_num`: 定义了执行线程数。
- `allocator`: 定义了内存分配器。
- `device_ctx`: 定义了设备信息。
- 返回值
MindSpore Lite Context 指针。
```
~Context()
```
MindSpore Lite Context 的析构函数。
**公有属性**
```
float16_priority
```
**bool** 值,默认为**false**,用于使能float16 推理。
```
device_ctx_{DT_CPU}
```
[**DeviceContext**](https://www.mindspore.cn/lite/docs/zh-CN/master/apicc/lite.html#devicecontext)结构体。用于设置设备信息。
```
thread_num_
```
**int** 值,默认为**2**,设置线程数。
```
allocator
```
指针类型,指向内存分配器[**Allocator**](https://www.mindspore.cn/lite/docs/zh-CN/master/apicc/lite.html#allocator)的指针。
```
cpu_bind_mode_
```
[**CpuBindMode**](https://www.mindspore.cn/lite/docs/zh-CN/master/apicc/lite.html#cpubindmode)枚举类型,默认为**MID_CPU**
## ModelImpl
ModelImpl定义了MindSpore Lite中的Model的实现类。
## PrimitiveC
PrimitiveC定义为算子的原型。
## Model
Model定义了MindSpore Lite中的模型,便于计算图管理。
**构造函数和析构函数**
```
Model()
```
MindSpore Lite Model的构造函数,使用默认参数。
```
virtual ~Model()
```
MindSpore Lite Model的析构函数。
**公有成员函数**
```
PrimitiveC* GetOp(const std::string &name) const
```
通过名称获取MindSpore Lite的Primitive对象。
- 参数
- `name`: 定义了所要返回的Primitive对象名。
- 返回值
指向MindSpore Lite Primitive的指针。
```
const schema::MetaGraph* GetMetaGraph() const
```
获取在flatbuffers中定义的图。
- 返回值
指向flatbuffers中定义的图的指针。
```
void FreeMetaGraph()
```
释放MindSpore Lite Model中的MetaGraph。
**静态公有成员函数**
```
static Model *Import(const char *model_buf, size_t size)
```
创建Model指针的静态方法。
- 参数
- `model_buf`: 定义了读取模型文件的缓存区。
- `size`: 定义了模型缓存区的字节数。
- 返回值
指向MindSpore Lite的Model的指针。
**公有属性**
```
model_impl_
```
指向MindSpore Lite模型实现的指针型变量。默认为**nullptr**
## ModelBuilder
ModelBuilder定义了MindSpore Lite中的模型构建器。
**构造函数和析构函数**
```
ModelBuilder()
```
MindSpore Lite ModelBuilder的构造函数,使用默认参数。
```
virtual ~ModelBuilder()
```
MindSpore Lite ModelBuilder的析构函数。
**公有成员函数**
```
virtual std::string AddOp(const PrimitiveC &op, const std::vector<OutEdge> &inputs)
```
向模型构建器中添加Primitive对象,用于构建模型。
- 参数
- `op`: 定义了添加的Primitive对象。
- `inputs`: 一个[**OutEdge**](https://www.mindspore.cn/lite/docs/zh-CN/master/apicc/lite.html#outedge)结构体的向量, 定义了添加的Primitive对象的输入的边。
- 返回值
添加的Primitive对象的ID。
```
const schema::MetaGraph* GetMetaGraph() const
```
获取在flatbuffers中所定义的图。
- 返回值
指向flatbuffers中所定义的图的指针。
```
virtual Model *Construct()
```
结束模型构建。
## OutEdge
一个结构体。OutEdge定义了计算图的边。
**属性**
```
nodeId
```
**string**类型变量。 被当前边所连接的节点的ID。
```
outEdgeIndex
```
**size_t**类型变量。 当前边的索引。
## CpuBindMode
枚举类型,设置cpu绑定策略。
**属性**
```
MID_CPU = -1
```
优先中等CPU绑定策略。
```
HIGHER_CPU = 1
```
优先高级CPU绑定策略。
```
NO_BIND = 0
```
不绑定。
## DeviceType
枚举类型,设置设备类型。
**属性**
```
DT_CPU = -1
```
设备为CPU。
```
DT_GPU = 1
```
设备为GPU。
```
DT_NPU = 0
```
设备为NPU,暂不支持。
## DeviceContext
定义设备类型的结构体。
**属性**
```
type
```
[**DeviceType**](https://www.mindspore.cn/lite/docs/zh-CN/master/apicc/lite.html#devicetype) 变量。设备类型。
## Version
```
std::string Version()
```
全局方法,用于获取版本的字符串。
- 返回值
MindSpore Lite版本的字符串。
\ No newline at end of file
# mindspore::session
#include &lt;[lite_session.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/lite_session.h)&gt;
## LiteSession
LiteSession定义了MindSpore Lite中的会话,用于进行Model的编译和前向推理。
**构造函数和析构函数**
```
LiteSession()
```
MindSpore Lite LiteSession的构造函数,使用默认参数。
```
~LiteSession()
```
MindSpore Lite LiteSession的析构函数。
**公有成员函数**
```
virtual void BindThread(bool if_bind)
```
尝试将线程池中的线程绑定到指定的cpu内核,或从指定的cpu内核进行解绑。
- 参数
- `if_bind`: 定义了对线程进行绑定或解绑。
```
virtual int CompileGraph(lite::Model *model)
```
编译MindSpore Lite模型。
> 注意: CompileGraph必须在RunGraph方法之后调用。
- 参数
- `model`: 定义了需要被编译的模型。
- 返回值
STATUS ,即编译图的错误码。STATUS在[errorcode.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/errorcode.h)中定义。
```
virtual std::vector <tensor::MSTensor *> GetInputs() const
```
获取MindSpore Lite模型的MSTensors输入。
- 返回值
MindSpore Lite MSTensor向量。
```
std::vector <tensor::MSTensor *> GetInputsByName(const std::string &node_name) const
```
通过节点名获取MindSpore Lite模型的MSTensors输入。
- 参数
- `node_name`: 定义了节点名。
- 返回值
MindSpore Lite MSTensor向量。
```
virtual int RunGraph(const KernelCallBack &before = nullptr, const KernelCallBack &after = nullptr)
```
运行带有回调函数的会话。
> 注意: RunGraph必须在CompileGraph方法之后调用。
- 参数
- `before`: 一个[**KernelCallBack**](https://www.mindspore.cn/lite/docs/zh-CN/master/apicc/session.html#kernelcallback) 结构体。定义了运行每个节点之前调用的回调函数。
- `after`: 一个[**KernelCallBack**](https://www.mindspore.cn/lite/docs/zh-CN/master/apicc/session.html#kernelcallback) 结构体。定义了运行每个节点之后调用的回调函数。
- 返回值
STATUS ,即编译图的错误码。STATUS在[errorcode.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/errorcode.h)中定义。
```
virtual std::unordered_map<std::string, std::vector<mindspore::tensor::MSTensor *>> GetOutputMapByNode() const
```
获取与节点名相关联的MindSpore Lite模型的MSTensors输出。
- 返回值
包含输出节点名和MindSpore Lite MSTensor的容器类型变量。
```
virtual std::vector <tensor::MSTensor *> GetOutputsByNodeName(const std::string &node_name) const
```
通过节点名获取MindSpore Lite模型的MSTensors输出。
- 参数
- `node_name`: 定义了节点名。
- 返回值
MindSpore Lite MSTensor向量。
```
virtual std::unordered_map <std::string, mindspore::tensor::MSTensor *> GetOutputMapByTensor() const
```
获取与张量名相关联的MindSpore Lite模型的MSTensors输出。
- 返回值
包含输出张量名和MindSpore Lite MSTensor的容器类型变量。
```
virtual std::vector <std::string> GetOutputTensorNames() const
```
获取由当前会话所编译的模型的输出张量名。
- 返回值
字符串向量,其中包含了按顺序排列的输出张量名。
```
virtual mindspore::tensor::MSTensor *GetOutputByTensorName(const std::string &tensor_name) const
```
通过张量名获取MindSpore Lite模型的MSTensors输出。
- 参数
- `tensor_name`: 定义了张量名。
- 返回值
指向MindSpore Lite MSTensor的指针。
```
virtual int Resize(const std::vector <tensor::MSTensor *> &inputs)
```
调整输入的形状。
- 参数
- `inputs`: 定义了新的输入形状。
- 返回值
STATUS ,即编译图的错误码。STATUS在[errorcode.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/errorcode.h)中定义。
**静态公有成员函数**
```
static LiteSession *CreateSession(lite::Context *context)
```
用于创建一个LiteSession指针的静态方法。
- 参数
- `context`: 定义了所要创建的session的上下文。
- 返回值
指向MindSpore Lite LiteSession的指针。
## KernelCallBack
```
using KernelCallBack = std::function<bool(std::vector<tensor::MSTensor *> inputs, std::vector<tensor::MSTensor *> outputs, const CallBackParam &opInfo)>
```
一个函数包装器。KernelCallBack 定义了指向回调函数的指针。
## CallBackParam
一个结构体。CallBackParam定义了回调函数的输入参数。
**属性**
```
name_callback_param
```
**string** 类型变量。节点名参数。
```
type_callback_param
```
**string** 类型变量。节点类型参数。
\ No newline at end of file
# mindspore::tensor
#include &lt;[ms_tensor.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/ms_tensor.h)&gt;
## MSTensor
MSTensor定义了MindSpore Lite中的张量。
**构造函数和析构函数**
```
MSTensor()
```
MindSpore Lite MSTensor的构造函数。
- 返回值
MindSpore Lite MSTensor 的实例。
```
virtual ~MSTensor()
```
MindSpore Lite Model的析构函数。
**公有成员函数**
```
virtual TypeId data_type() const
```
获取MindSpore Lite MSTensor的数据类型。
> 注意:TypeId在[mindspore/mindspore/core/ir/dtype/type_id\.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/core/ir/dtype/type_id.h)中定义。只有TypeId枚举中的数字类型可用于MSTensor。
- 返回值
MindSpore Lite MSTensor类的MindSpore Lite TypeId。
```
virtual TypeId set_data_type(TypeId data_type)
```
设置MindSpore Lite MSTensor的数据类型。
- 参数
- `data_type`: 定义了MindSpore Lite MSTensor所需设置的MindSpore Lite TypeId。
- 返回值
设置后的MindSpore Lite MSTensor的MindSpore Lite TypeI。
```
virtual std::vector<int> shape() const
```
获取MindSpore Lite MSTensor的形状。
- 返回值
一个包含MindSpore Lite MSTensor形状数值的整型向量。
```
virtual size_t set_shape(const std::vector<int> &shape)
```
设置MindSpore Lite MSTensor的形状.
- 参数
- `shape`: 定义了一个整型向量,包含了所需设置的MindSpore Lite MSTensor形状数值。
- 返回值
设置形状后的MindSpore Lite MSTensor的大小。
```
virtual int DimensionSize(size_t index) const
```
Get size of the dimension of the MindSpore Lite MSTensor index by the parameter index.
- 参数
- `index`: 定义了返回的维度的索引。
- 返回值
MindSpore Lite MSTensor的维度的大小。
```
virtual int ElementsNum() const
```
获取MSTensor中的元素个数。
- 返回值
MSTensor中的元素个数
```
virtual std::size_t hash() const
```
获取MindSpore Lite MSTensor的哈希码。
- 返回值
MindSpore Lite MSTensor的哈希码。
```
virtual size_t Size() const
```
获取MSTensor中的数据的字节数大小。
- 返回值
MSTensor中的数据的字节数大小。
```
virtual void *MutableData() const
```
获取MSTensor中的数据的指针。
> 注意:该数据指针可用于对MSTensor中的数据进行读取和写入。
- 返回值
指向MSTensor中的数据的指针。
**静态公有成员函数**
```
static MSTensor *CreateTensor(TypeId data_type, const std::vector<int> &shape)
```
创建MSTensor指针的静态方法。
> 注意:TypeId在[mindspore/mindspore/core/ir/dtype/type_id\.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/core/ir/dtype/type_id.h)中定义。只有TypeId枚举中的数字类型可用于MSTensor。
- 参数
- `data_type`: 定义了所要创建的张量的数据类型。
- `shape`: 定义了所要创建的张量的形状。
- 返回值
指向MSTensor的指针。
\ No newline at end of file
......@@ -3,31 +3,31 @@
<!-- TOC -->
- [Use Runtime for Model Inference](#use-runtime-for-model-inference)
- [Overview](#overview)
- [Reading Models](#reading-models)
- [Session Creation](#session-creation)
- [Creating Contexts](#creating-contexts)
- [Creating Sessions](#creating-sessions)
- [Example](#example)
- [Graph Compilation](#graph-compilation)
- [Variable Dimension](#variable-dimension)
- [Example](#example-1)
- [Compiling Graphs](#compiling-graphs)
- [Example](#example-2)
- [Data Input](#data-input)
- [Obtaining Input Tensors](#obtaining-input-tensors)
- [Copying Data](#copying-data)
- [Example](#example-3)
- [Graph Execution](#graph-execution)
- [Executing Sessions](#executing-sessions)
- [Core Binding](#core-binding)
- [Callback Running](#callback-running)
- [Example](#example-4)
- [Obtaining Outputs](#obtaining-outputs)
- [Obtaining Output Tensors](#obtaining-output-tensors)
- [Example](#example-5)
- [Obtaining Version String](#obtaining-version-string)
- [Example](#example-6)
- [Overview](#overview)
- [Reading Models](#reading-models)
- [Session Creation](#session-creation)
- [Creating Contexts](#creating-contexts)
- [Creating Sessions](#creating-sessions)
- [Example](#example)
- [Graph Compilation](#graph-compilation)
- [Variable Dimension](#variable-dimension)
- [Example](#example-1)
- [Compiling Graphs](#compiling-graphs)
- [Example](#example-2)
- [Data Input](#data-input)
- [Obtaining Input Tensors](#obtaining-input-tensors)
- [Copying Data](#copying-data)
- [Example](#example-3)
- [Graph Execution](#graph-execution)
- [Executing Sessions](#executing-sessions)
- [Core Binding](#core-binding)
- [Callback Running](#callback-running)
- [Example](#example-4)
- [Obtaining Outputs](#obtaining-outputs)
- [Obtaining Output Tensors](#obtaining-output-tensors)
- [Example](#example-5)
- [Obtaining Version String](#obtaining-version-string)
- [Example](#example-6)
<!-- /TOC -->
......@@ -132,7 +132,7 @@ session->Resize(inputs);
### Compiling Graphs
Before graph execution, call the `CompileGraph` API of the `LiteSession` to compile graphs and further parse the Model instance loaded from the file, mainly for subgraph split and operator selection and scheduling. This process takes a long time. Therefore, it is recommended that `ListSession` achieve multiple executions with one creation and one compilation.
Before graph execution, call the `CompileGraph` API of the `LiteSession` to compile graphs and further parse the Model instance loaded from the file, mainly for subgraph split and operator selection and scheduling. This process takes a long time. Therefore, it is recommended that `LiteSession` achieve multiple executions with one creation and one compilation.
### Example
......
......@@ -3,31 +3,31 @@
<!-- TOC -->
- [使用Runtime执行推理](#使用runtime执行推理)
- [概述](#概述)
- [读取模型](#读取模型)
- [创建会话](#创建会话)
- [创建上下文](#创建上下文)
- [创建会话](#创建会话-1)
- [使用示例](#使用示例)
- [图编译](#图编译)
- [可变维度](#可变维度)
- [使用示例](#使用示例-1)
- [图编译](#图编译-1)
- [使用示例](#使用示例-2)
- [输入数据](#输入数据)
- [获取输入Tensor](#获取输入tensor)
- [数据拷贝](#数据拷贝)
- [使用示例](#使用示例-3)
- [图执行](#图执行)
- [执行会话](#执行会话)
- [绑核](#绑核)
- [回调运行](#回调运行)
- [使用示例](#使用示例-4)
- [获取输出](#获取输出)
- [获取输出Tensor](#获取输出tensor)
- [使用示例](#使用示例-5)
- [获取版本号](#获取版本号)
- [使用示例](#使用示例-6)
- [概述](#概述)
- [读取模型](#读取模型)
- [创建会话](#创建会话)
- [创建上下文](#创建上下文)
- [创建会话](#创建会话-1)
- [使用示例](#使用示例)
- [图编译](#图编译)
- [可变维度](#可变维度)
- [使用示例](#使用示例-1)
- [图编译](#图编译-1)
- [使用示例](#使用示例-2)
- [输入数据](#输入数据)
- [获取输入Tensor](#获取输入tensor)
- [数据拷贝](#数据拷贝)
- [使用示例](#使用示例-3)
- [图执行](#图执行)
- [执行会话](#执行会话)
- [绑核](#绑核)
- [回调运行](#回调运行)
- [使用示例](#使用示例-4)
- [获取输出](#获取输出)
- [获取输出Tensor](#获取输出tensor)
- [使用示例](#使用示例-5)
- [获取版本号](#获取版本号)
- [使用示例](#使用示例-6)
<!-- /TOC -->
......@@ -132,7 +132,7 @@ session->Resize(inputs);
### 图编译
在图执行前,需要调用`LiteSession``CompileGraph`接口进行图编译,进一步解析从文件中加载的Model实例,主要进行子图切分、算子选型调度。这部分会耗费较多时间,所以建议`ListSession`创建一次,编译一次,多次执行。
在图执行前,需要调用`LiteSession``CompileGraph`接口进行图编译,进一步解析从文件中加载的Model实例,主要进行子图切分、算子选型调度。这部分会耗费较多时间,所以建议`LiteSession`创建一次,编译一次,多次执行。
### 使用示例
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册