Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BLAS/LAPACK routine 'DLASCL' gave error code -4 #2

Closed
davedgd opened this issue Mar 18, 2021 · 11 comments
Closed

BLAS/LAPACK routine 'DLASCL' gave error code -4 #2

davedgd opened this issue Mar 18, 2021 · 11 comments

Comments

@davedgd
Copy link

davedgd commented Mar 18, 2021

Thanks for putting this package together -- it's nice to have easy control over BLAS in Fedora!

I've run into an issue with it however. While I was able to replicate the R-bloggers example, I ran into an issue running the sample code from this StackOverflow post.

Specifically, running this code produces an error (m is set to 1000 here instead of 10000 as in the StackOverflow original since it errors quickly):

# Singular Value Decomposition
m <- 1000
n <- 2000
A <- matrix (runif (m*n),m,n)
system.time (S <- svd (A,nu=0,nv=0))

Within RStudio, I received:

BLAS/LAPACK routine 'DLASCL' gave error code -4

Similarly, I ran into issues running this from the terminal. I tried this with intel-mkl-2020.0-088, the 2019.5 version, as well as the most recent oneAPI (although admittedly for the latter I didn't test it fully).

The expected result should be a relatively quick calculation -- at least it is on macOS and Windows.

@Enchufa2
Copy link
Owner

Enchufa2 commented Mar 18, 2021

Could you paste the output from sessionInfo(), please? Also, does it fail with a specific backend? Did you use the CRAN package or did you install flexiblas from the system repositories? I have R-flexiblas installed from the system repositories in Fedora 33 and I cannot reproduce the error (with 10000).

@davedgd
Copy link
Author

davedgd commented Mar 18, 2021

@Enchufa2: thanks for the quick reply!

To clarify, I used the system repositories and tried OpenBLAS and MKL (intel-mkl-2020.0-088) following your R-bloggers guides, which worked perfectly for the benchmark example in the post. The code in the issue works with the default Fedora 33 OpenBLAS backend but fails when switching the backend to MKL. All of this was done with a fresh, fully-updated Fedora install.

I will post my sessionInfo() next time I’m at the computer along with some screenshots. Hopefully I can help replicate this.

@davedgd
Copy link
Author

davedgd commented Mar 18, 2021

Here is the sessionInfo:

> sessionInfo()
R version 4.0.4 (2021-02-15)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: Fedora 33 (Cinnamon)

Matrix products: default
BLAS/LAPACK: /usr/lib64/libflexiblas.so.3.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets 
[6] methods   base     

other attached packages:
[1] flexiblas_3.0.0

loaded via a namespace (and not attached):
[1] compiler_4.0.4 tools_4.0.4   

I've also attached screenshots showing 1) everything working fine with OpenBLAS; 2) the MKL error; and 3) sessionInfo:

Fine with OpenBLAS
OpenBLAS

Error with MKL
MKL

sessionInfo
sessionInfo

@davedgd
Copy link
Author

davedgd commented Mar 18, 2021

Sorry, one more screenshot showing how everything is oddly fine with the R-bloggers code:

RBloggers

@Enchufa2
Copy link
Owner

Thanks for all the details. Strange, indeed. Let's summon @grisuthedragon here, maybe this rings a bell to him.

@grisuthedragon
Copy link

grisuthedragon commented Mar 18, 2021

Never use the MKL_RT interface. That is more (or less) dangerous. The problem is that the mkl_rt.so contains an interface with a flexible ABI controlled by some environment variables and in this way its interface is not reblas compatible. This causes most of the errors I think. For example one can change the width of an integer and the threading model via environment variables and API calls.

The solution would be to create custumized MKL interfaces using the mklbuilder Makefile. Can you try this?
Details are there: mpimd-csc/flexiblas#13

The .so file created with this tool is refblas compatible and thus can be loaded as you did it.

@Enchufa2 yes it ringed a bell ;-)

@davedgd
Copy link
Author

davedgd commented Mar 18, 2021

@grisuthedragon: Yes, perfect! This solution works. I used the following code from your example, but modified for a parallel version:

make libintel64 export=blas_example_list interface=lp64 parallel=gnu threading=parallel name=flexiblas_mkl_parallel

I am now seeing performance approaching what I should get for MKL (using the MKL_DEBUG_CPU_TYPE=5 workaround for Ryzen):

> flexiblas_list_loaded()
[1] "OPENBLAS-OPENMP"                                
[2] "/home/daved/Downloads/flexiblas_mkl_parallel.so"
> 
> flexiblas_switch(2)
> flexiblas_current_backend()
[1] "/home/daved/Downloads/flexiblas_mkl_parallel.so"
> 
> flexiblas_set_num_threads(16)
> 
> m <- 10000
> n <- 2000
> A <- matrix (runif (m*n),m,n)
> system.time (S <- svd (A,nu=0,nv=0))
   user  system elapsed 
 15.487   0.181   2.294 
> 
> flexiblas_get_num_threads()
[1] 1

Which compares favorably with OpenBLAS when set equal to the number of physical cores (e.g., 16 for my 3950X):

> flexiblas_list_loaded()
[1] "OPENBLAS-OPENMP"                                
[2] "/home/daved/Downloads/flexiblas_mkl_parallel.so"
> 
> flexiblas_switch(1)
> flexiblas_current_backend()
[1] "OPENBLAS-OPENMP"
> 
> flexiblas_set_num_threads(16)
> 
> m <- 10000
> n <- 2000
> A <- matrix (runif (m*n),m,n)
> system.time (S <- svd (A,nu=0,nv=0))
   user  system elapsed 
 28.464   3.108   2.869 
> 
> flexiblas_get_num_threads()
[1] 16

The only lingering (and separate) issue here is that flexiblas_get_num_threads does not seem to work when using this customized MKL interface, but this can be solved via export commands.

Thank you!

@Enchufa2
Copy link
Owner

Nice! I should update the post then with these instructions... My bad. :)

@davedgd
Copy link
Author

davedgd commented Mar 18, 2021

No worries! =) I never would have found this easy MKL solution if not for your post (first result in Google atm). Thanks again to both of you!

@davedgd davedgd closed this as completed Mar 18, 2021
@Enchufa2
Copy link
Owner

Let me keep this open to remind me to update the post. ;-)

@Enchufa2 Enchufa2 reopened this Mar 18, 2021
@grisuthedragon
Copy link

In the next release (whenever I developed enough new stuff), we include a more extended verision of the text in mpimd-csc/flexiblas#13 including the way to add the MKL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants