[v5,11/16] ipa: mali-c55: Reduce AWB calculations to float precision
diff mbox series

Message ID 20260114173918.1744023-12-kieran.bingham@ideasonboard.com
State Superseded
Headers show
Series
  • libipa: Introduce a Quantized type
Related show

Commit Message

Kieran Bingham Jan. 14, 2026, 5:39 p.m. UTC
The AWB calculations are determined using double precision, and then
will be soon stored in a quantized float.

Use float types for the intermediate types after the sums have been
converted to an average to remove static cast assignments.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

---
v5:
 - New in v5

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
 src/ipa/mali-c55/algorithms/awb.cpp | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

Comments

Barnabás Pőcze Jan. 15, 2026, 10:44 a.m. UTC | #1
2026. 01. 14. 18:39 keltezéssel, Kieran Bingham írta:
> The AWB calculations are determined using double precision, and then
> will be soon stored in a quantized float.
> 
> Use float types for the intermediate types after the sums have been
> converted to an average to remove static cast assignments.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> 
> ---
> v5:
>   - New in v5
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> ---
>   src/ipa/mali-c55/algorithms/awb.cpp | 12 ++++++------
>   1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/src/ipa/mali-c55/algorithms/awb.cpp b/src/ipa/mali-c55/algorithms/awb.cpp
> index 964e810882a9..b179dd7f0c1c 100644
> --- a/src/ipa/mali-c55/algorithms/awb.cpp
> +++ b/src/ipa/mali-c55/algorithms/awb.cpp
> @@ -159,7 +159,7 @@ void Awb::process(IPAContext &context, const uint32_t frame,

Why not convert `{rg,bg}Sum` as well? There are only 225 zones,
so the sum should fit a `float`, no?


>   	 * Sometimes the first frame's statistics have no valid pixels, in which
>   	 * case we'll just assume a grey world until they say otherwise.
>   	 */
> -	double rgAvg, bgAvg;
> +	float rgAvg, bgAvg;
>   	if (!counted_zones) {
>   		rgAvg = 1.0;
>   		bgAvg = 1.0;
> @@ -174,15 +174,15 @@ void Awb::process(IPAContext &context, const uint32_t frame,
>   	 * figure by the gains that were applied when the statistics for this
>   	 * frame were generated.
>   	 */
> -	double rRatio = rgAvg / frameContext.awb.rGain;
> -	double bRatio = bgAvg / frameContext.awb.bGain;
> +	float rRatio = rgAvg / frameContext.awb.rGain;
> +	float bRatio = bgAvg / frameContext.awb.bGain;
>   
>   	/*
>   	 * And then we can simply invert the ratio to find the gain we should
>   	 * apply.
>   	 */
> -	double rGain = 1 / rRatio;
> -	double bGain = 1 / bRatio;
> +	float rGain = 1 / rRatio;
> +	float bGain = 1 / bRatio;
>   
>   	/*
>   	 * Running at full speed, this algorithm results in oscillations in the
> @@ -190,7 +190,7 @@ void Awb::process(IPAContext &context, const uint32_t frame,
>   	 * changes in gain, unless we're in the startup phase in which case we
>   	 * want to fix the miscolouring as quickly as possible.
>   	 */
> -	double speed = frame < kNumStartupFrames ? 1.0 : 0.2;
> +	float speed = frame < kNumStartupFrames ? 1.0 : 0.2;
>   	rGain = speed * rGain + context.activeState.awb.rGain * (1.0 - speed);
>   	bGain = speed * bGain + context.activeState.awb.bGain * (1.0 - speed);
>
Kieran Bingham Jan. 21, 2026, 4:32 p.m. UTC | #2
Quoting Barnabás Pőcze (2026-01-15 10:44:00)
> 2026. 01. 14. 18:39 keltezéssel, Kieran Bingham írta:
> > The AWB calculations are determined using double precision, and then
> > will be soon stored in a quantized float.
> > 
> > Use float types for the intermediate types after the sums have been
> > converted to an average to remove static cast assignments.
> > 
> > Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> > 
> > ---
> > v5:
> >   - New in v5
> > 
> > Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> > ---
> >   src/ipa/mali-c55/algorithms/awb.cpp | 12 ++++++------
> >   1 file changed, 6 insertions(+), 6 deletions(-)
> > 
> > diff --git a/src/ipa/mali-c55/algorithms/awb.cpp b/src/ipa/mali-c55/algorithms/awb.cpp
> > index 964e810882a9..b179dd7f0c1c 100644
> > --- a/src/ipa/mali-c55/algorithms/awb.cpp
> > +++ b/src/ipa/mali-c55/algorithms/awb.cpp
> > @@ -159,7 +159,7 @@ void Awb::process(IPAContext &context, const uint32_t frame,
> 
> Why not convert `{rg,bg}Sum` as well? There are only 225 zones,
> so the sum should fit a `float`, no?

Yes, I think we could do fixed point arithmetic in the future too
allowing the UQ<4, 8> to accumulate into a UQ<8, 8> for instance without
losing any precision.

But I've taken this in for now to keep it consistent.

--
Kieran

> 
> 
> >        * Sometimes the first frame's statistics have no valid pixels, in which
> >        * case we'll just assume a grey world until they say otherwise.
> >        */
> > -     double rgAvg, bgAvg;
> > +     float rgAvg, bgAvg;
> >       if (!counted_zones) {
> >               rgAvg = 1.0;
> >               bgAvg = 1.0;
> > @@ -174,15 +174,15 @@ void Awb::process(IPAContext &context, const uint32_t frame,
> >        * figure by the gains that were applied when the statistics for this
> >        * frame were generated.
> >        */
> > -     double rRatio = rgAvg / frameContext.awb.rGain;
> > -     double bRatio = bgAvg / frameContext.awb.bGain;
> > +     float rRatio = rgAvg / frameContext.awb.rGain;
> > +     float bRatio = bgAvg / frameContext.awb.bGain;
> >   
> >       /*
> >        * And then we can simply invert the ratio to find the gain we should
> >        * apply.
> >        */
> > -     double rGain = 1 / rRatio;
> > -     double bGain = 1 / bRatio;
> > +     float rGain = 1 / rRatio;
> > +     float bGain = 1 / bRatio;
> >   
> >       /*
> >        * Running at full speed, this algorithm results in oscillations in the
> > @@ -190,7 +190,7 @@ void Awb::process(IPAContext &context, const uint32_t frame,
> >        * changes in gain, unless we're in the startup phase in which case we
> >        * want to fix the miscolouring as quickly as possible.
> >        */
> > -     double speed = frame < kNumStartupFrames ? 1.0 : 0.2;
> > +     float speed = frame < kNumStartupFrames ? 1.0 : 0.2;
> >       rGain = speed * rGain + context.activeState.awb.rGain * (1.0 - speed);
> >       bGain = speed * bGain + context.activeState.awb.bGain * (1.0 - speed);
> >   
>

Patch
diff mbox series

diff --git a/src/ipa/mali-c55/algorithms/awb.cpp b/src/ipa/mali-c55/algorithms/awb.cpp
index 964e810882a9..b179dd7f0c1c 100644
--- a/src/ipa/mali-c55/algorithms/awb.cpp
+++ b/src/ipa/mali-c55/algorithms/awb.cpp
@@ -159,7 +159,7 @@  void Awb::process(IPAContext &context, const uint32_t frame,
 	 * Sometimes the first frame's statistics have no valid pixels, in which
 	 * case we'll just assume a grey world until they say otherwise.
 	 */
-	double rgAvg, bgAvg;
+	float rgAvg, bgAvg;
 	if (!counted_zones) {
 		rgAvg = 1.0;
 		bgAvg = 1.0;
@@ -174,15 +174,15 @@  void Awb::process(IPAContext &context, const uint32_t frame,
 	 * figure by the gains that were applied when the statistics for this
 	 * frame were generated.
 	 */
-	double rRatio = rgAvg / frameContext.awb.rGain;
-	double bRatio = bgAvg / frameContext.awb.bGain;
+	float rRatio = rgAvg / frameContext.awb.rGain;
+	float bRatio = bgAvg / frameContext.awb.bGain;
 
 	/*
 	 * And then we can simply invert the ratio to find the gain we should
 	 * apply.
 	 */
-	double rGain = 1 / rRatio;
-	double bGain = 1 / bRatio;
+	float rGain = 1 / rRatio;
+	float bGain = 1 / bRatio;
 
 	/*
 	 * Running at full speed, this algorithm results in oscillations in the
@@ -190,7 +190,7 @@  void Awb::process(IPAContext &context, const uint32_t frame,
 	 * changes in gain, unless we're in the startup phase in which case we
 	 * want to fix the miscolouring as quickly as possible.
 	 */
-	double speed = frame < kNumStartupFrames ? 1.0 : 0.2;
+	float speed = frame < kNumStartupFrames ? 1.0 : 0.2;
 	rGain = speed * rGain + context.activeState.awb.rGain * (1.0 - speed);
 	bGain = speed * bGain + context.activeState.awb.bGain * (1.0 - speed);