Class NativeWasiNnBindings
java.lang.Object
ai.tegmentum.wasmtime4j.panama.wasi.nn.NativeWasiNnBindings
Panama FFI bindings for WASI-NN native functions.
This class provides method handles for calling the C-exported WASI-NN functions from the native library. It uses the singleton pattern for efficient handle caching.
- Since:
- 1.0.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic NativeWasiNnBindingsGets the singleton instance.voidnnContextClose(MemorySegment ctxPtr) Closes an NnContext.Creates a new NnContext.nnContextGetBackendInfo(MemorySegment ctxPtr) Gets backend info as JSON string.intnnContextIsAvailable(MemorySegment ctxPtr) Checks if any backends are available.nnContextLoadGraph(Arena arena, MemorySegment ctxPtr, byte[][] parts, int encodingCode, int targetCode) Loads a graph.int[]nnContextSupportedEncodings(Arena arena, MemorySegment ctxPtr) Gets supported encoding codes.voidnnExecClose(MemorySegment execPtr) Closes an execution context.voidnnExecCompute(Arena arena, MemorySegment execPtr) Runs inference.byte[]nnExecGetOutputByIndex(Arena arena, MemorySegment execPtr, int index) Gets an output tensor by index as serialized bytes.byte[]nnExecGetOutputByName(Arena arena, MemorySegment execPtr, String name) Gets an output tensor by name as serialized bytes.voidnnExecSetInputByIndex(Arena arena, MemorySegment execPtr, int index, int[] dims, int tensorType, byte[] data) Sets an input tensor by index.voidnnExecSetInputByName(Arena arena, MemorySegment execPtr, String name, int[] dims, int tensorType, byte[] data) Sets an input tensor by name.voidnnGraphClose(MemorySegment graphPtr) Closes an NnGraph.nnGraphCreateExecCtx(Arena arena, MemorySegment graphPtr) Creates an execution context from a graph.
-
Method Details
-
getInstance
Gets the singleton instance.- Returns:
- the bindings instance
-
nnContextCreate
Creates a new NnContext.- Returns:
- the context pointer
- Throws:
ai.tegmentum.wasmtime4j.wasi.nn.NnException- if creation fails
-
nnContextIsAvailable
Checks if any backends are available.- Parameters:
ctxPtr- the context pointer- Returns:
- 1 if available, 0 otherwise
-
nnContextSupportedEncodings
Gets supported encoding codes.- Parameters:
arena- the arena for allocationsctxPtr- the context pointer- Returns:
- array of encoding codes
-
nnContextLoadGraph
public MemorySegment nnContextLoadGraph(Arena arena, MemorySegment ctxPtr, byte[][] parts, int encodingCode, int targetCode) throws ai.tegmentum.wasmtime4j.wasi.nn.NnException Loads a graph.- Parameters:
arena- the arena for allocationsctxPtr- the context pointerparts- the model data partsencodingCode- the encoding codetargetCode- the target code- Returns:
- the graph pointer
- Throws:
ai.tegmentum.wasmtime4j.wasi.nn.NnException- if loading fails
-
nnContextGetBackendInfo
Gets backend info as JSON string.- Parameters:
ctxPtr- the context pointer- Returns:
- the JSON info string, or null
-
nnContextClose
Closes an NnContext.- Parameters:
ctxPtr- the context pointer
-
nnGraphCreateExecCtx
public MemorySegment nnGraphCreateExecCtx(Arena arena, MemorySegment graphPtr) throws ai.tegmentum.wasmtime4j.wasi.nn.NnException Creates an execution context from a graph.- Parameters:
arena- the arena for allocationsgraphPtr- the graph pointer- Returns:
- the execution context pointer
- Throws:
ai.tegmentum.wasmtime4j.wasi.nn.NnException- if creation fails
-
nnGraphClose
Closes an NnGraph.- Parameters:
graphPtr- the graph pointer
-
nnExecSetInputByIndex
public void nnExecSetInputByIndex(Arena arena, MemorySegment execPtr, int index, int[] dims, int tensorType, byte[] data) throws ai.tegmentum.wasmtime4j.wasi.nn.NnException Sets an input tensor by index.- Parameters:
arena- the arena for allocationsexecPtr- the execution context pointerindex- the input indexdims- the tensor dimensionstensorType- the tensor type codedata- the tensor data- Throws:
ai.tegmentum.wasmtime4j.wasi.nn.NnException- if setting fails
-
nnExecSetInputByName
public void nnExecSetInputByName(Arena arena, MemorySegment execPtr, String name, int[] dims, int tensorType, byte[] data) throws ai.tegmentum.wasmtime4j.wasi.nn.NnException Sets an input tensor by name.- Parameters:
arena- the arena for allocationsexecPtr- the execution context pointername- the input namedims- the tensor dimensionstensorType- the tensor type codedata- the tensor data- Throws:
ai.tegmentum.wasmtime4j.wasi.nn.NnException- if setting fails
-
nnExecCompute
public void nnExecCompute(Arena arena, MemorySegment execPtr) throws ai.tegmentum.wasmtime4j.wasi.nn.NnException Runs inference.- Parameters:
arena- the arena for allocationsexecPtr- the execution context pointer- Throws:
ai.tegmentum.wasmtime4j.wasi.nn.NnException- if inference fails
-
nnExecGetOutputByIndex
public byte[] nnExecGetOutputByIndex(Arena arena, MemorySegment execPtr, int index) throws ai.tegmentum.wasmtime4j.wasi.nn.NnException Gets an output tensor by index as serialized bytes.- Parameters:
arena- the arena for allocationsexecPtr- the execution context pointerindex- the output index- Returns:
- the serialized tensor bytes, or null if not available
- Throws:
ai.tegmentum.wasmtime4j.wasi.nn.NnException- if getting fails
-
nnExecGetOutputByName
public byte[] nnExecGetOutputByName(Arena arena, MemorySegment execPtr, String name) throws ai.tegmentum.wasmtime4j.wasi.nn.NnException Gets an output tensor by name as serialized bytes.- Parameters:
arena- the arena for allocationsexecPtr- the execution context pointername- the output name- Returns:
- the serialized tensor bytes, or null if not available
- Throws:
ai.tegmentum.wasmtime4j.wasi.nn.NnException- if getting fails
-
nnExecClose
Closes an execution context.- Parameters:
execPtr- the execution context pointer
-