Actual source code: syclcontext.sycl.cxx
1: #include "../../interface/sycldevice.hpp"
2: #include <CL/sycl.hpp>
4: namespace Petsc
5: {
7: namespace Device
8: {
10: namespace SYCL
11: {
13: namespace Impl
14: {
16: class DeviceContext
17: {
18: public:
19: struct PetscDeviceContext_IMPLS {
20: sycl::event event;
21: sycl::event begin; // timer-only
22: sycl::event end; // timer-only
23: #if PetscDefined(USE_DEBUG)
24: PetscBool timerInUse;
25: #endif
26: };
28: private:
29: static bool initialized_;
31: PETSC_NODISCARD static PetscErrorCode finalize_() noexcept
32: {
33: initialized_ = false;
34: return 0;
35: }
37: PETSC_NODISCARD static PetscErrorCode initialize_(PetscInt id, DeviceContext *dci) noexcept
38: {
39: PetscDeviceCheckDeviceCount_Internal(id);
40: if (!initialized_) {
41: initialized_ = true;
42: PetscRegisterFinalize(finalize_);
43: }
44: return 0;
45: }
47: public:
48: const struct _DeviceContextOps ops = {
49: destroy,
50: changeStreamType,
51: setUp,
52: query,
53: waitForContext,
54: synchronize,
55: getBlasHandle,
56: getSolverHandle,
57: getStreamHandle,
58: beginTimer,
59: endTimer
60: };
62: // default constructor
63: DeviceContext() noexcept = default;
65: // All of these functions MUST be static in order to be callable from C, otherwise they
66: // get the implicit 'this' pointer tacked on
67: PETSC_NODISCARD static PetscErrorCode destroy(PetscDeviceContext dctx) noexcept
68: {
69: delete static_cast<PetscDeviceContext_IMPLS*>(dctx->data);
70: dctx->data = nullptr;
71: return 0;
72: };
73: PETSC_NODISCARD static PetscErrorCode changeStreamType(PetscDeviceContext,PetscStreamType) noexcept { SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Not implemented"); };
74: PETSC_NODISCARD static PetscErrorCode setUp(PetscDeviceContext) noexcept {return 0;}; // Nothing to setup
75: PETSC_NODISCARD static PetscErrorCode query(PetscDeviceContext,PetscBool*) noexcept { SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Not implemented"); };
76: PETSC_NODISCARD static PetscErrorCode waitForContext(PetscDeviceContext,PetscDeviceContext) noexcept { SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Not implemented"); };
77: PETSC_NODISCARD static PetscErrorCode synchronize(PetscDeviceContext) noexcept { SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Not implemented"); };
78: PETSC_NODISCARD static PetscErrorCode getBlasHandle(PetscDeviceContext,void*) noexcept { SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Not implemented"); };
79: PETSC_NODISCARD static PetscErrorCode getSolverHandle(PetscDeviceContext,void*) noexcept { SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Not implemented"); };
80: PETSC_NODISCARD static PetscErrorCode getStreamHandle(PetscDeviceContext,void*) noexcept { SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Not implemented"); };
81: PETSC_NODISCARD static PetscErrorCode beginTimer(PetscDeviceContext) noexcept { SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Not implemented"); };
82: PETSC_NODISCARD static PetscErrorCode endTimer(PetscDeviceContext,PetscLogDouble*) noexcept { SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Not implemented"); };
83: };
85: } // namespace Impl
87: } // namespace SYCL
89: } // namespace Device
91: } // namespace Petsc
93: PetscErrorCode PetscDeviceContextCreate_SYCL(PetscDeviceContext dctx)
94: {
95: using namespace Petsc::Device::SYCL::Impl;
97: static const DeviceContext syclctx;
99: dctx->data = new DeviceContext::PetscDeviceContext_IMPLS();
100: PetscMemcpy(dctx->ops,&syclctx.ops,sizeof(syclctx.ops));
101: return 0;
102: }