turn on -Werror=unused-variable in our Bazel CPU build

Summary:
We also fix any existing issues. Note that we only do this for the CPU
build because nvcc is considered a C++ toolchain but it does not have
the same flag support. Adding flags to the GPU build will cause nvcc
errors.

Test Plan: Built locally, rely on CI to confirm.

Reviewers: malfet

Subscribers:

Tasks:

Tags:

Pull Request resolved: https://github.com/pytorch/pytorch/pull/79156

Approved by: https://github.com/seemethere, https://github.com/osalpekar, https://github.com/albanD
This commit is contained in:
Michael Andreas Dagitses
2022-06-10 15:14:27 -07:00
committed by PyTorch MergeBot
parent e727539c29
commit ab2ca95dd1
25 changed files with 49 additions and 129 deletions

View File

@ -52,7 +52,9 @@ build \
--per_file_copt='^//.*\.(cpp|cc)$'@-Werror=type-limits \
--per_file_copt=^//.*\.cu$@--compiler-options=-Werror=type-limits \
--per_file_copt='^//.*\.(cpp|cc)$'@-Werror=unused-function \
--per_file_copt=^//.*\.cu$@--compiler-options=-Werror=unused-function
--per_file_copt=^//.*\.cu$@--compiler-options=-Werror=unused-function \
--per_file_copt='^//.*\.(cpp|cc)$'@-Werror=unused-variable \
--per_file_copt=^//.*\.cu$@--compiler-options=-Werror=unused-variable
build \
--per_file_copt=//:aten/src/ATen/RegisterCompositeExplicitAutograd.cpp@-Wno-error=unused-function \

View File

@ -504,6 +504,8 @@ class DispatchKeySet final {
using iterator_category = std::input_iterator_tag;
using value_type = DispatchKey;
using difference_type = ptrdiff_t;
using reference = value_type&;
using pointer = value_type*;
// final mask value should mask out the entire keyset
static const uint8_t end_iter_mask_val =
num_backends + num_functionality_keys;

View File

@ -1,5 +1,7 @@
#include <gtest/gtest.h>
#include <cstddef>
#include <iterator>
#include <unordered_set>
#include <c10/core/DispatchKeySet.h>
@ -14,7 +16,6 @@ TEST(DispatchKeySet, ShowSemantics) {
// It corresponds to "dense" functionality, "CPU" backend.
// This means that it gets a dense functionality bit, and a cpu backend bit
// set.
auto undefined_set = DispatchKeySet();
auto dense_cpu_set = DispatchKeySet(DispatchKey::CPU);
ASSERT_TRUE(dense_cpu_set.has(DispatchKey::Dense));
ASSERT_TRUE(dense_cpu_set.has_backend(BackendComponent::CPUBit));
@ -48,8 +49,6 @@ TEST(DispatchKeySet, ShowSemantics) {
DispatchKey::Dense,
DispatchKey::CUDA,
DispatchKey::CPU});
auto fpga = DispatchKeySet(DispatchKey::FPGA);
auto fpga_and_cpu = DispatchKeySet({DispatchKey::FPGA, DispatchKey::CPU});
// this keyset has all of the building block keys:
ASSERT_TRUE(autograd_dense_cpu_cuda.has(DispatchKey::AutogradFunctionality));
ASSERT_TRUE(autograd_dense_cpu_cuda.has(DispatchKey::Dense));
@ -86,8 +85,6 @@ TEST(DispatchKeySet, ShowSemantics) {
// Iterators allow you to iterate individually through the DispatchKey's in a
// DispatchKeySet
auto empty_set = DispatchKeySet();
auto t1 = empty_set.begin();
auto t2 = empty_set.end();
ASSERT_EQ(*empty_set.begin(), *empty_set.end());
// However, only keys that correspond to actual runtime indices of kernels in
@ -370,29 +367,12 @@ TEST(DispatchKeySet, IteratorCrossProduct) {
TEST(DispatchKeySet, IteratorFull) {
DispatchKeySet full_set(DispatchKeySet::FULL);
uint8_t i = 0;
for (const auto& it : full_set) {
i++;
}
// Total # of runtime entries includes an entry for DispatchKey::Undefined,
// which is not included when iterating through the DispatchKeySet.
ASSERT_EQ(i, num_runtime_entries - 1);
}
TEST(DispatchKeySet, IteratorRangeFull) {
DispatchKeySet full_set(DispatchKeySet::FULL);
uint8_t i = 0;
for (DispatchKey dispatch_key : full_set) {
i++;
}
std::ptrdiff_t count = std::distance(full_set.begin(), full_set.end());
// Total # of runtime entries includes an entry for DispatchKey::Undefined,
// which is not included when iterating through the DispatchKeySet.
ASSERT_EQ(i, num_runtime_entries - 1);
ASSERT_EQ(count, std::ptrdiff_t{num_runtime_entries} - 1);
}
TEST(DispatchKeySet, FailAtEndIterator) {
DispatchKeySet full_set(DispatchKeySet::FULL);
uint64_t raw_repr = full_set.raw_repr();

View File

@ -219,8 +219,6 @@ TEST(
givenInvalidPtr_whenMoveAssigning_thenNewInstanceIsValid) {
intrusive_ptr<SomeClass> obj1 = make_intrusive<SomeClass>();
intrusive_ptr<SomeClass> obj2;
// NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
SomeClass* obj1ptr = obj1.get();
obj2 = std::move(obj1);
EXPECT_TRUE(obj2.defined());
}
@ -271,8 +269,6 @@ TEST(
givenInvalidPtr_whenMoveAssigningToBaseClass_thenNewInstanceIsValid) {
intrusive_ptr<SomeChildClass> obj1 = make_intrusive<SomeChildClass>(5);
intrusive_ptr<SomeBaseClass> obj2;
// NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
SomeBaseClass* obj1ptr = obj1.get();
obj2 = std::move(obj1);
EXPECT_TRUE(obj2.defined());
}
@ -358,8 +354,6 @@ TEST(
givenInvalidPtr_whenCopyAssigning_thenNewInstanceIsValid) {
intrusive_ptr<SomeClass> obj1 = make_intrusive<SomeClass>();
intrusive_ptr<SomeClass> obj2;
// NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
SomeClass* obj1ptr = obj1.get();
obj2 = obj1;
EXPECT_TRUE(obj2.defined());
}
@ -387,8 +381,6 @@ TEST(
givenInvalidPtr_whenCopyAssigningToBaseClass_thenNewInstanceIsValid) {
intrusive_ptr<SomeChildClass> obj1 = make_intrusive<SomeChildClass>(5);
intrusive_ptr<SomeBaseClass> obj2;
// NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
SomeBaseClass* obj1ptr = obj1.get();
obj2 = obj1;
EXPECT_TRUE(obj2.defined());
}
@ -1779,8 +1771,7 @@ TEST(
givenInvalidPtr_whenMoveAssigning_thenNewInstanceIsValid) {
IntrusiveAndWeak<SomeClass> obj1 = make_weak_intrusive<SomeClass>();
weak_intrusive_ptr<SomeClass> obj2 = make_invalid_weak<SomeClass>();
// NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
SomeClass* obj1ptr = obj1.weak.lock().get();
obj1.weak.lock().get();
obj2 = std::move(obj1.weak);
EXPECT_FALSE(obj2.expired());
}
@ -1826,8 +1817,7 @@ TEST(
givenWeakOnlyPtr_whenMoveAssigning_thenNewInstanceIsValid) {
IntrusiveAndWeak<SomeClass> obj1 = make_weak_intrusive<SomeClass>();
weak_intrusive_ptr<SomeClass> obj2 = make_weak_only<SomeClass>();
// NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
SomeClass* obj1ptr = obj1.weak.lock().get();
obj1.weak.lock().get();
obj2 = std::move(obj1.weak);
EXPECT_FALSE(obj2.expired());
}
@ -1846,8 +1836,7 @@ TEST(
WeakIntrusivePtrTest,
givenWeakOnlyPtr_whenMoveAssigningToSelf_thenStaysInvalid) {
weak_intrusive_ptr<SomeClass> obj1 = make_weak_only<SomeClass>();
// NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
SomeClass* obj1ptr = obj1.lock().get();
obj1.lock().get();
obj1 = std::move(obj1);
// NOLINTNEXTLINE(bugprone-use-after-move)
EXPECT_TRUE(obj1.expired());
@ -1911,8 +1900,7 @@ TEST(
IntrusiveAndWeak<SomeChildClass> obj1 =
make_weak_intrusive<SomeChildClass>(5);
weak_intrusive_ptr<SomeBaseClass> obj2 = make_invalid_weak<SomeBaseClass>();
// NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
SomeBaseClass* obj1ptr = obj1.weak.lock().get();
obj1.weak.lock().get();
obj2 = std::move(obj1.weak);
EXPECT_FALSE(obj2.expired());
}
@ -1945,8 +1933,7 @@ TEST(
IntrusiveAndWeak<SomeChildClass> obj1 =
make_weak_intrusive<SomeChildClass>(5);
weak_intrusive_ptr<SomeBaseClass> obj2 = make_weak_only<SomeBaseClass>(2);
// NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
SomeBaseClass* obj1ptr = obj1.weak.lock().get();
obj1.weak.lock().get();
obj2 = std::move(obj1.weak);
EXPECT_FALSE(obj2.expired());
}
@ -2028,8 +2015,7 @@ TEST(
givenInvalidPtr_whenCopyAssigning_thenNewInstanceIsValid) {
IntrusiveAndWeak<SomeClass> obj1 = make_weak_intrusive<SomeClass>();
weak_intrusive_ptr<SomeClass> obj2 = make_invalid_weak<SomeClass>();
// NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
SomeClass* obj1ptr = obj1.weak.lock().get();
obj1.weak.lock().get();
obj2 = obj1.weak;
EXPECT_FALSE(obj2.expired());
}
@ -2048,8 +2034,7 @@ TEST(
givenWeakOnlyPtr_whenCopyAssigning_thenNewInstanceIsValid) {
IntrusiveAndWeak<SomeClass> obj1 = make_weak_intrusive<SomeClass>();
weak_intrusive_ptr<SomeClass> obj2 = make_weak_only<SomeClass>();
// NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
SomeClass* obj1ptr = obj1.weak.lock().get();
obj1.weak.lock().get();
obj2 = obj1.weak;
EXPECT_FALSE(obj2.expired());
}
@ -2068,8 +2053,7 @@ TEST(
WeakIntrusivePtrTest,
givenWeakOnlyPtr_whenCopyAssigningToSelf_thenStaysInvalid) {
weak_intrusive_ptr<SomeClass> obj1 = make_weak_only<SomeClass>();
// NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
SomeClass* obj1ptr = obj1.lock().get();
obj1.lock().get();
// NOLINTNEXTLINE(clang-diagnostic-self-assign-overloaded)
obj1 = obj1;
EXPECT_TRUE(obj1.expired());
@ -2111,8 +2095,7 @@ TEST(
IntrusiveAndWeak<SomeChildClass> obj1 =
make_weak_intrusive<SomeChildClass>(5);
weak_intrusive_ptr<SomeBaseClass> obj2 = make_invalid_weak<SomeBaseClass>();
// NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
SomeBaseClass* obj1ptr = obj1.weak.lock().get();
obj1.weak.lock().get();
obj2 = obj1.weak;
EXPECT_FALSE(obj2.expired());
}
@ -2145,8 +2128,7 @@ TEST(
IntrusiveAndWeak<SomeChildClass> obj1 =
make_weak_intrusive<SomeChildClass>(5);
weak_intrusive_ptr<SomeBaseClass> obj2 = make_weak_only<SomeBaseClass>(2);
// NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
SomeBaseClass* obj1ptr = obj1.weak.lock().get();
obj1.weak.lock().get();
obj2 = obj1.weak;
EXPECT_FALSE(obj2.expired());
}

View File

@ -1900,8 +1900,6 @@ TEST(DataLoaderTest, ChunkDatasetDoesNotHang) {
datasets::ChunkDatasetOptions(
prefetch_count, batch_size, cache_size));
samplers::SequentialSampler& chunk_sampler = dataset->chunk_sampler();
auto data_loader = torch::data::make_data_loader(
dataset.map(transforms::BatchLambda<DummyChunkDataReader::BatchType, DummyChunkDataReader::DataType>(
[](DummyChunkDataReader::BatchType batch) {
@ -2043,7 +2041,6 @@ TEST(DataLoaderTest, ChunkDatasetLoad) {
const size_t prefetch_count = 1;
const size_t batch_size = 10;
const size_t dataloader_worker_count = 0;
const size_t save_interval = 2;
DummyChunkDataReader data_reader;
samplers::SequentialSampler sampler(0);
@ -2223,8 +2220,6 @@ TEST(DataLoaderTest, ChunkDatasetCrossChunkShuffle) {
std::vector<int> expected_result;
{
// construct expected result
int offset = 0;
for (const auto i : c10::irange((chunk_count + cross_chunk_shuffle_count - 1) /
cross_chunk_shuffle_count)) {
for (const auto j : c10::irange(chunk_size)) {

View File

@ -1940,7 +1940,6 @@ TEST_F(FunctionalTest, InstanceNorm2d) {
TEST_F(FunctionalTest, InstanceNorm2dDefaultOptions) {
int num_features = 5;
double eps = 1e-05;
auto input = torch::arange(2. * num_features * 2 * 2).view({2, num_features, 2, 2});
auto output = F::instance_norm(input);
@ -2031,7 +2030,6 @@ TEST_F(FunctionalTest, InstanceNorm3d) {
TEST_F(FunctionalTest, InstanceNorm3dDefaultOptions) {
int num_features = 5;
double eps = 1e-05;
auto input = torch::arange(2. * num_features * 2 * 2 * 2).view({2, num_features, 2, 2, 2});
auto output = F::instance_norm(input);

View File

@ -613,7 +613,6 @@ TEST_F(NNUtilsTest, PackPaddedSequence) {
}
batch_sizes[i-1] = total;
}
int64_t offset = 0;
std::vector<torch::Tensor> tensors_to_be_cat;
for (int64_t i = 1; i < static_cast<int64_t>(sorted_lengths.size() + 1); i++) {
int64_t l = sorted_lengths.at(i-1);

View File

@ -173,7 +173,7 @@ TEST(OptimTest, OptimizerAccessors) {
const auto& optimizer_ = Adagrad(params, options);
optimizer_.defaults();
// test for param_groups() with const reference return
const auto& params_2 = optimizer_.param_groups();
(void)optimizer_.param_groups();
// test for state() with const reference return
optimizer_.state();
}

View File

@ -119,7 +119,6 @@ class BackendWithCompiler : public PyTorchBackendInterface {
IValue val = token;
auto instruction = val.toTupleRef().elements()[0].toStringRef();
auto debug_handle = val.toTupleRef().elements()[1].toInt();
double const_val = 1.0;
#ifndef NO_PROFILING
auto start_time_us = torch::profiler::impl::getTime() / 1000;
#endif
@ -132,8 +131,6 @@ class BackendWithCompiler : public PyTorchBackendInterface {
instruction);
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
auto sub = instruction.substr(15);
// NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
const_val = stod(sub);
} else if (instruction == "aten::add" || instruction == "aten::sub") {
TORCH_CHECK(x.sizes() == h.sizes());
if (x.dim() > 1 || (x.dim() == 1 && x.size(0) > 1)) {

View File

@ -122,11 +122,12 @@ TEST_F(FuserTest, TestOne_CUDA) {
// with different internal strides. To do this, we generate a tensor
// with the "wrong" dimensions, and then use transpose to get an
// appropriately sized view.
for (const auto i : c10::irange(graph.inputs().size())) {
std::vector<int64_t> dims = {128, 128, 32};
std::swap(dims[ti], dims[tj]);
inputs.push_back(at::rand(dims, at::kCUDA).transpose(ti, tj));
}
std::generate_n(
std::back_inserter(inputs), graph.inputs().size(), [ti, tj] {
std::array<int64_t, 3> dims = {128, 128, 32};
std::swap(dims[ti], dims[tj]);
return at::rand(dims, at::kCUDA).transpose(ti, tj);
});
auto t22 = inputs[4].sigmoid();
auto t20 = inputs[3].sigmoid();

View File

@ -301,7 +301,6 @@ graph(%a : Float(4, 5),
TEST(IRParserTest, MalformedStrides) {
auto graph = std::make_shared<Graph>();
std::unordered_map<std::string, Value*> vmap;
bool error_thrown = false;
// NOLINTNEXTLINE(cppcoreguidelines-avoid-goto,hicpp-avoid-goto)
EXPECT_ANY_THROW(parseIR(
R"IR(

View File

@ -1182,7 +1182,6 @@ TEST(RunTimeTest, ParseOperator) {
std::vector<IValue> constants{
to_tuple({1}),
};
int64_t model_version = caffe2::serialize::kProducedBytecodeVersion;
// 2. Parse the function
std::string function_name("test_function");
auto function = std::unique_ptr<mobile::Function>(
@ -1566,7 +1565,6 @@ TEST(RunTimeTest, RuntimeCall) {
std::vector<IValue> constantsCall{
1,
};
int64_t model_version = caffe2::serialize::kProducedBytecodeVersion;
auto foo = std::make_unique<mobile::Function>(c10::QualifiedName("foo"));
c10::ivalue::TupleElements debug_handles_m_tuple;

View File

@ -1049,8 +1049,7 @@ TEST(RecordFunctionTest, Callbacks) {
GraphOptimizerEnabledGuard opt_guard(false);
auto h1 = add_remove_test_add_cb<1>();
// NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
auto h2 = add_remove_test_add_cb<2>();
add_remove_test_add_cb<2>();
auto h3 = add_remove_test_add_cb<3>();
{ RECORD_USER_SCOPE("test"); }
@ -1144,7 +1143,6 @@ TEST(RecordFunctionTest, Callbacks) {
} // END: global test
{ // START: thread local test
auto ctx_th = std::thread([]() {
const int test_val = 234;
const std::string test_str = "test thread str";
addThreadLocalCallback(RecordFunctionCallback(
[](const RecordFunction&
@ -1417,22 +1415,6 @@ TEST(TestSymInt, AddSymbolicInt) {
}
TEST(FallbackGraphsTest, Basic) {
static const auto nestGraphIntoFallbackGraph =
[](const std::shared_ptr<Graph>& graph) {
ProfilingRecord::removeProfileCounter(graph->block());
auto fallback =
replaceBlockWithFallbackGraph(graph->block(), graph->inputs());
for (size_t i = 0; i < graph->outputs().size(); i++) {
graph->outputs()[i]->replaceAllUsesWith(fallback->output(i));
fallback->output(i)->copyMetadata(graph->outputs()[i]);
}
for (auto it = graph->block()->nodes().rbegin();
it != fallback->iterator();
it++) {
it.destroyCurrent();
}
};
auto x = at::randn({1}, at::kCPU);
auto y = at::randn({1}, at::kCPU);
auto stack = createStack({x.clone(), y.clone()});
@ -2656,11 +2638,13 @@ TEST(RecordDebugHandles, Basic) {
RECORD_EDGE_SCOPE_WITH_DEBUG_HANDLE_AND_INPUTS("my_function", 42, {});
float x{5.9999}, y{2.1212};
float z = x / y;
(void)z;
}
{
RECORD_USER_SCOPE_WITH_INPUTS("not_my_function", {});
float x{5.9999}, y{2.1212};
float z = x / y;
(void)z;
}
auto profiler_results_ptr = torch::autograd::profiler::disableProfiler();
const auto& kineto_events = profiler_results_ptr->events();

View File

@ -69,8 +69,6 @@ TEST_F(Kernel, InliningIntermediates) {
const auto graph_string = format(graph_template, env);
auto graph = std::make_shared<Graph>();
parseIR(graph_string, &*graph);
// NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
auto device = use_cuda ? kCUDA : kCPU;
TensorExprKernel k(graph);
auto stmt = k.getCodeGenStmt();
std::ostringstream oss;
@ -80,8 +78,6 @@ TEST_F(Kernel, InliningIntermediates) {
// aten_sub should be removed by the CUDA backend by metavar rewriting
// and by the CPU backend by horizontal fusion.
// NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores,cppcoreguidelines-avoid-magic-numbers)
size_t num_out1_uses = use_cuda ? 0 : 5;
torch::jit::testing::FileCheck().check_not("aten_sub")->run(oss.str());
}
}

View File

@ -50,8 +50,6 @@ TEST(Reductions, ReduceSum0D_1) {
}
TEST(Reductions, ReduceSum0D_2) {
const int M = 10;
BufHandle b("b", {}, kFloat);
std::vector<float> in(1);
in[0] = 77.7;

View File

@ -68,15 +68,14 @@ TEST(Type, BitCasting) {
ASSERT_EQ(y.dtype(), kShort);
}
constexpr int16_t ref16 = 1337;
constexpr int32_t ref32 = 1337;
constexpr int64_t ref64 = 1337;
at::Half reff16 = 1337.0f;
constexpr float reff32 = 1337.0f;
constexpr double reff64 = 1337.0f;
using SimpleIRExprEval = ExprEval<SimpleIREvaluator>;
// this is broken
/*{
constexpr int16_t ref16 = 1337;
at::Half k_;
at::Half* k = &k_;
*reinterpret_cast<int16_t*>(k) = ref16;

View File

@ -82,8 +82,8 @@ static PyObject * THPStorage_copy_(PyObject *self, PyObject *args, PyObject *kwa
static PyObject * THPStorage_isPinned(PyObject *_self, PyObject *noargs)
{
HANDLE_TH_ERRORS
auto self = (THPStorage*)_self;
#if defined(USE_CUDA)
auto self = (THPStorage*)_self;
return PyBool_FromLong(at::globalContext().isPinnedPtr(self->cdata->data<uint8_t>()));
#else
Py_RETURN_FALSE;
@ -94,7 +94,6 @@ static PyObject * THPStorage_isPinned(PyObject *_self, PyObject *noargs)
static PyObject * THPStorage_elementSize(PyObject *_self, PyObject *noargs)
{
HANDLE_TH_ERRORS
auto self = (THPStorage*)_self;
return THPUtils_packInt64(sizeof(uint8_t));
END_HANDLE_TH_ERRORS
}
@ -364,7 +363,6 @@ PyObject * THPStorage_newWithFile(PyObject *_unused, PyObject *args)
HANDLE_TH_ERRORS
TORCH_CHECK(PyTuple_Size(args) == 2,
"_new_with_file takes exactly two arguments");
PyObject *fd_obj = PyTuple_GetItem(args, 0);
int fd = PyObject_AsFileDescriptor(PyTuple_GetItem(args, 0));
THPUtils_assert(fd != -1, "_new_with_file couldn't retrieve a file "
"descriptor from given object");

View File

@ -221,7 +221,6 @@ void autogradNotImplementedInplaceOrViewFallbackImpl(const c10::OperatorHandle&
const auto num_arguments = arguments.size();
const auto num_returns = returns.size();
const auto stack_start = stack->size() - num_arguments;
bool any_is_inplace = false;
at::Tensor aliased_input;
@ -254,8 +253,6 @@ void autogradNotImplementedInplaceOrViewFallbackImpl(const c10::OperatorHandle&
const c10::IValue& aliased_input_iv = (*stack)[stack_start + i]; // get a reference to an ivalue on the stack
TORCH_CHECK(aliased_input_iv.isTensor());
aliased_input = aliased_input_iv.toTensor(); // TODO: Can we avoid saving this tensor and incurring the refcount bump?
} else {
any_is_inplace = true;
}
}
}

View File

@ -553,7 +553,6 @@ Node* FunctionExtractor::CreateFunctionNode(
const std::string& domain_name,
const std::string& func_name) {
const auto& func_scope = func_ctx.scope_key_;
const auto& func_scope_ctx = func_ctx.scope_ctxs_[func_scope];
GRAPH_DEBUG(
"Create and insert local function for scope: ",
func_scope->namesFromRoot());
@ -671,8 +670,7 @@ void FunctionExtractor::ConvertScopeToFunction(
const auto func_name =
construct_unique_module_name(module_class_name.substr(pos + 1));
auto func_def_n =
CreateFunctionDefNode(func_ctx, graph, domain_name, func_name);
CreateFunctionDefNode(func_ctx, graph, domain_name, func_name);
// create and insert local function node to graph.
for (const auto& it : func_ctx.scope_ctxs_) {

View File

@ -97,8 +97,7 @@ c10::optional<at::ScalarType> ONNXTypeToATenType(int32_t onnx_type) {
Node* addNodeToBlock(Block* block, Symbol kind, ArrayRef<Value*> inputs) {
auto new_node = block->appendNode(block->owningGraph()->create(kind));
for (auto input : inputs) {
// NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
auto new_input = new_node->addInput(input);
new_node->addInput(input);
}
return new_node;
}

View File

@ -15,6 +15,7 @@
#include <onnx/shape_inference/implementation.h>
#include <algorithm>
#include <cmath>
#include <iterator>
#include <limits>
#include <unordered_set>
#include <utility>
@ -684,9 +685,8 @@ std::vector<::c10::ShapeSymbol> Broadcast(
size_t rank_min = std::min(rank_0, rank_1);
std::vector<::c10::ShapeSymbol> final_shape;
final_shape.reserve(rank_max);
for (auto idx : c10::irange(rank_max)) {
final_shape.emplace_back(::c10::ShapeSymbol::newSymbol());
}
std::generate_n(
std::back_inserter(final_shape), rank_max, ::c10::ShapeSymbol::newSymbol);
for (auto idx : c10::irange(rank_min)) {
const c10::ShapeSymbol& ss_shape_0 = input_shape_value_0[rank_0 - 1 - idx];
const c10::ShapeSymbol& ss_shape_1 = input_shape_value_1[rank_1 - 1 - idx];
@ -1366,9 +1366,10 @@ void ComputeConstant(Node* n, int opset_version) {
expand_shape.value().size());
if (expand_shape.value()[0] > 0) {
std::vector<c10::ShapeSymbol> final_shape;
for (const auto i : c10::irange(expand_shape.value()[0])) {
final_shape.emplace_back(c10::ShapeSymbol::newSymbol());
}
std::generate_n(
std::back_inserter(final_shape),
expand_shape.value()[0],
::c10::ShapeSymbol::newSymbol);
UpdateShape(n->output(), c10::SymbolicShape(final_shape));
}
}
@ -1607,7 +1608,6 @@ void SpecialPostProcess(Node* n) {
// onnx Sequence type requires element type to be set.
// If the list to insert is empty, we set the elem type by
// looking at the tensor being inserted.
auto list_node = n->input(0)->node();
auto seq_node = n->input(0)->node();
auto t_type = n->input(1)->type()->cast<TensorType>();

View File

@ -608,7 +608,7 @@ void initPythonIRBindings(PyObject* module_) {
"schema",
[](Node& n) {
std::stringstream ss;
if (auto sch = n.maybeSchema()) {
if (n.maybeSchema()) {
ss << n.schema();
} else {
ss << "(no schema)";

View File

@ -1191,8 +1191,10 @@ std::shared_ptr<SugaredValue> toSugaredValue(
obj = py::getattr(obj, "op");
}
#ifdef USE_RPC
bool isRpcAvailable = py::cast<bool>(
py::module::import("torch.distributed.rpc").attr("is_available")());
#endif
if (auto callee = as_function(obj)) {
return std::make_shared<FunctionValue>(callee->function_);

View File

@ -1,4 +1,3 @@
#include <c10/util/irange.h>
#include <torch/csrc/python_headers.h>
#include <torch/csrc/THP.h>
#include <torch/csrc/utils/python_strings.h>
@ -10,6 +9,7 @@
#include <algorithm>
#include <cstdarg>
#include <iterator>
#include <sstream>
#include <string>
#include <unordered_map>
@ -129,9 +129,9 @@ void THPUtils_invalidArguments(PyObject *given_args, PyObject *given_kwargs,
std::vector<std::string> option_strings;
va_list option_list;
va_start(option_list, num_options);
// NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
for(const auto i : c10::irange(num_options))
option_strings.emplace_back(va_arg(option_list, const char*));
std::generate_n(std::back_inserter(option_strings), num_options, [&option_list] {
return va_arg(option_list, const char*);
});
va_end(option_list);
PyErr_SetString(PyExc_TypeError, torch::format_invalid_args(

View File

@ -55,12 +55,8 @@ void unregister_fd(int fd) {
}
void print_init_message(const char* message) {
// NOLINTNEXTLINE(cppcoreguidelines-init-variables)
size_t unused;
// NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
unused = write(1, message, strlen(message));
// NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
unused = write(1, "\n", 1);
write(1, message, strlen(message));
write(1, "\n", 1);
}
bool object_exists(const char* name) {