未验证 提交 f1f79b0d 编写于 作者: L Leo Chen 提交者: GitHub

fix maybe-uninitialized warning (#42902)

* fix maybe-uninitialized warning

* fix compile

* fix xpu compile

* fix npu compile

* fix infer compile

* fix compile

* fix compile
上级 45d7a3ea
...@@ -147,7 +147,6 @@ set(COMMON_FLAGS ...@@ -147,7 +147,6 @@ set(COMMON_FLAGS
-Wno-error=terminate # Warning in PADDLE_ENFORCE -Wno-error=terminate # Warning in PADDLE_ENFORCE
-Wno-error=int-in-bool-context # Warning in Eigen gcc 7.2 -Wno-error=int-in-bool-context # Warning in Eigen gcc 7.2
-Wimplicit-fallthrough=0 # Warning in tinyformat.h -Wimplicit-fallthrough=0 # Warning in tinyformat.h
-Wno-error=maybe-uninitialized # Warning in boost gcc 7.2
${fsanitize} ${fsanitize}
) )
......
...@@ -546,9 +546,9 @@ bool DistModel::Run(const std::vector<DistModelTensor> &input_data, ...@@ -546,9 +546,9 @@ bool DistModel::Run(const std::vector<DistModelTensor> &input_data,
DistModelTimer timer; DistModelTimer timer;
timer.tic(); timer.tic();
double feed_elapse; double feed_elapse = 0;
double fleet_exe_elapse; double fleet_exe_elapse = 0;
double fetch_elapse; double fetch_elapse = 0;
if (!FeedData(input_data, scope_.get())) { if (!FeedData(input_data, scope_.get())) {
LOG(ERROR) << "DistModel failed at feeding data."; LOG(ERROR) << "DistModel failed at feeding data.";
......
...@@ -488,7 +488,7 @@ void QuantDequantFusePass::FuseDequant(ir::Graph* graph, Scope* scope, ...@@ -488,7 +488,7 @@ void QuantDequantFusePass::FuseDequant(ir::Graph* graph, Scope* scope,
// Convert weight to fp32 range // Convert weight to fp32 range
auto* weight_tensor = auto* weight_tensor =
scope->Var(quantized_op_weight_node->Name())->GetMutable<LoDTensor>(); scope->Var(quantized_op_weight_node->Name())->GetMutable<LoDTensor>();
auto w_dims = weight_tensor->dims(); const auto& w_dims = weight_tensor->dims();
float* quantized_weight_data = float* quantized_weight_data =
weight_tensor->mutable_data<float>(platform::CPUPlace()); weight_tensor->mutable_data<float>(platform::CPUPlace());
// If quantized op is fc, weight scale size = 1; // If quantized op is fc, weight scale size = 1;
......
...@@ -93,7 +93,7 @@ void TransposeFlattenConcatFusePass::RunTransposeFlattenConcatFuse( ...@@ -93,7 +93,7 @@ void TransposeFlattenConcatFusePass::RunTransposeFlattenConcatFuse(
std::vector<Node *> nodes; std::vector<Node *> nodes;
std::vector<int> trans_axis0; std::vector<int> trans_axis0;
int flatten_axis0; int flatten_axis0 = 0;
for (int i = 0; i < times; i++) { for (int i = 0; i < times; i++) {
PADDLE_ENFORCE_NOT_NULL( PADDLE_ENFORCE_NOT_NULL(
subgraph.at(pattern.GetPDNode("transpose" + std::to_string(i))), subgraph.at(pattern.GetPDNode("transpose" + std::to_string(i))),
......
...@@ -268,7 +268,7 @@ void LiteSubgraphPass::SetUpEngine( ...@@ -268,7 +268,7 @@ void LiteSubgraphPass::SetUpEngine(
auto nnadapter_model_cache_token = auto nnadapter_model_cache_token =
Get<std::vector<std::string>>("nnadapter_model_cache_token"); Get<std::vector<std::string>>("nnadapter_model_cache_token");
lite_api::TargetType target_type; lite_api::TargetType target_type = TARGET(kX86);
if (use_gpu) { if (use_gpu) {
target_type = TARGET(kCUDA); target_type = TARGET(kCUDA);
} else if (use_xpu) { } else if (use_xpu) {
......
...@@ -522,7 +522,7 @@ TEST(Tensor, GpuShareExternalData) { ...@@ -522,7 +522,7 @@ TEST(Tensor, GpuShareExternalData) {
auto out = predictor->GetOutputHandle("fc_1.tmp_2"); auto out = predictor->GetOutputHandle("fc_1.tmp_2");
auto out_shape = out->shape(); auto out_shape = out->shape();
float* out_data; float* out_data = nullptr;
auto out_size = std::accumulate(out_shape.begin(), out_shape.end(), 1, auto out_size = std::accumulate(out_shape.begin(), out_shape.end(), 1,
std::multiplies<int>()) * std::multiplies<int>()) *
sizeof(float); sizeof(float);
......
...@@ -56,7 +56,7 @@ class MultiheadMatMulOpConverter : public OpConverter { ...@@ -56,7 +56,7 @@ class MultiheadMatMulOpConverter : public OpConverter {
weight_t->numel() * sizeof(float)); weight_t->numel() * sizeof(float));
// (hidden_in, 3, hidden_out) // (hidden_in, 3, hidden_out)
auto weight_dims = weight_t->dims(); const auto& weight_dims = weight_t->dims();
int hidden_in = weight_dims[0]; // channels_in int hidden_in = weight_dims[0]; // channels_in
int three = weight_dims[1]; // channels_out int three = weight_dims[1]; // channels_out
......
...@@ -41,7 +41,7 @@ class ReduceOpConverter : public OpConverter { ...@@ -41,7 +41,7 @@ class ReduceOpConverter : public OpConverter {
const framework::Scope& scope, bool test_mode) override { const framework::Scope& scope, bool test_mode) override {
VLOG(4) << "convert a paddle " << op_type << " op to tensorrt reduce layer"; VLOG(4) << "convert a paddle " << op_type << " op to tensorrt reduce layer";
framework::OpDesc op_desc(op, nullptr); framework::OpDesc op_desc(op, nullptr);
nvinfer1::ReduceOperation reduce_type; nvinfer1::ReduceOperation reduce_type = nvinfer1::ReduceOperation::kSUM;
if (op_type == "reduce_sum") { if (op_type == "reduce_sum") {
reduce_type = nvinfer1::ReduceOperation::kSUM; reduce_type = nvinfer1::ReduceOperation::kSUM;
} else if (op_type == "reduce_mean") { } else if (op_type == "reduce_mean") {
......
...@@ -161,8 +161,8 @@ class LazyZerosNPU { ...@@ -161,8 +161,8 @@ class LazyZerosNPU {
} }
auto place = dev_ctx.GetPlace(); auto place = dev_ctx.GetPlace();
auto stream = dev_ctx.stream(); auto stream = dev_ctx.stream();
Tensor* zero_tensor; Tensor* zero_tensor = nullptr;
void* zero_ptr; void* zero_ptr = nullptr;
if (found_inf_vec[0]) { if (found_inf_vec[0]) {
int max_num = -1; int max_num = -1;
for (size_t i = 0; i < xs.size(); ++i) { for (size_t i = 0; i < xs.size(); ++i) {
......
...@@ -75,7 +75,7 @@ void Compare(f::Scope *scope, const p::DeviceContext &ctx, ...@@ -75,7 +75,7 @@ void Compare(f::Scope *scope, const p::DeviceContext &ctx,
paddle::framework::TensorToVector(*tensor_out, ctx, &out_vec); paddle::framework::TensorToVector(*tensor_out, ctx, &out_vec);
ctx.Wait(); ctx.Wait();
float expected; float expected = 0.0;
if (op_type == "elementwise_add") { if (op_type == "elementwise_add") {
expected = 3.0; expected = 3.0;
} else if (op_type == "elementwise_sub") { } else if (op_type == "elementwise_sub") {
...@@ -133,7 +133,7 @@ void CompareGrad(f::Scope *scope, const p::DeviceContext &ctx, ...@@ -133,7 +133,7 @@ void CompareGrad(f::Scope *scope, const p::DeviceContext &ctx,
paddle::framework::TensorToVector(*tensor_dy, ctx, &dy_vec); paddle::framework::TensorToVector(*tensor_dy, ctx, &dy_vec);
ctx.Wait(); ctx.Wait();
float expected_x, expected_y; float expected_x = 0, expected_y = 0;
if (op_type == "elementwise_add_grad") { if (op_type == "elementwise_add_grad") {
expected_x = 1.0; expected_x = 1.0;
expected_y = 6.0; expected_y = 6.0;
......
...@@ -103,7 +103,7 @@ void ComputeSumAndSquareSum(const framework::Tensor &cpu_x, ...@@ -103,7 +103,7 @@ void ComputeSumAndSquareSum(const framework::Tensor &cpu_x,
framework::Tensor *cpu_sum, framework::Tensor *cpu_sum,
framework::Tensor *cpu_sum_of_square) { framework::Tensor *cpu_sum_of_square) {
// x is in NHWC format. // x is in NHWC format.
auto dims = cpu_x.dims(); const auto &dims = cpu_x.dims();
int64_t c = dims[3]; int64_t c = dims[3];
const T *cpu_x_ptr = cpu_x.data<T>(); const T *cpu_x_ptr = cpu_x.data<T>();
......
...@@ -51,7 +51,7 @@ void InitRandomTensor(const std::vector<int64_t> &dims, ...@@ -51,7 +51,7 @@ void InitRandomTensor(const std::vector<int64_t> &dims,
template <typename T> template <typename T>
void TransposeNchwToNhwc(const framework::Tensor &cpu_in, void TransposeNchwToNhwc(const framework::Tensor &cpu_in,
framework::Tensor *cpu_out) { framework::Tensor *cpu_out) {
auto in_dims = cpu_in.dims(); const auto &in_dims = cpu_in.dims();
EXPECT_EQ(cpu_in.dims().size(), 4); EXPECT_EQ(cpu_in.dims().size(), 4);
const T *cpu_in_ptr = cpu_in.data<T>(); const T *cpu_in_ptr = cpu_in.data<T>();
...@@ -184,7 +184,7 @@ template <typename T> ...@@ -184,7 +184,7 @@ template <typename T>
void ComputeSumAndSquareSum(const framework::Tensor &cpu_out, void ComputeSumAndSquareSum(const framework::Tensor &cpu_out,
framework::Tensor *cpu_sum, framework::Tensor *cpu_sum,
framework::Tensor *cpu_sum_of_square) { framework::Tensor *cpu_sum_of_square) {
auto dims = cpu_out.dims(); const auto &dims = cpu_out.dims();
int64_t c = dims[3]; int64_t c = dims[3];
const T *cpu_out_ptr = cpu_out.data<T>(); const T *cpu_out_ptr = cpu_out.data<T>();
......
...@@ -130,7 +130,7 @@ class FusionRepeatedFCReluKernel : public framework::OpKernel<T> { ...@@ -130,7 +130,7 @@ class FusionRepeatedFCReluKernel : public framework::OpKernel<T> {
int weight_sz = static_cast<int>(weights.size()); int weight_sz = static_cast<int>(weights.size());
auto i_dims = in->dims(); auto i_dims = in->dims();
auto w_dims = weights[0]->dims(); const auto& w_dims = weights[0]->dims();
jit::matmul_attr_t attr; jit::matmul_attr_t attr;
attr.m = i_dims[0]; attr.m = i_dims[0];
attr.n = w_dims[1]; attr.n = w_dims[1];
...@@ -140,8 +140,8 @@ class FusionRepeatedFCReluKernel : public framework::OpKernel<T> { ...@@ -140,8 +140,8 @@ class FusionRepeatedFCReluKernel : public framework::OpKernel<T> {
relus[0]->mutable_data<T>(place), attr); relus[0]->mutable_data<T>(place), attr);
for (int i = 1; i < weight_sz - 1; ++i) { for (int i = 1; i < weight_sz - 1; ++i) {
auto i_dims = relus[i - 1]->dims(); const auto& i_dims = relus[i - 1]->dims();
auto w_dims = weights[i]->dims(); const auto& w_dims = weights[i]->dims();
attr.m = i_dims[0]; attr.m = i_dims[0];
attr.n = w_dims[1]; attr.n = w_dims[1];
attr.k = w_dims[0]; attr.k = w_dims[0];
...@@ -150,8 +150,8 @@ class FusionRepeatedFCReluKernel : public framework::OpKernel<T> { ...@@ -150,8 +150,8 @@ class FusionRepeatedFCReluKernel : public framework::OpKernel<T> {
biases[i]->data<T>(), relus[i]->mutable_data<T>(place), attr); biases[i]->data<T>(), relus[i]->mutable_data<T>(place), attr);
} }
auto i_dims_last = relus[weight_sz - 2]->dims(); const auto& i_dims_last = relus[weight_sz - 2]->dims();
auto w_dims_last = weights[weight_sz - 1]->dims(); const auto& w_dims_last = weights[weight_sz - 1]->dims();
attr.m = i_dims_last[0]; attr.m = i_dims_last[0];
attr.n = w_dims_last[1]; attr.n = w_dims_last[1];
attr.k = w_dims_last[0]; attr.k = w_dims_last[0];
......
...@@ -91,8 +91,8 @@ class FusionSeqPoolConcatKernel : public framework::OpKernel<T> { ...@@ -91,8 +91,8 @@ class FusionSeqPoolConcatKernel : public framework::OpKernel<T> {
auto* out = ctx.Output<LoDTensor>("Out"); auto* out = ctx.Output<LoDTensor>("Out");
std::string pooltype = ctx.Attr<std::string>("pooltype"); std::string pooltype = ctx.Attr<std::string>("pooltype");
auto x0_lod = ins[0]->lod(); auto x0_lod = ins[0]->lod();
auto x0_dims = ins[0]->dims(); const auto& x0_dims = ins[0]->dims();
auto y_dims = out->dims(); const auto& y_dims = out->dims();
size_t bs = x0_lod[0].size() - 1; size_t bs = x0_lod[0].size() - 1;
out->Resize({static_cast<int64_t>(bs), y_dims[1]}); out->Resize({static_cast<int64_t>(bs), y_dims[1]});
framework::LoD y_lod(1); framework::LoD y_lod(1);
...@@ -122,7 +122,7 @@ class FusionSeqPoolConcatKernel : public framework::OpKernel<T> { ...@@ -122,7 +122,7 @@ class FusionSeqPoolConcatKernel : public framework::OpKernel<T> {
size_t n = ins.size(); size_t n = ins.size();
size_t dst_step_size = n * w; size_t dst_step_size = n * w;
for (size_t i = 0; i < n; ++i) { for (size_t i = 0; i < n; ++i) {
auto x_dims = ins[i]->dims(); const auto& x_dims = ins[i]->dims();
auto x_lod = ins[i]->lod()[0]; auto x_lod = ins[i]->lod()[0];
const T* src = ins[i]->data<T>(); const T* src = ins[i]->data<T>();
T* dst = y_data + i * w; T* dst = y_data + i * w;
......
...@@ -92,8 +92,8 @@ class FusionSeqPoolCVMConcatKernel : public framework::OpKernel<T> { ...@@ -92,8 +92,8 @@ class FusionSeqPoolCVMConcatKernel : public framework::OpKernel<T> {
auto* out = ctx.Output<LoDTensor>("Out"); auto* out = ctx.Output<LoDTensor>("Out");
std::string pooltype = ctx.Attr<std::string>("pooltype"); std::string pooltype = ctx.Attr<std::string>("pooltype");
auto x0_lod = ins[0]->lod(); auto x0_lod = ins[0]->lod();
auto x0_dims = ins[0]->dims(); const auto& x0_dims = ins[0]->dims();
auto y_dims = out->dims(); const auto& y_dims = out->dims();
size_t bs = x0_lod[0].size() - 1; size_t bs = x0_lod[0].size() - 1;
out->Resize({static_cast<int64_t>(bs), y_dims[1]}); out->Resize({static_cast<int64_t>(bs), y_dims[1]});
framework::LoD y_lod(1); framework::LoD y_lod(1);
...@@ -121,7 +121,7 @@ class FusionSeqPoolCVMConcatKernel : public framework::OpKernel<T> { ...@@ -121,7 +121,7 @@ class FusionSeqPoolCVMConcatKernel : public framework::OpKernel<T> {
size_t n = ins.size(); size_t n = ins.size();
size_t dst_step_size = n * w; size_t dst_step_size = n * w;
for (size_t i = 0; i < n; ++i) { for (size_t i = 0; i < n; ++i) {
auto x_dims = ins[i]->dims(); const auto& x_dims = ins[i]->dims();
auto x_lod = ins[i]->lod()[0]; auto x_lod = ins[i]->lod()[0];
const T* src = ins[i]->data<T>(); const T* src = ins[i]->data<T>();
T* dst = y_data + i * w; T* dst = y_data + i * w;
......
...@@ -52,7 +52,7 @@ class SampleWithProb { ...@@ -52,7 +52,7 @@ class SampleWithProb {
const std::size_t num_samples, const Tensor* L, Tensor* S, const std::size_t num_samples, const Tensor* L, Tensor* S,
Tensor* P) { Tensor* P) {
// UNDERSTAND: dimension issues // UNDERSTAND: dimension issues
const auto lbl_dim = L->dims(); const auto& lbl_dim = L->dims();
const int batch_size = lbl_dim[0]; const int batch_size = lbl_dim[0];
const int num_true = lbl_dim[1]; const int num_true = lbl_dim[1];
const int num_sampled_classes = num_true + num_samples; const int num_sampled_classes = num_true + num_samples;
......
...@@ -98,8 +98,8 @@ struct SelectedRowsAddTensor<platform::CPUDeviceContext, T> { ...@@ -98,8 +98,8 @@ struct SelectedRowsAddTensor<platform::CPUDeviceContext, T> {
const phi::SelectedRows& input1, const phi::SelectedRows& input1,
const framework::Tensor& input2, framework::Tensor* output) { const framework::Tensor& input2, framework::Tensor* output) {
auto in1_height = input1.height(); auto in1_height = input1.height();
auto in2_dims = input2.dims(); const auto& in2_dims = input2.dims();
auto out_dims = output->dims(); const auto& out_dims = output->dims();
PADDLE_ENFORCE_EQ( PADDLE_ENFORCE_EQ(
in1_height, in2_dims[0], in1_height, in2_dims[0],
platform::errors::InvalidArgument("The two inputs height must be equal." platform::errors::InvalidArgument("The two inputs height must be equal."
...@@ -249,7 +249,7 @@ struct SelectedRowsAddToTensor<platform::CPUDeviceContext, T> { ...@@ -249,7 +249,7 @@ struct SelectedRowsAddToTensor<platform::CPUDeviceContext, T> {
return; return;
} }
auto in1_height = input1.height(); auto in1_height = input1.height();
auto in2_dims = input2->dims(); const auto& in2_dims = input2->dims();
PADDLE_ENFORCE_EQ( PADDLE_ENFORCE_EQ(
in1_height, in2_dims[0], in1_height, in2_dims[0],
platform::errors::InvalidArgument("The two inputs height must be equal." platform::errors::InvalidArgument("The two inputs height must be equal."
...@@ -289,7 +289,7 @@ struct SelectedRowsAddToTensor<phi::CPUContext, T> { ...@@ -289,7 +289,7 @@ struct SelectedRowsAddToTensor<phi::CPUContext, T> {
return; return;
} }
auto in1_height = input1.height(); auto in1_height = input1.height();
auto in2_dims = input2->dims(); const auto& in2_dims = input2->dims();
PADDLE_ENFORCE_EQ( PADDLE_ENFORCE_EQ(
in1_height, in2_dims[0], in1_height, in2_dims[0],
platform::errors::InvalidArgument("The two inputs height must be equal." platform::errors::InvalidArgument("The two inputs height must be equal."
...@@ -838,7 +838,7 @@ struct UpdateToTensor<platform::CPUDeviceContext, T> { ...@@ -838,7 +838,7 @@ struct UpdateToTensor<platform::CPUDeviceContext, T> {
const ScatterOps& op, const phi::SelectedRows& input1, const ScatterOps& op, const phi::SelectedRows& input1,
framework::Tensor* input2) { framework::Tensor* input2) {
auto in1_height = input1.height(); auto in1_height = input1.height();
auto in2_dims = input2->dims(); const auto& in2_dims = input2->dims();
PADDLE_ENFORCE_EQ( PADDLE_ENFORCE_EQ(
in1_height, in2_dims[0], in1_height, in2_dims[0],
platform::errors::InvalidArgument("The two inputs height must be equal." platform::errors::InvalidArgument("The two inputs height must be equal."
......
...@@ -231,7 +231,7 @@ class SoftmaxFunctor<DeviceContext, T, is_test, enable_if_CPU<DeviceContext>> { ...@@ -231,7 +231,7 @@ class SoftmaxFunctor<DeviceContext, T, is_test, enable_if_CPU<DeviceContext>> {
public: public:
void operator()(const DeviceContext& context, const int axis_dim, void operator()(const DeviceContext& context, const int axis_dim,
const framework::Tensor* X, framework::Tensor* Y) { const framework::Tensor* X, framework::Tensor* Y) {
auto in_dims = X->dims(); const auto& in_dims = X->dims();
constexpr int kBatchDim = 0; constexpr int kBatchDim = 0;
constexpr int kClassDim = 1; constexpr int kClassDim = 1;
......
...@@ -53,7 +53,7 @@ std::vector<TreeNode> Tree2ColUtil::construct_patch( ...@@ -53,7 +53,7 @@ std::vector<TreeNode> Tree2ColUtil::construct_patch(
void Tree2ColUtil::construct_tree(const framework::Tensor &EdgeSet, void Tree2ColUtil::construct_tree(const framework::Tensor &EdgeSet,
std::vector<std::vector<int>> *tr, std::vector<std::vector<int>> *tr,
size_t *node_count) { size_t *node_count) {
auto edge_set_dims = EdgeSet.dims(); const auto &edge_set_dims = EdgeSet.dims();
PADDLE_ENFORCE_EQ(edge_set_dims[1], 2, PADDLE_ENFORCE_EQ(edge_set_dims[1], 2,
platform::errors::InvalidArgument( platform::errors::InvalidArgument(
"The second dimension of the EdgeSet shall be 2, but " "The second dimension of the EdgeSet shall be 2, but "
...@@ -89,7 +89,7 @@ class Tree2ColFunctor<platform::CPUDeviceContext, T> { ...@@ -89,7 +89,7 @@ class Tree2ColFunctor<platform::CPUDeviceContext, T> {
const framework::Tensor &node_features, const framework::Tensor &node_features,
framework::Tensor *patch, int max_depth) { framework::Tensor *patch, int max_depth) {
std::vector<std::vector<int>> tr; std::vector<std::vector<int>> tr;
auto feature_dims = node_features.dims(); const auto &feature_dims = node_features.dims();
auto cpu_place = context.GetPlace(); auto cpu_place = context.GetPlace();
phi::funcs::SetConstant<platform::CPUDeviceContext, T> constant; phi::funcs::SetConstant<platform::CPUDeviceContext, T> constant;
int64_t feature_size = feature_dims[1]; int64_t feature_size = feature_dims[1];
...@@ -142,7 +142,7 @@ class Col2TreeFunctor<platform::CPUDeviceContext, T> { ...@@ -142,7 +142,7 @@ class Col2TreeFunctor<platform::CPUDeviceContext, T> {
const framework::Tensor &out_grad, framework::Tensor *in_grad, const framework::Tensor &out_grad, framework::Tensor *in_grad,
int max_depth) { int max_depth) {
std::vector<std::vector<int>> tr; std::vector<std::vector<int>> tr;
auto output_dims = out_grad.dims(); const auto &output_dims = out_grad.dims();
auto cpu_place = context.GetPlace(); auto cpu_place = context.GetPlace();
phi::funcs::SetConstant<platform::CPUDeviceContext, T> constant; phi::funcs::SetConstant<platform::CPUDeviceContext, T> constant;
int64_t output_size = output_dims[1]; int64_t output_size = output_dims[1];
......
...@@ -37,7 +37,7 @@ class XPUROIAlignOpKernel : public framework::OpKernel<T> { ...@@ -37,7 +37,7 @@ class XPUROIAlignOpKernel : public framework::OpKernel<T> {
auto sampling_ratio = ctx.Attr<int>("sampling_ratio"); auto sampling_ratio = ctx.Attr<int>("sampling_ratio");
auto aligned = ctx.Attr<bool>("aligned"); auto aligned = ctx.Attr<bool>("aligned");
auto in_dims = in->dims(); const auto& in_dims = in->dims();
int batch_size = in_dims[0]; int batch_size = in_dims[0];
int channels = in_dims[1]; int channels = in_dims[1];
int height = in_dims[2]; int height = in_dims[2];
......
...@@ -31,7 +31,7 @@ void MvGradKernel(const Context& dev_ctx, ...@@ -31,7 +31,7 @@ void MvGradKernel(const Context& dev_ctx,
auto dx = x_grad; auto dx = x_grad;
auto dvec = vec_grad; auto dvec = vec_grad;
auto dim_x = x.dims(); const auto& dim_x = x.dims();
int m = dim_x[0]; int m = dim_x[0];
int n = dim_x[1]; int n = dim_x[1];
......
...@@ -32,7 +32,7 @@ void PsroiPoolGradKernel(const Context& ctx, ...@@ -32,7 +32,7 @@ void PsroiPoolGradKernel(const Context& ctx,
float spatial_scale, float spatial_scale,
DenseTensor* dx) { DenseTensor* dx) {
if (dx) { if (dx) {
auto in_dims = x.dims(); const auto& in_dims = x.dims();
int input_channels = in_dims[1]; int input_channels = in_dims[1];
int height = in_dims[2]; int height = in_dims[2];
int width = in_dims[3]; int width = in_dims[3];
......
...@@ -330,7 +330,7 @@ void RnnFunc(const Context& dev_ctx, ...@@ -330,7 +330,7 @@ void RnnFunc(const Context& dev_ctx,
} }
} }
DenseTensor* input_holder; DenseTensor* input_holder = nullptr;
DenseTensor* output_holder = output; DenseTensor* output_holder = output;
bool has_allocate_mem = false; bool has_allocate_mem = false;
......
...@@ -26,7 +26,7 @@ void TrilIndicesKernel(const Context& dev_ctx, ...@@ -26,7 +26,7 @@ void TrilIndicesKernel(const Context& dev_ctx,
DataType dtype, DataType dtype,
DenseTensor* out) { DenseTensor* out) {
T* out_data = dev_ctx.template Alloc<T>(out); T* out_data = dev_ctx.template Alloc<T>(out);
auto out_dims = out->dims(); const auto& out_dims = out->dims();
int64_t tril_size = out_dims[1]; int64_t tril_size = out_dims[1];
int64_t i = 0; int64_t i = 0;
T r = std::max<int64_t>(0, -offset), c = 0; T r = std::max<int64_t>(0, -offset), c = 0;
......
...@@ -1284,9 +1284,9 @@ void Blas<DeviceContext>::MatMul(const phi::DenseTensor &mat_a, ...@@ -1284,9 +1284,9 @@ void Blas<DeviceContext>::MatMul(const phi::DenseTensor &mat_a,
T alpha, T alpha,
phi::DenseTensor *mat_out, phi::DenseTensor *mat_out,
T beta) const { T beta) const {
auto dim_a = mat_a.dims(); const auto &dim_a = mat_a.dims();
auto dim_b = mat_b.dims(); const auto &dim_b = mat_b.dims();
auto dim_out = mat_out->dims(); const auto &dim_out = mat_out->dims();
PADDLE_ENFORCE_EQ( PADDLE_ENFORCE_EQ(
dim_a.size() == 2 && dim_b.size() == 2 && dim_out.size() == 2, dim_a.size() == 2 && dim_b.size() == 2 && dim_out.size() == 2,
true, true,
......
...@@ -32,8 +32,8 @@ void ChannelShuffleGradKernel(const Context& dev_ctx, ...@@ -32,8 +32,8 @@ void ChannelShuffleGradKernel(const Context& dev_ctx,
auto* dx = x_grad; auto* dx = x_grad;
dev_ctx.template Alloc<T>(dx); dev_ctx.template Alloc<T>(dx);
bool channel_last = (data_format == "NHWC"); bool channel_last = (data_format == "NHWC");
auto do_dims = dout->dims(); const auto& do_dims = dout->dims();
auto dx_dims = dx->dims(); const auto& dx_dims = dx->dims();
DenseTensor t(*dout); DenseTensor t(*dout);
if (!channel_last) { if (!channel_last) {
......
...@@ -31,8 +31,8 @@ void ChannelShuffleKernel(const Context& dev_ctx, ...@@ -31,8 +31,8 @@ void ChannelShuffleKernel(const Context& dev_ctx,
auto* in = &x; auto* in = &x;
dev_ctx.template Alloc<T>(out); dev_ctx.template Alloc<T>(out);
bool channel_last = (data_format == "NHWC"); bool channel_last = (data_format == "NHWC");
auto in_dims = in->dims(); const auto& in_dims = in->dims();
auto o_dims = out->dims(); const auto& o_dims = out->dims();
DenseTensor t(*in); DenseTensor t(*in);
if (!channel_last) { if (!channel_last) {
......
...@@ -23,7 +23,7 @@ void MvKernel(const Context& dev_ctx, ...@@ -23,7 +23,7 @@ void MvKernel(const Context& dev_ctx,
const DenseTensor& x, const DenseTensor& x,
const DenseTensor& vec, const DenseTensor& vec,
DenseTensor* out) { DenseTensor* out) {
auto dim_x = x.dims(); const auto& dim_x = x.dims();
// get data ptr // get data ptr
const T* x_data = x.data<T>(); const T* x_data = x.data<T>();
......
...@@ -32,8 +32,8 @@ void PixelShuffleGradKernel(const Context& ctx, ...@@ -32,8 +32,8 @@ void PixelShuffleGradKernel(const Context& ctx,
ctx.template Alloc<T>(dx); ctx.template Alloc<T>(dx);
int factor = upscale_factor; int factor = upscale_factor;
bool channel_last = (data_format == "NHWC"); bool channel_last = (data_format == "NHWC");
auto do_dims = dout->dims(); const auto& do_dims = dout->dims();
auto dx_dims = dx->dims(); const auto& dx_dims = dx->dims();
DenseTensor t(*dout); DenseTensor t(*dout);
if (!channel_last) { if (!channel_last) {
......
...@@ -31,8 +31,8 @@ void PixelShuffleKernel(const Context& ctx, ...@@ -31,8 +31,8 @@ void PixelShuffleKernel(const Context& ctx,
ctx.template Alloc<T>(out); ctx.template Alloc<T>(out);
int factor = upscale_factor; int factor = upscale_factor;
bool channel_last = (data_format == "NHWC"); bool channel_last = (data_format == "NHWC");
auto in_dims = in->dims(); const auto& in_dims = in->dims();
auto o_dims = out->dims(); const auto& o_dims = out->dims();
DenseTensor t(*in); DenseTensor t(*in);
if (!channel_last) { if (!channel_last) {
......
...@@ -33,8 +33,8 @@ void PixelUnshuffleGradKernel(const Context& dev_ctx, ...@@ -33,8 +33,8 @@ void PixelUnshuffleGradKernel(const Context& dev_ctx,
dev_ctx.template Alloc<T>(dx); dev_ctx.template Alloc<T>(dx);
int factor = downscale_factor; int factor = downscale_factor;
bool channel_last = (data_format == "NHWC"); bool channel_last = (data_format == "NHWC");
auto do_dims = dout->dims(); const auto& do_dims = dout->dims();
auto dx_dims = dx->dims(); const auto& dx_dims = dx->dims();
DenseTensor t(*dout); DenseTensor t(*dout);
if (!channel_last) { if (!channel_last) {
......
...@@ -32,8 +32,8 @@ void PixelUnshuffleKernel(const Context& dev_ctx, ...@@ -32,8 +32,8 @@ void PixelUnshuffleKernel(const Context& dev_ctx,
dev_ctx.template Alloc<T>(out); dev_ctx.template Alloc<T>(out);
int factor = downscale_factor; int factor = downscale_factor;
bool channel_last = (data_format == "NHWC"); bool channel_last = (data_format == "NHWC");
auto in_dims = in->dims(); const auto& in_dims = in->dims();
auto o_dims = out->dims(); const auto& o_dims = out->dims();
DenseTensor t(*in); DenseTensor t(*in);
if (!channel_last) { if (!channel_last) {
......
...@@ -35,7 +35,7 @@ void UnfoldGradKernel(const Context& ctx, ...@@ -35,7 +35,7 @@ void UnfoldGradKernel(const Context& ctx,
if (!x_grad) return; if (!x_grad) return;
auto x_dims = x_grad->dims(); const auto& x_dims = x_grad->dims();
const int batch_size = static_cast<int>(x_dims[0]); const int batch_size = static_cast<int>(x_dims[0]);
int out_height = phi::funcs::CalcOutputSize(x_dims[2], int out_height = phi::funcs::CalcOutputSize(x_dims[2],
......
...@@ -36,7 +36,7 @@ void UnfoldKernel(const Context& ctx, ...@@ -36,7 +36,7 @@ void UnfoldKernel(const Context& ctx,
paddle::operators::math:: paddle::operators::math::
Im2ColFunctor<paddle::operators::math::ColFormat::kCFO, Context, T> Im2ColFunctor<paddle::operators::math::ColFormat::kCFO, Context, T>
im2col; im2col;
auto x_dims = x.dims(); const auto& x_dims = x.dims();
int out_height = phi::funcs::CalcOutputSize(x_dims[2], int out_height = phi::funcs::CalcOutputSize(x_dims[2],
kernel_sizes[0], kernel_sizes[0],
......
...@@ -100,7 +100,11 @@ class reference_content { ...@@ -100,7 +100,11 @@ class reference_content {
public: // structors public: // structors
~reference_content() {} ~reference_content() {}
// TODO(zhiqiu): remove it
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
reference_content(RefT r) : content_(r) {} reference_content(RefT r) : content_(r) {}
#pragma GCC diagnostic pop
reference_content(const reference_content& operand) reference_content(const reference_content& operand)
: content_(operand.content_) {} : content_(operand.content_) {}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册