Skip to content

Commit b3dbe38

Browse files
[rocm-libraries] ROCm/rocm-libraries#1720 (commit 0098e5e)
[rocThrust] fix: HIP compiler rejects THRUST_NODISCARD after THRUST_DEPRECATED (#1720) ## Motivation - `THRUST_CPP_DIALECT` is used before being defined causing the code to use `__attribute__((...))` instead of `[[...]]` under c++ 17 standard, leading to the compiler throwing an error when putting `THRUST_DEPRECATED` in front of `THRUST_NODISCARD`. This will be fixed by this merge/pull request. - A separate issue is that rocm compiler (both on the host and device sides) rejects placing `[[nodiscard]]` in front of `__attribute__((deprecated))` for member functions and operators in classes. But this syntax is accepted for normal functions. Nvcc accepts this syntax in either case. In my opinion, this is not strictly a "bug", but an inconsistency. This can be reproduced on [godbolt](https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:cuda,selection:(endColumn:1,endLineNumber:6,positionColumn:1,positionLineNumber:6,selectionStartColumn:1,selectionStartLineNumber:6,startColumn:1,startLineNumber:6),source:'%0Astruct+test%7B%0A++++__attribute__((deprecated))+%5B%5Bnodiscard%5D%5D%0A++++int+oeprator()%7B+return+0%3B%7D%0A%7D%3B%0A'),l:'5',n:'0',o:'CUDA+C%2B%2B+source+%231',t:'0')),k:37.61119832548404,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:hipclang-rocm-60400,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1',verboseDemangling:'0'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:1,lang:cuda,libs:!(),options:'',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+clang+rocm-6.4.0+(Editor+%231)',t:'0')),header:(),k:31.010672395779828,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:output,i:(compilerName:'clang+rocm-6.4.0',editorid:1,fontScale:14,fontUsePx:'0',j:1,wrap:'1'),l:'5',n:'0',o:'Output+of+clang+rocm-6.4.0+(Compiler+%231)',t:'0')),k:31.378129278736132,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4) - `__host__` or `__device__` between 2 attribute is also not allowed by rocm compiler, but is allow by nvcc. see reproducer on [godbolt](https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:cuda,selection:(endColumn:1,endLineNumber:6,positionColumn:1,positionLineNumber:6,selectionStartColumn:1,selectionStartLineNumber:6,startColumn:1,startLineNumber:6),source:'%0Astruct+test%7B%0A+++++%5B%5Bnodiscard%5D%5D+__host__+%5B%5Bdeprecated%5D%5D%0A++++int+oeprator()%7B+return+0%3B%7D%0A%7D%3B%0A'),l:'5',n:'0',o:'CUDA+C%2B%2B+source+%231',t:'0')),k:28.20839874411303,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:hipclang-rocm-60400,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1',verboseDemangling:'0'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:1,lang:cuda,libs:!(),options:'',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+clang+rocm-6.4.0+(Editor+%231)',t:'0')),header:(),k:23.25800429683487,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:output,i:(compilerName:'clang+rocm-6.4.0',editorid:1,fontScale:14,fontUsePx:'0',j:1,wrap:'1'),l:'5',n:'0',o:'Output+of+clang+rocm-6.4.0+(Compiler+%231)',t:'0')),k:23.533596959052097,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:device,i:(compilerName:'NVCC+12.9.1',device:PTX,editorid:1,fontScale:14,fontUsePx:'0',j:1,selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),treeid:0),l:'5',n:'0',o:'Device+Viewer+clang+rocm-6.4.0+(Editor+%231,+Compiler+%231)',t:'0')),k:25,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4) ## Technical Details - Fix the include recursion in rocThrust `cpp_dialect.h` and `deprecated.h` - Change the order of `THRUST_NODISCARD` and `THRUST_DEPRECATED` for clarity and consistency with CCCL. ## Test Plan <!-- Explain any relevant testing done to verify this PR. --> ## Test Result <!-- Briefly summarize test outcomes. --> ## Submission Checklist - [x] Look over the contributing guidelines at https://github.com/ROCm/ROCm/blob/develop/CONTRIBUTING.md#pull-requests.
1 parent 9922784 commit b3dbe38

File tree

7 files changed

+43
-37
lines changed

7 files changed

+43
-37
lines changed

thrust/async/copy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ struct copy_fn final
115115
THRUST_FWD(output)))
116116

117117
template <typename... Args>
118-
THRUST_NODISCARD THRUST_DEPRECATED THRUST_HOST auto operator()(Args&&... args) const
118+
THRUST_DEPRECATED THRUST_NODISCARD THRUST_HOST auto operator()(Args&&... args) const
119119
THRUST_RETURNS(call(THRUST_FWD(args)...))
120120
};
121121

thrust/async/for_each.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ struct for_each_fn final
9292
THRUST_FWD(f)))
9393

9494
template <typename... Args>
95-
THRUST_NODISCARD THRUST_DEPRECATED THRUST_HOST auto operator()(Args&&... args) const
95+
THRUST_DEPRECATED THRUST_NODISCARD THRUST_HOST auto operator()(Args&&... args) const
9696
THRUST_RETURNS(call(THRUST_FWD(args)...))
9797
};
9898

thrust/async/reduce.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ struct reduce_fn final
162162
::internal::remove_cvref_t<typename iterator_traits<::internal::remove_cvref_t<ForwardIt>>::value_type>>{}))
163163

164164
template <typename... Args>
165-
THRUST_NODISCARD THRUST_DEPRECATED THRUST_HOST auto operator()(Args&&... args) const
165+
THRUST_DEPRECATED THRUST_NODISCARD THRUST_HOST auto operator()(Args&&... args) const
166166
THRUST_RETURNS(call(THRUST_FWD(args)...))
167167
};
168168

@@ -310,7 +310,7 @@ struct reduce_into_fn final
310310
thrust::is_execution_policy<::internal::remove_cvref_t<T1>>{}))
311311

312312
template <typename... Args>
313-
THRUST_NODISCARD THRUST_DEPRECATED THRUST_HOST auto operator()(Args&&... args) const
313+
THRUST_DEPRECATED THRUST_NODISCARD THRUST_HOST auto operator()(Args&&... args) const
314314
THRUST_RETURNS(call(THRUST_FWD(args)...))
315315
};
316316

thrust/async/sort.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,12 @@ THRUST_SUPPRESS_DEPRECATED_PUSH
144144
)
145145

146146
template <typename... Args>
147+
THRUST_DEPRECATED
147148
#if !(defined(__CUDA__) && THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_CLANG)
148149
// clang in CUDA mode can only handle one attribute
149150
THRUST_NODISCARD THRUST_HOST
150151
#endif
151-
THRUST_DEPRECATED auto operator()(Args&&... args) const
152+
auto operator()(Args&&... args) const
152153
THRUST_RETURNS(
153154
call(THRUST_FWD(args)...)
154155
)
@@ -267,11 +268,12 @@ struct sort_fn final
267268
)
268269

269270
template <typename... Args>
271+
THRUST_DEPRECATED
270272
#if !(defined(__CUDA__) && THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_CLANG)
271273
// clang in CUDA mode can only handle one attribute
272274
THRUST_NODISCARD THRUST_HOST
273275
#endif
274-
THRUST_DEPRECATED auto operator()(Args&&... args) const
276+
auto operator()(Args&&... args) const
275277
THRUST_RETURNS(
276278
call(THRUST_FWD(args)...)
277279
)

thrust/async/transform.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ struct transform_fn final
123123
)
124124

125125
template <typename... Args>
126-
THRUST_NODISCARD THRUST_DEPRECATED THRUST_HOST
126+
THRUST_DEPRECATED THRUST_NODISCARD THRUST_HOST
127127
auto operator()(Args&&... args) const
128128
THRUST_RETURNS(
129129
call(THRUST_FWD(args)...)

thrust/detail/config/cpp_dialect.h

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#endif // no system header
3131

3232
#include <thrust/detail/config/compiler.h> // IWYU pragma: export
33-
#include <thrust/detail/config/deprecated.h> // IWYU pragma: export
3433

3534
// Deprecation warnings may be silenced by defining the following macros. These
3635
// may be combined.
@@ -87,6 +86,38 @@
8786

8887
#endif // !THRUST_CPP_DIALECT
8988

89+
// Macros to suppress deprecation compiler warnings, from "deprecated.h"
90+
// TODO: These macros start with `LIBCUDACXX`. So, when libhipcxx is
91+
// available in this scope, we should remove these macros and use the ones
92+
// from libhipcxx.
93+
// Check for deprecation opt-outs
94+
#if defined(LIBCUDACXX_IGNORE_DEPRECATED_CPP_DIALECT) || defined(CCCL_IGNORE_DEPRECATED_CPP_DIALECT) \
95+
|| defined(CUB_IGNORE_DEPRECATED_CPP_DIALECT)
96+
# if !defined(THRUST_IGNORE_DEPRECATED_CPP_DIALECT)
97+
# define THRUST_IGNORE_DEPRECATED_CPP_DIALECT
98+
# endif
99+
#endif // suppress all dialect deprecation warnings
100+
#if defined(LIBCUDACXX_IGNORE_DEPRECATED_CPP_14) || defined(CCCL_IGNORE_DEPRECATED_CPP_14) \
101+
|| defined(CUB_IGNORE_DEPRECATED_CPP_14) || defined(THRUST_IGNORE_DEPRECATED_CPP_DIALECT)
102+
# if !defined(THRUST_IGNORE_DEPRECATED_CPP_14)
103+
# define THRUST_IGNORE_DEPRECATED_CPP_14
104+
# endif
105+
#endif // suppress all c++14 dialect deprecation warnings
106+
#if defined(LIBCUDACXX_IGNORE_DEPRECATED_CPP_11) || defined(CCCL_IGNORE_DEPRECATED_CPP_11) \
107+
|| defined(CUB_IGNORE_DEPRECATED_CPP_11) || defined(THRUST_IGNORE_DEPRECATED_CPP_DIALECT) \
108+
|| defined(THRUST_IGNORE_DEPRECATED_CPP_14)
109+
# if !defined(THRUST_IGNORE_DEPRECATED_CPP_11)
110+
# define THRUST_IGNORE_DEPRECATED_CPP_11
111+
# endif
112+
#endif // suppress all c++11 dialect deprecation warnings
113+
#if defined(LIBCUDACXX_IGNORE_DEPRECATED_COMPILER) || defined(CCCL_IGNORE_DEPRECATED_COMPILER) \
114+
|| defined(CUB_IGNORE_DEPRECATED_COMPILER) || defined(THRUST_IGNORE_DEPRECATED_CPP_DIALECT) \
115+
|| defined(THRUST_IGNORE_DEPRECATED_CPP_14) || defined(THRUST_IGNORE_DEPRECATED_CPP_11)
116+
# if !defined(THRUST_IGNORE_DEPRECATED_COMPILER)
117+
# define THRUST_IGNORE_DEPRECATED_COMPILER
118+
# endif
119+
#endif // suppress all compiler deprecation warnings
120+
90121
// Constexpr feature macros:
91122
#if THRUST_CPP_DIALECT >= 2023
92123
# define THRUST_CONSTEXPR_SINCE_CXX23 constexpr
@@ -149,7 +180,7 @@ THRUST_COMPILER_DEPRECATION_SOFT(C++ 17, C++ 11);
149180
#elif THRUST_CPP_DIALECT == 2014 && !defined(THRUST_IGNORE_DEPRECATED_CPP_14)
150181
// =C++14. Soft upgrade message:
151182
THRUST_COMPILER_DEPRECATION_SOFT(C++ 17, C++ 14);
152-
#endif // THRUST_CPP_DIALECT >= 2017
183+
#endif // THRUST_CPP_DIALECT < 2011
153184

154185
#undef THRUST_COMPILER_DEPRECATION_SOFT
155186
#undef THRUST_COMPILER_DEPRECATION

thrust/detail/config/deprecated.h

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#ifndef THRUST_DETAIL_CONFIG_DEPRECATED_H
1313
#define THRUST_DETAIL_CONFIG_DEPRECATED_H
1414

15-
#include <thrust/detail/config/compiler.h>
15+
#include <thrust/detail/config/cpp_dialect.h>
1616

1717
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
1818
# pragma GCC system_header
@@ -22,33 +22,6 @@
2222
# pragma system_header
2323
#endif // no system header
2424

25-
// Check for deprecation opt-outs
26-
#if defined(LIBCUDACXX_IGNORE_DEPRECATED_CPP_DIALECT) || defined(CCCL_IGNORE_DEPRECATED_CPP_DIALECT) \
27-
|| defined(CUB_IGNORE_DEPRECATED_CPP_DIALECT)
28-
# if !defined(THRUST_IGNORE_DEPRECATED_CPP_DIALECT)
29-
# define THRUST_IGNORE_DEPRECATED_CPP_DIALECT
30-
# endif
31-
#endif // suppress all dialect deprecation warnings
32-
#if defined(LIBCUDACXX_IGNORE_DEPRECATED_CPP_14) || defined(CCCL_IGNORE_DEPRECATED_CPP_14) \
33-
|| defined(CUB_IGNORE_DEPRECATED_CPP_14) || defined(THRUST_IGNORE_DEPRECATED_CPP_DIALECT)
34-
# if !defined(THRUST_IGNORE_DEPRECATED_CPP_14)
35-
# define THRUST_IGNORE_DEPRECATED_CPP_14
36-
# endif
37-
#endif // suppress all c++14 dialect deprecation warnings
38-
#if defined(LIBCUDACXX_IGNORE_DEPRECATED_CPP_11) || defined(CCCL_IGNORE_DEPRECATED_CPP_11) \
39-
|| defined(CUB_IGNORE_DEPRECATED_CPP_11) || defined(THRUST_IGNORE_DEPRECATED_CPP_DIALECT) \
40-
|| defined(THRUST_IGNORE_DEPRECATED_CPP_14)
41-
# if !defined(THRUST_IGNORE_DEPRECATED_CPP_11)
42-
# define THRUST_IGNORE_DEPRECATED_CPP_11
43-
# endif
44-
#endif // suppress all c++11 dialect deprecation warnings
45-
#if defined(LIBCUDACXX_IGNORE_DEPRECATED_COMPILER) || defined(CCCL_IGNORE_DEPRECATED_COMPILER) \
46-
|| defined(CUB_IGNORE_DEPRECATED_COMPILER) || defined(THRUST_IGNORE_DEPRECATED_CPP_DIALECT) \
47-
|| defined(THRUST_IGNORE_DEPRECATED_CPP_14) || defined(THRUST_IGNORE_DEPRECATED_CPP_11)
48-
# if !defined(THRUST_IGNORE_DEPRECATED_COMPILER)
49-
# define THRUST_IGNORE_DEPRECATED_COMPILER
50-
# endif
51-
#endif // suppress all compiler deprecation warnings
5225
#if defined(LIBCUDACXX_IGNORE_DEPRECATED_API) || defined(CCCL_IGNORE_DEPRECATED_API) \
5326
|| defined(CUB_IGNORE_DEPRECATED_API)
5427
# if !defined(THRUST_IGNORE_DEPRECATED_API)

0 commit comments

Comments
 (0)