1

I have an cython optimized speed program but still slowed. I want to know whether my cython program is using OpenBLAS or MKL (link openblas / mkl library)? How to know that?

machen
  • 283
  • 2
  • 10
  • Possible duplicate of [Find out if/which BLAS library is used by Numpy](https://stackoverflow.com/questions/37184618/find-out-if-which-blas-library-is-used-by-numpy) – DavidW Oct 05 '17 at 06:23
  • @ead's answer is looks good though, and suggests a slightly different approach to any on the other question. – DavidW Oct 05 '17 at 06:25

1 Answers1

1

It is not different as to see which dlls/shared libraries are used by a process. Start python and import your cython-module:

import my_cython_module

Python will now dynamically load your module and all shared libraries which are needed for you module, that means also MKL or BLAS.

On Linux:

  1. Get pid of the program: pgrep python
  2. Take a look at loaded shared libraries: cat /proc/<PID>/maps

On Windows:

  • You can use ProcessExplorer, select the python-process and take a look at loaded dll (Ctrl+D).
  • You can attach with VisualStudio-Debugger to the python-process and take a look at the modules (Ctrl+Alt+U).

Now, if you have both (blas and mkl) loaded, which might be the case, I guess you have to run the calculation and to look at the call stack by using a debugger to be sure.


Most of the time, your cython module wont be linked directly against MKL/BLAS but via numpy. In this case it, as it was shown in the link to a question provided by DavidW, you can just look it up via:

>>> numpy.show_config()
lapack_opt_info:
     libraries = ['mkl_core_dll', 'mkl_intel_lp64_dll', 'mkl_intel_thread_dll']
...
ead
  • 32,758
  • 6
  • 90
  • 153
  • Does numpy.show_config() shows: libraries = ['mkl_core_dll', 'mkl_intel_lp64_dll', 'mkl_intel_thread_dll'] means it is already linked against MKL/BLAS success? – machen Oct 05 '17 at 09:25
  • I use ProcessExplorer in My program running, during running, I have found mkl dll name appears in the ProcessExplorer python program , Does This mean the MKL is actually linked success? – machen Oct 05 '17 at 09:32
  • @machen In 99.9% of all cases it is enough. Do you see any blas-library loaded? If not then, if only mkl can be used - whether your code uses mkl is another question, but it does not use blas. – ead Oct 05 '17 at 10:21
  • I have an IBM power processor machine(I use anaconda ppcle64 version python), It does not show MKL, but shows openblas_info: libraries = ['openblas', 'openblas'], Does this means this machine is actually use openBLAS, if the CPU is not intel, Is OpenBLAS the current best choice I have to use? – machen Oct 05 '17 at 10:24
  • I don't quite understand. You said python loaded mkl, so it is using mkl. It does not matter what is installed on the machine (I have multiple different mkl versions and openblas on my machine, but anaconda uses the one version it was installed with) I have no idea, which library/implementation is better for your machine. – ead Oct 05 '17 at 11:53
  • My question is simple, Is MKL only support Intel CPU inside machine? I have another server machine but which is based on IBM power archetecture, not intel CPU. In this situation , MKL cannot use? – machen Oct 05 '17 at 11:58
  • @machen You can use MKL for other processors, but you should expect it to be slower as on an Intel. As I said, I don't know which library is best for which architecture. – ead Oct 05 '17 at 12:08
  • I have `['mkl_rt']`, is that also enough? :) – Roelant Dec 11 '19 at 08:28