lite/global.h

using lite::DecryptionFunc = std::function<std::vector<uint8_t>(const void*, size_t, const std::vector<uint8_t>&)>

Model decryption function.

Param arg1

the to be decrypted model memory pointer

Param arg2

the byte size of the decrypted model memory

Param arg3

the decryption key in vector

Return

the decrypted model in vector format, it’s length and content can get by the operators of vector

bool lite::register_decryption_and_key(std::string decrypt_name, const DecryptionFunc &func, const std::vector<uint8_t> &key)

register a custom decryption method and key to lite

Parameters
  • decrypt_name – the name of the decryption, which will act as the hash key to find the decryption method

  • func – the decryption function, which will decrypt the model with the registered key, return a vector that contain the decrypted model

  • key – the decryption key of the method

Returns

Whether or not the decryption method register successful

bool lite::update_decryption_or_key(std::string decrypt_name, const DecryptionFunc &func, const std::vector<uint8_t> &key)

update decryption function or key of a custom decryption method, in lite the decryption function and the key store in pair, user can change one of which by this function

Parameters
  • decrypt_name – the name of the decryption, which will act as the hash key to find the decryption method

  • func – the decryption function, which will decrypt the model with the registered key, return a vector that contain the decrypted model. if the function is nullptr, it will not be updated

  • key – the decryption key of the method, if the size of key is zero, the key will not be updated

Returns

Whether or not the decryption method update successful

using lite::ParseInfoFunc = std::function<bool(const void*, size_t, const std::string model_name, Config &config, NetworkIO &network_io, std::unordered_map<std::string, LiteAny> &isolated_config_map, std::string &extra_info)>

Model information parse function, MegEngine Lite model may pack some information with the model to configure the model inference processing conveniently, this function is used to parse the information packed with model, and store the parsed result into the params.

* embed:rst:leading-asterisk
*  .. list-table::
*      :widths: 20 10 30
*      :header-rows: 1
*
*      * - name
*        - type
*        - default
*      * - "device_id"
*        - int
*        - 0
*      * - "number_threads"
*        - uint32_t
*        - 1
*      * - "is_inplace_model"
*        - bool
*        - false
*      * - "use_tensorrt"
*        - bool
*        - false
*

Param arg1

the information memory pointer

Param arg2

the size the information memory

Param arg3

the model name used for check whether the name in the information

Param arg4

the model configuration, ParseInfoFunc fill it with the parsed information, the configuration will influence Network inference later

Param arg5

the model IO information, ParseInfoFunc fill it with the parsed information, the networkio will influence Network inference later

Param arg6

the other configurations do not include in configuration and networkIO, ParseInfoFunc fill it with the parsed information pair, now support:

Return

Whether or not the parse function parse successfully

bool lite::register_parse_info_func(std::string info_type, const ParseInfoFunc &parse_func)

register a custom parser function to lite

Parameters
  • info_type – the name of the parser function, which will act as the hash key to find the parser method.

  • parse_func – the parser function, which will parse the given information and modify the Network configuration and IO information.

Returns

Whether or not the parse function register successful

void lite::try_coalesce_all_free_memory()

try to coalesce all free memory in megenine, when call it MegEnine Lite will try to free all the unused memory thus decrease the runtime memory usage

void lite::set_loader_lib_path(const std::string &loader_path)

set the loader path to be used in lite

Parameters

loader_path – the file path which store the loader library

void lite::set_persistent_cache(const std::string &cache_path, bool always_sync = false)

Set the algo policy cache file for CPU/CUDA, the algo policy cache is produced by megengine fast-run.

Parameters
  • cache_path – the file path which store the cache

  • always_sync – always update the cache file when model run

void lite::dump_persistent_cache(const std::string &cache_path)

dump the PersistentCache policy cache to the specific file, if the network is set to profile when forward, though this the algo policy will dump to file

Parameters

cache_path – the cache file path to be dump

void lite::get_version(int &major, int &minor, int &patch)

get megengint lite version

Parameters
  • major – the major version of megengine lite

  • minor – the minor version of megengine lite

  • patch – the patch version of megengine lite

void lite::set_log_level(LiteLogLevel level)

set the current log level

Parameters

level – the new log level to be set

LiteLogLevel lite::get_log_level()

get the current log level

Returns

the current log level

size_t lite::get_device_count(LiteDeviceType device_type)

get the number of device of the given device type in current context

Parameters

device_type – the to be count device type

Returns

the number of device

bool lite::register_memory_pair(void *vir_ptr, void *phy_ptr, size_t length, LiteDeviceType device, LiteBackend backend = LiteBackend::LITE_DEFAULT)

register the physical and virtual address pair to the mge, some device need the map from physical to virtual

Parameters
  • vir_ptr – - the virtual ptr to set to megenine

  • phy_ptr – - the physical ptr to set to megenine

  • device – - the device to set the pair memory

  • backend – - the backend to set the pair memory

Returns

Whether the register is successful

bool lite::clear_memory_pair(void *vir_ptr, void *phy_ptr, LiteDeviceType device, LiteBackend backend = LiteBackend::LITE_DEFAULT)

clear the physical and virtual address pair in mge

Parameters
  • vir_ptr – - the virtual ptr to set to megenine

  • phy_ptr – - the physical ptr to set to megenine

  • device – - the device to set the pair memory

  • backend – - the backend to set the pair memory

Returns

Whether the clear is successful

void *lite::lookup_physic_ptr(void *vir_ptr, LiteDeviceType device, LiteBackend backend)

get the physic address by the virtual address in mge.

Parameters
  • vir_ptr – - the virtual ptr to set to megenine

  • device – - the device to set the pair memory

  • backend – - the backend to set the pair memory

Returns

The physic address to lookup