[Bug] [RISC-V RVV] max_pool2d operator shows minor performance regression
- Dominant language
- Python
- Stars
- 13.7k
- Forks
- 4k
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 112
Description
### Issue: [RISC-V RVV] max_pool2d operator shows minor performance regression
#### Description
The max_pool2d operator shows slight performance degradation with the RISC‑V Vector (RVV) extension, achieving 0.867× the performance of the scalar implementation. While the regression is smaller than other operators, it still indicates suboptimal vectorization for 2D max pooling.
#### Steps to Reproduce
1. Generate the max_pool2d operator with the following configuration:
```python
params = {
"dtype": "float32",
"batch": 14,
"pool_channels": 23,
"pool_size": 2,
"stride": 4,
"padding": 1,
"input_height": 99,
"input_width": 95
}
```
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_max_pool2d(params, set_dir=None, platform="rv"):
data = relay.var("data",
shape=(params["batch"], params["pool_channels"],
params["input_height"], params["input_width"]),
dtype=params["dtype"])
pool = relay.nn.max_pool2d(
data,
pool_size=(params["pool_size"], params["pool_size"]),
strides=(params["stride"], params["stride"]),
padding=(params["padding"], params["padding"])
)
export_op(pool, params["op_name"], [data], params, set_dir=set_dir)
```
#### Performance Data
- **RV execution time**: 8.357100 ms
- **RVV execution time**: 9.634620 ms
- **Acceleration ratio (RV/RVV)**: 0.867 (RVV is ~1.15× 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
- **Operation**: 2×2 max pooling with stride 4 on input shape (14, 23, 99, 95)
#### Expected Behavior
RVV vectorization should provide a performance improvement over the scalar RV baseline for 2D pooling operations like max_pool2d.
#### Additional Context
- The operation performs 2×2 max pooling with stride 4 and padding 1 on a 4D tensor.
- While the performance regression is less severe than for other operators, it still indicates that the vectorized implementation of 2D max pooling may have inefficiencies in memory access patterns or vector reduction within pooling windows.
- This is part of a broader pattern where all tested operators show performance degradation with RVV, suggesting potential issues with vectorization strategies in TVM's RISC‑V backend.
Contributor guide
No contributing guide indexed for this repository
Research direction
No source file or test is identified in the issue. Start by reproducing the supplied max_pool2d benchmark on the RV and RVV targets, then trace the generated pooling implementation and its performance measurement; done means explaining and addressing the RVV regression with comparative results.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100