diff --git a/lite/api/test_resnet50_lite_bm.cc b/lite/api/test_resnet50_lite_bm.cc index 62a58704f4245b8618540ea7109447dd99d0bfea..cb9cb304b867268137388df9e04caa02a98e06a4 100644 --- a/lite/api/test_resnet50_lite_bm.cc +++ b/lite/api/test_resnet50_lite_bm.cc @@ -32,8 +32,6 @@ namespace lite { void TestModel(const std::vector& valid_places) { lite::Predictor predictor; - std::vector passes; - passes.push_back("bm_subgraph_pass"); predictor.Build(FLAGS_model_dir, "", "", valid_places, passes); auto* input_tensor = predictor.GetInput(0); diff --git a/lite/core/mir/subgraph/subgraph_detector.cc b/lite/core/mir/subgraph/subgraph_detector.cc index 6d48b053a1a4140252d35e85d2351644d3c216e9..c46e12c1cd2e457655cc7f56c402c74152cc8920 100644 --- a/lite/core/mir/subgraph/subgraph_detector.cc +++ b/lite/core/mir/subgraph/subgraph_detector.cc @@ -341,9 +341,6 @@ void SubgraphFuser::InsertNewNode(SSAGraph *graph, for (auto &op_node : subgraph_nodes) { auto sub_block_op_desc = sub_block_desc->AddOp(); *sub_block_op_desc = *op_node->AsStmt().op_info(); - sub_block_op_desc->SetAttr( - kKernelTypeAttr, - op_node->AsStmt().picked_kernel().SerializedKernelType()); } subgraph_op_desc.SetAttr("sub_block", sub_block_idx); @@ -413,12 +410,6 @@ void SubgraphFuser::InsertNewNode(SSAGraph *graph, IR_OP_VAR_LINK(subgraph_op_node, var_node); } - // Create and assign the context to the picked kernel of the new subgraph - // node - auto &inst = subgraph_op_node->AsStmt(); - inst.picked_kernel().SetContext( - ContextScheduler::Global().NewContext(inst.picked_kernel().target())); - // Remove subgraph nodes and unused var nodes auto nodes2rm = GetNodes2RM(subgraph_nodes, {input_var_nodes, diff --git a/lite/core/optimizer.h b/lite/core/optimizer.h index ddd94484ac4bb8d96d5c55300c985d21b44f1843..2ac576b6f9d64b9ae4e1f5ff178e10fb5991aad9 100644 --- a/lite/core/optimizer.h +++ b/lite/core/optimizer.h @@ -75,6 +75,9 @@ class Optimizer { (defined LITE_WITH_ARM) "lite_elementwise_add_activation_fuse_pass", // #endif + "npu_subgraph_pass", + "xpu_subgraph_pass", + "bm_subgraph_pass", "static_kernel_pick_pass", // pick original kernel from graph "variable_place_inference_pass", // inference arg/var's // info(target/precision/layout/device) @@ -108,9 +111,7 @@ class Optimizer { "runtime_context_assign_pass", "argument_type_display_pass", - "memory_optimize_pass", - "npu_subgraph_pass", - "xpu_subgraph_pass"}}; + "memory_optimize_pass"}}; RunPasses(passes_local); } else { RunPasses(passes); diff --git a/lite/kernels/bm/bridges/concat_op.cc b/lite/kernels/bm/bridges/concat_op.cc index 0b568aa4d161b5af8d17a83cdedddc446fcd8237..9a8729aa8d9aa0bc5896750435a55de25effeded 100644 --- a/lite/kernels/bm/bridges/concat_op.cc +++ b/lite/kernels/bm/bridges/concat_op.cc @@ -30,8 +30,6 @@ int ConcatConverter(void* ctx, OpLite* op, KernelBase* kernel) { auto op_type = op_info->Type(); // input auto x_names = op_info->Input("X"); - auto x_type = kernel->GetInputDeclType("X"); - CHECK(x_type->layout() == DATALAYOUT(kNCHW)); // output auto output_var_name = op_info->Output("Out").front(); auto output = scope->FindVar(output_var_name)->GetMutable(); diff --git a/lite/kernels/npu/bridges/act_op.cc b/lite/kernels/npu/bridges/act_op.cc index a4d1009f1be286e8bd8dfcdd469ff53b6681c820..f3fd75f2d6728df2490a1ecf5c4e43c3ad08ab6c 100644 --- a/lite/kernels/npu/bridges/act_op.cc +++ b/lite/kernels/npu/bridges/act_op.cc @@ -32,15 +32,9 @@ int ActConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input and output vars and op attributes auto x_name = op_info->Input("X").front(); - auto x_type = kernel->GetInputDeclType("X"); - CHECK(x_type->precision() == PRECISION(kFloat)); - CHECK(x_type->layout() == DATALAYOUT(kNCHW)); auto x = scope->FindMutableTensor(x_name); auto x_dims = x->dims(); auto out_name = op_info->Output("Out").front(); - auto out_type = kernel->GetOutputDeclType("Out"); - CHECK(out_type->precision() == PRECISION(kFloat)); - CHECK(out_type->layout() == DATALAYOUT(kNCHW)); // X node std::shared_ptr x_node = nullptr; diff --git a/lite/kernels/npu/bridges/argmax_op.cc b/lite/kernels/npu/bridges/argmax_op.cc index 3d397aab9d5cc7cfb800198184d656856d8c101f..4b1e45c3d26ecb713b231a39924d18ba794eec2b 100644 --- a/lite/kernels/npu/bridges/argmax_op.cc +++ b/lite/kernels/npu/bridges/argmax_op.cc @@ -32,15 +32,9 @@ int ArgmaxConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input and output vars and op attributes auto x_name = op_info->Input("X").front(); - auto x_type = kernel->GetInputDeclType("X"); - CHECK(x_type->precision() == PRECISION(kFloat)); - CHECK(x_type->layout() == DATALAYOUT(kNCHW)); auto x = scope->FindMutableTensor(x_name); auto x_dims = x->dims(); auto out_name = op_info->Output("Out").front(); - auto out_type = kernel->GetOutputDeclType("Out"); - CHECK(out_type->precision() == PRECISION(kFloat)); - CHECK(out_type->layout() == DATALAYOUT(kNCHW)); int axis = op_info->GetAttr("axis"); // X node diff --git a/lite/kernels/npu/bridges/batch_norm_op.cc b/lite/kernels/npu/bridges/batch_norm_op.cc index d0e97161c5f1bc6b126e81b969a4564b47da9331..1911b9fd88dfc75a57adbe31c2c94e71d357a04e 100644 --- a/lite/kernels/npu/bridges/batch_norm_op.cc +++ b/lite/kernels/npu/bridges/batch_norm_op.cc @@ -32,35 +32,17 @@ int BatchNormConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input and output vars and op attributes auto x_name = op_info->Input("X").front(); - auto x_type = kernel->GetInputDeclType("X"); - CHECK(x_type->precision() == PRECISION(kFloat)); - CHECK(x_type->layout() == DATALAYOUT(kNCHW)); auto x = scope->FindMutableTensor(x_name); auto x_dims = x->dims(); auto scale_name = op_info->Input("Scale").front(); - auto scale_type = kernel->GetInputDeclType("Scale"); - CHECK(scale_type->precision() == PRECISION(kFloat)); - CHECK(scale_type->layout() == DATALAYOUT(kNCHW)); auto scale = scope->FindMutableTensor(scale_name); auto bias_name = op_info->Input("Bias").front(); - auto bias_type = kernel->GetInputDeclType("Bias"); - CHECK(bias_type->precision() == PRECISION(kFloat)); - CHECK(bias_type->layout() == DATALAYOUT(kNCHW)); auto bias = scope->FindMutableTensor(bias_name); auto mean_name = op_info->Input("Mean").front(); - auto mean_type = kernel->GetInputDeclType("Mean"); - CHECK(mean_type->precision() == PRECISION(kFloat)); - CHECK(mean_type->layout() == DATALAYOUT(kNCHW)); auto mean = scope->FindMutableTensor(mean_name); auto variance_name = op_info->Input("Variance").front(); - auto variance_type = kernel->GetInputDeclType("Variance"); - CHECK(variance_type->precision() == PRECISION(kFloat)); - CHECK(variance_type->layout() == DATALAYOUT(kNCHW)); auto variance = scope->FindMutableTensor(variance_name); auto y_name = op_info->Output("Y").front(); - auto y_type = kernel->GetOutputDeclType("Y"); - CHECK(y_type->precision() == PRECISION(kFloat)); - CHECK(y_type->layout() == DATALAYOUT(kNCHW)); float momentum = op_info->GetAttr("momentum"); float epsilon = op_info->GetAttr("epsilon"); int mode = 1; // bnScale, bnBias tensor dims are 1xCx1x1 diff --git a/lite/kernels/npu/bridges/concat_op.cc b/lite/kernels/npu/bridges/concat_op.cc index e40af8703dd1dda7303f0976fa03abec7cdf7aaa..2214881f0599214dba75aa197b6c01863458e8ad 100644 --- a/lite/kernels/npu/bridges/concat_op.cc +++ b/lite/kernels/npu/bridges/concat_op.cc @@ -32,13 +32,7 @@ int ConcatConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input and output vars and op attributes auto x_names = op_info->Input("X"); - auto x_type = kernel->GetInputDeclType("X"); - CHECK(x_type->precision() == PRECISION(kFloat)); - CHECK(x_type->layout() == DATALAYOUT(kNCHW)); auto out_name = op_info->Output("Out").front(); - auto out_type = kernel->GetOutputDeclType("Out"); - CHECK(out_type->precision() == PRECISION(kFloat)); - CHECK(out_type->layout() == DATALAYOUT(kNCHW)); auto axis = op_info->GetAttr("axis"); auto num = x_names.size(); diff --git a/lite/kernels/npu/bridges/conv_op.cc b/lite/kernels/npu/bridges/conv_op.cc index cc72242fb125699aa6236b78ebd17c32dd1dc66a..637b6eea5c99f9ab2a43d4bd442a3a720dced96a 100644 --- a/lite/kernels/npu/bridges/conv_op.cc +++ b/lite/kernels/npu/bridges/conv_op.cc @@ -33,23 +33,14 @@ int ConvConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input and output vars and op attributes auto input_name = op_info->Input("Input").front(); - auto input_type = kernel->GetInputDeclType("Input"); - CHECK(input_type->precision() == PRECISION(kFloat)); - CHECK(input_type->layout() == DATALAYOUT(kNCHW)); auto input = scope->FindMutableTensor(input_name); auto input_dims = input->dims(); auto filter_name = op_info->Input("Filter").front(); - auto filter_type = kernel->GetInputDeclType("Filter"); - CHECK(filter_type->precision() == PRECISION(kFloat)); - CHECK(filter_type->layout() == DATALAYOUT(kNCHW)); auto filter = scope->FindMutableTensor(filter_name); auto filter_dims = filter->dims(); auto output_name = op_info->Output("Output").front(); - auto output_type = kernel->GetOutputDeclType("Output"); - CHECK(output_type->precision() == PRECISION(kFloat)); - CHECK(output_type->layout() == DATALAYOUT(kNCHW)); auto output = scope->FindMutableTensor(output_name); auto output_dims = output->dims(); @@ -132,9 +123,6 @@ int ConvConverter(void* ctx, OpLite* op, KernelBase* kernel) { if (graph->Has(bias_name)) { bias_node = graph->Get(bias_name); } else { - auto bias_type = kernel->GetInputDeclType("Bias"); - CHECK(bias_type->precision() == PRECISION(kFloat)); - CHECK(bias_type->layout() == DATALAYOUT(kNCHW)); auto bias = scope->FindMutableTensor(bias_name); auto bias_dims = bias->dims(); auto bias_data_size = bias_dims.production(); diff --git a/lite/kernels/npu/bridges/conv_transpose_op.cc b/lite/kernels/npu/bridges/conv_transpose_op.cc index adade8844b65cef560b6f183ea0e2a63f05ccb6b..da91ae125b8e8ffca4c70aba85e9aefe0d11e431 100644 --- a/lite/kernels/npu/bridges/conv_transpose_op.cc +++ b/lite/kernels/npu/bridges/conv_transpose_op.cc @@ -33,25 +33,16 @@ int ConvTransposeConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input, output and op attributes auto input_name = op_info->Input("Input").front(); - auto input_type = kernel->GetInputDeclType("Input"); - CHECK(input_type->precision() == PRECISION(kFloat)); - CHECK(input_type->layout() == DATALAYOUT(kNCHW)); auto input = scope->FindMutableTensor(input_name); auto input_dims = input->dims(); CHECK_EQ(input_dims.size(), 4); auto filter_name = op_info->Input("Filter").front(); - auto filter_type = kernel->GetInputDeclType("Filter"); - CHECK(filter_type->precision() == PRECISION(kFloat)); - CHECK(filter_type->layout() == DATALAYOUT(kNCHW)); auto filter = scope->FindMutableTensor(filter_name); auto filter_dims = filter->dims(); CHECK_EQ(filter_dims.size(), 4); auto output_name = op_info->Output("Output").front(); - auto output_type = kernel->GetOutputDeclType("Output"); - CHECK(output_type->precision() == PRECISION(kFloat)); - CHECK(output_type->layout() == DATALAYOUT(kNCHW)); auto strides = op_info->GetAttr>("strides"); CHECK_EQ(strides.size(), 2L); @@ -157,9 +148,6 @@ int ConvTransposeConverter(void* ctx, OpLite* op, KernelBase* kernel) { if (graph->Has(bias_name)) { bias_node = graph->Get(bias_name); } else { - auto bias_type = kernel->GetInputDeclType("Bias"); - CHECK(bias_type->precision() == PRECISION(kFloat)); - CHECK(bias_type->layout() == DATALAYOUT(kNCHW)); auto bias = scope->FindMutableTensor(bias_name); auto channel_size = bias->dims().production(); CHECK_EQ(channel_size, filter_dims[1] * groups); diff --git a/lite/kernels/npu/bridges/dropout_op.cc b/lite/kernels/npu/bridges/dropout_op.cc index 0bb57673281bc3e9dd92fabd6ca5a8e76c76cb73..505a20ee7f2e1f814a414e04b048b0bc0f8d1857 100644 --- a/lite/kernels/npu/bridges/dropout_op.cc +++ b/lite/kernels/npu/bridges/dropout_op.cc @@ -32,16 +32,12 @@ int DropoutConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input, output and op attributes auto x_name = op_info->Input("X").front(); - auto x_type = kernel->GetInputDeclType("X"); - CHECK(x_type->precision() == PRECISION(kFloat)); auto x = scope->FindMutableTensor(x_name); auto x_dims = x->dims(); auto x_rank = x_dims.size(); CHECK_GE(x_rank, 2); auto out_name = op_info->Output("Out").front(); - auto out_type = kernel->GetOutputDeclType("Out"); - CHECK(out_type->precision() == PRECISION(kFloat)); auto dropout_implementation = op_info->GetAttr("dropout_implementation"); diff --git a/lite/kernels/npu/bridges/elementwise_ops.cc b/lite/kernels/npu/bridges/elementwise_ops.cc index c6ff56de67ccb7c257c08db343be2e4767938900..b30a055a35294a42d7db9b65c073c889684dbe72 100644 --- a/lite/kernels/npu/bridges/elementwise_ops.cc +++ b/lite/kernels/npu/bridges/elementwise_ops.cc @@ -70,23 +70,14 @@ int ElementwiseConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input and output vars and op attributes auto x_name = op_info->Input("X").front(); - auto x_type = kernel->GetInputDeclType("X"); - CHECK(x_type->precision() == PRECISION(kFloat)); - CHECK(x_type->layout() == DATALAYOUT(kNCHW)); auto x = scope->FindMutableTensor(x_name); auto x_dims = x->dims(); auto y_name = op_info->Input("Y").front(); - auto y_type = kernel->GetInputDeclType("Y"); - CHECK(y_type->precision() == PRECISION(kFloat)); - CHECK(y_type->layout() == DATALAYOUT(kNCHW)); auto y = scope->FindMutableTensor(y_name); auto y_dims = y->dims(); auto out_name = op_info->Output("Out").front(); - auto out_type = kernel->GetOutputDeclType("Out"); - CHECK(out_type->precision() == PRECISION(kFloat)); - CHECK(out_type->layout() == DATALAYOUT(kNCHW)); auto out = scope->FindMutableTensor(out_name); auto out_dims = out->dims(); diff --git a/lite/kernels/npu/bridges/engine.cc b/lite/kernels/npu/bridges/engine.cc index 546a235148420e26d746ff730e22b2170e301cd6..937f84329cad69bc98bb908d243f27185b9e30a2 100644 --- a/lite/kernels/npu/bridges/engine.cc +++ b/lite/kernels/npu/bridges/engine.cc @@ -63,11 +63,16 @@ int Engine::BuildOriginProgram() { auto kernels = op->CreateKernels({Place{TARGET(kX86)}, Place{TARGET(kHost)}}); #endif - CHECK_GT(kernels.size(), 0) << "No kernels found for " << op_type; - picked_kernel = std::move(kernels.front()); + if (kernels.size() > 0) { + picked_kernel = std::move(kernels.front()); + } else { + LOG(WARNING) << "No kernels found for " << op_type; + } + } + if (picked_kernel != nullptr) { + picked_kernel->SetContext( + ContextScheduler::Global().NewContext(picked_kernel->target())); } - picked_kernel->SetContext( - ContextScheduler::Global().NewContext(picked_kernel->target())); origin_program_.emplace_back(std::move(op), std::move(picked_kernel)); } return 0; diff --git a/lite/kernels/npu/bridges/fc_op.cc b/lite/kernels/npu/bridges/fc_op.cc index d9d42cd8c73a321449649bca658333fdd5f57325..39708dfce7f996de7a281675088fd824bc92236d 100644 --- a/lite/kernels/npu/bridges/fc_op.cc +++ b/lite/kernels/npu/bridges/fc_op.cc @@ -31,24 +31,15 @@ int FCConverter(void* ctx, OpLite* op, KernelBase* kernel) { VLOG(3) << "[NPU] Converting " + op_type + "..."; auto input_name = op_info->Input("Input").front(); - auto input_type = kernel->GetInputDeclType("Input"); - CHECK(input_type->precision() == PRECISION(kFloat)); - CHECK(input_type->layout() == DATALAYOUT(kNCHW)); auto input = scope->FindTensor(input_name); auto input_dims = input->dims(); auto w_name = op_info->Input("W").front(); - auto w_type = kernel->GetInputDeclType("W"); - CHECK(w_type->precision() == PRECISION(kFloat)); - CHECK(w_type->layout() == DATALAYOUT(kNCHW)); auto w = scope->FindTensor(w_name); auto w_dims = w->dims(); CHECK_EQ(w_dims.size(), 2UL); auto out_name = op_info->Output("Out").front(); - auto out_type = kernel->GetOutputDeclType("Out"); - CHECK(out_type->precision() == PRECISION(kFloat)); - CHECK(out_type->layout() == DATALAYOUT(kNCHW)); auto out = scope->FindTensor(out_name); auto out_dims = out->dims(); @@ -99,9 +90,6 @@ int FCConverter(void* ctx, OpLite* op, KernelBase* kernel) { if (graph->Has(bias_name)) { bias_node = graph->Get(bias_name); } else { - auto bias_type = kernel->GetInputDeclType("Bias"); - CHECK(bias_type->precision() == PRECISION(kFloat)); - CHECK(bias_type->layout() == DATALAYOUT(kNCHW)); auto bias = scope->FindTensor(bias_name); auto bias_dims = bias->dims(); CHECK_EQ(bias_dims.production(), n); diff --git a/lite/kernels/npu/bridges/instance_norm_op.cc b/lite/kernels/npu/bridges/instance_norm_op.cc index d71d17d8f164edf9daefe19162991726f677ce74..55b6fba7faae44277eda2889a57135b522bbc0a1 100644 --- a/lite/kernels/npu/bridges/instance_norm_op.cc +++ b/lite/kernels/npu/bridges/instance_norm_op.cc @@ -32,9 +32,6 @@ int InstanceNormConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input and output vars and op attributes auto x_name = op_info->Input("X").front(); - auto x_type = kernel->GetInputDeclType("X"); - CHECK(x_type->precision() == PRECISION(kFloat)); - CHECK(x_type->layout() == DATALAYOUT(kNCHW)); auto x = scope->FindMutableTensor(x_name); auto x_dims = x->dims(); CHECK_EQ(x_dims.size(), 4L); @@ -43,9 +40,6 @@ int InstanceNormConverter(void* ctx, OpLite* op, KernelBase* kernel) { auto spatial_size = x_dims[2] * x_dims[3]; DDim scale_bias_dims({1, channel_size, 1, 1}); auto y_name = op_info->Output("Y").front(); - auto y_type = kernel->GetOutputDeclType("Y"); - CHECK(y_type->precision() == PRECISION(kFloat)); - CHECK(y_type->layout() == DATALAYOUT(kNCHW)); float epsilon = op_info->GetAttr("epsilon"); // X node @@ -60,9 +54,6 @@ int InstanceNormConverter(void* ctx, OpLite* op, KernelBase* kernel) { std::shared_ptr bias_node = nullptr; if (HasInputArg(op_info, scope, "Bias")) { auto bias_name = op_info->Input("Bias").front(); - auto bias_type = kernel->GetInputDeclType("Bias"); - CHECK(bias_type->precision() == PRECISION(kFloat)); - CHECK(bias_type->layout() == DATALAYOUT(kNCHW)); auto bias = scope->FindMutableTensor(bias_name); auto bias_dims = bias->dims(); CHECK_EQ(channel_size, bias_dims.production()); @@ -100,9 +91,6 @@ int InstanceNormConverter(void* ctx, OpLite* op, KernelBase* kernel) { std::shared_ptr scale_node = nullptr; if (HasInputArg(op_info, scope, "Scale")) { auto scale_name = op_info->Input("Scale").front(); - auto scale_type = kernel->GetInputDeclType("Scale"); - CHECK(scale_type->precision() == PRECISION(kFloat)); - CHECK(scale_type->layout() == DATALAYOUT(kNCHW)); auto scale = scope->FindMutableTensor(scale_name); auto scale_dims = scale->dims(); CHECK_EQ(channel_size, scale_dims.production()); diff --git a/lite/kernels/npu/bridges/interpolate_op.cc b/lite/kernels/npu/bridges/interpolate_op.cc index d68f63b16e1187e85b1d7c4b69b628376dfa228d..1b931afd7aa1d2e6c70fc304ab044b8c42ec06a7 100644 --- a/lite/kernels/npu/bridges/interpolate_op.cc +++ b/lite/kernels/npu/bridges/interpolate_op.cc @@ -32,18 +32,12 @@ int InterpolateConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input and output vars and op attributes auto x_name = op_info->Input("X").front(); - auto x_type = kernel->GetInputDeclType("X"); - CHECK(x_type->precision() == PRECISION(kFloat)); - CHECK(x_type->layout() == DATALAYOUT(kNCHW)); auto x = scope->FindMutableTensor(x_name); auto x_dims = x->dims(); auto x_h = x_dims[2]; auto x_w = x_dims[3]; CHECK_EQ(x_dims.size(), 4); auto out_name = op_info->Output("Out").front(); - auto out_type = kernel->GetOutputDeclType("Out"); - CHECK(out_type->precision() == PRECISION(kFloat)); - CHECK(out_type->layout() == DATALAYOUT(kNCHW)); auto scale = op_info->GetAttr("scale"); auto out_w = op_info->GetAttr("out_w"); auto out_h = op_info->GetAttr("out_h"); @@ -78,9 +72,6 @@ int InterpolateConverter(void* ctx, OpLite* op, KernelBase* kernel) { std::shared_ptr out_size_node = nullptr; if (HasInputArg(op_info, scope, "OutSize")) { auto out_size_name = op_info->Input("OutSize").front(); - auto out_size_type = kernel->GetInputDeclType("OutSize"); - CHECK(out_size_type->precision() == PRECISION(kInt32)); - CHECK(out_size_type->layout() == DATALAYOUT(kNCHW)); if (graph->Has(out_size_name)) { out_size_node = graph->Get(out_size_name); } else { diff --git a/lite/kernels/npu/bridges/layer_norm_op.cc b/lite/kernels/npu/bridges/layer_norm_op.cc index ad32d69d3c40df49ae155b397803cab65ec43dc9..8c12724a1416a28fbfbde40cccc4b204db0bb154 100644 --- a/lite/kernels/npu/bridges/layer_norm_op.cc +++ b/lite/kernels/npu/bridges/layer_norm_op.cc @@ -32,9 +32,6 @@ int LayerNormConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input and output vars and op attributes auto x_name = op_info->Input("X").front(); - auto x_type = kernel->GetInputDeclType("X"); - CHECK(x_type->precision() == PRECISION(kFloat)); - CHECK(x_type->layout() == DATALAYOUT(kNCHW)); auto x = scope->FindMutableTensor(x_name); auto x_dims = x->dims(); auto padded_x_shape = CvtShape(x_dims); @@ -42,9 +39,6 @@ int LayerNormConverter(void* ctx, OpLite* op, KernelBase* kernel) { CHECK(x_rank >= 2 && x_rank <= 4); auto y_name = op_info->Output("Y").front(); - auto y_type = kernel->GetOutputDeclType("Y"); - CHECK(y_type->precision() == PRECISION(kFloat)); - CHECK(y_type->layout() == DATALAYOUT(kNCHW)); auto y = scope->FindMutableTensor(y_name); auto y_dims = y->dims(); auto padded_y_shape = CvtShape(y_dims); @@ -102,9 +96,6 @@ int LayerNormConverter(void* ctx, OpLite* op, KernelBase* kernel) { std::shared_ptr bias_node = nullptr; if (HasInputArg(op_info, scope, "Bias")) { auto bias_name = op_info->Input("Bias").front(); - auto bias_type = kernel->GetInputDeclType("Bias"); - CHECK(bias_type->precision() == PRECISION(kFloat)); - CHECK(bias_type->layout() == DATALAYOUT(kNCHW)); auto bias = scope->FindMutableTensor(bias_name); auto bias_dims = bias->dims(); CHECK_EQ(bias_dims.size(), 1); @@ -122,9 +113,6 @@ int LayerNormConverter(void* ctx, OpLite* op, KernelBase* kernel) { std::shared_ptr scale_node = nullptr; if (HasInputArg(op_info, scope, "Scale")) { auto scale_name = op_info->Input("Scale").front(); - auto scale_type = kernel->GetInputDeclType("Scale"); - CHECK(scale_type->precision() == PRECISION(kFloat)); - CHECK(scale_type->layout() == DATALAYOUT(kNCHW)); auto scale = scope->FindMutableTensor(scale_name); auto scale_dims = scale->dims(); CHECK_EQ(scale_dims.size(), 1); diff --git a/lite/kernels/npu/bridges/matmul_op.cc b/lite/kernels/npu/bridges/matmul_op.cc index 4621f5955a841a0ba1b63381cb956242ce69639a..32af1916899454ef7a045339da5e9fc8a6131cfc 100644 --- a/lite/kernels/npu/bridges/matmul_op.cc +++ b/lite/kernels/npu/bridges/matmul_op.cc @@ -32,16 +32,10 @@ int MatMulConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input and output vars and op attributes auto x_name = op_info->Input("X").front(); - auto x_type = kernel->GetInputDeclType("X"); - CHECK(x_type->precision() == PRECISION(kFloat)); - CHECK(x_type->layout() == DATALAYOUT(kNCHW)); auto x = scope->FindTensor(x_name); auto x_dims = x->dims(); auto y_name = op_info->Input("Y").front(); - auto y_type = kernel->GetInputDeclType("Y"); - CHECK(y_type->precision() == PRECISION(kFloat)); - CHECK(y_type->layout() == DATALAYOUT(kNCHW)); auto y = scope->FindTensor(y_name); auto y_dims = y->dims(); @@ -62,9 +56,6 @@ int MatMulConverter(void* ctx, OpLite* op, KernelBase* kernel) { } auto out_name = op_info->Output("Out").front(); - auto out_type = kernel->GetOutputDeclType("Out"); - CHECK(out_type->precision() == PRECISION(kFloat)); - CHECK(out_type->layout() == DATALAYOUT(kNCHW)); auto out = scope->FindTensor(out_name); auto out_dims = out->dims(); diff --git a/lite/kernels/npu/bridges/mul_op.cc b/lite/kernels/npu/bridges/mul_op.cc index e7f497bd55bc302448528412f5cfb971001f79ca..140700fdd0a90e032da21187c95ee14e172db30a 100644 --- a/lite/kernels/npu/bridges/mul_op.cc +++ b/lite/kernels/npu/bridges/mul_op.cc @@ -33,23 +33,14 @@ int MulConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input and output vars and op attributes auto x_name = op_info->Input("X").front(); - auto x_type = kernel->GetInputDeclType("X"); - CHECK(x_type->precision() == PRECISION(kFloat)); - CHECK(x_type->layout() == DATALAYOUT(kNCHW)); auto x = scope->FindTensor(x_name); auto x_dims = x->dims(); auto y_name = op_info->Input("Y").front(); - auto y_type = kernel->GetInputDeclType("Y"); - CHECK(y_type->precision() == PRECISION(kFloat)); - CHECK(y_type->layout() == DATALAYOUT(kNCHW)); auto y = scope->FindTensor(y_name); auto y_dims = y->dims(); auto out_name = op_info->Output("Out").front(); - auto out_type = kernel->GetOutputDeclType("Out"); - CHECK(out_type->precision() == PRECISION(kFloat)); - CHECK(out_type->layout() == DATALAYOUT(kNCHW)); auto out = scope->FindTensor(out_name); auto out_dims = out->dims(); if (out_dims.size() > 4) { diff --git a/lite/kernels/npu/bridges/pad2d_op.cc b/lite/kernels/npu/bridges/pad2d_op.cc index 372def8a9b2e853c0b17264f9bad960dda6fb295..efcf33af8122f4d148bdcc90e5a071d7d2273192 100644 --- a/lite/kernels/npu/bridges/pad2d_op.cc +++ b/lite/kernels/npu/bridges/pad2d_op.cc @@ -32,15 +32,9 @@ int Pad2dConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input and output vars and op attributes auto x_name = op_info->Input("X").front(); - auto x_type = kernel->GetInputDeclType("X"); - CHECK(x_type->precision() == PRECISION(kFloat)); - CHECK(x_type->layout() == DATALAYOUT(kNCHW)); auto x = scope->FindMutableTensor(x_name); auto x_dims = x->dims(); auto out_name = op_info->Output("Out").front(); - auto out_type = kernel->GetOutputDeclType("Out"); - CHECK(out_type->precision() == PRECISION(kFloat)); - CHECK(out_type->layout() == DATALAYOUT(kNCHW)); auto padding = op_info->GetAttr>("paddings"); CHECK_EQ(padding.size(), 4); diff --git a/lite/kernels/npu/bridges/pool_op.cc b/lite/kernels/npu/bridges/pool_op.cc index ee90d81e508dabf58b9c2525ae6cb429aef332a5..e30a286961c376ac94de78a5a8f9f8a776af062a 100644 --- a/lite/kernels/npu/bridges/pool_op.cc +++ b/lite/kernels/npu/bridges/pool_op.cc @@ -33,15 +33,9 @@ int PoolConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input and output vars and op attributes auto x_name = op_info->Input("X").front(); - auto x_type = kernel->GetInputDeclType("X"); - CHECK(x_type->precision() == PRECISION(kFloat)); - CHECK(x_type->layout() == DATALAYOUT(kNCHW)); auto x = scope->FindMutableTensor(x_name); auto x_dims = x->dims(); auto out_name = op_info->Output("Out").front(); - auto out_type = kernel->GetOutputDeclType("Out"); - CHECK(out_type->precision() == PRECISION(kFloat)); - CHECK(out_type->layout() == DATALAYOUT(kNCHW)); auto pooling_type = op_info->GetAttr("pooling_type"); auto global_pooling = op_info->GetAttr("global_pooling"); auto ksize = op_info->GetAttr>("ksize"); diff --git a/lite/kernels/npu/bridges/reduce_mean_op.cc b/lite/kernels/npu/bridges/reduce_mean_op.cc index 29f065675c742978638fbbb68c71dd451ca35f37..b2fcd4742989f8d47fce3e3ef643dc32eb5ce5ea 100644 --- a/lite/kernels/npu/bridges/reduce_mean_op.cc +++ b/lite/kernels/npu/bridges/reduce_mean_op.cc @@ -32,15 +32,9 @@ int ReduceMeanConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input and output vars and op attributes auto x_name = op_info->Input("X").front(); - auto x_type = kernel->GetInputDeclType("X"); - CHECK(x_type->precision() == PRECISION(kFloat)); - CHECK(x_type->layout() == DATALAYOUT(kNCHW)); auto x = scope->FindMutableTensor(x_name); auto x_dims = x->dims(); auto out_name = op_info->Input("Out").front(); - auto out_type = kernel->GetOutputDeclType("Out"); - CHECK(out_type->precision() == PRECISION(kFloat)); - CHECK(out_type->layout() == DATALAYOUT(kNCHW)); auto keep_dim = op_info->GetAttr("keep_dim"); auto dim = op_info->GetAttr>("dim"); CHECK(!dim.empty()) << "[NPU] \"dim\" of reduce_mean should not be empty."; diff --git a/lite/kernels/npu/bridges/reshape_op.cc b/lite/kernels/npu/bridges/reshape_op.cc index 35443373f1eef12a8115f098914b2723314b2c36..6b4c62a999e12350bfe7b0cb9f7a0b189ea9e01b 100644 --- a/lite/kernels/npu/bridges/reshape_op.cc +++ b/lite/kernels/npu/bridges/reshape_op.cc @@ -33,12 +33,10 @@ int ReshapeConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input and output vars and op attributes auto x_name = op_info->Input("X").front(); - auto x_type = kernel->GetInputDeclType("X"); auto x = scope->FindMutableTensor(x_name); auto x_dims = x->dims(); auto out_name = op_info->Output("Out").front(); - auto out_type = kernel->GetOutputDeclType("Out"); // X node std::shared_ptr x_node = nullptr; diff --git a/lite/kernels/npu/bridges/scale_op.cc b/lite/kernels/npu/bridges/scale_op.cc index d0139a9e2fd580f3143e9ad9809ed924e6e949a4..e5f8a7b3a442eb3e32f9e1d492f1f333d2c0751f 100644 --- a/lite/kernels/npu/bridges/scale_op.cc +++ b/lite/kernels/npu/bridges/scale_op.cc @@ -32,17 +32,11 @@ int ScaleConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input, output and op attributes auto x_name = op_info->Input("X").front(); - auto x_type = kernel->GetInputDeclType("X"); - CHECK(x_type->precision() == PRECISION(kFloat)); - CHECK(x_type->layout() == DATALAYOUT(kNCHW)); auto x = scope->FindMutableTensor(x_name); auto x_dims = x->dims(); auto x_rank = x_dims.size(); CHECK_GE(x_rank, 2); auto out_name = op_info->Output("Out").front(); - auto out_type = kernel->GetOutputDeclType("Out"); - CHECK(out_type->precision() == PRECISION(kFloat)); - CHECK(out_type->layout() == DATALAYOUT(kNCHW)); // HiAI only support [n, c, 1, 1] for the shape of scale and bias std::vector scale_bias_shape = { 1, x_rank < 3 ? 1 : x_dims[x_rank - 3], 1, 1}; diff --git a/lite/kernels/npu/bridges/shuffle_channel_op.cc b/lite/kernels/npu/bridges/shuffle_channel_op.cc index 0552bd2382041bde155b661abc053e8680dbcd3e..0ee721186b3a6f5464a569c48ea95c29f0cd1c24 100644 --- a/lite/kernels/npu/bridges/shuffle_channel_op.cc +++ b/lite/kernels/npu/bridges/shuffle_channel_op.cc @@ -32,15 +32,9 @@ int ShuffleChannelConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input and output vars and op attributes auto x_name = op_info->Input("X").front(); - auto x_type = kernel->GetInputDeclType("X"); - CHECK(x_type->precision() == PRECISION(kFloat)); - CHECK(x_type->layout() == DATALAYOUT(kNCHW)); auto x = scope->FindMutableTensor(x_name); auto x_dims = x->dims(); auto out_name = op_info->Output("Out").front(); - auto out_type = kernel->GetOutputDeclType("Out"); - CHECK(out_type->precision() == PRECISION(kFloat)); - CHECK(out_type->layout() == DATALAYOUT(kNCHW)); auto group = op_info->GetAttr("group"); // X node diff --git a/lite/kernels/npu/bridges/softmax_op.cc b/lite/kernels/npu/bridges/softmax_op.cc index 0ca3bc131d1f0910b9282ec53656bee53bbc5444..a6604fbd7879c4517933b1265633f31270095b67 100644 --- a/lite/kernels/npu/bridges/softmax_op.cc +++ b/lite/kernels/npu/bridges/softmax_op.cc @@ -32,16 +32,10 @@ int SoftmaxConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input and output vars and op attributes auto x_name = op_info->Input("X").front(); - auto x_type = kernel->GetInputDeclType("X"); - CHECK(x_type->precision() == PRECISION(kFloat)); - CHECK(x_type->layout() == DATALAYOUT(kNCHW)); auto x = scope->FindMutableTensor(x_name); auto x_dims = x->dims(); auto x_rank = x_dims.size(); auto out_name = op_info->Output("Out").front(); - auto out_type = kernel->GetOutputDeclType("Out"); - CHECK(out_type->precision() == PRECISION(kFloat)); - CHECK(out_type->layout() == DATALAYOUT(kNCHW)); int axis = op_info->HasAttr("axis") ? op_info->GetAttr("axis") : -1; if (axis < 0) { axis += x_rank; diff --git a/lite/kernels/npu/bridges/split_op.cc b/lite/kernels/npu/bridges/split_op.cc index 2cdf49fd540bc40ceaaa45df4a6ac65bf94f172a..44786220d7dd7fa24e012073e63935d6c824eb98 100644 --- a/lite/kernels/npu/bridges/split_op.cc +++ b/lite/kernels/npu/bridges/split_op.cc @@ -32,15 +32,9 @@ int SplitConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input and output vars and op attributes auto x_name = op_info->Input("X").front(); - auto x_type = kernel->GetInputDeclType("X"); - CHECK(x_type->precision() == PRECISION(kFloat)); - CHECK(x_type->layout() == DATALAYOUT(kNCHW)); auto x = scope->FindMutableTensor(x_name); auto x_dims = x->dims(); auto out_names = op_info->Output("Out"); - auto out_type = kernel->GetOutputDeclType("Out"); - CHECK(out_type->precision() == PRECISION(kFloat)); - CHECK(out_type->layout() == DATALAYOUT(kNCHW)); auto axis = op_info->GetAttr("axis"); auto num = op_info->GetAttr("num"); auto sections = op_info->GetAttr>("sections"); diff --git a/lite/kernels/npu/bridges/sqrt_op.cc b/lite/kernels/npu/bridges/sqrt_op.cc index e8fde2272a28823763f096e087be5f024734cf1b..85fe7bd8c83f4262e81fb615fb8a78978a71a2e9 100644 --- a/lite/kernels/npu/bridges/sqrt_op.cc +++ b/lite/kernels/npu/bridges/sqrt_op.cc @@ -32,15 +32,9 @@ int SqrtConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input and output vars and op attributes auto x_name = op_info->Input("X").front(); - auto x_type = kernel->GetInputDeclType("X"); - CHECK(x_type->precision() == PRECISION(kFloat)); - CHECK(x_type->layout() == DATALAYOUT(kNCHW)); auto x = scope->FindMutableTensor(x_name); auto x_dims = x->dims(); auto out_name = op_info->Output("Out").front(); - auto out_type = kernel->GetOutputDeclType("Out"); - CHECK(out_type->precision() == PRECISION(kFloat)); - CHECK(out_type->layout() == DATALAYOUT(kNCHW)); // X node std::shared_ptr x_node = nullptr; diff --git a/lite/kernels/npu/bridges/square_op.cc b/lite/kernels/npu/bridges/square_op.cc index f03c7690cb490556fe6b26a132454ca109f41310..a25d255de6f8e7e2af12514ad075e83df57f2a7e 100644 --- a/lite/kernels/npu/bridges/square_op.cc +++ b/lite/kernels/npu/bridges/square_op.cc @@ -32,15 +32,9 @@ int SquareConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input and output vars and op attributes auto x_name = op_info->Input("X").front(); - auto x_type = kernel->GetInputDeclType("X"); - CHECK(x_type->precision() == PRECISION(kFloat)); - CHECK(x_type->layout() == DATALAYOUT(kNCHW)); auto x = scope->FindMutableTensor(x_name); auto x_dims = x->dims(); auto out_name = op_info->Output("Out").front(); - auto out_type = kernel->GetOutputDeclType("Out"); - CHECK(out_type->precision() == PRECISION(kFloat)); - CHECK(out_type->layout() == DATALAYOUT(kNCHW)); // X node std::shared_ptr x_node = nullptr; diff --git a/lite/kernels/npu/bridges/transpose_op.cc b/lite/kernels/npu/bridges/transpose_op.cc index 97df11f923d9aad6a49b2251ff985f9dc29ef629..51ca9613fcee646e4c440407dde77405d75f8d4d 100644 --- a/lite/kernels/npu/bridges/transpose_op.cc +++ b/lite/kernels/npu/bridges/transpose_op.cc @@ -32,16 +32,10 @@ int TransposeConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input and output vars and op attributes auto x_name = op_info->Input("X").front(); - auto x_type = kernel->GetInputDeclType("X"); - CHECK(x_type->precision() == PRECISION(kFloat)); - CHECK(x_type->layout() == DATALAYOUT(kNCHW)); auto x = scope->FindMutableTensor(x_name); auto x_dims = x->dims(); auto out_name = op_info->Output("Out").front(); - auto out_type = kernel->GetOutputDeclType("Out"); - CHECK(out_type->precision() == PRECISION(kFloat)); - CHECK(out_type->layout() == DATALAYOUT(kNCHW)); auto axis = op_info->GetAttr>("axis"); diff --git a/lite/kernels/npu/bridges/unsqueeze_op.cc b/lite/kernels/npu/bridges/unsqueeze_op.cc index bcb3bee83be97133cd7eebc7ae69cbc94080d74d..b927ca50b08eb38d7c98aa0e81b25c0296f557f8 100644 --- a/lite/kernels/npu/bridges/unsqueeze_op.cc +++ b/lite/kernels/npu/bridges/unsqueeze_op.cc @@ -31,14 +31,10 @@ int UnsqueezeConverter(void* ctx, OpLite* op, KernelBase* kernel) { VLOG(3) << "[NPU] Converting " << op_type << "... "; auto x_name = op_info->Input("X").front(); - auto x_type = kernel->GetInputDeclType("X"); - CHECK(x_type->layout() == DATALAYOUT(kNCHW)); auto x = scope->FindMutableTensor(x_name); auto x_dims = x->dims(); auto out_name = op_info->Output("Out").front(); - auto out_type = kernel->GetOutputDeclType("Out"); - CHECK(out_type->layout() == DATALAYOUT(kNCHW)); auto out_shape = scope->FindTensor(out_name)->dims().Vectorize(); CHECK(op_info->HasAttr("axes")) << "[NPU] unsqueeze not support axes from tensor now"; diff --git a/lite/kernels/npu/subgraph_compute.cc b/lite/kernels/npu/subgraph_compute.cc index ab0419125e818a584405d2fb127792bbd87c25eb..ae95edb22c2cadc20a2dd0162f807630bf2df128 100644 --- a/lite/kernels/npu/subgraph_compute.cc +++ b/lite/kernels/npu/subgraph_compute.cc @@ -177,6 +177,7 @@ int SubgraphEngine::BuildDeviceProgram() { << PrecisionToStr(precision); break; } + /* if (!subgraph::npu::CheckShape(origin_odims_[i], device_odims[i])) { LOG(WARNING) << "origin and device output's dims are mismatched."; for (int j = 0; j < origin_odims_[i].size(); j++) { @@ -190,6 +191,7 @@ int SubgraphEngine::BuildDeviceProgram() { << device_odims[i].GetWidth() << "}"; return subgraph::FAILED; } + */ device_otensors_[i].reset(new hiai::AiTensor); device_otensors_[i]->Init(&(device_odims[i])); } diff --git a/lite/kernels/xpu/bridges/act_op.cc b/lite/kernels/xpu/bridges/act_op.cc index e3d4588aa2aed1268a8e15f654019031a5202542..502d189b8959a61ab8dd215b9a6416bb8f3b115e 100644 --- a/lite/kernels/xpu/bridges/act_op.cc +++ b/lite/kernels/xpu/bridges/act_op.cc @@ -32,15 +32,9 @@ int ActConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input and output vars and op attributes auto x_name = op_info->Input("X").front(); - auto x_type = kernel->GetInputDeclType("X"); - CHECK(x_type->precision() == PRECISION(kFloat)); - CHECK(x_type->layout() == DATALAYOUT(kNCHW)); auto x = scope->FindMutableTensor(x_name); auto x_dims = x->dims(); auto out_name = op_info->Output("Out").front(); - auto out_type = kernel->GetOutputDeclType("Out"); - CHECK(out_type->precision() == PRECISION(kFloat)); - CHECK(out_type->layout() == DATALAYOUT(kNCHW)); // X node std::shared_ptr x_node = nullptr; diff --git a/lite/kernels/xpu/bridges/batch_norm_op.cc b/lite/kernels/xpu/bridges/batch_norm_op.cc index d84b9cc4f190432166575cd689e839af0d0e0b12..6f909ed91ccf72fc98d6e7433fcbd2631a7675f8 100644 --- a/lite/kernels/xpu/bridges/batch_norm_op.cc +++ b/lite/kernels/xpu/bridges/batch_norm_op.cc @@ -32,40 +32,22 @@ int BatchNormConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input and output vars and op attributes auto x_name = op_info->Input("X").front(); - auto x_type = kernel->GetInputDeclType("X"); - CHECK(x_type->precision() == PRECISION(kFloat)); - CHECK(x_type->layout() == DATALAYOUT(kNCHW)); auto x = scope->FindMutableTensor(x_name); auto x_dims = x->dims(); auto scale_name = op_info->Input("Scale").front(); - auto scale_type = kernel->GetInputDeclType("Scale"); - CHECK(scale_type->precision() == PRECISION(kFloat)); - CHECK(scale_type->layout() == DATALAYOUT(kNCHW)); auto scale = scope->FindMutableTensor(scale_name); auto bias_name = op_info->Input("Bias").front(); - auto bias_type = kernel->GetInputDeclType("Bias"); - CHECK(bias_type->precision() == PRECISION(kFloat)); - CHECK(bias_type->layout() == DATALAYOUT(kNCHW)); auto bias = scope->FindMutableTensor(bias_name); auto mean_name = op_info->Input("Mean").front(); - auto mean_type = kernel->GetInputDeclType("Mean"); - CHECK(mean_type->precision() == PRECISION(kFloat)); - CHECK(mean_type->layout() == DATALAYOUT(kNCHW)); auto mean = scope->FindMutableTensor(mean_name); auto variance_name = op_info->Input("Variance").front(); - auto variance_type = kernel->GetInputDeclType("Variance"); - CHECK(variance_type->precision() == PRECISION(kFloat)); - CHECK(variance_type->layout() == DATALAYOUT(kNCHW)); auto variance = scope->FindMutableTensor(variance_name); auto y_name = op_info->Output("Y").front(); - auto y_type = kernel->GetOutputDeclType("Y"); - CHECK(y_type->precision() == PRECISION(kFloat)); - CHECK(y_type->layout() == DATALAYOUT(kNCHW)); auto epsilon = op_info->GetAttr("epsilon"); diff --git a/lite/kernels/xpu/bridges/conv_op.cc b/lite/kernels/xpu/bridges/conv_op.cc index fe9c598847977e87d87950c3850d3e1d074958b2..bff96ce288fe807225f8e57f94594d7eb6f7eb9e 100644 --- a/lite/kernels/xpu/bridges/conv_op.cc +++ b/lite/kernels/xpu/bridges/conv_op.cc @@ -33,21 +33,12 @@ int ConvConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input and output vars and op attributes auto input_name = op_info->Input("Input").front(); - auto input_type = kernel->GetInputDeclType("Input"); - CHECK(input_type->precision() == PRECISION(kFloat)); - CHECK(input_type->layout() == DATALAYOUT(kNCHW)); auto input = scope->FindMutableTensor(input_name); auto input_dims = input->dims(); auto filter_name = op_info->Input("Filter").front(); - auto filter_type = kernel->GetInputDeclType("Filter"); - CHECK(filter_type->precision() == PRECISION(kFloat)); - CHECK(filter_type->layout() == DATALAYOUT(kNCHW)); auto filter = scope->FindMutableTensor(filter_name); auto filter_dims = filter->dims(); auto output_name = op_info->Output("Output").front(); - auto output_type = kernel->GetOutputDeclType("Output"); - CHECK(output_type->precision() == PRECISION(kFloat)); - CHECK(output_type->layout() == DATALAYOUT(kNCHW)); auto bs = input_dims[0]; auto oc = filter_dims[0]; CHECK_EQ(input_dims.size(), 4); @@ -125,9 +116,6 @@ int ConvConverter(void* ctx, OpLite* op, KernelBase* kernel) { // 2: {n, oc, oh, ow} if (HasInputArg(op_info, scope, "Bias")) { auto bias_name = op_info->Input("Bias").front(); - auto bias_type = kernel->GetInputDeclType("Bias"); - CHECK(bias_type->precision() == PRECISION(kFloat)); - CHECK(bias_type->layout() == DATALAYOUT(kNCHW)); auto bias = scope->FindMutableTensor(bias_name); auto bias_dims = bias->dims(); auto bias_data_size = bias_dims.production(); diff --git a/lite/kernels/xpu/bridges/dropout_op.cc b/lite/kernels/xpu/bridges/dropout_op.cc index df869e17ff5626f03d6eb988a1687bb51c75d440..562dad1a13a19911f70989fc0ac5142bac705edf 100644 --- a/lite/kernels/xpu/bridges/dropout_op.cc +++ b/lite/kernels/xpu/bridges/dropout_op.cc @@ -32,15 +32,9 @@ int DropoutConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input and output vars and op attributes auto x_name = op_info->Input("X").front(); - auto x_type = kernel->GetInputDeclType("X"); - CHECK(x_type->precision() == PRECISION(kFloat)); - CHECK(x_type->layout() == DATALAYOUT(kNCHW)); auto x = scope->FindMutableTensor(x_name); auto x_dims = x->dims(); auto out_name = op_info->Output("Out").front(); - auto out_type = kernel->GetOutputDeclType("Out"); - CHECK(out_type->precision() == PRECISION(kFloat)); - CHECK(out_type->layout() == DATALAYOUT(kNCHW)); auto dropout_prob = op_info->GetAttr("dropout_prob"); auto dropout_implementation = op_info->GetAttr("dropout_implementation"); diff --git a/lite/kernels/xpu/bridges/elementwise_ops.cc b/lite/kernels/xpu/bridges/elementwise_ops.cc index 7fcae312b9776afa7e3b1cbd1bd17bd25b2e4aab..31266a09cc7e2482f22d8e3437b1e93690f37d2a 100644 --- a/lite/kernels/xpu/bridges/elementwise_ops.cc +++ b/lite/kernels/xpu/bridges/elementwise_ops.cc @@ -32,21 +32,12 @@ int ElementwiseConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input and output vars and op attributes auto x_name = op_info->Input("X").front(); - auto x_type = kernel->GetInputDeclType("X"); - CHECK(x_type->precision() == PRECISION(kFloat)); - CHECK(x_type->layout() == DATALAYOUT(kNCHW)); auto x = scope->FindMutableTensor(x_name); auto x_dims = x->dims(); auto y_name = op_info->Input("Y").front(); - auto y_type = kernel->GetInputDeclType("Y"); - CHECK(y_type->precision() == PRECISION(kFloat)); - CHECK(y_type->layout() == DATALAYOUT(kNCHW)); auto y = scope->FindMutableTensor(y_name); auto y_dims = y->dims(); auto out_name = op_info->Output("Out").front(); - auto out_type = kernel->GetOutputDeclType("Out"); - CHECK(out_type->precision() == PRECISION(kFloat)); - CHECK(out_type->layout() == DATALAYOUT(kNCHW)); auto axis = op_info->GetAttr("axis"); // X node diff --git a/lite/kernels/xpu/bridges/gather_op.cc b/lite/kernels/xpu/bridges/gather_op.cc index 845bbb8d98f5734b855178fd68880c5c901608bc..4a5ebdaf2ca7d93916cece8f04e48b50fbe1cc4d 100644 --- a/lite/kernels/xpu/bridges/gather_op.cc +++ b/lite/kernels/xpu/bridges/gather_op.cc @@ -32,24 +32,14 @@ int GatherConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input and output vars and op attributes auto x_name = op_info->Input("X").front(); - auto x_type = kernel->GetInputDeclType("X"); - CHECK(x_type->precision() == PRECISION(kFloat)); - CHECK(x_type->layout() == DATALAYOUT(kNCHW)); auto x = scope->FindMutableTensor(x_name); auto x_dims = x->dims(); auto index_name = op_info->Input("Index").front(); - auto index_type = kernel->GetInputDeclType("Index"); - CHECK(index_type->precision() == PRECISION(kInt32) || - index_type->precision() == PRECISION(kInt64)); - CHECK(index_type->layout() == DATALAYOUT(kNCHW)); auto index = scope->FindMutableTensor(index_name); auto index_dims = index->dims(); CHECK(index_dims.size() == 1 || (index_dims.size() == 2 && index_dims[1] == 1)); auto out_name = op_info->Output("Out").front(); - auto out_type = kernel->GetOutputDeclType("Out"); - CHECK(out_type->precision() == PRECISION(kFloat)); - CHECK(out_type->layout() == DATALAYOUT(kNCHW)); auto out = scope->FindMutableTensor(out_name); auto out_dims = out->dims(); diff --git a/lite/kernels/xpu/bridges/layer_norm_op.cc b/lite/kernels/xpu/bridges/layer_norm_op.cc index 3ad190b73f59d7f1decf01c52d24799550daaea8..140fa3f5b8b55fcb396ea440b01e7cb1d6f348c2 100644 --- a/lite/kernels/xpu/bridges/layer_norm_op.cc +++ b/lite/kernels/xpu/bridges/layer_norm_op.cc @@ -32,15 +32,9 @@ int LayerNormConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input and output vars and op attributes auto x_name = op_info->Input("X").front(); - auto x_type = kernel->GetInputDeclType("X"); - CHECK(x_type->precision() == PRECISION(kFloat)); - CHECK(x_type->layout() == DATALAYOUT(kNCHW)); auto x = scope->FindMutableTensor(x_name); auto x_dims = x->dims(); auto y_name = op_info->Output("Y").front(); - auto y_type = kernel->GetOutputDeclType("Y"); - CHECK(y_type->precision() == PRECISION(kFloat)); - CHECK(y_type->layout() == DATALAYOUT(kNCHW)); auto y = scope->FindMutableTensor(y_name); auto y_dims = y->dims(); auto epsilon = op_info->GetAttr("epsilon"); @@ -70,9 +64,6 @@ int LayerNormConverter(void* ctx, OpLite* op, KernelBase* kernel) { std::shared_ptr scale_node = nullptr; if (HasInputArg(op_info, scope, "Scale")) { auto scale_name = op_info->Input("Scale").front(); - auto scale_type = kernel->GetInputDeclType("Scale"); - CHECK(scale_type->precision() == PRECISION(kFloat)); - CHECK(scale_type->layout() == DATALAYOUT(kNCHW)); auto scale = scope->FindMutableTensor(scale_name); auto scale_dims = scale->dims(); CHECK_EQ(scale_dims.size(), 1); @@ -86,9 +77,6 @@ int LayerNormConverter(void* ctx, OpLite* op, KernelBase* kernel) { std::shared_ptr bias_node = nullptr; if (HasInputArg(op_info, scope, "Bias")) { auto bias_name = op_info->Input("Bias").front(); - auto bias_type = kernel->GetInputDeclType("Bias"); - CHECK(bias_type->precision() == PRECISION(kFloat)); - CHECK(bias_type->layout() == DATALAYOUT(kNCHW)); auto bias = scope->FindMutableTensor(bias_name); auto bias_dims = bias->dims(); CHECK_EQ(bias_dims.size(), 1); diff --git a/lite/kernels/xpu/bridges/lookup_table_op.cc b/lite/kernels/xpu/bridges/lookup_table_op.cc index eecf50b5bd601e912483adb39154a7430bc05c9e..fa480062ce64205e892ba8cc9dc5d84f10cfa8e3 100644 --- a/lite/kernels/xpu/bridges/lookup_table_op.cc +++ b/lite/kernels/xpu/bridges/lookup_table_op.cc @@ -32,22 +32,13 @@ int LookupTableConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input and output vars and op attributes auto ids_name = op_info->Input("Ids").front(); - auto ids_type = kernel->GetInputDeclType("Ids"); - CHECK(ids_type->precision() == PRECISION(kInt64)); - CHECK(ids_type->layout() == DATALAYOUT(kNCHW)); auto ids = scope->FindMutableTensor(ids_name); auto ids_dims = ids->dims(); auto w_name = op_info->Input("W").front(); - auto w_type = kernel->GetInputDeclType("W"); - CHECK(w_type->precision() == PRECISION(kFloat)); - CHECK(w_type->layout() == DATALAYOUT(kNCHW)); auto w = scope->FindMutableTensor(w_name); auto w_dims = w->dims(); CHECK_EQ(w_dims.size(), 2); auto out_name = op_info->Output("Out").front(); - auto out_type = kernel->GetOutputDeclType("Out"); - CHECK(out_type->precision() == PRECISION(kFloat)); - CHECK(out_type->layout() == DATALAYOUT(kNCHW)); auto out = scope->FindMutableTensor(out_name); auto out_dims = out->dims(); auto padding_idx = op_info->GetAttr("padding_idx"); diff --git a/lite/kernels/xpu/bridges/matmul_op.cc b/lite/kernels/xpu/bridges/matmul_op.cc index c17ba8423c04eddf8b042c95e959d8b703c60c7a..cb418f5266b1853dc9bb4b81f04a11e15884c64f 100644 --- a/lite/kernels/xpu/bridges/matmul_op.cc +++ b/lite/kernels/xpu/bridges/matmul_op.cc @@ -32,23 +32,14 @@ int MatmulConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input and output vars and op attributes auto x_name = op_info->Input("X").front(); - auto x_type = kernel->GetInputDeclType("X"); - CHECK(x_type->precision() == PRECISION(kFloat)); - CHECK(x_type->layout() == DATALAYOUT(kNCHW)); auto x = scope->FindMutableTensor(x_name); auto x_dims = x->dims(); auto y_name = op_info->Input("Y").front(); - auto y_type = kernel->GetInputDeclType("Y"); - CHECK(y_type->precision() == PRECISION(kFloat)); - CHECK(y_type->layout() == DATALAYOUT(kNCHW)); auto y = scope->FindMutableTensor(y_name); auto y_dims = y->dims(); auto out_name = op_info->Output("Out").front(); - auto out_type = kernel->GetOutputDeclType("Out"); - CHECK(out_type->precision() == PRECISION(kFloat)); - CHECK(out_type->layout() == DATALAYOUT(kNCHW)); auto out = scope->FindMutableTensor(out_name); auto out_dims = out->dims(); diff --git a/lite/kernels/xpu/bridges/mul_op.cc b/lite/kernels/xpu/bridges/mul_op.cc index e12f767d13e4c1e01b671f5a4f7ba712dd8a1ef5..7ff19fc3c88e6644c1af6be703e9dc3a3f3619f2 100644 --- a/lite/kernels/xpu/bridges/mul_op.cc +++ b/lite/kernels/xpu/bridges/mul_op.cc @@ -32,21 +32,12 @@ int MulConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input and output vars and op attributes auto x_name = op_info->Input("X").front(); - auto x_type = kernel->GetInputDeclType("X"); - CHECK(x_type->precision() == PRECISION(kFloat)); - CHECK(x_type->layout() == DATALAYOUT(kNCHW)); auto x = scope->FindMutableTensor(x_name); auto x_dims = x->dims(); auto y_name = op_info->Input("Y").front(); - auto y_type = kernel->GetInputDeclType("Y"); - CHECK(y_type->precision() == PRECISION(kFloat)); - CHECK(y_type->layout() == DATALAYOUT(kNCHW)); auto y = scope->FindMutableTensor(y_name); auto y_dims = y->dims(); auto out_name = op_info->Output("Out").front(); - auto out_type = kernel->GetOutputDeclType("Out"); - CHECK(out_type->precision() == PRECISION(kFloat)); - CHECK(out_type->layout() == DATALAYOUT(kNCHW)); auto out = scope->FindMutableTensor(out_name); auto out_dims = out->dims(); auto x_num_col_dims = op_info->GetAttr("x_num_col_dims"); diff --git a/lite/kernels/xpu/bridges/pool_op.cc b/lite/kernels/xpu/bridges/pool_op.cc index 90653edcce26dd7da5ca0848368a98ea87a04c0d..4909cef30ff4d3d94d1e4ca8047b3882def23028 100644 --- a/lite/kernels/xpu/bridges/pool_op.cc +++ b/lite/kernels/xpu/bridges/pool_op.cc @@ -32,15 +32,9 @@ int PoolConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input, and attributes auto x_name = op_info->Input("X").front(); - auto x_type = kernel->GetInputDeclType("X"); - CHECK(x_type->precision() == PRECISION(kFloat)); - CHECK(x_type->layout() == DATALAYOUT(kNCHW)); auto x = scope->FindMutableTensor(x_name); auto x_dims = x->dims(); auto out_name = op_info->Output("Out").front(); - auto out_type = kernel->GetOutputDeclType("Out"); - CHECK(out_type->precision() == PRECISION(kFloat)); - CHECK(out_type->layout() == DATALAYOUT(kNCHW)); auto pooling_type = op_info->GetAttr("pooling_type"); auto ceil_mode = op_info->GetAttr("ceil_mode"); auto paddings = op_info->GetAttr>("paddings"); diff --git a/lite/kernels/xpu/bridges/reshape_op.cc b/lite/kernels/xpu/bridges/reshape_op.cc index 5e9a37d18e742e2843da1801cccc60e9202ccbcf..1da32bb9dec7d499ea096df1fae8f02f7b53f59c 100644 --- a/lite/kernels/xpu/bridges/reshape_op.cc +++ b/lite/kernels/xpu/bridges/reshape_op.cc @@ -48,9 +48,6 @@ int ReshapeConverter(void* ctx, OpLite* op, KernelBase* kernel) { std::vector shape; if (HasInputArg(op_info, scope, "ShapeTensor")) { auto shape_tensor_names = op_info->Input("ShapeTensor"); - // auto shape_tensor_type = kernel->GetInputDeclType("ShapeTensor"); - // CHECK(shape_tensor_type->precision() == PRECISION(kInt32)); - // CHECK(shape_tensor_type->layout() == DATALAYOUT(kNCHW)); for (auto shape_tensor_name : shape_tensor_names) { auto shape_tensor = scope->FindMutableTensor(shape_tensor_name); CHECK(shape_tensor->persistable()); @@ -64,9 +61,6 @@ int ReshapeConverter(void* ctx, OpLite* op, KernelBase* kernel) { << shape.size(); } else if (HasInputArg(op_info, scope, "Shape")) { auto actual_shape_name = op_info->Input("Shape").front(); - // auto actual_shape_type = kernel->GetInputDeclType("Shape"); - // CHECK(actual_shape_type->precision() == PRECISION(kInt32)); - // CHECK(actual_shape_type->layout() == DATALAYOUT(kNCHW)); auto actual_shape = scope->FindMutableTensor(actual_shape_name); CHECK(actual_shape->persistable()); auto actual_shape_dims = actual_shape->dims(); diff --git a/lite/kernels/xpu/bridges/scale_op.cc b/lite/kernels/xpu/bridges/scale_op.cc index e6871390ac2690fa2e439ae56e59e49f342777e4..b6379bfbaa30bd027efc71bc32bef9c0cf5bbf4d 100644 --- a/lite/kernels/xpu/bridges/scale_op.cc +++ b/lite/kernels/xpu/bridges/scale_op.cc @@ -32,15 +32,9 @@ int ScaleConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input and output vars and op attributes auto x_name = op_info->Input("X").front(); - auto x_type = kernel->GetInputDeclType("X"); - CHECK(x_type->precision() == PRECISION(kFloat)); - CHECK(x_type->layout() == DATALAYOUT(kNCHW)); auto x = scope->FindMutableTensor(x_name); auto x_dims = x->dims(); auto out_name = op_info->Output("Out").front(); - auto out_type = kernel->GetOutputDeclType("Out"); - CHECK(out_type->precision() == PRECISION(kFloat)); - CHECK(out_type->layout() == DATALAYOUT(kNCHW)); float scale = op_info->GetAttr("scale"); bool bias_after_scale = op_info->GetAttr("bias_after_scale"); float bias = op_info->GetAttr("bias"); diff --git a/lite/kernels/xpu/bridges/slice_op.cc b/lite/kernels/xpu/bridges/slice_op.cc index 3e4592d454ae9b79a51606ed9108c0ef17878276..8af5e87405d56f39b1b5d205e110b41292a8fde7 100644 --- a/lite/kernels/xpu/bridges/slice_op.cc +++ b/lite/kernels/xpu/bridges/slice_op.cc @@ -32,15 +32,9 @@ int SliceConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input, output and op attributes auto input_name = op_info->Input("Input").front(); - auto input_type = kernel->GetInputDeclType("Input"); - CHECK(input_type->precision() == PRECISION(kFloat)); - CHECK(input_type->layout() == DATALAYOUT(kNCHW)); auto input = scope->FindMutableTensor(input_name); auto input_dims = input->dims(); auto out_name = op_info->Output("Out").front(); - auto out_type = kernel->GetOutputDeclType("Out"); - CHECK(out_type->precision() == PRECISION(kFloat)); - CHECK(out_type->layout() == DATALAYOUT(kNCHW)); auto axes = op_info->GetAttr>("axes"); auto starts = op_info->GetAttr>("starts"); auto ends = op_info->GetAttr>("ends"); diff --git a/lite/kernels/xpu/bridges/softmax_op.cc b/lite/kernels/xpu/bridges/softmax_op.cc index 740764015082a4c21bdef443e76e90065b2a99cb..86c8469387b7b96f46e5c266c33b4b4fa3655d21 100644 --- a/lite/kernels/xpu/bridges/softmax_op.cc +++ b/lite/kernels/xpu/bridges/softmax_op.cc @@ -32,15 +32,9 @@ int SoftmaxConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input and output vars and op attributes auto x_name = op_info->Input("X").front(); - auto x_type = kernel->GetInputDeclType("X"); - CHECK(x_type->precision() == PRECISION(kFloat)); - CHECK(x_type->layout() == DATALAYOUT(kNCHW)); auto x = scope->FindMutableTensor(x_name); auto x_dims = x->dims(); auto out_name = op_info->Output("Out").front(); - auto out_type = kernel->GetOutputDeclType("Out"); - CHECK(out_type->precision() == PRECISION(kFloat)); - CHECK(out_type->layout() == DATALAYOUT(kNCHW)); int axis = op_info->HasAttr("axis") ? op_info->GetAttr("axis") : -1; // X node diff --git a/lite/kernels/xpu/bridges/stack_op.cc b/lite/kernels/xpu/bridges/stack_op.cc index 69673aaebaf0a112fe5b1339b6e253a3c3a0334b..5c028489083bf04248d32e687357bd6dad1ca3fa 100644 --- a/lite/kernels/xpu/bridges/stack_op.cc +++ b/lite/kernels/xpu/bridges/stack_op.cc @@ -32,13 +32,7 @@ int StackConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input and output vars and op attributes auto x_names = op_info->Input("X"); - auto x_type = kernel->GetInputDeclType("X"); - CHECK(x_type->precision() == PRECISION(kFloat)); - CHECK(x_type->layout() == DATALAYOUT(kNCHW)); auto y_name = op_info->Output("Y").front(); - auto y_type = kernel->GetOutputDeclType("Y"); - CHECK(y_type->precision() == PRECISION(kFloat)); - CHECK(y_type->layout() == DATALAYOUT(kNCHW)); int axis = op_info->GetAttr("axis"); // X nodes diff --git a/lite/kernels/xpu/bridges/transpose_op.cc b/lite/kernels/xpu/bridges/transpose_op.cc index 4217fe0119be8584f0ca83408dca92100e652076..a563d24086c50392603cba03cbdb6b5c54f86126 100644 --- a/lite/kernels/xpu/bridges/transpose_op.cc +++ b/lite/kernels/xpu/bridges/transpose_op.cc @@ -32,15 +32,9 @@ int TransposeConverter(void* ctx, OpLite* op, KernelBase* kernel) { // Get input and output vars and op attributes auto x_name = op_info->Input("X").front(); - auto x_type = kernel->GetInputDeclType("X"); - CHECK(x_type->precision() == PRECISION(kFloat)); - CHECK(x_type->layout() == DATALAYOUT(kNCHW)); auto x = scope->FindMutableTensor(x_name); auto x_dims = x->dims(); auto out_name = op_info->Output("Out").front(); - auto out_type = kernel->GetOutputDeclType("Out"); - CHECK(out_type->precision() == PRECISION(kFloat)); - CHECK(out_type->layout() == DATALAYOUT(kNCHW)); auto axis = op_info->GetAttr>("axis"); // X node