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
This commit is contained in:
Adrian Kuegel 2019-04-01 05:13:27 -07:00 committed by TensorFlower Gardener
parent 9ccf10c72a
commit b06f06148e
2 changed files with 4 additions and 0 deletions

View File

@ -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",

View File

@ -18,6 +18,7 @@ limitations under the License.
#include <numeric>
#include <vector>
#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<llvm::Value*> ForLoopNest::EmitOperandArrayLoopNest(
// 'dimension_to_skip' dimension.
std::vector<int64> 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.