xref: /petsc/src/sys/objects/device/impls/host/hostcontext.cxx (revision 1cc06b555e92f8ec64db10330b8bbd830e5bc876)
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   static constexpr _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 constexpr _DeviceContextOps DeviceContext::ops;
56 
57 } // namespace impl
58 
59 } // namespace host
60 
61 } // namespace device
62 
63 } // namespace Petsc
64 
65 PetscErrorCode PetscDeviceContextCreate_HOST(PetscDeviceContext dctx)
66 {
67   static constexpr auto hostctx = ::Petsc::device::host::impl::DeviceContext{};
68 
69   PetscFunctionBegin;
70   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);
71   *dctx->ops = hostctx.ops;
72   PetscFunctionReturn(PETSC_SUCCESS);
73 }
74