GetMemRefType failed on 0-D tensors. Loosened check to allow tensors with shape

{}.

--

PiperOrigin-RevId: 245104548
This commit is contained in:
Rob Suderman 2019-04-24 13:25:49 -07:00 committed by Mehdi Amini
parent ce12875333
commit 69cdceae73
4 changed files with 7 additions and 15 deletions

View File

@ -678,8 +678,8 @@ of tensor type.
Note: hexadecimal integer literals are not allowed in tensor type declarations Note: hexadecimal integer literals are not allowed in tensor type declarations
to avoid confusion between `0xf32` and `0 x f32`. Zero sizes are allowed in to avoid confusion between `0xf32` and `0 x f32`. Zero sizes are allowed in
tensors and treated as other sizes, e.g., `tensor<0 x 1 x i32>` and `tensor<1 x tensors and treated as other sizes, e.g., `tensor<0 x 1 x i32>` and `tensor<1 x
0 x i32>` are different types. Since zero sizes are not allowed in other types, 0 x i32>` are different types. Since zero sizes are not allowed in some other
such tensors should be optimized away before lowering tensors to memrefs. types, such tensors should be optimized away before lowering tensors to vectors.
Examples: Examples:
@ -722,7 +722,9 @@ A `memref` type is a reference to a region of memory (similar to a buffer
pointer, but more powerful). The buffer pointed to by a memref can be allocated, pointer, but more powerful). The buffer pointed to by a memref can be allocated,
aliased and deallocated. A memref can be used to read and write data from/to the aliased and deallocated. A memref can be used to read and write data from/to the
memory region which it references. Memref types use the same shape specifier as memory region which it references. Memref types use the same shape specifier as
tensor types, but do not allow unknown rank nor zero sizes. tensor types, but do not allow unknown rank. Note that `memref<f32>`, `memref<0
x f32>`, `memref<1 x 0 x f32>`, and `memref<0 x 1 x f32>` are all different
types.
The memory space of a memref is specified by a target-specific integer index. If The memory space of a memref is specified by a target-specific integer index. If
no memory space is specified, then the default memory space (0) is used. The no memory space is specified, then the default memory space (0) is used. The

View File

@ -353,7 +353,7 @@ public:
}; };
/// MemRef types represent a region of memory that have a shape with a fixed /// MemRef types represent a region of memory that have a shape with a fixed
/// number of dimensions. Each shape element can be a positive integer or /// number of dimensions. Each shape element can be a non-negative integer or
/// unknown (represented by any negative integer). MemRef types also have an /// unknown (represented by any negative integer). MemRef types also have an
/// affine map composition, represented as an array AffineMap pointers. /// affine map composition, represented as an array AffineMap pointers.
class MemRefType class MemRefType

View File

@ -314,7 +314,7 @@ MemRefType MemRefType::getImpl(ArrayRef<int64_t> shape, Type elementType,
for (int64_t s : shape) { for (int64_t s : shape) {
// Negative sizes are not allowed except for `-1` that means dynamic size. // Negative sizes are not allowed except for `-1` that means dynamic size.
if (s <= 0 && s != -1) { if (s < -1) {
if (location) if (location)
context->emitError(*location, "invalid memref size"); context->emitError(*location, "invalid memref size");
return {}; return {};

View File

@ -871,16 +871,6 @@ func @zero_in_vector_type() -> vector<1x0xi32>
// ----- // -----
// expected-error @+1 {{invalid memref size}}
func @zero_memref_type() -> memref<0xi32>
// -----
// expected-error @+1 {{invalid memref size}}
func @zero_in_memref_type() -> memref<1x0xi32>
// -----
// expected-error @+1 {{expected dimension size in vector type}} // expected-error @+1 {{expected dimension size in vector type}}
func @negative_vector_size() -> vector<-1xi32> func @negative_vector_size() -> vector<-1xi32>