MLIR 24.0.0git
LevelZeroRuntimeWrappers.cpp File Reference
#include "level_zero/ze_api.h"
#include <cassert>
#include <cstring>
#include <deque>
#include <exception>
#include <functional>
#include <iostream>
#include <limits>
#include <memory>
#include <stdexcept>
#include <string>
#include <unordered_map>
#include <vector>

Go to the source code of this file.

Classes

struct  ZeContextDeleter
struct  ZeCommandListDeleter
struct  L0RTContextWrapper
struct  ZeEventDeleter
struct  ZeEventPoolDeleter
struct  DynamicEventPool
struct  StreamWrapper

Macros

#define MLIR_LEVELZERO_WRAPPERS_EXPORT   __attribute__((visibility("default")))
#define L0_SAFE_CALL(call)

Typedefs

using UniqueZeContext
using UniqueZeCommandList
using UniqueZeEvent
using UniqueZeEventPool

Functions

static ze_result_t zeDriverGetLastErrorDescriptionWrapper (const char **errorString)
static ze_driver_handle_t getDriver (uint32_t idx=0)
static ze_device_handle_t getDevice (const uint32_t driverIdx=0, const int32_t devIdx=0)
static ze_context_handle_t getContext (ze_driver_handle_t driver)
static L0RTContextWrapper & getRtContext ()
static DynamicEventPool & getDynamicEventPool ()
static ze_module_handle_t loadModule (const void *data, size_t dataSize, ze_module_format_t format=ZE_MODULE_FORMAT_NATIVE)
MLIR_LEVELZERO_WRAPPERS_EXPORT StreamWrapper * mgpuStreamCreate ()
MLIR_LEVELZERO_WRAPPERS_EXPORT void mgpuStreamSynchronize (StreamWrapper *stream)
MLIR_LEVELZERO_WRAPPERS_EXPORT void mgpuStreamDestroy (StreamWrapper *stream)
MLIR_LEVELZERO_WRAPPERS_EXPORT void mgpuStreamWaitEvent (StreamWrapper *stream, ze_event_handle_t event)
MLIR_LEVELZERO_WRAPPERS_EXPORT ze_event_handle_t mgpuEventCreate ()
MLIR_LEVELZERO_WRAPPERS_EXPORT void mgpuEventDestroy (ze_event_handle_t event)
MLIR_LEVELZERO_WRAPPERS_EXPORT void mgpuEventSynchronize (ze_event_handle_t event)
MLIR_LEVELZERO_WRAPPERS_EXPORT void mgpuEventRecord (ze_event_handle_t event, StreamWrapper *stream)
MLIR_LEVELZERO_WRAPPERS_EXPORT void * mgpuMemAlloc (uint64_t size, StreamWrapper *stream, bool isShared)
MLIR_LEVELZERO_WRAPPERS_EXPORT void mgpuMemFree (void *ptr, StreamWrapper *stream)
MLIR_LEVELZERO_WRAPPERS_EXPORT void mgpuMemcpy (void *dst, void *src, size_t sizeBytes, StreamWrapper *stream)
template<typename PATTERN_TYPE>
static void mgpuMemset (void *dst, PATTERN_TYPE value, size_t count, StreamWrapper *stream)
MLIR_LEVELZERO_WRAPPERS_EXPORT void mgpuMemset32 (void *dst, unsigned int value, size_t count, StreamWrapper *stream)
MLIR_LEVELZERO_WRAPPERS_EXPORT void mgpuMemset16 (void *dst, unsigned short value, size_t count, StreamWrapper *stream)
MLIR_LEVELZERO_WRAPPERS_EXPORT ze_module_handle_t mgpuModuleLoad (const void *data, size_t gpuBlobSize)
MLIR_LEVELZERO_WRAPPERS_EXPORT ze_module_handle_t mgpuModuleLoadJIT (void *data, int optLevel, size_t assemblySize)
MLIR_LEVELZERO_WRAPPERS_EXPORT ze_kernel_handle_t mgpuModuleGetFunction (ze_module_handle_t module, const char *name)
MLIR_LEVELZERO_WRAPPERS_EXPORT void mgpuLaunchKernel (ze_kernel_handle_t kernel, size_t gridX, size_t gridY, size_t gridZ, size_t blockX, size_t blockY, size_t blockZ, int32_t sharedMemBytes, StreamWrapper *stream, void **params, void **, size_t paramsCount)
MLIR_LEVELZERO_WRAPPERS_EXPORT void mgpuModuleUnload (ze_module_handle_t module)
MLIR_LEVELZERO_WRAPPERS_EXPORT void mgpuSetDefaultDevice (int32_t devIdx)

Macro Definition Documentation

◆ L0_SAFE_CALL

#define L0_SAFE_CALL ( call)
Value:
{ \
ze_result_t status = (call); \
if (status != ZE_RESULT_SUCCESS) { \
const char *errorString; \
ze_result_t descriptionStatus = \
zeDriverGetLastErrorDescriptionWrapper(&errorString); \
if (descriptionStatus == ZE_RESULT_SUCCESS && errorString) \
std::cerr << "L0 error " << status << ": " << errorString \
<< std::endl; \
else \
std::cerr << "Level Zero call failed: " << #call << ", status=0x" \
<< std::hex << static_cast<uint32_t>(status) << std::dec \
<< std::endl; \
std::abort(); \
} \
}

Definition at line 47 of file LevelZeroRuntimeWrappers.cpp.

Referenced by DynamicEventPool::createNewPool(), getContext(), getDevice(), getDriver(), L0RTContextWrapper::L0RTContextWrapper(), loadModule(), mgpuEventRecord(), mgpuEventSynchronize(), mgpuLaunchKernel(), mgpuMemAlloc(), mgpuMemcpy(), mgpuMemFree(), mgpuMemset(), mgpuModuleGetFunction(), mgpuModuleUnload(), ZeCommandListDeleter::operator()(), ZeContextDeleter::operator()(), ZeEventDeleter::operator()(), ZeEventPoolDeleter::operator()(), DynamicEventPool::releaseEvent(), StreamWrapper::sync(), and DynamicEventPool::takeEvent().

◆ MLIR_LEVELZERO_WRAPPERS_EXPORT

#define MLIR_LEVELZERO_WRAPPERS_EXPORT   __attribute__((visibility("default")))

Definition at line 30 of file LevelZeroRuntimeWrappers.cpp.

Referenced by mgpuEventCreate(), and mgpuStreamCreate().

Typedef Documentation

◆ UniqueZeCommandList

Initial value:
std::unique_ptr<std::remove_pointer<ze_command_list_handle_t>::type,

Definition at line 153 of file LevelZeroRuntimeWrappers.cpp.

◆ UniqueZeContext

Initial value:
std::unique_ptr<std::remove_pointer<ze_context_handle_t>::type,

Definition at line 150 of file LevelZeroRuntimeWrappers.cpp.

◆ UniqueZeEvent

Initial value:
std::unique_ptr<std::remove_pointer<ze_event_handle_t>::type,

Definition at line 251 of file LevelZeroRuntimeWrappers.cpp.

◆ UniqueZeEventPool

Initial value:
std::unique_ptr<std::remove_pointer<ze_event_pool_handle_t>::type,

Definition at line 254 of file LevelZeroRuntimeWrappers.cpp.

Function Documentation

◆ getContext()

ze_context_handle_t getContext ( ze_driver_handle_t driver)
static

Definition at line 122 of file LevelZeroRuntimeWrappers.cpp.

References L0_SAFE_CALL.

◆ getDevice()

ze_device_handle_t getDevice ( const uint32_t driverIdx = 0,
const int32_t devIdx = 0 )
static

Definition at line 99 of file LevelZeroRuntimeWrappers.cpp.

References getDriver(), and L0_SAFE_CALL.

Referenced by L0RTContextWrapper::L0RTContextWrapper().

◆ getDriver()

ze_driver_handle_t getDriver ( uint32_t idx = 0)
static

Definition at line 76 of file LevelZeroRuntimeWrappers.cpp.

References L0_SAFE_CALL.

Referenced by getDevice(), and L0RTContextWrapper::L0RTContextWrapper().

◆ getDynamicEventPool()

DynamicEventPool & getDynamicEventPool ( )
static

◆ getRtContext()

◆ loadModule()

ze_module_handle_t loadModule ( const void * data,
size_t dataSize,
ze_module_format_t format = ZE_MODULE_FORMAT_NATIVE )
static

◆ mgpuEventCreate()

◆ mgpuEventDestroy()

MLIR_LEVELZERO_WRAPPERS_EXPORT void mgpuEventDestroy ( ze_event_handle_t event)

◆ mgpuEventRecord()

◆ mgpuEventSynchronize()

MLIR_LEVELZERO_WRAPPERS_EXPORT void mgpuEventSynchronize ( ze_event_handle_t event)

Definition at line 467 of file LevelZeroRuntimeWrappers.cpp.

References L0_SAFE_CALL.

◆ mgpuLaunchKernel()

MLIR_LEVELZERO_WRAPPERS_EXPORT void mgpuLaunchKernel ( ze_kernel_handle_t kernel,
size_t gridX,
size_t gridY,
size_t gridZ,
size_t blockX,
size_t blockY,
size_t blockZ,
int32_t sharedMemBytes,
StreamWrapper * stream,
void ** params,
void ** ,
size_t paramsCount )

◆ mgpuMemAlloc()

MLIR_LEVELZERO_WRAPPERS_EXPORT void * mgpuMemAlloc ( uint64_t size,
StreamWrapper * stream,
bool isShared )

◆ mgpuMemcpy()

MLIR_LEVELZERO_WRAPPERS_EXPORT void mgpuMemcpy ( void * dst,
void * src,
size_t sizeBytes,
StreamWrapper * stream )

◆ mgpuMemFree()

◆ mgpuMemset()

template<typename PATTERN_TYPE>
void mgpuMemset ( void * dst,
PATTERN_TYPE value,
size_t count,
StreamWrapper * stream )
static

◆ mgpuMemset16()

MLIR_LEVELZERO_WRAPPERS_EXPORT void mgpuMemset16 ( void * dst,
unsigned short value,
size_t count,
StreamWrapper * stream )

Definition at line 544 of file LevelZeroRuntimeWrappers.cpp.

References mgpuMemset().

◆ mgpuMemset32()

MLIR_LEVELZERO_WRAPPERS_EXPORT void mgpuMemset32 ( void * dst,
unsigned int value,
size_t count,
StreamWrapper * stream )

Definition at line 538 of file LevelZeroRuntimeWrappers.cpp.

References mgpuMemset().

◆ mgpuModuleGetFunction()

MLIR_LEVELZERO_WRAPPERS_EXPORT ze_kernel_handle_t mgpuModuleGetFunction ( ze_module_handle_t module,
const char * name )

Definition at line 573 of file LevelZeroRuntimeWrappers.cpp.

References L0_SAFE_CALL.

◆ mgpuModuleLoad()

MLIR_LEVELZERO_WRAPPERS_EXPORT ze_module_handle_t mgpuModuleLoad ( const void * data,
size_t gpuBlobSize )

Definition at line 550 of file LevelZeroRuntimeWrappers.cpp.

References loadModule().

◆ mgpuModuleLoadJIT()

MLIR_LEVELZERO_WRAPPERS_EXPORT ze_module_handle_t mgpuModuleLoadJIT ( void * data,
int optLevel,
size_t assemblySize )

Definition at line 555 of file LevelZeroRuntimeWrappers.cpp.

References loadModule().

◆ mgpuModuleUnload()

MLIR_LEVELZERO_WRAPPERS_EXPORT void mgpuModuleUnload ( ze_module_handle_t module)

Definition at line 610 of file LevelZeroRuntimeWrappers.cpp.

References L0_SAFE_CALL.

◆ mgpuSetDefaultDevice()

◆ mgpuStreamCreate()

◆ mgpuStreamDestroy()

MLIR_LEVELZERO_WRAPPERS_EXPORT void mgpuStreamDestroy ( StreamWrapper * stream)

Definition at line 446 of file LevelZeroRuntimeWrappers.cpp.

◆ mgpuStreamSynchronize()

MLIR_LEVELZERO_WRAPPERS_EXPORT void mgpuStreamSynchronize ( StreamWrapper * stream)

Definition at line 440 of file LevelZeroRuntimeWrappers.cpp.

References StreamWrapper::sync().

◆ mgpuStreamWaitEvent()

MLIR_LEVELZERO_WRAPPERS_EXPORT void mgpuStreamWaitEvent ( StreamWrapper * stream,
ze_event_handle_t event )

Definition at line 451 of file LevelZeroRuntimeWrappers.cpp.

References StreamWrapper::sync().

◆ zeDriverGetLastErrorDescriptionWrapper()

ze_result_t zeDriverGetLastErrorDescriptionWrapper ( const char ** errorString)
static

Definition at line 359 of file LevelZeroRuntimeWrappers.cpp.

References L0RTContextWrapper::driver, and getRtContext().