tvm
|
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>
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... | |
The virtual memory manager for micro-controllers.
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.
code | An error code. |
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.
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.
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.
out_buf | A char buffer where the formatted string should be written. |
out_buf_size_bytes | Number of bytes available for writing in out_buf. |
fmt | The printf-style formatstring. |
args | extra arguments to be formatted. |
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.
buffer | Pointer to the 0th byte to write with random data. num_bytes of random data should be written here. |
num_bytes | Number of bytes to write. |
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.
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.
num_bytes | Number of bytes requested. |
dev | Execution device that will be used with the allocated memory. Fixed to {kDLCPU, 0}. |
out_ptr | A pointer to which is written a pointer to the newly-allocated memory. |
tvm_crt_error_t TVMPlatformMemoryFree | ( | void * | ptr, |
DLDevice | dev | ||
) |
Free memory used by TVM.
ptr | A pointer returned from TVMPlatformMemoryAllocate which should be free'd. |
dev | Execution device passed to TVMPlatformMemoryAllocate. Fixed to {kDLCPU, 0}. |
tvm_crt_error_t TVMPlatformTimerStart | ( | ) |
Start a device timer.
The device timer used must not be running.
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.
elapsed_time_seconds | Pointer to write elapsed time into. |