File rocsolver.spec of Package rocsolver

%global upstreamname rocSOLVER

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

# rocSOLVER version
%define so_major 0
%define so_version %{so_major}.2
%define so_name librocsolver
%define libname %{so_name}%{so_major}
%define rocsolver_version 3.26.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:           rocsolver
Version:        %{rocm_version}
Release:        0
Summary:        Next generation LAPACK implementation for ROCm platform
Url:            https://github.com/ROCm/%{upstreamname}
License:        MIT

Source0:        %{url}/archive/rocm-%{version}.tar.gz#/%{upstreamname}-rocm-%{version}.tar.gz
Patch0:         rocsolver-Add-llvm-style-compile-and-link-options.patch

BuildRequires:  cmake
BuildRequires:  ninja
BuildRequires:  cmake(fmt)
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}

%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:  gcc-fortran
BuildRequires:  blas-devel-static
BuildRequires:  lapack-devel-static
%endif

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

# Only x86_64 works right now
ExclusiveArch:  x86_64

%description
rocSOLVER is a work-in-progress implementation of a subset of LAPACK functionality on the ROCm platform.

%package     -n %{libname}
Summary:        Next generation LAPACK implementation for ROCm platform
Group:          System/Libraries/C and C++
Provides:       %{libname}%{?_isa} = %{rocsolver_version}

%description -n %{libname}
rocSOLVER is a work-in-progress implementation of a subset of LAPACK functionality on the ROCm platform.

%package        devel
Summary:        The %{upstreamname} development package
Group:          System/Libraries/C and C++
Requires:       %{name}%{?_isa} = %{version}-%{release}
Requires:       %{libname}%{?_isa} = %{rocsolver_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 ccache 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
%if %{with compress}
    -DBUILD_OFFLOAD_COMPRESS=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