/* Access to the packed weight blob produced by tools/export_weights.py. * * The blob is already in the layout the kernels read, so loading it is a table * walk that hands out pointers: no transposing, no unpacking, no allocation * for the weights themselves. That holds both for the copy compiled into the * binary and for a file, which is mapped read-only and shared between every * process on the host that maps it. */ #ifndef PYSEG_WEIGHTS_H #define PYSEG_WEIGHTS_H #include #define PYSEG_ALIGN64 __attribute__((aligned(64))) /* Every weight matrix is [rows, window] row-major, matching pyseg_kernels. */ typedef struct { const float *ih; /* [512, input] */ const float *hh; /* [512, 128] */ const float *bias; /* [512], the two PyTorch bias vectors already summed */ } pyseg_lstm_weights; typedef struct { const float *wavnorm; /* [2]: InstanceNorm1d scale then shift */ const float *sinc_w; /* [80, 256]: 251 taps then five zero columns */ const float *norm_w[3]; /* [80], [60], [60] */ const float *norm_b[3]; const float *conv_w[2]; /* [60, 400] and [60, 300] */ const float *conv_b[2]; pyseg_lstm_weights lstm[4][2]; /* [layer][0 = forward, 1 = backward] */ const float *lin_w[2]; /* [128, 256] and [128, 128] */ const float *lin_b[2]; const float *cls_w; /* [7, 128] */ const float *cls_b; } pyseg_weights; /* Returns 0 on success. verify recomputes the per-tensor checksum. */ int pyseg_weights_parse(const void *blob, size_t len, int verify, pyseg_weights *out); /* Maps path read-only and parses it. On success the caller must keep the * mapping alive for as long as the weights are used. */ int pyseg_weights_map(const char *path, int verify, pyseg_weights *out, void **map, size_t *map_len); void pyseg_weights_unmap(void *map, size_t len); /* The blob compiled into this binary, or NULL when built without one. */ const void *pyseg_weights_embedded(size_t *len); #endif /* PYSEG_WEIGHTS_H */