Skip to contents

Currently, {anvl} is not available on CRAN, so you either have to install it via r-universe or from GitHub.

System Dependencies

The system library required during runtime is libprotobuf. Source installation requires a C++20 compiler and protoc (protobuf compiler).

CPU Installation

You can install the latest release from r-universe (prebuilt binary).

install.packages("anvl",repos = c("https://cloud.r-project.org", "https://r-xla.r-universe.dev"))

You can also install the latest release from GitHub

pak::repo_add("https://r-xla.r-universe.dev")
pak::pak("r-xla/anvl@*release")

The development version can be installed via:

pak::pak("r-xla/anvl")

PJRT Plugins

The PJRT plugins that actually execute anvl’s programs are not shipped with the package. They are downloaded and cached the first time they are needed, which requires your confirmation: an interactive session asks before downloading, and a non-interactive one aborts with an error instead of downloading behind your back.

To make the download an explicit step – in a Dockerfile layer of its own, or before a script that later runs unattended – call:

anvl::install_anvl()

The PJRT_INSTALL environment variable overrides this behaviour:

Value Effect
1 Always download, without asking. Use this in CI, scripts and Docker builds.
0 Never download; abort with instructions instead.
unset Ask in an interactive session, abort in a non-interactive one.

To confirm that your CPU installation is working, run:

library(anvl)
nv_scalar(1, device = "cpu")

GPU Installation

Running {anvl} with GPU support currently only works on Linux (amd64/x86-64) or via WSL2 on Windows (experimental).

The recommended way to use CUDA there is to install the {cuda12.8} R package, which only requires a compatible driver to be installed. You can install it from GitHub or r-universe:

pak::pak("mlverse/cudatoolkit/cuda12.8")
install.packages("cuda12.8", repos = "https://mlverse.r-universe.dev")

When the {cuda12.8} package is not installed, the correct runtime libraries need to be installed on the system and discoverable via LD_LIBRARY_PATH. The specific versions of the CUDA runtime libraries provided with {cuda12.8} are listed here.

To confirm that your CUDA installation is working, run:

library(anvl)
nv_scalar(1, device = "cuda")

Troubleshooting

To trouble-shoot the CUDA installation, run the following in a new R session for maximum debug output.

Sys.setenv(PJRT_DEBUG = "1", TF_CPP_MIN_LOG_LEVEL = "0")
anvl::nv_scalar(1, device = "cuda")

Note that if another package is using a different cudatoolkit package (e.g. when using {torch}), there might be some issues. In this case, use separate R processes, e.g. via {mirai}.

Docker

Prebuilt Docker images are available in r-xla/docker. This includes a CUDA and CPU build for amd64/x86-64 architecture:

Available Images

Image Description
anvl-cpu CPU support, based on rocker/r-ver
anvl-cuda GPU support with CUDA 12.8

Note that running the GPU container requires the NVIDIA Container Toolkit to be installed on the host. Once installed (and the Docker daemon restarted), pass --gpus all to docker run to expose the host GPUs to the container:

docker run --rm -it --gpus all ghcr.io/r-xla/anvl-cuda:latest R

You can verify that the GPU is visible inside the container by running nvidia-smi, or from R:

anvl::nv_scalar(1, device = "cuda")

Tags

Each image is available with two tags:

Tag Description
:latest Built from the main branch (rebuilt daily)
:release Built from the latest release