@@ -19,8 +19,20 @@ QnnProfile::QnnProfile(
1919 : handle_(nullptr ), implementation_(implementation), backend_(backend) {
2020 if (profile_level != QnnExecuTorchProfileLevel::kProfileOff ) {
2121 const QnnInterface& qnn_interface = implementation_.GetQnnInterface ();
22+
23+ QnnProfile_Level_t qnnProfileLevel = 0 ;
24+ if (profile_level == QnnExecuTorchProfileLevel::kProfileBasic ) {
25+ qnnProfileLevel = QNN_PROFILE_LEVEL_BASIC;
26+ } else if (profile_level == QnnExecuTorchProfileLevel::kProfileDetailed
27+ || profile_level == QnnExecuTorchProfileLevel::kProfileOptrace ) {
28+ qnnProfileLevel = QNN_PROFILE_LEVEL_DETAILED;
29+ } else {
30+ QNN_EXECUTORCH_LOG_WARN (" Invalid profile level" );
31+ return ;
32+ }
33+
2234 Qnn_ErrorHandle_t error = qnn_interface.qnn_profile_create (
23- backend_->GetHandle (), static_cast < int >(profile_level) , &handle_);
35+ backend_->GetHandle (), qnnProfileLevel , &handle_);
2436 if (error != QNN_SUCCESS) {
2537 QNN_EXECUTORCH_LOG_WARN (
2638 " Failed to create profile_handle for backend "
@@ -31,6 +43,27 @@ QnnProfile::QnnProfile(
3143 // ignore error and continue to create backend handle...
3244 handle_ = nullptr ;
3345 }
46+
47+ if (profile_level == QnnExecuTorchProfileLevel::kProfileOptrace ) {
48+ if (handle_ == nullptr ) {
49+ QNN_EXECUTORCH_LOG_WARN (" Prfoile handle is null, cannot enable optrace" );
50+ return ;
51+ }
52+
53+ QnnProfile_Config_t qnnProfileConfig = QNN_PROFILE_CONFIG_INIT;
54+ qnnProfileConfig.option = QNN_PROFILE_CONFIG_OPTION_ENABLE_OPTRACE;
55+ std::array<const QnnProfile_Config_t*, 2 > profileConfigs = {
56+ &qnnProfileConfig, nullptr };
57+ error = qnn_interface.qnn_profile_set_config (handle_, profileConfigs.data ());
58+
59+ if (error != QNN_SUCCESS) {
60+ QNN_EXECUTORCH_LOG_WARN (
61+ " Failed to set optrace for backend "
62+ " %u, error=%d" ,
63+ qnn_interface.GetBackendId (),
64+ QNN_GET_ERROR_CODE (error));
65+ }
66+ }
3467 }
3568}
3669
0 commit comments