xref: /petsc/config/BuildSystem/config/packages/BLIS.py (revision 7b2fcb5d6efa604aac62606659be4a62fc8a0438)
1import config.package
2
3#
4# If --download-blis is used WITHOUT --download-f2cblaslapack it is possible that the installed BLIS libraries will NOT be used!
5# This is because some automatically detected LAPACK libraries are so intimately connected to their own BLAS they do not utilize
6# the other BLAS symbols provided in the link line (that, in this situation, come from BLIS)
7#
8class Configure(config.package.Package):
9  def __init__(self, framework):
10    config.package.Package.__init__(self, framework)
11    self.version   = '2.0'
12    self.gitcommit = '2.0-rc0'
13    self.download  = ['git://https://github.com/flame/blis.git', 'https://github.com/flame/blis/archive/%s.tar.gz' % self.gitcommit]
14    self.functions = ['bli_init']
15    self.includes  = ['blis/blis.h']
16    self.liblist   = [['libblis.a']]
17    self.complex_return = None
18    return
19
20  def setupHelp(self, help):
21    import nargs
22    config.package.Package.setupHelp(self, help)
23    help.addArgument(self.PACKAGE,'-download-blis-use-pthreads=<bool>',nargs.ArgBool(None,1,'Use pthreads threading support for '+self.name ))
24    help.addArgument(self.PACKAGE,'-download-blis-use-openmp=<bool>',nargs.ArgBool(None,1,'Use OpenMP threading support for '+self.name))
25    help.addArgument(self.PACKAGE,'-download-blis-enable-cblas-headers=<bool>',nargs.ArgBool(None,0,'Enable CBLAS headers for '+self.name ))
26    help.addArgument(self.PACKAGE,'-download-blis-complex-return=<string>',nargs.ArgString(None,None,'Specify the method of returning complex numbers from blas routines ('+self.name+' supports "gnu" and "intel")'))
27    help.addArgument(self.PACKAGE,'-download-blis-confname=<string>',nargs.ArgString(None,'auto','Select blis confname: "auto", "generic", "sandybridge", "haswell", etc.'))
28    return
29
30  def configureLibrary(self):
31    import os
32    config.package.Package.configureLibrary(self)
33    if not hasattr(self, 'known64'): self.known64 = 'unknown'
34    if self.found:
35      try:
36        threading_model = re.compile(r'THREADING_MODEL\s*:=\s*(.*)')
37        for line in os.path.join(self.directory, 'share', 'blis', 'config.mk'):
38            match = threading_model.match(line)
39            if match:
40              self.threading_model = match.groups()[0]
41              self.usesopenmp = 'no'
42              self.usespthreads = 'no'
43              if self.threading_model == 'openmp':
44                self.usesopenmp = 'yes'
45              if self.threading_model == 'pthreads':
46                self.usespthreads = 'yes'
47      except:
48        pass
49
50  def setupDependencies(self, framework):
51    config.package.Package.setupDependencies(self, framework)
52    self.setCompilers    = framework.require('config.setCompilers',self)
53    self.make            = framework.require('config.packages.make', self)
54    self.openmp          = framework.require('config.packages.OpenMP',self)
55    self.pthread         = framework.require('config.packages.pthread',self)
56
57  def Install(self):
58    import os
59    self.logPrintBox('Configuring BLIS; this may take several minutes')
60    args = ['./configure', '--prefix='+self.installDir]
61    try:
62      if self.argDB['with-64-bit-blas-indices']:
63        args.append('--blas-int-size=64')
64        self.known64 = '64'
65      else:
66        self.known64 = '32'
67      threads = []
68      if self.argDB['download-blis-use-pthreads'] and self.pthread.found:
69          threads.append('pthreads')
70          self.usespthreads = 'yes'
71      if self.argDB['download-blis-use-openmp'] and self.openmp.found:
72          threads.append('openmp')
73          self.usesopenmp = 'yes'
74      if threads:
75        args.append('--enable-threading='+','.join(threads))
76      if self.argDB['download-blis-enable-cblas-headers']:
77        args.append('--enable-cblas')
78      try:
79        self.complex_return = self.argDB['download-blis-complex-return']
80      except:
81        pass
82      if self.complex_return:
83        args.append('--complex-return=' + self.complex_return)
84      with self.Language('C'):
85        args.append('CC=' + self.getCompiler())
86      with self.Language('Cxx'):
87        args.append('CXX=' + self.getCompiler())
88      if hasattr(self.compilers, 'FC'):
89        with self.Language('FC'):
90          args.append('FC=' + self.getCompiler())
91      args.append(str(self.argDB['download-blis-confname']))
92      config.package.Package.executeShellCommand(args, cwd=self.packageDir, timeout=60, log=self.log)
93    except RuntimeError as e:
94      raise RuntimeError('Error running configure on BLIS: '+str(e))
95    try:
96      self.logPrintBox('Compiling and installing BLIS; this may take several minutes')
97      config.package.Package.executeShellCommand(self.make.make_jnp_list, cwd=self.packageDir, timeout=500, log=self.log)
98      config.package.Package.executeShellCommand(self.make.make_jnp_list + ['install'], cwd=self.packageDir, timeout=30, log=self.log)
99    except RuntimeError as e:
100      raise RuntimeError('Error running make on BLIS: '+str(e))
101    return self.installDir
102