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/// TODO: figure out other options.
46 MlirModule op, int optLevel, int numPaths,
47 const MlirStringRef *sharedLibPaths, bool enableObjectDump);
48
49/// Initialize the ExecutionEngine. Global constructors specified by
50/// `llvm.mlir.global_ctors` will be run. One common scenario is that kernel
51/// binary compiled from `gpu.module` gets loaded during initialization. Make
52/// sure all symbols are resolvable before initialization by calling
53/// `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 arguments
65/// and result of the invoked function passed as an array of pointers. The
66/// 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 name
68/// can't be resolved for instance).
70 MlirExecutionEngine jit, MlirStringRef name, void **arguments);
71
72/// Lookup the wrapper of the native function in the execution engine with the
73/// given name, returns nullptr if the function can't be looked-up.
75mlirExecutionEngineLookupPacked(MlirExecutionEngine jit, MlirStringRef name);
76
77/// Lookup a native function in the execution engine by name, returns nullptr
78/// 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 jitted
83/// code.
85mlirExecutionEngineRegisterSymbol(MlirExecutionEngine jit, MlirStringRef name,
86 void *sym);
87
88/// Dump as an object in `fileName`.
90mlirExecutionEngineDumpToObjectFile(MlirExecutionEngine jit,
91 MlirStringRef fileName);
92
93#ifdef __cplusplus
94}
95#endif
96
97#endif // MLIR_C_EXECUTIONENGINE_H
MLIR_CAPI_EXPORTED MlirExecutionEngine mlirExecutionEngineCreate(MlirModule op, int optLevel, int numPaths, const MlirStringRef *sharedLibPaths, bool enableObjectDump)
Creates an ExecutionEngine for the provided ModuleOp.
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 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