Actual source code: hostcontext.cxx

  1: #include <petsc/private/deviceimpl.h>

  3: #include <petsc/private/cpp/macros.hpp>
  4: #include <petsc/private/cpp/utility.hpp>

  6: namespace Petsc
  7: {

  9: namespace device
 10: {

 12: namespace host
 13: {

 15: namespace impl
 16: {

 18: class DeviceContext {
 19: public:
 20:   PETSC_CXX_COMPAT_DECL(PetscErrorCode destroy(PetscDeviceContext)) { return 0; }
 21:   PETSC_CXX_COMPAT_DECL(PetscErrorCode changeStreamType(PetscDeviceContext, PetscStreamType)) { return 0; }
 22:   PETSC_CXX_COMPAT_DECL(PetscErrorCode setUp(PetscDeviceContext)) { return 0; }
 23:   PETSC_CXX_COMPAT_DECL(PetscErrorCode query(PetscDeviceContext, PetscBool *idle))
 24:   {
 25:     *idle = PETSC_TRUE; // the host is always idle
 26:     return 0;
 27:   }
 28:   PETSC_CXX_COMPAT_DECL(PetscErrorCode waitForContext(PetscDeviceContext, PetscDeviceContext)) { return 0; }
 29:   PETSC_CXX_COMPAT_DECL(PetscErrorCode synchronize(PetscDeviceContext)) { return 0; }
 30:   PETSC_CXX_COMPAT_DECL(PetscErrorCode getBlasHandle(PetscDeviceContext, void *)) { SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, "Not implemented"); }
 31:   PETSC_CXX_COMPAT_DECL(PetscErrorCode getSolverHandle(PetscDeviceContext, void *)) { SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, "Not implemented"); }
 32:   PETSC_CXX_COMPAT_DECL(PetscErrorCode getStreamHandle(PetscDeviceContext, void *)) { SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, "Not implemented"); }
 33:   PETSC_CXX_COMPAT_DECL(PetscErrorCode beginTimer(PetscDeviceContext)) { SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, "Not implemented"); }
 34:   PETSC_CXX_COMPAT_DECL(PetscErrorCode endTimer(PetscDeviceContext, PetscLogDouble *)) { SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, "Not implemented"); }

 36:   const _DeviceContextOps ops = {destroy, changeStreamType, setUp, query, waitForContext, synchronize, getBlasHandle, getSolverHandle, getStreamHandle, beginTimer, endTimer, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr};
 37: };

 39: } // namespace impl

 41: } // namespace host

 43: } // namespace device

 45: } // namespace Petsc

 47: PetscErrorCode PetscDeviceContextCreate_HOST(PetscDeviceContext dctx)
 48: {
 49:   static constexpr auto hostctx = ::Petsc::device::host::impl::DeviceContext{};

 51:   PetscAssert(!dctx->data, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "PetscDeviceContext %" PetscInt64_FMT " is of type host, but still has data member %p", PetscObjectCast(dctx)->id, dctx->data);
 52:   PetscArraycpy(dctx->ops, &hostctx.ops, 1);
 53:   return 0;
 54: }