|
EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
|
Backend-neutral GPU runtime API surface (CUDA or HIP). More...
Namespaces | |
| namespace | AlgorithmsDetail |
| The functors behind boundingBox() and bitonicSort(). | |
Classes | |
| struct | Ascending |
| The order operator< gives, as a trivially copyable functor callable on a device. More... | |
Typedefs | |
| using | Error = int |
Backend runtime error code (cudaError_t under CUDA, hipError_t under HIP). | |
| using | MemcpyKind = int |
Memory-copy direction (cudaMemcpyKind under CUDA, hipMemcpyKind under HIP). | |
| using | Stream = void * |
A stream of device work (cudaStream_t / hipStream_t). | |
| template<class Query , class In > | |
| using | TransformResult = std::decay_t< std::invoke_result_t< const Query &, const In & > > |
| The result type of a query on an input. | |
Functions | |
| uint32_t | exclusiveScanScratchSize (const uint32_t a_count) noexcept |
Scratch elements exclusiveScan() needs for a_count values: one per chunk, and one for the total. | |
| uint32_t | boundingBoxScratchSize (const uint32_t a_count) noexcept |
Scratch elements boundingBox() needs for a_count points: two corners per chunk. | |
| template<class T , class Source > | |
| BoundingVolumes::AABBT< T > | boundingBoxOf (const Source &a_points, const uint32_t a_count, Vec3T< T > *a_scratch) |
| The smallest box holding every point, from a source of points: one box per chunk of BoundingBoxChunk points, then one thread merging them. | |
| template<class T > | |
| BoundingVolumes::AABBT< T > | boundingBox (const Vec3T< T > *a_points, const uint32_t a_count, Vec3T< T > *a_scratch) |
| The smallest box holding an array of points; see boundingBoxOf(). | |
| template<class Key , class Less = Ascending> | |
| void | bitonicSort (Key *a_keys, const uint32_t a_count, const Less &a_less=Less()) |
Sort a_count keys in place with a bitonic network: log2(n) (log2(n) + 1) / 2 passes of n / 2 compare-exchanges each. | |
| uint32_t | exclusiveScan (uint32_t *a_values, const uint32_t a_count, uint32_t *a_scratch) |
Replace a_count values by their exclusive prefix sums, in place, and return their total: one sum per chunk of ScanChunk values, one thread scanning the sums, then each chunk scanned from its offset. | |
| template<class Source > | |
| void | mortonOrder (MemoryResource &a_where, const Source &a_source, PODSpan< uint32_t > a_order) |
| Write into a_order the order to run queries at a source's points in: the permutation of 0, ..., n - 1 (n = a_order.size()) that sorts the points along a Morton curve over their bounding box, ties broken by index. Runs on the device, with a bitonic sort, when a_where's memory is device-accessible in a CUDA or HIP build; on the host, with a sort, otherwise. Both give the same order, element for element. | |
| template<class Source > | |
| void | mortonOrder (const Pool &a_pool, const Source &a_source, PODVector< uint32_t > &a_order) |
| Write into a_order, an array in a_pool, the order to run queries at a source's points in; the span overload on a_pool's resource, for an order reserved in a pool. | |
| Error | memAlloc (void **a_devicePtr, size_t a_numBytes) noexcept |
Allocate device memory (cudaMalloc / hipMalloc). | |
| Error | memFree (void *a_devicePtr) noexcept |
Free device memory allocated with memAlloc (cudaFree / hipFree). | |
| Error | memAllocManaged (void **a_ptr, size_t a_numBytes) noexcept |
Allocate managed (unified) memory accessible from host and device (cudaMallocManaged / hipMallocManaged). | |
| Error | memAllocHost (void **a_ptr, size_t a_numBytes) noexcept |
Allocate page-locked (pinned) host memory (cudaHostAlloc / hipHostMalloc). | |
| Error | memAllocHostMapped (void **a_ptr, size_t a_numBytes) noexcept |
Allocate page-locked (pinned) host memory that is additionally mapped into the device address space for zero-copy access (cudaHostAlloc with cudaHostAllocMapped / hipHostMalloc with hipHostMallocMapped). Under unified virtual addressing the returned host pointer is directly valid on the device. Free with memFreeHost. | |
| Error | memFreeHost (void *a_ptr) noexcept |
Free page-locked host memory allocated with memAllocHost (cudaFreeHost / hipHostFree). | |
| Error | memcpy (void *a_dst, const void *a_src, size_t a_numBytes, MemcpyKind a_kind) noexcept |
Copy memory between host and device (cudaMemcpy / hipMemcpy). Synchronous. | |
| Error | getDeviceCount (int *a_count) noexcept |
Get the number of available GPU devices (cudaGetDeviceCount / hipGetDeviceCount). | |
| Error | streamCreateNonBlocking (Stream *a_stream) noexcept |
Create a stream that runs alongside the default stream rather than waiting for its work (cudaStreamCreateWithFlags / hipStreamCreateWithFlags with the non-blocking flag), for a copy made while a kernel on the default stream runs. Destroy it with streamDestroy. | |
| Error | streamDestroy (Stream a_stream) noexcept |
Destroy a stream (cudaStreamDestroy / hipStreamDestroy). | |
| Error | streamSynchronize (Stream a_stream) noexcept |
Wait until a stream's work is done (cudaStreamSynchronize / hipStreamSynchronize). | |
| Error | memcpyAsync (void *a_dst, const void *a_src, size_t a_numBytes, MemcpyKind a_kind, Stream a_stream) noexcept |
Copy memory between host and device on a stream, returning before the copy is done (cudaMemcpyAsync / hipMemcpyAsync); from pinned host memory, it does not wait for the host either. | |
| Error | getClockRate (int *a_kiloHertz) noexcept |
Get the current device's clock rate, the rate at which clock64() counts in a kernel (cudaDeviceGetAttribute with cudaDevAttrClockRate / hipDeviceGetAttribute with hipDeviceAttributeClockRate). | |
| Error | getLastError () noexcept |
Get and clear the last runtime error (cudaGetLastError / hipGetLastError). | |
| Error | deviceSynchronize () noexcept |
Block until the device has finished all preceding work (cudaDeviceSynchronize / hipDeviceSynchronize). | |
| const char * | getErrorString (Error a_error) noexcept |
Get the human-readable description of an error code (cudaGetErrorString / hipGetErrorString). | |
| bool | isShutdownError (Error a_error) noexcept |
True for the errors a runtime call returns once the runtime has shut down at program exit (cudaErrorCudartUnloading or cudaErrorContextIsDestroyed under CUDA, hipErrorDeinitialized or hipErrorContextIsDestroyed under HIP). | |
| const char * | getErrorHint (Error a_error) noexcept |
What to do about an error that means the binary has no code this GPU can run: the binary was built for another architecture, or carries only PTX that the driver, older than the toolkit, cannot compile (cudaErrorUnsupportedPtxVersion or cudaErrorNoKernelImageForDevice under CUDA, hipErrorNoBinaryForGpu under HIP). | |
| bool | deviceAvailable () noexcept |
| Whether a GPU is visible to the runtime. | |
| MemoryResource & | memoryResource () noexcept |
| The memory a query's data must live in for parallelFor() and transform() to read it. | |
| template<unsigned int BlockSize = DefaultBlockSize, unsigned int MinResidentThreads = DefaultMinResidentThreads, class F > | |
| 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. | |
| template<unsigned int BlockSize = DefaultBlockSize, unsigned int MinResidentThreads = DefaultMinResidentThreads, class Query , class In , class Out > | |
| 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. | |
| template<unsigned int BlockSize = DefaultBlockSize, unsigned int MinResidentThreads = DefaultMinResidentThreads, class Query , class In , class Out > | |
| void | transform (const Query &a_query, const Pool &a_pool, const PODVector< In > &a_in, const PODVector< Out > &a_out) |
| Run a query on every input of a pool-resident array, writing the results into another array in the same pool: out[i] = a_query(in[i]), with no allocation and no copies. | |
| template<unsigned int BlockSize = DefaultBlockSize, unsigned int MinResidentThreads = DefaultMinResidentThreads, class Query , class In , class Out > | |
| void | transform (const Query &a_query, const std::vector< In > &a_in, std::vector< Out > &a_out) |
| Run a query on every input, from host memory to host memory: a_out[i] = a_query(a_in[i]). | |
| template<unsigned int BlockSize = DefaultBlockSize, unsigned int MinResidentThreads = DefaultMinResidentThreads, class F > | |
| void | parallelFor (uint32_t a_n, const F &a_f, PODSpan< const uint32_t > a_order) |
| Run a functor on every index, in a given order: a_f(a_order[i]) for i = 0, ..., a_n - 1. | |
| template<unsigned int BlockSize = DefaultBlockSize, unsigned int MinResidentThreads = DefaultMinResidentThreads, class Query , class In , class Out > | |
| void | transform (const Query &a_query, PODSpan< In > a_in, PODSpan< Out > a_out, PODSpan< const uint32_t > a_order) |
| Run a query on every input in a given order: a_out[o] = a_query(a_in[o]) for o = a_order[i], i = 0, 1, ... | |
| template<unsigned int BlockSize = DefaultBlockSize, unsigned int MinResidentThreads = DefaultMinResidentThreads, class Query , class In , class Out > | |
| void | transform (const Query &a_query, const Pool &a_pool, const PODVector< In > &a_in, const PODVector< Out > &a_out, const PODVector< uint32_t > &a_order) |
| Run a query on every input of a pool-resident array in a given order, writing the results into another array in the same pool: out[o] = a_query(in[o]) for o = order[i]. | |
| template<unsigned int BlockSize = DefaultBlockSize, unsigned int MinResidentThreads = DefaultMinResidentThreads, class Query , class In , class Out > | |
| void | transform (const Query &a_query, const std::vector< In > &a_in, std::vector< Out > &a_out, const std::vector< uint32_t > &a_order) |
| Run a query on every input in a given order, from host memory to host memory: a_out[o] = a_query(a_in[o]) for o = a_order[i]. | |
Variables | |
| constexpr uint32_t | ScanChunk = 256 |
| Values per chunk in exclusiveScan()'s passes. | |
| constexpr uint32_t | BoundingBoxChunk = 256 |
| Points per chunk in boundingBox()'s first pass. | |
| constexpr Error | Success = 0 |
Success value of Error (cudaSuccess / hipSuccess). | |
| constexpr MemcpyKind | MemcpyHostToDevice = 1 |
Host-to-device copy direction (cudaMemcpyHostToDevice / hipMemcpyHostToDevice). | |
| constexpr MemcpyKind | MemcpyDeviceToHost = 2 |
Device-to-host copy direction (cudaMemcpyDeviceToHost / hipMemcpyDeviceToHost). | |
| constexpr MemcpyKind | MemcpyDeviceToDevice = 3 |
Device-to-device copy direction (cudaMemcpyDeviceToDevice / hipMemcpyDeviceToDevice). | |
| constexpr bool | enabled = false |
| Whether this translation unit is compiled as CUDA or HIP, so that parallelFor() and transform() run a kernel. | |
| constexpr const char * | backendName = "host" |
| Where parallelFor() and transform() run in this translation unit: "HIP", "CUDA" or "host". | |
| constexpr unsigned int | DefaultBlockSize = 128 |
| The number of threads per block a launch uses unless it is given another. | |
| constexpr unsigned int | DefaultMinResidentThreads = 384 |
| The threads a launch asks the CUDA compiler to keep resident on each multiprocessor, at least, unless it is given another: 384, three blocks of 128, which holds a thread to at most 168 registers. | |
Backend-neutral GPU runtime API surface (CUDA or HIP).
Thin aliases and inline forwarders over the backend runtime (cuda* under CUDA, hip* under HIP) covering exactly the surface EBGeometry uses: memory allocation/copy/free, device enumeration, error retrieval, and synchronization. The two runtimes mirror each other's signatures 1:1 for this surface, so every wrapper is a one-line forwarder.
| using EBGeometry::GPU::TransformResult = typedef std::decay_t<std::invoke_result_t<const Query&, const In&> > |
The result type of a query on an input.
| Query | Query functor type. |
| In | Input type. |
|
inline |
Sort a_count keys in place with a bitonic network: log2(n) (log2(n) + 1) / 2 passes of n / 2 compare-exchanges each.
Not stable, so for a reproducible result a_less must order every pair of distinct keys. Pad an arbitrary count up to a power of two with keys that sort last. Aborts, in every build, if a_count is not a power of two.
| Key | Trivially copyable key type. |
| Less | Trivially copyable strict order with an EBGEOMETRY_HOST_DEVICE call operator. |
| [in,out] | a_keys | The keys. |
| [in] | a_count | Number of keys: a power of two, or zero. |
| [in] | a_less | The order. |
|
inline |
The smallest box holding an array of points; see boundingBoxOf().
| T | Precision. |
| [in] | a_points | The points, which the launches can read. |
| [in] | a_count | Number of points. |
| [out] | a_scratch | boundingBoxScratchSize(a_count) elements of scratch, which the launches can write. |
|
inline |
The smallest box holding every point, from a source of points: one box per chunk of BoundingBoxChunk points, then one thread merging them.
The minimum and maximum are exact, so the box is the one a host loop over the points finds. The source is any trivially copyable functor whose const call operator returns point i, callable where the launches run. The result is copied back from a_scratch to the host (from device memory in a CUDA or HIP build). If a point has a non-finite coordinate, a corner of the box is not finite: check it, since the launches check nothing else.
| T | Precision. |
| Source | Source type. |
| [in] | a_points | The points. |
| [in] | a_count | Number of points. |
| [out] | a_scratch | boundingBoxScratchSize(a_count) elements of scratch, which the launches can write. |
|
inlinenoexcept |
Scratch elements boundingBox() needs for a_count points: two corners per chunk.
| [in] | a_count | Number of points. |
|
inlinenoexcept |
Whether a GPU is visible to the runtime.
Always false in a host build. In a CUDA or HIP build, false also when the runtime itself reports an error (no driver, for instance) rather than a device count.
|
inlinenoexcept |
Block until the device has finished all preceding work (cudaDeviceSynchronize / hipDeviceSynchronize).
|
inline |
Replace a_count values by their exclusive prefix sums, in place, and return their total: one sum per chunk of ScanChunk values, one thread scanning the sums, then each chunk scanned from its offset.
Integer sums in a fixed order, so the result does not depend on thread scheduling. The values and the scratch must be memory the launches can reach; the total is copied back to the host (from device memory in a CUDA or HIP build).
| [in,out] | a_values | The values. |
| [in] | a_count | Number of values. |
| [out] | a_scratch | exclusiveScanScratchSize(a_count) elements of scratch, which the launches can write. |
|
inlinenoexcept |
Scratch elements exclusiveScan() needs for a_count values: one per chunk, and one for the total.
| [in] | a_count | Number of values. |
|
inlinenoexcept |
Get the current device's clock rate, the rate at which clock64() counts in a kernel (cudaDeviceGetAttribute with cudaDevAttrClockRate / hipDeviceGetAttribute with hipDeviceAttributeClockRate).
| [out] | a_kiloHertz | Receives the clock rate in kHz. |
|
inlinenoexcept |
|
inlinenoexcept |
What to do about an error that means the binary has no code this GPU can run: the binary was built for another architecture, or carries only PTX that the driver, older than the toolkit, cannot compile (cudaErrorUnsupportedPtxVersion or cudaErrorNoKernelImageForDevice under CUDA, hipErrorNoBinaryForGpu under HIP).
| [in] | a_error | Backend error code. |
|
inlinenoexcept |
Get the human-readable description of an error code (cudaGetErrorString / hipGetErrorString).
| [in] | a_error | Backend error code. |
|
inlinenoexcept |
Get and clear the last runtime error (cudaGetLastError / hipGetLastError).
|
inlinenoexcept |
True for the errors a runtime call returns once the runtime has shut down at program exit (cudaErrorCudartUnloading or cudaErrorContextIsDestroyed under CUDA, hipErrorDeinitialized or hipErrorContextIsDestroyed under HIP).
| [in] | a_error | Backend error code. |
a_error is one of those errors.
|
inlinenoexcept |
Allocate device memory (cudaMalloc / hipMalloc).
| [out] | a_devicePtr | Receives the device pointer to the allocation. |
| [in] | a_numBytes | Number of bytes to allocate. |
|
inlinenoexcept |
Allocate page-locked (pinned) host memory (cudaHostAlloc / hipHostMalloc).
| [out] | a_ptr | Receives the host pointer to the pinned allocation. |
| [in] | a_numBytes | Number of bytes to allocate. |
|
inlinenoexcept |
Allocate page-locked (pinned) host memory that is additionally mapped into the device address space for zero-copy access (cudaHostAlloc with cudaHostAllocMapped / hipHostMalloc with hipHostMallocMapped). Under unified virtual addressing the returned host pointer is directly valid on the device. Free with memFreeHost.
| [out] | a_ptr | Receives the host pointer to the mapped pinned allocation. |
| [in] | a_numBytes | Number of bytes to allocate. |
|
inlinenoexcept |
Allocate managed (unified) memory accessible from host and device (cudaMallocManaged / hipMallocManaged).
| [out] | a_ptr | Receives the managed pointer to the allocation. |
| [in] | a_numBytes | Number of bytes to allocate. |
|
inlinenoexcept |
Copy memory between host and device (cudaMemcpy / hipMemcpy). Synchronous.
| [out] | a_dst | Destination pointer (host or device, per a_kind). |
| [in] | a_src | Source pointer (host or device, per a_kind). |
| [in] | a_numBytes | Number of bytes to copy. |
| [in] | a_kind | Copy direction. |
|
inlinenoexcept |
Copy memory between host and device on a stream, returning before the copy is done (cudaMemcpyAsync / hipMemcpyAsync); from pinned host memory, it does not wait for the host either.
| [out] | a_dst | Destination pointer (host or device, per a_kind). |
| [in] | a_src | Source pointer (host or device, per a_kind). |
| [in] | a_numBytes | Number of bytes to copy. |
| [in] | a_kind | Copy direction. |
| [in] | a_stream | The stream. |
|
inlinenoexcept |
|
inlinenoexcept |
Free page-locked host memory allocated with memAllocHost (cudaFreeHost / hipHostFree).
| [in] | a_ptr | Host pointer to free (null is a no-op). |
|
inlinenoexcept |
The memory a query's data must live in for parallelFor() and transform() to read it.
deviceMemoryResource() in a CUDA or HIP build, and emulatedDeviceMemoryResource() (host memory that reports itself device-accessible) otherwise. Mirroring a frozen pool into it and taking a rebasedView() onto the mirror is then the same code in both builds: a device copy that a kernel reads, or a host copy that the host loop reads.
|
inline |
Write into a_order, an array in a_pool, the order to run queries at a source's points in; the span overload on a_pool's resource, for an order reserved in a pool.
See the span overload for the order, the source and where it runs. a_pool may be frozen (a mirror), since nothing is reserved in it. Aborts with a message unless a_order lies within a_pool's used bytes, and in the cases the span overload aborts in.
| Source | Source of the points. |
| [in] | a_pool | The pool holding a_order; its resource decides where the order is computed. |
| [in] | a_source | The points. |
| [out] | a_order | The order, one entry per point, in a_pool. |
|
inline |
Write into a_order the order to run queries at a source's points in: the permutation of 0, ..., n - 1 (n = a_order.size()) that sorts the points along a Morton curve over their bounding box, ties broken by index. Runs on the device, with a bitonic sort, when a_where's memory is device-accessible in a CUDA or HIP build; on the host, with a sort, otherwise. Both give the same order, element for element.
Queries that arrive in no spatial order make neighboring threads walk unrelated parts of a BVH or a mesh. Run in this order (the ordered GPU::parallelFor() and GPU::transform()), nearby points run side by side, share cache lines and diverge less, while every result still lands at its own index. That pays for queries that read memory (BVHs, meshes, point clouds), not for an analytic shape, whose distance reads none. The order depends on the points only: compute it once and reuse it while they stay put. Any permutation works with the ordered launches, so a caller with its own space-filling curve or sort can pass its own order instead; this is a convenience.
The points come from a source: a trivially copyable functor whose const call operator takes an index (uint32_t) and returns that point's Vec3T (PointCloud::FromArray wraps an array), so a struct of particles needs no copy into points first. The source and a_order are used where a_where's memory is, so they must be readable (and a_order writable) there: device or managed memory for a device-accessible a_where, host memory otherwise. This is not checked.
Scratch, a 16-byte key per point (on a device rounded up to a power of two) and a few bytes for the box, is allocated on a_where and released before returning. Aborts with a message unless n is at most 2^31 and every point is finite.
| Source | Source of the points. |
| [in] | a_where | The resource whose memory decides where the order is computed, and which holds the scratch. |
| [in] | a_source | The points. |
| [out] | a_order | The order, one entry per point. |
|
inline |
Run a functor on every index: a_f(i) for i = 0, ..., a_n - 1, in no particular order.
In a CUDA or HIP build, a kernel runs the functor once per index (one thread each, in blocks of BlockSize threads) on the current device, and the call returns once it has finished. Every runtime call is checked with EBGEOMETRY_GPU_CHECK, which aborts with the failing call on an error, and a visible device is required (see deviceAvailable()). The functor reaches the kernel by value, so anything it reads or writes must be memory the device can access.
In a host build the functor is copied once, as a kernel launch would copy it, and run in a loop. The functor must be trivially copyable in both builds, which is checked at compile time. A grid holds at most 2^31 - 1 blocks, so a_n may not exceed (2^31 - 1) * BlockSize; a larger count aborts with a message, in both builds.
| BlockSize | Threads per block: a multiple of 64 (an AMD wavefront, and two NVIDIA warps), at most 1024. The kernel carries it as launch bounds, so the compiler can give each thread the registers that block size allows. |
| MinResidentThreads | In a CUDA build, the threads to keep resident on a multiprocessor, at least, which fixes the register budget (see DefaultMinResidentThreads); at most 2048, 0 for no minimum. |
| F | Trivially copyable functor with an EBGEOMETRY_HOST_DEVICE call operator taking a std::size_t. |
| [in] | a_n | Number of indices. |
| [in] | a_f | The functor. |
|
inline |
Run a functor on every index, in a given order: a_f(a_order[i]) for i = 0, ..., a_n - 1.
parallelFor() with the indices taken through a permutation, so that neighboring threads (a warp on a device, consecutive iterations on the host) run indices the caller knows to be close: mortonOrder() gives one that puts queries at nearby points side by side, so that they walk the same parts of a BVH. Every index still runs once, and the functor sees the index itself, not its position in the order, so its results land where the unordered parallelFor() puts them: only the speed changes. The order must be a permutation of 0, ..., a_n - 1, in memory the launch can read; its size is checked (it aborts with a message otherwise), each entry is checked to be below a_n with assertions on, and that no entry repeats is the caller's responsibility (a repeated index would run twice, and another not at all). An order is worth computing once and reusing while the points stay put.
| BlockSize | Threads per block; see parallelFor(). |
| MinResidentThreads | Threads to keep resident, in a CUDA build; see parallelFor(). |
| F | Trivially copyable functor with an EBGEOMETRY_HOST_DEVICE call operator taking a std::size_t. |
| [in] | a_n | Number of indices. |
| [in] | a_f | The functor. |
| [in] | a_order | The order: a_n indices, a permutation of 0, ..., a_n - 1. |
Create a stream that runs alongside the default stream rather than waiting for its work (cudaStreamCreateWithFlags / hipStreamCreateWithFlags with the non-blocking flag), for a copy made while a kernel on the default stream runs. Destroy it with streamDestroy.
| [out] | a_stream | Receives the stream. |
Destroy a stream (cudaStreamDestroy / hipStreamDestroy).
| [in] | a_stream | The stream. |
Wait until a stream's work is done (cudaStreamSynchronize / hipStreamSynchronize).
| [in] | a_stream | The stream. |
|
inline |
Run a query on every input of a pool-resident array, writing the results into another array in the same pool: out[i] = a_query(in[i]), with no allocation and no copies.
The span overload, with the memory checked first. A PODVector is an offset into a pool, so this overload takes the pool both arrays live in and binds them against its base. It aborts with a message, in every build, unless the pool is frozen (as rebasedView() requires of a device-accessible pool) and its resource is device-accessible: a mirror into memoryResource(), or a pool built in managed memory. A pool in hostMemoryResource() is therefore rejected in a host build too, where memoryResource() is the emulated device resource. A PODVector holds an offset, not its pool, so membership can be checked only as far as both arrays ending inside the pool's used bytes, which also aborts otherwise; that an array really belongs to this pool (or a mirror of its pool) is the caller's responsibility. The inputs are bound read-only. Freezing forbids reservations, not writes, so the results can be written into a frozen pool, in place over the inputs or into a disjoint array as for the span overload. Arrays in two different pools, or not in a pool at all, go through the span overload.
| BlockSize | Threads per block; see parallelFor(). |
| MinResidentThreads | Threads to keep resident, in a CUDA build; see parallelFor(). |
| Query | Trivially copyable functor with an EBGEOMETRY_HOST_DEVICE call operator taking a const In&. |
| In | Input type. |
| Out | Result type: the query's result type. |
| [in] | a_query | The query. |
| [in] | a_pool | The frozen, device-accessible pool holding both arrays. |
| [in] | a_in | The inputs. |
| [in] | a_out | The results' array, as many elements as a_in; its elements are written. |
|
inline |
Run a query on every input of a pool-resident array in a given order, writing the results into another array in the same pool: out[o] = a_query(in[o]) for o = order[i].
The pool transform() with the order of the ordered span overload: the pool is checked as there, the order is a third array in the same pool, and the inputs and the results must not overlap.
| BlockSize | Threads per block; see parallelFor(). |
| MinResidentThreads | Threads to keep resident, in a CUDA build; see parallelFor(). |
| Query | Trivially copyable functor with an EBGEOMETRY_HOST_DEVICE call operator taking a const In&. |
| In | Input type. |
| Out | Result type: the query's result type. |
| [in] | a_query | The query. |
| [in] | a_pool | The frozen, device-accessible pool holding the three arrays. |
| [in] | a_in | The inputs. |
| [in] | a_out | The results' array, as many elements as a_in, not overlapping it; its elements are written. |
| [in] | a_order | The order: as many entries as a_in, a permutation of their indices. |
|
inline |
Run a query on every input, from host memory to host memory: a_out[i] = a_query(a_in[i]).
A convenience over the span overload. In a CUDA or HIP build it allocates device memory for the inputs and the results, copies the inputs in, runs the query in a kernel, copies the results into a_out and frees, so timing it includes two allocations and two copies; time the span or pool overload to measure the query itself. In a host build the query runs in a loop directly on the vectors. a_out is not resized: it must already hold as many elements as a_in, which aborts with a message otherwise, and can be reused across calls. At most 2^32 - 1 inputs, which also aborts with a message otherwise. Neither the input nor the result may be bool (std::vector<bool> has no contiguous storage to copy), which is checked at compile time in both builds.
| BlockSize | Threads per block; see parallelFor(). |
| MinResidentThreads | Threads to keep resident, in a CUDA build; see parallelFor(). |
| Query | Trivially copyable functor with an EBGEOMETRY_HOST_DEVICE call operator taking a const In&. |
| In | Trivially copyable input type. |
| Out | Result type: the query's result type. |
| [in] | a_query | The query. |
| [in] | a_in | The inputs. |
| [out] | a_out | The results, in input order; as many elements as a_in. |
|
inline |
Run a query on every input in a given order, from host memory to host memory: a_out[o] = a_query(a_in[o]) for o = a_order[i].
The std::vector transform() with the order of the ordered span overload; in a CUDA or HIP build the order is copied to the device with the inputs.
| BlockSize | Threads per block; see parallelFor(). |
| MinResidentThreads | Threads to keep resident, in a CUDA build; see parallelFor(). |
| Query | Trivially copyable functor with an EBGEOMETRY_HOST_DEVICE call operator taking a const In&. |
| In | Trivially copyable input type. |
| Out | Result type: the query's result type. |
| [in] | a_query | The query. |
| [in] | a_in | The inputs. |
| [out] | a_out | The results, in input order; as many elements as a_in. |
| [in] | a_order | The order (mortonOrder(), say): as many entries as a_in, a permutation of their indices. |
|
inline |
Run a query on every input in place: a_out[i] = a_query(a_in[i]), with no allocation and no copies.
The inputs and the results stay wherever the caller put them, so this is the call to time when a query's cost is what is being measured, and the one to use for repeated queries over the same points. A span is a pointer and a count: bind a PODVector against the base of a pool mirrored into memoryResource() (inputs) or of a pool reserved there (results), or wrap managed memory or a buffer the application already owns on the device. In a host build the spans are host memory. The results may overwrite the inputs in place (the same array, when In and Out are the same type), but the two must otherwise not overlap, which aborts with a message. The query runs through parallelFor(), with its requirements.
| BlockSize | Threads per block; see parallelFor(). |
| MinResidentThreads | Threads to keep resident, in a CUDA build; see parallelFor(). |
| Query | Trivially copyable functor with an EBGEOMETRY_HOST_DEVICE call operator taking a const In&. |
| In | Input type, const or not. |
| Out | Result type: the query's result type, not const. |
| [in] | a_query | The query. |
| [in] | a_in | The inputs, in memory the device can read. |
| [out] | a_out | The results, in memory the device can write; as many as there are inputs. |
|
inline |
Run a query on every input in a given order: a_out[o] = a_query(a_in[o]) for o = a_order[i], i = 0, 1, ...
The span transform() run through the ordered parallelFor(), with its requirements on the order: every result lands where the unordered transform() puts it, and only the speed changes. Unlike the unordered overload, the results may not overwrite the inputs in place, since a thread could then overwrite an input that another thread has not read yet: the inputs and the results must not overlap, which aborts with a message otherwise.
| BlockSize | Threads per block; see parallelFor(). |
| MinResidentThreads | Threads to keep resident, in a CUDA build; see parallelFor(). |
| Query | Trivially copyable functor with an EBGEOMETRY_HOST_DEVICE call operator taking a const In&. |
| In | Input type, const or not. |
| Out | Result type: the query's result type, not const. |
| [in] | a_query | The query. |
| [in] | a_in | The inputs, in memory the device can read. |
| [out] | a_out | The results, in memory the device can write; as many as there are inputs, not overlapping them. |
| [in] | a_order | The order (mortonOrder(), say): as many entries as inputs, a permutation of their indices. |
|
inlineconstexpr |
The number of threads per block a launch uses unless it is given another.
Not tuned: the best block size depends on the device and on the query (a BVH traversal uses many registers per thread). Pass another as the first template argument to measure it, e.g. GPU::transform<256>(query, points, results).
|
inlineconstexpr |
The threads a launch asks the CUDA compiler to keep resident on each multiprocessor, at least, unless it is given another: 384, three blocks of 128, which holds a thread to at most 168 registers.
The kernel carries it as launch bounds (a minimum number of resident blocks, rounded up). Without a minimum, the compiler picks one register budget for the whole kernel, every function it calls included, and the pick jumps with small changes to code the kernel may not even run (a tape's ray kernel once went from 255 registers to 40, spilling twice as much); given one, it uses the budget the minimum allows. Not tuned for every query: the budget is a ceiling the compiler tends to fill, so a kernel that runs best with few registers may be slower under it (rays traced through a fused composition went from 56 registers to 161 and ran up to a third slower, and the renderer's frame of a mesh from 128 to 161, 10% slower). The minimum still pays where registers matter: on one desktop GPU, ray tracing through a tape took 2.5 times as long with no minimum as at 384, and 1.45 times as long at 768, while a mesh's signed distance took the same time at every setting; DeviceTuning's mesh-minus-ball tape distance in float was a fifth to a quarter faster at 768 than at 384, whatever the block size. 0 asks for no minimum. HIP reads a second launch bound differently, and a HIP build ignores it.