brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.1 KiB · 1a58d68 Raw
98 lines · c
1//===-- mlir-c/ExecutionEngine.h - Execution engine management ---*- C -*-====//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM4// Exceptions.5// See https://llvm.org/LICENSE.txt for license information.6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7//8//===----------------------------------------------------------------------===//9//10// This header provides basic access to the MLIR JIT. This is minimalist and11// experimental at the moment.12//13//===----------------------------------------------------------------------===//14 15#ifndef MLIR_C_EXECUTIONENGINE_H16#define MLIR_C_EXECUTIONENGINE_H17 18#include "mlir-c/IR.h"19#include "mlir-c/Support.h"20 21#ifdef __cplusplus22extern "C" {23#endif24 25#define DEFINE_C_API_STRUCT(name, storage)                                     \26  struct name {                                                                \27    storage *ptr;                                                              \28  };                                                                           \29  typedef struct name name30 31DEFINE_C_API_STRUCT(MlirExecutionEngine, void);32 33#undef DEFINE_C_API_STRUCT34 35/// Creates an ExecutionEngine for the provided ModuleOp. The ModuleOp is36/// expected to be "translatable" to LLVM IR (only contains operations in37/// dialects that implement the `LLVMTranslationDialectInterface`). The module38/// ownership stays with the client and can be destroyed as soon as the call39/// returns. `optLevel` is the optimization level to be used for transformation40/// and code generation. LLVM passes at `optLevel` are run before code41/// generation. The number and array of paths corresponding to shared libraries42/// that will be loaded are specified via `numPaths` and `sharedLibPaths`43/// respectively.44/// TODO: figure out other options.45MLIR_CAPI_EXPORTED MlirExecutionEngine mlirExecutionEngineCreate(46    MlirModule op, int optLevel, int numPaths,47    const MlirStringRef *sharedLibPaths, bool enableObjectDump);48 49/// Initialize the ExecutionEngine. Global constructors specified by50/// `llvm.mlir.global_ctors` will be run. One common scenario is that kernel51/// binary compiled from `gpu.module` gets loaded during initialization. Make52/// sure all symbols are resolvable before initialization by calling53/// `mlirExecutionEngineRegisterSymbol` or including shared libraries.54MLIR_CAPI_EXPORTED void mlirExecutionEngineInitialize(MlirExecutionEngine jit);55 56/// Destroy an ExecutionEngine instance.57MLIR_CAPI_EXPORTED void mlirExecutionEngineDestroy(MlirExecutionEngine jit);58 59/// Checks whether an execution engine is null.60static inline bool mlirExecutionEngineIsNull(MlirExecutionEngine jit) {61  return !jit.ptr;62}63 64/// Invoke a native function in the execution engine by name with the arguments65/// and result of the invoked function passed as an array of pointers. The66/// function must have been tagged with the `llvm.emit_c_interface` attribute.67/// Returns a failure if the execution fails for any reason (the function name68/// can't be resolved for instance).69MLIR_CAPI_EXPORTED MlirLogicalResult mlirExecutionEngineInvokePacked(70    MlirExecutionEngine jit, MlirStringRef name, void **arguments);71 72/// Lookup the wrapper of the native function in the execution engine with the73/// given name, returns nullptr if the function can't be looked-up.74MLIR_CAPI_EXPORTED void *75mlirExecutionEngineLookupPacked(MlirExecutionEngine jit, MlirStringRef name);76 77/// Lookup a native function in the execution engine by name, returns nullptr78/// if the name can't be looked-up.79MLIR_CAPI_EXPORTED void *mlirExecutionEngineLookup(MlirExecutionEngine jit,80                                                   MlirStringRef name);81 82/// Register a symbol with the jit: this symbol will be accessible to the jitted83/// code.84MLIR_CAPI_EXPORTED void85mlirExecutionEngineRegisterSymbol(MlirExecutionEngine jit, MlirStringRef name,86                                  void *sym);87 88/// Dump as an object in `fileName`.89MLIR_CAPI_EXPORTED void90mlirExecutionEngineDumpToObjectFile(MlirExecutionEngine jit,91                                    MlirStringRef fileName);92 93#ifdef __cplusplus94}95#endif96 97#endif // MLIR_C_EXECUTIONENGINE_H98