File pocl.spec of Package pocl

#
# spec file for package pocl
#
# Copyright (c) 2024 SUSE LLC
# Copyright (c) 2014 Guillaume GARDET <guillaume@opensuse.org>
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#


#
%ifarch %ix86 %arm
%global use_clang 0
%global use_lld 0
%global use_lto 0
%else
%global use_clang 1
%global use_lld 1
%global use_lto 1
%endif

%define sover  2
Name:           pocl
Version:        6.0~RC2+718~git20241220.ab1a76a17
Release:        0
Summary:        Portable Computing Language - an OpenCL implementation
# The whole code is under MIT
# except include/utlist.h which is under BSD (and unbundled)
License:        MIT
Group:          Development/Tools/Other
URL:            http://portablecl.org/
#Source0:        https://github.com/pocl/pocl/archive/v%{version}.tar.gz#/%{name}-%{version}.tar.gz
Source0:        %{name}-%{version}.tar.gz
Source99:       pocl-rpmlintrc
#Patch0:         link_against_libclang-cpp_so.patch
BuildRequires:  cmake
%if 0%{?use_clang}
%if 0%{?use_lld}
BuildRequires:  lld
%else
BuildRequires:  binutils-gold
BuildRequires:  llvm-gold
%endif
%else
BuildRequires:  binutils-gold
BuildRequires:  gcc-c++
%endif
#BuildRequires:  ncurses-devel
%ifarch x86_64
BuildRequires:  pkgconfig(level-zero)
#BuildRequires:  HSAIL-Tools-devel
BuildRequires:  hsa-runtime-devel
%endif
BuildRequires:  glslang-devel
BuildRequires:  ninja
BuildRequires:  ocl-icd-devel
BuildRequires:  pkgconfig
BuildRequires:  spirv-headers
BuildRequires:  pkgconfig(LLVMSPIRVLib)
BuildRequires:  pkgconfig(OpenCL)
BuildRequires:  pkgconfig(SPIRV-Tools-shared)
%if 0%{?suse_version} <= 1500 && 0%{?sle_version} > 150500
BuildRequires:  ((clang-devel >= 6.0.0 with clang-devel < 18) or clang17-devel)
%else
BuildRequires:  ((clang-devel >= 18.0.0 with clang-devel < 20) or clang19-devel)
%endif
BuildRequires:  pkgconfig(hwloc)
BuildRequires:  pkgconfig(shaderc)
BuildRequires:  pkgconfig(vulkan)
#BuildRequires:  pkgconfig(lttng-ust)
# Autoreq does not look into the ICD file
#Requires:       libpocl2
# PPC has limited support/testing from upstream
# s390(x) is also not supported, so use ExclusiveArch
ExclusiveArch:  %{ix86} x86_64 %{arm} aarch64 riscv64

%description
Portable Computing Language (pocl) is an implementation of the OpenCL standard
which can be adapted for new targets and devices, both for homogeneous CPU and
heterogenous GPUs/accelerators.

pocl uses Clang as an OpenCL C frontend and LLVM for the kernel compiler
implementation, and as a portability layer. If your desired target has an LLVM
backend, it should be possible to get OpenCL support by using pocl.

pocl yields improved performance portability by using a kernel compiler that
can generate multi-work-item work-group functions that exploit various types of
parallel hardware resources, such as VLIW, superscalar, SIMD, SIMT, multicore
and multithread.

%package -n libpocl%{sover}
Summary:        Shared Library part of pocl
Group:          System/Libraries

%description -n libpocl%{sover}
Portable Computing Language (pocl) is an implementation of the OpenCL standard
which can be adapted for new targets and devices, both for homogeneous CPU and
heterogenous GPUs/accelerators.

This subpackage contains the shared library part of pocl.

%package devel
Summary:        Development files for the Portable Computing Language
Group:          Development/Languages/Other
Requires:       %{name} = %{version}
Requires:       libpocl%{sover} = %{version}
Requires:       opencl-headers >= 2.2

%description devel
Portable Computing Language (pocl) is an implementation of the OpenCL standard
which can be adapted for new targets and devices, both for homogeneous CPU and
heterogenous GPUs/accelerators.

This subpackage provides the development files needed for pocl.

%prep
%autosetup -p1
#sed -i -e 's:"-emit-llvm":"-emit-llvm" "-nogpulib":g' cmake/HSA.cmake

%build
# this macro needs 'BuildRequires: memory-constraints'
#limit_build -m 3072
ulimit -Sn 4000
#export UCFLAGS="-fPIC -O3 -fno-strict-aliasing"
#export KCFLAGS="-O3"
#export KCFLAGS="${KCFLAGS} -fexceptions -relocatable-pch -faligned-allocation"
#export KCXXFLAGS="${KCXXFLAGS} -fpermissive"
#export KCXXFLAGS="${KCXXFLAGS} -fcxx-exceptions"
export UCFLAGS="${CFLAGS} -fPIC -O3 -w"
%ifarch x86_64
export UCFLAGS="${UCFLAGS} -march=x86-64 -mtune=generic -mssse3 -msse4 -msse4.1 -msse4.2 -mavx -maes -mpclmul"
%endif
export ULDFLAGS="-fPIC -Wl,--gc-sections -Wl,--icf=safe"
%if 0%{?use_lld}
export ULDFLAGS="${ULDFLAGS} -fuse-ld=lld"
export LD="lld"
alias ld=ld.lld
%else
export ULDFLAGS="${ULDFLAGS} -fuse-ld=gold -Wl,--sort-common -Wl,-O1"
export LD=ld.gold
alias ld=gold
%endif
%if 0%{?use_clang}
export CC=clang
export CXX=clang++
#export UCFLAGS="${UCFLAGS} -v -D_GNU_SOURCE -fexceptions -relocatable-pch -faligned-allocation"
export UCXXFLAGS="${UCFLAGS} -fpermissive"
#export UCXXFLAGS="${UCFLAGS} -fcxx-exceptions"
export HOST="$(${CC} -print-target-triple)"
%if 0%{?use_lto}
%if 0%{?use_lld}
%global _lto_cflags -flto=thin -Wl,--lto-O3 -Wl,--thinlto-jobs=3
%global _lto_ldlags -flto=thin -Wl,--lto-O3 -Wl,--thinlto-jobs=3
%else
%global _lto_cflags -flto=thin
%global _lto_ldlags -flto=thin
%endif
%else
%global _lto_cflags %nil
%global _lto_ldlags %nil
%endif
%else
export CC=gcc
export CXX=g++
export UCFLAGS="${UCFLAGS} -ftree-parallelize-loops=4 -ftree-vectorize -fvect-cost-model=cheap -fsimd-cost-model=cheap -fpredictive-commoning"
export UCXXFLAGS="${UCFLAGS} -fpermissive"
export HOST="%{_target_platform}"
%if 0%{?use_lto}
%global _lto_cflags -fuse-linker-plugin %_lto_cflags -ffat-lto-objects -flto-odr-type-merging
%global _lto_ldlags -fuse-linker-plugin -flto=2
%else
%global _lto_cflags %nil
%global _lto_ldlags %nil
%endif
%endif
export TARGET="${HOST}"
export UCFLAGS="${UCFLAGS} %_lto_cflags"
export UCXXFLAGS="${UCXXFLAGS} %_lto_cflags"
export ULDFLAGS="${ULDFLAGS} %_lto_cflags %_lto_ldlags"
# override OBS defaults ?
export CFLAGS="${UCFLAGS}"
export CXXFLAGS="${UCXXFLAGS}"
export LDFLAGS="${ULDFLAGS}"

%define __builder ninja
# Support for AMD's "ROCm" seems to be unmaintained and broken
#  -DENABLE_HSA=ON \
#  -DWITH_HSA_RUNTIME_DIR=%{_prefix} \
#  -DWITH_HSA_RUNTIME_INCLUDE_DIR=%{_includedir}/hsa \
#  -DWITH_HSA_RUNTIME_LIB_DIR=%{_libdir} \
#  -DWITH_HSAILASM_PATH=%{_bindir}/HSAILasm \
#  -DHSAIL_ENABLED=0 \
# also unmaintained
#  -DENABLE_ACCEL_DEVICE=ON \
# And that, of course, requires Nvidia's dirty shims
#  -DENABLE_CUDA=1 \
# static linking to LLVM
# -DSINGLE_LLVM_LIB=ON \
# discouraged by upstream
#  -DUSE_POCL_MEMMANAGER=ON \
# not compatible with -DENABLE_VULKAN=ON and -DENABLE_ICD=ON
#  -DENABLE_PROXY_DEVICE=ON \
#  -DENABLE_PROXY_DEVICE_INTEROP=ON \
# but -DENABLE_VULKAN=ON needs Google's clspv
# broken now too
#  -DENABLE_LEVEL0=ON \

%cmake \
  -DSINGLE_LLVM_LIB=OFF \
  -DENABLE_CONFORMANCE=OFF \
  -DENABLE_TESTS=OFF \
  -DENABLE_EXAMPLES=OFF \
  -DENABLE_CUDA=OFF \
  -DCL_DISABLE_HALF=OFF \
  -DENABLE_SPIR=FORCE \
  -DENABLE_SPIRV=FORCE \
  -DENABLE_HOST_CPU_DEVICES=ON \
  -DENABLE_ALMAIF_DEVICE=OFF \
%ifarch x86_64
  -DENABLE_POCL_FLOAT_CONVERSION=ON \
  -DWITH_HSA_RUNTIME_DIR=%{_prefix} \
  -DWITH_HSA_RUNTIME_INCLUDE_DIR=%{_includedir}/hsa \
  -DWITH_HSA_RUNTIME_LIB_DIR=%{_libdir} \
  -DWITH_HSAILASM_PATH=%{_bindir}/HSAILasm \
%endif
  -DENABLE_ICD=ON \
  -DINSTALL_OPENCL_HEADERS=OFF \
  -DPOCL_INSTALL_ICD_VENDORDIR=%{_datadir}/OpenCL/vendors \
  -DEXTRA_KERNEL_C_FLAGS="${KCFLAGS}" \
  -DEXTRA_KERNEL_CXX_FLAGS="${KCXXFLAGS}" \
  -DCMAKE_EXE_LINKER_FLAGS="${ULDFLAGS}" \
  -DCMAKE_MODULE_LINKER_FLAGS="${ULDFLAGS}" \
  -DCMAKE_SHARED_LINKER_FLAGS="${ULDFLAGS}" \
%ifarch %{ix86} x86_64
  -DKERNELLIB_HOST_CPU_VARIANTS=distro \
%endif
%ifarch %{arm}
  -DLLC_HOST_CPU=cortex-a9 \
%endif
%ifarch aarch64
  -DLLC_HOST_CPU=cortex-a53 \
%endif
%ifarch riscv64
  -DLLC_HOST_CPU=generic-rv64 \
%endif
%if 0%{?suse_version} <= 1500 && 0%{?sle_version} <= 150300
  -DCMAKE_INSTALL_LIBDIR:PATH=%{_lib} \
%endif
  -DWITH_LLVM_CONFIG=%{_bindir}/llvm-config

%cmake_build

%install
%cmake_install

%post -n libpocl%{sover} -p /sbin/ldconfig
%postun -n libpocl%{sover} -p /sbin/ldconfig

%files
%doc CHANGES README.* doc/sphinx/source/*.rst
%license LICENSE
%dir %{_datadir}/OpenCL/
%dir %{_datadir}/OpenCL/vendors
%{_datadir}/OpenCL/vendors/pocl.icd
%{_bindir}/poclcc
%{_libdir}/pocl/
%{_datadir}/pocl/

%files -n libpocl%{sover}
%{_libdir}/libpocl.so.%{sover}*

%files devel
%{_libdir}/libpocl.so
%{_libdir}/pkgconfig/pocl.pc

%changelog
openSUSE Build Service is sponsored by