Skip to content

Commit 0d43b3a

Browse files
YunanAZcopybara-github
authored andcommitted
Introduce RegisterAllTransformation API in compiler plugin c api.
This function will be implemented in vendor compiler plugin to register transformations. LiteRT-PiperOrigin-RevId: 815881905
1 parent 4a1e5f5 commit 0d43b3a

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

litert/vendors/c/BUILD

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ cc_library(
2828
"//litert/c:litert_environment_options",
2929
"//litert/c:litert_model",
3030
"//litert/c:litert_options",
31+
"//litert/c:litert_rewriter",
3132
],
3233
)
3334

@@ -37,10 +38,10 @@ cc_library(
3738
deps = [
3839
":litert_compiler_plugin",
3940
"//litert/c:litert_common",
40-
"//litert/c:litert_environment",
4141
"//litert/c:litert_environment_options",
4242
"//litert/c:litert_model",
4343
"//litert/c:litert_options",
44+
"//litert/c:litert_rewriter",
4445
"@com_google_absl//absl/strings:string_view",
4546
],
4647
)

litert/vendors/c/litert_compiler_plugin.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
#include <stddef.h>
1919

2020
#include "litert/c/litert_common.h"
21-
#include "litert/c/litert_environment_options.h"
22-
#include "litert/c/litert_model.h"
23-
#include "litert/c/litert_options.h"
21+
#include "litert/c/litert_rewriter.h"
2422

2523
#ifdef __cplusplus
2624
extern "C" {
@@ -111,6 +109,16 @@ LITERT_CAPI_EXPORT LiteRtStatus LiteRtGetCompiledResultCallInfo(
111109
LITERT_CAPI_EXPORT LiteRtStatus LiteRtGetNumCompiledResultCalls(
112110
LiteRtCompiledResult compiled_result, LiteRtParamIndex* num_calls);
113111

112+
// Allow the compiler plugin to registers all the graph transformations
113+
// required. This function populates the provided arrays with pattern functions
114+
// and their corresponding names. Registered patterns will be applied to the
115+
// graph before partition and compilation.
116+
//
117+
// Experimental: Unstable ABI, function signature is subject to change.
118+
LiteRtStatus LiteRtCompilerPluginRegisterAllTransformations(
119+
LiteRtCompilerPlugin compiler_plugin, LiteRtPatternFn** pattern_fns,
120+
const char*** transformation_names, LiteRtParamIndex* num_patterns);
121+
114122
#ifdef __cplusplus
115123
}
116124
#endif // __cplusplus

litert/vendors/c/litert_compiler_plugin_api.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <stddef.h>
1919

2020
#include "litert/c/litert_common.h"
21+
#include "litert/c/litert_rewriter.h"
2122
#include "litert/vendors/c/litert_compiler_plugin.h"
2223

2324
// Wrapper for dynamically loaded LiteRtCompilerPlugin library. See
@@ -75,6 +76,10 @@ typedef LiteRtStatus (*LiteRtGetCompiledResultCallInfoT)(
7576
typedef LiteRtStatus (*LiteRtGetNumCompiledResultCallsT)(
7677
LiteRtCompiledResult, LiteRtParamIndex* num_calls);
7778

79+
typedef LiteRtStatus (*LiteRtCompilerPluginRegisterAllTransformationsT)(
80+
LiteRtCompilerPlugin compiler_plugin, LiteRtPatternFn** pattern_fns,
81+
const char*** transformation_names, LiteRtParamIndex* num_patterns);
82+
7883
//
7984
// Function Pointer Container
8085
//
@@ -101,6 +106,7 @@ struct LiteRtCompilerPluginApi {
101106
LiteRtCompiledResultNumByteCodeModulesT get_compiled_result_num_byte_code;
102107
LiteRtGetCompiledResultCallInfoT get_compiled_result_call_info;
103108
LiteRtGetNumCompiledResultCallsT get_compiled_result_num_calls;
109+
LiteRtCompilerPluginRegisterAllTransformationsT register_all_transformations;
104110
};
105111

106112
#ifdef __cplusplus
@@ -142,6 +148,9 @@ static constexpr absl::string_view kLiteRtGetCompiledResultCallInfo =
142148
"LiteRtGetCompiledResultCallInfo";
143149
static constexpr absl::string_view kLiteRtGetNumCompiledResultCalls =
144150
"LiteRtGetNumCompiledResultCalls";
151+
static constexpr absl::string_view
152+
kLiteRtCompilerPluginRegisterAllTransformations =
153+
"LiteRtCompilerPluginRegisterAllTransformations";
145154

146155
#endif // __cplusplus
147156

0 commit comments

Comments
 (0)