Systems
vgpu
Runs vector math on the GPU when there is one, and falls back otherwise.
Released v1.0.0 · 2026-09-28use "stdlib/gpu.ven"
Vector math on the GPU when there is one, with CPU fallbacks: element wise operations, dot products and matrix multiplication above a size threshold.
print vector_add_cpu([1.0, 2.0, 3.0], [10.0, 20.0, 30.0])
:: [11.0, 22.0, 33.0]
Reference (32 functions)
API reference
elementwise_gpu_threshold()
The List-length threshold at or above which an elementwise vector op dispatches to the GPU.
elementwise_gpu_threshold() == 2000dot_product_gpu_threshold()
The List-length threshold at or above which dot_product_accelerated dispatches to the GPU.
dot_product_gpu_threshold() == 2000matrix_multiply_gpu_threshold()
The multiply-add-count threshold at or above which matrix_multiply_accelerated dispatches to the GPU.
matrix_multiply_gpu_threshold() == 1728gpu_is_available()
Reports whether real GPU dispatch is usable right now, on this runtime and this machine.
available = gpu_is_available()
print available == yes or available == no
:: prints: yes (gpu_is_available() always returns a real boolean, never raises)gpu_status()
A human-readable one-line summary of whether GPU acceleration is available, and why not if it isn't.
print contains(gpu_status(), "GPU acceleration")
:: prints: yes (true on every virtual machine)check_same_length(a, b, who)
Raises unless two Lists have the same length.
check_same_length([1.0, 2.0], [3.0, 4.0], "example")
:: does nothing, since both lists have length 2check_matrix_multiply_shapes(a_flat, a_rows, a_cols, b_flat, b_cols, who)
Raises unless two flat matrices' lengths match the claimed multiply dimensions.
check_matrix_multiply_shapes([1.0, 2.0, 3.0, 4.0], 2, 2, [5.0, 6.0, 7.0, 8.0], 2, "example")
:: does nothing, since both flat lists have the expected 4 elementssized_placeholder_cpu(n, seed_list)
Builds a fresh List of exactly n elements in true O(n) time, for callers to fill by index.
placeholder = sized_placeholder_cpu(3, [1.0])
print length(placeholder)
:: prints: 3Elementwise vector ops
vector_add_cpu(a, b)
The pure-Venutian CPU fallback for elementwise vector addition.
print vector_add_cpu([1.0, 2.0, 3.0], [10.0, 20.0, 30.0])
:: prints: [11.0, 22.0, 33.0]vector_add_accelerated(a, b)
Adds two Lists elementwise, on the GPU when available and worthwhile, otherwise on the CPU.
print vector_add_accelerated([1.0, 2.0, 3.0], [10.0, 20.0, 30.0])
:: prints: [11.0, 22.0, 33.0]vector_subtract_cpu(a, b)
The pure-Venutian CPU fallback for elementwise vector subtraction.
print vector_subtract_cpu([10.0, 20.0, 30.0], [1.0, 2.0, 3.0])
:: prints: [9.0, 18.0, 27.0]vector_subtract_accelerated(a, b)
Subtracts two Lists elementwise, on the GPU when available and worthwhile, otherwise on the CPU.
print vector_subtract_accelerated([10.0, 20.0, 30.0], [1.0, 2.0, 3.0])
:: prints: [9.0, 18.0, 27.0]vector_multiply_cpu(a, b)
The pure-Venutian CPU fallback for elementwise vector multiplication.
print vector_multiply_cpu([2.0, 3.0, 4.0], [5.0, 6.0, 7.0])
:: prints: [10.0, 18.0, 28.0]vector_multiply_accelerated(a, b)
Multiplies two Lists elementwise, on the GPU when available and worthwhile, otherwise on the CPU.
print vector_multiply_accelerated([2.0, 3.0, 4.0], [5.0, 6.0, 7.0])
:: prints: [10.0, 18.0, 28.0]scalar_multiply_cpu(a, scalar)
The pure-Venutian CPU fallback for scaling a List by a single Number.
print scalar_multiply_cpu([1.0, 2.0, 3.0], 2.5)
:: prints: [2.5, 5.0, 7.5]scalar_multiply_accelerated(a, scalar)
Scales a List by a single Number, on the GPU when available and worthwhile, otherwise on the CPU.
print scalar_multiply_accelerated([1.0, 2.0, 3.0], 2.5)
:: prints: [2.5, 5.0, 7.5]Elementwise math
map_sqrt_cpu(a)
The pure-Venutian CPU fallback for elementwise square root.
print map_sqrt_cpu([4.0, 9.0, 16.0])
:: prints: [2.0, 3.0, 4.0]map_sqrt_accelerated(a)
Takes the elementwise square root of a List, on the GPU when available and worthwhile, otherwise on the CPU.
print map_sqrt_accelerated([4.0, 9.0, 16.0])
:: prints: [2.0, 3.0, 4.0]map_exp_cpu(a)
The pure-Venutian CPU fallback for elementwise natural exponential.
result = map_exp_cpu([0.0, 1.0])
print result[0]
:: prints: 1.0map_exp_accelerated(a)
Takes the elementwise natural exponential of a List, on the GPU when available and worthwhile, otherwise on the CPU.
result = map_exp_accelerated([0.0, 1.0])
print result[0]
:: prints: 1.0map_log_cpu(a)
The pure-Venutian CPU fallback for elementwise natural logarithm.
e = 2.718281828459045
result = map_log_cpu([1.0, e])
print result[0]
:: prints: 0.0map_log_accelerated(a)
Takes the elementwise natural logarithm of a List, on the GPU when available and worthwhile, otherwise on the CPU.
e = 2.718281828459045
result = map_log_accelerated([1.0, e])
print result[0]
:: prints: 0.0map_sin_cpu(a)
The pure-Venutian CPU fallback for elementwise sine.
print map_sin_cpu([0.0])
:: prints: [0.0]map_sin_accelerated(a)
Takes the elementwise sine of a List, on the GPU when available and worthwhile, otherwise on the CPU.
print map_sin_accelerated([0.0])
:: prints: [0.0]map_cos_cpu(a)
The pure-Venutian CPU fallback for elementwise cosine.
print map_cos_cpu([0.0])
:: prints: [1.0]map_cos_accelerated(a)
Takes the elementwise cosine of a List, on the GPU when available and worthwhile, otherwise on the CPU.
print map_cos_accelerated([0.0])
:: prints: [1.0]reduce_sum_cpu(a)
The pure-Venutian CPU fallback for summing a List into one Number.
print reduce_sum_cpu([1.0, 2.0, 3.0, 4.0])
:: prints: 10.0reduce_sum_accelerated(a)
Sums a List into one Number, on the GPU whenever it's available, with no size threshold.
print reduce_sum_accelerated([1.0, 2.0, 3.0, 4.0])
:: prints: 10.0dot_product_cpu(a, b)
The pure-Venutian CPU fallback for the dot product of two Lists.
print dot_product_cpu([1.0, 2.0, 3.0], [4.0, 5.0, 6.0])
:: prints: 32.0dot_product_accelerated(a, b)
Computes the dot product of two Lists, on the GPU when available and worthwhile, otherwise on the CPU.
print dot_product_accelerated([1.0, 2.0, 3.0], [4.0, 5.0, 6.0])
:: prints: 32.0Matrix multiply
matrix_multiply_cpu(a_flat, a_rows, a_cols, b_flat, b_cols)
The pure-Venutian CPU fallback for row-major flat-List matrix multiply.
a = [1.0, 2.0, 3.0, 4.0]
b = [5.0, 6.0, 7.0, 8.0]
print matrix_multiply_cpu(a, 2, 2, b, 2)
:: prints: [19.0, 22.0, 43.0, 50.0]matrix_multiply_accelerated(a_flat, a_rows, a_cols, b_flat, b_cols)
Multiplies two row-major flat-List matrices, on the GPU when available and worthwhile, otherwise on the CPU.
a = [1.0, 2.0, 3.0, 4.0]
b = [5.0, 6.0, 7.0, 8.0]
print matrix_multiply_accelerated(a, 2, 2, b, 2)
:: prints: [19.0, 22.0, 43.0, 50.0]