Package com.gencior.triton.core
Class InferInput
java.lang.Object
com.gencior.triton.core.InferInput
An object of
InferInput class is used to describe an input tensor for
an inference request.
* This class is designed to be aligned with the Python invalid input: '{@':tritonclient.grpc.InferInput} implementation. It provides a high-level API to handle data serialization into the raw byte format required by Triton, supporting various data types and shared memory regions.
Key features include:
- Automatic Little-Endian serialization for numeric types.
- Length-prefixed serialization for
BYTES(String) data types. - Data size validation against the provided tensor shape.
- Support for System and CUDA Shared Memory parameters.
- Author:
- sachachoumiloff
-
Constructor Summary
ConstructorsConstructorDescriptionInferInput(String name, long[] shape, TritonDataType datatype) Creates anInferInputinstance. -
Method Summary
Modifier and TypeMethodDescriptionboolean[]Reconstructs a boolean array from the internal raw content.double[]Reconstructs a double array from the internal raw content.float[]Reconstructs a float array from the internal raw content.int[]Reconstructs an int array from the internal raw content.long[]Reconstructs a long array from the internal raw content.String[]Reconstructs a String array from the internal raw content (BYTES format).getName()byte[]Returns the serialized binary content of the tensor.long[]getShape()Returns the underlying Protobuf message builder result.booleansetData(boolean[] data) Sets the tensor data from a boolean array.setData(byte[] data) Sets the tensor data from raw bytes.setData(double[] data) Sets the tensor data from a double array (FP64).setData(float[] data) Sets the tensor data from a float array.setData(int[] data) Sets the tensor data from an int array.setData(long[] data) Sets the tensor data from a long array (INT64).Sets the tensor data from a String array (BYTES datatype).setShape(long[] shape) Updates the shape of the input.
-
Constructor Details
-
InferInput
Creates anInferInputinstance.- Parameters:
name- The name of the input.shape- The shape of the associated input.datatype- TheTritonDataTypeof the associated input.
-
-
Method Details
-
getName
- Returns:
- The name of the input associated with this Input Tensor.
-
getDatatype
- Returns:
- The datatype of the input associated with this object.
-
getShape
public long[] getShape()- Returns:
- The current shape of the input as an array of longs.
-
setShape
Updates the shape of the input. Useful for models with dynamic input shapes. * @param shape The new shape for the associated input.- Returns:
- This
InferInputinstance for method chaining.
-
setData
Sets the tensor data from a float array. Validates that the input matches the expected "FP32" datatype and size. * @param data The float array to be used as input.- Returns:
- This
InferInputinstance for method chaining. - Throws:
TritonDataTypeException- If data size mismatch.TritonShapeMismatchException- If data size mismatch.
-
setData
Sets the tensor data from a double array (FP64). * @param data The double array to be used as input.- Returns:
- This
InferInputinstance for method chaining.
-
setData
Sets the tensor data from an int array. Supports INT32, INT16, or INT8 datatypes. * @param data The int array to be used as input.- Returns:
- This
InferInputinstance for method chaining.
-
setData
Sets the tensor data from a long array (INT64). * @param data The long array to be used as input.- Returns:
- This
InferInputinstance for method chaining.
-
setData
Sets the tensor data from a boolean array. Internally converts booleans to 1-byte integers (1 for true, 0 for false). * @param data The boolean array to be used as input.- Returns:
- This
InferInputinstance for method chaining.
-
setData
Sets the tensor data from raw bytes. Use this if you have already serialized the data externally. * @param data The raw byte array.- Returns:
- This
InferInputinstance for method chaining.
-
setData
Sets the tensor data from a String array (BYTES datatype). Each string is serialized with a 4-byte Little-Endian length prefix followed by the UTF-8 encoded string bytes. * @param data The string array to be used as input.- Returns:
- This
InferInputinstance for method chaining.
-
getTensor
Returns the underlying Protobuf message builder result. * @return TheInferInputTensormessage. -
getRawContent
public byte[] getRawContent()Returns the serialized binary content of the tensor. * @return A byte array containing the tensor data. -
hasRawContent
public boolean hasRawContent()- Returns:
trueif raw content has been set and is not empty.
-
getDataAsFloatArray
public float[] getDataAsFloatArray()Reconstructs a float array from the internal raw content.- Returns:
- A float array representation of the data.
-
getDataAsDoubleArray
public double[] getDataAsDoubleArray()Reconstructs a double array from the internal raw content.- Returns:
- A double array representation of the data.
-
getDataAsIntArray
public int[] getDataAsIntArray()Reconstructs an int array from the internal raw content.- Returns:
- An int array representation of the data.
-
getDataAsLongArray
public long[] getDataAsLongArray()Reconstructs a long array from the internal raw content.- Returns:
- A long array representation of the data.
-
getDataAsBooleanArray
public boolean[] getDataAsBooleanArray()Reconstructs a boolean array from the internal raw content.- Returns:
- A boolean array representation of the data.
-
getDataAsStringArray
Reconstructs a String array from the internal raw content (BYTES format).- Returns:
- A String array representation of the data.
-