apache / apache/tvm

[Bug] [RISC-V RVV] Performance Regression: sum operator slower on RVV than RV

Open
#18,560 0 comments 0 reactions 0 assignees View on GitHub
needs-triage type: bug
Dominant language
Python
Stars
13.7k
Forks
4k
Avg merge
2d 1h
Merged PRs (30d)
112

Description

### Issue: [RISC-V RVV] Performance Regression: sum operator slower on RVV than RV

#### Description
The sum operator shows significant performance degradation when using the RISC‑V Vector (RVV) extension compared to the scalar RV baseline. The acceleration ratio is 0.325, meaning the RVV version is about 3× slower. This is unexpected because vector extensions should improve performance, especially for reduction operations like sum.

#### Steps to Reproduce
1. Generate the sum operator with the following configuration:
```python
params = {
"dtype": "float32",
"batch": 14,
"channels": 23,
"input_height": 67,
"input_width": 99,
"axis": 1,
"keepdims": True
}
```

2. Export the operator to two targets:
- **RV target** (scalar, without vector extension):
```
llvm -mtriple=riscv64-linux-gnu -mcpu=generic-rv64 -mabi=lp64d -mattr=+64bit,+m,+a,+f,+d,+c
```
- **RVV target** (with vector extension):
```
llvm -mtriple=riscv64-linux-gnu -mcpu=generic-rv64 -mabi=lp64d -mattr=+64bit,+m,+a,+f,+d,+c,+v
```

3. Run performance measurement on both targets.

Operator definition code:
```python
def export_sum(params, set_dir=None, platform="rv"):
data = relay.var("data",
shape=(params["batch"], params["channels"],
params["input_height"], params["input_width"]),
dtype=params["dtype"])
sum_op = relay.sum(data, axis=params["axis"], keepdims=params["keepdims"])
export_op(sum_op, params["op_name"], [data], params, set_dir=set_dir)
```

#### Performance Data
- **RV execution time**: 9.301150 ms
- **RVV execution time**: 28.622800 ms
- **Acceleration ratio (RV/RVV)**: 0.325 (RVV is ~3× slower)

#### Environment Information
- **TVM version**: 0.19.0
- **LLVM version**: [Please provide: `llvm-config --version`]
- **Hardware**: Spacemit K1‑X bit‑brick board
- **CPU**: Spacemit X60 (8 cores, 1.6 GHz)
- **ISA**: rv64imafdcv (with vector extensions)
- **Memory**: 7.6 GB
- **OS**: Bianbu 2.2, Linux kernel 6.6.63

#### Expected Behavior
RVV vectorization should provide a performance improvement over the scalar RV baseline for reduction operations like sum.

#### Additional Context
- The sum operation reduces along axis=1 on a tensor of shape (14, 23, 67, 99) (≈1.7M elements).
- The performance regression suggests suboptimal vectorization for reduction operations on RVV.
- Other operators (log, relu, bias_add, sqrt, etc.) also show similar regressions, indicating a broader RVV code‑generation or optimization issue.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the provided export_sum entry point and relay.sum configuration, then reproduce the RV and RVV builds using the stated LLVM targets on the Spacemit board. Compare the measured execution times and identify the relevant RVV code-generation or optimization area; done means the reduction no longer shows the reported regression and the result is covered by a reproducible measurement.

Written by the indexing model from the issue text.

Assessment

Tech stack
linux, python
Domain
compilers, operating-systems, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.