Skip to content
Draft
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
c45e205
OpenVX: Add row-based parallelism framework
Jun 13, 2026
a1b408e
Fix: Correct function name for Subtract serial fallback
Jun 13, 2026
c2fd8ce
Add function declarations for parallel kernels in header
Jun 13, 2026
5d42bab
Connect parallel kernels to OpenVX node layer + benchmark
Jun 13, 2026
ce8ca61
Fix Subtract function name and add Box3x3 parallel integration
Jun 13, 2026
e8d72a3
Final: Working parallel Add and Subtract kernels
Jun 13, 2026
e1c0485
Add parallel logical operations: And, Or, Xor, Not
Jun 13, 2026
e8ad1f5
Add OpenCV vs OpenVX performance comparison benchmark
Jun 13, 2026
5553f9e
Add streaming stores to Add and Subtract kernels
Jun 13, 2026
49afe7d
Add PR documentation and instructions
Jun 13, 2026
e72ecbf
Merge branch 'develop' into feature/openvx-row-based-parallelism
kiritigowda Jun 13, 2026
32af8e0
Merge branch 'develop' into feature/openvx-row-based-parallelism
kiritigowda Jun 13, 2026
03a381d
Merge branch 'develop' into feature/openvx-row-based-parallelism
kiritigowda Jun 16, 2026
e00ad37
Merge branch 'develop' into feature/openvx-row-based-parallelism
kiritigowda Jun 17, 2026
793bca4
Merge branch 'develop' into feature/openvx-row-based-parallelism
kiritigowda Jun 19, 2026
675193d
Merge branch 'develop' into feature/openvx-row-based-parallelism
kiritigowda Jun 23, 2026
aa52a0a
Merge branch 'develop' into feature/openvx-row-based-parallelism
kiritigowda Jun 30, 2026
7beb07f
Merge branch 'develop' into feature/openvx-row-based-parallelism
kiritigowda Jul 9, 2026
f6dec79
Merge branch 'develop' into feature/openvx-row-based-parallelism
kiritigowda Jul 12, 2026
64a816e
Merge branch 'develop' into feature/openvx-row-based-parallelism
kiritigowda Jul 14, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added EOF
Empty file.
118 changes: 118 additions & 0 deletions IMPLEMENTATION_FINAL_SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# OpenVX Parallel Implementation - Final Summary

## Branch: feature/openvx-row-based-parallelism

## What Was Achieved

### Parallel Kernels Implemented

| Kernel | File | Status | Speedup Achieved |
|--------|------|--------|------------------|
| Add | ago_haf_cpu_arithmetic_parallel.cpp | ✅ Working | 1.4x (4 threads) |
| Subtract | ago_haf_cpu_arithmetic_parallel.cpp | ✅ Working | 1.4x (4 threads) |
| And | ago_haf_cpu_logical_parallel.cpp | ✅ Working | 1.0x (memory bound) |
| Or | ago_haf_cpu_logical_parallel.cpp | ✅ Working | 1.0x (memory bound) |
| Xor | ago_haf_cpu_logical_parallel.cpp | ✅ Working | 1.3x (4 threads) |
| Not | ago_haf_cpu_logical_parallel.cpp | ✅ Working | 1.0x (memory bound) |
| Box3x3 | ago_haf_cpu_arithmetic_parallel.cpp | ⚠️ Serial | 1.0x (needs work) |

### Key Files Created/Modified

```
MIVisionX/amd_openvx/openvx/
├── ago/
│ ├── ago_parallel.h [NEW]
│ ├── ago_haf_cpu_arithmetic_parallel.cpp [NEW]
│ ├── ago_haf_cpu_logical_parallel.cpp [NEW]
│ ├── ago_haf_cpu.h [MOD]
│ └── ago_kernel_api.cpp [MOD]
└── CMakeLists.txt [MOD]
```

### Test Files Created

- test_parallel.cpp - Initial Add kernel test
- benchmark_parallel.cpp - Multi-kernel benchmark
- test_logical.cpp - Logical operations test
- benchmark_opencv_vs_openvx.cpp - OpenCV comparison
- test_accurate_timing.cpp - Accurate process graph timing

## Benchmark Results

### Direct Kernel Calls (No Graph Overhead)

| Kernel | 1 Thread | 4 Threads | Speedup |
|--------|----------|-----------|---------|
| Add | 14,000 MP/s | 44,000 MP/s | **3.1x** |
| Subtract | 14,000 MP/s | 44,000 MP/s | **3.1x** |

### Via OpenVX Graph (Process Graph Only)

| Kernel | 1 Thread | 4 Threads | Speedup |
|--------|----------|-----------|---------|
| Add | 10,677 MP/s | 14,692 MP/s | **1.4x** |
| And | 16,647 MP/s | 16,796 MP/s | **1.0x** |
| Not | 22,729 MP/s | 22,340 MP/s | **1.0x** |

## Why Lower Speedup in Graph Mode

1. **Graph execution overhead** - The vxProcessGraph() call has fixed overhead
2. **Memory bandwidth saturation** - Some operations already near memory limits
3. **Thread synchronization** - OpenMP overhead in parallel regions

## Comparison with OpenCV

| Operation | OpenCV (1T) | OpenVX (4T) | Gap |
|-----------|-------------|-------------|-----|
| Add | 39,844 MP/s | 14,692 MP/s | **2.7x** |
| And | 43,584 MP/s | 16,796 MP/s | **2.6x** |
| Not | 66,285 MP/s | 22,340 MP/s | **3.0x** |

**OpenCV advantages:**
- Streaming stores (bypass cache)
- More aggressive loop unrolling
- Better memory access patterns
- Contiguous buffer allocation

## Build Instructions

```bash
cd MIVisionX/amd_openvx
mkdir build && cd build
cmake .. -DENABLE_OPENMP=ON
make -j$(nproc) openvx
```

## Test

```bash
export OMP_NUM_THREADS=4
./test_accurate_timing
```

## Commits

```
e8ad1f5a Add OpenCV vs OpenVX performance comparison benchmark
e1c0485a Add parallel logical operations: And, Or, Xor, Not
e8d72a34 Final: Working parallel Add and Subtract kernels
ce8ca61b Fix Subtract function name and add Box3x3 parallel integration
5d42babd Connect parallel kernels to OpenVX node layer + benchmark
...
```

## Next Steps for Further Optimization

1. **Implement streaming stores** - Could improve bandwidth by 30-50%
2. **Optimize thread scheduling** - Current guided schedule may not be optimal
3. **Box3x3** - Implement tile-based parallelism for 2-pass filter
4. **ColorConvert** - Likely good candidate for parallelization

## Conclusion

The row-based parallelism framework is **working correctly** and achieves:
- **1.4x speedup** on Add/Subtract via graph execution
- **3.1x speedup** on direct kernel calls
- Memory-bound operations (And, Or, Not) show limited scaling

The implementation follows OpenCV's pattern but needs streaming stores and more aggressive optimization to match OpenCV's single-threaded performance.
153 changes: 153 additions & 0 deletions IMPLEMENTATION_SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
# OpenVX Row-Based Parallelism Implementation Summary

## Branch
`feature/openvx-row-based-parallelism` (from `develop`)

## What Was Implemented

### 1. Parallel Infrastructure (`ago_parallel.h`)
- **AgoParallelForRows()** - Row-based parallelization with guided scheduling
- **AgoShouldUseThreading()** - Auto-disable for small images (<32 rows)
- **OpenMP backend** with fallback to serial execution
- Configurable via CMake: `-DENABLE_OPENMP=ON/OFF`

### 2. CMake Integration
- OpenMP detection and configuration
- Automatic `-fopenmp` flag addition
- Compile definitions: `USE_OPENMP=1`

### 3. Parallel Kernel Implementations

| Kernel | Function | Status | Expected Speedup |
|--------|----------|--------|------------------|
| Add U8 | `HafCpu_Add_U8_U8U8_Wrap_OpenMP()` | ✅ Implemented | 2.5-3.0x |
| Subtract U8 | `HafCpu_Sub_U8_U8U8_Wrap_OpenMP()` | ✅ Implemented | 2.5-3.0x |
| Box3x3 | `HafCpu_Box_U8_U8_3x3_OpenMP()` | ✅ Implemented | 1.4-1.7x |

## Build Instructions

```bash
cd MIVisionX/amd_openvx
mkdir build && cd build
cmake .. -DENABLE_OPENMP=ON
make -j$(nproc) openvx
```

## How It Works

### Row-Based Parallelism Pattern
```cpp
// Serial version
for (int y = 0; y < height; y++) {
process_row(y);
}

// Parallel version (guided scheduling)
#pragma omp parallel for schedule(guided)
for (int y = 0; y < height; y++) {
process_row(y);
}
```

### Key Features
1. **Cache-friendly**: Threads process contiguous rows
2. **No false sharing**: Each thread writes to different rows
3. **Auto-threshold**: Disabled for images < 32 rows
4. **AVX preserved**: SIMD optimizations maintained

## Performance Expectations

Based on OpenCV benchmarks on AMD Ryzen:

| Configuration | Add Kernel | Box3x3 |
|---------------|------------|--------|
| Single-threaded | ~30K MP/s | ~2.1K MP/s |
| 4 threads (expected) | ~75-90K MP/s | ~3.0-3.5K MP/s |
| **Speedup** | **2.5-3.0x** | **1.4-1.7x** |

## Next Steps

### To Complete Implementation:

1. **Connect to OpenVX node layer**
- Modify kernel registration to use parallel versions
- Add function prototypes to `ago_internal.h`

2. **Port remaining P0 kernels**
- Gaussian3x3 (filter)
- ColorConvert (color)
- Erode/Dilate (filter)

3. **Performance validation**
- Build with `-DENABLE_OPENMP=ON`
- Run `openvx-mark` benchmark
- Compare with OpenCV results

4. **Fine-tuning**
- Adjust `AGO_PARALLEL_MIN_HEIGHT` threshold
- Tune `AGO_PARALLEL_ROWS_PER_TASK` for optimal chunking
- Profile with `OMP_SCHEDULE=guided,4` vs other settings

## Files Modified/Created

```
MIVisionX/
├── amd_openvx/openvx/
│ ├── ago/
│ │ ├── ago_parallel.h [NEW]
│ │ └── ago_haf_cpu_arithmetic_parallel.cpp [NEW]
│ └── CMakeLists.txt [MODIFIED]
```

## Testing

### Manual Test
```bash
# Build
mkdir build && cd build
cmake .. -DENABLE_OPENMP=ON
make openvx

# Run with specific thread count
OMP_NUM_THREADS=4 ./your_test_app

# Verify threading is active
OMP_DISPLAY_ENV=VERBOSE ./your_test_app
```

### Benchmark Comparison
```bash
# Run OpenVX benchmark
./openvx-mark --kernel Add --threads 1
./openvx-mark --kernel Add --threads 4

# Compare with OpenCV
./opencv-mark (from MIVisionX/tests/opencv_benchmark)
```

## Technical Notes

### Why Guided Scheduling?
- **OpenCV uses it** - proven optimal for image processing
- **Adaptive chunk sizes** - starts large, decreases as work completes
- **Load balancing** - handles variable row processing times

### Why Row-Based?
- **Memory access**: Rows are contiguous (cache-friendly)
- **No conflicts**: Each row is independent
- **SIMD compatibility**: Existing AVX code preserved
- **Simple**: Easy to understand and maintain

### Fallback Strategy
```cpp
if (!AgoShouldUseThreading(height, width)) {
// Use original serial implementation
return HafCpu_Add_U8_U8U8_Wrap(...);
}
// Use parallel version
```

---

*Implementation date: Sat Jun 13 2026*
*Based on OpenCV benchmark analysis showing 1.71x speedup potential*
Loading