Tpetra parallel linear algebra Version of the Day
Loading...
Searching...
No Matches
Tpetra_Details_WrappedDualView.hpp
1// @HEADER
2// ***********************************************************************
3//
4// Tpetra: Templated Linear Algebra Services Package
5// Copyright (2008) Sandia Corporation
6//
7// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8// the U.S. Government retains certain rights in this software.
9//
10// Redistribution and use in source and binary forms, with or without
11// modification, are permitted provided that the following conditions are
12// met:
13//
14// 1. Redistributions of source code must retain the above copyright
15// notice, this list of conditions and the following disclaimer.
16//
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// 3. Neither the name of the Corporation nor the names of the
22// contributors may be used to endorse or promote products derived from
23// this software without specific prior written permission.
24//
25// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36//
37// ************************************************************************
38// @HEADER
39
40#ifndef TPETRA_DETAILS_WRAPPEDDUALVIEW_HPP
41#define TPETRA_DETAILS_WRAPPEDDUALVIEW_HPP
42
43#include <Tpetra_Access.hpp>
44#include <Tpetra_Details_temporaryViewUtils.hpp>
45#include <Kokkos_DualView.hpp>
46#include "Teuchos_TestForException.hpp"
47#include <sstream>
48
49//#define DEBUG_UVM_REMOVAL // Works only with gcc > 4.8
50
51#ifdef DEBUG_UVM_REMOVAL
52
53#define DEBUG_UVM_REMOVAL_ARGUMENT ,const char* callerstr = __builtin_FUNCTION(),const char * filestr=__builtin_FILE(),const int linnum = __builtin_LINE()
54
55#define DEBUG_UVM_REMOVAL_PRINT_CALLER(fn) \
56 { \
57 auto envVarSet = std::getenv("TPETRA_UVM_REMOVAL"); \
58 if (envVarSet && (std::strcmp(envVarSet,"1") == 0)) \
59 std::cout << (fn) << " called from " << callerstr \
60 << " at " << filestr << ":"<<linnum \
61 << " host cnt " << dualView.h_view.use_count() \
62 << " device cnt " << dualView.d_view.use_count() \
63 << std::endl; \
64 }
65
66#else
67
68#define DEBUG_UVM_REMOVAL_ARGUMENT
69#define DEBUG_UVM_REMOVAL_PRINT_CALLER(fn)
70
71#endif
72
74namespace Tpetra {
75
76 // We really need this forward declaration here for friend to work
77 template<typename SC, typename LO, typename GO, typename NO>
78 class MultiVector;
79
80
83namespace Details {
84
85namespace impl {
86
87template <typename DualViewType>
88struct hasConstData {
89 using valueType = typename DualViewType::value_type;
90 using constValueType = typename DualViewType::const_value_type;
91 static constexpr bool value = std::is_same<valueType, constValueType>::value;
92};
93
94template <typename DualViewType>
95using enableIfConstData = std::enable_if_t<hasConstData<DualViewType>::value>;
96
97template <typename DualViewType>
98using enableIfNonConstData = std::enable_if_t<!hasConstData<DualViewType>::value>;
99
100template <typename DualViewType>
101enableIfNonConstData<DualViewType>
102sync_host(DualViewType dualView) {
103 dualView.sync_host();
104}
105
106template <typename DualViewType>
107enableIfConstData<DualViewType>
108sync_host(DualViewType dualView) { }
109
110template <typename DualViewType>
111enableIfNonConstData<DualViewType>
112sync_device(DualViewType dualView) {
113 dualView.sync_device();
114}
115
116template <typename DualViewType>
117enableIfConstData<DualViewType>
118sync_device(DualViewType dualView) { }
119
120}
121
125
126extern bool wdvTrackingEnabled;
127
132void disableWDVTracking();
133
135void enableWDVTracking();
136
139template <typename DualViewType>
140class WrappedDualView {
141public:
142
143 using DVT = DualViewType;
144 using t_host = typename DualViewType::t_host;
145 using t_dev = typename DualViewType::t_dev;
146
147 using HostType = typename t_host::device_type;
148 using DeviceType = typename t_dev::device_type;
149
150private:
151 static constexpr bool dualViewHasNonConstData = !impl::hasConstData<DualViewType>::value;
152 static constexpr bool deviceMemoryIsHostAccessible =
153 Kokkos::SpaceAccessibility<Kokkos::DefaultHostExecutionSpace, typename t_dev::memory_space>::accessible;
154
155public:
156 WrappedDualView() {}
157
158 WrappedDualView(DualViewType dualV)
159 : originalDualView(dualV),
160 dualView(originalDualView)
161 { }
162
163 // This is an expert-only constructor
164 // For WrappedDualView to manage synchronizations correctly,
165 // it must have an DualView which is not a subview to due the
166 // sync's on. This is what origDualV is for. In this case,
167 // dualV is a subview of origDualV.
168 WrappedDualView(DualViewType dualV,DualViewType origDualV)
169 : originalDualView(origDualV),
170 dualView(dualV)
171 { }
172
173
174 WrappedDualView(const t_dev deviceView) {
175 TEUCHOS_TEST_FOR_EXCEPTION(
176 deviceView.data() != nullptr && deviceView.use_count() == 0,
177 std::invalid_argument,
178 "Tpetra::Details::WrappedDualView: cannot construct with a device view that\n"
179 "does not own its memory (i.e. constructed with a raw pointer and dimensions)\n"
180 "because the WrappedDualView needs to assume ownership of the memory.");
181 //If the provided view is default-constructed (null, 0 extent, 0 use count),
182 //leave the host mirror default-constructed as well in order to have a matching use count of 0.
183 t_host hostView;
184 if(deviceView.use_count() != 0)
185 {
186 hostView = Kokkos::create_mirror_view(
187 Kokkos::WithoutInitializing,
188 typename t_host::memory_space(),
189 deviceView);
190 }
191 originalDualView = DualViewType(deviceView, hostView);
192 originalDualView.clear_sync_state();
193 originalDualView.modify_device();
194 dualView = originalDualView;
195 }
196
197 // 1D View constructors
198 WrappedDualView(const WrappedDualView parent, int offset, int numEntries) {
199 originalDualView = parent.originalDualView;
200 dualView = getSubview(parent.dualView, offset, numEntries);
201 }
202
203
204 // 2D View Constructors
205 WrappedDualView(const WrappedDualView parent,const Kokkos::pair<size_t,size_t>& rowRng, const Kokkos::ALL_t& colRng) {
206 originalDualView = parent.originalDualView;
207 dualView = getSubview2D(parent.dualView,rowRng,colRng);
208 }
209
210 WrappedDualView(const WrappedDualView parent,const Kokkos::ALL_t &rowRng, const Kokkos::pair<size_t,size_t>& colRng) {
211 originalDualView = parent.originalDualView;
212 dualView = getSubview2D(parent.dualView,rowRng,colRng);
213 }
214
215 WrappedDualView(const WrappedDualView parent,const Kokkos::pair<size_t,size_t>& rowRng, const Kokkos::pair<size_t,size_t>& colRng) {
216 originalDualView = parent.originalDualView;
217 dualView = getSubview2D(parent.dualView,rowRng,colRng);
218 }
219
220 size_t extent(const int i) const {
221 return dualView.h_view.extent(i);
222 }
223
224 void stride(size_t * stride_) const {
225 dualView.stride(stride_);
226 }
227
228
229 size_t origExtent(const int i) const {
230 return originalDualView.h_view.extent(i);
231 }
232
233 const char * label() const {
234 return dualView.d_view.label();
235 }
236
237
238 typename t_host::const_type
239 getHostView(Access::ReadOnlyStruct
240 DEBUG_UVM_REMOVAL_ARGUMENT
241 ) const
242 {
243 DEBUG_UVM_REMOVAL_PRINT_CALLER("getHostViewReadOnly");
244 if(needsSyncPath()) {
245 throwIfDeviceViewAlive();
246 impl::sync_host(originalDualView);
247 }
248 return dualView.view_host();
249 }
250
251 t_host
252 getHostView(Access::ReadWriteStruct
253 DEBUG_UVM_REMOVAL_ARGUMENT
254 )
255 {
256 DEBUG_UVM_REMOVAL_PRINT_CALLER("getHostViewReadWrite");
257 static_assert(dualViewHasNonConstData,
258 "ReadWrite views are not available for DualView with const data");
259 if(needsSyncPath()) {
260 throwIfDeviceViewAlive();
261 impl::sync_host(originalDualView);
262 originalDualView.modify_host();
263 }
264
265 return dualView.view_host();
266 }
267
268 t_host
269 getHostView(Access::OverwriteAllStruct
270 DEBUG_UVM_REMOVAL_ARGUMENT
271 )
272 {
273 DEBUG_UVM_REMOVAL_PRINT_CALLER("getHostViewOverwriteAll");
274 static_assert(dualViewHasNonConstData,
275 "OverwriteAll views are not available for DualView with const data");
276 if (iAmASubview()) {
277 return getHostView(Access::ReadWrite);
278 }
279 if(needsSyncPath()) {
280 throwIfDeviceViewAlive();
281 if (deviceMemoryIsHostAccessible) Kokkos::fence();
282 dualView.clear_sync_state();
283 dualView.modify_host();
284 }
285 return dualView.view_host();
286 }
287
288 typename t_dev::const_type
289 getDeviceView(Access::ReadOnlyStruct
290 DEBUG_UVM_REMOVAL_ARGUMENT
291 ) const
292 {
293 DEBUG_UVM_REMOVAL_PRINT_CALLER("getDeviceViewReadOnly");
294 if(needsSyncPath()) {
295 throwIfHostViewAlive();
296 impl::sync_device(originalDualView);
297 }
298 return dualView.view_device();
299 }
300
301 t_dev
302 getDeviceView(Access::ReadWriteStruct
303 DEBUG_UVM_REMOVAL_ARGUMENT
304 )
305 {
306 DEBUG_UVM_REMOVAL_PRINT_CALLER("getDeviceViewReadWrite");
307 static_assert(dualViewHasNonConstData,
308 "ReadWrite views are not available for DualView with const data");
309 if(needsSyncPath()) {
310 throwIfHostViewAlive();
311 impl::sync_device(originalDualView);
312 originalDualView.modify_device();
313 }
314 return dualView.view_device();
315 }
316
317 t_dev
318 getDeviceView(Access::OverwriteAllStruct
319 DEBUG_UVM_REMOVAL_ARGUMENT
320 )
321 {
322 DEBUG_UVM_REMOVAL_PRINT_CALLER("getDeviceViewOverwriteAll");
323 static_assert(dualViewHasNonConstData,
324 "OverwriteAll views are not available for DualView with const data");
325 if (iAmASubview()) {
326 return getDeviceView(Access::ReadWrite);
327 }
328 if(needsSyncPath()) {
329 throwIfHostViewAlive();
330 if (deviceMemoryIsHostAccessible) Kokkos::fence();
331 dualView.clear_sync_state();
332 dualView.modify_device();
333 }
334 return dualView.view_device();
335 }
336
337 template<class TargetDeviceType>
338 typename std::remove_reference<decltype(std::declval<DualViewType>().template view<TargetDeviceType>())>::type::const_type
339 getView (Access::ReadOnlyStruct s DEBUG_UVM_REMOVAL_ARGUMENT) const {
340 using ReturnViewType = typename std::remove_reference<decltype(std::declval<DualViewType>().template view<TargetDeviceType>())>::type::const_type;
341 using ReturnDeviceType = typename ReturnViewType::device_type;
342 constexpr bool returnDevice = std::is_same<ReturnDeviceType, DeviceType>::value;
343 if(returnDevice) {
344 DEBUG_UVM_REMOVAL_PRINT_CALLER("getView<Device>ReadOnly");
345 if(needsSyncPath()) {
346 throwIfHostViewAlive();
347 impl::sync_device(originalDualView);
348 }
349 }
350 else {
351 DEBUG_UVM_REMOVAL_PRINT_CALLER("getView<Host>ReadOnly");
352 if(needsSyncPath()) {
353 throwIfDeviceViewAlive();
354 impl::sync_host(originalDualView);
355 }
356 }
357
358 return dualView.template view<TargetDeviceType>();
359 }
360
361
362 template<class TargetDeviceType>
363 typename std::remove_reference<decltype(std::declval<DualViewType>().template view<TargetDeviceType>())>::type
364 getView (Access::ReadWriteStruct s DEBUG_UVM_REMOVAL_ARGUMENT) const {
365 using ReturnViewType = typename std::remove_reference<decltype(std::declval<DualViewType>().template view<TargetDeviceType>())>::type;
366 using ReturnDeviceType = typename ReturnViewType::device_type;
367 constexpr bool returnDevice = std::is_same<ReturnDeviceType, DeviceType>::value;
368
369 if(returnDevice) {
370 DEBUG_UVM_REMOVAL_PRINT_CALLER("getView<Device>ReadWrite");
371 static_assert(dualViewHasNonConstData,
372 "ReadWrite views are not available for DualView with const data");
373 if(needsSyncPath()) {
374 throwIfHostViewAlive();
375 impl::sync_device(originalDualView);
376 originalDualView.modify_device();
377 }
378 }
379 else {
380 DEBUG_UVM_REMOVAL_PRINT_CALLER("getView<Host>ReadWrite");
381 static_assert(dualViewHasNonConstData,
382 "ReadWrite views are not available for DualView with const data");
383 if(needsSyncPath()) {
384 throwIfDeviceViewAlive();
385 impl::sync_host(originalDualView);
386 originalDualView.modify_host();
387 }
388 }
389
390 return dualView.template view<TargetDeviceType>();
391 }
392
393
394 template<class TargetDeviceType>
395 typename std::remove_reference<decltype(std::declval<DualViewType>().template view<TargetDeviceType>())>::type
396 getView (Access::OverwriteAllStruct s DEBUG_UVM_REMOVAL_ARGUMENT) const {
397 using ReturnViewType = typename std::remove_reference<decltype(std::declval<DualViewType>().template view<TargetDeviceType>())>::type;
398 using ReturnDeviceType = typename ReturnViewType::device_type;
399
400 if (iAmASubview())
401 return getView<TargetDeviceType>(Access::ReadWrite);
402
403 constexpr bool returnDevice = std::is_same<ReturnDeviceType, DeviceType>::value;
404
405 if(returnDevice) {
406 DEBUG_UVM_REMOVAL_PRINT_CALLER("getView<Device>OverwriteAll");
407 static_assert(dualViewHasNonConstData,
408 "OverwriteAll views are not available for DualView with const data");
409 if(needsSyncPath()) {
410 throwIfHostViewAlive();
411 dualView.clear_sync_state();
412 dualView.modify_host();
413 }
414 }
415 else {
416 DEBUG_UVM_REMOVAL_PRINT_CALLER("getView<Host>OverwriteAll");
417 static_assert(dualViewHasNonConstData,
418 "OverwriteAll views are not available for DualView with const data");
419 if(needsSyncPath()) {
420 throwIfDeviceViewAlive();
421 dualView.clear_sync_state();
422 dualView.modify_device();
423 }
424 }
425
426 return dualView.template view<TargetDeviceType>();
427 }
428
429
430 typename t_host::const_type
431 getHostSubview(int offset, int numEntries, Access::ReadOnlyStruct
432 DEBUG_UVM_REMOVAL_ARGUMENT
433 ) const
434 {
435 DEBUG_UVM_REMOVAL_PRINT_CALLER("getHostSubviewReadOnly");
436 if(needsSyncPath()) {
437 throwIfDeviceViewAlive();
438 impl::sync_host(originalDualView);
439 }
440 return getSubview(dualView.view_host(), offset, numEntries);
441 }
442
443 t_host
444 getHostSubview(int offset, int numEntries, Access::ReadWriteStruct
445 DEBUG_UVM_REMOVAL_ARGUMENT
446 )
447 {
448 DEBUG_UVM_REMOVAL_PRINT_CALLER("getHostSubviewReadWrite");
449 static_assert(dualViewHasNonConstData,
450 "ReadWrite views are not available for DualView with const data");
451 if(needsSyncPath()) {
452 throwIfDeviceViewAlive();
453 impl::sync_host(originalDualView);
454 originalDualView.modify_host();
455 }
456 return getSubview(dualView.view_host(), offset, numEntries);
457 }
458
459 t_host
460 getHostSubview(int offset, int numEntries, Access::OverwriteAllStruct
461 DEBUG_UVM_REMOVAL_ARGUMENT
462 )
463 {
464 DEBUG_UVM_REMOVAL_PRINT_CALLER("getHostSubviewOverwriteAll");
465 static_assert(dualViewHasNonConstData,
466 "OverwriteAll views are not available for DualView with const data");
467 return getHostSubview(offset, numEntries, Access::ReadWrite);
468 }
469
470 typename t_dev::const_type
471 getDeviceSubview(int offset, int numEntries, Access::ReadOnlyStruct
472 DEBUG_UVM_REMOVAL_ARGUMENT
473 ) const
474 {
475 DEBUG_UVM_REMOVAL_PRINT_CALLER("getDeviceSubviewReadOnly");
476 if(needsSyncPath()) {
477 throwIfHostViewAlive();
478 impl::sync_device(originalDualView);
479 }
480 return getSubview(dualView.view_device(), offset, numEntries);
481 }
482
483 t_dev
484 getDeviceSubview(int offset, int numEntries, Access::ReadWriteStruct
485 DEBUG_UVM_REMOVAL_ARGUMENT
486 )
487 {
488 DEBUG_UVM_REMOVAL_PRINT_CALLER("getDeviceSubviewReadWrite");
489 static_assert(dualViewHasNonConstData,
490 "ReadWrite views are not available for DualView with const data");
491 if(needsSyncPath()) {
492 throwIfHostViewAlive();
493 impl::sync_device(originalDualView);
494 originalDualView.modify_device();
495 }
496 return getSubview(dualView.view_device(), offset, numEntries);
497 }
498
499 t_dev
500 getDeviceSubview(int offset, int numEntries, Access::OverwriteAllStruct
501 DEBUG_UVM_REMOVAL_ARGUMENT
502 )
503 {
504 DEBUG_UVM_REMOVAL_PRINT_CALLER("getDeviceSubviewOverwriteAll");
505 static_assert(dualViewHasNonConstData,
506 "OverwriteAll views are not available for DualView with const data");
507 return getDeviceSubview(offset, numEntries, Access::ReadWrite);
508 }
509
510
511 // Debugging functions to get copies of the view state
512 typename t_host::HostMirror getHostCopy() const {
513 auto X_dev = dualView.view_host();
514 if(X_dev.span_is_contiguous()) {
515 auto mirror = Kokkos::create_mirror_view(X_dev);
516 Kokkos::deep_copy(mirror,X_dev);
517 return mirror;
518 }
519 else {
520 auto X_contig = Tpetra::Details::TempView::toLayout<decltype(X_dev), Kokkos::LayoutLeft>(X_dev);
521 auto mirror = Kokkos::create_mirror_view(X_contig);
522 Kokkos::deep_copy(mirror,X_contig);
523 return mirror;
524 }
525 }
526
527 typename t_dev::HostMirror getDeviceCopy() const {
528 auto X_dev = dualView.view_device();
529 if(X_dev.span_is_contiguous()) {
530 auto mirror = Kokkos::create_mirror_view(X_dev);
531 Kokkos::deep_copy(mirror,X_dev);
532 return mirror;
533 }
534 else {
535 auto X_contig = Tpetra::Details::TempView::toLayout<decltype(X_dev), Kokkos::LayoutLeft>(X_dev);
536 auto mirror = Kokkos::create_mirror_view(X_contig);
537 Kokkos::deep_copy(mirror,X_contig);
538 return mirror;
539 }
540 }
541
542 // Debugging functions for validity checks
543 bool is_valid_host() const {
544 return dualView.view_host().size() == 0 || dualView.view_host().data();
545 }
546
547 bool is_valid_device() const {
548 return dualView.view_device().size() == 0 || dualView.view_device().data();
549 }
550
551
552 bool need_sync_host() const {
553 return originalDualView.need_sync_host();
554 }
555
556 bool need_sync_device() const {
557 return originalDualView.need_sync_device();
558 }
559
560 int host_view_use_count() const {
561 return originalDualView.h_view.use_count();
562 }
563
564 int device_view_use_count() const {
565 return originalDualView.d_view.use_count();
566 }
567
568
569 // MultiVector really needs to get at the raw DualViews,
570 // but we'd very much prefer that users not.
571 template<typename SC, typename LO, typename GO, typename NO>
572 friend class ::Tpetra::MultiVector;
573
574private:
575 // A Kokkos implementation of WrappedDualView will have to make these
576 // functions publically accessable, but in the Tpetra version, we'd
577 // really rather not.
578 DualViewType getOriginalDualView() const {
579 return originalDualView;
580 }
581
582 DualViewType getDualView() const {
583 return dualView;
584 }
585
586 template <typename ViewType>
587 ViewType getSubview(ViewType view, int offset, int numEntries) const {
588 return Kokkos::subview(view, Kokkos::pair<int, int>(offset, offset+numEntries));
589 }
590
591 template <typename ViewType,typename int_type>
592 ViewType getSubview2D(ViewType view, Kokkos::pair<int_type,int_type> offset0, const Kokkos::ALL_t&) const {
593 return Kokkos::subview(view,offset0,Kokkos::ALL());
594 }
595
596 template <typename ViewType,typename int_type>
597 ViewType getSubview2D(ViewType view, const Kokkos::ALL_t&, Kokkos::pair<int_type,int_type> offset1) const {
598 return Kokkos::subview(view,Kokkos::ALL(),offset1);
599 }
600
601 template <typename ViewType,typename int_type>
602 ViewType getSubview2D(ViewType view, Kokkos::pair<int_type,int_type> offset0, Kokkos::pair<int_type,int_type> offset1) const {
603 return Kokkos::subview(view,offset0,offset1);
604 }
605
606 bool memoryIsAliased() const {
607 return deviceMemoryIsHostAccessible && dualView.h_view.data() == dualView.d_view.data();
608 }
609
627 bool needsSyncPath() const {
628
630 return false;
631
632#ifdef KOKKOS_ENABLE_CUDA
633 return std::is_same<typename t_dev::memory_space,Kokkos::CudaUVMSpace>::value || !memoryIsAliased();
634#elif defined(KOKKOS_ENABLE_SYCL)
635 return std::is_same<typename t_dev::memory_space,Kokkos::Experimental::SYCLSharedUSMSpace>::value || !memoryIsAliased();
636#else
637 return !memoryIsAliased();
638#endif
639 }
640
641
642 void throwIfViewsAreDifferentSizes() const {
643 // Here we check *size* (the product of extents) rather than each extent individually.
644 // This is mostly designed to catch people resizing one view, but not the other.
645 if(dualView.d_view.size() != dualView.h_view.size()) {
646 std::ostringstream msg;
647 msg << "Tpetra::Details::WrappedDualView (name = " << dualView.d_view.label()
648 << "; host and device views are different sizes: "
649 << dualView.h_view.size() << " vs " <<dualView.h_view.size();
650 throw std::runtime_error(msg.str());
651 }
652 }
653
654 void throwIfHostViewAlive() const {
655 throwIfViewsAreDifferentSizes();
656 if (dualView.h_view.use_count() > dualView.d_view.use_count()) {
657 std::ostringstream msg;
658 msg << "Tpetra::Details::WrappedDualView (name = " << dualView.d_view.label()
659 << "; host use_count = " << dualView.h_view.use_count()
660 << "; device use_count = " << dualView.d_view.use_count() << "): "
661 << "Cannot access data on device while a host view is alive";
662 throw std::runtime_error(msg.str());
663 }
664 }
665
666 void throwIfDeviceViewAlive() const {
667 throwIfViewsAreDifferentSizes();
668 if (dualView.d_view.use_count() > dualView.h_view.use_count()) {
669 std::ostringstream msg;
670 msg << "Tpetra::Details::WrappedDualView (name = " << dualView.d_view.label()
671 << "; host use_count = " << dualView.h_view.use_count()
672 << "; device use_count = " << dualView.d_view.use_count() << "): "
673 << "Cannot access data on host while a device view is alive";
674 throw std::runtime_error(msg.str());
675 }
676 }
677
678 bool iAmASubview() {
679 return originalDualView.h_view != dualView.h_view;
680 }
681
682 mutable DualViewType originalDualView;
683 mutable DualViewType dualView;
684};
685
686} // namespace Details
687
688} // namespace Tpetra
689
690#endif
One or more distributed dense vectors.
Nonmember function that computes a residual Computes R = B - A * X.
void disableWDVTracking()
Disable WrappedDualView reference-count tracking and syncing. Call this before entering a host-parall...
bool wdvTrackingEnabled
Whether WrappedDualView reference count checking is enabled. Initially true. Since the DualView sync ...
void enableWDVTracking()
Enable WrappedDualView reference-count tracking and syncing. Call this after exiting a host-parallel ...
Namespace Tpetra contains the class and methods constituting the Tpetra library.