| Title: | Runtime 'SIMD' Dispatch Templates for 'C' Code in 'R' Packages |
|---|---|
| Description: | Provides templates and a working example for runtime Single Instruction Multiple Data ('SIMD') dispatch in 'C' code used by 'R' packages. Packages can stage scalar and architecture-specific kernel objects during configuration, then select compiled and CPU-supported implementations at runtime through guarded operation tables. The package also vendors the header-only 'SIMDe' library for downstream packages through the 'LinkingTo' field. |
| Authors: | Sounkou Mahamane Toure [aut, cre], Evan Nemerson [cph] (SIMDe copyright holder), SIMDe contributors [ctb] (Contributors to the bundled SIMDe header library) |
| Maintainer: | Sounkou Mahamane Toure <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 0.1.2.9001 |
| Built: | 2026-05-31 20:09:54 UTC |
| Source: | https://github.com/sounkou-bioinfo/RsimdDispatch |
Demonstration numeric kernel for the runtime dispatch template.
convolve1d() computes the same full convolution as a simple nested-loop R
definition. For each pair of positions it adds a[i] * b[j] to
out[i + j - 1]. SIMD backends vectorize the inner multiply-add over b
and the shifted output window.
convolve1d(a, b)convolve1d(a, b)
a, b
|
Numeric vectors. |
A numeric vector of length length(a) + length(b) - 1, or
numeric(0) when either input is empty.
convolve1d(c(1, 2, 3), c(10, 100))convolve1d(c(1, 2, 3), c(10, 100))
Demonstration kernel for the runtime dispatch template. count_nonzero()
counts bytes that are not 00 in a raw vector using the currently selected
backend. The default backend is "auto", which selects the best compiled
backend supported by the current CPU/runtime.
count_nonzero(x)count_nonzero(x)
x |
A raw vector. |
A double scalar giving the count of non-zero bytes. The return
type is double rather than integer to accommodate vectors longer than
.Machine$integer.max without overflow.
count_nonzero(as.raw(c(0, 1, 0, 2)))count_nonzero(as.raw(c(0, 1, 0, 2)))
Report the currently selected SIMD backend
simd_backend()simd_backend()
A character scalar naming the selected backend summary.
simd_backend()simd_backend()
use_simd_dispatch() copies the dispatch scaffold into an R package and
performs the package-name and C-prefix substitutions needed for a working
package. It writes package files, updates DESCRIPTION, .Rbuildignore,
and .gitignore, and returns the copied paths invisibly.
simd_dispatch_template_path() use_simd_dispatch( path = ".", pkg = NULL, prefix = NULL, overwrite = FALSE, quiet = FALSE )simd_dispatch_template_path() use_simd_dispatch( path = ".", pkg = NULL, prefix = NULL, overwrite = FALSE, quiet = FALSE )
path |
Package root where the template should be copied. |
pkg |
R package name. If |
prefix |
C symbol prefix used to replace |
overwrite |
Whether to overwrite existing files. |
quiet |
Whether to suppress progress messages. |
Invisibly returns copied file paths.
This function is intended for package authors. It is not needed at runtime by users of packages that already include generated dispatch code.
simd_dispatch_template_path()simd_dispatch_template_path()
Returns the requested backend, selected backend, compiled backends,
CPU-supported backends, operation-level backend availability, operation-level
selected backends, SIMDe-native backends, and target architecture information.
Calling this initializes the lazy auto-dispatch selection if it has not
already been initialized. For SIMDe provenance (version, commit, date) use
simde_info().
simd_info()simd_info()
A named list with the following elements:
dispatch_modeCharacter scalar. Internal dispatch implementation strategy string (stable across patch releases).
requested_backendCharacter scalar. The last value passed to
simd_set_backend(), or "auto" if not explicitly set.
selected_backendCharacter scalar. Summary of the currently
active backend: a backend name, "mixed", or "unavailable".
compiled_backendsCharacter vector. Backends compiled into the shared library (not necessarily supported by the current CPU).
cpu_supported_backendsCharacter vector. Backends whose required CPU features are present at runtime.
available_backendsCharacter vector. Backends that are both compiled and CPU-supported (i.e. usable).
simde_native_backendsCharacter vector. Backends for which the compiler emitted native intrinsics rather than SIMDe emulation.
operationsCharacter vector. Names of registered operations
(e.g. "count_nonzero", "convolve1d").
operation_backendsNamed list of character vectors. For each operation, the backends that provide a kernel for it.
operation_selected_backendsNamed character vector. For each
operation, the backend currently selected for dispatch (or NA if
none is resolved).
cpu_sse2Logical scalar. TRUE if SSE2 is detected at runtime.
cpu_sse41Logical scalar. TRUE if SSE4.1 is detected.
cpu_avx2Logical scalar. TRUE if AVX2 is detected.
cpu_avx512Logical scalar. TRUE if AVX-512 (F/BW/VL) is detected.
cpu_neonLogical scalar. TRUE if NEON/AdvSIMD is detected.
cpu_wasm_simd128Logical scalar. TRUE if WASM SIMD128 is
available.
target_archCharacter scalar. Compiler target CPU architecture
(e.g. "x86_64", "aarch64").
target_osCharacter scalar. Compiler target OS family
(e.g. "linux", "macos", "windows", "emscripten").
names(simd_info())names(simd_info())
Select the backend used by subsequent calls to dispatched demo kernels such
as count_nonzero() and convolve1d(). RsimdDispatch keeps all compiled
variants in one shared object and switches a guarded resolved operation
table. This makes same-process benchmarking possible.
simd_set_backend(backend = "auto")simd_set_backend(backend = "auto")
backend |
Character scalar. Use |
The selected backend summary string, invisibly. Possible values:
"<name>"All operations resolved to the same named backend.
"mixed"Different operations resolved to different backends
(only possible under "auto").
"unavailable"No operation could be resolved for the requested backend.
old <- simd_backend() simd_set_backend("scalar") simd_set_backend("auto")old <- simd_backend() simd_set_backend("scalar") simd_set_backend("auto")
simde_info() reports the version, upstream repository, pinned commit, and
commit date for the bundled header-only SIMDe library.
simde_info()simde_info()
A named list of character scalars describing the vendored SIMDe copy.
simde_info()[c("version", "commit")]simde_info()[c("version", "commit")]