Module: Numo::Linalg::Autoloader

Defined in:
lib/numo/linalg/autoloader.rb

Constant Summary

@@libs =
nil

Class Method Summary collapse

Class Method Details

.libsObject



13
14
15
# File 'lib/numo/linalg/autoloader.rb', line 13

def libs
  @@libs
end

.load_libraryString

Load backend libraries for Numo::Linalg automatically.

Returns:

  • (String)

    name of loaded backend library (mkl/openblas/lapack)



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/numo/linalg/autoloader.rb', line 20

def load_library
  mkl_dirs = ['/opt/intel/lib', '/opt/intel/lib64', '/opt/intel/mkl/lib', '/opt/intel/mkl/lib64']
  openblas_dirs = ['/opt/openblas/lib', '/opt/openblas/lib64', '/usr/local/opt/openblas/lib']
  atlas_dirs = ['/opt/atlas/lib', '/opt/atlas/lib64',
                '/usr/lib/atlas', '/usr/lib64/atlas', '/usr/local/opt/atlas/lib']
  lapacke_dirs = ['/opt/lapack/lib', '/opt/lapack/lib64', '/opt/local/lib/lapack',
                  '/usr/local/opt/lapack/lib']
  opt_dirs =  ['/opt/local/lib', '/opt/local/lib64', '/opt/lib', '/opt/lib64']
  base_dirs = ['/usr/local/lib', '/usr/local/lib64', '/usr/lib', '/usr/lib64']
  base_dirs.unshift(*ENV['LD_LIBRARY_PATH'].split(':')) unless ENV['LD_LIBRARY_PATH'].nil?

  mkl_libs = find_mkl_libs([*base_dirs, *opt_dirs, *mkl_dirs])
  openblas_libs = find_openblas_libs([*base_dirs, *opt_dirs, *openblas_dirs])
  atlas_libs = find_atlas_libs([*base_dirs, *opt_dirs, *atlas_dirs, *lapacke_dirs])
  lapack_libs = find_lapack_libs([*base_dirs, *opt_dirs, *lapacke_dirs])

  @@libs = nil
  if !mkl_libs.value?(nil)
    open_mkl_libs(mkl_libs)
    @@libs = mkl_libs.values
    'mkl'
  elsif !openblas_libs.value?(nil)
    open_openblas_libs(openblas_libs)
    @@libs = openblas_libs.values.uniq
    'openblas'
  elsif !atlas_libs.value?(nil)
    open_atlas_libs(atlas_libs)
    @@libs = atlas_libs.values.uniq
    'atlas'
  elsif !lapack_libs.value?(nil)
    open_lapack_libs(lapack_libs)
    @@libs = lapack_libs.values.uniq
    'lapack'
  else
    raise 'cannot find MKL/OpenBLAS/ATLAS/BLAS-LAPACK library'
  end
end