-
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
Add support for org.apache.spark.sql.catalyst.expressions.Bin
#2760
Merged
ustcfy
merged 8 commits into
NVIDIA:branch-25.02
from
ustcfy:feature/add-bin-expression-support
Jan 20, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
13874a5
Add support for Bin
ustcfy 9c59f74
Update license
ustcfy 51a0d87
Address some comments
ustcfy d6d5d4c
Add java tests
ustcfy 6fb3589
Update copyright years
ustcfy a7da182
Remove template variable LongType
ustcfy 72b58fd
Reduce warp divergence
ustcfy 4ca9fd4
Fix arithmetic right shift bug
ustcfy 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Copyright (c) 2025, 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 <cudf/column/column_device_view.cuh> | ||
#include <cudf/column/column_factories.hpp> | ||
#include <cudf/detail/null_mask.hpp> | ||
#include <cudf/detail/nvtx/ranges.hpp> | ||
#include <cudf/strings/detail/strings_children.cuh> | ||
#include <cudf/utilities/default_stream.hpp> | ||
|
||
#include <rmm/cuda_stream_view.hpp> | ||
#include <rmm/exec_policy.hpp> | ||
|
||
namespace spark_rapids_jni { | ||
|
||
namespace detail { | ||
namespace { | ||
struct long_to_binary_string_fn { | ||
cudf::column_device_view d_longs; | ||
cudf::size_type* d_sizes; | ||
char* d_chars; | ||
cudf::detail::input_offsetalator d_offsets; | ||
|
||
__device__ void long_to_binary_string(cudf::size_type idx) | ||
{ | ||
auto const value = d_longs.element<int64_t>(idx); | ||
char* d_buffer = d_chars + d_offsets[idx]; | ||
for (auto i = d_sizes[idx] - 1; i >= 0; --i) { | ||
*d_buffer++ = '0' + ((value & (1UL << i)) >> i); | ||
} | ||
} | ||
|
||
__device__ void operator()(cudf::size_type idx) | ||
{ | ||
if (d_longs.is_null(idx)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: Just some nice-to-have improvement, use |
||
if (d_chars == nullptr) { d_sizes[idx] = 0; } | ||
return; | ||
} | ||
if (d_chars != nullptr) { | ||
long_to_binary_string(idx); | ||
} else { | ||
// If the value is 0, the size should be 1 | ||
d_sizes[idx] = max(1, 64 - __clzll(d_longs.element<int64_t>(idx))); | ||
} | ||
} | ||
}; | ||
|
||
} // namespace | ||
|
||
std::unique_ptr<cudf::column> long_to_binary_string(cudf::column_view const& input, | ||
rmm::cuda_stream_view stream, | ||
rmm::device_async_resource_ref mr) | ||
{ | ||
if (input.is_empty()) return cudf::make_empty_column(cudf::type_id::STRING); | ||
|
||
CUDF_EXPECTS(input.type().id() == cudf::type_id::INT64, "Input column must be long type"); | ||
|
||
auto const d_column = cudf::column_device_view::create(input, stream); | ||
|
||
auto [offsets, chars] = cudf::strings::detail::make_strings_children( | ||
long_to_binary_string_fn{*d_column}, input.size(), stream, mr); | ||
|
||
return cudf::make_strings_column(input.size(), | ||
std::move(offsets), | ||
chars.release(), | ||
input.null_count(), | ||
cudf::detail::copy_bitmask(input, stream, mr)); | ||
} | ||
|
||
} // namespace detail | ||
|
||
// external API | ||
std::unique_ptr<cudf::column> long_to_binary_string(cudf::column_view const& input, | ||
rmm::cuda_stream_view stream, | ||
rmm::device_async_resource_ref mr) | ||
{ | ||
CUDF_FUNC_RANGE(); | ||
ustcfy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return detail::long_to_binary_string(input, stream, mr); | ||
} | ||
|
||
} // namespace spark_rapids_jni |
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,48 @@ | ||
/* | ||
* Copyright (c) 2025, 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_test/base_fixture.hpp> | ||
#include <cudf_test/column_wrapper.hpp> | ||
|
||
#include <rmm/device_uvector.hpp> | ||
|
||
#include <cast_string.hpp> | ||
|
||
#include <limits> | ||
|
||
using namespace cudf; | ||
|
||
constexpr cudf::test::debug_output_level verbosity{cudf::test::debug_output_level::FIRST_ERROR}; | ||
|
||
struct LongToBinaryStringTests : public cudf::test::BaseFixture {}; | ||
|
||
TEST_F(LongToBinaryStringTests, FromLongToBinary) | ||
{ | ||
auto const longs = cudf::test::fixed_width_column_wrapper<int64_t>{ | ||
0L, 1L, 10L, -1L, std::numeric_limits<int64_t>::max(), std::numeric_limits<int64_t>::min()}; | ||
|
||
auto results = spark_rapids_jni::long_to_binary_string(longs, cudf::get_default_stream()); | ||
|
||
auto const expected = cudf::test::strings_column_wrapper{ | ||
"0", | ||
"1", | ||
"1010", | ||
"1111111111111111111111111111111111111111111111111111111111111111", | ||
"111111111111111111111111111111111111111111111111111111111111111", | ||
"1000000000000000000000000000000000000000000000000000000000000000"}; | ||
|
||
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*results, expected, verbosity); | ||
} |
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
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.
Useless include (not sure)?