megenginelite.global_setting#

class LiteGlobal[source]#

Some global config in lite

static clear_memory_pair(vir_ptr, phy_ptr, device, backend=LiteBackend.LITE_DEFAULT)[source]#

Clear the physical and virtual address pair in MegEngine.

Parameters:
  • vir_ptr – the virtual ptr to set to MegEngine.

  • phy_ptr – the physical ptr to set to MegEngine.

  • device – the the device to set the pair memory.

  • backend – the backend to set the pair memory.

Returns:

Whether the clear is operation successful.

static dump_persistent_cache(path)[source]#

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:

path – the cache file path to be dumped.

static dump_tensorrt_cache()[source]#

Dump the TensorRT cache to the file set in set_tensorrt_cache.

static get_device_count(device_type)[source]#

Get the number of device of the given device type in current context.

Parameters:

device_type – the device type to be counted.

Returns:

the number of device.

static lookup_physic_ptr(vir_ptr, device, backend=LiteBackend.LITE_DEFAULT)[source]#

Get the physic address by the virtual address in MegEngine.

Parameters:
  • vir_ptr – the virtual ptr to set to MegEngine.

  • device – the the device to set the pair memory.

  • backend – the backend to set the pair memory.

Returns:

The physic address to lookup.

static register_decryption_and_key(decryption_name, decryption_func, key)[source]#

Register a custom decryption method and key to lite

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

  • decryption_func – the decryption function, which will decrypt the model with the registered key, then return the decrypted model. See decryption_func for more details.

  • key – the decryption key of the method.

static register_memory_pair(vir_ptr, phy_ptr, length, device, backend=LiteBackend.LITE_DEFAULT)[source]#

Register the physical and virtual address pair to the MegEngine, some device need the map from physical to virtual.

Parameters:
  • vir_ptr – the virtual ptr to set to MegEngine.

  • phy_ptr – the physical ptr to set to MegEngine.

  • length – the length of bytes to set pair memory.

  • device – the the device to set the pair memory.

  • backend – the backend to set the pair memory

Returns:

Whether the register operation is successful.

static set_loader_lib_path(path)[source]#

Set the loader path to be used in lite.

Parameters:

path – the file path which store the loader library.

static set_persistent_cache(path, always_sync=False)[source]#

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

Parameters:
  • path – the file path which store the cache.

  • always_sync – always update the cache file when model runs.

static set_tensorrt_cache(path)[source]#

Set the TensorRT engine cache path for serialized prebuilt ICudaEngine.

Parameters:

path – the cache file path to set

static try_coalesce_all_free_memory()[source]#

Try to coalesce all free memory in MegEngine. When call it MegEnine Lite will try to free all the unused memory thus decrease the runtime memory usage.

static update_decryption_key(decryption_name, key)[source]#

Update decryption key of a custom decryption method.

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

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