dispenso 1.4.1
A library for task parallelism
Loading...
Searching...
No Matches
util.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
18#pragma once
19
20#include <dispenso/detail/math.h>
21#include <dispenso/detail/op_result.h>
22#include <dispenso/platform.h>
23
24namespace dispenso {
25
46inline void* alignedMalloc(size_t bytes, size_t alignment) {
47 return detail::alignedMalloc(bytes, alignment);
48}
49
62inline void* alignedMalloc(size_t bytes) {
63 return detail::alignedMalloc(bytes);
64}
65
73inline void alignedFree(void* ptr) {
74 detail::alignedFree(ptr);
75}
76
92template <typename T>
93using AlignedDeleter = detail::AlignedFreeDeleter<T>;
94
111inline constexpr uintptr_t alignToCacheLine(uintptr_t val) {
112 return detail::alignToCacheLine(val);
113}
114
131inline void cpuRelax() {
132 detail::cpuRelax();
133}
134
151constexpr uint64_t nextPow2(uint64_t v) {
152 return detail::nextPow2(v);
153}
154
172constexpr inline uint32_t log2const(uint64_t v) {
173 return detail::log2const(v);
174}
175
193inline uint32_t log2(uint64_t v) {
194 return detail::log2(v);
195}
196
212template <typename T>
213using AlignedBuffer = detail::AlignedBuffer<T>;
214
229template <typename T>
230using AlignedAtomic = detail::AlignedAtomic<T>;
231
254template <typename T>
255using OpResult = detail::OpResult<T>;
256
264using StaticChunking = detail::StaticChunking;
265
284inline StaticChunking staticChunkSize(ssize_t items, ssize_t chunks) {
285 return detail::staticChunkSize(items, chunks);
286}
287
288} // namespace dispenso
detail::OpResult< T > OpResult
Optional-like storage with in-place construction (C++14 compatible).
Definition pipeline.h:30
detail::AlignedAtomic< T > AlignedAtomic
Cache-line aligned atomic pointer.
Definition util.h:230
detail::AlignedFreeDeleter< T > AlignedDeleter
Deleter for smart pointers that use aligned memory allocation.
Definition util.h:93
detail::AlignedBuffer< T > AlignedBuffer
Buffer with proper alignment for type T.
Definition util.h:213
detail::StaticChunking StaticChunking
Information for statically chunking a range across threads.
Definition util.h:264
constexpr uint32_t log2const(uint64_t v)
Compute log base 2 of a value (compile-time).
Definition util.h:172
uint32_t log2(uint64_t v)
Compute log base 2 of a value (runtime).
Definition util.h:193
constexpr uint64_t nextPow2(uint64_t v)
Round up to the next power of 2.
Definition util.h:151