Skip to content

Commit

Permalink
exposing streams
Browse files Browse the repository at this point in the history
  • Loading branch information
shrshi committed Nov 6, 2024
1 parent ac5b3ed commit 774f58b
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 10 deletions.
6 changes: 6 additions & 0 deletions cpp/include/cudf/quantiles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ namespace CUDF_EXPORT cudf {
* ignored.
* @param[in] exact If true, returns doubles.
* If false, returns same type as input.
* @param[in] stream CUDA stream used for device memory operations and kernel launches
* @param[in] mr Device memory resource used to allocate the returned column's device
memory
* @returns Column of specified quantiles, with nulls for indeterminable values
Expand All @@ -59,6 +60,7 @@ std::unique_ptr<column> quantile(
interpolation interp = interpolation::LINEAR,
column_view const& ordered_indices = {},
bool exact = true,
rmm::cuda_stream_view stream = cudf::get_default_stream(),
rmm::device_async_resource_ref mr = cudf::get_current_device_resource_ref());

/**
Expand All @@ -85,6 +87,7 @@ std::unique_ptr<column> quantile(
* @param is_input_sorted Indicates if the input has been pre-sorted
* @param column_order The desired sort order for each column
* @param null_precedence The desired order of null compared to other elements
* @param stream CUDA stream used for device memory operations and kernel launches
* @param mr Device memory resource used to allocate the returned table's device memory
*
* @returns Table of specified quantiles, with nulls for indeterminable values
Expand All @@ -98,6 +101,7 @@ std::unique_ptr<table> quantiles(
cudf::sorted is_input_sorted = sorted::NO,
std::vector<order> const& column_order = {},
std::vector<null_order> const& null_precedence = {},
rmm::cuda_stream_view stream = cudf::get_default_stream(),
rmm::device_async_resource_ref mr = cudf::get_current_device_resource_ref());

/**
Expand All @@ -114,6 +118,7 @@ std::unique_ptr<table> quantiles(
*
* @param input tdigest input data. One tdigest per row
* @param percentiles Desired percentiles in range [0, 1]
* @param stream CUDA stream used for device memory operations and kernel launches
* @param mr Device memory resource used to allocate the returned column's device
* memory
*
Expand All @@ -125,6 +130,7 @@ std::unique_ptr<table> quantiles(
std::unique_ptr<column> percentile_approx(
tdigest::tdigest_column_view const& input,
column_view const& percentiles,
rmm::cuda_stream_view stream = cudf::get_default_stream(),
rmm::device_async_resource_ref mr = cudf::get_current_device_resource_ref());

/** @} */ // end of group
Expand Down
3 changes: 2 additions & 1 deletion cpp/src/quantiles/quantile.cu
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,11 @@ std::unique_ptr<column> quantile(column_view const& input,
interpolation interp,
column_view const& ordered_indices,
bool exact,
rmm::cuda_stream_view stream,
rmm::device_async_resource_ref mr)
{
CUDF_FUNC_RANGE();
return detail::quantile(input, q, interp, ordered_indices, exact, cudf::get_default_stream(), mr);
return detail::quantile(input, q, interp, ordered_indices, exact, stream, mr);
}

} // namespace cudf
11 changes: 3 additions & 8 deletions cpp/src/quantiles/quantiles.cu
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,12 @@ std::unique_ptr<table> quantiles(table_view const& input,
cudf::sorted is_input_sorted,
std::vector<order> const& column_order,
std::vector<null_order> const& null_precedence,
rmm::cuda_stream_view stream,
rmm::device_async_resource_ref mr)
{
CUDF_FUNC_RANGE();
return detail::quantiles(input,
q,
interp,
is_input_sorted,
column_order,
null_precedence,
cudf::get_default_stream(),
mr);
return detail::quantiles(
input, q, interp, is_input_sorted, column_order, null_precedence, stream, mr);
}

} // namespace cudf
3 changes: 2 additions & 1 deletion cpp/src/quantiles/tdigest/tdigest.cu
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,11 @@ std::unique_ptr<column> percentile_approx(tdigest_column_view const& input,

std::unique_ptr<column> percentile_approx(tdigest_column_view const& input,
column_view const& percentiles,
rmm::cuda_stream_view stream,
rmm::device_async_resource_ref mr)
{
CUDF_FUNC_RANGE();
return tdigest::percentile_approx(input, percentiles, cudf::get_default_stream(), mr);
return tdigest::percentile_approx(input, percentiles, stream, mr);
}

} // namespace cudf
1 change: 1 addition & 0 deletions cpp/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,7 @@ ConfigureTest(STREAM_ORCIO_TEST streams/io/orc_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_PARQUETIO_TEST streams/io/parquet_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_PARTITIONING_TEST streams/partitioning_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_POOL_TEST streams/pool_test.cu STREAM_MODE testing)
ConfigureTest(STREAM_QUANTILE_TEST streams/quantile_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_REDUCTION_TEST streams/reduction_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_REPLACE_TEST streams/replace_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_RESHAPE_TEST streams/reshape_test.cpp STREAM_MODE testing)
Expand Down
76 changes: 76 additions & 0 deletions cpp/tests/streams/quantile_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright (c) 2024, 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 <cudf_test/base_fixture.hpp>
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/table_utilities.hpp>
#include <cudf_test/type_lists.hpp>

#include <cudf/column/column_view.hpp>
#include <cudf/detail/tdigest/tdigest.hpp>
#include <cudf/quantiles.hpp>
#include <cudf/table/table_view.hpp>
#include <cudf/types.hpp>

#include <stdexcept>

struct QuantileTest : public cudf::test::BaseFixture {};

TEST_F(QuantileTest, TestMultiColumnUnsorted)
{
auto input_a = cudf::test::strings_column_wrapper(
{"C", "B", "A", "A", "D", "B", "D", "B", "D", "C", "C", "C",
"D", "B", "D", "B", "C", "C", "A", "D", "B", "A", "A", "A"},
{true, true, true, true, true, true, true, true, true, true, true, true,
true, true, true, true, true, true, true, true, true, true, true, true});

cudf::test::fixed_width_column_wrapper<numeric::decimal32, int32_t> input_b(
{4, 3, 5, 0, 1, 0, 4, 1, 5, 3, 0, 5, 2, 4, 3, 2, 1, 2, 3, 0, 5, 1, 4, 2},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1});

auto input = cudf::table_view({input_a, input_b});

auto actual = cudf::quantiles(input,
{0.0f, 0.5f, 0.7f, 0.25f, 1.0f},
cudf::interpolation::NEAREST,
cudf::sorted::NO,
{cudf::order::ASCENDING, cudf::order::DESCENDING},
{},
cudf::test::get_default_stream());
}

TEST_F(QuantileTest, TestEmpty)
{
auto input = cudf::test::fixed_width_column_wrapper<numeric::decimal32>({});
cudf::quantile(
input, {0.5, 0.25}, cudf::interpolation::LINEAR, {}, true, cudf::test::get_default_stream());
}

TEST_F(QuantileTest, EmptyInput)
{
auto empty_ = cudf::tdigest::detail::make_empty_tdigests_column(
1, cudf::get_default_stream(), cudf::get_current_device_resource_ref());
cudf::test::fixed_width_column_wrapper<double> percentiles{0.0, 0.25, 0.3};

std::vector<cudf::column_view> input;
input.push_back(*empty_);
input.push_back(*empty_);
input.push_back(*empty_);
auto empty = cudf::concatenate(input);

cudf::tdigest::tdigest_column_view tdv(*empty);
auto result = cudf::percentile_approx(tdv, percentiles, cudf::test::get_default_stream());
}

0 comments on commit 774f58b

Please sign in to comment.