# ACL **Repository Path**: chen-junhao1234/acl ## Basic Information - **Project Name**: ACL - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-08-19 - **Last Updated**: 2026-03-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README 静态图 Profiling 过滤 - 需要修改的文件清单 当前 PR 的问题 当前 PR 中 ParseProfilingCallbackFilter 是从 config_para 字符串参数中解析 "taskinfo" 和 "scale",这不对。应该从 MsprofCommandHandle.profSwitch 的 bit 位判断。 --- 1. runtime/v1/common/profiling/command_handle.cc 问题: PROF_SCALE_MASK 被注释掉了,需要恢复。 // 第 36 行附近 - 恢复宏定义 constexpr uint64_t PROF_SCALE_MASK = 0x0000200000000ULL; // 恢复函数 bool IsProfScaleMaskEnabled(const MsprofCommandHandle &prof_command_handle) { return (prof_command_handle.profSwitch & PROF_SCALE_MASK) != 0; } 新增判断逻辑 (在 HandleCtrlSwitch 中): // 在调用 ExecuteCommand 之前,传递 profSwitch 信息到 ProfilingProperties if (IsProfScaleMaskEnabled(prof_command_handle)) { ProfilingProperties::Instance().SetHasScaleMask(true); } --- 2. runtime/v1/common/profiling/profiling_manager.cc 问题: ParseProfilingCallbackFilter 需要接收 module 参数来判断 bit 位。 // 修改函数签名,增加 module 参数 void ProfilingManager::ParseProfilingCallbackFilter(const uint64_t module, const std::map &config_para) { OpProfilingFilter filter; bool has_op_type = false; bool has_op_name = false; // 从 module bit 位判断是否有 taskinfo(L0/L1/L2) constexpr uint64_t PROF_TASK_INFO_MASKS = 0x0000000000010ULL | // L0 (假设值) 0x0000000000020ULL | // L1 (假设值) 0x0000000000040ULL; // L2 (假设值) bool has_taskinfo = (module & PROF_TASK_INFO_MASKS) != 0; bool has_scale = (module & PROF_SCALE_MASK) != 0; // 解析 opType/opName(如果有配置) for (const auto ¶ : config_para) { // ... 解析 opType/opName 到 filter.op_types 和 filter.op_names } // 同时有 taskinfo bit 和 scale bit 时,启用过滤 if (has_taskinfo && has_scale) { filter.has_filter = true; ProfilingProperties::Instance().SetOpProfilingFilter(filter); GELOGI("Op profiling filter enabled by profSwitch taskinfo+scale."); } } // 调用处 - 传入 module 参数 ParseProfilingCallbackFilter(module, config_para); --- 3. base/common/profiling/profiling_properties.h 新增: 存储是否有 scale mask 的标志 class ProfilingProperties { public: // ... 现有接口 void SetHasScaleMask(bool has_scale_mask) { has_scale_mask_ = has_scale_mask; } bool HasScaleMask() const { return has_scale_mask_; } private: OpProfilingFilter op_profiling_filter_; bool has_scale_mask_ = false; // 新增 }; --- 4. base/common/profiling/profiling_properties.cc 修改: IsOpProfilingEnabled 调用 MsprofCheckOpSwitch 接口 bool ProfilingProperties::IsOpProfilingEnabled(const std::string &op_type, const std::string &op_name) const { const std::lock_guard lock(mutex_); // 如果没有启用过滤器,默认使能 if (!op_profiling_filter_.has_filter) { return true; } // 先检查 opType/opName 是否匹配配置的过滤列表 bool op_match = false; if (!op_type.empty() && op_profiling_filter_.op_types.find(op_type) != op_profiling_filter_.op_types.end()) { op_match = true; } if (!op_name.empty() && op_profiling_filter_.op_names.find(op_name) != op_profiling_filter_.op_names.end()) { op_match = true; } if (!op_match) { return false; // 不在过滤列表中,不使能 } // 调用 profiling 组件提供的接口进一步判断 // TODO: type 参数需要根据 L0/L1/L2 等级别设置 extern "C" bool MsprofCheckOpSwitch(uint32_t type, const char *op, size_t len); return MsprofCheckOpSwitch(0, op_name.c_str(), op_name.length()); } --- 5. runtime/v1/graph/load/model_manager/task_info/fe/kernel_task_info.cc 当前修改基本正确,但需要增加 Prof Tag 设置 Status KernelTaskInfo::DistributeAicoreTask() { // ... 现有代码 ... // 检查算子是否需要profiling(根据opType/opName过滤) const auto &op_filter = ProfilingProperties::Instance().GetOpProfilingFilter(); bool is_op_profiling_enabled = ProfilingProperties::Instance().IsOpProfilingEnabled( op_desc_->GetType(), op_desc_->GetName()); if (op_filter.has_filter) { cfg_.enableprofiling = is_op_profiling_enabled ? 1 : 0; // 新增:配置 prof tag 给 runtime if (is_op_profiling_enabled) { // 调用 rtSetTaskTag 设置 prof tag const rtError_t ret = rtSetTaskTag(op_name.c_str()); if (ret != RT_ERROR_NONE) { GELOGW("[SetTaskTag] failed for op: %s, ret: 0x%X", op_name.c_str(), ret); } } GELOGD("Op: %s (type: %s) profiling %s due to filter", op_name.c_str(), op_desc_->GetTypePtr(), is_op_profiling_enabled ? "enabled" : "disabled"); } else { cfg_.enableprofiling = 1; } // ... 现有代码 ... } --- 6. runtime/v1/graph/load/model_manager/davinci_model.cc 当前修改正确,无需修改 ReportTaskTimeL0Info 和 ReportTaskTimeL1Info 中的过滤逻辑已经实现了只上报匹配算子的 taskinfo。 // 获取profiling过滤器 const auto &op_filter = ProfilingProperties::Instance().GetOpProfilingFilter(); bool filter_enabled = op_filter.has_filter; // 如果启用了过滤器,检查是否匹配 if (filter_enabled) { if (!ProfilingProperties::Instance().IsOpProfilingEnabled(node_basic_info.op_type, node_basic_info.op_name)) { GELOGD("Skip reporting l1 info for op: %s (type: %s) due to filter", node_basic_info.op_name.c_str(), node_basic_info.op_type.c_str()); continue; } } // 获取profiling过滤器 const auto &op_filter = ProfilingProperties::Instance().GetOpProfilingFilter(); bool filter_enabled = op_filter.has_filter; // 如果启用了过滤器,检查是否匹配 // 注意:context_info_id中可能没有直接的op_type信息,需要根据op_name来判断 if (filter_enabled) { if (!ProfilingProperties::Instance().IsOpProfilingEnabled("", context_info_id.op_name)) { GELOGD("Skip reporting l0 context info for op: %s due to filter", context_info_id.op_name.c_str()); continue; } } // 如果启用了过滤器,检查是否匹配 if (filter_enabled) { if (!ProfilingProperties::Instance().IsOpProfilingEnabled(launch_api.op_type, launch_api.op_name)) { GELOGD("Skip reporting l0 launch api for op: %s (type: %s) due to filter", launch_api.op_name.c_str(), launch_api.op_type.c_str()); continue; } } --- 7. 其他 TaskInfo 子类(如果需要) 文件: - runtime/v1/graph/load/model_manager/task_info/aicpu/kernel_ex_task_info.cc - runtime/v1/graph/load/model_manager/task_info/fe/fusion_task_info.cc - runtime/v1/graph/load/model_manager/task_info/fe/dsa_task_info.cc - runtime/v1/graph/load/model_manager/task_info/fe/super_kernel_task_info.cc 修改: 参考 KernelTaskInfo::DistributeAicoreTask 的模式,在类似位置增加过滤逻辑 --- 总结 ┌─────────────────────────┬───────────┬───────────────────────────────────────────────────────────────────────────────┐ │ 文件 │ 修改类型 │ 内容 │ ├─────────────────────────┼───────────┼───────────────────────────────────────────────────────────────────────────────┤ │ command_handle.cc │ 恢复/新增 │ PROF_SCALE_MASK 宏定义、IsProfScaleMaskEnabled 函数、设置 has_scale_mask 标志 │ ├─────────────────────────┼───────────┼───────────────────────────────────────────────────────────────────────────────┤ │ profiling_manager.h │ 新增 │ SetHasScaleMask/HasScaleMask 接口 │ ├─────────────────────────┼───────────┼───────────────────────────────────────────────────────────────────────────────┤ │ profiling_manager.cc │ 修改 │ ParseProfilingCallbackFilter 从 module bit 位判断 │ ├─────────────────────────┼───────────┼───────────────────────────────────────────────────────────────────────────────┤ │ profiling_properties.h │ 新增 │ has_scale_mask_ 成员变量 │ ├─────────────────────────┼───────────┼───────────────────────────────────────────────────────────────────────────────┤ │ profiling_properties.cc │ 修改 │ IsOpProfilingEnabled 调用 MsprofCheckOpSwitch │ ├─────────────────────────┼───────────┼───────────────────────────────────────────────────────────────────────────────┤ │ kernel_task_info.cc │ 新增 │ 过滤时设置 rtSetTaskTag │ ├─────────────────────────┼───────────┼───────────────────────────────────────────────────────────────────────────────┤ │ davinci_model.cc │ 无需修改 │ 当前 PR 修改已正确 │ └─────────────────────────┴───────────┴───────────────────────────────────────────────────────────────────────────────┘