Skip to content

Commit

Permalink
WIP: enum CeedRestrictionType for CeedElemRestriction type
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastiangrimberg committed Apr 24, 2023
1 parent 518cc37 commit 0534fe3
Show file tree
Hide file tree
Showing 12 changed files with 277 additions and 243 deletions.
49 changes: 26 additions & 23 deletions backends/blocked/ceed-blocked-operator.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,37 +49,40 @@ static int CeedOperatorSetupFields_Blocked(CeedQFunction qf, CeedOperator op, bo
CeedCallBackend(CeedElemRestrictionGetElementSize(r, &elem_size));
CeedCallBackend(CeedElemRestrictionGetLVectorSize(r, &l_size));
CeedCallBackend(CeedElemRestrictionGetNumComponents(r, &num_comp));

bool strided;
CeedCallBackend(CeedElemRestrictionIsStrided(r, &strided));
if (strided) {
CeedInt strides[3];
CeedCallBackend(CeedElemRestrictionGetStrides(r, &strides));
CeedCallBackend(
CeedElemRestrictionCreateBlockedStrided(ceed, num_elem, elem_size, blk_size, num_comp, l_size, strides, &blk_restr[i + start_e]));
} else {
const CeedInt *offsets = NULL;
const bool *orients = NULL;
const CeedInt *curl_orients = NULL;
CeedCallBackend(CeedElemRestrictionGetOffsets(r, CEED_MEM_HOST, &offsets));
CeedCallBackend(CeedElemRestrictionGetOrientations(r, CEED_MEM_HOST, &orients));
CeedCallBackend(CeedElemRestrictionGetCurlOrientations(r, CEED_MEM_HOST, &curl_orients));
CeedCallBackend(CeedElemRestrictionGetCompStride(r, &comp_stride));
if (!orients && !curl_orients) {
CeedCallBackend(CeedElemRestrictionGetCompStride(r, &comp_stride));

CeedRestrictionType rstr_type;
CeedCallBackend(CeedElemRestrictionGetType(r, &rstr_type));
const CeedInt *offsets = NULL;
CeedCallBackend(CeedElemRestrictionGetOffsets(r, CEED_MEM_HOST, &offsets));
switch (rstr_type) {
case CEED_RESTRICTION_DEFAULT: {
CeedCallBackend(CeedElemRestrictionCreateBlocked(ceed, num_elem, elem_size, blk_size, num_comp, comp_stride, l_size, CEED_MEM_HOST,
CEED_COPY_VALUES, offsets, &blk_restr[i + start_e]));
} else if (!curl_orients) {
} break;
case CEED_RESTRICTION_ORIENTED: {
const bool *orients = NULL;
CeedCallBackend(CeedElemRestrictionGetOrientations(r, CEED_MEM_HOST, &orients));
CeedCallBackend(CeedElemRestrictionCreateBlockedOriented(ceed, num_elem, elem_size, blk_size, num_comp, comp_stride, l_size, CEED_MEM_HOST,
CEED_COPY_VALUES, offsets, orients, &blk_restr[i + start_e]));
} else {
CeedCallBackend(CeedElemRestrictionRestoreOrientations(r, &orients));
} break;
case CEED_RESTRICTION_CURL_ORIENTED: {
const CeedInt *curl_orients = NULL;
CeedCallBackend(CeedElemRestrictionGetCurlOrientations(r, CEED_MEM_HOST, &curl_orients));
CeedCallBackend(CeedElemRestrictionCreateBlockedCurlOriented(ceed, num_elem, elem_size, blk_size, num_comp, comp_stride, l_size,
CEED_MEM_HOST, CEED_COPY_VALUES, offsets, curl_orients,
&blk_restr[i + start_e]));
}
CeedCallBackend(CeedElemRestrictionRestoreOffsets(r, &offsets));
CeedCallBackend(CeedElemRestrictionRestoreOrientations(r, &orients));
CeedCallBackend(CeedElemRestrictionRestoreCurlOrientations(r, &curl_orients));
CeedCallBackend(CeedElemRestrictionRestoreCurlOrientations(r, &curl_orients));
} break;
case CEED_RESTRICTION_STRIDED: {
CeedInt strides[3];
CeedCallBackend(CeedElemRestrictionGetStrides(r, &strides));
CeedCallBackend(
CeedElemRestrictionCreateBlockedStrided(ceed, num_elem, elem_size, blk_size, num_comp, l_size, strides, &blk_restr[i + start_e]));
} break;
}
CeedCallBackend(CeedElemRestrictionRestoreOffsets(r, &offsets));
CeedCallBackend(CeedElemRestrictionCreateVector(blk_restr[i + start_e], NULL, &e_vecs_full[i + start_e]));
}

Expand Down
6 changes: 4 additions & 2 deletions backends/cuda-ref/ceed-cuda-restriction.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ static int CeedElemRestrictionOffset_Cuda(const CeedElemRestriction r, const Cee
//------------------------------------------------------------------------------
// Create restriction
//------------------------------------------------------------------------------
int CeedElemRestrictionCreate_Cuda(CeedMemType m_type, CeedCopyMode copy_mode, const CeedInt *indices, CeedElemRestriction r) {
int CeedElemRestrictionCreate_Cuda(CeedMemType m_type, CeedCopyMode copy_mode, const CeedInt *indices, const bool *orients,
const CeedInt *curl_orients, CeedElemRestriction r) {
Ceed ceed;
CeedCallBackend(CeedElemRestrictionGetCeed(r, &ceed));
CeedElemRestriction_Cuda *impl;
Expand Down Expand Up @@ -343,7 +344,8 @@ int CeedElemRestrictionCreate_Cuda(CeedMemType m_type, CeedCopyMode copy_mode, c
//------------------------------------------------------------------------------
// Blocked not supported
//------------------------------------------------------------------------------
int CeedElemRestrictionCreateBlocked_Cuda(const CeedMemType m_type, const CeedCopyMode copy_mode, const CeedInt *indices, CeedElemRestriction r) {
int CeedElemRestrictionCreateBlocked_Cuda(const CeedMemType m_type, const CeedCopyMode copy_mode, const CeedInt *indices, const bool *orients,
const CeedInt *curl_orients, CeedElemRestriction r) {
Ceed ceed;
CeedCallBackend(CeedElemRestrictionGetCeed(r, &ceed));
return CeedError(ceed, CEED_ERROR_BACKEND, "Backend does not implement blocked restrictions");
Expand Down
6 changes: 4 additions & 2 deletions backends/hip-ref/ceed-hip-ref-restriction.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ static int CeedElemRestrictionOffset_Hip(const CeedElemRestriction r, const Ceed
//------------------------------------------------------------------------------
// Create restriction
//------------------------------------------------------------------------------
int CeedElemRestrictionCreate_Hip(CeedMemType mtype, CeedCopyMode cmode, const CeedInt *indices, CeedElemRestriction r) {
int CeedElemRestrictionCreate_Hip(CeedMemType mtype, CeedCopyMode cmode, const CeedInt *indices, const bool *orients, const CeedInt *curl_orients,
CeedElemRestriction r) {
Ceed ceed;
CeedCallBackend(CeedElemRestrictionGetCeed(r, &ceed));
CeedElemRestriction_Hip *impl;
Expand Down Expand Up @@ -341,7 +342,8 @@ int CeedElemRestrictionCreate_Hip(CeedMemType mtype, CeedCopyMode cmode, const C
//------------------------------------------------------------------------------
// Blocked not supported
//------------------------------------------------------------------------------
int CeedElemRestrictionCreateBlocked_Hip(const CeedMemType mtype, const CeedCopyMode cmode, const CeedInt *indices, CeedElemRestriction r) {
int CeedElemRestrictionCreateBlocked_Hip(const CeedMemType mtype, const CeedCopyMode cmode, const CeedInt *indices, const bool *orients,
const CeedInt *curl_orients, CeedElemRestriction r) {
Ceed ceed;
CeedCallBackend(CeedElemRestrictionGetCeed(r, &ceed));
return CeedError(ceed, CEED_ERROR_BACKEND, "Backend does not implement blocked restrictions");
Expand Down
6 changes: 4 additions & 2 deletions backends/magma/ceed-magma-restriction.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ static int CeedElemRestrictionDestroy_Magma(CeedElemRestriction r) {
return CEED_ERROR_SUCCESS;
}

int CeedElemRestrictionCreate_Magma(CeedMemType mtype, CeedCopyMode cmode, const CeedInt *offsets, CeedElemRestriction r) {
int CeedElemRestrictionCreate_Magma(CeedMemType mtype, CeedCopyMode cmode, const CeedInt *offsets, const bool *orients, const CeedInt *curl_orients,
CeedElemRestriction r) {
Ceed ceed;
CeedCallBackend(CeedElemRestrictionGetCeed(r, &ceed));

Expand Down Expand Up @@ -278,7 +279,8 @@ int CeedElemRestrictionCreate_Magma(CeedMemType mtype, CeedCopyMode cmode, const
return CEED_ERROR_SUCCESS;
}

int CeedElemRestrictionCreateBlocked_Magma(const CeedMemType mtype, const CeedCopyMode cmode, const CeedInt *offsets, const CeedElemRestriction r) {
int CeedElemRestrictionCreateBlocked_Magma(const CeedMemType mtype, const CeedCopyMode cmode, const CeedInt *offsets, const bool *orients,
const CeedInt *curl_orients, const CeedElemRestriction r) {
Ceed ceed;
CeedCallBackend(CeedElemRestrictionGetCeed(r, &ceed));
return CeedError(ceed, CEED_ERROR_BACKEND, "Backend does not implement blocked restrictions");
Expand Down
50 changes: 26 additions & 24 deletions backends/opt/ceed-opt-operator.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,45 +42,47 @@ static int CeedOperatorSetupFields_Opt(CeedQFunction qf, CeedOperator op, bool i

if (eval_mode != CEED_EVAL_WEIGHT) {
CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_fields[i], &r));
Ceed ceed;
CeedCallBackend(CeedElemRestrictionGetCeed(r, &ceed));
CeedSize l_size;
CeedInt num_elem, elem_size, comp_stride;
CeedCallBackend(CeedElemRestrictionGetNumElements(r, &num_elem));
CeedCallBackend(CeedElemRestrictionGetElementSize(r, &elem_size));
CeedCallBackend(CeedElemRestrictionGetLVectorSize(r, &l_size));
CeedCallBackend(CeedElemRestrictionGetNumComponents(r, &num_comp));

bool strided;
CeedCallBackend(CeedElemRestrictionIsStrided(r, &strided));
if (strided) {
CeedInt strides[3];
CeedCallBackend(CeedElemRestrictionGetStrides(r, &strides));
CeedCallBackend(
CeedElemRestrictionCreateBlockedStrided(ceed, num_elem, elem_size, blk_size, num_comp, l_size, strides, &blk_restr[i + start_e]));
} else {
const CeedInt *offsets = NULL;
const bool *orients = NULL;
const CeedInt *curl_orients = NULL;
CeedCallBackend(CeedElemRestrictionGetOffsets(r, CEED_MEM_HOST, &offsets));
CeedCallBackend(CeedElemRestrictionGetOrientations(r, CEED_MEM_HOST, &orients));
CeedCallBackend(CeedElemRestrictionGetCurlOrientations(r, CEED_MEM_HOST, &curl_orients));
CeedCallBackend(CeedElemRestrictionGetCompStride(r, &comp_stride));
if (!orients && !curl_orients) {
CeedCallBackend(CeedElemRestrictionGetCompStride(r, &comp_stride));

CeedRestrictionType rstr_type;
CeedCallBackend(CeedElemRestrictionGetType(r, &rstr_type));
const CeedInt *offsets = NULL;
CeedCallBackend(CeedElemRestrictionGetOffsets(r, CEED_MEM_HOST, &offsets));
switch (rstr_type) {
case CEED_RESTRICTION_DEFAULT: {
CeedCallBackend(CeedElemRestrictionCreateBlocked(ceed, num_elem, elem_size, blk_size, num_comp, comp_stride, l_size, CEED_MEM_HOST,
CEED_COPY_VALUES, offsets, &blk_restr[i + start_e]));
} else if (!curl_orients) {
} break;
case CEED_RESTRICTION_ORIENTED: {
const bool *orients = NULL;
CeedCallBackend(CeedElemRestrictionGetOrientations(r, CEED_MEM_HOST, &orients));
CeedCallBackend(CeedElemRestrictionCreateBlockedOriented(ceed, num_elem, elem_size, blk_size, num_comp, comp_stride, l_size, CEED_MEM_HOST,
CEED_COPY_VALUES, offsets, orients, &blk_restr[i + start_e]));
} else {
CeedCallBackend(CeedElemRestrictionRestoreOrientations(r, &orients));
} break;
case CEED_RESTRICTION_CURL_ORIENTED: {
const CeedInt *curl_orients = NULL;
CeedCallBackend(CeedElemRestrictionGetCurlOrientations(r, CEED_MEM_HOST, &curl_orients));
CeedCallBackend(CeedElemRestrictionCreateBlockedCurlOriented(ceed, num_elem, elem_size, blk_size, num_comp, comp_stride, l_size,
CEED_MEM_HOST, CEED_COPY_VALUES, offsets, curl_orients,
&blk_restr[i + start_e]));
}
CeedCallBackend(CeedElemRestrictionRestoreOffsets(r, &offsets));
CeedCallBackend(CeedElemRestrictionRestoreOrientations(r, &orients));
CeedCallBackend(CeedElemRestrictionRestoreCurlOrientations(r, &curl_orients));
CeedCallBackend(CeedElemRestrictionRestoreCurlOrientations(r, &curl_orients));
} break;
case CEED_RESTRICTION_STRIDED: {
CeedInt strides[3];
CeedCallBackend(CeedElemRestrictionGetStrides(r, &strides));
CeedCallBackend(
CeedElemRestrictionCreateBlockedStrided(ceed, num_elem, elem_size, blk_size, num_comp, l_size, strides, &blk_restr[i + start_e]));
} break;
}
CeedCallBackend(CeedElemRestrictionRestoreOffsets(r, &offsets));
CeedCallBackend(CeedElemRestrictionCreateVector(blk_restr[i + start_e], NULL, &e_vecs_full[i + start_e]));
}

Expand Down

0 comments on commit 0534fe3

Please sign in to comment.