Skip to content

Commit

Permalink
Add _CCCL_BUILTIN_PREFETCH (#3433)
Browse files Browse the repository at this point in the history
  • Loading branch information
fbusato authored Jan 21, 2025
1 parent da9f6e3 commit d2857b1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
16 changes: 9 additions & 7 deletions docs/cccl_development/macro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,15 @@ Usage example:

**Portable Builtin Macros**:

+-----------------------------+--------------------------------------------+
| ``_CCCL_UNREACHABLE()`` | Portable ``__builtin_unreachable()`` |
+-----------------------------+--------------------------------------------+
| ``_CCCL_BUILTIN_ASSUME(X)`` | Portable ``__builtin_assume(X)`` |
+-----------------------------+--------------------------------------------+
| ``_CCCL_BUILTIN_EXPECT(X)`` | Portable ``__builtin_expected(X)`` |
+-----------------------------+--------------------------------------------+
+---------------------------------------+--------------------------------------------+
| ``_CCCL_UNREACHABLE()`` | Portable ``__builtin_unreachable()`` |
+---------------------------------------+--------------------------------------------+
| ``_CCCL_BUILTIN_ASSUME(X)`` | Portable ``__builtin_assume(X)`` |
+---------------------------------------+--------------------------------------------+
| ``_CCCL_BUILTIN_EXPECT(X)`` | Portable ``__builtin_expected(X)`` |
+---------------------------------------+--------------------------------------------+
| ``_CCCL_BUILTIN_PREFETCH(X[, Y, Z])`` | Portable ``__builtin_prefetch(X, Y, Z)`` |
+---------------------------------------+--------------------------------------------+

**Portable Keyword Macros**

Expand Down
6 changes: 6 additions & 0 deletions libcudacxx/include/cuda/std/__cccl/builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@
NV_IF_ELSE_TARGET(NV_IS_DEVICE, (__builtin_assume(__VA_ARGS__);), (__assume(__VA_ARGS__);))
#endif // _CCCL_CHECK_BUILTIN(builtin_assume)

#if _CCCL_CHECK_BUILTIN(builtin_prefetch) || _CCCL_COMPILER(GCC)
# define _CCCL_BUILTIN_PREFETCH(...) NV_IF_TARGET(NV_IS_HOST, __builtin_prefetch(__VA_ARGS__);)
#else
# define _CCCL_BUILTIN_PREFETCH(...)
#endif // _CCCL_CHECK_BUILTIN(builtin_prefetch)

// NVCC prior to 11.2 cannot handle __builtin_assume
#if _CCCL_CUDACC_BELOW(11, 2)
# undef _CCCL_BUILTIN_ASSUME
Expand Down
22 changes: 22 additions & 0 deletions libcudacxx/test/libcudacxx/libcxx/macros/prefetch.compile.pass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//

#include <cuda/std/detail/__config>

#include <test_macros.h>

int main(int, char**)
{
int memory[8];
_CCCL_BUILTIN_PREFETCH(memory);
_CCCL_BUILTIN_PREFETCH(memory, /*read-only=*/0);
_CCCL_BUILTIN_PREFETCH(memory, /*read-only=*/0, /*medium cache utilization=*/1);
unused(memory);
return 0;
}

0 comments on commit d2857b1

Please sign in to comment.