Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion cub/cub/agent/agent_adjacent_difference.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ struct AgentDifference
OffsetT num_items)
: temp_storage(temp_storage.Alias())
, input_it(input_it)
, load_it(LoadIt(input_it))
, load_it(try_make_cache_modified_iterator<Policy::LOAD_MODIFIER>(input_it))
, first_tile_previous(first_tile_previous)
, result(result)
, difference_op(difference_op)
Expand Down
35 changes: 35 additions & 0 deletions cub/test/catch2_test_device_adjacent_difference_api.cu

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important: Please move the new test into the file catch2_test_device_adjacent_difference_substract_left.cu. The _api.cu files cover tested API examples for the documentation.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the regression test to
catch2_test_device_adjacent_difference_substract_left.cu
and restored catch2_test_device_adjacent_difference_api.cu to its previous scope.

The relocated focused test, target build, and targeted pre-commit checks pass locally.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

#include <cub/device/device_adjacent_difference.cuh>

#include <cuda/buffer>
#include <cuda/devices>
#include <cuda/std/functional>

#include <cstdint>

#include <c2h/catch2_test_helper.h>

// Guard: the legacy memory-size query call with all defaults (no explicit difference_op,
Expand Down Expand Up @@ -51,4 +57,33 @@ C2H_TEST("DeviceAdjacentDifference::SubtractRight legacy size-query is unambiguo
REQUIRE(cudaSuccess == cub::DeviceAdjacentDifference::SubtractRight(nullptr, bytes, d_in, n));
}

C2H_TEST("DeviceAdjacentDifference::SubtractLeftCopy accepts cuda::device_buffer input",
"[adjacent_difference][device]")
{
using type = std::int32_t;

cuda::stream stream{cuda::devices[0]};
auto input = cuda::make_device_buffer<type>(stream, cuda::devices[0], {2, 5, 9, 14, 20});
c2h::device_vector<type> output(input.size());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
c2h::device_vector<type> output(input.size());
c2h::device_vector<type> output(input.size(), thrust::no_init);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied thrust::no_init to the output allocation in the relocated test.

auto output_it = thrust::raw_pointer_cast(output.data());

void* temporary_storage = nullptr;
std::size_t temporary_bytes = 0;
REQUIRE(
cudaSuccess
== cub::DeviceAdjacentDifference::SubtractLeftCopy(
temporary_storage, temporary_bytes, input.begin(), output_it, input.size(), cuda::std::minus<>{}, stream.get()));

c2h::device_vector<std::uint8_t> temporary_buffer(temporary_bytes);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
c2h::device_vector<std::uint8_t> temporary_buffer(temporary_bytes);
c2h::device_vector<std::uint8_t> temporary_buffer(temporary_bytes, thrust::no_init);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied thrust::no_init to the temporary-storage allocation in the relocated test.

temporary_storage = thrust::raw_pointer_cast(temporary_buffer.data());
REQUIRE(
cudaSuccess
== cub::DeviceAdjacentDifference::SubtractLeftCopy(
temporary_storage, temporary_bytes, input.begin(), output_it, input.size(), cuda::std::minus<>{}, stream.get()));
stream.sync();

const c2h::host_vector<type> expected{2, 3, 4, 5, 6};
REQUIRE(output == expected);
}

// todo(giannis): extract examples from the docs to literalinclude extracts here
Loading