Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,30 @@ ctest
./test/<unit-test-name>
```

## Using custom seeds for the tests

Go to the `rocPRIM/test/rocprim/test_seed.hpp` file.
```cpp
//(1)
static constexpr int random_seeds_count = 10;

//(2)
static constexpr unsigned int seeds [] = {0, 2, 10, 1000};

//(3)
static constexpr size_t seed_size = sizeof(seeds) / sizeof(seeds[0]);
```

(1) defines a constant that sets how many passes over the tests will be done with runtime-generated seeds. Modify at will.

(2) defines the user generated seeds. Each of the elements of the array will be used as seed for all tests. Modify at will. If no static seeds are desired, the array should be left empty.

```cpp
static constexpr unsigned int seeds [] = {};
```

(3) this line should never be modified.

## Documentation

Documentation is available [here](https://rocthrust.readthedocs.io/en/latest/).
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ endfunction()
# Tests
# ****************************************************************************


add_rocthrust_test("thrust.hip.adjacent_difference" test_adjacent_difference.cpp)
add_rocthrust_test("thrust.hip.advance" test_advance.cpp)
add_rocthrust_test("thrust.hip.allocator" test_allocator.cpp)
Expand Down
182 changes: 104 additions & 78 deletions test/test_adjacent_difference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,42 +70,52 @@ TYPED_TEST(AdjacentDifferenceVariableTests, TestAdjacentDifference)
const std::vector<size_t> sizes = get_sizes();
for(auto size : sizes)
{
thrust::host_vector<T> h_input = get_random_data<T>(
size, std::numeric_limits<T>::min(), std::numeric_limits<T>::max());
thrust::device_vector<T> d_input = h_input;

thrust::host_vector<T> h_output(size);
thrust::device_vector<T> d_output(size);

typename thrust::host_vector<T>::iterator h_result;
typename thrust::device_vector<T>::iterator d_result;

h_result = thrust::adjacent_difference(h_input.begin(), h_input.end(), h_output.begin());
d_result = thrust::adjacent_difference(d_input.begin(), d_input.end(), d_output.begin());

ASSERT_EQ(h_result - h_output.begin(), size);
ASSERT_EQ(d_result - d_output.begin(), size);
ASSERT_EQ_QUIET(h_output, d_output);

h_result = thrust::adjacent_difference(
h_input.begin(), h_input.end(), h_output.begin(), thrust::plus<T>());
d_result = thrust::adjacent_difference(
d_input.begin(), d_input.end(), d_output.begin(), thrust::plus<T>());

ASSERT_EQ(h_result - h_output.begin(), size);
ASSERT_EQ(d_result - d_output.begin(), size);
ASSERT_EQ_QUIET(h_output, d_output);

// in-place operation
h_result = thrust::adjacent_difference(
h_input.begin(), h_input.end(), h_input.begin(), thrust::plus<T>());
d_result = thrust::adjacent_difference(
d_input.begin(), d_input.end(), d_input.begin(), thrust::plus<T>());

ASSERT_EQ(h_result - h_input.begin(), size);
ASSERT_EQ(d_result - d_input.begin(), size);
ASSERT_EQ_QUIET(h_input, h_output); //computed previously
ASSERT_EQ_QUIET(d_input, d_output); //computed previously
SCOPED_TRACE(testing::Message() << "with size= " << size);
for(size_t seed_index = 0; seed_index < random_seeds_count + seed_size; seed_index++)
{
unsigned int seed_value
= seed_index < random_seeds_count ? rand() : seeds[seed_index - random_seeds_count];
SCOPED_TRACE(testing::Message() << "with seed= " << seed_value);

thrust::host_vector<T> h_input = get_random_data<T>(
size, std::numeric_limits<T>::min(), std::numeric_limits<T>::max(), seed_value);
thrust::device_vector<T> d_input = h_input;

thrust::host_vector<T> h_output(size);
thrust::device_vector<T> d_output(size);

typename thrust::host_vector<T>::iterator h_result;
typename thrust::device_vector<T>::iterator d_result;

h_result
= thrust::adjacent_difference(h_input.begin(), h_input.end(), h_output.begin());
d_result
= thrust::adjacent_difference(d_input.begin(), d_input.end(), d_output.begin());

ASSERT_EQ(h_result - h_output.begin(), size);
ASSERT_EQ(d_result - d_output.begin(), size);
ASSERT_EQ_QUIET(h_output, d_output);

h_result = thrust::adjacent_difference(
h_input.begin(), h_input.end(), h_output.begin(), thrust::plus<T>());
d_result = thrust::adjacent_difference(
d_input.begin(), d_input.end(), d_output.begin(), thrust::plus<T>());

ASSERT_EQ(h_result - h_output.begin(), size);
ASSERT_EQ(d_result - d_output.begin(), size);
ASSERT_EQ_QUIET(h_output, d_output);

// in-place operation
h_result = thrust::adjacent_difference(
h_input.begin(), h_input.end(), h_input.begin(), thrust::plus<T>());
d_result = thrust::adjacent_difference(
d_input.begin(), d_input.end(), d_input.begin(), thrust::plus<T>());

ASSERT_EQ(h_result - h_input.begin(), size);
ASSERT_EQ(d_result - d_input.begin(), size);
ASSERT_EQ_QUIET(h_input, h_output); //computed previously
ASSERT_EQ_QUIET(d_input, d_output); //computed previously
}
}
}

Expand All @@ -116,31 +126,39 @@ TYPED_TEST(AdjacentDifferenceVariableTests, TestAdjacentDifferenceInPlaceWithRel
const std::vector<size_t> sizes = get_sizes();
for(auto size : sizes)
{
thrust::host_vector<T> h_input = get_random_data<T>(
size, std::numeric_limits<T>::min(), std::numeric_limits<T>::max());
thrust::device_vector<T> d_input = h_input;

thrust::host_vector<T> h_output(size);
thrust::device_vector<T> d_output(size);

typename thrust::host_vector<T>::iterator h_result;
typename thrust::device_vector<T>::iterator d_result;

h_result = thrust::adjacent_difference(
h_input.begin(), h_input.end(), h_output.begin(), thrust::plus<T>());
d_result = thrust::adjacent_difference(
d_input.begin(), d_input.end(), d_output.begin(), thrust::plus<T>());

// in-place operation with different iterator types
h_result = thrust::adjacent_difference(
h_input.cbegin(), h_input.cend(), h_input.begin(), thrust::plus<T>());
d_result = thrust::adjacent_difference(
d_input.cbegin(), d_input.cend(), d_input.begin(), thrust::plus<T>());

ASSERT_EQ(h_result - h_input.begin(), size);
ASSERT_EQ(d_result - d_input.begin(), size);
ASSERT_EQ_QUIET(h_output, h_input); // reference computed previously
ASSERT_EQ_QUIET(d_output, d_input); // reference computed previously
SCOPED_TRACE(testing::Message() << "with size= " << size);
for(size_t seed_index = 0; seed_index < random_seeds_count + seed_size; seed_index++)
{
unsigned int seed_value
= seed_index < random_seeds_count ? rand() : seeds[seed_index - random_seeds_count];
SCOPED_TRACE(testing::Message() << "with seed= " << seed_value);

thrust::host_vector<T> h_input = get_random_data<T>(
size, std::numeric_limits<T>::min(), std::numeric_limits<T>::max(), seed_value);
thrust::device_vector<T> d_input = h_input;

thrust::host_vector<T> h_output(size);
thrust::device_vector<T> d_output(size);

typename thrust::host_vector<T>::iterator h_result;
typename thrust::device_vector<T>::iterator d_result;

h_result = thrust::adjacent_difference(
h_input.begin(), h_input.end(), h_output.begin(), thrust::plus<T>());
d_result = thrust::adjacent_difference(
d_input.begin(), d_input.end(), d_output.begin(), thrust::plus<T>());

// in-place operation with different iterator types
h_result = thrust::adjacent_difference(
h_input.cbegin(), h_input.cend(), h_input.begin(), thrust::plus<T>());
d_result = thrust::adjacent_difference(
d_input.cbegin(), d_input.cend(), d_input.begin(), thrust::plus<T>());

ASSERT_EQ(h_result - h_input.begin(), size);
ASSERT_EQ(d_result - d_input.begin(), size);
ASSERT_EQ_QUIET(h_output, h_input); // reference computed previously
ASSERT_EQ_QUIET(d_output, d_input); // reference computed previously
}
}
}

Expand All @@ -151,28 +169,36 @@ TYPED_TEST(AdjacentDifferenceVariableTests, TestAdjacentDifferenceDiscardIterato
const std::vector<size_t> sizes = get_sizes();
for(auto size : sizes)
{
thrust::host_vector<T> h_input = get_random_data<T>(
size, std::numeric_limits<T>::min(), std::numeric_limits<T>::max());
thrust::device_vector<T> d_input = h_input;

thrust::discard_iterator<> h_result;
thrust::discard_iterator<> d_result;

h_result = thrust::adjacent_difference(
h_input.begin(), h_input.end(), thrust::make_discard_iterator());
d_result = thrust::adjacent_difference(
d_input.begin(), d_input.end(), thrust::make_discard_iterator());

thrust::discard_iterator<> reference(size);

ASSERT_EQ_QUIET(reference, h_result);
ASSERT_EQ_QUIET(reference, d_result);
SCOPED_TRACE(testing::Message() << "with size= " << size);
for(size_t seed_index = 0; seed_index < random_seeds_count + seed_size; seed_index++)
{
unsigned int seed_value
= seed_index < random_seeds_count ? rand() : seeds[seed_index - random_seeds_count];
SCOPED_TRACE(testing::Message() << "with seed= " << seed_value);

thrust::host_vector<T> h_input = get_random_data<T>(
size, std::numeric_limits<T>::min(), std::numeric_limits<T>::max(), seed_value);
thrust::device_vector<T> d_input = h_input;

thrust::discard_iterator<> h_result;
thrust::discard_iterator<> d_result;

h_result = thrust::adjacent_difference(
h_input.begin(), h_input.end(), thrust::make_discard_iterator());
d_result = thrust::adjacent_difference(
d_input.begin(), d_input.end(), thrust::make_discard_iterator());

thrust::discard_iterator<> reference(size);

ASSERT_EQ_QUIET(reference, h_result);
ASSERT_EQ_QUIET(reference, d_result);
}
}
}

template <typename InputIterator, typename OutputIterator>
OutputIterator
adjacent_difference(my_system& system, InputIterator, InputIterator, OutputIterator result)
adjacent_difference(my_system& system, InputIterator, InputIterator, OutputIterator result)
{
system.validate_dispatch();
return result;
Expand Down
Loading