-
Notifications
You must be signed in to change notification settings - Fork 187
Expose support for <iterator> and <array> #243
Conversation
Closes #51 |
@griwes / @jrhemstad If anyone wants to take a particular look at changes for |
Can you summarize the problem/solution? I'm guessing something to do with |
include/cuda/std/array
Outdated
#include "iterator" | ||
#include "utility" | ||
|
||
#include <initializer_list> |
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.
@jrhemstad This is mostly what I was talking about. We can't use cuda::std::initializer_list
, due to the implicit construction of a std::initializer_list
.
The compiler might insert something like the below, and if we are really certain on using a cuda::std::initializer_list
we would need to add an implicit conversion which makes 'our' initializer_list
behave weird: https://gcc.godbolt.org/z/EG739eEdP
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.
Yeah, I don't see how we're going to get around this. intializer_list
is a type that has special rules that the compiler follows that we can't really emulate with cuda::std::initializer_list
.
@@ -1749,14 +1749,14 @@ reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np]) | |||
|
|||
template <class _Ep> | |||
_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 | |||
reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il) | |||
reverse_iterator<const _Ep*> rbegin(::std::initializer_list<_Ep> __il) |
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.
@jrhemstad hacks here.
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 seems fine to me.
cfa48ad
to
312aaf0
Compare
@@ -7,7 +7,7 @@ root_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) | |||
stdlib_headers=$(<"${root_dir}/maintenance/stdlib-headers") | |||
header_replacements=$(echo "${stdlib_headers}" | sed 's#<\(.*\)>#-e s:<\1>:<cuda/std/\1>:g#') | |||
|
|||
find "${root_dir}/test" -name "*.cpp" | | |||
find "${root_dir}/test/std/iterators" -name "*.cpp" | |
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.
I don't think you meant to keep this ;>
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 should be fixed now.
@@ -13,7 +13,7 @@ | |||
/* | |||
algorithm synopsis | |||
|
|||
#include <initializer_list> | |||
#include <::std::initializer_list> |
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.
Tell me you've just run search+replace without telling me... :D
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.
Also fixed. >.>
@@ -3302,6 +3336,7 @@ partition_copy(_InputIterator __first, _InputIterator __last, | |||
// partition_point | |||
|
|||
template<class _ForwardIterator, class _Predicate> | |||
_LIBCUDACXX_INLINE_VISIBILITY |
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.
We probably also want _LIBCUDACXX_EXECUTION_SPACE_SPECIFIER
for the ones here and above? I assume this is where you invented the new macro.
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.
I'm wary to do that, when building source files in libcxx there are places where some extra ABI flags are set that may matter. The ones I've marked are mainly internal and inline.
Putting _LIBCUDACXX_INLINE_VISIBLITY
on those causes them to fail to build due to the linkage flags.
e.g.
#if __has_attribute(internal_linkage)
# define _LIBCUDACXX_INTERNAL_LINKAGE __attribute__ ((internal_linkage))
#else
# define _LIBCUDACXX_INTERNAL_LINKAGE _LIBCUDACXX_ALWAYS_INLINE
#endif
|
||
_Tp __elems_[_Size]; | ||
|
||
// No explicit construct/copy/destroy for aggregate type | ||
_LIBCUDACXX_INLINE_VISIBILITY void fill(const value_type& __u) { | ||
_CUDA_VSTD::fill_n(__elems_, _Size, __u); | ||
fill_n(__elems_, _Size, __u); |
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 (and swap_ranges below) are now ADL calls, we need to keep them qualified.
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.
I've replaced _CUDA_VSTD::
on this and below.
@@ -714,7 +714,7 @@ public: | |||
_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 | |||
reference operator*() const {_Iter __tmp = current; return *--__tmp;} | |||
_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 | |||
pointer operator->() const {return _CUDA_VSTD::addressof(operator*());} | |||
pointer operator->() const {return addressof(operator*());} |
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.
Needs to be qualified to avoid ADL.
@@ -1168,7 +1168,7 @@ public: | |||
_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 | |||
move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;} | |||
_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 | |||
reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); } | |||
reference operator[](difference_type __n) const { return move(__i[__n]); } |
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.
Ditto.
@@ -1749,14 +1749,14 @@ reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np]) | |||
|
|||
template <class _Ep> | |||
_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 | |||
reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il) | |||
reverse_iterator<const _Ep*> rbegin(::std::initializer_list<_Ep> __il) |
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 seems fine to me.
NV_IF_ELSE_TARGET( | ||
NV_IS_DEVICE, | ||
__trap();, | ||
_CUDA_VSTD::abort(); | ||
) |
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.
Somewhere above you're made a macro for this, though using if/else on __CUDA_ARCH__
instead of if target. Should we replace that with what's in here, and just use the macro here to avoid repeating this construct?
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.
Which macro was this?
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.
Replaced with _LIBCUDACXX_UNREACHABLE
8804caf
to
fe8f048
Compare
…erts ::std::initializer_list into the cuda:: namespace
…ted in some libcu++ things were expected in std::
Co-authored-by: Jake Hemstad <jhemstad@nvidia.com>
8d9bff1
to
6496c8e
Compare
<cuda/std/array> + <cuda/std/iterator> - Statically sized arrays and iterators.
Adds support for cuda::std::array and cuda::std::iterator.
Details
Motivation
array<T,N>
class.--expt-relaxed-constexpr
is required to allow users to usestd::array
in device code.Impact
<cuda/std/array>
and<cuda/std/iterator>
headers.algorithm
as an implementation detail. Full support will come later.Checklists
Testing