Update vector tests and add vector manipulation tests.
MODIFY
test/CMakeLists.txt
test/CMakeLists.txt
@@ -64,3 +64,4 @@ add_hipthrust_test("thrust.hip.sort" test_sort.cpp)
add_hipthrust_test("thrust.hip.device_ptr" test_device_ptr.cpp)
add_hipthrust_test("thrust.hip.device_reference" test_device_reference.cpp)
add_hipthrust_test("thrust.hip.vector" test_vector.cpp)
+add_hipthrust_test("thrust.hip.vector_manipulation" test_vector_manipulation.cpp)

MODIFY
test/test_vector.cpp
test/test_vector.cpp
@@ -81,15 +81,6 @@ typedef ::testing::Types<
TYPED_TEST_CASE(VectorTests, VectorTestsParams);
-std::vector<size_t> get_sizes()
-{
- std::vector<size_t> sizes = {
- 0, 1, 2, 12, 63, 64, 211, 256, 344,
- 1024, 2048, 5096, 34567, (1 << 17) - 1220
- };
- return sizes;
-}
-
#if THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_HCC
TYPED_TEST(VectorTests, TestVectorZeroSize)
@@ -332,4 +323,497 @@ TYPED_TEST(VectorTests, TestVectorToAndFromHostVector)
ASSERT_EQ(v, h);
}
+
+// TODO: Implement reduce in system
+/*TYPED_TEST(VectorTests, TestVectorAssignFromDeviceVector)
+{
+ using Vector = typename TestFixture::input_type;
+ using T = typename Vector::value_type;
+
+ thrust::device_vector<T> d(3);
+ d[0] = T(0);
+ d[1] = T(1);
+ d[2] = T(2);
+
+ Vector v;
+ v.assign(d.begin(), d.end());
+
+ ASSERT_EQ(v, d);
+}
+
+// TODO: Implement reduce in system
+TYPED_TEST(VectorTests, TestVectorToAndFromDeviceVector)
+{
+ using Vector = typename TestFixture::input_type;
+ using T = typename Vector::value_type;
+
+ thrust::device_vector<T> h(3);
+ h[0] = T(0);
+ h[1] = T(1);
+ h[2] = T(2);
+
+ Vector v(h);
+
+ ASSERT_EQ(v, h);
+
+ v[0] = T(10);
+ v[1] = T(11);
+ v[2] = T(12);
+
+ ASSERT_EQ(h[0], T(0)); ASSERT_EQ(v[0], T(10));
+ ASSERT_EQ(h[1], T(1)); ASSERT_EQ(v[1], T(11));
+ ASSERT_EQ(h[2], T(2)); ASSERT_EQ(v[2], T(12));
+
+ h = v;
+
+ ASSERT_EQ(v, h);
+
+ h[1] = T(11);
+
+ v = h;
+
+ ASSERT_EQ(v, h);
+}*/
+
+TYPED_TEST(VectorTests, TestVectorWithInitialValue)
+{
+ using Vector = typename TestFixture::input_type;
+ using T = typename Vector::value_type;
+
+ const T init = T(17);
+
+ Vector v(3, init);
+
+ ASSERT_EQ(v.size(), 3);
+ ASSERT_EQ(v[0], init);
+ ASSERT_EQ(v[1], init);
+ ASSERT_EQ(v[2], init);
+}
+
+TYPED_TEST(VectorTests, TestVectorSwap)
+{
+ using Vector = typename TestFixture::input_type;
+ using T = typename Vector::value_type;
+
+ Vector v(3);
+ v[0] = T(0); v[1] = T(1); v[2] = T(2);
+
+ Vector u(3);
+ u[0] = T(10); u[1] = T(11); u[2] = T(12);
+
+ v.swap(u);
+
+ ASSERT_EQ(v[0], T(10)); ASSERT_EQ(u[0], T(0));
+ ASSERT_EQ(v[1], T(11)); ASSERT_EQ(u[1], T(1));
+ ASSERT_EQ(v[2], T(12)); ASSERT_EQ(u[2], T(2));
+}
+
+TYPED_TEST(VectorTests, TestVectorErasePosition)
+{
+ using Vector = typename TestFixture::input_type;
+ using T = typename Vector::value_type;
+
+ Vector v(5);
+ v[0] = T(0); v[1] = T(1); v[2] = T(2); v[3] = T(3); v[4] = T(4);
+
+ v.erase(v.begin() + 2);
+
+ ASSERT_EQ(v.size(), 4);
+ ASSERT_EQ(v[0], T(0));
+ ASSERT_EQ(v[1], T(1));
+ ASSERT_EQ(v[2], T(3));
+ ASSERT_EQ(v[3], T(4));
+
+ v.erase(v.begin() + 0);
+
+ ASSERT_EQ(v.size(), 3);
+ ASSERT_EQ(v[0], T(1));
+ ASSERT_EQ(v[1], T(3));
+ ASSERT_EQ(v[2], T(4));
+
+ v.erase(v.begin() + 2);
+
+ ASSERT_EQ(v.size(), 2);
+ ASSERT_EQ(v[0], T(1));
+ ASSERT_EQ(v[1], T(3));
+
+ v.erase(v.begin() + 1);
+
+ ASSERT_EQ(v.size(), T(1));
+ ASSERT_EQ(v[0], T(1));
+
+ v.erase(v.begin() + 0);
+
+ ASSERT_EQ(v.size(), 0);
+}
+
+TYPED_TEST(VectorTests, TestVectorEraseRange)
+{
+ using Vector = typename TestFixture::input_type;
+ using T = typename Vector::value_type;
+
+ Vector v(6);
+ v[0] = T(0); v[1] = T(1); v[2] = T(2); v[3] = T(3); v[4] = T(4); v[5] = T(5);
+
+ v.erase(v.begin() + 1, v.begin() + 3);
+
+ ASSERT_EQ(v.size(), 4);
+ ASSERT_EQ(v[0], T(0));
+ ASSERT_EQ(v[1], T(3));
+ ASSERT_EQ(v[2], T(4));
+ ASSERT_EQ(v[3], T(5));
+
+ v.erase(v.begin() + 2, v.end());
+
+ ASSERT_EQ(v.size(), 2);
+ ASSERT_EQ(v[0], T(0));
+ ASSERT_EQ(v[1], T(3));
+
+ v.erase(v.begin() + 0, v.begin() + 1);
+
+ ASSERT_EQ(v.size(), 1);
+ ASSERT_EQ(v[0], T(3));
+
+ v.erase(v.begin(), v.end());
+
+ ASSERT_EQ(v.size(), 0);
+}
+
+TYPED_TEST(VectorTests, TestVectorEquality)
+{
+ using Vector = typename TestFixture::input_type;
+ using T = typename Vector::value_type;
+
+ thrust::host_vector<T> h_a(3);
+ thrust::host_vector<T> h_b(3);
+ thrust::host_vector<T> h_c(3);
+ h_a[0] = T(0); h_a[1] = T(1); h_a[2] = T(2);
+ h_b[0] = T(0); h_b[1] = T(1); h_b[2] = T(3);
+ h_b[0] = T(0); h_b[1] = T(1);
+
+ thrust::device_vector<T> d_a(3);
+ thrust::device_vector<T> d_b(3);
+ thrust::device_vector<T> d_c(3);
+ d_a[0] = T(0); d_a[1] = T(1); d_a[2] = T(2);
+ d_b[0] = T(0); d_b[1] = T(1); d_b[2] = T(3);
+ d_b[0] = T(0); d_b[1] = T(1);
+
+ std::vector<T> s_a(3);
+ std::vector<T> s_b(3);
+ std::vector<T> s_c(3);
+ s_a[0] = T(0); s_a[1] = T(1); s_a[2] = T(2);
+ s_b[0] = T(0); s_b[1] = T(1); s_b[2] = T(3);
+ s_b[0] = T(0); s_b[1] = T(1);
+
+ // TODO: Implement reduce in system
+ ASSERT_EQ((h_a == h_a), true); //ASSERT_EQ((h_a == d_a), true); ASSERT_EQ((d_a == h_a), true); ASSERT_EQ((d_a == d_a), true);
+ ASSERT_EQ((h_b == h_b), true); //ASSERT_EQ((h_b == d_b), true); ASSERT_EQ((d_b == h_b), true); ASSERT_EQ((d_b == d_b), true);
+ ASSERT_EQ((h_c == h_c), true); //ASSERT_EQ((h_c == d_c), true); ASSERT_EQ((d_c == h_c), true); ASSERT_EQ((d_c == d_c), true);
+
+ // test vector vs device_vector
+ //ASSERT_EQ((s_a == d_a), true); ASSERT_EQ((d_a == s_a), true);
+ //ASSERT_EQ((s_b == d_b), true); ASSERT_EQ((d_b == s_b), true);
+ //ASSERT_EQ((s_c == d_c), true); ASSERT_EQ((d_c == s_c), true);
+
+ // test vector vs host_vector
+ ASSERT_EQ((s_a == h_a), true); ASSERT_EQ((h_a == s_a), true);
+ ASSERT_EQ((s_b == h_b), true); ASSERT_EQ((h_b == s_b), true);
+ ASSERT_EQ((s_c == h_c), true); ASSERT_EQ((h_c == s_c), true);
+
+ ASSERT_EQ((h_a == h_b), false); /*ASSERT_EQ((h_a == d_b), false); ASSERT_EQ((d_a == h_b), false); ASSERT_EQ((d_a == d_b), false);*/
+ ASSERT_EQ((h_b == h_a), false); /*ASSERT_EQ((h_b == d_a), false); ASSERT_EQ((d_b == h_a), false); ASSERT_EQ((d_b == d_a), false);*/
+ ASSERT_EQ((h_a == h_c), false); /*ASSERT_EQ((h_a == d_c), false); ASSERT_EQ((d_a == h_c), false); ASSERT_EQ((d_a == d_c), false);*/
+ ASSERT_EQ((h_c == h_a), false); /*ASSERT_EQ((h_c == d_a), false); ASSERT_EQ((d_c == h_a), false); ASSERT_EQ((d_c == d_a), false);*/
+ ASSERT_EQ((h_b == h_c), false); /*ASSERT_EQ((h_b == d_c), false); ASSERT_EQ((d_b == h_c), false); ASSERT_EQ((d_b == d_c), false);*/
+ ASSERT_EQ((h_c == h_b), false); /*ASSERT_EQ((h_c == d_b), false); ASSERT_EQ((d_c == h_b), false); ASSERT_EQ((d_c == d_b), false);*/
+
+ // test vector vs device_vector
+ //ASSERT_EQ((s_a == d_b), false); ASSERT_EQ((d_a == s_b), false);
+ //ASSERT_EQ((s_b == d_a), false); ASSERT_EQ((d_b == s_a), false);
+ //ASSERT_EQ((s_a == d_c), false); ASSERT_EQ((d_a == s_c), false);
+ //ASSERT_EQ((s_c == d_a), false); ASSERT_EQ((d_c == s_a), false);
+ //ASSERT_EQ((s_b == d_c), false); ASSERT_EQ((d_b == s_c), false);
+ //ASSERT_EQ((s_c == d_b), false); ASSERT_EQ((d_c == s_b), false);
+
+ // test vector vs host_vector
+ ASSERT_EQ((s_a == h_b), false); ASSERT_EQ((h_a == s_b), false);
+ ASSERT_EQ((s_b == h_a), false); ASSERT_EQ((h_b == s_a), false);
+ ASSERT_EQ((s_a == h_c), false); ASSERT_EQ((h_a == s_c), false);
+ ASSERT_EQ((s_c == h_a), false); ASSERT_EQ((h_c == s_a), false);
+ ASSERT_EQ((s_b == h_c), false); ASSERT_EQ((h_b == s_c), false);
+ ASSERT_EQ((s_c == h_b), false); ASSERT_EQ((h_c == s_b), false);
+}
+
+TYPED_TEST(VectorTests, TestVectorInequality)
+{
+ using Vector = typename TestFixture::input_type;
+ using T = typename Vector::value_type;
+
+ thrust::host_vector<T> h_a(3);
+ thrust::host_vector<T> h_b(3);
+ thrust::host_vector<T> h_c(3);
+ h_a[0] = T(0); h_a[1] = T(1); h_a[2] = T(2);
+ h_b[0] = T(0); h_b[1] = T(1); h_b[2] = T(3);
+ h_b[0] = T(0); h_b[1] = T(1);
+
+ thrust::device_vector<T> d_a(3);
+ thrust::device_vector<T> d_b(3);
+ thrust::device_vector<T> d_c(3);
+ d_a[0] = T(0); d_a[1] = T(1); d_a[2] = T(2);
+ d_b[0] = T(0); d_b[1] = T(1); d_b[2] = T(3);
+ d_b[0] = T(0); d_b[1] = T(1);
+
+ std::vector<T> s_a(3);
+ std::vector<T> s_b(3);
+ std::vector<T> s_c(3);
+ s_a[0] = T(0); s_a[1] = T(1); s_a[2] = T(2);
+ s_b[0] = T(0); s_b[1] = T(1); s_b[2] = T(3);
+ s_b[0] = T(0); s_b[1] = T(1);
+
+ // TODO: Implement reduce in system
+ ASSERT_EQ((h_a != h_a), false); //ASSERT_EQ((h_a != d_a), false); ASSERT_EQ((d_a != h_a), false); ASSERT_EQ((d_a != d_a), false);
+ ASSERT_EQ((h_b != h_b), false); //ASSERT_EQ((h_b != d_b), false); ASSERT_EQ((d_b != h_b), false); ASSERT_EQ((d_b != d_b), false);
+ ASSERT_EQ((h_c != h_c), false); //ASSERT_EQ((h_c != d_c), false); ASSERT_EQ((d_c != h_c), false); ASSERT_EQ((d_c != d_c), false);
+
+ // test vector vs device_vector
+ //ASSERT_EQ((s_a != d_a), false); ASSERT_EQ((d_a != s_a), false);
+ //ASSERT_EQ((s_b != d_b), false); ASSERT_EQ((d_b != s_b), false);
+ //ASSERT_EQ((s_c != d_c), false); ASSERT_EQ((d_c != s_c), false);
+
+ // test vector vs host_vector
+ ASSERT_EQ((s_a != h_a), false); ASSERT_EQ((h_a != s_a), false);
+ ASSERT_EQ((s_b != h_b), false); ASSERT_EQ((h_b != s_b), false);
+ ASSERT_EQ((s_c != h_c), false); ASSERT_EQ((h_c != s_c), false);
+
+ ASSERT_EQ((h_a != h_b), true); //ASSERT_EQ((h_a != d_b), true); ASSERT_EQ((d_a != h_b), true); ASSERT_EQ((d_a != d_b), true);
+ ASSERT_EQ((h_b != h_a), true); //ASSERT_EQ((h_b != d_a), true); ASSERT_EQ((d_b != h_a), true); ASSERT_EQ((d_b != d_a), true);
+ ASSERT_EQ((h_a != h_c), true); //ASSERT_EQ((h_a != d_c), true); ASSERT_EQ((d_a != h_c), true); ASSERT_EQ((d_a != d_c), true);
+ ASSERT_EQ((h_c != h_a), true); //ASSERT_EQ((h_c != d_a), true); ASSERT_EQ((d_c != h_a), true); ASSERT_EQ((d_c != d_a), true);
+ ASSERT_EQ((h_b != h_c), true); //ASSERT_EQ((h_b != d_c), true); ASSERT_EQ((d_b != h_c), true); ASSERT_EQ((d_b != d_c), true);
+ ASSERT_EQ((h_c != h_b), true); //ASSERT_EQ((h_c != d_b), true); ASSERT_EQ((d_c != h_b), true); ASSERT_EQ((d_c != d_b), true);
+
+ // test vector vs device_vector
+ //ASSERT_EQ((s_a != d_b), true); ASSERT_EQ((d_a != s_b), true);
+ //ASSERT_EQ((s_b != d_a), true); ASSERT_EQ((d_b != s_a), true);
+ //ASSERT_EQ((s_a != d_c), true); ASSERT_EQ((d_a != s_c), true);
+ //ASSERT_EQ((s_c != d_a), true); ASSERT_EQ((d_c != s_a), true);
+ //ASSERT_EQ((s_b != d_c), true); ASSERT_EQ((d_b != s_c), true);
+ //ASSERT_EQ((s_c != d_b), true); ASSERT_EQ((d_c != s_b), true);
+
+ // test vector vs host_vector
+ ASSERT_EQ((s_a != h_b), true); ASSERT_EQ((h_a != s_b), true);
+ ASSERT_EQ((s_b != h_a), true); ASSERT_EQ((h_b != s_a), true);
+ ASSERT_EQ((s_a != h_c), true); ASSERT_EQ((h_a != s_c), true);
+ ASSERT_EQ((s_c != h_a), true); ASSERT_EQ((h_c != s_a), true);
+ ASSERT_EQ((s_b != h_c), true); ASSERT_EQ((h_b != s_c), true);
+ ASSERT_EQ((s_c != h_b), true); ASSERT_EQ((h_c != s_b), true);
+}
+
+TYPED_TEST(VectorTests, TestVectorResizing)
+{
+ using Vector = typename TestFixture::input_type;
+ using T = typename Vector::value_type;
+
+ Vector v;
+
+ v.resize(3);
+
+ ASSERT_EQ(v.size(), 3);
+
+ v[0] = T(0); v[1] = T(1); v[2] = T(2);
+
+ v.resize(5);
+
+ ASSERT_EQ(v.size(), 5);
+
+ ASSERT_EQ(v[0], T(0));
+ ASSERT_EQ(v[1], T(1));
+ ASSERT_EQ(v[2], T(2));
+
+ v[3] = T(3); v[4] = T(4);
+
+ v.resize(4);
+
+ ASSERT_EQ(v.size(), 4);
+
+ ASSERT_EQ(v[0], T(0));
+ ASSERT_EQ(v[1], T(1));
+ ASSERT_EQ(v[2], T(2));
+ ASSERT_EQ(v[3], T(3));
+
+ v.resize(0);
+
+ ASSERT_EQ(v.size(), 0);
+}
+
+TYPED_TEST(VectorTests, TestVectorReserving)
+{
+ using Vector = typename TestFixture::input_type;
+
+ Vector v;
+
+ v.reserve(3);
+
+ ASSERT_EQ(v.capacity(), 3);
+
+ size_t old_capacity = v.capacity();
+
+ v.reserve(0);
+
+ ASSERT_EQ(v.capacity(), old_capacity);
+}
+
+TYPED_TEST(VectorTests, TestVectorShrinkToFit)
+{
+ using Vector = typename TestFixture::input_type;
+ using T = typename Vector::value_type;
+
+ Vector v;
+
+ v.reserve(200);
+
+ ASSERT_EQ(v.capacity(), 200);
+
+ v.push_back(T(1));
+ v.push_back(T(2));
+ v.push_back(T(3));
+
+ v.shrink_to_fit();
+
+ ASSERT_EQ(T(1), v[0]);
+ ASSERT_EQ(T(2), v[1]);
+ ASSERT_EQ(T(3), v[2]);
+ ASSERT_EQ( 3, v.size());
+ ASSERT_EQ( 3, v.capacity());
+}
+
+// TODO: Implement reduce in system
+/*
+template <int N>
+struct LargeStruct
+{
+ int data[N];
+
+ __host__ __device__
+ bool operator==(const LargeStruct & ls) const
+ {
+ for (int i = 0; i < N; i++)
+ if (data[i] != ls.data[i])
+ return false;
+ return true;
+ }
+};
+
+TEST(VectorTests, TestVectorContainingLargeType)
+{
+ const static int N = 100;
+ using T = LargeStruct<N> T;
+
+ thrust::device_vector<T> dv1;
+ thrust::host_vector<T> hv1;
+
+ ASSERT_EQ(dv1, hv1);
+
+ thrust::device_vector<T> dv2(20);
+ thrust::host_vector<T> hv2(20);
+
+ ASSERT_EQ(dv2, hv2);
+
+ // initialize tofirst element to something nonzero
+ T ls;
+
+ for (int i = 0; i < N; i++)
+ ls.data[i] = i;
+
+ thrust::device_vector<T> dv3(20, ls);
+ thrust::host_vector<T> hv3(20, ls);
+
+ ASSERT_EQ(dv3, hv3);
+
+ // change first element
+ ls.data[0] = -13;
+
+ dv3[2] = ls;
+ hv3[2] = ls;
+
+ ASSERT_EQ(dv3, hv3);
+}*/
+
+TYPED_TEST(VectorTests, TestVectorReversed)
+{
+ using Vector = typename TestFixture::input_type;
+ using T = typename Vector::value_type;
+
+ Vector v(3);
+ v[0] = T(0); v[1] = T(1); v[2] = T(2);
+
+ ASSERT_EQ(3, v.rend() - v.rbegin());
+ ASSERT_EQ(3, static_cast<const Vector&>(v).rend() - static_cast<const Vector&>(v).rbegin());
+ ASSERT_EQ(3, v.crend() - v.crbegin());
+
+ ASSERT_EQ(T(2), *v.rbegin());
+ ASSERT_EQ(T(2), *static_cast<const Vector&>(v).rbegin());
+ ASSERT_EQ(T(2), *v.crbegin());
+
+ ASSERT_EQ(T(1), *(v.rbegin() + 1));
+ ASSERT_EQ(T(0), *(v.rbegin() + 2));
+
+ ASSERT_EQ(T(0), *(v.rend() - 1));
+ ASSERT_EQ(T(1), *(v.rend() - 2));
+}
+
+#if __cplusplus >= 201103L
+TYPED_TEST(VectorTests, TestVectorMove)
+{
+ using Vector = typename TestFixture::input_type;
+ using T = typename Vector::value_type;
+
+ //test move construction
+ Vector v1(3);
+ v1[0] = T(0); v1[1] = T(1); v1[2] = T(2);
+
+ const auto ptr1 = v1.data();
+ const auto size1 = v1.size();
+
+ Vector v2(std::move(v1));
+ const auto ptr2 = v2.data();
+ const auto size2 = v2.size();
+
+ // ensure v1 was left empty
+ ASSERT_EQ(true, v1.empty());
+
+ // ensure v2 received the data from before
+ ASSERT_EQ(v2[0], T(0));
+ ASSERT_EQ(v2[1], T(1));
+ ASSERT_EQ(v2[2], T(2));
+ ASSERT_EQ(size1, size2);
+
+ // ensure v2 received the pointer from before
+ ASSERT_EQ(ptr1, ptr2);
+
+ //test move assignment
+ Vector v3(3);
+ v3[0] = T(3); v3[1] = T(4); v3[2] = T(5);
+
+ const auto ptr3 = v3.data();
+ const auto size3 = v3.size();
+
+ v2 = std::move(v3);
+ const auto ptr4 = v2.data();
+ const auto size4 = v2.size();
+
+ // ensure v3 was left empty
+ ASSERT_EQ(true, v3.empty());
+
+ // ensure v2 received the data from before
+ ASSERT_EQ(v2[0], T(3));
+ ASSERT_EQ(v2[1], T(4));
+ ASSERT_EQ(v2[2], T(5));
+ ASSERT_EQ(size3, size4);
+
+ // ensure v2 received the pointer from before
+ ASSERT_EQ(ptr3, ptr4);
+}
+#endif
+
#endif // THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_HCC

ADD
test/test_vector_manipulation.cpp
+// MIT License
+//
+// Copyright (c) 2018 Advanced Micro Devices, Inc. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all
+// copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+// SOFTWARE.
+
+#include <vector>
+
+// Google Test
+#include <gtest/gtest.h>
+
+// Thrust include
+#include <thrust/device_malloc_allocator.h>
+#include <thrust/device_vector.h>
+#include <thrust/host_vector.h>
+
+// HIP API
+#if THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_HCC
+#include <hip/hip_runtime_api.h>
+#include <hip/hip_runtime.h>
+
+#include <algorithm>
+#include <random>
+
+template<class T>
+inline auto get_random_data(size_t size, T min, T max)
+ -> typename std::enable_if<rocprim::is_integral<T>::value, thrust::host_vector<T>>::type
+{
+ std::random_device rd;
+ std::default_random_engine gen(rd());
+ std::uniform_int_distribution<T> distribution(min, max);
+ thrust::host_vector<T> data(size);
+ std::generate(data.begin(), data.end(), [&]() { return distribution(gen); });
+ return data;
+}
+
+template<class T>
+inline auto get_random_data(size_t size, T min, T max)
+ -> typename std::enable_if<rocprim::is_floating_point<T>::value, thrust::host_vector<T>>::type
+{
+ std::random_device rd;
+ std::default_random_engine gen(rd());
+ std::uniform_real_distribution<T> distribution(min, max);
+ thrust::host_vector<T> data(size);
+ std::generate(data.begin(), data.end(), [&]() { return distribution(gen); });
+ return data;
+}
+
+#define HIP_CHECK(condition) ASSERT_EQ(condition, hipSuccess)
+#endif // THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_HCC
+
+template<
+ class InputType
+>
+struct Params
+{
+ using input_type = InputType;
+};
+
+template<class Params>
+class VectorManipulationTests : public ::testing::Test
+{
+public:
+ using input_type = typename Params::input_type;
+};
+
+typedef ::testing::Types<
+ Params<thrust::host_vector<short>>,
+ Params<thrust::host_vector<int>>,
+ Params<thrust::host_vector<long long>>,
+ Params<thrust::host_vector<unsigned short>>,
+ Params<thrust::host_vector<unsigned int>>,
+ Params<thrust::host_vector<unsigned long long>>,
+ Params<thrust::host_vector<float>>,
+ Params<thrust::host_vector<double>>,
+ Params<thrust::device_vector<short>>,
+ Params<thrust::device_vector<int>>,
+ Params<thrust::device_vector<long long>>,
+ Params<thrust::device_vector<unsigned short>>,
+ Params<thrust::device_vector<unsigned int>>,
+ Params<thrust::device_vector<unsigned long long>>,
+ Params<thrust::device_vector<float>>,
+ Params<thrust::device_vector<double>>
+> VectorManipulationTestsParams;
+
+TYPED_TEST_CASE(VectorManipulationTests, VectorManipulationTestsParams);
+
+std::vector<size_t> get_sizes()
+{
+ std::vector<size_t> sizes = {
+ 0, 1, 2, 12, 63, 64, 211, 256, 344,
+ 1024, 2048, 5096, 34567, (1 << 17) - 1220
+ };
+ return sizes;
+}
+
+#if THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_HCC
+
+TYPED_TEST(VectorManipulationTests, TestVectorManipulation)
+{
+ using Vector = typename TestFixture::input_type;
+ using T = typename Vector::value_type;
+ using Iterator = typename Vector::iterator;
+
+ const std::vector<size_t> sizes = get_sizes();
+ for(auto size : sizes)
+ {
+ thrust::host_vector<T> src;
+ if (std::is_floating_point<T>::value)
+ {
+ src = get_random_data<T>(size, (T)-1000, (T)+1000);
+ }
+ else
+ {
+ src = get_random_data<T>(
+ size,
+ std::numeric_limits<T>::min(),
+ std::numeric_limits<T>::max()
+ );
+ }
+
+ ASSERT_EQ(src.size(), size);
+
+ // basic initialization
+ Vector test0(size);
+ Vector test1(size, T(3));
+ ASSERT_EQ(test0.size(), size);
+ ASSERT_EQ(test1.size(), size);
+ ASSERT_EQ((test1 == std::vector<T>(size, T(3))), true);
+
+ #if (THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_MSVC) && (_MSC_VER <= 1400)
+ // XXX MSVC 2005's STL unintentionally uses adl to dispatch advance which
+ // produces an ambiguity between std::advance & thrust::advance
+ // don't produce a KNOWN_FAILURE, just ignore the issue
+ #else
+ // initializing from other vector
+ std::vector<T> stl_vector(src.begin(), src.end());
+ Vector cpy0 = src;
+ Vector cpy1(stl_vector);
+ Vector cpy2(stl_vector.begin(), stl_vector.end());
+ // TODO: Implement reduce in system
+ //ASSERT_EQ(cpy0, src);
+ //ASSERT_EQ(cpy1, src);
+ //ASSERT_EQ(cpy2, src);
+ #endif
+
+ // resizing
+ Vector vec1(src);
+ vec1.resize(size + 3);
+ ASSERT_EQ(vec1.size(), size + 3);
+ vec1.resize(size);
+ ASSERT_EQ(vec1.size(), size);
+ //ASSERT_EQ(vec1, src); // TODO: Implement reduce in system
+
+ vec1.resize(size + 20, T(11));
+ Vector tail(vec1.begin() + size, vec1.end());
+ ASSERT_EQ( (tail == std::vector<T>(20, T(11))), true);
+
+ // shrinking a vector should not invalidate iterators
+ Iterator first = vec1.begin();
+ vec1.resize(10);
+ ASSERT_EQ(first, vec1.begin());
+
+ vec1.resize(0);
+ ASSERT_EQ(vec1.size(), 0);
+ ASSERT_EQ(vec1.empty(), true);
+ vec1.resize(10);
+ ASSERT_EQ(vec1.size(), 10);
+ vec1.clear();
+ ASSERT_EQ(vec1.size(), 0);
+ vec1.resize(5);
+ ASSERT_EQ(vec1.size(), 5);
+
+ // push_back
+ Vector vec2;
+ for(size_t i = 0; i < 10; ++i)
+ {
+ ASSERT_EQ(vec2.size(), i);
+ vec2.push_back( (T) i );
+ ASSERT_EQ(vec2.size(), i + 1);
+ for(size_t j = 0; j <= i; j++)
+ ASSERT_EQ(vec2[j], j);
+ ASSERT_EQ(vec2.back(), i);
+ }
+
+ // pop_back
+ for(size_t i = 10; i > 0; --i)
+ {
+ ASSERT_EQ(vec2.size(), i);
+ ASSERT_EQ(vec2.back(), i-1);
+ vec2.pop_back();
+ ASSERT_EQ(vec2.size(), i-1);
+ for(size_t j = 0; j < i; j++)
+ ASSERT_EQ(vec2[j], j);
+ }
+ }
+}
+
+#endif // THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_HCC

Update vector tests and add vector manipulation tests.