File hipsolver.spec of Package hipsolver

%global upstreamname hipSOLVER

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

# hipSOLVER version
%define so_major 0
%define so_version %{so_major}.2
%define so_name libhipsolver
%define libname %{so_name}%{so_major}
%define hipsolver_version 2.2.0

%global toolchain clang
# 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/') -fPIE -Wdeprecated-declarations

%bcond_with debug
%if %{with debug}
%global build_type DEBUG
%else
%global build_type RelWithDebInfo
%endif

# Option to build the test suite
%bcond_with test
# Option to run the test suite for testing on real HW:
%bcond_with check

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

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

BuildRequires:  cmake
BuildRequires:  ninja
BuildRequires:  gcc-fortran
BuildRequires:  rocm-cmake
BuildRequires:  rocm-comgr-devel
BuildRequires:  rocm-hip-devel
BuildRequires:  rocm-runtime-devel
BuildRequires:  rocm-rpm-macros
BuildRequires:  rocm-release(rocprim-headers) = %{rocm_release}
BuildRequires:  rocm-release(rocsparse-devel) = %{rocm_release}
BuildRequires:  rocm-release(rocblas-devel) = %{rocm_release}
BuildRequires:  rocm-release(rocsolver-devel) = %{rocm_release}
BuildRequires:  suitesparse-devel

%if 0%{?sle_version} == 150600
BuildRequires:  gcc12-c++
BuildRequires:  libstdc++6-devel-gcc12
%else
BuildRequires:  libstdc++-devel
%endif

%if %{with check} || %{with test}
BuildRequires:  googletest-devel
BuildRequires:  rocm-release(hipsparse-devel) = %{rocm_release}
BuildRequires:  blas-devel-static
BuildRequires:  lapack-devel-static
%endif

Requires:       %{libname}%{?_isa} = %{hipsolver_version}
Provides:       rocm-release(%{name}) = %{rocm_release}

# 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     -n %{libname}
Summary:        ROCm SOLVER marshalling library
Group:          System/Libraries/C and C++
Provides:       %{libname}%{?_isa} = %{hipsolver_version}

%description -n %{libname}
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:        The %{upstreamname} development package
Group:          System/Libraries/C and C++
Requires:       %{name}%{?_isa} = %{version}-%{release}
Requires:       %{libname}%{?_isa} = %{hipsolver_version}
Provides:       rocm-release(%{name}-devel) = %{rocm_release}

%description    devel
The %{upstreamname} development package.

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

%description    test
This package contains the test files to be run on real hardware.
%endif

%prep
%autosetup -n %{upstreamname}-rocm-%{version} -p 1

%build
# enable sccache during build if available
if command -v ccache > /dev/null; then
  export HIP_CLANG_LAUNCHER=ccache
fi

%define __builder ninja
%cmake \
    -DBUILD_FILE_REORG_BACKWARD_COMPATIBILITY=OFF \
%if %{with test}
    -DBUILD_CLIENTS_TESTS=ON \
%endif
    -DBUILD_SHARED_LIBS=ON \
    -DBUILD_WITH_SPARSE_DEFAULT=ON \
    -DCMAKE_BUILD_TYPE=%build_type \
    -DCMAKE_C_COMPILER=%rocm_cc \
    -DCMAKE_CXX_COMPILER=%rocm_cxx \
    -DCMAKE_CXX_FLAGS="%build_cxxflags" \
    -DCMAKE_PREFIX_PATH="%rocm_path" \
    -DCMAKE_SKIP_INSTALL_RPATH=ON \
    -DCMAKE_INSTALL_DO_STRIP=ON \
    -DCMAKE_INSTALL_LIBDIR=%{_lib} \
    -DROCM_SYMLINK_LIBS=OFF \
    -DHIP_PLATFORM=amd \
    -DAMDGPU_TARGETS="%{list_sep rocm_gpu_list ;}"
%cmake_build

%install
%cmake_install

# we don't nned the installed docs
rm -rf %{buildroot}%{_docdir}/%{name}

%if %{with test}
# move tests to libexec
mkdir -p %{buildroot}%{_libexecdir}/%{name}-test
mv %{buildroot}%{_bindir}/* %{buildroot}%{_libexecdir}/%{name}-test/
%endif

%check
%if %{with check}
%ctest
%endif

%ldconfig_scriptlets -n %{libname}

%files
%doc README.md
%license LICENSE.md

%files -n %{libname}
%{_libdir}/%{so_name}.so.%{so_major}
%{_libdir}/%{so_name}.so.%{so_version}

%files devel
%{_includedir}/%{name}
%{_libdir}/cmake/%{name}
%{_libdir}/%{so_name}.so

%if %{with test}
%files test
%{_libexecdir}/%{name}-test
%endif

%changelog
openSUSE Build Service is sponsored by