20 #ifndef RAJA_ListSegment_HPP
21 #define RAJA_ListSegment_HPP
23 #include "RAJA/config.hpp"
26 #include <type_traits>
29 #include "camp/resource.hpp"
86 template<
typename StorageT>
123 camp::resources::Resource resource,
125 : m_resource(nullptr),
130 initIndexData(values, length, resource, owned);
145 template<
typename Container>
147 camp::resources::Resource resource)
148 : m_resource(nullptr),
151 m_size(container.
size())
156 camp::resources::Resource host_res {camp::resources::Host::get_default()};
161 auto src = container.begin();
162 auto const end = container.end();
170 m_resource =
new camp::resources::Resource(resource);
171 m_data = m_resource->allocate<
value_type>(m_size);
172 m_resource->memcpy(m_data, tmp,
sizeof(
value_type) * m_size);
176 host_res.deallocate(tmp);
187 : m_resource(nullptr),
189 m_data(other.m_data),
199 m_resource =
nullptr;
201 m_data = other.m_data;
202 m_size = other.m_size;
211 m_resource = rhs.m_resource;
212 m_owned = rhs.m_owned;
216 rhs.m_resource =
nullptr;
218 rhs.m_data =
nullptr;
224 : m_resource(rhs.m_resource),
225 m_owned(rhs.m_owned),
230 rhs.m_resource =
nullptr;
232 rhs.m_data =
nullptr;
242 #if !defined(RAJA_GPU_DEVICE_COMPILE_PASS_ACTIVE)
243 if (m_data !=
nullptr && m_owned ==
Owned)
245 m_resource->deallocate(m_data);
250 m_resource =
nullptr;
300 if (container == m_data)
return len == m_size;
301 if (len != m_size || container ==
nullptr || m_data ==
nullptr)
304 if (m_data[i] != container[i])
return false;
331 return (!(*
this == other));
341 camp::safe_swap(m_resource, other.m_resource);
342 camp::safe_swap(m_data, other.m_data);
343 camp::safe_swap(m_size, other.m_size);
344 camp::safe_swap(m_owned, other.m_owned);
351 void initIndexData(
const value_type* container,
353 camp::resources::Resource resource_,
358 if (len <= 0 || container ==
nullptr)
368 m_owned = container_own;
369 if (m_owned ==
Owned)
372 m_resource =
new camp::resources::Resource(resource_);
374 camp::resources::Resource host_res {camp::resources::Host::get_default()};
380 tmp[i] = container[i];
383 m_data = m_resource->allocate<
value_type>(m_size);
384 m_resource->memcpy(m_data, tmp,
sizeof(
value_type) * m_size);
387 host_res.deallocate(tmp);
398 camp::resources::Resource* m_resource;
419 template<
typename StorageT>
Header file for RAJA span constructs.
Definition: ListSegment.hpp:88
RAJA_HOST_DEVICE TypedListSegment(const TypedListSegment &other)
Copy constructor for list segment.
Definition: ListSegment.hpp:186
TypedListSegment()=delete
Disable compiler generated constructor.
RAJA_HOST_DEVICE TypedListSegment(TypedListSegment &&rhs)
Move constructor for list segment.
Definition: ListSegment.hpp:223
RAJA_HOST_DEVICE iterator end() const
Get iterator to the end of this segment.
Definition: ListSegment.hpp:268
RAJA_HOST_DEVICE TypedListSegment & operator=(const TypedListSegment &other)
Copy assignment for list segment.
Definition: ListSegment.hpp:196
RAJA_HOST_DEVICE void clear()
Clear method to be called.
Definition: ListSegment.hpp:239
RAJA_HOST_DEVICE bool operator==(const TypedListSegment &other) const
Compare this segment to another for equality.
Definition: ListSegment.hpp:316
RAJA_HOST_DEVICE void swap(TypedListSegment &other)
Swap this segment with another.
Definition: ListSegment.hpp:339
StorageT * iterator
The underlying terator type.
Definition: ListSegment.hpp:97
StorageT IndexType
Expose underlying index type for consistency with other segment types.
Definition: ListSegment.hpp:100
RAJA_HOST_DEVICE bool indicesEqual(const value_type *container, Index_type len) const
Compare this segment's indices to an array of values.
Definition: ListSegment.hpp:297
TypedListSegment(const value_type *values, Index_type length, camp::resources::Resource resource, IndexOwnership owned=Owned)
Construct a list segment from given array with specified length and use given camp resource to alloca...
Definition: ListSegment.hpp:121
RAJA_HOST_DEVICE IndexOwnership getIndexOwnership() const
Get ownership of index data (Owned/Unowned)
Definition: ListSegment.hpp:278
StorageT value_type
The underlying value type for index storage.
Definition: ListSegment.hpp:94
RAJA_HOST_DEVICE ~TypedListSegment()
List segment destructor.
Definition: ListSegment.hpp:236
TypedListSegment(const Container &container, camp::resources::Resource resource)
Construct a list segment from given container of indices.
Definition: ListSegment.hpp:146
RAJA_HOST_DEVICE iterator begin() const
Get iterator to the beginning of this segment.
Definition: ListSegment.hpp:263
RAJA_HOST_DEVICE bool operator!=(const TypedListSegment &other) const
Compare this segment to another for inequality.
Definition: ListSegment.hpp:329
RAJA_HOST_DEVICE Index_type size() const
Get size of this segment (number of indices)
Definition: ListSegment.hpp:273
RAJA_HOST_DEVICE TypedListSegment & operator=(TypedListSegment &&rhs)
move assignment for list segment
Definition: ListSegment.hpp:208
Header file for RAJA concept definitions.
Header file for common RAJA internal macro definitions.
#define RAJA_HOST_DEVICE
Definition: macros.hpp:65
Definition: AlignedRangeIndexSetBuilders.cpp:35
IndexOwnership
Definition: types.hpp:218
@ Owned
Definition: types.hpp:220
@ Unowned
Definition: types.hpp:219
std::ptrdiff_t Index_type
Definition: types.hpp:226
Definition: ListSegment.hpp:416
RAJA_INLINE void swap(RAJA::TypedListSegment< StorageT > &a, RAJA::TypedListSegment< StorageT > &b)
Specialization of std::swap for TypedListSegment.
Definition: ListSegment.hpp:420
Header file for RAJA type definitions.