Skip to content

Commit

Permalink
Added Fastor as a full backend and frontend. (#78)
Browse files Browse the repository at this point in the history
This adds the fastor plugin
  • Loading branch information
wermos authored Mar 15, 2023
1 parent 5662e8b commit c4e5aa4
Show file tree
Hide file tree
Showing 28 changed files with 1,114 additions and 30 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ jobs:
-DALGEBRA_PLUGINS_INCLUDE_VECMEM=TRUE
-DALGEBRA_PLUGINS_SETUP_VECMEM=TRUE
-DALGEBRA_PLUGINS_USE_SYSTEM_VECMEM=FALSE
-DALGEBRA_PLUGINS_INCLUDE_FASTOR=TRUE
-DALGEBRA_PLUGINS_SETUP_FASTOR=TRUE
-DALGEBRA_PLUGINS_USE_SYSTEM_FASTOR=FALSE
-S ${{ github.workspace }} -B build
-G "${{ matrix.PLATFORM.GENERATOR }}"
# Perform the build.
Expand Down
34 changes: 27 additions & 7 deletions extern/fastor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,36 @@ message( STATUS "Building Fastor as part of the Algebra Plugins project" )
# We need to use this alternative syntax for FetchContent_Declare because the
# latest release for Fastor does not have a CMakeLists.txt file.
set( ALGEBRA_PLUGINS_FASTOR_SOURCE
"fastor;GIT_REPOSITORY;https://github.com/romeric/Fastor.git;GIT_TAG;6d7216f304d60d92b9b042566d4d6e94c65086a3"
"fastor;GIT_REPOSITORY;https://github.com/romeric/Fastor.git;GIT_TAG;e96e63fe8a05898d732d0b9faba3667d9a25a38f"
CACHE STRING "Source for Fastor, when built as part of this project" )
mark_as_advanced( ALGEBRA_PLUGINS_FASTOR_SOURCE )
FetchContent_Declare( fastor ${ALGEBRA_PLUGINS_FASTOR_SOURCE} )

# Options used in the build of Fastor.
set(BUILD_TESTING OFF CACHE BOOL "Don't build the Fastor tests")
add_compile_definitions(FASTOR_ENABLE_RUNTIME_CHECKS=0)
# Turn off the unit tests for Fastor.
if( DEFINED CACHE{BUILD_TESTING} )
set( _buildTestingValue ${BUILD_TESTING} )
endif()
set( BUILD_TESTING FALSE CACHE INTERNAL "Forceful setting of BUILD_TESTING" )

# Get it into the current directory.
FetchContent_Populate( fastor )
add_subdirectory( "${fastor_SOURCE_DIR}" "${fastor_BINARY_DIR}"
EXCLUDE_FROM_ALL )
FetchContent_MakeAvailable( fastor )

# Reset the BUILD_TESTING variable.
if( DEFINED _buildTestingValue )
set( BUILD_TESTING ${_buildTestingValue} CACHE BOOL "Turn tests on/off"
FORCE )
unset( _buildTestingValue )
else()
unset( BUILD_TESTING CACHE )
endif()

# Treat the Fastor headers as "system headers", to avoid getting warnings from
# them.
get_target_property( _incDirs Fastor INTERFACE_INCLUDE_DIRECTORIES )
target_include_directories( Fastor
SYSTEM INTERFACE ${_incDirs} )
unset( _incDirs )

# Set up an alias for the Fastor target, with the same name that it will have
# when "finding it".
add_library( Fastor::Fastor ALIAS Fastor )
4 changes: 4 additions & 0 deletions frontend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ if( ALGEBRA_PLUGINS_INCLUDE_VC )
add_subdirectory( vc_vc )
endif()

if( ALGEBRA_PLUGINS_INCLUDE_FASTOR )
add_subdirectory( fastor_fastor )
endif()

if( ALGEBRA_PLUGINS_INCLUDE_VECMEM )
add_subdirectory( vecmem_cmath )
endif()
12 changes: 12 additions & 0 deletions frontend/fastor_fastor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Algebra plugins library, part of the ACTS project (R&D line)
#
# (c) 2022 CERN for the benefit of the ACTS project
#
# Mozilla Public License Version 2.0

# Set up the library.
algebra_add_library( algebra_fastor_fastor fastor_fastor
"include/algebra/fastor_fastor.hpp" )
target_link_libraries( algebra_fastor_fastor
INTERFACE algebra::common algebra::fastor_storage algebra::cmath_math
algebra::fastor_math )
86 changes: 86 additions & 0 deletions frontend/fastor_fastor/include/algebra/fastor_fastor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/** Algebra plugins library, part of the ACTS project
*
* (c) 2022 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

// Project include(s).
#include "algebra/math/cmath.hpp"
#include "algebra/math/fastor.hpp"
#include "algebra/storage/fastor.hpp"

// Fastor include(s).
#ifdef _MSC_VER
#pragma warning(disable : 4244 4701 4702)
#endif // MSVC
#include <Fastor/Fastor.h>
#ifdef _MSC_VER
#pragma warning(default : 4244 4701 4702)
#endif // MSVC

namespace algebra {

namespace getter {

/// @name Getter functions on @c algebra::fastor::storage_type
/// @{

using fastor::math::eta;
using fastor::math::norm;
using fastor::math::perp;
using fastor::math::phi;
using fastor::math::theta;

/// @}

/// Function extracting a slice from the matrix used by
/// @c algebra::fastor::transform3
template <std::size_t SIZE, std::size_t ROWS, std::size_t COLS,
typename scalar_t>
ALGEBRA_HOST_DEVICE inline auto vector(
const Fastor::Tensor<scalar_t, ROWS, COLS>& m, std::size_t row,
std::size_t col) {

return fastor::storage_type<scalar_t, SIZE>(
m(Fastor::seq(static_cast<int>(row), static_cast<int>(row + SIZE)),
static_cast<int>(col)));
}

/// @name Getter functions on @c algebra::fastor::matrix_type
/// @{

using fastor::math::element;

/// @}

} // namespace getter

namespace vector {

/// @name Vector functions on @c algebra::fastor::storage_type
/// @{

using fastor::math::cross;
using fastor::math::dot;
using fastor::math::normalize;

/// @}

} // namespace vector

namespace matrix {

template <typename scalar_t>
using actor = fastor::matrix::actor<scalar_t>;

} // namespace matrix

namespace fastor {

template <typename T>
using transform3 = math::transform3<T, matrix::actor<T>>;

} // namespace fastor

} // namespace algebra
3 changes: 3 additions & 0 deletions math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ add_subdirectory( cmath )
if( ALGEBRA_PLUGINS_INCLUDE_EIGEN )
add_subdirectory( eigen )
endif()
if( ALGEBRA_PLUGINS_INCLUDE_FASTOR )
add_subdirectory( fastor )
endif()
if( ALGEBRA_PLUGINS_INCLUDE_SMATRIX )
add_subdirectory( smatrix )
endif()
Expand Down
2 changes: 1 addition & 1 deletion math/cmath/include/algebra/math/impl/cmath_getter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ ALGEBRA_HOST_DEVICE inline scalar_t theta(
v[2]);
}

/** This method retrieves the perpenticular magnitude of a vector with rows >= 2
/** This method retrieves the perpendicular magnitude of a vector with rows >= 2
*
* @param v the input vector
**/
Expand Down
4 changes: 2 additions & 2 deletions math/eigen/include/algebra/math/impl/eigen_getter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ ALGEBRA_HOST_DEVICE inline auto theta(
v[2]);
}

/** This method retrieves the perpenticular magnitude of a vector with rows >= 2
/** This method retrieves the perpendicular magnitude of a vector with rows >= 2
*
* @param v the input vector
**/
Expand All @@ -79,7 +79,7 @@ ALGEBRA_HOST_DEVICE inline auto norm(const Eigen::MatrixBase<derived_type> &v) {
}

/** This method retrieves the pseudo-rapidity from a vector or vector base with
*rows >= 3
* rows >= 3
*
* @param v the input vector
**/
Expand Down
8 changes: 4 additions & 4 deletions math/eigen/include/algebra/math/impl/eigen_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ ALGEBRA_HOST_DEVICE inline auto normalize(

/** Dot product between two input vectors
*
* @tparam derived_type_lhs is the first matrix (epresseion) template
* @tparam derived_type_rhs is the second matrix (epresseion) template
* @tparam derived_type_lhs is the first matrix (expression) template
* @tparam derived_type_rhs is the second matrix (expression) template
*
* @param a the first input vector
* @param b the second input vector
Expand All @@ -52,8 +52,8 @@ ALGEBRA_HOST_DEVICE inline auto dot(

/** Cross product between two input vectors
*
* @tparam derived_type_lhs is the first matrix (epresseion) template
* @tparam derived_type_rhs is the second matrix (epresseion) template
* @tparam derived_type_lhs is the first matrix (expression) template
* @tparam derived_type_rhs is the second matrix (expression) template
*
* @param a the first input vector
* @param b the second input vector
Expand Down
17 changes: 17 additions & 0 deletions math/fastor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Algebra plugins library, part of the ACTS project (R&D line)
#
# (c) 2022 CERN for the benefit of the ACTS project
#
# Mozilla Public License Version 2.0

# Set up the library.
algebra_add_library(algebra_fastor_math fastor_math
"include/algebra/math/fastor.hpp"
"include/algebra/math/impl/fastor_getter.hpp"
"include/algebra/math/impl/fastor_matrix.hpp"
"include/algebra/math/impl/fastor_transform3.hpp"
"include/algebra/math/impl/fastor_vector.hpp")

target_link_libraries(algebra_fastor_math
INTERFACE algebra::common algebra::common_math Fastor::Fastor )

14 changes: 14 additions & 0 deletions math/fastor/include/algebra/math/fastor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/** Algebra plugins library, part of the ACTS project
*
* (c) 2020-2022 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

#pragma once

// Project include(s).
#include "algebra/math/impl/fastor_getter.hpp"
#include "algebra/math/impl/fastor_matrix.hpp"
#include "algebra/math/impl/fastor_transform3.hpp"
#include "algebra/math/impl/fastor_vector.hpp"
Loading

0 comments on commit c4e5aa4

Please sign in to comment.