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

[REVIEW] Abstract Syntax Tree evaluator #5494

Merged
merged 186 commits into from
Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from 216 commits
Commits
Show all changes
186 commits
Select commit Hold shift + click to select a range
80aecd6
First draft of ast.
bdice Jun 17, 2020
65feb88
Fix style in tests CMakeLists.
bdice Jun 17, 2020
bffe833
Update CHANGELOG.md.
bdice Jun 17, 2020
03accf4
Working kernel. (Tests will fail without row dispatch.)
bdice Jun 18, 2020
844379a
Add row dispatch.
bdice Jun 18, 2020
784a24b
Add comparators, refactor operation dispatch.
bdice Jun 19, 2020
c1ee9b5
Move to ast namespace.
bdice Jun 23, 2020
777f2b3
Add operators header.
bdice Jun 26, 2020
f63d525
Interim work: added visitor pattern for tree parsing, improved data r…
bdice Jun 26, 2020
2cfca4a
Remove templates from tests (not yet passing).
bdice Jun 26, 2020
687d4d7
Added column_reference and made progress on AST linearizer.
bdice Jun 29, 2020
da054e8
Use const& instead of shared pointers.
bdice Jun 30, 2020
aeb5a09
Refactoring data references, eliminating TODOs.
bdice Jul 1, 2020
5f871f5
Implement operator!= for cudf::data_type (needed for std::not_equal_t…
bdice Jul 1, 2020
d673c8d
Add intermediate counter, more linearizer info.
bdice Jul 1, 2020
7e04e62
Starting device code.
bdice Jul 1, 2020
fc99a01
Starting work on operator dispatch.
bdice Jul 1, 2020
236d0e6
Added shared memory and operator traits.
bdice Jul 2, 2020
f3995e0
Check binary trait.
bdice Jul 2, 2020
f96da22
Refactor ast_operator_dispatcher to be more general.
bdice Jul 2, 2020
75989b8
Implement additional dispatching logic. This commit has some kind of …
bdice Jul 2, 2020
b2233e7
Remove unused code.
bdice Jul 2, 2020
66e2ece
Separate input and output data reference resolution.
bdice Jul 2, 2020
56c5416
Add output copy functor and passing tests!
bdice Jul 2, 2020
79a03f9
Add passing tests for double columns with unbalanced tree.
bdice Jul 2, 2020
bb0a79c
Simplify code, add comments.
bdice Jul 2, 2020
6002c4d
Disable verbose output.
bdice Jul 8, 2020
15063e0
Add AST benchmark draft.
bdice Jul 8, 2020
01b4425
Update AST benchmarks.
bdice Jul 10, 2020
1397c75
Add draft of binaryop benchmarks.
bdice Jul 10, 2020
ce1bdd9
Minor cleanup.
bdice Jul 10, 2020
74e6534
Re-use intermediate locations in shared memory.
bdice Jul 10, 2020
bdd5815
Clarify comment.
bdice Jul 10, 2020
929e87b
Add re-used column tests.
bdice Jul 15, 2020
7aa1a28
Re-use data references.
bdice Jul 15, 2020
4001f43
Add NVTX markers.
bdice Jul 15, 2020
7044f87
Clean up includes.
bdice Jul 15, 2020
31a2421
Perform all benchmarks.
bdice Jul 15, 2020
672c81e
Use rmm::device_vector, offers significantly less overhead.
bdice Jul 15, 2020
949856b
Remove unused include.
bdice Jul 15, 2020
a0e77be
Merge remote-tracking branch 'upstream/branch-0.15' into ast
bdice Jul 15, 2020
070a99d
Use async streams to copy AST plan to device.
bdice Jul 15, 2020
4f465c3
Move ast code into separate headers.
bdice Jul 15, 2020
cdf6969
Move linearizer implementations to cpp file.
bdice Jul 15, 2020
3f69c1c
Remove unused includes.
bdice Jul 15, 2020
129608c
Add operators (intermediate work).
bdice Jul 17, 2020
1fc3de5
Add a validity trait.
bdice Jul 17, 2020
3a9438d
Merge remote-tracking branch 'upstream/branch-0.15' into ast
bdice Jul 20, 2020
7145b9a
Merge branch 'double-dispatcher' into ast
bdice Jul 20, 2020
140457a
Expand benchmarks.
bdice Jul 20, 2020
35180ff
Add notes about possible nullary operators.
bdice Jul 20, 2020
b06f745
Intermediate work. Compiles.
bdice Jul 22, 2020
6f36db3
Fix benchmark bytes processed.
bdice Jul 24, 2020
1423013
Rewrite operator-type-type dispatching.
bdice Jul 24, 2020
ca6bb0f
Merge branch 'double-dispatcher' into ast
bdice Jul 27, 2020
c8bb499
Simplify benchmarking logic.
bdice Jul 27, 2020
b7a5585
Fix name of double_type_dispatcher.
bdice Jul 27, 2020
e206287
Use fewer benchmarks.
bdice Jul 27, 2020
c838f1b
Re-order includes.
bdice Jul 28, 2020
46df001
Add typed_operator_dispatch_functor.
bdice Jul 28, 2020
5b89091
Miscellaneous small fixes and debugging code.
bdice Jul 28, 2020
a4e8dfa
Use 512 block size, CHECK_CUDA.
bdice Jul 29, 2020
54fd274
Remove final output functor, increase use of const.
bdice Jul 30, 2020
79526d8
Fix output reference, minor refactoring.
bdice Jul 30, 2020
6290d84
Pass more arguments as const&.
bdice Jul 30, 2020
eb71d3d
Remove most of previous dispatch code in ast.cuh, add data type funct…
bdice Jul 31, 2020
412f2f2
Refactor ast.cuh into ast.cu.
bdice Jul 31, 2020
f0b7e4f
Add back const qualifiers.
bdice Jul 31, 2020
e0c0eb2
Remove old operators.
bdice Jul 31, 2020
2d587a6
Enable SUB operator.
bdice Jul 31, 2020
a0fbea8
Update tests for custom functor.
bdice Jul 31, 2020
e12a6f3
Merge remote-tracking branch 'sriramch/add_months' into ast-add_months
bdice Jul 31, 2020
002735b
Make dictionary value constructor explicit so it isn't implicited con…
bdice Jul 31, 2020
3a1bfdc
Default-construct return value of unsupported input references.
bdice Jul 31, 2020
d7d1bfe
Use explicit Element constructor rather than implicit conversion.
bdice Jul 31, 2020
6fcafe1
Fix include.
bdice Aug 3, 2020
2c4c36a
Merge remote-tracking branch 'sriramch/add_months' into ast-add_months
bdice Aug 3, 2020
74df976
Merge branch 'explicit-dictionary-constructor' into ast-add_months
bdice Aug 3, 2020
c2c2b99
Fix const qualifiers.
bdice Aug 3, 2020
f3ec77b
Add back tests.
bdice Aug 3, 2020
165faae
Merge remote-tracking branch 'upstream/branch-0.15' into ast
bdice Aug 3, 2020
d702d30
Merge remote-tracking branch 'sriramch/add_months' into ast
bdice Aug 5, 2020
905d11c
Expand supported operators.
bdice Aug 5, 2020
14c5e78
Expand tests for comparators.
bdice Aug 5, 2020
98e17de
Add explicit conversion for fixed_point to bool.
bdice Aug 5, 2020
8d9dd8b
Update changelog.
bdice Aug 5, 2020
e12c9b6
Use static casts to bool.
bdice Aug 5, 2020
dce0c8d
Update Doxygen comments.
bdice Aug 6, 2020
7e7bfe1
Merge branch 'branch-0.15' into ast
bdice Aug 6, 2020
e2cb56a
Add more operators.
bdice Aug 6, 2020
4b897dc
Switch to single dispatch.
bdice Aug 6, 2020
1a5ded1
Remove extra const.
bdice Aug 6, 2020
7f0d8ed
Separate tests.
bdice Aug 6, 2020
2833b9c
Add support for literal values via type-erased fixed_width_scalar_dev…
bdice Aug 7, 2020
29d2827
Merge remote-tracking branch 'upstream/branch-0.15' into ast
bdice Aug 7, 2020
2ac44e9
Add arity support and preliminary unary operator support.
bdice Aug 7, 2020
97dbdf4
Add working unary operators and tests.
bdice Aug 7, 2020
1536e4e
Merge branch 'add_months' into ast
bdice Aug 7, 2020
b64a73a
Add test for multi-type operation failure.
bdice Aug 10, 2020
9e94ac6
Use detail function instead of several async copies.
bdice Aug 10, 2020
bdc2b41
Add data_reference_resolver class, reduce repetition.
bdice Aug 11, 2020
ca80c17
Remove call_*_operator functions, add detail namespaces.
bdice Aug 11, 2020
18fc15e
Rename data_reference_resolver to row_evaluator, add operator() and r…
bdice Aug 11, 2020
5ab6cbd
Remove unnecessary compiler directives.
bdice Aug 11, 2020
d83bc61
Use arity_functor.
bdice Aug 11, 2020
13ea706
Add docstrings to operators.hpp.
bdice Aug 11, 2020
e3563b8
Add docstrings to linearizer.cuh.
bdice Aug 11, 2020
5be9fd8
Add docstrings to ast.cuh.
bdice Aug 11, 2020
e6becb2
Merge branch 'add_months' into ast
bdice Aug 12, 2020
044e9f6
Remove NVTX ranges.
bdice Aug 12, 2020
9c76bcd
Use .data() instead of thrust raw pointer cast.
bdice Aug 12, 2020
ff85ce1
Define Out type with using declaration instead of template parameter.
bdice Aug 12, 2020
2f768b3
Linearize in constructor.
bdice Aug 12, 2020
8e73955
Merge unary/binary expression classes, rename expression to node.
bdice Aug 12, 2020
55ea383
Remove Out template parameter.
bdice Aug 12, 2020
3360e89
Construct vector with known size.
bdice Aug 12, 2020
afddf6d
Clean up includes.
bdice Aug 12, 2020
7a5a647
Move __device__ method definitions to ast.cuh header.
bdice Aug 12, 2020
a3bedc0
Use memcpy instead of unsafe type aliasing in data reference resoluti…
bdice Aug 13, 2020
b0f439b
Add string comparison test.
bdice Aug 13, 2020
202da27
Remove abstract_visitor.
bdice Aug 13, 2020
8c8bff1
Move linearizer to cpp/hpp.
bdice Aug 13, 2020
864642d
Unify return_type_functor.
bdice Aug 13, 2020
cf15615
Use one ast operator dispatch.
bdice Aug 14, 2020
87144df
Add identity function and tests.
bdice Aug 14, 2020
4493bb5
Build and copy buffer in one step instead of multiple host-device cop…
bdice Aug 15, 2020
8f8fa8b
Check shared memory limits and use a smaller block size if necessary.
bdice Aug 15, 2020
6cdd31b
Finish some TODO items about error handling.
bdice Aug 15, 2020
953802d
Reduce stack frame with judicious use of const& (64 registers, 320 st…
bdice Aug 15, 2020
08ba438
More stack frame reduction, specialized ABS to arithmetic types to fi…
bdice Aug 15, 2020
0c1716b
Use auto const.
bdice Aug 15, 2020
d343851
Tweaks to stack frame.
bdice Aug 15, 2020
c92556d
Improve comments.
bdice Aug 15, 2020
3fb30ff
Merge remote-tracking branch 'sriramch/add_months' into ast
bdice Aug 17, 2020
71dc4b0
Merge remote-tracking branch 'upstream/branch-0.16' into ast
bdice Aug 17, 2020
f1bdfd7
Enable 'late' dispatch. Compiles.
bdice Aug 17, 2020
f59a5a7
Merge remote-tracking branch 'harrism/fix-benchmark-fixture-crash' in…
bdice Aug 18, 2020
257ff94
Merge remote-tracking branch 'upstream/branch-0.16' into ast
bdice Aug 18, 2020
cacb9c1
Merge remote-tracking branch 'harrism/fix-benchmark-fixture-crash' in…
bdice Aug 18, 2020
9f52eae
Only enable trigonometric operators for floating types (no C++11 inte…
bdice Aug 18, 2020
4014722
Merge branch 'ast-dispatch-late' into ast
bdice Aug 18, 2020
e108643
Move unimplemented operators together.
bdice Aug 18, 2020
f576c13
Use 128 block size for optimal performance.
bdice Aug 18, 2020
96893a3
Remove testing comments.
bdice Aug 18, 2020
5897059
Remove testing comments.
bdice Aug 18, 2020
8ca99da
Remove custom functor test.
bdice Aug 18, 2020
1737a45
Make some APIs detail.
bdice Aug 18, 2020
eee6656
Initialize with known number of values.
bdice Aug 18, 2020
ad31eba
Merge branch 'branch-0.16' into ast
bdice Aug 19, 2020
81581f9
Update meta.yaml.
bdice Aug 19, 2020
72b5584
Merge branch 'ast' of github.com:bdice/cudf into ast
bdice Aug 19, 2020
05a1388
Merge remote-tracking branch 'upstream/branch-0.16' into ast
bdice Aug 19, 2020
c550472
Move detail namespace into its own headers, rename "ast" to "transform."
bdice Aug 20, 2020
7498eb3
Add missing detail headers to meta.yaml.
bdice Aug 20, 2020
4bb70a5
Remove extra file.
bdice Aug 20, 2020
4c75f71
Merge remote-tracking branch 'upstream/branch-0.16' into ast
bdice Aug 20, 2020
5ecd6fc
Add AST transform tests.
bdice Aug 20, 2020
91350a3
Make operators CUDA_DEVICE_CALLABLE.
bdice Aug 21, 2020
a73fa20
Accept literal values as scalar&.
bdice Aug 21, 2020
e61a035
Fix line endings
bdice Aug 21, 2020
475e937
Fix commented code in AST benchmark.
bdice Aug 21, 2020
9bb8556
Make intermediate_counter an inner class.
bdice Aug 21, 2020
fb00dc5
Use __device__ for evaluate_row_operator_function::operator().
bdice Aug 21, 2020
a54a34c
Remove use of this->.
bdice Aug 21, 2020
a53442c
Improve find_first_missing.
bdice Aug 21, 2020
45bff49
Rename DEFAULT_BLOCK_SIZE to MAX_BLOCK_SIZE.
bdice Aug 21, 2020
d8479b4
Move ast plan logic into constructor, replace .at(i) with [i].
bdice Aug 21, 2020
edc0b23
Revert "Move ast plan logic into constructor, replace .at(i) with [i]."
bdice Aug 21, 2020
7231b02
Use [i] instead of .at(i).
bdice Aug 21, 2020
6ce0a85
Add constructor and update operator== for device_data_reference.
bdice Aug 21, 2020
9df472a
Use a constructor for device_data_reference.
bdice Aug 21, 2020
14b9678
Add double type dispatch with preprocessor guard.
bdice Aug 21, 2020
ed622d5
Reorder functors/functions.
bdice Aug 21, 2020
9b15e41
Move functor body inline.
bdice Aug 21, 2020
c398a61
Remove unnecessary declaration of kernel.
bdice Aug 21, 2020
b1d7d69
Use device_buffer constructor to copy from host.
bdice Aug 21, 2020
1f5e089
Return constant references (no copy).
bdice Aug 21, 2020
d3fcd26
Make single_dispatch_binary_operator device-only.
bdice Aug 21, 2020
1d9167c
Merge branch 'branch-0.16' into ast
jrhemstad Sep 15, 2020
ec0435e
Merge branch 'branch-0.16' into ast
harrism Sep 24, 2020
bea507d
Replace rmm::mr::get_default_resource()
harrism Sep 24, 2020
b44438a
Merge branch 'branch-0.16' into ast
harrism Sep 24, 2020
1d0b36d
Fix test utilities paths
harrism Sep 24, 2020
e696736
Deleted r-value constructors for 'expression' object
lamarrr Sep 25, 2020
91fe9ef
Merge pull request #1 from lamarrr/patch-1
bdice Sep 26, 2020
3692b80
Merge branch 'branch-0.16' into ast
harrism Sep 29, 2020
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## New Features

- PR #5974 Use libcudf instead of cupy for `arange` or column creation from a scalar.
- PR #5494 Add Abstract Syntax Tree (AST) evaluator.

## Improvements

Expand Down Expand Up @@ -39,7 +40,6 @@
- PR #5364 Validate array interface during buffer construction
- PR #5418 Add support for `DataFrame.info`
- PR #5425 Add Python `Groupby.rolling()`
- PR #5359 Add duration types
- PR #5434 Add nvtext function generate_character_grams
- PR #5442 Add support for `cudf.isclose`
- PR #5444 Remove usage of deprecated RMM APIs and headers.
Expand Down Expand Up @@ -189,6 +189,7 @@
- PR #5720 Replace owning raw pointers with std::unique_ptr
- PR #5702 Add inherited methods to python docs and other docs fixes
- PR #5733 Add support for `size` property in `DataFrame`/ `Series` / `Index`/ `MultiIndex`
- PR #5735 Force timestamp creation only with duration
- PR #5743 Reduce number of test cases in concatenate benchmark
- PR #5748 Disable `tolist` API in `Series` & `Index` and add `tolist` dispatch in `dask-cudf`
- PR #5744 Reduce number of test cases in reduction benchmark
Expand Down
4 changes: 3 additions & 1 deletion conda/recipes/libcudf/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2018, NVIDIA CORPORATION.
# Copyright (c) 2018-2020, NVIDIA CORPORATION.

{% set version = environ.get('GIT_DESCRIBE_TAG', '0.0.0.dev').lstrip('v') + environ.get('VERSION_SUFFIX', '') %}
{% set minor_version = version.split('.')[0] + '.' + version.split('.')[1] %}
Expand Down Expand Up @@ -46,6 +46,8 @@ test:
- test -f $PREFIX/lib/libcudf.so
- test -f $PREFIX/lib/libcudftestutil.a
- test -f $PREFIX/include/cudf/aggregation.hpp
- test -f $PREFIX/include/cudf/ast/linearizer.hpp
- test -f $PREFIX/include/cudf/ast/operators.hpp
- test -f $PREFIX/include/cudf/binaryop.hpp
- test -f $PREFIX/include/cudf/column/column_factories.hpp
- test -f $PREFIX/include/cudf/column/column.hpp
Expand Down
2 changes: 2 additions & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,8 @@ add_library(cudf
src/aggregation/aggregation.cpp
src/aggregation/aggregation.cu
src/aggregation/result_cache.cpp
src/ast/ast.cu
src/ast/linearizer.cpp
)

# Override RPATH for cudf
Expand Down
30 changes: 23 additions & 7 deletions cpp/benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ include_directories("${CUB_INCLUDE_DIR}"
if(CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES)
include_directories("${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}")
endif(CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES)

include_directories("${CMAKE_BINARY_DIR}/include"
"${CMAKE_SOURCE_DIR}/include"
"${CMAKE_SOURCE_DIR}"
Expand Down Expand Up @@ -174,23 +174,23 @@ set(HASHING_BENCH_SRC
ConfigureBench(HASHING_BENCH "${HASHING_BENCH_SRC}")

###################################################################################################
# - merge benchmark -----------------------------------------------------------------------------
# - merge benchmark -------------------------------------------------------------------------------

set(MERGE_BENCH_SRC
"${CMAKE_CURRENT_SOURCE_DIR}/merge/merge_benchmark.cpp")

ConfigureBench(MERGE_BENCH "${MERGE_BENCH_SRC}")

###################################################################################################
# - null_mask benchmark -----------------------------------------------------------------------------
# - null_mask benchmark ---------------------------------------------------------------------------

set(NULLMASK_BENCH_SRC
"${CMAKE_CURRENT_SOURCE_DIR}/null_mask/set_null_mask_benchmark.cpp")

ConfigureBench(NULLMASK_BENCH "${NULLMASK_BENCH_SRC}")

###################################################################################################
# - parquet writer chunks benchmark -----------------------------------------------------------------------------
# - parquet writer chunks benchmark ---------------------------------------------------------------

set(PARQUET_WRITER_CHUNKS_BENCH_SRC
"${CMAKE_CURRENT_SOURCE_DIR}/io/parquet/parquet_writer_chunks_benchmark.cpp")
Expand Down Expand Up @@ -222,29 +222,45 @@ set(CSV_READER_BENCH_SRC
ConfigureBench(CSV_READER_BENCH "${CSV_READER_BENCH_SRC}")

###################################################################################################
# - parquet writer benchmark -----------------------------------------------------------------------------
# - parquet writer benchmark ----------------------------------------------------------------------

set(PARQUET_WRITER_BENCH_SRC
"${CMAKE_CURRENT_SOURCE_DIR}/io/parquet/parquet_writer_benchmark.cpp")

ConfigureBench(PARQUET_WRITER_BENCH "${PARQUET_WRITER_BENCH_SRC}")

###################################################################################################
# - orc writer benchmark -----------------------------------------------------------------------------
# - orc writer benchmark --------------------------------------------------------------------------

set(ORC_WRITER_BENCH_SRC
"${CMAKE_CURRENT_SOURCE_DIR}/io/orc/orc_writer_benchmark.cpp")

ConfigureBench(ORC_WRITER_BENCH "${ORC_WRITER_BENCH_SRC}")

###################################################################################################
# - csv writer benchmark -----------------------------------------------------------------------------
# - csv writer benchmark --------------------------------------------------------------------------

set(CSV_WRITER_BENCH_SRC
"${CMAKE_CURRENT_SOURCE_DIR}/io/csv/csv_writer_benchmark.cpp")

ConfigureBench(CSV_WRITER_BENCH "${CSV_WRITER_BENCH_SRC}")

###################################################################################################
# - ast benchmark ---------------------------------------------------------------------------------

set(AST_BENCH_SRC
"${CMAKE_CURRENT_SOURCE_DIR}/ast/ast_benchmark.cu")

ConfigureBench(AST_BENCH "${AST_BENCH_SRC}")

###################################################################################################
# - binaryop benchmark ----------------------------------------------------------------------------

set(BINARYOP_BENCH_SRC
"${CMAKE_CURRENT_SOURCE_DIR}/binaryop/binaryop_benchmark.cu")

ConfigureBench(BINARYOP_BENCH "${BINARYOP_BENCH_SRC}")

###################################################################################################
# - subword tokenizer benchmark -------------------------------------------------------------------

Expand Down
155 changes: 155 additions & 0 deletions cpp/benchmarks/ast/ast_benchmark.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/*
* Copyright (c) 2020, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <benchmark/benchmark.h>

#include <thrust/iterator/counting_iterator.h>

#include <cudf/ast/ast.cuh>
#include <cudf/column/column_factories.hpp>
#include <cudf/table/table.hpp>
#include <cudf/table/table_view.hpp>
#include <cudf/types.hpp>
#include <cudf/utilities/error.hpp>
#include <tests/utilities/column_wrapper.hpp>

#include <fixture/benchmark_fixture.hpp>
#include <synchronization/synchronization.hpp>

#include <algorithm>
#include <iostream>
#include <list>
#include <numeric>
#include <vector>

enum class TreeType {
IMBALANCED_LEFT // All operator expressions have a left child operator expression and a right
// child column reference
};

template <typename key_type, TreeType tree_type, bool reuse_columns>
class AST : public cudf::benchmark {
};

template <typename key_type, TreeType tree_type, bool reuse_columns>
static void BM_ast_transform(benchmark::State& state)
{
const cudf::size_type table_size{(cudf::size_type)state.range(0)};
const cudf::size_type tree_levels = (cudf::size_type)state.range(1);

// Create table data
auto n_cols = reuse_columns ? 1 : tree_levels + 1;
auto column_wrappers = std::vector<cudf::test::fixed_width_column_wrapper<key_type>>(n_cols);
auto columns = std::vector<cudf::column_view>(n_cols);

auto data_iterator = thrust::make_counting_iterator(0);
std::generate_n(column_wrappers.begin(), n_cols, [=]() {
return cudf::test::fixed_width_column_wrapper<key_type>(data_iterator,
data_iterator + table_size);
});
std::transform(
column_wrappers.begin(), column_wrappers.end(), columns.begin(), [](auto const& col) {
return static_cast<cudf::column_view>(col);
});

cudf::table_view table{columns};

// Create column references
auto column_refs = std::vector<cudf::ast::column_reference>();
std::transform(thrust::make_counting_iterator(0),
thrust::make_counting_iterator(n_cols),
std::back_inserter(column_refs),
[](auto const& column_id) {
return cudf::ast::column_reference(reuse_columns ? 0 : column_id);
});

// Create expression trees

// Note that a std::list is required here because of its guarantees against reference invalidation
// when items are added or removed. References to items in a std::vector are not safe if the
// vector must re-allocate.
auto expressions = std::list<cudf::ast::expression>();

// Construct tree that chains additions like (((a + b) + c) + d)
auto const op = cudf::ast::ast_operator::ADD;
if (reuse_columns) {
expressions.push_back(cudf::ast::expression(op, column_refs.at(0), column_refs.at(0)));
for (cudf::size_type i = 0; i < tree_levels - 1; i++) {
expressions.push_back(cudf::ast::expression(op, expressions.back(), column_refs.at(0)));
}
} else {
expressions.push_back(cudf::ast::expression(op, column_refs.at(0), column_refs.at(1)));
std::transform(std::next(column_refs.cbegin(), 2),
column_refs.cend(),
std::back_inserter(expressions),
[&](auto const& column_ref) {
return cudf::ast::expression(op, expressions.back(), column_ref);
});
}

auto const& expression_tree_root = expressions.back();

// Execute benchmark
for (auto _ : state) {
cuda_event_timer raii(state, true); // flush_l2_cache = true, stream = 0
cudf::ast::compute_column(table, expression_tree_root);
}

// Use the number of bytes read from global memory
state.SetBytesProcessed(static_cast<int64_t>(state.iterations()) * state.range(0) *
(tree_levels + 1) * sizeof(key_type));
}

#define AST_TRANSFORM_BENCHMARK_DEFINE(name, key_type, tree_type, reuse_columns) \
BENCHMARK_TEMPLATE_DEFINE_F(AST, name, key_type, tree_type, reuse_columns) \
(::benchmark::State & st) { BM_ast_transform<key_type, tree_type, reuse_columns>(st); }

AST_TRANSFORM_BENCHMARK_DEFINE(ast_int32_imbalanced_unique,
int32_t,
TreeType::IMBALANCED_LEFT,
false);
AST_TRANSFORM_BENCHMARK_DEFINE(ast_int32_imbalanced_reuse,
int32_t,
TreeType::IMBALANCED_LEFT,
true);
AST_TRANSFORM_BENCHMARK_DEFINE(ast_double_imbalanced_unique,
double,
TreeType::IMBALANCED_LEFT,
false);

static void CustomRanges(benchmark::internal::Benchmark* b)
{
auto row_counts = std::vector<cudf::size_type>{100'000, 1'000'000, 10'000'000, 100'000'000};
auto operation_counts = std::vector<cudf::size_type>{1, 2, 5, 10};
for (auto const& row_count : row_counts) {
for (auto const& operation_count : operation_counts) { b->Args({row_count, operation_count}); }
}
}

BENCHMARK_REGISTER_F(AST, ast_int32_imbalanced_unique)
->Apply(CustomRanges)
->Unit(benchmark::kMillisecond)
->UseManualTime();

BENCHMARK_REGISTER_F(AST, ast_int32_imbalanced_reuse)
->Apply(CustomRanges)
->Unit(benchmark::kMillisecond)
->UseManualTime();

BENCHMARK_REGISTER_F(AST, ast_double_imbalanced_unique)
->Apply(CustomRanges)
->Unit(benchmark::kMillisecond)
->UseManualTime();
Loading