Actual source code: sycldevice.hpp

  1: #pragma once

  3: #include "../impldevicebase.hpp" /* I "petscdevice.h" */

  5: #include <array>

  7: namespace Petsc
  8: {

 10: namespace device
 11: {

 13: namespace sycl
 14: {

 16: #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
 17: #define PETSC_SYCL_DEVICE_NONE -3

 19: class Device : public ::Petsc::device::impl::DeviceBase<Device> {
 20: public:
 21:   PETSC_DEVICE_IMPL_BASE_CLASS_HEADER(base_type, Device);

 23:   ~Device() { auto PETSC_UNUSED _ = finalize_(); }

 25:   static PetscErrorCode initialize(MPI_Comm, PetscInt *, PetscBool *, PetscDeviceInitType *) noexcept;

 27: private:
 28:   // opaque class representing a single device instance
 29:   class DeviceInternal;

 31:   // currently stores sycl host and gpu devices
 32:   static std::array<DeviceInternal *, PETSC_DEVICE_MAX_DEVICES> devices_array_;
 33:   static DeviceInternal                                       **devices_; // alias to devices_array_, but shifted to support devices_[-1] for sycl host device

 35:   // this rank's default device. If equals to PETSC_SYCL_DEVICE_NONE, then all sycl devices are disabled
 36:   static int defaultDevice_;

 38:   // have we tried looking for devices
 39:   static bool initialized_;

 41:   // clean-up
 42:   static PetscErrorCode finalize_() noexcept;

 44:   PETSC_CXX_COMPAT_DECL(constexpr PetscDeviceType PETSC_DEVICE_IMPL_()) { return PETSC_DEVICE_SYCL; }
 45:   PetscErrorCode        init_device_id_(PetscInt *) const noexcept;
 46:   static PetscErrorCode view_device_(PetscDevice, PetscViewer) noexcept;
 47:   static PetscErrorCode get_attribute_(PetscInt, PetscDeviceAttribute, void *) noexcept;
 48: };

 50: } // namespace sycl

 52: } // namespace device

 54: } // namespace Petsc