[v7,21/26] ipa: libipa: module: Add createSelfEnumeratingAlgorithm
diff mbox series

Message ID 20251210005354.44726-22-bryan.odonoghue@linaro.org
State Superseded
Headers show
Series
  • Add GLES 2.0 GPUISP to libcamera
Related show

Commit Message

Bryan O'Donoghue Dec. 10, 2025, 12:53 a.m. UTC
Create an algorithm without having YAML data input.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
---
 src/ipa/libipa/module.h | 45 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

Comments

Milan Zamazal Dec. 10, 2025, 5 p.m. UTC | #1
Bryan O'Donoghue <bryan.odonoghue@linaro.org> writes:

> Create an algorithm without having YAML data input.
>
> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
> ---
>  src/ipa/libipa/module.h | 45 +++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 45 insertions(+)
>
> diff --git a/src/ipa/libipa/module.h b/src/ipa/libipa/module.h
> index c27af7718..c5767c6f3 100644
> --- a/src/ipa/libipa/module.h
> +++ b/src/ipa/libipa/module.h
> @@ -70,6 +70,51 @@ public:
>  		factories().push_back(factory);
>  	}
>  
> +	/**
> +	 * \fn int Module::createSelfEnumeratingAlgorithm(Context &context, const std::string &name)
> +	 * \brief Create and initialise a self-enumerating algorithm by name
> +	 *
> +	 * This function creates an algorithm instance from the registered algorithm
> +	 * factories using only the algorithm name, without requiring YAML configuration
> +	 * data.
> +	 *
> +	 * This is useful for algorithms that don't require external configuration
> +	 * parameters and can self-configure or use default values.
> +	 *
> +	 * \param[in] context The IPA context to pass to the algorithm's init function
> +	 * \param[in] name The name of the algorithm to instantiate
> +	 *
> +	 * \return 0 on success, negative errno value on failure:
> +	 *         -EINVAL if the algorithm is not found in the factory registry
> +	 *         Other negative values if algorithm initialisation fails
> +	 */

The docstring should go to the .cpp file.

> +	int createSelfEnumeratingAlgorithm(Context &context, const std::string &name)
> +	{
> +		YamlObject dummy;
> +
> +		std::unique_ptr<Algorithm<Module>> algo = createAlgorithm(name);
> +		if (!algo) {
> +			LOG(IPAModuleAlgo, Error)
> +				<< "Algorithm '" << name << "' not found";
> +			return -EINVAL;
> +		}
> +
> +		context.selfInitialising = true;
> +
> +		int ret = algo->init(context, dummy);
> +		if (ret) {
> +			LOG(IPAModuleAlgo, Error)
> +				<< "Algorithm '" << name << "' failed to initialize";
> +			return ret;
> +		}
> +
> +		LOG(IPAModuleAlgo, Debug)
> +			<< "Instantiated algorithm '" << name << "'";
> +
> +		algorithms_.push_back(std::move(algo));
> +		return 0;
> +	}

Hmm, this code duplication doesn't feel good.  For example, it already
omits the change that allows disabling algorithms in the tuning file; or
is it on purpose?  I should look into my simple algorithms refactoring
and think more whether there is a chance to find a better mechanism.

>  private:
>  	int createAlgorithm(Context &context, const YamlObject &data)
>  	{

Patch
diff mbox series

diff --git a/src/ipa/libipa/module.h b/src/ipa/libipa/module.h
index c27af7718..c5767c6f3 100644
--- a/src/ipa/libipa/module.h
+++ b/src/ipa/libipa/module.h
@@ -70,6 +70,51 @@  public:
 		factories().push_back(factory);
 	}
 
+	/**
+	 * \fn int Module::createSelfEnumeratingAlgorithm(Context &context, const std::string &name)
+	 * \brief Create and initialise a self-enumerating algorithm by name
+	 *
+	 * This function creates an algorithm instance from the registered algorithm
+	 * factories using only the algorithm name, without requiring YAML configuration
+	 * data.
+	 *
+	 * This is useful for algorithms that don't require external configuration
+	 * parameters and can self-configure or use default values.
+	 *
+	 * \param[in] context The IPA context to pass to the algorithm's init function
+	 * \param[in] name The name of the algorithm to instantiate
+	 *
+	 * \return 0 on success, negative errno value on failure:
+	 *         -EINVAL if the algorithm is not found in the factory registry
+	 *         Other negative values if algorithm initialisation fails
+	 */
+	int createSelfEnumeratingAlgorithm(Context &context, const std::string &name)
+	{
+		YamlObject dummy;
+
+		std::unique_ptr<Algorithm<Module>> algo = createAlgorithm(name);
+		if (!algo) {
+			LOG(IPAModuleAlgo, Error)
+				<< "Algorithm '" << name << "' not found";
+			return -EINVAL;
+		}
+
+		context.selfInitialising = true;
+
+		int ret = algo->init(context, dummy);
+		if (ret) {
+			LOG(IPAModuleAlgo, Error)
+				<< "Algorithm '" << name << "' failed to initialize";
+			return ret;
+		}
+
+		LOG(IPAModuleAlgo, Debug)
+			<< "Instantiated algorithm '" << name << "'";
+
+		algorithms_.push_back(std::move(algo));
+		return 0;
+	}
+
 private:
 	int createAlgorithm(Context &context, const YamlObject &data)
 	{