Deepity
Ultra-fast, SIMD-accelerated Predictive Coding
Loading...
Searching...
No Matches
Optimize.h File Reference

Defines useful optimization functions of a PC model. More...

#include <algorithm>
#include <cstddef>
#include <memory>
#include <vector>
#include <immintrin.h>
#include <omp.h>

Go to the source code of this file.

Namespaces

namespace  Deep
 This file exists to provide both Tensor.h and IComputeBackend.h with device types without introducing circular dependencies.

Functions

void openblas_set_num_threads (int num_threads)
 OpenBLAS's own thread-count setter, declared directly since OpenBLAS ships no public header for it in this build.
size_t Deep::GetL2CacheBytes ()
 Queries the size of this CPU's L2 cache (per-core, level 2), falling back to 512 KiB on platforms where it can't be queried.
size_t Deep::AutoBatchSize (size_t inSize, size_t outSize)
 Picks a batch size (a power of 2 clamped to [64, 512]) sized so a layer's weights plus one batch's activations fit within the L2 cache, for a size -> outSize transition.
static void Deep::DynamicThread (int batchSize) noexcept
 Sets OpenMP's (and the BLAS library's) thread count for the given batch size, memoized so it's a no-op if the target hasn't changed since the last call. Small batches get 1 thread (avoids parallelization overhead dominating tiny work); larger batches scale up to a measured, capped optimum – see the inline note on why 16 threads, not the full core count, is the ceiling.
static float Deep::hsum256_ps (__m256 x)
 Horizontal sum of all 8 lanes of an AVX2 register.
static float Deep::hsum128_ps (__m128 x)
 Horizontal sum of all 4 lanes of an SSE register.

Detailed Description

Defines useful optimization functions of a PC model.

This header currently only includes implementation of an L2 Cache size lookup.

size_t sizeofL2 = GetL2CacheBytes();
Defines useful optimization functions of a PC model.
Note
Separate versions exist for Windows VS. Linux.
Version
1.0
Date
2026-06-21
Author
Jack Rose

Function Documentation

◆ openblas_set_num_threads()

void openblas_set_num_threads ( int num_threads)

OpenBLAS's own thread-count setter, declared directly since OpenBLAS ships no public header for it in this build.