Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <cub/device/device_adjacent_difference.cuh>

#include <cuda/buffer>
#include <cuda/devices>
#include <cuda/iterator>
#include <cuda/std/execution>
Expand Down Expand Up @@ -258,6 +259,35 @@ C2H_TEST("DeviceAdjacentDifference::SubtractLeftCopy works with user provided me
test_subtract_left_copy(policy);
}
}

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(), thrust::no_init);
const 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, thrust::no_init);
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()));

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: Just use the launch wrapper adjacent_difference_subtract_left instead of handling the temporary storage allocation yourself.

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.

Updated the regression test to use adjacent_difference_subtract_left_copy, since this test covers SubtractLeftCopy. The launch wrapper now handles the temporary storage internally.

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

stream.sync();

const c2h::host_vector<type> expected{2, 3, 4, 5, 6};
REQUIRE(output == expected);
Comment on lines +274 to +276

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: I think we do not to sync when we use a custom stream:

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

}
#endif // TEST_LAUNCH == 0

C2H_TEST("DeviceAdjacentDifference::SubtractLeftCopy works with iterators", "[device][adjacent_difference]", types)
Expand Down