Skip to content

Commit

Permalink
sycl - use switch for enums
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylt committed Jan 30, 2024
1 parent ec27d2c commit 29b978c
Showing 1 changed file with 39 additions and 37 deletions.
76 changes: 39 additions & 37 deletions backends/sycl-ref/ceed-sycl-restriction.sycl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,8 @@ int CeedElemRestrictionCreate_Sycl(CeedMemType mem_type, CeedCopyMode copy_mode,
CeedCallBackend(CeedElemRestrictionSetELayout(rstr, layout));

// Set up device indices/offset arrays
if (mem_type == CEED_MEM_HOST) {
switch (mem_type)
case CEED_MEM_HOST: {
switch (copy_mode) {
case CEED_OWN_POINTER:
impl->h_ind_allocated = (CeedInt *)indices;
Expand Down Expand Up @@ -411,44 +412,45 @@ int CeedElemRestrictionCreate_Sycl(CeedMemType mem_type, CeedCopyMode copy_mode,
CeedCallSycl(ceed, copy_event.wait_and_throw());
CeedCallBackend(CeedElemRestrictionOffset_Sycl(rstr, indices));
}
} else if (mem_type == CEED_MEM_DEVICE) {
switch (copy_mode) {
case CEED_COPY_VALUES:
if (indices != NULL) {
CeedCallSycl(ceed, impl->d_ind = sycl::malloc_device<CeedInt>(size, data->sycl_device, data->sycl_context));
impl->d_ind_allocated = impl->d_ind; // We own the device memory
// Copy from device to device
// Order queue
sycl::event e = data->sycl_queue.ext_oneapi_submit_barrier();
sycl::event copy_event = data->sycl_queue.copy<CeedInt>(indices, impl->d_ind, size, {e});
// Wait for copy to finish and handle exceptions
CeedCallSycl(ceed, copy_event.wait_and_throw());
}
break;
case CEED_OWN_POINTER:
impl->d_ind = (CeedInt *)indices;
impl->d_ind_allocated = impl->d_ind;
break;
case CEED_USE_POINTER:
impl->d_ind = (CeedInt *)indices;
}
if (indices != NULL) {
CeedCallBackend(CeedMalloc(elem_size * num_elem, &impl->h_ind_allocated));
// Order queue
sycl::event e = data->sycl_queue.ext_oneapi_submit_barrier();
// Copy from device to host
sycl::event copy_event = data->sycl_queue.copy<CeedInt>(impl->d_ind, impl->h_ind_allocated, elem_size * num_elem, {e});
CeedCallSycl(ceed, copy_event.wait_and_throw());
impl->h_ind = impl->h_ind_allocated;
CeedCallBackend(CeedElemRestrictionOffset_Sycl(rstr, indices));
}
} break;
case CEED_MEM_DEVICE): {
switch (copy_mode) {
case CEED_COPY_VALUES:
if (indices != NULL) {
CeedCallSycl(ceed, impl->d_ind = sycl::malloc_device<CeedInt>(size, data->sycl_device, data->sycl_context));
impl->d_ind_allocated = impl->d_ind; // We own the device memory
// Copy from device to device
// Order queue
sycl::event e = data->sycl_queue.ext_oneapi_submit_barrier();
sycl::event copy_event = data->sycl_queue.copy<CeedInt>(indices, impl->d_ind, size, {e});
// Wait for copy to finish and handle exceptions
CeedCallSycl(ceed, copy_event.wait_and_throw());
}
break;
case CEED_OWN_POINTER:
impl->d_ind = (CeedInt *)indices;
impl->d_ind_allocated = impl->d_ind;
break;
case CEED_USE_POINTER:
impl->d_ind = (CeedInt *)indices;
}
if (indices != NULL) {
CeedCallBackend(CeedMalloc(elem_size * num_elem, &impl->h_ind_allocated));
// Order queue
sycl::event e = data->sycl_queue.ext_oneapi_submit_barrier();
// Copy from device to host
sycl::event copy_event = data->sycl_queue.copy<CeedInt>(impl->d_ind, impl->h_ind_allocated, elem_size * num_elem, {e});
CeedCallSycl(ceed, copy_event.wait_and_throw());
impl->h_ind = impl->h_ind_allocated;
CeedCallBackend(CeedElemRestrictionOffset_Sycl(rstr, indices));
}
}

// Register backend functions
CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "ElemRestriction", rstr, "Apply", CeedElemRestrictionApply_Sycl));
CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "ElemRestriction", rstr, "ApplyUnsigned", CeedElemRestrictionApply_Sycl));
CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "ElemRestriction", rstr, "ApplyUnoriented", CeedElemRestrictionApply_Sycl));
CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "ElemRestriction", rstr, "GetOffsets", CeedElemRestrictionGetOffsets_Sycl));
CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "ElemRestriction", rstr, "Destroy", CeedElemRestrictionDestroy_Sycl));
return CEED_ERROR_SUCCESS;
CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "ElemRestriction", rstr, "ApplyUnsigned", CeedElemRestrictionApply_Sycl));
CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "ElemRestriction", rstr, "ApplyUnoriented", CeedElemRestrictionApply_Sycl));
CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "ElemRestriction", rstr, "GetOffsets", CeedElemRestrictionGetOffsets_Sycl));
CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "ElemRestriction", rstr, "Destroy", CeedElemRestrictionDestroy_Sycl));
return CEED_ERROR_SUCCESS;
}

0 comments on commit 29b978c

Please sign in to comment.