Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ ColumnLimit: 80
IndentWidth: 4
IndentWrappedFunctionNames: true

Standard: c++17
Standard: c++20
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ This release drops support for Python 3.10, making Python 3.11 the minimum requi
* Reduced the overhead of `dpnp.ndarray.flags` and `dpnp.tensor.usm_ndarray.flags` [#3168](https://github.com/IntelPython/dpnp/pull/3168)
* Changed `dpnp.linalg.LinAlgError` to derive from `numpy.linalg.LinAlgError`, so `except numpy.linalg.LinAlgError` also catches errors raised by dpnp linear algebra functions [#3184](https://github.com/IntelPython/dpnp/pull/3184)
* Bumped the minimum required `dpctl` version to `0.24.0` [#3169](https://github.com/IntelPython/dpnp/pull/3169)
* Changed the C++ standard used to build dpnp and the pybind11 example from C++17 to C++20. C++ extensions that include the headers shipped with dpnp (`dpnp4pybind11.hpp`, the libtensor headers) must now be built as C++20 [#3190](https://github.com/IntelPython/dpnp/pull/3190)

### Deprecated

Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ size of shared object with offloading sections"
OFF
)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
Expand Down
3 changes: 2 additions & 1 deletion doc/quick_start_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ needed when building C++ extensions with dpnp:
python -m dpnp --tensor-include-dir # print path to libtensor include directory

These options are useful when building pybind11 extensions that use
``dpnp4pybind11.hpp`` or libtensor kernel headers.
``dpnp4pybind11.hpp`` or libtensor kernel headers. Such extensions must be
compiled as C++20 or later.


Testing
Expand Down
14 changes: 2 additions & 12 deletions dpnp/backend/src/dpnp_fptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <complex>
#include <map>
#include <stdexcept>
#include <type_traits>

#include <sycl/sycl.hpp>

Expand Down Expand Up @@ -104,17 +105,6 @@ template <typename T1, typename T2, typename... Ts>
constexpr auto both_types_are_same =
std::conjunction_v<is_any<T1, Ts...>, are_same<T1, T2>>;

/**
* @brief If the type _Tp is a reference type, provides the member typedef type
* which is the type referred to by _Tp with its topmost cv-qualifiers removed.
* Otherwise type is _Tp with its topmost cv-qualifiers removed.
*
* @note std::remove_cvref is only available since c++20
*/
template <typename _Tp>
using dpnp_remove_cvref_t =
typename std::remove_cv_t<typename std::remove_reference_t<_Tp>>;

/**
* @brief "<" comparison with complex types support.
*
Expand All @@ -127,7 +117,7 @@ class dpnp_less_comp
bool operator()(_Xp &&__x, _Yp &&__y) const
{
if constexpr (both_types_are_same<
dpnp_remove_cvref_t<_Xp>, dpnp_remove_cvref_t<_Yp>,
std::remove_cvref_t<_Xp>, std::remove_cvref_t<_Yp>,
std::complex<float>, std::complex<double>>) {
bool ret = false;
_Xp a = std::forward<_Xp>(__x);
Expand Down
4 changes: 4 additions & 0 deletions dpnp/include/dpnp4pybind11.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@

#pragma once

#if (defined(_MSVC_LANG) ? _MSVC_LANG : __cplusplus) < 202002L
#error "dpnp4pybind11.hpp requires C++20 or later"
#endif

// Include for dpctl_capi struct and casters
#include "dpctl4pybind11.hpp"

Expand Down
2 changes: 1 addition & 1 deletion dpnp/libtensor/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
A new extension's `CMakeLists.txt` lists its sources and calls `build_dpnp_pybind11_ext(<module> SOURCES ... [INCLUDE_DIRS ...] [LARGE_RANGES])` from `dpnp/CMakeLists.txt`, which sets the options all extensions share and installs the module into `dpnp/libtensor`; only oneMKL/oneMath linking and the `-DUSE_ONEMATH*` definitions stay in the extension. Add it with `add_subdirectory` in `dpnp/CMakeLists.txt`, and put an option every extension needs into the helper, not into one extension.

## Rules for Changes
- C++17. Include what you use (`<cstdint>`, `<vector>`, ...), use `std::`-qualified fixed-width types (`std::int64_t`, `std::size_t`), make by-value parameters and locals `const` (`constexpr` where possible), and pass non-output parameters as `const T &`.
- C++20. Include what you use (`<cstdint>`, `<vector>`, ...), use `std::`-qualified fixed-width types (`std::int64_t`, `std::size_t`), make by-value parameters and locals `const` (`constexpr` where possible), and pass non-output parameters as `const T &`.
- Headers use `#pragma once`. New files in `include/` and `source/` add a `/// \file` block after the license header.
- Python-facing functions take `sycl::queue &exec_q` and `const std::vector<sycl::event> &depends`, and return `std::pair<sycl::event, sycl::event>` (keep-alive host-task event, compute event). Keep arguments alive with `dpnp::utils::keep_args_alive`.
- Validate inputs before launching: queue compatibility, contiguity, writability, memory overlap (including the same logical tensor), dtype and ndim. Reuse the helpers neighbouring files use: `check_queue`, `check_c_contig`, `check_no_overlap`, `check_writable` from `include/ext/validation_utils.hpp` (`putmask`, `statistics`, `isclose`, `interpolate`), or `dpnp::utils::queues_are_compatible`, `dpnp::tensor::overlap::MemoryOverlap` and `dpnp::tensor::validation::CheckWritable` (extensions and the Array API functions). Don't silently accept strided input.
Expand Down
2 changes: 1 addition & 1 deletion examples/pybind11/use_dpnp_array/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ project(
DESCRIPTION "Example of using dpnp::tensor::usm_ndarray type caster"
)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The installed dpnp4pybind11.hpp still compiles as C++17, but this example is its only build in CI. At C++20, nothing would catch a C++20-only change in that header, which would break C++17 extensions built against dpnp. Should the public headers stay C++17-compatible? If yes, could the example stay at C++17?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is intentional: the C++20 switch applies to the shipped headers too, and is treated as a breaking change for C++ extensions built against dpnp. I updated the changelog entry and the quick start guide to say these extensions must now build as C++20, and the PR description to match. dpnp4pybind11.hpp now fails with a clear #error when compiled below C++20. The example stays at C++20 as the consumer build in CI.

set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Fetch pybind11
Expand Down
Loading