Skip to content

Commit 0a1178a

Browse files
authored
Fix lint C++ actions (microsoft#21303)
### Description <!-- Describe your changes. --> microsoft@83e0c6b is the last commit having Lint C++ actions pass. ![image](https://github.com/microsoft/onnxruntime/assets/10530022/96bf005e-5815-46d0-ac17-c6094200957c) microsoft@4a7eaff is the first commit let it fail. ![image](https://github.com/microsoft/onnxruntime/assets/10530022/72a9271e-7b4b-40f8-83a5-f28b82c5e726) Reviewdog/action-cpplint@master changed since that day. https://github.com/reviewdog/action-cpplint/pull/42/files make action-cpplint starts using reviewdog release https://github.com/reviewdog/reviewdog/releases/tag/v0.19.0. Optional Lint also failed with many typos, should be also related to the same reason. Let's fix that in different prs. ### Motivation and Context <!-- - Why is this change required? What problem does it solve? - If it fixes an open issue, please link to the issue here. -->
1 parent fe6ef40 commit 0a1178a

23 files changed

+1029
-1052
lines changed

.github/workflows/lint.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ jobs:
9898
--exclude=onnxruntime/core/mlas/inc/*
9999
--exclude=onnxruntime/core/mlas/lib/*
100100
--exclude=onnxruntime/contrib_ops/cuda/bert/flash_attention/*
101+
--exclude=build/Debug/*
102+
--exclude=cmake/*
103+
--exclude=csharp/test/*
104+
--exclude=onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/GeneratedShaders/*
105+
--exclude=orttraining/orttraining/test/*
106+
--exclude=onnxruntime/test/*
107+
--exclude=winml/*
101108
filter: "-runtime/references"
102109

103110
lint-js:

include/onnxruntime/core/providers/cuda/cuda_context.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@
1212

1313
#define ORT_CUDA_CTX
1414

15-
#include "cuda_resource.h"
16-
#include "core/providers/custom_op_context.h"
1715
#include <cuda.h>
1816
#include <cuda_runtime.h>
1917
#ifndef USE_CUDA_MINIMAL
2018
#include <cublas_v2.h>
2119
#include <cudnn.h>
2220
#endif
21+
22+
#include "core/providers/cuda/cuda_resource.h"
23+
#include "core/providers/custom_op_context.h"
24+
2325
namespace Ort {
2426

2527
namespace Custom {

onnxruntime/core/graph/graph.cc

Lines changed: 51 additions & 30 deletions
Large diffs are not rendered by default.

onnxruntime/core/graph/graph_utils.cc

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
// Licensed under the MIT License.
33

44
#include "core/graph/graph_utils.h"
5-
6-
#include <queue>
7-
85
#include "core/graph/graph.h"
96
#include "core/common/logging/logging.h"
107

8+
#include <algorithm>
9+
#include <queue>
10+
#include <string>
11+
#include <vector>
12+
1113
namespace onnxruntime {
1214

1315
namespace graph_utils {
@@ -56,7 +58,8 @@ static bool CanUpdateImplicitInputNameInSubgraph(const Node& node,
5658
}
5759

5860
for (auto& subgraph_node : subgraph->Nodes()) {
59-
// recurse if this node also consumes removed_output_name as an implicit input (i.e. there are multiple levels of nested
61+
// recurse if this node also consumes removed_output_name as an implicit input (i.e. there are multiple levels
62+
// of nested
6063
// subgraphs, and at least one level lower uses removed_output_name as an implicit input
6164
const auto subgraph_node_implicit_inputs = subgraph_node.ImplicitInputDefs();
6265
if (!subgraph_node_implicit_inputs.empty()) {
@@ -464,13 +467,13 @@ static bool IsOnlyOneOutputUsed(const Graph& graph, const Node& node, const std:
464467
// a) there's only 1, and b) it's the same as any output consumed by another node
465468
auto output_indexes = graph.GetNodeOutputsInGraphOutputs(node);
466469
auto num_graph_outputs = output_indexes.size();
467-
if (num_graph_outputs > 1)
470+
if (num_graph_outputs > 1) {
468471
return false;
469-
else if (num_graph_outputs == 1) {
470-
if (first_output != unassigned)
472+
} else if (num_graph_outputs == 1) {
473+
if (first_output != unassigned) {
471474
// an output is consumed by other nodes, so make sure the same output is providing the graph output
472475
return output_indexes.front() == first_output;
473-
else {
476+
} else {
474477
// graph output only as no other nodes are consuming the output, so just update the output_name
475478
output_name = &node.OutputDefs()[output_indexes.front()]->Name();
476479
}
@@ -678,7 +681,8 @@ const Node* FirstParentByType(const Node& node, const std::string& parent_type)
678681
return nullptr;
679682
}
680683

681-
void ReplaceDownstreamNodeInput(Graph& graph, Node& node, int output_idx, Node& replacement, int replacement_output_idx) {
684+
void ReplaceDownstreamNodeInput(Graph& graph, Node& node, int output_idx, Node& replacement,
685+
int replacement_output_idx) {
682686
// get the output edges from node for output_idx
683687
std::vector<GraphEdge> output_edges = GraphEdge::GetNodeOutputEdges(node, output_idx);
684688

@@ -726,7 +730,9 @@ void AddNodeInput(Node& target, int target_input_idx, NodeArg& new_input) {
726730
"Can only add a new input at the end of the current ones.");
727731

728732
target.MutableInputDefs().push_back(&new_input);
729-
assert(target.MutableInputArgsCount().size() > static_cast<size_t>(target_input_idx)); // expect existing entry for all possible inputs
733+
734+
// expect existing entry for all possible inputs
735+
assert(target.MutableInputArgsCount().size() > static_cast<size_t>(target_input_idx));
730736
target.MutableInputArgsCount()[target_input_idx] = 1;
731737
}
732738

@@ -798,7 +804,8 @@ bool FindPath(const Node& node, bool is_input_edge, gsl::span<const EdgeEndToMat
798804
// For output edge, there could be multiple edges matched.
799805
// This function will return failure in such case by design.
800806
if (nullptr != edge_found) {
801-
LOGS(logger, WARNING) << "Failed since multiple edges matched:" << current_node->OpType() << "->" << edge.op_type;
807+
LOGS(logger, WARNING) << "Failed since multiple edges matched:" << current_node->OpType() << "->"
808+
<< edge.op_type;
802809
return false;
803810
}
804811
edge_found = &(*it);
@@ -821,7 +828,8 @@ bool FindPath(const Node& node, bool is_input_edge, gsl::span<const EdgeEndToMat
821828
return true;
822829
}
823830

824-
bool FindPath(Graph& graph, const Node& node, bool is_input_edge, gsl::span<const EdgeEndToMatch> edges_to_match, std::vector<std::reference_wrapper<Node>>& result, const logging::Logger& logger) {
831+
bool FindPath(Graph& graph, const Node& node, bool is_input_edge, gsl::span<const EdgeEndToMatch> edges_to_match,
832+
std::vector<std::reference_wrapper<Node>>& result, const logging::Logger& logger) {
825833
result.clear();
826834

827835
std::vector<const Node::EdgeEnd*> edge_ends;
@@ -830,9 +838,10 @@ bool FindPath(Graph& graph, const Node& node, bool is_input_edge, gsl::span<cons
830838
}
831839

832840
result.reserve(edges_to_match.size());
833-
std::transform(edge_ends.begin(), edge_ends.end(), std::back_inserter(result), [&graph](const Node::EdgeEnd* edge_end) -> Node& {
834-
return *graph.GetNode(edge_end->GetNode().Index());
835-
});
841+
std::transform(edge_ends.begin(), edge_ends.end(), std::back_inserter(result),
842+
[&graph](const Node::EdgeEnd* edge_end) -> Node& {
843+
return *graph.GetNode(edge_end->GetNode().Index());
844+
});
836845

837846
return true;
838847
}

onnxruntime/core/graph/graph_utils.h

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
#include "core/graph/onnx_protobuf.h"
99
#include "core/graph/graph.h"
1010

11+
#include <string>
12+
#include <vector>
13+
1114
namespace onnxruntime {
1215
namespace graph_utils {
1316

@@ -247,7 +250,8 @@ e.g. Node A produces outputs A1 and A2.
247250
to replace B1 (output index 0 for node B) with A2 (output index 1 for node A) as input to the downstream node C.
248251
The edge that existed between B and C for B1 will be removed, and replaced with an edge between A and C for A2.
249252
*/
250-
void ReplaceDownstreamNodeInput(Graph& graph, Node& node, int output_idx, Node& replacement, int replacement_output_idx);
253+
void ReplaceDownstreamNodeInput(Graph& graph, Node& node, int output_idx, Node& replacement,
254+
int replacement_output_idx);
251255

252256
/** Replace the input to a node with a NodeArg.
253257
@remarks The replacement only updates the node's input definition and does not create any edges,
@@ -302,11 +306,13 @@ inline void FinalizeNodeFusion(Graph& graph,
302306
The output definitions and edges from the last node in 'nodes' will be moved to replacement_node.
303307
All nodes in 'nodes' will be removed.
304308
*/
305-
inline void FinalizeNodeFusion(Graph& graph, gsl::span<const std::reference_wrapper<Node>> nodes, Node& replacement_node) {
309+
inline void FinalizeNodeFusion(Graph& graph, gsl::span<const std::reference_wrapper<Node>> nodes,
310+
Node& replacement_node) {
306311
FinalizeNodeFusion(graph, nodes, replacement_node, replacement_node);
307312
}
308313

309-
inline void FinalizeNodeFusion(Graph& graph, std::initializer_list<std::reference_wrapper<Node>> nodes, Node& replacement_node) {
314+
inline void FinalizeNodeFusion(Graph& graph, std::initializer_list<std::reference_wrapper<Node>> nodes,
315+
Node& replacement_node) {
310316
FinalizeNodeFusion(graph, AsSpan(nodes), replacement_node, replacement_node);
311317
}
312318

@@ -357,17 +363,23 @@ struct EdgeEndToMatch {
357363
It is recommended to match path from bottom to top direction to avoid such issue.
358364
It is because each node input (dst_arg_index) only accepts one input edge.
359365
*/
360-
bool FindPath(const Node& node, bool is_input_edge, gsl::span<const EdgeEndToMatch> edges_to_match, std::vector<const Node::EdgeEnd*>& result, const logging::Logger& logger);
366+
bool FindPath(const Node& node, bool is_input_edge, gsl::span<const EdgeEndToMatch> edges_to_match,
367+
std::vector<const Node::EdgeEnd*>& result, const logging::Logger& logger);
361368

362-
inline bool FindPath(const Node& node, bool is_input_edge, std::initializer_list<EdgeEndToMatch> edges_to_match, std::vector<const Node::EdgeEnd*>& result, const logging::Logger& logger) {
369+
inline bool FindPath(const Node& node, bool is_input_edge, std::initializer_list<EdgeEndToMatch> edges_to_match,
370+
std::vector<const Node::EdgeEnd*>& result, const logging::Logger& logger) {
363371
return FindPath(node, is_input_edge, AsSpan(edges_to_match), result, logger);
364372
}
365373

366374
/** Same as FindPath above, but return the references of matched Node
367375
*/
368-
bool FindPath(Graph& graph, const Node& node, bool is_input_edge, gsl::span<const EdgeEndToMatch> edges_to_match, std::vector<std::reference_wrapper<Node>>& result, const logging::Logger& logger);
376+
bool FindPath(Graph& graph, const Node& node, bool is_input_edge, gsl::span<const EdgeEndToMatch> edges_to_match,
377+
std::vector<std::reference_wrapper<Node>>& result, const logging::Logger& logger);
369378

370-
inline bool FindPath(Graph& graph, const Node& node, bool is_input_edge, std::initializer_list<EdgeEndToMatch> edges_to_match, std::vector<std::reference_wrapper<Node>>& result, const logging::Logger& logger) {
379+
inline bool FindPath(Graph& graph, const Node& node, bool is_input_edge,
380+
std::initializer_list<EdgeEndToMatch> edges_to_match,
381+
std::vector<std::reference_wrapper<Node>>& result,
382+
const logging::Logger& logger) {
371383
return FindPath(graph, node, is_input_edge, AsSpan(edges_to_match), result, logger);
372384
}
373385

onnxruntime/core/graph/graph_viewer.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ const std::vector<NodeIndex>& GraphViewer::GetNodesInTopologicalOrder(ExecutionO
332332
}
333333

334334
const std::vector<NodeIndex>& GraphViewer::GetRootNodes() const {
335-
// TODO: See if we need to calculate the root_nodes_ of the filtered graph.
335+
// TODO(somebody): See if we need to calculate the root_nodes_ of the filtered graph.
336336
// GetRootNodes is only used by parallel executor currently, and isn't relevant to the usage of a filtered graph.
337337
ORT_ENFORCE(filter_info_ == nullptr, "Not supported with filtered graph.");
338338

onnxruntime/core/graph/model.cc

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,13 @@ Model::Model(const std::string& graph_name,
140140
auto func_template_ptr = std::make_unique<FunctionTemplate>();
141141
func_template_ptr->op_schema_ = std::move(func_schema_ptr);
142142
func_template_ptr->onnx_func_proto_ = &func;
143-
model_local_function_templates_maps_.insert_or_assign(function_utils::GetFunctionIdentifier(func.domain(), func.name()),
143+
model_local_function_templates_maps_.insert_or_assign(function_utils::GetFunctionIdentifier(func.domain(),
144+
func.name()),
144145
std::move(func_template_ptr));
145146
}
146147

147148
// need to call private ctor so can't use make_shared
148-
GSL_SUPPRESS(r.11)
149+
GSL_SUPPRESS(r .11)
149150
graph_.reset(new Graph(*this, model_proto_.mutable_graph(), *p_domain_to_version, IrVersion(), schema_registry,
150151
logger, options.strict_shape_type_inference));
151152
}
@@ -269,11 +270,13 @@ Model::Model(ModelProto&& model_proto, const PathString& model_path,
269270
auto func_template_ptr = std::make_unique<FunctionTemplate>();
270271
func_template_ptr->op_schema_ = std::move(func_schema_ptr);
271272
func_template_ptr->onnx_func_proto_ = &func;
272-
model_local_function_templates_maps_.insert_or_assign(function_utils::GetFunctionIdentifier(func.domain(), func.name()), std::move(func_template_ptr));
273+
model_local_function_templates_maps_.insert_or_assign(function_utils::GetFunctionIdentifier(func.domain(),
274+
func.name()),
275+
std::move(func_template_ptr));
273276
}
274277

275278
// create instance. need to call private ctor so can't use make_unique
276-
GSL_SUPPRESS(r.11)
279+
GSL_SUPPRESS(r .11)
277280
graph_.reset(new Graph(*this, model_proto_.mutable_graph(), domain_to_version, IrVersion(), schema_registry,
278281
logger, options.strict_shape_type_inference));
279282
}
@@ -425,7 +428,7 @@ Status Model::Load(const ModelProto& model_proto,
425428
}
426429

427430
// need to call private ctor so can't use make_shared
428-
GSL_SUPPRESS(r.11)
431+
GSL_SUPPRESS(r .11)
429432

430433
auto status = Status::OK();
431434
ORT_TRY {
@@ -465,7 +468,7 @@ Status Model::Load(ModelProto&& model_proto,
465468
}
466469

467470
// need to call private ctor so can't use make_shared
468-
GSL_SUPPRESS(r.11)
471+
GSL_SUPPRESS(r .11)
469472
auto status = Status::OK();
470473
ORT_TRY {
471474
model = std::make_unique<Model>(std::move(model_proto), model_path, local_registries, logger, options);
@@ -512,7 +515,7 @@ static Status LoadModelHelper(const T& file_path, Loader loader) {
512515
}
513516

514517
if (!status.IsOK()) {
515-
GSL_SUPPRESS(es.84)
518+
GSL_SUPPRESS(es .84)
516519
ORT_IGNORE_RETURN_VALUE(Env::Default().FileClose(fd));
517520
return status;
518521
}
@@ -554,7 +557,8 @@ static Status SaveModel(Model& model, const T& file_path) {
554557
const file_path = UTF8ToString($2);
555558
const bytes = new Uint8Array(buffer_size);
556559
bytes.set(HEAPU8.subarray(buffer, buffer + buffer_size));
557-
if (typeof process == 'object' && typeof process.versions == 'object' && typeof process.versions.node == 'string') {
560+
if (typeof process == 'object' && typeof process.versions == 'object' &&
561+
typeof process.versions.node == 'string') {
558562
// Node.js
559563
require('fs').writeFileSync(file_path, bytes);
560564
} else {
@@ -585,7 +589,7 @@ static Status SaveModel(Model& model, const T& file_path) {
585589
});
586590
}
587591
if (!status.IsOK()) {
588-
GSL_SUPPRESS(es.84)
592+
GSL_SUPPRESS(es .84)
589593
ORT_IGNORE_RETURN_VALUE(Env::Default().FileClose(fd));
590594
return status;
591595
}
@@ -616,7 +620,7 @@ static Status SaveModelWithExternalInitializers(Model& model,
616620
});
617621
}
618622
if (!status.IsOK()) {
619-
GSL_SUPPRESS(es.84)
623+
GSL_SUPPRESS(es .84)
620624
ORT_IGNORE_RETURN_VALUE(Env::Default().FileClose(fd));
621625
return status;
622626
}
@@ -628,8 +632,8 @@ Status Model::Load(const PathString& file_path,
628632
return LoadModel(file_path, model_proto);
629633
}
630634

631-
GSL_SUPPRESS(r.30) // spurious warnings. p_model is potentially reset in the internal call to Load
632-
GSL_SUPPRESS(r.35)
635+
GSL_SUPPRESS(r .30) // spurious warnings. p_model is potentially reset in the internal call to Load
636+
GSL_SUPPRESS(r .35)
633637
Status Model::Load(const PathString& file_path, std::shared_ptr<Model>& p_model,
634638
const IOnnxRuntimeOpSchemaRegistryList* local_registries,
635639
const logging::Logger& logger, const ModelOptions& options) {
@@ -762,7 +766,8 @@ Status Model::SaveWithExternalInitializers(Model& model,
762766

763767
ORT_RETURN_IF_ERROR(model.MainGraph().Resolve());
764768

765-
auto model_proto = model.ToGraphProtoWithExternalInitializers(external_file_name, file_path, initializer_size_threshold);
769+
auto model_proto = model.ToGraphProtoWithExternalInitializers(external_file_name, file_path,
770+
initializer_size_threshold);
766771
google::protobuf::io::FileOutputStream output(fd);
767772
const bool result = model_proto.SerializeToZeroCopyStream(&output) && output.Flush();
768773
if (result) {

onnxruntime/core/graph/op.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33

44
#pragma once
55

6-
#include <functional>
7-
#include <unordered_map>
86
#include "core/graph/onnx_protobuf.h"
97
#include "core/common/status.h"
108
#include "core/graph/constants.h"
119

10+
#include <functional>
11+
#include <unordered_map>
12+
1213
namespace onnxruntime {
1314
using AttrType = ONNX_NAMESPACE::AttributeProto_AttributeType;
1415
using NodeAttributes = std::unordered_map<std::string, ONNX_NAMESPACE::AttributeProto>;
@@ -29,19 +30,18 @@ AttributeProto_AttributeType_GRAPHS = 10,
2930
AttributeProto_AttributeType_SPARSE_TENSOR = 22,
3031
AttributeProto_AttributeType_SPARSE_TENSORS = 23,
3132
*/
32-
static constexpr const char* kAttrTypeStrings[] =
33-
{
34-
"UNDEFINED",
35-
"FLOAT",
36-
"INT",
37-
"STRING",
38-
"TENSOR",
39-
"GRAPH",
40-
"FLOATS",
41-
"INTS",
42-
"STRINGS",
43-
"TENSORS",
44-
"GRAPHS"};
33+
static constexpr const char* kAttrTypeStrings[] = {
34+
"UNDEFINED",
35+
"FLOAT",
36+
"INT",
37+
"STRING",
38+
"TENSOR",
39+
"GRAPH",
40+
"FLOATS",
41+
"INTS",
42+
"STRINGS",
43+
"TENSORS",
44+
"GRAPHS"};
4545

4646
class TypeUtils {
4747
public:

onnxruntime/core/graph/runtime_optimization_record_container.cc

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44
#if !defined(ORT_MINIMAL_BUILD) || defined(ORT_EXTENDED_MINIMAL_BUILD)
55

66
#include "core/graph/runtime_optimization_record_container.h"
7-
8-
#include <algorithm>
9-
10-
#include <gsl/gsl>
11-
127
#include "core/flatbuffers/flatbuffers_utils.h"
138
#include "core/flatbuffers/schema/ort.fbs.h"
149
#include "core/graph/op_identifier_utils.h"
1510

11+
#include <algorithm>
12+
#include <gsl/gsl>
13+
1614
namespace onnxruntime {
1715

1816
#if !defined(ORT_MINIMAL_BUILD)
@@ -182,7 +180,8 @@ Status RuntimeOptimizationRecordContainer::LoadFromOrtFormat(
182180
}
183181

184182
ORT_RETURN_IF_NOT(optimizer_name_to_records.emplace(optimizer_name, std::move(records)).second,
185-
"Attempting to load runtime optimization records for a previously loaded optimizer: ", optimizer_name);
183+
"Attempting to load runtime optimization records for a previously loaded optimizer: ",
184+
optimizer_name);
186185
}
187186

188187
optimizer_name_to_records_ = std::move(optimizer_name_to_records);

0 commit comments

Comments
 (0)