Actual source code: hostcontext.cxx

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

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

      5: namespace Petsc
      6: {

      8: namespace device
      9: {

     11: namespace host
     12: {

     14: namespace impl
     15: {

     17: class DeviceContext {
     18: public:
     19:   static PetscErrorCode destroy(PetscDeviceContext) noexcept { return PETSC_SUCCESS; }
     20:   static PetscErrorCode changeStreamType(PetscDeviceContext, PetscStreamType) noexcept { return PETSC_SUCCESS; }
     21:   static PetscErrorCode setUp(PetscDeviceContext) noexcept { return PETSC_SUCCESS; }
     22:   static PetscErrorCode query(PetscDeviceContext, PetscBool *idle) noexcept
     23:   {
     24:     PetscFunctionBegin;
     25:     *idle = PETSC_TRUE; // the host is always idle
     26:     PetscFunctionReturn(PETSC_SUCCESS);
     27:   }
     28:   static PetscErrorCode waitForContext(PetscDeviceContext, PetscDeviceContext) noexcept { return PETSC_SUCCESS; }
     29:   static PetscErrorCode synchronize(PetscDeviceContext) noexcept { return PETSC_SUCCESS; }

     31:   // clang-format off
     32:   const _DeviceContextOps ops = {
     33:     PetscDesignatedInitializer(destroy, destroy),
     34:     PetscDesignatedInitializer(changestreamtype, changeStreamType),
     35:     PetscDesignatedInitializer(setup, setUp),
     36:     PetscDesignatedInitializer(query, query),
     37:     PetscDesignatedInitializer(waitforcontext, waitForContext),
     38:     PetscDesignatedInitializer(synchronize, synchronize),
     39:     PetscDesignatedInitializer(getblashandle, nullptr),
     40:     PetscDesignatedInitializer(getsolverhandle, nullptr),
     41:     PetscDesignatedInitializer(getstreamhandle, nullptr),
     42:     PetscDesignatedInitializer(begintimer, nullptr),
     43:     PetscDesignatedInitializer(endtimer, nullptr),
     44:     PetscDesignatedInitializer(getpower, nullptr),
     45:     PetscDesignatedInitializer(beginenergymeter, nullptr),
     46:     PetscDesignatedInitializer(endenergymeter, nullptr),
     47:     PetscDesignatedInitializer(memalloc, nullptr),
     48:     PetscDesignatedInitializer(memfree, nullptr),
     49:     PetscDesignatedInitializer(memcopy, nullptr),
     50:     PetscDesignatedInitializer(memset, nullptr),
     51:     PetscDesignatedInitializer(createevent, nullptr),
     52:     PetscDesignatedInitializer(recordevent, nullptr),
     53:     PetscDesignatedInitializer(waitforevent, nullptr)
     54:   };
     55:   // clang-format on
     56: };

     58: } // namespace impl

     60: } // namespace host

     62: } // namespace device

     64: } // namespace Petsc

     66: PetscErrorCode PetscDeviceContextCreate_HOST(PetscDeviceContext dctx)
     67: {
     68:   static constexpr auto hostctx = ::Petsc::device::host::impl::DeviceContext{};

     70:   PetscFunctionBegin;
     71:   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);
     72:   *dctx->ops = hostctx.ops;
     73:   PetscFunctionReturn(PETSC_SUCCESS);
     74: }