Skip to content

Commit

Permalink
copy assembly to benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
icui committed Feb 20, 2025
1 parent 61ac516 commit e1c79f9
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 63 deletions.
4 changes: 2 additions & 2 deletions benchmarks/archive/stiffness1.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ constexpr static auto boundary_tag = specfem::element::boundary_tag::none;

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

constexpr auto medium_tag = MediumTag;
constexpr auto property_tag = PropertyTag;
Expand Down
143 changes: 143 additions & 0 deletions benchmarks/assembly.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
#pragma once

#include "IO/reader.hpp"
#include "compute/boundaries/boundaries.hpp"
#include "compute/boundary_values/boundary_values.hpp"
#include "compute/compute_mesh.hpp"
#include "compute/compute_partial_derivatives.hpp"
#include "compute/coupled_interfaces/coupled_interfaces.hpp"
#include "compute/fields/fields.hpp"
#include "compute/kernels/kernels.hpp"
#include "compute/properties/interface.hpp"
#include "compute/receivers/receivers.hpp"
#include "compute/sources/sources.hpp"
#include "enumerations/display.hpp"
#include "enumerations/interface.hpp"
#include "mesh/mesh.hpp"
#include "receiver/interface.hpp"
#include "source/interface.hpp"

namespace specfem {
/**
* @brief Compute namespace defines data structures used to store data related
* to finite element assembly.
*
* The data is organized in a manner that makes it effiecient to access when
* computing finite element compute kernels.
*
*/
namespace benchmarks {
/**
* @brief Finite element assembly data
*
*/
struct assembly {
specfem::compute::mesh mesh; ///< Properties of the assembled mesh
specfem::compute::element_types element_types; ///< Element tags for every
///< spectral element
specfem::compute::partial_derivatives partial_derivatives; ///< Partial
///< derivatives of
///< the basis
///< functions
specfem::compute::properties properties; ///< Material properties
specfem::compute::kernels kernels; ///< Frechet derivatives (Misfit kernels)
specfem::compute::sources sources; ///< Source information
specfem::compute::receivers receivers; ///< Receiver information
specfem::compute::boundaries boundaries; ///< Boundary conditions
specfem::compute::coupled_interfaces coupled_interfaces; ///< Coupled
///< interfaces
///< between 2
///< mediums
specfem::compute::fields fields; ///< Displacement, velocity, and acceleration
///< fields
specfem::compute::boundary_values boundary_values; ///< Field values at the
///< boundaries

/**
* @brief Generate a finite element assembly
*
* @param mesh Finite element mesh as read from mesher
* @param quadratures Quadrature points and weights
* @param sources Source information
* @param receivers Receiver information
* @param stypes Types of seismograms
* @param t0 Start time of simulation
* @param dt Time step
* @param max_timesteps Maximum number of time steps
* @param max_sig_step Maximum number of seismogram time steps
* @param nstep_between_samples Number of time steps between output seismogram
* samples
* @param simulation Type of simulation (forward, adjoint, etc.)
* @param property_reader Reader for GLL model (skip material property
* assignment if exists)
*/
assembly(
const specfem::mesh::mesh<specfem::dimension::type::dim2> &mesh,
const specfem::quadrature::quadratures &quadratures,
const std::vector<std::shared_ptr<specfem::sources::source> > &sources,
const std::vector<std::shared_ptr<specfem::receivers::receiver> >
&receivers,
const std::vector<specfem::enums::seismogram::type> &stypes,
const type_real t0, const type_real dt, const int max_timesteps,
const int max_sig_step, const int nsteps_between_samples,
const specfem::simulation::type simulation,
const std::shared_ptr<specfem::IO::reader> &property_reader) {
this->mesh = { mesh.tags, mesh.control_nodes, quadratures };
this->element_types = { this->mesh.nspec, this->mesh.ngllz,
this->mesh.ngllx, this->mesh.mapping, mesh.tags };
this->partial_derivatives = { this->mesh };
this->properties = { this->mesh.nspec, this->mesh.ngllz,
this->mesh.ngllx, this->element_types,
mesh.materials, property_reader != nullptr };
this->kernels = { this->mesh.nspec, this->mesh.ngllz, this->mesh.ngllx,
this->element_types };
this->sources = {
sources, this->mesh, this->partial_derivatives, this->element_types, t0,
dt, max_timesteps
};
this->receivers = { this->mesh.nspec,
this->mesh.ngllz,
this->mesh.ngllz,
max_sig_step,
dt,
t0,
nsteps_between_samples,
receivers,
stypes,
this->mesh,
mesh.tags,
this->element_types };
this->boundaries = { this->mesh.nspec, this->mesh.ngllz,
this->mesh.ngllx, mesh,
this->mesh.mapping, this->mesh.quadratures,
this->properties, this->partial_derivatives };
this->coupled_interfaces = { mesh,
this->mesh.points,
this->mesh.quadratures,
this->partial_derivatives,
this->element_types,
this->mesh.mapping };
this->fields = { this->mesh, this->element_types, simulation };
this->boundary_values = { max_timesteps, this->mesh, this->element_types,
this->boundaries };
return;
}

/**
* @brief Maps the component of wavefield on the entire spectral element grid
*
* This field can be used to generate a plot of the wavefield
*
* @param component Component of the wavefield to map
* @return Kokkos::View<type_real ***, Kokkos::LayoutLeft, Kokkos::HostSpace>
* Wavefield mapped on the entire grid. Dimensions of the view are nspec,
* ngllz, ngllx
*/
Kokkos::View<type_real ****, Kokkos::LayoutLeft, Kokkos::HostSpace>
generate_wavefield_on_entire_grid(
const specfem::wavefield::simulation_field wavefield,
const specfem::wavefield::type component);
};

} // namespace benchmarks
} // namespace specfem
76 changes: 17 additions & 59 deletions benchmarks/main.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "archive/stiffness1.hpp"
#include "assembly.hpp"
#include "execute.hpp"
#include "stiffness.hpp"
// #include "divide.hpp"

namespace specfem {
namespace benchmarks {

template <bool flag>
void benchmark(specfem::compute::assembly &assembly,
template <typename AssemblyType>
void benchmark(AssemblyType &assembly,
std::shared_ptr<specfem::time_scheme::time_scheme> time_scheme) {
constexpr auto acoustic = specfem::element::medium_tag::acoustic;
constexpr auto elastic = specfem::element::medium_tag::elastic;
Expand All @@ -18,59 +18,10 @@ void benchmark(specfem::compute::assembly &assembly,

const auto solver_start_time = std::chrono::system_clock::now();

// const auto &field = assembly.fields.get_simulation_field<wavefield>();
// std::cout << ">>>>" << field.acoustic.nglob << " | " << field.elastic.nglob
// << std::endl;

// specfem::kokkos::DeviceView4d<type_real, Kokkos::LayoutLeft>
// acoustic_field("acoustic_field", field.acoustic.nglob/ngll/ngll,ngll,ngll,
// field.acoustic.components); specfem::kokkos::DeviceView4d<type_real,
// Kokkos::LayoutLeft> acoustic_field_dot_dot("acoustic_field_dot_dot",
// field.acoustic.nglob/ngll/ngll,ngll,ngll, field.acoustic.components);

// specfem::kokkos::DeviceView4d<type_real, Kokkos::LayoutLeft>
// elastic_field("elastic_field", field.elastic.nglob/ngll/ngll,ngll,ngll,
// field.elastic.components); specfem::kokkos::DeviceView4d<type_real,
// Kokkos::LayoutLeft> elastic_field_dot_dot("elastic_field_dot_dot",
// field.elastic.nglob/ngll/ngll,ngll,ngll, field.elastic.components);

// specfem::kokkos::DeviceView2d<type_real, Kokkos::LayoutLeft>
// acoustic_field("acoustic_field", field.acoustic.nglob,
// field.acoustic.components); specfem::kokkos::DeviceView2d<type_real,
// Kokkos::LayoutLeft> acoustic_field_dot_dot("acoustic_field_dot_dot",
// field.acoustic.nglob, field.acoustic.components);

// specfem::kokkos::DeviceView2d<type_real, Kokkos::LayoutLeft>
// elastic_field("elastic_field", field.elastic.nglob,
// field.elastic.components); specfem::kokkos::DeviceView2d<type_real,
// Kokkos::LayoutLeft> elastic_field_dot_dot("elastic_field_dot_dot",
// field.elastic.nglob, field.elastic.components);

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);

// compute_stiffness_interaction2<acoustic, isotropic, flag>(assembly,
// istep); compute_stiffness_interaction2<elastic, isotropic,
// flag>(assembly, istep); compute_stiffness_interaction2<elastic,
// anisotropic, flag>(assembly, istep);

if constexpr (flag) {
compute_stiffness_interaction<acoustic, isotropic, false>(assembly,
istep);
compute_stiffness_interaction<elastic, isotropic, false>(assembly, istep);
compute_stiffness_interaction<elastic, anisotropic, false>(assembly,
istep);
} else {
compute_stiffness_interaction2<acoustic, isotropic, false>(assembly,
istep);
compute_stiffness_interaction2<elastic, isotropic, false>(assembly,
istep);
compute_stiffness_interaction2<elastic, anisotropic, false>(assembly,
istep);
}
compute_stiffness_interaction<acoustic, isotropic, false>(assembly, istep);
compute_stiffness_interaction<elastic, isotropic, false>(assembly, istep);
compute_stiffness_interaction<elastic, anisotropic, false>(assembly, istep);

// divide_mass_matrix<dimension, wavefield, acoustic>(assembly);
// divide_mass_matrix<dimension, wavefield, elastic>(assembly);
Expand Down Expand Up @@ -127,17 +78,24 @@ void run_benchmark(const YAML::Node &parameter_dict,
const std::vector<std::shared_ptr<specfem::sources::source> > sources;
const std::vector<std::shared_ptr<specfem::receivers::receiver> > receivers;
const int nsteps = setup.get_nsteps();

specfem::compute::assembly assembly(
mesh, quadrature, sources, receivers, setup.get_seismogram_types(),
setup.get_t0(), dt, nsteps, max_seismogram_time_step,
nstep_between_samples, setup.get_simulation_type(),
setup.instantiate_property_reader());
time_scheme->link_assembly(assembly);

benchmark<true>(assembly, time_scheme);
benchmark<false>(assembly, time_scheme);
benchmark<true>(assembly, time_scheme);
benchmark<false>(assembly, time_scheme);
specfem::benchmarks::assembly assembly2(
mesh, quadrature, sources, receivers, setup.get_seismogram_types(),
setup.get_t0(), dt, nsteps, max_seismogram_time_step,
nstep_between_samples, setup.get_simulation_type(),
setup.instantiate_property_reader());

benchmark(assembly2, time_scheme);
benchmark(assembly, time_scheme);
benchmark(assembly2, time_scheme);
benchmark(assembly, time_scheme);
std::cout << std::endl;
}

Expand Down
5 changes: 3 additions & 2 deletions benchmarks/stiffness.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "enumerations/medium.hpp"
#include "enumerations/wavefield.hpp"

#include "assembly.hpp"
#include "impl_chunk.hpp"
#include "impl_point.hpp"
#include "impl_policy.hpp"
Expand All @@ -19,8 +20,8 @@ namespace benchmarks {

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

constexpr auto medium_tag = MediumTag;
constexpr auto property_tag = PropertyTag;
Expand Down

0 comments on commit e1c79f9

Please sign in to comment.