This section describes the python APIs of PPLNN
. Refer to pplnn.py for usage examples and py_pplnn.cc for exported symbols.
dims = TensorShape::GetDims()
Returns a tuple of array 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 pyppl.common
.
data_format = TensorShape::GetDataFormat()
Returns the data format of tensor. Data formats are defined in pyppl.common
.
is_scalar = TensorShape::IsScalar()
Tells whether a tensor is a scalar.
name_str = Tensor::GetName()
Returns the tensor's name.
tensor_shape = Tensor::GetShape()
Returns a TensorShape
info of the tensor.
ret_code = Tensor::ConvertFromHost(numpy_ndarray)
Copies NDARRAY data to the tensor from an ndarray
object. ret_code
is an instance of RetCode
defined in pyppl.common
.
tensor_data = Tensor::ConvertToHost()
Copies tensor's data to host in NDARRAY format. We can use numpy.array
to create an ndarray
instance using numpy_ndarray = numpy.array(tensor_data, copy=False)
.
addr = Tensor::GetBufferPtr()
Returns the underlying buffer ptr as an integer.
Tensor::SetBfferPtr(addr)
Sets the tensor buffer area to addr
which is an integer and can be casted to void*
. Note that addr
can be read/written by internal Device
class.
name_str = Engine::GetName()
Returns engine's name.
Refer to runtime_options.h for more details.
runtime_builder = OnnxRuntimeBuilderFactory::CreateFromFile(onnx_model_file, engines)
Creates an OnnxRuntimeBuilder
instance from an ONNX model. engines
is a list of Engine
instances that may be used to evaluate the model.
runtime_options = RuntimeOptions()
runtime = OnnxRuntimeBuilder::CreateRuntime(runtime_options)
Creates a Runtime
instance for inferencing.
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 pyppl.common
.
ret_code = Runtime::Sync()
Waits for all operations to finish.
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).
x86_engine = X86EngineFactory::Create()
Creates an Engine
instance running on x86-64 compatiable CPUs.
ret_code = x86_engine.Configure(option)
Configures x86_engine
. Refer to x86_options.h for available options.
Refer to cuda_engine_options.h for more details.
cuda_options = CudaEngineOptions()
cuda_engine = CudaEngineFactory::Create(cuda_options)
Creates an Engine
instance running on NVIDIA GPUs.
ret_code = cuda_engine.Configure(option)
Configures cuda_engine
. Refer to cuda_options.h for available options(some options are not exported yet).
version_str = pypplnn.GetVersionString()
Returns the version string of current version.
msg_str = pyppl.common.GetRetCodeStr(ret_code)
Returns a human-readable message of ret_code
.
pyppl.common.SetLoggingLevel(log_level)
log_level = pyppl.common.GetLoggingLevel()
Sets and gets the current logging level respectively. Logging levels are defined in pyppl.common
.