Skip to content

Commit

Permalink
split benchmark flag
Browse files Browse the repository at this point in the history
  • Loading branch information
icui committed Feb 7, 2025
1 parent 5afdb1d commit e50d8b5
Show file tree
Hide file tree
Showing 3 changed files with 452 additions and 197 deletions.
14 changes: 11 additions & 3 deletions benchmarks/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "execute.hpp"
#include "stiffness.hpp"
#include "stiffness2.hpp"
// #include "divide.hpp"

namespace specfem {
Expand All @@ -18,9 +19,16 @@ void benchmark(specfem::compute::assembly &assembly,
const auto solver_start_time = std::chrono::system_clock::now();

for (const auto [istep, dt] : time_scheme->iterate_forward()) {
compute_stiffness_interaction<acoustic, isotropic, flag>(assembly, istep);
compute_stiffness_interaction<elastic, isotropic, flag>(assembly, istep);
compute_stiffness_interaction<elastic, anisotropic, flag>(assembly, istep);
if constexpr (flag) {
compute_stiffness_interaction<acoustic, isotropic>(assembly, istep);
compute_stiffness_interaction<elastic, isotropic>(assembly, istep);
compute_stiffness_interaction<elastic, anisotropic>(assembly, istep);
} else {
compute_stiffness_interaction2<acoustic, isotropic>(assembly, istep);
compute_stiffness_interaction2<elastic, isotropic>(assembly, istep);
compute_stiffness_interaction2<elastic, anisotropic>(assembly, istep);
}

// divide_mass_matrix<dimension, wavefield, acoustic>(assembly);
// divide_mass_matrix<dimension, wavefield, elastic>(assembly);

Expand Down
205 changes: 11 additions & 194 deletions benchmarks/stiffness.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ constexpr static auto ngll = 5;
constexpr static auto boundary_tag = specfem::element::boundary_tag::none;

template <specfem::element::medium_tag MediumTag,
specfem::element::property_tag PropertyTag, bool flag>
specfem::element::property_tag PropertyTag>
void compute_stiffness_interaction(const specfem::compute::assembly &assembly,
const int &istep) {

Expand Down Expand Up @@ -114,20 +114,8 @@ void compute_stiffness_interaction(const specfem::compute::assembly &assembly,
ElementQuadratureType element_quadrature(team);
ChunkStressIntegrandType stress_integrand(team);

if constexpr (flag) {
specfem::benchmarks::load_quadrature(team, quadrature,
element_quadrature);
} else {
Kokkos::parallel_for(
Kokkos::TeamThreadRange(team, ngll * ngll), [&](const int &xz) {
int ix, iz;
sub2ind(xz, ngll, iz, ix);
element_quadrature.hprime_gll(iz, ix) =
quadrature.gll.hprime(iz, ix);
element_quadrature.hprime_wgll(ix, iz) =
quadrature.gll.hprime(iz, ix) * quadrature.gll.weights(iz);
});
}
specfem::benchmarks::load_quadrature(team, quadrature,
element_quadrature);

for (int tile = 0; tile < ChunkPolicyType::tile_size * simd_size;
tile += ChunkPolicyType::chunk_size * simd_size) {
Expand All @@ -141,50 +129,8 @@ void compute_stiffness_interaction(const specfem::compute::assembly &assembly,

const auto iterator =
chunk_policy.league_iterator(starting_element_index);
if constexpr (flag) {
specfem::benchmarks::load_wavefield(team, iterator, field,
element_field);
} else {
const auto &curr_field =
[&]() -> const specfem::compute::impl::field_impl<
specfem::dimension::type::dim2, MediumTag> & {
if constexpr (MediumTag ==
specfem::element::medium_tag::elastic) {
return field.elastic;
} else if constexpr (MediumTag ==
specfem::element::medium_tag::acoustic) {
return field.acoustic;
} else {
static_assert("medium type not supported");
}
}();

Kokkos::parallel_for(
Kokkos::TeamThreadRange(team, iterator.chunk_size()),
[&](const int &i) {
const auto iterator_index = iterator(i);
const int ielement = iterator_index.ielement;
const int ispec = iterator_index.index.ispec;
const int iz = iterator_index.index.iz;
const int ix = iterator_index.index.ix;

for (int lane = 0; lane < simd::size(); ++lane) {
if (!iterator_index.index.mask(lane)) {
continue;
}

const int iglob = field.assembly_index_mapping(
field.index_mapping(ispec + lane, iz, ix),
static_cast<int>(MediumTag));

for (int icomp = 0; icomp < components; ++icomp) {
element_field.displacement(ielement, iz, ix,
icomp)[lane] =
curr_field.field(iglob, icomp);
}
}
});
}
specfem::benchmarks::load_wavefield(team, iterator, field,
element_field);

team.team_barrier();

Expand Down Expand Up @@ -216,31 +162,8 @@ void compute_stiffness_interaction(const specfem::compute::assembly &assembly,
using_simd>
point_partial_derivatives;

if constexpr (flag) {
specfem::benchmarks::load_partial_derivative(
index, partial_derivatives, point_partial_derivatives);
} else {
const int ispec = index.ispec;
mask_type mask(
[&](std::size_t lane) { return index.mask(lane); });

Kokkos::Experimental::where(mask,
point_partial_derivatives.xix)
.copy_from(&partial_derivatives.xix(ispec, iz, ix),
tag_type());
Kokkos::Experimental::where(mask,
point_partial_derivatives.gammax)
.copy_from(&partial_derivatives.gammax(ispec, iz, ix),
tag_type());
Kokkos::Experimental::where(mask,
point_partial_derivatives.xiz)
.copy_from(&partial_derivatives.xiz(ispec, iz, ix),
tag_type());
Kokkos::Experimental::where(mask,
point_partial_derivatives.gammaz)
.copy_from(&partial_derivatives.gammaz(ispec, iz, ix),
tag_type());
}
specfem::benchmarks::load_partial_derivative(
index, partial_derivatives, point_partial_derivatives);

VectorPointViewType df;

Expand All @@ -257,118 +180,12 @@ void compute_stiffness_interaction(const specfem::compute::assembly &assembly,

specfem::point::partial_derivatives<dimension, true, using_simd>
point_partial_derivatives2;
if constexpr (flag) {
specfem::benchmarks::load_partial_derivative(
index, partial_derivatives, point_partial_derivatives2);
} else {
const int ispec = index.ispec;
mask_type mask(
[&](std::size_t lane) { return index.mask(lane); });

Kokkos::Experimental::where(mask,
point_partial_derivatives2.xix)
.copy_from(&partial_derivatives.xix(ispec, iz, ix),
tag_type());
Kokkos::Experimental::where(mask,
point_partial_derivatives2.gammax)
.copy_from(&partial_derivatives.gammax(ispec, iz, ix),
tag_type());
Kokkos::Experimental::where(mask,
point_partial_derivatives2.xiz)
.copy_from(&partial_derivatives.xiz(ispec, iz, ix),
tag_type());
Kokkos::Experimental::where(mask,
point_partial_derivatives2.gammaz)
.copy_from(&partial_derivatives.gammaz(ispec, iz, ix),
tag_type());
Kokkos::Experimental::where(
mask, point_partial_derivatives2.jacobian)
.copy_from(&partial_derivatives.jacobian(ispec, iz, ix),
tag_type());
}
specfem::benchmarks::load_partial_derivative(
index, partial_derivatives, point_partial_derivatives2);

PointPropertyType point_property;
if constexpr (flag) {
specfem::benchmarks::load_point_property(index, properties,
point_property);
} else {
const int ispec =
properties.property_index_mapping(index.ispec);

const auto &container =
properties.get_container<MediumTag, PropertyTag>();

mask_type mask(
[&](std::size_t lane) { return index.mask(lane); });

if constexpr (MediumTag ==
specfem::element::medium_tag::acoustic &&
PropertyTag ==
specfem::element::property_tag::isotropic) {
Kokkos::Experimental::where(mask,
point_property.rho_inverse)
.copy_from(&container.rho_inverse(ispec, iz, ix),
tag_type());
Kokkos::Experimental::where(mask, point_property.kappa)
.copy_from(&container.kappa(ispec, iz, ix), tag_type());

point_property.kappa_inverse =
static_cast<type_real>(1.0) / point_property.kappa;
point_property.rho_vpinverse =
Kokkos::sqrt(point_property.rho_inverse *
point_property.kappa_inverse);
} else if constexpr (
MediumTag == specfem::element::medium_tag::elastic &&
PropertyTag ==
specfem::element::property_tag::isotropic) {
Kokkos::Experimental::where(mask, point_property.rho)
.copy_from(&container.rho(ispec, iz, ix), tag_type());
Kokkos::Experimental::where(mask, point_property.mu)
.copy_from(&container.mu(ispec, iz, ix), tag_type());
Kokkos::Experimental::where(mask,
point_property.lambdaplus2mu)
.copy_from(&container.lambdaplus2mu(ispec, iz, ix),
tag_type());

point_property.lambda =
point_property.lambdaplus2mu - 2 * point_property.mu;
point_property.rho_vp = Kokkos::sqrt(
point_property.rho * point_property.lambdaplus2mu);
point_property.rho_vs =
Kokkos::sqrt(point_property.rho * point_property.mu);
} else if constexpr (
MediumTag == specfem::element::medium_tag::elastic &&
PropertyTag ==
specfem::element::property_tag::anisotropic) {
Kokkos::Experimental::where(mask, point_property.rho)
.copy_from(&container.rho(ispec, iz, ix), tag_type());
Kokkos::Experimental::where(mask, point_property.c11)
.copy_from(&container.c11(ispec, iz, ix), tag_type());
Kokkos::Experimental::where(mask, point_property.c12)
.copy_from(&container.c12(ispec, iz, ix), tag_type());
Kokkos::Experimental::where(mask, point_property.c13)
.copy_from(&container.c13(ispec, iz, ix), tag_type());
Kokkos::Experimental::where(mask, point_property.c15)
.copy_from(&container.c15(ispec, iz, ix), tag_type());
Kokkos::Experimental::where(mask, point_property.c33)
.copy_from(&container.c33(ispec, iz, ix), tag_type());
Kokkos::Experimental::where(mask, point_property.c35)
.copy_from(&container.c35(ispec, iz, ix), tag_type());
Kokkos::Experimental::where(mask, point_property.c55)
.copy_from(&container.c55(ispec, iz, ix), tag_type());
Kokkos::Experimental::where(mask, point_property.c23)
.copy_from(&container.c23(ispec, iz, ix), tag_type());
Kokkos::Experimental::where(mask, point_property.c25)
.copy_from(&container.c25(ispec, iz, ix), tag_type());

point_property.rho_vp =
Kokkos::sqrt(point_property.rho * point_property.c33);
point_property.rho_vs =
Kokkos::sqrt(point_property.rho * point_property.c55);
} else {
static_assert("medium type not supported");
}
}
specfem::benchmarks::load_point_property(index, properties,
point_property);

PointFieldDerivativesType field_derivatives(df);

Expand Down
Loading

0 comments on commit e50d8b5

Please sign in to comment.