-
Notifications
You must be signed in to change notification settings - Fork 68
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
Adding format_float kernel #1572
Merged
Merged
Changes from 64 commits
Commits
Show all changes
73 commits
Select commit
Hold shift + click to select a range
0e7485c
wip
thirtiseven 2c04fff
wip
thirtiseven 6883988
Merge branch 'NVIDIA:branch-23.12' into float_to_string
thirtiseven cbce724
Add float to string kernel
thirtiseven 8d7ead2
Update src/main/cpp/src/cast_float_to_string.cu
thirtiseven 9ab2089
Update src/main/cpp/src/cast_float_to_string.cu
thirtiseven c3b3d64
address comments and use different precision for float
thirtiseven ebb1238
a runnable format_number demo
thirtiseven 007cf5e
rewrite the solution with ryu
thirtiseven 1264317
update license
thirtiseven a87a403
clean up
thirtiseven 267a421
wip
thirtiseven 979dc39
Split ftos_converter out
thirtiseven 4c75bc7
clean up
thirtiseven 744d0df
Merge branch 'float_to_string' of https://github.com/thirtiseven/spar…
thirtiseven f1c11e6
resolve cudf conflicts
thirtiseven 760799b
resolve cudf conflicts
thirtiseven bfba655
resolve cudf conflicts
thirtiseven ad27fee
resolve cudf conflicts
thirtiseven 77841d9
Merge branch 'float_to_string' of https://github.com/thirtiseven/spar…
thirtiseven 6728170
Merge branch 'thirtiseven-float_to_string' into float_to_string
thirtiseven 40a4cb8
remove cudf changes
thirtiseven 05f5517
remove cudf changes
thirtiseven 07c961e
Merge branch 'NVIDIA:branch-23.12' into float_to_string
thirtiseven 8ed59bd
add ryu
thirtiseven e3a983d
Merge branch 'float_to_string' into format_float
thirtiseven da2197b
Add copyright and notice
thirtiseven 48a5d7a
Merge branch 'float_to_string' of https://github.com/thirtiseven/spar…
thirtiseven 2c6cdcb
Fix copyrights and license
thirtiseven 3228755
cudf conflict resolve
thirtiseven d79dd44
Merge branch 'float_to_string' into format_float
thirtiseven d7be0d7
Add format_float kernel
thirtiseven 5397f12
clean up
thirtiseven 8aeeb6b
Fixed two bugs
thirtiseven a6578c7
Added a failed case back
thirtiseven 9b7fb4a
Refactor
thirtiseven 41967d9
Handle d=0 case
thirtiseven dc570cb
Add nv apache license to ftos_converter
thirtiseven 96333ca
Add nv apache license to ftos_converter
thirtiseven c36ce94
Fix an rounding bug
thirtiseven 360a77b
Update src/main/cpp/src/ftos_converter.cu
thirtiseven ced33b6
address some comments
thirtiseven 0b0a473
Merge remote-tracking branch 'upstream/branch-24.02' into format_float
thirtiseven 08f73ac
Merge branch 'float_to_string' into format_float
thirtiseven 199e1db
Merge remote-tracking branch 'upstream/branch-24.02' into float_to_st…
thirtiseven 131e48c
cudf conflict
thirtiseven 3c09c49
Update src/main/cpp/src/cast_float_to_string.cu
thirtiseven 346c1f7
Make it runable again
thirtiseven 98918ce
address some comments
thirtiseven b78e3b3
addressed comments
thirtiseven d2cba4f
Address comments
thirtiseven 62aa3ba
Merge branch 'NVIDIA:branch-24.02' into float_to_string
thirtiseven 04d1c4f
clang format
thirtiseven 388cb50
Address comments
thirtiseven 54fa73c
Address comments
thirtiseven 1f49d5a
Merge branch 'NVIDIA:branch-24.02' into format_float
thirtiseven 6f4dae8
Merge branch 'float_to_string' into format_float
thirtiseven c71cf9d
Merge branch 'format_float' of https://github.com/thirtiseven/spark-r…
thirtiseven a40c388
Merge branch 'format_float' of https://github.com/thirtiseven/spark-r…
thirtiseven ea2325b
Merge branch 'format_float' of https://github.com/thirtiseven/spark-r…
thirtiseven 3d19638
address comments
thirtiseven b9bccee
Merge branch 'branch-24.02' into format_float
thirtiseven 8d02a3f
fix build after upmerge
thirtiseven 62ff4f7
move inf/nan replacement to kernel
thirtiseven 10bfe09
Apply suggestions from code review
thirtiseven e264ba9
address comments
thirtiseven eab61eb
Apply suggestions from code review
thirtiseven 9892cae
address comments
thirtiseven 8bf5b1c
cudf
thirtiseven 81ba4a0
cudf
thirtiseven efb2736
format
thirtiseven 0505d71
cudf reset
thirtiseven 20415e7
Apply suggestions from code review
thirtiseven File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/* | ||
* Copyright (c) 2023, 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 "cast_string.hpp" | ||
#include "ftos_converter.cuh" | ||
|
||
#include <cudf/column/column_device_view.cuh> | ||
#include <cudf/detail/null_mask.hpp> | ||
#include <cudf/detail/nvtx/ranges.hpp> | ||
#include <cudf/strings/detail/strings_children.cuh> | ||
#include <cudf/utilities/type_dispatcher.hpp> | ||
|
||
#include <rmm/cuda_stream_view.hpp> | ||
#include <rmm/exec_policy.hpp> | ||
thirtiseven marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
namespace spark_rapids_jni { | ||
|
||
namespace detail { | ||
namespace { | ||
|
||
template <typename FloatType> | ||
struct format_float_fn { | ||
cudf::column_device_view d_floats; | ||
int const digits; | ||
hyperbolic2346 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
cudf::size_type* d_offsets; | ||
char* d_chars; | ||
|
||
__device__ cudf::size_type compute_output_size(FloatType value, int digits) const | ||
hyperbolic2346 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
bool constexpr is_float = std::is_same_v<FloatType, float>; | ||
return static_cast<cudf::size_type>( | ||
ftos_converter::compute_format_float_size(static_cast<double>(value), digits, is_float)); | ||
} | ||
|
||
__device__ void format_float(cudf::size_type idx, int digits) const | ||
{ | ||
auto const value = d_floats.element<FloatType>(idx); | ||
bool constexpr is_float = std::is_same_v<FloatType, float>; | ||
auto const output = d_chars + d_offsets[idx]; | ||
ftos_converter::format_float(static_cast<double>(value), digits, is_float, output); | ||
} | ||
|
||
__device__ void operator()(cudf::size_type idx) const | ||
thirtiseven marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
if (d_floats.is_null(idx)) { | ||
if (d_chars == nullptr) { d_offsets[idx] = 0; } | ||
return; | ||
} | ||
if (d_chars != nullptr) { | ||
format_float(idx, digits); | ||
} else { | ||
d_offsets[idx] = compute_output_size(d_floats.element<FloatType>(idx), digits); | ||
} | ||
} | ||
}; | ||
|
||
/** | ||
* @brief This dispatch method is for converting floats into strings. | ||
* | ||
* The template function declaration ensures only float types are allowed. | ||
*/ | ||
struct dispatch_format_float_fn { | ||
template <typename FloatType, CUDF_ENABLE_IF(std::is_floating_point_v<FloatType>)> | ||
std::unique_ptr<cudf::column> operator()(cudf::column_view const& floats, | ||
int digits, | ||
thirtiseven marked this conversation as resolved.
Show resolved
Hide resolved
|
||
rmm::cuda_stream_view stream, | ||
rmm::mr::device_memory_resource* mr) const | ||
{ | ||
auto const strings_count = floats.size(); | ||
if (strings_count == 0) { return cudf::make_empty_column(cudf::type_id::STRING); } | ||
|
||
auto const input_ptr = cudf::column_device_view::create(floats, stream); | ||
|
||
auto [offsets, chars] = cudf::strings::detail::make_strings_children( | ||
format_float_fn<FloatType>{*input_ptr, digits}, strings_count, stream, mr); | ||
|
||
return cudf::make_strings_column(strings_count, | ||
std::move(offsets), | ||
std::move(chars), | ||
floats.null_count(), | ||
cudf::detail::copy_bitmask(floats, stream, mr)); | ||
} | ||
|
||
// non-float types throw an exception | ||
template <typename T, CUDF_ENABLE_IF(not std::is_floating_point_v<T>)> | ||
std::unique_ptr<cudf::column> operator()(cudf::column_view const&, | ||
int, | ||
thirtiseven marked this conversation as resolved.
Show resolved
Hide resolved
|
||
rmm::cuda_stream_view, | ||
rmm::mr::device_memory_resource*) const | ||
{ | ||
CUDF_FAIL("Values for format_float function must be a float type."); | ||
} | ||
}; | ||
|
||
} // namespace | ||
|
||
// This will convert all float column types into a strings column. | ||
std::unique_ptr<cudf::column> format_float(cudf::column_view const& floats, | ||
int digits, | ||
thirtiseven marked this conversation as resolved.
Show resolved
Hide resolved
|
||
rmm::cuda_stream_view stream, | ||
rmm::mr::device_memory_resource* mr) | ||
{ | ||
return type_dispatcher(floats.type(), dispatch_format_float_fn{}, floats, digits, stream, mr); | ||
} | ||
|
||
} // namespace detail | ||
|
||
// external API | ||
std::unique_ptr<cudf::column> format_float(cudf::column_view const& floats, | ||
int digits, | ||
thirtiseven marked this conversation as resolved.
Show resolved
Hide resolved
|
||
rmm::cuda_stream_view stream, | ||
rmm::mr::device_memory_resource* mr) | ||
{ | ||
CUDF_FUNC_RANGE(); | ||
return detail::format_float(floats, digits, stream, mr); | ||
} | ||
|
||
} // namespace spark_rapids_jni |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove duplication.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, done. I didn't find those copyright issues when upmerging.