From b06f06148e8adf156702e43e421d78a5bd2ca79b Mon Sep 17 00:00:00 2001 From: Adrian Kuegel Date: Mon, 1 Apr 2019 05:13:27 -0700 Subject: [PATCH] Change loop order to major to minor instead of minor to major. This matches the comment, and it should make the memory access potentially faster. PiperOrigin-RevId: 241304479 --- tensorflow/compiler/xla/service/llvm_ir/BUILD | 1 + tensorflow/compiler/xla/service/llvm_ir/llvm_loop.cc | 3 +++ 2 files changed, 4 insertions(+) diff --git a/tensorflow/compiler/xla/service/llvm_ir/BUILD b/tensorflow/compiler/xla/service/llvm_ir/BUILD index 8b35f1b5ba6..ca85dd7647e 100644 --- a/tensorflow/compiler/xla/service/llvm_ir/BUILD +++ b/tensorflow/compiler/xla/service/llvm_ir/BUILD @@ -113,6 +113,7 @@ cc_library( "//tensorflow/compiler/xla:types", "//tensorflow/compiler/xla:xla_data_proto", "//tensorflow/core:lib", + "@com_google_absl//absl/algorithm:container", "@com_google_absl//absl/strings", "@com_google_absl//absl/types:span", "@llvm//:core", diff --git a/tensorflow/compiler/xla/service/llvm_ir/llvm_loop.cc b/tensorflow/compiler/xla/service/llvm_ir/llvm_loop.cc index e08248b9cc4..2e769b5588a 100644 --- a/tensorflow/compiler/xla/service/llvm_ir/llvm_loop.cc +++ b/tensorflow/compiler/xla/service/llvm_ir/llvm_loop.cc @@ -18,6 +18,7 @@ limitations under the License. #include #include +#include "absl/algorithm/container.h" #include "absl/strings/str_cat.h" #include "llvm/IR/Constants.h" #include "llvm/IR/Function.h" @@ -261,11 +262,13 @@ std::vector ForLoopNest::EmitOperandArrayLoopNest( // 'dimension_to_skip' dimension. std::vector dimensions; const Shape& shape = operand_array.GetShape(); + // Initially get the dimensions in minor to major order, then reverse them. for (int64 dimension : LayoutUtil::MinorToMajor(shape)) { if (dimension != dimension_to_skip) { dimensions.push_back(dimension); } } + absl::c_reverse(dimensions); // Create loop nest with one for-loop for each dimension of the // output.