vaccel #
A virtual machine or a unikernel usually has no access to the host's GPU, yet
the workloads it runs increasingly need one for model inference, running an
already trained machine-learning model on new input to get its output. The
vAccel framework solves this by forwarding
acceleration operations (model inference, image classification, or a generic
typed-argument genop) from the guest to a host agent that owns the hardware. A
genop (generic operation) is vAccel's catch-all call: an operation name plus a
list of typed input and output arguments that the host's plugin interprets. This
library implements the vAccel RPC protocol in OCaml.
The core package vaccel is the wire contract and does no I/O: hand-written
nox-protobuf codecs for
every vaccel-rpc-proto message, and
the typed method table of the synchronous AgentService over
ttrpc. The other packages
build on it:
vaccel-clientcalls a running agent, with a session bracket that always
destroys the session;vaccel-eioserves an agent from a compute backend (Vaccel_eio.Agent),
keeping each connection's sessions separate from every other tenant's, and
runs a broker in front of an upstream agent that authenticates guests and
bounds their sessions and resources. Each call carries a bearer token in its
ttrpc metadata (theauthorizationkey by default); the broker passes the
metadata to anauthenticatefunction the operator supplies, such as
Vaccel_eio.Broker.bearer, which maps the token to a guest identity. The
broker then applies a per-call policy and the per-guest session and resource
quotas, and checks that a guest touches only the sessions it opened, before
forwarding the call upstream;vaccel-metalis an agent backend that scores a linear classifier on the
GPU with Metal, falling back to the CPU off macOS;vaccel-ociresolves models by digest from an OCI content store, so every
guest naming the same model is served one cached, parsed copy. OCI (the Open
Container Initiative) defines the image format containers are distributed
in, and its content store keeps each blob under the SHA-256 digest of its
bytes, so a model named by digest is the same bytes wherever it is
fetched.
Installation #
Install with opam:
$ opam install vaccel
If opam cannot find the package, it may not yet be released in the public
opam-repository. Add the overlay repository, then install it:
$ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git
$ opam update
$ opam install vaccel
Usage #
vaccel-client calls a running agent. A session is the capability every
operation runs under, and the bracket destroys it however the body leaves,
whether it returns, fails or raises:
let ( let* ) = Result.bind
(* Register a model, then score a batch of feature vectors against it: one
genop call carries the whole batch, and one score vector comes back per
input. *)
let score ~sw ~clock ~net ~token ~model ~embeddings agent =
let client =
Vaccel_client.connect ~sw ~clock ~net
~metadata:(Vaccel_client.bearer token)
agent
in
Vaccel_client.Session.with_ client @@ fun session ->
let* _model =
Vaccel_client.Resource.register session
~blobs:[ Vaccel.Resource.blob ~name:"landcover" model ]
()
in
let* written =
Vaccel_client.genop session (Vaccel.Genop.float32_arrays embeddings)
in
Ok (Vaccel.Genop.to_float32_arrays written)
Underneath, each RPC is a Ttrpc.Method.t pairing the service-qualified name
with its request and response codecs, so an agent, a broker or a test can drive
the same methods directly:
# Ttrpc.Method.service Vaccel.Agent.genop
- : string = "vaccel.sync.agent.AgentService"
# Ttrpc.Method.name Vaccel.Agent.session_create
- : string = "CreateSession"
# Protobuf.to_string
(Ttrpc.Method.request Vaccel.Agent.session_create)
{ Vaccel.Session.Create.flags = 1l }
- : string = "\b\001"
The upstream Rust vaccel-rpc-agent listens on vsock://2:2048 by default.
In a vsock address the first number is the context identifier (CID) and the
second the port; CID 2 is reserved for the host, so the agent listens on the
host, on port 2048, for connections from its guests.
The Ttrpc.Client state machine drives the same methods without I/O, and
test/test_vaccel.ml uses it to run full calls in memory.
Specification #
The message schemas follow the .proto files of the vaccel-rpc-proto crate in
nubificus/vaccel-rust: session,
resource, genop, image, tf, tflite, torch, profiling, and sync/agent.proto
for the service. The test suite cites them module by module and checks exact
byte vectors.
Related work #
- nubificus/vaccel is the C runtime and
plugin framework behind the protocol. - nubificus/vaccel-rust holds the
Rust RPC agent and client, the peers this library interoperates with. - ttrpc is the transport
underneath.
Licence #
ISC. See LICENSE.md.