## START: Set by rpmautospec
## (rpmautospec version 0.7.3)
## RPMAUTOSPEC: autorelease, autochangelog
%define autorelease(e:s:pb:n) %{?-p:0.}%{lua:
    release_number = 2;
    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

# So pre releases can be tried
%bcond_with gitcommit

%if %{with gitcommit}
# Something recent to match change to cpuinfo
%global commit0 312eb7e13554ce75d02c5cb27357555f1368f2d1
%global date0 20240814

%else
# For PyTorch 2.5
%global commit0 312eb7e13554ce75d02c5cb27357555f1368f2d1
%global date0 20240814
%endif

%global shortcommit0 %(c=%{commit0}; echo ${c:0:7})


%global upstream_name XNNPACK

# This project is not well behaved so build in source
%global __cmake_in_source_build 1
# No debug info
%global debug_package %{nil}

Summary:        High-efficiency floating-point neural network inference operators
Name:           xnnpack
License:        BSD-3-Clause
Version:        0.0^git%{date0}.%{shortcommit0}
Release:        %autorelease

URL:            https://github.com/google/%{upstream_name}
Source0:        %{url}/archive/%{commit0}/%{name}-%{shortcommit0}.tar.gz
# https://github.com/google/XNNPACK/pull/6144
Patch0:         0001-Fix-cmake-for-pthread-and-cpuinfo-with-USE_SYSTEM_LI.patch

ExclusiveArch:  x86_64 aarch64

BuildRequires:  cmake
BuildRequires:  cpuinfo-devel
BuildRequires:  FP16-devel
BuildRequires:  fxdiv-devel
BuildRequires:  gcc-c++
BuildRequires:  make
BuildRequires:  ninja-build
BuildRequires:  pthreadpool-devel

%description
XNNPACK is a highly optimized solution for neural network inference on ARM,
x86, WebAssembly, and RISC-V platforms. XNNPACK is not intended for direct
use by deep learning practitioners and researchers; instead it provides
low-level performance primitives for accelerating high-level machine learning
frameworks, such as TensorFlow Lite, TensorFlow.js, PyTorch, ONNX Runtime,
and MediaPipe.

%package devel
Summary:        Headers and libraries for %{name}
Requires:       %{name}%{?_isa} = %{version}-%{release}

%description devel
%{summary}

%prep
%autosetup -p1 -n %{upstream_name}-%{commit0}

# version of the *.so
echo "SET_TARGET_PROPERTIES(XNNPACK PROPERTIES SOVERSION \"24.08.14\")" >> CMakeLists.txt

%build
%cmake -G Ninja \
      -DBUILD_SHARED_LIBS=ON \
      -DCMAKE_C_FLAGS=-fPIC \
      -DCMAKE_CXX_FLAGS=-fPIC \
      -DXNNPACK_BUILD_BENCHMARKS=OFF \
      -DXNNPACK_BUILD_LIBRARY=ON \
      -DXNNPACK_BUILD_TESTS=OFF \
      -DXNNPACK_ENABLE_KLEIDIAI=OFF \
      -DXNNPACK_USE_SYSTEM_LIBS=ON \
      -DXNNPACK_LIBRARY_TYPE=shared

%cmake_build

%install
mkdir -p %{buildroot}%{_includedir}
install -p -m 644 include/xnnpack.h %{buildroot}%{_includedir}
mkdir -p %{buildroot}%{_libdir}
strip libXNNPACK.so.24.08.14
install -p -m 755 libXNNPACK.so.24.08.14 %{buildroot}%{_libdir}
cd %{buildroot}%{_libdir}
ln -s libXNNPACK.so.24.08.14 libXNNPACK.so

# building tests or benchmarks is broken
# % check
# ctest

%files
%license LICENSE
%{_libdir}/libXNNPACK.so.*

%files devel
%doc README.md
%{_includedir}/xnnpack.h
%{_libdir}/libXNNPACK.so

%changelog
## START: Generated by rpmautospec
* Wed Oct 23 2024 Tom Rix <Tom.Rix@amd.com> - 0.0^git20240814.312eb7e-2
- Turn off kleidiai

* Wed Oct 23 2024 Tom Rix <Tom.Rix@amd.com> - 0.0^git20240814.312eb7e-1
- Update to 24.08.14

* Wed Aug 14 2024 Tom Rix <Tom.Rix@amd.com> - 0.0^git20240229.fcbf55a-4
- Update gitcommit

* Sat Jul 20 2024 Fedora Release Engineering <releng@fedoraproject.org> - 0.0^git20240229.fcbf55a-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_41_Mass_Rebuild

* Mon Mar 11 2024 Tom Rix <trix@redhat.com> - 0.0^git20240229.fcbf55a-2
- Missing from checkin

* Sun Mar 10 2024 Tom Rix <trix@redhat.com> - 0.0^git20240229.fcbf55a-1
- Update to 24.02.29

* Sat Mar 09 2024 Tom Rix <trix@redhat.com> - 0.0^git20221221.51a9875-6
- Fix rhel 9

* Fri Mar 08 2024 Tom Rix <trix@redhat.com> - 0.0^git20221221.51a9875-5
- Update for pt 2.3

* Sat Feb 03 2024 Tom Rix <trix@redhat.com> - 0.0^git20221221.51a9875-4
- Prepare for the next release

* Tue Jan 30 2024 Tom Rix <trix@redhat.com> - 0.0^git20221221.51a9875-3
- Fix broken arm build

* Sat Jan 27 2024 Fedora Release Engineering <releng@fedoraproject.org> - 0.0^git20221221.51a9875-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild

* Thu Oct 12 2023 Tom Rix <trix@redhat.com> - 0.0^git20221221.51a9875-1
- Initial package
## END: Generated by rpmautospec