Skip to content

Commit

Permalink
Merge branch 'main' into fea/build-rapids
Browse files Browse the repository at this point in the history
  • Loading branch information
trxcllnt authored May 16, 2024
2 parents f5da241 + 2c6203e commit 3a40a7c
Show file tree
Hide file tree
Showing 29 changed files with 883 additions and 137 deletions.
Binary file added .devcontainer/img/build_button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .devcontainer/img/cmaketools_presets.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .devcontainer/img/cmaketools_sidebar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .devcontainer/img/cmaketools_targets.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .devcontainer/img/debug.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .devcontainer/img/nsight.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .devcontainer/img/run.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
81 changes: 78 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,12 @@ Coming soon!
## Building and Testing
CCCL components are header-only libraries. This means there isn't a traditional build process for the library itself. However, before submitting contributions, it's a good idea to build and run tests. Dedicated build and test scripts for each component are provided in the `ci/` directory.
CCCL components are header-only libraries. This means there isn't a traditional build process for the library itself. However, before submitting contributions, it's a good idea to [build and run tests](#developer-guides).
### Building
There are multiple options for building and running our tests. Which option you choose depends on your preferences and whether you are using [CCCL's DevContainers](.devcontainer/README.md) (highly recommended!).

### Using Manual Build Scripts
#### Building

Use the build scripts provided in the `ci/` directory to build tests for each component. Building tests does not require a GPU.

Expand All @@ -76,7 +79,7 @@ Use the build scripts provided in the `ci/` directory to build tests for each co
./ci/build_cub.sh -cxx g++ -std 14 -arch "70;75;80-virtual"
```
### Testing
#### Testing
Use the test scripts provided in the `ci/` directory to run tests for each component. These take the same arguments as the build scripts and will automatically build the tests if they haven't already been built. Running tests requires a GPU.
Expand All @@ -89,6 +92,78 @@ Use the test scripts provided in the `ci/` directory to run tests for each compo
./ci/test_cub.sh -cxx g++ -std 14 -arch "70;75;80-virtual"
```

### Using CMake Presets

[CMake Presets](https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html) are a set of configurations defined in a JSON file that specify project-wide build details for CMake. They provide a standardized and sharable way to configure, build, and test projects across different platforms and development environments. Presets are available from CMake versions 3.19 and later.

There are three kinds of Presets

- Configure Presets: specify options for the `cmake` command,

- Build Presets: specify options for the `cmake --build` command,

- Test Presets: specify options for the `ctest` command.

In CCCL we provide many presets to be used out of the box. You can find the complete list in our corresponding [CMakePresets.json](./CMakePresets.json) file.

These commands can be used to get lists of the configure, build, and test presets.

```bash
cmake --list-presets # Configure presets
cmake --build --list-presets # Build presets
ctest --list-presets # Test presets
```

While there is a lot of overlap, there may be differences between the configure, build, and test presets to support various testing workflows.

The `dev` presets are intended as a base for general development while the others are useful for replicating CI failures.

#### Using CMake Presets via Command Line

CMake automatically generates the preset build directories. You can configure, build and test for a specific preset (e.g. `thrust-cpp11`) via cmake from the root directory by appending `--preset=thrust-cpp11` to the corresponding commands. For example:

```bash
cmake --preset=thrust-cpp11
cmake --build --preset=thrust-cpp11
ctest --preset=thrust-cpp11
```

That will create `build/<optional devcontainer name>/thrust-cpp11/` and build everything in there. The devcontainer name is inserted automatically on devcontainer builds to keep build artifacts separate for the different toolchains.

It's also worth mentioning that additional cmake options can still be passed in and will override the preset settings.

As a common example, the presets are currently always `60;70;80` for `CMAKE_CUDA_ARCHITECTURES`, but this can be overridden at configure time with something like:

```bash
cmake --preset=thrust-cpp20 "-DCMAKE_CUDA_ARCHITECTURES=89"
```

> __Note__: Either using the `cmake` command from within the root directory or from within the build directory works, but will behave in slightly different ways. Building and running tests from the build directory will compile every target and run all of the tests configured in the configure step. Doing so from the root directory using the `--preset=<test_preset>` option will build and run a subset of configured targets and tests.
#### Using CMake Presets via VS Code GUI extension (Recommended when using DevContainers)

The recommended way to use CMake Presets is via the VS Code extension [CMake Tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cmake-tools), already included in [CCCL's DevContainers](.devcontainer/README.md). As soon as you install the extension you would be able to see the sidebar menu below.

![cmaketools sidebar](/.devcontainer/img/cmaketools_sidebar.png)

You can specify the desired CMake Preset by clicking the "Select Configure Preset" button under the "Configure" node (see image below).

![cmaketools presets](.devcontainer/img/cmaketools_presets.png)

After that you can select the default build target from the "Build" node. As soon as you expand it, a list will appear with all the available targets that are included within the preset you selected. For example if you had selected the `all-dev` preset VS Code will display all the available targets we have in cccl.

![cmaketools presets](.devcontainer/img/cmaketools_targets.png)

You can build the selected target by pressing the gear button ![gear](.devcontainer/img/build_button.png) at the bottom of the VS Code window.

Alternatively you can select the desired target from either the "Debug" or "Launch" drop down menu (for debugging or running correspondingly). <b>In that case after you select the target and either press "Run" ![run](.devcontainer/img/run.png) or "Debug" ![debug](.devcontainer/img/debug.png) the target will build on its own before running without the user having to build it explicitly from the gear button.</b>

---

We encourage users who want to debug device code to install the [Nsight Visual Studio Code Edition extension](https://marketplace.visualstudio.com/items?itemName=NVIDIA.nsight-vscode-edition) that enables the VS Code frontend for `cuda-gdb`. <u>To use it you should launch from the sidebar menu instead of pressing the "Debug" button from the bottom menu</u>.

![nsight](.devcontainer/img/nsight.png)

## Creating a Pull Request

1. Push changes to your fork
Expand Down
4 changes: 2 additions & 2 deletions cub/docs/gen_docs.bash
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ if [ ! -d cubimg ]; then
git clone -b gh-pages https://github.com/NVlabs/cub.git cubimg
fi

if [ ! -n "$(find img -name 'example_range.png')" ]; then
wget -q https://raw.githubusercontent.com/NVIDIA/NVTX/release-v3/docs/images/example_range.png -O img/example_range.png
if [ ! -n "$(find cubimg -name 'example_range.png')" ]; then
wget -q https://raw.githubusercontent.com/NVIDIA/NVTX/release-v3/docs/images/example_range.png -O cubimg/example_range.png
fi

if [ ! -n "$(find img -name '*.png')" ]; then
Expand Down
26 changes: 26 additions & 0 deletions cub/test/catch2_test_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,32 @@ auto BitwiseEqualsRange(const Range& range) -> CustomEqualsRangeMatcher<Range, b
REQUIRE_THAT(vec_ref, detail::NaNEqualsRange(vec_out)); \
}

#include <cuda/std/tuple>
_LIBCUDACXX_BEGIN_NAMESPACE_STD
template <size_t N, typename... T>
__enable_if_t<(N == sizeof...(T))> print_elem(::std::ostream&, const tuple<T...>&)
{}

template <size_t N, typename... T>
__enable_if_t<(N < sizeof...(T))> print_elem(::std::ostream& os, const tuple<T...>& tup)
{
_CCCL_IF_CONSTEXPR (N != 0)
{
os << ", ";
}
os << _CUDA_VSTD::get<N>(tup);
_CUDA_VSTD::print_elem<N + 1>(os, tup);
}

template <typename... T>
::std::ostream& operator<<(::std::ostream& os, const tuple<T...>& tup)
{
os << "[";
_CUDA_VSTD::print_elem<0>(os, tup);
return os << "]";
}
_LIBCUDACXX_END_NAMESPACE_STD

#include <c2h/custom_type.cuh>
#include <c2h/generators.cuh>

Expand Down
1 change: 1 addition & 0 deletions libcudacxx/include/cuda/__cccl_config
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <cuda/std/__cccl/dialect.h>
#include <cuda/std/__cccl/execution_space.h>
#include <cuda/std/__cccl/ptx_isa.h>
#include <cuda/std/__cccl/sequence_access.h>
#include <cuda/std/__cccl/system_header.h>
#include <cuda/std/__cccl/version.h>
#include <cuda/std/__cccl/visibility.h>
Expand Down
88 changes: 88 additions & 0 deletions libcudacxx/include/cuda/std/__cccl/sequence_access.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//===----------------------------------------------------------------------===//
//
// Part of libcu++, the C++ Standard Library for your entire system,
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//

#ifndef __CCCL_SEQUENCE_ACCESS_H
#define __CCCL_SEQUENCE_ACCESS_H

#include <cuda/std/__cccl/compiler.h>
#include <cuda/std/__cccl/system_header.h>

#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header

// We need to define hidden friends for {cr,r,}{begin,end} of our containers as we will otherwise encounter ambigouities
#define _CCCL_SYNTHESIZE_SEQUENCE_ACCESS(_ClassName, _ConstIter) \
_CCCL_NODISCARD_FRIEND _CCCL_HOST_DEVICE iterator begin(_ClassName& __sequence) noexcept( \
noexcept(__sequence.begin())) \
{ \
return __sequence.begin(); \
} \
_CCCL_NODISCARD_FRIEND _CCCL_HOST_DEVICE _ConstIter begin(const _ClassName& __sequence) noexcept( \
noexcept(__sequence.begin())) \
{ \
return __sequence.begin(); \
} \
_CCCL_NODISCARD_FRIEND _CCCL_HOST_DEVICE iterator end(_ClassName& __sequence) noexcept(noexcept(__sequence.end())) \
{ \
return __sequence.end(); \
} \
_CCCL_NODISCARD_FRIEND _CCCL_HOST_DEVICE _ConstIter end(const _ClassName& __sequence) noexcept( \
noexcept(__sequence.end())) \
{ \
return __sequence.end(); \
} \
_CCCL_NODISCARD_FRIEND _CCCL_HOST_DEVICE _ConstIter cbegin(const _ClassName& __sequence) noexcept( \
noexcept(__sequence.begin())) \
{ \
return __sequence.begin(); \
} \
_CCCL_NODISCARD_FRIEND _CCCL_HOST_DEVICE _ConstIter cend(const _ClassName& __sequence) noexcept( \
noexcept(__sequence.end())) \
{ \
return __sequence.end(); \
}
#define _CCCL_SYNTHESIZE_SEQUENCE_REVERSE_ACCESS(_ClassName, _ConstRevIter) \
_CCCL_NODISCARD_FRIEND _CCCL_HOST_DEVICE reverse_iterator rbegin(_ClassName& __sequence) noexcept( \
noexcept(__sequence.rbegin())) \
{ \
return __sequence.rbegin(); \
} \
_CCCL_NODISCARD_FRIEND _CCCL_HOST_DEVICE _ConstRevIter rbegin(const _ClassName& __sequence) noexcept( \
noexcept(__sequence.rbegin())) \
{ \
return __sequence.rbegin(); \
} \
_CCCL_NODISCARD_FRIEND _CCCL_HOST_DEVICE reverse_iterator rend(_ClassName& __sequence) noexcept( \
noexcept(__sequence.rend())) \
{ \
return __sequence.rend(); \
} \
_CCCL_NODISCARD_FRIEND _CCCL_HOST_DEVICE _ConstRevIter rend(const _ClassName& __sequence) noexcept( \
noexcept(__sequence.rend())) \
{ \
return __sequence.rend(); \
} \
_CCCL_NODISCARD_FRIEND _CCCL_HOST_DEVICE _ConstRevIter crbegin(const _ClassName& __sequence) noexcept( \
noexcept(__sequence.rbegin())) \
{ \
return __sequence.rbegin(); \
} \
_CCCL_NODISCARD_FRIEND _CCCL_HOST_DEVICE _ConstRevIter crend(const _ClassName& __sequence) noexcept( \
noexcept(__sequence.rend())) \
{ \
return __sequence.rend(); \
}

#endif // __CCCL_SEQUENCE_ACCESS_H
1 change: 1 addition & 0 deletions libcudacxx/include/cuda/std/__cuda/barrier.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ class barrier<thread_scope_block, _CUDA_VSTD::__empty_completion> : public __blo
private:
_LIBCUDACXX_INLINE_VISIBILITY inline bool __test_wait_sm_80(arrival_token __token) const
{
(void) __token;
int32_t __ready = 0;
NV_DISPATCH_TARGET(
NV_PROVIDES_SM_80,
Expand Down
126 changes: 88 additions & 38 deletions libcudacxx/include/cuda/std/__iterator/access.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,57 +25,107 @@

_LIBCUDACXX_BEGIN_NAMESPACE_STD

template <class _Tp, size_t _Np>
_LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 _Tp* begin(_Tp (&__array)[_Np])
namespace __begin
{
return __array;
}

template <class _Tp, size_t _Np>
_LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 _Tp* end(_Tp (&__array)[_Np])
struct __fn
{
return __array + _Np;
}

template <class _Cp>
_LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 auto begin(_Cp& __c) -> decltype(__c.begin())
template <class _Tp, size_t _Np>
_LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 _Tp* operator()(_Tp (&__array)[_Np]) const noexcept
{
return __array;
}

template <class _Cp>
_LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 auto operator()(_Cp& __c) const noexcept(noexcept(__c.begin()))
-> decltype(__c.begin())
{
return __c.begin();
}

template <class _Cp>
_LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 auto operator()(const _Cp& __c) const
noexcept(noexcept(__c.begin())) -> decltype(__c.begin())
{
return __c.begin();
}
};
} // namespace __begin

inline namespace __cpo
{
return __c.begin();
}
_LIBCUDACXX_CPO_ACCESSIBILITY auto begin = __begin::__fn{};
} // namespace __cpo

template <class _Cp>
_LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 auto begin(const _Cp& __c) -> decltype(__c.begin())
namespace __end
{
return __c.begin();
}

template <class _Cp>
_LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 auto end(_Cp& __c) -> decltype(__c.end())
struct __fn
{
return __c.end();
}

template <class _Cp>
_LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 auto end(const _Cp& __c) -> decltype(__c.end())
template <class _Tp, size_t _Np>
_LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 _Tp* operator()(_Tp (&__array)[_Np]) const noexcept
{
return __array + _Np;
}

template <class _Cp>
_LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 auto operator()(_Cp& __c) const noexcept(noexcept(__c.end()))
-> decltype(__c.end())
{
return __c.end();
}

template <class _Cp>
_LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 auto operator()(const _Cp& __c) const
noexcept(noexcept(__c.end())) -> decltype(__c.end())
{
return __c.end();
}
};
} // namespace __end

inline namespace __cpo
{
return __c.end();
}
_LIBCUDACXX_CPO_ACCESSIBILITY auto end = __end::__fn{};
} // namespace __cpo

#if _CCCL_STD_VER > 2011
#if _CCCL_STD_VER >= 2014

template <class _Cp>
_LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 auto cbegin(const _Cp& __c) -> decltype(_CUDA_VSTD::begin(__c))
namespace __cbegin
{
return _CUDA_VSTD::begin(__c);
}
struct __fn
{
template <class _Cp>
_LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 auto operator()(const _Cp& __c) const
noexcept(noexcept(_CUDA_VSTD::begin(__c))) -> decltype(_CUDA_VSTD::begin(__c))
{
return _CUDA_VSTD::begin(__c);
}
};
} // namespace __cbegin

inline namespace __cpo
{
_LIBCUDACXX_CPO_ACCESSIBILITY auto cbegin = __cbegin::__fn{};
} // namespace __cpo

template <class _Cp>
_LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 auto cend(const _Cp& __c) -> decltype(_CUDA_VSTD::end(__c))
namespace __cend
{
struct __fn
{
template <class _Cp>
_LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 auto operator()(const _Cp& __c) const
noexcept(noexcept(_CUDA_VSTD::end(__c))) -> decltype(_CUDA_VSTD::end(__c))
{
return _CUDA_VSTD::end(__c);
}
};
} // namespace __cend

inline namespace __cpo
{
return _CUDA_VSTD::end(__c);
}
_LIBCUDACXX_CPO_ACCESSIBILITY auto cend = __cend::__fn{};
} // namespace __cpo

#endif
#endif // _CCCL_STD_VER >= 2014

_LIBCUDACXX_END_NAMESPACE_STD

Expand Down
Loading

0 comments on commit 3a40a7c

Please sign in to comment.