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
5 changes: 5 additions & 0 deletions mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,11 @@ static Type convertTensorType(const spirv::TargetEnv &targetEnv,
<< type << " illegal: cannot handle zero-element tensors\n");
return nullptr;
}
if (arrayElemCount > std::numeric_limits<unsigned>::max()) {
LLVM_DEBUG(llvm::dbgs()
<< type << " illegal: cannot fit tensor into target type\n");
return nullptr;
}

Type arrayElemType = convertScalarType(targetEnv, options, scalarType);
if (!arrayElemType)
Expand Down
9 changes: 9 additions & 0 deletions mlir/test/Conversion/TensorToSPIRV/tensor-ops-to-spirv.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,12 @@ func.func @tensor_2d_empty() -> () {
%x = arith.constant dense<> : tensor<2x0xi32>
return
}

// Tensors with more than UINT32_MAX elements cannnot fit in a spirv.array.
// Test that they are not lowered.
// CHECK-LABEL: func @very_large_tensor
// CHECK-NEXT: arith.constant dense<1>
func.func @very_large_tensor() -> () {
%x = arith.constant dense<1> : tensor<4294967296xi32>
return
}
Loading