From bb2abb9d63c40d2db07be4c1e01d1ee53bf08249 Mon Sep 17 00:00:00 2001 From: Basit Ayantunde Date: Mon, 13 Jan 2025 17:59:58 +0000 Subject: [PATCH] added random scalar generation & cleanup of polynomials benchmark --- cpp/benchmarks/CMakeLists.txt | 5 +++-- cpp/benchmarks/ast/polynomials.cpp | 17 ++++++++++++----- cpp/benchmarks/binaryop/polynomials.cpp | 19 ++++++++++++++----- cpp/benchmarks/transform/polynomials.cpp | 16 +++++++++++----- 4 files changed, 40 insertions(+), 17 deletions(-) diff --git a/cpp/benchmarks/CMakeLists.txt b/cpp/benchmarks/CMakeLists.txt index 468115942fb..4d32a1a1f3e 100644 --- a/cpp/benchmarks/CMakeLists.txt +++ b/cpp/benchmarks/CMakeLists.txt @@ -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 ---------------------------------------------------------------------------- @@ -353,7 +353,8 @@ ConfigureNVBench( ) # ################################################################################################## -# * ast benchmark --------------------------------------------------------------------------------- +# * transform benchmark +# --------------------------------------------------------------------------------- ConfigureNVBench(TRANSFORM_NVBENCH transform/polynomials.cpp) # ################################################################################################## diff --git a/cpp/benchmarks/ast/polynomials.cpp b/cpp/benchmarks/ast/polynomials.cpp index c71f3dfedc9..b8e4ca46b72 100644 --- a/cpp/benchmarks/ast/polynomials.cpp +++ b/cpp/benchmarks/ast/polynomials.cpp @@ -28,6 +28,8 @@ #include #include +#include + template static void BM_ast_polynomials(nvbench::state& state) { @@ -45,11 +47,16 @@ static void BM_ast_polynomials(nvbench::state& state) auto column_view = table->get_column(0); std::vector> constants; - - std::transform(thrust::make_counting_iterator(0), - thrust::make_counting_iterator(order + 1), - std::back_inserter(constants), - [](int) { return cudf::numeric_scalar(1); }); + { + std::random_device random_device; + std::mt19937 generator; + std::uniform_real_distribution 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{}; diff --git a/cpp/benchmarks/binaryop/polynomials.cpp b/cpp/benchmarks/binaryop/polynomials.cpp index 7a6489eb2c9..782ae1db927 100644 --- a/cpp/benchmarks/binaryop/polynomials.cpp +++ b/cpp/benchmarks/binaryop/polynomials.cpp @@ -28,6 +28,7 @@ #include #include +#include template static void BM_binaryop_polynomials(nvbench::state& state) @@ -46,11 +47,16 @@ static void BM_binaryop_polynomials(nvbench::state& state) auto column_view = table->get_column(0); std::vector> constants; + { + std::random_device random_device; + std::mt19937 generator; + std::uniform_real_distribution 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(0.8F); }); + std::transform(thrust::make_counting_iterator(0), + thrust::make_counting_iterator(order + 1), + std::back_inserter(constants), + [&](int) { return cudf::numeric_scalar(distribution(generator)); }); + } // Use the number of bytes read from global memory state.add_global_memory_reads(num_rows); @@ -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> intermediates; auto result = cudf::make_column_from_scalar(constants[0], num_rows, stream); @@ -74,7 +81,9 @@ static void BM_binaryop_polynomials(nvbench::state& state) cudf::binary_operator::ADD, cudf::data_type{cudf::type_to_id()}, stream); - result = std::move(sum); + intermediates.push_back(std::move(product)); + intermediates.push_back(std::move(result)); + result = std::move(sum); } }); } diff --git a/cpp/benchmarks/transform/polynomials.cpp b/cpp/benchmarks/transform/polynomials.cpp index 32fbeb0af45..f23789f5460 100644 --- a/cpp/benchmarks/transform/polynomials.cpp +++ b/cpp/benchmarks/transform/polynomials.cpp @@ -47,10 +47,16 @@ static void BM_transform_polynomials(nvbench::state& state) std::vector 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 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(num_rows); @@ -71,7 +77,7 @@ static void BM_transform_polynomials(nvbench::state& state) std::string type = std::is_same_v ? "float" : "double"; std::string udf = R"***( -__device__ inline void fdsf ( +__device__ inline void compute_polynomial ( )***" + type + R"***(* out, )***" + type + R"***( x )