// Copyright (C) 2023-2025 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
include "fileHeader.fbs";
include "structure.fbs";
include "memoryManagement.fbs";
include "dma.fbs";
include "nnController.fbs";
include "nnNCE2.fbs";
include "upaNCE.fbs";
include "actKernel.fbs";
include "software.fbs";
include "m2i.fbs";

namespace MVCNN;

// The "magic" values at the start of the file, that identify a file as a graphfile.
file_identifier "BLOB";
// The file extension a generated file will take.
file_extension "blob";

table GraphFile {

    /// Overview:
    ///    This is the "root" object of the file. Start here and traverse into different objects
    ///    while reading.
    ///
    ///

    // This object contains meta information about the graph contained inside this file.
    header: SummaryHeader;

    // This is the sets of work that need to be completed by the VPU to complete an inference
    task_lists: [TaskList];

    /// A list of barriers to be consumed by the device for its own scheduling.
    /// If you are manually scheduling barriers with leon tasks, you do not need to
    /// populate this field.
    barrier_table: [Barrier];

    // The binary_data section contains all, well, all of the binary data in the file.
    // This would include things like weights, biases, etc.

    // Technical Note: The "force_align" here may not be functional until later releases of FlatBuffers.
    binary_data: [BinaryData] (force_align:64);

    // The kernel_data section contains all, kernel data in the file.
    // This would generally includes entire ELFs of the activation kernels, although they are
    // pre-parsed with offsets into the ELF (for .text, code entry, .data, etc.) already baked into the
    // schedule. [see actKernel.fbs]

    // Technical Note: The "force_align" here may not be functional until later releases of FlatBuffers.
    kernel_data: [KernelData] (force_align:64);
}


table TaskList{
  // A Tasklist must only contain Tasks of the same type.
  // These lists can be then given to the relevant processing code of the VPU and sent for dispatch.
  content: [Task];

  // In the case of multiple schedules, multiple networks, or other such scenarios where there may be
  // several TaskLists of a similar type, the groupIdentifier is used to distinguish between these sets.
  groupIdentifier: uint;
}

union SpecificTask{
    MvTensorTask,       // Only for backward compatibility
    NNDMATask,
    NCE1Task,           // Only for backward compatibility
    NCE2Task,
    NNTensorTask,       // Only for backward compatibility
    ControllerTask,
    SNNLayerTask,
    ActKernelTask,
    GenericTask,
    M2ITask
}

table Task{
    name: string; // Field for easier debug

    // Unique Task Identifier
    nodeID: uint;

    // Id of related GraphNode (see Structure.fbs)
    sourceTaskIDs: [uint];

    // Note here that this barrier reference is to a Task, not any 'subtasks' or similar.
    // These must be detailed at that level instead.
    associated_barriers: BarrierReference;

    // The details of a task, that are particular to the type of task represented.
    task: SpecificTask;
}

table GenericTask{
    cost: long;   // Cycles to process
    clock: long;   // Based on clock
}


// This line just tells FlatBuffers to start with this object when parsing.
// As a human, you would already understand more of the schema at this point than the robots
// because you were reading my comments from the start of the file :)
root_type GraphFile;
