tvm
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Functions
platform.h File Reference

The virtual memory manager for micro-controllers. More...

#include <stdarg.h>
#include <stddef.h>
#include <tvm/runtime/c_runtime_api.h>
#include <tvm/runtime/crt/error_codes.h>
Include dependency graph for platform.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void TVMPlatformAbort (tvm_crt_error_t code)
 Called when an internal error occurs and execution cannot continue. More...
 
size_t TVMPlatformFormatMessage (char *out_buf, size_t out_buf_size_bytes, const char *fmt, va_list args)
 Called by the microTVM RPC server to implement TVMLogf. More...
 
tvm_crt_error_t TVMPlatformMemoryAllocate (size_t num_bytes, DLDevice dev, void **out_ptr)
 Allocate memory for use by TVM. More...
 
tvm_crt_error_t TVMPlatformMemoryFree (void *ptr, DLDevice dev)
 Free memory used by TVM. More...
 
tvm_crt_error_t TVMPlatformTimerStart ()
 Start a device timer. More...
 
tvm_crt_error_t TVMPlatformTimerStop (double *elapsed_time_seconds)
 Stop the running device timer and get the elapsed time (in microseconds). More...
 
tvm_crt_error_t TVMPlatformBeforeMeasurement ()
 Platform-specific before measurement call. More...
 
tvm_crt_error_t TVMPlatformAfterMeasurement ()
 Platform-specific after measurement call. More...
 
tvm_crt_error_t TVMPlatformGenerateRandom (uint8_t *buffer, size_t num_bytes)
 Fill a buffer with random data. More...
 
tvm_crt_error_t TVMPlatformInitialize ()
 Initialize TVM inference. More...
 

Detailed Description

The virtual memory manager for micro-controllers.

Function Documentation

◆ TVMPlatformAbort()

void TVMPlatformAbort ( tvm_crt_error_t  code)

Called when an internal error occurs and execution cannot continue.

The platform should ideally restart or hang at this point.

Parameters
codeAn error code.

◆ TVMPlatformAfterMeasurement()

tvm_crt_error_t TVMPlatformAfterMeasurement ( )

Platform-specific after measurement call.

A function which is called after calling TVMFuncCall in the TimeEvaluator. It is the counterpart of the TVMPlatformBeforeMeasurement function.

Returns
kTvmErrorNoError if successful; a descriptive error code otherwise.

◆ TVMPlatformBeforeMeasurement()

tvm_crt_error_t TVMPlatformBeforeMeasurement ( )

Platform-specific before measurement call.

A function which is called before calling TVMFuncCall in the TimeEvaluator. Can be used, for example, to initialize reset global state which may affect the results of measurement.

Returns
kTvmErrorNoError if successful; a descriptive error code otherwise.

◆ TVMPlatformFormatMessage()

size_t TVMPlatformFormatMessage ( char *  out_buf,
size_t  out_buf_size_bytes,
const char *  fmt,
va_list  args 
)

Called by the microTVM RPC server to implement TVMLogf.

Not required to be implemented when the RPC server is not linked into the binary. This function's signature matches that of vsnprintf, so trivial implementations can just call vsnprintf.

Parameters
out_bufA char buffer where the formatted string should be written.
out_buf_size_bytesNumber of bytes available for writing in out_buf.
fmtThe printf-style formatstring.
argsextra arguments to be formatted.
Returns
number of bytes written.

◆ TVMPlatformGenerateRandom()

tvm_crt_error_t TVMPlatformGenerateRandom ( uint8_t *  buffer,
size_t  num_bytes 
)

Fill a buffer with random data.

Cryptographically-secure random data is NOT required. This function is intended for use cases such as filling autotuning input tensors and choosing the nonce used for microTVM RPC.

This function does not need to be implemented for inference tasks. It is used only by AutoTVM and the RPC server. When not implemented, an internal weak-linked stub is provided.

Please take care that across successive resets, this function returns different sequences of values. If e.g. the random number generator is seeded with the same value, it may make it difficult for a host to detect device resets during autotuning or host-driven inference.

Parameters
bufferPointer to the 0th byte to write with random data. num_bytes of random data should be written here.
num_bytesNumber of bytes to write.
Returns
kTvmErrorNoError if successful; a descriptive error code otherwise.

◆ TVMPlatformInitialize()

tvm_crt_error_t TVMPlatformInitialize ( )

Initialize TVM inference.

Placeholder function for TVM inference initializations on a specific platform. A common use of this function is setting up workspace memory for TVM inference.

Returns
kTvmErrorNoError if successful.

◆ TVMPlatformMemoryAllocate()

tvm_crt_error_t TVMPlatformMemoryAllocate ( size_t  num_bytes,
DLDevice  dev,
void **  out_ptr 
)

Allocate memory for use by TVM.

When this function returns something other than kTvmErrorNoError, *out_ptr should not be modified and the caller is not obligated to call TVMPlatformMemoryFree in order to avoid a memory leak.

Parameters
num_bytesNumber of bytes requested.
devExecution device that will be used with the allocated memory. Fixed to {kDLCPU, 0}.
out_ptrA pointer to which is written a pointer to the newly-allocated memory.
Returns
kTvmErrorNoError if successful; a descriptive error code otherwise.

◆ TVMPlatformMemoryFree()

tvm_crt_error_t TVMPlatformMemoryFree ( void *  ptr,
DLDevice  dev 
)

Free memory used by TVM.

Parameters
ptrA pointer returned from TVMPlatformMemoryAllocate which should be free'd.
devExecution device passed to TVMPlatformMemoryAllocate. Fixed to {kDLCPU, 0}.
Returns
kTvmErrorNoError if successful; a descriptive error code otherwise.

◆ TVMPlatformTimerStart()

tvm_crt_error_t TVMPlatformTimerStart ( )

Start a device timer.

The device timer used must not be running.

Returns
kTvmErrorNoError if successful; a descriptive error code otherwise.

◆ TVMPlatformTimerStop()

tvm_crt_error_t TVMPlatformTimerStop ( double *  elapsed_time_seconds)

Stop the running device timer and get the elapsed time (in microseconds).

The device timer used must be running.

Parameters
elapsed_time_secondsPointer to write elapsed time into.
Returns
kTvmErrorNoError if successful; a descriptive error code otherwise.