SIMD
An extension of Open Graph's own: which vector instructions its kernels run on. The answers are the same on every path.
2 entries: 2 functions. Part of the Open Graph reference; All functions lists every entry on one page, with a filter. The badges say how each entry is checked.
Functions
simd_path#
Unit tests SIMD Extension
Returns the name of the vector-instruction path Open Graph's kernels run on.
const char *og_simd_path(void);
One of "avx512" (AVX-512 F/CD/BW/DQ/VL with the operating system saving the wide registers; bit counts use VPOPCNTDQ where present), "avx2" (AVX2 with FMA, BMI1/2, LZCNT, POPCNT, F16C and MOVBE), "neon" (every ARM64 CPU) or "scalar" (plain C: the reference, and the path of an x86-64 CPU without AVX2). The path is chosen once, at the first use, from what the CPU and operating system support; the environment variable OG_SIMD=scalar|avx2|avx512|neon chooses a lower path, to compare paths on one machine (a path the CPU cannot run is ignored).
Results never depend on the path: element-wise kernels do the plain loop's IEEE operations in its order, never fused, and every floating-point reduction uses one fixed order on every path (element i to lane i mod 16, each lane summed in increasing i, the 16 lanes combined by a fixed tree), so all paths agree to the last bit. The kernels serve bit sets, connected-component reachability counts, Jaccard and Dice similarity, the Fruchterman-Reingold, Kamada-Kawai and DrL layouts, the BLAS-style vector operations and the eigenvalue solvers (eigenvector centrality and others).
- Returns
- A static string: "avx512", "avx2", "neon" or "scalar".
- Complexity
- O(1) after the first call (which runs the CPU detection once, thread safe).
- Checked
- Open Graph extension, no igraph counterpart. tests/simd checks every kernel on every path the CPU runs, bit for bit, and the library functions that use them for identical results on every path.
- SIMD
- Part of the SIMD extension: it reports the path the kernels run on and runs no kernel itself.
- C name
og_simd_path- In notebooks
Og.Native.og_simd_path- igraph 1.0
- None: Open Graph's own.
- See also
simd_features
#include "og.h"
#include <stdio.h>
int main(void) {
char cpu[256];
const char *path, *best, *lowered;
og_simd_features(cpu, sizeof cpu, &path, &best, &lowered);
printf("running on %s (best %s)%s%s\n", og_simd_path(), best,
lowered ? ", lowered by OG_SIMD=" : "", lowered ? lowered : "");
printf("CPU: %s\n", cpu);
return 0;
}
simd_features#
Unit tests SIMD Extension
Reports what the CPU detection saw and which path it chose.
void og_simd_features(
char *buf,
size_t cap,
const char **path,
const char **best,
const char **lowered
);
buf receives the relevant instruction sets the CPU has, separated by spaces (on x86-64 for example "SSE4.2 POPCNT AVX AVX2 FMA ... AVX-512F ... AVX-512VPOPCNTDQ", on ARM64 "NEON"), cut to fit cap bytes. *path receives the path in use (as simd_path), *best the best path this CPU can run, and *lowered the value of OG_SIMD when it chose a lower path, otherwise NULL. Every output may be NULL. On x86-64 the AVX paths need the operating system to save the wide registers (XGETBV), not only the CPUID bits.
- Parameters
bufOutput, may be NULL: the instruction sets found.capSize of buf in bytes.pathOutput, may be NULL: the path in use.bestOutput, may be NULL: the best path this CPU runs.loweredOutput, may be NULL:OG_SIMD's value when it lowered the path, else NULL.
- Returns
- Nothing.
- Complexity
- O(cap).
- Checked
- Open Graph extension, no igraph counterpart.
- SIMD
- Part of the SIMD extension: it reports what the CPU offers and runs no kernel itself.
- C name
og_simd_features- In notebooks
Og.Native.og_simd_features- igraph 1.0
- None: Open Graph's own.
- See also
simd_path