Learn R Programming

ggmlR (version 0.8.1)

ggml_matmul_f64: GPU double-precision matrix multiply

Description

Computes A %*% B on the Vulkan GPU in full double precision (fp64), returning an ordinary R matrix, with a transparent CPU fallback. Unlike ggml_matmul (which is f32/f16 and approximate), this matches R's %*% to machine precision (~1e-15), because the kernel accumulates in double throughout.

Usage

ggml_matmul_f64(A, B, device = "auto")

Value

The product A %*% B as a numeric matrix, accurate to double precision.

Arguments

A, B

Numeric matrices with ncol(A) == nrow(B).

device

"auto" (default: GPU when present, fp64-capable and the multiply is large enough to amortise the transfer, else CPU), "gpu" (force GPU, still falls back to CPU if fp64 is unavailable), or "cpu".

Details

fp64 on the GPU is only worthwhile on hardware with fast double throughput: data-centre cards (NVIDIA Tesla P100/V100, AMD Instinct) run fp64 at 1:2 of fp32, whereas consumer GPUs cripple it (RDNA ~1:16, GeForce ~1:64), where the CPU (multithreaded double BLAS) is usually faster. Use this when you need bit-accurate double results on a capable GPU, or for numerically sensitive work where the f32 path's error is unacceptable; otherwise prefer ggml_matmul. Requires the shaderFloat64 device feature — without it (or without a GPU), the multiply silently falls back to the CPU.

See Also

ggml_matmul (faster f32/f16 approximate path).

Examples

Run this code
A <- matrix(rnorm(4), 2); B <- matrix(rnorm(4), 2)
ggml_matmul_f64(A, B, device = "cpu")

Run the code above in your browser using DataLab