1 #ifndef PETSCSYCLDEVICE_HPP 2 #define PETSCSYCLDEVICE_HPP 3 4 #if defined(__cplusplus) 5 #include "../impldevicebase.hpp" /* I "petscdevice.h" */ 6 7 #include <array> 8 9 namespace Petsc { 10 11 namespace device { 12 13 namespace sycl { 14 15 #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 16 #define PETSC_SYCL_DEVICE_NONE -3 17 18 class Device : public ::Petsc::device::impl::DeviceBase<Device> { 19 public: 20 PETSC_DEVICE_IMPL_BASE_CLASS_HEADER(base_type, Device); 21 22 ~Device() { auto PETSC_UNUSED _ = finalize_(); } 23 24 PETSC_NODISCARD static PetscErrorCode initialize(MPI_Comm, PetscInt *, PetscBool *, PetscDeviceInitType *) noexcept; 25 26 private: 27 // opaque class representing a single device instance 28 class DeviceInternal; 29 30 // currently stores sycl host and gpu devices 31 static std::array<DeviceInternal *, PETSC_DEVICE_MAX_DEVICES> devices_array_; 32 static DeviceInternal **devices_; // alias to devices_array_, but shifted to support devices_[-1] for sycl host device 33 34 // this rank's default device. If equals to PETSC_SYCL_DEVICE_NONE, then all sycl devices are disabled 35 static int defaultDevice_; 36 37 // have we tried looking for devices 38 static bool initialized_; 39 40 // clean-up 41 PETSC_NODISCARD static PetscErrorCode finalize_() noexcept; 42 43 PETSC_CXX_COMPAT_DECL(constexpr PetscDeviceType PETSC_DEVICE_IMPL_()) { return PETSC_DEVICE_SYCL; } 44 PETSC_NODISCARD PetscErrorCode init_device_id_(PetscInt *) const noexcept; 45 PETSC_NODISCARD static PetscErrorCode view_device_(PetscDevice, PetscViewer) noexcept; 46 PETSC_NODISCARD static PetscErrorCode get_attribute_(PetscInt, PetscDeviceAttribute, void *) noexcept; 47 }; 48 49 } // namespace sycl 50 51 } // namespace device 52 53 } // namespace Petsc 54 55 #endif // __cplusplus 56 57 #endif /* PETSCSYCLDEVICE_HPP */ 58