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

Intrepid2: Initial implementation of team-level getValues #13437

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
48 changes: 48 additions & 0 deletions packages/intrepid2/src/Discretization/Basis/Intrepid2_Basis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,54 @@ using HostBasisPtr = BasisPtr<typename Kokkos::HostSpace::device_type, OutputTyp
}
}


/** \brief Return the size of the scratch space, in bytes, needed for using the team-level implementation of getValues.

Warning, <var>inputPoints</var> is only used to deduce the type of the points where to evaluate basis functions.
The rank of </var>inputPoints</var> and its size are not relevant, however,
when using DFAD types, </var>inputPoints</var> cannot be empty and has to be allocated,
otherwise the size of the scracth space needed won't be deduced correctly.

\param space [in] - inputPoints
\param perTeamSpaceSize [out] - size of the scratch space needed per team
\param perThreadeSize [out] - size of the scratch space beeded per thread
*/
virtual
void getScratchSpaceSize( ordinal_type& perTeamSpaceSize,
ordinal_type& perThreadSpaceSize,
const PointViewType inputPoints,
const EOperator operatorType = OPERATOR_VALUE) const {
INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE( true, std::logic_error,
">>> ERROR (Basis::getValuesScratchSpace): this method (FEM) is not supported or should be overridden accordingly by derived classes.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the "(FEM)" supposed to convey here? I think the message is clearer without it, but maybe there is something else you wanted to communicate.

}


/** \brief Team-level evaluation of a FEM basis on a <strong>reference cell</strong>.

Returns values of <var>operatorType</var> acting on FEM basis functions for a set of
points in the <strong>reference cell</strong> for which the basis is defined.

\param space [in] - execution space instance
\param outputValues [out] - variable rank array with the basis values
\param inputPoints [in] - rank-2 array (P,D) with the evaluation points
\param operatorType [in] - the operator acting on the basis functions

\remark This function is supposed to be called within a TeamPolicy kernel.
The size of the required scratch space is determined by the getScratchSpaceSize function.
*/
KOKKOS_INLINE_FUNCTION
virtual
void getValues( OutputViewType /* outputValues */,
const PointViewType /* inputPoints */,
const EOperator /* operatorType */,
const typename Kokkos::TeamPolicy<ExecutionSpace>::member_type& team_member,
const typename ExecutionSpace::scratch_memory_space &scratchStorage,
const ordinal_type subcellDim=-1,
const ordinal_type subcellOrdinal=-1) const {
INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE( true, std::logic_error,
">>> ERROR (Basis::getValues): this method (FEM) is not supported or should be overridden accordingly by derived classes.");
}

/** \brief Evaluation of a FEM basis on a <strong>reference cell</strong>.

Returns values of <var>operatorType</var> acting on FEM basis functions for a set of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,23 @@ namespace Intrepid2 {
operatorType );
}

virtual void
getScratchSpaceSize( ordinal_type& perTeamSpaceSize,
ordinal_type& perThreadSpaceSize,
const PointViewType inputPointsconst,
const EOperator operatorType = OPERATOR_VALUE) const override;

KOKKOS_INLINE_FUNCTION
virtual void
getValues(
OutputViewType outputValues,
const PointViewType inputPoints,
const EOperator operatorType,
const typename Kokkos::TeamPolicy<typename DeviceType::execution_space>::member_type& team_member,
const typename DeviceType::execution_space::scratch_memory_space & scratchStorage,
const ordinal_type subcellDim = -1,
const ordinal_type subcellOrdinal = -1) const override;

virtual
void
getDofCoords( ScalarViewType dofCoords ) const override {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,53 @@ namespace Intrepid2 {
Kokkos::deep_copy(this->dofCoeffs_, dofCoeffs);
}

template<typename DT, typename OT, typename PT>
void
Basis_HDIV_TET_I1_FEM<DT,OT,PT>::getScratchSpaceSize(
ordinal_type& perTeamSpaceSize,
ordinal_type& perThreadSpaceSize,
const PointViewType inputPoints,
const EOperator operatorType) const {
perTeamSpaceSize = 0;
perThreadSpaceSize = 0;
}

template<typename DT, typename OT, typename PT>
KOKKOS_INLINE_FUNCTION
void
Basis_HDIV_TET_I1_FEM<DT,OT,PT>::getValues(
OutputViewType outputValues,
const PointViewType inputPoints,
const EOperator operatorType,
const typename Kokkos::TeamPolicy<typename DT::execution_space>::member_type& team_member,
const typename DT::execution_space::scratch_memory_space & scratchStorage,
const ordinal_type subcellDim,
const ordinal_type subcellOrdinal) const {

INTREPID2_TEST_FOR_ABORT( !((subcellDim == -1) && (subcellOrdinal == -1)),
">>> ERROR: (Intrepid2::Basis_HDIV_TET_I1_FEM::getValues), The capability of selecting subsets of basis functions has not been implemented yet.");

(void) scratchStorage;
const int numPoints = inputPoints.extent(0);
switch(operatorType) {
case OPERATOR_VALUE:
Kokkos::parallel_for (Kokkos::TeamThreadRange (team_member, numPoints), [=] (int& pt) {
auto output = Kokkos::subview( outputValues, Kokkos::ALL(), pt, Kokkos::ALL() );
const auto input = Kokkos::subview( inputPoints, pt, Kokkos::ALL() );
Impl::Basis_HDIV_TET_I1_FEM::Serial<OPERATOR_VALUE>::getValues( output, input );
});
break;
case OPERATOR_DIV:
Kokkos::parallel_for (Kokkos::TeamThreadRange (team_member, numPoints), [=] (int& pt) {
auto output = Kokkos::subview( outputValues, Kokkos::ALL(), pt, Kokkos::ALL() );
const auto input = Kokkos::subview( inputPoints, pt, Kokkos::ALL() );
Impl::Basis_HDIV_TET_I1_FEM::Serial<OPERATOR_DIV>::getValues( output, input );
});
break;
default: {}
}
}

}// namespace Intrepid2
#endif

Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,23 @@ namespace Intrepid2 {
operatorType);
}

virtual void
getScratchSpaceSize( ordinal_type& perTeamSpaceSize,
ordinal_type& perThreadSpaceSize,
const PointViewType inputPoints,
const EOperator operatorType = OPERATOR_VALUE) const override;

KOKKOS_INLINE_FUNCTION
virtual void
getValues(
OutputViewType outputValues,
const PointViewType inputPoints,
const EOperator operatorType,
const typename Kokkos::TeamPolicy<typename DeviceType::execution_space>::member_type& team_member,
const typename DeviceType::execution_space::scratch_memory_space & scratchStorage,
const ordinal_type subcellDim = -1,
const ordinal_type subcellOrdinal = -1) const override;


virtual
void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ namespace Intrepid2 {
const auto input_y = Kokkos::subview(input, Kokkos::ALL(), range_type(1,2));
const auto input_z = Kokkos::subview(input, Kokkos::ALL(), range_type(2,3));

const ordinal_type dim_s = get_dimension_scalar(work);
const ordinal_type dim_s = get_dimension_scalar(input);
auto ptr0 = work.data();
auto ptr1 = work.data()+cardLine*npts*dim_s;
auto ptr2 = work.data()+2*cardLine*npts*dim_s;
auto ptr3 = work.data()+3*cardLine*npts*dim_s;

typedef typename Kokkos::DynRankView<typename workViewType::value_type, typename workViewType::memory_space> viewType;
auto vcprop = Kokkos::common_view_alloc_prop(work);
typedef typename Kokkos::DynRankView<typename inputViewType::value_type, typename workViewType::memory_space> viewType;
auto vcprop = Kokkos::common_view_alloc_prop(input);

switch (opType) {
case OPERATOR_VALUE: {
Expand Down Expand Up @@ -382,7 +382,64 @@ namespace Intrepid2 {
this->dofCoords_ = Kokkos::create_mirror_view(typename DT::memory_space(), dofCoordsHost);
Kokkos::deep_copy(this->dofCoords_, dofCoordsHost);
}


template<typename DT, typename OT, typename PT>
void
Basis_HGRAD_HEX_Cn_FEM<DT,OT,PT>::getScratchSpaceSize(
ordinal_type& perTeamSpaceSize,
ordinal_type& perThreadSpaceSize,
const PointViewType inputPoints,
const EOperator operatorType) const {
(void) operatorType; //avoid warning for unused variable
perTeamSpaceSize = 0;
perThreadSpaceSize = 4*this->vinv_.extent(0)*get_dimension_scalar(inputPoints)*sizeof(typename BasisBase::scalarType);
}

template<typename DT, typename OT, typename PT>
KOKKOS_INLINE_FUNCTION
void
Basis_HGRAD_HEX_Cn_FEM<DT,OT,PT>::getValues(
OutputViewType outputValues,
const PointViewType inputPoints,
const EOperator operatorType,
const typename Kokkos::TeamPolicy<typename DT::execution_space>::member_type& team_member,
const typename DT::execution_space::scratch_memory_space & scratchStorage,
const ordinal_type subcellDim,
const ordinal_type subcellOrdinal) const {

INTREPID2_TEST_FOR_ABORT( !((subcellDim == -1) && (subcellOrdinal == -1)),
">>> ERROR: (Intrepid2::Basis_HGRAD_HEX_Cn_FEM::getValues), The capability of selecting subsets of basis functions has not been implemented yet.");

const int numPoints = inputPoints.extent(0);
using ScalarType = typename ScalarTraits<typename PointViewType::value_type>::scalar_type;
using WorkViewType = Kokkos::DynRankView< ScalarType,typename DT::execution_space::scratch_memory_space,Kokkos::MemoryTraits<Kokkos::Unmanaged> >;
ordinal_type sizePerPoint = 4*this->vinv_.extent(0)*get_dimension_scalar(inputPoints);
WorkViewType workView(scratchStorage, sizePerPoint*team_member.team_size());
using range_type = Kokkos::pair<ordinal_type,ordinal_type>;

switch(operatorType) {
case OPERATOR_VALUE:
Kokkos::parallel_for (Kokkos::TeamThreadRange (team_member, numPoints), [=] (ordinal_type& pt) {
auto output = Kokkos::subview( outputValues, Kokkos::ALL(), range_type (pt,pt+1), Kokkos::ALL() );
const auto input = Kokkos::subview( inputPoints, range_type(pt, pt+1), Kokkos::ALL() );
WorkViewType work(workView.data() + sizePerPoint*team_member.team_rank(), sizePerPoint);
Impl::Basis_HGRAD_HEX_Cn_FEM::Serial<OPERATOR_VALUE>::getValues( output, input, work, this->vinv_ );
});
break;
case OPERATOR_GRAD:
Kokkos::parallel_for (Kokkos::TeamThreadRange (team_member, numPoints), [=] (ordinal_type& pt) {
auto output = Kokkos::subview( outputValues, Kokkos::ALL(), range_type(pt,pt+1), Kokkos::ALL() );
const auto input = Kokkos::subview( inputPoints, range_type(pt,pt+1), Kokkos::ALL() );
WorkViewType work(workView.data() + sizePerPoint*team_member.team_rank(), sizePerPoint);
Impl::Basis_HGRAD_HEX_Cn_FEM::Serial<OPERATOR_GRAD>::getValues( output, input, work, this->vinv_ );
});
break;
default: {
INTREPID2_TEST_FOR_ABORT( true,
">>> ERROR (Basis_HGRAD_TET_Cn_FEM): getValues not implemented for this operator");
}
}
}
}// namespace Intrepid2

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,23 @@ namespace Intrepid2 {
operatorType);
}

virtual void
getScratchSpaceSize( ordinal_type& perTeamSpaceSize,
ordinal_type& perThreadSpaceSize,
const PointViewType inputPointsconst,
const EOperator operatorType = OPERATOR_VALUE) const override;

KOKKOS_INLINE_FUNCTION
virtual void
getValues(
OutputViewType outputValues,
const PointViewType inputPoints,
const EOperator operatorType,
const typename Kokkos::TeamPolicy<typename DeviceType::execution_space>::member_type& team_member,
const typename DeviceType::execution_space::scratch_memory_space & scratchStorage,
const ordinal_type subcellDim = -1,
const ordinal_type subcellOrdinal = -1) const override;

virtual
void
getDofCoords( ScalarViewType dofCoords ) const override {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@
const auto input_x = Kokkos::subview(input, Kokkos::ALL(), range_type(0,1));
const auto input_y = Kokkos::subview(input, Kokkos::ALL(), range_type(1,2));

const int dim_s = get_dimension_scalar(work);
const int dim_s = get_dimension_scalar(input);
auto ptr0 = work.data();
auto ptr1 = work.data()+cardLine*npts*dim_s;
auto ptr2 = work.data()+2*cardLine*npts*dim_s;

typedef typename Kokkos::DynRankView<typename workViewType::value_type, typename workViewType::memory_space> viewType;
auto vcprop = Kokkos::common_view_alloc_prop(work);
typedef typename Kokkos::DynRankView<typename inputViewType::value_type, typename workViewType::memory_space> viewType;
auto vcprop = Kokkos::common_view_alloc_prop(input);

switch (opType) {
case OPERATOR_VALUE: {
Expand Down Expand Up @@ -240,6 +240,68 @@
}
}

template<typename DT, typename OT, typename PT>
void
Basis_HGRAD_QUAD_Cn_FEM<DT,OT,PT>::getScratchSpaceSize(
ordinal_type& perTeamSpaceSize,
ordinal_type& perThreadSpaceSize,
const PointViewType inputPoints,
const EOperator operatorType) const {
perTeamSpaceSize = 0;
perThreadSpaceSize = 3*this->vinv_.extent(0)*get_dimension_scalar(inputPoints)*sizeof(typename BasisBase::scalarType);
}

template<typename DT, typename OT, typename PT>
KOKKOS_INLINE_FUNCTION
void
Basis_HGRAD_QUAD_Cn_FEM<DT,OT,PT>::getValues(
OutputViewType outputValues,
const PointViewType inputPoints,
const EOperator operatorType,
const typename Kokkos::TeamPolicy<typename DT::execution_space>::member_type& team_member,
const typename DT::execution_space::scratch_memory_space & scratchStorage,
const ordinal_type subcellDim,
const ordinal_type subcellOrdinal) const {

INTREPID2_TEST_FOR_ABORT( !((subcellDim == -1) && (subcellOrdinal == -1)),
">>> ERROR: (Intrepid2::Basis_HGRAD_QUAD_Cn_FEM::getValues), The capability of selecting subsets of basis functions has not been implemented yet.");

const int numPoints = inputPoints.extent(0);
using ScalarType = typename ScalarTraits<typename PointViewType::value_type>::scalar_type;
using WorkViewType = Kokkos::DynRankView< ScalarType,typename DT::execution_space::scratch_memory_space,Kokkos::MemoryTraits<Kokkos::Unmanaged> >;
ordinal_type sizePerPoint = 3*this->vinv_.extent(0)*get_dimension_scalar(inputPoints);
WorkViewType workView(scratchStorage, sizePerPoint*team_member.team_size());

Check failure

Code scanning / CodeQL

Multiplication result converted to larger type High

Multiplication result may overflow 'int' before it is converted to 'size_t'.
using range_type = Kokkos::pair<ordinal_type,ordinal_type>;

switch(operatorType) {
case OPERATOR_VALUE:
Kokkos::parallel_for (Kokkos::TeamThreadRange (team_member, numPoints), [=] (ordinal_type& pt) {
auto output = Kokkos::subview( outputValues, Kokkos::ALL(), range_type (pt,pt+1), Kokkos::ALL() );
const auto input = Kokkos::subview( inputPoints, range_type(pt, pt+1), Kokkos::ALL() );
WorkViewType work(workView.data() + sizePerPoint*team_member.team_rank(), sizePerPoint);
Impl::Basis_HGRAD_QUAD_Cn_FEM::Serial<OPERATOR_VALUE>::getValues( output, input, work, this->vinv_ );
});
break;
case OPERATOR_GRAD:
Kokkos::parallel_for (Kokkos::TeamThreadRange (team_member, numPoints), [=] (ordinal_type& pt) {
auto output = Kokkos::subview( outputValues, Kokkos::ALL(), range_type(pt,pt+1), Kokkos::ALL() );
const auto input = Kokkos::subview( inputPoints, range_type(pt,pt+1), Kokkos::ALL() );
WorkViewType work(workView.data() + sizePerPoint*team_member.team_rank(), sizePerPoint);
Impl::Basis_HGRAD_QUAD_Cn_FEM::Serial<OPERATOR_GRAD>::getValues( output, input, work, this->vinv_ );
});
break;
case OPERATOR_CURL:
Kokkos::parallel_for (Kokkos::TeamThreadRange (team_member, numPoints), [=] (ordinal_type& pt) {
auto output = Kokkos::subview( outputValues, Kokkos::ALL(), range_type(pt,pt+1), Kokkos::ALL() );
const auto input = Kokkos::subview( inputPoints, range_type(pt,pt+1), Kokkos::ALL() );
WorkViewType work(workView.data() + sizePerPoint*team_member.team_rank(), sizePerPoint);
Impl::Basis_HGRAD_QUAD_Cn_FEM::Serial<OPERATOR_CURL>::getValues( output, input, work, this->vinv_ );
});
break;
default: {}
}
}

// -------------------------------------------------------------------------------------
template<typename DT, typename OT, typename PT>
Basis_HGRAD_QUAD_Cn_FEM<DT,OT,PT>::
Expand Down
Loading
Loading