From a0ce65e425e47706a22f4244d163135accccfc71 Mon Sep 17 00:00:00 2001 From: Wonchan Lee Date: Tue, 23 Feb 2021 10:45:37 -0800 Subject: [PATCH 1/4] Add detail APIs for datetime functions --- cpp/include/cudf/detail/datetime.hpp | 129 +++++++++++++++++++++++++++ cpp/src/datetime/datetime_ops.cu | 108 +++++++++++++++++----- 2 files changed, 214 insertions(+), 23 deletions(-) create mode 100644 cpp/include/cudf/detail/datetime.hpp diff --git a/cpp/include/cudf/detail/datetime.hpp b/cpp/include/cudf/detail/datetime.hpp new file mode 100644 index 00000000000..684f33e609b --- /dev/null +++ b/cpp/include/cudf/detail/datetime.hpp @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2018-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. + */ + +#pragma once + +#include + +#include + +namespace cudf { +namespace datetime { +namespace detail { +/** + * @copydoc cudf::extract_year(cudf::column_view const&, rmm::mr::device_memory_resource *) + * + * @param stream CUDA stream used for device memory operations and kernel launches. + */ +std::unique_ptr extract_year( + cudf::column_view const& column, + rmm::cuda_stream_view stream = rmm::cuda_stream_default, + rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); + +/** + * @copydoc cudf::extract_month(cudf::column_view const&, rmm::mr::device_memory_resource *) + * + * @param stream CUDA stream used for device memory operations and kernel launches. + */ +std::unique_ptr extract_month( + cudf::column_view const& column, + rmm::cuda_stream_view stream = rmm::cuda_stream_default, + rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); + +/** + * @copydoc cudf::extract_day(cudf::column_view const&, rmm::mr::device_memory_resource *) + * + * @param stream CUDA stream used for device memory operations and kernel launches. + */ +std::unique_ptr extract_day( + cudf::column_view const& column, + rmm::cuda_stream_view stream = rmm::cuda_stream_default, + rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); + +/** + * @copydoc cudf::extract_weekday(cudf::column_view const&, rmm::mr::device_memory_resource *) + * + * @param stream CUDA stream used for device memory operations and kernel launches. + */ +std::unique_ptr extract_weekday( + cudf::column_view const& column, + rmm::cuda_stream_view stream = rmm::cuda_stream_default, + rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); + +/** + * @copydoc cudf::extract_hour(cudf::column_view const&, rmm::mr::device_memory_resource *) + * + * @param stream CUDA stream used for device memory operations and kernel launches. + */ +std::unique_ptr extract_hour( + cudf::column_view const& column, + rmm::cuda_stream_view stream = rmm::cuda_stream_default, + rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); + +/** + * @copydoc cudf::extract_minute(cudf::column_view const&, rmm::mr::device_memory_resource *) + * + * @param stream CUDA stream used for device memory operations and kernel launches. + */ +std::unique_ptr extract_minute( + cudf::column_view const& column, + rmm::cuda_stream_view stream = rmm::cuda_stream_default, + rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); + +/** + * @copydoc cudf::extract_second(cudf::column_view const&, rmm::mr::device_memory_resource *) + * + * @param stream CUDA stream used for device memory operations and kernel launches. + */ +std::unique_ptr extract_second( + cudf::column_view const& column, + rmm::cuda_stream_view stream = rmm::cuda_stream_default, + rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); + +/** + * @copydoc cudf::last_day_of_month(cudf::column_view const&, rmm::mr::device_memory_resource *) + * + * @param stream CUDA stream used for device memory operations and kernel launches. + */ +std::unique_ptr last_day_of_month( + cudf::column_view const& column, + rmm::cuda_stream_view stream = rmm::cuda_stream_default, + rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); + +/** + * @copydoc cudf::day_of_year(cudf::column_view const&, rmm::mr::device_memory_resource *) + * + * @param stream CUDA stream used for device memory operations and kernel launches. + */ +std::unique_ptr day_of_year( + cudf::column_view const& column, + rmm::cuda_stream_view stream = rmm::cuda_stream_default, + rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); + +/** + * @copydoc cudf::add_calendrical_months(cudf::column_view const&, cudf::column_view const&, + * rmm::mr::device_memory_resource *) + * + * @param stream CUDA stream used for device memory operations and kernel launches. + */ +std::unique_ptr add_calendrical_months( + cudf::column_view const& timestamps, + cudf::column_view const& months, + rmm::cuda_stream_view stream = rmm::cuda_stream_default, + rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); +} // namespace detail +} // namespace datetime +} // namespace cudf diff --git a/cpp/src/datetime/datetime_ops.cu b/cpp/src/datetime/datetime_ops.cu index cf889810b0f..fc572a43769 100644 --- a/cpp/src/datetime/datetime_ops.cu +++ b/cpp/src/datetime/datetime_ops.cu @@ -278,82 +278,144 @@ std::unique_ptr add_calendrical_months(column_view const& timestamp_colu return output; } -} // namespace detail -std::unique_ptr extract_year(column_view const& column, rmm::mr::device_memory_resource* mr) +std::unique_ptr extract_year(column_view const& column, + rmm::cuda_stream_view stream, + rmm::mr::device_memory_resource* mr) { - CUDF_FUNC_RANGE(); return detail::apply_datetime_op< detail::extract_component_operator, - cudf::type_id::INT16>(column, 0, mr); + cudf::type_id::INT16>(column, stream, mr); } std::unique_ptr extract_month(column_view const& column, + rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr) { - CUDF_FUNC_RANGE(); - return detail::apply_datetime_op< detail::extract_component_operator, - cudf::type_id::INT16>(column, 0, mr); + cudf::type_id::INT16>(column, stream, mr); } -std::unique_ptr extract_day(column_view const& column, rmm::mr::device_memory_resource* mr) +std::unique_ptr extract_day(column_view const& column, + rmm::cuda_stream_view stream, + rmm::mr::device_memory_resource* mr) { - CUDF_FUNC_RANGE(); return detail::apply_datetime_op< detail::extract_component_operator, - cudf::type_id::INT16>(column, 0, mr); + cudf::type_id::INT16>(column, stream, mr); } std::unique_ptr extract_weekday(column_view const& column, + rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr) { - CUDF_FUNC_RANGE(); return detail::apply_datetime_op< detail::extract_component_operator, - cudf::type_id::INT16>(column, 0, mr); + cudf::type_id::INT16>(column, stream, mr); } -std::unique_ptr extract_hour(column_view const& column, rmm::mr::device_memory_resource* mr) +std::unique_ptr extract_hour(column_view const& column, + rmm::cuda_stream_view stream, + rmm::mr::device_memory_resource* mr) { - CUDF_FUNC_RANGE(); return detail::apply_datetime_op< detail::extract_component_operator, - cudf::type_id::INT16>(column, 0, mr); + cudf::type_id::INT16>(column, stream, mr); } std::unique_ptr extract_minute(column_view const& column, + rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr) { - CUDF_FUNC_RANGE(); return detail::apply_datetime_op< detail::extract_component_operator, - cudf::type_id::INT16>(column, 0, mr); + cudf::type_id::INT16>(column, stream, mr); } std::unique_ptr extract_second(column_view const& column, + rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr) { - CUDF_FUNC_RANGE(); return detail::apply_datetime_op< detail::extract_component_operator, - cudf::type_id::INT16>(column, 0, mr); + cudf::type_id::INT16>(column, stream, mr); } std::unique_ptr last_day_of_month(column_view const& column, + rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr) { - CUDF_FUNC_RANGE(); return detail::apply_datetime_op(column, 0, mr); + cudf::type_id::TIMESTAMP_DAYS>(column, stream, mr); +} + +std::unique_ptr day_of_year(column_view const& column, + rmm::cuda_stream_view stream, + rmm::mr::device_memory_resource* mr) +{ + return detail::apply_datetime_op( + column, stream, mr); +} +} // namespace detail + +std::unique_ptr extract_year(column_view const& column, rmm::mr::device_memory_resource* mr) +{ + CUDF_FUNC_RANGE(); + return detail::extract_year(column, 0, mr); +} + +std::unique_ptr extract_month(column_view const& column, + rmm::mr::device_memory_resource* mr) +{ + CUDF_FUNC_RANGE(); + return detail::extract_month(column, 0, mr); +} + +std::unique_ptr extract_day(column_view const& column, rmm::mr::device_memory_resource* mr) +{ + CUDF_FUNC_RANGE(); + return detail::extract_day(column, 0, mr); +} + +std::unique_ptr extract_weekday(column_view const& column, + rmm::mr::device_memory_resource* mr) +{ + CUDF_FUNC_RANGE(); + return detail::extract_weekday(column, 0, mr); +} + +std::unique_ptr extract_hour(column_view const& column, rmm::mr::device_memory_resource* mr) +{ + CUDF_FUNC_RANGE(); + return detail::extract_hour(column, 0, mr); +} + +std::unique_ptr extract_minute(column_view const& column, + rmm::mr::device_memory_resource* mr) +{ + CUDF_FUNC_RANGE(); + return detail::extract_minute(column, 0, mr); +} + +std::unique_ptr extract_second(column_view const& column, + rmm::mr::device_memory_resource* mr) +{ + CUDF_FUNC_RANGE(); + return detail::extract_second(column, 0, mr); +} + +std::unique_ptr last_day_of_month(column_view const& column, + rmm::mr::device_memory_resource* mr) +{ + CUDF_FUNC_RANGE(); + return detail::last_day_of_month(column, 0, mr); } std::unique_ptr day_of_year(column_view const& column, rmm::mr::device_memory_resource* mr) { CUDF_FUNC_RANGE(); - return detail::apply_datetime_op( - column, 0, mr); + return detail::day_of_year(column, 0, mr); } std::unique_ptr add_calendrical_months(cudf::column_view const& timestamp_column, From aed0c46e63a0799f38d2438251148c9195d67dc7 Mon Sep 17 00:00:00 2001 From: Wonchan Lee Date: Tue, 23 Feb 2021 15:58:54 -0800 Subject: [PATCH 2/4] Add the new header to meta.yaml --- conda/recipes/libcudf/meta.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/conda/recipes/libcudf/meta.yaml b/conda/recipes/libcudf/meta.yaml index 63e4ac889c7..885a22870bb 100644 --- a/conda/recipes/libcudf/meta.yaml +++ b/conda/recipes/libcudf/meta.yaml @@ -69,6 +69,7 @@ test: - test -f $PREFIX/include/cudf/detail/binaryop.hpp - test -f $PREFIX/include/cudf/detail/concatenate.hpp - test -f $PREFIX/include/cudf/detail/copy.hpp + - test -f $PREFIX/include/cudf/detail/datetime.hpp - test -f $PREFIX/include/cudf/detail/fill.hpp - test -f $PREFIX/include/cudf/detail/gather.hpp - test -f $PREFIX/include/cudf/detail/groupby.hpp From 2d6619cabf932c6cc0dc328a5711e87596b8ac52 Mon Sep 17 00:00:00 2001 From: Wonchan Lee Date: Wed, 24 Feb 2021 11:12:07 -0800 Subject: [PATCH 3/4] Implementing suggestions from the code review --- cpp/include/cudf/detail/datetime.hpp | 2 +- cpp/src/datetime/datetime_ops.cu | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/cpp/include/cudf/detail/datetime.hpp b/cpp/include/cudf/detail/datetime.hpp index 684f33e609b..017fe0d96ff 100644 --- a/cpp/include/cudf/detail/datetime.hpp +++ b/cpp/include/cudf/detail/datetime.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2021, NVIDIA CORPORATION. + * 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. diff --git a/cpp/src/datetime/datetime_ops.cu b/cpp/src/datetime/datetime_ops.cu index fc572a43769..446d3f679d8 100644 --- a/cpp/src/datetime/datetime_ops.cu +++ b/cpp/src/datetime/datetime_ops.cu @@ -362,60 +362,60 @@ std::unique_ptr day_of_year(column_view const& column, std::unique_ptr extract_year(column_view const& column, rmm::mr::device_memory_resource* mr) { CUDF_FUNC_RANGE(); - return detail::extract_year(column, 0, mr); + return detail::extract_year(column, rmm::cuda_stream_default, mr); } std::unique_ptr extract_month(column_view const& column, rmm::mr::device_memory_resource* mr) { CUDF_FUNC_RANGE(); - return detail::extract_month(column, 0, mr); + return detail::extract_month(column, rmm::cuda_stream_default, mr); } std::unique_ptr extract_day(column_view const& column, rmm::mr::device_memory_resource* mr) { CUDF_FUNC_RANGE(); - return detail::extract_day(column, 0, mr); + return detail::extract_day(column, rmm::cuda_stream_default, mr); } std::unique_ptr extract_weekday(column_view const& column, rmm::mr::device_memory_resource* mr) { CUDF_FUNC_RANGE(); - return detail::extract_weekday(column, 0, mr); + return detail::extract_weekday(column, rmm::cuda_stream_default, mr); } std::unique_ptr extract_hour(column_view const& column, rmm::mr::device_memory_resource* mr) { CUDF_FUNC_RANGE(); - return detail::extract_hour(column, 0, mr); + return detail::extract_hour(column, rmm::cuda_stream_default, mr); } std::unique_ptr extract_minute(column_view const& column, rmm::mr::device_memory_resource* mr) { CUDF_FUNC_RANGE(); - return detail::extract_minute(column, 0, mr); + return detail::extract_minute(column, rmm::cuda_stream_default, mr); } std::unique_ptr extract_second(column_view const& column, rmm::mr::device_memory_resource* mr) { CUDF_FUNC_RANGE(); - return detail::extract_second(column, 0, mr); + return detail::extract_second(column, rmm::cuda_stream_default, mr); } std::unique_ptr last_day_of_month(column_view const& column, rmm::mr::device_memory_resource* mr) { CUDF_FUNC_RANGE(); - return detail::last_day_of_month(column, 0, mr); + return detail::last_day_of_month(column, rmm::cuda_stream_default, mr); } std::unique_ptr day_of_year(column_view const& column, rmm::mr::device_memory_resource* mr) { CUDF_FUNC_RANGE(); - return detail::day_of_year(column, 0, mr); + return detail::day_of_year(column, rmm::cuda_stream_default, mr); } std::unique_ptr add_calendrical_months(cudf::column_view const& timestamp_column, @@ -423,7 +423,8 @@ std::unique_ptr add_calendrical_months(cudf::column_view const& ti rmm::mr::device_memory_resource* mr) { CUDF_FUNC_RANGE(); - return detail::add_calendrical_months(timestamp_column, months_column, 0, mr); + return detail::add_calendrical_months( + timestamp_column, months_column, rmm::cuda_stream_default, mr); } } // namespace datetime } // namespace cudf From 0428516e490893a27e04f9a8a67795c3963bc93c Mon Sep 17 00:00:00 2001 From: Wonchan Lee Date: Thu, 25 Feb 2021 10:40:07 -0800 Subject: [PATCH 4/4] Add a copyright year --- cpp/src/datetime/datetime_ops.cu | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/src/datetime/datetime_ops.cu b/cpp/src/datetime/datetime_ops.cu index 446d3f679d8..36c3605951e 100644 --- a/cpp/src/datetime/datetime_ops.cu +++ b/cpp/src/datetime/datetime_ops.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, NVIDIA CORPORATION. + * Copyright (c) 2020-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.