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

ranges: Add index64_t constructor and deprecate index_t version #102

Merged
merged 1 commit into from
Feb 13, 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
30 changes: 26 additions & 4 deletions src/stdgpu/impl/ranges_detail.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,18 @@ namespace stdgpu

template <typename T>
device_range<T>::device_range(T* p)
: device_range(p, static_cast<index_t>(stdgpu::size(p)))
: device_range(p, stdgpu::size(p))
{

}


template <typename T>
STDGPU_HOST_DEVICE
device_range<T>::device_range(T* p,
index64_t n)
: _begin(p),
_end(p + n)
{

}
Expand Down Expand Up @@ -56,10 +67,18 @@ device_range<T>::end()
}


template <typename T>
host_range<T>::host_range(T* p)
: host_range(p, stdgpu::size(p))
{

}


template <typename T>
STDGPU_HOST_DEVICE
host_range<T>::host_range(T* p,
index_t n)
index64_t n)
: _begin(p),
_end(p + n)
{
Expand All @@ -68,8 +87,11 @@ host_range<T>::host_range(T* p,


template <typename T>
host_range<T>::host_range(T* p)
: host_range(p, static_cast<index_t>(stdgpu::size(p)))
STDGPU_HOST_DEVICE
host_range<T>::host_range(T* p,
index_t n)
: _begin(p),
_end(p + n)
{

}
Expand Down
22 changes: 22 additions & 0 deletions src/stdgpu/ranges.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ class device_range
* \param[in] n The number of array elements
*/
STDGPU_HOST_DEVICE
device_range(T* p,
index64_t n);

/**
* \deprecated Replaced by device_range(T*, index64_t)
* \brief Constructor
* \param[in] p A pointer to the array
* \param[in] n The number of array elements
*/
//[[deprecated("Replaced by device_range(T*, index64_t")]]
STDGPU_HOST_DEVICE
device_range(T* p,
index_t n);

Expand Down Expand Up @@ -100,6 +111,17 @@ class host_range
* \param[in] n The number of array elements
*/
STDGPU_HOST_DEVICE
host_range(T* p,
index64_t n);

/**
* \deprecated Replaced by host_range(T*, index64_t)
* \brief Constructor
* \param[in] p A pointer to the array
* \param[in] n The number of array elements
*/
//[[deprecated("Replaced by host_range(T*, index64_t")]]
STDGPU_HOST_DEVICE
host_range(T* p,
index_t n);

Expand Down
38 changes: 35 additions & 3 deletions test/stdgpu/ranges.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ class transform_range<device_range<int>, thrust::identity<int>>;


TEST_F(stdgpu_ranges, device_range_with_size)
{
const stdgpu::index64_t size = 42;
int* array = createDeviceArray<int>(size);

stdgpu::device_range<int> array_range(array, size);
int* array_begin = array_range.begin().get();
int* array_end = array_range.end().get();

EXPECT_EQ(array_begin, array);
EXPECT_EQ(array_end, array + size);

destroyDeviceArray<int>(array);
}


TEST_F(stdgpu_ranges, device_range_with_size_deprecated)
{
const stdgpu::index_t size = 42;
int* array = createDeviceArray<int>(size);
Expand All @@ -78,7 +94,7 @@ TEST_F(stdgpu_ranges, device_range_with_size)

TEST_F(stdgpu_ranges, device_range_automatic_size)
{
const stdgpu::index_t size = 42;
const stdgpu::index64_t size = 42;
int* array = createDeviceArray<int>(size);

stdgpu::device_range<int> array_range(array);
Expand All @@ -93,6 +109,22 @@ TEST_F(stdgpu_ranges, device_range_automatic_size)


TEST_F(stdgpu_ranges, host_range_with_size)
{
const stdgpu::index64_t size = 42;
int* array = createHostArray<int>(size);

stdgpu::host_range<int> array_range(array, size);
int* array_begin = array_range.begin().get();
int* array_end = array_range.end().get();

EXPECT_EQ(array_begin, array);
EXPECT_EQ(array_end, array + size);

destroyHostArray<int>(array);
}


TEST_F(stdgpu_ranges, host_range_with_size_deprecated)
{
const stdgpu::index_t size = 42;
int* array = createHostArray<int>(size);
Expand All @@ -110,7 +142,7 @@ TEST_F(stdgpu_ranges, host_range_with_size)

TEST_F(stdgpu_ranges, host_range_automatic_size)
{
const stdgpu::index_t size = 42;
const stdgpu::index64_t size = 42;
int* array = createHostArray<int>(size);

stdgpu::host_range<int> array_range(array);
Expand All @@ -137,7 +169,7 @@ struct square

TEST_F(stdgpu_ranges, transform_range)
{
const stdgpu::index_t size = 42;
const stdgpu::index64_t size = 42;
int* array = createHostArray<int>(size);
int* array_result = createHostArray<int>(size);

Expand Down