| 1470 | memcpy(buf.data(), info.t.data, nbytes); |
| 1471 | } |
| 1472 | write(buf); |
| 1473 | |
| 1474 | pad(alignment); |
| 1475 | } |
| 1476 | }; |
| 1477 | |
| 1478 | template <typename writer_t> |
| 1479 | static void gguf_write_out(const struct gguf_context * ctx, writer_t & gw, bool only_meta) { |
| 1480 | const int64_t n_kv = gguf_get_n_kv(ctx); |
| 1481 | const int64_t n_tensors = gguf_get_n_tensors(ctx); |
| 1482 | |
| 1483 | // write header |
| 1484 | gw.write(GGUF_MAGIC[0]); |
| 1485 | gw.write(GGUF_MAGIC[1]); |
| 1486 | gw.write(GGUF_MAGIC[2]); |
| 1487 | gw.write(GGUF_MAGIC[3]); |
| 1488 | gw.write(ctx->version); |
| 1489 | gw.write(n_tensors); |
| 1490 | gw.write(n_kv); |
| 1491 | |
| 1492 | // write key-value pairs |
| 1493 | for (int64_t i = 0; i < n_kv; ++i) { |
| 1494 | gw.write(ctx->kv[i]); |
| 1495 | } |
| 1496 | |
| 1497 | // write tensor info |
| 1498 | for (int64_t i = 0; i < n_tensors; ++i) { |
| 1499 | gw.write_tensor_meta(ctx->info[i]); |
| 1500 | } |
| 1501 | |
| 1502 | // we require the data section to be aligned |
| 1503 | gw.pad(ctx->alignment); |
| 1504 | |
| 1505 | if (only_meta) { |
| 1506 | return; |
| 1507 | } |
| 1508 | |
| 1509 | const size_t offset_data = gw.written_bytes; |
| 1510 | |
| 1511 | // write tensor data |
no test coverage detected