Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 52 additions & 1 deletion .github/workflows/test-install.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
on:
push:
branches: [main]
branches:
- main
pull_request:
workflow_dispatch:

name: test-install

Expand Down Expand Up @@ -58,3 +60,52 @@ jobs:

echo ""
echo "=== All libraries have \$ORIGIN in RUNPATH ==="

test-rocm:
runs-on: ubuntu-22.04
env:
ROCM_COMPONENTS: core,hipblas-common,hip-dev,hsa-dev

name: rocm6.4

steps:
- uses: actions/checkout@v5

- uses: r-lib/actions/setup-r@v2
with:
r-version: release

- name: Install package
run: |
cd rocm6.4
R CMD INSTALL .

- name: Verify paths and headers
run: |
Rscript -e '
stopifnot(requireNamespace("rocm6.4", quietly = TRUE))
inc <- rocm6.4::include_path()
lib <- rocm6.4::lib_path()
cat("include_path:", inc, "\n")
cat("lib_path:", lib, "\n")
stopifnot(file.exists(file.path(inc, "hip", "hip_runtime.h")))
stopifnot(file.exists(file.path(inc, "hsa", "hsa.h")))
stopifnot(file.exists(file.path(inc, "hipblas-common", "hipblas-common.h")))
ver <- readLines(file.path(inc, "..", ".info", "version"))
cat("rocm version:", ver, "\n")
stopifnot(grepl("^6\\.4", ver))
stopifnot(length(list.files(lib, pattern = "\\.so")) > 0)
'

- name: Verify RPATH contains \$ORIGIN
run: |
LIB_PATH=$(Rscript -e 'cat(rocm6.4::lib_path())')
for so in "$LIB_PATH"/*.so*; do
[ -f "$so" ] || continue
[ -L "$so" ] && continue
readelf -d "$so" | grep -q '\$ORIGIN' || {
echo "FAIL: $(basename "$so") is missing \$ORIGIN in RPATH"
exit 1
}
done
echo "=== All ROCm libraries have \$ORIGIN in RPATH ==="
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata

# ROCm configure output
rocm*/inst/lib/
rocm*/inst/include/
rocm*/inst/rocm/
rocm*/inst/.info/
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ install.packages("remotes")
# Install a specific CUDA version
remotes::install_github("mlverse/cudatoolkit/cuda12.6")
remotes::install_github("mlverse/cudatoolkit/cuda12.8")
remotes::install_github("mlverse/cudatoolkit/cuda12.9")
remotes::install_github("mlverse/cudatoolkit/cuda13.2")

# Install a specific ROCm version (see ROCM.md for details)
remotes::install_github("mlverse/cudatoolkit/rocm6.4")

```

### Installing specific components
Expand Down
205 changes: 205 additions & 0 deletions ROCM.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
# cudatoolkit (ROCm)

R packages that provide ROCm toolkit binaries by downloading pre-built `.deb`
packages from `repo.radeon.com` at install time. Source packages are
lightweight — all ROCm components are fetched during installation, without
root (no `apt install`).

## Packages

| Package | ROCm | Source prefix |
| --------- | ---- | ----------------- |
| `rocm6.4` | 6.4 | `opt/rocm-6.4.0/` |

## Installation

```r
# Install the remotes package if needed
install.packages("remotes")

# Install the ROCm toolkit
remotes::install_github("mlverse/cudatoolkit/rocm6.4", ref = "rocm6.4")
```

`configure` downloads the `.deb` files listed in `inst/components.tsv`,
extracts them with `dpkg-deb -x` (or `ar` + `tar` on non-Debian systems) and
installs the payload into the R library.

### Installing specific components

By default, a lean set of components is installed (runtime, HSA, HIP headers,
device libs, comgr, rocBLAS/hipBLAS, hipFFT, hipSPARSE, hipSOLVER,
rocRAND/hipRAND and their `-dev` packages). Set the `ROCM_COMPONENTS`
environment variable to install only what you need:

```r
Sys.setenv(ROCM_COMPONENTS = "runtime,rocblas,hipblas-common")
remotes::install_github("mlverse/cudatoolkit/rocm6.4", ref = "rocm6.4")
```

Use `ROCM_COMPONENTS=all` to install every component. `miopen`, `rccl`,
`hipblaslt` and the header-only Thrust/CUB/rocPRIM packages are opt-in.

Installing all components is large (~15 GB): `rocblas` is ~3.6 GB,
`hipblaslt` ~2.7 GB and `miopen` ~2.2 GB installed. Set `ROCM_DEB_CACHE` to a
persistent directory to avoid re-downloading `.deb` files:

```sh
ROCM_DEB_CACHE=~/.cache/rocm-debs ROCM_COMPONENTS=all R CMD INSTALL rocm6.4
```

### Overriding platform detection

ROCm packages are only available for Linux x86_64; platform detection fails on
other platforms. `ROCM_PLATFORM` exists mainly for tests and error messages:

```r
Sys.setenv(ROCM_PLATFORM = "linux-x64")
```

## Usage

```r
library(rocm6.4)

# Path to shared libraries (*.so)
lib_path()

# Path to the shared headers (include/hip, include/rocblas, ...)
include_path()

# Validate a component name, still returns the shared include root
include_path("hipsparse")

# Path to component binaries (e.g., rocminfo, hipcc helpers)
bin_path("rocminfo")

# Path to a component's installation root
rocm_path("runtime")

# Alias for lib_path(); all components share one library directory
all_lib_paths()
```

`include_path()` contains `hip/`, `rocblas/`, `hipsparse/`, ... just like
`/opt/rocm/include`; the version metadata is available at
`file.path(include_path(), "..", ".info", "version")`.

## Available components

core, runtime, hsa-runtime, hsa-dev, comgr, hip-dev, device-libs, rocblas,
rocblas-dev, hipblas, hipblas-dev, hipblas-common, hipfft, hipfft-dev,
hipsparse, hipsparse-dev, hipsolver, hipsolver-dev, rocrand, rocrand-dev,
hiprand, hiprand-dev, rccl, rccl-dev, miopen, miopen-dev, hipblaslt,
hipblaslt-dev, rocthrust-dev, hipcub-dev, rocprim-dev, rocminfo

The default set is: core, runtime, hsa-runtime, hsa-dev, hip-dev, device-libs,
comgr, rocblas, rocblas-dev, hipblas, hipblas-dev, hipblas-common, hipfft,
hipfft-dev, hipsparse, hipsparse-dev, hipsolver, hipsolver-dev, rocrand,
rocrand-dev, hiprand, hiprand-dev.

`inst/components.tsv` is generated by `resolve-rocm.sh` and has the columns:

```
component deb_package version filename extract linux_only
```

`component` is the name used by the public API, `deb_package` is the Debian
package, `filename` is the pool-relative path and `extract` is the comma
separated list of top-level directories to keep (`lib`, `include`, `bin`,
`share`, `amdgcn`).

## Supported platforms

- Linux x86_64 (Ubuntu 22.04 "jammy" `.deb` payload)

macOS and Windows are not supported (no ROCm). Other Linux distributions can
work when the `.deb` payload and its system dependencies are compatible.

## Development

The repo uses a `shared-rocm/` directory for files common to all ROCm versions.
Version-specific configuration lives in each `rocm*/inst/` directory.

### Installed layout

```
inst/
include/ all headers (include/hip, include/rocblas, ...)
lib/ all shared libraries (single directory)
.info/version ROCm version (copied from rocm-core)
rocm/<component>/
bin/ tools (hipcc helpers, rocminfo, ...)
share/ licenses and data
amdgcn/ device bitcode (device-libs only)
lib/cmake/ CMake package files
.info/version ROCm version (copied from rocm-core)
```

Headers and libraries are merged into shared directories because ROCm
components resolve each other by soname and include path, mirroring
`/opt/rocm/{include,lib}`. `rocm_path(component)` keeps per-component
binaries, data and CMake files namespaced. `configure` sets `RPATH` to
`$ORIGIN:$ORIGIN/rocm_sysdeps/lib:$ORIGIN/host-math/lib` so the shared
directory is used before `LD_LIBRARY_PATH`.

### Updating component versions

1. Edit `rocm*/inst/rocm-version.env` with new toolkit/suite versions
(`ROCM_MINOR`, `ROCM_PREFIX`, `ROCM_APT_BASE`, `ROCM_APT_SUITE`).
2. Run `./resolve-rocm.sh` to regenerate `inst/components.tsv` from the apt
`Packages.gz` index.
3. Run `./sync-rocm.sh` to copy shared files and regenerate DESCRIPTION files.
4. Commit and push.

### Adding a new ROCm version

1. Create a new directory: `mkdir -p rocm{X.Y}/inst`
2. Add `rocm{X.Y}/inst/rocm-version.env` with the version info:
```
ROCM_MINOR="X.Y"
ROCM_MAJOR="X"
ROCM_PATCH="Z"
ROCM_PREFIX="opt/rocm-X.Y.Z"
ROCM_APT_BASE="https://repo.radeon.com/rocm/apt/X.Y"
ROCM_APT_SUITE="jammy"
PKG_VERSION="0.1.0"
ROCM_DEFAULT_COMPONENTS="..."
```
3. Run `./resolve-rocm.sh` and `./sync-rocm.sh`.
4. Commit and push.

### Editing shared files

Edit files in `shared-rocm/` (`configure`, `NAMESPACE`, `R/paths.R`, `LICENSE`,
`DESCRIPTION.template`), then run `./sync-rocm.sh` to propagate changes to all
packages.

### CI

`.github/workflows/test-install.yaml` has a `test-rocm` job that installs a
small component subset (`core,hipblas-common,hip-dev,hsa-dev`) and checks the
API, headers, version metadata and `$ORIGIN` RPATH.

## Relationship to torch

The torch ROCm CI uses:

1. `rocm6.4` for the ROCm SDK (this package);
2. the official libtorch ROCm archive from `download.pytorch.org`
(`libtorch-shared-with-deps-<version>+rocm<X.Y>.zip`).

The kit stages libtorch with `--from-zip` and reads the SDK paths from
`rocm_path()` / `include_path()` (`ROCM_PATH` = the installed package root);
no Python venv is involved.

## Open questions

- `hipcc`/LLVM are not included yet. Building ROCm kernels from R needs
`clang`/`lld` (the `rocm-llvm` package); add it when needed.
- CI: a full install is too heavy for every run; the `test-rocm` job uses a
small subset and `ROCM_DEB_CACHE` can be cached.
- Generate `man/` from the roxygen comments before a release (the package
currently installs without help pages).
- Compatibility with `load_cudatoolkit_libs()` in `{torch}` (package-name
detection, ROCm vs CUDA) is still to be validated.
Loading
Loading