-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Justinchu/clang tidy test #12655
Justinchu/clang tidy test #12655
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
There were too many comments to post at once. Showing the first 25 out of 102. Check the log or trigger a new build to see more.
@@ -1130,7 +1130,7 @@ | |||
|
|||
// Adapter to convert the legacy OrtCUDAProviderOptions to the latest OrtCUDAProviderOptionsV2 | |||
OrtCUDAProviderOptionsV2 OrtCUDAProviderOptionsToOrtCUDAProviderOptionsV2(const OrtCUDAProviderOptions* legacy_cuda_options) { | |||
OrtCUDAProviderOptionsV2 cuda_options_converted; | |||
OrtCUDAProviderOptionsV2 cuda_options_converted{}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: variable 'cuda_options_converted' is not initialized [cppcoreguidelines-init-variables]
OrtCUDAProviderOptionsV2 cuda_options_converted{}; | |
OrtCUDAProviderOptionsV2 cuda_options_converted = 0{}; |
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
#include "orttraining/lazy_tensor/accelerator.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: 'orttraining/lazy_tensor/accelerator.h' file not found [clang-diagnostic-error]
#include "orttraining/lazy_tensor/accelerator.h"
^
namespace onnxruntime { | ||
|
||
namespace python { | ||
Environment& GetTrainingORTEnv(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: use a trailing return type for this function [modernize-use-trailing-return-type]
Environment& GetTrainingORTEnv();
^
// Be aware of GIL issue. | ||
// The returned value is the path to exported | ||
// ONNX file. | ||
static std::string ExportToOnnx( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: use a trailing return type for this function [modernize-use-trailing-return-type]
static std::string ExportToOnnx( | |
static auto ExportToOnnx( |
orttraining/orttraining/lazy_tensor/accelerator.cc:238:
- const at::ArrayRef<c10::IValue>& args) {
+ const at::ArrayRef<c10::IValue>& args) -> std::string {
// ONNX exporter modifies the graph in-place, so we | ||
// need to clone it to avoid interaction between | ||
// Pytorch's JIT mechanism and ONNX graph. | ||
std::shared_ptr<torch::jit::Graph> new_subgraph(graph->copyUnique().release()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: variable 'new_subgraph' is not initialized [cppcoreguidelines-init-variables]
std::shared_ptr<torch::jit::Graph> new_subgraph(graph->copyUnique().release()); | |
std::shared_ptr<torch::jit::Graph> new_subgraph = 0(graph->copyUnique().release()); |
onnxruntime::MLDataType element_type = CreateOrtScalarType(tensor.scalar_type()); | ||
onnxruntime::TensorShape shape(tensor.sizes().vec()); | ||
OrtDevice device = CreateOrtDevice(tensor.device()); | ||
OrtMemoryInfo memory_info = OrtMemoryInfo("LTC", OrtAllocatorType::OrtDeviceAllocator, device, device.Id()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: variable 'memory_info' is not initialized [cppcoreguidelines-init-variables]
OrtMemoryInfo memory_info = OrtMemoryInfo("LTC", OrtAllocatorType::OrtDeviceAllocator, device, device.Id()); | |
OrtMemoryInfo memory_info = 0 = OrtMemoryInfo("LTC", OrtAllocatorType::OrtDeviceAllocator, device, device.Id()); |
OrtDevice device = CreateOrtDevice(tensor.device()); | ||
OrtMemoryInfo memory_info = OrtMemoryInfo("LTC", OrtAllocatorType::OrtDeviceAllocator, device, device.Id()); | ||
// This tensor's life time is controlled by Pytorch. | ||
// TODO: consider to let ORT also own that tensor. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: missing username/bug in TODO [google-readability-todo]
// TODO: consider to let ORT also own that tensor. | |
// TODO(unknown): consider to let ORT also own that tensor. |
element_type, shape, | ||
tensor.data_ptr(), memory_info); | ||
|
||
OrtValue ort_value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: variable 'ort_value' is not initialized [cppcoreguidelines-init-variables]
OrtValue ort_value; | |
OrtValue ort_value = 0; |
return ort_value; | ||
} | ||
|
||
c10::IValue CreateC10IvalueTensor(OrtValue value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: use a trailing return type for this function [modernize-use-trailing-return-type]
c10::IValue CreateC10IvalueTensor(OrtValue value) {
^
} | ||
|
||
c10::IValue CreateC10IvalueTensor(OrtValue value) { | ||
onnxruntime::Tensor* tensor = value.GetMutable<onnxruntime::Tensor>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: variable 'tensor' is not initialized [cppcoreguidelines-init-variables]
onnxruntime::Tensor* tensor = value.GetMutable<onnxruntime::Tensor>(); | |
onnxruntime::Tensor* tensor = nullptr = value.GetMutable<onnxruntime::Tensor>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Our Linux VMs are Ubuntu 20.04 based, and they have clang 14.0 installed. Once this work is done, we can add it to CI to enforce the rules.
@@ -88,6 +88,13 @@ jobs: | |||
level: warning | |||
flags: --linelength=120 --exclude=java/src/main/native/*.c | |||
filter: "-runtime/references" | |||
- name: Run clang-tidy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest not using 3rd-party actions when possible, for the possibility of leaking tokens.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call. Although IIRC the token is periodically rotated? We are using a few 3rd party checks so that would be an all or non situation. Would it make sense for us to verify the token access to make sure "posting to the PR thread" (and other necessary access) are the only things allowed?
@snnn With this test PR I am seeing a few checks that are particularly noisy / may not make sense ( I am still learning c++ so I don't have good judgement on the suggestions generated. Do you have a recommended rules list we can modify based on the currect .clang-tidy file? |
No, I don't. I will look into it this weekend. |
@edgchen1 do you have any suggestions on .clang-tidy rules? |
I don't have much at the moment - would need to familiarize myself with them more. From a quick look at the list, "google" ones seem good since we follow their style guide. Some of the "bugprone", "cppcoreguidlines", "modernize", "performance", and "readability" ones look useful too, though perhaps we should pick and choose from them. For example, I think we can do without modernize-use-trailing-return-type, it's just stylistic. Looking at the warnings in this PR, it appears that maybe clang-tidy isn't configured correctly. For example, a lot of the warnings from cppcoreguidelines-init-variables are actually referring to initialized variables. It also complains about being unable to find include files. Is the compile_commands.json file getting generated and passed to clang-tidy (-p option)? |
No since I wasn't sure what the best way is to generate it. Is there a command I can run to create it? |
That's a good question. We do have various build options, which ones should we test with? @snnn |
…led. Convert KernelDefBuilder functions to use string_view.
…type_constraints' into justinchu/clang-tidy-test
…g' into justinchu/clang-tidy-test
e1d55da
to
9759107
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
@@ -3,17 +3,18 @@ | |||
|
|||
#pragma once | |||
|
|||
#include <limits.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: inclusion of deprecated C++ header 'limits.h'; consider using 'climits' instead [modernize-deprecated-headers]
#include <limits.h> | |
#include <climits> |
// type constraints with types supported in this build | ||
const std::unordered_map<std::string, std::vector<MLDataType>>& EnabledTypeConstraints() const { | ||
return enabled_type_constraints_; | ||
const std::unordered_map<std::string, std::vector<MLDataType>>& TypeConstraints() const { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: function 'TypeConstraints' should be marked [[nodiscard]] [modernize-use-nodiscard]
const std::unordered_map<std::string, std::vector<MLDataType>>& TypeConstraints() const { | |
[[nodiscard]] const std::unordered_map<std::string, std::vector<MLDataType>>& TypeConstraints() const { |
@@ -73,7 +67,7 @@ | |||
return alias_map_; | |||
} | |||
|
|||
const optional<std::pair<int, int>>& VariadicAlias() const { | |||
const std::optional<std::pair<int, int>>& VariadicAlias() const { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: function 'VariadicAlias' should be marked [[nodiscard]] [modernize-use-nodiscard]
const std::optional<std::pair<int, int>>& VariadicAlias() const { | |
[[nodiscard]] const std::optional<std::pair<int, int>>& VariadicAlias() const { |
KernelDefBuilder& KernelDefBuilder::SetDomain(const char* domain) { | ||
kernel_def_->op_domain_ = std::string(domain); | ||
KernelDefBuilder& KernelDefBuilder::TypeConstraint(std::string_view arg_name, | ||
std::vector<MLDataType> types) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: parameter 'types' is unused [misc-unused-parameters]
std::vector<MLDataType> types) { | |
std::vector<MLDataType> /*types*/) { |
KernelDefBuilder& KernelDefBuilder::TypeConstraint(const char* arg_name, | ||
MLDataType default_type) { | ||
return TypeConstraint(std::string(arg_name), default_type); | ||
KernelDefBuilder& KernelDefBuilder::TypeConstraint(std::string_view arg_name, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: method 'TypeConstraint' can be made static [readability-convert-member-functions-to-static]
include/onnxruntime/core/framework/kernel_def_builder.h:216:
- KernelDefBuilder& TypeConstraint(std::string_view arg_name, MLDataType type);
+ static KernelDefBuilder& TypeConstraint(std::string_view arg_name, MLDataType type);
return TypeConstraint(std::string(arg_name), default_type); | ||
KernelDefBuilder& KernelDefBuilder::TypeConstraint(std::string_view arg_name, | ||
MLDataType type) { | ||
std::vector<MLDataType> types{type}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: variable 'types' is not initialized [cppcoreguidelines-init-variables]
std::vector<MLDataType> types{type}; | |
std::vector<MLDataType> types = 0{type}; |
auto kernel = reinterpret_cast<onnxruntime::OpKernel*>(op); | ||
onnxruntime::standalone::NodeRepo::GetInstance().RemoveNode(kernel); | ||
delete kernel; | ||
std::unique_ptr<onnxruntime::OpKernel> op_ptr{reinterpret_cast<onnxruntime::OpKernel*>(op)}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: variable 'op_ptr' is not initialized [cppcoreguidelines-init-variables]
std::unique_ptr<onnxruntime::OpKernel> op_ptr{reinterpret_cast<onnxruntime::OpKernel*>(op)}; | |
std::unique_ptr<onnxruntime::OpKernel> op_ptr = 0{reinterpret_cast<onnxruntime::OpKernel*>(op)}; |
@@ -531,8 +531,7 @@ | |||
|
|||
ORT_API(void, OrtApis::ReleaseKernelInfo, _Frees_ptr_opt_ OrtKernelInfo* info_copy) { | |||
if (info_copy) { | |||
auto kernel_info = reinterpret_cast<onnxruntime::OpKernelInfo*>(info_copy); | |||
delete kernel_info; | |||
std::unique_ptr<onnxruntime::OpKernelInfo> info_copy_ptr{reinterpret_cast<onnxruntime::OpKernelInfo*>(info_copy)}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: variable 'info_copy_ptr' is not initialized [cppcoreguidelines-init-variables]
std::unique_ptr<onnxruntime::OpKernelInfo> info_copy_ptr{reinterpret_cast<onnxruntime::OpKernelInfo*>(info_copy)}; | |
std::unique_ptr<onnxruntime::OpKernelInfo> info_copy_ptr = 0{reinterpret_cast<onnxruntime::OpKernelInfo*>(info_copy)}; |
FYI, these warnings seem incorrect: |
@edgchen1 that's a little more noise than what I hope it would produce! Should I turn off
for now? I am not sure why |
I think those are reasonable checks and it's ok to leave them on. there are some errors from clang-tidy:
https://github.com/microsoft/onnxruntime/actions/runs/3116529857/jobs/5054446243 which may be why we get these spurious warnings.
after the call to build.py: onnxruntime/.github/workflows/lint.yml Lines 86 to 92 in a2fa01b
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
@@ -77,7 +77,18 @@ ORT_API(void, OrtApis::ReleaseKernelInfo, _Frees_ptr_opt_ OrtKernelInfo*) { | |||
namespace onnxruntime { | |||
namespace standalone { | |||
|
|||
using NodePtr = std::unique_ptr<onnxruntime::Node>; | |||
void ReleaseNode(onnxruntime::Node* node) { | |||
if (node) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: implicit conversion 'onnxruntime::Node *' -> bool [readability-implicit-bool-conversion]
if (node) { | |
if (node != nullptr) { |
using NodePtr = std::unique_ptr<onnxruntime::Node>; | ||
void ReleaseNode(onnxruntime::Node* node) { | ||
if (node) { | ||
for (auto* input_arg : node->InputDefs()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: 'auto *input_arg' can be declared as 'const auto *input_arg' [readability-qualified-auto]
for (auto* input_arg : node->InputDefs()) { | |
for (const auto* input_arg : node->InputDefs()) { |
for (auto* input_arg : node->InputDefs()) { | ||
std::unique_ptr<const onnxruntime::NodeArg>{input_arg}; | ||
} | ||
for (auto* output_arg : node->OutputDefs()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: 'auto *output_arg' can be declared as 'const auto *output_arg' [readability-qualified-auto]
for (auto* output_arg : node->OutputDefs()) { | |
for (const auto* output_arg : node->OutputDefs()) { |
@edgchen1 looking good now (to me) |
Do not merge.
Test clang-tidy CI