tensorflow/lite/delegates/gpu/common/model_builder_test.cc
// Same as GetOpsToReplaceAcceptsFp16DequantizeNodes, but the DEQUANTIZE inputs
// are not constant. As a result, we don't allow the delegate to accept them.
Same as GetOpsToReplaceAcceptsFp16DequantizeNodes, but the DEQUANTIZE inputs
are not constant. As a result, we don't allow the delegate to accept them.
Same as GetOpsToReplaceAcceptsFp16DequantizeNodes but the DEQUANTIZE inputs are not constant . As a result we don ' t allow the delegate to accept them .
TEST(ModelBuilderTest, GetOpsToReplaceRejectsNonConstantFp16DequantizeNodes) {
  TfLiteContext* context = interpreter_fp16_non_constant->context();
  context->GetExecutionPlan = [](struct TfLiteContext* context,
                                 TfLiteIntArray** execution_plan) {
    *execution_plan = interpreter_fp16_non_constant->exec_plan();
    return kTfLiteOk;
  };
  context->GetNodeAndRegistration = [](struct TfLiteContext*, int node_index,
                                       TfLiteNode** node,
                                       TfLiteRegistration** registration) {
    *node = interpreter_fp16_non_constant->node(node_index);
    *registration = interpreter_fp16_non_constant->registration(node_index);
    return kTfLiteOk;
  };
  context->PreviewDelegatePartitioning =
      [](struct TfLiteContext* context, const TfLiteIntArray* nodes_to_replace,
         TfLiteDelegateParams** partition_params_array, int* num_partitions) {
        EXPECT_EQ(nodes_to_replace->size, 1);
        auto params = interpreter_fp16_non_constant->add_delegate_params();
        params->nodes_to_replace = TfLiteIntArrayCreate(1);
        params->nodes_to_replace->data[0] = 2;
        params->input_tensors = TfLiteIntArrayCreate(2);
        params->input_tensors->data[0] = 1;
        params->input_tensors->data[1] = 3;
        params->output_tensors = TfLiteIntArrayCreate(1);
        params->output_tensors->data[0] = 4;
        *partition_params_array =
            interpreter_fp16_non_constant->delegate_params();
        *num_partitions = interpreter_fp16_non_constant->num_delegate_params();
        return kTfLiteOk;
      };
  TfLiteIntArray* ops_to_replace = GetOpsToReplace(context);
  EXPECT_EQ(ops_to_replace->size, 1);
  TfLiteNode* node = nullptr;
  TfLiteRegistration* registration = nullptr;
  context->GetNodeAndRegistration(context, ops_to_replace->data[0], &node,
                                  &registration);
  EXPECT_EQ(context->tensors[node->inputs->data[0]].type,
            TfLiteType::kTfLiteFloat32);
  EXPECT_EQ(context->tensors[node->inputs->data[1]].type,
            TfLiteType::kTfLiteFloat32);
  TfLiteIntArrayFree(ops_to_replace);
}
TEST ( ModelBuilderTest , GetOpsToReplaceRejectsNonConstantFp16DequantizeNodes ) { TfLiteContext * context = interpreter_fp16_non_constant -> context ( ) ; context -> GetExecutionPlan = [ ] ( struct TfLiteContext * context , TfLiteIntArray * * execution_plan ) { * execution_plan = interpreter_fp16_non_constant -> exec_plan ( ) ; return kTfLiteOk ; } ; context -> GetNodeAndRegistration = [ ] ( struct TfLiteContext * , int node_index , TfLiteNode * * node , TfLiteRegistration * * registration ) { * node = interpreter_fp16_non_constant -> node ( node_index ) ; * registration = interpreter_fp16_non_constant -> registration ( node_index ) ; return kTfLiteOk ; } ; context -> PreviewDelegatePartitioning = [ ] ( struct TfLiteContext * context , const TfLiteIntArray * nodes_to_replace , TfLiteDelegateParams * * partition_params_array , int * num_partitions ) { EXPECT_EQ ( nodes_to_replace -> size , 1 ) ; auto params = interpreter_fp16_non_constant -> add_delegate_params ( ) ; params -> nodes_to_replace = TfLiteIntArrayCreate ( 1 ) ; params -> nodes_to_replace -> data [ 0 ] = 2 ; params -> input_tensors = TfLiteIntArrayCreate ( 2 ) ; params -> input_tensors -> data [ 0 ] = 1 ; params -> input_tensors -> data [ 1 ] = 3 ; params -> output_tensors = TfLiteIntArrayCreate ( 1 ) ; params -> output_tensors -> data [ 0 ] = 4 ; * partition_params_array = interpreter_fp16_non_constant -> delegate_params ( ) ; * num_partitions = interpreter_fp16_non_constant -> num_delegate_params ( ) ; return kTfLiteOk ; } ; TfLiteIntArray * ops_to_replace = GetOpsToReplace ( context ) ; EXPECT_EQ ( ops_to_replace -> size , 1 ) ; TfLiteNode * node = nullptr ; TfLiteRegistration * registration = nullptr ; context -> GetNodeAndRegistration ( context , ops_to_replace -> data [ 0 ] , & node , & registration ) ; EXPECT_EQ ( context -> tensors [ node -> inputs -> data [ 0 ] ] . type , TfLiteType :: kTfLiteFloat32 ) ; EXPECT_EQ ( context -> tensors [ node -> inputs -> data [ 1 ] ] . type , TfLiteType :: kTfLiteFloat32 ) ; TfLiteIntArrayFree ( ops_to_replace ) ; }
Same as GetOpsToReplaceAcceptsFp16DequantizeNodes, but the DEQUANTIZE inputs
are not constant.
Same as GetOpsToReplaceAcceptsFp16DequantizeNodes but the DEQUANTIZE inputs are not constant .
// These functions are meant to be called inside delegates. Swap out // for similar functions to permit direct calling of GetOpsToReplace. // The partitioner should accept only the Add op initially. // Single partition output. // Only ADD is delegated, with FP32 (dequantized) inputs.