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 12 namespace device 13 { 14 15 namespace sycl 16 { 17 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 20 21 class Device : public ::Petsc::device::impl::DeviceBase<Device> { 22 public: 23 PETSC_DEVICE_IMPL_BASE_CLASS_HEADER(base_type, Device); 24 25 ~Device() { auto PETSC_UNUSED _ = finalize_(); } 26 27 PETSC_NODISCARD static PetscErrorCode initialize(MPI_Comm, PetscInt *, PetscBool *, PetscDeviceInitType *) noexcept; 28 29 private: 30 // opaque class representing a single device instance 31 class DeviceInternal; 32 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 36 37 // this rank's default device. If equals to PETSC_SYCL_DEVICE_NONE, then all sycl devices are disabled 38 static int defaultDevice_; 39 40 // have we tried looking for devices 41 static bool initialized_; 42 43 // clean-up 44 PETSC_NODISCARD static PetscErrorCode finalize_() noexcept; 45 46 PETSC_CXX_COMPAT_DECL(constexpr PetscDeviceType PETSC_DEVICE_IMPL_()) { return PETSC_DEVICE_SYCL; } 47 PETSC_NODISCARD PetscErrorCode init_device_id_(PetscInt *) const noexcept; 48 PETSC_NODISCARD static PetscErrorCode view_device_(PetscDevice, PetscViewer) noexcept; 49 PETSC_NODISCARD static PetscErrorCode get_attribute_(PetscInt, PetscDeviceAttribute, void *) noexcept; 50 }; 51 52 } // namespace sycl 53 54 } // namespace device 55 56 } // namespace Petsc 57 58 #endif // __cplusplus 59 60 #endif /* PETSCSYCLDEVICE_HPP */ 61