EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
EBGeometry_GPUTransform.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Robert Marskar <robert.marskar@sintef.no>
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
38#ifndef EBGEOMETRY_GPUTRANSFORM_HPP
39#define EBGEOMETRY_GPUTRANSFORM_HPP
40
41// Std includes
42#include <cstddef>
43#include <cstdint>
44#include <type_traits>
45#include <vector>
46
47// Our includes
48#include "EBGeometry_GPU.hpp"
52
53namespace EBGeometry {
54namespace GPU {
55
60#if defined(EBGEOMETRY_CUDA) || defined(EBGEOMETRY_HIP)
61inline constexpr bool enabled = true;
62#else
63inline constexpr bool enabled = false;
64#endif
65
69#if defined(EBGEOMETRY_HIP)
70inline constexpr const char* backendName = "HIP";
71#elif defined(EBGEOMETRY_CUDA)
72inline constexpr const char* backendName = "CUDA";
73#else
74inline constexpr const char* backendName = "host";
75#endif
76
83inline constexpr unsigned int DefaultBlockSize = 128;
84
100inline constexpr unsigned int DefaultMinResidentThreads = 384;
101
108[[nodiscard]] EBGEOMETRY_HOST
109inline bool
111
120[[nodiscard]] EBGEOMETRY_HOST
121inline MemoryResource&
122memoryResource() noexcept;
123
129template <class Query, class In>
130using TransformResult = std::decay_t<std::invoke_result_t<const Query&, const In&>>;
131
154template <unsigned int BlockSize = DefaultBlockSize,
155 unsigned int MinResidentThreads = DefaultMinResidentThreads,
156 class F>
158inline void
159parallelFor(std::size_t a_n, const F& a_f);
160
182template <unsigned int BlockSize = DefaultBlockSize,
183 unsigned int MinResidentThreads = DefaultMinResidentThreads,
184 class Query,
185 class In,
186 class Out>
188inline void
189transform(const Query& a_query, PODSpan<In> a_in, PODSpan<Out> a_out);
190
217template <unsigned int BlockSize = DefaultBlockSize,
218 unsigned int MinResidentThreads = DefaultMinResidentThreads,
219 class Query,
220 class In,
221 class Out>
223inline void
224transform(const Query& a_query, const Pool& a_pool, const PODVector<In>& a_in, const PODVector<Out>& a_out);
225
247template <unsigned int BlockSize = DefaultBlockSize,
248 unsigned int MinResidentThreads = DefaultMinResidentThreads,
249 class Query,
250 class In,
251 class Out>
253inline void
254transform(const Query& a_query, const std::vector<In>& a_in, std::vector<Out>& a_out);
255
256} // namespace GPU
257} // namespace EBGeometry
258
259#include "EBGeometry_GPUTransformImplem.hpp"
260
261#endif
Backend-neutral GPU runtime API layer (CUDA or HIP) plus the EBGEOMETRY_GPU_CHECK macro.
GPU portability layer: host/device decoration macros and backend detection.
#define EBGEOMETRY_HOST
Mark a function as callable from host code only (no-op on host compilers).
Definition EBGeometry_GPU.hpp:83
Placement-policy layer for the GPU memory foundation: the abstract MemoryResource and its concrete ho...
Placement-independent POD array views for the GPU memory foundation.
Abstract placement policy: allocates and frees raw, correctly-aligned byte blocks.
Definition EBGeometry_MemoryResource.hpp:69
Growable bump arena over a MemoryResource.
Definition EBGeometry_Pool.hpp:183
void parallelFor(std::size_t a_n, const F &a_f)
Run a functor on every index: a_f(i) for i = 0, ..., a_n - 1, in no particular order.
void transform(const Query &a_query, PODSpan< In > a_in, PODSpan< Out > a_out)
Run a query on every input in place: a_out[i] = a_query(a_in[i]), with no allocation and no copies.
constexpr bool enabled
Whether this translation unit is compiled as CUDA or HIP, so that parallelFor() and transform() run a...
Definition EBGeometry_GPUTransform.hpp:63
constexpr const char * backendName
Where parallelFor() and transform() run in this translation unit: "HIP", "CUDA" or "host".
Definition EBGeometry_GPUTransform.hpp:74
std::decay_t< std::invoke_result_t< const Query &, const In & > > TransformResult
The result type of a query on an input.
Definition EBGeometry_GPUTransform.hpp:130
constexpr unsigned int DefaultMinResidentThreads
The threads a launch asks the CUDA compiler to keep resident on each multiprocessor,...
Definition EBGeometry_GPUTransform.hpp:100
MemoryResource & memoryResource() noexcept
The memory a query's data must live in for parallelFor() and transform() to read it.
constexpr unsigned int DefaultBlockSize
The number of threads per block a launch uses unless it is given another.
Definition EBGeometry_GPUTransform.hpp:83
bool deviceAvailable() noexcept
Whether a GPU is visible to the runtime.
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_Affine.hpp:26
Raw pointer + size view into a Pool block, for hot inner loops.
Definition EBGeometry_PODVector.hpp:52
Placement-independent descriptor of a POD array inside a Pool.
Definition EBGeometry_PODVector.hpp:119