Skip to content

Commit

Permalink
Refs #22027: Update HW Constraints node to receive data from extra_da…
Browse files Browse the repository at this point in the history
…ta field

Signed-off-by: eProsima <jesuspoderoso@eprosima.com>
  • Loading branch information
JesusPoderoso committed Nov 4, 2024
1 parent 618391c commit 5d0582c
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions hw_constraints_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
from sustainml_py.nodes.HardwareConstraintsNode import HardwareConstraintsNode

# Manage signaling
import ctypes
import json
import numpy as np
import signal
import threading
import time
Expand All @@ -35,9 +38,29 @@ def signal_handler(sig, frame):
# Outputs: node_status, hw_constraints
def task_callback(user_input, node_status, hw_constraints):

# Callback implementation here
# Default values
hw_req = "PIM_AI_1chip"
mem_footprint = 100

hw_constraints.max_memory_footprint(100)
# Check if extra data has been sent
if user_input.extra_data().size() != 0:
buffer = ctypes.c_ubyte * user_input.extra_data().size()
buffer = buffer.from_address(int(user_input.extra_data().get_buffer()))
extra_data = np.frombuffer(buffer, dtype=np.uint8)
extra_data_str = extra_data.tobytes().decode('utf-8', errors='ignore')
try:
json_obj = json.loads(extra_data_str)
if json_obj is not None:
mem_footprint = int(json_obj["max_memory_footprint"])
hw_req = json_obj["hardware_required"]
except:
print("Extra data is not a valid JSON object, using default values")

# TODO parse other possible data hidden in the extra_data field, if any
# TODO populate the hw_constraints object with the required data

hw_constraints.max_memory_footprint(mem_footprint)
hw_constraints.hardware_required([hw_req])

# Main workflow routine
def run():
Expand Down

0 comments on commit 5d0582c

Please sign in to comment.