Why?
Internally at Cruise, we’ve been using empty tensors created with TOSA when mapping to kernels that have toggle-able features. For example, consider a bias addition for kernel having biased and non-biased variants.
Roughly speaking we have some IR:
%0 = "tosa.const"() <{value = dense<> : tensor<0xi32>}> : () -> tensor<0xi32>
%2 = tcp.custom_op("kernel") %0 %other : tensor<0xi32>, tensor<32x32xi32> -> tensor<32x32xi32>
After several lowering passes, it becomes:
%0 = cruise.allocate_buffer() : !cruise.buffer<0xi32>
%ptr = cruise.get_buffer_ptr(%0) : !llvm.ptr
%2 = llvm.call @ kernel(%ptr, %other) : ( !llvm.ptr, !llvm.ptr) -> i1
the kernel checks whether the tensor is empty to determine whether a particular feature (like bias) is required.
While zero-sized tensors don’t generally make sense for most TOSA operators, we do have tensor.empty
which supports creating a 0-sized tensor. Should tosa.const
also allow creating a 0-sized tensor in a similar manner?