-
Notifications
You must be signed in to change notification settings - Fork 90
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
Porting some optimization cases to run on GPU without UVM #1086
Open
mcarlson801
wants to merge
11
commits into
master
Choose a base branch
from
mcarlson801/port_l2squaredside_response
base: master
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 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4ae05ff
Port DistParamDeriv and HessianVec specializations for uvm-free optim…
mcarlson801 205f152
Convert local_VP to view and port hessianVec/DistParamDeriv gather/sc…
mcarlson801 93f6eef
Restore ResponseSquaredL2DifferenceSide precomputation, add atomic_ad…
mcarlson801 39db7d7
Fixes for GatherScalarNodalParameter
mcarlson801 ae4e26f
Fix for ScatterResidual
mcarlson801 e612ead
Loop bound fixes
mcarlson801 baf1b3b
Update scatter unit tests to work without uvm, fixed bug in Separable…
mcarlson801 3d1babc
Fix warnings
mcarlson801 d2e177b
Move temporary data movement out of ScatterResidual and into Albany D…
mcarlson801 eb3bcbb
Cleanup and adding comment
mcarlson801 6e7ef8d
Port some more gather specializations for extruded mesh
mcarlson801 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
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 |
---|---|---|
|
@@ -191,17 +191,19 @@ evaluateFields(typename Traits::EvalData workset) | |
|
||
// Distributed parameter vector | ||
const auto p = workset.distParamLib->get(this->param_name); | ||
const auto p_data = Albany::getLocalData(p->overlapped_vector().getConst()); | ||
const auto p_data = Albany::getDeviceData(p->overlapped_vector().getConst()); | ||
|
||
const auto Vp = workset.Vp; | ||
const auto Vp_data = !Vp.is_null() ? Albany::getLocalData(Vp) : Teuchos::null; | ||
Albany::ThyraMVDeviceView<const ST> Vp_data; | ||
if (!Vp.is_null()) Vp_data = Albany::getDeviceData(Vp); | ||
|
||
// Parameter/solution/nodes dof numbering info | ||
const auto dof_mgr = workset.disc->getDOFManager(); | ||
const auto p_elem_dof_lids = p->get_dof_mgr()->elem_dof_lids().host(); | ||
const auto p_elem_dof_lids = p->get_dof_mgr()->elem_dof_lids().dev(); | ||
|
||
const auto ws = workset.wsIndex; | ||
const auto elem_lids = workset.disc->getElementLIDs_host(ws); | ||
const auto ws_elem_lids = workset.disc->getWsElementLIDs().dev(); | ||
const auto elem_lids = Kokkos::subview(ws_elem_lids,ws,Kokkos::ALL()); | ||
|
||
// Are we differentiating w.r.t. this parameter? | ||
const bool is_active = (workset.dist_param_deriv_name == this->param_name); | ||
|
@@ -211,58 +213,76 @@ evaluateFields(typename Traits::EvalData workset) | |
const int neq = dof_mgr->getNumFields(); | ||
const int num_deriv = this->numNodes; | ||
bool trans = workset.transpose_dist_param_deriv; | ||
const auto elem_dof_lids = dof_mgr->elem_dof_lids().host(); | ||
for (std::size_t cell=0; cell<workset.numCells; ++cell) { | ||
const auto elem_dof_lids = dof_mgr->elem_dof_lids().dev(); | ||
|
||
Kokkos::parallel_for(this->getName(),RangePolicy(0,workset.numCells), | ||
KOKKOS_CLASS_LAMBDA(const int& cell) { | ||
const auto elem_LID = elem_lids(cell); | ||
const auto p_dof_lids = Kokkos::subview(p_elem_dof_lids,elem_LID,ALL); | ||
for (int node=0; node<num_deriv; ++node) { | ||
const LO lid = p_dof_lids(node); | ||
|
||
// Initialize Fad type for parameter value | ||
const auto p_val = lid>=0 ? p_data[lid] : 0; | ||
const auto p_val = lid>=0 ? p_data(lid) : 0; | ||
ParamScalarT v(num_deriv, node, p_val); | ||
this->val(cell,node) = v; | ||
} | ||
}); | ||
|
||
if (Vp != Teuchos::null) { | ||
const int num_cols = Vp->domain()->dim(); | ||
const int num_dofs = elem_dof_lids.extent(1); | ||
if (trans) { | ||
workset.local_Vp = Kokkos::View<double***, PHX::Device>("local_Vp",workset.numCells,num_dofs,num_cols); | ||
} else { | ||
workset.local_Vp = Kokkos::View<double***, PHX::Device>("local_Vp",workset.numCells,num_deriv,num_cols); | ||
} | ||
|
||
if (Vp != Teuchos::null) { | ||
const int num_cols = Vp->domain()->dim(); | ||
const auto& local_Vp = workset.local_Vp; | ||
|
||
auto& local_Vp = workset.local_Vp[cell]; | ||
if (trans) { | ||
for (int eq=0; eq<neq; ++eq) { | ||
const auto& offsets = dof_mgr->getGIDFieldOffsetsKokkos(eq); | ||
const int num_offsets = offsets.size(); | ||
|
||
if (trans) { | ||
auto dof_lids = Kokkos::subview(elem_dof_lids,elem_LID,ALL); | ||
// const auto& offsets = this->m_sol_fields_offsets; | ||
local_Vp.resize(dof_lids.size()); | ||
for (int eq=0; eq<neq; ++eq) { | ||
const auto& offsets = dof_mgr->getGIDFieldOffsets(eq); | ||
for (const auto o : offsets) { | ||
local_Vp[o].resize(num_cols); | ||
Kokkos::parallel_for(this->getName()+"_transvp",RangePolicy(0,workset.numCells), | ||
KOKKOS_CLASS_LAMBDA(const int& cell) { | ||
const auto elem_LID = elem_lids(cell); | ||
const auto dof_lids = Kokkos::subview(elem_dof_lids,elem_LID,ALL); | ||
for (int i=0; i < num_offsets; ++i) { | ||
const auto o = offsets(i); | ||
const LO lid = dof_lids(o); | ||
for (int col=0; col<num_cols; ++col) | ||
local_Vp[o][col] = Vp_data[col][lid]; | ||
local_Vp(cell,o,col) = Vp_data(lid,col); | ||
} | ||
} | ||
} else { | ||
local_Vp.resize(num_deriv); | ||
}); | ||
} | ||
} | ||
else { | ||
Kokkos::parallel_for(this->getName()+"_notransvp",RangePolicy(0,workset.numCells), | ||
KOKKOS_CLASS_LAMBDA(const int& cell) { | ||
const auto elem_LID = elem_lids(cell); | ||
const auto p_dof_lids = Kokkos::subview(p_elem_dof_lids,elem_LID,ALL); | ||
for (int node=0; node<num_deriv; ++node) { | ||
const LO lid = p_dof_lids(node); | ||
local_Vp[node].resize(num_cols); | ||
for (int col=0; col<num_cols; ++col) | ||
local_Vp[node][col] = lid>=0 ? Vp_data[col][lid] : 0; | ||
local_Vp(cell,node,col) = lid>=0 ? Vp_data(lid,col) : 0; | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
} else { | ||
// If not active, just set the parameter value in the phalanx field | ||
for (std::size_t cell=0; cell < workset.numCells; ++cell ) { | ||
const int num_nodes = this->numNodes; | ||
Kokkos::parallel_for(this->getName(),RangePolicy(0,workset.numCells), | ||
KOKKOS_CLASS_LAMBDA(const int& cell) { | ||
const auto elem_LID = elem_lids(cell); | ||
const auto p_dof_lids = Kokkos::subview(p_elem_dof_lids,elem_LID,ALL); | ||
for (int node=0; node<this->numNodes; ++node) { | ||
for (int node=0; node<num_nodes; ++node) { | ||
const LO lid = p_dof_lids(node); | ||
this->val(cell,node) = lid>=0 ? p_data[lid] : 0; | ||
this->val(cell,node) = lid>=0 ? p_data(lid) : 0; | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
|
||
|
@@ -330,6 +350,18 @@ evaluateFields(typename Traits::EvalData workset) | |
const int neq = sol_dof_mgr->getNumFields(); | ||
const int num_deriv = this->numNodes; | ||
const bool trans = workset.transpose_dist_param_deriv; | ||
|
||
if (Vp != Teuchos::null) { | ||
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. Indentation seems off here. |
||
const int num_cols = workset.Vp->domain()->dim(); | ||
if (trans) { | ||
const int num_dofs = elem_dof_lids.extent(1); | ||
workset.local_Vp = Kokkos::View<double***, PHX::Device>("local_Vp",workset.numCells,num_dofs,num_cols); | ||
} else { | ||
workset.local_Vp = Kokkos::View<double***, PHX::Device>("local_Vp",workset.numCells,num_deriv,num_cols); | ||
} | ||
} | ||
const auto& local_Vp = workset.local_Vp; | ||
|
||
for (std::size_t cell=0; cell<workset.numCells; ++cell) { | ||
const auto elem_LID = elem_lids(cell); | ||
const auto basal_elem_LID = layers_data->getColumnId(elem_LID); | ||
|
@@ -349,27 +381,22 @@ evaluateFields(typename Traits::EvalData workset) | |
if (Vp != Teuchos::null) { | ||
const int num_cols = workset.Vp->domain()->dim(); | ||
|
||
auto& local_Vp = workset.local_Vp[cell]; | ||
if (trans) { | ||
auto dof_lids = Kokkos::subview(elem_dof_lids,elem_LID,ALL); | ||
local_Vp.resize(dof_lids.size()); | ||
for (int eq=0; eq<neq; ++eq) { | ||
const auto& sol_offsets = sol_dof_mgr->getGIDFieldOffsets(eq); | ||
for (const auto o : sol_offsets) { | ||
local_Vp[o].resize(num_cols); | ||
const LO lid = dof_lids(o); | ||
for (int col=0; col<num_cols; ++col) | ||
local_Vp[o][col] = Vp_data[col][lid]; | ||
local_Vp(cell,o,col) = Vp_data[col][lid]; | ||
} | ||
} | ||
} else { | ||
local_Vp.resize(num_deriv); | ||
for (int node2d=0; node2d<num_nodes_2d; ++node2d) { | ||
const LO p_lid = p_elem_dof_lids(param_elem_LID,offsets_p[node2d]); | ||
for (auto node : {offsets_bot[node2d], offsets_top[node2d]}) { | ||
local_Vp[node].resize(num_cols); | ||
for (int col=0; col<num_cols; ++col) { | ||
local_Vp[node][col] = p_lid>=0 ? Vp_data[col][p_lid] : 0; | ||
local_Vp(cell,node,col) = p_lid>=0 ? Vp_data[col][p_lid] : 0; | ||
} | ||
} | ||
} | ||
|
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.
Does this work on device, and is it performant? With certain fads, doesn't it allocate memory on device at every call?