Skip to content

Instantly share code, notes, and snippets.

@zachlewis
Created August 20, 2020 23:44
Show Gist options
  • Save zachlewis/b6a7b32a604ff964894566151230c4d3 to your computer and use it in GitHub Desktop.
Save zachlewis/b6a7b32a604ff964894566151230c4d3 to your computer and use it in GitHub Desktop.
MAGMA rez package build thingie
name = 'magma'
version = '2.5.3.z11'
description = \
'''
The goal of the MAGMA project is to create a new generation of linear algebra
libraries that achieves the fastest possible time to an accurate solution on
heterogeneous architectures, starting with current multicore + multi-GPU
systems. To address the complex challenges stemming from these systems'
heterogeneity, massive parallelism, and the gap between compute speed and
CPU-GPU communication speed, MAGMA's research is based on the idea that
optimal software solutions will themselves have to hybridize, combining
the strengths of different algorithms within a single framework. Building
on this idea, the goal is to design linear algebra algorithms and frameworks
for hybrid multicore and multi-GPU systems that can enable applications to
fully exploit the power that each of the hybrid components offers.
Designed to be similar to LAPACK in functionality, data storage, and interface,
the MAGMA library allows scientists to easily port their existing software
components from LAPACK to MAGMA, to take advantage of the new hybrid
architectures. MAGMA users do not have to know CUDA in order to use the library.
'''
authors = ['zlewis']
tools = []
requires = [
#'lapack-3.9.1+<4',
#'tensorrt-7.0',
]
private_build_requires = [
'cmake-3',
'gcc-6+<8',
'mkl-2019',
#'llvm-8',
]
@early()
def uuid():
import uuid
return str(uuid.uuid5(uuid.NAMESPACE_DNS, name))
@early()
def variants():
from rez.package_py_utils import expand_requires
requires = ["platform-**", "arch-**", "os-**"]
cudas = [
#'cuda-10.2',
#'cuda-10.0',
'cuda-10.1',
#'!cuda'
]
blases = [
#'openblas-0.3.9',
#'oneapi_base-2021',
'cuda',
]
return [expand_requires(*requires) + [cuda, blas] for cuda in cudas for blas in blases]
hashed_variants = True
def pre_build_commands():
env.MAGMA_VERSION = '.'.join(str(this.version).split('.')[0:3])
env.CFLAGS = ' '.join([
'$CFLAGS',
'-DMAGMA_WITH_MKL' if 'intel_mkl' in resolve or 'oneapi_base' in resolve or 'mkl' in resolve else '',
'-DMAGMA_WITH_ACML' if 'acml' in resolve else '',
#'-DMAGMA_NO_V1', # Skips compiling non-queue versions of MAGMA BLAS routines, and simplifies magma_init().
'-DMAGMA_NOAFFINITY', # Disables thread affinity, available in glibc 2.6 and later.
'-fPIC',
])
cuda_ver = '%s.%s' % (resolve.cuda.version.major, resolve.cuda.version.minor)
info('CUDA VER: {cuda_ver}')
env.FFLAGS = '$FFLAGS -fPIC'
env.F90FLAGS = '$F90FLAGS -fPIC'
env.NVCCFLAGS = '$NVCCFLAGS -DHAVE_CUBLAS -Xfatbin -compress-all -Xcompiler -fPIC -std=c++11'
env.LDFLAGS = ' '.join([
'-Wl,--enable-new-dtags,--no-as-needed',
'$LDFLAGS',
'-Wall',
'-fopenmp',
#'-llapack',
#'-lblas',
#'-lgfortran',
'-lcublasLt' if 'cuda' in resolve and cuda_ver not in ['9.2', '10.0'] else '',
])
env.CXXFLAGS = '$CXXFLAGS -static-libstdc++ -fexceptions -fPIC'
env.FPIC = '-fPIC'
# see: http://icl.utk.edu/projectsfiles/magma/doxygen/
if 'lapack' in resolve:
env.LAPACKDIR = '{resolve.lapack.root}'
blas_vendor = 'Generic'
if 'acml' in resolve:
env.ACMLDIR = '{resolve.acml.root}'
blas_vendor = 'ACML'
if 'atlas' in resolve:
env.ATLASDIR = '{resolve.atlas.root}'
#blas_vendor = '' # what should this be?
if 'openblas' in resolve:
env.OPENBLASDIR = '{resolve.openblas.root}'
blas_vendor = 'OpenBLAS'
if 'cuda' in resolve:
env.CUDADIR = '$CUDA_HOME'
if 'blis' in resolve:
blas_vendor = 'FLAME'
if 'mkl' in resolve:
#if unset('MKLROOT'):
# env.MKLROOT = '{resolve.intel_mkl.root}'
blas_vendor = 'Intel10_64lp' # Intel10_64lp, Intel10_64lp_seq, Intel10_64ilp, Intel10_64ilp_seq, Intel10_32
if 'oneapi_base' in resolve:
#if unset('MKLROOT'):
# mkl_maj, mkl_min, mkl_patch = resolve.oneapi_base.version[0:3]
# env.MKLROOT = '{resolve.oneapi_base.root}/oneapi_base/mkl/{mkl_maj}.{mkl_min}-beta0{mkl_patch}'
blas_vendor = 'Intel10_64lp'
env.REZ_BUILD_CMAKE_ARGS = ' '.join([
'-DCMAKE_INSTALL_PREFIX={build.install_path}',
'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={build.install_path}/lib',
'-DBLA_VENDOR={blas_vendor}', # Intel10_64lp, Intel10_64lp_seq, Intel10_64ilp, Intel10_64ilp_seq, Intel10_32, OpenBLAS, FLAME, ACML, Apple, NAS, Generic.
#"-DGPU_TARGET='sm_61\\ sm_75'", # Fermi, Kepler, Maxwell, Pascal, Volta, Turing,
'-DBUILD_SHARED_LIBS=ON',
'-DFORTRAN_CONVENTION=-DADD_',
'-DUSE_FORTRAN=OFF',
'-DCMAKE_BUILD_TYPE=Release',
'-DCUDA_SEPARABLE_COMPILATION=OFF',
'-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=1',
])
build_command = """
wget http://icl.utk.edu/projectsfiles/magma/downloads/magma-$MAGMA_VERSION.tar.gz
tar -xvf magma-*.tar.gz --strip 1
mkdir build && cd build
cmake .. $REZ_BUILD_CMAKE_ARGS -DGPU_TARGET="sm_61 sm_75"
make {install} -j$REZ_BUILD_THREAD_COUNT
"""
def commands():
env.LD_LIBRARY_PATH.prepend('{root}/lib')
env.LIBRARY_PATH.prepend('{root}/lib')
if building:
env.MAGMA_ROOT = '{root}'
env.MAGMA_HOME = '{root}'
env.LIBS = '-L{root}/lib $LIBS'
env.LDFLAGS = '-L{root}/lib -Wl,-rpath,{root}/lib $LDFLAGS'
for c in ['CFLAGS', 'CPPFLAGS', 'CXXFLAGS']:
setenv(c, '-I{root}/include $%s' % c)
env.PKG_CONFIG_PATH.prepend('{root}/lib/pkgconfig')
env.CMAKE_MODULE_PATH.prepend('{root}/lib/cmake')
#env.CMAKE_INCLUDE_PATH.prepend('{root}/include')
#env.CMAKE_LIBRARY_PATH.prepend('{root}/lib')
def post_commands():
from multiprocessing import cpu_count
cpus = cpu_count()
# todo: dynamically determine num GPUs, num threads
if undefined("MAGMA_NUM_GPUS"):
env.MAGMA_NUM_GPUS = 1
if undefined("OMP_NUM_THREADS"):
env.OMP_NUM_THREADS = cpus
if undefined("MKL_NUM_THREADS"):
env.MKL_NUM_THREADS = cpus
if undefined("VECLIB_MAXIMUM_THREADS"):
env.VECLIB_MAXIMUM_THREADS = cpus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment