Skip to content

Commit

Permalink
added random scalar generation & cleanup of polynomials benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
lamarrr committed Jan 13, 2025
1 parent f84cb54 commit bb2abb9
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 17 deletions.
5 changes: 3 additions & 2 deletions cpp/benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ ConfigureNVBench(CSV_WRITER_NVBENCH io/csv/csv_writer.cpp)

# ##################################################################################################
# * ast benchmark ---------------------------------------------------------------------------------
ConfigureNVBench(AST_NVBENCH ast/transform.cpp ast/polynomials.cpp)
ConfigureNVBench(AST_NVBENCH ast/polynomials.cpp ast/transform.cpp)

# ##################################################################################################
# * binaryop benchmark ----------------------------------------------------------------------------
Expand All @@ -353,7 +353,8 @@ ConfigureNVBench(
)

# ##################################################################################################
# * ast benchmark ---------------------------------------------------------------------------------
# * transform benchmark
# ---------------------------------------------------------------------------------
ConfigureNVBench(TRANSFORM_NVBENCH transform/polynomials.cpp)

# ##################################################################################################
Expand Down
17 changes: 12 additions & 5 deletions cpp/benchmarks/ast/polynomials.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <nvbench/nvbench.cuh>
#include <nvbench/types.cuh>

#include <random>

template <typename key_type>
static void BM_ast_polynomials(nvbench::state& state)
{
Expand All @@ -45,11 +47,16 @@ static void BM_ast_polynomials(nvbench::state& state)
auto column_view = table->get_column(0);

std::vector<cudf::numeric_scalar<key_type>> constants;

std::transform(thrust::make_counting_iterator(0),
thrust::make_counting_iterator(order + 1),
std::back_inserter(constants),
[](int) { return cudf::numeric_scalar<key_type>(1); });
{
std::random_device random_device;
std::mt19937 generator;
std::uniform_real_distribution<key_type> distribution{0, 1};

std::transform(thrust::make_counting_iterator(0),
thrust::make_counting_iterator(order + 1),
std::back_inserter(constants),
[&](int) { return distribution(generator); });
}

cudf::ast::tree tree{};

Expand Down
19 changes: 14 additions & 5 deletions cpp/benchmarks/binaryop/polynomials.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <nvbench/nvbench.cuh>

#include <algorithm>
#include <random>

template <typename key_type>
static void BM_binaryop_polynomials(nvbench::state& state)
Expand All @@ -46,11 +47,16 @@ static void BM_binaryop_polynomials(nvbench::state& state)
auto column_view = table->get_column(0);

std::vector<cudf::numeric_scalar<key_type>> constants;
{
std::random_device random_device;
std::mt19937 generator;
std::uniform_real_distribution<key_type> distribution{0, 1};

std::transform(thrust::make_counting_iterator(0),
thrust::make_counting_iterator(order + 1),
std::back_inserter(constants),
[](int) { return cudf::numeric_scalar<key_type>(0.8F); });
std::transform(thrust::make_counting_iterator(0),
thrust::make_counting_iterator(order + 1),
std::back_inserter(constants),
[&](int) { return cudf::numeric_scalar<key_type>(distribution(generator)); });
}

// Use the number of bytes read from global memory
state.add_global_memory_reads<key_type>(num_rows);
Expand All @@ -60,6 +66,7 @@ static void BM_binaryop_polynomials(nvbench::state& state)
// computes polynomials: (((ax + b)x + c)x + d)x + e... = ax**4 + bx**3 + cx**2 + dx + e....
cudf::scoped_range range{"benchmark_iteration"};
rmm::cuda_stream_view stream{launch.get_stream().get_stream()};
std::vector<std::unique_ptr<cudf::column>> intermediates;

auto result = cudf::make_column_from_scalar(constants[0], num_rows, stream);

Expand All @@ -74,7 +81,9 @@ static void BM_binaryop_polynomials(nvbench::state& state)
cudf::binary_operator::ADD,
cudf::data_type{cudf::type_to_id<key_type>()},
stream);
result = std::move(sum);
intermediates.push_back(std::move(product));
intermediates.push_back(std::move(result));
result = std::move(sum);
}
});
}
Expand Down
16 changes: 11 additions & 5 deletions cpp/benchmarks/transform/polynomials.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,16 @@ static void BM_transform_polynomials(nvbench::state& state)

std::vector<key_type> constants;

std::transform(thrust::make_counting_iterator(0),
thrust::make_counting_iterator(order + 1),
std::back_inserter(constants),
[](int) { return 0.8F; });
{
std::random_device random_device;
std::mt19937 generator;
std::uniform_real_distribution<key_type> distribution{0, 1};

std::transform(thrust::make_counting_iterator(0),
thrust::make_counting_iterator(order + 1),
std::back_inserter(constants),
[&](int) { return distribution(generator); });
}

// Use the number of bytes read from global memory
state.add_global_memory_reads<key_type>(num_rows);
Expand All @@ -71,7 +77,7 @@ static void BM_transform_polynomials(nvbench::state& state)
std::string type = std::is_same_v<key_type, float> ? "float" : "double";

std::string udf = R"***(
__device__ inline void fdsf (
__device__ inline void compute_polynomial (
)***" + type + R"***(* out,
)***" + type + R"***( x
)
Expand Down

0 comments on commit bb2abb9

Please sign in to comment.