diff --git a/test/stdgpu/CMakeLists.txt b/test/stdgpu/CMakeLists.txt index 99488699e..27e2b7174 100644 --- a/test/stdgpu/CMakeLists.txt +++ b/test/stdgpu/CMakeLists.txt @@ -2,15 +2,16 @@ add_executable(teststdgpu main.cpp) target_sources(teststdgpu PRIVATE cuda/atomic.cu + cuda/bit.cu algorithm.cpp atomic.cu - bit.cu + bit.cpp bitset.cu cmath.cpp cstdlib.cpp deque.cu functional.cpp - iterator.cu + iterator.cpp limits.cpp memory.cpp memory.cu diff --git a/test/stdgpu/bit.cu b/test/stdgpu/bit.cpp similarity index 57% rename from test/stdgpu/bit.cu rename to test/stdgpu/bit.cpp index 0a5029bac..40c8d6315 100644 --- a/test/stdgpu/bit.cu +++ b/test/stdgpu/bit.cpp @@ -15,19 +15,13 @@ #include -#include #include #include #include -#include #include -#include -#include #include #include -#include -#include @@ -137,7 +131,7 @@ TEST_F(stdgpu_bit, mod2_one_zero) } -TEST_F(stdgpu_bit, log2pow2_host) +TEST_F(stdgpu_bit, log2pow2) { for (size_t i = 0; i < std::numeric_limits::digits; ++i) { @@ -145,35 +139,6 @@ TEST_F(stdgpu_bit, log2pow2_host) } } -struct log2pow2_functor -{ - STDGPU_HOST_DEVICE size_t - operator()(const size_t i) const - { - return stdgpu::log2pow2(static_cast(1) << i); - } -}; - -TEST_F(stdgpu_bit, log2pow2_device) -{ - size_t* powers = createDeviceArray(std::numeric_limits::digits); - thrust::sequence(stdgpu::device_begin(powers), stdgpu::device_end(powers)); - - thrust::transform(stdgpu::device_begin(powers), stdgpu::device_end(powers), - stdgpu::device_begin(powers), - log2pow2_functor()); - - size_t* host_powers = copyCreateDevice2HostArray(powers, std::numeric_limits::digits); - - for (size_t i = 0; i < std::numeric_limits::digits; ++i) - { - EXPECT_EQ(host_powers[i], static_cast(i)); - } - - destroyDeviceArray(powers); - destroyHostArray(host_powers); -} - TEST_F(stdgpu_bit, popcount_zero) { @@ -181,7 +146,7 @@ TEST_F(stdgpu_bit, popcount_zero) } -TEST_F(stdgpu_bit, popcount_pow2_host) +TEST_F(stdgpu_bit, popcount_pow2) { for (size_t i = 0; i < std::numeric_limits::digits; ++i) { @@ -189,37 +154,8 @@ TEST_F(stdgpu_bit, popcount_pow2_host) } } -struct popcount_pow2 -{ - STDGPU_HOST_DEVICE size_t - operator()(const size_t i) const - { - return stdgpu::popcount(static_cast(1) << i); - } -}; - -TEST_F(stdgpu_bit, popcount_pow2_device) -{ - size_t* powers = createDeviceArray(std::numeric_limits::digits); - thrust::sequence(stdgpu::device_begin(powers), stdgpu::device_end(powers)); - - thrust::transform(stdgpu::device_begin(powers), stdgpu::device_end(powers), - stdgpu::device_begin(powers), - popcount_pow2()); - - size_t* host_powers = copyCreateDevice2HostArray(powers, std::numeric_limits::digits); - - for (size_t i = 0; i < std::numeric_limits::digits; ++i) - { - EXPECT_EQ(host_powers[i], 1); - } - - destroyDeviceArray(powers); - destroyHostArray(host_powers); -} - -TEST_F(stdgpu_bit, popcount_pow2m1_host) +TEST_F(stdgpu_bit, popcount_pow2m1) { for (size_t i = 0; i < std::numeric_limits::digits; ++i) { @@ -227,33 +163,3 @@ TEST_F(stdgpu_bit, popcount_pow2m1_host) } } - -struct popcount_pow2m1 -{ - STDGPU_HOST_DEVICE size_t - operator()(const size_t i) const - { - return stdgpu::popcount((static_cast(1) << i) - 1); - } -}; - -TEST_F(stdgpu_bit, popcount_pow2m1_device) -{ - size_t* powers = createDeviceArray(std::numeric_limits::digits); - thrust::sequence(stdgpu::device_begin(powers), stdgpu::device_end(powers)); - - thrust::transform(stdgpu::device_begin(powers), stdgpu::device_end(powers), - stdgpu::device_begin(powers), - popcount_pow2m1()); - - size_t* host_powers = copyCreateDevice2HostArray(powers, std::numeric_limits::digits); - - for (size_t i = 0; i < std::numeric_limits::digits; ++i) - { - EXPECT_EQ(host_powers[i], i); - } - - destroyDeviceArray(powers); - destroyHostArray(host_powers); -} - diff --git a/test/stdgpu/cuda/bit.cu b/test/stdgpu/cuda/bit.cu new file mode 100644 index 000000000..f12a538b0 --- /dev/null +++ b/test/stdgpu/cuda/bit.cu @@ -0,0 +1,133 @@ +/* + * Copyright 2019 Patrick Stotko + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include + +#include +#include +#include + + + +class stdgpu_cuda_bit : public ::testing::Test +{ + protected: + // Called before each test + virtual void SetUp() + { + + } + + // Called after each test + virtual void TearDown() + { + + } + +}; + + +struct log2pow2_functor +{ + STDGPU_DEVICE_ONLY size_t + operator()(const size_t i) const + { + return stdgpu::cuda::log2pow2(static_cast(1) << i); + } +}; + +TEST_F(stdgpu_cuda_bit, log2pow2) +{ + size_t* powers = createDeviceArray(std::numeric_limits::digits); + thrust::sequence(stdgpu::device_begin(powers), stdgpu::device_end(powers)); + + thrust::transform(stdgpu::device_begin(powers), stdgpu::device_end(powers), + stdgpu::device_begin(powers), + log2pow2_functor()); + + size_t* host_powers = copyCreateDevice2HostArray(powers, std::numeric_limits::digits); + + for (size_t i = 0; i < std::numeric_limits::digits; ++i) + { + EXPECT_EQ(host_powers[i], static_cast(i)); + } + + destroyDeviceArray(powers); + destroyHostArray(host_powers); +} + + +struct popcount_pow2 +{ + STDGPU_DEVICE_ONLY size_t + operator()(const size_t i) const + { + return stdgpu::cuda::popcount(static_cast(1) << i); + } +}; + +TEST_F(stdgpu_cuda_bit, popcount_pow2) +{ + size_t* powers = createDeviceArray(std::numeric_limits::digits); + thrust::sequence(stdgpu::device_begin(powers), stdgpu::device_end(powers)); + + thrust::transform(stdgpu::device_begin(powers), stdgpu::device_end(powers), + stdgpu::device_begin(powers), + popcount_pow2()); + + size_t* host_powers = copyCreateDevice2HostArray(powers, std::numeric_limits::digits); + + for (size_t i = 0; i < std::numeric_limits::digits; ++i) + { + EXPECT_EQ(host_powers[i], 1); + } + + destroyDeviceArray(powers); + destroyHostArray(host_powers); +} + + +struct popcount_pow2m1 +{ + STDGPU_DEVICE_ONLY size_t + operator()(const size_t i) const + { + return stdgpu::popcount((static_cast(1) << i) - 1); + } +}; + +TEST_F(stdgpu_cuda_bit, popcount_pow2m1) +{ + size_t* powers = createDeviceArray(std::numeric_limits::digits); + thrust::sequence(stdgpu::device_begin(powers), stdgpu::device_end(powers)); + + thrust::transform(stdgpu::device_begin(powers), stdgpu::device_end(powers), + stdgpu::device_begin(powers), + popcount_pow2m1()); + + size_t* host_powers = copyCreateDevice2HostArray(powers, std::numeric_limits::digits); + + for (size_t i = 0; i < std::numeric_limits::digits; ++i) + { + EXPECT_EQ(host_powers[i], i); + } + + destroyDeviceArray(powers); + destroyHostArray(host_powers); +} + diff --git a/test/stdgpu/iterator.cpp b/test/stdgpu/iterator.cpp new file mode 100644 index 000000000..e00b8a196 --- /dev/null +++ b/test/stdgpu/iterator.cpp @@ -0,0 +1,365 @@ +/* + * Copyright 2019 Patrick Stotko + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include +#include + +#include +#include + + + +class stdgpu_iterator : public ::testing::Test +{ + protected: + // Called before each test + virtual void SetUp() + { + + } + + // Called after each test + virtual void TearDown() + { + + } + +}; + + +TEST_F(stdgpu_iterator, size_device_void) +{ + int* array = createDeviceArray(42); + + EXPECT_EQ(stdgpu::size((void*)array), 42 * sizeof(int)); + + destroyDeviceArray(array); +} + + +TEST_F(stdgpu_iterator, size_host_void) +{ + int* array_result = createHostArray(42); + + EXPECT_EQ(stdgpu::size((void*)array_result), 42 * sizeof(int)); + + destroyHostArray(array_result); +} + + +TEST_F(stdgpu_iterator, size_nullptr_void) +{ + EXPECT_EQ(stdgpu::size((void*)nullptr), static_cast(0)); +} + + +TEST_F(stdgpu_iterator, size_device) +{ + int* array = createDeviceArray(42); + + EXPECT_EQ(stdgpu::size(array), static_cast(42)); + + destroyDeviceArray(array); +} + + +TEST_F(stdgpu_iterator, size_host) +{ + int* array_result = createHostArray(42); + + EXPECT_EQ(stdgpu::size(array_result), static_cast(42)); + + destroyHostArray(array_result); +} + + +TEST_F(stdgpu_iterator, size_nullptr) +{ + EXPECT_EQ(stdgpu::size((int*)nullptr), static_cast(0)); +} + + +TEST_F(stdgpu_iterator, size_device_shifted) +{ + int* array = createDeviceArray(42); + + EXPECT_EQ(stdgpu::size(array + 24), static_cast(0)); + + destroyDeviceArray(array); +} + + +TEST_F(stdgpu_iterator, size_host_shifted) +{ + int* array_result = createHostArray(42); + + EXPECT_EQ(stdgpu::size(array_result + 24), static_cast(0)); + + destroyHostArray(array_result); +} + + +TEST_F(stdgpu_iterator, size_device_wrong_alignment) +{ + int* array = createDeviceArray(1); + + EXPECT_EQ(stdgpu::size(reinterpret_cast(array)), static_cast(0)); + + destroyDeviceArray(array); +} + + +TEST_F(stdgpu_iterator, size_host_wrong_alignment) +{ + int* array_result = createHostArray(1); + + EXPECT_EQ(stdgpu::size(reinterpret_cast(array_result)), static_cast(0)); + + destroyHostArray(array_result); +} + + +TEST_F(stdgpu_iterator, device_begin_end) +{ + int* array = createDeviceArray(42); + + int* array_begin = stdgpu::device_begin(array).get(); + int* array_end = stdgpu::device_end( array).get(); + + EXPECT_EQ(array_begin, array); + EXPECT_EQ(array_end, array + 42); + + destroyDeviceArray(array); +} + + +TEST_F(stdgpu_iterator, host_begin_end) +{ + int* array_result = createHostArray(42); + + int* array_result_begin = stdgpu::host_begin(array_result).get(); + int* array_result_end = stdgpu::host_end( array_result).get(); + + EXPECT_EQ(array_result_begin, array_result); + EXPECT_EQ(array_result_end, array_result + 42); + + destroyHostArray(array_result); +} + + +TEST_F(stdgpu_iterator, device_begin_end_const) +{ + int* array = createDeviceArray(42); + + const int* array_begin = stdgpu::device_begin(reinterpret_cast(array)).get(); + const int* array_end = stdgpu::device_end( reinterpret_cast(array)).get(); + + EXPECT_EQ(array_begin, array); + EXPECT_EQ(array_end, array + 42); + + destroyDeviceArray(array); +} + + +TEST_F(stdgpu_iterator, host_begin_end_const) +{ + int* array_result = createHostArray(42); + + const int* array_result_begin = stdgpu::host_begin(reinterpret_cast(array_result)).get(); + const int* array_result_end = stdgpu::host_end( reinterpret_cast(array_result)).get(); + + EXPECT_EQ(array_result_begin, array_result); + EXPECT_EQ(array_result_end, array_result + 42); + + destroyHostArray(array_result); +} + + +TEST_F(stdgpu_iterator, device_cbegin_cend) +{ + int* array = createDeviceArray(42); + + const int* array_begin = stdgpu::device_cbegin(array).get(); + const int* array_end = stdgpu::device_cend( array).get(); + + EXPECT_EQ(array_begin, array); + EXPECT_EQ(array_end, array + 42); + + destroyDeviceArray(array); +} + + +TEST_F(stdgpu_iterator, host_cbegin_cend) +{ + int* array_result = createHostArray(42); + + const int* array_result_begin = stdgpu::host_cbegin(array_result).get(); + const int* array_result_end = stdgpu::host_cend( array_result).get(); + + EXPECT_EQ(array_result_begin, array_result); + EXPECT_EQ(array_result_end, array_result + 42); + + destroyHostArray(array_result); +} + + +struct back_insert_interface +{ + using value_type = std::vector::value_type; + + back_insert_interface(std::vector& vector) + : vector(vector) + { + + } + + void + push_back(const int x) + { + vector.push_back(x); + } + + std::vector& vector; +}; + + +struct front_insert_interface +{ + using value_type = std::vector::value_type; + + front_insert_interface(std::vector& vector) + : vector(vector) + { + + } + + void + push_front(const int x) + { + vector.push_back(x); + } + + std::vector& vector; +}; + + +struct insert_interface +{ + using value_type = std::vector::value_type; + + insert_interface(std::vector& vector) + : vector(vector) + { + + } + + void + insert(const int x) + { + vector.push_back(x); + } + + std::vector& vector; +}; + + +TEST_F(stdgpu_iterator, back_inserter) +{ + const stdgpu::index_t N = 100000; + + int* array = createHostArray(N); + std::vector numbers; + + thrust::sequence(stdgpu::host_begin(array), stdgpu::host_end(array), + 1); + + back_insert_interface ci(numbers); + thrust::copy(stdgpu::host_cbegin(array), stdgpu::host_cend(array), + stdgpu::back_inserter(ci)); + + int* array_result = copyCreateHost2HostArray(numbers.data(), N, MemoryCopy::NO_CHECK); + + thrust::sort(stdgpu::host_begin(array_result), stdgpu::host_end(array_result)); + + for (stdgpu::index_t i = 0; i < N; ++i) + { + EXPECT_EQ(array_result[i], i + 1); + } + + destroyHostArray(array_result); + destroyHostArray(array); +} + + +TEST_F(stdgpu_iterator, front_inserter) +{ + const stdgpu::index_t N = 100000; + + int* array = createHostArray(N); + std::vector numbers; + + thrust::sequence(stdgpu::host_begin(array), stdgpu::host_end(array), + 1); + + front_insert_interface ci(numbers); + thrust::copy(stdgpu::host_cbegin(array), stdgpu::host_cend(array), + stdgpu::front_inserter(ci)); + + int* array_result = copyCreateHost2HostArray(numbers.data(), N, MemoryCopy::NO_CHECK); + + thrust::sort(stdgpu::host_begin(array_result), stdgpu::host_end(array_result)); + + for (stdgpu::index_t i = 0; i < N; ++i) + { + EXPECT_EQ(array_result[i], i + 1); + } + + destroyHostArray(array_result); + destroyHostArray(array); +} + + +TEST_F(stdgpu_iterator, inserter) +{ + const stdgpu::index_t N = 100000; + + int* array = createHostArray(N); + std::vector numbers; + + thrust::sequence(stdgpu::host_begin(array), stdgpu::host_end(array), + 1); + + insert_interface ci(numbers); + thrust::copy(stdgpu::host_cbegin(array), stdgpu::host_cend(array), + stdgpu::inserter(ci)); + + int* array_result = copyCreateHost2HostArray(numbers.data(), N, MemoryCopy::NO_CHECK); + + thrust::sort(stdgpu::host_begin(array_result), stdgpu::host_end(array_result)); + + for (stdgpu::index_t i = 0; i < N; ++i) + { + EXPECT_EQ(array_result[i], i + 1); + } + + destroyHostArray(array_result); + destroyHostArray(array); +} + + diff --git a/test/stdgpu/iterator.cu b/test/stdgpu/iterator.cu deleted file mode 100644 index aba48b321..000000000 --- a/test/stdgpu/iterator.cu +++ /dev/null @@ -1,370 +0,0 @@ -/* - * Copyright 2019 Patrick Stotko - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include -#include -#include -#include -#include - -#include -#include -#include - - - -class stdgpu_iterator : public ::testing::Test -{ - protected: - // Called before each test - virtual void SetUp() - { - - } - - // Called after each test - virtual void TearDown() - { - - } - -}; - - -TEST_F(stdgpu_iterator, size_device_void) -{ - int* array_device = createDeviceArray(42); - - EXPECT_EQ(stdgpu::size((void*)array_device), 42 * sizeof(int)); - - destroyDeviceArray(array_device); -} - - -TEST_F(stdgpu_iterator, size_host_void) -{ - int* array_host = createHostArray(42); - - EXPECT_EQ(stdgpu::size((void*)array_host), 42 * sizeof(int)); - - destroyHostArray(array_host); -} - - -TEST_F(stdgpu_iterator, size_nullptr_void) -{ - EXPECT_EQ(stdgpu::size((void*)nullptr), static_cast(0)); -} - - -TEST_F(stdgpu_iterator, size_device) -{ - int* array_device = createDeviceArray(42); - - EXPECT_EQ(stdgpu::size(array_device), static_cast(42)); - - destroyDeviceArray(array_device); -} - - -TEST_F(stdgpu_iterator, size_host) -{ - int* array_host = createHostArray(42); - - EXPECT_EQ(stdgpu::size(array_host), static_cast(42)); - - destroyHostArray(array_host); -} - - -TEST_F(stdgpu_iterator, size_nullptr) -{ - EXPECT_EQ(stdgpu::size((int*)nullptr), static_cast(0)); -} - - -TEST_F(stdgpu_iterator, size_device_shifted) -{ - int* array_device = createDeviceArray(42); - - EXPECT_EQ(stdgpu::size(array_device + 24), static_cast(0)); - - destroyDeviceArray(array_device); -} - - -TEST_F(stdgpu_iterator, size_host_shifted) -{ - int* array_host = createHostArray(42); - - EXPECT_EQ(stdgpu::size(array_host + 24), static_cast(0)); - - destroyHostArray(array_host); -} - - -TEST_F(stdgpu_iterator, size_device_wrong_alignment) -{ - int* array_device = createDeviceArray(1); - - EXPECT_EQ(stdgpu::size(reinterpret_cast(array_device)), static_cast(0)); - - destroyDeviceArray(array_device); -} - - -TEST_F(stdgpu_iterator, size_host_wrong_alignment) -{ - int* array_host = createHostArray(1); - - EXPECT_EQ(stdgpu::size(reinterpret_cast(array_host)), static_cast(0)); - - destroyHostArray(array_host); -} - - -TEST_F(stdgpu_iterator, device_begin_end) -{ - int* array_device = createDeviceArray(42); - - int* array_device_begin = stdgpu::device_begin(array_device).get(); - int* array_device_end = stdgpu::device_end( array_device).get(); - - EXPECT_EQ(array_device_begin, array_device); - EXPECT_EQ(array_device_end, array_device + 42); - - destroyDeviceArray(array_device); -} - - -TEST_F(stdgpu_iterator, host_begin_end) -{ - int* array_host = createHostArray(42); - - int* array_host_begin = stdgpu::host_begin(array_host).get(); - int* array_host_end = stdgpu::host_end( array_host).get(); - - EXPECT_EQ(array_host_begin, array_host); - EXPECT_EQ(array_host_end, array_host + 42); - - destroyHostArray(array_host); -} - - -TEST_F(stdgpu_iterator, device_begin_end_const) -{ - int* array_device = createDeviceArray(42); - - const int* array_device_begin = stdgpu::device_begin(reinterpret_cast(array_device)).get(); - const int* array_device_end = stdgpu::device_end( reinterpret_cast(array_device)).get(); - - EXPECT_EQ(array_device_begin, array_device); - EXPECT_EQ(array_device_end, array_device + 42); - - destroyDeviceArray(array_device); -} - - -TEST_F(stdgpu_iterator, host_begin_end_const) -{ - int* array_host = createHostArray(42); - - const int* array_host_begin = stdgpu::host_begin(reinterpret_cast(array_host)).get(); - const int* array_host_end = stdgpu::host_end( reinterpret_cast(array_host)).get(); - - EXPECT_EQ(array_host_begin, array_host); - EXPECT_EQ(array_host_end, array_host + 42); - - destroyHostArray(array_host); -} - - -TEST_F(stdgpu_iterator, device_cbegin_cend) -{ - int* array_device = createDeviceArray(42); - - const int* array_device_begin = stdgpu::device_cbegin(array_device).get(); - const int* array_device_end = stdgpu::device_cend( array_device).get(); - - EXPECT_EQ(array_device_begin, array_device); - EXPECT_EQ(array_device_end, array_device + 42); - - destroyDeviceArray(array_device); -} - - -TEST_F(stdgpu_iterator, host_cbegin_cend) -{ - int* array_host = createHostArray(42); - - const int* array_host_begin = stdgpu::host_cbegin(array_host).get(); - const int* array_host_end = stdgpu::host_cend( array_host).get(); - - EXPECT_EQ(array_host_begin, array_host); - EXPECT_EQ(array_host_end, array_host + 42); - - destroyHostArray(array_host); -} - - -struct back_insert_interface -{ - using value_type = stdgpu::vector::value_type; - - back_insert_interface(const stdgpu::vector& vector) - : vector(vector) - { - - } - - inline STDGPU_DEVICE_ONLY void - push_back(const int x) - { - vector.push_back(x); - } - - stdgpu::vector vector; -}; - - -struct front_insert_interface -{ - using value_type = stdgpu::vector::value_type; - - front_insert_interface(const stdgpu::vector& vector) - : vector(vector) - { - - } - - inline STDGPU_DEVICE_ONLY void - push_front(const int x) - { - vector.push_back(x); - } - - stdgpu::vector vector; -}; - - -struct insert_interface -{ - using value_type = stdgpu::vector::value_type; - - insert_interface(const stdgpu::vector& vector) - : vector(vector) - { - - } - - inline STDGPU_DEVICE_ONLY void - insert(const int x) - { - vector.push_back(x); - } - - stdgpu::vector vector; -}; - - -TEST_F(stdgpu_iterator, back_inserter) -{ - const stdgpu::index_t N = 100000; - - int* array_device = createDeviceArray(N); - stdgpu::vector numbers = stdgpu::vector::createDeviceObject(N); - - thrust::sequence(stdgpu::device_begin(array_device), stdgpu::device_end(array_device), - 1); - - back_insert_interface ci(numbers); - thrust::copy(stdgpu::device_cbegin(array_device), stdgpu::device_cend(array_device), - stdgpu::back_inserter(ci)); - - int* array_host = copyCreateDevice2HostArray(numbers.data(), N); - - thrust::sort(stdgpu::host_begin(array_host), stdgpu::host_end(array_host)); - - for (stdgpu::index_t i = 0; i < N; ++i) - { - EXPECT_EQ(array_host[i], i + 1); - } - - destroyHostArray(array_host); - stdgpu::vector::destroyDeviceObject(numbers); - destroyDeviceArray(array_device); -} - - -TEST_F(stdgpu_iterator, front_inserter) -{ - const stdgpu::index_t N = 100000; - - int* array_device = createDeviceArray(N); - stdgpu::vector numbers = stdgpu::vector::createDeviceObject(N); - - thrust::sequence(stdgpu::device_begin(array_device), stdgpu::device_end(array_device), - 1); - - front_insert_interface ci(numbers); - thrust::copy(stdgpu::device_cbegin(array_device), stdgpu::device_cend(array_device), - stdgpu::front_inserter(ci)); - - int* array_host = copyCreateDevice2HostArray(numbers.data(), N); - - thrust::sort(stdgpu::host_begin(array_host), stdgpu::host_end(array_host)); - - for (stdgpu::index_t i = 0; i < N; ++i) - { - EXPECT_EQ(array_host[i], i + 1); - } - - destroyHostArray(array_host); - stdgpu::vector::destroyDeviceObject(numbers); - destroyDeviceArray(array_device); -} - - -TEST_F(stdgpu_iterator, inserter) -{ - const stdgpu::index_t N = 100000; - - int* array_device = createDeviceArray(N); - stdgpu::vector numbers = stdgpu::vector::createDeviceObject(N); - - thrust::sequence(stdgpu::device_begin(array_device), stdgpu::device_end(array_device), - 1); - - insert_interface ci(numbers); - thrust::copy(stdgpu::device_cbegin(array_device), stdgpu::device_cend(array_device), - stdgpu::inserter(ci)); - - int* array_host = copyCreateDevice2HostArray(numbers.data(), N); - - thrust::sort(stdgpu::host_begin(array_host), stdgpu::host_end(array_host)); - - for (stdgpu::index_t i = 0; i < N; ++i) - { - EXPECT_EQ(array_host[i], i + 1); - } - - destroyHostArray(array_host); - stdgpu::vector::destroyDeviceObject(numbers); - destroyDeviceArray(array_device); -} - -