Skip to content

Commit

Permalink
Refs #22027: Use user_input extra_data to propagate HW Constraints no…
Browse files Browse the repository at this point in the history
…de data

Signed-off-by: eProsima <[email protected]>
  • Loading branch information
JesusPoderoso committed Oct 31, 2024
1 parent bec10b7 commit 0d516ed
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"""SustainML Orchestrator Node API specification."""

from . import utils
import numpy as np

from sustainml_swig import OrchestratorNodeHandle as cpp_OrchestratorNodeHandle
from sustainml_swig import OrchestratorNode as cpp_OrchestratorNode
Expand Down Expand Up @@ -208,4 +209,19 @@ def send_user_input(self, json_data):
#user_input.evaluation_metrics(evaluation_metrics)
#user_input.model(model)

# Prepare extra data
hw_req = utils.default_hw_requirement
mem_footprint = utils.default_mem_footprint
if (json_data.get('hardware_required') is not None):
hw_req = json_data.get('hardware_required')
if (json_data.get('max_memory_footprint') is not None):
mem_footprint = json_data.get('max_memory_footprint')

# Add extra data to user user_input
extra_data = {'hardware_required': hw_req,
'max_memory_footprint': mem_footprint}
json_obj = utils.json_dict(extra_data)
data_array = np.frombuffer(json_obj.encode(), dtype=np.uint8)
user_input.extra_data(sustainml_swig.uint8_t_vector(data_array.tolist()))

return self.node_.start_task(task_id, user_input)
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
"""SustainML Orchestrator Node utility methods."""

from enum import Enum
from sustainml_swig import AppRequirements, CO2Footprint, HWConstraints, HWResource, MLModelMetadata, MLModel
import sustainml_swig
import json

default_hw_requirement = "PIM_AI_1chip"
default_mem_footprint = 100

class node_id(Enum):
APP_REQUIREMENTS = 0
Expand Down Expand Up @@ -87,3 +89,8 @@ def string_std_vector(vector):
def string_task(task):
return "{" + str(task.problem_id()) + ", " + str(task.iteration_id()) + "}"

def json_dict(dict):
return json.dumps(dict, indent=4)

def dict_from_json(json_obj):
return json.loads(json_obj)
12 changes: 11 additions & 1 deletion sustainml_swig/src/swig/sustainml_swig/types/types.i
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,23 @@
%include std_string.i

// Ignore overloaded methods that have no application on Python
// Warnings regarding equiality operators and stuff
// Warnings regarding equality operators and stuff
%ignore *::operator=;
%ignore operator<<;

%{
#include <sustainml_cpp/types/types.hpp>
%}

%extend std::vector<uint8_t>
{
const uint8_t* get_buffer() const
{
return self->data();
}
}

%template(uint8_t_vector) std::vector<uint8_t>;

// Include the class interfaces
%include <sustainml_cpp/types/types.hpp>

0 comments on commit 0d516ed

Please sign in to comment.