Skip to content

Commit ec8f074

Browse files
LukeBoyertensorflower-gardener
authored andcommitted
Update apply plugin tool to load and select from multiple shared lib files. Move apply plugin tool into tools/ and general cleanup.
PiperOrigin-RevId: 686729742
1 parent 32ee73e commit ec8f074

34 files changed

+1136
-336
lines changed

tensorflow/lite/experimental/lrt/BUILD

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,3 @@ package(
1616
# copybara:uncomment default_applicable_licenses = ["//tensorflow:license"],
1717
default_visibility = ["//tensorflow/lite/experimental/lrt:__subpackages__"],
1818
)
19-
20-
cc_binary(
21-
name = "apply_plugin",
22-
srcs = [
23-
"apply_plugin.cc",
24-
# TODO: b/366821557 - Support pre-compiled plugins as data dependencies.
25-
"//tensorflow/lite/experimental/lrt/vendors/examples:example_plugin_so",
26-
],
27-
deps = [
28-
"//tensorflow/lite/experimental/lrt/core:api_internal",
29-
"//tensorflow/lite/experimental/lrt/core:lite_rt_model_init",
30-
"//tensorflow/lite/experimental/lrt/core:model",
31-
"//tensorflow/lite/experimental/lrt/core/compiler_plugin:algo",
32-
"@llvm-project//llvm:Support",
33-
],
34-
)

tensorflow/lite/experimental/lrt/apply_plugin.cc

Lines changed: 0 additions & 204 deletions
This file was deleted.

tensorflow/lite/experimental/lrt/c/lite_rt_common.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,20 @@ typedef enum {
6060
kLrtStatusErrorTimeoutExpired = 7,
6161

6262
// File and loading related errors.
63-
kLrtStatusBadFileOp = 500,
64-
kLrtStatusFlatbufferFailedVerify = 501,
65-
kLrtStatusDynamicLoadErr = 502,
63+
kLrtStatusErrorFileIO = 500,
64+
kLrtStatusErrorInvalidFlatbuffer = 501,
65+
kLrtStatusErrorDynamicLoading = 502,
66+
kLrtStatusSerializationErr = 503,
67+
kLrtStatusCompilationError = 504,
6668

6769
// IR related errors.
68-
kLrtStatusParamIndexOOB = 1000,
69-
kLrtStatusBadTensorType = 1001,
70-
kLrtStatusGraphInvariantError = 1002,
70+
kLrtStatusErrorIndexOOB = 1000,
71+
kLrtStatusErrorInvalidIrType = 1001,
72+
kLrtStatusErrorInvalidGraphInvariant = 1002,
73+
kLrtStatusErrorGraphModification = 1003,
7174

7275
// Tool related errors.
73-
kLrtStatusToolBadConfig = 1500,
76+
kLrtStatusErrorInvalidToolConfig = 1500,
7477
} LrtStatus;
7578

7679
#ifdef __cplusplus

tensorflow/lite/experimental/lrt/cc/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ cc_library(
2828
"//tensorflow/compiler/mlir/lite/core:model_builder_base",
2929
"//tensorflow/lite/c:c_api_types",
3030
"//tensorflow/lite/experimental/lrt/c:lite_rt_c_api",
31-
"@com_google_absl//absl/log:absl_check",
3231
"@com_google_absl//absl/types:span",
3332
],
3433
)

tensorflow/lite/experimental/lrt/cc/lite_rt_support.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,16 @@ class LrtResult {
132132
} \
133133
decl = result.Value();
134134

135+
#define _MOVE_OR_BLOCK(decl, expr, block, result) \
136+
auto result = (expr); \
137+
if (!result.HasValue()) { \
138+
block; \
139+
} \
140+
decl = std::move(result.Value());
141+
142+
#define _MOVE_OR_RETURN_VAL(decl, expr, val, result) \
143+
_MOVE_OR_BLOCK(decl, expr, _RETURN_VAL(val), result)
144+
135145
#define _ASSIGN_OR_RETURN_VAL(decl, expr, val, result) \
136146
_ASSIGN_OR_BLOCK(decl, expr, _RETURN_VAL(val), result)
137147

@@ -144,10 +154,17 @@ class LrtResult {
144154
#define _ASSIGN_OR_RETURN_STATUS(decl, expr, result) \
145155
_ASSIGN_OR_RETURN_VAL(decl, expr, _STATUS_FROM_RESULT(result), result)
146156

157+
#define _MOVE_OR_RETURN_STATUS(decl, expr, result) \
158+
_MOVE_OR_RETURN_VAL(decl, expr, _STATUS_FROM_RESULT(result), result)
159+
147160
// Assign value behind result returned from expr. If not ok, return status.
148161
#define LRT_ASSIGN_OR_RETURN_STATUS(decl, expr) \
149162
_ASSIGN_OR_RETURN_STATUS(decl, expr, _CONCAT_NAME(_result, __COUNTER__))
150163

164+
// Assign value behind result returned from expr. If not ok, return status.
165+
#define LRT_MOVE_OR_RETURN_STATUS(decl, expr) \
166+
_MOVE_OR_RETURN_STATUS(decl, expr, _CONCAT_NAME(_result, __COUNTER__))
167+
151168
#define _FORWARD_RESULT(result, ty) LrtResult<ty>::FromStatus(result.Status());
152169

153170
#define _ASSIGN_OR_RETURN_RESULT(decl, expr, ty, result) \
@@ -157,6 +174,13 @@ class LrtResult {
157174
#define LRT_ASSIGN_OR_RETURN_RESULT(decl, expr, ty) \
158175
_ASSIGN_OR_RETURN_RESULT(decl, expr, ty, _CONCAT_NAME(_result, __COUNTER__))
159176

177+
#define _MOVE_OR_RETURN_RESULT(decl, expr, ty, result) \
178+
_MOVE_OR_RETURN_VAL(decl, expr, _FORWARD_RESULT(result, ty), result)
179+
180+
// Move value behind result returned from expr. If not ok, return result.
181+
#define LRT_MOVE_OR_RETURN_RESULT(decl, expr, ty) \
182+
_MOVE_OR_RETURN_RESULT(decl, expr, ty, _CONCAT_NAME(_result, __COUNTER__))
183+
160184
#define LRT_ENSURE_SUPPORTED(cond, msg) \
161185
if (!(cond)) { \
162186
std::cerr << __FILE__ << ":" << __LINE__ << " " << msg << "\n"; \

tensorflow/lite/experimental/lrt/core/compiler_plugin/compiler_plugin.cc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,14 @@ CompilerPlugin::ResultT CompilerPlugin::LoadPlugin(
138138

139139
if (OpenLib(lib_path, &plugin.lib_handle_) != kLrtStatusOk) {
140140
LITE_RT_LOG(LRT_WARNING, "Failed to load plugin at: %s", lib_path.data());
141-
return ResultT::FromStatus(kLrtStatusDynamicLoadErr);
141+
return ResultT::FromStatus(kLrtStatusErrorDynamicLoading);
142142
}
143143

144144
if (ResolvePluginApi(plugin.lib_handle_, plugin.plugin_api_) !=
145145
kLrtStatusOk) {
146146
LITE_RT_LOG(LRT_WARNING, "Failed to resolve plugin api at: %s",
147147
lib_path.data());
148-
return ResultT::FromStatus(kLrtStatusDynamicLoadErr);
148+
return ResultT::FromStatus(kLrtStatusErrorDynamicLoading);
149149
}
150150

151151
if (plugin.plugin_api_.init(&plugin.plugin_handle_) != kLrtStatusOk) {
@@ -155,7 +155,7 @@ CompilerPlugin::ResultT CompilerPlugin::LoadPlugin(
155155
LITE_RT_LOG(LRT_WARNING, "Failed to close loaded library at: %s",
156156
lib_path.data());
157157
}
158-
return ResultT::FromStatus(kLrtStatusDynamicLoadErr);
158+
return ResultT::FromStatus(kLrtStatusErrorDynamicLoading);
159159
}
160160

161161
// This should never change throughout the lifetime of the compiler
@@ -235,8 +235,7 @@ LrtResult<std::vector<LrtOp>> CompilerPlugin::PartitionModel(
235235
LRT_RETURN_RESULT_IF_NOT_OK(
236236
plugin_api_.partition_model(plugin_handle_, c_model, &ops),
237237
std::vector<LrtOp>);
238-
239-
return LrtResult<std::vector<LrtOp>>::TakeValue(std::move(ops.ops));
238+
return LrtResult<std::vector<LrtOp>>::TakeValue(ops.Vec());
240239
}
241240

242241
LrtStatus CompilerPlugin::Compile(const absl::string_view soc_model,

tensorflow/lite/experimental/lrt/core/dynamic_loading.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ LrtStatus OpenLib(absl::string_view so_path, void** lib_handle) {
4646
"Failed to load .so at path: %s, with error:\n\t %s\n", so_path,
4747
::dlerror());
4848

49-
return kLrtStatusDynamicLoadErr;
49+
return kLrtStatusErrorDynamicLoading;
5050
}
5151
*lib_handle = res;
5252
return kLrtStatusOk;
@@ -55,7 +55,7 @@ LrtStatus OpenLib(absl::string_view so_path, void** lib_handle) {
5555
LrtStatus CloseLib(void* lib_handle) {
5656
if (0 != ::dlclose(lib_handle)) {
5757
LITE_RT_LOG(LRT_ERROR, "Failed to close .so with error: %s", ::dlerror());
58-
return kLrtStatusDynamicLoadErr;
58+
return kLrtStatusErrorDynamicLoading;
5959
}
6060
return kLrtStatusOk;
6161
}

tensorflow/lite/experimental/lrt/core/dynamic_loading.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ inline static LrtStatus ResolveLibSymbol(void* lib_handle,
4141
if (ptr == nullptr) {
4242
LITE_RT_LOG(LRT_ERROR, "Faild to resolve symbol: %s, with err: %s\n",
4343
sym_name, ::dlerror());
44-
return kLrtStatusDynamicLoadErr;
44+
return kLrtStatusErrorDynamicLoading;
4545
}
4646
*sym_handle = ptr;
4747
return kLrtStatusOk;

0 commit comments

Comments
 (0)