Platform Support for XSched

Code Explanation

Platforms includes two parts of code in XSched: XAL Lib & XShim Lib, corresponding to hal & shim directory in each platform.

XAL

The XAL Lib implements the HwCommand and HwQueue abstraction for each platform.

HwCommand

When hijacking a command to launch a kernel to XPU (such as zeCommandListAppendLaunchKernel in LevelZero, cuLaunch in CUDA), we need to encapsulate it as HwCommand and submit it to corresponding XQueue.

The main member functions implemented in HwCommand and their explanations are as follows:

Interface Description
Enqueue() Call driver API to launch kernel
Synchronize() Synchronize HwCommand
Synchronizable() Check if HwCommand can be synchronized
EnableSynchronization() Enable HwCommand to be synchronized by appending event or fence

HwQueue

HwQueue is an abstraction of real device queue (such as zeCommandQueue and zeImmediateCommandList in LevelZero, CUstream in CUDA). We need to implement different functions to support different preemption level.

Preemption Level Interface Description
Level-1 Launch(HwCommand) Launch a HwCommand by calling HwCommand->Enqueue()
Synchronize() Wait for all commands in the HwQueue to complete
Level-2 Deactivate() Deactivate the HwQueue to prevent all its commands from being selected for execution
Reactivate() Reactivate the HwQueue to allow all its commands to be selected for execution
Level-3 Interrupt() Interrupt the running command of the HwQueue
Restore() Restore the interrupted command of the HwQueue

XShim

The main function of XShim Lib is to change the applicaion workflow by intercepting XPU driver API calls. The XShim library provides transparency and allow applications to use XSched without modifications.

XShim Lib mainly consists of two files: intercept.cpp and shim.cpp.

  • intercept.cpp can be auto generated by tools we provide. It provides transparent hijacking of Driver API through a unified macro definitio.
  • shim.cpp implements the handling of hijacked APIs.

Supported Platforms

Name Usage
CUDA README
HIP README
LevelZero README
OpenCL README
AscendCL README
cuDLA README
VIP README

If you are interested in supporting XSched on a new platform, please refer to our example and guide.