-
Notifications
You must be signed in to change notification settings - Fork 35
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
Support use in CUDA device-side code #20
base: master
Are you sure you want to change the base?
Conversation
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.
Please prefix macros with TCB_SPAN_
rather than just TCB_
, i.e. the new ones should be TCB_SPAN_CUDA_HOST_AND_DEVICE
and TCB_SPAN_CONSTEXPR
.
Other than that this looks good to me.
@tcbrindle : How about now? Also, even if you ok this - don't merge yet. |
@eyalroz I had to make some changes to your tentative span to get it to compile with diff --git a/span.h b/span.h
index 380402b..41a20da 100644
--- a/span.h
+++ b/span.h
@@ -52,6 +52,11 @@
#define TCB_SPAN_CUDA_HOST_AND_DEVICE
#endif
+#ifdef __CUDA_ARCH__
+#define TCB_SPAN_NO_EXCEPTIONS
+#define TCB_SPAN_NO_CONTRACT_CHECKING
+#endif
+
#ifndef TCB_SPAN_NO_EXCEPTIONS
#include <cstdio>
#include <stdexcept>
@@ -169,7 +174,8 @@ using byte = unsigned char;
#define TCB_SPAN_NODISCARD
#endif
-TCB_SPAN_INLINE_VAR constexpr std::size_t dynamic_extent = -1;
+TCB_SPAN_INLINE_VAR constexpr std::size_t dynamic_extent =
+ static_cast<std::size_t>(-1);
template <typename ElementType, std::size_t Extent = dynamic_extent>
class span;
@@ -178,7 +184,7 @@ namespace detail {
template <typename E, std::size_t S>
struct span_storage {
- TCB_SPAN_CONSTEXPR span_storage() noexcept = default;
+ constexpr span_storage() noexcept = default;
TCB_SPAN_CONSTEXPR span_storage(E* ptr, std::size_t /*unused*/) noexcept
: ptr(ptr) {}
@@ -189,7 +195,7 @@ struct span_storage {
template <typename E>
struct span_storage<E, dynamic_extent> {
- TCB_SPAN_CONSTEXPR span_storage() noexcept = default;
+ constexpr span_storage() noexcept = default;
TCB_SPAN_CONSTEXPR span_storage(E* ptr, std::size_t size) noexcept
: ptr(ptr), size(size) {}
@@ -385,7 +391,7 @@ class span {
TCB_SPAN_CONSTEXPR span(const Container& cont)
: storage_(detail::data(cont), detail::size(cont)) {}
- TCB_SPAN_CONSTEXPR span(const span& other) noexcept = default;
+ constexpr span(const span& other) noexcept = default;
template <typename OtherElementType, std::size_t OtherExtent,
typename std::enable_if<
@@ -399,8 +405,7 @@ class span {
~span() noexcept = default;
- TCB_SPAN_CONSTEXPR_ASSIGN span& operator=(const span& other) noexcept =
- default;
+ constexpr span& operator=(const span& other) noexcept = default;
// [span.sub], span subviews
template <std::size_t Count> |
TCB_CONSTEXPR
macro instead ofconstexpr
, to hook our extra decorationsTCB_CONSTEXPR
functions with__host__ __device__
when compiling CUDA code.Notes:
span
s are fully-constexpr.