-
Notifications
You must be signed in to change notification settings - Fork 9
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
refactor point_properties and property_container #509
Open
icui
wants to merge
4
commits into
issue-493
Choose a base branch
from
issue-489
base: issue-493
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,211 +9,19 @@ namespace medium { | |
|
||
template <> | ||
struct properties_container<specfem::element::medium_tag::acoustic, | ||
specfem::element::property_tag::isotropic> { | ||
|
||
constexpr static auto dimension = specfem::dimension::type::dim2; | ||
constexpr static auto value_type = specfem::element::medium_tag::acoustic; | ||
constexpr static auto property_type = | ||
specfem::element::property_tag::isotropic; | ||
|
||
using ViewType = typename Kokkos::View<type_real ***, Kokkos::LayoutLeft, | ||
Kokkos::DefaultExecutionSpace>; | ||
|
||
int nspec; ///< total number of acoustic spectral elements | ||
int ngllz; ///< number of quadrature points in z dimension | ||
int ngllx; ///< number of quadrature points in x dimension | ||
ViewType rho_inverse; | ||
ViewType::HostMirror h_rho_inverse; | ||
ViewType kappa; | ||
ViewType::HostMirror h_kappa; | ||
|
||
properties_container() = default; | ||
|
||
properties_container(const int nspec, const int ngllz, const int ngllx) | ||
: nspec(nspec), ngllz(ngllz), ngllx(ngllx), | ||
rho_inverse("specfem::compute::properties::rho_inverse", nspec, ngllz, | ||
ngllx), | ||
h_rho_inverse(Kokkos::create_mirror_view(rho_inverse)), | ||
kappa("specfem::compute::properties::kappa", nspec, ngllz, ngllx), | ||
h_kappa(Kokkos::create_mirror_view(kappa)) {} | ||
|
||
template < | ||
typename PointProperties, | ||
typename std::enable_if_t<!PointProperties::simd::using_simd, int> = 0> | ||
KOKKOS_FORCEINLINE_FUNCTION void | ||
load_device_properties(const specfem::point::index<dimension> &index, | ||
PointProperties &property) const { | ||
|
||
static_assert(PointProperties::dimension == dimension, | ||
"Dimension mismatch"); | ||
static_assert(PointProperties::medium_tag == value_type, | ||
"Medium tag mismatch"); | ||
static_assert(PointProperties::property_tag == property_type, | ||
"Property tag mismatch"); | ||
|
||
const int ispec = index.ispec; | ||
const int iz = index.iz; | ||
const int ix = index.ix; | ||
|
||
property.rho_inverse = rho_inverse(ispec, iz, ix); | ||
property.kappa = kappa(ispec, iz, ix); | ||
property.kappa_inverse = static_cast<type_real>(1.0) / property.kappa; | ||
property.rho_vpinverse = | ||
sqrt(property.rho_inverse * property.kappa_inverse); | ||
} | ||
|
||
template < | ||
typename PointProperties, | ||
typename std::enable_if_t<PointProperties::simd::using_simd, int> = 0> | ||
KOKKOS_FORCEINLINE_FUNCTION void | ||
load_device_properties(const specfem::point::simd_index<dimension> &index, | ||
PointProperties &property) const { | ||
|
||
static_assert(PointProperties::dimension == dimension, | ||
"Dimension mismatch"); | ||
static_assert(PointProperties::medium_tag == value_type, | ||
"Medium tag mismatch"); | ||
static_assert(PointProperties::property_tag == property_type, | ||
"Property tag mismatch"); | ||
|
||
using simd = typename PointProperties::simd; | ||
using mask_type = typename simd::mask_type; | ||
using tag_type = typename simd::tag_type; | ||
|
||
const int ispec = index.ispec; | ||
const int iz = index.iz; | ||
const int ix = index.ix; | ||
|
||
mask_type mask([&, this](std::size_t lane) { return index.mask(lane); }); | ||
|
||
Kokkos::Experimental::where(mask, property.rho_inverse) | ||
.copy_from(&rho_inverse(ispec, iz, ix), tag_type()); | ||
Kokkos::Experimental::where(mask, property.kappa) | ||
.copy_from(&kappa(ispec, iz, ix), tag_type()); | ||
|
||
property.kappa_inverse = static_cast<type_real>(1.0) / property.kappa; | ||
property.rho_vpinverse = | ||
Kokkos::sqrt(property.rho_inverse * property.kappa_inverse); | ||
} | ||
|
||
template < | ||
typename PointProperties, | ||
typename std::enable_if_t<!PointProperties::simd::using_simd, int> = 0> | ||
inline void | ||
load_host_properties(const specfem::point::index<dimension> &index, | ||
PointProperties &property) const { | ||
|
||
static_assert(PointProperties::dimension == dimension, | ||
"Dimension mismatch"); | ||
static_assert(PointProperties::medium_tag == value_type, | ||
"Medium tag mismatch"); | ||
static_assert(PointProperties::property_tag == property_type, | ||
"Property tag mismatch"); | ||
|
||
const int ispec = index.ispec; | ||
const int iz = index.iz; | ||
const int ix = index.ix; | ||
|
||
property.rho_inverse = h_rho_inverse(ispec, iz, ix); | ||
property.kappa = h_kappa(ispec, iz, ix); | ||
property.kappa_inverse = static_cast<type_real>(1.0) / property.kappa; | ||
property.rho_vpinverse = | ||
sqrt(property.rho_inverse * property.kappa_inverse); | ||
} | ||
|
||
template < | ||
typename PointProperties, | ||
typename std::enable_if_t<PointProperties::simd::using_simd, int> = 0> | ||
inline void | ||
load_host_properties(const specfem::point::simd_index<dimension> &index, | ||
PointProperties &property) const { | ||
|
||
static_assert(PointProperties::dimension == dimension, | ||
"Dimension mismatch"); | ||
static_assert(PointProperties::medium_tag == value_type, | ||
"Medium tag mismatch"); | ||
static_assert(PointProperties::property_tag == property_type, | ||
"Property tag mismatch"); | ||
|
||
using simd = typename PointProperties::simd; | ||
using mask_type = typename simd::mask_type; | ||
using tag_type = typename simd::tag_type; | ||
|
||
const int ispec = index.ispec; | ||
const int iz = index.iz; | ||
const int ix = index.ix; | ||
|
||
mask_type mask([&, this](std::size_t lane) { return index.mask(lane); }); | ||
|
||
Kokkos::Experimental::where(mask, property.rho_inverse) | ||
.copy_from(&h_rho_inverse(ispec, iz, ix), tag_type()); | ||
Kokkos::Experimental::where(mask, property.kappa) | ||
.copy_from(&h_kappa(ispec, iz, ix), tag_type()); | ||
|
||
property.kappa_inverse = static_cast<type_real>(1.0) / property.kappa; | ||
property.rho_vpinverse = | ||
Kokkos::sqrt(property.rho_inverse * property.kappa_inverse); | ||
} | ||
|
||
void copy_to_device() { | ||
Kokkos::deep_copy(rho_inverse, h_rho_inverse); | ||
Kokkos::deep_copy(kappa, h_kappa); | ||
} | ||
|
||
void copy_to_host() { | ||
Kokkos::deep_copy(h_rho_inverse, rho_inverse); | ||
Kokkos::deep_copy(h_kappa, kappa); | ||
} | ||
|
||
template < | ||
typename PointProperties, | ||
typename std::enable_if_t<!PointProperties::simd::using_simd, int> = 0> | ||
inline void assign(const specfem::point::index<dimension> &index, | ||
const PointProperties &property) const { | ||
|
||
static_assert(PointProperties::dimension == dimension, | ||
"Dimension mismatch"); | ||
static_assert(PointProperties::medium_tag == value_type, | ||
"Medium tag mismatch"); | ||
static_assert(PointProperties::property_tag == property_type, | ||
"Property tag mismatch"); | ||
|
||
const int ispec = index.ispec; | ||
const int iz = index.iz; | ||
const int ix = index.ix; | ||
|
||
h_rho_inverse(ispec, iz, ix) = property.rho_inverse; | ||
h_kappa(ispec, iz, ix) = property.kappa; | ||
} | ||
|
||
template < | ||
typename PointProperties, | ||
typename std::enable_if_t<PointProperties::simd::using_simd, int> = 0> | ||
inline void assign(const specfem::point::simd_index<dimension> &index, | ||
const PointProperties &property) const { | ||
|
||
static_assert(PointProperties::dimension == dimension, | ||
"Dimension mismatch"); | ||
static_assert(PointProperties::medium_tag == value_type, | ||
"Medium tag mismatch"); | ||
static_assert(PointProperties::property_tag == property_type, | ||
"Property tag mismatch"); | ||
|
||
using simd = typename PointProperties::simd; | ||
using mask_type = typename simd::mask_type; | ||
using tag_type = typename simd::tag_type; | ||
|
||
const int ispec = index.ispec; | ||
const int iz = index.iz; | ||
const int ix = index.ix; | ||
|
||
mask_type mask([&, this](std::size_t lane) { return index.mask(lane); }); | ||
|
||
Kokkos::Experimental::where(mask, property.rho_inverse) | ||
.copy_to(&h_rho_inverse(ispec, iz, ix), tag_type()); | ||
Kokkos::Experimental::where(mask, property.kappa) | ||
.copy_to(&h_kappa(ispec, iz, ix), tag_type()); | ||
} | ||
specfem::element::property_tag::isotropic> | ||
: public impl::impl_properties_container< | ||
specfem::element::medium_tag::acoustic, | ||
specfem::element::property_tag::isotropic, 2> { | ||
using Base = | ||
impl::impl_properties_container<specfem::element::medium_tag::acoustic, | ||
specfem::element::property_tag::isotropic, | ||
2>; | ||
using Base::Base; | ||
constexpr static int _counter = __COUNTER__; | ||
|
||
DEFINE_CONTAINER(rho_inverse) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is awesome! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, this is nuts. |
||
DEFINE_CONTAINER(kappa) | ||
}; | ||
|
||
} // namespace medium | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use
base_type
here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated