-
Notifications
You must be signed in to change notification settings - Fork 578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tpetra: Don't access DualView's [h|d]_view directly #13778
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,8 +29,8 @@ | |
if (envVarSet && (std::strcmp(envVarSet,"1") == 0)) \ | ||
std::cout << (fn) << " called from " << callerstr \ | ||
<< " at " << filestr << ":"<<linnum \ | ||
<< " host cnt " << dualView.h_view.use_count() \ | ||
<< " device cnt " << dualView.d_view.use_count() \ | ||
<< " host cnt " << dualView.view_host().use_count() \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I’m not sure if it’s an issue, but here, behavior changes, right? Because the getter is making a copy, so we’ll now report the previous use count incremented by one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, in general all use counts will be larger but from what I understand only the difference between host and device is of relevance here. |
||
<< " device cnt " << dualView.view_device().use_count() \ | ||
<< std::endl; \ | ||
} | ||
|
||
|
@@ -210,7 +210,7 @@ class WrappedDualView { | |
} | ||
|
||
size_t extent(const int i) const { | ||
return dualView.h_view.extent(i); | ||
return dualView.view_host().extent(i); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can probably become just |
||
} | ||
|
||
void stride(size_t * stride_) const { | ||
|
@@ -219,11 +219,11 @@ class WrappedDualView { | |
|
||
|
||
size_t origExtent(const int i) const { | ||
return originalDualView.h_view.extent(i); | ||
return originalDualView.view_host().extent(i); | ||
} | ||
|
||
const char * label() const { | ||
return dualView.d_view.label(); | ||
return dualView.view_device().label(); | ||
} | ||
|
||
|
||
|
@@ -551,11 +551,11 @@ class WrappedDualView { | |
} | ||
|
||
int host_view_use_count() const { | ||
return originalDualView.h_view.use_count(); | ||
return originalDualView.view_host().use_count(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here, the increment by one may be worth considering. Similar cases below. |
||
} | ||
|
||
int device_view_use_count() const { | ||
return originalDualView.d_view.use_count(); | ||
return originalDualView.view_device().use_count(); | ||
} | ||
|
||
|
||
|
@@ -597,7 +597,7 @@ class WrappedDualView { | |
} | ||
|
||
bool memoryIsAliased() const { | ||
return deviceMemoryIsHostAccessible && dualView.h_view.data() == dualView.d_view.data(); | ||
return deviceMemoryIsHostAccessible && dualView.view_host().data() == dualView.view_device().data(); | ||
} | ||
|
||
|
||
|
@@ -631,41 +631,41 @@ class WrappedDualView { | |
void throwIfViewsAreDifferentSizes() const { | ||
// Here we check *size* (the product of extents) rather than each extent individually. | ||
// This is mostly designed to catch people resizing one view, but not the other. | ||
if(dualView.d_view.size() != dualView.h_view.size()) { | ||
if(dualView.view_device().size() != dualView.view_host().size()) { | ||
std::ostringstream msg; | ||
msg << "Tpetra::Details::WrappedDualView (name = " << dualView.d_view.label() | ||
msg << "Tpetra::Details::WrappedDualView (name = " << dualView.view_device().label() | ||
<< "; host and device views are different sizes: " | ||
<< dualView.h_view.size() << " vs " <<dualView.h_view.size(); | ||
<< dualView.view_host().size() << " vs " <<dualView.view_host().size(); | ||
throw std::runtime_error(msg.str()); | ||
} | ||
} | ||
|
||
void throwIfHostViewAlive() const { | ||
throwIfViewsAreDifferentSizes(); | ||
if (dualView.h_view.use_count() > dualView.d_view.use_count()) { | ||
if (dualView.view_host().use_count() > dualView.view_device().use_count()) { | ||
std::ostringstream msg; | ||
msg << "Tpetra::Details::WrappedDualView (name = " << dualView.d_view.label() | ||
<< "; host use_count = " << dualView.h_view.use_count() | ||
<< "; device use_count = " << dualView.d_view.use_count() << "): " | ||
msg << "Tpetra::Details::WrappedDualView (name = " << dualView.view_device().label() | ||
<< "; host use_count = " << dualView.view_host().use_count() | ||
<< "; device use_count = " << dualView.view_device().use_count() << "): " | ||
<< "Cannot access data on device while a host view is alive"; | ||
throw std::runtime_error(msg.str()); | ||
} | ||
} | ||
|
||
void throwIfDeviceViewAlive() const { | ||
throwIfViewsAreDifferentSizes(); | ||
if (dualView.d_view.use_count() > dualView.h_view.use_count()) { | ||
if (dualView.view_device().use_count() > dualView.view_host().use_count()) { | ||
std::ostringstream msg; | ||
msg << "Tpetra::Details::WrappedDualView (name = " << dualView.d_view.label() | ||
<< "; host use_count = " << dualView.h_view.use_count() | ||
<< "; device use_count = " << dualView.d_view.use_count() << "): " | ||
msg << "Tpetra::Details::WrappedDualView (name = " << dualView.view_device().label() | ||
<< "; host use_count = " << dualView.view_host().use_count() | ||
<< "; device use_count = " << dualView.view_device().use_count() << "): " | ||
<< "Cannot access data on host while a device view is alive"; | ||
throw std::runtime_error(msg.str()); | ||
} | ||
} | ||
|
||
bool iAmASubview() { | ||
return originalDualView.h_view != dualView.h_view; | ||
return originalDualView.view_host() != dualView.view_host(); | ||
} | ||
|
||
mutable DualViewType originalDualView; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fence is new but seems necessary. The constructor will not fence and the
deep_copy
is asynchronous. The function doesn't take an execution space instance argument so it should be synchronous.