Installing and switching to MKL on Fedora

UPDATE: MKL is a bit trickier than other backends. See this and this comment on how to use mklbuilder to generate a specific .so file to use with FlexiBLAS as described below.

In our last post, we presented the FlexiBLAS library, coming to Fedora 33, and the accompanying flexiblas R package, which enables live switching of the BLAS backend among the various open source options readily available in the Fedora repositories.

In this post, we demonstrate how to install, register with FlexiBLAS, and finally switch to Intel’s Math Kernel Library (MKL) in a few steps. First, we prepare a proper environment using docker:

$ docker run --rm -it fedora:33
$ dnf install 'dnf-command(config-manager)' # install config manager
$ dnf install R-flexiblas # install R and the FlexiBLAS API interface for R

Then we add Intel’s YUM repository, import the public key and install MKL:

$ dnf config-manager --add-repo
$ rpm --import
$ dnf install intel-mkl # or a specific version, e.g. intel-mkl-2020.0-088

Then, in an R session:

#> flexiblas BLAS /opt/intel/mkl/lib/intel64/ not found in config.
#> <flexiblas> BLAS /opt/intel/mkl/lib/intel64/ does not provide an integer size hint. Assuming 4 Byte.
#> [1] 2
backends <- flexiblas_list_loaded()
#> [1] "OPENBLAS-OPENMP"                        
#> [2] "/opt/intel/mkl/lib/intel64/"

And that’s it: now, we are able to switch between the default one and MKL. As in our previous post, let’s compare them with a simple GEMM benchmark:

n <- 2000
runs <- 10
A <- matrix(runif(n*n), nrow=n)
B <- matrix(runif(n*n), nrow=n)
# benchmark
timings <- sapply(seq_along(backends), function(i) {
  # warm-up
  C <- A[1:100, 1:100] %*% B[1:100, 1:100]
    for (j in seq_len(runs))
      C <- A %*% B
results <- data.frame(
  backend = backends,
  `timing [s]` = timings,
  `performance [GFlops]` = (2 * (n / 1000)^3) / timings,
  check.names = FALSE)
#>                                   backend timing [s] performance [GFlops]
#> 2 /opt/intel/mkl/lib/intel64/      3.487             4.588471
#> 1                         OPENBLAS-OPENMP      0.754            21.220159

And still OpenBLAS rocks!

For questions, suggestions or issues related to this R interface, please use its issue tracker or the R-SIG-Fedora mailing list. For more general issues, please use Red Hat Bugzilla or the upstream issue tracker.

Publicada en R

3 comentarios sobre “Installing and switching to MKL on Fedora

Comentarios cerrados.