Skip to content

Commit

Permalink
Merge pull request #342 from bluescarni/pr/math_vec
Browse files Browse the repository at this point in the history
New auto-vectorization framework
  • Loading branch information
bluescarni authored Sep 1, 2023
2 parents 0e7d086 + 359d30d commit e59e24e
Show file tree
Hide file tree
Showing 41 changed files with 2,345 additions and 1,947 deletions.
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

0 comments on commit e59e24e

Please sign in to comment.