Actual source code: sycldevice.hpp
1: #ifndef PETSCSYCLDEVICE_HPP
2: #define PETSCSYCLDEVICE_HPP
4: #if defined(__cplusplus)
5: #include "../impldevicebase.hpp" /* I "petscdevice.h" */
7: #include <array>
9: namespace Petsc
10: {
12: namespace device
13: {
15: namespace sycl
16: {
18: #define PETSC_SYCL_DEVICE_HOST -1 // Note -1 is also used by PETSC_DECIDE, so user needs to pass -2 to explicitly select the host
19: #define PETSC_SYCL_DEVICE_NONE -3
21: class Device : public ::Petsc::device::impl::DeviceBase<Device> {
22: public:
23: PETSC_DEVICE_IMPL_BASE_CLASS_HEADER(base_type, Device);
25: ~Device() { auto PETSC_UNUSED _ = finalize_(); }
27: static PetscErrorCode initialize(MPI_Comm, PetscInt *, PetscBool *, PetscDeviceInitType *) noexcept;
29: private:
30: // opaque class representing a single device instance
31: class DeviceInternal;
33: // currently stores sycl host and gpu devices
34: static std::array<DeviceInternal *, PETSC_DEVICE_MAX_DEVICES> devices_array_;
35: static DeviceInternal **devices_; // alias to devices_array_, but shifted to support devices_[-1] for sycl host device
37: // this rank's default device. If equals to PETSC_SYCL_DEVICE_NONE, then all sycl devices are disabled
38: static int defaultDevice_;
40: // have we tried looking for devices
41: static bool initialized_;
43: // clean-up
44: static PetscErrorCode finalize_() noexcept;
46: PETSC_CXX_COMPAT_DECL(constexpr PetscDeviceType PETSC_DEVICE_IMPL_()) { return PETSC_DEVICE_SYCL; }
47: PetscErrorCode init_device_id_(PetscInt *) const noexcept;
48: static PetscErrorCode view_device_(PetscDevice, PetscViewer) noexcept;
49: static PetscErrorCode get_attribute_(PetscInt, PetscDeviceAttribute, void *) noexcept;
50: };
52: } // namespace sycl
54: } // namespace device
56: } // namespace Petsc
58: #endif // __cplusplus
60: #endif /* PETSCSYCLDEVICE_HPP */