mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-06-03 21:58:26 +02:00
ethosu: handle NULL bias tensor in convolution
PyTorch Conv2d without explicit bias produces a NULL bias_tensor in the Gallium pipe_ml_operation. Guard against NULL dereferences in two places: - ethosu_lower.c: pass NULL to fill_coefs when bias_tensor is NULL - ethosu_coefs.c: treat missing biases as zero Fixes crashes when running Conv2d models without bias through the Ethos-U NPU backend. Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/40578>
This commit is contained in:
parent
e0b401aa87
commit
f0e4ccf664
2 changed files with 8 additions and 4 deletions
|
|
@ -87,12 +87,14 @@ fill_scale_and_biases(struct ethosu_subgraph *subgraph, struct ethosu_operation
|
|||
uint32_t shift;
|
||||
int scale = ethosu_quantize_scale(conv_scale, &shift);
|
||||
|
||||
uint64_t bias = biases ? biases[i] : 0;
|
||||
|
||||
if (ethosu_ml_device(subgraph->base.device)->is_u65)
|
||||
encode_bias_scale_u65(
|
||||
biases[i], scale, shift, &(*scales)[idx]);
|
||||
bias, scale, shift, &(*scales)[idx]);
|
||||
else
|
||||
encode_bias_scale_u85(
|
||||
biases[i], scale, shift, &(*scales)[idx]);
|
||||
bias, scale, shift, &(*scales)[idx]);
|
||||
|
||||
/* Saved for NPU_SET_OFM_SCALE emission in the command stream. */
|
||||
if (i == 0) {
|
||||
|
|
|
|||
|
|
@ -105,6 +105,8 @@ ethosu_lower_convolution(struct ethosu_subgraph *subgraph,
|
|||
struct pipe_tensor *input_tensor,
|
||||
struct ethosu_operation *operation)
|
||||
{
|
||||
uint8_t *bias_data = poperation->conv.bias_tensor ? poperation->conv.bias_tensor->data : NULL;
|
||||
|
||||
operation->type = ETHOSU_OPERATION_TYPE_CONVOLUTION;
|
||||
|
||||
operation->conv.depthwise = is_depthwise(poperation);
|
||||
|
|
@ -148,8 +150,8 @@ ethosu_lower_convolution(struct ethosu_subgraph *subgraph,
|
|||
allocate_feature_maps(subgraph, operation);
|
||||
|
||||
ethosu_sched_operation(subgraph, operation);
|
||||
fill_coefs(subgraph, operation,
|
||||
(int32_t *)poperation->conv.bias_tensor->data,
|
||||
|
||||
fill_coefs(subgraph, operation, (int32_t *)bias_data,
|
||||
poperation->conv.weight_tensor->data,
|
||||
poperation->conv.weight_tensor->dims[0] *
|
||||
poperation->conv.weight_tensor->dims[1] *
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue