Skip to content

Commit dc313db

Browse files
Merge pull request #387 from cheng874/Update-FlagTensor
Update flag tensor
2 parents 2d53c49 + 11cb284 commit dc313db

8 files changed

Lines changed: 166 additions & 36 deletions

File tree

docs/flagtensor_en/overview/overview.md

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ FlagTensor is part of [FlagOS](https://flagos.io/), a fully open-source system s
44

55
FlagTensor is a high-performance tensor-primitive library implemented in [Triton](https://github.com/openai/triton) language. It provides optimized implementations of common tensor primitives (unary, binary, and tensor contraction operations) benchmarked against [cuTensor](https://developer.nvidia.com/cutensor) baselines, delivering reference-level correctness with competitive performance across diverse GPU architectures.
66

7-
Built on [FlagTree](https://github.com/flagos-ai/FlagTree) (a FlagOS-maintained Triton fork supporting multiple hardware backends), FlagTensor offers a vendor-agnostic operator interface with pluggable backend support.
7+
Built on [FlagTree](https://github.com/flagos-ai/FlagTree) (a FlagOS-maintained Triton fork supporting multiple hardware backends), FlagTensor offers a vendor-agnostic operator interface with pluggable backend support. Currently the primary backend is NVIDIA; other vendor backends are registered but not yet fully functional.
88

99
## Features
1010

1111
- Comprehensive collection of tensor primitives: unary (28 ops), binary (4 ops), contraction (3 ops), sparse (1 op)
1212
- Hand-optimized Triton kernels with per-architecture autotune (Ampere, Hopper)
1313
- Correctness validated against CPU-FP64 golden reference
1414
- Performance benchmarked against cuTensor baselines
15-
- Vendor-agnostic backend abstraction (15 vendors registered)
15+
- Vendor-agnostic backend abstraction (15 vendors registered; NVIDIA backend primary)
1616
- Architecture-specific kernel specialization (e.g., `_nvidia/hopper/`, `_nvidia/ampere/`)
1717
- Per-operator test infrastructure with pytest marks and JSON result recording
1818
- Multi-GPU parallel test runner with live progress display
@@ -31,18 +31,36 @@ FlagTensor
3131
│ ├── testing/ # Testing utilities (assertions, shapes, dtypes)
3232
│ ├── fused/ # Fused operators
3333
│ └── modules/ # Module implementations
34-
├── tests/ # Per-operator correctness tests
35-
│ ├── unary/test_CUTENSOR_OP_*.py # 28 unary operator tests
36-
│ ├── binary/test_CUTENSOR_OP_*.py # 4 binary operator tests
37-
│ ├── contraction/ # Contraction operator tests
38-
│ └── sparse/ # Sparse operator tests
39-
├── benchmark/ # Performance tests
34+
├── tests/ # Correctness tests (category-level + per-operator)
35+
│ ├── unary/
36+
│ │ ├── test_unary_correctness.py # Category-level entry (28 unary ops)
37+
│ │ └── test_CUTENSOR_OP_*.py # Per-operator tests (28 files)
38+
│ ├── binary/
39+
│ │ ├── test_binary_correctness.py # Category-level entry (4 binary ops)
40+
│ │ └── test_CUTENSOR_OP_*.py # Per-operator tests (4 files)
41+
│ ├── contraction/
42+
│ │ ├── test_contraction_correctness.py # Category-level entry (3 contraction ops)
43+
│ │ ├── test_Contraction.py
44+
│ │ ├── test_ContractionTrinary.py
45+
│ │ └── test_ElementwiseTrinary.py
46+
│ └── sparse/
47+
│ ├── test_sparse_correctness.py # Category-level entry (1 sparse op)
48+
│ └── test_BlockSparseContraction.py
49+
├── benchmark/ # Performance tests (category-level + per-operator)
4050
│ ├── consts.py # Dtypes, shapes, metrics definitions
41-
│ └── test_<category>_perf.py
51+
│ ├── test_unary_perf.py # Category-level: 28 unary operators
52+
│ ├── test_binary_perf.py # Category-level: 4 binary operators
53+
│ ├── test_contraction_perf.py # Category-level: 3 contraction operators
54+
│ ├── test_sparse_perf.py # Category-level: 1 sparse operator
55+
│ └── test_CUTENSOR_OP_*_perf.py # Per-operator benchmark files
4256
├── tools/ # CLI tooling
4357
│ ├── run_tests.py # Multi-GPU test runner
58+
│ ├── run_flagtensor_ci.py # CI runner (smoke/acceptance correctness & perf)
59+
│ ├── run_flagtensor_weekly.py # Weekly regression runner
4460
│ ├── get_marks.py # Extract pytest marks from YAML
45-
│ └── summary_for_plot.py # Parse & aggregate benchmark logs
61+
│ ├── summary_for_plot.py # Parse & aggregate benchmark logs
62+
│ ├── generate_flagtensor_html_report.py # HTML report generator
63+
│ └── export_env.py # Environment export for reproducibility
4664
├── conf/
4765
│ └── operators.yaml # Operator registry (authoritative test entry point)
4866
├── docs/ # Documentation

docs/flagtensor_en/reference/benchmark_policy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Current category entry points (all four complete):
7171

7272
- `benchmark/test_unary_perf.py` — 28 unary operators
7373
- `benchmark/test_binary_perf.py` — 4 binary operators
74-
- `benchmark/test_contraction_perf.py`5 contraction operators
74+
- `benchmark/test_contraction_perf.py`3 contraction operators
7575
- `benchmark/test_sparse_perf.py` — 1 sparse operator
7676

7777
Legacy per-operator benchmark files (`benchmark/test_CUTENSOR_OP_*_perf.py`) are retained as

docs/flagtensor_en/reference/reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This section contains the FlagTensor acceptance documentation, covering policies
99
| [Benchmark Policy](benchmark_policy.md) | Defines benchmark goals, execution modes (smoke/acceptance/weekly), shape/dtype policy, timing policy, and reporting policy for performance validation. |
1010
| [CI Matrix](ci_matrix.md) | Describes all CI/CD workflows (quality-gate, ci, weekly, acceptance) with job details, parameters, artifact storage, and cluster GPU validation. |
1111
| [Known Issues](known_issues.md) | Tracks experimental operators, CI limitations, dtype/shape coverage gaps, performance notes, migration status, and future work. |
12-
| [Operator Coverage](operator_coverage.md) | Per-operator implementation, correctness, and benchmark coverage matrix across all 38 operators (28 unary, 4 binary, 5 contraction, 1 sparse). |
12+
| [Operator Coverage](operator_coverage.md) | Per-operator implementation, correctness, and benchmark coverage matrix across all 36 operators (28 unary, 4 binary, 3 contraction, 1 sparse). |
1313
| [Standard Commands](standard_commands.md) | Standard commands for running acceptance checks: static quality, correctness testing, performance testing, weekly regression, registry operations, and GPU cluster validation. |
1414

1515
```{toctree}

docs/flagtensor_en/user_guide/user-guide.md

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ FlagTensor integrates directly with PyTorch. Import the package and call operato
88
import torch
99
import flagtensor
1010

11-
# Element-wise operations
11+
# Element-wise (unary) operations
1212
x = torch.randn(1024, device="cuda", dtype=torch.float32)
1313
y = flagtensor.abs(x)
1414
z = flagtensor.relu(x)
@@ -18,11 +18,21 @@ w = flagtensor.sigmoid(x)
1818
a = torch.randn(1024, device="cuda")
1919
b = torch.randn(1024, device="cuda")
2020
c = flagtensor.add(a, b)
21+
d = flagtensor.mul(a, b)
2122

2223
# Tensor contraction
2324
m = torch.randn(64, 32, device="cuda")
2425
n = torch.randn(32, 48, device="cuda")
2526
r = flagtensor.contraction(m, n)
27+
28+
# Trinary contraction
29+
p = torch.randn(64, 32, device="cuda")
30+
q = torch.randn(32, 48, device="cuda")
31+
s = torch.randn(64, 48, device="cuda")
32+
t = flagtensor.contraction_trinary(p, q, s)
33+
34+
# Element-wise trinary
35+
u = flagtensor.elementwise_trinary(a, b, c)
2636
```
2737

2838
## Operator List
@@ -33,13 +43,22 @@ The complete operator registry is maintained at [FlagTensor conf/operators.yaml]
3343
|---|---|---|
3444
| **Unary** | abs, acos, acosh, asin, asinh, atan, atanh, ceil, conj, cos, cosh, exp, floor, identity, log, mish, neg, rcp, relu, sigmoid, sin, sinh, soft_plus, soft_sign, sqrt, swish, tan, tanh | stable |
3545
| **Binary** | add, max, min, mul | stable |
36-
| **Contraction** | contraction, contraction_trinary, elementwise_trinary | stable |
46+
| **Contraction** | contraction, elementwise_trinary | stable |
47+
| **Contraction** | contraction_trinary | active |
3748
| **Sparse** | block_sparse_contraction | experimental |
3849

3950
## Run Tests
4051

52+
### Correctness Tests
53+
4154
```bash
42-
# Single operator correctness test
55+
# Category-level correctness (primary acceptance interface)
56+
pytest tests/unary/test_unary_correctness.py -v
57+
pytest tests/binary/test_binary_correctness.py -v
58+
pytest tests/contraction/test_contraction_correctness.py -v
59+
pytest tests/sparse/test_sparse_correctness.py -v
60+
61+
# Single operator correctness test (per-operator file)
4362
pytest tests/unary/test_CUTENSOR_OP_ABS.py -v
4463

4564
# Record test results as JSON (using CPU-FP64 reference)
@@ -50,11 +69,39 @@ python tools/run_tests.py --stages stable --gpus 0,1
5069

5170
# Extract operator marks
5271
python tools/get_marks.py --stage stable --output ops.txt
72+
```
73+
74+
### Performance Tests
75+
76+
```bash
77+
# Category-level benchmark (primary acceptance interface)
78+
pytest benchmark/test_unary_perf.py -m CUTENSOR_OP_ABS --mode kernel --level core --record log
79+
pytest benchmark/test_binary_perf.py -m CUTENSOR_OP_ADD --mode kernel --level core --record log
80+
pytest benchmark/test_contraction_perf.py -m Contraction --mode kernel --level core --record log
81+
pytest benchmark/test_sparse_perf.py -m BlockSparseContraction --mode kernel --level core --record log
5382

54-
# Benchmark with recording
55-
pytest benchmark/test_unary_perf.py -m CUTENSOR_OP_ABS \
56-
--mode kernel --level core --record log
83+
# Per-operator benchmark (legacy/debug)
84+
pytest benchmark/test_CUTENSOR_OP_ABS_perf.py --mode kernel --level core --record log
5785

5886
# Parse benchmark summary
5987
python tools/summary_for_plot.py result-*.log
6088
```
89+
90+
### CI Runner
91+
92+
```bash
93+
# Smoke correctness
94+
python tools/run_flagtensor_ci.py --smoke --run-correctness --results-dir ci_results_correctness --dump-json-summary
95+
96+
# Smoke performance
97+
python tools/run_flagtensor_ci.py --smoke --run-perf --results-dir ci_results_perf --dump-json-summary
98+
99+
# Acceptance correctness (full coverage)
100+
python tools/run_flagtensor_ci.py --run-correctness --results-dir acceptance_results_correctness --dump-json-summary
101+
102+
# Acceptance performance (full coverage)
103+
python tools/run_flagtensor_ci.py --run-perf --results-dir acceptance_results_perf --dump-json-summary
104+
105+
# Weekly regression
106+
python tools/run_flagtensor_weekly.py --project-root . --results-dir weekly_results --gpus 0 --mode kernel
107+
```

docs/flagtensor_zh/overview/overview.md

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ FlagTensor 是 [FlagOS](https://flagos.io/) 的组成部分。FlagOS 是一个
44

55
FlagTensor 是一个使用 [Triton](https://github.com/openai/triton) 语言实现的高性能张量原语库。它提供常见张量原语(一元、二元和张量收缩操作)的优化实现,以 [cuTensor](https://developer.nvidia.com/cutensor) 基线为基准,在不同 GPU 架构上提供参考级正确性和具有竞争力的性能。
66

7-
FlagTensor 构建在 [FlagTree](https://github.com/flagos-ai/FlagTree)(FlagOS 维护的 Triton 分支,支持多种硬件后端)之上,提供与供应商无关的算子接口和可插拔后端支持。
7+
FlagTensor 构建在 [FlagTree](https://github.com/flagos-ai/FlagTree)(FlagOS 维护的 Triton 分支,支持多种硬件后端)之上,提供与供应商无关的算子接口和可插拔后端支持。当前主要后端为 NVIDIA;其他供应商后端已注册但功能尚未完全就绪。
88

99
## 特性
1010

1111
- 全面的张量原语集合:一元(28 个算子)、二元(4 个算子)、收缩(3 个算子)、稀疏(1 个算子)
1212
- 手工优化的 Triton 内核,支持按架构自动调优(Ampere、Hopper)
1313
- 基于 CPU-FP64 金标准参考验证正确性
1414
- 以 cuTensor 基线为基准进行性能基准测试
15-
- 与供应商无关的后端抽象(已注册 15 家供应商)
15+
- 与供应商无关的后端抽象(已注册 15 家供应商;NVIDIA 后端为主要后端
1616
- 架构特定的内核特化(如 `_nvidia/hopper/``_nvidia/ampere/`
1717
- 每个算子的测试基础设施,支持 pytest 标记和 JSON 结果记录
1818
- 多 GPU 并行测试运行器,带实时进度显示
@@ -31,18 +31,36 @@ FlagTensor
3131
│ ├── testing/ # 测试工具(断言、形状、dtype)
3232
│ ├── fused/ # 融合算子
3333
│ └── modules/ # 模块实现
34-
├── tests/ # 每个算子的正确性测试
35-
│ ├── unary/test_CUTENSOR_OP_*.py # 28 个一元算子测试
36-
│ ├── binary/test_CUTENSOR_OP_*.py # 4 个二元算子测试
37-
│ ├── contraction/ # 收缩算子测试
38-
│ └── sparse/ # 稀疏算子测试
39-
├── benchmark/ # 性能测试
34+
├── tests/ # 正确性测试(分类级 + 每个算子)
35+
│ ├── unary/
36+
│ │ ├── test_unary_correctness.py # 分类级入口(28 个一元算子)
37+
│ │ └── test_CUTENSOR_OP_*.py # 每个算子测试(28 个文件)
38+
│ ├── binary/
39+
│ │ ├── test_binary_correctness.py # 分类级入口(4 个二元算子)
40+
│ │ └── test_CUTENSOR_OP_*.py # 每个算子测试(4 个文件)
41+
│ ├── contraction/
42+
│ │ ├── test_contraction_correctness.py # 分类级入口(3 个收缩算子)
43+
│ │ ├── test_Contraction.py
44+
│ │ ├── test_ContractionTrinary.py
45+
│ │ └── test_ElementwiseTrinary.py
46+
│ └── sparse/
47+
│ ├── test_sparse_correctness.py # 分类级入口(1 个稀疏算子)
48+
│ └── test_BlockSparseContraction.py
49+
├── benchmark/ # 性能测试(分类级 + 每个算子)
4050
│ ├── consts.py # Dtype、形状、指标定义
41-
│ └── test_<category>_perf.py
51+
│ ├── test_unary_perf.py # 分类级:28 个一元算子
52+
│ ├── test_binary_perf.py # 分类级:4 个二元算子
53+
│ ├── test_contraction_perf.py # 分类级:3 个收缩算子
54+
│ ├── test_sparse_perf.py # 分类级:1 个稀疏算子
55+
│ └── test_CUTENSOR_OP_*_perf.py # 每个算子的基准测试文件
4256
├── tools/ # CLI 工具
4357
│ ├── run_tests.py # 多 GPU 测试运行器
58+
│ ├── run_flagtensor_ci.py # CI 运行器(冒烟/验收正确性与性能)
59+
│ ├── run_flagtensor_weekly.py # 每周回归运行器
4460
│ ├── get_marks.py # 从 YAML 提取 pytest 标记
45-
│ └── summary_for_plot.py # 解析和聚合基准测试日志
61+
│ ├── summary_for_plot.py # 解析和聚合基准测试日志
62+
│ ├── generate_flagtensor_html_report.py # HTML 报告生成器
63+
│ └── export_env.py # 环境导出用于可复现性
4664
├── conf/
4765
│ └── operators.yaml # 算子注册表(权威测试入口点)
4866
├── docs/ # 文档

docs/flagtensor_zh/reference/benchmark_policy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171

7272
- `benchmark/test_unary_perf.py` —— 28 个一元算子
7373
- `benchmark/test_binary_perf.py` —— 4 个二元算子
74-
- `benchmark/test_contraction_perf.py` —— 5 个收缩算子
74+
- `benchmark/test_contraction_perf.py` —— 3 个收缩算子
7575
- `benchmark/test_sparse_perf.py` —— 1 个稀疏算子
7676

7777
旧版每个算子的基准测试文件(`benchmark/test_CUTENSOR_OP_*_perf.py`)保留为

docs/flagtensor_zh/reference/reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
| [基准测试策略](benchmark_policy.md) | 定义性能验证的基准测试目标、执行模式(冒烟/验收/每周)、形状/dtype 策略、计时策略和报告策略。 |
1010
| [CI 矩阵](ci_matrix.md) | 描述所有 CI/CD 工作流(质量门、ci、每周、验收),包括作业详情、参数、工件存储和集群 GPU 验证。 |
1111
| [已知问题](known_issues.md) | 跟踪实验性算子、CI 限制、dtype/形状覆盖差距、性能说明、迁移状态和未来工作。 |
12-
| [算子覆盖率](operator_coverage.md) | 全部 38 个算子(28 个一元、4 个二元、5 个收缩、1 个稀疏)的每个算子实现、正确性和基准测试覆盖率矩阵。 |
12+
| [算子覆盖率](operator_coverage.md) | 全部 36 个算子(28 个一元、4 个二元、3 个收缩、1 个稀疏)的每个算子实现、正确性和基准测试覆盖率矩阵。 |
1313
| [标准命令](standard_commands.md) | 运行验收检查的标准命令:静态质量、正确性测试、性能测试、每周回归、注册表操作和 GPU 集群验证。 |
1414

1515
```{toctree}

docs/flagtensor_zh/user_guide/user-guide.md

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ FlagTensor 直接与 PyTorch 集成。导入包并对 CUDA 张量调用算子:
88
import torch
99
import flagtensor
1010

11-
# 逐元素操作
11+
# 逐元素(一元)操作
1212
x = torch.randn(1024, device="cuda", dtype=torch.float32)
1313
y = flagtensor.abs(x)
1414
z = flagtensor.relu(x)
@@ -18,11 +18,21 @@ w = flagtensor.sigmoid(x)
1818
a = torch.randn(1024, device="cuda")
1919
b = torch.randn(1024, device="cuda")
2020
c = flagtensor.add(a, b)
21+
d = flagtensor.mul(a, b)
2122

2223
# 张量收缩
2324
m = torch.randn(64, 32, device="cuda")
2425
n = torch.randn(32, 48, device="cuda")
2526
r = flagtensor.contraction(m, n)
27+
28+
# 三元收缩
29+
p = torch.randn(64, 32, device="cuda")
30+
q = torch.randn(32, 48, device="cuda")
31+
s = torch.randn(64, 48, device="cuda")
32+
t = flagtensor.contraction_trinary(p, q, s)
33+
34+
# 逐元素三元操作
35+
u = flagtensor.elementwise_trinary(a, b, c)
2636
```
2737

2838
## 算子列表
@@ -33,13 +43,22 @@ r = flagtensor.contraction(m, n)
3343
|---|---|---|
3444
| **一元** | abs、acos、acosh、asin、asinh、atan、atanh、ceil、conj、cos、cosh、exp、floor、identity、log、mish、neg、rcp、relu、sigmoid、sin、sinh、soft_plus、soft_sign、sqrt、swish、tan、tanh | stable |
3545
| **二元** | add、max、min、mul | stable |
36-
| **收缩** | contraction、contraction_trinary、elementwise_trinary | stable |
46+
| **收缩** | contraction、elementwise_trinary | stable |
47+
| **收缩** | contraction_trinary | active |
3748
| **稀疏** | block_sparse_contraction | experimental |
3849

3950
## 运行测试
4051

52+
### 正确性测试
53+
4154
```bash
42-
# 单个算子正确性测试
55+
# 分类级正确性(主要验收接口)
56+
pytest tests/unary/test_unary_correctness.py -v
57+
pytest tests/binary/test_binary_correctness.py -v
58+
pytest tests/contraction/test_contraction_correctness.py -v
59+
pytest tests/sparse/test_sparse_correctness.py -v
60+
61+
# 单个算子正确性测试(每个算子文件)
4362
pytest tests/unary/test_CUTENSOR_OP_ABS.py -v
4463

4564
# 记录测试结果为 JSON(使用 CPU-FP64 参考)
@@ -50,11 +69,39 @@ python tools/run_tests.py --stages stable --gpus 0,1
5069

5170
# 提取算子标记
5271
python tools/get_marks.py --stage stable --output ops.txt
72+
```
73+
74+
### 性能测试
75+
76+
```bash
77+
# 分类级基准测试(主要验收接口)
78+
pytest benchmark/test_unary_perf.py -m CUTENSOR_OP_ABS --mode kernel --level core --record log
79+
pytest benchmark/test_binary_perf.py -m CUTENSOR_OP_ADD --mode kernel --level core --record log
80+
pytest benchmark/test_contraction_perf.py -m Contraction --mode kernel --level core --record log
81+
pytest benchmark/test_sparse_perf.py -m BlockSparseContraction --mode kernel --level core --record log
5382

54-
# 带记录的基准测试
55-
pytest benchmark/test_unary_perf.py -m CUTENSOR_OP_ABS \
56-
--mode kernel --level core --record log
83+
# 每个算子基准测试(旧版/调试)
84+
pytest benchmark/test_CUTENSOR_OP_ABS_perf.py --mode kernel --level core --record log
5785

5886
# 解析基准测试摘要
5987
python tools/summary_for_plot.py result-*.log
6088
```
89+
90+
### CI 运行器
91+
92+
```bash
93+
# 冒烟正确性
94+
python tools/run_flagtensor_ci.py --smoke --run-correctness --results-dir ci_results_correctness --dump-json-summary
95+
96+
# 冒烟性能
97+
python tools/run_flagtensor_ci.py --smoke --run-perf --results-dir ci_results_perf --dump-json-summary
98+
99+
# 验收正确性(完整覆盖率)
100+
python tools/run_flagtensor_ci.py --run-correctness --results-dir acceptance_results_correctness --dump-json-summary
101+
102+
# 验收性能(完整覆盖率)
103+
python tools/run_flagtensor_ci.py --run-perf --results-dir acceptance_results_perf --dump-json-summary
104+
105+
# 每周回归
106+
python tools/run_flagtensor_weekly.py --project-root . --results-dir weekly_results --gpus 0 --mode kernel
107+
```

0 commit comments

Comments
 (0)