Files
zeekay d14b104790 feat(zap): v2 generic API, bufpool, transport allocator + UMA/RDMA cgo
Three orthogonal additions, one wire format.

v2 package — generic ad-hoc schema dispatch (~/work/lux/zap/v2):
- README + IMPOSSIBILITY + BENCH_RESULTS document the v1↔v2 split.
- builder/field/iter/list/pool/registry/schema/view + codegen package
  emit v1-equivalent fast paths from declarative .zap sources.
- _compile_fail_test/ + examples/ cover negative and positive cases.
- v2_test.go exercises the generic dispatch path.
- doc.go in v1 marks v1 deprecated for *new* schema authoring; existing
  v1 buffers stay parseable by both v1 and v2.

bufpool — pooled read slabs (bufpool.go + bufpool_test.go):
- Message gains optional *bufRef; Release() returns the slab to its
  pool when sourced from the pooled read path, GC-managed otherwise.
- ParseHeader returns (data, rootOffset) without allocating *Message,
  used by zapv2 to avoid two allocations per parse.
- bench_read_test.go + node_quic_stream_test.go cover both paths.

Transport allocator + UMA/RDMA cgo (transport/*):
- Transport.Caps()/Buffer interface: capability + slab-typed buffer
  contract. Bytes() vs DevicePtr() decoupled so UMA and GPUDirect
  can share the same call surface.
- DPDK PMD + GPUDirect RDMA + CUDA UMA real cgo backends gated behind
  build tags; stub paths remain default on darwin / non-Linux.
- transport_test.go covers Caps reporting + Buffer lifecycle on the
  default transport.

LLM.md + go.mod follow the additions.
2026-06-04 17:06:59 -07:00

69 lines
1.6 KiB
C

// Copyright (C) 2025-2026, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
//
//go:build cgo && linux && cuda
//
// cudaMallocManaged-backed UMA pool, host-side glue. Compiled into the
// luxfi/zap binary only when the cgo + linux + cuda build tags are set;
// see uma_linux_cuda.go for the Go cgo bridge.
//
// We keep this file pure C (not .cu) so the host's plain `gcc`/`cc` can
// build it; the CUDA runtime is linked via -lcudart and headers are
// pulled from cuda_runtime_api.h (the C-only subset of the CUDA SDK).
#include "uma_cuda.h"
#include <cuda_runtime_api.h>
#include <string.h>
int luxzap_cuda_probe(void) {
int count = 0;
cudaError_t e = cudaGetDeviceCount(&count);
if (e != cudaSuccess) {
return (int)e;
}
if (count == 0) {
return -1; // no device — distinct from a cuda error
}
return 0;
}
int luxzap_cuda_alloc_managed(size_t size, void** out_ptr) {
if (!out_ptr) {
return (int)cudaErrorInvalidValue;
}
*out_ptr = NULL;
void* p = NULL;
cudaError_t e = cudaMallocManaged(&p, size, cudaMemAttachGlobal);
if (e != cudaSuccess) {
return (int)e;
}
*out_ptr = p;
return 0;
}
int luxzap_cuda_free(void* ptr) {
if (!ptr) {
return 0;
}
return (int)cudaFree(ptr);
}
size_t luxzap_cuda_device_name(char* buf, size_t buflen) {
if (!buf || buflen == 0) {
return 0;
}
buf[0] = '\0';
struct cudaDeviceProp prop;
if (cudaGetDeviceProperties(&prop, 0) != cudaSuccess) {
return 0;
}
size_t n = strnlen(prop.name, sizeof(prop.name));
if (n >= buflen) {
n = buflen - 1;
}
memcpy(buf, prop.name, n);
buf[n] = '\0';
return n;
}