Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speedup make_blobs by up to 2x by fixing inefficient kernel launch configuration #1100

Merged
merged 3 commits into from
Dec 14, 2022
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
10 changes: 10 additions & 0 deletions cpp/bench/random/make_blobs.cu
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ struct make_blobs_inputs {
bool row_major;
}; // struct make_blobs_inputs

inline auto operator<<(std::ostream& os, const make_blobs_inputs& p) -> std::ostream&
{
os << p.rows << "#" << p.cols << "#" << p.clusters << "#" << p.row_major;
return os;
}

template <typename T>
struct make_blobs : public fixture {
make_blobs(const make_blobs_inputs& p)
Expand All @@ -34,6 +40,10 @@ struct make_blobs : public fixture {

void run_benchmark(::benchmark::State& state) override
{
std::ostringstream label_stream;
label_stream << params;
state.SetLabel(label_stream.str());

loop_on_state(state, [this]() {
raft::random::make_blobs(data.data(),
labels.data(),
Expand Down
6 changes: 4 additions & 2 deletions cpp/include/raft/random/detail/make_blobs.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,10 @@ void generate_data(DataT* out,
const DataT cluster_std_scalar,
raft::random::RngState& rng_state)
{
IdxT items = n_rows * n_cols;
IdxT nBlocks = (items + 127) / 128;
constexpr IdxT block_size = 128;
IdxT items = n_rows * n_cols;
// Choose a grid size so that each thread can write two output values.
IdxT nBlocks = ceildiv<IdxT>(items, 2 * block_size);
// parentheses needed here for kernel, otherwise macro interprets the arguments
// of triple chevron notation as macro arguments
RAFT_CALL_RNG_FUNC(rng_state,
Expand Down