@@ -918,6 +918,9 @@ TfLiteStatus ParseOpDataTfLite(const Operator* op, BuiltinOperator op_type,
918
918
*builtin_data = params.release ();
919
919
return kTfLiteOk ;
920
920
}
921
+ case BuiltinOperator_STABLEHLO_PAD: {
922
+ return ParseStablehloPad (op, error_reporter, allocator, builtin_data);
923
+ }
921
924
// TODO: skip param parsing for now since ops below don't have kernels
922
925
case BuiltinOperator_STABLEHLO_SLICE:
923
926
case BuiltinOperator_STABLEHLO_BROADCAST_IN_DIM:
@@ -952,7 +955,6 @@ TfLiteStatus ParseOpDataTfLite(const Operator* op, BuiltinOperator op_type,
952
955
case BuiltinOperator_STABLEHLO_IOTA:
953
956
case BuiltinOperator_STABLEHLO_COMPARE:
954
957
case BuiltinOperator_STABLEHLO_CONVERT:
955
- case BuiltinOperator_STABLEHLO_PAD:
956
958
case BuiltinOperator_STABLEHLO_DOT_GENERAL:
957
959
case BuiltinOperator_STABLEHLO_SORT:
958
960
case BuiltinOperator_STABLEHLO_WHILE:
@@ -2316,6 +2318,59 @@ TfLiteStatus ParseStablehloGather(const Operator* op,
2316
2318
return kTfLiteOk ;
2317
2319
}
2318
2320
2321
+ TfLiteStatus ParseStablehloPad (const Operator* op,
2322
+ ErrorReporter* error_reporter,
2323
+ BuiltinDataAllocator* allocator,
2324
+ void ** builtin_data) {
2325
+ CheckParsePointerParams (op, error_reporter, allocator, builtin_data);
2326
+
2327
+ SafeBuiltinDataAllocator safe_allocator (allocator);
2328
+ auto params = safe_allocator.Allocate <TfLiteStablehloPadParams>();
2329
+ const StablehloPadOptions* schema_params =
2330
+ op->builtin_options_2_as_StablehloPadOptions ();
2331
+
2332
+ if (schema_params) {
2333
+ auto LoadAttr =
2334
+ [&error_reporter](
2335
+ int64_t * params_array, const size_t params_array_size_bytes,
2336
+ const flatbuffers::Vector<int64_t >* const flatbuffer_vector,
2337
+ const char * const attr_name) -> TfLiteStatus {
2338
+ TfLiteStatus status = FlatBufferIntVectorToArray (
2339
+ params_array_size_bytes, flatbuffer_vector, params_array,
2340
+ error_reporter, " stablehlo.pad" );
2341
+ if (status != kTfLiteOk ) {
2342
+ TF_LITE_REPORT_ERROR (error_reporter, " Check the '%s' attribute." ,
2343
+ attr_name);
2344
+ }
2345
+ return status;
2346
+ };
2347
+
2348
+ TF_LITE_ENSURE_STATUS (
2349
+ LoadAttr (params->edge_padding_low , sizeof (params->edge_padding_low ),
2350
+ schema_params->edge_padding_low (), " edge_padding_low" ));
2351
+ TF_LITE_ENSURE_STATUS (
2352
+ LoadAttr (params->edge_padding_high , sizeof (params->edge_padding_high ),
2353
+ schema_params->edge_padding_high (), " edge_padding_high" ));
2354
+ TF_LITE_ENSURE_STATUS (
2355
+ LoadAttr (params->interior_padding , sizeof (params->interior_padding ),
2356
+ schema_params->interior_padding (), " interior_padding" ));
2357
+ if (schema_params->edge_padding_low ()->size () !=
2358
+ schema_params->edge_padding_high ()->size () ||
2359
+ schema_params->edge_padding_low ()->size () !=
2360
+ schema_params->interior_padding ()->size ()) {
2361
+ TF_LITE_REPORT_ERROR (error_reporter,
2362
+ " 'stablehlo.pad' operation parameter array sizes "
2363
+ " are not consistent." );
2364
+ return kTfLiteError ;
2365
+ }
2366
+ *builtin_data = params.release ();
2367
+ return kTfLiteOk ;
2368
+ }
2369
+ TF_LITE_REPORT_ERROR (error_reporter,
2370
+ " Could not get 'stablehlo.pad' operation parameters." );
2371
+ return kTfLiteError ;
2372
+ }
2373
+
2319
2374
// We have this parse function instead of directly returning kTfLiteOk from the
2320
2375
// switch-case in ParseOpData because this function is used as part of the
2321
2376
// selective registration for the OpResolver implementation in micro.
0 commit comments