Repository navigation
sve2 HISTSEG support for fast ondemand parsing on ARM - #108
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #108 +/- ##
=======================================
Coverage 69.67% 69.67%
=======================================
Files 27 27
Lines 3706 3706
Branches 1189 1189
=======================================
Hits 2582 2582
Misses 211 211
Partials 913 913 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
#110 The CI bugs have been fixed,please rebase master |
|
@xiegx94 |
| #include "../common/arm_common/skip.inc.h" | ||
|
|
||
| // Requires clang vx or GCC>=14 | ||
| #if (defined(__clang__) && (__clang_major__ >= 14)) || \ |
There was a problem hiding this comment.
__has_include would be better
| #if (defined(__clang__) && (__clang_major__ >= 14)) || \ | ||
| (defined(__GNUC__) && !defined(__clang__) && (__GNUC__ >= 14)) | ||
|
|
||
| #define USE_SVE_HIST 1 |
There was a problem hiding this comment.
check USE_SVE_HIST is not defined.
|
@xiegx94 |
d9a222b to
15ed14a
Compare
|
Hi @xiegx94 :) any chance you can look at it soon? |
|
PTAL :) |
| uint64_t escaped = 0; | ||
| uint64_t bs_bits = 0; | ||
| if (backslash_count) { | ||
| uint64_t bs_bits = v.eq('\\'); |
There was a problem hiding this comment.
same variable bs_bits with line 54
| } | ||
|
|
||
| sonic_force_inline uint32_t count_chars(const uint8x16_t &data, | ||
| svuint8_t &tokens, uint8_t left, |
There was a problem hiding this comment.
uint8_t left, uint8_t right unused ?
|
|
||
| #ifdef __has_include | ||
| #if __has_include(<arm_neon_sve_bridge.h>) | ||
| #include <arm_neon_sve_bridge.h> |
There was a problem hiding this comment.
why include sys header inside sonic_json::internal::sve2_128 namespace
| #ifdef __has_include | ||
| #if __has_include(<arm_neon_sve_bridge.h>) | ||
| #include <arm_neon_sve_bridge.h> | ||
| #ifndef USE_SVE_HIST |
There was a problem hiding this comment.
| #ifndef USE_SVE_HIST | |
| #ifndef SONIC_USE_SVE_HIST |
| #if __has_include(<arm_neon_sve_bridge.h>) | ||
| #include <arm_neon_sve_bridge.h> | ||
| #ifndef USE_SVE_HIST | ||
| #define USE_SVE_HIST 1 |
| // only backslahes and no quotes, the whole 64 bytes are inside a string | ||
| // so we dont care about left & right | ||
| // just check if the last character is a backslash | ||
| prev_escaped = (p[63] == '\\'); |
There was a problem hiding this comment.
This fast path tracks only whether the last byte of a 64-byte block is a backslash, but the escape state depends on the parity of consecutive trailing backslashes.
For example, consider a block ending with two backslashes, followed by a closing quote in the next block:
["<125 times 'a'>\\"]
The two backslashes represent one literal backslash, so the following quote is not escaped and should close the string. However, the current code sets prev_escaped = true, treats that quote as escaped, and may reject the valid JSON as an unclosed container.
dcf7c82 to
e00f215
Compare
|
@yangzhg all the issues should been solved :) thanks a lot for the awesome review |
|
@yangzhg thanks for landing this!!! |
This PR uses the SVE2 HISTSEG instruction to improve performance of ondemand parsing in ARM cpus
https://developer.arm.com/documentation/ddi0602/latest/SVE-Instructions/HISTSEG--Count-matching-elements-in-vector-segments-
Creating the bitmasks for each structural character is very expensive in ARM due to the lack of pmovmskb similar instructions. Histseg gives us the number of characters of interest in a single instruction with low latency and high throughput in neoverse v2 cpus.
This allows us to skip mask creation of characters that are not present and even to implement some fast path codes when we have only quotes for example. It is worth noting that x86 doesn't have an equivalent instruction and the avx2 VP2INTERSECT instruction doesn't support int8 datatypes.
Performance:
Master branch
This PR
This is faster than even the most recent x86 cpus which shows result around 24Gi/s for twitter.
Thanks to @supermartian !
This PR is contributed by nvidia.