Skip to content
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

Spell value initialization where used in thrust vectors #1990

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ namespace detail
{

template <typename Allocator, typename Pointer, typename Size>
_CCCL_HOST_DEVICE inline void default_construct_range(Allocator& a, Pointer p, Size n);
_CCCL_HOST_DEVICE inline void value_initialize_range(Allocator& a, Pointer p, Size n);

} // namespace detail
THRUST_NAMESPACE_END

#include <thrust/detail/allocator/default_construct_range.inl>
#include <thrust/detail/allocator/value_initialize_range.inl>
Original file line number Diff line number Diff line change
Expand Up @@ -73,25 +73,25 @@ struct needs_default_construct_via_allocator<std::allocator<U>, T>
template <typename Allocator, typename Pointer, typename Size>
_CCCL_HOST_DEVICE ::cuda::std::__enable_if_t<
needs_default_construct_via_allocator<Allocator, typename pointer_element<Pointer>::type>::value>
default_construct_range(Allocator& a, Pointer p, Size n)
value_initialize_range(Allocator& a, Pointer p, Size n)
{
thrust::for_each_n(allocator_system<Allocator>::get(a), p, n, construct1_via_allocator<Allocator>(a));
}

template <typename Allocator, typename Pointer, typename Size>
_CCCL_HOST_DEVICE
typename disable_if<needs_default_construct_via_allocator<Allocator, typename pointer_element<Pointer>::type>::value>::type
default_construct_range(Allocator& a, Pointer p, Size n)
value_initialize_range(Allocator& a, Pointer p, Size n)
{
thrust::uninitialized_fill_n(allocator_system<Allocator>::get(a), p, n, typename pointer_element<Pointer>::type());
}

} // namespace allocator_traits_detail

template <typename Allocator, typename Pointer, typename Size>
_CCCL_HOST_DEVICE void default_construct_range(Allocator& a, Pointer p, Size n)
_CCCL_HOST_DEVICE void value_initialize_range(Allocator& a, Pointer p, Size n)
{
return allocator_traits_detail::default_construct_range(a, p, n);
return allocator_traits_detail::value_initialize_range(a, p, n);
}

} // namespace detail
Expand Down
2 changes: 1 addition & 1 deletion thrust/thrust/detail/contiguous_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class contiguous_storage

_CCCL_HOST_DEVICE void swap(contiguous_storage& x);

_CCCL_HOST_DEVICE void default_construct_n(iterator first, size_type n);
_CCCL_HOST_DEVICE void value_initialize_n(iterator first, size_type n);

_CCCL_HOST_DEVICE void uninitialized_fill_n(iterator first, size_type n, const value_type& value);

Expand Down
8 changes: 4 additions & 4 deletions thrust/thrust/detail/contiguous_storage.inl
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
#endif // no system header
#include <thrust/detail/allocator/allocator_traits.h>
#include <thrust/detail/allocator/copy_construct_range.h>
#include <thrust/detail/allocator/default_construct_range.h>
#include <thrust/detail/allocator/destroy_range.h>
#include <thrust/detail/allocator/fill_construct_range.h>
#include <thrust/detail/allocator/value_initialize_range.h>
#include <thrust/detail/contiguous_storage.h>
#include <thrust/detail/swap.h>

Expand Down Expand Up @@ -203,10 +203,10 @@ _CCCL_HOST_DEVICE void contiguous_storage<T, Alloc>::swap(contiguous_storage& x)
} // end contiguous_storage::swap()

template <typename T, typename Alloc>
_CCCL_HOST_DEVICE void contiguous_storage<T, Alloc>::default_construct_n(iterator first, size_type n)
_CCCL_HOST_DEVICE void contiguous_storage<T, Alloc>::value_initialize_n(iterator first, size_type n)
{
default_construct_range(m_allocator, first.base(), n);
} // end contiguous_storage::default_construct_n()
value_initialize_range(m_allocator, first.base(), n);
} // end contiguous_storage::value_initialize_n()

template <typename T, typename Alloc>
_CCCL_HOST_DEVICE void
Expand Down
2 changes: 1 addition & 1 deletion thrust/thrust/detail/temporary_array.inl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ _CCCL_HOST_DEVICE ::cuda::std::__enable_if_t<avoid_initialization<T>::value> con
template <typename T, typename TemporaryArray, typename Size>
_CCCL_HOST_DEVICE ::cuda::std::__enable_if_t<!avoid_initialization<T>::value> construct_values(TemporaryArray& a, Size n)
{
a.default_construct_n(a.begin(), n);
a.value_initialize_n(a.begin(), n);
} // end construct_values()

} // namespace temporary_array_detail
Expand Down
12 changes: 5 additions & 7 deletions thrust/thrust/detail/vector_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,12 @@ class vector_base
*/
explicit vector_base(const Alloc& alloc);

/*! This constructor creates a vector_base with default-constructed
* elements.
/*! This constructor creates a vector_base with value-initialized elements.
* \param n The number of elements to create.
*/
explicit vector_base(size_type n);

/*! This constructor creates a vector_base with default-constructed
* elements.
/*! This constructor creates a vector_base with value-initialized elements.
* \param n The number of elements to create.
* \param alloc The allocator to use by this vector_base.
*/
Expand Down Expand Up @@ -210,7 +208,7 @@ class vector_base
* This method will resize this vector_base to the specified number of
* elements. If the number is smaller than this vector_base's current
* size this vector_base is truncated, otherwise this vector_base is
* extended and new elements are default constructed.
* extended and new elements are value initialized.
*/
void resize(size_type new_size);

Expand Down Expand Up @@ -499,7 +497,7 @@ class vector_base
template <typename ForwardIterator>
void range_init(ForwardIterator first, ForwardIterator last, thrust::random_access_traversal_tag);

void default_init(size_type n);
void value_init(size_type n);

void fill_init(size_type n, const T& x);

Expand All @@ -512,7 +510,7 @@ class vector_base
template <typename InputIteratorOrIntegralType>
void insert_dispatch(iterator position, InputIteratorOrIntegralType n, InputIteratorOrIntegralType x, true_type);

// this method appends n default-constructed elements at the end
// this method appends n value-initialized elements at the end
void append(size_type n);

// this method performs insertion from a fill value
Expand Down
14 changes: 7 additions & 7 deletions thrust/thrust/detail/vector_base.inl
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ vector_base<T, Alloc>::vector_base(size_type n)
: m_storage()
, m_size(0)
{
default_init(n);
value_init(n);
} // end vector_base::vector_base()

template <typename T, typename Alloc>
vector_base<T, Alloc>::vector_base(size_type n, const Alloc& alloc)
: m_storage(alloc)
, m_size(0)
{
default_init(n);
value_init(n);
} // end vector_base::vector_base()

template <typename T, typename Alloc>
Expand Down Expand Up @@ -212,16 +212,16 @@ void vector_base<T, Alloc>::init_dispatch(IteratorOrIntegralType n, IteratorOrIn
} // end vector_base::init_dispatch()

template <typename T, typename Alloc>
void vector_base<T, Alloc>::default_init(size_type n)
void vector_base<T, Alloc>::value_init(size_type n)
{
if (n > 0)
{
m_storage.allocate(n);
m_size = n;

m_storage.default_construct_n(begin(), size());
m_storage.value_initialize_n(begin(), size());
} // end if
} // end vector_base::default_init()
} // end vector_base::value_init()

template <typename T, typename Alloc>
void vector_base<T, Alloc>::fill_init(size_type n, const T& x)
Expand Down Expand Up @@ -792,7 +792,7 @@ void vector_base<T, Alloc>::append(size_type n)
// we've got room for all of them

// default construct new elements at the end of the vector
m_storage.default_construct_n(end(), n);
m_storage.value_initialize_n(end(), n);

// extend the size
m_size += n;
Expand Down Expand Up @@ -822,7 +822,7 @@ void vector_base<T, Alloc>::append(size_type n)
new_end = m_storage.uninitialized_copy(begin(), end(), new_storage.begin());

// construct new elements to insert
new_storage.default_construct_n(new_end, n);
new_storage.value_initialize_n(new_end, n);
new_end += n;
} // end try
catch (...)
Expand Down
4 changes: 2 additions & 2 deletions thrust/thrust/device_reference.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ class device_reference : public thrust::reference<T, thrust::device_ptr<T>, thru
}

// declare these members for the purpose of Doxygenating them
// they actually exist in a derived-from class
// they actually exist in a base class
#if 0
/*! Address-of operator returns a \p device_ptr pointing to the object
* referenced by this \p device_reference. It does not return the
Expand Down Expand Up @@ -960,7 +960,7 @@ _CCCL_HOST_DEVICE void swap(device_reference<T>& x, device_reference<T>& y)
}

// declare these methods for the purpose of Doxygenating them
// they actually are defined for a derived-from class
// they actually are defined for a base class
#if THRUST_DOXYGEN
/*! Writes to an output stream the value of a \p device_reference.
*
Expand Down
2 changes: 1 addition & 1 deletion thrust/thrust/device_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ class device_vector : public detail::vector_base<T, Alloc>
{}

// declare these members for the purpose of Doxygenating them
// they actually exist in a derived-from class
// they actually exist in a base class
#if 0
/*! \brief Resizes this vector to the specified number of elements.
* \param new_size Number of elements this vector should contain.
Expand Down
2 changes: 1 addition & 1 deletion thrust/thrust/host_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class host_vector : public detail::vector_base<T, Alloc>
{}

// declare these members for the purpose of Doxygenating them
// they actually exist in a derived-from class
// they actually exist in a base class
#if 0
/*! \brief Resizes this vector to the specified number of elements.
* \param new_size Number of elements this vector should contain.
Expand Down
Loading