Class NDIterBufferManager
Buffer management for NDIter. Handles allocation, copy-in, and copy-out of iteration buffers.
public static class NDIterBufferManager
- Inheritance
-
NDIterBufferManager
- Inherited Members
Fields
Alignment
Required alignment for SIMD operations.
public const int Alignment = 64
Field Value
DefaultBufferSize
Default buffer size (number of elements).
public const long DefaultBufferSize = 8192
Field Value
Methods
AllocateAligned(long, NPTypeCode)
Allocate aligned buffer for an operand.
public static void* AllocateAligned(long elements, NPTypeCode dtype)
Parameters
elementslongdtypeNPTypeCode
Returns
- void*
AllocateBuffers(ref NDIterState, long)
Allocate buffers for all operands that need buffering.
Buffering criterion (NumPy nditer parity): an operand is buffered when it needs a CAST, when the user requested CONTIG, or when its memory is not a single linear walk across the whole (coalesced) iteration space (IsOperandIterLinear(ref NDIterState, int)). Linear operands — contiguous OR constant-stride 1-D views OR fully-broadcast scalars — stay unbuffered (BUFNEVER-style) and the kernel reads/writes the array directly through its true stride, which the Tier-3B kernels handle (incl. AVX2 gather).
For unbuffered operands, BufStrides is set to
the operand's TRUE inner-axis byte stride so that
GetInnerLoopByteStrides() exposes one consistent stride array to
kernels under BUFFER. (Buffered operands get the tight element size.)
public static bool AllocateBuffers(ref NDIterState state, long bufferSize)
Parameters
stateNDIterStatebufferSizelong
Returns
ComputeTransferSize(ref NDIterState)
Number of elements the next buffer fill should cover, from the iterator's current position. Capped at BufferSize; for multi-dim iterations the window ends on an inner-row boundary unless a single row exceeds the buffer (then a partial row is used).
public static long ComputeTransferSize(ref NDIterState state)
Parameters
stateNDIterState
Returns
CopyFromBuffer(ref NDIterState, int, long)
Copy data from buffer to operand (contiguous to strided). If operand needs casting, performs type conversion during copy. Runtime dtype dispatch version - handles any NumSharp dtype.
public static void CopyFromBuffer(ref NDIterState state, int op, long count)
Parameters
stateNDIterStateopintcountlong
CopyFromBufferWithCast(ref NDIterState, int, long)
Copy data from buffer to operand with type conversion.
public static void CopyFromBufferWithCast(ref NDIterState state, int op, long count)
Parameters
stateNDIterStateopintcountlong
CopyFromBuffer<T>(ref NDIterState, int, long)
Copy data from buffer to operand (contiguous to strided).
public static void CopyFromBuffer<T>(ref NDIterState state, int op, long count) where T : unmanaged
Parameters
stateNDIterStateopintcountlong
Type Parameters
T
CopyToBuffer(ref NDIterState, int, long)
Copy data from operand to buffer (strided to contiguous). If operand needs casting, performs type conversion during copy. Runtime dtype dispatch version - handles any NumSharp dtype.
public static void CopyToBuffer(ref NDIterState state, int op, long count)
Parameters
stateNDIterStateopintcountlong
CopyToBufferIfNeeded(ref NDIterState, int, long)
Copy data to buffer only if not reusable. Returns true if copy was performed, false if buffer was reused.
public static bool CopyToBufferIfNeeded(ref NDIterState state, int op, long count)
Parameters
stateNDIterStateopintcountlong
Returns
CopyToBufferWithCast(ref NDIterState, int, long)
Copy data from operand to buffer with type conversion.
public static void CopyToBufferWithCast(ref NDIterState state, int op, long count)
Parameters
stateNDIterStateopintcountlong
CopyToBuffer<T>(ref NDIterState, int, long)
Copy data from operand to buffer (strided to contiguous).
public static void CopyToBuffer<T>(ref NDIterState state, int op, long count) where T : unmanaged
Parameters
stateNDIterStateopintcountlong
Type Parameters
T
DetermineBufferSize(ref NDIterState, long)
Determine optimal buffer size based on array sizes and cache.
public static long DetermineBufferSize(ref NDIterState state, long requestedSize)
Parameters
stateNDIterStaterequestedSizelong
Returns
FillBufferWindow(ref NDIterState, long)
Fill all buffered READ operands from the iterator's current position
for count elements, record the array write-back
positions, swap buffered operands' DataPtrs to their buffers, and set
the window bookkeeping (BufTransferSize / BufIterEnd / BufFlushed).
public static void FillBufferWindow(ref NDIterState state, long count)
Parameters
stateNDIterStatecountlong
FlushBufferWindow(ref NDIterState)
Write the current window's buffered WRITE operands back to their arrays. Idempotent (BufFlushed) so iternext, the single-inner-loop fast paths, and Dispose can all call it.
public static void FlushBufferWindow(ref NDIterState state)
Parameters
stateNDIterState
FreeAligned(void*)
Free aligned buffer.
public static void FreeAligned(void* buffer)
Parameters
buffervoid*
FreeBuffers(ref NDIterState)
Free all allocated buffers.
public static void FreeBuffers(ref NDIterState state)
Parameters
stateNDIterState
InvalidateAllBuffers(ref NDIterState)
Invalidate all buffers (e.g., after Reset or GotoIterIndex).
public static void InvalidateAllBuffers(ref NDIterState state)
Parameters
stateNDIterState
InvalidateBuffer(ref NDIterState, int)
Clear buffer reusable flag (contents are no longer valid). Call this when the source data or iteration position changes.
public static void InvalidateBuffer(ref NDIterState state, int op)
Parameters
stateNDIterStateopint
IsBufferReusable(ref NDIterState, int)
Check if operand buffer can be reused (contents still valid).
public static bool IsBufferReusable(ref NDIterState state, int op)
Parameters
stateNDIterStateopint
Returns
IsOperandIterLinear(ref NDIterState, int)
True when the operand's memory positions form one arithmetic progression over the entire (coalesced) iteration space — i.e. a single 1-D walk at the inner stride covers every element in order. Contiguous operands, constant-stride 1-D views, and fully-broadcast (all-stride-0) operands qualify; genuinely multi-dimensional strided operands do not.
public static bool IsOperandIterLinear(ref NDIterState state, int op)
Parameters
stateNDIterStateopint
Returns
MarkBufferReusable(ref NDIterState, int)
Mark operand buffer as reusable (contents are still valid). Call this after CopyToBuffer when the source data hasn't changed.
public static void MarkBufferReusable(ref NDIterState state, int op)
Parameters
stateNDIterStateopint