SetSysWorkSpace

Function Usage

Sets the pointer to the system workspace, which is the workspace required by the framework. When using high-level APIs such as Matmul, you need to call this API. When the project-based operator development mode or development processes based on the kernel launch mode (-DHAVE_WORKSPACE is enabled) is used, the framework automatically sets the parameters. In other scenarios, you need to call SetSysWorkSpace to set the system workspace.

Before calling this API on the kernel, call GetLibApiWorkSpaceSize on the host to obtain the size of the system workspace and set workspace size. An example is as follows.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
// User-defined tiling function
static ge::graphStatus TilingFunc(gert::TilingContext* context)
{
    AddApiTiling tiling;
    ...
    size_t usrSize = 256; // Set the workspace size as required.
    // To use the system workspace, call GetLibApiWorkSpaceSize to obtain the size of the system workspace.
    auto ascendcPlatform = platform_ascendc:: PlatformAscendC(context->GetPlatformInfo());
    uint32_t sysWorkspaceSize = ascendcPlatform.GetLibApiWorkSpaceSize();
    size_t *currentWorkspace = context->GetWorkspaceSizes(1); // Obtain the workspace pointer through the framework. The input parameter of GetWorkspaceSizes is the number of required workspace blocks. Currently, only one board can be used.
    currentWorkspace[0] = usrSize + sysWorkspaceSize; // Specify the total workspace size. The total workspace space is allocated and managed by the framework.
    ...
}

Prototype

1
__aicore__ inline void SetSysWorkSpace(GM_ADDR workspace)

Parameters

Table 1 Parameters

Parameter

Input/Output

Description

workspace

Input

Pointer to the workspace input by the kernel function, including the system workspace and the workspace used by the user.

Availability

Atlas Training Series Product

Precautions

None

Returns

None

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
template<typename aType, typename bType, typename cType, typename biasType>
__aicore__ inline void MatmulLeakyKernel<aType, bType, cType, biasType>::Init(
    GM_ADDR a, GM_ADDR b, GM_ADDR bias, GM_ADDR c, GM_ADDR workspace, const TCubeTiling& tiling, float alpha)
{
    // Initialize the fusion operator.
    // ...
    AscendC::SetSysWorkspace(workspace);
    if (GetSysWorkSpacePtr() == nullptr) {
        return;
    }
}