Noodle
Loading...
Searching...
No Matches
noodle.cpp File Reference

Noodle implementation (streaming kernels, filesystem init, parsing helpers). More...

#include "noodle.h"
#include <math.h>
#include <float.h>
#include <stdint.h>
Include dependency graph for noodle.cpp:

Functions

float * noodle_slice (float *flat, size_t W, size_t z)
 
void noodle_setup_temp_buffers (void *b1, void *b2)
 Provide two reusable temporary buffers used internally by file-streaming operations.Must be called before conv/FCN variants that read from files. Two temp buffers are needed for operations that read from a file. For C*W*W tensor, the buffer should be W*W.
 
size_t noodle_read_bytes_until (NDL_File &file, char terminator, char *buffer, size_t length)
 Read bytes from a file until a terminator or length-1 (NULL terminated).
 
bool noodle_fs_init (uint8_t clk_pin, uint8_t cmd_pin, uint8_t d0_pin)
 Initialize SD/FS backend (pins variant is meaningful only for SD_MMC).
 
bool noodle_fs_init (uint8_t clk_pin, uint8_t cmd_pin, uint8_t d0_pin, uint8_t d1_pin, uint8_t d2_pin, uint8_t d3_pin)
 Initialize SD/FS backend with default pins/settings.
 
bool noodle_fs_init ()
 
bool noodle_fs_init (uint8_t cs_pin)
 Initialize SD/FS backend with a specific CS_PIN.
 
float noodle_read_float (NDL_File &f)
 Read a float up to the next newline.
 
byte noodle_read_byte (NDL_File &f)
 Read a byte value fron an opened file handler and store as an integer text line.
 
void noodle_write_float (NDL_File &f, float d)
 
void noodle_write_byte (NDL_File &f, byte d)
 Write a byte value as an integer text line to an opend file.
 
void noodle_delete_file (const char *fn)
 Delete a file if it exists.
 
float * noodle_create_buffer (uint16_t size)
 Allocate a raw float buffer of size bytes.
 
void noodle_delete_buffer (float *buffer)
 Free a buffer allocated by noodle_create_buffer.
 
void noodle_array_to_file (float *array, const char *fn, uint16_t n)
 Write an array of n floats to fn, one value per line. File will be opened and closed.
 
void noodle_array_to_file (float *array, NDL_File &fo, uint16_t n)
 Write an array of n floats to fo (an opened file handler), one value per line. No file open and close operations.
 
void noodle_grid_to_file (byte *grid, const char *fn, uint16_t n)
 Write an n byte grid to fn as bytes, row-major. File will be opened and closed.
 
void noodle_grid_to_file (byte *grid, NDL_File &fo, uint16_t n)
 Write an n byte grid to fo (opened file handler) as bytes, row-major. No file open and close operations.
 
void noodle_grid_to_file (float *grid, const char *fn, uint16_t n)
 Write an n float grid to fn, row-major.
 
void noodle_grid_to_file (float *grid, NDL_File &fo, uint16_t n)
 Write an n float grid to fo (an opened file handler), row-major.
 
float noodle_get_padded_x (byte *grid, int16_t i, int16_t j, int16_t W, int16_t P)
 Get padded input sample from a byte grid with zero padding.Noodle uses symmetric, stride-independent padding for all convolutions.
 
float noodle_get_padded_x (float *grid, int16_t i, int16_t j, int16_t W, int16_t P)
 Get padded input sample from a float grid with zero padding.
 
uint16_t noodle_do_bias (float *output, float bias, uint16_t n)
 
uint16_t noodle_do_pooling (const float *input, uint16_t W, uint16_t K, uint16_t S, const char *fn)
 2D pooling over a V×V map, writing results to a file (one float per line).Pooling mode (MAX or MEAN) is selected via NOODLE_POOL_MODE at compile time. This layer uses valid pooling. NO PADDING IS APPLIED!
 
uint16_t noodle_do_pooling (const float *input, uint16_t W, uint16_t K, uint16_t S, NDL_File &fo)
 
uint16_t noodle_do_pooling (const float *input, uint16_t W, uint16_t K, uint16_t S, float *output)
 
uint16_t noodle_do_conv (byte *grid, const float *kernel, uint16_t K, uint16_t W, float *output, uint16_t P, uint16_t S)
 2D valid/same convolution with zero padding and stride, accumulating into output.Output spatial size is V = (W - K + 2P)/S + 1.
 
uint16_t noodle_do_conv (float *grid, const float *kernel, uint16_t K, uint16_t W, float *output, uint16_t P, uint16_t S)
 
void noodle_array_from_file (const char *fn, float *buffer, uint16_t K)
 Read a float array of length K from fn (one value per line).
 
void noodle_array_from_file (NDL_File &fi, float *buffer, uint16_t K)
 Read a float array of length K from an opened file handler fi (one value per line).
 
void noodle_grid_from_file (const char *fn, byte *buffer, uint16_t K)
 
void noodle_grid_from_file (NDL_File &fi, byte *buffer, uint16_t K)
 Read an K × K grid (stored as byte) from fi (opened file handler) into buffer.
 
void noodle_grid_from_file (const char *fn, int8_t *buffer, uint16_t K)
 Read an K × K grid (stored as float) from fn into buffer.
 
void noodle_grid_from_file (NDL_File &fi, int8_t *buffer, uint16_t K)
 Read an K × K grid (stored as int8) from fi (opened file handler) into buffer.
 
void noodle_grid_from_file (const char *fn, float *buffer, uint16_t K)
 Read an K × K grid (stored as float) from fn into buffer.
 
void noodle_grid_from_file (NDL_File &fi, float *buffer, uint16_t K)
 
void noodle_reset_buffer (float *buffer, uint16_t n)
 Fill buffer with zeros (n floats).
 
uint16_t noodle_conv_byte (const char *in_fn, uint16_t n_inputs, uint16_t n_outputs, const char *out_fn, uint16_t W, const Conv &conv, const Pool &pool, CBFPtr progress_cb)
 File→File 2D conv with BYTE input feature maps.
 
uint16_t noodle_conv_float (const char *in_fn, uint16_t n_inputs, uint16_t n_outputs, const char *out_fn, uint16_t W, const Conv &conv, const Pool &pool, CBFPtr progress_cb)
 File→File 2D conv with FLOAT input feature maps.
 
uint16_t noodle_conv_float (const char *in_fn, uint16_t n_inputs, uint16_t n_outputs, float *output, uint16_t W, const Conv &conv, const Pool &pool, CBFPtr progress_cb)
 File→Memory 2D conv with FLOAT inputs; writes [O, Wo, Wo] tensor to output.
 
uint16_t noodle_conv_float (float *input, uint16_t n_inputs, uint16_t n_outputs, const char *out_fn, uint16_t W, const Conv &conv, const Pool &pool, CBFPtr progress_cb)
 Memory→File 2D conv with FLOAT inputs and in-file conv parameters.
 
uint16_t noodle_conv_float (float *input, uint16_t n_inputs, uint16_t n_outputs, const char *out_fn, uint16_t W, const ConvMem &conv, const Pool &pool, CBFPtr progress_cb)
 Memory→File 2D conv with FLOAT inputs and in-varibale conv parameters.
 
uint16_t noodle_conv_float (float *input, uint16_t n_inputs, uint16_t n_outputs, float *output, uint16_t W, const Conv &conv, const Pool &pool, CBFPtr progress_cb)
 Memory→Memory 2D conv with FLOAT inputs and in-file conv parameters.
 
uint16_t noodle_conv_float (float *input, uint16_t n_inputs, uint16_t n_outputs, float *output, uint16_t W, const ConvMem &conv, const Pool &pool, CBFPtr progress_cb)
 
uint16_t noodle_flat (const char *in_fn, float *output, uint16_t V, uint16_t n_filters)
 
uint16_t noodle_flat (float *input, float *output, uint16_t V, uint16_t n_filters)
 
uint16_t noodle_fcn (const int8_t *input, uint16_t n_inputs, uint16_t n_outputs, const char *out_fn, const FCNFile &fcn, CBFPtr progress_cb)
 
uint16_t noodle_fcn (const byte *input, uint16_t n_inputs, uint16_t n_outputs, const char *out_fn, const FCNFile &fcn, CBFPtr progress_cb)
 
uint16_t noodle_fcn (const byte *input, uint16_t n_inputs, uint16_t n_outputs, float *output, const FCNFile &fcn, CBFPtr progress_cb)
 
uint16_t noodle_fcn (const float *input, uint16_t n_inputs, uint16_t n_outputs, float *output, const FCNFile &fcn, CBFPtr progress_cb)
 
uint16_t noodle_fcn (const float *input, uint16_t n_inputs, uint16_t n_outputs, const char *out_fn, const FCNFile &fcn, CBFPtr progress_cb)
 
uint16_t noodle_fcn (const char *in_fn, uint16_t n_inputs, uint16_t n_outputs, float *output, const FCNFile &fcn, CBFPtr progress_cb)
 
uint16_t noodle_fcn (const int8_t *input, uint16_t n_inputs, uint16_t n_outputs, float *output, const FCNFile &fcn, CBFPtr progress_cb)
 
uint16_t noodle_fcn (const char *in_fn, uint16_t n_inputs, uint16_t n_outputs, const char *out_fn, const FCNFile &fcn, CBFPtr progress_cb)
 
uint16_t noodle_fcn (const float *input, uint16_t n_inputs, uint16_t n_outputs, float *output, const FCNMem &fcn, CBFPtr progress_cb)
 
uint16_t noodle_soft_max (float *input_output, uint16_t n)
 
uint16_t noodle_sigmoid (float *input_output, uint16_t n)
 
uint16_t noodle_relu (float *input_output, uint16_t n)
 
uint16_t noodle_do_conv1d (float *input, float *kernel, uint16_t W, uint16_t K, float *output, uint16_t P, uint16_t S)
 
uint16_t noodle_do_pooling1d (float *input, uint16_t W, uint16_t K, uint16_t S, const char *fn)
 
uint16_t noodle_do_pooling1d (float *input, uint16_t W, uint16_t K, uint16_t S, NDL_File &fo)
 
uint16_t noodle_conv1d (const char *in_fn, uint16_t n_inputs, const char *out_fn, uint16_t n_outputs, uint16_t W, const Conv &conv, const Pool &pool, CBFPtr progress_cb)
 
uint16_t noodle_conv1d (const char *in_fn, uint16_t n_inputs, const char *out_fn, uint16_t n_outputs, uint16_t W, const Conv &conv, CBFPtr progress_cb)
 
uint16_t noodle_conv1d (const char *in_fn, uint16_t n_inputs, const char *out_fn, uint16_t n_outputs, uint16_t W, const ConvMem &conv, CBFPtr progress_cb)
 
uint16_t noodle_conv1d (float *in, uint16_t n_inputs, float *out, uint16_t n_outputs, uint16_t W, const ConvMem &conv, CBFPtr progress_cb)
 
uint16_t noodle_conv1d (float *in, uint16_t n_inputs, const char *out_fn, uint16_t n_outputs, uint16_t W, const ConvMem &conv, CBFPtr progress_cb)
 
uint16_t noodle_conv1d (const char *in_fn, uint16_t n_inputs, float *out, uint16_t n_outputs, uint16_t W, const ConvMem &conv, CBFPtr progress_cb)
 
uint16_t noodle_do_bias_act (float *output, float bias, uint16_t n, Activation act)
 Add bias to each element of a V×V map (in-place) and optionally apply activation.
 
void noodle_read_top_line (const char *fn, char *line, size_t maxlen)
 Read the first line of a given text file.
 
uint16_t noodle_dwconv_float (const char *in_fn, uint16_t n_channels, const char *out_fn, uint16_t W, const Conv &conv, const Pool &pool, CBFPtr progress_cb)
 
uint16_t noodle_dwconv_float (float *input, uint16_t n_channels, float *output, uint16_t W, const Conv &conv, const Pool &pool, CBFPtr progress_cb)
 
uint16_t noodle_dwconv_float (float *input, uint16_t n_channels, float *output, uint16_t W, const ConvMem &conv, const Pool &pool, CBFPtr progress_cb)
 
uint16_t noodle_gap (float *inout, uint16_t C, uint16_t W)
 
void noodle_unpack_bn_params (const float *bn_params, uint16_t C, const float **gamma, const float **beta, const float **mean, const float **var)
 
uint16_t noodle_bn (float *x, uint16_t C, uint16_t W, const float *gamma, const float *beta, const float *mean, const float *var, float eps)
 
uint16_t noodle_bn (float *x, uint16_t C, uint16_t W, const float *bn_params, float eps)
 
uint16_t noodle_bn_relu (float *x, uint16_t C, uint16_t W, const float *bn_params, float eps)
 
uint16_t noodle_bn_relu (float *x, uint16_t C, uint16_t W, const float *gamma, const float *beta, const float *mean, const float *var, float eps)
 
void noodle_find_max (float *input, uint16_t n, float &max_val, uint16_t &max_idx)
 

Variables

SdFat NOODLE_FS
 
NDL_File fw
 
NDL_File fb
 
NDL_File fo
 
NDL_File fi
 
static void * temp_buff1 = NULL
 
static void * temp_buff2 = NULL
 

Detailed Description

Noodle implementation (streaming kernels, filesystem init, parsing helpers).

Function Documentation

◆ noodle_bn_relu() [1/2]

uint16_t noodle_bn_relu ( float *  x,
uint16_t  C,
uint16_t  W,
const float *  bn_params,
float  eps 
)

◆ noodle_bn_relu() [2/2]

uint16_t noodle_bn_relu ( float *  x,
uint16_t  C,
uint16_t  W,
const float *  gamma,
const float *  beta,
const float *  mean,
const float *  var,
float  eps = 1e-3 
)

Batch Normalization followed by ReLU for a channel-first tensor in memory.

Parameters
xPointer to the input tensor in [C][W][W] layout.
CNumber of channels.
WWidth/height of each channel plane.
gammaPointer to the per-channel scale parameters.
betaPointer to the per-channel shift parameters.
meanPointer to the per-channel mean parameters.
varPointer to the per-channel variance parameters.
epsSmall constant to avoid division by zero.

◆ noodle_conv1d() [1/3]

uint16_t noodle_conv1d ( const char *  in_fn,
uint16_t  n_inputs,
const char *  out_fn,
uint16_t  n_outputs,
uint16_t  W,
const ConvMem conv,
CBFPtr  progress_cb 
)

◆ noodle_conv1d() [2/3]

uint16_t noodle_conv1d ( const char *  in_fn,
uint16_t  n_inputs,
float *  out,
uint16_t  n_outputs,
uint16_t  W,
const ConvMem conv,
CBFPtr  progress_cb 
)

◆ noodle_conv1d() [3/3]

uint16_t noodle_conv1d ( float *  in,
uint16_t  n_inputs,
const char *  out_fn,
uint16_t  n_outputs,
uint16_t  W,
const ConvMem conv,
CBFPtr  progress_cb 
)

◆ noodle_do_conv()

uint16_t noodle_do_conv ( float *  grid,
const float *  kernel,
uint16_t  K,
uint16_t  W,
float *  output,
uint16_t  P,
uint16_t  S 
)

◆ noodle_do_pooling() [1/2]

uint16_t noodle_do_pooling ( const float *  input,
uint16_t  W,
uint16_t  K,
uint16_t  S,
float *  output 
)

◆ noodle_do_pooling() [2/2]

uint16_t noodle_do_pooling ( const float *  input,
uint16_t  W,
uint16_t  K,
uint16_t  S,
NDL_File &  fo 
)

◆ noodle_do_pooling1d()

uint16_t noodle_do_pooling1d ( float *  input,
uint16_t  W,
uint16_t  K,
uint16_t  S,
NDL_File &  fo 
)

◆ noodle_fcn()

uint16_t noodle_fcn ( const byte input,
uint16_t  n_inputs,
uint16_t  n_outputs,
const char *  out_fn,
const FCNFile fcn,
CBFPtr  progress_cb 
)

Variable Documentation

◆ fb

NDL_File fb

◆ fi

NDL_File fi

◆ fo

NDL_File fo

◆ fw

NDL_File fw

◆ NOODLE_FS

SdFat NOODLE_FS

◆ temp_buff1

void* temp_buff1 = NULL
static

◆ temp_buff2

void* temp_buff2 = NULL
static