-
Notifications
You must be signed in to change notification settings - Fork 88
/
magma.py
138 lines (107 loc) · 4.77 KB
/
magma.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# pylint: disable=invalid-name, too-few-public-methods
# pylint: disable=too-many-instance-attributes
"""MAGMA building block"""
from __future__ import absolute_import
from __future__ import unicode_literals
from __future__ import print_function
import posixpath
import hpccm.templates.envvars
import hpccm.templates.ldconfig
from hpccm.building_blocks.base import bb_base
from hpccm.building_blocks.generic_cmake import generic_cmake
from hpccm.building_blocks.packages import packages
from hpccm.primitives.comment import comment
class magma(bb_base, hpccm.templates.envvars, hpccm.templates.ldconfig):
"""The `magma` building block configures, builds, and installs the
[MAGMA](https://icl.cs.utk.edu/magma) component.
The [CMake](#cmake) building block should be installed prior to
this building block.
Either the [MKL](#mkl) or [OpenBLAS](#openblas) building block
should also be installed.
# Parameters
annotate: Boolean flag to specify whether to include annotations
(labels). The default is False.
cmake_opts: List of options to pass to `cmake`. The default value
is an empty list.
gpu_target: List of GPU architectures to compile. The default
values are `Pascal`, `Volta`, and `Turing`.
ospackages: List of OS packages to install prior to configuring
and building. The default values are `tar` and `wget`.
prefix: The top level install location. The default value is
`/usr/local/magma`.
toolchain: The toolchain object. This should be used if
non-default compilers or other toolchain options are needed. The
default is empty.
version: The version of MAGMA source to download. The default
value is `2.5.3`.
# Examples
```python
magma(prefix='/opt/magma', version='2.5.3')
```
"""
def __init__(self, **kwargs):
"""Initialize building block"""
super(magma, self).__init__(**kwargs)
self.__baseurl = kwargs.pop('baseurl', 'http://icl.utk.edu/projectsfiles/magma/downloads')
self.__cmake_opts = kwargs.pop('cmake_opts', [])
self.__gpu_target = kwargs.pop('gpu_target',
['Pascal', 'Volta', 'Turing'])
self.__ospackages = kwargs.pop('ospackages', ['tar', 'wget'])
self.__prefix = kwargs.pop('prefix', '/usr/local/magma')
self.__version = kwargs.pop('version', '2.5.3')
# Set the cmake options
self.__cmake()
# Setup the environment variables
self.environment_variables['CPATH'] = '{}:$CPATH'.format(
posixpath.join(self.__prefix, 'include'))
self.environment_variables['LIBRARY_PATH'] = '{}:$LIBRARY_PATH'.format(
posixpath.join(self.__prefix, 'lib'))
if not self.ldconfig:
self.environment_variables['LD_LIBRARY_PATH'] = '{}:$LD_LIBRARY_PATH'.format(posixpath.join(self.__prefix, 'lib'))
# Setup build configuration
self.__bb = generic_cmake(
annotations={'version': self.__version},
base_annotation=self.__class__.__name__,
comment=False,
cmake_opts=self.__cmake_opts,
devel_environment=self.environment_variables,
prefix=self.__prefix,
runtime_environment=self.environment_variables,
url='{0}/magma-{1}.tar.gz'.format(self.__baseurl, self.__version),
**kwargs)
# Container instructions
self += comment('MAGMA version {}'.format(self.__version))
self += packages(ospackages=self.__ospackages)
self += self.__bb
def __cmake(self):
"""Setup cmake options based on users parameters"""
# GPU architectures
if self.__gpu_target:
self.__cmake_opts.append('-DGPU_TARGET="{}"'.format(
' '.join(self.__gpu_target)))
def runtime(self, _from='0'):
"""Generate the set of instructions to install the runtime specific
components from a build in a previous stage.
# Examples
```python
m = magma(...)
Stage0 += m
Stage1 += m.runtime()
```
"""
self.rt += comment('MAGMA')
self.rt += self.__bb.runtime(_from=_from)
return str(self.rt)