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: BSD-3-Clause
4
42#ifndef EBGEOMETRY_GPUTRANSFORM_HPP
43#define EBGEOMETRY_GPUTRANSFORM_HPP
44
45// Std includes
46#include <cstddef>
47#include <cstdint>
48#include <type_traits>
49#include <vector>
50
51// Our includes
52#include "EBGeometry_GPU.hpp"
56
57namespace EBGeometry {
58namespace GPU {
59
64#if defined(EBGEOMETRY_CUDA) || defined(EBGEOMETRY_HIP)
65inline constexpr bool enabled = true;
66#else
67inline constexpr bool enabled = false;
68#endif
69
73#if defined(EBGEOMETRY_HIP)
74inline constexpr const char* backendName = "HIP";
75#elif defined(EBGEOMETRY_CUDA)
76inline constexpr const char* backendName = "CUDA";
77#else
78inline constexpr const char* backendName = "host";
79#endif
80
87inline constexpr unsigned int DefaultBlockSize = 128;
88
104inline constexpr unsigned int DefaultMinResidentThreads = 384;
105
112[[nodiscard]] EBGEOMETRY_HOST
113inline bool
115
124[[nodiscard]] EBGEOMETRY_HOST
125inline MemoryResource&
126memoryResource() noexcept;
127
133template <class Query, class In>
134using TransformResult = std::decay_t<std::invoke_result_t<const Query&, const In&>>;
135
158template <unsigned int BlockSize = DefaultBlockSize,
159 unsigned int MinResidentThreads = DefaultMinResidentThreads,
160 class F>
162inline void
163parallelFor(std::size_t a_n, const F& a_f);
164
186template <unsigned int BlockSize = DefaultBlockSize,
187 unsigned int MinResidentThreads = DefaultMinResidentThreads,
188 class Query,
189 class In,
190 class Out>
192inline void
193transform(const Query& a_query, PODSpan<In> a_in, PODSpan<Out> a_out);
194
221template <unsigned int BlockSize = DefaultBlockSize,
222 unsigned int MinResidentThreads = DefaultMinResidentThreads,
223 class Query,
224 class In,
225 class Out>
227inline void
228transform(const Query& a_query, const Pool& a_pool, const PODVector<In>& a_in, const PODVector<Out>& a_out);
229
251template <unsigned int BlockSize = DefaultBlockSize,
252 unsigned int MinResidentThreads = DefaultMinResidentThreads,
253 class Query,
254 class In,
255 class Out>
257inline void
258transform(const Query& a_query, const std::vector<In>& a_in, std::vector<Out>& a_out);
259
278template <unsigned int BlockSize = DefaultBlockSize,
279 unsigned int MinResidentThreads = DefaultMinResidentThreads,
280 class F>
282inline void
283parallelFor(uint32_t a_n, const F& a_f, PODSpan<const uint32_t> a_order);
284
302template <unsigned int BlockSize = DefaultBlockSize,
303 unsigned int MinResidentThreads = DefaultMinResidentThreads,
304 class Query,
305 class In,
306 class Out>
308inline void
309transform(const Query& a_query, PODSpan<In> a_in, PODSpan<Out> a_out, PODSpan<const uint32_t> a_order);
310
328template <unsigned int BlockSize = DefaultBlockSize,
329 unsigned int MinResidentThreads = DefaultMinResidentThreads,
330 class Query,
331 class In,
332 class Out>
334inline void
335transform(const Query& a_query,
336 const Pool& a_pool,
337 const PODVector<In>& a_in,
338 const PODVector<Out>& a_out,
339 const PODVector<uint32_t>& a_order);
340
357template <unsigned int BlockSize = DefaultBlockSize,
358 unsigned int MinResidentThreads = DefaultMinResidentThreads,
359 class Query,
360 class In,
361 class Out>
363inline void
364transform(const Query& a_query,
365 const std::vector<In>& a_in,
366 std::vector<Out>& a_out,
367 const std::vector<uint32_t>& a_order);
368
369} // namespace GPU
370} // namespace EBGeometry
371
372#include "EBGeometry_GPUTransformImplem.hpp"
373
374#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:205
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:67
constexpr const char * backendName
Where parallelFor() and transform() run in this translation unit: "HIP", "CUDA" or "host".
Definition EBGeometry_GPUTransform.hpp:78
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:134
constexpr unsigned int DefaultMinResidentThreads
The threads a launch asks the CUDA compiler to keep resident on each multiprocessor,...
Definition EBGeometry_GPUTransform.hpp:104
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:87
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:131