Actual source code: cupmdevice.hpp
1: #pragma once
3: #include <petsc/private/cupminterface.hpp>
4: #include <petsc/private/cpp/memory.hpp>
5: #include <petsc/private/cpp/array.hpp>
7: #include "../impldevicebase.hpp" /* I "petscdevice.h" */
9: namespace Petsc
10: {
12: namespace device
13: {
15: namespace cupm
16: {
18: #if defined(PETSC_CUPM_DEVICE_NONE)
19: #error redefinition of PETSC_CUPM_DEVICE_NONE
20: #endif
22: #define PETSC_CUPM_DEVICE_NONE -3
24: template <DeviceType T>
25: class Device : public ::Petsc::device::impl::DeviceBase<Device<T>>, impl::Interface<T> {
26: public:
27: PETSC_DEVICE_IMPL_BASE_CLASS_HEADER(base_type, Device<T>);
28: PETSC_CUPM_INHERIT_INTERFACE_TYPEDEFS_USING(T);
30: static PetscErrorCode initialize(MPI_Comm, PetscInt *, PetscBool *, PetscDeviceInitType *) noexcept;
32: private:
33: // opaque class representing a single device
34: class DeviceInternal;
36: // all known devices
37: using devices_type = std::array<std::unique_ptr<DeviceInternal>, PETSC_DEVICE_MAX_DEVICES>;
38: static devices_type devices_;
40: // this ranks default device, if < 0 then devices are specifically disabled
41: static int defaultDevice_;
43: // have we tried looking for devices
44: static bool initialized_;
46: // clean-up
47: static PetscErrorCode finalize_() noexcept;
49: PETSC_NODISCARD static constexpr PetscDeviceType PETSC_DEVICE_IMPL_() noexcept { return PETSC_DEVICE_CUPM(); }
51: PetscErrorCode init_device_id_(PetscInt *) const noexcept;
52: static PetscErrorCode configure_device_(PetscDevice) noexcept;
53: static PetscErrorCode view_device_(PetscDevice, PetscViewer) noexcept;
54: static PetscErrorCode get_attribute_(PetscInt, PetscDeviceAttribute, void *) noexcept;
55: };
57: // define static variables
58: template <DeviceType T>
59: typename Device<T>::devices_type Device<T>::devices_ = {};
61: template <DeviceType T>
62: int Device<T>::defaultDevice_ = PETSC_CUPM_DEVICE_NONE;
64: template <DeviceType T>
65: bool Device<T>::initialized_ = false;
67: } // namespace cupm
69: } // namespace device
71: } // namespace Petsc