Skip to content

Latest commit

 

History

History
178 lines (115 loc) · 3.52 KB

lua-api-reference.md

File metadata and controls

178 lines (115 loc) · 3.52 KB

This section describes the Lua APIs of PPLNN. Refer to pplnn.lua for usage examples and lua_pplnn.cc for exported symbols.

Common APIs in luappl.nn

TensorShape

dims = TensorShape:GetDims()

Returns an array of dimensions.

TensorShape:SetDims(dims)

Sets dims of the tensor.

data_type = TensorShape:GetDataType()

Returns the data type of elements in tensor. Data types are defined in luappl.common.

data_format = TensorShape:GetDataFormat()

Returns the data format of tensor. Data formats are defined in luappl.common.

is_scalar = TensorShape:IsScalar()

Tells whether a tensor is a scalar.

Tensor

name_str = Tensor:GetName()

Returns the tensor's name.

tensor_shape = Tensor:GetShape()

Returns a TensorShape object of the tensor.

ret_code = Tensor:ConvertFromHost(buffer, dims, data_type)

Copies data to the tensor from buffer shaped as dims and data_type. ret_code is an instance of RetCode defined in luappl.common. data_type is defined in luappl.common.

tensor_data = Tensor:ConvertToHost()

Copies tensor's data to host in NDARRAY format. Shape and data type can be retrieved by Tensor:GetShape():GetDims() and Tensor:GetShape():GetDataType() respectively.

Engine

name_str = Engine:GetName()

Returns engine's name.

OnnxRuntimeBuilderFactory

runtime_builder = OnnxRuntimeBuilderFactory:Create()

Creates an OnnxRuntimeBuilder instance.

OnnxRuntimeBuilder

status = runtime_builder:InitFromFile(onnx_model_file, engines)

initializes runtime_builder from an ONNX model. engines is a list of Engine instances that may be used to evaluate the model.

status = runtime_builder:Preprocess()

does some preparations before creating Runtime instances.

runtime = RuntimeBuilder:CreateRuntime()

creates a Runtime instance for inferencing.

Runtime

input_count = Runtime:GetInputCount()

Returns the number of model inputs.

input_tensor = Runtime:GetInputTensor(idx)

Returns the input tensor in position idx, which is in range [0, input_count).

ret_code = Runtime::Run()

Evaluates the model. ret_code is an instance of RetCode defined in luappl.common.

output_count = Runtime:GetOutputCount()

Returns the number of model outputs.

output_tensor = Runtime:GetOutputTensor(idx)

Returns the output tensor in position idx, which is in range [0, output_count).

Device Specific APIs in luappl.nn

X86

X86EngineFactory

x86_options = X86EngineOptions()
x86_engine = X86EngineFactory:Create(x86_options)

Creates an Engine instance running on x86-64 compatiable CPUs.

CUDA

CudaEngineOptions

Refer to cuda_engine_options.h for more details.

CudaEngineFactory

cuda_options = CudaEngineOptions()
cuda_engine = CudaEngineFactory:Create(cuda_options)

Creates an Engine instance running on NVIDIA GPUs.

Other Utilities

version_str = luappl.nn.GetVersionString()

Returns the version string of current version.

msg_str = luappl.common.GetRetCodeStr(ret_code)

Returns a human-readable message of ret_code.

luappl.common.SetLoggingLevel(log_level)
log_level = luappl.common.GetLoggingLevel()

Sets and gets the current logging level respectively. Logging levels are defined in luappl.common.