From e2f7e3d7bb84412f7a953b44d9c2eeb5c6f4b00d Mon Sep 17 00:00:00 2001 From: Giulio Eulisse <10544+ktf@users.noreply.github.com> Date: Mon, 23 Nov 2026 15:45:00 +0100 Subject: [PATCH] GPU: provide the layout type traits on all device backends, numeric_limits for Metal OpenCL C++ and MSL have no , so GPUCommonTypeTraits now provides is_standard_layout_v and is_trivially_copyable_v for both, spelled like its other program-scope variables. numeric_limits is not a type trait, so it gets its own GPUCommonNumericLimits.h, with the same backend selection: on the host, CUDA and HIP, metal::numeric_limits as std::numeric_limits for Metal, nothing yet for OpenCL. --- GPU/Common/GPUCommonNumericLimits.h | 32 +++++++++++++++++++++++++++++ GPU/Common/GPUCommonTypeTraits.h | 4 ++++ 2 files changed, 36 insertions(+) create mode 100644 GPU/Common/GPUCommonNumericLimits.h diff --git a/GPU/Common/GPUCommonNumericLimits.h b/GPU/Common/GPUCommonNumericLimits.h new file mode 100644 index 0000000000000..050dd1324ea97 --- /dev/null +++ b/GPU/Common/GPUCommonNumericLimits.h @@ -0,0 +1,32 @@ +// Copyright 2019-2026 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +/// \file GPUCommonNumericLimits.h + +#ifndef GPUCOMMONNUMERICLIMITS_H +#define GPUCOMMONNUMERICLIMITS_H + +#include "GPUCommonDef.h" + +#if !defined(GPUCA_GPUCODE_DEVICE) || defined(__CUDACC__) || defined(__HIPCC__) // TODO: Get rid of this once std is available in all backends +#ifndef GPUCA_GPUCODE_COMPILEKERNELS +#include +#endif +#elif defined(__METAL__) // metal::numeric_limits comes with , which the Metal kernel source includes first +namespace std +{ +using metal::numeric_limits; +} // namespace std +#else +// Not supported yet for OpenCL / other backends +#endif + +#endif diff --git a/GPU/Common/GPUCommonTypeTraits.h b/GPU/Common/GPUCommonTypeTraits.h index 6d72f164771bc..ff73f8601d8ad 100644 --- a/GPU/Common/GPUCommonTypeTraits.h +++ b/GPU/Common/GPUCommonTypeTraits.h @@ -33,6 +33,10 @@ #endif namespace std { +template +GPUCA_TT_PROGRAMSCOPE static constexpr bool is_standard_layout_v = __is_standard_layout(T); +template +GPUCA_TT_PROGRAMSCOPE static constexpr bool is_trivially_copyable_v = __is_trivially_copyable(T); template struct conditional { typedef T type;