SetSysWorkSpace

Applicability

Product

Supported

Atlas 350 Accelerator Card

Atlas A3 training product / Atlas A3 inference product

Atlas A2 training product / Atlas A2 inference product

Atlas 200I/500 A2 inference product

x

Atlas inference product AI Core

Atlas inference product Vector Core

x

Atlas training product

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 Kernel APIs, this API needs to be called. When the project-based operator development mode or development processes based on the kernel launch mode (HAVE_WORKSPACE is enabled) are 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 API parameters

Parameter

Input/Output

Description

workspace

Input

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

Constraints

None

Returns

None

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
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.
    // ...
    // Global memory pointer to the workspace passed by the kernel function, which is used to set the system workspace.
    AscendC::SetSysWorkspace(workspace);
    if (GetSysWorkSpacePtr() == nullptr) {
        return;
    }
    // Subsequent Matmul instructions
    ...
}