# Data Structure

## BM Runtime Library <a href="#bmerr_t" id="bmerr_t"></a>

### bmerr\_t

bmerr\_t is a enum type which enumerates all API returned status. The values are listed as follows.

| Value                      | Description                                  |
| -------------------------- | -------------------------------------------- |
| BM\_SUCCESS                | API call returns successfully                |
| BM\_ERR\_AGAIN             | API call fails due to device not ready       |
| BM\_ERR\_FAILURE           | API call returns general failure             |
| BM\_ERR\_TIMEOUT           | API call fails due to time out               |
| BM\_ERR\_UNINITIALIZED     | API call fails due to device un-initialized  |
| BM\_ERR\_INVALID\_ARGUMENT | API call fails due to invalid argument       |
| BM\_ERR\_NOMEM             | API call fails due to insufficient memory    |
| BM\_ERR\_DATA              | API call fails due to data error             |
| BM\_ERR\_BUSY              | API call fails due to device being busy      |
| BM\_ERR\_NOT\_SUPPORTED    | API call fails due to unsupported parameters |

### bmctx\_t

bmctx\_t is a BM context handle, generated by bm\_init(), released by bm\_exit().

### bmdev\_t

bmdev\_t is a BM device handle, generated by bm\_device\_open(), closed by bm\_device\_close().

### bm\_devinfo\_t

bm\_devinfo\_t is a structure type which describes device info. It includes the following members:

| Value       | Description                                                |
| ----------- | ---------------------------------------------------------- |
| chip        | A enum value describes chip version.                       |
| npu\_num    | A uint32\_t type value describes NPU number.               |
| eu\_num     | A uint32\_t type value describes EU number.                |
| lmem\_size  | A uint32\_t type value describes local memory size.        |
| lmem\_banks | A uint32\_t type value describes local memory bank number. |
| gmem\_size  | A uint32\_t type value describes global memory size.       |

### bmmem\_t

bmmem\_t is a handle which points to BM memory structure. bmmem\_device\_t, bmmem\_host\_t and bmmem\_system\_t are all alias of bmmem\_t.

Define as follow:

```c
struct bm_memory;
typedef struct bm_memory *bmmem_t;
typedef bmmem_t bmmem_device_t;
typedef bmmem_t bmmem_host_t;
```

Normally, bmmem\_device\_t is device memory handle, generated by bmmem\_device\_alloc() function.bmmem\_host\_t is host memory handle, generated by bmmem\_host\_alloc().

### bmnet\_info\_t

bmnet\_info\_t is a structure type which describes BM network’s input info. It includes the following members:

| Value          | Description                                                           |
| -------------- | --------------------------------------------------------------------- |
| batch\_size    | A uint32\_t type value describes batch size.                          |
| weight         | A uint8\_t pointer type value which points to the weight memory.      |
| weight\_size   | A size\_t type value describes weight memory size.                    |
| cmdbuf         | A uint8\_t pointer type value which points to the command buffer.     |
| cmdbuf\_size   | A size\_t type value describes command buffer size.                   |
| neuron\_size   | A size\_t type value describes neuron memory size.                    |
| input\_size    | A size\_t type value describes input memory size.                     |
| output\_offset | A uint64\_t type value describes output neuron offset to neuron base. |
| output\_size   | A size\_t type value describes output neuron size in bytes.           |

Command buffer: command buffer stores instruction streams generated by BMNet using caffe model, and these instruction streams can be executed by TPU processor.

### bmnet\_output\_info\_t

bmnet\_output\_info\_t is a structure type which describes BM network’s output info. It includes the following members:

| Value            | Description                                                      |
| ---------------- | ---------------------------------------------------------------- |
| output\_size     | Total output size of inference.                                  |
| output\_num      | Output number.                                                   |
| name\_array      | Array of pointers to the output names                            |
| shape\_array     | Array of pointers to the output shapes                           |
| threshold\_array | Array of pointers to the output threshold（meaningless on BM1682） |

### bmnet\_t

bmnet\_t is a BMNet context handle, generated by bmnet\_register\_bmodel(), released by bmnet\_cleanup().
