diff --git a/projects/rocprim/test/rocprim/test_device_merge.cpp b/projects/rocprim/test/rocprim/test_device_merge.cpp index a51560bd802..fc07d9ca5bd 100644 --- a/projects/rocprim/test/rocprim/test_device_merge.cpp +++ b/projects/rocprim/test/rocprim/test_device_merge.cpp @@ -193,9 +193,21 @@ TYPED_TEST(RocprimDeviceMergeTests, MergeKey) test_utils::out_of_bounds_flag out_of_bounds; - common::device_ptr d_keys_input1(keys_input1); - common::device_ptr d_keys_input2(keys_input2); - common::device_ptr d_keys_output(keys_output.size()); + common::device_ptr d_keys_input1; + common::device_ptr d_keys_input2; + common::device_ptr d_keys_output; + + if(!d_keys_input1.resize_with_memory_check(keys_input1.size()) + || !d_keys_input2.resize_with_memory_check(keys_input2.size()) + || !d_keys_output.resize_with_memory_check(keys_output.size())) + { + std::cout << "Out of memory. Skipping test with sizes = {" << size1 << ", " << size2 + << "}" << std::endl; + break; + } + + d_keys_input1.store(keys_input1); + d_keys_input2.store(keys_input2); test_utils::bounds_checking_iterator d_keys_checking_output( d_keys_output.get(), @@ -219,7 +231,14 @@ TYPED_TEST(RocprimDeviceMergeTests, MergeKey) ASSERT_GT(temp_storage_size_bytes, 0); // allocate temporary storage - common::device_ptr d_temp_storage(temp_storage_size_bytes); + common::device_ptr d_temp_storage; + + if(!d_temp_storage.resize_with_memory_check(temp_storage_size_bytes)) + { + std::cout << "Out of memory. Skipping test with sizes = {" << size1 << ", " << size2 + << "}" << std::endl; + break; + } test_utils::GraphHelper gHelper; if(TestFixture::use_graphs) @@ -354,12 +373,29 @@ TYPED_TEST(RocprimDeviceMergeTests, MergeKeyValue) test_utils::out_of_bounds_flag out_of_bounds; - common::device_ptr d_keys_input1(keys_input1); - common::device_ptr d_keys_input2(keys_input2); - common::device_ptr d_keys_output(keys_output.size()); - common::device_ptr d_values_input1(values_input1); - common::device_ptr d_values_input2(values_input2); - common::device_ptr d_values_output(values_output.size()); + common::device_ptr d_keys_input1; + common::device_ptr d_keys_input2; + common::device_ptr d_keys_output; + common::device_ptr d_values_input1; + common::device_ptr d_values_input2; + common::device_ptr d_values_output; + + if(!d_keys_input1.resize_with_memory_check(keys_input1.size()) + || !d_keys_input2.resize_with_memory_check(keys_input2.size()) + || !d_keys_output.resize_with_memory_check(keys_output.size()) + || !d_values_input1.resize_with_memory_check(values_input1.size()) + || !d_values_input2.resize_with_memory_check(values_input1.size()) + || !d_values_output.resize_with_memory_check(values_output.size())) + { + std::cout << "Out of memory. Skipping test with sizes = {" << size1 << ", " << size2 + << "}" << std::endl; + break; + } + + d_keys_input1.store(keys_input1); + d_keys_input2.store(keys_input2); + d_values_input1.store(values_input1); + d_values_input2.store(values_input2); test_utils::bounds_checking_iterator d_keys_checking_output( d_keys_output.get(), @@ -390,7 +426,14 @@ TYPED_TEST(RocprimDeviceMergeTests, MergeKeyValue) ASSERT_GT(temp_storage_size_bytes, 0); // allocate temporary storage - common::device_ptr d_temp_storage(temp_storage_size_bytes); + common::device_ptr d_temp_storage; + + if(!d_temp_storage.resize_with_memory_check(temp_storage_size_bytes)) + { + std::cout << "Out of memory. Skipping test with sizes = {" << size1 << ", " << size2 + << "}" << std::endl; + break; + } test_utils::GraphHelper gHelper; if(TestFixture::use_graphs) diff --git a/projects/rocprim/test/rocprim/test_device_merge_sort.cpp b/projects/rocprim/test/rocprim/test_device_merge_sort.cpp index d5996ecaf38..bf5792b954c 100644 --- a/projects/rocprim/test/rocprim/test_device_merge_sort.cpp +++ b/projects/rocprim/test/rocprim/test_device_merge_sort.cpp @@ -148,9 +148,17 @@ TYPED_TEST(RocprimDeviceSortTests, SortKey) 100, seed_value); // float16 can't exceed 65504 - common::device_ptr d_input(input); + common::device_ptr d_input; common::device_ptr d_output_alloc; - d_output_alloc.resize(in_place ? 0 : size); + + if(!d_input.resize_with_memory_check(size) + || !d_output_alloc.resize_with_memory_check(in_place ? 0 : size)) + { + std::cout << "Out of memory. Skipping test for size = " << size << std::endl; + break; + } + + d_input.store(input); common::device_ptr& d_output = in_place ? d_input : d_output_alloc; // compare function @@ -175,7 +183,13 @@ TYPED_TEST(RocprimDeviceSortTests, SortKey) ASSERT_GT(temp_storage_size_bytes, 0); // allocate temporary storage - common::device_ptr d_temp_storage(temp_storage_size_bytes); + common::device_ptr d_temp_storage; + + if(!d_temp_storage.resize_with_memory_check(temp_storage_size_bytes)) + { + std::cout << "Out of memory. Skipping test for size = " << size << std::endl; + break; + } test_utils::GraphHelper gHelper; if(TestFixture::use_graphs) @@ -258,15 +272,25 @@ TYPED_TEST(RocprimDeviceSortTests, SortKeyValue) std::vector values_input(size); test_utils::iota(values_input.begin(), values_input.end(), 0); - common::device_ptr d_keys_input(keys_input); - common::device_ptr d_keys_output_alloc; - d_keys_output_alloc.resize(in_place ? 0 : size); + common::device_ptr d_keys_input; + common::device_ptr d_keys_output_alloc; + common::device_ptr d_values_input; + common::device_ptr d_values_output_alloc; + + if(!d_keys_input.resize_with_memory_check(size) + || !d_keys_output_alloc.resize_with_memory_check(in_place ? 0 : size) + || !d_values_input.resize_with_memory_check(size) + || !d_values_output_alloc.resize_with_memory_check(in_place ? 0 : size)) + { + std::cout << "Out of memory. Skipping test for size = " << size << std::endl; + break; + } + + d_keys_input.store(keys_input); + d_values_input.store(values_input); + common::device_ptr& d_keys_output = in_place ? d_keys_input : d_keys_output_alloc; - - common::device_ptr d_values_input(values_input); - common::device_ptr d_values_output_alloc; - d_values_output_alloc.resize(in_place ? 0 : size); common::device_ptr& d_values_output = in_place ? d_values_input : d_values_output_alloc; @@ -302,7 +326,13 @@ TYPED_TEST(RocprimDeviceSortTests, SortKeyValue) ASSERT_GT(temp_storage_size_bytes, 0); // allocate temporary storage - common::device_ptr d_temp_storage(temp_storage_size_bytes); + common::device_ptr d_temp_storage; + + if(!d_temp_storage.resize_with_memory_check(temp_storage_size_bytes)) + { + std::cout << "Out of memory. Skipping test for size = " << size << std::endl; + break; + } test_utils::GraphHelper gHelper; if(TestFixture::use_graphs) diff --git a/projects/rocprim/test/rocprim/test_device_partition.cpp b/projects/rocprim/test/rocprim/test_device_partition.cpp index 554f80c46f3..fff00f960fa 100644 --- a/projects/rocprim/test/rocprim/test_device_partition.cpp +++ b/projects/rocprim/test/rocprim/test_device_partition.cpp @@ -142,10 +142,21 @@ TYPED_TEST(RocprimDevicePartitionTests, Flagged) std::vector input = test_utils::get_random_data_wrapped(size, 1, 100, seed_value); std::vector flags = test_utils::get_random_data01(size, 0.25, seed_value); - common::device_ptr d_input(input); - common::device_ptr d_flags(flags); - common::device_ptr d_output(input.size()); - common::device_ptr d_selected_count_output(1); + common::device_ptr d_input; + common::device_ptr d_flags; + common::device_ptr d_output; + common::device_ptr d_selected_count_output; + + if(!d_input.resize_with_memory_check(size) || !d_flags.resize_with_memory_check(size) + || !d_output.resize_with_memory_check(size) + || !d_selected_count_output.resize_with_memory_check(1)) + { + std::cout << "Out of memory. Skipping test for size = " << size << std::endl; + break; + } + + d_input.store(input); + d_flags.store(flags); // Calculate expected_selected and expected_rejected results on host std::vector expected_selected; @@ -184,7 +195,13 @@ TYPED_TEST(RocprimDevicePartitionTests, Flagged) ASSERT_GT(temp_storage_size_bytes, 0); // allocate temporary storage - common::device_ptr d_temp_storage(temp_storage_size_bytes); + common::device_ptr d_temp_storage; + + if(!d_temp_storage.resize_with_memory_check(temp_storage_size_bytes)) + { + std::cout << "Out of memory. Skipping test for size = " << size << std::endl; + break; + } test_utils::GraphHelper gHelper; if(TestFixture::use_graphs) @@ -366,9 +383,18 @@ TYPED_TEST(RocprimDevicePartitionTests, Predicate) // Generate data std::vector input = test_utils::get_random_data_wrapped(size, 1, 100, seed_value); - common::device_ptr d_input(input); - common::device_ptr d_output(input.size()); - common::device_ptr d_selected_count_output(1); + common::device_ptr d_input; + common::device_ptr d_output; + common::device_ptr d_selected_count_output; + + if(!d_input.resize_with_memory_check(size) || !d_output.resize_with_memory_check(size) + || !d_selected_count_output.resize_with_memory_check(1)) + { + std::cout << "Out of memory. Skipping test for size = " << size << std::endl; + break; + } + + d_input.store(input); // Calculate expected_selected and expected_rejected results on host std::vector expected_selected; @@ -406,7 +432,13 @@ TYPED_TEST(RocprimDevicePartitionTests, Predicate) ASSERT_GT(temp_storage_size_bytes, 0); // allocate temporary storage - common::device_ptr d_temp_storage(temp_storage_size_bytes); + common::device_ptr d_temp_storage; + + if(!d_temp_storage.resize_with_memory_check(temp_storage_size_bytes)) + { + std::cout << "Out of memory. Skipping test for size = " << size << std::endl; + break; + } test_utils::GraphHelper gHelper; if(TestFixture::use_graphs) @@ -496,10 +528,20 @@ TYPED_TEST(RocprimDevicePartitionTests, PredicateTwoWay) // Generate data std::vector input = test_utils::get_random_data_wrapped(size, 1, 100, seed_value); - common::device_ptr d_input(input); - common::device_ptr d_selected(input.size()); - common::device_ptr d_rejected(input.size()); - common::device_ptr d_selected_count_output(1); + common::device_ptr d_input; + common::device_ptr d_selected; + common::device_ptr d_rejected; + common::device_ptr d_selected_count_output; + + if(!d_input.resize_with_memory_check(size) || !d_selected.resize_with_memory_check(size) + || !d_rejected.resize_with_memory_check(size) + || !d_selected_count_output.resize_with_memory_check(1)) + { + std::cout << "Out of memory. Skipping test for size = " << size << std::endl; + break; + } + + d_input.store(input); // Calculate expected_selected and expected_rejected results on host std::vector expected_selected; @@ -537,7 +579,13 @@ TYPED_TEST(RocprimDevicePartitionTests, PredicateTwoWay) ASSERT_GT(temp_storage_size_bytes, 0); // allocate temporary storage - common::device_ptr d_temp_storage(temp_storage_size_bytes); + common::device_ptr d_temp_storage; + + if(!d_temp_storage.resize_with_memory_check(temp_storage_size_bytes)) + { + std::cout << "Out of memory. Skipping test for size = " << size << std::endl; + break; + } test_utils::GraphHelper gHelper; if(TestFixture::use_graphs) @@ -645,11 +693,23 @@ TYPED_TEST(RocprimDevicePartitionTests, PredicateThreeWay) // Generate data const auto input = test_utils::get_random_data_wrapped(size, 1, 100, seed_value); - common::device_ptr d_input(input); - common::device_ptr d_first_output(input.size()); - common::device_ptr d_second_output(input.size()); - common::device_ptr d_unselected_output(input.size()); - common::device_ptr d_selected_counts(2); + common::device_ptr d_input; + common::device_ptr d_first_output; + common::device_ptr d_second_output; + common::device_ptr d_unselected_output; + common::device_ptr d_selected_counts; + + if(!d_input.resize_with_memory_check(size) + || !d_first_output.resize_with_memory_check(size) + || !d_second_output.resize_with_memory_check(size) + || !d_unselected_output.resize_with_memory_check(size) + || !d_selected_counts.resize_with_memory_check(2)) + { + std::cout << "Out of memory. Skipping test for size = " << size << std::endl; + break; + } + + d_input.store(input); const auto first_op = LessOp{std::get<0>(limits)}; const auto second_op = LessOp{std::get<1>(limits)}; @@ -696,7 +756,13 @@ TYPED_TEST(RocprimDevicePartitionTests, PredicateThreeWay) ASSERT_GT(temp_storage_size_bytes, 0); // allocate temporary storage - common::device_ptr d_temp_storage(temp_storage_size_bytes); + common::device_ptr d_temp_storage; + + if(!d_temp_storage.resize_with_memory_check(temp_storage_size_bytes)) + { + std::cout << "Out of memory. Skipping test for size = " << size << std::endl; + break; + } test_utils::GraphHelper gHelper; if(TestFixture::use_graphs) diff --git a/projects/rocprim/test/rocprim/test_device_select.cpp b/projects/rocprim/test/rocprim/test_device_select.cpp index e3fef19ca20..a8737bd8058 100644 --- a/projects/rocprim/test/rocprim/test_device_select.cpp +++ b/projects/rocprim/test/rocprim/test_device_select.cpp @@ -125,10 +125,21 @@ TYPED_TEST(RocprimDeviceSelectTests, Flagged) std::vector input = test_utils::get_random_data_wrapped(size, 1, 100, seed_value); std::vector flags = test_utils::get_random_data_wrapped(size, 0, 1, seed_value); - common::device_ptr d_input(input); - common::device_ptr d_flags(flags); - common::device_ptr d_output(input.size()); - common::device_ptr d_selected_count_output(1); + common::device_ptr d_input; + common::device_ptr d_flags; + common::device_ptr d_output; + common::device_ptr d_selected_count_output; + + if(!d_input.resize_with_memory_check(size) || !d_flags.resize_with_memory_check(size) + || !d_output.resize_with_memory_check(size) + || !d_selected_count_output.resize_with_memory_check(1)) + { + std::cout << "Out of memory. Skipping test for size = " << size << std::endl; + break; + } + + d_input.store(input); + d_flags.store(flags); // Calculate expected results on host std::vector expected; @@ -161,7 +172,13 @@ TYPED_TEST(RocprimDeviceSelectTests, Flagged) ASSERT_GT(temp_storage_size_bytes, 0); // allocate temporary storage - common::device_ptr d_temp_storage(temp_storage_size_bytes); + common::device_ptr d_temp_storage; + + if(!d_temp_storage.resize_with_memory_check(temp_storage_size_bytes)) + { + std::cout << "Out of memory. Skipping test for size = " << size << std::endl; + break; + } test_utils::GraphHelper gHelper; if(TestFixture::use_graphs) @@ -251,9 +268,18 @@ TYPED_TEST(RocprimDeviceSelectTests, SelectOp) // Generate data std::vector input = test_utils::get_random_data_wrapped(size, 0, 100, seed_value); - common::device_ptr d_input(input); - common::device_ptr d_output(input.size()); - common::device_ptr d_selected_count_output(1); + common::device_ptr d_input; + common::device_ptr d_output; + common::device_ptr d_selected_count_output; + + if(!d_input.resize_with_memory_check(size) || !d_output.resize_with_memory_check(size) + || !d_selected_count_output.resize_with_memory_check(1)) + { + std::cout << "Out of memory. Skipping test for size = " << size << std::endl; + break; + } + + d_input.store(input); // Calculate expected results on host std::vector expected; @@ -286,7 +312,13 @@ TYPED_TEST(RocprimDeviceSelectTests, SelectOp) ASSERT_GT(temp_storage_size_bytes, 0); // allocate temporary storage - common::device_ptr d_temp_storage(temp_storage_size_bytes); + common::device_ptr d_temp_storage; + + if(!d_temp_storage.resize_with_memory_check(temp_storage_size_bytes)) + { + std::cout << "Out of memory. Skipping test for size = " << size << std::endl; + break; + } test_utils::GraphHelper gHelper; if(TestFixture::use_graphs) @@ -366,10 +398,21 @@ TYPED_TEST(RocprimDeviceSelectTests, SelectFlagged) std::vector input = test_utils::get_random_data_wrapped(size, 1, 100, seed_value); std::vector flags = test_utils::get_random_data_wrapped(size, 0, 1, seed_value); - common::device_ptr d_input(input); - common::device_ptr d_flags(flags); - common::device_ptr d_output(input.size()); - common::device_ptr d_selected_count_output(1); + common::device_ptr d_input; + common::device_ptr d_flags; + common::device_ptr d_output; + common::device_ptr d_selected_count_output; + + if(!d_input.resize_with_memory_check(size) || !d_flags.resize_with_memory_check(size) + || !d_output.resize_with_memory_check(size) + || !d_selected_count_output.resize_with_memory_check(1)) + { + std::cout << "Out of memory. Skipping test for size = " << size << std::endl; + break; + } + + d_input.store(input); + d_flags.store(flags); // Calculate expected results on host std::vector expected; @@ -403,7 +446,13 @@ TYPED_TEST(RocprimDeviceSelectTests, SelectFlagged) ASSERT_GT(temp_storage_size_bytes, 0); // allocate temporary storage - common::device_ptr d_temp_storage(temp_storage_size_bytes); + common::device_ptr d_temp_storage; + + if(!d_temp_storage.resize_with_memory_check(temp_storage_size_bytes)) + { + std::cout << "Out of memory. Skipping test for size = " << size << std::endl; + break; + } test_utils::GraphHelper gHelper; if(TestFixture::use_graphs) @@ -502,9 +551,19 @@ TYPED_TEST(RocprimDeviceSelectTests, Unique) } // Allocate and copy to device - common::device_ptr d_input(input); - common::device_ptr d_output(input.size()); - common::device_ptr d_selected_count_output(1); + common::device_ptr d_input; + common::device_ptr d_output; + common::device_ptr d_selected_count_output; + + if(!d_input.resize_with_memory_check(size) + || !d_output.resize_with_memory_check(size) + || !d_selected_count_output.resize_with_memory_check(1)) + { + std::cout << "Out of memory. Skipping test for size = " << size << std::endl; + break; + } + + d_input.store(input); // Calculate expected results on host std::vector expected; @@ -541,7 +600,13 @@ TYPED_TEST(RocprimDeviceSelectTests, Unique) ASSERT_GT(temp_storage_size_bytes, 0); // allocate temporary storage - common::device_ptr d_temp_storage(temp_storage_size_bytes); + common::device_ptr d_temp_storage; + + if(!d_temp_storage.resize_with_memory_check(temp_storage_size_bytes)) + { + std::cout << "Out of memory. Skipping test for size = " << size << std::endl; + break; + } test_utils::GraphHelper gHelper; if(TestFixture::use_graphs) @@ -864,11 +929,24 @@ TYPED_TEST(RocprimDeviceUniqueByKeyTests, UniqueByKey) seed_value); // Allocate and copy to device - common::device_ptr d_keys_input(input_keys); - common::device_ptr d_values_input(input_values); - common::device_ptr d_keys_output(input_keys.size()); - common::device_ptr d_values_output(input_values.size()); - common::device_ptr d_selected_count_output(1); + common::device_ptr d_keys_input; + common::device_ptr d_values_input; + common::device_ptr d_keys_output; + common::device_ptr d_values_output; + common::device_ptr d_selected_count_output; + + if(!d_keys_input.resize_with_memory_check(size) + || !d_values_input.resize_with_memory_check(size) + || !d_keys_output.resize_with_memory_check(size) + || !d_values_output.resize_with_memory_check(size) + || !d_selected_count_output.resize_with_memory_check(1)) + { + std::cout << "Out of memory. Skipping test for size = " << size << std::endl; + break; + } + + d_keys_input.store(input_keys); + d_values_input.store(input_values); // Calculate expected results on host std::vector expected_keys; @@ -913,7 +991,13 @@ TYPED_TEST(RocprimDeviceUniqueByKeyTests, UniqueByKey) ASSERT_GT(temp_storage_size_bytes, 0); // allocate temporary storage - common::device_ptr d_temp_storage(temp_storage_size_bytes); + common::device_ptr d_temp_storage; + + if(!d_temp_storage.resize_with_memory_check(temp_storage_size_bytes)) + { + std::cout << "Out of memory. Skipping test for size = " << size << std::endl; + break; + } test_utils::GraphHelper gHelper; if(TestFixture::use_graphs) @@ -1027,9 +1111,20 @@ TYPED_TEST(RocprimDeviceUniqueByKeyTests, UniqueByKeyAlias) seed_value); // Allocate and copy to device - common::device_ptr d_keys_input(input_keys); - common::device_ptr d_values_input(input_values); - common::device_ptr d_selected_count_output(1); + common::device_ptr d_keys_input; + common::device_ptr d_values_input; + common::device_ptr d_selected_count_output; + + if(!d_keys_input.resize_with_memory_check(size) + || !d_values_input.resize_with_memory_check(size) + || !d_selected_count_output.resize_with_memory_check(1)) + { + std::cout << "Out of memory. Skipping test for size = " << size << std::endl; + break; + } + + d_keys_input.store(input_keys); + d_values_input.store(input_values); // Calculate expected results on host std::vector expected_keys; @@ -1074,7 +1169,13 @@ TYPED_TEST(RocprimDeviceUniqueByKeyTests, UniqueByKeyAlias) ASSERT_GT(temp_storage_size_bytes, 0); // allocate temporary storage - common::device_ptr d_temp_storage(temp_storage_size_bytes); + common::device_ptr d_temp_storage; + + if(!d_temp_storage.resize_with_memory_check(temp_storage_size_bytes)) + { + std::cout << "Out of memory. Skipping test for size = " << size << std::endl; + break; + } test_utils::GraphHelper gHelper; if(TestFixture::use_graphs)