Constrain mhlo.const to static shaped tensors.
Constants of unknown shape cannot be materialized. In most cases, one likely wants to use a scalar constant and rely on broadcasting instead. PiperOrigin-RevId: 324252475
This commit is contained in:
parent
734b9b25fd
commit
9cbe5f2285
|
@ -52,7 +52,7 @@ def HLO_ConstOp : HLO_Op<"constant",
|
|||
);
|
||||
|
||||
let results = (outs
|
||||
HLO_Tensor:$output
|
||||
HLO_StaticShapeTensor:$output
|
||||
);
|
||||
|
||||
let builders = [OpBuilder<
|
||||
|
|
|
@ -939,7 +939,23 @@ func @constants() -> () {
|
|||
|
||||
func @constant_invalid() -> () {
|
||||
// expected-error@+1 {{op failed to verify that all of {value, output} have same type}}
|
||||
%0 = "mhlo.constant"() {value = dense<0> : tensor<i32>} : () -> (tensor<*xi32>)
|
||||
%0 = "mhlo.constant"() {value = dense<0> : tensor<i32>} : () -> (tensor<3xi32>)
|
||||
return
|
||||
}
|
||||
|
||||
// -----
|
||||
|
||||
func @constant_invalid() -> () {
|
||||
// expected-error@+1 {{op result #0 must be statically shaped tensor}}
|
||||
%0 = "mhlo.constant"() {value = dense<1> : tensor<i32>} : () -> tensor<?xi32>
|
||||
return
|
||||
}
|
||||
|
||||
// -----
|
||||
|
||||
func @constant_invalid() -> () {
|
||||
// expected-error@+1 {{elements literal type must have static shape}}
|
||||
%0 = "mhlo.constant"() {value = dense<1> : tensor<?xi32>} : () -> tensor<?xi32>
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue