struct FeatureMap {
&heap float data;
unsigned long channels;
unsigned long height;
unsigned long width;
int fromArena;
}Fields
flat, channelsheightwidth, CHW order (data[cHW + h*W + w])
1 if data came from a TensorArena (FeatureMap::free leaves it)
Methods
= drop()
static struct FeatureMap new(
unsigned long channels,
unsigned long height,
unsigned long width,
)source · definitionBetween TensorArena::begin and tensor_arena_end (std/ml/tensor.h), new feature maps -- the ones these functions return, and every layer's intermediate inside UNet::forward and the like -- come from the thread's TensorArena, as tensors do: no malloc (or page faults, for fresh memory) per layer. FeatureMap::free does nothing for them; TensorArena::reset releases them all, so don't use one after its arena is reset.
Max/avg pooling: kernel x kernel window, given stride, no padding. Channel count is preserved; caller must choose dimensions divisible by the kernel/stride combination.
struct FeatureMap maxpool2d_ex(
unsigned long kernel,
unsigned long stride,
unsigned long padding,
) constsource · definitionThe same with 'padding' on every side; output side (dim + 2*padding - kernel)/stride + 1. Max pooling ignores the padded positions (as PyTorch's MaxPool2d does); avg pooling counts them as zeros in the divisor when 'countIncludePad' (PyTorch's AvgPool2d default) and divides by the positions inside the plane otherwise.
struct FeatureMap avgpool2d_ex(
unsigned long kernel,
unsigned long stride,
unsigned long padding,
int countIncludePad,
) constsource · definitionGlobal pooling over each channel's whole plane: channels x 1 x 1 (the classifier head of ResNet-style networks).
Nearest-neighbor 2x spatial upsample: out[c][2h+dh][2w+dw] = in[c][h][w] for dh,dw in {0,1}. Used by U-Net's decoder path (see unet.h) in place of a learned transposed convolution.