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

Fix read out of bounds in string concatenate #13838

Merged
merged 4 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions cpp/src/strings/copying/concatenate.cu
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ __global__ void fused_concatenate_string_offset_kernel(column_device_view const*
bitmask_type* output_mask,
size_type* out_valid_count)
{
size_type output_index = threadIdx.x + blockIdx.x * blockDim.x;
int64_t output_index = threadIdx.x + blockIdx.x * blockDim.x;
Copy link
Contributor

@GregoryKimball GregoryKimball Aug 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you please use the cudf::thread_index_type alias? Thank you again for diagnosing this issue.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @GregoryKimball , addressed that.

size_type warp_valid_count = 0;

unsigned active_mask;
Expand Down Expand Up @@ -175,7 +175,7 @@ __global__ void fused_concatenate_string_chars_kernel(column_device_view const*
size_type const output_size,
char* output_data)
{
size_type output_index = threadIdx.x + blockIdx.x * blockDim.x;
int64_t output_index = threadIdx.x + blockIdx.x * blockDim.x;

while (output_index < output_size) {
// Lookup input index by searching for output index in offsets
Expand Down
31 changes: 31 additions & 0 deletions cpp/tests/copying/concatenate_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,37 @@ TEST_F(StringColumnTest, ConcatenateColumnView)
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*results, expected);
}

TEST_F(StringColumnTest, ConcatenateColumnViewLarge)
{
// Test large concatenate, causes out of bound device memory errors if kernel
// indexing is not int64_t.
// 1.5GB bytes, 5k columns
constexpr size_t num_strings = 10000;
constexpr size_t string_length = 150000;
constexpr size_t strings_per_column = 2;
constexpr size_t num_columns = num_strings / strings_per_column;

std::vector<std::string> strings;
std::vector<char const*> h_strings;
std::vector<cudf::test::strings_column_wrapper> strings_column_wrappers;
std::vector<cudf::column_view> strings_columns;

std::string s(string_length, 'a');
for (size_t i = 0; i < num_strings; ++i)
h_strings.push_back(s.data());

for (size_t i = 0; i < num_columns; ++i)
strings_column_wrappers.push_back(cudf::test::strings_column_wrapper(
h_strings.data() + i * strings_per_column, h_strings.data() + (i + 1) * strings_per_column));
for (auto& wrapper : strings_column_wrappers)
strings_columns.push_back(wrapper);

auto results = cudf::concatenate(strings_columns);

cudf::test::strings_column_wrapper expected(h_strings.begin(), h_strings.end());
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*results, expected);
}

TEST_F(StringColumnTest, ConcatenateTooManyColumns)
{
std::vector<char const*> h_strings{"aaa",
Expand Down