xref: /petsc/src/sys/objects/device/impls/host/hostcontext.cxx (revision 0619917b5a674bb687c64e7daba2ab22be99af31)
1 #include <petsc/private/deviceimpl.h>
2 
3 #include <petsc/private/cpp/utility.hpp> // PetscObjectCast()
4 
5 namespace Petsc
6 {
7 
8 namespace device
9 {
10 
11 namespace host
12 {
13 
14 namespace impl
15 {
16 
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; }
30 
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(memalloc, nullptr),
45     PetscDesignatedInitializer(memfree, nullptr),
46     PetscDesignatedInitializer(memcopy, nullptr),
47     PetscDesignatedInitializer(memset, nullptr),
48     PetscDesignatedInitializer(createevent, nullptr),
49     PetscDesignatedInitializer(recordevent, nullptr),
50     PetscDesignatedInitializer(waitforevent, nullptr)
51   };
52   // clang-format on
53 };
54 
55 } // namespace impl
56 
57 } // namespace host
58 
59 } // namespace device
60 
61 } // namespace Petsc
62 
63 PetscErrorCode PetscDeviceContextCreate_HOST(PetscDeviceContext dctx)
64 {
65   static constexpr auto hostctx = ::Petsc::device::host::impl::DeviceContext{};
66 
67   PetscFunctionBegin;
68   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);
69   *dctx->ops = hostctx.ops;
70   PetscFunctionReturn(PETSC_SUCCESS);
71 }
72