Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
2 changes: 0 additions & 2 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ mark_as_advanced(CUDF_BUILD_STREAMS_TEST_UTIL)
option(CUDF_CLANG_TIDY "Enable clang-tidy during compilation" OFF)
option(CUDF_IWYU "Enable IWYU during compilation" OFF)
option(CUDF_CLANG_TIDY_AUTOFIX "Enable clang-tidy autofixes" OFF)

option(
CUDF_KVIKIO_REMOTE_IO
"Enable remote IO (e.g. AWS S3) support through KvikIO. If disabled, cudf-python will still be able to do remote IO through fsspec."
Expand All @@ -101,7 +100,6 @@ message(VERBOSE "CUDF: Statically link the CUDA runtime: ${CUDA_STATIC_RUNTIME}"
message(VERBOSE
"CUDF: Build with remote IO (e.g. AWS S3) support through KvikIO: ${CUDF_KVIKIO_REMOTE_IO}"
)

# Set a default build type if none was specified
rapids_cmake_build_type("Release")
set(CUDF_BUILD_TESTS ${BUILD_TESTS})
Expand Down
498 changes: 355 additions & 143 deletions cpp/include/cudf/fixed_point/fixed_point.hpp

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion cpp/include/cudf/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ enum class type_id : int32_t {
DECIMAL64, ///< Fixed-point type with int64_t
DECIMAL128, ///< Fixed-point type with __int128_t
STRUCT, ///< Struct elements
DECIMAL32_SAFE, ///< Fixed-point type with int32_t and sticky overflow tracking
DECIMAL64_SAFE, ///< Fixed-point type with int64_t and sticky overflow tracking
DECIMAL128_SAFE, ///< Fixed-point type with __int128_t and sticky overflow tracking
// `NUM_TYPE_IDS` must be last!
NUM_TYPE_IDS ///< Total number of type ids
};
Expand Down Expand Up @@ -310,7 +313,9 @@ class data_type {
*/
explicit data_type(type_id id, int32_t scale) : _id{id}, _fixed_point_scale{scale}
{
assert(id == type_id::DECIMAL32 || id == type_id::DECIMAL64 || id == type_id::DECIMAL128);
assert(id == type_id::DECIMAL32 || id == type_id::DECIMAL64 || id == type_id::DECIMAL128 ||
id == type_id::DECIMAL32_SAFE || id == type_id::DECIMAL64_SAFE ||
id == type_id::DECIMAL128_SAFE);
}

/**
Expand Down
14 changes: 13 additions & 1 deletion cpp/include/cudf/utilities/traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,21 @@ CUDF_HOST_DEVICE constexpr inline bool is_fixed_point()
return cuda::std::is_same_v<numeric::decimal32, T> ||
cuda::std::is_same_v<numeric::decimal64, T> ||
cuda::std::is_same_v<numeric::decimal128, T> ||
cuda::std::is_same_v<numeric::decimal32_safe, T> ||
cuda::std::is_same_v<numeric::decimal64_safe, T> ||
cuda::std::is_same_v<numeric::decimal128_safe, T> ||
cuda::std::is_same_v<numeric::fixed_point<int32_t, numeric::Radix::BASE_2>, T> ||
cuda::std::is_same_v<numeric::fixed_point<int64_t, numeric::Radix::BASE_2>, T> ||
cuda::std::is_same_v<numeric::fixed_point<__int128_t, numeric::Radix::BASE_2>, T>;
cuda::std::is_same_v<numeric::fixed_point<__int128_t, numeric::Radix::BASE_2>, T> ||
cuda::std::is_same_v<
numeric::fixed_point<int32_t, numeric::Radix::BASE_2, numeric::overflow_tracking::on>,
T> ||
cuda::std::is_same_v<
numeric::fixed_point<int64_t, numeric::Radix::BASE_2, numeric::overflow_tracking::on>,
T> ||
cuda::std::is_same_v<
numeric::fixed_point<__int128_t, numeric::Radix::BASE_2, numeric::overflow_tracking::on>,
T>;
}

/**
Expand Down
48 changes: 44 additions & 4 deletions cpp/include/cudf/utilities/type_dispatcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,12 @@ using id_to_type = typename id_to_type_impl<Id>::type;
// clang-format off
template <typename T>
using device_storage_type_t =
std::conditional_t<std::is_same_v<numeric::decimal32, T>, int32_t,
std::conditional_t<std::is_same_v<numeric::decimal64, T>, int64_t,
std::conditional_t<std::is_same_v<numeric::decimal128, T>, __int128_t, T>>>;
std::conditional_t<std::is_same_v<numeric::decimal32, T>, int32_t,
std::conditional_t<std::is_same_v<numeric::decimal64, T>, int64_t,
std::conditional_t<std::is_same_v<numeric::decimal128, T>, __int128_t,
std::conditional_t<std::is_same_v<numeric::decimal32_safe, T>, int32_t,
std::conditional_t<std::is_same_v<numeric::decimal64_safe, T>, int64_t,
std::conditional_t<std::is_same_v<numeric::decimal128_safe, T>, __int128_t, T>>>>>>;
// clang-format on

/**
Expand Down Expand Up @@ -176,6 +179,9 @@ CUDF_TYPE_MAPPING(cudf::list_view, type_id::LIST)
CUDF_TYPE_MAPPING(numeric::decimal32, type_id::DECIMAL32)
CUDF_TYPE_MAPPING(numeric::decimal64, type_id::DECIMAL64)
CUDF_TYPE_MAPPING(numeric::decimal128, type_id::DECIMAL128)
CUDF_TYPE_MAPPING(numeric::decimal32_safe, type_id::DECIMAL32_SAFE)
CUDF_TYPE_MAPPING(numeric::decimal64_safe, type_id::DECIMAL64_SAFE)
CUDF_TYPE_MAPPING(numeric::decimal128_safe, type_id::DECIMAL128_SAFE)
CUDF_TYPE_MAPPING(cudf::struct_view, type_id::STRUCT)

/**
Expand Down Expand Up @@ -206,7 +212,11 @@ constexpr bool type_id_matches_device_storage_type(type_id id)
{
return (id == type_id::DECIMAL32 && std::is_same_v<T, int32_t>) ||
(id == type_id::DECIMAL64 && std::is_same_v<T, int64_t>) ||
(id == type_id::DECIMAL128 && std::is_same_v<T, __int128_t>) || id == type_to_id<T>();
(id == type_id::DECIMAL128 && std::is_same_v<T, __int128_t>) ||
(id == type_id::DECIMAL32_SAFE && std::is_same_v<T, int32_t>) ||
(id == type_id::DECIMAL64_SAFE && std::is_same_v<T, int64_t>) ||
(id == type_id::DECIMAL128_SAFE && std::is_same_v<T, __int128_t>) ||
id == type_to_id<T>();
}

/**
Expand Down Expand Up @@ -285,6 +295,27 @@ struct type_to_scalar_type_impl<numeric::decimal128> {
using ScalarDeviceType = cudf::fixed_point_scalar_device_view<numeric::decimal128>;
};

// Scalar specializations for the overflow-tracking decimal aliases. The scalar
// storage shares the underlying integer representation; the wrapper only adds
// the sticky overflow bit at the value-type layer.
template <>
struct type_to_scalar_type_impl<numeric::decimal32_safe> {
using ScalarType = cudf::fixed_point_scalar<numeric::decimal32_safe>;
using ScalarDeviceType = cudf::fixed_point_scalar_device_view<numeric::decimal32_safe>;
};

template <>
struct type_to_scalar_type_impl<numeric::decimal64_safe> {
using ScalarType = cudf::fixed_point_scalar<numeric::decimal64_safe>;
using ScalarDeviceType = cudf::fixed_point_scalar_device_view<numeric::decimal64_safe>;
};

template <>
struct type_to_scalar_type_impl<numeric::decimal128_safe> {
using ScalarType = cudf::fixed_point_scalar<numeric::decimal128_safe>;
using ScalarDeviceType = cudf::fixed_point_scalar_device_view<numeric::decimal128_safe>;
};

template <> // TODO: this is a temporary solution for make_pair_iterator
struct type_to_scalar_type_impl<cudf::dictionary32> {
using ScalarType = cudf::numeric_scalar<int32_t>;
Expand Down Expand Up @@ -548,6 +579,15 @@ CUDF_HOST_DEVICE __forceinline__ constexpr decltype(auto) type_dispatcher(cudf::
case type_id::DECIMAL128:
return f.template operator()<typename IdTypeMap<type_id::DECIMAL128>::type>(
std::forward<Ts>(args)...);
case type_id::DECIMAL32_SAFE:
return f.template operator()<typename IdTypeMap<type_id::DECIMAL32_SAFE>::type>(
std::forward<Ts>(args)...);
case type_id::DECIMAL64_SAFE:
return f.template operator()<typename IdTypeMap<type_id::DECIMAL64_SAFE>::type>(
std::forward<Ts>(args)...);
case type_id::DECIMAL128_SAFE:
return f.template operator()<typename IdTypeMap<type_id::DECIMAL128_SAFE>::type>(
std::forward<Ts>(args)...);
case type_id::STRUCT:
return f.template operator()<typename IdTypeMap<type_id::STRUCT>::type>(
std::forward<Ts>(args)...);
Expand Down
3 changes: 3 additions & 0 deletions cpp/src/scalar/scalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ typename fixed_point_scalar<T>::rep_type const* fixed_point_scalar<T>::data() co
template class fixed_point_scalar<numeric::decimal32>;
template class fixed_point_scalar<numeric::decimal64>;
template class fixed_point_scalar<numeric::decimal128>;
template class fixed_point_scalar<numeric::decimal32_safe>;
template class fixed_point_scalar<numeric::decimal64_safe>;
template class fixed_point_scalar<numeric::decimal128_safe>;

namespace CUDF_HIDDEN detail {

Expand Down
1 change: 1 addition & 0 deletions cpp/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ ConfigureTest(CLAMP_TEST replace/clamp_test.cpp)
# ##################################################################################################
# * fixed_point tests -----------------------------------------------------------------------------
ConfigureTest(FIXED_POINT_TEST fixed_point/fixed_point_tests.cpp fixed_point/fixed_point_tests.cu)
ConfigureTest(FIXED_POINT_OVERFLOW_TEST fixed_point/fixed_point_overflow_tests.cpp)

# ##################################################################################################
# * unary tests -----------------------------------------------------------------------------------
Expand Down
Loading
Loading