Numerical Libraries

vtensor

Region-local device tensor handles with HWC shape metadata and packed-buffer crop staging.

Quick factValue
Modulevtensor
Importuse external "vtensor/vtensor.vy";
Depends onan active @device region for device helpers
StatusUnstable — the public surface may change between releases.
Generated reference

This page is generated from the library's in-repo manual (vyne/modules/external/vtensor/README.md) so signatures and behaviour stay aligned with the source tree. Examples assume a desktop target unless the text says otherwise.

vtensor is the small metadata layer over @device handles. It does not own device memory and it does not allocate by itself. A DeviceTensor pairs an Int64 device handle with HWC shape and element count so higher-level device helpers can pass shape safely without long argument lists.

 vyne snippetvyne
use external "vtensor/vtensor.vy"; @device<cuda> region r { h :: Int64 := device_alloc(64 * 64 * 3); x :: vtensor.DeviceTensor := vtensor.tensor(h, 64, 64, 3); };

Rules

  • Handles are region-local. Do not store DeviceTensor values outside the @device region that owns their handles.
  • V1 is HWC-only because it targets image models first.
  • Helpers marked @device_fn are callable only from active @device regions or other @device_fn helpers.

API

FunctionResult
vtensor.tensor(handle, h, w, c)shape metadata for an existing handle
vtensor.copy_slice(dst, packed, offset)device-side packed-buffer crop staging

DeviceTensor exposes handle, height, width, channels, and n (height * width * channels). Supply positive dimensions matching the actual allocation. Metadata does not validate the capacity or dtype of an arbitrary handle. copy_slice copies dst.n elements from the packed device buffer at offset; it does not create a host slice or a borrowed sub-tensor handle.

Use vnn for explicit neural-network blocks and the ESPCN project for the full graph.

 shell snippetshell
vynec --run examples/test/vtensor_vnn_test.vy