# mlu-ops
**Repository Path**: Frankd35/mlu-ops
## Basic Information
- **Project Name**: mlu-ops
- **Description**: Efficient operation implementation based on the Cambricon Machine Learning Unit (MLU) .
- **Primary Language**: C++
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 4
- **Created**: 2023-12-27
- **Last Updated**: 2025-01-23
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
[](https://github.com/Cambricon/mlu-ops/actions/workflows/ci.yaml)
[](https://github.com/Cambricon/mlu-ops/blob/master/LICENSE)


## 简介
MLU-OPS™提供基于寒武纪人工智能单元(MLU),使用 C 接口开发高性能算子的示例代码。
MLU-OPS™旨在通过提供示例代码,供开发者参考使用,可用于开发自定义算子,实现对应模型的计算。
MLU-OPS™提供了以下功能:
- [算子精度标准](https://github.com/Cambricon/mlu-ops/blob/master/docs/MLU-OPS-Accuracy-Acceptance-Standard.md)
- [算子性能标准](https://github.com/Cambricon/mlu-ops/blob/master/docs/MLU-OPS-Performance-Acceptance-Standard.md)
- [Op List (高质量实现 BANG C 算子)](https://github.com/Cambricon/mlu-ops/blob/master/docs/MLU-OPS-OpList.md)
- [CNNL基础算子使用](https://github.com/Cambricon/mlu-ops/blob/master/docs/MLU-OPS-How-To-Use-CNNL-API.md)
- [测试模块 GTest](https://github.com/cambricon/mlu-ops/blob/master/docs/GTest-User-Guide-zh.md) 支持 [内存泄露测试](https://github.com/cambricon/mlu-ops/blob/master/docs/GTest-User-Guide-zh.md#6-%E5%86%85%E5%AD%98%E6%B3%84%E6%BC%8F%E6%A3%80%E6%B5%8B)、[代码覆盖率测试](https://github.com/cambricon/mlu-ops/blob/master/docs/GTest-User-Guide-zh.md#7-%E4%BB%A3%E7%A0%81%E8%A6%86%E7%9B%96%E7%8E%87)
- [Gen-case (运行时测例生成工具)](https://github.com/Cambricon/mlu-ops/blob/master/docs/Gencase-User-Guide-zh.md)
- [Perf-Analyse (算子性能分析工具)](https://github.com/Cambricon/mlu-ops/tree/master/tools/perf_analyse#readme)
## 依赖条件
- 操作系统:
- 支持 x86_64 架构下的 Ubuntu20.04、Centos7.6、Centos8.5、Kylin10
- MLU-OPS v1.0.0版本后将不再支持 Ubuntu18.04。Ubuntu22.04系统将在后续的版本提供支持。
- 寒武纪 MLU SDK:
- 编译和运行时依赖 CNToolkit v3.8.4 或更高版本,CNNL v1.23.2 或者更高版本
- 寒武纪 MLU 驱动:
- 运行时依赖驱动 v5.10.25 或更高版本
- 外部链接库:
- libxml2-dev、libprotobuf-dev、protobuf-compiler、llvm-6.0-dev、libeigen3-dev>=3.4
- Python环境:
- 依赖Python-3版本(默认版本 python 3.8.0,最低要求 python 3.6.0)
## 依赖环境准备
- 获取 MLU-OPS™ 代码
以Ubuntu20.04版本为例
```sh
git clone https://github.com/Cambricon/mlu-ops.git
cd mlu-ops
git submodule update --init --recursive
```
- 准备 CNToolkit、CNNL 环境
```sh
wget https://sdk.cambricon.com/static/Basis/MLU370_X86_ubuntu20.04/cntoolkit_3.8.4-1.ubuntu20.04_amd64.deb
wget https://sdk.cambricon.com/static/Basis/MLU370_X86_ubuntu20.04/cnnl_1.23.2-1.ubuntu20.04_amd64.deb
sudo apt-get install ./cntoolkit-3.8.4-1.ubuntu20.04_amd64.deb
sudo apt-get update
sudo apt-get install cncc cnas cnbin cndrv cndev cnrt cnrtc cngdb cnperf
sudo apt-get install ./cnnl_1.23.2-1.ubuntu20.04_amd64.deb
```
- 准备 Python-3.8.0 环境
```sh
wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz
tar -xvf Python-3.8.0.tgz
cd Python-3.8.0
make -j24 && make install
- 准备链接库环境
```sh
sudo apt-get update
sudo apt-get install protobuf-compiler libxml2-dev libprotobuf-dev llvm-6.0-dev
```
## 获取关于 BANG 语言基础和开发相关工具介绍的文档
可查看最新版 [开发者文档](https://developer.cambricon.com/index/document/index/classid/3.html)
- [BANG C/C++ 编程指南](https://www.cambricon.com/docs/sdk_1.13.0/cntoolkit_3.5.2/programming_guide_1.5.0/index.html)
- [BANG C Developer Guide](https://www.cambricon.com/docs/sdk_1.13.0/cntoolkit_3.5.2/cambricon_bang_c_4.5.1/index.html)
- [CNNL Developer Guide](https://www.cambricon.com/docs/sdk_1.15.0/cambricon_cnnl_1.21.1/developer_guide/index.html)
- [MLU 架构调优指南](https://www.cambricon.com/docs/sdk_1.13.0/cntoolkit_3.5.2/cntoolkit_tuning_0.4.1/index.html)
- [CNRT Developer Guide](https://www.cambricon.com/docs/sdk_1.13.0/cntoolkit_3.5.2/cnrt_6.5.2/index.html)
- [CNRTC Developer Guide](https://www.cambricon.com/docs/sdk_1.13.0/cntoolkit_3.5.2/cambricon_cnrtc_0.6.0/index.html)
- [CNDrv Developer Guide](https://www.cambricon.com/docs/sdk_1.13.0/cntoolkit_3.5.2/cndrv_2.5.2/index.html)
- [CNGDB Developer Guide](https://www.cambricon.com/docs/sdk_1.13.0/cntoolkit_3.5.2/cngdb_3.5.0/index.html)
- [Libdevice Developer Guide](https://www.cambricon.com/docs/sdk_1.13.0/cntoolkit_3.5.2/libdevice_4.5.1/index.html)
## 目录文件结构
| 目录/文件 | 描述 |
| ------------------------ | -------------------------------------- |
| [cmake](cmake) | 存放编译相关的 make 文件。 |
| [core](core) | 存放公共数据类型的操作、运行时管理、日志等公共实现。|
| [docker](docker) | 存放 docker 打包脚本,提供 CI 构建环境。 |
| [docs](docs) | 存放算子开发、测试、精度验收等说明文档。 |
| [kernels](kernels) | 算子代码实现,包含一元、二元算子模板供其他算子调用。 |
| [test](test) | 存放测试算子用的代码。 |
| [mlu_op.h](mlu_op.h) | 公共数据类型描述,以及 kernels 目录中的算子对外提供的 C 接口。 |
## 编译、开发与测试
提供基于寒武纪人工智能单元(MLU)开发高性能算子、C 接口封装的示例代码。
具体的编译、开发与测试介绍见 [MLU-OPS™算子编译、开发与测试介绍.md](docs/MLU-OPS-Compile-Develop-And-Test.md)。
更多内容见 docs 目录下文档。