Vectorised array operations leveraging Java Vector API for SIMD parallelism.
- Clojure >= 1.12.0
- jdk.incubator.vector
Add the following module to the list of JVM options inside your deps.edn
:
:jvm-opts ["--add-modules" "jdk.incubator.vector"]
com.github.igmonk/clj-vapi {:mvn/version "0.1.0-SNAPSHOT"}
[com.github.igmonk/clj-vapi "0.1.0-SNAPSHOT"]
The top level interface is in clj-vapi.core
.
(use 'clj-vapi.core)
Use vadd
to add two arrays element-wise:
(def sum
(vadd (int-array (range 1000))
(int-array (range 1000))))
Refer to examples/clj_vapi for more examples.
Execution time estimation using criterium:
(use 'criterium.core)
(def a (int-array (range 1000)))
(def b (int-array (range 1000)))
(quick-bench (vadd a b))
Expected output for a CPU with SIMD registers limited to 128 bit-size:
Evaluation count : 1632240 in 6 samples of 272040 calls.
Execution time mean : 397.445113 ns
Execution time std-deviation : 48.570087 ns
Execution time lower quantile : 355.713814 ns ( 2.5%)
Execution time upper quantile : 460.866929 ns (97.5%)
Overhead used : 7.036000 ns
Refer to bench/clj_vapi for more benches.