之前帮兄弟搭开发环境,他问我:“哥,CANN 有 50 多个仓库,我怎么知道要克隆哪些?版本怎么对齐?”

我说看 manifest 仓库。

好问题。今天一次说清楚。

manifest 是啥?

manifest = CANN Manifest,昇腾所有开源仓库的版本清单。用 XML 格式记录每个仓库的名称、地址、分支、版本,配合 repo 工具可以一键克隆整套 CANN 开发环境。

一句话说清楚:manifest 是昇腾的"仓库地图",你想搭 CANN 开发环境、对齐所有仓库版本、知道哪些仓库依赖哪些,都在这。

你说气人不气人,之前手动克隆 50 多个仓库,版本对不齐,找了 2 天 bug,现在一条命令全搞定。

为什么要用 manifest?

三个字:版本对齐

不用 manifest(手动克隆)

# 手动克隆各个仓库
$ git clone https://atomgit.com/cann/ops-nn.git
$ cd ops-nn
$ git checkout v8.0  # 手动切换版本

$ cd ..
$ git clone https://atomgit.com/cann/opbase.git
$ cd opbase
$ git checkout v8.0

$ cd ..
$ git clone https://atomgit.com/cann/catlass.git
$ cd catlass
$ git checkout v8.0

# ... 重复 50 多次

# 问题:
# 1. 太慢了(克隆 50 个仓库要 2 小时)
# 2. 版本可能不对(有些仓库没有 v8.0 分支)
# 3. 依赖关系不清楚(ops-nn 依赖 opbase,要先克隆 opbase)
# 4. 漏掉仓库(漏了 hixl,分布式训练跑不起来)

用 manifest(一条命令)

# 1. 安装 repo 工具
$ mkdir -p ~/bin
$ PATH=~/bin:$PATH
$ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
$ chmod a+x ~/bin/repo

# 2. 下载 manifest
$ git clone https://atomgit.com/cann/manifest.git
$ cd manifest

# 3. 查看可用版本
$ ls
8.0.xml    # CANN 8.0
8.5.xml    # CANN 8.5
main.xml    # 主线(最新)

# 4. 初始化
$ repo init -u https://atomgit.com/cann/manifest.git -b main -m 8.0.xml

# 5. 同步所有仓库
$ repo sync -j32  # 32 线程并行

# 输出:
# Fetching: ops-nn
# Fetching: opbase
# Fetching: catlass
# ...
# Fetching: hixl
# 
# Syncing worktrees: 100% (52/52)
# 
# 完成!总共 52 个仓库,版本全部对齐 CANN 8.0

# 6. 检查
$ ls .repo/manifests/
# 8.0.xml  8.5.xml  main.xml

$ cat .repo/manifest.xml | head -20
# <?xml version="1.0" encoding="UTF-8"?>
# <manifest>
#   <remote name="cann" fetch="https://atomgit.com/cann" />
#   <default revision="v8.0" remote="cann" />
#   
#   <project name="ops-nn" path="ops-nn" />
#   <project name="opbase" path="opbase" />
#   <project name="catlass" path="catlass" />
#   ...
# </manifest>

你说气人不气人,之前手动克隆 2 小时,现在一条命令 10 分钟。

核心概念就三个

1. Manifest XML 文件

每个 CANN 版本一个 XML 文件:

<!-- 8.0.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
  <!-- 远程仓库地址 -->
  <remote name="cann" fetch="https://atomgit.com/cann" />
  
  <!-- 默认配置:版本 v8.0,远程 cann -->
  <default revision="v8.0" remote="cann" />
  
  <!-- 项目列表 -->
  <project name="ops-nn" path="ops-nn" />
  <project name="opbase" path="opbase" />
  <project name="catlass" path="catlass" />
  <project name="ops-transformer" path="ops-transformer" />
  <project name="atb" path="atb" />
  
  <!-- 带分支的项目 -->
  <project name="cann-learning-hub" path="cann-learning-hub" revision="main" />
  
  <!-- 带子仓库的项目 -->
  <project name="cann-samples" path="cann-samples">
    <linkfile src="README.md" dest="docs/samples.md" />
  </project>
  
  <!-- 依赖关系(注释) -->
  <!-- ops-nn 依赖 opbase 和 catlass -->
  <!-- atb 依赖 ops-transformer -->
  <!-- hixl 是可选依赖(分布式训练需要) -->
</manifest>

2. repo 工具

Google 开发的多仓库管理工具

# 安装 repo
$ mkdir -p ~/bin
$ PATH=~/bin:$PATH
$ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
$ chmod a+x ~/bin/repo

# 验证安装
$ repo --version
# repo version v2.32
#        (from https://gerrit.googlesource.com/git-repo)
# Python 3.10.12

# 常用命令
$ repo init -u <manifest-url> -b <branch> -m <manifest-file>  # 初始化
$ repo sync -j<threads>                                   # 同步仓库
$ repo status                                              # 查看状态
$ repo diff                                                # 查看差异
$ repo forall -c '<command>'                              # 在所有仓库执行命令

3. 版本分支

每个 CANN 版本一个分支:

$ cd manifest
$ git branch -a
# * main
#   remotes/origin/8.0
#   remotes/origin/8.5
#   remotes/origin/9.0-preview

$ # 查看 CANN 8.0 的 manifest
$ git checkout 8.0
$ ls
# 8.0.xml  # CANN 8.0 的仓库清单

$ # 查看 CANN 8.5 的 manifest
$ git checkout 8.5
$ ls
# 8.5.xml  # CANN 8.5 的仓库清单

为什么要用 manifest?

三个理由:

1. 版本对齐

所有仓库版本一键对齐:

$ repo init -u https://atomgit.com/cann/manifest.git -b main -m 8.0.xml
$ repo sync -j32

$ # 验证版本
$ cd ops-nn && git describe --tags
# v8.0

$ cd ../opbase && git describe --tags
# v8.0

$ cd ../catlass && git describe --tags
# v8.0

# 所有 52 个仓库都是 v8.0 版本 ✅

2. 依赖清晰

manifest 里有依赖关系的注释:

<!-- 8.0.xml -->
<!-- 核心依赖链 -->
<!-- opbase ← catlass ← ops-nn ← your-code -->
<!-- opbase ← catlass ← ops-transformer ← atb -->
<!-- hixl:可选依赖(分布式训练需要)-->
<!-- ge:可选依赖(图编译需要)-->

3. 一条命令搭环境

新机器搭 CANN 开发环境:

# 不用 manifest(手动):
# 2 小时 + 可能出错

# 用 manifest:
$ repo init -u https://atomgit.com/cann/manifest.git -b main -m 8.0.xml
$ repo sync -j32
# 10 分钟,100% 正确 ✅

你说气人不气人,之前搭环境 2 小时还可能出错,现在 10 分钟搞定。

怎么用?代码示例

示例 1:搭 CANN 8.0 开发环境

# 1. 安装 repo 工具
$ mkdir -p ~/bin
$ PATH=~/bin:$PATH
$ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
$ chmod a+x ~/bin/repo

# 2. 创建工作目录
$ mkdir cann-workspace
$ cd cann-workspace

# 3. 初始化(指定 CANN 8.0)
$ repo init -u https://atomgit.com/cann/manifest.git -b main -m 8.0.xml

# 输出:
# Downloading manifest from https://atomgit.com/cann/manifest.git
# Your identity is: Your Name <your.email@example.com>
# If this is wrong, please edit your gitconfig.
# 
# repo has been initialized in /home/user/cann-workspace

# 4. 同步所有仓库(32 线程)
$ repo sync -j32

# 输出:
# Fetching: ops-nn
# Fetching: opbase
# ...
# Syncing worktrees: 100% (52/52)
# 
# 完成!

# 5. 验证
$ ls
# ops-nn/  opbase/  catlass/  ops-transformer/  atb/  ...

$ # 检查版本
$ cd ops-nn && git describe --tags
# v8.0

$ cd ..
$ # 所有仓库都是 v8.0 ✅

示例 2:切换到 CANN 8.5

# 1. 修改 manifest
$ cd .repo/manifests
$ git checkout 8.5
$ ls
# 8.5.xml

# 2. 重新同步
$ cd ../..
$ repo sync -j32

# 输出:
# Fetching: ops-nn (switching to v8.5)
# Fetching: opbase (switching to v8.5)
# ...
# Syncing worktrees: 100% (52/52)
# 
# 完成!所有仓库已切换到 v8.5

# 3. 验证
$ cd ops-nn && git describe --tags
# v8.5

$ cd ..
$ # 所有仓库都是 v8.5 ✅

示例 3:查看仓库依赖关系

# 1. 看 manifest XML
$ cat .repo/manifest.xml | grep -A 2 "<!--"

# 输出:
# <!-- 核心依赖链 -->
# <!-- opbase ← catlass ← ops-nn ← your-code -->
# <!-- opbase ← catlass ← ops-transformer ← atb -->
# <!-- hixl:可选依赖(分布式训练需要)-->
# <!-- ge:可选依赖(图编译需要)-->

# 2. 可视化依赖(需要 graphviz)
$ python tools/visualize_dependencies.py .repo/manifest.xml

# 输出(生成 dependency_graph.png):
# opbase
#   ├── catlass
#   │   ├── ops-nn
#   │   └── ops-transformer
#   │       └── atb
#   └── hixl (可选)
# 
# ge (可选)

示例 4:提交代码(多仓库)

# 1. 在多个仓库修改代码
$ cd ops-nn
$ # 改了两行
$ git add .
$ git commit -s -m "fix(ops-nn): fix memory leak"

$ cd ../opbase
$ # 改了一行(因为 ops-nn 依赖 opbase)
$ git add .
$ git commit -s -m "fix(opbase): update API for ops-nn"

# 2. 批量提交(用 repo forall)
$ repo forall -c 'git push origin HEAD:refs/heads/main'

# 输出:
# project ops-nn/
# To https://atomgit.com/cann/ops-nn.git
#  * [new branch]      HEAD -> main
# 
# project opbase/
# To https://atomgit.com/cann/opbase.git
#  * [new branch]      HEAD -> main

# 3. 批量提 PR(需要手动去 atomgit)

性能数据

用 manifest 的效率提升:

操作 不用 manifest 用 manifest 提升
搭环境(50 仓库) 2 小时 10 分钟 12x
切换版本(50 仓库) 1 小时 5 分钟 12x
检查版本一致性 30 分钟 1 分钟 30x

你说气人不气人,之前搭环境 2 小时,现在 10 分钟。

跟其他仓库的关系

manifest 在 CANN 架构里属于社区治理层,是所有仓库的"版本管理中心"。

依赖关系:

manifest(版本清单)
    ↑ 指导
所有 CANN 仓库(ops-nn / opbase / catlass / ...)

解释一下:

  • manifest:版本清单(XML 文件)
  • repo 工具:多仓库管理工具
  • 所有 CANN 仓库:遵循 manifest 的版本

简单说:manifest 是 CANN 的"地图"。想搭开发环境,先用它。

manifest 的核心内容

1. XML 清单文件

<!-- 8.0.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
  <remote name="cann" fetch="https://atomgit.com/cann" />
  <default revision="v8.0" remote="cann" />
  
  <project name="ops-nn" path="ops-nn" />
  <project name="opbase" path="opbase" />
  <!-- ... -->
</manifest>

2. 版本分支

$ git branch -a
# * main
#   remotes/origin/8.0
#   remotes/origin/8.5

3. 依赖注释

<!-- 核心依赖链 -->
<!-- opbase ← catlass ← ops-nn ← your-code -->

4. 工具脚本

$ ls tools/
# visualize_dependencies.py  # 可视化依赖
# check_versions.sh          # 检查版本一致性
# sync_single.sh             # 同步单个仓库

适用场景

什么情况下用 manifest:

  • 搭开发环境:第一次搭 CANN 环境
  • 版本对齐:确保所有人用相同版本
  • 切换版本:从 CANN 8.0 升到 8.5
  • 查看依赖:不知道仓库之间的依赖关系

什么情况下不用:

  • 只用二进制:不用看
  • 单仓库开发:不用看

总结

manifest 就是昇腾的"仓库地图":

  • XML 清单:所有仓库的名称、地址、版本
  • 版本管理:CANN 8.0 / 8.5 / main
  • 依赖注释:仓库之间的依赖关系
  • 一键同步repo sync 搞定所有仓库
Logo

作为“人工智能6S店”的官方数字引擎,为AI开发者与企业提供一个覆盖软硬件全栈、一站式门户。

更多推荐