Sets the pointer to the system workspace, which is the workspace required by the framework. High-level APIs such as Matmul require the system workspace. Therefore, when using such APIs, you need to call this API to set the pointer to 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. Example:
// 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 block can be used.
currentWorkspace[0] = usrSize + sysWorkspaceSize; // Set the total workspace size. The total workspace space is allocated and managed by the framework.
// ...
} 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 developer. |
Kirin 9020 series processors
Kirin 9030 series processors
Kirin X90 series processors
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 fused operator.
// ...
AscendC::SetSysWorkspace(workspace);
if (GetSysWorkSpacePtr() == nullptr) {
return;
}
}