Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New auto-vectorization framework #342

Merged
merged 56 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
62aaafc
Update changelog.
bluescarni Aug 25, 2023
41819ad
Initial code/testing for the new auto-vectorization capabilities.
bluescarni Aug 25, 2023
fb7f206
Tentative fix for older LLVM versions.
bluescarni Aug 25, 2023
a34ddcd
Enable the new pass manager from LLVM 14.
bluescarni Aug 26, 2023
d0ff3d8
Add a couple of internal assertions.
bluescarni Aug 26, 2023
6598137
Internal doc.
bluescarni Aug 26, 2023
a293df2
Add more Windows builds, testing adjustments.
bluescarni Aug 27, 2023
c338d11
Testing additions.
bluescarni Aug 27, 2023
c051475
Add cos() and log().
bluescarni Aug 27, 2023
e93740e
exp() and sqrt().
bluescarni Aug 27, 2023
e268587
Try switching to mamba on the arm64 build.
bluescarni Aug 27, 2023
79d8643
Test fix for LLVM10.
bluescarni Aug 27, 2023
519f434
Tentative LLVM 10 fix.
bluescarni Aug 27, 2023
b43a097
pow().
bluescarni Aug 28, 2023
894625e
Coverage fixes.
bluescarni Aug 28, 2023
af50fda
Test fix.
bluescarni Aug 28, 2023
4193837
Test additions.
bluescarni Aug 28, 2023
4ba1557
Abstract away the generation of the attributes for math functions.
bluescarni Aug 28, 2023
4126f4c
Minor.
bluescarni Aug 29, 2023
f97d096
Ditto.
bluescarni Aug 30, 2023
73c9555
Re-use llvm_lookup_intrinsic() within llvm_invoke_intrinsic().
bluescarni Aug 30, 2023
2ac0063
Add a couple of assertions.
bluescarni Aug 30, 2023
9472e62
More minor internal bits.
bluescarni Aug 30, 2023
884d877
Abstract in separate function the invocation with vfabi variants.
bluescarni Aug 30, 2023
7937bd7
Yet another internal API tweak.
bluescarni Aug 30, 2023
15ee892
Fix warning.
bluescarni Aug 30, 2023
f435276
More WIP on the implementation.
bluescarni Aug 31, 2023
a5e672c
Enhance llvm_math_intr() to take advantage of vfabi autovec when the
bluescarni Aug 31, 2023
fe75b68
Internal renaming, testing.
bluescarni Aug 31, 2023
facab9a
Minor internal bits.
bluescarni Aug 31, 2023
7531440
Minor simplification.
bluescarni Aug 31, 2023
2ba8063
Test fix.
bluescarni Aug 31, 2023
449995d
Initial code/testing for llvm_math_cmath().
bluescarni Aug 31, 2023
139f4ff
Remove support for LLVM 10, bump version number.
bluescarni Aug 31, 2023
dc2a9ea
Tentative test fix.
bluescarni Aug 31, 2023
e0f8020
Attempt at fixing the static builds.
bluescarni Aug 31, 2023
7789292
Attempt at LLVM 16 Windows build.
bluescarni Aug 31, 2023
71fe4f4
Evolving the workaround.
bluescarni Aug 31, 2023
5e5f8aa
cosh, plus some internal docs.
bluescarni Aug 31, 2023
6aafc94
Try switching to VS2022 on the LLVM16 build.
bluescarni Aug 31, 2023
7c38c7a
asin, acos.
bluescarni Aug 31, 2023
8c2eb7d
Try with mamba.
bluescarni Aug 31, 2023
65069e7
asinh and acosh.
bluescarni Aug 31, 2023
12614af
Improve build system verbosity.
bluescarni Aug 31, 2023
a1ebe6b
More CI debug.
bluescarni Aug 31, 2023
00619f8
tan, tanh, atan, atanh.
bluescarni Aug 31, 2023
2ad5cdf
Trying random stuff.
bluescarni Aug 31, 2023
55c94b2
atan2 and erf.
bluescarni Aug 31, 2023
0b53088
Remove unused header.
bluescarni Aug 31, 2023
1677c38
Another merry go round.
bluescarni Aug 31, 2023
1e74589
sincos.
bluescarni Sep 1, 2023
25cbce7
Remove the unused llvm_modulus() function.
bluescarni Sep 1, 2023
8a8e593
Round of cleanups.
bluescarni Sep 1, 2023
80983c0
More cleanups.
bluescarni Sep 1, 2023
503a6b1
Warning fix.
bluescarni Sep 1, 2023
359d30d
Update changelog, small internal doc bit.
bluescarni Sep 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 47 additions & 9 deletions .github/workflows/gha_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- uses: actions/checkout@v3
- name: Build
run: bash tools/gha_osx_static.sh
windows_2019:
windows_2019_llvm12:
runs-on: windows-2019
steps:
- uses: actions/checkout@v3
Expand All @@ -28,13 +28,57 @@ jobs:
- uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
python-version: 3.8
python-version: "3.10"
channels: conda-forge
channel-priority: strict
- name: Build
shell: pwsh
run: |
conda install -y cmake 'llvmdev=14.*' tbb-devel tbb boost-cpp xtensor xtensor-blas blas blas-devel 'fmt=9.*' spdlog sleef zlib libzlib 'mppp>=0.27'
conda install -y cmake 'llvmdev=12.*' tbb-devel tbb boost-cpp xtensor xtensor-blas blas blas-devel fmt spdlog sleef zlib libzlib 'mppp>=0.27'
mkdir build
cd build
cmake ../ -G "Visual Studio 16 2019" -A x64 -DHEYOKA_BUILD_TESTS=yes -DHEYOKA_WITH_MPPP=yes -DHEYOKA_BUILD_TUTORIALS=ON -DHEYOKA_ENABLE_IPO=yes -DBoost_NO_BOOST_CMAKE=ON -DHEYOKA_WITH_SLEEF=yes -DMPPP_GMP_INCLUDE_DIR=C:\Miniconda\envs\test\Library\include -DMPPP_GMP_LIBRARY=C:\Miniconda\envs\test\Library\lib\mpir.lib
cmake --build . --config Release
copy Release\heyoka.dll test\Release\
ctest -j4 -V -C Release
windows_2019_llvm13:
runs-on: windows-2019
steps:
- uses: actions/checkout@v3
- name: Add msbuild to PATH
uses: microsoft/[email protected]
- uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
python-version: "3.10"
channels: conda-forge
channel-priority: strict
- name: Build
shell: pwsh
run: |
conda install -y cmake 'llvmdev=13.*' tbb-devel tbb boost-cpp xtensor xtensor-blas blas blas-devel fmt spdlog sleef zlib libzlib 'mppp>=0.27'
mkdir build
cd build
cmake ../ -G "Visual Studio 16 2019" -A x64 -DHEYOKA_BUILD_TESTS=yes -DHEYOKA_WITH_MPPP=yes -DHEYOKA_BUILD_TUTORIALS=ON -DHEYOKA_ENABLE_IPO=yes -DBoost_NO_BOOST_CMAKE=ON -DHEYOKA_WITH_SLEEF=yes -DMPPP_GMP_INCLUDE_DIR=C:\Miniconda\envs\test\Library\include -DMPPP_GMP_LIBRARY=C:\Miniconda\envs\test\Library\lib\mpir.lib
cmake --build . --config Release
copy Release\heyoka.dll test\Release\
ctest -j4 -V -C Release
windows_2019_llvm14:
runs-on: windows-2019
steps:
- uses: actions/checkout@v3
- name: Add msbuild to PATH
uses: microsoft/[email protected]
- uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
python-version: "3.10"
channels: conda-forge
channel-priority: strict
- name: Build
shell: pwsh
run: |
conda install -y cmake 'llvmdev=14.*' tbb-devel tbb boost-cpp xtensor xtensor-blas blas blas-devel fmt spdlog sleef zlib libzlib 'mppp>=0.27'
mkdir build
cd build
cmake ../ -G "Visual Studio 16 2019" -A x64 -DHEYOKA_BUILD_TESTS=yes -DHEYOKA_WITH_MPPP=yes -DHEYOKA_BUILD_TUTORIALS=ON -DHEYOKA_ENABLE_IPO=yes -DBoost_NO_BOOST_CMAKE=ON -DHEYOKA_WITH_SLEEF=yes -DMPPP_GMP_INCLUDE_DIR=C:\Miniconda\envs\test\Library\include -DMPPP_GMP_LIBRARY=C:\Miniconda\envs\test\Library\lib\mpir.lib
Expand Down Expand Up @@ -100,9 +144,3 @@ jobs:
- uses: actions/checkout@v3
- name: Build
run: bash tools/gha_llvm11_conda_asan.sh
conda_llvm10_asan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build
run: bash tools/gha_llvm10_conda_asan.sh
23 changes: 15 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if(NOT CMAKE_BUILD_TYPE)
FORCE)
endif()

project(heyoka VERSION 1.1.0 LANGUAGES CXX C)
project(heyoka VERSION 2.0.0 LANGUAGES CXX C)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/yacma")

Expand Down Expand Up @@ -143,13 +143,23 @@ if(YACMA_COMPILER_IS_MSVC)
endif()

# Mandatory dependency on LLVM.
#
# NOTE: do it early so that we can set up
# compiler flags based on the LLVM version
# if needed.
#
# NOTE: forcibly include GNUInstallDirs (even
# though we might have already included it
# earlier) in order to work around an apparent issue
# in Findzstd.cmake triggered by the LLVM config-file packages.
# See:
#
# https://github.com/llvm/llvm-project/issues/58558
include(GNUInstallDirs)
find_package(LLVM REQUIRED CONFIG)

if(${LLVM_VERSION_MAJOR} LESS 10)
message(FATAL_ERROR "LLVM >= 10 is required.")
if(${LLVM_VERSION_MAJOR} LESS 11)
message(FATAL_ERROR "LLVM >= 11 is required.")
endif()

# Mandatory dependency on fmt.
Expand All @@ -170,6 +180,7 @@ set(HEYOKA_SRC_FILES
"${CMAKE_CURRENT_SOURCE_DIR}/src/detail/sum_sq.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/detail/div.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/detail/sub.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/detail/vector_math.cpp"
# NOTE: this will be an empty file in case we are not
# building with support for real.
"${CMAKE_CURRENT_SOURCE_DIR}/src/detail/real_helpers.cpp"
Expand Down Expand Up @@ -275,13 +286,9 @@ set(HEYOKA_SRC_FILES
"${CMAKE_CURRENT_SOURCE_DIR}/src/math/prod.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/math/constants.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/detail/string_conv.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/detail/math_wrappers.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/detail/logging_impl.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/step_callback.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/llvm_state_mem_cache.cpp"
# NOTE: sleef.cpp needs to be compiled even if we are not
# building with sleef support on.
"${CMAKE_CURRENT_SOURCE_DIR}/src/detail/sleef.cpp"
)

if(HEYOKA_WITH_SLEEF)
Expand Down Expand Up @@ -476,7 +483,7 @@ set(_HEYOKA_MIN_MPPP_VERSION "0.27")
if(HEYOKA_WITH_MPPP)
find_package(mp++ REQUIRED CONFIG)
if(${mp++_VERSION} VERSION_LESS ${_HEYOKA_MIN_MPPP_VERSION})
message(FATAL_ERROR "mp++ >= ${_HEYOKA_MIN_MPPP_VERSION} is required.")
message(FATAL_ERROR "mp++ >= ${_HEYOKA_MIN_MPPP_VERSION} is required, but version ${mp++_VERSION} was found instead.")
endif()

# NOTE: this is necessary for the serialisation of several classes.
Expand Down
8 changes: 8 additions & 0 deletions doc/breaking_changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
Breaking changes
================

.. _bchanges_2_0_0:

2.0.0
-----

- The minimum supported LLVM version has been bumped
from 10 to 11.

.. _bchanges_1_0_0:

1.0.0
Expand Down
11 changes: 10 additions & 1 deletion doc/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
Changelog
=========

1.1.0 (unreleased)
2.0.0 (unreleased)
------------------

New
~~~

- heyoka can now automatically vectorise scalar calls to
floating-point math functions
(`#342 <https://github.com/bluescarni/heyoka/pull/342>`__).
- Implement an in-memory cache for ``llvm_state``. The cache is used
to avoid re-optimising and re-compiling LLVM code which has
already been optimised and compiled during the program execution
Expand All @@ -18,6 +21,12 @@ New
Changes
~~~~~~~

- **BREAKING**: the minimum supported LLVM version is now 11
(`#342 <https://github.com/bluescarni/heyoka/pull/342>`__).
This is a :ref:`breaking change <bchanges_2_0_0>`.
- The LLVM SLP vectorizer is now enabled when JIT compiling
with optimisations
(`#341 <https://github.com/bluescarni/heyoka/pull/341>`__).
- The optimisation level for an ``llvm_state`` is now clamped
within the ``[0, 3]`` range
(`#340 <https://github.com/bluescarni/heyoka/pull/340>`__).
Expand Down
2 changes: 1 addition & 1 deletion doc/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The tested and supported CPU architectures at this time are x86-64,

heyoka has the following **mandatory** dependencies:

* the `LLVM <https://llvm.org/>`__ compiler infrastructure library (version >= 10),
* the `LLVM <https://llvm.org/>`__ compiler infrastructure library (version >= 11),
* the `Boost <https://www.boost.org/>`__ C++ libraries (version >= 1.69),
* the `{fmt} <https://fmt.dev/latest/index.html>`__ library,
* the `spdlog <https://github.com/gabime/spdlog>`__ library,
Expand Down
3 changes: 0 additions & 3 deletions include/heyoka/detail/llvm_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ HEYOKA_DLL_PUBLIC std::string llvm_type_name(llvm::Type *);

HEYOKA_DLL_PUBLIC bool compare_function_signature(llvm::Function *, llvm::Type *, const std::vector<llvm::Type *> &);

HEYOKA_DLL_PUBLIC llvm::Value *call_extern_vec(llvm_state &, const std::vector<llvm::Value *> &, const std::string &);

void llvm_append_block(llvm::Function *, llvm::BasicBlock *);

// Math helpers.
Expand All @@ -141,7 +139,6 @@ HEYOKA_DLL_PUBLIC llvm::Value *llvm_sgn(llvm_state &, llvm::Value *);

HEYOKA_DLL_PUBLIC llvm::Value *llvm_ui_to_fp(llvm_state &, llvm::Value *, llvm::Type *);

HEYOKA_DLL_PUBLIC llvm::Value *llvm_modulus(llvm_state &, llvm::Value *, llvm::Value *);
HEYOKA_DLL_PUBLIC llvm::Value *llvm_abs(llvm_state &, llvm::Value *);
HEYOKA_DLL_PUBLIC llvm::Value *llvm_floor(llvm_state &, llvm::Value *);

Expand Down
13 changes: 2 additions & 11 deletions include/heyoka/detail/llvm_vector_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#ifndef HEYOKA_DETAIL_LLVM_VECTOR_TYPE_HPP
#define HEYOKA_DETAIL_LLVM_VECTOR_TYPE_HPP

#include <llvm/Config/llvm-config.h>
#include <llvm/IR/DerivedTypes.h>

#include <heyoka/config.hpp>
Expand All @@ -21,16 +20,8 @@ namespace detail

// NOTE: this is a convenience typedef for the LLVM
// vector type used internally by heyoka. It is a vector
// whose size is fixed at compile time. In LLVM 10 we have
// to use the generic VectorType class, from LLVM 11 onwards
// there is a more specialised class.
using llvm_vector_type =
#if LLVM_VERSION_MAJOR == 10
llvm::VectorType
#else
llvm::FixedVectorType
#endif
;
// whose size is fixed at compile time.
using llvm_vector_type = llvm::FixedVectorType;

} // namespace detail

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,34 @@
// Public License v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

#ifndef HEYOKA_DETAIL_SLEEF_HPP
#define HEYOKA_DETAIL_SLEEF_HPP
#ifndef HEYOKA_DETAIL_VECTOR_MATH_HPP
#define HEYOKA_DETAIL_VECTOR_MATH_HPP

#include <cstdint>
#include <string>
#include <vector>

#include <heyoka/config.hpp>
#include <heyoka/detail/llvm_fwd.hpp>
#include <heyoka/detail/visibility.hpp>

HEYOKA_BEGIN_NAMESPACE

namespace detail
{

HEYOKA_DLL_PUBLIC std::string sleef_function_name(llvm::LLVMContext &, const std::string &, llvm::Type *,
std::uint32_t);
struct vf_info {
// The name of the vector function
// to be invoked (e.g., from SLEEF).
std::string name;
// The vfabi attribute corresponding
// to the vector function.
std::string vf_abi_attr;
// Number of SIMD lanes.
std::uint32_t width = 0;
// Number of arguments.
std::uint32_t nargs = 0;
};

const std::vector<vf_info> &lookup_vf_info(const std::string &);

} // namespace detail

Expand Down
4 changes: 1 addition & 3 deletions include/heyoka/llvm_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ struct target_features {
#endif
};

// NOTE: no need to make this DLL-public as long
// as this is used only in library code.
const target_features &get_target_features();
HEYOKA_DLL_PUBLIC const target_features &get_target_features();

} // namespace detail

Expand Down
Loading