Package 'flexiblas'

Title: 'FlexiBLAS' API Interface
Description: Provides functions to switch the 'BLAS'/'LAPACK' optimized backend and change the number of threads without leaving the R session, which needs to be linked against the 'FlexiBLAS' wrapper library <https://www.mpi-magdeburg.mpg.de/projects/flexiblas>.
Authors: Iñaki Ucar [aut, cph, cre] , Martin Koehler [aut, cph]
Maintainer: Iñaki Ucar <[email protected]>
License: LGPL (>= 3)
Version: 3.4.0.2
Built: 2024-11-01 11:30:40 UTC
Source: https://github.com/Enchufa2/r-flexiblas

Help Index


flexiblas: FlexiBLAS API Interface for R

Description

Provides functions to switch the BLAS/LAPACK optimized backend and change the number of threads without leaving the R session, which needs to be linked against the FlexiBLAS wrapper library.

Author(s)

Martin Koehler, Iñaki Ucar

References

Koehler M., Saak J. (2020). "FlexiBLAS - A BLAS and LAPACK wrapper library with runtime exchangeable backends." doi:10.5281/zenodo.3909214.


Check Availability

Description

Check whether FlexiBLAS is available.

Usage

flexiblas_avail()

Value

A boolean.

See Also

flexiblas_version, flexiblas-backends, flexiblas-threads


Get Version

Description

Get current version of FlexiBLAS.

Usage

flexiblas_version()

Value

A package_version object.

See Also

flexiblas_avail, flexiblas-backends, flexiblas-threads


Handle Backends

Description

Get current backend, list available ones, load and switch between backends.

Usage

flexiblas_current_backend()

flexiblas_list()

flexiblas_list_loaded()

flexiblas_load_backend(name)

flexiblas_switch(n)

Arguments

name

character vector of backend names or paths (case insensitive).

n

loaded backend index.

Value

flexiblas_current_backend and ⁠flexiblas_list*⁠ return a character vector of backend names or paths.

flexiblas_load_backend and flexiblas_switch return the indices of the loaded backends if the operation was successful, or fail otherwise.

See Also

flexiblas_avail, flexiblas_version, flexiblas-threads

Examples

n <- 2000
runs <- 10
ignore <- "__FALLBACK__"

A <- matrix(runif(n*n), nrow=n)
B <- matrix(runif(n*n), nrow=n)

# load backends
backends <- setdiff(flexiblas_list(), ignore)
idx <- flexiblas_load_backend(backends)

# benchmark
timings <- sapply(idx, function(i) {
  flexiblas_switch(i)

  # warm-up
  C <- A[1:100, 1:100] %*% B[1:100, 1:100]

  unname(system.time({
    for (j in seq_len(runs))
      C <- A %*% B
  })[3])
})

if (length(timings)) {
  results <- data.frame(
    backend = backends,
    `timing [s]` = timings,
    `performance [GFlops]` = (2 * (n / 1000)^3) / timings,
    check.names = FALSE)

  results[order(results$performance),]
}

Get/Set Number of Threads

Description

Get or set the number of threads for the BLAS backend.

Usage

flexiblas_get_num_threads()

flexiblas_set_num_threads(n)

Arguments

n

number of threads.

Value

flexiblas_get_num_threads returns the number of threads.

flexiblas_set_num_threads returns nothing.

See Also

flexiblas_avail, flexiblas_version, flexiblas-backends

Examples

max_threads <- 4
n <- 2000
runs <- 10

A <- matrix(runif(n*n), nrow=n)
B <- matrix(runif(n*n), nrow=n)

for (i in seq_len(max_threads)) {
  message("Set number of threads to: ", i)
  flexiblas_set_num_threads(i)

  print(system.time({
    for (j in seq_len(runs))
      C <- A %*% B
  }))
}