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

Message ID 20251212002937.3118-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. 12, 2025, 12:29 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.cpp | 34 ++++++++++++++++++++++++++++
 src/ipa/libipa/module.h   | 47 +++++++++++++++++++++++++++++----------
 2 files changed, 69 insertions(+), 12 deletions(-)

Comments

Milan Zamazal Dec. 12, 2025, 9:23 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>

The patch looks OK to me now, but my suggestion from the preceding patch
about postponing this (as well as the followup patches) applies.

> ---
>  src/ipa/libipa/module.cpp | 34 ++++++++++++++++++++++++++++
>  src/ipa/libipa/module.h   | 47 +++++++++++++++++++++++++++++----------
>  2 files changed, 69 insertions(+), 12 deletions(-)
>
> diff --git a/src/ipa/libipa/module.cpp b/src/ipa/libipa/module.cpp
> index a95dca696..41235f902 100644
> --- a/src/ipa/libipa/module.cpp
> +++ b/src/ipa/libipa/module.cpp
> @@ -83,6 +83,40 @@ namespace ipa {
>   * \return The list of instantiated algorithms
>   */
>  
> +/**
> + * \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
> + */
> +
> +/**
> + * \fn int Module::createAlgorithmCommon(Context &context, const YamlObject &algoData, const std::string &name)
> + * \brief Common helper fucntion to allow createSelfEnumeratingAlgorithm and createAlgorithm share code
> + *
> + * Worker method which allows sharing of common code in the Yaml and self-initialising algorithm case
> + *
> + * \param[in] context The IPA context to pass to the algorithm's init function
> + * \param[in] algoData Yaml object.
> + * \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
> + */
> +
>  /**
>   * \fn Module::createAlgorithms()
>   * \brief Create algorithms from YAML configuration data
> diff --git a/src/ipa/libipa/module.h b/src/ipa/libipa/module.h
> index c27af7718..5ab6afc18 100644
> --- a/src/ipa/libipa/module.h
> +++ b/src/ipa/libipa/module.h
> @@ -70,22 +70,26 @@ public:
>  		factories().push_back(factory);
>  	}
>  
> -private:
> -	int createAlgorithm(Context &context, const YamlObject &data)
> +	int createSelfEnumeratingAlgorithm(Context &context, const std::string &name)
>  	{
> -		const auto &[name, algoData] = *data.asDict().begin();
> +		YamlObject dummy;
>  
> -		/*
> -		 * Optionally, algorithms can be disabled via the tuning file
> -		 * by including enabled: false as a parameter within the
> -		 * algorithm tuning data. This is not an error, so we return 0.
> -		 */
> -		if (!algoData["enabled"].get<bool>(true)) {
> -			LOG(IPAModuleAlgo, Info)
> -				<< "Algorithm '" << name << "' disabled via tuning file";
> -			return 0;
> +		std::unique_ptr<Algorithm<Module>> algo = createAlgorithm(name);
> +		if (!algo) {
> +			LOG(IPAModuleAlgo, Error)
> +				<< "Algorithm '" << name << "' not found";
> +			return -EINVAL;
>  		}
>  
> +		context.selfInitialising = true;
> +
> +		return createAlgorithmCommon(context, dummy, name);
> +	}
> +
> +private:
> +
> +	int createAlgorithmCommon(Context &context, const YamlObject &algoData, const std::string &name)
> +	{
>  		std::unique_ptr<Algorithm<Module>> algo = createAlgorithm(name);
>  		if (!algo) {
>  			LOG(IPAModuleAlgo, Error)
> @@ -104,9 +108,28 @@ private:
>  			<< "Instantiated algorithm '" << name << "'";
>  
>  		algorithms_.push_back(std::move(algo));
> +
>  		return 0;
>  	}
>  
> +	int createAlgorithm(Context &context, const YamlObject &data)
> +	{
> +		const auto &[name, algoData] = *data.asDict().begin();
> +
> +		/*
> +		 * Optionally, algorithms can be disabled via the tuning file
> +		 * by including enabled: false as a parameter within the
> +		 * algorithm tuning data. This is not an error, so we return 0.
> +		 */
> +		if (!algoData["enabled"].get<bool>(true)) {
> +			LOG(IPAModuleAlgo, Info)
> +				<< "Algorithm '" << name << "' disabled via tuning file";
> +			return 0;
> +		}
> +
> +		return createAlgorithmCommon(context, algoData, name);
> +	}
> +
>  	static std::unique_ptr<Algorithm<Module>> createAlgorithm(const std::string &name)
>  	{
>  		for (const AlgorithmFactoryBase<Module> *factory : factories()) {
Milan Zamazal Dec. 15, 2025, 10:42 a.m. UTC | #2
Milan Zamazal <mzamazal@redhat.com> writes:

> 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>
>
> The patch looks OK to me now, but my suggestion from the preceding patch
> about postponing this (as well as the followup patches) applies.

Reviewed-by: Milan Zamazal <mzamazal@redhat.com>

>> ---
>>  src/ipa/libipa/module.cpp | 34 ++++++++++++++++++++++++++++
>>  src/ipa/libipa/module.h   | 47 +++++++++++++++++++++++++++++----------
>>  2 files changed, 69 insertions(+), 12 deletions(-)
>>
>> diff --git a/src/ipa/libipa/module.cpp b/src/ipa/libipa/module.cpp
>> index a95dca696..41235f902 100644
>> --- a/src/ipa/libipa/module.cpp
>> +++ b/src/ipa/libipa/module.cpp
>> @@ -83,6 +83,40 @@ namespace ipa {
>>   * \return The list of instantiated algorithms
>>   */
>>  
>> +/**
>> + * \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
>> + */
>> +
>> +/**
>> + * \fn int Module::createAlgorithmCommon(Context &context, const YamlObject &algoData, const std::string &name)
>> + * \brief Common helper fucntion to allow createSelfEnumeratingAlgorithm and createAlgorithm share code
>> + *
>> + * Worker method which allows sharing of common code in the Yaml and self-initialising algorithm case
>> + *
>> + * \param[in] context The IPA context to pass to the algorithm's init function
>> + * \param[in] algoData Yaml object.
>> + * \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
>> + */
>> +
>>  /**
>>   * \fn Module::createAlgorithms()
>>   * \brief Create algorithms from YAML configuration data
>> diff --git a/src/ipa/libipa/module.h b/src/ipa/libipa/module.h
>> index c27af7718..5ab6afc18 100644
>> --- a/src/ipa/libipa/module.h
>> +++ b/src/ipa/libipa/module.h
>> @@ -70,22 +70,26 @@ public:
>>  		factories().push_back(factory);
>>  	}
>>  
>> -private:
>> -	int createAlgorithm(Context &context, const YamlObject &data)
>> +	int createSelfEnumeratingAlgorithm(Context &context, const std::string &name)
>>  	{
>> -		const auto &[name, algoData] = *data.asDict().begin();
>> +		YamlObject dummy;
>>  
>> -		/*
>> -		 * Optionally, algorithms can be disabled via the tuning file
>> -		 * by including enabled: false as a parameter within the
>> -		 * algorithm tuning data. This is not an error, so we return 0.
>> -		 */
>> -		if (!algoData["enabled"].get<bool>(true)) {
>> -			LOG(IPAModuleAlgo, Info)
>> -				<< "Algorithm '" << name << "' disabled via tuning file";
>> -			return 0;
>> +		std::unique_ptr<Algorithm<Module>> algo = createAlgorithm(name);
>> +		if (!algo) {
>> +			LOG(IPAModuleAlgo, Error)
>> +				<< "Algorithm '" << name << "' not found";
>> +			return -EINVAL;
>>  		}
>>  
>> +		context.selfInitialising = true;
>> +
>> +		return createAlgorithmCommon(context, dummy, name);
>> +	}
>> +
>> +private:
>> +
>> +	int createAlgorithmCommon(Context &context, const YamlObject &algoData, const std::string &name)
>> +	{
>>  		std::unique_ptr<Algorithm<Module>> algo = createAlgorithm(name);
>>  		if (!algo) {
>>  			LOG(IPAModuleAlgo, Error)
>> @@ -104,9 +108,28 @@ private:
>>  			<< "Instantiated algorithm '" << name << "'";
>>  
>>  		algorithms_.push_back(std::move(algo));
>> +
>>  		return 0;
>>  	}
>>  
>> +	int createAlgorithm(Context &context, const YamlObject &data)
>> +	{
>> +		const auto &[name, algoData] = *data.asDict().begin();
>> +
>> +		/*
>> +		 * Optionally, algorithms can be disabled via the tuning file
>> +		 * by including enabled: false as a parameter within the
>> +		 * algorithm tuning data. This is not an error, so we return 0.
>> +		 */
>> +		if (!algoData["enabled"].get<bool>(true)) {
>> +			LOG(IPAModuleAlgo, Info)
>> +				<< "Algorithm '" << name << "' disabled via tuning file";
>> +			return 0;
>> +		}
>> +
>> +		return createAlgorithmCommon(context, algoData, name);
>> +	}
>> +
>>  	static std::unique_ptr<Algorithm<Module>> createAlgorithm(const std::string &name)
>>  	{
>>  		for (const AlgorithmFactoryBase<Module> *factory : factories()) {

Patch
diff mbox series

diff --git a/src/ipa/libipa/module.cpp b/src/ipa/libipa/module.cpp
index a95dca696..41235f902 100644
--- a/src/ipa/libipa/module.cpp
+++ b/src/ipa/libipa/module.cpp
@@ -83,6 +83,40 @@  namespace ipa {
  * \return The list of instantiated algorithms
  */
 
+/**
+ * \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
+ */
+
+/**
+ * \fn int Module::createAlgorithmCommon(Context &context, const YamlObject &algoData, const std::string &name)
+ * \brief Common helper fucntion to allow createSelfEnumeratingAlgorithm and createAlgorithm share code
+ *
+ * Worker method which allows sharing of common code in the Yaml and self-initialising algorithm case
+ *
+ * \param[in] context The IPA context to pass to the algorithm's init function
+ * \param[in] algoData Yaml object.
+ * \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
+ */
+
 /**
  * \fn Module::createAlgorithms()
  * \brief Create algorithms from YAML configuration data
diff --git a/src/ipa/libipa/module.h b/src/ipa/libipa/module.h
index c27af7718..5ab6afc18 100644
--- a/src/ipa/libipa/module.h
+++ b/src/ipa/libipa/module.h
@@ -70,22 +70,26 @@  public:
 		factories().push_back(factory);
 	}
 
-private:
-	int createAlgorithm(Context &context, const YamlObject &data)
+	int createSelfEnumeratingAlgorithm(Context &context, const std::string &name)
 	{
-		const auto &[name, algoData] = *data.asDict().begin();
+		YamlObject dummy;
 
-		/*
-		 * Optionally, algorithms can be disabled via the tuning file
-		 * by including enabled: false as a parameter within the
-		 * algorithm tuning data. This is not an error, so we return 0.
-		 */
-		if (!algoData["enabled"].get<bool>(true)) {
-			LOG(IPAModuleAlgo, Info)
-				<< "Algorithm '" << name << "' disabled via tuning file";
-			return 0;
+		std::unique_ptr<Algorithm<Module>> algo = createAlgorithm(name);
+		if (!algo) {
+			LOG(IPAModuleAlgo, Error)
+				<< "Algorithm '" << name << "' not found";
+			return -EINVAL;
 		}
 
+		context.selfInitialising = true;
+
+		return createAlgorithmCommon(context, dummy, name);
+	}
+
+private:
+
+	int createAlgorithmCommon(Context &context, const YamlObject &algoData, const std::string &name)
+	{
 		std::unique_ptr<Algorithm<Module>> algo = createAlgorithm(name);
 		if (!algo) {
 			LOG(IPAModuleAlgo, Error)
@@ -104,9 +108,28 @@  private:
 			<< "Instantiated algorithm '" << name << "'";
 
 		algorithms_.push_back(std::move(algo));
+
 		return 0;
 	}
 
+	int createAlgorithm(Context &context, const YamlObject &data)
+	{
+		const auto &[name, algoData] = *data.asDict().begin();
+
+		/*
+		 * Optionally, algorithms can be disabled via the tuning file
+		 * by including enabled: false as a parameter within the
+		 * algorithm tuning data. This is not an error, so we return 0.
+		 */
+		if (!algoData["enabled"].get<bool>(true)) {
+			LOG(IPAModuleAlgo, Info)
+				<< "Algorithm '" << name << "' disabled via tuning file";
+			return 0;
+		}
+
+		return createAlgorithmCommon(context, algoData, name);
+	}
+
 	static std::unique_ptr<Algorithm<Module>> createAlgorithm(const std::string &name)
 	{
 		for (const AlgorithmFactoryBase<Module> *factory : factories()) {