MemoryConfig Constructor
Applicability
Product |
Supported |
|---|---|
√ |
|
√ |
|
☓ |
|
☓ |
|
√ |
Function Description
Constructs an object of class MemoryConfig for configuring system memory handling.
Function Prototype
1 2 3 4 5 6 | class MemoryConfig(): def __init__(self, atomic_clean_policy=0, static_memory_policy=0, memory_optimization_policy=None, variable_use_1g_huge_page=0 |
Parameters
Option |
Input/Output |
Description |
|---|---|---|
atomic_clean_policy |
Input |
Whether to clean up the memory occupied by all operators with the memset attribute (memset operators) on the network. The options are as follows:
|
static_memory_policy |
Input |
Memory allocation mode used during network running.
The default value is 0. NOTE:
|
variable_use_1g_huge_page |
Input |
In recommendation models, the embedding layer in TensorFlow uses variables. When embedding layers serve as input or output addresses for index-based operators (such as Gather and ScatterNd), large memory footprints may lead to extensive scattered access, potentially causing performance degradation. In such cases, you can try configuring this parameter to allocate memory for variables and constants using 1 GB huge pages, thereby improving memory access performance. The options are as follows:
Using 1 GB huge pages can effectively reduce the number of page table entries and expand the address range covered by the translation lookaside buffer (TLB) cache, thereby improving performance for scattered access patterns. The TLB is a hardware module on the Ascend AI processor that caches recently used virtual-to-physical address mappings. NOTE:
This parameter can be used only by the following products:
|
Returns
An object of the MemoryConfig class, as an argument passed to the NPURunConfig call.
Constraints
None
Example
1 2 3 4 5 | from npu_bridge.npu_init import * ... mem_config = MemoryConfig(atomic_clean_policy=0, static_memory_policy=0) session_config=tf.ConfigProto(allow_soft_placement=True) config = NPURunConfig(memory_config=mem_config, session_config=session_config) |