## START: Set by rpmautospec
## (rpmautospec version 0.7.2)
## RPMAUTOSPEC: autorelease, autochangelog
%define autorelease(e:s:pb:n) %{?-p:0.}%{lua:
    release_number = 1;
    base_release_number = tonumber(rpm.expand("%{?-b*}%{!?-b:1}"));
    print(release_number + base_release_number - 1);
}%{?-e:.%{-e*}}%{?-s:.%{-s*}}%{!?-n:%{?dist}}
## END: Set by rpmautospec

%global upstreamname hipSOLVER
%global rocm_release 6.2
%global rocm_patch 0
%global rocm_version %{rocm_release}.%{rocm_patch}

%global toolchain rocm
# hipcc does not support some clang flags
%global build_cxxflags %(echo %{optflags} | sed -e 's/-fstack-protector-strong/-Xarch_host -fstack-protector-strong/' -e 's/-fcf-protection/-Xarch_host -fcf-protection/')

# $gpu will be evaluated in the loops below             
%global _vpath_builddir %{_vendor}-%{_target_os}-build-${gpu}

# It is necessary to use this with a local build
# export QA_RPATHS=0xff
%bcond_with test

# gfortran and clang rpm macros do not mix
%global build_fflags %{nil}

Name:           hipsolver
Version:        %{rocm_version}
Release:        %autorelease
Summary:        ROCm SOLVER marshalling library
Url:            https://github.com/ROCm/%{upstreamname}
License:        MIT

Source0:        %{url}/archive/rocm-%{rocm_version}.tar.gz#/%{upstreamname}-%{rocm_version}.tar.gz

BuildRequires:  cmake
BuildRequires:  gcc-gfortran
BuildRequires:  ninja-build
BuildRequires:  rocblas-devel
BuildRequires:  rocm-cmake
BuildRequires:  rocm-comgr-devel
BuildRequires:  rocm-hip-devel
BuildRequires:  rocm-runtime-devel
BuildRequires:  rocm-rpm-macros
BuildRequires:  rocm-rpm-macros-modules
BuildRequires:  rocsolver-devel
BuildRequires:  rocsparse-devel
BuildRequires:  suitesparse-devel

%if %{with test}

# test parallel building broken
%global _smp_mflags -j1

BuildRequires:  gtest-devel
BuildRequires:  blas-static
BuildRequires:  lapack-static
%endif

Requires:       rocm-rpm-macros-modules

# Only x86_64 works right now:
ExclusiveArch:  x86_64

%description
hipSOLVER is a LAPACK marshalling library, with multiple supported
backends. It sits between the application and a 'worker'
LAPACK library, marshalling inputs into the backend library and
marshalling results back to the application. hipSOLVER exports an
interface that does not require the client to change, regardless
of the chosen backend. Currently, hipSOLVER supports rocSOLVER
and cuSOLVER as backends.

%package devel
Summary:        Libraries and headers for %{name}
Requires:       %{name}%{?_isa} = %{version}-%{release}
Requires:       %{name}-gfx90a%{?_isa} = %{version}-%{release}
Requires:       %{name}-gfx942%{?_isa} = %{version}-%{release}
Requires:       %{name}-gfx1100%{?_isa} = %{version}-%{release}
Requires:       %{name}-gfx1103%{?_isa} = %{version}-%{release}

%description devel
%{summary}

%if %{with test}
%package test
Summary:        Tests for %{name}
Requires:       %{name}%{?_isa} = %{version}-%{release}

%description test
%{summary}
%endif

%package gfx90a
Summary:        %{name} for MI200
%description gfx90a
%{summary}

%package gfx942
Summary:        %{name} for MI300
%description gfx942
%{summary}

%package gfx1100
Summary:        %{name} for W7900
%description gfx1100
%{summary}

%package gfx1103
Summary:        %{name} for gfx1103 (experimental)
%description gfx1103
%{summary}

%prep
%autosetup -p1 -n %{upstreamname}-rocm-%{version}

%build

for gpu in %{rocm_gpu_list}
do
    module load rocm/$gpu
    %cmake %rocm_cmake_options \
          -DCMAKE_BUILD_TYPE=RelWithDebugInfo \
%if %{with test}
           %rocm_cmake_test_options \
%endif

    %cmake_build
    module purge
done

%install

for gpu in %{rocm_gpu_list}
do
    %cmake_install
done

%files
%dir %{_libdir}/cmake/%{name}/
%license LICENSE.md
%exclude %{_docdir}/%{name}/LICENSE.md
%{_libdir}/lib%{name}.so.*
%{_libdir}/rocm/gfx{8,9,10,11}/lib/lib%{name}.so.*

%files gfx90a
%{_libdir}/rocm/gfx90a/lib/lib%{name}.so.*

%files gfx942
%{_libdir}/rocm/gfx942/lib/lib%{name}.so.*

%files gfx1100
%{_libdir}/rocm/gfx1100/lib/lib%{name}.so.*

%files gfx1103
%{_libdir}/rocm/gfx1103/lib/lib%{name}.so.*


%files devel
%doc README.md
%{_includedir}/%{name}
%{_libdir}/cmake/%{name}/
%{_libdir}/lib%{name}.so
%{_libdir}/rocm/gfx*/lib/lib%{name}.so
%{_libdir}/rocm/gfx*/lib/cmake/%{name}/

%if %{with test}
%files test
%dir %{_datadir}/%{name}
%dir %{_datadir}/%{name}/test
%dir %{_datadir}/%{name}/test/mat_20_60
%dir %{_datadir}/%{name}/test/mat_20_100
%dir %{_datadir}/%{name}/test/mat_20_140
%dir %{_datadir}/%{name}/test/mat_50_60
%dir %{_datadir}/%{name}/test/mat_50_100
%dir %{_datadir}/%{name}/test/mat_50_140
%dir %{_datadir}/%{name}/test/mat_100_300
%dir %{_datadir}/%{name}/test/mat_100_500
%dir %{_datadir}/%{name}/test/mat_100_700
%dir %{_datadir}/%{name}/test/mat_250_300
%dir %{_datadir}/%{name}/test/mat_250_500
%dir %{_datadir}/%{name}/test/mat_250_700

%{_datadir}/%{name}/test/mat_20_60/*
%{_datadir}/%{name}/test/mat_20_100/*
%{_datadir}/%{name}/test/mat_20_140/*
%{_datadir}/%{name}/test/mat_50_60/*
%{_datadir}/%{name}/test/mat_50_100/*
%{_datadir}/%{name}/test/mat_50_140/*
%{_datadir}/%{name}/test/mat_100_300/*
%{_datadir}/%{name}/test/mat_100_500/*
%{_datadir}/%{name}/test/mat_100_700/*
%{_datadir}/%{name}/test/mat_250_300/*
%{_datadir}/%{name}/test/mat_250_500/*
%{_datadir}/%{name}/test/mat_250_700/*
%{_bindir}/%{name}*
%{_libdir}/rocm/gfx*/bin/%{name}*
%endif

%changelog
## START: Generated by rpmautospec
* Thu Aug 22 2024 Jeremy Newton <Jeremy.Newton@amd.com> - 6.2.0-1
- Update to 6.2.0

* Thu Jul 18 2024 Fedora Release Engineering <releng@fedoraproject.org> - 6.1.1-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_41_Mass_Rebuild

* Tue Jun 04 2024 Tom Rix <trix@redhat.com> - 6.1.1-1
- Update to 6.1.1

* Wed Mar 13 2024 Tom Rix <trix@redhat.com> - 6.0.2-1
- Update to 6.0.2

* Thu Jan 25 2024 Tom Rix <trix@redhat.com> - 6.0.0-1
- Initial import
## END: Generated by rpmautospec