Skip to content

File ns_debug_log.cc

FileList > neuralSPOT > neuralspot > ns-harness > src > ns_debug_log.cc

Go to the source code of this file

  • #include "ns_debug_log.h"
  • #include "tensorflow/lite/micro/cortex_m_generic/debug_log_callback.h"
  • #include "ns_ambiqsuite_harness.h"
  • #include "ns_pmu_map.h"
  • #include "ns_pmu_utils.h"
  • #include <cstring>
  • #include <cstdio>

Public Functions

Type Name
void ns_TFDebugLog (const char * s)
void ns_TFDebugLogInit (ns_debug_log_init_t * cfg)
uint32_t ns_characterize_model (invoke_fp func)
Given a model, characterize it by running it repeatedly and capturing PMU events.
uint32_t ns_get_layer_counters (uint32_t layer, uint32_t num_layers, uint32_t rv, uint32_t * out_counters)
Retrieves PMU counters for a given layer.
uint32_t ns_parse_pmu_stats (uint32_t num_layers, uint32_t rv)
Parses and prints performance monitoring unit (PMU) statistics for each layer.
uint32_t ns_set_pmu_header (void)
Searches for the "CALL_ONCE" layer in the global profiler stats array.

Public Functions Documentation

function ns_TFDebugLog

void ns_TFDebugLog (
    const char * s
) 

function ns_TFDebugLogInit

void ns_TFDebugLogInit (
    ns_debug_log_init_t * cfg
) 

function ns_characterize_model

Given a model, characterize it by running it repeatedly and capturing PMU events.

uint32_t ns_characterize_model (
    invoke_fp func
) 

Returns:

uint32_t


function ns_get_layer_counters

Retrieves PMU counters for a given layer.

uint32_t ns_get_layer_counters (
    uint32_t layer,
    uint32_t num_layers,
    uint32_t rv,
    uint32_t * out_counters
) 

This function determines if the layer is within a "skip" range for PMU counters (related to CALL_ONCE), then either returns zeros or calculates the counters based on the "non-obvious" index formula:

index = (num_layers + source_layer) + (source_layer_count) * (map_index / 4);
counterValue = ns_microProfilerSidecar.pmu_snapshot[index].counterValue[ map_index % 4 ];

Parameters:

  • layer The layer index for which PMU values are requested.
  • num_layers Total layers in the pipeline.
  • rv Number of "resource variables" used to offset certain layers.
  • out_counters Pointer to an array in which to store the retrieved counter values.
  • max_counters Size of the out_counters array (e.g. number of PMU registers).

Returns:

NS_STATUS_SUCCESS on success. Could return an error code if desired.


function ns_parse_pmu_stats

Parses and prints performance monitoring unit (PMU) statistics for each layer.

uint32_t ns_parse_pmu_stats (
    uint32_t num_layers,
    uint32_t rv
) 

This function retrieves PMU counter values from a global profiler sidecar and prints them in a CSV-like format for external analysis. It supports the concept of a "CALL_ONCE" layer, whereby certain layers are "skipped" on subsequent runs (and thus display zero counters).

The high-level logic: 1) Search for a layer tagged as "CALL_ONCE". If found, record its index. 2) Print CSV headers, including names of PMU registers. 3) For each layer: * Print basic profiling data (layer index, tag, time, estimated MACs). * Print detailed sidecar information (e.g., output shape, filter shape, strides). * Determine if the layer is in the "skipped" region. If so, print zeros. Otherwise, compute a non-obvious index for accessing PMU counters and print them.

The non-obvious indexing formula for the PMU counters follows:

// source_layer is either the current layer or offset by rv*2 if we are beyond the skip region
uint32_t index = (num_layers + source_layer) + (num_layers - rv * 2) * (map_index / 4);
uint32_t counterValue = ns_microProfilerSidecar.pmu_snapshot[index].counterValue[ map_index % 4 ];

Skipped region logic: * If a CALL_ONCE layer is present at index C, then any layer in the range (C, C + rv*2] prints zero counters.

Parameters:

  • num_layers The total number of layers (including any special layers).
  • rv The number of resource variables, used to determine how many layers get skipped after the CALL_ONCE layer.

Returns:

NS_STATUS_SUCCESS on success.


function ns_set_pmu_header

Searches for the "CALL_ONCE" layer in the global profiler stats array.

uint32_t ns_set_pmu_header (
    void
) 

This function scans through all layers to see if any layer is tagged "CALL_ONCE". If found, the layer index is returned. If not, returns -1.

Parameters:

  • num_layers The total number of layers in the model or pipeline.

Returns:

Index of the CALL_ONCE layer if found, otherwise -1.



The documentation for this class was generated from the following file neuralSPOT/neuralspot/ns-harness/src/ns_debug_log.cc