-
Notifications
You must be signed in to change notification settings - Fork 21
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
Introduce ldg_ptr to Enable __ldg in Data Stores and simple_ptr_holder #1802
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
a474a09
Added gridtools::as_ldg_ptr and tests
fthaler 8e72be2
Fix unused include
fthaler ce9bf69
CMake for tests
fthaler fca595d
Use ldg_ptr in simple_ptr_holder
fthaler 2f7a48f
Use ldg_ptr in data_store SID adaptor
fthaler 47f5aa3
Remove (now unnecessary) usage of __ldg outside of ldg_ptr
fthaler f1a9ec3
Allow ldg_ptr to be compared to normal pointers; currently required f…
fthaler 274759a
Implement ldg_ptr - ldg_ptr to allow sid_get_default_ptr_diff to work
fthaler 1c43f2e
Revert simple_ptr_holder to an aggregate
fthaler cb15a2b
Fix ldg_ptr tests to use volatile arrays
fthaler a650d51
Added test for ldg_ptr diff operator
fthaler 8722d38
Make ldg_ptr an aggregate
fthaler d81db7a
Re-enable explicit LDG loads in stencil backends for non-const data s…
fthaler 8f43100
Enable explicit LDG loads in fn cartesian
fthaler 9d4e60d
Enable explicit LDG loads in fn unstructured
fthaler 6f4ac92
Enable explicit LDG loads in fn neighbor tables
fthaler 63ffeaa
Updated references
fthaler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* GridTools | ||
* | ||
* Copyright (c) 2014-2023, ETH Zurich | ||
* All rights reserved. | ||
* | ||
* Please, refer to the LICENSE file in the root directory. | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
#pragma once | ||
|
||
#include <cstddef> | ||
#include <type_traits> | ||
#include <utility> | ||
|
||
#include "defs.hpp" | ||
#include "host_device.hpp" | ||
|
||
#ifdef GT_CUDACC | ||
#include "cuda_type_traits.hpp" | ||
#endif | ||
|
||
namespace gridtools { | ||
|
||
#ifdef GT_CUDACC | ||
namespace impl_ { | ||
|
||
template <class T> | ||
struct ldg_ptr { | ||
T const *m_ptr; | ||
|
||
static_assert(is_texture_type<T>::value); | ||
|
||
GT_FUNCTION constexpr T operator*() const { | ||
#ifdef GT_CUDA_ARCH | ||
return __ldg(m_ptr); | ||
#else | ||
return *m_ptr; | ||
#endif | ||
} | ||
|
||
GT_FUNCTION constexpr ldg_ptr &operator+=(std::ptrdiff_t diff) { | ||
m_ptr += diff; | ||
return *this; | ||
} | ||
|
||
GT_FUNCTION constexpr ldg_ptr &operator-=(std::ptrdiff_t diff) { | ||
m_ptr -= diff; | ||
return *this; | ||
} | ||
|
||
friend GT_FUNCTION constexpr bool operator==(ldg_ptr const &a, ldg_ptr const &b) { | ||
return a.m_ptr == b.m_ptr; | ||
} | ||
friend GT_FUNCTION constexpr bool operator==(ldg_ptr const &a, T const *b) { return a.m_ptr == b; } | ||
friend GT_FUNCTION constexpr bool operator==(T const *a, ldg_ptr const &b) { return a == b.m_ptr; } | ||
|
||
friend GT_FUNCTION constexpr bool operator!=(ldg_ptr const &a, ldg_ptr const &b) { | ||
return a.m_ptr != b.m_ptr; | ||
} | ||
friend GT_FUNCTION constexpr bool operator!=(ldg_ptr const &a, T const *b) { return a.m_ptr != b; } | ||
friend GT_FUNCTION constexpr bool operator!=(T const *a, ldg_ptr const &b) { return a != b.m_ptr; } | ||
|
||
friend GT_FUNCTION constexpr ldg_ptr &operator++(ldg_ptr &ptr) { | ||
++ptr.m_ptr; | ||
return ptr; | ||
} | ||
|
||
friend GT_FUNCTION constexpr ldg_ptr &operator--(ldg_ptr &ptr) { | ||
--ptr.m_ptr; | ||
return ptr; | ||
} | ||
|
||
friend GT_FUNCTION constexpr ldg_ptr operator++(ldg_ptr &ptr, int) { | ||
ldg_ptr p = ptr; | ||
++ptr.m_ptr; | ||
return p; | ||
} | ||
|
||
friend GT_FUNCTION constexpr ldg_ptr operator--(ldg_ptr &ptr, int) { | ||
ldg_ptr p = ptr; | ||
--ptr.m_ptr; | ||
return p; | ||
} | ||
|
||
friend GT_FUNCTION constexpr ldg_ptr operator+(ldg_ptr const &ptr, std::ptrdiff_t diff) { | ||
return {ptr.m_ptr + diff}; | ||
} | ||
|
||
friend GT_FUNCTION constexpr ldg_ptr operator-(ldg_ptr const &ptr, std::ptrdiff_t diff) { | ||
return {ptr.m_ptr - diff}; | ||
} | ||
|
||
friend GT_FUNCTION constexpr std::ptrdiff_t operator-(ldg_ptr const &ptr, ldg_ptr const &other) { | ||
return ptr.m_ptr - other.m_ptr; | ||
} | ||
}; | ||
} // namespace impl_ | ||
|
||
template <class T> | ||
GT_FUNCTION constexpr std::enable_if_t<is_texture_type<T>::value, impl_::ldg_ptr<T>> as_ldg_ptr(T const *ptr) { | ||
return {ptr}; | ||
} | ||
|
||
#endif | ||
|
||
template <class T> | ||
GT_FUNCTION constexpr T &&as_ldg_ptr(T &&value) { | ||
return std::forward<T>(value); | ||
} | ||
|
||
} // namespace gridtools |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Not sure I like this fallback. Doesn't it mean that if you wrap any pointer ad "ldg" pointer, which is not "ldg"-capable, it will silently do that. If this is the intent, then at least I don't like the naming.
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.
It doesn’t wrap anything, it just passes unsupported types through as is. We just call this function wherever we would like to use LDG when available. The name might be improvable though, so let me know if you have a better one …