Type: | Package |
Title: | 'FlexiBLAS' API Interface |
Version: | 3.4.0 |
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. |
License: | LGPL (≥ 3) |
Encoding: | UTF-8 |
OS_type: | unix |
URL: | https://github.com/Enchufa2/r-flexiblas |
BugReports: | https://github.com/Enchufa2/r-flexiblas/issues |
Suggests: | tinytest |
RoxygenNote: | 7.1.1 |
NeedsCompilation: | yes |
Packaged: | 2024-01-11 09:49:21 UTC; iucar |
Author: | Iñaki Ucar |
Maintainer: | Iñaki Ucar <iucar@fedoraproject.org> |
Repository: | CRAN |
Date/Publication: | 2024-01-11 10:00:09 UTC |
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.
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
}))
}
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.