Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Carl_B_
Beginner
67 Views

In R session, first Sys.setenv(MKL_MIC_ENABLE = 0), then 1

Dear All,

I'm trying to benchmark automatic offload to Xeon Phi by in R by changing OS environment variables (MKL_MIC_ENABLE, etc.) exclusively from within R via the base function Sys.setenv.

Here's my Linux OS:

uname -a
Linux cypress1 2.6.32-431.23.3.el6.x86_64 #1 SMP Thu Jul 31 17:20:51 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

I'm running the following version of R - built by our sys admin with MKL:

> R.version
               _
platform       x86_64-pc-linux-gnu
arch           x86_64
os             linux-gnu
system         x86_64, linux-gnu
status
major          3
minor          2.5
year           2016
month          04
day            14
svn rev        70478
language       R
version.string R version 3.2.5 (2016-04-14)
nickname       Very, Very Secure Dishes

Also see the following R files pasted below: multiGemm.R, gemm.R.

When I run the following command...

Rscript multiGemm.R

...I observe that the automatic offload never occurs - even after the environment variable MKL_MIC_ENABLE has been set (changed from initially 0) to 1 within the R session via the base function "Sys.setenv".

Is this a problem with our version of R - or is it simply not possible to change MKL_MIC_ENABLE from it's initial value from within R?

Please advise, thanks.

Best,

CB

gemm.R

# See https://software.intel.com/en-us/forums/intel-many-integrated-core/topic/538102

require(Matrix)
#sink("output.txt")
cat("Initialization...\n")
a <- matrix(runif(N*N), ncol=N, nrow=N);
b <- matrix(runif(N*N), ncol=N, nrow=N);
cat("Matrix-matrix multiplication of size ", N, "x", N, ":\n")
timeVec <- gflopsVec <- c()
for (i in 1:5) {
  dt=system.time( c <- a %*% b )
  gflops = 2*N*N*N*1e-9/dt[3]
  names(gflops) <- NULL
  cat("Trial: ", i, ", time: ", dt[3], " sec, performance: ", gflops, " GFLOP/s\n")
  timeVec <- c(timeVec, dt[3])
  gflopsVec <- c(gflopsVec, gflops)
}
cat("Average time: ", mean(timeVec), " sec, average performance: ", mean(gflopsVec), " GFLOP/s\n")

---

multiGemm.R

# See, e.g., https://software.intel.com/en-us/forums/intel-many-integrated-core/topic/538102
if ((.Platform$OS.type == "unix") &&
    (grepl("cypress", system("uname -a", intern = T)))) {
      setwd('~/R/benchmarks')
    } else {
      setwd('~/Documents/R/benchmarks')
    }
stopifnot(file.exists("gemm.R"))

micSettings <-  list(
  "Host CPU only" = list(
    MKL_MIC_ENABLE="0",
    OFFLOAD_REPORT="2"
  ),
  "MIC Affinity Balanced" = list(
    MKL_MIC_ENABLE="1",
    MIC_KMP_AFFINITY="balanced,verbose"
  ),
  "MIC Affinity Compact" = list(
    MIC_KMP_AFFINITY="compact,verbose"
  ),
  "MIC Affinity Scatter" = list(
    MIC_KMP_AFFINITY="scatter,verbose"
  )
)

N <- 16000 # set N for gemm.R
multiGemm <- lapply(micSettings, function(settings) {
  cat("Settings=..\n")
  print(settings, row.names=F, sep = "\n")
  do.call(Sys.setenv, settings)
  source("gemm.R")
})
multiGemm <- as.data.frame(do.call(cbind, multiGemm))
rVersion <- with(R.version, paste(major, minor, sep = "."))
names(multiGemm) <- paste(rVersion, names(multiGemm), sep = "\n")
rdsPath <- paste('multiGemmR', rVersion, 'rds', sep = ".")
saveRDS(multiGemm, rdsPath)

 

0 Kudos
0 Replies
Reply