Skip to content

Commit

Permalink
Use [[nodiscard]] attribute before __device__ (#17608)
Browse files Browse the repository at this point in the history
Clang-tidy does not like `[[nodiscard]]` after `__device__` and I don't like red squigly lines.

Authors:
  - Vukasin Milovanovic (https://github.com/vuule)

Approvers:
  - Yunsong Wang (https://github.com/PointKernel)
  - David Wendt (https://github.com/davidwendt)

URL: #17608
  • Loading branch information
vuule authored Dec 17, 2024
1 parent 187053a commit becfacc
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
12 changes: 6 additions & 6 deletions cpp/include/cudf/column/column_device_view.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ class alignas(16) column_device_view : public detail::column_device_view_base {
* @return string_view instance representing this element at this index
*/
template <typename T, CUDF_ENABLE_IF(std::is_same_v<T, string_view>)>
__device__ [[nodiscard]] T element(size_type element_index) const noexcept
[[nodiscard]] __device__ T element(size_type element_index) const noexcept
{
size_type index = element_index + offset(); // account for this view's _offset
char const* d_strings = static_cast<char const*>(_data);
Expand Down Expand Up @@ -503,7 +503,7 @@ class alignas(16) column_device_view : public detail::column_device_view_base {
* @return dictionary32 instance representing this element at this index
*/
template <typename T, CUDF_ENABLE_IF(std::is_same_v<T, dictionary32>)>
__device__ [[nodiscard]] T element(size_type element_index) const noexcept
[[nodiscard]] __device__ T element(size_type element_index) const noexcept
{
size_type index = element_index + offset(); // account for this view's _offset
auto const indices = d_children[0];
Expand All @@ -521,7 +521,7 @@ class alignas(16) column_device_view : public detail::column_device_view_base {
* @return numeric::fixed_point representing the element at this index
*/
template <typename T, CUDF_ENABLE_IF(cudf::is_fixed_point<T>())>
__device__ [[nodiscard]] T element(size_type element_index) const noexcept
[[nodiscard]] __device__ T element(size_type element_index) const noexcept
{
using namespace numeric;
using rep = typename T::rep;
Expand Down Expand Up @@ -1034,7 +1034,7 @@ class alignas(16) mutable_column_device_view : public detail::column_device_view
* @return Reference to the element at the specified index
*/
template <typename T, CUDF_ENABLE_IF(is_rep_layout_compatible<T>())>
__device__ [[nodiscard]] T& element(size_type element_index) const noexcept
[[nodiscard]] __device__ T& element(size_type element_index) const noexcept
{
return data<T>()[element_index];
}
Expand Down Expand Up @@ -1427,13 +1427,13 @@ struct pair_rep_accessor {

private:
template <typename R, std::enable_if_t<std::is_same_v<R, rep_type>, void>* = nullptr>
__device__ [[nodiscard]] inline auto get_rep(cudf::size_type i) const
[[nodiscard]] __device__ inline auto get_rep(cudf::size_type i) const
{
return col.element<R>(i);
}

template <typename R, std::enable_if_t<not std::is_same_v<R, rep_type>, void>* = nullptr>
__device__ [[nodiscard]] inline auto get_rep(cudf::size_type i) const
[[nodiscard]] __device__ inline auto get_rep(cudf::size_type i) const
{
return col.element<R>(i).value();
}
Expand Down
22 changes: 11 additions & 11 deletions cpp/include/cudf/strings/string_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class string_view {
*
* @return The number of characters in this string
*/
__device__ [[nodiscard]] inline size_type length() const;
[[nodiscard]] __device__ inline size_type length() const;
/**
* @brief Return a pointer to the internal device array
*
Expand Down Expand Up @@ -119,13 +119,13 @@ class string_view {
*
* @return new iterator pointing to the beginning of this string
*/
__device__ [[nodiscard]] inline const_iterator begin() const;
[[nodiscard]] __device__ inline const_iterator begin() const;
/**
* @brief Return new iterator pointing past the end of this string
*
* @return new iterator pointing past the end of this string
*/
__device__ [[nodiscard]] inline const_iterator end() const;
[[nodiscard]] __device__ inline const_iterator end() const;

/**
* @brief Return single UTF-8 character at the given character position
Expand All @@ -140,7 +140,7 @@ class string_view {
* @param pos Character position
* @return Byte offset from data() for a given character position
*/
__device__ [[nodiscard]] inline size_type byte_offset(size_type pos) const;
[[nodiscard]] __device__ inline size_type byte_offset(size_type pos) const;

/**
* @brief Comparing target string with this string. Each character is compared
Expand All @@ -155,7 +155,7 @@ class string_view {
* not match is greater in the arg string, or all compared characters
* match but the arg string is longer.
*/
__device__ [[nodiscard]] inline int compare(string_view const& str) const;
[[nodiscard]] __device__ inline int compare(string_view const& str) const;
/**
* @brief Comparing target string with this string. Each character is compared
* as a UTF-8 code-point value.
Expand Down Expand Up @@ -225,7 +225,7 @@ class string_view {
* Specify -1 to indicate to the end of the string.
* @return npos if str is not found in this string.
*/
__device__ [[nodiscard]] inline size_type find(string_view const& str,
[[nodiscard]] __device__ inline size_type find(string_view const& str,
size_type pos = 0,
size_type count = -1) const;
/**
Expand Down Expand Up @@ -253,7 +253,7 @@ class string_view {
* Specify -1 to indicate to the end of the string.
* @return npos if arg string is not found in this string.
*/
__device__ [[nodiscard]] inline size_type find(char_utf8 character,
[[nodiscard]] __device__ inline size_type find(char_utf8 character,
size_type pos = 0,
size_type count = -1) const;
/**
Expand All @@ -266,7 +266,7 @@ class string_view {
* Specify -1 to indicate to the end of the string.
* @return npos if arg string is not found in this string.
*/
__device__ [[nodiscard]] inline size_type rfind(string_view const& str,
[[nodiscard]] __device__ inline size_type rfind(string_view const& str,
size_type pos = 0,
size_type count = -1) const;
/**
Expand Down Expand Up @@ -294,7 +294,7 @@ class string_view {
* Specify -1 to indicate to the end of the string.
* @return npos if arg string is not found in this string.
*/
__device__ [[nodiscard]] inline size_type rfind(char_utf8 character,
[[nodiscard]] __device__ inline size_type rfind(char_utf8 character,
size_type pos = 0,
size_type count = -1) const;

Expand All @@ -306,7 +306,7 @@ class string_view {
* @param length Number of characters from start to include in the sub-string.
* @return New instance pointing to a subset of the characters within this instance.
*/
__device__ [[nodiscard]] inline string_view substr(size_type start, size_type length) const;
[[nodiscard]] __device__ inline string_view substr(size_type start, size_type length) const;

/**
* @brief Return minimum value associated with the string type
Expand Down Expand Up @@ -386,7 +386,7 @@ class string_view {
* @param bytepos Byte position from start of _data.
* @return The character position for the specified byte.
*/
__device__ [[nodiscard]] inline size_type character_offset(size_type bytepos) const;
[[nodiscard]] __device__ inline size_type character_offset(size_type bytepos) const;

/**
* @brief Common internal implementation for string_view::find and string_view::rfind.
Expand Down
12 changes: 6 additions & 6 deletions cpp/src/strings/regex/regex.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class reprog_device {
* Specify -1 to match any virtual positions past the end of the string.
* @return If match found, returns character positions of the matches.
*/
__device__ [[nodiscard]] inline match_result find(int32_t const thread_idx,
[[nodiscard]] __device__ inline match_result find(int32_t const thread_idx,
string_view const d_str,
string_view::const_iterator begin,
cudf::size_type end = -1) const;
Expand All @@ -205,7 +205,7 @@ class reprog_device {
* @param group_id The specific group to return its matching position values.
* @return If valid, returns the character position of the matched group in the given string,
*/
__device__ [[nodiscard]] inline match_result extract(int32_t const thread_idx,
[[nodiscard]] __device__ inline match_result extract(int32_t const thread_idx,
string_view const d_str,
string_view::const_iterator begin,
cudf::size_type end,
Expand All @@ -225,17 +225,17 @@ class reprog_device {
/**
* @brief Returns the regex instruction object for a given id.
*/
__device__ [[nodiscard]] inline reinst get_inst(int32_t id) const;
[[nodiscard]] __device__ inline reinst get_inst(int32_t id) const;

/**
* @brief Returns the regex class object for a given id.
*/
__device__ [[nodiscard]] inline reclass_device get_class(int32_t id) const;
[[nodiscard]] __device__ inline reclass_device get_class(int32_t id) const;

/**
* @brief Executes the regex pattern on the given string.
*/
__device__ [[nodiscard]] inline match_result regexec(string_view const d_str,
[[nodiscard]] __device__ inline match_result regexec(string_view const d_str,
reljunk jnk,
string_view::const_iterator begin,
cudf::size_type end,
Expand All @@ -244,7 +244,7 @@ class reprog_device {
/**
* @brief Utility wrapper to setup state memory structures for calling regexec
*/
__device__ [[nodiscard]] inline match_result call_regexec(
[[nodiscard]] __device__ inline match_result call_regexec(
int32_t const thread_idx,
string_view const d_str,
string_view::const_iterator begin,
Expand Down
6 changes: 3 additions & 3 deletions cpp/src/strings/regex/regex.inl
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ struct alignas(8) relist {
return true;
}

__device__ [[nodiscard]] __forceinline__ restate get_state(int16_t idx) const
[[nodiscard]] __device__ __forceinline__ restate get_state(int16_t idx) const
{
return restate{ranges[idx * stride], inst_ids[idx * stride]};
}
__device__ [[nodiscard]] __forceinline__ int16_t get_size() const { return size; }
[[nodiscard]] __device__ __forceinline__ int16_t get_size() const { return size; }

private:
int16_t size{};
Expand All @@ -101,7 +101,7 @@ struct alignas(8) relist {
mask[pos >> 3] |= uc;
}

__device__ [[nodiscard]] __forceinline__ bool readMask(int32_t pos) const
[[nodiscard]] __device__ __forceinline__ bool readMask(int32_t pos) const
{
u_char const uc = mask[pos >> 3];
return static_cast<bool>((uc >> (pos & 7)) & 1);
Expand Down

0 comments on commit becfacc

Please sign in to comment.