From 876b4764b77384100867cefb2cb15362b3f0f8ce Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Fri, 31 Mar 2023 14:15:59 -0400 Subject: [PATCH 01/11] adding custom constructor Signed-off-by: Dan Hoeflinger --- help_function/src/onedpl_test_vector.cpp | 95 ++++++++++++++++++++---- 1 file changed, 81 insertions(+), 14 deletions(-) diff --git a/help_function/src/onedpl_test_vector.cpp b/help_function/src/onedpl_test_vector.cpp index ccb7a84e4..f323482d5 100644 --- a/help_function/src/onedpl_test_vector.cpp +++ b/help_function/src/onedpl_test_vector.cpp @@ -43,6 +43,24 @@ int test_passed(int failing_elems, std::string test_name) { return 1; } + + +template +class my_allocator_with_custom_construct : public dpct::internal::usm_device_allocator { + public: + my_allocator_with_custom_construct() {} + my_allocator_with_custom_construct(const sycl::queue &Q, const sycl::property_list &PropList = {}) + : dpct::internal::usm_device_allocator(Q, PropList) + {} + + static void construct(T *p) { ::new((void*)p) T(6); } + template + static void construct(T *p, _Arg arg) { ::new((void*)p) T(arg + 3); } + static void destroy(T *p) { p->~T(); } + +}; + + int main() { // used to detect failures @@ -90,6 +108,9 @@ int main() { v4.insert(v4.begin(), 2, *(v2.begin()) - 111); v4.insert(v4.begin(), v2.begin(), v2.begin() + 2); #endif + std::vector host_v(2, 79); + v4.insert(v4.begin()+3, host_v.begin(), host_v.end()); + #ifdef _VERBOSE std::cout << "v4.size() = " << v4.size() << std::endl; std::cout << "v4: "; @@ -123,7 +144,7 @@ int main() { //failed_tests += ASSERT_EQUAL("v6.back() = 2", v6.back(), 2); #endif v6.pop_back(); - v6.reserve(20); + v6.reserve(24); #ifdef _VERBOSE if (!v6.empty() && v6.front() == *v6.begin()) { std::cout << "v6.size() = " << v6.size() << ", v6.max_size() = " << @@ -133,19 +154,19 @@ int main() { std::cout << "v6[0] = " << v6[0] << std::endl; // expected: 5 } #else - failed_tests += ASSERT_EQUAL("v6.size() = 12", v6.size(), 12); + failed_tests += ASSERT_EQUAL("v6.size() = 14", v6.size(), 14); failed_tests += ASSERT_EQUAL("v6.max_size()", v6.max_size(), 4611686018427387903); - failed_tests += ASSERT_EQUAL("v6.capacity() = 20", v6.capacity(), 20); + failed_tests += ASSERT_EQUAL("v6.capacity() = 24", v6.capacity(), 24); v6.shrink_to_fit(); - failed_tests += ASSERT_EQUAL("v6.capacity() = 12", v6.capacity(), 12); + failed_tests += ASSERT_EQUAL("v6.capacity() = 14", v6.capacity(), 14); failed_tests += ASSERT_EQUAL("v6[0] = 0", v6[0], 0); #endif v6.resize(20, 99); auto resize_policy = oneapi::dpl::execution::make_device_policy(dpct::get_default_queue()); - auto sum = std::reduce(resize_policy, v6.begin()+12, v6.end(), 0); - failed_tests += ASSERT_EQUAL("sum = 792", sum, 792); + auto sum = std::reduce(resize_policy, v6.begin()+14, v6.end(), 0); + failed_tests += ASSERT_EQUAL("sum = 594", sum, 594); - v6.erase(v6.cbegin() + 10, v6.cend()); + v6.erase(v6.cbegin() + 14, v6.cend()); #ifdef _VERBOSE for (std::size_t i = 0; i < v6.size(); ++i) { std::cout << v6[i] << " "; // expected: 5 4 3 2 1 -111 -111 -111 1 0 @@ -157,13 +178,15 @@ int main() { num_failing += ASSERT_ARRAY_EQUAL(test_name, v6[0], 0); num_failing += ASSERT_ARRAY_EQUAL(test_name, v6[1], 1); num_failing += ASSERT_ARRAY_EQUAL(test_name, v6[2], -111); - num_failing += ASSERT_ARRAY_EQUAL(test_name, v6[3], -111); - num_failing += ASSERT_ARRAY_EQUAL(test_name, v6[4], -111); - num_failing += ASSERT_ARRAY_EQUAL(test_name, v6[5], 1); - num_failing += ASSERT_ARRAY_EQUAL(test_name, v6[6], 2); - num_failing += ASSERT_ARRAY_EQUAL(test_name, v6[7], 3); - num_failing += ASSERT_ARRAY_EQUAL(test_name, v6[8], 4); - num_failing += ASSERT_ARRAY_EQUAL(test_name, v6[9], 5); + num_failing += ASSERT_ARRAY_EQUAL(test_name, v6[3], 79); + num_failing += ASSERT_ARRAY_EQUAL(test_name, v6[4], 79); + num_failing += ASSERT_ARRAY_EQUAL(test_name, v6[5], -111); + num_failing += ASSERT_ARRAY_EQUAL(test_name, v6[6], -111); + num_failing += ASSERT_ARRAY_EQUAL(test_name, v6[7], 1); + num_failing += ASSERT_ARRAY_EQUAL(test_name, v6[8], 2); + num_failing += ASSERT_ARRAY_EQUAL(test_name, v6[9], 3); + num_failing += ASSERT_ARRAY_EQUAL(test_name, v6[10], 4); + num_failing += ASSERT_ARRAY_EQUAL(test_name, v6[11], 5); failed_tests += test_passed(num_failing, test_name); num_failing = 0; @@ -209,6 +232,50 @@ int main() { failed_tests += test_passed(num_failing, test_name); } + num_failing = 0; + test_name = "custom_allocator default construction"; + { // test with custom allocator which constructs default constructor of 6 + dpct::device_vector> default_construct(5); + default_construct[4] += 2; + num_failing += ASSERT_ARRAY_EQUAL(test_name, default_construct[0], 6); + num_failing += ASSERT_ARRAY_EQUAL(test_name, default_construct[1], 6); + num_failing += ASSERT_ARRAY_EQUAL(test_name, default_construct[2], 6); + num_failing += ASSERT_ARRAY_EQUAL(test_name, default_construct[3], 6); + num_failing += ASSERT_ARRAY_EQUAL(test_name, default_construct[4], 8); + failed_tests += test_passed(num_failing, test_name); + } + num_failing = 0; + test_name = "custom_allocator construction from input"; + { // test with custom allocator which whos default constructor adds of 3 when constructing from a value or iterator + dpct::device_vector> construct_from_value(5, 2); + construct_from_value[4] += 2; + num_failing += ASSERT_ARRAY_EQUAL(test_name, construct_from_value[0], 5); + num_failing += ASSERT_ARRAY_EQUAL(test_name, construct_from_value[1], 5); + num_failing += ASSERT_ARRAY_EQUAL(test_name, construct_from_value[2], 5); + num_failing += ASSERT_ARRAY_EQUAL(test_name, construct_from_value[3], 5); + num_failing += ASSERT_ARRAY_EQUAL(test_name, construct_from_value[4], 7); + + std::vector src(8); + src[0] = -1; src[1] = 2; src[2] = -3; src[3] = 4; src[4] = -5; src[5] = 6; src[6] = -7; src[7] = 8; + + dpct::device_vector> construct_from_iter(src.begin()+2, src.begin()+7); + construct_from_iter[4] += 2; + num_failing += ASSERT_ARRAY_EQUAL(test_name, construct_from_iter[0], 0); + num_failing += ASSERT_ARRAY_EQUAL(test_name, construct_from_iter[1], 7); + num_failing += ASSERT_ARRAY_EQUAL(test_name, construct_from_iter[2], -2); + num_failing += ASSERT_ARRAY_EQUAL(test_name, construct_from_iter[3], 9); + num_failing += ASSERT_ARRAY_EQUAL(test_name, construct_from_iter[4], -2); + failed_tests += test_passed(num_failing, test_name); + } + + num_failing = 0; + test_name = "inserting host iterators"; + { + + + } + + std::cout << std::endl << failed_tests << " failing test(s) detected." << std::endl; if (failed_tests == 0) { From 39821d813a643f147dbe27ac0cbd96951a83d09b Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Fri, 31 Mar 2023 14:28:05 -0400 Subject: [PATCH 02/11] adding comment Signed-off-by: Dan Hoeflinger --- help_function/src/onedpl_test_vector.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/help_function/src/onedpl_test_vector.cpp b/help_function/src/onedpl_test_vector.cpp index f323482d5..338cfcd8e 100644 --- a/help_function/src/onedpl_test_vector.cpp +++ b/help_function/src/onedpl_test_vector.cpp @@ -108,6 +108,7 @@ int main() { v4.insert(v4.begin(), 2, *(v2.begin()) - 111); v4.insert(v4.begin(), v2.begin(), v2.begin() + 2); #endif + //insert host side data into the vector std::vector host_v(2, 79); v4.insert(v4.begin()+3, host_v.begin(), host_v.end()); From 20c7a038bd2ca85890c5ab063349f8d2f459007a Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Fri, 31 Mar 2023 14:36:52 -0400 Subject: [PATCH 03/11] Adding constructors Signed-off-by: Dan Hoeflinger --- help_function/src/onedpl_test_vector.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/help_function/src/onedpl_test_vector.cpp b/help_function/src/onedpl_test_vector.cpp index 338cfcd8e..430dd7029 100644 --- a/help_function/src/onedpl_test_vector.cpp +++ b/help_function/src/onedpl_test_vector.cpp @@ -48,7 +48,9 @@ int test_passed(int failing_elems, std::string test_name) { template class my_allocator_with_custom_construct : public dpct::internal::usm_device_allocator { public: - my_allocator_with_custom_construct() {} + my_allocator_with_custom_construct(const sycl::context &Ctxt, const sycl::device &Dev, + const sycl::property_list &PropList = {}) + : dpct::internal::usm_device_allocator(Ctxt, Dev, PropList) {} my_allocator_with_custom_construct(const sycl::queue &Q, const sycl::property_list &PropList = {}) : dpct::internal::usm_device_allocator(Q, PropList) {} From c7fd1de0f88bc0bca239ec464241f8e9e30f454e Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Wed, 5 Apr 2023 08:26:28 -0400 Subject: [PATCH 04/11] switch to shared memory allocator Signed-off-by: Dan Hoeflinger --- help_function/src/onedpl_test_vector.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/help_function/src/onedpl_test_vector.cpp b/help_function/src/onedpl_test_vector.cpp index 430dd7029..747aeafd4 100644 --- a/help_function/src/onedpl_test_vector.cpp +++ b/help_function/src/onedpl_test_vector.cpp @@ -46,13 +46,13 @@ int test_passed(int failing_elems, std::string test_name) { template -class my_allocator_with_custom_construct : public dpct::internal::usm_device_allocator { +class my_allocator_with_custom_construct : public sycl::usm_allocator { public: my_allocator_with_custom_construct(const sycl::context &Ctxt, const sycl::device &Dev, const sycl::property_list &PropList = {}) - : dpct::internal::usm_device_allocator(Ctxt, Dev, PropList) {} + : sycl::usm_allocator(Ctxt, Dev, PropList) {} my_allocator_with_custom_construct(const sycl::queue &Q, const sycl::property_list &PropList = {}) - : dpct::internal::usm_device_allocator(Q, PropList) + : sycl::usm_allocator(Q, PropList) {} static void construct(T *p) { ::new((void*)p) T(6); } From a8ff7ce0ccb81a035c1a5c40bfc788b8ab3c506f Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Thu, 18 May 2023 17:10:08 -0400 Subject: [PATCH 05/11] Adding test coverage for device_vector Signed-off-by: Dan Hoeflinger --- help_function/help_function.xml | 1 + help_function/src/assign_device_vector.cpp | 124 +++++++++++++- help_function/src/move_device_vector.cpp | 110 ++++++++++++- help_function/src/swap_device_vector.cpp | 180 +++++++++++++++++++++ 4 files changed, 411 insertions(+), 4 deletions(-) create mode 100644 help_function/src/swap_device_vector.cpp diff --git a/help_function/help_function.xml b/help_function/help_function.xml index c88c7789c..4824be2e8 100644 --- a/help_function/help_function.xml +++ b/help_function/help_function.xml @@ -6,6 +6,7 @@ + diff --git a/help_function/src/assign_device_vector.cpp b/help_function/src/assign_device_vector.cpp index 9deb9d577..3be4e31ec 100644 --- a/help_function/src/assign_device_vector.cpp +++ b/help_function/src/assign_device_vector.cpp @@ -4,6 +4,73 @@ #include #include +template +bool verify(Vector &D, int N, int V) { + if (D.size() != N) + { + std::cout<<"size mismatch"<> D3(10, alloc_no_copy_prop2); + //since there is no copy propagation, we only destroy the excess, not all 10 elements, and we copy the N elements + D3 = D2; + if (!verify(D3, N, V)) { + std::cout<<"Failed move assign of AllocWithNoCopyProp"< alloc_copy_prop1(dpct::get_default_queue()); + AllocWithCopyPropagation alloc_copy_prop2(dpct::get_default_queue()); + + //Should allocate 5 ints from D3 in the new allocation space + dpct::device_vector> D4(std::move(D3), alloc_copy_prop1); + if (!verify(D4, N, V)) { + std::cout<<"Failed move of AllocWithNoCopyProp to AllocWithCopyProp"<> D5(10, alloc_copy_prop2); + //since there is copy propagation, we destroy all 10 elements, and use the propagated allocator to construct + // 5 new elements + D5 = D4; + if (!verify(D5, N, V)) { + std::cout<<"Failed copy assign of AllocWithCopyProp"< #include -bool verify(dpct::device_vector &D, int N, int V) { +template +bool verify(Vector &D, int N, int V) { if (D.size() != N) + { + std::cout<<"size mismatch"<> D4(std::move(D3)); + if (!verify(D4, N, V)) { + std::cout<<"Failed move of AllocWithNoMoveProp"<> D5; + D5 = std::move(D4); + if (!verify(D5, N, V)) { + std::cout<<"Failed move assign of AllocWithNoMoveProp"< alloc_move_prop(dpct::get_default_queue()); + + dpct::device_vector> D6(std::move(D5), alloc_move_prop); + if (!verify(D6, N, V)) { + std::cout<<"Failed move of AllocWithNoMoveProp to AllocWithMoveProp"<> D7; + D7 = std::move(D6); + if (!verify(D7, N, V)) { + std::cout<<"Failed move assign of AllocWithMoveProp"<> D8(std::move(D7)); + if (!verify(D8, N, V)) { + std::cout<<"Failed move of AllocWithMoveProp"< +#include +#include +#include +#include + +template +bool +verify(Vector& D, int N, int V) +{ + if (D.size() != N) + { + std::cout << "size mismatch" << std::endl; + return false; + } + for (int i = 0; i < N; ++i) + if (D[i] != V) + { + std::cout << "value mismatch " << D[i] << " != " << V << std::endl; + return false; + } + return true; +} + +static int num_constructed_prop = 0; +static int num_destroyed_prop = 0; +static int num_constructed_no_prop = 0; +static int num_destroyed_no_prop = 0; + +template +class AllocWithNoSwapPropagation : public sycl::usm_allocator +{ + public: + AllocWithNoSwapPropagation(const sycl::context& Ctxt, const sycl::device& Dev, + const sycl::property_list& PropList = {}) + : sycl::usm_allocator(Ctxt, Dev, PropList) + { + } + AllocWithNoSwapPropagation(const sycl::queue& Q, const sycl::property_list& PropList = {}) + : sycl::usm_allocator(Q, PropList) + { + } + + AllocWithNoSwapPropagation(const AllocWithNoSwapPropagation& other) + : sycl::usm_allocator(other) + { + } + + typedef ::std::false_type propagate_on_container_swap; + static void + construct(T* p) + { + ::new ((void*)p) T(); + num_constructed_no_prop++; + } + template + static void + construct(T* p, _Arg arg) + { + ::new ((void*)p) T(arg); + num_constructed_no_prop++; + } + static void + destroy(T* p) + { + p->~T(); + num_destroyed_no_prop++; + } +}; + +template +class AllocWithSwapPropagation : public sycl::usm_allocator +{ + public: + AllocWithSwapPropagation(const sycl::context& Ctxt, const sycl::device& Dev, + const sycl::property_list& PropList = {}) + : sycl::usm_allocator(Ctxt, Dev, PropList) + { + } + AllocWithSwapPropagation(const sycl::queue& Q, const sycl::property_list& PropList = {}) + : sycl::usm_allocator(Q, PropList) + { + } + + AllocWithSwapPropagation(const AllocWithSwapPropagation& other) + : sycl::usm_allocator(other) + { + } + + typedef ::std::true_type propagate_on_container_swap; + static void + construct(T* p) + { + ::new ((void*)p) T(); + num_constructed_prop++; + } + template + static void + construct(T* p, _Arg arg) + { + ::new ((void*)p) T(arg); + num_constructed_prop++; + } + static void + destroy(T* p) + { + p->~T(); + num_destroyed_prop++; + } +}; + +int +main(void) +{ + constexpr int N1 = 3; + constexpr int V1 = 99; + constexpr int N2 = 7; + constexpr int V2 = 98; + dpct::device_vector D1(N1, V1); + + AllocWithNoSwapPropagation alloc_no_swap_prop1(dpct::get_default_queue()); + AllocWithNoSwapPropagation alloc_no_swap_prop2(dpct::get_default_queue()); + + //Should allocate and construct N1 int{} + dpct::device_vector> D2(std::move(D1), alloc_no_swap_prop1); + if (!verify(D2, N1, V1)) + { + std::cout << "Failed move of default allocator to AllocWithNoSwapProp" << std::endl; + return 1; + } + + //Should allocate and construct N2 int{} + dpct::device_vector> D3(N2, V2, alloc_no_swap_prop2); + //since there is no swap propagation, we only destroy the excess + D3.swap(D2); + if (!verify(D3, N1, V1) || !verify(D2, N2, V2)) + { + std::cout << "Failed swap of AllocWithNoSwapProp" << std::endl; + return 1; + } + + if (num_constructed_no_prop != 14 && num_destroyed_no_prop != 4) + { + std::cout << "Allocator without swap propagation is swaping incorrectly: [" << num_constructed_no_prop << ", " + << num_destroyed_no_prop << "]" << std::endl; + return 1; + } + + + dpct::device_vector D4(N1, V1); + + AllocWithSwapPropagation alloc_swap_prop1(dpct::get_default_queue()); + AllocWithSwapPropagation alloc_swap_prop2(dpct::get_default_queue()); + + //Should allocate and construct N1 int{} + dpct::device_vector> D5(std::move(D4), alloc_swap_prop1); + if (!verify(D5, N1, V1)) + { + std::cout << "Failed move of default allocator to AllocWithSwapProp" << std::endl; + return 1; + } + + //Should allocate and construct N2 int{} + dpct::device_vector> D6(N2, V2, alloc_swap_prop2); + //since there is no swap propagation, we only destroy the excess + D6.swap(D5); + if (!verify(D6, N1, V1) || !verify(D5, N2, V2)) + { + std::cout << "Failed swap of AllocWithSwapProp" << std::endl; + return 1; + } + + if (num_constructed_prop != 10 && num_destroyed_prop != 0) + { + std::cout << "Allocator with swap propagation is swaping incorrectly: [" << num_constructed_prop << ", " + << num_destroyed_prop << "]" << std::endl; + return 1; + } + return 0; +} \ No newline at end of file From dbdc82847fcb6bf2da03c3f172a081a34d80f07d Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Fri, 19 May 2023 13:23:06 -0400 Subject: [PATCH 06/11] testing select_on_container_copy_construction() Signed-off-by: Dan Hoeflinger --- help_function/src/assign_device_vector.cpp | 87 ++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/help_function/src/assign_device_vector.cpp b/help_function/src/assign_device_vector.cpp index 3be4e31ec..abc5b9521 100644 --- a/help_function/src/assign_device_vector.cpp +++ b/help_function/src/assign_device_vector.cpp @@ -71,6 +71,50 @@ class AllocWithCopyPropagation : public sycl::usm_allocator~T(); num_destroyed_prop++;} }; +template +class AllocWithDefaultOnCopyConstruction : public sycl::usm_allocator { + public: + AllocWithDefaultOnCopyConstruction(const sycl::queue &Q, int _index = 0, const sycl::property_list &PropList = {}) + : sycl::usm_allocator(Q, PropList), index(_index) + {} + + AllocWithDefaultOnCopyConstruction(const AllocWithDefaultOnCopyConstruction& other) + : sycl::usm_allocator(other), index(other.index) + {} + + AllocWithDefaultOnCopyConstruction():AllocWithDefaultOnCopyConstruction(dpct::get_default_queue()){} + + AllocWithDefaultOnCopyConstruction select_on_container_copy_construction() const + { + AllocWithDefaultOnCopyConstruction tmp; + return tmp; + } + + int index; +}; + +template +class AllocWithCopyOnCopyConstruction : public sycl::usm_allocator { + public: + AllocWithCopyOnCopyConstruction(const sycl::queue &Q, int _index = 0, const sycl::property_list &PropList = {}) + : sycl::usm_allocator(Q, PropList), index(_index) + {} + + AllocWithCopyOnCopyConstruction(const AllocWithCopyOnCopyConstruction& other) + : sycl::usm_allocator(other), index(other.index) + {} + + AllocWithCopyOnCopyConstruction():AllocWithCopyOnCopyConstruction(dpct::get_default_queue()){} + + AllocWithCopyOnCopyConstruction select_on_container_copy_construction() const + { + AllocWithCopyOnCopyConstruction tmp{*this}; + return tmp; + } + + int index; +}; + int main(void) { // H has storage for 4 integers @@ -145,4 +189,47 @@ int main(void) std::cout<<"Allocator with copy propagation is copying incorrectly: ["< alloc_default_on_copy(dpct::get_default_queue(), 42); + dpct::device_vector> D6(N, V, alloc_default_on_copy); + if (D6.get_allocator().index != 42) { + std::cout<<"index not set correctly for AllocWithDefaultOnCopyConstruction "<> D7(D6); + if (!verify(D7, N, V)) { + std::cout<<"Failed copy constructor of AllocWithDefaultOnCopyConstruction"< alloc_copy_on_copy(dpct::get_default_queue(), 33); + dpct::device_vector> D8(N, V, alloc_copy_on_copy); + if (!verify(D8, N, V)) { + std::cout<<"Failed creation of AllocWithCopyOnCopyConstruction"<> D9(D8); + if (!verify(D9, N, V)) { + std::cout<<"Failed copy constructor of AllocWithCopyOnCopyConstruction"< Date: Fri, 19 May 2023 14:05:22 -0400 Subject: [PATCH 07/11] cleanup, comments Signed-off-by: Dan Hoeflinger --- help_function/src/assign_device_vector.cpp | 22 +++++++++++++++------- help_function/src/move_device_vector.cpp | 10 ++++++++-- help_function/src/swap_device_vector.cpp | 12 ++++++++---- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/help_function/src/assign_device_vector.cpp b/help_function/src/assign_device_vector.cpp index abc5b9521..5ea3e9665 100644 --- a/help_function/src/assign_device_vector.cpp +++ b/help_function/src/assign_device_vector.cpp @@ -20,7 +20,8 @@ bool verify(Vector &D, int N, int V) { return true; } - +//adding these global variables to track construction and destruction +// using custom allocators with different settings. static int num_constructed_prop = 0; static int num_destroyed_prop = 0; static int num_constructed_no_prop = 0; @@ -141,6 +142,7 @@ int main(void) constexpr int V = 99; dpct::device_vector D1(N, V); + // check appropriate effect of Allocator::propagate_on_container_copy_assignment AllocWithNoCopyPropagation alloc_no_copy_prop1(dpct::get_default_queue()); AllocWithNoCopyPropagation alloc_no_copy_prop2(dpct::get_default_queue()); @@ -155,13 +157,14 @@ int main(void) //since there is no copy propagation, we only destroy the excess, not all 10 elements, and we copy the N elements D3 = D2; if (!verify(D3, N, V)) { - std::cout<<"Failed move assign of AllocWithNoCopyProp"< alloc_default_on_copy(dpct::get_default_queue(), 42); dpct::device_vector> D6(N, V, alloc_default_on_copy); if (D6.get_allocator().index != 42) { - std::cout<<"index not set correctly for AllocWithDefaultOnCopyConstruction "< alloc_no_move_prop(dpct::get_default_queue()); dpct::device_vector> D3(std::move(D2), alloc_no_move_prop); @@ -107,7 +111,8 @@ int main(void) { if (num_constructed_no_prop != 8 && num_destroyed_no_prop != 4) { - std::cout<<"Allocator without move propagation is moving incorrectly: ["< D1(N1, V1); + // check appropriate effect of Allocator::propagate_on_container_swap + AllocWithNoSwapPropagation alloc_no_swap_prop1(dpct::get_default_queue()); AllocWithNoSwapPropagation alloc_no_swap_prop2(dpct::get_default_queue()); @@ -141,8 +145,8 @@ main(void) if (num_constructed_no_prop != 14 && num_destroyed_no_prop != 4) { - std::cout << "Allocator without swap propagation is swaping incorrectly: [" << num_constructed_no_prop << ", " - << num_destroyed_no_prop << "]" << std::endl; + std::cout << "Allocator without swap propagation is swaping incorrectly: [14, 4] != [" + << num_constructed_no_prop << ", "<< num_destroyed_no_prop << "]" << std::endl; return 1; } @@ -172,8 +176,8 @@ main(void) if (num_constructed_prop != 10 && num_destroyed_prop != 0) { - std::cout << "Allocator with swap propagation is swaping incorrectly: [" << num_constructed_prop << ", " - << num_destroyed_prop << "]" << std::endl; + std::cout << "Allocator with swap propagation is swaping incorrectly: [10, 0] != [" + << num_constructed_prop << ", "<< num_destroyed_prop << "]" << std::endl; return 1; } return 0; From 3dbf86aed90b67ec409a4e4b6ddcc60eabc06e58 Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Fri, 19 May 2023 14:05:56 -0400 Subject: [PATCH 08/11] extra coverage of constructor for device_vector Signed-off-by: Dan Hoeflinger --- help_function/src/onedpl_test_vector.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/help_function/src/onedpl_test_vector.cpp b/help_function/src/onedpl_test_vector.cpp index 747aeafd4..f06821f80 100644 --- a/help_function/src/onedpl_test_vector.cpp +++ b/help_function/src/onedpl_test_vector.cpp @@ -194,6 +194,27 @@ int main() { failed_tests += test_passed(num_failing, test_name); num_failing = 0; #endif + Vector v7(v5.begin()+3, v5.end()-2); + dpct::get_default_queue().wait(); +#ifdef _VERBOSE + std::cout << std::endl << "v7: "; + for (std::size_t i = 0; i < v7.size(); ++i) { + std::cout << v7[i] << " "; // expected: 79 79 -111 -111 -111 1 2 3 + } + std::cout << std::endl; +#else + test_name = "v7 = modified v5"; + + num_failing += ASSERT_ARRAY_EQUAL(test_name, v7[0], 79); + num_failing += ASSERT_ARRAY_EQUAL(test_name, v7[1], 79); + num_failing += ASSERT_ARRAY_EQUAL(test_name, v7[2], -111); + num_failing += ASSERT_ARRAY_EQUAL(test_name, v7[3], -111); + num_failing += ASSERT_ARRAY_EQUAL(test_name, v7[4], 1); + num_failing += ASSERT_ARRAY_EQUAL(test_name, v7[5], 2); + num_failing += ASSERT_ARRAY_EQUAL(test_name, v7[6], 3); +#endif + + { // Simple test of DPCT vector with PSTL algorithm // create buffer std::vector src(8); From a87d9d6d65ef0be75d052051f7cdf6417735856d Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Wed, 8 Nov 2023 13:17:18 -0500 Subject: [PATCH 09/11] adding section to tests for inserting host data Signed-off-by: Dan Hoeflinger --- help_function/src/onedpl_test_vector.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/help_function/src/onedpl_test_vector.cpp b/help_function/src/onedpl_test_vector.cpp index f06821f80..62cce4882 100644 --- a/help_function/src/onedpl_test_vector.cpp +++ b/help_function/src/onedpl_test_vector.cpp @@ -295,8 +295,29 @@ int main() { num_failing = 0; test_name = "inserting host iterators"; { + std::vector src(8, 99); + std::vector src2(2, 2); + std::vector src3(3, 33); - + dpct::device_vector dst = src; + dst.insert(dst.end(), src2.begin(), src2.end()); + + dst.insert(dst.begin() + 3, src3.begin(), src3.end()); + + num_failing += ASSERT_ARRAY_EQUAL(test_name, dst.size(), 13); + num_failing += ASSERT_ARRAY_EQUAL(test_name, dst[0], 99); + num_failing += ASSERT_ARRAY_EQUAL(test_name, dst[1], 99); + num_failing += ASSERT_ARRAY_EQUAL(test_name, dst[2], 99); + num_failing += ASSERT_ARRAY_EQUAL(test_name, dst[3], 33); + num_failing += ASSERT_ARRAY_EQUAL(test_name, dst[4], 33); + num_failing += ASSERT_ARRAY_EQUAL(test_name, dst[5], 33); + num_failing += ASSERT_ARRAY_EQUAL(test_name, dst[6], 99); + num_failing += ASSERT_ARRAY_EQUAL(test_name, dst[7], 99); + num_failing += ASSERT_ARRAY_EQUAL(test_name, dst[8], 99); + num_failing += ASSERT_ARRAY_EQUAL(test_name, dst[9], 99); + num_failing += ASSERT_ARRAY_EQUAL(test_name, dst[10], 99); + num_failing += ASSERT_ARRAY_EQUAL(test_name, dst[11], 2); + num_failing += ASSERT_ARRAY_EQUAL(test_name, dst[12], 2); } From b4c7ed87d2e31f71222b7d9a742630a2254ea293 Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Wed, 8 Nov 2023 13:23:51 -0500 Subject: [PATCH 10/11] restrict to USM cases Signed-off-by: Dan Hoeflinger --- help_function/help_function.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/help_function/help_function.xml b/help_function/help_function.xml index 4824be2e8..373ac4ce7 100644 --- a/help_function/help_function.xml +++ b/help_function/help_function.xml @@ -4,9 +4,9 @@ Test the helper function - - - + + + From 3bbe166497901dd1e902cd27ff639aae05c019a2 Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Wed, 8 Nov 2023 13:24:47 -0500 Subject: [PATCH 11/11] adding copyright notice Signed-off-by: Dan Hoeflinger --- help_function/src/assign_device_vector.cpp | 9 +++++++++ help_function/src/move_device_vector.cpp | 9 +++++++++ help_function/src/swap_device_vector.cpp | 9 +++++++++ 3 files changed, 27 insertions(+) diff --git a/help_function/src/assign_device_vector.cpp b/help_function/src/assign_device_vector.cpp index 5ea3e9665..8148782fa 100644 --- a/help_function/src/assign_device_vector.cpp +++ b/help_function/src/assign_device_vector.cpp @@ -1,3 +1,12 @@ +// ====------ assign_device_vector.cpp---------- -*- C++ -* ----===//// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// +// ===----------------------------------------------------------------------===// + #include #include #include diff --git a/help_function/src/move_device_vector.cpp b/help_function/src/move_device_vector.cpp index 604c820a2..83da11fb5 100644 --- a/help_function/src/move_device_vector.cpp +++ b/help_function/src/move_device_vector.cpp @@ -1,3 +1,12 @@ +// ====------ move_device_vector.cpp---------- -*- C++ -* ----===//// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// +// ===----------------------------------------------------------------------===// + #include #include #include diff --git a/help_function/src/swap_device_vector.cpp b/help_function/src/swap_device_vector.cpp index b20701c5a..f0ebaff7a 100644 --- a/help_function/src/swap_device_vector.cpp +++ b/help_function/src/swap_device_vector.cpp @@ -1,3 +1,12 @@ +// ====------ swap_device_vector.cpp---------- -*- C++ -* ----===//// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// +// ===----------------------------------------------------------------------===// + #include #include #include