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
31 changes: 23 additions & 8 deletions cpp/benchmarks/utils/random_data.cu
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <cstdint>
#include <limits>

#include <thrust/random.h>
#include <thrust/transform.h>

Expand All @@ -17,21 +20,30 @@
#include "random_data.hpp"

rmm::device_uvector<std::int32_t> random_device_vector(
cudf::size_type nelem,
std::size_t nelem,
std::int32_t min_val,
std::int32_t max_val,
rmm::cuda_stream_view stream,
rmm::device_async_resource_ref mr
) {
// Fill vector with random data.
rmm::device_uvector<std::int32_t> vec(static_cast<std::size_t>(nelem), stream, mr);
using index_t = std::int64_t;
RAPIDSMPF_EXPECTS(
nelem <= static_cast<std::size_t>(std::numeric_limits<index_t>::max()),
"random_device_vector size exceeds signed iterator range"
);
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.

Nit. Do we consider 32-bit systems? For 64 bit nelem > INT64_MAX seems unlikely isnt it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Always use safe_cast()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Nit. Do we consider 32-bit systems?

No: https://forums.developer.nvidia.com/t/whats-the-last-version-of-the-cuda-toolkit-to-support-32-bit-applications/323106/4

For 64 bit nelem > INT64_MAX seems unlikely isnt it?

Removed that.

Always use safe_cast()

Done.

rmm::device_uvector<std::int32_t> vec(nelem, stream, mr);
thrust::counting_iterator<index_t> const begin(0);
thrust::counting_iterator<index_t> const end(static_cast<index_t>(nelem));
thrust::transform(
rmm::exec_policy(stream),
thrust::make_counting_iterator(0),
thrust::make_counting_iterator(nelem),
begin,
end,
vec.begin(),
[min_val, max_val] __device__(cudf::size_type index) {
thrust::default_random_engine engine(index); // HACK: use the seed as index
[min_val, max_val] __device__(index_t index) {
thrust::default_random_engine engine(
static_cast<thrust::default_random_engine::result_type>(index)
);
thrust::uniform_int_distribution<std::int32_t> dist(min_val, max_val);
return dist(engine);
}
Expand All @@ -46,7 +58,10 @@ std::unique_ptr<cudf::column> random_column(
rmm::cuda_stream_view stream,
rmm::device_async_resource_ref mr
) {
auto vec = random_device_vector(nrows, min_val, max_val, stream, mr);
RAPIDSMPF_EXPECTS(nrows >= 0, "nrows must be non-negative");
auto vec = random_device_vector(
static_cast<std::size_t>(nrows), min_val, max_val, stream, mr
);
return std::make_unique<cudf::column>(
std::move(vec), rmm::device_buffer{0, stream, mr}, 0
);
Expand All @@ -72,7 +87,7 @@ void random_fill(rapidsmpf::Buffer& buffer, rmm::device_async_resource_ref mr) {
case rapidsmpf::MemoryType::DEVICE:
{
auto vec = random_device_vector(
buffer.size / sizeof(std::int32_t) + sizeof(std::int32_t),
(buffer.size + sizeof(std::int32_t) - 1) / sizeof(std::int32_t),
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.

if buffer is empty now, we will be passing 0 to random_device_vector. I think random_fill was trying to prevent that before? I'm not sure.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Should be fixed now.

std::numeric_limits<std::int32_t>::min(),
std::numeric_limits<std::int32_t>::max(),
buffer.stream(),
Expand Down
5 changes: 4 additions & 1 deletion cpp/benchmarks/utils/random_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
*/
#pragma once

#include <cstddef>
#include <cstdint>

#include <cudf/column/column.hpp>
#include <cudf/table/table.hpp>
#include <cudf/types.hpp>
Expand Down Expand Up @@ -44,7 +47,7 @@ std::size_t constexpr random_table_size_lower_bound(
* @note The function uses the specified CUDA stream for asynchronous operations.
*/
rmm::device_uvector<std::int32_t> random_device_vector(
cudf::size_type nelem,
std::size_t nelem,
std::int32_t min_val,
std::int32_t max_val,
rmm::cuda_stream_view stream,
Expand Down
Loading