File rocblas.spec of Package rocblas

%global upstreamname rocblas

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

# rocBLAS version
%define so_major 5
%define so_version %{so_major}.2
%define so_name librocblas
%define libname %{so_name}%{so_major}
%define rocblas_version 5.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/') -fuse-ld=lld-rocm

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

%bcond_without tensile

Name:           rocblas
Version:        %{rocm_version}
Release:        0
Summary:        BLAS implementation for ROCm
Url:            https://github.com/ROCm/rocm-libraries
License:        MIT AND BSD-3-Clause AND 0BSD

Source0:        %{url}/releases/download/rocm-%{version}/%{upstreamname}.tar.gz#/%{upstreamname}-%{version}.tar.gz
Patch0:         rocblas-fixup-install-of-tensile-output.patch

BuildRequires:  git
BuildRequires:  cmake
BuildRequires:  ninja
BuildRequires:  python3-base
BuildRequires:  rocm-release(cmake) = %{rocm_release}
BuildRequires:  cmake(COMgr-ROCm) = %{rocm_release}
BuildRequires:  rocm-release(hip-devel) = %{rocm_release}
BuildRequires:  rocm-release(rocm-runtime-devel) = %{rocm_release}
BuildRequires:  rocm-release(rpm-macros) = %{rocm_release}

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

%if %{with tensile}
BuildRequires:  msgpack-cxx-devel
BuildRequires:  python3-tensile-devel
BuildRequires:  python3-joblib
%endif

%if %{with check} || %{with test}
BuildRequires:  googletest-devel
BuildRequires:  openblas-devel(default)
BuildRequires:  libomp-devel
BuildRequires:  python3-PyYAML
BuildRequires:  python3-rocminfo
%endif

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

# Only x86_64 works right now:
ExclusiveArch:  x86_64

%description
rocBLAS is the AMD library for Basic Linear Algebra Subprograms
(BLAS) on the ROCm platform. It is implemented in the HIP
programming language and optimized for AMD GPUs.

%package     -n %{libname}
Summary:        BLAS library form ROCm
Group:          System/Libraries/C and C++
Provides:       %{libname}%{?_isa} = %{rocblas_version}

%description -n %{libname}
rocBLAS is the AMD library for Basic Linear Algebra Subprograms
(BLAS) on the ROCm platform. It is implemented in the HIP
programming language and optimized for AMD GPUs.

%package        devel
Summary:        Libraries and headers for %{name}
Requires:       %{name}%{?_isa} = %{version}-%{release}
Requires:       %{libname}%{?_isa} = %{rocblas_version}
Provides:       rocm-release(%{name}-devel) = %{rocm_release}

%description    devel
%{summary}

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

%description    test
%{summary}
%endif

%prep
%autosetup -p3 -n %{upstreamname}
sed -i -e 's@set( BLAS_LIBRARY "blas" )@set( BLAS_LIBRARY "openblas" )@' clients/CMakeLists.txt
sed -i -e 's@target_link_libraries( rocblas-test PRIVATE ${BLAS_LIBRARY} ${GTEST_BOTH_LIBRARIES} roc::rocblas )@target_link_libraries( rocblas-test PRIVATE openblas ${GTEST_BOTH_LIBRARIES} roc::rocblas )@' clients/gtest/CMakeLists.txt
sed -i -e 's@find_package(Git REQUIRED)@find_package(Git)@' library/CMakeLists.txt

%build
# With compat llvm the system clang is wrong
export TENSILE_ROCM_ASSEMBLER_PATH=clang++-rocm
export TENSILE_ROCM_OFFLOAD_BUNDLER_PATH=clang-offload-bundler-rocm

%define __builder ninja
%cmake \
    -DBUILD_FILE_REORG_BACKWARD_COMPATIBILITY=OFF \
%if %{with check} || %{with test}
    -DBUILD_TEST=ON \
    -DBUILD_CLIENTS_BENCHMARKS=ON \
    -DBUILD_CLIENTS_TESTS=ON \
%else
    -DBUILD_TEST=OFF \
    -DBUILD_CLIENTS_BENCHMARKS=OFF \
    -DBUILD_CLIENTS_TESTS=OFF \
%endif
    -DBUILD_CLIENTS_TESTS_OPENMP=OFF \
    -DBUILD_FORTRAN_CLIENTS=OFF \
    -DBUILD_WITH_PIP=OFF \
%if %{with tensile}
    -DBUILD_WITH_TENSILE=ON \
%else
    -DBUILD_WITH_TENSILE=OFF \
%endif
    -DBUILD_WITH_HIPBLASLT=OFF \
    -DCMAKE_CXX_COMPILER=%rocm_cxx \
    -DCMAKE_CXX_FLAGS="%build_cxxflags" \
    -DCMAKE_PREFIX_PATH="%rocm_path" \
    -DCMAKE_SKIP_INSTALL_RPATH=ON \
    -DCMAKE_INSTALL_LIBDIR=%{_lib} \
    -DPython3_EXECUTABLE=$(which python3) \
    -DROCM_SYMLINK_LIBS=OFF \
    -DHIP_PLATFORM=amd \
    -DGPU_TARGETS="%{list_sep rocm_gpu_list ;}"
%cmake_build

%install
%cmake_install

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

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

# do not strip the generated code objects as debug sections may be used by the CLR
# find %%{buildroot}%%{_libdir}/%%{name}/library -type f -iname '*.hsaco' | xargs llvm-strip-rocm

%check
%if %{with check}
# Assumes default
%ctest
%endif

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

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

%files devel
%{_includedir}/%{name}
%{_libdir}/cmake/%{name}
%{_libdir}/%{so_name}.so
openSUSE Build Service is sponsored by