Tasks

Task

class Task : public Object

Abstract base class representing a task to be executed on an accelerator.

Task provides a common interface for all task types. All tasks have common fields for compute demand, I/O sizes, and timing metadata. Derived classes must implement GetName() to identify the task type.

Subclassed by ns3::SimpleTask

Public Functions

virtual uint64_t GetTaskId() const

Get the unique task identifier.

Returns:

The task ID.

void SetTaskId(uint64_t id)

Set the unique task identifier.

Parameters:

id – The task ID.

virtual std::string GetName() const = 0

Get the task type name.

Used for logging and for dispatching tasks to appropriate accelerators or headers.

Returns:

A string identifying the task type (e.g., “SimpleTask”).

uint64_t GetInputSize() const

Get the input data size in bytes.

Returns:

The input size.

void SetInputSize(uint64_t bytes)

Set the input data size in bytes.

Parameters:

bytes – The input size.

uint64_t GetOutputSize() const

Get the output data size in bytes.

Returns:

The output size.

void SetOutputSize(uint64_t bytes)

Set the output data size in bytes.

Parameters:

bytes – The output size.

double GetComputeDemand() const

Get the compute demand in FLOPS.

Returns:

The compute demand.

void SetComputeDemand(double flops)

Set the compute demand in FLOPS.

Parameters:

flops – The compute demand.

virtual Time GetArrivalTime() const

Get the task arrival time.

Returns:

The arrival time.

virtual void SetArrivalTime(Time time)

Set the task arrival time.

Parameters:

time – The arrival time.

bool HasDeadline() const

Check if the task has a deadline.

Returns:

true if deadline is set (>= 0), false otherwise.

Time GetDeadline() const

Get the task deadline.

Returns:

The deadline time. Returns Time(-1) if no deadline.

void SetDeadline(Time deadline)

Set the task deadline.

Parameters:

deadline – The deadline time. Use Time(-1) to clear.

void ClearDeadline()

Clear the task deadline.

uint32_t GetPriority() const

Get the task priority.

Returns:

The priority value. Higher value = higher priority.

void SetPriority(uint32_t priority)

Set the task priority.

Parameters:

priority – The priority value. Higher value = higher priority.

Time GetComputeTime() const

Get the recorded compute time (accelerator execution).

Returns:

The compute time. Returns Time(0) if not set.

void SetComputeTime(Time time)

Set the recorded compute time.

Parameters:

time – The compute time.

Time GetBackendTime() const

Get the recorded backend time (arrival to response, includes queuing + compute).

Returns:

The backend time. Returns Time(0) if not set.

void SetBackendTime(Time time)

Set the recorded backend time.

Parameters:

time – The backend time.

std::string GetRequiredAcceleratorType() const

Get the required accelerator type.

Returns:

The accelerator type string (e.g., “GPU”, “TPU”). Empty string means any accelerator.

void SetRequiredAcceleratorType(const std::string &type)

Set the required accelerator type.

Parameters:

type – The accelerator type (e.g., “GPU”, “TPU”). Empty string means any accelerator.

virtual Ptr<Packet> Serialize(bool isResponse) const = 0

Serialize this task to a packet for network transmission.

Creates a packet containing the task’s header and payload data. Each Task subclass implements this using its corresponding TaskHeader.

Parameters:

isResponse – true for response (output payload), false for request (input payload).

Returns:

A packet ready for transmission.

virtual uint32_t GetSerializedHeaderSize() const = 0

Get the serialized header size for this task type.

Used for TCP stream reassembly to know how many bytes to read before the header can be fully deserialized.

Returns:

Header size in bytes.

virtual uint8_t GetTaskType() const = 0

Get the task type identifier.

Returns a stable 1-byte identifier for this task type. Used by DAG serialization and the EdgeOrchestrator’s task type registry to dispatch deserialization to the correct callback.

Returns:

The task type identifier.

TaskState GetState() const

Get the current lifecycle state.

Returns:

The task state.

void SetState(TaskState newState)

Set the lifecycle state.

Validates the transition is legal. Invalid transitions log a warning and are ignored.

Parameters:

newState – The new state.

Public Static Functions

static TypeId GetTypeId()

Get the type ID.

Returns:

The object TypeId.

SimpleTask

class SimpleTask : public ns3::Task

Concrete task implementation using the common Task fields.

SimpleTask is the basic concrete implementation of Task, providing a task with compute demand, input size, and output size.

Public Functions

virtual std::string GetName() const override

Get the task type name.

Returns:

“SimpleTask”

virtual uint8_t GetTaskType() const override

Get the task type identifier.

Returns:

SimpleTask::TASK_TYPE (0)

virtual Ptr<Packet> Serialize(bool isResponse) const override

Serialize this task to a packet using SimpleTaskHeader.

Parameters:

isResponse – true for response (output payload), false for request (input payload).

Returns:

A packet with SimpleTaskHeader and payload.

virtual uint32_t GetSerializedHeaderSize() const override

Get SimpleTaskHeader size.

Returns:

SimpleTaskHeader::SERIALIZED_SIZE

Public Static Functions

static TypeId GetTypeId()

Get the type ID.

Returns:

The object TypeId.

static Ptr<Task> Deserialize(Ptr<Packet> packet, uint64_t &consumedBytes)

Deserialize a SimpleTask from a packet buffer.

Stream-aware deserialization that handles message boundary detection. Peeks at the header to determine total message size, and only extracts data if a complete message is available.

Parameters:
  • packet – The packet buffer (may contain multiple messages or partial data).

  • consumedBytes – Output: bytes consumed from packet (0 if not enough data).

Returns:

A new SimpleTask, or nullptr if not enough data for complete message.

static Ptr<Task> DeserializeHeader(Ptr<Packet> packet, uint64_t &consumedBytes)

Deserialize a SimpleTask from header bytes only (no payload).

Creates a task with all metadata fields populated but does not expect or consume any payload bytes. Used for DAG admission requests where only task metadata is sent.

Parameters:
  • packet – The packet buffer containing at least one header.

  • consumedBytes – Output: bytes consumed (header size, or 0 if insufficient data).

Returns:

A new SimpleTask, or nullptr if not enough data for header.

Public Static Attributes

static constexpr uint8_t TASK_TYPE = 0

Task type identifier for SimpleTask.

DagTask

class DagTask : public Object

Container for a directed acyclic graph (DAG) of tasks.

DagTask holds multiple Task objects and their dependency edges, enabling scheduling of task graphs where some tasks must complete before others can begin.

DagTask is a container, not a Task itself. It tracks task completion and provides efficient access to ready tasks (those with all dependencies satisfied).

Example (diamond DAG: a->c, b->c):

DagTask dag;
uint32_t a = dag.AddTask(taskA);
uint32_t b = dag.AddTask(taskB);
uint32_t c = dag.AddTask(taskC);
dag.AddDependency(a, c);  // a must complete before c
dag.AddDependency(b, c);  // b must complete before c

// Initially: GetReadyTasks() returns {a, b}
// After MarkCompleted(a): GetReadyTasks() returns {b}
// After MarkCompleted(b): GetReadyTasks() returns {c}

Public Functions

uint32_t AddTask(Ptr<Task> task)

Add a task to the DAG.

Parameters:

task – The task to add.

Returns:

The index of the added task.

void AddDependency(uint32_t fromIdx, uint32_t toIdx)

Add a dependency edge between tasks.

The task at fromIdx must complete before the task at toIdx can start.

Parameters:
  • fromIdx – The index of the predecessor task.

  • toIdx – The index of the successor task.

void AddDataDependency(uint32_t fromIdx, uint32_t toIdx)

Add a data dependency edge between tasks.

Creates an ordering dependency (like AddDependency) and also marks that data flows from the predecessor to the successor. When the predecessor completes, its output size is added to the successor’s input size.

Multiple data predecessors accumulate (outputs are summed).

Parameters:
  • fromIdx – The index of the predecessor task.

  • toIdx – The index of the successor task.

std::vector<uint32_t> GetReadyTasks() const

Get indices of tasks that are ready to execute.

A task is ready if all its dependencies are completed and it hasn’t been completed itself.

Returns:

Vector of ready task indices.

std::vector<uint32_t> GetSinkTasks() const

Get indices of sink tasks (tasks with no successors).

Sink tasks are the final outputs of the DAG - their results should be returned to the client when the DAG completes.

Note

Well-designed workload DAGs typically have a single sink task that aggregates results from upstream tasks. If your DAG has multiple sinks, consider adding an aggregation task to produce a single output.

Returns:

Vector of sink task indices (usually contains one element).

void MarkCompleted(uint32_t idx)

Mark a task as completed.

This decrements the in-degree of all successor tasks.

Parameters:

idx – The index of the completed task.

Ptr<Task> GetTask(uint32_t idx) const

Get a task by index.

Parameters:

idx – The task index.

Returns:

The task, or nullptr if index is invalid.

int32_t GetTaskIndex(uint64_t taskId) const

Get the index of a task by its task ID.

Parameters:

taskId – The task ID to search for.

Returns:

The task index, or -1 if not found.

bool SetTask(uint32_t idx, Ptr<Task> task)

Update a task at the given index.

Used to replace original task with response data after execution.

Parameters:
  • idx – The task index.

  • task – The new task to set.

Returns:

true if successful, false if index is invalid.

const std::vector<uint32_t> &GetSuccessors(uint32_t idx) const

Get the successor indices for a task.

Returns the indices of tasks that depend on the given task.

Parameters:

idx – The task index.

Returns:

Vector of successor task indices.

std::vector<uint32_t> GetTopologicalOrder() const

Get a topological ordering of the DAG.

Returns task indices in an order where every task appears before its successors. Uses Kahn’s algorithm.

Returns:

Vector of task indices in topological order.

uint32_t GetTaskCount() const

Get the number of tasks in the DAG.

Returns:

The task count.

bool IsComplete() const

Check if all tasks are completed.

Returns:

true if all tasks are completed.

bool Validate() const

Validate that the DAG has no cycles.

A DAG with cycles cannot be scheduled.

Returns:

true if the DAG is valid (no cycles).

Ptr<Packet> SerializeMetadata() const

Serialize DAG metadata for admission request (Phase 1).

Serializes task headers (no payload data) and graph edges.

Returns:

Packet containing the serialized DAG metadata.

Ptr<Packet> SerializeFullData() const

Serialize full DAG data for data upload (Phase 2).

Serializes complete tasks (headers + payload data) and graph edges.

Returns:

Packet containing the serialized DAG with full data.

Public Static Functions

static TypeId GetTypeId()

Get the type ID.

Returns:

The object TypeId.

static Ptr<DagTask> DeserializeMetadata(Ptr<Packet> packet, Callback<Ptr<Task>, Ptr<Packet>, uint64_t&> deserializer, uint64_t &consumedBytes)

Deserialize DAG metadata from a packet (Phase 1).

Reconstructs a DagTask from metadata-only serialization. Tasks will have metadata but no payload data.

Parameters:
  • packet – The packet containing the serialized DAG metadata.

  • deserializer – Callback to deserialize individual task headers.

  • consumedBytes – Output: total bytes consumed from packet.

Returns:

The deserialized DagTask, or nullptr on failure.

static Ptr<DagTask> DeserializeFullData(Ptr<Packet> packet, Callback<Ptr<Task>, Ptr<Packet>, uint64_t&> deserializer, uint64_t &consumedBytes)

Deserialize full DAG data from a packet (Phase 2).

Reconstructs a DagTask from full serialization. Tasks will have metadata and payload data.

Parameters:
  • packet – The packet containing the serialized DAG data.

  • deserializer – Callback to deserialize individual tasks.

  • consumedBytes – Output: total bytes consumed from packet.

Returns:

The deserialized DagTask, or nullptr on failure.