Epic: pybind11 Python bindings v1 (для yolo-world-detector) #6
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Зачем
Чтобы downstream Python consumer'ы (новый сервис
yolo-world-detector, ML-скрипты) могли подписываться на cuframes без CPU round-trip: получать NV12 frame прямо как CUDA pointer /torch.Tensor(DLPack), не уходя из VRAM.Сейчас в
examples/python-consumer/cuframes_consumer.pyесть ctypes skeleton, но он не делает actual CUDA copy (placeholder). README отмечает pybind11 как planned.Решение
Полноценные
pybind11bindings, минимум для:Scope (из architect review)
CuframesSubscriber,CuframesFrame)frame.__dlpack__()для zero-copy →torch.from_dlpackилиcupy.from_dlpackwith cuframes.subscribe(key) as sub: ...гарантированноrelease()при exceptionCuframesPublisherGone,CuframesFrameTimeout,CuframesDeviceLost,CuframesShmError. Не голыйRuntimeError.subscriber.ring_occupancy,subscriber.drop_count,subscriber.publisher_state(ACTIVE/STALE/DEAD). Не logging, для MQTT health publisher.frame.pitch_y,frame.pitch_uv. Архитектор предупредил: для большой камеры (2688×1520, gate_lpr) pitched NV12 не contiguous, downstream kernel должен принимать pitch как параметр.Не входит в scope (Phase 0.5+)
async for frame in subscriber.stream()) — приоритет если есть времяDefinition of done
pip install cuframesиз локального wheel работаетexamples/python-consumer/yolo_world_smoke.py: subscribe → 100 frames → DLPack → ONNX inference dummy → release. Без leaks (ring occupancy стабильный).docs/python.mdс примером, pitfalls, threading contract.Зависимости
goldix-smart-home/yolo-world-detectorPhase 1+.Estimate
1 неделя focused work.
Architect review fed into this scope: см. context из чат-сессии 2026-06-13.
Закрыто PR'ом #7 (merged 2026-06-13).
Что сделано (все 8 пунктов scope)
CuframesSubscriber,CuframesFrame)dlpack_y()/dlpack_uv()/__dlpack__()/__dlpack_device__()consumer_stream(cudaStream_tкак int)CuframesError+ 8 subclassesframes_received,timeouts,errors,last_seq,gap_count,stats()dict (counted в pybind layer т.к. C API не expose'ит ring_occupancy)CuframesSubscriberpitch_y,pitch_uv) + предупреждение в docsBackpressure
Документирован в
docs/python.md, NEWEST_ONLY default. Реальный policy switch не нужен в Phase 0 — устанавливается через subscriber mode.Не вошло в Phase 0 — отдельные задачи
ring_occupancy/ drop counter — future enhancement issueФайлы
python/CMakeLists.txt,pyproject.toml,README.md,.gitignorepython/src/_native.cpp— ~530 строк pybind codepython/cuframes/__init__.py— re-exportpython/tests/test_smoke.py— 10 testsdocs/python.md— ~250 строк документацииCMakeLists.txt—add_subdirectory(python)при BUILD_PYTHON_BINDINGS=ONVerify
Phase 0 closed. Можно запускать yolo-world-detector#2 Phase 1.