Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Replace allocator and vector classes with alias templates #1221

Merged
merged 1 commit into from
Jul 28, 2020
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
59 changes: 1 addition & 58 deletions thrust/system/cpp/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,72 +66,15 @@ inline pointer<T> malloc(std::size_t n);
*/
inline void free(pointer<void> ptr);

// XXX upon c++11
// template<typename T>
// using allocator = thrust::mr::stateless_resource_allocator<T, memory_resource>;

/*! \p cpp::allocator is the default allocator used by the \p cpp system's containers such as
* <tt>cpp::vector</tt> if no user-specified allocator is provided. \p cpp::allocator allocates
* (deallocates) storage with \p cpp::malloc (\p cpp::free).
*/
template<typename T>
struct allocator
: thrust::mr::stateless_resource_allocator<
T,
memory_resource
>
{
private:
typedef thrust::mr::stateless_resource_allocator<
T,
memory_resource
> base;

public:
/*! The \p rebind metafunction provides the type of an \p allocator
* instantiated with another type.
*
* \tparam U The other type to use for instantiation.
*/
template<typename U>
struct rebind
{
/*! The typedef \p other gives the type of the rebound \p allocator.
*/
typedef allocator<U> other;
};

/*! No-argument constructor has no effect.
*/
__host__ __device__
inline allocator() {}

/*! Copy constructor has no effect.
*/
__host__ __device__
inline allocator(const allocator & other) : base(other) {}

/*! Constructor from other \p allocator has no effect.
*/
template<typename U>
__host__ __device__
inline allocator(const allocator<U> & other) : base(other) {}

#if THRUST_CPP_DIALECT >= 2011
allocator & operator=(const allocator &) = default;
#endif

/*! Destructor has no effect.
*/
__host__ __device__
inline ~allocator() {}
}; // end allocator
using allocator = thrust::mr::stateless_resource_allocator<T, memory_resource>;

} // end cpp

/*! \}
*/

} // end system

/*! \namespace thrust::cpp
Expand Down
103 changes: 1 addition & 102 deletions thrust/system/cpp/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ namespace system
namespace cpp
{

// XXX upon c++11
// template<typename T, typename Allocator = allocator<T> > using vector = thrust::detail::vector_base<T,Allocator>;

/*! \p cpp::vector is a container that supports random access to elements,
* constant time removal of elements at the end, and linear time insertion
* and removal of elements at the beginning or in the middle. The number of
Expand All @@ -56,102 +53,7 @@ namespace cpp
* \see device_vector
*/
template<typename T, typename Allocator = allocator<T> >
class vector
: public thrust::detail::vector_base<T,Allocator>
{
/*! \cond
*/
private:
typedef thrust::detail::vector_base<T,Allocator> super_t;
/*! \endcond
*/

public:

/*! \cond
*/
typedef typename super_t::size_type size_type;
typedef typename super_t::value_type value_type;

/*! \endcond
*/

/*! This constructor creates an empty \p cpp::vector.
*/
vector();

/*! This constructor creates a \p cpp::vector with \p n default-constructed elements.
* \param n The size of the \p cpp::vector to create.
*/
explicit vector(size_type n);

/*! This constructor creates a \p cpp::vector with \p n copies of \p value.
* \param n The size of the \p cpp::vector to create.
* \param value An element to copy.
*/
explicit vector(size_type n, const value_type &value);

/*! Copy constructor copies from another \p cpp::vector.
* \param x The other \p cpp::vector to copy.
*/
vector(const vector &x);

#if THRUST_CPP_DIALECT >= 2011
/*! Move constructor moves from over another \p cpp::vector.
* \param x The other \p cpp::vector to move from.
*/
vector(vector &&x);
#endif

/*! This constructor copies from another Thrust vector-like object.
* \param x The other object to copy from.
*/
template<typename OtherT, typename OtherAllocator>
vector(const thrust::detail::vector_base<OtherT,OtherAllocator> &x);

/*! This constructor copies from a \c std::vector.
* \param x The \c std::vector to copy from.
*/
template<typename OtherT, typename OtherAllocator>
vector(const std::vector<OtherT,OtherAllocator> &x);

/*! This constructor creates a \p cpp::vector by copying from a range.
* \param first The beginning of the range.
* \param last The end of the range.
*/
template<typename InputIterator>
vector(InputIterator first, InputIterator last);

// XXX vector_base should take a Derived type so we don't have to define these superfluous assigns

/*! Assignment operator assigns from another \p cpp::vector.
* \param x The other object to assign from.
* \return <tt>*this</tt>
*/
vector &operator=(const vector &x);

#if THRUST_CPP_DIALECT >= 2011
/*! Move assignment operator moves from another \p cpp::vector.
* \param x The other \p cpp::vector to move from.
* \return <tt>*this</tt>
*/
vector &operator=(vector &&x);
#endif

/*! Assignment operator assigns from a \c std::vector.
* \param x The \c std::vector to assign from.
* \return <tt>*this</tt>
*/
template<typename OtherT, typename OtherAllocator>
vector &operator=(const std::vector<OtherT,OtherAllocator> &x);

/*! Assignment operator assigns from another Thrust vector-like object.
* \param x The other object to assign from.
* \return <tt>*this</tt>
*/
template<typename OtherT, typename OtherAllocator>
vector &operator=(const thrust::detail::vector_base<OtherT,OtherAllocator> &x);
}; // end vector
using vector = thrust::detail::vector_base<T, Allocator>;

} // end cpp
} // end system
Expand All @@ -165,6 +67,3 @@ using thrust::system::cpp::vector;
} // end cpp

} // end thrust

#include <thrust/system/cpp/detail/vector.inl>

122 changes: 0 additions & 122 deletions thrust/system/cuda/detail/vector.inl

This file was deleted.

58 changes: 2 additions & 56 deletions thrust/system/cuda/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,66 +64,12 @@ inline __host__ __device__ pointer<T> malloc(std::size_t n);
*/
inline __host__ __device__ void free(pointer<void> ptr);

// XXX upon c++11
// template<typename T>
// using allocator = thrust::mr::stateless_resource_allocator<T, memory_resource>;

/*! \p cuda::allocator is the default allocator used by the \p cuda system's containers such as
* <tt>cuda::vector</tt> if no user-specified allocator is provided. \p cuda::allocator allocates
* (deallocates) storage with \p cuda::malloc (\p cuda::free).
*/
template <typename T>
struct allocator
: thrust::mr::stateless_resource_allocator<
T,
system::cuda::memory_resource
>
{
private:
typedef thrust::mr::stateless_resource_allocator<
T,
system::cuda::memory_resource
> base;

public:
/*! The \p rebind metafunction provides the type of an \p allocator
* instantiated with another type.
*
* \tparam U The other type to use for instantiation.
*/
template <typename U>
struct rebind
{
/*! The typedef \p other gives the type of the rebound \p allocator.
*/
typedef allocator<U> other;
};

/*! No-argument constructor has no effect.
*/
__host__
inline allocator() {}

/*! Copy constructor has no effect.
*/
__host__ __device__
inline allocator(const allocator & other) : base(other) {}

/*! Constructor from other \p allocator has no effect.
*/
template <typename U>
__host__ __device__
inline allocator(const allocator<U> & other) : base(other) {}

#if THRUST_CPP_DIALECT >= 2011
allocator & operator=(const allocator &) = default;
#endif

/*! Destructor has no effect.
*/
__host__ __device__
inline ~allocator() {}
}; // struct allocator
template<typename T>
using allocator = thrust::mr::stateless_resource_allocator<T, system::cuda::memory_resource>;

} // namespace cuda_cub

Expand Down
Loading