{
  "name": "Model Runner",
  "status": "experimental",
  "shortId": "modelrunner",
  "camelName": "modelRunner",
  "shortName": "modelRunner",
  "extends": [
    "_base"
  ],
  "notes": {
    "short": "Runs machine learning models.\n\nOnly models with a single input tensor and a single output tensor are supported at the moment.\nInput is provided by Sensor Aggregator service on the same device.\nMultiple instances of this service may be present, if more than one model format is supported by a device."
  },
  "classIdentifier": 336566904,
  "enums": {
    "ModelFormat": {
      "name": "ModelFormat",
      "storage": 4,
      "members": {
        "TFLite": 860636756,
        "ML4F": 809963362,
        "EdgeImpulseCompiled": 810961221
      }
    }
  },
  "constants": {},
  "packets": [
    {
      "kind": "report",
      "name": "command_not_implemented",
      "identifier": 3,
      "description": "This report may be emitted by a server in response to a command (action or register operation)\nthat it does not understand.\nThe `service_command` and `packet_crc` fields are copied from the command packet that was unhandled.\nNote that it's possible to get an ACK, followed by such an error report.",
      "fields": [
        {
          "name": "service_command",
          "type": "u16",
          "storage": 2,
          "isSimpleType": true
        },
        {
          "name": "packet_crc",
          "type": "u16",
          "storage": 2,
          "isSimpleType": true
        }
      ],
      "identifierName": "command_not_implemented",
      "packFormat": "u16 u16",
      "derived": "_base"
    },
    {
      "kind": "const",
      "name": "instance_name",
      "identifier": 265,
      "description": "A friendly name that describes the role of this service instance in the device.\nIt often corresponds to what's printed on the device:\nfor example, `A` for button A, or `S0` for servo channel 0.\nWords like `left` should be avoided because of localization issues (unless they are printed on the device).",
      "fields": [
        {
          "name": "_",
          "type": "string",
          "storage": 0
        }
      ],
      "optional": true,
      "identifierName": "instance_name",
      "packFormat": "s",
      "derived": "_base"
    },
    {
      "kind": "ro",
      "name": "status_code",
      "identifier": 259,
      "description": "Reports the current state or error status of the device. ``code`` is a standardized value from \nthe Jacdac status/error codes. ``vendor_code`` is any vendor specific error code describing the device\nstate. This report is typically not queried, when a device has an error, it will typically\nadd this report in frame along with the announce packet. If a service implements this register,\nit should also support the ``status_code_changed`` event defined below.",
      "fields": [
        {
          "name": "code",
          "type": "u16",
          "storage": 2,
          "isSimpleType": true
        },
        {
          "name": "vendor_code",
          "type": "u16",
          "storage": 2,
          "isSimpleType": true
        }
      ],
      "optional": true,
      "identifierName": "status_code",
      "packFormat": "u16 u16",
      "derived": "_base"
    },
    {
      "kind": "rw",
      "name": "client_variant",
      "identifier": 9,
      "description": "An optional register in the format of a URL query string where the client can provide hints how\nthe device twin should be rendered. If the register is not implemented, the client library can simulate the register client side.",
      "fields": [
        {
          "name": "_",
          "type": "string",
          "storage": 0
        }
      ],
      "optional": true,
      "identifierName": "client_variant",
      "packFormat": "s",
      "derived": "_base"
    },
    {
      "kind": "event",
      "name": "status_code_changed",
      "identifier": 4,
      "description": "Notifies that the status code of the service changed.",
      "fields": [
        {
          "name": "code",
          "type": "u16",
          "storage": 2,
          "isSimpleType": true
        },
        {
          "name": "vendor_code",
          "type": "u16",
          "storage": 2,
          "isSimpleType": true
        }
      ],
      "optional": true,
      "identifierName": "status_code_changed",
      "packFormat": "u16 u16",
      "derived": "_base"
    },
    {
      "kind": "command",
      "name": "set_model",
      "identifier": 128,
      "description": "Open pipe for streaming in the model. The size of the model has to be declared upfront.\nThe model is streamed over regular pipe data packets.\nThe format supported by this instance of the service is specified in `format` register.\nWhen the pipe is closed, the model is written all into flash, and the device running the service may reset.",
      "fields": [
        {
          "name": "model_size",
          "unit": "B",
          "type": "u32",
          "storage": 4,
          "isSimpleType": true
        }
      ],
      "unique": true,
      "hasReport": true,
      "packFormat": "u32"
    },
    {
      "kind": "report",
      "name": "set_model",
      "identifier": 128,
      "description": "Open pipe for streaming in the model. The size of the model has to be declared upfront.\nThe model is streamed over regular pipe data packets.\nThe format supported by this instance of the service is specified in `format` register.\nWhen the pipe is closed, the model is written all into flash, and the device running the service may reset.",
      "fields": [
        {
          "name": "model_port",
          "type": "pipe_port",
          "storage": 2
        }
      ],
      "secondary": true,
      "pipeType": "set_model",
      "packFormat": "u16"
    },
    {
      "kind": "command",
      "name": "predict",
      "identifier": 129,
      "description": "Open channel that can be used to manually invoke the model. When enough data is sent over the `inputs` pipe, the model is invoked,\nand results are send over the `outputs` pipe.",
      "fields": [
        {
          "name": "outputs",
          "type": "pipe",
          "storage": 12
        }
      ],
      "pipeType": "predict",
      "hasReport": true,
      "packFormat": "b[12]"
    },
    {
      "kind": "report",
      "name": "predict",
      "identifier": 129,
      "description": "Open channel that can be used to manually invoke the model. When enough data is sent over the `inputs` pipe, the model is invoked,\nand results are send over the `outputs` pipe.",
      "fields": [
        {
          "name": "inputs",
          "type": "pipe_port",
          "storage": 2
        }
      ],
      "secondary": true,
      "pipeType": "predict",
      "packFormat": "u16"
    },
    {
      "kind": "rw",
      "name": "auto_invoke_every",
      "identifier": 128,
      "description": "When register contains `N > 0`, run the model automatically every time new `N` samples are collected.\nModel may be run less often if it takes longer to run than `N * sampling_interval`.\nThe `outputs` register will stream its value after each run.\nThis register is not stored in flash.",
      "fields": [
        {
          "name": "_",
          "type": "u16",
          "storage": 2,
          "isSimpleType": true
        }
      ],
      "packFormat": "u16"
    },
    {
      "kind": "ro",
      "name": "outputs",
      "identifier": 257,
      "description": "Results of last model invocation as `float32` array.",
      "fields": [
        {
          "name": "output",
          "isFloat": true,
          "type": "f32",
          "storage": 4,
          "startRepeats": true
        }
      ],
      "volatile": true,
      "identifierName": "reading",
      "packFormat": "r: f32"
    },
    {
      "kind": "ro",
      "name": "input_shape",
      "identifier": 384,
      "description": "The shape of the input tensor.",
      "fields": [
        {
          "name": "dimension",
          "type": "u16",
          "storage": 2,
          "isSimpleType": true,
          "startRepeats": true
        }
      ],
      "packFormat": "r: u16"
    },
    {
      "kind": "ro",
      "name": "output_shape",
      "identifier": 385,
      "description": "The shape of the output tensor.",
      "fields": [
        {
          "name": "dimension",
          "type": "u16",
          "storage": 2,
          "isSimpleType": true,
          "startRepeats": true
        }
      ],
      "packFormat": "r: u16"
    },
    {
      "kind": "ro",
      "name": "last_run_time",
      "identifier": 386,
      "description": "The time consumed in last model execution.",
      "fields": [
        {
          "name": "_",
          "unit": "us",
          "type": "u32",
          "storage": 4,
          "isSimpleType": true
        }
      ],
      "packFormat": "u32"
    },
    {
      "kind": "ro",
      "name": "allocated_arena_size",
      "identifier": 387,
      "description": "Number of RAM bytes allocated for model execution.",
      "fields": [
        {
          "name": "_",
          "unit": "B",
          "type": "u32",
          "storage": 4,
          "isSimpleType": true
        }
      ],
      "packFormat": "u32"
    },
    {
      "kind": "ro",
      "name": "model_size",
      "identifier": 388,
      "description": "The size of the model in bytes.",
      "fields": [
        {
          "name": "_",
          "unit": "B",
          "type": "u32",
          "storage": 4,
          "isSimpleType": true
        }
      ],
      "packFormat": "u32"
    },
    {
      "kind": "ro",
      "name": "last_error",
      "identifier": 389,
      "description": "Textual description of last error when running or loading model (if any).",
      "fields": [
        {
          "name": "_",
          "type": "string",
          "storage": 0
        }
      ],
      "packFormat": "s"
    },
    {
      "kind": "const",
      "name": "format",
      "identifier": 390,
      "description": "The type of ML models supported by this service.\n`TFLite` is flatbuffer `.tflite` file.\n`ML4F` is compiled machine code model for Cortex-M4F.\nThe format is typically present as first or second little endian word of model file.",
      "fields": [
        {
          "name": "_",
          "type": "ModelFormat",
          "storage": 4
        }
      ],
      "packFormat": "u32"
    },
    {
      "kind": "const",
      "name": "format_version",
      "identifier": 391,
      "description": "A version number for the format.",
      "fields": [
        {
          "name": "_",
          "type": "u32",
          "storage": 4,
          "isSimpleType": true
        }
      ],
      "packFormat": "u32"
    },
    {
      "kind": "const",
      "name": "parallel",
      "identifier": 392,
      "description": "If present and true this service can run models independently of other\ninstances of this service on the device.",
      "fields": [
        {
          "name": "_",
          "type": "bool",
          "storage": 1
        }
      ],
      "optional": true,
      "packFormat": "u8"
    }
  ],
  "tags": []
}