Skip to content

Commit c506769

Browse files
r-barnesfacebook-github-bot
authored andcommitted
irange-ify 8 (pytorch#62422)
Summary: Pull Request resolved: pytorch#62422 Test Plan: Sandcastle Reviewed By: ngimel Differential Revision: D29879655 fbshipit-source-id: 69fdf0196091932f866bfaba707ad7643790fdd8
1 parent bd9f353 commit c506769

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

torch/csrc/jit/passes/batch_mm.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <ATen/core/functional.h>
44
#include <ATen/core/interned_strings.h>
55
#include <c10/util/Exception.h>
6+
#include <c10/util/irange.h>
67
#include <torch/csrc/jit/ir/alias_analysis.h>
78
#include <torch/csrc/jit/ir/constants.h>
89
#include <torch/csrc/jit/passes/dead_code_elimination.h>
@@ -151,7 +152,7 @@ RegisterOperators mm_tree_reduction_reg({Operator(
151152
push(stack, at::mm(lhs, rhs));
152153
} else {
153154
auto acc = at::mm(inputs[0], inputs[side_num_elems]);
154-
for (size_t i = 1; i < side_num_elems; ++i) {
155+
for (const auto i : c10::irange(1, side_num_elems)) {
155156
acc.add_(at::mm(inputs[i], inputs[side_num_elems + i]));
156157
}
157158
push(stack, std::move(acc));
@@ -374,7 +375,7 @@ std::pair<std::vector<Node*>, std::vector<Node*>> gatherIndependentMMUses(
374375
// Filter out dependent MMs. This algorithm might do very badly if e.g. you
375376
// have a lot of independent MMs, that depend on the first one, but I doubt
376377
// this will be a common scenario.
377-
for (size_t i = 0; i < mms.size(); ++i) {
378+
for (const auto i : c10::irange(mms.size())) {
378379
if (mms[i] == nullptr)
379380
continue;
380381
for (size_t j = i + 1; j < mms.size(); ++j) {
@@ -423,7 +424,7 @@ void BatchMMSide(Block* block, AliasDb& alias_db) {
423424
batch_mm->i_(Symbol::attr("side"), static_cast<int>(side));
424425
Value* const_side = mms[0]->inputs().at(side == Side::LHS ? 0 : 1);
425426
batch_mm->addInput(const_side);
426-
for (size_t i = 0; i < mms.size(); ++i) {
427+
for (const auto i : c10::irange(mms.size())) {
427428
batch_mm->addInput(mms[i]->inputs().at(side == Side::LHS ? 1 : 0));
428429
mms[i]->output()->replaceAllUsesWith(batch_mm->outputs().at(i));
429430
}

torch/csrc/jit/passes/canonicalize_graph_fuser_ops.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <c10/util/irange.h>
12
#include <torch/csrc/jit/jit_log.h>
23
#include <torch/csrc/jit/passes/canonicalize_graph_fuser_ops.h>
34
#include <torch/csrc/jit/passes/dead_code_elimination.h>
@@ -28,7 +29,7 @@ static c10::optional<std::vector<ChunkOutput>> getChunkOutputs(Node* chunk) {
2829
return c10::nullopt;
2930
}
3031
auto unpack_outputs = list_use.user->outputs();
31-
for (size_t i = 0; i < unpack_outputs.size(); ++i) {
32+
for (const auto i : c10::irange(unpack_outputs.size())) {
3233
outputs.emplace_back(unpack_outputs[i], i);
3334
}
3435
} else {

0 commit comments

Comments
 (0)