apache / apache/tvm

[Bug] [RISC-V RVV] Performance Issue: log operator slower on RVV

Open
#18,561 1 comment 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 Issue: log operator slower on RVV

#### Description
The log operator exhibits performance regression with the RISC‑V Vector (RVV) extension enabled. The acceleration ratio is 0.328, indicating the RVV implementation is approximately 3× slower than the scalar RV version. This is unexpected for an elementwise mathematical operation that should benefit from vectorization.

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

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_log(params, set_dir=None, platform="rv"):
data = relay.var("data",
shape=(params["batch"], params["channels"],
params["input_height"], params["input_width"]),
dtype=params["dtype"])
log_op = relay.log(data)
export_op(log_op, params["op_name"], [data], params, set_dir=set_dir)
```

#### Performance Data
- **RV execution time**: 13.393300 ms
- **RVV execution time**: 40.848000 ms
- **Acceleration ratio (RV/RVV)**: 0.328 (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
- **Input shape**: (14, 23, 67, 99) ≈ 1.7M elements

#### Expected Behavior
RVV vectorization should provide a performance improvement over the scalar RV baseline for elementwise mathematical operations like log.

#### Additional Context
- The log operation is applied elementwise to a tensor of ~1.7M elements.
- This severe performance regression suggests inefficient vector code generation or suboptimal use of RVV instructions for mathematical functions.
- Similar regressions are observed across multiple operators (sum, relu, bias_add, sqrt, etc.), indicating a potential systemic issue with RVV vectorization in TVM.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the provided export_log definition and reproduce the comparison using the RV and RVV LLVM target flags on the stated tensor shape. Inspect the generated behavior for the log operator and compare the reported timings; done means identifying the source of the RVV regression and demonstrating improved performance against the scalar baseline.

Written by the indexing model from the issue text.

Assessment

Tech stack
linux, python
Domain
compilers, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.