# Copyright 2013-2020 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)


from spack import *


class Cosma(CMakePackage):
    """
    Distributed Communication-Optimal Matrix-Matrix Multiplication Library
    """

    maintainers = ['teonnik', 'kabicm']
    homepage = 'https://github.com/eth-cscs/COSMA'
    url = 'https://github.com/eth-cscs/COSMA/releases/download/v2.0.2/cosma.tar.gz'
    git = 'https://github.com/eth-cscs/COSMA.git'

    # note: The default archives produced with github do not have the archives
    #       of the submodules.
    version('master', branch='master', submodules=True)
    version('2.0.2', sha256='4f3354828bc718f3eef2f0098c3bdca3499297497a220da32db1acd57920c68d')
    # note: this version fails to build at the moment
    # version('1.0.0',
    #         url='https://github.com/eth-cscs/COSMA/releases/download/1.0/cosma.tar.gz',
    #         sha256='c142104258dcca4c17fa7faffc2990a08d2777235c7980006e93c5dca51061f6')

    variant('cuda', default=False,
            description='Build with the CUBLAS back end.')
    variant('scalapack', default=False,
            description='Build with ScaLAPACK support.')

    depends_on('cmake@3.12:', type='build')
    depends_on('mpi@3:')
    depends_on('blas', when='~cuda')
    depends_on('scalapack', when='+scalapack')
    # COSMA is written entirely in C++, it may use cublasXt but a CUDA capable
    # compiler is not needed. There is no need for CudaPackage in this recipe.
    depends_on('cuda', when='+cuda')

    def setup_build_environment(self, env):
        if '+cuda' in self.spec:
            env.set('CUDA_PATH', self.spec['cuda'].prefix)

    def cmake_args(self):
        spec = self.spec
        args = ['-DCOSMA_WITH_TESTS=OFF',
                '-DCOSMA_WITH_APPS=OFF',
                '-DCOSMA_WITH_PROFILING=OFF',
                '-DCOSMA_WITH_BENCHMARKS=OFF']

        if '^mkl' in spec:
            args += ['-DCOSMA_BLAS=MKL']
        elif '^netlib-lapack' in spec:
            args += ['-DCOSMA_BLAS=CUSTOM']
        elif '^openblas' in spec:
            args += ['-DCOSMA_BLAS=OPENBLAS']
        elif '+cuda' in spec:
            args += ['-DCOSMA_BLAS=CUDA']
        else:  # TODO '^rocm' in spec:
            args += ['-DCOSMA_BLAS=ROCM']

        if '+scalapack' and '^mkl' in spec:
            args += ['-DCOSMA_SCALAPACK=MKL']
        elif '+scalapack' and '^netlib-scalapack' in spec:
            args += ['-DCOSMA_SCALAPACK=CUSTOM']

        return args

@@ -238,16 +238,29 @@
 ePackage
+, CudaPackage
 ):%0A    %22
@@ -370,15 +370,15 @@
 = %5B'
-teonnik
+haampie
 ', '
@@ -384,16 +384,27 @@
 'kabicm'
+, 'teonnik'
 %5D%0A    ho
@@ -514,19 +514,19 @@
 load/v2.
-0.2
+2.0
 /cosma.t
@@ -768,11 +768,11 @@
 ('2.
-0.2
+2.0
 ', s
@@ -782,426 +782,268 @@
 56='
-4f3354828bc718f3eef2f0098c3bdca3499297497a220da32db1acd57920c68d')%0A    # note: this version fails to build at the moment%0A    # version('1.0.0',%0A    #         url='https://github.com/eth-cscs/COSMA/releases/download/1.0/cosma.tar.gz',%0A    #         sha256='c142104258dcca4c17fa7faffc2990a08d2777235c
+1eb92a98110df595070a12193b9221eecf9d103ced8836c960f6c79a2bd553ca')%0A    version('2.0.7', sha256='8d70bfcbda6239b6a8fbeaca138790bbe58c0c3aa5768
 79
+4
 80
-006e93c5dca51061f6
+d2632d4936cf7e
 ')%0A
-%0A
     v
-ariant('cuda', default=False,%0A            description='Build with the CUBLAS back end.
+ersion('2.0.2', sha256='4f3354828bc718f3eef2f0098c3bdca3499297497a220da32db1acd57920c68d
 ')%0A
+%0A
     
@@ -1128,15 +1128,11 @@
 ACK 
-support
+API
 .')%0A
@@ -1288,203 +1288,8 @@
 ck')
-%0A    # COSMA is written entirely in C++, it may use cublasXt but a CUDA capable%0A    # compiler is not needed. There is no need for CudaPackage in this recipe.%0A    depends_on('cuda', when='+cuda')
 %0A%0A  
@@ -1715,24 +1715,110 @@
 _BLAS=MKL'%5D%0A
+        elif '%5Ecray-libsci' in spec:%0A            args += %5B'-DCOSMA_BLAS=CRAY_LIBSCI'%5D%0A
         elif
@@ -2208,24 +2208,132 @@
 APACK=MKL'%5D%0A
+        elif '+scalapack' and '%5Ecray-libsci' in spec:%0A            args += %5B'-DCOSMA_SCALAPACK=CRAY_LIBSCI'%5D%0A
         elif

Add new version of COSMA: 2.2.0 (#16672)