as_gpu_matrix: Wrap a matrix so multiplies run on the GPU

View source: R/gpu_linalg.R

as_gpu_matrixR Documentation

Wrap a matrix so multiplies run on the GPU

Description

Tags a matrix as GPU-backed. In an expression like as_gpu_matrix(A) %*% B, the multiply dispatches to ggml_matmul (Vulkan GPU with CPU fallback) instead of R's built-in. Only one operand needs wrapping. crossprod() and tcrossprod() on a wrapped matrix likewise use the GPU.

Usage

as_gpu_matrix(x, device = "auto", prec = "f32")

Arguments

x

A numeric matrix (or something coercible with as.matrix).

device

"auto" (default), "gpu" or "cpu"; see ggml_matmul.

prec

"f32" (default) or "f16"; see ggml_matmul.

Value

A ggml_matrix.

Examples

A <- matrix(rnorm(9), 3)
B <- matrix(rnorm(9), 3)
as_gpu_matrix(A, device = "cpu") %*% B

ggmlR documentation built on July 14, 2026, 1:08 a.m.