|
13 | 13 | #define ONNX_MLIR_ONNXMLIRCOMPILER_H
|
14 | 14 |
|
15 | 15 | #include <onnx-mlir/Compiler/OMCompilerTypes.h>
|
| 16 | +#ifdef __cplusplus |
| 17 | +#include <cstdint> |
| 18 | +#else |
| 19 | +#include <stdint.h> |
| 20 | +#endif // #ifdef __cplusplus |
| 21 | + |
16 | 22 |
|
17 | 23 | #ifdef ONNX_MLIR_BUILT_AS_STATIC
|
18 | 24 | #define ONNX_MLIR_EXPORT
|
|
33 | 39 |
|
34 | 40 | #ifdef __cplusplus
|
35 | 41 | extern "C" {
|
| 42 | +namespace onnx_mlir { |
36 | 43 | #endif
|
37 | 44 |
|
38 |
| -namespace onnx_mlir { |
| 45 | +/*! |
| 46 | + * Define ONNX-MLIR compiler options with options defined by |
| 47 | + * the envVarName (default ONNX_MLIR_FLAGS) environment variable. |
| 48 | + * Values not recognized as compiler options result in an error. |
| 49 | + * Only a single call to omSetCompilerOptionsFromEnv, |
| 50 | + * omSetCompilerOptionsFromArgs, or omSetCompilerOptionsFromEnvAndArgs |
| 51 | + * is allowed. |
| 52 | + * @param envVarName Environment variable name, use default when null. |
| 53 | + * @return 0 on success or non-zero error code on failure. |
| 54 | + */ |
| 55 | +ONNX_MLIR_EXPORT int64_t omSetCompilerOptionsFromEnv( |
| 56 | + const char *envVarName); |
| 57 | + |
| 58 | +/*! |
| 59 | + * Define ONNX-MLIR compiler options with options defined by |
| 60 | + * the argc/argv parameters. Call expects argv[0] to contain the program |
| 61 | + * name. Values not recognized as compiler options result in an error. |
| 62 | + * Only a single call to omSetCompilerOptionsFromEnv, |
| 63 | + * omSetCompilerOptionsFromArgs, or omSetCompilerOptionsFromEnvAndArgs |
| 64 | + * is allowed. |
| 65 | + * @param argc Number of input parameters in argv. |
| 66 | + * @param argv Array of strings, some of which may be compiler options. |
| 67 | + * First argv is ignored as it contains the name of the program. |
| 68 | + * @return 0 on success or non-zero error code on failure. |
| 69 | + */ |
| 70 | +ONNX_MLIR_EXPORT int64_t omSetCompilerOptionsFromArgs( |
| 71 | + int64_t argc, char *argv[]); |
| 72 | + |
| 73 | +/*! |
| 74 | + * Define ONNX-MLIR compiler options with options defined by |
| 75 | + * the envVarName (default ONNX_MLIR_FLAGS) environment variable |
| 76 | + * and the argc/argv parameters. Call expects argv[0] to contain the program |
| 77 | + * name. Values not recognized as compiler options result in an error. |
| 78 | + * Only a single call to omSetCompilerOptionsFromEnv, |
| 79 | + * omSetCompilerOptionsFromArgs, or omSetCompilerOptionsFromEnvAndArgs |
| 80 | + * is allowed. |
| 81 | + * @param argc Number of input parameters in argv. |
| 82 | + * @param argv Array of strings, some of which may be compiler options. |
| 83 | + * First argv is ignored as it contains the name of the program. |
| 84 | + * @param envVarName Environment variable name, use default when null. |
| 85 | + * @return 0 on success or non-zero error code on failure. |
| 86 | + */ |
| 87 | +ONNX_MLIR_EXPORT int64_t omSetCompilerOptionsFromArgsAndEnv( |
| 88 | + int64_t argc, char *argv[], const char *envVarName); |
| 89 | + |
| 90 | +/*! |
| 91 | + * Overwrite the compiler option defined by input parameters. |
| 92 | + * Set default value by calling this function before a call to |
| 93 | + * omSetCompilerOptionsFromEnv, omSetCompilerOptionsFromArgs, or |
| 94 | + * omSetCompilerOptionsFromEnvAndArgs. Or overwrite the current value |
| 95 | + * by calling this function after one of the above 3 setter functions. |
| 96 | + * @param kind Describe which option kind is being set. |
| 97 | + * @param val Value of the option being set. Null pointer reset the |
| 98 | + * option. |
| 99 | + * @return 0 on success or non-zero error code on failure. |
| 100 | + */ |
| 101 | +ONNX_MLIR_EXPORT int64_t omSetCompilerOption( |
| 102 | + const OptionKind kind, const char *val); |
| 103 | + |
| 104 | +/*! |
| 105 | + * Get the compiler options. |
| 106 | + * @param kind Describe which option kind is being set. |
| 107 | + * @return Value of compiler option. |
| 108 | + */ |
| 109 | +ONNX_MLIR_EXPORT const char *omGetCompilerOption( |
| 110 | + const OptionKind kind); |
39 | 111 |
|
40 | 112 | /*!
|
41 | 113 | * Compile an onnx model from a file containing MLIR or ONNX protobuf.
|
42 | 114 | * @param inputFilename File name pointing onnx model protobuf or MLIR.
|
43 | 115 | * @param outputBaseName File name without extension to write output.
|
44 | 116 | * @param emissionTarget Target format to compile to.
|
45 |
| - * @param optionKey List of keys specified for the compiler options. |
46 |
| - * @param optionVal List of string values for corresponding keys. |
47 |
| - * @param optionNum Number of keys and strings. |
48 | 117 | * @param errorMessage Error message.
|
49 | 118 | * @return 0 on success or non-zero error code on failure.
|
50 | 119 | */
|
51 |
| -ONNX_MLIR_EXPORT int omCompileFromFile(const char *inputFilename, |
| 120 | +ONNX_MLIR_EXPORT int64_t omCompileFromFile(const char *inputFilename, |
52 | 121 | const char *outputBaseName, EmissionTargetType emissionTarget,
|
53 |
| - const onnx_mlir::OptionKind *optionKey, const char **optionVal, |
54 |
| - const int optionNum, const char **errorMessage); |
| 122 | + const char **errorMessage); |
55 | 123 |
|
56 | 124 | /*!
|
57 | 125 | * Compile an onnx model from an ONNX protobuf array.
|
58 | 126 | * @param inputBuffer ONNX protobuf array.
|
59 | 127 | * @param bufferSize Size of ONNX protobuf array.
|
60 | 128 | * @param outputBaseName File name without extension to write output.
|
61 | 129 | * @param emissionTarget Target format to compile to.
|
62 |
| - * @param optionKey List of keys specified for the compiler options. |
63 |
| - * @param optionVal List of string values for corresponding keys. |
64 |
| - * @param optionNum Number of keys and strings. |
| 130 | + * @param errorMessage Error message. |
65 | 131 | * @return 0 on success or non-zero error code on failure
|
66 | 132 | */
|
67 |
| -ONNX_MLIR_EXPORT int omCompileFromArray(const void *inputBuffer, int bufferSize, |
68 |
| - const char *outputBaseName, EmissionTargetType emissionTarget, |
69 |
| - const onnx_mlir::OptionKind *optionKey, const char **optionVal, |
70 |
| - const int optionNum |
71 |
| -); |
72 |
| - |
73 |
| -} // namespace onnx_mlir |
| 133 | +ONNX_MLIR_EXPORT int64_t omCompileFromArray(const void *inputBuffer, |
| 134 | + int bufferSize, const char *outputBaseName, |
| 135 | + EmissionTargetType emissionTarget, const char **errorMessage); |
74 | 136 |
|
75 | 137 | #ifdef __cplusplus
|
76 |
| -} |
| 138 | +} // namespace onnx_mlir |
| 139 | +} // extern C |
77 | 140 | #endif
|
78 | 141 |
|
79 | 142 | #endif
|
0 commit comments