From f56ba9f6b3af2bb1787c157ad34957f2ed0b5038 Mon Sep 17 00:00:00 2001 From: Tim Shen Date: Mon, 6 May 2019 18:12:57 -0700 Subject: [PATCH] [XLA] Clarify the dimension ordering. This comment contradicts the behavior of the class. Both Linearize() and Delinearize() use major-first multi-dimensional semantics. Apart from pure reasoning about the code, the following test cases also exhibit major-first behavior: // Prints 42 IrArray::Index({llvm::ConstantInt::get(builder->getInt64Ty(), 4), llvm::ConstantInt::get(builder->getInt64Ty(), 2)}, {10, 10}, index_type) .Linearize({10, 10}, builder)->dump(); // Prints 4 IrArray::Index({llvm::ConstantInt::get(builder->getInt64Ty(), 1), llvm::ConstantInt::get(builder->getInt64Ty(), 1)}, {2, 3}, index_type) .Linearize({2, 3}, builder)->dump(); // Prints 4, 2 for (llvm::Value* digit : std::vector( IrArray::Index(llvm::ConstantInt::get(builder->getInt64Ty(), 42), {10, 10}, builder) .multidim())) { digit->dump(); } // Prints 1, 1 for (llvm::Value* digit : std::vector( IrArray::Index(llvm::ConstantInt::get(builder->getInt64Ty(), 4), {2, 3}, builder) .multidim())) { digit->dump(); } PiperOrigin-RevId: 246935221 --- tensorflow/compiler/xla/service/llvm_ir/ir_array.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/tensorflow/compiler/xla/service/llvm_ir/ir_array.h b/tensorflow/compiler/xla/service/llvm_ir/ir_array.h index 5b5f7dc400c..b043f95b1de 100644 --- a/tensorflow/compiler/xla/service/llvm_ir/ir_array.h +++ b/tensorflow/compiler/xla/service/llvm_ir/ir_array.h @@ -43,12 +43,9 @@ namespace llvm_ir { // are supported. class IrArray { public: - // A multidimensional index into an IrArray. The index for dimension zero is - // first in the vector. This is the reverse order of the notation used for - // describing the dimensions of an array. That is, for a [4 x 3 x 2] array - // dimension zero has size 2, dimension one has size 3, and dimension two has - // size 4. Thus the index {1, 2, 3} indexes the last element of this [4 x 3 x - // 2] array. + // A multidimensional index into an IrArray. All the runtime indices + // (multidim) and dimensions (Shape::dimensions(), absl::Span) + // are major-first. // // This may also keep a linear index and the layout and dimensions it was // emitted for; if the shape where this `Index` is used matches, the linear