feat(erasure_code): optimize SVE/SVE2 dot product with XOR for coeffi… - #409
feat(erasure_code): optimize SVE/SVE2 dot product with XOR for coeffi…#409zwtao40 wants to merge 3 commits into
Conversation
4a2b958 to
26c5be4
Compare
|
Hi @pablodelara, sorry to bother you. This PR has been open for a while and already received an LGTM from @liuqinfei. Could you please help review it or advise who would be the right maintainer to review/merge this change? Thanks! |
| svuint8_t src_hi2 = svlsr_x(predicate_2, src_data2, 4); | ||
| svuint8_t src_lo3 = svand_x(predicate_3, src_data3, mask0f); | ||
| svuint8_t src_hi3 = svlsr_x(predicate_3, src_data3, 4); | ||
| svuint8_t src_lo0, src_hi0, src_lo1, src_hi1, src_lo2, src_hi2, src_lo3, |
There was a problem hiding this comment.
These variables need to be initialized here, since they might be used uninitialized in lines 184 to 201.
There was a problem hiding this comment.
Thanks for pointing this out. I initialized all source nibble vectors at declaration to avoid any potential uninitialized use.
…cient=1 Optimize the GF(2^8) vector dot product implementation for ARM SVE/SVE2 by using direct XOR operations when the encoding coefficient is 1, eliminating unnecessary table lookups. Technical Details: - Add is_dest_coeff_all_one() helper to detect coefficient=1 blocks - Pre-compute coefficient status for each destination vector - For coefficient=1 blocks: use direct XOR (src_data XOR accumulator) - For other coefficients: use traditional nibble-based table lookup - Optimization applied uniformly inside gf_nvect_dot_prod_sve_unrolled() The optimization leverages the property that EC encoding matrices often have coefficient 1 for the first parity block, making XOR operations sufficient instead of full GF multiplication via table lookup. Performance Results: Kunpeng-920 (SVE): +------------------+------------+------------+--------+ | Test Case | Before | After | Speedup| +------------------+------------+------------+--------+ | 10+1 encode | 15 GB/s | 79 GB/s | 5.3x | | 10+1 decode(1) | 15 GB/s | 78 GB/s | 5.2x | | 4+2 encode | 19 GB/s | 23 GB/s | 1.2x | | 4+2 decode(1) | 24 GB/s | 85 GB/s | 3.5x | | 8+3 encode | 13 GB/s | 14 GB/s | 1.1x | | 8+3 decode(1) | 21 GB/s | 77 GB/s | 3.7x | +------------------+------------+------------+--------+ Kunpeng-950 (SVE2): +------------------+------------+------------+--------+ | Test Case | Before | After | Speedup| +------------------+------------+------------+--------+ | 10+1 encode | 13 GB/s | 84 GB/s | 6.5x | | 10+1 decode(1) | 13 GB/s | 84 GB/s | 6.5x | | 4+2 encode | 17 GB/s | 22 GB/s | 1.3x | | 4+2 decode(1) | 24 GB/s | 85 GB/s | 3.5x | | 8+3 encode | 12 GB/s | 14 GB/s | 1.2x | | 8+3 decode(1) | 12 GB/s | 88 GB/s | 7.3x | +------------------+------------+------------+--------+ Measured using erasure_code_perf tool on Huawei Kunpeng platforms. Files modified: - erasure_code/aarch64/gf_nvect_dot_prod_sve.c Signed-off-by: Chenxuqiang <chenxuqiang3@hisilicon.com> Signed-off-by: Enigmo <guotaowei4@huawei.com>
Initialize the source nibble vectors to avoid potential uninitialized use in the table lookup path. Signed-off-by: Chenxuqiang <chenxuqiang3@hisilicon.com> Signed-off-by: Enigmo <guotaowei4@huawei.com>
41b65aa to
56d4bf3
Compare
pablodelara
left a comment
There was a problem hiding this comment.
A couple of comments.
Compute source nibbles when the first non-unit coefficient is found and mark lookup table variables as const. Signed-off-by: Chenxuqiang <chenxuqiang3@hisilicon.com> Signed-off-by: Enigmo <guotaowei4@huawei.com>
|
This is merged now, thanks! Just FYI, I removed "Files modified" in commit message, as that info is already in the commit itself. Also, I added some missing "const" qualifiers. Thanks! |
This patch optimizes the GF(2^8) vector dot product implementation for ARM SVE/SVE2 by using direct XOR operations when the encoding coefficient is 1, eliminating unnecessary table lookups.
Background
In erasure coding, the encoding matrix often has coefficient 1 for the first parity block. When the coefficient is 1, the GF multiplication a × 1 = a simplifies to a direct XOR operation, avoiding the overhead of table-based multiplication.
Changes
Optimization Approach:
Added is_dest_coeff_all_one() helper function to detect coefficient=1 blocks at runtime
Pre-compute coefficient status for each destination vector before the main loop
For coefficient=1 blocks: use direct XOR ( src_data XOR accumulator )
For other coefficients: use traditional nibble-based table lookup
Optimization applied uniformly inside gf_nvect_dot_prod_sve_unrolled()
Key Benefits:
Encoding path: first parity block typically has coefficient=1 → uses XOR optimization
Decoding path: coefficient may not be 1 → automatically falls back to table lookup
No separate functions needed for encode/decode paths
Maintains original code structure and API compatibility
Performance Results
Kunpeng-920 (SVE):
+------------------+------------+------------+--------+
| Test Case | Before | After | Speedup|
+------------------+------------+------------+--------+
| 10+1 encode | 15 GB/s | 79 GB/s | 5.3x |
| 10+1 decode(1) | 15 GB/s | 78 GB/s | 5.2x |
| 4+2 encode | 19 GB/s | 23 GB/s | 1.2x |
| 4+2 decode(1) | 24 GB/s | 85 GB/s | 3.5x |
| 8+3 encode | 13 GB/s | 14 GB/s | 1.1x |
| 8+3 decode(1) | 21 GB/s | 77 GB/s | 3.7x |
+------------------+------------+------------+--------+
Kunpeng-950 (SVE2):
+------------------+------------+------------+--------+
| Test Case | Before | After | Speedup|
+------------------+------------+------------+--------+
| 10+1 encode | 13 GB/s | 84 GB/s | 6.5x |
| 10+1 decode(1) | 13 GB/s | 84 GB/s | 6.5x |
| 4+2 encode | 17 GB/s | 22 GB/s | 1.3x |
| 4+2 decode(1) | 24 GB/s | 85 GB/s | 3.5x |
| 8+3 encode | 12 GB/s | 14 GB/s | 1.2x |
| 8+3 decode(1) | 12 GB/s | 88 GB/s | 7.3x |
+------------------+------------+------------+--------+
Measured using erasure_code_perf tool on Huawei Kunpeng platforms.
Files modified: