You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -60,6 +60,15 @@ Let's implement three versions of our search function:
60
60
Create a generic implementation in C, checking each element individually against each key. Open a editor of your choice and copy the code shown into a file named `sve2_match_demo.c`:
61
61
62
62
```c
63
+
#include<arm_sve.h>
64
+
#include<inttypes.h>
65
+
#include<stddef.h>
66
+
#include<stdint.h>
67
+
#include<stdio.h>
68
+
#include<stdlib.h>
69
+
#include<string.h>
70
+
#include<time.h>
71
+
63
72
intsearch_generic_u8(const uint8_t *hay, size_t n, const uint8_t *keys,
64
73
size_t nkeys) {
65
74
for (size_t i = 0; i < n; ++i) {
@@ -186,6 +195,54 @@ int search_sve2_match_u8_unrolled(const uint8_t *hay, size_t n, const uint8_t *k
186
195
}
187
196
return 0;
188
197
}
198
+
199
+
// Optimized 16-bit version with unrolling
200
+
int search_sve2_match_u16_unrolled(const uint16_t *hay, size_t n, const uint16_t *keys,
201
+
size_t nkeys) {
202
+
if (nkeys == 0) return 0;
203
+
const size_t VL = svcnth();
204
+
svbool_t pg = svptrue_b16();
205
+
206
+
// Prepare key vector
207
+
uint16_t tmp[128]__attribute__((aligned(64)));
208
+
for (size_t i = 0; i < VL; ++i) tmp[i] = keys[i % nkeys];
if (svptest_any(pg, svmatch_u16(pg, block, keyvec))) return 1;
236
+
}
237
+
238
+
// Handle remainder
239
+
for (; i < n; ++i) {
240
+
uint16_t v = hay[i];
241
+
for (size_t k = 0; k < nkeys; ++k)
242
+
if (v == keys[k]) return 1;
243
+
}
244
+
return 0;
245
+
}
189
246
```
190
247
The main highlights of this implementation are:
191
248
- Processes 4 vectors per iteration instead of just one
@@ -195,7 +252,7 @@ The main highlights of this implementation are:
195
252
196
253
## Benchmarking Framework
197
254
198
-
To compare the performance of the three implementations, you will use a benchmarking framework that measures the execution time of each implementation:
255
+
To compare the performance of the three implementations, you will use a benchmarking framework that measures the execution time of each implementation. You will also add helper functions for membership testing that are needed to setup the test data with controlled hit rates:
@@ -234,7 +428,7 @@ Now run the benchmark on a dataset of 65,536 elements (2^16) with a 0.001% hit r
234
428
235
429
```bash
236
430
./sve2_match_demo $((1<<16)) 3 0.00001
237
-
431
+
```
238
432
The output will look like:
239
433
240
434
```output
@@ -299,13 +493,9 @@ When running on a Graviton4 instance with Ubuntu 24.04 and a dataset of 65,536 e
299
493
| 0.01% | 21.00x | 27.08x |
300
494
| 0.1% | 17.25x | 20.97x |
301
495
302
-
# Understanding the Performance Results
303
-
304
-
The benchmark results reveal several important insights about the performance characteristics of SVE2 MATCH instructions:
305
496
306
497
### Impact of Hit Rate on Performance
307
-
308
-
The most striking observation is how the performance advantage of SVE2 MATCH varies with the hit rate:
498
+
The benchmark results reveal several important insights about the performance characteristics of SVE2 MATCH instructions. The most striking observation is how the performance advantage of SVE2 MATCH varies with the hit rate:
309
499
310
500
1.**Very Low Hit Rates (0% - 0.001%)**:
311
501
- For 8-bit data, SVE2 MATCH Unrolled achieves an impressive 90-95x speedup
@@ -338,32 +528,32 @@ The unrolled implementation consistently outperforms the basic SVE2 MATCH implem
338
528
339
529
This demonstrates the value of combining algorithmic optimizations (loop unrolling, prefetching) with hardware-specific instructions for maximum performance.
340
530
341
-
## Applications of SVE2 MATCH
531
+
###Applications of SVE2 MATCH
342
532
343
-
The SVE2 MATCH instruction can be applied to various real-world scenarios:
533
+
The SVE2 MATCH instruction can be applied to various real-world scenarios such as:
344
534
345
-
### 1. Database Systems
535
+
**Database Systems**
346
536
347
537
In database systems, MATCH can accelerate:
348
538
- String pattern matching in text columns
349
539
- Value existence checks in arrays
350
540
- Filtering operations in columnar databases
351
541
352
-
### 2. Text Processing
542
+
**Text Processing**
353
543
354
544
For text processing applications, MATCH can speed up:
0 commit comments