From 242766f2029e573091de07865ff66aad95fc78dc Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Mon, 16 Nov 2026 18:46:51 +0100 Subject: [PATCH] Build dpnp as C++20 Bump CMAKE_CXX_STANDARD from 17 to 20 in the root CMakeLists.txt and in the pybind11 example, set the clang-format standard to c++20, and replace the dpnp_remove_cvref_t helper in the legacy backend with std::remove_cvref_t. --- .clang-format | 2 +- CHANGELOG.md | 1 + CMakeLists.txt | 2 +- dpnp/backend/src/dpnp_fptr.hpp | 14 ++------------ dpnp/libtensor/AGENTS.md | 2 +- examples/pybind11/use_dpnp_array/CMakeLists.txt | 2 +- 6 files changed, 7 insertions(+), 16 deletions(-) diff --git a/.clang-format b/.clang-format index 4304e0ed40d4..663ffb122ef1 100644 --- a/.clang-format +++ b/.clang-format @@ -39,4 +39,4 @@ ColumnLimit: 80 IndentWidth: 4 IndentWrappedFunctionNames: true -Standard: c++17 +Standard: c++20 diff --git a/CHANGELOG.md b/CHANGELOG.md index c0470fd0bf4b..23cc7a6c85d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 [#3190](https://github.com/IntelPython/dpnp/pull/3190) ### Deprecated diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e45698b116b..b100cc1163c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/dpnp/backend/src/dpnp_fptr.hpp b/dpnp/backend/src/dpnp_fptr.hpp index 15d6b7ab20ee..6199be81aa6b 100644 --- a/dpnp/backend/src/dpnp_fptr.hpp +++ b/dpnp/backend/src/dpnp_fptr.hpp @@ -38,6 +38,7 @@ #include #include #include +#include #include @@ -104,17 +105,6 @@ template constexpr auto both_types_are_same = std::conjunction_v, are_same>; -/** - * @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 -using dpnp_remove_cvref_t = - typename std::remove_cv_t>; - /** * @brief "<" comparison with complex types support. * @@ -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, std::complex>) { bool ret = false; _Xp a = std::forward<_Xp>(__x); diff --git a/dpnp/libtensor/AGENTS.md b/dpnp/libtensor/AGENTS.md index c6cec65c2044..4a729fb3c185 100644 --- a/dpnp/libtensor/AGENTS.md +++ b/dpnp/libtensor/AGENTS.md @@ -15,7 +15,7 @@ A new extension's `CMakeLists.txt` lists its sources and calls `build_dpnp_pybind11_ext( 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 (``, ``, ...), 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 (``, ``, ...), 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 &depends`, and return `std::pair` (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. diff --git a/examples/pybind11/use_dpnp_array/CMakeLists.txt b/examples/pybind11/use_dpnp_array/CMakeLists.txt index bcbe1748ef04..91b17efefc8d 100644 --- a/examples/pybind11/use_dpnp_array/CMakeLists.txt +++ b/examples/pybind11/use_dpnp_array/CMakeLists.txt @@ -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) set(CMAKE_CXX_STANDARD_REQUIRED ON) # Fetch pybind11