Skip to content

Commit dde8e11

Browse files
davebayermiscco
andauthored
Globalize the include of <cuda_runtime_api.h> (NVIDIA#4704)
Co-authored-by: Michael Schellenberger Costa <miscco@nvidia.com>
1 parent 1b13308 commit dde8e11

File tree

9 files changed

+32
-45
lines changed

9 files changed

+32
-45
lines changed

libcudacxx/include/cuda/__annotated_ptr/access_property.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
#include <cuda/std/cstddef>
2626
#include <cuda/std/cstdint>
2727

28-
#include <cuda_runtime_api.h>
29-
3028
#include <cuda/std/__cccl/prologue.h>
3129

3230
_LIBCUDACXX_BEGIN_NAMESPACE_CUDA
@@ -53,24 +51,30 @@ class access_property
5351
{};
5452
struct persisting
5553
{
54+
#if _CCCL_HAS_CTK()
5655
[[nodiscard]] _LIBCUDACXX_HIDE_FROM_ABI constexpr operator cudaAccessProperty() const noexcept
5756
{
5857
return cudaAccessProperty::cudaAccessPropertyPersisting;
5958
}
59+
#endif // _CCCL_HAS_CTK()
6060
};
6161
struct streaming
6262
{
63+
#if _CCCL_HAS_CTK()
6364
[[nodiscard]] _LIBCUDACXX_HIDE_FROM_ABI constexpr operator cudaAccessProperty() const noexcept
6465
{
6566
return cudaAccessProperty::cudaAccessPropertyStreaming;
6667
}
68+
#endif // _CCCL_HAS_CTK()
6769
};
6870
struct normal
6971
{
72+
#if _CCCL_HAS_CTK()
7073
[[nodiscard]] _LIBCUDACXX_HIDE_FROM_ABI constexpr operator cudaAccessProperty() const noexcept
7174
{
7275
return cudaAccessProperty::cudaAccessPropertyNormal;
7376
}
77+
#endif // _CCCL_HAS_CTK()
7478
};
7579

7680
_CCCL_HIDE_FROM_ABI access_property() noexcept = default;

libcudacxx/include/cuda/__functional/get_device_address.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323

2424
#if _CCCL_HAS_CTK()
2525

26-
# if !_CCCL_HAS_CUDA_COMPILER() || _CCCL_CUDA_COMPILER(CLANG)
27-
# include <cuda_runtime_api.h>
28-
# endif // !_CCCL_HAS_CUDA_COMPILER() || _CCCL_CUDA_COMPILER(CLANG)
29-
3026
# include <cuda/std/__cuda/api_wrapper.h>
3127
# include <cuda/std/__memory/addressof.h>
3228

libcudacxx/include/cuda/__mdspan/host_device_accessor.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
# pragma system_header
2222
#endif // no system header
2323

24-
#if !_CCCL_HAS_CUDA_COMPILER || _CCCL_CUDA_COMPILER(CLANG)
25-
# include <cuda_runtime_api.h>
26-
#endif // _CCCL_CUDA_COMPILER(CLANG)
27-
2824
#include <cuda/std/__concepts/concept_macros.h>
2925
#include <cuda/std/__cuda/api_wrapper.h>
3026
#include <cuda/std/__iterator/concepts.h>
@@ -107,6 +103,7 @@ class __host_accessor : public _Accessor
107103
[[nodiscard]] _LIBCUDACXX_HIDE_FROM_ABI static constexpr bool
108104
__is_host_accessible_pointer([[maybe_unused]] __data_handle_type __p) noexcept
109105
{
106+
#if _CCCL_HAS_CTK()
110107
if constexpr (_CUDA_VSTD::contiguous_iterator<__data_handle_type>)
111108
{
112109
::cudaPointerAttributes __ptr_attrib{};
@@ -115,6 +112,7 @@ class __host_accessor : public _Accessor
115112
return __ptr_attrib.hostPointer != nullptr || __ptr_attrib.type == ::cudaMemoryTypeUnregistered;
116113
}
117114
else
115+
#endif // _CCCL_HAS_CTK()
118116
{
119117
return true; // cannot be verified
120118
}
@@ -222,6 +220,7 @@ class __device_accessor : public _Accessor
222220
[[nodiscard]] _LIBCUDACXX_HIDE_FROM_ABI static constexpr bool
223221
__is_device_accessible_pointer([[maybe_unused]] __data_handle_type __p) noexcept
224222
{
223+
#if _CCCL_HAS_CTK()
225224
if constexpr (_CUDA_VSTD::contiguous_iterator<__data_handle_type>)
226225
{
227226
::cudaPointerAttributes __ptr_attrib{};
@@ -230,6 +229,7 @@ class __device_accessor : public _Accessor
230229
return __ptr_attrib.devicePointer != nullptr || __ptr_attrib.type == ::cudaMemoryTypeUnregistered;
231230
}
232231
else
232+
#endif // _CCCL_HAS_CTK()
233233
{
234234
return true; // cannot be verified
235235
}
@@ -342,6 +342,7 @@ class __managed_accessor : public _Accessor
342342
[[nodiscard]] _LIBCUDACXX_HIDE_FROM_ABI static constexpr bool
343343
__is_managed_pointer([[maybe_unused]] __data_handle_type __p) noexcept
344344
{
345+
#if _CCCL_HAS_CTK()
345346
if constexpr (_CUDA_VSTD::contiguous_iterator<__data_handle_type>)
346347
{
347348
::cudaPointerAttributes __ptr_attrib{};
@@ -350,6 +351,7 @@ class __managed_accessor : public _Accessor
350351
return __ptr_attrib.devicePointer != nullptr && __ptr_attrib.hostPointer == __ptr_attrib.devicePointer;
351352
}
352353
else
354+
#endif // _CCCL_HAS_CTK()
353355
{
354356
return true; // cannot be verified
355357
}

libcudacxx/include/cuda/std/__cccl/cuda_capabilities.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@
2121
# pragma system_header
2222
#endif // no system header
2323

24-
// CUDA headers might not be present when using NVRTC, see NVIDIA/cccl#2095 for detail
25-
#if !_CCCL_COMPILER(NVRTC)
26-
# include <cuda_runtime_api.h>
27-
#endif // !_CCCL_COMPILER(NVRTC)
24+
#include <cuda/std/__cccl/cuda_toolkit.h>
2825

2926
#include <nv/target>
3027

libcudacxx/include/cuda/std/__cuda/api_wrapper.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
# pragma system_header
2222
#endif // no system header
2323

24-
#if _CCCL_CUDA_COMPILER(CLANG)
25-
# include <cuda_runtime_api.h>
26-
#endif // _CCCL_CUDA_COMPILER(CLANG)
27-
2824
#include <cuda/std/__exception/cuda_error.h>
2925

3026
#define _CCCL_TRY_CUDA_API(_NAME, _MSG, ...) \

libcudacxx/include/cuda/std/__cuda/ensure_current_device.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,15 @@
2121
# pragma system_header
2222
#endif // no system header
2323

24-
#if _CCCL_CUDA_COMPILER(CLANG)
25-
# include <cuda_runtime_api.h>
26-
#endif // _CCCL_CUDA_COMPILER(CLANG)
24+
#if _CCCL_HAS_CTK()
2725

28-
#include <cuda/std/__cuda/api_wrapper.h>
26+
# include <cuda/std/__cuda/api_wrapper.h>
2927

30-
#include <cuda/std/__cccl/prologue.h>
28+
# include <cuda/std/__cccl/prologue.h>
3129

3230
_LIBCUDACXX_BEGIN_NAMESPACE_CUDA
3331

34-
#if !_CCCL_COMPILER(NVRTC)
32+
# if !_CCCL_COMPILER(NVRTC)
3533

3634
//! @brief `__ensure_current_device` is a simple helper that the current device is set to the right one.
3735
//! Only changes the current device if the target device is not the current one
@@ -63,10 +61,12 @@ struct __ensure_current_device
6361
}
6462
};
6563

66-
#endif // !_CCCL_COMPILER(NVRTC)
64+
# endif // !_CCCL_COMPILER(NVRTC)
6765

6866
_LIBCUDACXX_END_NAMESPACE_CUDA
6967

70-
#include <cuda/std/__cccl/epilogue.h>
68+
# include <cuda/std/__cccl/epilogue.h>
69+
70+
#endif // _CCCL_HAS_CTK()
7171

7272
#endif //_CUDA__STD__CUDA_ENSURE_CURRENT_DEVICE_H

libcudacxx/include/cuda/std/__exception/cuda_error.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@
2222
# pragma system_header
2323
#endif // no system header
2424

25-
#if !_CCCL_COMPILER(NVRTC)
26-
# if _CCCL_HAS_CUDA_COMPILER()
27-
# include <cuda_runtime_api.h>
28-
# endif // _CCCL_HAS_CUDA_COMPILER()
29-
#endif // !_CCCL_COMPILER(NVRTC)
30-
3125
#include <cuda/std/__exception/terminate.h>
3226
#include <cuda/std/source_location>
3327

@@ -67,11 +61,11 @@ static char* __format_cuda_error(
6761
__loc.line(),
6862
__api ? __api : "",
6963
__api ? " " : "",
70-
# if _CCCL_HAS_CUDA_COMPILER()
64+
# if _CCCL_HAS_CTK()
7165
::cudaGetErrorString(::cudaError_t(__status)),
72-
# else
66+
# else // ^^^ _CCCL_HAS_CTK() ^^^ / vvv !_CCCL_HAS_CTK() vvv
7367
"cudaError",
74-
# endif
68+
# endif // ^^^ !_CCCL_HAS_CTK() ^^^
7569
__status,
7670
__msg);
7771
return __msg_buffer.__buffer;

libcudacxx/include/cuda/std/__tuple_dir/vector_types.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ _CCCL_DIAG_SUPPRESS_CLANG("-Wmismatched-tags")
3434
# include <cuda/std/__utility/forward.h>
3535
# include <cuda/std/__utility/move.h>
3636

37-
# if !_CCCL_CUDA_COMPILATION()
38-
# include <cuda_runtime_api.h>
39-
# endif // !_CCCL_CUDA_COMPILATION()
40-
4137
# define _LIBCUDACXX_SPECIALIZE_TUPLE_INTERFACE(__name, __type, __size) \
4238
template <> \
4339
struct tuple_size<__name##__size> : _CUDA_VSTD::integral_constant<size_t, __size> \

libcudacxx/include/cuda/stream_ref

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ private:
4848
# pragma system_header
4949
#endif // no system header
5050

51-
#include <cuda/std/__cuda/api_wrapper.h>
52-
#include <cuda/std/__exception/cuda_error.h>
53-
#include <cuda/std/cstddef>
51+
#if _CCCL_HAS_CTK()
5452

55-
#include <cuda_runtime_api.h>
53+
# include <cuda/std/__cuda/api_wrapper.h>
54+
# include <cuda/std/__exception/cuda_error.h>
55+
# include <cuda/std/cstddef>
5656

57-
#include <cuda/std/__cccl/prologue.h>
57+
# include <cuda/std/__cccl/prologue.h>
5858

5959
_LIBCUDACXX_BEGIN_NAMESPACE_CUDA
6060

@@ -200,6 +200,8 @@ public:
200200

201201
_LIBCUDACXX_END_NAMESPACE_CUDA
202202

203-
#include <cuda/std/__cccl/epilogue.h>
203+
# include <cuda/std/__cccl/epilogue.h>
204+
205+
#endif // _CCCL_HAS_CTK()
204206

205207
#endif //_CUDA_STREAM_REF

0 commit comments

Comments
 (0)