File hipblaslt.spec of Package hipblaslt

%global upstreamname hipBLASLt

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

# hipBLASLt version
%define so_major 0
%define so_version %{so_major}.8
%define so_name libhipblaslt
%define libname %{so_name}%{so_major}
%define hipblaslt_version 0.8.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

# This builds a dummy library, skip testing
# # Option to build the test suite
# %%bcond_with test
# # Option to run the test suite for testing on real HW:
# %%bcond_with check

%define pythons python3

Name:           hipblaslt
Version:        %{rocm_version}
Release:        0
Summary:        ROCm general matrix operations beyond BLAS
Url:            https://github.com/ROCm/%{upstreamname}
License:        MIT

Source0:        %{url}/archive/rocm-%{version}.tar.gz#/%{upstreamname}-rocm-%{version}.tar.gz
Patch0:         hipBLASLt-fix-libcxx.patch
Patch1:         hipBLASLt-fix-msgpack-dependency.patch
Patch2:         hipBLASLt-no-git.patch
Patch3:         hipBLASLt-no-arch.patch
Patch4:         hipBLASLt-fix-tensilelite.patch

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

BuildRequires:  pkgconfig(libedit)
BuildRequires:  pkgconfig(zlib)
BuildRequires:  cmake(msgpack-cxx)

BuildRequires:  rocm-release(hipblas-devel) = %{rocm_release}

# For tensilelite
BuildRequires:  %{python_module dataclasses if %python-base < 3.7}
BuildRequires:  %{python_module devel}
BuildRequires:  %{python_module joblib}
BuildRequires:  %{python_module PyYAML}
BuildRequires:  %{python_module msgpack}
BuildRequires:  %{python_module setuptools}

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

%if %{with check} || %{with test}
BuildRequires:  googletest-devel
%endif

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

# Only x86_64 works right now
ExclusiveArch:  x86_64

%description
hipBLASLt is a library that provides general matrix-matrix
operations. It has a flexible API that extends functionalities
beyond a traditional BLAS library, such as adding flexibility
to matrix data layouts, input types, compute types, and
algorithmic implementations and heuristics.

%package     -n %{libname}
Summary:        ROCm general matrix operations beyond BLAS
Group:          System/Libraries/C and C++
Provides:       %{libname}%{?_isa} = %{hipblaslt_version}

%description -n %{libname}
hipBLASLt is a library that provides general matrix-matrix
operations. It has a flexible API that extends functionalities
beyond a traditional BLAS library, such as adding flexibility
to matrix data layouts, input types, compute types, and
algorithmic implementations and heuristics.

%package        devel
Summary:        The %{upstreamname} development package
Group:          System/Libraries/C and C++
Requires:       %{name}%{?_isa} = %{version}-%{release}
Requires:       %{libname}%{?_isa} = %{hipblaslt_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
# Do a manual install instead of cmake's virtualenv

cd tensilelite
%if 0%{?sle_version} == 150600
echo "" > requirements.txt
%endif
%{python_exec setup.py install --root $PWD}
cd -

# Should not have to do this
export DEVICE_LIB_PATH="`clang-rocm -print-resource-dir`/amdgcn/bitcode"

# Look for the just built tensilelite
export PATH=$PWD/tensilelite/%{_bindir}:$PATH
export PYTHONPATH=$PWD/tensilelite%{python_sitelib}:$PYTHONPATH
export Tensile_PREFIX=$PWD/tensilelite/usr

# 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
    -DCMAKE_BUILD_TYPE=%build_type \
    -DCMAKE_C_COMPILER=%rocm_cc \
    -DCMAKE_CXX_COMPILER=%rocm_cxx \
    -DCMAKE_CXX_FLAGS="%build_cxxflags" \
    -DCMAKE_SKIP_INSTALL_RPATH=ON \
    -DCMAKE_PREFIX_PATH="%rocm_path" \
    -DCMAKE_INSTALL_LIBDIR=%{_lib} \
    -DTensile_DIR=tensilelite/usr/cmake/ \
    -DTensile_LIBRARY_FORMAT=msgpack \
    -DROCM_SYMLINK_LIBS=OFF \
    -DBUILD_WITH_TENSILE=ON \
    -DHIP_PLATFORM=amd \
    -DAMDGPU_TARGETS="gfx1100;gfx1101;gfx1102"
%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}
%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

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

%changelog
openSUSE Build Service is sponsored by