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

Detail APIs for datetime functions #7430

Merged
merged 4 commits into from
Feb 25, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
1 change: 1 addition & 0 deletions conda/recipes/libcudf/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
129 changes: 129 additions & 0 deletions cpp/include/cudf/detail/datetime.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
* 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.
*/

#pragma once

#include <cudf/types.hpp>

#include <memory>

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<cudf::column> 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<cudf::column> 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<cudf::column> 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<cudf::column> 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<cudf::column> 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<cudf::column> 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<cudf::column> 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<cudf::column> 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<cudf::column> 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<cudf::column> 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
111 changes: 87 additions & 24 deletions cpp/src/datetime/datetime_ops.cu
Original file line number Diff line number Diff line change
Expand Up @@ -278,90 +278,153 @@ std::unique_ptr<column> add_calendrical_months(column_view const& timestamp_colu

return output;
}
} // namespace detail

std::unique_ptr<column> extract_year(column_view const& column, rmm::mr::device_memory_resource* mr)
std::unique_ptr<column> 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<detail::datetime_component::YEAR>,
cudf::type_id::INT16>(column, 0, mr);
cudf::type_id::INT16>(column, stream, mr);
}

std::unique_ptr<column> 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<detail::datetime_component::MONTH>,
cudf::type_id::INT16>(column, 0, mr);
cudf::type_id::INT16>(column, stream, mr);
}

std::unique_ptr<column> extract_day(column_view const& column, rmm::mr::device_memory_resource* mr)
std::unique_ptr<column> 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<detail::datetime_component::DAY>,
cudf::type_id::INT16>(column, 0, mr);
cudf::type_id::INT16>(column, stream, mr);
}

std::unique_ptr<column> 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<detail::datetime_component::WEEKDAY>,
cudf::type_id::INT16>(column, 0, mr);
cudf::type_id::INT16>(column, stream, mr);
}

std::unique_ptr<column> extract_hour(column_view const& column, rmm::mr::device_memory_resource* mr)
std::unique_ptr<column> 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<detail::datetime_component::HOUR>,
cudf::type_id::INT16>(column, 0, mr);
cudf::type_id::INT16>(column, stream, mr);
}

std::unique_ptr<column> 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<detail::datetime_component::MINUTE>,
cudf::type_id::INT16>(column, 0, mr);
cudf::type_id::INT16>(column, stream, mr);
}

std::unique_ptr<column> 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<detail::datetime_component::SECOND>,
cudf::type_id::INT16>(column, 0, mr);
cudf::type_id::INT16>(column, stream, mr);
}

std::unique_ptr<column> 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<detail::extract_last_day_of_month,
cudf::type_id::TIMESTAMP_DAYS>(column, 0, mr);
cudf::type_id::TIMESTAMP_DAYS>(column, stream, mr);
}

std::unique_ptr<column> day_of_year(column_view const& column,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr)
{
return detail::apply_datetime_op<detail::extract_day_num_of_year, cudf::type_id::INT16>(
column, stream, mr);
}
} // namespace detail

std::unique_ptr<column> extract_year(column_view const& column, rmm::mr::device_memory_resource* mr)
{
CUDF_FUNC_RANGE();
return detail::extract_year(column, rmm::cuda_stream_default, mr);
}

std::unique_ptr<column> extract_month(column_view const& column,
rmm::mr::device_memory_resource* mr)
{
CUDF_FUNC_RANGE();
return detail::extract_month(column, rmm::cuda_stream_default, mr);
}

std::unique_ptr<column> extract_day(column_view const& column, rmm::mr::device_memory_resource* mr)
{
CUDF_FUNC_RANGE();
return detail::extract_day(column, rmm::cuda_stream_default, mr);
}

std::unique_ptr<column> extract_weekday(column_view const& column,
rmm::mr::device_memory_resource* mr)
{
CUDF_FUNC_RANGE();
return detail::extract_weekday(column, rmm::cuda_stream_default, mr);
}

std::unique_ptr<column> extract_hour(column_view const& column, rmm::mr::device_memory_resource* mr)
{
CUDF_FUNC_RANGE();
return detail::extract_hour(column, rmm::cuda_stream_default, mr);
}

std::unique_ptr<column> extract_minute(column_view const& column,
rmm::mr::device_memory_resource* mr)
{
CUDF_FUNC_RANGE();
return detail::extract_minute(column, rmm::cuda_stream_default, mr);
}

std::unique_ptr<column> extract_second(column_view const& column,
rmm::mr::device_memory_resource* mr)
{
CUDF_FUNC_RANGE();
return detail::extract_second(column, rmm::cuda_stream_default, mr);
}

std::unique_ptr<column> last_day_of_month(column_view const& column,
rmm::mr::device_memory_resource* mr)
{
CUDF_FUNC_RANGE();
return detail::last_day_of_month(column, rmm::cuda_stream_default, mr);
}

std::unique_ptr<column> day_of_year(column_view const& column, rmm::mr::device_memory_resource* mr)
{
CUDF_FUNC_RANGE();
return detail::apply_datetime_op<detail::extract_day_num_of_year, cudf::type_id::INT16>(
column, 0, mr);
return detail::day_of_year(column, rmm::cuda_stream_default, mr);
}

std::unique_ptr<cudf::column> add_calendrical_months(cudf::column_view const& timestamp_column,
cudf::column_view const& months_column,
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