SetNeedAtomic
Function Usage
Sets whether the framework is required to perform the atomic clean operation to ensure that the output memory has been initialized before the operator kernel is executed.
Atomic clean refers to the process of initializing the output memory on the global memory (GM) before operator execution to ensure the correctness of operations such as accumulation, maximum value calculation, and minimum value calculation.
- Before performing accumulation, clear related values in the GM.
- Before calculating the maximum value, initialize the related values in the GM to the minimum value of the corresponding data type.
- Before calculating the minimum value, initialize the related values in the GM to the maximum value of the corresponding data type.
The operator can perform initialization on its own, or you can use this API to enable the framework to automatically insert cleanup operators for initialization. Leveraging the framework for initialization takes advantage of the framework's optimization capabilities. For example, it centrally allocates zero-clearing buffers in graph mode to improve the efficiency of resource management and allocation.
The SetNeedAtomic API is used together with InitValue. InitValue is used to configure the outputs to be initialized and the initial values.
Prototype
ge::graphStatus SetNeedAtomic(const bool atomic)
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
atomic |
Input |
|
Returns
ge::GRAPH_SUCCESS on success.
For details about the definition of graphStatus, see ge::graphStatus.
Constraints
SetNeedAtomic and InitValue must be used together. Otherwise, the initialization does not take effect.
Examples
ge::graphStatus Tiling4XXX(TilingContext* context) {
auto ret = context->SetNeedAtomic(true);
// ...
}