Skip to content

Commit

Permalink
Improve scalar string replace performance for long strings (#7415)
Browse files Browse the repository at this point in the history
Fixes #7370.

This adds a scalar string replace algorithm with character-level parallelism which significantly improves the performance of scalar string replacement on longer strings.  It can involve many more kernel launches than the row-based algorithm and does not always outperform on short strings.  Therefore a heuristic based on the average character length of valid string rows is used to automatically select which algorithm to use.

Authors:
  - Jason Lowe (@jlowe)

Approvers:
  - David (@davidwendt)
  - Karthikeyan (@karthikeyann)

URL: #7415
  • Loading branch information
jlowe authored Mar 1, 2021
1 parent a4c1dba commit 3135f1b
Show file tree
Hide file tree
Showing 3 changed files with 724 additions and 78 deletions.
13 changes: 12 additions & 1 deletion cpp/include/cudf/strings/detail/replace.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, NVIDIA CORPORATION.
* Copyright (c) 2020-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.
Expand All @@ -25,12 +25,23 @@ namespace cudf {
namespace strings {
namespace detail {

/**
* @brief The type of algorithm to use for a replace operation.
*/
enum class replace_algorithm {
AUTO, ///< Automatically choose the algorithm based on heuristics
ROW_PARALLEL, ///< Row-level parallelism
CHAR_PARALLEL ///< Character-level parallelism
};

/**
* @copydoc cudf::strings::replace(strings_column_view const&, string_scalar const&,
* string_scalar const&, int32_t, rmm::mr::device_memory_resource*)
*
* @tparam alg Replacement algorithm to use
* @param[in] stream CUDA stream used for device memory operations and kernel launches.
*/
template <replace_algorithm alg = replace_algorithm::AUTO>
std::unique_ptr<column> replace(
strings_column_view const& strings,
string_scalar const& target,
Expand Down
Loading

0 comments on commit 3135f1b

Please sign in to comment.