xref: /petsc/src/sys/objects/device/impls/host/hostcontext.cxx (revision aa16454f2191670bfeae7f535172792cf3e6e0ea)
1 #include <petsc/private/deviceimpl.h>
2 
3 #include <petsc/private/cpp/macros.hpp>
4 #include <petsc/private/cpp/utility.hpp>
5 
6 namespace Petsc {
7 
8 namespace device {
9 
10 namespace host {
11 
12 namespace impl {
13 
14 class DeviceContext {
15 public:
16   PETSC_CXX_COMPAT_DECL(PetscErrorCode destroy(PetscDeviceContext)) { return 0; }
17   PETSC_CXX_COMPAT_DECL(PetscErrorCode changeStreamType(PetscDeviceContext, PetscStreamType)) { return 0; }
18   PETSC_CXX_COMPAT_DECL(PetscErrorCode setUp(PetscDeviceContext)) { return 0; }
19   PETSC_CXX_COMPAT_DECL(PetscErrorCode query(PetscDeviceContext, PetscBool *idle)) {
20     PetscFunctionBegin;
21     *idle = PETSC_TRUE; // the host is always idle
22     PetscFunctionReturn(0);
23   }
24   PETSC_CXX_COMPAT_DECL(PetscErrorCode waitForContext(PetscDeviceContext, PetscDeviceContext)) { return 0; }
25   PETSC_CXX_COMPAT_DECL(PetscErrorCode synchronize(PetscDeviceContext)) { return 0; }
26   PETSC_CXX_COMPAT_DECL(PetscErrorCode getBlasHandle(PetscDeviceContext, void *)) { SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, "Not implemented"); }
27   PETSC_CXX_COMPAT_DECL(PetscErrorCode getSolverHandle(PetscDeviceContext, void *)) { SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, "Not implemented"); }
28   PETSC_CXX_COMPAT_DECL(PetscErrorCode getStreamHandle(PetscDeviceContext, void *)) { SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, "Not implemented"); }
29   PETSC_CXX_COMPAT_DECL(PetscErrorCode beginTimer(PetscDeviceContext)) { SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, "Not implemented"); }
30   PETSC_CXX_COMPAT_DECL(PetscErrorCode endTimer(PetscDeviceContext, PetscLogDouble *)) { SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, "Not implemented"); }
31 
32   const _DeviceContextOps ops = {destroy, changeStreamType, setUp, query, waitForContext, synchronize, getBlasHandle, getSolverHandle, getStreamHandle, beginTimer, endTimer, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr};
33 };
34 
35 } // namespace impl
36 
37 } // namespace host
38 
39 } // namespace device
40 
41 } // namespace Petsc
42 
43 PetscErrorCode PetscDeviceContextCreate_HOST(PetscDeviceContext dctx) {
44   static constexpr auto hostctx = ::Petsc::device::host::impl::DeviceContext{};
45 
46   PetscFunctionBegin;
47   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);
48   PetscCall(PetscArraycpy(dctx->ops, &hostctx.ops, 1));
49   PetscFunctionReturn(0);
50 }
51