Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: Excuter/cppcommon Build
on:
push:
paths:
- 'executor/cpp-common/**'
- 'executor/deepxcore/**'
pull_request:
paths:
- 'executor/cpp-common/**'
- 'executor/deepxcore/**'
env:
HIGHWAY_VERSION: 1.2.0

Expand Down Expand Up @@ -48,16 +48,16 @@ jobs:
uses: actions/cache@v3
with:
path: |
executor/cpp-common/build
executor/deepxcore/build
~/.ccache
key: ${{ runner.os }}-build-${{ hashFiles('**/CMakeLists.txt') }}
restore-keys: |
${{ runner.os }}-build-

# 构建 cpp-common
- name: Build Common Library
# 构建 deepxcore
- name: Build deepx core Library
run: |
cd executor/cpp-common
cd executor/deepxcore
mkdir -p build && cd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER_LAUNCHER=ccache ..
cmake --build . --config Release -j$(nproc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: op/cuda-linux Build
on:
push:
paths:
- 'executor/mem-cuda/**'
- 'executor/heapmem-cuda/**'
pull_request:
paths:
- 'executor/mem-cuda/**'
- 'executor/heapmem-cuda/**'
env:
CUDA_VERSION: "12.9.1"
CUDA_MAJOR_VERSION: "12"
Expand Down Expand Up @@ -69,7 +69,7 @@ jobs:

# 构建 CUDA 执行器
apt install -y libhiredis-dev && \
cd ../../mem-cuda && \
cd ../../heapmem-cuda && \
mkdir -p build && cd build && \
cmake -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/executor-op-cuda-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ jobs:
cp -r include/* /usr/local/include/ && \
cd /workspace && \

# 构建 common
cd executor/cpp-common && \
# 构建 deepxcore
cd executor/deepxcore && \
mkdir -p build && cd build && \
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -GNinja .. && \
ninja && \
Expand All @@ -72,9 +72,7 @@ jobs:
mkdir -p build && cd build && \
cmake -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda \
-DCMAKE_CUDA_ARCHITECTURES=\"60;70;75;80;86\" \
-DCUTLASS_DIR=/usr/local \
-GNinja .. && \
ninja
"
15 changes: 6 additions & 9 deletions .github/workflows/executor-op-ompsimd-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ jobs:
uses: actions/cache@v3
with:
path: |
executor/op-mem-ompsimd/build
executor/cpp-common/build
executor/op-ompsimd/build
executor/deepxcore/build
~/.ccache
key: ${{ runner.os }}-build-${{ hashFiles('**/CMakeLists.txt') }}
restore-keys: |
Expand All @@ -58,9 +58,6 @@ jobs:
# Highway 库安装
- name: Install Highway (Ubuntu)
run: |
# 安装依赖
sudo apt-get install -y libgtest-dev

# 克隆 Highway
git clone --depth 1 --branch ${HIGHWAY_VERSION} https://github.com/google/highway.git
cd highway
Expand All @@ -81,18 +78,18 @@ jobs:
# 确保头文件正确安装
sudo cp -r ../hwy /usr/local/include/

# 构建 cpp-common
- name: Build Common Library
# 构建 deepxcore
- name: Build deepxcore Library
run: |
cd executor/cpp-common
cd executor/deepxcore
mkdir -p build && cd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER_LAUNCHER=ccache ..
cmake --build . --config Release -j$(nproc)

# 构建执行器
- name: CMake Build
run: |
cd executor/op-mem-ompsimd
cd executor/op-ompsimd
mkdir -p build && cd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER_LAUNCHER=ccache ..
cmake --build . --config Release -j$(nproc)
101 changes: 42 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,81 +1,64 @@
# deepx

## 一.deepx概述
deepx一种以IR计算图为核心的原生分布式自动并行的训推一体化的深度学习框架,以IR计算图为核心,经过多层级等价替换,实现从简单的数学形式的计算图,自适应等价替换为分布式、并行、自动反向的工程系统架构
deepx一种以统一存算面为底座的深度学习计算框架,模型函数可以通过简单的数学形式进行表达为计算图,计算图可以写入到统一存算面的存储空间,被统一存算面的调度执行器自动执行,你也可以按照统一存算面的协议,实现自己的执行器,例如dataloader的数据处理执行器是训练用户必须自己实现的

deepx的分前中后端,分别是为前端表达侧,编译替换调度层,执行器层,遵守严格的进程间与代码组件的隔离,以保证分工明确,架构长久稳定。
## 二.前端与统一存算面

+ 前端/模型表达侧,交由算法工程师、用接近数学的表达方式,设计其数学计算过程。只表示为单线程的简洁数学表达过程,不涉及复杂的device类型、分布式等。
+ 中端:编译替换与分布式调度层:注册了多轮不同类型的IR编译器,实现等价替换,可以以插件的形式增加自定义能力如定制kvcache,实现对计算图进行局部替换,获得新的能力。
+ 执行器层:绑定具体的加速硬件,实现真正的tensor的储存、计算、网络通信,大规模并行化。
deepx可以划分为前端与统一存算面(中端与后端),分别是为

+ 前端
* 模型表达api
* 统一存算面sdk
+ 统一存算面
中端:编译替换调度层。对数学表达式进行等价编译替换,以匹配最优的后端kernel。
后端:执行器层:遵守严格的进程间与代码组件的隔离,以保证分工明确,架构长久稳定。

### 前端
### 前端-模型表达侧
面向算法工程师、用接近数学的表达方式,设计其数学计算过程。只表示为单线程的简洁数学表达过程。不容许涉及复杂的device类型、分布式概念等。
tensor相关的函数表达式,和pytorch/numpy的api风格接近
deepx前端会输出计算图的IR序列,传递给统一存算面

python sdk提供接近pytorch的API
也容许其他语言的sdk接入,
### 前端-统一存算面sdk
面向算法和infra工程师,可以通过deepx存算协议标准,实现自己的调度器、执行器。
dataloader程序负责向存算面注册新的input tensor序列,因此依赖deepx sdk

+ IR通信调度。不同于pytorch或其他py+bind c++这种单一进程的栈上函数调度执行的方式。deepx各个程序(如front的python sdk,back的计算图编译器优化器、executor如ompsimd)之间,通过IR实现网络通信调度,需要各自启动对应进程
### 统一存算面:通过统一的kv寻址空间,组织分散的gpu算力与tensor

统一存算面可以被看作一个原生的分布式tensor计算解释器。
统一存算面把分布式的gpu集群,抽象为统一的计算与存储平面,具体而言,就是存储了tensor元信息、计算图。但存算面本身,目前只利用了redis的kv功能。tensor的真正存储依然在gpu显存、内存、磁盘上,真正的计算,也是由执行器进程通过gpu/cpu去进行计算。但统一存算面的作用在于,抽象了tensor相关的计算图与存储表示,为tensor编程,开辟了新的上层表达语言,从而可以完全和复杂的底层工程代码隔离。

| 维度 | PyTorch类框架 | DeepX |
|--------------|-----------------------|-------------------------|
| 执行模式 | 单进程内函数栈调度 | 多进程分布式协同 |
| 通信方式 | 内存直接访问 | IR网络计算调度协议交换 |
| 组件耦合度 | 紧耦合(Python绑定C++)| 松耦合|
| tensor生命周期管理 | 由python侧控制 | 由deltensor这个IR指令,显示管理tensor|

### 中端:编译替换与分布式调度层
+ 统一寻址空间
* 当前采用redis存储tensor元信息,配合heapmem进程,负责管理堆tensor的生命周期。

+ 调度层:编译替换与分布式调度层:注册了多轮不同类型的IR编译器,实现等价替换,可以以插件的形式增加自定义能力如定制kvcache,实现对计算图进行局部替换,获得新的能力。
* 算子注册: 收集当前已就绪的执行器的算子列表,收集算子时耗和存储占用信息。计算图编译器优化器:fusion算子,计算图节点消除,自动生成tensor拆分并行的计算子图并替代原节点
* 反向传播推导引擎:深度学习模型,如pytorch框架,通常只需要定义模型前向过程,反向的计算图是通过pytorch自动实现的。deepx同理。
* 执行调度器:负责数据并行,流水线并行(前向反向并行),模型并行

+ 注册中心:收集当前已就绪的执行器的算子列表,收集算子时耗和空间占用信息
+ 计算图编译器优化器:fusion算子,计算图节点消除,自动生成tensor拆分并行的计算子图并替代原节点
+ 执行调度器:数据并行,流水线并行(前向反向并行),模型并行。
+ front生成基础IR,编译器负责进行fusion成executor注册的高级算子。
+ 执行器层:绑定具体的加速硬件,实现真正的tensor的储存、计算、网络通信,大规模并行化。
* heapmem-cuda:实现了nv平台的tensor生命周期管理,是统一寻址空间中的tensor的具体实现。
当我们在统一寻址空间删除一个key对应的tensor,实际的tensor会通过heapmem-cuda进程进行删除,创建同理。
heapmem管理的tensor,通常是持久的权重,可能被很多个不同进程访问,。
相对应的,随着函数执行完毕自动回收的中间变量tensor,可以被称之为stacktensor,这些tensor交给op进程自行管理。
* op-cuda:实现了nv平台的常用基础算子。[cuda](docs/executor/op-mem-cuda/list.md)

## 三.deepx T程序与cpu程序

### 执行层
为了把gpu上的tensor计算过程,区别于传统cpu上的程序,我们为tensor的分布式计算,定义一个新概念————T程序

执行层包括op和mem两种执行器,但实际实现时,当前只设计了一个程序同时负责op和mem的管理。
概念比较

负责低级的算子计算操作,以IR为执行的核心单元
```
Op{args(args_grad),returns(returns_grad)|func run}
```
|cpu程序| T程序 |
|---|---|
|数据区、代码区|kv存储管理|
|上层程序设:func和struct| deepxIR和tensor|
|cpu执行底层机器码/字节码| deepx执行器执行deepxIR|
|存储-堆 |kv存储tensor元信息,heapmem管理gpu、内存上的tensordata|
|线程栈|计算进程自行管理|

Op需要实现run方法

关于executor,只要能按deepxIR序列执行,并返回结果,就可以接入deepx分布式调度框架,因此,从硬件、指令、加速库、高级框架包括训练、推理引擎,都可以稍作修改,就接入deepx体系。

当前的


#### 默认执行器
+ cpu执行器,已实现ompsimd。其支持的算子列表[ompsimd](docs/executor/op-mem-ompsimd/list.md)

#### GPU执行器
+ cuda执行器,其支持的算子列表[cuda](docs/executor/op-mem-cuda/list.md)

欢迎大家提交cuda代码

+ rocm
+ apple
+ 其他硬件加速器

#### 张量计算框架or函数级执行器

DeepX可以集成现有的张量计算框架作为执行器,充分利用现有生态系统的优化能力:

+ jax:
- 结合DeepX的分布式调度,使JAX代码自动获得分布式执行能力
- 支持异构设备(GPU/TPU)加速的同时保持DeepX的分布式弹性扩展

+ LibTorch/aten:
- 可将PyTorch生态系统的算子作为DeepX执行器
- 利用ATEN底层优化的同时享受DeepX分布式调度的优势

这种架构使得DeepX可以整合各类先进的计算框架作为执行引擎,同时提供统一的分布式调度和执行能力,为用户提供更灵活的选择和更高的性能。


### 官方文档

[https://deepx.array2d.com](https://deepx.array2d.com)
Expand Down
12 changes: 0 additions & 12 deletions executor/cpp-common/test/CMakeLists.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.15...3.29)
project(deepx-common LANGUAGES CXX )
project(deepxcore LANGUAGES CXX )

# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 17)
Expand All @@ -14,10 +14,10 @@ include_directories(src)

# 源文件

file(GLOB_RECURSE DEEPX_COMMON_SOURCES "src/*.cpp")
file(GLOB_RECURSE DEEPX_CORE_SOURCES "src/*.cpp")

add_library(deepx_common SHARED
${DEEPX_COMMON_SOURCES}
add_library(deepxcore SHARED
${DEEPX_CORE_SOURCES}
)


Expand All @@ -30,9 +30,9 @@ else()
set(YAMLCPP_LIB yaml-cpp)
endif()

target_link_libraries(deepx_common PUBLIC ${YAMLCPP_LIB})
target_link_libraries(deepxcore PUBLIC ${YAMLCPP_LIB})

target_include_directories(deepx_common PUBLIC
target_include_directories(deepxcore PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:include>
)
Expand Down
File renamed without changes.
12 changes: 12 additions & 0 deletions executor/deepxcore/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

add_executable(test_dtypes 0_dtypes.cpp)
target_link_libraries(test_dtypes deepxcore)

add_executable(test_tf 1_tf.cpp)
target_link_libraries(test_tf deepxcore)

add_executable(test_tfcheck 1_tfcheck.cpp)
target_link_libraries(test_tfcheck deepxcore)

add_executable(test_saveload 2_saveload.cpp)
target_link_libraries(test_saveload deepxcore)
File renamed without changes.
38 changes: 33 additions & 5 deletions executor/mem-cuda/README.md → executor/heapmem-cuda/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# mem-cuda 方案草案
# heapmem-cuda 方案草案

本目录用于设计/实现单机多进程的 GPU Tensor 统一存储面(CUDA IPC),并通过 Redis 做 name → IPC handle 的集中注册与控制。

Expand All @@ -20,7 +20,7 @@
- `bytes`: int
- `ipc_handle`: binary
- `refcount`: int
无需设计tensor owner


### 2) Redis 指令队列(List)
控制通道 list key: `tensor_lifecycle`。
Expand All @@ -39,20 +39,29 @@
- 仅限同机;需保证 device id 一致
- 跨 stream 写读需要显式同步(事件/流同步策略)

## 显存池方案
## 是否有必要使用显存池

显存池通常用于子分配(suballoc),子分配和cuda ipc存在冲突。

堆tensor不会高频alloc/free

但是,计算进程的栈tensor必须使用,现在有以下2个选项

- **RMM (RAPIDS Memory Manager)**
**RMM (RAPIDS Memory Manager)**
- 优点:成熟、支持 pool/async allocator、统计完善
- 适合:对稳定性与可观察性要求高的生产环境

其他op计算进程可以使用CUB。
**CUB**

## 目录结构(具体方案)
```
mem-cuda/
README.md
doc/
src/
registry/
init.h #进程初始化时,向redis注册当前节点、节点所有gpu、和gpu显存大小
cudastream.h # cudastream流和redis的list(lifecycle指令)结合
ipc/ # CUDA IPC 封装
ipc.h
ipc.cpp
Expand All @@ -74,6 +83,25 @@ mem-cuda/
- `runtime/`: 指令消费/路由与跨 stream 同步策略。
- `common/`: 状态码、JSON 解析、日志等公共工具聚合。


### 架构图
``` mermaid
graph LR
subgraph 单机
RM["Redis (元数据 + 指令队列)"]
HMC["heapmem-cuda 进程"]
CP["计算进程 (多进程)"]
GPU["GPU"]
end

HMC -->|注册/读写 Hash| RM
CP -->|读写/推送 指令 list| RM
HMC -->|cudaMalloc / cudaIpcGetMemHandle| GPU
CP -->|cudaIpcOpenMemHandle| GPU
HMC -->|管理 ipc_handle / GC| CP
HMC -->|流/同步策略| GPU
```

## 后续工作清单(分阶段)
- [ ] 阶段 0:确定目录与接口(完成本 README 细化)
- [ ] 阶段 1:实现 `lifecycle/`
Expand Down
4 changes: 2 additions & 2 deletions executor/op-cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ include_directories(src)
# include_directories(${cutlass_SOURCE_DIR}/tools/util/include)


add_subdirectory(../cpp-common common) # 包含公共模块
add_subdirectory(../deepxcore deepxcore) # 包含公共模块

# 源文件
file(GLOB_RECURSE DEEPX_SOURCES "src/deepx/*.cpp" "src/deepx/*.cu" "src/deepx/*.cuh")
Expand All @@ -53,7 +53,7 @@ add_library(deepx SHARED

target_link_libraries( deepx
PUBLIC
deepx_common
deepxcore
yaml-cpp
CUDA::cublas
)
Expand Down
File renamed without changes.
File renamed without changes.
Loading
Loading