teflon: Add support for setting the tensor type size

Drivers supporting different element sizes need to know the element type
size.

Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/40525>
This commit is contained in:
Rob Herring (Arm) 2026-03-12 21:59:29 -05:00 committed by Marge Bot
parent c29860e9e9
commit 7613788f06
2 changed files with 31 additions and 0 deletions

View file

@ -308,6 +308,35 @@ all_zero_points_equal(const TfLiteAffineQuantization *quant)
return true;
}
static size_t
tf_format_to_size(TfLiteType type)
{
switch (type) {
case kTfLiteFloat32:
return sizeof(float);
case kTfLiteFloat64:
return sizeof(double);
case kTfLiteInt8:
return sizeof(int8_t);
case kTfLiteUInt8:
return sizeof(uint8_t);
case kTfLiteInt16:
return sizeof(int16_t);
case kTfLiteUInt16:
return sizeof(uint16_t);
case kTfLiteInt32:
return sizeof(int32_t);
case kTfLiteUInt32:
return sizeof(uint32_t);
case kTfLiteInt64:
return sizeof(int64_t);
case kTfLiteUInt64:
return sizeof(uint64_t);
default:
return 0;
}
}
static void
fill_tensor(struct teflon_delegate *delegate, TfLiteContext *tf_context, struct pipe_tensor *tensor, unsigned index)
{
@ -320,6 +349,7 @@ fill_tensor(struct teflon_delegate *delegate, TfLiteContext *tf_context, struct
if (tf_tensor.data.data)
tensor->resource = create_resource(context, tf_tensor);
tensor->type_size = tf_format_to_size(tf_tensor.type);
tensor->index = index;
for (int out_dim = 0; out_dim < 4; out_dim++) {
int in_dim = tf_tensor.dims->size - 4 + out_dim;

View file

@ -1044,6 +1044,7 @@ struct pipe_tensor {
* Whether the tensor contains data in INT8 or UINT8 format.
*/
bool is_signed;
uint8_t type_size;
};
/**