Actual source code: cupmdevice.hpp
1: #ifndef PETSCCUPMDEVICE_HPP
2: #define PETSCCUPMDEVICE_HPP
4: #if defined(__cplusplus)
5: #include <petsc/private/cupminterface.hpp>
6: #include <petsc/private/cpp/memory.hpp>
7: #include <petsc/private/cpp/array.hpp>
9: #include "../impldevicebase.hpp" /* I "petscdevice.h" */
11: namespace Petsc
12: {
14: namespace device
15: {
17: namespace cupm
18: {
20: #if defined(PETSC_CUPM_DEVICE_NONE)
21: #error redefinition of PETSC_CUPM_DEVICE_NONE
22: #endif
24: #define PETSC_CUPM_DEVICE_NONE -3
26: template <DeviceType T>
27: class Device : public ::Petsc::device::impl::DeviceBase<Device<T>>, impl::Interface<T> {
28: public:
29: PETSC_DEVICE_IMPL_BASE_CLASS_HEADER(base_type, Device<T>);
30: PETSC_CUPM_INHERIT_INTERFACE_TYPEDEFS_USING(cupmInterface_t, T);
32: PETSC_NODISCARD static PetscErrorCode initialize(MPI_Comm, PetscInt *, PetscBool *, PetscDeviceInitType *) noexcept;
34: private:
35: // opaque class representing a single device
36: class DeviceInternal;
38: // all known devices
39: using devices_type = std::array<std::unique_ptr<DeviceInternal>, PETSC_DEVICE_MAX_DEVICES>;
40: static devices_type devices_;
42: // this ranks default device, if < 0 then devices are specifically disabled
43: static int defaultDevice_;
45: // have we tried looking for devices
46: static bool initialized_;
48: // clean-up
49: PETSC_NODISCARD static PetscErrorCode finalize_() noexcept;
51: PETSC_NODISCARD static constexpr PetscDeviceType PETSC_DEVICE_IMPL_() noexcept { return PETSC_DEVICE_CUPM(); }
53: PETSC_NODISCARD PetscErrorCode init_device_id_(PetscInt *) const noexcept;
54: PETSC_NODISCARD static PetscErrorCode configure_device_(PetscDevice) noexcept;
55: PETSC_NODISCARD static PetscErrorCode view_device_(PetscDevice, PetscViewer) noexcept;
56: PETSC_NODISCARD static PetscErrorCode get_attribute_(PetscInt, PetscDeviceAttribute, void *) noexcept;
57: };
59: // define static variables
60: template <DeviceType T>
61: typename Device<T>::devices_type Device<T>::devices_ = {};
63: template <DeviceType T>
64: int Device<T>::defaultDevice_ = PETSC_CUPM_DEVICE_NONE;
66: template <DeviceType T>
67: bool Device<T>::initialized_ = false;
69: } // namespace cupm
71: } // namespace device
73: } // namespace Petsc
75: #endif // __cplusplus
77: #endif /* PETSCCUPMDEVICE_HPP */