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

ref: Adapt to client interface and allow to compile multiple plugins side by side #133

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,10 @@ endif()

# Set up the Algebra Plugin libraries.
add_subdirectory( common )
add_subdirectory( storage )
add_subdirectory( math )
add_subdirectory( frontend )
add_subdirectory( math )
add_subdirectory( storage )
add_subdirectory( utils )

# Set up the test(s).
if( BUILD_TESTING AND ALGEBRA_PLUGINS_BUILD_TESTING )
Expand Down
4 changes: 3 additions & 1 deletion benchmarks/array/include/benchmark/array/data_generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ inline void fill_random_trf(std::vector<transform3_t> &collection) {
1.f);

auto rand_obj = [&]() {
vector_t x_axis, z_axis, t;
vector_t x_axis;
vector_t z_axis;
vector_t t;

x_axis = vector::normalize(vector_t{dist(mt), dist(mt), dist(mt)});
z_axis = {dist(mt), dist(mt), dist(mt)};
Expand Down
20 changes: 9 additions & 11 deletions benchmarks/common/include/benchmark/common/benchmark_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,15 @@ struct benchmark_base {
/// @}

/// Print configuration
friend std::ostream& operator<<(std::ostream& os, const configuration& c);
friend std::ostream& operator<<(std::ostream& os,
const benchmark_base::configuration& cfg) {
os << " -> running:\t " << cfg.n_samples() << " samples" << std::endl;
if (cfg.do_sleep()) {
os << " -> cool down:\t " << cfg.n_sleep() << "s" << std::endl;
}
os << std::endl;
return os;
}
};

/// The benchmark configuration
Expand All @@ -77,14 +85,4 @@ struct benchmark_base {
virtual void operator()(::benchmark::State&) = 0;
};

std::ostream& operator<<(std::ostream& os,
const benchmark_base::configuration& cfg) {
os << " -> running:\t " << cfg.n_samples() << " samples" << std::endl;
if (cfg.do_sleep()) {
os << " -> cool down:\t " << cfg.n_sleep() << "s" << std::endl;
}
os << std::endl;
return os;
}

} // namespace algebra
12 changes: 7 additions & 5 deletions benchmarks/common/include/benchmark/common/benchmark_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ struct vector_bm : public benchmark_base {
/// Prefix for the benchmark name
inline static const std::string name{"vector"};

std::vector<vector_t> a, b, results;
std::vector<vector_t> a;
std::vector<vector_t> b;
std::vector<vector_t> results;

/// No default construction: Cannot prepare data
vector_bm() = delete;
Expand Down Expand Up @@ -82,8 +84,8 @@ requires std::invocable<unaryOP, vector_t<scalar_t>> struct vector_unaryOP_bm
// Run the benchmark
for (auto _ : state) {
for (std::size_t i{0}; i < n_samples; ++i) {
result_t result = unaryOP{}(this->a[i]);
::benchmark::DoNotOptimize(const_cast<const result_t &>(result));
const result_t result = unaryOP{}(this->a[i]);
::benchmark::DoNotOptimize(result);
}
}
}
Expand Down Expand Up @@ -117,8 +119,8 @@ requires std::invocable<binaryOP, vector_t<scalar_t>,
// Run the benchmark
for (auto _ : state) {
for (std::size_t i{0}; i < n_samples; ++i) {
result_t result = binaryOP{}(this->a[i], this->b[i]);
::benchmark::DoNotOptimize(const_cast<const result_t &>(result));
const result_t result = binaryOP{}(this->a[i], this->b[i]);
::benchmark::DoNotOptimize(result);
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion benchmarks/eigen/include/benchmark/eigen/data_generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ inline void fill_random_trf(std::vector<transform3_t> &collection) {
using vector_t = typename transform3_t::vector3;

auto rand_obj = []() {
vector_t x_axis, z_axis, t;
vector_t x_axis;
vector_t z_axis;
vector_t t;

x_axis = vector::normalize(vector_t::Random());
z_axis = vector_t::Random();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ inline void fill_random_trf(std::vector<transform3_t> &collection) {
// Generate a random, but valid affine transformation
auto rand_obj = []() {
using vector_t = typename transform3_t::vector3;
vector_t x_axis, z_axis, t;
vector_t x_axis;
vector_t z_axis;
vector_t t;

x_axis = vector_t{vector_t::array_type::Random()};
x_axis = vector::normalize(x_axis);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,13 @@ template <concepts::transform3D transform3_t>
inline void fill_random_trf(std::vector<transform3_t> &collection) {
// Generate a random, but valid affine transformation
auto rand_obj = []() {
using vector_t = typename transform3_t::vector3;
using simd_vector_t = typename transform3_t::scalar_type;
typename transform3_t::vector3 x_axis, z_axis, t;

vector_t x_axis;
vector_t z_axis;
vector_t t;

x_axis[0] = simd_vector_t::Random();
x_axis[1] = simd_vector_t::Random();
x_axis[2] = simd_vector_t::Random();
Expand Down
22 changes: 11 additions & 11 deletions benchmarks/vc_soa/vc_soa_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,6 @@ int main(int argc, char** argv) {
//
// Register all benchmarks
//
algebra::register_benchmark<phi_f_t>(cfg_s, "_single");
algebra::register_benchmark<phi_d_t>(cfg_d, "_double");
algebra::register_benchmark<theta_f_t>(cfg_s, "_single");
algebra::register_benchmark<theta_d_t>(cfg_d, "_double");
algebra::register_benchmark<perp_f_t>(cfg_s, "_single");
algebra::register_benchmark<perp_d_t>(cfg_d, "_double");
algebra::register_benchmark<norm_f_t>(cfg_s, "_single");
algebra::register_benchmark<norm_d_t>(cfg_d, "_double");
algebra::register_benchmark<eta_f_t>(cfg_s, "_single");
algebra::register_benchmark<eta_d_t>(cfg_d, "_double");

algebra::register_benchmark<add_f_t>(cfg_s, "_single");
algebra::register_benchmark<add_d_t>(cfg_d, "_double");
algebra::register_benchmark<sub_f_t>(cfg_s, "_single");
Expand All @@ -92,6 +81,17 @@ int main(int argc, char** argv) {
algebra::register_benchmark<normlz_f_t>(cfg_s, "_single");
algebra::register_benchmark<normlz_d_t>(cfg_d, "_double");

algebra::register_benchmark<phi_f_t>(cfg_s, "_single");
algebra::register_benchmark<phi_d_t>(cfg_d, "_double");
algebra::register_benchmark<theta_f_t>(cfg_s, "_single");
algebra::register_benchmark<theta_d_t>(cfg_d, "_double");
algebra::register_benchmark<perp_f_t>(cfg_s, "_single");
algebra::register_benchmark<perp_d_t>(cfg_d, "_double");
algebra::register_benchmark<norm_f_t>(cfg_s, "_single");
algebra::register_benchmark<norm_d_t>(cfg_d, "_double");
algebra::register_benchmark<eta_f_t>(cfg_s, "_single");
algebra::register_benchmark<eta_d_t>(cfg_d, "_double");

::benchmark::Initialize(&argc, argv);
::benchmark::RunSpecifiedBenchmarks();
::benchmark::Shutdown();
Expand Down
27 changes: 26 additions & 1 deletion common/include/algebra/concepts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@

namespace algebra::concepts {

/// Arithmetic types
template <typename T>
concept arithmetic = std::is_arithmetic_v<T>;

// Value concept: Single entry
template <typename T>
concept value = std::is_arithmetic_v<std::decay_t<T>>;
concept value = algebra::concepts::arithmetic<std::decay_t<T>>;

/// Scalar concept: Elements of vectors/matrices (can be simd vectors)
template <typename T>
Expand Down Expand Up @@ -104,4 +108,25 @@ concept transform3D = requires(T trf) {
trf.vector_to_local(typename T::vector3());
};

/// Algebra plugin concept
template <typename A>
concept algebra = (concepts::value<typename A::value_type> &&
concepts::scalar<typename A::scalar> &&
concepts::index<typename A::size_type> &&
concepts::simd_scalar<typename A::template simd<float>> &&
concepts::vector3D<typename A::vector3D> &&
concepts::point2D<typename A::point2D> &&
concepts::point3D<typename A::point3D> &&
concepts::transform3D<typename A::transform3D> &&
concepts::matrix<typename A::template matrix<3, 3>>);

/// Check if an algebra has soa layout
/// @{
template <typename A>
concept soa = (!concepts::arithmetic<algebra::get_scalar_t<A>>);

template <typename A>
concept aos = (!concepts::soa<A>);
/// @}

} // namespace algebra::concepts
60 changes: 58 additions & 2 deletions common/include/algebra/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
#include <cmath>
#include <type_traits>

namespace algebra::traits {
namespace algebra {

namespace traits {

/// Matrix traits
/// @{
Expand Down Expand Up @@ -129,7 +131,61 @@ template <class M>
using block_getter_t = typename block_getter<M>::type;
/// @}

} // namespace algebra::traits
/// The algebra types
/// @{
template <typename T>
struct get_algebra {};

template <typename T>
requires(!std::is_same_v<typename T::point3D, void>) struct get_algebra<T> {
niermann999 marked this conversation as resolved.
Show resolved Hide resolved
template <typename U>
using simd = typename T::template simd<U>;
using size_type = typename T::size_type;
using boolean = typename T::boolean;
using value = typename T::value_type;
using scalar = typename T::scalar;
using point2D = typename T::point2D;
using point3D = typename T::point3D;
using vector3D = typename T::vector3D;
using transform3D = typename T::transform3D;
template <std::size_t ROWS, std::size_t COLS>
using matrix = typename T::template matrix<ROWS, COLS>;
};

} // namespace traits

template <typename A>
using get_value_t = typename traits::get_algebra<A>::value;
niermann999 marked this conversation as resolved.
Show resolved Hide resolved

template <typename A>
using get_boolean_t = typename traits::get_algebra<A>::boolean;

template <typename A, typename T>
using get_simd_t = typename traits::get_algebra<A>::template simd<T>;

template <typename A>
using get_size_t = typename traits::get_algebra<A>::size_type;

template <typename A>
using get_scalar_t = typename traits::get_algebra<A>::scalar;

template <typename A>
using get_point2D_t = typename traits::get_algebra<A>::point2D;

template <typename A>
using get_point3D_t = typename traits::get_algebra<A>::point3D;

template <typename A>
using get_vector3D_t = typename traits::get_algebra<A>::vector3D;

template <typename A>
using get_transform3D_t = typename traits::get_algebra<A>::transform3D;

template <typename A, std::size_t R, std::size_t C>
using get_matrix_t = typename traits::get_algebra<A>::template matrix<R, C>;
/// @}

} // namespace algebra

/// Default type trait specializations
/// @{
Expand Down
46 changes: 37 additions & 9 deletions frontend/array_cmath/include/algebra/array_cmath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ using cmath::dot;
using cmath::normalize;

// generic implementations
using generic::math::cross;
using generic::math::eta;
using generic::math::norm;
using generic::math::perp;
using generic::math::phi;
using generic::math::theta;
using cmath::cross;
using cmath::eta;
using cmath::norm;
using cmath::perp;
using cmath::phi;
using cmath::theta;

/// @}

Expand Down Expand Up @@ -88,9 +88,10 @@ using cmath::set_identity;
using cmath::set_zero;
using cmath::zero;

using generic::math::determinant;
using generic::math::inverse;
using generic::math::transpose;
// Uses generic implementation in the background
using cmath::determinant;
using cmath::inverse;
using cmath::transpose;

/// @}

Expand All @@ -110,4 +111,31 @@ using transform3 =

} // namespace array

namespace plugin {

/// Define the plugin types
/// @{
template <concepts::value V>
struct array {
/// Define scalar type
using value_type = V;

template <concepts::value T>
using simd = T;

using boolean = bool;
using scalar = value_type;
using size_type = algebra::array::size_type;
using transform3D = algebra::array::transform3<value_type>;
using point2D = algebra::array::point2<value_type>;
using point3D = algebra::array::point3<value_type>;
using vector3D = algebra::array::vector3<value_type>;

template <std::size_t ROWS, std::size_t COLS>
using matrix = algebra::array::matrix_type<value_type, ROWS, COLS>;
};
/// @}

} // namespace plugin

} // namespace algebra
4 changes: 2 additions & 2 deletions frontend/eigen_eigen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
algebra_add_library( algebra_eigen_eigen eigen_eigen
"include/algebra/eigen_eigen.hpp" )
target_link_libraries( algebra_eigen_eigen
INTERFACE algebra::common algebra::eigen_storage algebra::generic_math
algebra::eigen_math Eigen3::Eigen )
INTERFACE algebra::common algebra::eigen_storage algebra::eigen_math
Eigen3::Eigen )
algebra_test_public_headers( algebra_eigen_eigen
"algebra/eigen_eigen.hpp" )
Loading