MLIR 22.0.0git
ExecutionEngine.h
Go to the documentation of this file.
1//===-- mlir-c/ExecutionEngine.h - Execution engine management ---*- C -*-====//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM
4// Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9//
10// This header provides basic access to the MLIR JIT. This is minimalist and
11// experimental at the moment.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef MLIR_C_EXECUTIONENGINE_H
16#define MLIR_C_EXECUTIONENGINE_H
17
18#include "mlir-c/IR.h"
19#include "mlir-c/Support.h"
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25#define DEFINE_C_API_STRUCT(name, storage) \
26 struct name { \
27 storage *ptr; \
28 }; \
29 typedef struct name name
30
31DEFINE_C_API_STRUCT(MlirExecutionEngine, void);
32
33#undef DEFINE_C_API_STRUCT
34
35/// Creates an ExecutionEngine for the provided ModuleOp. The ModuleOp is
36/// expected to be "translatable" to LLVM IR (only contains operations in
37/// dialects that implement the `LLVMTranslationDialectInterface`). The module
38/// ownership stays with the client and can be destroyed as soon as the call
39/// returns. `optLevel` is the optimization level to be used for transformation
40/// and code generation. LLVM passes at `optLevel` are run before code
41/// generation. The number and array of paths corresponding to shared libraries
42/// that will be loaded are specified via `numPaths` and `sharedLibPaths`
43/// respectively.
44/// The `enablePIC` arguments controls the relocation model, when true the
45/// generated code is emitted as "position independent", making it possible to
46/// save it and reload it as a shared object in another process.
47/// TODO: figure out other options.
49 MlirModule op, int optLevel, int numPaths,
50 const MlirStringRef *sharedLibPaths, bool enableObjectDump, bool enablePIC);
51
52/// Initialize the ExecutionEngine. Global constructors specified by
53/// `llvm.mlir.global_ctors` will be run. One common scenario is that kernel
54/// binary compiled from `gpu.module` gets loaded during initialization. Make
55/// sure all symbols are resolvable before initialization by calling
56/// `mlirExecutionEngineRegisterSymbol` or including shared libraries.
57MLIR_CAPI_EXPORTED void mlirExecutionEngineInitialize(MlirExecutionEngine jit);
58
59/// Destroy an ExecutionEngine instance.
60MLIR_CAPI_EXPORTED void mlirExecutionEngineDestroy(MlirExecutionEngine jit);
61
62/// Checks whether an execution engine is null.
63static inline bool mlirExecutionEngineIsNull(MlirExecutionEngine jit) {
64 return !jit.ptr;
65}
66
67/// Invoke a native function in the execution engine by name with the arguments
68/// and result of the invoked function passed as an array of pointers. The
69/// function must have been tagged with the `llvm.emit_c_interface` attribute.
70/// Returns a failure if the execution fails for any reason (the function name
71/// can't be resolved for instance).
73 MlirExecutionEngine jit, MlirStringRef name, void **arguments);
74
75/// Lookup the wrapper of the native function in the execution engine with the
76/// given name, returns nullptr if the function can't be looked-up.
78mlirExecutionEngineLookupPacked(MlirExecutionEngine jit, MlirStringRef name);
79
80/// Lookup a native function in the execution engine by name, returns nullptr
81/// if the name can't be looked-up.
82MLIR_CAPI_EXPORTED void *mlirExecutionEngineLookup(MlirExecutionEngine jit,
83 MlirStringRef name);
84
85/// Register a symbol with the jit: this symbol will be accessible to the jitted
86/// code.
88mlirExecutionEngineRegisterSymbol(MlirExecutionEngine jit, MlirStringRef name,
89 void *sym);
90
91/// Dump as an object in `fileName`.
93mlirExecutionEngineDumpToObjectFile(MlirExecutionEngine jit,
94 MlirStringRef fileName);
95
96#ifdef __cplusplus
97}
98#endif
99
100#endif // MLIR_C_EXECUTIONENGINE_H
MLIR_CAPI_EXPORTED void * mlirExecutionEngineLookupPacked(MlirExecutionEngine jit, MlirStringRef name)
Lookup the wrapper of the native function in the execution engine with the given name,...
MLIR_CAPI_EXPORTED void * mlirExecutionEngineLookup(MlirExecutionEngine jit, MlirStringRef name)
Lookup a native function in the execution engine by name, returns nullptr if the name can't be looked...
#define DEFINE_C_API_STRUCT(name, storage)
MLIR_CAPI_EXPORTED void mlirExecutionEngineDumpToObjectFile(MlirExecutionEngine jit, MlirStringRef fileName)
Dump as an object in fileName.
MLIR_CAPI_EXPORTED MlirExecutionEngine mlirExecutionEngineCreate(MlirModule op, int optLevel, int numPaths, const MlirStringRef *sharedLibPaths, bool enableObjectDump, bool enablePIC)
Creates an ExecutionEngine for the provided ModuleOp.
MLIR_CAPI_EXPORTED void mlirExecutionEngineDestroy(MlirExecutionEngine jit)
Destroy an ExecutionEngine instance.
MLIR_CAPI_EXPORTED MlirLogicalResult mlirExecutionEngineInvokePacked(MlirExecutionEngine jit, MlirStringRef name, void **arguments)
Invoke a native function in the execution engine by name with the arguments and result of the invoked...
MLIR_CAPI_EXPORTED void mlirExecutionEngineInitialize(MlirExecutionEngine jit)
Initialize the ExecutionEngine.
MLIR_CAPI_EXPORTED void mlirExecutionEngineRegisterSymbol(MlirExecutionEngine jit, MlirStringRef name, void *sym)
Register a symbol with the jit: this symbol will be accessible to the jitted code.
static bool mlirExecutionEngineIsNull(MlirExecutionEngine jit)
Checks whether an execution engine is null.
#define MLIR_CAPI_EXPORTED
Definition Support.h:46
A logical result value, essentially a boolean with named states.
Definition Support.h:116
A pointer to a sized fragment of a string, not necessarily null-terminated.
Definition Support.h:73