-
Notifications
You must be signed in to change notification settings - Fork 924
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
535 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright (c) 2021, 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/column/column.hpp> | ||
#include <cudf/detail/aggregation/aggregation.hpp> | ||
#include <cudf/detail/copy.hpp> | ||
#include <cudf/detail/nvtx/ranges.hpp> | ||
#include <cudf/detail/quantiles.hpp> | ||
#include <cudf/detail/reduction_functions.hpp> | ||
#include <cudf/detail/sorting.hpp> | ||
#include <cudf/detail/stream_compaction.hpp> | ||
#include <cudf/reduction.hpp> | ||
#include <cudf/scalar/scalar_factories.hpp> | ||
|
||
#include <cudf/structs/structs_column_view.hpp> | ||
#include <rmm/cuda_stream_view.hpp> | ||
|
||
namespace cudf { | ||
namespace detail { | ||
struct segmented_reduce_dispatch_functor { | ||
column_view const col; | ||
column_view const offsets; | ||
data_type output_dtype; | ||
rmm::mr::device_memory_resource* mr; | ||
rmm::cuda_stream_view stream; | ||
|
||
segmented_reduce_dispatch_functor(column_view const& col, | ||
column_view const& offsets, | ||
data_type output_dtype, | ||
rmm::cuda_stream_view stream, | ||
rmm::mr::device_memory_resource* mr) | ||
: col(col), offsets(offsets), output_dtype(output_dtype), mr(mr), stream(stream) | ||
{ | ||
} | ||
|
||
template <aggregation::Kind k> | ||
std::unique_ptr<column> operator()(std::unique_ptr<aggregation> const& agg) | ||
{ | ||
switch (k) { | ||
case aggregation::SUM: | ||
return reduction::segmented_sum(col, offsets, output_dtype, stream, mr); | ||
break; | ||
// case aggregation::PRODUCT: return reduction::product(col, output_dtype, stream, mr); break; | ||
// case aggregation::MIN: return reduction::min(col, output_dtype, stream, mr); break; | ||
// case aggregation::MAX: return reduction::max(col, output_dtype, stream, mr); break; | ||
// case aggregation::ANY: return reduction::any(col, output_dtype, stream, mr); break; | ||
// case aggregation::ALL: return reduction::all(col, output_dtype, stream, mr); break; | ||
default: CUDF_FAIL("Unsupported aggregation type."); | ||
} | ||
} | ||
}; | ||
|
||
std::unique_ptr<column> segmented_reduce( | ||
column_view const& col, | ||
column_view const& offsets, | ||
std::unique_ptr<aggregation> const& agg, | ||
data_type output_dtype, | ||
rmm::cuda_stream_view stream = rmm::cuda_stream_default, | ||
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()) | ||
{ | ||
// TODO: handle invalid inputs. | ||
|
||
return aggregation_dispatcher( | ||
agg->kind, segmented_reduce_dispatch_functor{col, offsets, output_dtype, stream, mr}, agg); | ||
} | ||
} // namespace detail | ||
|
||
std::unique_ptr<column> segmented_reduce(column_view const& col, | ||
column_view const& offsets, | ||
std::unique_ptr<aggregation> const& agg, | ||
data_type output_dtype, | ||
rmm::mr::device_memory_resource* mr) | ||
{ | ||
CUDF_FUNC_RANGE(); | ||
return detail::segmented_reduce(col, offsets, agg, output_dtype, rmm::cuda_stream_default, mr); | ||
} | ||
|
||
} // namespace cudf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (c) 2019-2021, 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/detail/reduction_functions.hpp> | ||
#include <cudf/dictionary/dictionary_column_view.hpp> | ||
#include <reductions/simple_segmented.cuh> | ||
|
||
#include <rmm/cuda_stream_view.hpp> | ||
|
||
namespace cudf { | ||
namespace reduction { | ||
|
||
std::unique_ptr<cudf::column> segmented_sum(column_view const& col, | ||
column_view const& offsets, | ||
cudf::data_type const output_dtype, | ||
rmm::cuda_stream_view stream, | ||
rmm::mr::device_memory_resource* mr) | ||
{ | ||
return cudf::type_dispatcher(col.type(), | ||
simple::column_type_dispatcher<cudf::reduction::op::sum>{}, | ||
col, | ||
offsets, | ||
output_dtype, | ||
stream, | ||
mr); | ||
} | ||
|
||
} // namespace reduction | ||
} // namespace cudf |
Oops, something went wrong.