diff --git a/lite/docs/source_en/api/class_list.md b/lite/docs/source_en/api/class_list.md new file mode 100644 index 0000000000000000000000000000000000000000..da4efb18c51b4836021f76c5dadcb6bb7cb8c070 --- /dev/null +++ b/lite/docs/source_en/api/class_list.md @@ -0,0 +1,12 @@ +Here is a list of all namespace members with links to the namespace documentation for each member: + +| Namespace | Class Name | Description | +| --- | --- | --- | +| mindspore::lite | [Allocator](https://www.mindspore.cn/lite/docs/en/master/api/context.html#allocator) | Allocator defines a memory pool for dynamic memory malloc and memory free. | +| mindspore::lite | [Context](https://www.mindspore.cn/lite/docs/en/master/api/context.html#context) | Context defines for holding environment variables during runtime. | +| mindspore::lite | [ModelImpl](https://www.mindspore.cn/lite/docs/en/master/api/model.html#modelimpl) | ModelImpl defines the implement class of Model in MindSpore Lite. | +| mindspore::lite | [PrimitiveC](https://www.mindspore.cn/lite/docs/en/master/api/model.html#primitivec) | Primitive defines as prototype of operator. | +| mindspore::lite | [Model](https://www.mindspore.cn/lite/docs/en/master/api/model.html#model) | Model defines model in MindSpore Lite for managing graph. | +| mindspore::lite | [ModelBuilder](https://www.mindspore.cn/lite/docs/en/master/api/model.html#modelbuilder) | ModelBuilder is defined by MindSpore Lite. | +| mindspore::session | [LiteSession](https://www.mindspore.cn/lite/docs/en/master/api/lite_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/api/ms_tensor.html#mstensor) | MSTensor defines tensor in MindSpore Lite. | \ No newline at end of file diff --git a/lite/docs/source_en/api/context.md b/lite/docs/source_en/api/context.md new file mode 100644 index 0000000000000000000000000000000000000000..0e2d0e1414ee4e867998d96e75f89aec4cf75835 --- /dev/null +++ b/lite/docs/source_en/api/context.md @@ -0,0 +1,117 @@ +# mindspore::lite + +## Allocator + +Allocator defines a memory pool for dynamic memory malloc and memory free. + +## Context + +Context is defined for holding environment variables during runtime. + +**Constructors & Destructors** + +``` +Context() +``` + +Constructor of MindSpore Lite Context using default value for parameters. + +``` +Context(int thread_num, std::shared_ptr< Allocator > allocator, DeviceContext device_ctx) +``` +Constructor of MindSpore Lite Context using input value for parameters. + +- Parameters + + - `thread_num`: Define the work thread number during the runtime. + + - `allocator`: Define the allocator for malloc. + + - `device_ctx`: Define device information during the runtime. + +- Returns + + The instance of MindSpore Lite Context. + +``` + ~Context() +``` +Destructor of MindSpore Lite Context. + +**Public Attributes** + +``` +float16_priority +``` +A **bool** value. Defaults to **false**. Prior enable float16 inference. + +``` +device_ctx_{DT_CPU} +``` +A **DeviceContext** struct. + +``` +thread_num_ +``` + +An **int** value. Defaults to **2**. Thread number config for thread pool. + +``` +allocator +``` + +A **std::shared_ptr** pointer. + +``` +cpu_bind_mode_ +``` + +A **CpuBindMode** enum variable. Defaults to **MID_CPU**. + +## CpuBindMode +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. + +**Attributes** +``` +type +``` +A **DeviceType** variable. The device type. \ No newline at end of file diff --git a/lite/docs/source_en/api/errorcode_and_metatype.md b/lite/docs/source_en/api/errorcode_and_metatype.md new file mode 100644 index 0000000000000000000000000000000000000000..59081a20ca387add2d5ccb8c1f78ce11d3c04f08 --- /dev/null +++ b/lite/docs/source_en/api/errorcode_and_metatype.md @@ -0,0 +1,79 @@ +Description of error code and meta type supported in MindSpore Lite. + +# ErrorCode + +| Definition | Value | Description | +| --- | --- | --- | +| RET_OK | 0 | No error occurs. | +| RET_ERROR | -1 | Common error code. | +| RET_NULL_PTR | -2 | NULL pointer returned. | +| RET_PARAM_INVALID | -3 | Invalid parameter. | +| RET_NO_CHANGE | -4 | No change. | +| RET_SUCCESS_EXIT | -5 | No error but exit. | +| RET_MEMORY_FAILED | -6 | Fail to create memory. | +| RET_OUT_OF_TENSOR_RANGE | -101 | Failed to check range. | +| RET_INPUT_TENSOR_ERROR | -102 | Failed to check input tensor. | +| RET_REENTRANT_ERROR | -103 | Exist executor running. | +| RET_GRAPH_FILE_ERR | -201 | Failed to verify graph file. | +| RET_NOT_FIND_OP | -301 | Failed to find operator. | +| RET_INVALID_OP_NAME | -302 | Invalid operator name. | +| RET_INVALID_OP_ATTR | -303 | Invalid operator attr. | +| RET_OP_EXECUTE_FAILURE | -304 | Failed to execute the operator. | +| RET_FORMAT_ERR | -401 | Failed to check the tensor format. | +| RET_INFER_ERR | -501 | Failed to infer shape. | +| RET_INFER_INVALID | -502 | Invalid infer shape before runtime. | + +# 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 diff --git a/lite/docs/source_en/api/lite_session.md b/lite/docs/source_en/api/lite_session.md new file mode 100644 index 0000000000000000000000000000000000000000..321e2b5b5da38e92d23c74addd91c8a08a0f0574 --- /dev/null +++ b/lite/docs/source_en/api/lite_session.md @@ -0,0 +1,191 @@ +# mindspore::session + +## 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() +``` +Destructor of MindSpore Lite LiteSession. + +**Public Member Functions** +``` +virtual void BindThread(bool if_bind) +``` +Attempt to bind or unbind threads in the thread pool to or from the specified cpu core. + +- Parameters + + - `if_bind`: Define whether to bind or unbind threads. + +``` +virtual int CompileGraph(lite::Model *model) +``` +Compile MindSpore Lite model. + +> Note: CompileGraph should be called before RunGraph. + +- Parameters + + - `model`: Define the model to be compiled. + +- Returns + + STATUS as an error code of compiling graph, STATUS is defined in errorcode.h. + +``` +virtual std::vector GetInputs() const +``` +Get input MindSpore Lite MSTensors of model. + +- Returns + + The vector of MindSpore Lite MSTensor. + +``` +std::vector GetInputsByName(const std::string &node_name) const +``` +Get input MindSpore Lite MSTensors of model by node name. + +- Parameters + + - `node_name`: Define node name. + +- Returns + + The vector of MindSpore Lite MSTensor. + +``` +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. + + - `after`: Define a call_back_function called after running each node. + +- Returns + + STATUS as an error code of running graph, STATUS is defined in errorcode.h. + +``` +virtual std::unordered_map> GetOutputMapByNode() const +``` +Get output MindSpore Lite MSTensors of model mapped by node name. + +- Returns + + The map of output node name and MindSpore Lite MSTensor. + +``` +virtual std::vector GetOutputsByNodeName(const std::string &node_name) const +``` +Get output MindSpore Lite MSTensors of model by node name. + +- Parameters + + - `node_name`: Define node name. + +- Returns + + The vector of MindSpore Lite MSTensor. + +``` +virtual std::unordered_map GetOutputMapByTensor() const +``` +Get output MindSpore Lite MSTensors of model mapped by tensor name. + +- Returns + + The map of output tensor name and MindSpore Lite MSTensor. + +``` +virtual std::vector GetOutputTensorNames() const +``` +Get name of output tensors of model compiled by this session. + +- Returns + + The vector of string as output tensor names in order. + +``` +virtual mindspore::tensor::MSTensor *GetOutputByTensorName(const std::string &tensor_name) const +``` +Get output MindSpore Lite MSTensors of model by tensor name. + +- Parameters + + - `tensor_name`: Define tensor name. + +- Returns + + Pointer of MindSpore Lite MSTensor. + +``` +virtual mindspore::tensor::MSTensor *GetOutputByTensorName(const std::string &tensor_name) const +``` +Get output MindSpore Lite MSTensors of model by tensor name. + +- Parameters + + - `tensor_name`: Define tensor name. + +- Returns + + Pointer of MindSpore Lite MSTensor. + +``` +virtual int Resize(const std::vector &inputs) + +``` +Resize inputs shape. + +- Parameters + + - `inputs`: Define the new inputs shape. + +- Returns + + STATUS as an error code of resize inputs, STATUS is defined in errorcode.h. + +**Static Public Member Functions** + +``` +static LiteSession *CreateSession(lite::Context *context) +``` +Static method to create a LiteSession pointer. + +- Parameters + + - `context`: Define the context of session to be created. + +- Returns + + Pointer of MindSpore Lite LiteSession. + + +## CallBackParam + +CallBackParam defines input arguments for callBack function. + +**Attributes** +``` +name_callback_param +``` +A **string** variable. Node name argument. + +``` +type_callback_param +``` +A **string** variable. Node type argument. \ No newline at end of file diff --git a/lite/docs/source_en/api/model.md b/lite/docs/source_en/api/model.md new file mode 100644 index 0000000000000000000000000000000000000000..abc00be29cb009aff4ba6efd6f00cebd1aba0a9c --- /dev/null +++ b/lite/docs/source_en/api/model.md @@ -0,0 +1,131 @@ +# mindspore::lite +## ModelImpl +ModelImpl defines the implement class of Model in MindSpore Lite. + +## PrimitiveC +Primitive is defined as prototype of operator. + +## Model +Model defines model in MindSpore Lite for managing graph. + +**Constructors & Destructors** +``` +Model() +``` + +Constructor of MindSpore Lite Model using default value for parameters. + +``` +virtual ~Model() +``` + +Destructor of MindSpore Lite Model. + +**Public Member Functions** +``` +PrimitiveC* GetOp(const std::string &name) const +``` +Get MindSpore Lite Primitive by name. + +- Parameters + + - `name`: Define name of primitive to be returned. + +- Returns + + The pointer of MindSpore Lite Primitive. + +``` +const schema::MetaGraph* GetMetaGraph() const +``` +Get graph defined in flatbuffers. + +- Returns + + The pointer of graph defined in flatbuffers. + +``` +void FreeMetaGraph() +``` +Free MetaGraph in MindSpore Lite Model. + +**Static Public Member Functions** +``` +static Model *Import(const char *model_buf, size_t size) +``` +Static method to create a Model pointer. + +- Parameters + + - `model_buf`: Define the buffer read from a model file. + + - `size`: variable. Define bytes number of model buffer. + +- Returns + + Pointer of MindSpore Lite Model. + +**Public Attributes** +``` + model_impl_ +``` +The **pointer** of implement of model in MindSpore Lite. Defaults to **nullptr**. + +## ModelBuilder +ModelBuilder is defined by MindSpore Lite. + +**Constructors & Destructors** +``` +ModelBuilder() +``` + +Constructor of MindSpore Lite ModelBuilder using default value for parameters. + +``` +virtual ~ModelBuilder() +``` + +Destructor of MindSpore Lite ModelBuilder. + +**Public Member Functions** +``` +virtual std::string AddOp(const PrimitiveC &op, const std::vector &inputs) +``` + +Add primitive into model builder for model building. + +- Parameters + + - `op`: Define the primitive to be added. + + - `inputs`: Define input edge of primitive to be added. + +- Returns + + ID of the added primitive. + +``` +const schema::MetaGraph* GetMetaGraph() const +``` +Get graph defined in flatbuffers. + +- Returns + + The pointer of graph defined in flatbuffers. + +``` +virtual Model *Construct() +``` +Finish constructing the model. + +## OutEdge +**Attributes** +``` +nodeId +``` +A **string** variable. ID of a node linked by this edge. + +``` +outEdgeIndex +``` +A **size_t** variable. Index of this edge. \ No newline at end of file diff --git a/lite/docs/source_en/api/ms_tensor.md b/lite/docs/source_en/api/ms_tensor.md new file mode 100644 index 0000000000000000000000000000000000000000..01b4916e6bd3e59bcd3d6305677f690b35d26ace --- /dev/null +++ b/lite/docs/source_en/api/ms_tensor.md @@ -0,0 +1,148 @@ +# mindspore::tensor + +## MSTensor + +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** + +``` +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. + +- Returns + + MindSpore Lite TypeId of the MindSpore Lite MSTensor. + +``` +virtual TypeId set_data_type(TypeId data_type) +``` +Set data type for the MindSpore Lite MSTensor. + +- Parameters + + - `data_type`: Define MindSpore Lite TypeId to be set in the MindSpore Lite MSTensor. + +- Returns + + MindSpore Lite TypeId of the MindSpore Lite MSTensor after set. + +``` +virtual std::vector shape() const +``` + +Get shape of the MindSpore Lite MSTensor. + +- Returns + + A vector of int as the shape of the MindSpore Lite MSTensor. + +``` +virtual size_t set_shape(const std::vector &shape) +``` +Set shape for the MindSpore Lite MSTensor. + +- Parameters + + - `shape`: Define a vector of int as shape to be set into the MindSpore Lite MSTensor. + +- Returns + + Size of shape of the MindSpore Lite MSTensor after set. + +``` +virtual int DimensionSize(size_t index) const +``` + +Get size of the dimension of the MindSpore Lite MSTensor index by the parameter index. + +- Parameters + + - `index`: Define index of dimension returned. + +- Returns + + Size of dimension of the MindSpore Lite MSTensor. + +``` +virtual int ElementsNum() const +``` + +Get number of element in MSTensor. + +- Returns + + Number of element in MSTensor. + +``` +virtual std::size_t hash() const +``` + +Get hash of the MindSpore Lite MSTensor. + +- Returns + + Hash of the MindSpore Lite MSTensor. + +``` +virtual size_t Size() const +``` + +Get byte size of data in MSTensor. + +- Returns + + Byte size of data in MSTensor. + + +``` +virtual void *MutableData() const +``` + +Get the pointer of data in MSTensor. + + +> Note: The data pointer can be used to both write and read data in MSTensor. + +- Returns + + The pointer points to data in MSTensor. + +**Static Public Member Functions** + +``` +static MSTensor *CreateTensor(TypeId data_type, const std::vector &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. + +- Parameters + + - `data_type`: Define the data type of tensor to be created. + + - `shape`: Define the shape of tensor to be created. + +- Returns + + The pointer of MSTensor. \ No newline at end of file diff --git a/lite/docs/source_en/api/vision.md b/lite/docs/source_en/api/vision.md new file mode 100644 index 0000000000000000000000000000000000000000..e9ba66be054e76ce6b5bc4dac4791e51c23ac68d --- /dev/null +++ b/lite/docs/source_en/api/vision.md @@ -0,0 +1,11 @@ +# mindspore::lite + +**Functions** +``` +std::string Version() +``` +Global method to get a version string. + +- Returns + + The version string of MindSpore Lite.