Repository: microsoft/onnxruntime
File: onnxruntime/core/providers/qnn/builder/qnn_backend_manager.h (C/C++)

Code before:
  ~QnnBackendManager();

  std::unique_ptr<unsigned char[]> GetContextBinaryBuffer(uint64_t& written_buffer_size);

  Status LoadCachedQnnContextFromBuffer(char* buffer, uint64_t buffer_length,
                                        std::string node_name,
                                        std::unordered_map<std::string, std::unique_ptr<qnn::QnnModel>>& qnn_models,
                                        int64_t max_spill_fill_size);

  // Initializes handles to QNN resources (device, logger, etc.).
  // NOTE: This function locks the internal `logger_recursive_mutex_`.
  Status SetupBackend(const logging::Logger& logger, bool load_from_cached_context,
                      bool need_load_system_lib, bool share_ep_contexts,
                      bool enable_vtcm_backup_buffer_sharing,
                      std::unordered_map<std::string, std::unique_ptr<std::vector<std::string>>>& context_bin_map);

  Status CreateHtpPowerCfgId(uint32_t deviceId, uint32_t coreId, uint32_t& htp_power_config_id);

  Status SetHtpPowerConfig(uint32_t htp_power_config_client_id,
                           HtpPerformanceMode htp_performance_mode);

  Status SetRpcPowerConfigs(uint32_t htp_power_config_client_id,
                            uint32_t rpc_control_latency,
                            uint32_t rpc_polling_time);

  Status SetPerThreadHtpPowerConfigs(const std::thread::id& theard_id, bool post_run);

  Status AddPerThreadHtpPowerConfigMapping(const std::thread::id& thread_id,
                                           const PerThreadHtpPowerConfigs_t& htp_power_configs);

  void RemovePerThreadHtpPowerConfigs(const std::thread::id& thread_id);

  const QNN_INTERFACE_VER_TYPE& GetQnnInterface() { return qnn_interface_; }

  const Qnn_ContextHandle_t& GetQnnContext(int index = 0) {
    ORT_ENFORCE((contexts_.size() > 0) && (static_cast<size_t>(index) < contexts_.size()), "No valid QNN context!");
    return contexts_[index];
  }

  size_t GetQnnContextSize() {
    return contexts_.size();
  }

  const Qnn_BackendHandle_t& GetQnnBackendHandle() { return backend_handle_; }

  const Qnn_ProfileHandle_t& GetQnnProfileHandle() { return profile_backend_handle_; }

  // Resets the QNN log level to the given ORT log level or to the default log level if the argument is
  // std::nullopt.
  // NOTE: This function locks the internal `logger_recursive_mutex_`.
  Status ResetQnnLogLevel(std::optional<logging::Severity> ort_log_level = std::nullopt);

Review comment (suggestion):
```suggestion
  Status SetPerThreadHtpPowerConfigs(const std::thread::id& thread_id, bool pre_run);
```

Code after:
  ~QnnBackendManager();

  std::unique_ptr<unsigned char[]> GetContextBinaryBuffer(uint64_t& written_buffer_size);

  Status LoadCachedQnnContextFromBuffer(char* buffer, uint64_t buffer_length,
                                        std::string node_name,
                                        std::unordered_map<std::string, std::unique_ptr<qnn::QnnModel>>& qnn_models,
                                        int64_t max_spill_fill_size);

  // Initializes handles to QNN resources (device, logger, etc.).
  // NOTE: This function locks the internal `logger_recursive_mutex_`.
  Status SetupBackend(const logging::Logger& logger, bool load_from_cached_context,
                      bool need_load_system_lib, bool share_ep_contexts,
                      bool enable_vtcm_backup_buffer_sharing,
                      std::unordered_map<std::string, std::unique_ptr<std::vector<std::string>>>& context_bin_map);

  Status CreateHtpPowerCfgId(uint32_t deviceId, uint32_t coreId, uint32_t& htp_power_config_id);

  Status SetHtpPowerConfig(uint32_t htp_power_config_client_id,
                           HtpPerformanceMode htp_performance_mode);

  Status SetRpcPowerConfigs(uint32_t htp_power_config_client_id,
                            uint32_t rpc_control_latency,
                            uint32_t rpc_polling_time);

  Status SetPerThreadHtpPowerConfigs(const std::thread::id& thread_id, bool pre_run);

  Status AddPerThreadHtpPowerConfigMapping(const std::thread::id& thread_id,
                                           const PerThreadHtpPowerConfigs_t& htp_power_configs);

  void RemovePerThreadHtpPowerConfigMapping(const std::thread::id& thread_id);

  const QNN_INTERFACE_VER_TYPE& GetQnnInterface() { return qnn_interface_; }

  const Qnn_ContextHandle_t& GetQnnContext(int index = 0) {
    ORT_ENFORCE((contexts_.size() > 0) && (static_cast<size_t>(index) < contexts_.size()), "No valid QNN context!");
    return contexts_[index];
  }

  size_t GetQnnContextSize() {
    return contexts_.size();
  }

  const Qnn_BackendHandle_t& GetQnnBackendHandle() { return backend_handle_; }

  const Qnn_ProfileHandle_t& GetQnnProfileHandle() { return profile_backend_handle_; }

  // Resets the QNN log level to the given ORT log level or to the default log level if the argument is
  // std::nullopt.
  // NOTE: This function locks the internal `logger_recursive_mutex_`.
  Status ResetQnnLogLevel(std::optional<logging::Severity> ort_log_level = std::nullopt);