xref: /petsc/src/sys/objects/device/impls/cupm/cupmdevice.cxx (revision 0f1503a698da0451f8f2e3e02a165d4e1f526457)
1 #include "../../interface/cupmdevice.hpp"
2 #include <algorithm>
3 #include <csetjmp> // for cuda mpi awareness
4 #include <csignal> // SIGSEGV
5 #include <iterator>
6 #include <type_traits>
7 
8 #if PetscDefined(USE_LOG)
9 PETSC_INTERN PetscErrorCode PetscLogInitialize(void);
10 #else
11 #define PetscLogInitialize() 0
12 #endif
13 
14 namespace Petsc
15 {
16 
17 namespace Device
18 {
19 
20 namespace CUPM
21 {
22 
23 // internal "impls" class for CUPMDevice. Each instance represents a single cupm device
24 template <DeviceType T>
25 class Device<T>::DeviceInternal
26 {
27   const int        id_;
28   bool             devInitialized_ = false;
29   cupmDeviceProp_t dprop_; // cudaDeviceProp appears to be an actual struct, i.e. you can't
30                            // initialize it with nullptr or NULL (i've tried)
31 
32   PETSC_CXX_COMPAT_DECL(bool CUPMAwareMPI_());
33 
34 public:
35   // default constructor
36   explicit constexpr DeviceInternal(int dev) noexcept : id_(dev) { }
37 
38   // gather all relevant information for a particular device, a cupmDeviceProp_t is
39   // usually sufficient here
40   PETSC_NODISCARD PetscErrorCode initialize() noexcept;
41   PETSC_NODISCARD PetscErrorCode configure() noexcept;
42   PETSC_NODISCARD PetscErrorCode view(PetscViewer) const noexcept;
43   PETSC_NODISCARD PetscErrorCode finalize() noexcept;
44 
45   PETSC_NODISCARD auto id()          const -> decltype(id_)             { return id_;             }
46   PETSC_NODISCARD auto initialized() const -> decltype(devInitialized_) { return devInitialized_; }
47   PETSC_NODISCARD auto prop()        const -> const decltype(dprop_)&   { return dprop_;          }
48 
49   // factory
50   PETSC_CXX_COMPAT_DECL(std::unique_ptr<DeviceInternal> makeDevice(int i))
51   {
52     return std::unique_ptr<DeviceInternal>(new DeviceInternal(i));
53   }
54 };
55 
56 // the goal here is simply to get the cupm backend to create its context, not to do any type of
57 // modification of it, or create objects (since these may be affected by subsequent
58 // configuration changes)
59 template <DeviceType T>
60 PetscErrorCode Device<T>::DeviceInternal::initialize() noexcept
61 {
62   cupmError_t cerr;
63 
64   PetscFunctionBegin;
65   if (devInitialized_) PetscFunctionReturn(0);
66   devInitialized_ = true;
67   // need to do this BEFORE device has been set, although if the user
68   // has already done this then we just ignore it
69   if (cupmSetDeviceFlags(cupmDeviceMapHost) == cupmErrorSetOnActiveProcess) {
70     // reset the error if it was cupmErrorSetOnActiveProcess
71     const auto PETSC_UNUSED unused = cupmGetLastError();
72   } else {CHKERRCUPM(cupmGetLastError());}
73   // cuda 5.0+ will create a context when cupmSetDevice is called
74   if (cupmSetDevice(id_) != cupmErrorDeviceAlreadyInUse) CHKERRCUPM(cupmGetLastError());
75   // forces cuda < 5.0 to initialize a context
76   cerr = cupmFree(nullptr);CHKERRCUPM(cerr);
77   // where is this variable defined and when is it set? who knows! but it is defined and set
78   // at this point. either way, each device must make this check since I guess MPI might not be
79   // aware of all of them?
80   if (use_gpu_aware_mpi) {
81     // For OpenMPI, we could do a compile time check with
82     // "defined(PETSC_HAVE_OMPI_MAJOR_VERSION) && defined(MPIX_CUDA_AWARE_SUPPORT) &&
83     // MPIX_CUDA_AWARE_SUPPORT" to see if it is CUDA-aware. However, recent versions of IBM
84     // Spectrum MPI (e.g., 10.3.1) on Summit meet above conditions, but one has to use jsrun
85     // --smpiargs=-gpu to really enable GPU-aware MPI. So we do the check at runtime with a
86     // code that works only with GPU-aware MPI.
87     if (PetscUnlikely(!CUPMAwareMPI_())) {
88       (*PetscErrorPrintf)("PETSc is configured with GPU support, but your MPI is not GPU-aware. For better performance, please use a GPU-aware MPI.\n");
89       (*PetscErrorPrintf)("If you do not care, add option -use_gpu_aware_mpi 0. To not see the message again, add the option to your .petscrc, OR add it to the env var PETSC_OPTIONS.\n");
90       (*PetscErrorPrintf)("If you do care, for IBM Spectrum MPI on OLCF Summit, you may need jsrun --smpiargs=-gpu.\n");
91       (*PetscErrorPrintf)("For OpenMPI, you need to configure it --with-cuda (https://www.open-mpi.org/faq/?category=buildcuda)\n");
92       (*PetscErrorPrintf)("For MVAPICH2-GDR, you need to set MV2_USE_CUDA=1 (http://mvapich.cse.ohio-state.edu/userguide/gdr/)\n");
93       (*PetscErrorPrintf)("For Cray-MPICH, you need to set MPICH_RDMA_ENABLED_CUDA=1 (https://www.olcf.ornl.gov/tutorials/gpudirect-mpich-enabled-cuda/)\n");
94       PETSCABORT(PETSC_COMM_SELF,PETSC_ERR_LIB);
95     }
96   }
97   PetscFunctionReturn(0);
98 }
99 
100 template <DeviceType T>
101 PetscErrorCode Device<T>::DeviceInternal::configure() noexcept
102 {
103   cupmError_t    cerr;
104   PetscErrorCode ierr;
105 
106   PetscFunctionBegin;
107   if (PetscUnlikelyDebug(!devInitialized_)) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_COR,"Device %d being configured before it was initialized",id_);
108   // why on EARTH nvidia insists on making otherwise informational states into
109   // fully-fledged error codes is beyond me. Why couldn't a pointer to bool argument have
110   // sufficed?!?!?!
111   if (cupmSetDevice(id_) != cupmErrorDeviceAlreadyInUse) CHKERRCUPM(cupmGetLastError());
112   // need to update the device properties
113   cerr = cupmGetDeviceProperties(&dprop_,id_);CHKERRCUPM(cerr);
114   ierr = PetscInfo1(nullptr,"Configured device %d\n",id_);CHKERRQ(ierr);
115   PetscFunctionReturn(0);
116 }
117 
118 template <DeviceType T>
119 PetscErrorCode Device<T>::DeviceInternal::view(PetscViewer viewer) const noexcept
120 {
121   PetscBool      iascii;
122   PetscErrorCode ierr;
123 
124   PetscFunctionBegin;
125   if (PetscUnlikelyDebug(!devInitialized_)) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_COR,"Device %d being viewed before it was initialized or configured",id_);
126   ierr = PetscObjectTypeCompare(PetscObjectCast(viewer),PETSCVIEWERASCII,&iascii);CHKERRQ(ierr);
127   if (iascii) {
128     MPI_Comm    comm;
129     PetscMPIInt rank;
130 
131     ierr = PetscObjectGetComm(PetscObjectCast(viewer),&comm);CHKERRQ(ierr);
132     ierr = MPI_Comm_rank(comm,&rank);CHKERRMPI(ierr);
133     // flush before we start
134     ierr = PetscViewerFlush(viewer);CHKERRQ(ierr);
135     ierr = PetscViewerASCIIPushSynchronized(viewer);CHKERRQ(ierr);
136     ierr = PetscViewerASCIISynchronizedPrintf(viewer,"[%d] device %d: %s\n",rank,id_,dprop_.name);CHKERRQ(ierr);
137     // flush the assignment information
138     ierr = PetscViewerFlush(viewer);CHKERRQ(ierr);
139     ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
140     ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Compute capability: %d.%d\n",dprop_.major,dprop_.minor);CHKERRQ(ierr);
141     ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Multiprocessor Count: %d\n",dprop_.multiProcessorCount);CHKERRQ(ierr);
142     ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Maximum Grid Dimensions: %d x %d x %d\n",dprop_.maxGridSize[0],dprop_.maxGridSize[1],dprop_.maxGridSize[2]);CHKERRQ(ierr);
143     ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Maximum Block Dimensions: %d x %d x %d\n",dprop_.maxThreadsDim[0],dprop_.maxThreadsDim[1],dprop_.maxThreadsDim[2]);CHKERRQ(ierr);
144     ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Maximum Threads Per Block: %d\n",dprop_.maxThreadsPerBlock);CHKERRQ(ierr);
145     ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Warp Size: %d\n",dprop_.warpSize);CHKERRQ(ierr);
146     ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Total Global Memory (bytes): %zu\n",dprop_.totalGlobalMem);CHKERRQ(ierr);
147     ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Total Constant Memory (bytes): %zu\n",dprop_.totalConstMem);CHKERRQ(ierr);
148     ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Shared Memory Per Block (bytes): %zu\n",dprop_.sharedMemPerBlock);CHKERRQ(ierr);
149     ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Multiprocessor Clock Rate (KHz): %d\n",dprop_.clockRate);CHKERRQ(ierr);
150     ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Memory Clock Rate (KHz): %d\n",dprop_.memoryClockRate);CHKERRQ(ierr);
151     ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Memory Bus Width (bits): %d\n",dprop_.memoryBusWidth);CHKERRQ(ierr);
152     ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Peak Memory Bandwidth (GB/s): %f\n",2.0*dprop_.memoryClockRate*(dprop_.memoryBusWidth/8)/1.0e6);CHKERRQ(ierr);
153     ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Can map host memory: %s\n",dprop_.canMapHostMemory ? "PETSC_TRUE" : "PETSC_FALSE");CHKERRQ(ierr);
154     ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Can execute multiple kernels concurrently: %s\n",dprop_.concurrentKernels ? "PETSC_TRUE" : "PETSC_FALSE");CHKERRQ(ierr);
155     ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
156     ierr = PetscViewerFlush(viewer);CHKERRQ(ierr);
157     ierr = PetscViewerASCIIPopSynchronized(viewer);CHKERRQ(ierr);
158   }
159   PetscFunctionReturn(0);
160 }
161 
162 static std::jmp_buf cupmMPIAwareJumpBuffer;
163 static bool         cupmMPIAwareJumpBufferSet;
164 
165 // godspeed to anyone that attempts to call this function
166 void SilenceVariableIsNotNeededAndWillNotBeEmittedWarning_ThisFunctionShouldNeverBeCalled()
167 {
168   PETSCABORT(MPI_COMM_NULL,INT_MAX);
169   if (cupmMPIAwareJumpBufferSet) (void)cupmMPIAwareJumpBuffer;
170 }
171 
172 #define CHKCUPMAWARE(expr) if (PetscUnlikely((expr) != cupmSuccess)) return false;
173 
174 template <DeviceType T>
175 PETSC_CXX_COMPAT_DEFN(bool Device<T>::DeviceInternal::CUPMAwareMPI_())
176 {
177   constexpr int  bufSize = 2;
178   constexpr int  hbuf[bufSize] = {1,0};
179   int            *dbuf = nullptr;
180   constexpr auto bytes = bufSize*sizeof(*dbuf);
181   auto           awareness = false;
182   cupmError_t    cerr;
183   PetscErrorCode ierr;
184   const auto     cupmSignalHandler = [](int signal, void *ptr) -> PetscErrorCode {
185     if ((signal == SIGSEGV) && cupmMPIAwareJumpBufferSet) std::longjmp(cupmMPIAwareJumpBuffer,1);
186     return PetscSignalHandlerDefault(signal,ptr);
187   };
188 
189   PetscFunctionBegin;
190   cerr = cupmMalloc(reinterpret_cast<void**>(&dbuf),bytes);CHKCUPMAWARE(cerr);
191   cerr = cupmMemcpy(dbuf,hbuf,bytes,cupmMemcpyHostToDevice);CHKCUPMAWARE(cerr);
192   ierr = PetscPushSignalHandler(cupmSignalHandler,nullptr);CHKERRABORT(PETSC_COMM_SELF,ierr);
193   cupmMPIAwareJumpBufferSet = true;
194   if (setjmp(cupmMPIAwareJumpBuffer)) {
195     // if a segv was triggered in the MPI_Allreduce below, it is very likely due to MPI not
196     // being GPU-aware
197     awareness = false;
198     // control flow up until this point:
199     // 1. CUPMDevice<T>::CUPMDeviceInternal::MPICUPMAware__()
200     // 2. MPI_Allreduce
201     // 3. SIGSEGV
202     // 4. PetscSignalHandler_Private
203     // 5. cupmSignalHandler (lambda function)
204     // 6. here
205     // PetscSignalHandler_Private starts with PetscFunctionBegin and is pushed onto the stack
206     // so we must undo this. This would be most naturally done in cupmSignalHandler, however
207     // the C/C++ standard dictates:
208     //
209     // After invoking longjmp(), non-volatile-qualified local objects should not be accessed if
210     // their values could have changed since the invocation of setjmp(). Their value in this
211     // case is considered indeterminate, and accessing them is undefined behavior.
212     //
213     // so for safety (since we don't know what PetscStackPop may try to read/declare) we do it
214     // outside of the longjmp control flow
215     PetscStackPop;
216   } else if (!MPI_Allreduce(dbuf,dbuf+1,1,MPI_INT,MPI_SUM,PETSC_COMM_SELF)) awareness = true;
217   cupmMPIAwareJumpBufferSet = false;
218   ierr = PetscPopSignalHandler();CHKERRABORT(PETSC_COMM_SELF,ierr);
219   cerr = cupmFree(dbuf);CHKCUPMAWARE(cerr);
220   PetscFunctionReturn(awareness);
221 }
222 
223 template <DeviceType T>
224 PetscErrorCode Device<T>::DeviceInternal::finalize() noexcept
225 {
226   PetscFunctionBegin;
227   devInitialized_ = false;
228   PetscFunctionReturn(0);
229 }
230 
231 template <DeviceType T>
232 PetscErrorCode Device<T>::finalize_() noexcept
233 {
234   PetscFunctionBegin;
235   if (!initialized_) PetscFunctionReturn(0);
236   for (auto&& device : devices_) {
237     if (device) {
238       const auto ierr = device->finalize();CHKERRQ(ierr);
239       device.reset();
240     }
241   }
242   defaultDevice_ = PETSC_CUPM_DEVICE_NONE;  // disabled by default
243   initialized_   = false;
244   PetscFunctionReturn(0);
245 }
246 
247 // these functions should be named identically to the option they produce where "CUPMTYPE" and
248 // "cupmtype" are the uppercase and lowercase string versions of the cupm backend respectively
249 template <DeviceType T>
250 PETSC_CXX_COMPAT_DECL(PETSC_CONSTEXPR_14 const char* PetscDevice_CUPMTYPE_Options())
251 {
252   switch (T) {
253   case DeviceType::CUDA: return "PetscDevice CUDA Options";
254   case DeviceType::HIP:  return "PetscDevice HIP Options";
255   }
256 }
257 
258 template <DeviceType T>
259 PETSC_CXX_COMPAT_DECL(PETSC_CONSTEXPR_14 const char* device_enable_cupmtype())
260 {
261   switch (T) {
262   case DeviceType::CUDA: return "-device_enable_cuda";
263   case DeviceType::HIP:  return "-device_enable_hip";
264   }
265 }
266 
267 template <DeviceType T>
268 PETSC_CXX_COMPAT_DECL(PETSC_CONSTEXPR_14 const char* device_select_cupmtype())
269 {
270   switch (T) {
271   case DeviceType::CUDA: return "-device_select_cuda";
272   case DeviceType::HIP:  return "-device_select_hip";
273   }
274 }
275 
276 template <DeviceType T>
277 PETSC_CXX_COMPAT_DECL(PETSC_CONSTEXPR_14 const char* device_view_cupmtype())
278 {
279   switch (T) {
280   case DeviceType::CUDA: return "-device_view_cuda";
281   case DeviceType::HIP:  return "-device_view_hip";
282   }
283 }
284 
285 template <DeviceType T>
286 PetscErrorCode Device<T>::initialize(MPI_Comm comm, PetscInt *defaultDeviceId, PetscDeviceInitType *defaultInitType) noexcept
287 {
288   PetscInt       initTypeCUPM = *defaultInitType,id = *defaultDeviceId;
289   PetscBool      view = PETSC_FALSE,flg;
290   int            ndev;
291   cupmError_t    cerr;
292   PetscErrorCode ierr;
293 
294   PetscFunctionBegin;
295   if (initialized_) PetscFunctionReturn(0);
296   initialized_ = true;
297   ierr = PetscRegisterFinalize(finalize_);CHKERRQ(ierr);
298 
299   {
300     // the functions to populate the command line strings are named after the string they return
301     ierr = PetscOptionsBegin(comm,nullptr,PetscDevice_CUPMTYPE_Options<T>(),"Sys");CHKERRQ(ierr);
302     ierr = PetscOptionsEList(device_enable_cupmtype<T>(),"How (or whether) to initialize a device","CUPMDevice<CUPMDeviceType>::initialize()",PetscDeviceInitTypes,3,PetscDeviceInitTypes[initTypeCUPM],&initTypeCUPM,nullptr);CHKERRQ(ierr);
303     ierr = PetscOptionsRangeInt(device_select_cupmtype<T>(),"Which device to use. Pass " PetscStringize(PETSC_DECIDE) " to have PETSc decide or (given they exist) [0-NUM_DEVICE) for a specific device","PetscDeviceCreate",id,&id,nullptr,PETSC_DECIDE,std::numeric_limits<decltype(defaultDevice_)>::max());CHKERRQ(ierr);
304     ierr = PetscOptionsBool(device_view_cupmtype<T>(),"Display device information and assignments (forces eager initialization)",nullptr,view,&view,&flg);CHKERRQ(ierr);
305     ierr = PetscOptionsEnd();CHKERRQ(ierr);
306   }
307 
308   cerr = cupmGetDeviceCount(&ndev);
309   // post-process the options and lay the groundwork for initialization if needs be
310   if (PetscUnlikely((cerr == cupmErrorStubLibrary) || (cerr == cupmErrorNoDevice))) {
311     if (PetscUnlikely((initTypeCUPM == PETSC_DEVICE_INIT_EAGER) || (view && flg))) {
312       const auto name    = cupmGetErrorName(cerr);
313       const auto desc    = cupmGetErrorString(cerr);
314       const auto backend = cupmName();
315       SETERRQ5(comm,PETSC_ERR_USER_INPUT,"Cannot eagerly initialize %s, as doing so results in %s error %d (%s) : %s",backend,backend,static_cast<PetscErrorCode>(cerr),name,desc);
316     }
317     id   = -cerr;
318     cerr = cupmGetLastError(); // reset error
319     initTypeCUPM = PETSC_DEVICE_INIT_NONE;
320   } else CHKERRCUPM(cerr);
321 
322   if (initTypeCUPM == PETSC_DEVICE_INIT_NONE) {
323     if ((id > 0) || (id == PETSC_DECIDE)) id = PETSC_CUPM_DEVICE_NONE;
324   } else {
325     ierr = PetscDeviceCheckDeviceCount_Internal(ndev);CHKERRQ(ierr);
326     if (id == PETSC_DECIDE) {
327       if (ndev) {
328         PetscMPIInt rank;
329 
330         ierr = MPI_Comm_rank(comm,&rank);CHKERRMPI(ierr);
331         id   = rank % ndev;
332       } else id = 0;
333     }
334     view = static_cast<decltype(view)>(view && flg);
335     if (view) initTypeCUPM = PETSC_DEVICE_INIT_EAGER;
336   }
337 
338   static_assert(std::is_same<PetscMPIInt,decltype(defaultDevice_)>::value,"");
339   // id is PetscInt, _defaultDevice is int
340   ierr = PetscMPIIntCast(id,&defaultDevice_);CHKERRQ(ierr);
341   if (initTypeCUPM == PETSC_DEVICE_INIT_EAGER) {
342     devices_[defaultDevice_] = DeviceInternal::makeDevice(defaultDevice_);
343     ierr = devices_[defaultDevice_]->initialize();CHKERRQ(ierr);
344     ierr = devices_[defaultDevice_]->configure();CHKERRQ(ierr);
345     if (view) {
346       PetscViewer vwr;
347 
348       ierr = PetscLogInitialize();CHKERRQ(ierr);
349       ierr = PetscViewerASCIIGetStdout(comm,&vwr);CHKERRQ(ierr);
350       ierr = devices_[defaultDevice_]->view(vwr);CHKERRQ(ierr);
351     }
352   }
353 
354   // record the results of the initialization
355   *defaultInitType = static_cast<PetscDeviceInitType>(initTypeCUPM);
356   *defaultDeviceId = id;
357   PetscFunctionReturn(0);
358 }
359 
360 template <DeviceType T>
361 PetscErrorCode Device<T>::getDevice(PetscDevice device, PetscInt id) const noexcept
362 {
363   PetscErrorCode ierr;
364 
365   PetscFunctionBegin;
366   if (PetscUnlikelyDebug(defaultDevice_ < 0)) {
367     if (defaultDevice_ == PETSC_CUPM_DEVICE_NONE) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Trying to retrieve a %s PetscDevice when it has been disabled",cupmName());
368     const auto cerr = static_cast<cupmError_t>(-defaultDevice_);
369 
370     SETERRQ4(PETSC_COMM_SELF,PETSC_ERR_GPU,"Cannot lazily initialize PetscDevice: %s error %d (%s) : %s",cupmName(),static_cast<PetscErrorCode>(cerr),cupmGetErrorName(cerr),cupmGetErrorString(cerr));
371   }
372   if (id == PETSC_DECIDE) id = defaultDevice_;
373   if (PetscUnlikelyDebug(static_cast<std::size_t>(id) >= devices_.size())) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Only supports %zu number of devices but trying to get device with id %" PetscInt_FMT,devices_.size(),id);
374   if (devices_[id]) {
375     if (PetscUnlikelyDebug(id != devices_[id]->id())) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_PLIB,"Entry %" PetscInt_FMT " contains device with mismatching id %d",id,devices_[id]->id());
376   } else devices_[id] = DeviceInternal::makeDevice(id);
377   ierr = devices_[id]->initialize();CHKERRQ(ierr);
378   device->deviceId           = devices_[id]->id(); // technically id = _devices[id]->_id here
379   device->ops->createcontext = create_;
380   device->ops->configure     = this->configureDevice;
381   device->ops->view          = this->viewDevice;
382   PetscFunctionReturn(0);
383 }
384 
385 template <DeviceType T>
386 PetscErrorCode Device<T>::configureDevice(PetscDevice device) noexcept
387 {
388   PetscErrorCode ierr;
389 
390   PetscFunctionBegin;
391   ierr = devices_[device->deviceId]->configure();CHKERRQ(ierr);
392   PetscFunctionReturn(0);
393 }
394 
395 template <DeviceType T>
396 PetscErrorCode Device<T>::viewDevice(PetscDevice device, PetscViewer viewer) noexcept
397 {
398   PetscErrorCode ierr;
399 
400   PetscFunctionBegin;
401   // now this __shouldn't__ reconfigure the device, but there is a petscinfo call to indicate
402   // it is being reconfigured
403   ierr = devices_[device->deviceId]->configure();CHKERRQ(ierr);
404   ierr = devices_[device->deviceId]->view(viewer);CHKERRQ(ierr);
405   PetscFunctionReturn(0);
406 }
407 
408 // explicitly instantiate the classes
409 #if PetscDefined(HAVE_CUDA)
410 template class Device<DeviceType::CUDA>;
411 #endif
412 #if PetscDefined(HAVE_HIP)
413 template class Device<DeviceType::HIP>;
414 #endif
415 
416 } // namespace CUPM
417 
418 } // namespace Device
419 
420 } // namespace Petsc
421