From 821f187b28febe4bb96f63e45ce6e2d7e9f67f74 Mon Sep 17 00:00:00 2001 From: zhupengyang Date: Mon, 19 Sep 2022 17:52:26 +0800 Subject: [PATCH 1/2] fix cmake cxx flags --- cmake/flags.cmake | 13 +++++++++---- .../optimizer/fix_non_max_suppression.cc | 3 --- .../src/optimizer/constant_fold_operations.cc | 2 +- .../optimizer/fuse_conv2d_activation_into_conv2d.cc | 2 +- .../src/optimizer/fuse_conv2d_add_into_conv2d.cc | 5 +---- ...tmul_dequant_add_into_fully_connected_dequant.cc | 1 - .../src/optimizer/remove_useless_operations.cc | 3 +-- .../nnadapter/nnadapter/src/runtime/device.cc | 5 ++++- lite/backends/x86/math/conv_direct_fp32.cc | 6 +++--- .../optimizer/mir/fusion/quant_dequant_op_fuser.cc | 9 +++------ lite/kernels/xpu/topk_v2_compute.cc | 3 --- lite/operators/__xpu__multi_encoder_op.cc | 7 ++++--- .../kernels/generate_proposals_v2_compute_test.cc | 11 ----------- lite/tests/kernels/roll_compute_test.cc | 2 -- lite/tests/math/sgemm_compute_test.cc | 2 +- 15 files changed, 28 insertions(+), 46 deletions(-) diff --git a/cmake/flags.cmake b/cmake/flags.cmake index 77d547acd5a..5fc870a6599 100644 --- a/cmake/flags.cmake +++ b/cmake/flags.cmake @@ -119,6 +119,7 @@ if (NOT WIN32) set(COMMON_FLAGS -fPIC -fno-omit-frame-pointer + -Werror -Wall -Wextra -Wnon-virtual-dtor @@ -139,10 +140,14 @@ set(COMMON_FLAGS -Wno-error=maybe-uninitialized # Warning in boost gcc 7.2 ) -if (NOT EMSCRIPTEN) - # disable -Werror for Emscripten - set(COMMON_FLAGS "${COMMON_FLAGS} -Werror") -endif(NOT EMSCRIPTEN) +if((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") OR EMSCRIPTEN) + # disable -Werror + list(REMOVE_ITEM COMMON_FLAGS "-Werror") +endif() + +if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 9.3)) + list(APPEND COMMON_FLAGS "-Wno-error=deprecated-copy") # Warning in Eigen +endif() set(GPU_COMMON_FLAGS -fPIC diff --git a/lite/backends/nnadapter/nnadapter/src/driver/cambricon_mlu/optimizer/fix_non_max_suppression.cc b/lite/backends/nnadapter/nnadapter/src/driver/cambricon_mlu/optimizer/fix_non_max_suppression.cc index d3148663a48..62f826d7690 100644 --- a/lite/backends/nnadapter/nnadapter/src/driver/cambricon_mlu/optimizer/fix_non_max_suppression.cc +++ b/lite/backends/nnadapter/nnadapter/src/driver/cambricon_mlu/optimizer/fix_non_max_suppression.cc @@ -221,7 +221,6 @@ bool NMSFixer::HandleMatchedResults(core::Model* model, auto concat0_operand0 = concat0_operation->input_operands[0]; auto concat0_operand1 = concat0_operation->input_operands[1]; auto concat0_operand2 = concat0_operation->input_operands[2]; - auto concat0_operand3 = concat0_operation->input_operands[3]; auto concat0_operand4 = concat0_operation->input_operands[4]; concat0_operation->input_operands = { concat0_operand0, concat0_operand1, concat0_operand2, concat0_operand4}; @@ -230,14 +229,12 @@ bool NMSFixer::HandleMatchedResults(core::Model* model, auto concat1_operand0 = concat1_operation->input_operands[0]; auto concat1_operand1 = concat1_operation->input_operands[1]; auto concat1_operand2 = concat1_operation->input_operands[2]; - auto concat1_operand3 = concat1_operation->input_operands[3]; auto concat1_operand4 = concat1_operation->input_operands[4]; concat1_operation->input_operands = { concat1_operand0, concat1_operand1, concat1_operand2, concat1_operand4}; auto concat2_operation = nodes.at("concat2")->operation; auto concat2_operand0 = concat2_operation->input_operands[0]; - auto concat2_operand1 = concat2_operation->input_operands[1]; auto concat2_operand2 = concat2_operation->input_operands[2]; auto nms_operation = nodes.at("nms")->operation; auto nms_index_operand = nms_operation->output_operands[2]; diff --git a/lite/backends/nnadapter/nnadapter/src/optimizer/constant_fold_operations.cc b/lite/backends/nnadapter/nnadapter/src/optimizer/constant_fold_operations.cc index cbc615d7f9c..d5ed043dd66 100644 --- a/lite/backends/nnadapter/nnadapter/src/optimizer/constant_fold_operations.cc +++ b/lite/backends/nnadapter/nnadapter/src/optimizer/constant_fold_operations.cc @@ -50,7 +50,7 @@ class ConstantFoldOperationsFuser : public PatternMatcher { void ConstantFoldOperationsFuser::BuildPattern() { // Create patterns - auto operation = CreatePattern("operation")->IsOperation(); + CreatePattern("operation")->IsOperation(); } bool ConstantFoldOperationsFuser::HandleMatchedResults( diff --git a/lite/backends/nnadapter/nnadapter/src/optimizer/fuse_conv2d_activation_into_conv2d.cc b/lite/backends/nnadapter/nnadapter/src/optimizer/fuse_conv2d_activation_into_conv2d.cc index 90929d7404c..5fd2b978f22 100644 --- a/lite/backends/nnadapter/nnadapter/src/optimizer/fuse_conv2d_activation_into_conv2d.cc +++ b/lite/backends/nnadapter/nnadapter/src/optimizer/fuse_conv2d_activation_into_conv2d.cc @@ -47,7 +47,7 @@ void Conv2DActivationFuser::BuildPattern() { // Operand patterns auto conv2d_input_pattern = CreatePattern("conv2d_input")->IsOperationInputOperand(conv2d_type_, 0); - int conv2d_fuse_code_index; + int conv2d_fuse_code_index = -1; if (conv2d_type_ == NNADAPTER_CONV_2D) { conv2d_fuse_code_index = 8; } else if (conv2d_type_ == NNADAPTER_CONV_2D_TRANSPOSE) { diff --git a/lite/backends/nnadapter/nnadapter/src/optimizer/fuse_conv2d_add_into_conv2d.cc b/lite/backends/nnadapter/nnadapter/src/optimizer/fuse_conv2d_add_into_conv2d.cc index 56c837b1b58..472b41d46ce 100644 --- a/lite/backends/nnadapter/nnadapter/src/optimizer/fuse_conv2d_add_into_conv2d.cc +++ b/lite/backends/nnadapter/nnadapter/src/optimizer/fuse_conv2d_add_into_conv2d.cc @@ -44,7 +44,7 @@ void Conv2DAddFuser::BuildPattern() { // Operand patterns auto conv2d_input_pattern = CreatePattern("conv2d_input")->IsOperationInputOperand(conv2d_type_, 0); - int conv2d_fuse_code_index; + int conv2d_fuse_code_index = -1; if (conv2d_type_ == NNADAPTER_CONV_2D) { conv2d_fuse_code_index = 8; } else if (conv2d_type_ == NNADAPTER_CONV_2D_TRANSPOSE) { @@ -91,8 +91,6 @@ bool Conv2DAddFuser::HandleMatchedResults( // Get the operands and operations from the matched subgraph nodes. auto conv2d_operation = nodes.at("conv2d")->operation; auto conv2d_fuse_code_operand = nodes.at("conv2d_fuse_code")->operand; - auto conv2d_input_operand = conv2d_operation->input_operands[0]; - auto conv2d_output_operand = conv2d_operation->output_operands[0]; auto conv2d_filter_operand = conv2d_operation->input_operands[1]; auto conv2d_bias_operand = conv2d_operation->input_operands[2]; auto conv2d_group = @@ -103,7 +101,6 @@ bool Conv2DAddFuser::HandleMatchedResults( conv2d_output_channel_size = conv2d_filter_operand->type.dimensions.data[1] * conv2d_group; } - auto add_operation = nodes.at("add")->operation; auto add_input_operand = nodes.at("add_input")->operand; auto add_fuse_code_operand = nodes.at("add_fuse_code")->operand; auto add_output_operand = nodes.at("add_output")->operand; diff --git a/lite/backends/nnadapter/nnadapter/src/optimizer/fuse_matmul_dequant_add_into_fully_connected_dequant.cc b/lite/backends/nnadapter/nnadapter/src/optimizer/fuse_matmul_dequant_add_into_fully_connected_dequant.cc index 35da661aae1..c5f560abe02 100644 --- a/lite/backends/nnadapter/nnadapter/src/optimizer/fuse_matmul_dequant_add_into_fully_connected_dequant.cc +++ b/lite/backends/nnadapter/nnadapter/src/optimizer/fuse_matmul_dequant_add_into_fully_connected_dequant.cc @@ -119,7 +119,6 @@ bool MatMulDequantAddFuser::HandleMatchedResults( auto add_output_operand = add_operation->output_operands[0]; auto dequant_operation = nodes.at("dequant")->operation; auto dequant_input_operand = dequant_operation->input_operands[0]; - auto dequant_output_operand = dequant_operation->output_operands[0]; auto matmul_transpose_y = *reinterpret_cast(matmul_transpose_y_operand->buffer); auto matmul_num_units = diff --git a/lite/backends/nnadapter/nnadapter/src/optimizer/remove_useless_operations.cc b/lite/backends/nnadapter/nnadapter/src/optimizer/remove_useless_operations.cc index d49e646079d..e07e3f4af93 100644 --- a/lite/backends/nnadapter/nnadapter/src/optimizer/remove_useless_operations.cc +++ b/lite/backends/nnadapter/nnadapter/src/optimizer/remove_useless_operations.cc @@ -36,7 +36,7 @@ class RemoveUselessCastFuser : public PatternMatcher { void RemoveUselessCastFuser::BuildPattern() { // Create patterns - auto cast = CreatePattern("cast", NNADAPTER_CAST); + CreatePattern("cast", NNADAPTER_CAST); } bool RemoveUselessCastFuser::HandleMatchedResults( @@ -149,7 +149,6 @@ void RemoveUselessMulFuser::BuildPattern() { bool RemoveUselessMulFuser::HandleMatchedResults( core::Model* model, const std::map& nodes) { auto mul_x = nodes.at("mul_x")->operand; - auto mul = nodes.at("mul")->operation; auto mul_out = nodes.at("mul_out")->operand; if (IsModelInputOperand(mul_x) && IsModelOutputOperand(mul_out)) return false; diff --git a/lite/backends/nnadapter/nnadapter/src/runtime/device.cc b/lite/backends/nnadapter/nnadapter/src/runtime/device.cc index 05f89b7a34b..e9d6a21e2c6 100644 --- a/lite/backends/nnadapter/nnadapter/src/runtime/device.cc +++ b/lite/backends/nnadapter/nnadapter/src/runtime/device.cc @@ -74,6 +74,7 @@ class Context { }; Context::Context(void* device, const char* properties) : device_(device) { + NNADAPTER_CHECK(device_); // Extract the runtime parameters from the context properties NNADAPTER_LOG(INFO) << "properties: " << std::string(properties); std::string key_value; @@ -89,7 +90,9 @@ Context::Context(void* device, const char* properties) : device_(device) { class Program { public: - explicit Program(Context* context) : context_(context) {} + explicit Program(Context* context) : context_(context) { + NNADAPTER_CHECK(context_); + } ~Program() { Clear(); } int Validate(const core::Model* model, bool* supported_operations); diff --git a/lite/backends/x86/math/conv_direct_fp32.cc b/lite/backends/x86/math/conv_direct_fp32.cc index 672b2036469..52f568e2c10 100644 --- a/lite/backends/x86/math/conv_direct_fp32.cc +++ b/lite/backends/x86/math/conv_direct_fp32.cc @@ -180,10 +180,10 @@ void conv_direct::generate_code(int ic, // compute output whole line // three parts: [left, middle, right] - auto cal_out_whole_line = [=, &temp](int oc_group, int ic_group) { + auto cal_out_whole_line = [=](int oc_group, int ic_group) { int ow_bulk_i = ow / ow_bulk; - auto cal_bulk = [=, &temp]( + auto cal_bulk = [=]( int oc_group, int ic_group, int l_pad, int r_pad, int bulk) { load(oc_group, bulk); @@ -255,7 +255,7 @@ void conv_direct::generate_code(int ic, }; // - auto cal_with_ic_fixed = [=, &temp](int ic_group) { + auto cal_with_ic_fixed = [=](int ic_group) { // ic_group is fixed // according to oc ! Xbyak::Label label_oc_remain; diff --git a/lite/core/optimizer/mir/fusion/quant_dequant_op_fuser.cc b/lite/core/optimizer/mir/fusion/quant_dequant_op_fuser.cc index 0e9e5cc33c6..ba3cfd83d4f 100644 --- a/lite/core/optimizer/mir/fusion/quant_dequant_op_fuser.cc +++ b/lite/core/optimizer/mir/fusion/quant_dequant_op_fuser.cc @@ -322,13 +322,12 @@ void DequantOpFuser::InsertNewNode(SSAGraph* graph, #endif op_desc.SetInputScale(weight_name, weight_scale); - // change the weight from the float type to int8 type. +// change the weight from the float type to int8 type. +#ifdef LITE_WITH_FPGA Tensor temp_tensor; temp_tensor.CopyDataFrom(*quantized_weight_t); float* temp_data = temp_tensor.mutable_data(); size_t weight_num = quantized_weight_t->data_size(); - -#ifdef LITE_WITH_FPGA float* quantized_weight_data = quantized_weight_t->mutable_data(); for (size_t i = 0; i < weight_num; i++) { quantized_weight_data[i] = temp_data[i] * whole_weight_scale; @@ -442,11 +441,10 @@ void ChannelWiseDequantOpFuser::InsertNewNode(SSAGraph* graph, auto quantized_weight_var_name = quantized_op_weight->arg()->name; auto quantized_weight_t = scope->FindVar(quantized_weight_var_name)->GetMutable(); +#ifdef LITE_WITH_FPGA Tensor temp_tensor; temp_tensor.CopyDataFrom(*quantized_weight_t); float* temp_data = temp_tensor.mutable_data(); - -#ifdef LITE_WITH_FPGA float* quantized_weight_data = quantized_weight_t->mutable_data(); int channel = channel_scale_tensor->data_size(); int weight_chw = quantized_weight_t->data_size() / channel; @@ -456,7 +454,6 @@ void ChannelWiseDequantOpFuser::InsertNewNode(SSAGraph* graph, } quantized_weight_t->set_persistable(true); quantized_weight_t->set_precision(PRECISION(kFloat)); - #else CastPersistableTensorInPlace(quantized_weight_t, weight_bit_length); #endif diff --git a/lite/kernels/xpu/topk_v2_compute.cc b/lite/kernels/xpu/topk_v2_compute.cc index 1536fdfb1d0..5b9941e9fb6 100644 --- a/lite/kernels/xpu/topk_v2_compute.cc +++ b/lite/kernels/xpu/topk_v2_compute.cc @@ -25,9 +25,6 @@ namespace xpu { void TopkV2Compute::Run() { auto& param = this->Param(); auto& ctx = this->ctx_->As(); - const float* x_data = param.X->data(); - float* out_val = param.Out->mutable_data(); - auto out_ind = param.Indices->mutable_data(); DDim x_dims = param.X->dims(); int axis = param.axis; diff --git a/lite/operators/__xpu__multi_encoder_op.cc b/lite/operators/__xpu__multi_encoder_op.cc index 2fc55089be1..019a5e0632d 100644 --- a/lite/operators/__xpu__multi_encoder_op.cc +++ b/lite/operators/__xpu__multi_encoder_op.cc @@ -143,9 +143,10 @@ bool XPUMultiEncoderOp::AttachImpl(const cpp::OpDesc& op_desc, param_.norm_before = op_desc.GetAttr("norm_before"); param_.adaptive_seqlen = op_desc.GetAttr("adaptive_seqlen"); param_.per_channel = op_desc.GetAttr("per_channel"); - if (op_desc.HasAttr("enable_int8") && op_desc.GetAttr("enable_int8") || - op_desc.HasAttr("enable_int16") && - op_desc.GetAttr("enable_int16")) { + if ((op_desc.HasAttr("enable_int8") && + op_desc.GetAttr("enable_int8")) || + (op_desc.HasAttr("enable_int16") && + op_desc.GetAttr("enable_int16"))) { param_.input_max = op_desc.GetAttr>("FCInputMax"); } param_.weight_max.clear(); diff --git a/lite/tests/kernels/generate_proposals_v2_compute_test.cc b/lite/tests/kernels/generate_proposals_v2_compute_test.cc index f6057404f2a..175206ac8f7 100644 --- a/lite/tests/kernels/generate_proposals_v2_compute_test.cc +++ b/lite/tests/kernels/generate_proposals_v2_compute_test.cc @@ -258,10 +258,6 @@ class GenerateProposalsV2ComputeTester : public arena::TestCase { const T* im_info_data = im_info.data(); T offset = pixel_offset ? static_cast(1) : 0; T zero(0); - T im_w = - is_scale ? round(im_info_data[1] / im_info_data[2]) : im_info_data[1]; - T im_h = - is_scale ? round(im_info_data[0] / im_info_data[2]) : im_info_data[0]; for (int64_t i = 0; i < boxes->numel(); ++i) { if (i % 4 == 0) { boxes_data[i] = @@ -301,13 +297,6 @@ class GenerateProposalsV2ComputeTester : public arena::TestCase { T x_ctr = boxes_data[4 * i] + ws / 2; T y_ctr = boxes_data[4 * i + 1] + hs / 2; - if (is_scale) { - T ws = - (boxes_data[4 * i + 2] - boxes_data[4 * i]) / im_info_data[2] + 1; - T hs = (boxes_data[4 * i + 3] - boxes_data[4 * i + 1]) / - im_info_data[2] + - 1; - } if (ws >= min_size && hs >= min_size && x_ctr <= im_info_data[1] && y_ctr <= im_info_data[0]) { keep_data[keep_len++] = i; diff --git a/lite/tests/kernels/roll_compute_test.cc b/lite/tests/kernels/roll_compute_test.cc index 179d1a87b83..5f19adb04ce 100644 --- a/lite/tests/kernels/roll_compute_test.cc +++ b/lite/tests/kernels/roll_compute_test.cc @@ -97,7 +97,6 @@ class RollComputeTester : public arena::TestCase { void RunBaseline(Scope* scope) override { auto* x = scope->FindTensor(x_); - const auto* x_data = x->data(); std::vector shifts; if (!shifts_tensor_.empty()) { auto* shift = scope->FindTensor(shifts_tensor_); @@ -121,7 +120,6 @@ class RollComputeTester : public arena::TestCase { out->CopyDataFrom(*x); auto* out_data = out->mutable_data(); for (size_t i = 0; i < nums; i++) { - int64_t input_size = input_dim.size(); ShiftAlongDim(out_data, input_dim, axis_[i], shifts_[i]); } } diff --git a/lite/tests/math/sgemm_compute_test.cc b/lite/tests/math/sgemm_compute_test.cc index d81c6e00e9e..e525a8ea93f 100644 --- a/lite/tests/math/sgemm_compute_test.cc +++ b/lite/tests/math/sgemm_compute_test.cc @@ -122,7 +122,6 @@ bool test_sgemm(bool tra, auto da = ta.mutable_data(); auto db = tb.mutable_data(); auto dc = tc.mutable_data(); - auto dc_sve = tc_sve.mutable_data(); auto dc_basic = tc_basic.mutable_data(); auto dc_backup = tc_backup.mutable_data(); auto dbias = tbias.mutable_data(); @@ -212,6 +211,7 @@ bool test_sgemm(bool tra, } #ifdef LITE_WITH_ARM8_SVE2 // sve + auto dc_sve = tc_sve.mutable_data(); Timer t1; for (int i = 0; i < FLAGS_repeats; ++i) { if (i == FLAGS_repeats - 1) { From 2cf0c2c0e5181afb1474314eba72ddec1ff62915 Mon Sep 17 00:00:00 2001 From: zhupengyang Date: Wed, 21 Sep 2022 11:01:00 +0800 Subject: [PATCH 2/2] fix opencl --- lite/kernels/opencl/conv_image_compute.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lite/kernels/opencl/conv_image_compute.cc b/lite/kernels/opencl/conv_image_compute.cc index cd4cb6cb6b7..4b69b28ae86 100644 --- a/lite/kernels/opencl/conv_image_compute.cc +++ b/lite/kernels/opencl/conv_image_compute.cc @@ -1841,6 +1841,8 @@ void ConvImageCompute::Conv2d1x1opt() { } } +void ConvImageCompute::Conv2d3x3() { LOG(FATAL) << "Not implement."; } + void ConvImageCompute::Conv2dnxnopt() { int arg_idx = 0; status_ = kernel_.setArg(arg_idx++, c_blk_);