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(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: };
55: } // namespace impl
57: } // namespace host
59: } // namespace device
61: } // namespace Petsc
63: PetscErrorCode PetscDeviceContextCreate_HOST(PetscDeviceContext dctx)
64: {
65: static constexpr auto hostctx = ::Petsc::device::host::impl::DeviceContext{};
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: }