Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mlir/lib/Dialect/Bufferization/IR/BufferizationDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ LogicalResult BufferizationDialect::verifyRegionArgAttribute(
return success();
}
if (attr.getName() == kBufferLayoutAttrName) {
if (!llvm::isa<AffineMapAttr>(attr.getValue())) {
if (!llvm::isa<MemRefLayoutAttrInterface>(attr.getValue())) {
return op->emitError() << "'" << kBufferLayoutAttrName
<< "' is expected to be a affine map attribute";
<< "' is expected to be a memref layout attribute";
}
if (!isa<FunctionOpInterface>(op))
return op->emitError() << "expected '" << kBufferLayoutAttrName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ getBufferizedFunctionArgType(FuncOp funcOp, int64_t index,
BaseMemRefType memrefType = options.functionArgTypeConverterFn(
tensorType, *options.defaultMemorySpaceFn(tensorType), funcOp, options);

auto layoutAttr = funcOp.getArgAttrOfType<AffineMapAttr>(
auto layoutAttr = funcOp.getArgAttrOfType<MemRefLayoutAttrInterface>(
index, BufferizationDialect::kBufferLayoutAttrName);
if (!layoutAttr)
return memrefType;

auto rankedMemrefType = dyn_cast<MemRefType>(memrefType);
assert(rankedMemrefType && "buffer layout not supported on unranked tensors");
return MemRefType::get(
rankedMemrefType.getShape(), rankedMemrefType.getElementType(),
layoutAttr.getValue(), rankedMemrefType.getMemorySpace());
return MemRefType::get(rankedMemrefType.getShape(),
rankedMemrefType.getElementType(), layoutAttr,
rankedMemrefType.getMemorySpace());
}

/// Return the FuncOp called by `callOp`.
Expand Down
22 changes: 22 additions & 0 deletions mlir/test/Dialect/Tensor/one-shot-bufferize.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,28 @@ func.func @cast_retains_buffer_layout(

// -----

// CHECK-LABEL: func.func @cast_retains_buffer_layout_strided(
// CHECK-SAME: %[[t:.*]]: memref<?xf32, strided<[1], offset: 5>>, %[[sz:.*]]: index) -> memref<?xf32, strided<[1], offset: 7>> {
// CHECK: %[[casted:.*]] = memref.cast %[[t]] : memref<?xf32, strided<[1], offset: 5>> to memref<10xf32, strided<[1], offset: 5>>
// CHECK: %[[slice:.*]] = memref.subview %[[casted]][2] [%[[sz]]] [1] : memref<10xf32, strided<[1], offset: 5>> to memref<?xf32, strided<[1], offset: 7>>
// CHECK: return %[[slice]]
func.func @cast_retains_buffer_layout_strided(
%t: tensor<?xf32>
{bufferization.buffer_layout = strided<[1], offset: 5>},
%sz: index)
-> (tensor<10xf32>, tensor<?xf32>)
{
%casted = tensor.cast %t : tensor<?xf32> to tensor<10xf32>
%slice = tensor.extract_slice %casted[2][%sz][1] : tensor<10xf32> to tensor<?xf32>

// Note: The %casted return type is folded away because both buffers are
// equivalent. Therefore, we currently loose some static type information
// in the caller.
return %casted, %slice : tensor<10xf32>, tensor<?xf32>
}

// -----

// CHECK-LABEL: func.func @parallel_insert_slice_source_out_of_place
func.func @parallel_insert_slice_source_out_of_place(%in: tensor<1xf32>, %out: tensor<100xf32>, %f: f32) {
%c0 = arith.constant 0 : index
Expand Down