From 790d240b7fb1d36c647e6ef8a7f65842f4ed399b Mon Sep 17 00:00:00 2001 From: eProsima Date: Wed, 30 Oct 2024 10:07:18 +0100 Subject: [PATCH] Refs #22026: Update usage and documentation Signed-off-by: eProsima --- sustainml_cpp/examples/CliModules/main.cpp | 1 + sustainml_cpp/test/blackbox/helpers/data_generators.cpp | 1 + .../architecture/backend/module_nodes/hwconstraints.rst | 1 + .../architecture/backend/module_nodes/hwprovider.rst | 3 ++- .../architecture/backend/module_nodes/mlmodelprovider.rst | 3 ++- sustainml_docs/rst/developer_manual/data_model/data_model.rst | 2 ++ .../sustainml-wp5/orchestrator_node/orchestrator_node.py | 4 +++- sustainml_py/examples/hw_constratins_node.py | 1 + sustainml_py/examples/ml_model_node.py | 4 +++- 9 files changed, 16 insertions(+), 4 deletions(-) diff --git a/sustainml_cpp/examples/CliModules/main.cpp b/sustainml_cpp/examples/CliModules/main.cpp index 9e3a827..7f0e4ab 100644 --- a/sustainml_cpp/examples/CliModules/main.cpp +++ b/sustainml_cpp/examples/CliModules/main.cpp @@ -405,6 +405,7 @@ class CustomHardwareConstraintsListener : public sustainml::hardware_module::Har // Populate output output.max_memory_footprint(user_input.task_id().problem_id()); + output.hardware_required(std::vector{"PIM_AI_1chip"}); // Wait the time it takes the node to generate the output sleep(1); diff --git a/sustainml_cpp/test/blackbox/helpers/data_generators.cpp b/sustainml_cpp/test/blackbox/helpers/data_generators.cpp index 26aab53..3d9d6e1 100644 --- a/sustainml_cpp/test/blackbox/helpers/data_generators.cpp +++ b/sustainml_cpp/test/blackbox/helpers/data_generators.cpp @@ -83,6 +83,7 @@ std::list default_hwconstraints_task_generator( hw_cons.task_id().problem_id(index); hw_cons.task_id().iteration_id(1); hw_cons.max_memory_footprint(index); + hw_cons.hardware_required(std::vector{"PIM_AI_1chip"}); ++index; return hw_cons; }); diff --git a/sustainml_docs/rst/developer_manual/architecture/backend/module_nodes/hwconstraints.rst b/sustainml_docs/rst/developer_manual/architecture/backend/module_nodes/hwconstraints.rst index 8cf91d4..dfe69d4 100644 --- a/sustainml_docs/rst/developer_manual/architecture/backend/module_nodes/hwconstraints.rst +++ b/sustainml_docs/rst/developer_manual/architecture/backend/module_nodes/hwconstraints.rst @@ -118,6 +118,7 @@ User is meant to implement the funcionality of the node within the ``test:callba # There is no need to specify node_status for the moment # as it will automatically be set to IDLE when the callback returns. hw_constraints.max_memory_footprint(100) + hw_constraints.hardware_required(["PIM_AI_1chip"]) # Main workflow routine def run(): diff --git a/sustainml_docs/rst/developer_manual/architecture/backend/module_nodes/hwprovider.rst b/sustainml_docs/rst/developer_manual/architecture/backend/module_nodes/hwprovider.rst index f555938..d088f5b 100644 --- a/sustainml_docs/rst/developer_manual/architecture/backend/module_nodes/hwprovider.rst +++ b/sustainml_docs/rst/developer_manual/architecture/backend/module_nodes/hwprovider.rst @@ -111,7 +111,8 @@ User is meant to implement the funcionality of the node within the ``test:callba print(requirement) # HWConstraints - hw_constraint = hw_constraints.max_memory_footprint() + max_mem_footprint = hw_constraints.max_memory_footprint() + hw_required = hw_constraints.hardware_required() # Do processing... diff --git a/sustainml_docs/rst/developer_manual/architecture/backend/module_nodes/mlmodelprovider.rst b/sustainml_docs/rst/developer_manual/architecture/backend/module_nodes/mlmodelprovider.rst index ec611bf..8e33530 100644 --- a/sustainml_docs/rst/developer_manual/architecture/backend/module_nodes/mlmodelprovider.rst +++ b/sustainml_docs/rst/developer_manual/architecture/backend/module_nodes/mlmodelprovider.rst @@ -121,7 +121,8 @@ User is meant to implement the funcionality of the node within the ``test:callba print(requirement) # HWConstraints - hw_constraint = hw_constraints.max_memory_footprint() + max_mem_footprint = hw_constraints.max_memory_footprint() + hw_required = hw_constraints.hardware_required() # MLModel # Only in case of optimization (task_id.iteration_id() > 1) diff --git a/sustainml_docs/rst/developer_manual/data_model/data_model.rst b/sustainml_docs/rst/developer_manual/data_model/data_model.rst index ea11f65..1e8d223 100644 --- a/sustainml_docs/rst/developer_manual/data_model/data_model.rst +++ b/sustainml_docs/rst/developer_manual/data_model/data_model.rst @@ -193,6 +193,7 @@ Hardware Constraints Type The ``HWConstraints`` represents the group of constraints defined (or not) by the user when describing the problem. It is the output from the ``Hardware Constraints Node``. * ``max_memory_footprint``: The maximum memory footprint allowed for the ML model. +* ``hardware_required``: A sequence of hardware selected by the user to be taken into account by the framework. * ``extra_data``: A sequence of raw extra data for out-of-scope use cases. * ``task_id``: The identifier of the ML problem to solve. @@ -203,6 +204,7 @@ The ``HWConstraints`` represents the group of constraints defined (or not) by th struct HWConstraints { unsigned long max_memory_footprint; + sequence hardware_required; sequence extra_data; @key long task_id; }; diff --git a/sustainml_modules/sustainml_modules/sustainml-wp5/orchestrator_node/orchestrator_node.py b/sustainml_modules/sustainml_modules/sustainml-wp5/orchestrator_node/orchestrator_node.py index cbeb62a..a38a8d0 100644 --- a/sustainml_modules/sustainml_modules/sustainml-wp5/orchestrator_node/orchestrator_node.py +++ b/sustainml_modules/sustainml_modules/sustainml-wp5/orchestrator_node/orchestrator_node.py @@ -121,7 +121,9 @@ def get_hw_constraints(self, task_id): # Parse data into json max_value = node_data.max_memory_footprint() - json_output = {'max_memory_footprint': f'{max_value}'} + required_hardware = node_data.hardware_required() + json_output = {'max_memory_footprint': f'{max_value}', + 'hardware_required': f'{utils.string_std_vector(required_hardware)}'} return json_output def get_ml_model_provider(self, task_id): diff --git a/sustainml_py/examples/hw_constratins_node.py b/sustainml_py/examples/hw_constratins_node.py index 6393cf6..e3f9c8c 100755 --- a/sustainml_py/examples/hw_constratins_node.py +++ b/sustainml_py/examples/hw_constratins_node.py @@ -36,6 +36,7 @@ def signal_handler(sig, frame): def task_callback(user_input, node_status, hw_constraints): print (user_input.problem_definition()) hw_constraints.max_memory_footprint(100) + hw_constraints.hardware_required(['PIM_AI_1chip']) # Main workflow routine def run(): diff --git a/sustainml_py/examples/ml_model_node.py b/sustainml_py/examples/ml_model_node.py index 98d60dc..b70940e 100755 --- a/sustainml_py/examples/ml_model_node.py +++ b/sustainml_py/examples/ml_model_node.py @@ -47,7 +47,9 @@ def task_callback( print("Received metadata " + metadata) for requirement in app_requirements.app_requirements(): print("Received app requirement " + requirement) - print ("Received HW constraints: Max memory footprint: " + str(hw_constraints.max_memory_footprint()) + " MB") + print ("Received HW constraints:\n Max memory footprint: " + str(hw_constraints.max_memory_footprint()) + " MB") + for hw in hw_constraints.hardware_required(): + print(" Hardware required: " + hw) print (node_status.node_status()) ml_model.model("MODEL in ONXX format")