Samsung/ONE

[onert] Revise observers

hseok-oh opened this issue · 3 comments

What

  • Revise execution observer's creation and registration
  • Introduce APIs to use observers

Why

  • Create and/or register observers on execution, not compilation
    • More flexible observation: enable on sampled inferences, disable after requirement fulfilled
  • Require APIs to enable minmax recording observer for on-device full quantization
    • Not just for debugging

Draft: #13013

ExecutionObserver implementation status

  • ProfileObserver
    • Defined in runtime/onert/core/src/exec/ExecutionObservers.h
    • Related config: PROFILING_MODE (bool), CompilerOptions::he_profiling_mode
    • Support dataflow executor only (not linear, parallel executor)
    • Model type
      • Don't support multimodel
      • Support training
    • Require additional compile option
      • Need to enable heterogenous scheduler
        • USE_SCHEDULER (bool), CompilerOptions::he_scheduler
      • Add sync function for every operation on executor
  • TracingObserver
    • Defined in runtime/onert/core/src/exec/ExecutionObservers.h
    • Related config: TRACE_FILEPATH (string), CompilerOptions::trace_filepath
    • Support all executor
    • Model type
      • Support multimodel and training
  • MinMaxRecorder
    • Defined in runtime/onert/core/src/exec/MinMaxRecorder.h
    • Related config: MINMAX_FILEPATH (string), CompilerOptions::minmax_filepath
    • Support linear executor only (not dataflow, parallel executor)
    • Model type
      • Don't support multimodel and training

Compile / Execution configuration API

  • Enum value for configuration feature key
  • Set API: feature key, value (optional)
  • Reset all API

01eb31e#diff-30f63142d4c553c3758435142ec90439942da99e9f67101e3ce6cf1abc955030

/**
 * @brief Configuration key for prepare (compile and schedule)
 */
typedef enum
{
  /**
   * Prepare to dump execution time profile file (not require value setting)
   * TODO: Use workspace
   */
  NNFW_PREPARE_CONFIG_PROFILE,
} NNFW_PREPARE_CONFIG;

/**
 * @brief      Set prepare configuration
 *
 * This function set prepare configuration to decide additional compiling and scheduing feature.
 * If you enable configuration to prepare dumping execution data into workspace,
 * {@link nnfw_set_workspace} should be invoked before {@link nnfw_prepare} is invoked.
 *
 * @param[in] session nnfw_session to set prepare configuration
 * @param[in] key     prepare configuration key
 * @param[in] value   prepare configuration value
 * @return    @c NNFW_STATUS_NO_ERROR if successful
 */
NNFW_STATUS nnfw_set_prepare_config(nnfw_session *session, NNFW_PREPARE_CONFIG key,
                                    const char *value);

/**
 * @brief     Reset prepare configurations
 *
 * This function reset all prepare configuration.
 *
 * @param[in] session nnfw_session to reset all prepare configurations
 * @return    @c NNFW_STATUS_NO_ERROR if successful
 */
NNFW_STATUS nnfw_reset_prepare_config(nnfw_session *session);

/**
 * @brief Configuration key for execution
 */
typedef enum
{
  /** Dump minmax data for each layers to workspace (not require value setting) */
  NNFW_RUN_CONFIG_DUMP_MINMAX,
  /** Dump execution event file to workspace (not require value setting) */
  NNFW_RUN_CONFIG_TRACE,
  /**
   * Dump execution time profile file (not require value setting)
   *
   * You should set prepare configuration NNFW_PREPARE_CONFIG_DUMP_PROFILE before prepare.
   * Otherwise, this configuration will be ignored.
   *
   * TODO: Use workspace
   */
  NNFW_RUN_CONFIG_PROFILE,
} NNFW_RUN_CONFIG;

/**
 * @brief     Set execution (run or train) configuration
 *
 * This function set execution configuration to dump execution data to workspace.
 * If you enable configuration to dump execution data into workspace,
 * {@link nnfw_set_workspace} should be invoked before {@link nnfw_run} or {@link nnfw_train} is
 * invoked.
 *
 * @param[in] session nnfw_session to set execution configuration
 * @param[in] key     execution configuration key
 * @param[in] value   execution configuration value if needed, otherwise set NULL
 * @return    @c NNFW_STATUS_NO_ERROR if successful
 */
NNFW_STATUS nnfw_set_execution_config(nnfw_session *session, const NNFW_RUN_CONFIG key,
                                      const char *value);

/**
 * @brief     Reset execution (run or train) configurations
 *
 * This function reset all execution configuration.
 *
 * @param[in] session nnfw_session to reset all execution configurations
 * @return    @c NNFW_STATUS_NO_ERROR if successful
 */
NNFW_STATUS nnfw_reset_exection_config(nnfw_session *session);

Done