Go to the source code of this file.
|
| int | ck_load_weights_manifest_v4 (void *base, const char *weights_path, const char *manifest_path) |
| | Load BUMPWGT4 weights into a v4 model buffer using a manifest map. More...
|
| |
◆ ck_load_weights_manifest_v4()
| int ck_load_weights_manifest_v4 |
( |
void * |
base, |
|
|
const char * |
weights_path, |
|
|
const char * |
manifest_path |
|
) |
| |
Load BUMPWGT4 weights into a v4 model buffer using a manifest map.
The manifest format is line-based: name|dtype|file_offset|size|runtime_offset Offsets/sizes accept decimal or hex (0x...).
- Parameters
-
| base | Base pointer for the generated model buffer. |
| weights_path | Path to BUMPWGT4 weights file. |
| manifest_path | Path to weights_manifest.map emitted by build_ir_v4.py. |
- Returns
- 0 on success, non-zero on error.
Definition at line 24 of file ckernel_model_load_v4.c.
28 if (!base || !weights_path || !manifest_path) {
29 fprintf(stderr,
"ck_load_weights_manifest_v4: invalid arguments\n");
33 FILE *wf = fopen(weights_path,
"rb");
35 fprintf(stderr,
"ck_load_weights_manifest_v4: failed to open %s: %s\n",
36 weights_path, strerror(errno));
41 if (fread(magic, 1, 8, wf) != 8 || memcmp(magic,
"BUMPWGT4", 8) != 0) {
42 fprintf(stderr,
"ck_load_weights_manifest_v4: invalid BUMPWGT4 magic\n");
47 FILE *mf = fopen(manifest_path,
"r");
49 fprintf(stderr,
"ck_load_weights_manifest_v4: failed to open %s: %s\n",
50 manifest_path, strerror(errno));
58 fprintf(stderr,
"ck_load_weights_manifest_v4: malloc failed\n");
64 while (fgets(line,
sizeof(line), mf)) {
65 if (line[0] ==
'#' || line[0] ==
'\n') {
68 line[strcspn(line,
"\r\n")] =
'\0';
70 char *name = strtok(line,
"|");
71 char *dtype = strtok(NULL,
"|");
72 char *file_off = strtok(NULL,
"|");
73 char *size_str = strtok(NULL,
"|");
74 char *rt_off = strtok(NULL,
"|");
76 if (!name || !dtype || !file_off || !size_str || !rt_off) {
77 fprintf(stderr,
"ck_load_weights_manifest_v4: malformed line\n");
87 unsigned long long file_offset =
parse_u64(file_off);
88 unsigned long long size =
parse_u64(size_str);
89 unsigned long long runtime_offset =
parse_u64(rt_off);
91 if (fseek(wf, (
long)file_offset, SEEK_SET) != 0) {
92 fprintf(stderr,
"ck_load_weights_manifest_v4: fseek failed\n");
99 unsigned char *dst = (
unsigned char *)base + runtime_offset;
100 unsigned long long remaining = size;
102 while (remaining > 0) {
104 size_t n = fread(buf, 1, take, wf);
106 fprintf(stderr,
"ck_load_weights_manifest_v4: short read\n");
112 memcpy(dst, buf, take);
static unsigned long long parse_u64(const char *s)
#define MANIFEST_LINE_MAX
References COPY_CHUNK, MANIFEST_LINE_MAX, and parse_u64().