Skip to content
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
69 changes: 69 additions & 0 deletions .github/workflows/enflame-build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Enflame-Build-And-Test

on:
push:
branches: [ "triton_v3.3.x" ]
pull_request:
branches: [ "triton_v3.3.x" ]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
enflame-build-and-test:
runs-on: enflame
if: ${{ github.repository == 'FlagTree/flagtree' || github.repository == 'flagos-ai/flagtree' }}
steps:
- name: Setup environment
shell: bash
run: |
source ~/env.sh
env | grep -E '^(http_proxy|https_proxy|all_proxy|no_proxy)=' >> $GITHUB_ENV || true

- name: Checkout code (attempt 1)
id: checkout1
uses: actions/checkout@v5
continue-on-error: true

- name: Sleep before checkout2
if: steps.checkout1.outcome == 'failure'
run: |
echo "First checkout attempt failed. Sleeping for 120 seconds before retry..."
sleep 120

- name: Checkout code (attempt 2)
id: checkout2
if: steps.checkout1.outcome == 'failure'
uses: actions/checkout@v5
continue-on-error: true

- name: Sleep before final checkout
if: steps.checkout1.outcome == 'failure' && steps.checkout2.outcome == 'failure'
run: |
echo "Second checkout attempt failed. Sleeping for 180 seconds before final retry..."
sleep 180

- name: Checkout code (final attempt)
if: steps.checkout1.outcome == 'failure' && steps.checkout2.outcome == 'failure'
uses: actions/checkout@v5

- name: Verify checkout success
if: success()
run: echo "Checkout completed successfully"

- name: FlagTree Build on Enflame
shell: bash
run: |
set -x
pip uninstall -y triton
pip uninstall -y triton_gcu
export FLAGTREE_BACKEND=enflame
cd python
MAX_JOBS=32 python3 -m pip install . --no-build-isolation

- name: FlagTree Test on Enflame
shell: bash
run: |
set -x
python3 -m pytest -s third_party/enflame/python/test/unit
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ include_directories(${PROJECT_SOURCE_DIR}/third_party)
include_directories(${PROJECT_BINARY_DIR}/third_party) # Tablegen'd files

# link_directories(${LLVM_LIBRARY_DIR})
if (FLAGTREE_BACKEND MATCHES "^(cambricon|aipu|tsingmicro)$")
if (FLAGTREE_BACKEND MATCHES "^(cambricon|aipu|tsingmicro|enflame)$")
include_directories(${PROJECT_SOURCE_DIR}/include)
include_directories(${PROJECT_BINARY_DIR}/include) # Tablegen'd files
add_subdirectory(include)
Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,16 @@ cd ${YOUR_CODE_DIR}/flagtree/python
export FLAGTREE_BACKEND=hcu
python3 -m pip install . --no-build-isolation -v
```

[enflame](https://github.com/FlagTree/flagtree/triton_v3.3.x/main/third_party/enflame/)
```shell
# 推荐使用镜像: https://baai-cp-web.ks3-cn-beijing.ksyuncs.com/trans/enflame-flagtree-0.3.1.tar.gz
mkdir -p ~/.flagtree/enflame; cd ~/.flagtree/enflame
wget baai-cp-web.ks3-cn-beijing.ksyuncs.com/trans/enflame-llvm21-d752c5b-gcc9-x64_v0.3.0.tar.gz
tar zxvf enflame-llvm21-d752c5b-gcc9-x64_v0.3.0.tar.gz
cd ${YOUR_CODE_DIR}/flagtree/python
export FLAGTREE_BACKEND=enflame
python3 -m pip install . --no-build-isolation -v
```
[nvidia](/third_party/nvidia/)
To build with default backends nvidia, amd, triton_shared cpu:
```shell
Expand Down
11 changes: 10 additions & 1 deletion README_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,16 @@ cd ${YOUR_CODE_DIR}/flagtree/python
export FLAGTREE_BACKEND=hcu
python3 -m pip install . --no-build-isolation -v
```

[enflame](https://github.com/FlagTree/flagtree/triton_v3.3.x/main/third_party/enflame/)
```shell
# 推荐使用镜像: https://baai-cp-web.ks3-cn-beijing.ksyuncs.com/trans/enflame-flagtree-0.3.1.tar.gz
mkdir -p ~/.flagtree/enflame; cd ~/.flagtree/enflame
wget baai-cp-web.ks3-cn-beijing.ksyuncs.com/trans/enflame-llvm21-d752c5b-gcc9-x64_v0.3.0.tar.gz
tar zxvf enflame-llvm21-d752c5b-gcc9-x64_v0.3.0.tar.gz
cd ${YOUR_CODE_DIR}/flagtree/python
export FLAGTREE_BACKEND=enflame
python3 -m pip install . --no-build-isolation -v
```
[nvidia](/third_party/nvidia/)
使用默认的构建命令,可以构建安装 nvidia、amd、triton_shared cpu 后端:
```shell
Expand Down
2 changes: 1 addition & 1 deletion python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ def build_extension(self, ext):
)

if helper.flagtree_backend:
if helper.flagtree_backend in ("aipu", "tsingmicro"):
if helper.flagtree_backend in ("aipu", "tsingmicro", "enflame"):
backends = [
*BackendInstaller.copy(helper.default_backends + helper.extend_backends),
*BackendInstaller.copy_externals(),
Expand Down
17 changes: 16 additions & 1 deletion python/setup_tools/setup_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

extend_backends = []
default_backends = ["nvidia", "amd"]
plugin_backends = ["cambricon", "ascend", "aipu", "tsingmicro"]
plugin_backends = ["cambricon", "ascend", "aipu", "tsingmicro", "enflame"]
ext_sourcedir = "triton/_C/"
flagtree_backend = os.getenv("FLAGTREE_BACKEND", "").lower()
flagtree_plugin = os.getenv("FLAGTREE_PLUGIN", "").lower()
Expand Down Expand Up @@ -380,6 +380,21 @@ def check_env(env_val):
post_hock=set_llvm_env,
)

# enflame
cache.store(
file="llvm-d752c5b-gcc9-x64",
condition=("enflame" == flagtree_backend),
## TODO upload enflame llvm to blob storage
url = f"https://baai-cp-web.ks3-cn-beijing.ksyuncs.com/trans/enflame-llvm21-d752c5b-gcc9-x64_v0.3.0.tar.gz",
pre_hock=lambda: check_env('KURAMA_LLVM_DIR_GCU300'),
post_hock=lambda path: set_env({
'KURAMA_LLVM_DIR_GCU300': path,
'LLVM_INCLUDE_DIRS': Path(path) / "include",
'LLVM_LIBRARY_DIR': Path(path) / "lib",
'LLVM_SYSPATH': path,
}),
)

# tsingmicro
cache.store(
file="tsingmicro-llvm21-glibc2.30-glibcxx3.4.28-python3.11-x64",
Expand Down
27 changes: 27 additions & 0 deletions python/setup_tools/utils/enflame.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import os
import shutil
from pathlib import Path
from build_helpers import get_cmake_dir

def install_extension(*args, **kargs):
cmake_dir = get_cmake_dir()
binary_dir = cmake_dir / "bin"
python_root_dir = Path(__file__).parent.parent.parent
src_root_dir = python_root_dir.parent

drvfile = src_root_dir / 'third_party' / 'nvidia' / 'backend' / 'driver.py'
with open(drvfile, 'r') as f:
lines = f.readlines()
for i, line in enumerate(lines):
if 'def is_active():' in line:
if not 'return False' in lines[i+1]:
lines.insert(i+1, ' return False\n')
break
with open(drvfile, 'w') as f:
f.writelines(lines)

dst_dir = python_root_dir / "triton" / "backends" / "enflame"
for target in ["triton-gcu300-opt"]:
src_path = binary_dir / target
dst_path = dst_dir / target
shutil.copy(src_path, dst_path)
74 changes: 74 additions & 0 deletions third_party/enflame/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#set(CMAKE_INCLUDE_DIRECTORIES_BEFORE ON)


set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/install)
set(MLIR_BINARY_DIR ${CMAKE_BINARY_DIR})

if (DEFINED ENV{LLVM_SYSPATH})
else()
endif()

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)

# 添加 cmake 模块路径,以便 include() 可以找到相应的文件
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/2nd")

# 添加 triton_enflame 插件的构建
add_triton_plugin(TritonEnflame
${CMAKE_CURRENT_SOURCE_DIR}/triton_enflame.cc

DEPENDS
TritonTableGen
)

# 设置包含目录
target_include_directories(TritonEnflame PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/triton_gcu/include
)

# 链接必要的库
target_link_libraries(TritonEnflame PRIVATE
# MLIR 核心库
MLIRIR
MLIRPass
MLIRTransforms
MLIROptLib

# Python 绑定库
Python3::Module
pybind11::headers

# 如果需要链接 GCU 相关的库,可以在这里添加
# GCUIRgcu300
# TritonGCUIR_gcu300
# MLIRTritonGCUCommon_gcu300
# MLIRTritonToGCU_gcu300
# MLIRTritonGCUTransforms_gcu300
)

# 设置编译选项
target_compile_definitions(TritonEnflame PRIVATE
-DTRITON_ENFLAME_VERSION="1.0.0"
)


set(HACK_INCLUDE_DIRS true)
if(HACK_INCLUDE_DIRS)

get_property(inc_dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)

list(REMOVE_ITEM inc_dirs "${CMAKE_SOURCE_DIR}/include")
list(REMOVE_ITEM inc_dirs "${CMAKE_BINARY_DIR}/include")
list(REMOVE_ITEM inc_dirs "${CMAKE_SOURCE_DIR}/third_party")
list(REMOVE_ITEM inc_dirs "${CMAKE_BINARY_DIR}/third_party")
list(REMOVE_ITEM inc_dirs "${MLIR_INCLUDE_DIRS}")
list(REMOVE_ITEM inc_dirs "${LLVM_INCLUDE_DIRS}")

set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES "${include_dirs}")
endif()

# 添加 triton_gcu 子目录构建
add_subdirectory(triton_gcu)
add_subdirectory(include)
138 changes: 138 additions & 0 deletions third_party/enflame/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
# Flagtree Framework - Enflame Accelerator Support

## Overview

Flagtree is a high-performance computing framework optimized for Enflame accelerators. This repository provides core component backend bindings and test suites for developing and deploying applications on Enflame hardware platforms.

## Prerequisites

- Linux host system with Docker support
- Enflame 3rd Generation Accelerator Card (S60)
- Minimum 16GB RAM (32GB recommended)
- 100GB available disk space

## Environment Preparation

### 1. Pull Source Code

```bash
# Pull code and switch to triton_v3.3.x branch
cd ~
git clone https://github.com/flagos-ai/flagtree.git
cd flagtree
git checkout triton_v3.3.x
```

### 2. Prepare Docker Image

```bash
# Load pre-built container image
curl -sL https://baai-cp-web.ks3-cn-beijing.ksyuncs.com/trans/enflame-flagtree-0.3.1.tar.gz | docker load

# Or manually download and load
wget https://baai-cp-web.ks3-cn-beijing.ksyuncs.com/trans/enflame-flagtree-0.3.1.tar.gz
docker load -i enflame-flagtree-0.3.1.tar.gz
```

### 3. Start Docker Container

```bash
# To re-run container, remove the existing one
# docker rm -f enflame-flagtree

# Assuming flagtree source code is located at ~/flagtree
docker run -itd \
--privileged \
--name enflame-flagtree \
-v ~/flagtree:/root/flagtree \
enflame/flagtree:0.3.1 bash
```

### 4. Install Driver

```bash
# Extract and install Enflame driver
docker cp enflame-flagtree:/enflame enflame

sudo bash enflame/driver/enflame-x86_64-gcc-1.6.3.12-20251115104629.run
# Use other arguments if prompt, e.g.
# sudo bash enflame/driver/enflame-x86_64-gcc-1.6.3.12-20251115104629.run --virt-host

efsmi
```

Check driver status with efsmi. Example output:

```
-------------------------------------------------------------------------------
--------------------- Enflame System Management Interface ---------------------
--------- Enflame Tech, All Rights Reserved. 2024-2025 Copyright (C) ----------
-------------------------------------------------------------------------------

+2025-11-28, 10:50:14 CST-----------------------------------------------------+
| EFSMI: 1.6.3.12 Driver Ver: 1.6.3.12 |
+-----------------------------+-------------------+---------------------------+
| DEV NAME | FW VER | BUS-ID ECC |
| TEMP Lpm Pwr(Usage/Cap) | Mem GCU Virt | DUsed SN |
|=============================================================================|
| 0 Enflame S60G | 31.5.3 | 00:2e:00.0 Disable |
| 34℃ LP0 N/A | 23552MiB SRIOV | 0% A018K30520031 |
+-----------------------------+-------------------+---------------------------+
| 1 Enflame S60G | 31.5.3 | 00:2f:00.0 Disable |
| 34℃ LP0 N/A | 23552MiB SRIOV | 0% A018K30520031 |
+-----------------------------+-------------------+---------------------------+
```

### 5. Enter Docker Container

```bash
# Execute docker
docker exec -it enflame-flagtree bash
```

> Note: All subsequent commands should be executed within the container.

## Build and Install

### 1. Prepare Toolchain

```
mkdir -p ~/.flagtree/enflame
cd ~/.flagtree/enflame
wget baai-cp-web.ks3-cn-beijing.ksyuncs.com/trans/enflame-llvm21-d752c5b-gcc9-x64_v0.3.0.tar.gz
tar -xzf enflame-llvm21-d752c5b-gcc9-x64_v0.3.0.tar.gz
```

### 2. Configure Build Environment

```bash
export FLAGTREE_BACKEND=enflame
git config --global --add safe.directory ~/flagtree
```

### 3. Install Python Dependencies

```bash
cd ~/flagtree/python
pip3 install -r requirements.txt
```

### 4. Build and Install Package

```bash
cd ~/flagtree/python

# Initial build
pip3 install . --no-build-isolation -v

# Rebuild after code modification
pip3 install . --no-build-isolation --force-reinstall -v
```

## Test Validation

```bash
# Run unit tests
cd ~/flagtree
pytest third_party/enflame/python/test/unit
```
Loading