# Installation

## Get BMNNSDK  <a href="#get-bmnnsdk" id="get-bmnnsdk"></a>

You can freely downloaded the BMNNSDK installation package at BitMian website <https://sophon.cn/drive/35.html> or：

```bash
git clone https://github.com/BM1880-BIRD/bm1880-bmnnsdk-usb.git
```

BM1880 supports three types of run mode, they are USB mode, Cmodel and SoC mode, and we provide compression package, installation package and docker image for each of them.

* Compression package: you can unzip and install manually, making it easy to debug and install.
* Installation package: one-click installation, regardness of installation details.
* Docker image：you can use it directly without changing the host environment.(only for usb mode)

You can choose one that suits your need and download.

* USB Compression package：bmtap2-bm1880-usb\_x.y.z.tar.gz

### Contents <a href="#contents" id="contents"></a>

BMNNSDK installation package contains driver, runtime library, header, tools and example codes.

```bash
BMNNSDK
   |-- bin          // related tools
   |-- documents    // related documents
   |-- include      // runtime library headerfile, for secondary development
   |-- lib          // runtime library, for runtime and secondary development
   |-- driver       // device driver
   |-- test         // test program
   |-- example      // example code
   |-- python       // Python api
|-- install.sh
|-- uninstall.sh
```

## BMNNSDK installation <a href="#bmnnsdk-installation" id="bmnnsdk-installation"></a>

We support three types of runtime mode for 1880, they are Cmodel, USB and SoC mode, we will describe how to install and test the SDK for each mode as follow.

### USB Mode <a href="#usb-mode" id="usb-mode"></a>

In USB mode, BMNNSDK is installed on the X86 host, and calling chip’s computing for deep learning, the environment requirement are as follows.

* Hardware environment: X86 host with usb, BM1880 Neural Network Stick.
* Operating system: Ubuntu/CentOS.
* Package: dkms、libgoogle-glog-dev、libboost-all-dev、libprotobuf-dev, libusb.
* Ubuntu 16.04 is recommended, you can execute below commands to install package.

```bash
$ sudo apt-get install dkms libgoogle-glog-dev libboost-all-dev libprotobuf-dev
```

Please execute below commands to install package on CentOS（>=7.2）host.

#### Compression package <a href="#compression-package" id="compression-package"></a>

Compression package include installation script, please copy the compression package to x86, unzip and execute the script install.sh.

```bash
$ tar zxvf bmtap2-bm1880-usb-x.y.z.tar.gz
$ cd bmtap2-bm1880-usb-x.y.z
$ sudo ./install.sh
```

The script will install the BMNNSDK to default directory: /opt/bmtap2, and Symbolic Link will be created in the system content, it also will automatically compile and load the BM1880’s USB device by DKMS, which will drive the bmdnn.ko:

```bash
// you will see the installation folder in the/opt/bmtap2 after successful installation
$ ls /opt/bmtap2

// symbolic link will be found in /usr/bin、/usr/lib、/usr/include
$ ls -alh /usr/bin/bm*
$ ls –alh /usr/lib/bm*  
$ ls –alh /usr/include/bmtap2

// use lsmod to find driver information
$ lsmod | grep bmdnn
bmdnn

// if the host has BM1880 NNS，you will find device fold in the directory/dev
$ ls /dev/bm*
/dev/bm180-dev0
```

To uninstall the BMNNSDK ,simply execute the uninstall script in the installation directory.

```bash
$ sudo /opt/bmtap2/bm1880-usb-x.y.z/uninstall.sh
```

#### Installation package <a href="#installation-package" id="installation-package"></a>

Installation package is a self-extracting file that can be run directly. Please copy the installation package to x86 host and run it.

```bash
$ chmod +x bmtap2-bm1880-usb_x.y.z.run
$ sudo ./bmtap2-bm1880-usb -x.y.z.run
```

The installation package will install the BMNNSDK to default directory: /opt/bmtap2, and Symbolic Link will be created in the system content, it also will automatically compile and load the BM1880’s USB device by DKMS, which will drive the bmdnn.ko:

```bash
// you will see the installation folder in the directory /opt/bmtap2 after successful installation
$ ls /opt/bmtap2

// symbolic link will be found in /usr/bin、/usr/lib、/usr/include
$ ls -alh /usr/bin/bm*
$ ls –alh /usr/lib/bm*  
$ ls –alh /usr/include/bmtap2

// use lsmod to find driver information
$ lsmod | grep bmdnn
bmdnn

// if the host has BM1880 NNS, you will find the device file in the /dev directory

$ ls /dev/bm*
/dev/bm1880-dev0
```

To uninstall the BMNNSDK ,simply execute the uninstall script in the installation directory.

```bash
$ sudo /opt/bmtap2/bm1880- pcie-x.y.z/uninstall.sh
```

### SoC Mode <a href="#soc-mode" id="soc-mode"></a>

In SoC mode, BMNNSDK is installed on the BM1880 Developer Board, use the compluting resources on the BM1880 SoC board to accelerate the deep learning calculation, the environment requirements are as follows.

* Hardware environment：BM1880 SoC board
* Operating system：BM1880 Linux Release

#### Compression package <a href="#compression-package-1" id="compression-package-1"></a>

Compression package contains the installation script, please copy it to the SoC board, unzip and execute the script install.sh in the directory.

```
$ tar zxvf bmtap2-bm1880-SoC-x.y.z.tar.gz
$ cd bmtap2-bm1880-SoC-x.y.z
$ sudo ./install.sh
```

The script will install the BMNNSDK to default directory: /opt/bmtap2, and Symbolic Link will be created in the system content, it also will load the BM1880’s TPU driver by insmod, which will drive the bmdnn.ko:

```bash
// you will see the installation folder in the/opt/bmtap2 after successful installation

$ ls /opt/bmtap2

// symbolic link will be found in /usr/bin、/usr/lib、/usr/include
$ ls -alh /usr/bin/bm*
$ ls –alh /usr/lib/bm*  
$ ls –alh /usr/include/bmtap2

// use lsmod to find driver information
$ lsmod | grep bmnpu
bmnpu

// you will find device file in the /dev directory
$ ls /dev/bm*
/dev/bm-npu
```

To uninstall the BMNNSDK ,simply execute the uninstall script in the installation directory.

```
$ sudo /opt/bmtap2/bm1880-SoC-x.y.z/uninstall.sh
```

#### Installation package <a href="#installation-package-1" id="installation-package-1"></a>

Installation package is a self-extracting file that can be run directly. Please copy the installation package to BM1880 SoC board and run it.

```bash
$ chmod +x bmtap2-bm1880-SoC_x.y.z.run
$ sudo ./bmtap2-bm1880-SoC-x.y.z.run
```

The installation package will install the BMNNSDK to default directory: /opt/bmtap2, and Symbolic Link will be created in the system directory, it also will load the BM1880’s TPU device by insmod, which will drive the bmdnn.ko:

```bash
// you will see the installation folder in the directory /opt/bmtap2 after successful installation
$ ls /opt/bmtap2

// symbolic link will be found in /usr/bin、/usr/bin、/usr/include

$ ls -alh /usr/bin/bm*
$ ls –alh /usr/lib/bm*  
$ ls –alh /usr/include/bmtap2

// use lsmod to find driver information
$ lsmod | grep bmnpu
bmnpu

// you will find the device file in the /dev directory
$ ls /dev/bm*
/dev/bm-npu
```

To uninstall the BMNNSDK ,simply execute the uninstall script in the installation directory.

```bash
$ sudo /opt/bmtap2/bm1880- SoC-x.y.z/uninstall.sh
```

### CModel <a href="#cmodel" id="cmodel"></a>

In CModel, BMNNSDK use the host’s CPU for deeplearning compulting, you can use the BMNNSDK or develop the BMNNSDK application without BM1880 device. And the environment requirements are as follows:

* Hardware：X86 host
* Operating：Ubuntu/CentOS
* Software package：libgoogle-glog-dev、libboost-all-dev、libprotobuf-dev

```bash
$ sudo apt-get install libgoogle-glog-dev libboost-all-dev libprotobuf-dev
```

#### Compression package <a href="#compression-package-2" id="compression-package-2"></a>

Compression package contains the installation script, please copy it to the x86 host, unzip and execute the script install.sh in the directory.

```bash
$ tar zxvf bmtap2-bm1880-cmodel-x.y.z.tar.gz
$ cd bmtap2-bm1880- cmodel-x.y.z
$ sudo ./install.sh
```

The script will install the BMNNSDK to default directory: /opt/bmtap2, and Symbolic Link will be created in the system content.

```bash
// you will see the installation folder in the/opt/bmtap2 after successful installation

$ ls /opt/bmtap2

// symbolic link will be found in /usr/bin、/usr/lib、/usr/include
$ ls -alh /usr/bin/bm*
$ ls –alh /usr/lib/bm*  
$ ls –alh /usr/include/bmtap2
```

To uninstall the BMNNSDK ,simply execute the uninstall script in the installation directory.

```
$ sudo /opt/bmtap2/bm1880-cmodel-x.y.z/uninstall.sh
```

#### Installation package <a href="#installation-package-2" id="installation-package-2"></a>

Installation package is a self-extracting file that can be run directly. Please copy the installation package to x86 host and run it.

```bash
$ chmod +x bmtap2-bm1880-cmodel_x.y.z.run
$ sudo ./bmtap2-bm1880- cmodel -x.y.z.run
```

The installation package will install the BMNNSDK to default directory: /opt/bmtap2, and Symbolic Link will be created in the system directory.

```bash
// you will see the installation folder in the directory /opt/bmtap2 after successful installation
$ ls /opt/bmtap2

// symbolic link will be found in /usr/bin、/usr/bin、/usr/include
$ ls -alh /usr/bin/bm*
$ ls –alh /usr/lib/bm*  
$ ls –alh /usr/include/bmtap2
```

To uninstall the BMNNSDK ,simply execute the uninstall script in the installation directory.

```
$ sudo /opt/bmtap2/bm1880- cmodel-x.y.z/uninstall.sh
```
