diff --git a/.github/workflows/test-install.yaml b/.github/workflows/test-install.yaml index 3c6bb7e..6bec99c 100644 --- a/.github/workflows/test-install.yaml +++ b/.github/workflows/test-install.yaml @@ -1,7 +1,9 @@ on: push: - branches: [main] + branches: + - main pull_request: + workflow_dispatch: name: test-install @@ -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 ===" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bac4972 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +.Rproj.user +.Rhistory +.RData +.Ruserdata + +# ROCm configure output +rocm*/inst/lib/ +rocm*/inst/include/ +rocm*/inst/rocm/ +rocm*/inst/.info/ diff --git a/README.md b/README.md index 5998868..e58d918 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/ROCM.md b/ROCM.md new file mode 100644 index 0000000..12b0075 --- /dev/null +++ b/ROCM.md @@ -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// + 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-+rocm.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. diff --git a/resolve-rocm.sh b/resolve-rocm.sh new file mode 100755 index 0000000..7e77c02 --- /dev/null +++ b/resolve-rocm.sh @@ -0,0 +1,112 @@ +#!/bin/sh + +# Regenerates rocm*/inst/components.tsv from the repo.radeon.com apt index. +# Run from the repository root (or anywhere; paths are resolved relative to +# this script). Requires curl/wget and gzip. +# +# The pinned versions come from the apt index of the configured suite, so +# update ROCM_APT_SUITE when targeting a different Ubuntu release. + +set -e + +SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) + +# component deb package extract +COMPONENTS=' +core rocm-core lib,include,share +runtime hip-runtime-amd lib,include,share +hsa-runtime hsa-rocr lib,include,share +hsa-dev hsa-rocr-dev lib,include +comgr comgr lib,include +hip-dev hip-dev lib,include,bin,share +device-libs rocm-device-libs lib,include,amdgcn +rocblas rocblas lib +rocblas-dev rocblas-dev lib,include +hipblas hipblas lib +hipblas-dev hipblas-dev lib,include +hipblas-common hipblas-common-dev lib,include +hipblaslt hipblaslt lib +hipblaslt-dev hipblaslt-dev lib,include +hipfft hipfft lib +hipfft-dev hipfft-dev lib,include +hipsparse hipsparse lib +hipsparse-dev hipsparse-dev lib,include +hipsolver hipsolver lib +hipsolver-dev hipsolver-dev lib,include +rocrand rocrand lib +rocrand-dev rocrand-dev lib,include +hiprand hiprand lib +hiprand-dev hiprand-dev lib,include +rccl rccl lib +rccl-dev rccl-dev lib,include +miopen miopen-hip lib +miopen-dev miopen-hip-dev lib,include +rocthrust-dev rocthrust-dev include +hipcub-dev hipcub-dev include +rocprim-dev rocprim-dev include +rocminfo rocminfo bin +' + +download_file() { + url="$1"; dest="$2" + if command -v curl > /dev/null 2>&1; then + curl -fsSL -o "$dest" "$url" + elif command -v wget > /dev/null 2>&1; then + wget -q -O "$dest" "$url" + else + echo "ERROR: Neither curl nor wget found." >&2 + exit 1 + fi +} + +TMPDIR=$(mktemp -d) +trap 'rm -rf "$TMPDIR"' EXIT + +for pkg_dir in "$SCRIPT_DIR"/rocm*/; do + [ -d "$pkg_dir/inst" ] || continue + version_env="$pkg_dir/inst/rocm-version.env" + [ -f "$version_env" ] || continue + + unset ROCM_MINOR ROCM_MAJOR ROCM_PATCH ROCM_PREFIX ROCM_APT_BASE ROCM_APT_SUITE PKG_VERSION + . "$version_env" + + index_gz="${TMPDIR}/Packages-${ROCM_MINOR}.gz" + index_txt="${TMPDIR}/Packages-${ROCM_MINOR}" + url="${ROCM_APT_BASE}/dists/${ROCM_APT_SUITE}/main/binary-amd64/Packages.gz" + + echo "==> ${pkg_dir} (ROCm ${ROCM_MINOR}, suite ${ROCM_APT_SUITE})" + echo " ${url}" + download_file "$url" "$index_gz" + gzip -dc "$index_gz" > "$index_txt" + + out="$pkg_dir/inst/components.tsv" + printf 'component\tdeb_package\tversion\tfilename\textract\tlinux_only\n' > "$out" + + echo "$COMPONENTS" | while read -r component deb extract; do + [ -z "$component" ] && continue + + row=$(awk -v pkg="$deb" ' + BEGIN { RS = ""; FS = "\n" } + { + p = ""; v = ""; f = "" + for (i = 1; i <= NF; i++) { + if ($i ~ /^Package: /) p = substr($i, 10) + if ($i ~ /^Version: /) v = substr($i, 10) + if ($i ~ /^Filename: /) f = substr($i, 11) + } + if (p == pkg) { print v "\t" f; exit } + } + ' "$index_txt") + + if [ -z "$row" ]; then + echo " ERROR: package '${deb}' not found in the index." >&2 + exit 1 + fi + + ver=$(printf '%s' "$row" | cut -f1) + filename=$(printf '%s' "$row" | cut -f2) + printf '%s\t%s\t%s\t%s\t%s\tyes\n' \ + "$component" "$deb" "$ver" "$filename" "$extract" >> "$out" + echo " ${component}: ${deb} ${ver}" + done +done diff --git a/rocm6.4/DESCRIPTION b/rocm6.4/DESCRIPTION new file mode 100644 index 0000000..c747616 --- /dev/null +++ b/rocm6.4/DESCRIPTION @@ -0,0 +1,19 @@ +Package: rocm6.4 +Title: ROCm 6.4 Toolkit Libraries +Version: 0.1.0 +Authors@R: + person("Daniel", "Falbel", , "daniel@posit.co", role = c("aut", "cre")) +Description: Provides ROCm 6.4 native libraries (HIP runtime, HSA, + rocBLAS, hipBLAS, hipBLASLt, hipFFT, hipSPARSE, hipSOLVER, rocRAND, + hipRAND, RCCL, MIOpen, device libraries, and their development headers) + by downloading pre-built packages from repo.radeon.com at install time. + Intended to be used as a dependency by packages that require ROCm + 6.4. +SystemRequirements: Linux x86_64; not supported on macOS or Windows. +Imports: stats, utils +License: MIT + file LICENSE +URL: https://github.com/mlverse/cudatoolkit +BugReports: https://github.com/mlverse/cudatoolkit/issues +Encoding: UTF-8 +Roxygen: list(markdown = TRUE) +RoxygenNote: 7.3.2 diff --git a/rocm6.4/LICENSE b/rocm6.4/LICENSE new file mode 100644 index 0000000..fc752b6 --- /dev/null +++ b/rocm6.4/LICENSE @@ -0,0 +1,2 @@ +YEAR: 2026 +COPYRIGHT HOLDER: Daniel Falbel diff --git a/rocm6.4/NAMESPACE b/rocm6.4/NAMESPACE new file mode 100644 index 0000000..5ebd06a --- /dev/null +++ b/rocm6.4/NAMESPACE @@ -0,0 +1,7 @@ +# Generated by roxygen2: do not edit by hand + +export(all_lib_paths) +export(bin_path) +export(include_path) +export(lib_path) +export(rocm_path) diff --git a/rocm6.4/R/paths.R b/rocm6.4/R/paths.R new file mode 100644 index 0000000..f746558 --- /dev/null +++ b/rocm6.4/R/paths.R @@ -0,0 +1,81 @@ +# Read component names from the installed components.tsv +.read_components <- function() { + tsv <- system.file("components.tsv", package = utils::packageName(), mustWork = TRUE) + df <- utils::read.delim(tsv, stringsAsFactors = FALSE) + stats::setNames(df$component, df$component) +} + +# Lazily cached component map +.component_env <- new.env(parent = emptyenv()) + +.component_name <- function(component) { + if (is.null(.component_env$map)) { + .component_env$map <- .read_components() + } + known <- .component_env$map[[component]] + if (is.null(known)) { + stop(sprintf( + "Unknown ROCm component: '%s'. Available: %s", + component, paste(names(.component_env$map), collapse = ", ") + )) + } + known +} + +#' Path to a ROCm component installation +#' +#' @param component Component name (e.g., "runtime", "rocblas", "hipsparse"). +#' @return A character string with the path to the installed component files. +#' @export +rocm_path <- function(component) { + system.file(file.path("rocm", .component_name(component)), + package = utils::packageName(), mustWork = TRUE) +} + +#' Path to the shared library directory +#' +#' All ROCm component libraries are installed into a single shared directory. +#' +#' @return A character string with the path to the lib directory. +#' @export +lib_path <- function() { + system.file("lib", package = utils::packageName(), mustWork = TRUE) +} + +#' Path to the ROCm headers +#' +#' All component headers are merged into a single include root, mirroring +#' \code{/opt/rocm/include}. Header directories are namespaced by component +#' (e.g., \code{hip/}, \code{rocblas/}). +#' +#' @param component Optional component name. If supplied, it is validated +#' against the installed components but the returned path is the shared +#' include root. +#' @return A character string with the path to the include directory. +#' @export +include_path <- function(component = NULL) { + if (!is.null(component)) { + .component_name(component) + } + system.file("include", package = utils::packageName(), mustWork = TRUE) +} + +#' Path to a ROCm component's binaries +#' +#' @param component Component name (e.g., "rocminfo"). +#' @return A character string with the path to the bin directory. +#' @export +bin_path <- function(component) { + file.path(rocm_path(component), "bin") +} + +#' Path to the shared library directory +#' +#' Alias for \code{\link{lib_path}}. All ROCm component libraries are in a +#' single directory, so this simply returns that path. +#' +#' @return A character vector of length one with the library path. +#' @export +all_lib_paths <- function() { + lib_path() +} diff --git a/rocm6.4/configure b/rocm6.4/configure new file mode 100755 index 0000000..5073e6e --- /dev/null +++ b/rocm6.4/configure @@ -0,0 +1,252 @@ +#!/bin/sh + +# Downloads ROCm toolkit components from repo.radeon.com during package +# installation. Component names and pinned versions are read from +# inst/components.tsv (generated at build time by resolve-rocm.sh). +# +# Environment variables: +# ROCM_COMPONENTS Comma-separated list of components to install. +# Default: all components. Example: "runtime,rocblas,hipsparse" +# ROCM_PLATFORM Only "linux-x64" is supported (ROCm packages are amd64). +# ROCM_APT_BASE Override the apt repository base URL. +# ROCM_DEB_CACHE Persistent directory for downloaded .deb files (optional). + +detect_platform() { + if [ -n "$ROCM_PLATFORM" ]; then + case "$ROCM_PLATFORM" in + linux-x64) echo "x86_64" ;; + *) + echo "ERROR: Unsupported ROCM_PLATFORM: $ROCM_PLATFORM" >&2 + exit 1 + ;; + esac + return + fi + + os=$(uname -s) + arch=$(uname -m) + + case "$os" in + Linux) + case "$arch" in + x86_64) echo "x86_64" ;; + *) + echo "ERROR: ROCm packages are only available for Linux x86_64," >&2 + echo " got: $arch" >&2 + exit 1 + ;; + esac + ;; + *) + echo "ERROR: ROCm packages are only available on Linux, got: $os" >&2 + exit 1 + ;; + esac +} + +download_file() { + url="$1"; dest="$2" + if command -v curl > /dev/null 2>&1; then + curl -fsSL -o "$dest" "$url" + elif command -v wget > /dev/null 2>&1; then + wget -q -O "$dest" "$url" + else + echo "ERROR: Neither curl nor wget found." >&2 + exit 1 + fi +} + +# Extract a .deb without requiring root. Prefer dpkg-deb; fall back to +# ar + tar so the package works on non-Debian distributions too. +extract_deb() { + deb="$1"; dest="$2" + mkdir -p "$dest" + + if command -v dpkg-deb > /dev/null 2>&1; then + dpkg-deb -x "$deb" "$dest" + return + fi + + if ! command -v ar > /dev/null 2>&1; then + echo "ERROR: Cannot extract .deb files: install 'dpkg-deb' or 'ar'." >&2 + exit 1 + fi + + member=$(ar t "$deb" | grep '^data\.tar' | head -1) + if [ -z "$member" ]; then + echo "ERROR: No data.tar member found in $deb." >&2 + exit 1 + fi + + case "$member" in + *.xz) ar p "$deb" "$member" | tar -xJf - -C "$dest" ;; + *.gz) ar p "$deb" "$member" | tar -xzf - -C "$dest" ;; + *.bz2) ar p "$deb" "$member" | tar -xjf - -C "$dest" ;; + *.zst) ar p "$deb" "$member" | tar --zstd -xf - -C "$dest" ;; + *) ar p "$deb" "$member" | tar -xf - -C "$dest" ;; + esac +} + +if [ -f inst/rocm-version.env ]; then + . inst/rocm-version.env +fi +ROCM_APT_BASE="${ROCM_APT_BASE:-https://repo.radeon.com/rocm/apt/6.4}" + +PLATFORM=$(detect_platform) || exit 1 +TMPDIR=$(mktemp -d) +trap "rm -rf '$TMPDIR'" EXIT + +SELECTED_COMPONENTS="${ROCM_COMPONENTS:-}" +if [ -z "$SELECTED_COMPONENTS" ]; then + SELECTED_COMPONENTS="${ROCM_DEFAULT_COMPONENTS:-}" +fi +case "$SELECTED_COMPONENTS" in + all) SELECTED_COMPONENTS="" ;; +esac + +is_selected() { + comp="$1" + [ -z "$SELECTED_COMPONENTS" ] && return 0 + echo ",$SELECTED_COMPONENTS," | grep -q ",${comp}," +} + +echo "=== ROCm Toolkit ===" +echo "* Platform: ${PLATFORM}" +if [ -n "$SELECTED_COMPONENTS" ]; then + echo "* Components: ${SELECTED_COMPONENTS}" +fi +echo "" + +mkdir -p inst/lib inst/include inst/rocm + +# Read components.tsv (skip header) and install each component +tail -n +2 inst/components.tsv | while IFS=" " read -r component deb_package version filename extract linux_only; do + [ -z "$component" ] && continue + + if ! is_selected "$component"; then + echo "* Skipping ${component} (not selected)" + continue + fi + + echo "* Installing ${component} (${deb_package} ${version})..." + + deb_name=$(basename "$filename") + if [ -n "$ROCM_DEB_CACHE" ]; then + mkdir -p "$ROCM_DEB_CACHE" + deb_path="${ROCM_DEB_CACHE}/${deb_name}" + else + deb_path="${TMPDIR}/${deb_name}" + fi + + if [ ! -f "$deb_path" ]; then + echo " Downloading ${deb_name}..." + download_file "${ROCM_APT_BASE}/${filename}" "$deb_path" + fi + + root="${TMPDIR}/root_${component}" + extract_deb "$deb_path" "$root" + + prefix="" + [ -n "$ROCM_PREFIX" ] && prefix="${root}/${ROCM_PREFIX}" + if [ -z "$prefix" ] || [ ! -d "$prefix" ]; then + prefix=$(find "$root" -maxdepth 3 -type d -name 'rocm-*' -print -quit) + fi + if [ -z "$prefix" ] || [ ! -d "$prefix" ]; then + echo " ERROR: Could not locate the ROCm prefix in ${deb_name}." >&2 + exit 1 + fi + + pkgdir="inst/rocm/${component}" + mkdir -p "$pkgdir" + + for dir in $(echo "$extract" | tr ',' ' '); do + [ -d "${prefix}/${dir}" ] || continue + if [ "$dir" = "lib" ]; then + # Keep CMake package files under the component, merge the rest into + # the shared lib directory so a single lib_path() works for everything. + for entry in "${prefix}/lib"/*; do + [ -e "$entry" ] || continue + if [ "$(basename "$entry")" = "cmake" ]; then + mkdir -p "${pkgdir}/lib" + cp -a "$entry" "${pkgdir}/lib/" + else + cp -a "$entry" inst/lib/ + fi + done + elif [ "$dir" = "include" ]; then + # Mirror /opt/rocm/include: headers are namespaced by component + # (include/hip, include/rocblas, ...) so a single include root works. + mkdir -p inst/include + cp -a "${prefix}/include/." inst/include/ + else + cp -a "${prefix}/${dir}" "$pkgdir/" + fi + done + + # Expose ROCm version metadata next to each component. + if [ -d "${prefix}/.info" ]; then + cp -a "${prefix}/.info" "$pkgdir/" + mkdir -p inst/.info + cp -a "${prefix}/.info/." inst/.info/ + fi + + if echo "$extract" | grep -q "bin"; then + chmod +x "${pkgdir}"/bin/* 2>/dev/null || true + fi + + rm -rf "$root" + [ -n "$ROCM_DEB_CACHE" ] || rm -f "$deb_path" + echo " Done." +done + +# Copy .info/version into every component so `include_path(comp)/../.info` +# resolves (used by tools/kit-lib.sh to verify the ROCm SDK version). +if [ -f "inst/rocm/core/.info/version" ]; then + mkdir -p inst/.info + cp "inst/rocm/core/.info/version" "inst/.info/version" + for d in inst/rocm/*/; do + [ -d "$d" ] || continue + mkdir -p "${d}.info" + cp "inst/rocm/core/.info/version" "${d}.info/version" + done +fi + +get_patchelf() { + command -v patchelf > /dev/null 2>&1 && { echo "patchelf"; return 0; } + + PATCHELF_VERSION="0.17.2.2" + case "$(uname -m)" in + x86_64) + PATCHELF_URL="https://files.pythonhosted.org/packages/f2/f9/e070956e350ccdfdf059251836f757ad91ac0c01b0ba3e033ea7188d8d42/patchelf-0.17.2.2-py3-none-manylinux1_x86_64.manylinux_2_5_x86_64.musllinux_1_1_x86_64.whl" + ;; + *) return 1 ;; + esac + + PATCHELF_DIR="${TMPDIR}/patchelf" + PATCHELF_WHL="${PATCHELF_DIR}/patchelf.whl" + mkdir -p "$PATCHELF_DIR" + download_file "$PATCHELF_URL" "$PATCHELF_WHL" || return 1 + command -v unzip > /dev/null 2>&1 || return 1 + unzip -q -o "$PATCHELF_WHL" "patchelf-${PATCHELF_VERSION}.data/scripts/patchelf" -d "$PATCHELF_DIR" || return 1 + chmod +x "${PATCHELF_DIR}/patchelf-${PATCHELF_VERSION}.data/scripts/patchelf" + echo "${PATCHELF_DIR}/patchelf-${PATCHELF_VERSION}.data/scripts/patchelf" +} + +PATCHELF_BIN=$(get_patchelf) +if [ -n "$PATCHELF_BIN" ]; then + echo "* Patching RPATH with \$ORIGIN (--force-rpath so it takes precedence over LD_LIBRARY_PATH)..." + for so in inst/lib/*.so*; do + [ -f "$so" ] || continue + "$PATCHELF_BIN" --force-rpath \ + --set-rpath '$ORIGIN:$ORIGIN/rocm_sysdeps/lib:$ORIGIN/host-math/lib' \ + "$so" 2>/dev/null || true + done + echo " Done." +else + echo "* WARNING: Could not obtain patchelf, skipping RUNPATH patching." + echo " Install patchelf for reliable ROCm library loading when" + echo " LD_LIBRARY_PATH contains other ROCm installations." +fi + +echo "" +echo "=== All components installed successfully ===" diff --git a/rocm6.4/inst/components.tsv b/rocm6.4/inst/components.tsv new file mode 100644 index 0000000..f57c4bb --- /dev/null +++ b/rocm6.4/inst/components.tsv @@ -0,0 +1,33 @@ +component deb_package version filename extract linux_only +core rocm-core 6.4.0.60400-47~22.04 pool/main/r/rocm-core/rocm-core_6.4.0.60400-47~22.04_amd64.deb lib,include,share yes +runtime hip-runtime-amd 6.4.43482.60400-47~22.04 pool/main/h/hip-runtime-amd/hip-runtime-amd_6.4.43482.60400-47~22.04_amd64.deb lib,include,share yes +hsa-runtime hsa-rocr 1.15.0.60400-47~22.04 pool/main/h/hsa-rocr/hsa-rocr_1.15.0.60400-47~22.04_amd64.deb lib,include,share yes +hsa-dev hsa-rocr-dev 1.15.0.60400-47~22.04 pool/main/h/hsa-rocr-dev/hsa-rocr-dev_1.15.0.60400-47~22.04_amd64.deb lib,include yes +comgr comgr 3.0.0.60400-47~22.04 pool/main/c/comgr/comgr_3.0.0.60400-47~22.04_amd64.deb lib,include yes +hip-dev hip-dev 6.4.43482.60400-47~22.04 pool/main/h/hip-dev/hip-dev_6.4.43482.60400-47~22.04_amd64.deb lib,include,bin,share yes +device-libs rocm-device-libs 1.0.0.60400-47~22.04 pool/main/r/rocm-device-libs/rocm-device-libs_1.0.0.60400-47~22.04_amd64.deb lib,include,amdgcn yes +rocblas rocblas 4.4.0.60400-47~22.04 pool/main/r/rocblas/rocblas_4.4.0.60400-47~22.04_amd64.deb lib yes +rocblas-dev rocblas-dev 4.4.0.60400-47~22.04 pool/main/r/rocblas-dev/rocblas-dev_4.4.0.60400-47~22.04_amd64.deb lib,include yes +hipblas hipblas 2.4.0.60400-47~22.04 pool/main/h/hipblas/hipblas_2.4.0.60400-47~22.04_amd64.deb lib yes +hipblas-dev hipblas-dev 2.4.0.60400-47~22.04 pool/main/h/hipblas-dev/hipblas-dev_2.4.0.60400-47~22.04_amd64.deb lib,include yes +hipblas-common hipblas-common-dev 1.0.0.60400-47~22.04 pool/main/h/hipblas-common-dev/hipblas-common-dev_1.0.0.60400-47~22.04_amd64.deb lib,include yes +hipblaslt hipblaslt 0.12.0.60400-47~22.04 pool/main/h/hipblaslt/hipblaslt_0.12.0.60400-47~22.04_amd64.deb lib yes +hipblaslt-dev hipblaslt-dev 0.12.0.60400-47~22.04 pool/main/h/hipblaslt-dev/hipblaslt-dev_0.12.0.60400-47~22.04_amd64.deb lib,include yes +hipfft hipfft 1.0.18.60400-47~22.04 pool/main/h/hipfft/hipfft_1.0.18.60400-47~22.04_amd64.deb lib yes +hipfft-dev hipfft-dev 1.0.18.60400-47~22.04 pool/main/h/hipfft-dev/hipfft-dev_1.0.18.60400-47~22.04_amd64.deb lib,include yes +hipsparse hipsparse 3.2.0.60400-47~22.04 pool/main/h/hipsparse/hipsparse_3.2.0.60400-47~22.04_amd64.deb lib yes +hipsparse-dev hipsparse-dev 3.2.0.60400-47~22.04 pool/main/h/hipsparse-dev/hipsparse-dev_3.2.0.60400-47~22.04_amd64.deb lib,include yes +hipsolver hipsolver 2.4.0.60400-47~22.04 pool/main/h/hipsolver/hipsolver_2.4.0.60400-47~22.04_amd64.deb lib yes +hipsolver-dev hipsolver-dev 2.4.0.60400-47~22.04 pool/main/h/hipsolver-dev/hipsolver-dev_2.4.0.60400-47~22.04_amd64.deb lib,include yes +rocrand rocrand 3.3.0.60400-47~22.04 pool/main/r/rocrand/rocrand_3.3.0.60400-47~22.04_amd64.deb lib yes +rocrand-dev rocrand-dev 3.3.0.60400-47~22.04 pool/main/r/rocrand-dev/rocrand-dev_3.3.0.60400-47~22.04_amd64.deb lib,include yes +hiprand hiprand 2.12.0.60400-47~22.04 pool/main/h/hiprand/hiprand_2.12.0.60400-47~22.04_amd64.deb lib yes +hiprand-dev hiprand-dev 2.12.0.60400-47~22.04 pool/main/h/hiprand-dev/hiprand-dev_2.12.0.60400-47~22.04_amd64.deb lib,include yes +rccl rccl 2.22.3.60400-47~22.04 pool/main/r/rccl/rccl_2.22.3.60400-47~22.04_amd64.deb lib yes +rccl-dev rccl-dev 2.22.3.60400-47~22.04 pool/main/r/rccl-dev/rccl-dev_2.22.3.60400-47~22.04_amd64.deb lib,include yes +miopen miopen-hip 3.4.0.60400-47~22.04 pool/main/m/miopen-hip/miopen-hip_3.4.0.60400-47~22.04_amd64.deb lib yes +miopen-dev miopen-hip-dev 3.4.0.60400-47~22.04 pool/main/m/miopen-hip-dev/miopen-hip-dev_3.4.0.60400-47~22.04_amd64.deb lib,include yes +rocthrust-dev rocthrust-dev 3.3.0.60400-47~22.04 pool/main/r/rocthrust-dev/rocthrust-dev_3.3.0.60400-47~22.04_amd64.deb include yes +hipcub-dev hipcub-dev 3.4.0.60400-47~22.04 pool/main/h/hipcub-dev/hipcub-dev_3.4.0.60400-47~22.04_amd64.deb include yes +rocprim-dev rocprim-dev 3.4.0.60400-47~22.04 pool/main/r/rocprim-dev/rocprim-dev_3.4.0.60400-47~22.04_amd64.deb include yes +rocminfo rocminfo 1.0.0.60400-47~22.04 pool/main/r/rocminfo/rocminfo_1.0.0.60400-47~22.04_amd64.deb bin yes diff --git a/rocm6.4/inst/rocm-version.env b/rocm6.4/inst/rocm-version.env new file mode 100644 index 0000000..19b300e --- /dev/null +++ b/rocm6.4/inst/rocm-version.env @@ -0,0 +1,8 @@ +ROCM_MINOR="6.4" +ROCM_MAJOR="6" +ROCM_PATCH="0" +ROCM_PREFIX="opt/rocm-6.4.0" +ROCM_APT_BASE="https://repo.radeon.com/rocm/apt/6.4" +ROCM_APT_SUITE="jammy" +PKG_VERSION="0.1.0" +ROCM_DEFAULT_COMPONENTS="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" diff --git a/shared-rocm/DESCRIPTION.template b/shared-rocm/DESCRIPTION.template new file mode 100644 index 0000000..d31614f --- /dev/null +++ b/shared-rocm/DESCRIPTION.template @@ -0,0 +1,19 @@ +Package: rocm{{ROCM_MINOR}} +Title: ROCm {{ROCM_MINOR}} Toolkit Libraries +Version: {{PKG_VERSION}} +Authors@R: + person("Daniel", "Falbel", , "daniel@posit.co", role = c("aut", "cre")) +Description: Provides ROCm {{ROCM_MINOR}} native libraries (HIP runtime, HSA, + rocBLAS, hipBLAS, hipBLASLt, hipFFT, hipSPARSE, hipSOLVER, rocRAND, + hipRAND, RCCL, MIOpen, device libraries, and their development headers) + by downloading pre-built packages from repo.radeon.com at install time. + Intended to be used as a dependency by packages that require ROCm + {{ROCM_MINOR}}. +SystemRequirements: Linux x86_64; not supported on macOS or Windows. +Imports: stats, utils +License: MIT + file LICENSE +URL: https://github.com/mlverse/cudatoolkit +BugReports: https://github.com/mlverse/cudatoolkit/issues +Encoding: UTF-8 +Roxygen: list(markdown = TRUE) +RoxygenNote: 7.3.2 diff --git a/shared-rocm/LICENSE b/shared-rocm/LICENSE new file mode 100644 index 0000000..fc752b6 --- /dev/null +++ b/shared-rocm/LICENSE @@ -0,0 +1,2 @@ +YEAR: 2026 +COPYRIGHT HOLDER: Daniel Falbel diff --git a/shared-rocm/NAMESPACE b/shared-rocm/NAMESPACE new file mode 100644 index 0000000..5ebd06a --- /dev/null +++ b/shared-rocm/NAMESPACE @@ -0,0 +1,7 @@ +# Generated by roxygen2: do not edit by hand + +export(all_lib_paths) +export(bin_path) +export(include_path) +export(lib_path) +export(rocm_path) diff --git a/shared-rocm/R/paths.R b/shared-rocm/R/paths.R new file mode 100644 index 0000000..f746558 --- /dev/null +++ b/shared-rocm/R/paths.R @@ -0,0 +1,81 @@ +# Read component names from the installed components.tsv +.read_components <- function() { + tsv <- system.file("components.tsv", package = utils::packageName(), mustWork = TRUE) + df <- utils::read.delim(tsv, stringsAsFactors = FALSE) + stats::setNames(df$component, df$component) +} + +# Lazily cached component map +.component_env <- new.env(parent = emptyenv()) + +.component_name <- function(component) { + if (is.null(.component_env$map)) { + .component_env$map <- .read_components() + } + known <- .component_env$map[[component]] + if (is.null(known)) { + stop(sprintf( + "Unknown ROCm component: '%s'. Available: %s", + component, paste(names(.component_env$map), collapse = ", ") + )) + } + known +} + +#' Path to a ROCm component installation +#' +#' @param component Component name (e.g., "runtime", "rocblas", "hipsparse"). +#' @return A character string with the path to the installed component files. +#' @export +rocm_path <- function(component) { + system.file(file.path("rocm", .component_name(component)), + package = utils::packageName(), mustWork = TRUE) +} + +#' Path to the shared library directory +#' +#' All ROCm component libraries are installed into a single shared directory. +#' +#' @return A character string with the path to the lib directory. +#' @export +lib_path <- function() { + system.file("lib", package = utils::packageName(), mustWork = TRUE) +} + +#' Path to the ROCm headers +#' +#' All component headers are merged into a single include root, mirroring +#' \code{/opt/rocm/include}. Header directories are namespaced by component +#' (e.g., \code{hip/}, \code{rocblas/}). +#' +#' @param component Optional component name. If supplied, it is validated +#' against the installed components but the returned path is the shared +#' include root. +#' @return A character string with the path to the include directory. +#' @export +include_path <- function(component = NULL) { + if (!is.null(component)) { + .component_name(component) + } + system.file("include", package = utils::packageName(), mustWork = TRUE) +} + +#' Path to a ROCm component's binaries +#' +#' @param component Component name (e.g., "rocminfo"). +#' @return A character string with the path to the bin directory. +#' @export +bin_path <- function(component) { + file.path(rocm_path(component), "bin") +} + +#' Path to the shared library directory +#' +#' Alias for \code{\link{lib_path}}. All ROCm component libraries are in a +#' single directory, so this simply returns that path. +#' +#' @return A character vector of length one with the library path. +#' @export +all_lib_paths <- function() { + lib_path() +} diff --git a/shared-rocm/configure b/shared-rocm/configure new file mode 100755 index 0000000..5073e6e --- /dev/null +++ b/shared-rocm/configure @@ -0,0 +1,252 @@ +#!/bin/sh + +# Downloads ROCm toolkit components from repo.radeon.com during package +# installation. Component names and pinned versions are read from +# inst/components.tsv (generated at build time by resolve-rocm.sh). +# +# Environment variables: +# ROCM_COMPONENTS Comma-separated list of components to install. +# Default: all components. Example: "runtime,rocblas,hipsparse" +# ROCM_PLATFORM Only "linux-x64" is supported (ROCm packages are amd64). +# ROCM_APT_BASE Override the apt repository base URL. +# ROCM_DEB_CACHE Persistent directory for downloaded .deb files (optional). + +detect_platform() { + if [ -n "$ROCM_PLATFORM" ]; then + case "$ROCM_PLATFORM" in + linux-x64) echo "x86_64" ;; + *) + echo "ERROR: Unsupported ROCM_PLATFORM: $ROCM_PLATFORM" >&2 + exit 1 + ;; + esac + return + fi + + os=$(uname -s) + arch=$(uname -m) + + case "$os" in + Linux) + case "$arch" in + x86_64) echo "x86_64" ;; + *) + echo "ERROR: ROCm packages are only available for Linux x86_64," >&2 + echo " got: $arch" >&2 + exit 1 + ;; + esac + ;; + *) + echo "ERROR: ROCm packages are only available on Linux, got: $os" >&2 + exit 1 + ;; + esac +} + +download_file() { + url="$1"; dest="$2" + if command -v curl > /dev/null 2>&1; then + curl -fsSL -o "$dest" "$url" + elif command -v wget > /dev/null 2>&1; then + wget -q -O "$dest" "$url" + else + echo "ERROR: Neither curl nor wget found." >&2 + exit 1 + fi +} + +# Extract a .deb without requiring root. Prefer dpkg-deb; fall back to +# ar + tar so the package works on non-Debian distributions too. +extract_deb() { + deb="$1"; dest="$2" + mkdir -p "$dest" + + if command -v dpkg-deb > /dev/null 2>&1; then + dpkg-deb -x "$deb" "$dest" + return + fi + + if ! command -v ar > /dev/null 2>&1; then + echo "ERROR: Cannot extract .deb files: install 'dpkg-deb' or 'ar'." >&2 + exit 1 + fi + + member=$(ar t "$deb" | grep '^data\.tar' | head -1) + if [ -z "$member" ]; then + echo "ERROR: No data.tar member found in $deb." >&2 + exit 1 + fi + + case "$member" in + *.xz) ar p "$deb" "$member" | tar -xJf - -C "$dest" ;; + *.gz) ar p "$deb" "$member" | tar -xzf - -C "$dest" ;; + *.bz2) ar p "$deb" "$member" | tar -xjf - -C "$dest" ;; + *.zst) ar p "$deb" "$member" | tar --zstd -xf - -C "$dest" ;; + *) ar p "$deb" "$member" | tar -xf - -C "$dest" ;; + esac +} + +if [ -f inst/rocm-version.env ]; then + . inst/rocm-version.env +fi +ROCM_APT_BASE="${ROCM_APT_BASE:-https://repo.radeon.com/rocm/apt/6.4}" + +PLATFORM=$(detect_platform) || exit 1 +TMPDIR=$(mktemp -d) +trap "rm -rf '$TMPDIR'" EXIT + +SELECTED_COMPONENTS="${ROCM_COMPONENTS:-}" +if [ -z "$SELECTED_COMPONENTS" ]; then + SELECTED_COMPONENTS="${ROCM_DEFAULT_COMPONENTS:-}" +fi +case "$SELECTED_COMPONENTS" in + all) SELECTED_COMPONENTS="" ;; +esac + +is_selected() { + comp="$1" + [ -z "$SELECTED_COMPONENTS" ] && return 0 + echo ",$SELECTED_COMPONENTS," | grep -q ",${comp}," +} + +echo "=== ROCm Toolkit ===" +echo "* Platform: ${PLATFORM}" +if [ -n "$SELECTED_COMPONENTS" ]; then + echo "* Components: ${SELECTED_COMPONENTS}" +fi +echo "" + +mkdir -p inst/lib inst/include inst/rocm + +# Read components.tsv (skip header) and install each component +tail -n +2 inst/components.tsv | while IFS=" " read -r component deb_package version filename extract linux_only; do + [ -z "$component" ] && continue + + if ! is_selected "$component"; then + echo "* Skipping ${component} (not selected)" + continue + fi + + echo "* Installing ${component} (${deb_package} ${version})..." + + deb_name=$(basename "$filename") + if [ -n "$ROCM_DEB_CACHE" ]; then + mkdir -p "$ROCM_DEB_CACHE" + deb_path="${ROCM_DEB_CACHE}/${deb_name}" + else + deb_path="${TMPDIR}/${deb_name}" + fi + + if [ ! -f "$deb_path" ]; then + echo " Downloading ${deb_name}..." + download_file "${ROCM_APT_BASE}/${filename}" "$deb_path" + fi + + root="${TMPDIR}/root_${component}" + extract_deb "$deb_path" "$root" + + prefix="" + [ -n "$ROCM_PREFIX" ] && prefix="${root}/${ROCM_PREFIX}" + if [ -z "$prefix" ] || [ ! -d "$prefix" ]; then + prefix=$(find "$root" -maxdepth 3 -type d -name 'rocm-*' -print -quit) + fi + if [ -z "$prefix" ] || [ ! -d "$prefix" ]; then + echo " ERROR: Could not locate the ROCm prefix in ${deb_name}." >&2 + exit 1 + fi + + pkgdir="inst/rocm/${component}" + mkdir -p "$pkgdir" + + for dir in $(echo "$extract" | tr ',' ' '); do + [ -d "${prefix}/${dir}" ] || continue + if [ "$dir" = "lib" ]; then + # Keep CMake package files under the component, merge the rest into + # the shared lib directory so a single lib_path() works for everything. + for entry in "${prefix}/lib"/*; do + [ -e "$entry" ] || continue + if [ "$(basename "$entry")" = "cmake" ]; then + mkdir -p "${pkgdir}/lib" + cp -a "$entry" "${pkgdir}/lib/" + else + cp -a "$entry" inst/lib/ + fi + done + elif [ "$dir" = "include" ]; then + # Mirror /opt/rocm/include: headers are namespaced by component + # (include/hip, include/rocblas, ...) so a single include root works. + mkdir -p inst/include + cp -a "${prefix}/include/." inst/include/ + else + cp -a "${prefix}/${dir}" "$pkgdir/" + fi + done + + # Expose ROCm version metadata next to each component. + if [ -d "${prefix}/.info" ]; then + cp -a "${prefix}/.info" "$pkgdir/" + mkdir -p inst/.info + cp -a "${prefix}/.info/." inst/.info/ + fi + + if echo "$extract" | grep -q "bin"; then + chmod +x "${pkgdir}"/bin/* 2>/dev/null || true + fi + + rm -rf "$root" + [ -n "$ROCM_DEB_CACHE" ] || rm -f "$deb_path" + echo " Done." +done + +# Copy .info/version into every component so `include_path(comp)/../.info` +# resolves (used by tools/kit-lib.sh to verify the ROCm SDK version). +if [ -f "inst/rocm/core/.info/version" ]; then + mkdir -p inst/.info + cp "inst/rocm/core/.info/version" "inst/.info/version" + for d in inst/rocm/*/; do + [ -d "$d" ] || continue + mkdir -p "${d}.info" + cp "inst/rocm/core/.info/version" "${d}.info/version" + done +fi + +get_patchelf() { + command -v patchelf > /dev/null 2>&1 && { echo "patchelf"; return 0; } + + PATCHELF_VERSION="0.17.2.2" + case "$(uname -m)" in + x86_64) + PATCHELF_URL="https://files.pythonhosted.org/packages/f2/f9/e070956e350ccdfdf059251836f757ad91ac0c01b0ba3e033ea7188d8d42/patchelf-0.17.2.2-py3-none-manylinux1_x86_64.manylinux_2_5_x86_64.musllinux_1_1_x86_64.whl" + ;; + *) return 1 ;; + esac + + PATCHELF_DIR="${TMPDIR}/patchelf" + PATCHELF_WHL="${PATCHELF_DIR}/patchelf.whl" + mkdir -p "$PATCHELF_DIR" + download_file "$PATCHELF_URL" "$PATCHELF_WHL" || return 1 + command -v unzip > /dev/null 2>&1 || return 1 + unzip -q -o "$PATCHELF_WHL" "patchelf-${PATCHELF_VERSION}.data/scripts/patchelf" -d "$PATCHELF_DIR" || return 1 + chmod +x "${PATCHELF_DIR}/patchelf-${PATCHELF_VERSION}.data/scripts/patchelf" + echo "${PATCHELF_DIR}/patchelf-${PATCHELF_VERSION}.data/scripts/patchelf" +} + +PATCHELF_BIN=$(get_patchelf) +if [ -n "$PATCHELF_BIN" ]; then + echo "* Patching RPATH with \$ORIGIN (--force-rpath so it takes precedence over LD_LIBRARY_PATH)..." + for so in inst/lib/*.so*; do + [ -f "$so" ] || continue + "$PATCHELF_BIN" --force-rpath \ + --set-rpath '$ORIGIN:$ORIGIN/rocm_sysdeps/lib:$ORIGIN/host-math/lib' \ + "$so" 2>/dev/null || true + done + echo " Done." +else + echo "* WARNING: Could not obtain patchelf, skipping RUNPATH patching." + echo " Install patchelf for reliable ROCm library loading when" + echo " LD_LIBRARY_PATH contains other ROCm installations." +fi + +echo "" +echo "=== All components installed successfully ===" diff --git a/sync-rocm.sh b/sync-rocm.sh new file mode 100755 index 0000000..d8b8246 --- /dev/null +++ b/sync-rocm.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +# Copies shared-rocm/ into every rocm*/ package directory and generates its +# DESCRIPTION from DESCRIPTION.template. Run after editing any shared file. + +set -e + +SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) + +for pkg_dir in "$SCRIPT_DIR"/rocm*/; do + [ -d "$pkg_dir/inst" ] || continue + version_env="$pkg_dir/inst/rocm-version.env" + [ -f "$version_env" ] || continue + + unset ROCM_MINOR ROCM_MAJOR ROCM_PATCH ROCM_PREFIX ROCM_APT_BASE ROCM_APT_SUITE PKG_VERSION + . "$version_env" + + echo "==> syncing ${pkg_dir}" + + mkdir -p "$pkg_dir/R" + cp "$SCRIPT_DIR/shared-rocm/configure" "$pkg_dir/configure" + cp "$SCRIPT_DIR/shared-rocm/NAMESPACE" "$pkg_dir/NAMESPACE" + cp "$SCRIPT_DIR/shared-rocm/LICENSE" "$pkg_dir/LICENSE" + cp "$SCRIPT_DIR/shared-rocm/R/paths.R" "$pkg_dir/R/paths.R" + chmod +x "$pkg_dir/configure" + + sed -e "s/{{ROCM_MINOR}}/${ROCM_MINOR}/g" \ + -e "s/{{PKG_VERSION}}/${PKG_VERSION}/g" \ + "$SCRIPT_DIR/shared-rocm/DESCRIPTION.template" > "$pkg_dir/DESCRIPTION" +done