Skip to content

Ascend/msagent / skills/profiler/ascend-prof-compare

ascend-prof-compare

Verified

Compares two Prof datasets (GPU vs NPU / NPU vs NPU) by auto-installing and calling msprof-analyze compare, then parses the result xlsx into HTML report and Chinese xlsx. Invoke when user provides two prof dirs to compare, or has a compare result xlsx to analyze/translate.

scripts/parsers/operator.py

View on GitHub
"""算子比对解析器(合并 operator_statistic + operator_compare)

分析思路:
- Statistic:按算子名聚合,按 Diff Duration 降序,提取 Top 10,计算集中度
- Detail:关联统计页 Top 算子,提取 Kernel 详情和 Input Shape
"""
from parsers.common import safe_float, safe_int, get_sheet_data


def parse_statistic(wb) -> dict:
    """OperatorCompareStatistic 算子统计比对"""
    headers, rows = get_sheet_data(wb, 'OperatorCompareStatistic')
    if not rows:
        return {'sheet_name': 'OperatorCompareStatistic', 'available': False, 'reason': 'Sheet不存在或为空'}

    operators = []
    for row in rows:
        if len(row) < 8:
            continue
        op_name = row[1].strip() if row[1] else ''
        if not op_name or op_name == 'Operator Name':
            continue
        diff_dur = safe_float(row[6])
        diff_ratio = safe_float(row[7])
        operators.append({
            'name': op_name,
            'base_duration': safe_float(row[2]),
            'base_number': safe_int(row[3]),
            'comp_duration': safe_float(row[4]),
            'comp_number': safe_int(row[5]),
            'diff_duration': diff_dur,
            'diff_ratio': diff_ratio,
            'degraded': diff_dur > 0,
        })

    operators.sort(key=lambda x: x['diff_duration'], reverse=True)
    top10 = operators[:10]

    total_diff = sum(o['diff_duration'] for o in operators)
    top10_diff = sum(o['diff_duration'] for o in top10)
    concentration = abs(top10_diff) / abs(total_diff) * 100 if total_diff != 0 else 0

    degraded_count = sum(1 for o in operators if o['diff_duration'] > 0)
    improved_count = sum(1 for o in operators if o['diff_duration'] < 0)

    return {
        'sheet_name': 'OperatorCompareStatistic',
        'available': True,
        'total_operators': len(operators),
        'degraded_count': degraded_count,
        'improved_count': improved_count,
        'total_diff_duration': round(total_diff, 2),
        'top10': top10,
        'concentration': round(concentration, 1),
        'is_concentrated': concentration > 80,
    }


def parse_compare(wb, top_op_names=None) -> dict:
    """OperatorCompare 算子明细比对"""
    headers, rows = get_sheet_data(wb, 'OperatorCompare')
    if not rows:
        return {'sheet_name': 'OperatorCompare', 'available': False, 'reason': 'Sheet不存在或为空'}

    all_details = []
    for row in rows:
        if len(row) < 13:
            continue
        base_name = row[1].strip() if row[1] else ''
        comp_name = row[6].strip() if row[6] else ''
        op_name = base_name or comp_name
        if not op_name:
            continue
        all_details.append({
            'order': row[0],
            'base_name': base_name,
            'base_shape': row[2],
            'base_type': row[3],
            'base_kernel': row[4],
            'base_duration': safe_float(row[5]),
            'comp_name': comp_name,
            'comp_shape': row[7],
            'comp_type': row[8],
            'comp_kernel': row[9],
            'comp_duration': safe_float(row[10]),
            'diff_duration': safe_float(row[11]),
            'diff_ratio': safe_float(row[12]),
        })

    if top_op_names:
        top_set = set(top_op_names)
        filtered = [d for d in all_details if d['base_name'] in top_set or d['comp_name'] in top_set]
    else:
        all_details.sort(key=lambda x: x['diff_duration'], reverse=True)
        filtered = all_details[:10]

    for d in filtered:
        base_kernels = d['base_kernel'].split('\n') if d['base_kernel'] else []
        comp_kernels = d['comp_kernel'].split('\n') if d['comp_kernel'] else []
        d['base_kernel_count'] = len([k for k in base_kernels if k.strip()])
        d['comp_kernel_count'] = len([k for k in comp_kernels if k.strip()])
        d['kernel_count_changed'] = d['base_kernel_count'] != d['comp_kernel_count']

    return {
        'sheet_name': 'OperatorCompare',
        'available': True,
        'total_rows': len(all_details),
        'top_details': filtered[:10],
    }
canvas-designanthropics/skillsCreate beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists' work to avoid copyright violations.Stars: 197kUpdated Claude CodeCodexVerifiedInstall
docxanthropics/skillsUse this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include: any mention of 'Word doc', 'word document', '.docx', '.dotx', or requests to produce professional documents with formatting like tables of contents, headings, page numbers, or letterheads. Also use when extracting or reorganizing content from .docx or .dotx files, inserting or replacing images in documents, performing find-and-replace in Word files, working with tracked changes or comments, or converting content into a polished Word document. If the user asks for a 'report', 'memo', 'letter', 'template', or similar deliverable as a Word or .docx file, use this skill. Do NOT use for PDFs, spreadsheets, Google Docs, or general coding tasks unrelated to document generation.Stars: 197kUpdated Claude CodeCodexVerifiedInstall
pdfanthropics/skillsUse this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple PDFs into one, splitting PDFs apart, rotating pages, adding watermarks, creating new PDFs, filling PDF forms, encrypting/decrypting PDFs, extracting images, and OCR on scanned PDFs to make them searchable. If the user mentions a .pdf file or asks to produce one, use this skill.Stars: 197kUpdated Claude CodeCodexVerifiedInstall
pptxanthropics/skillsUse this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or presentations; reading, parsing, or extracting text from any .pptx or .potx file (even if the extracted content will be used elsewhere, like in an email or summary); editing, modifying, or updating existing presentations; combining or splitting slide files; working with templates (.potx), layouts, speaker notes, or comments. Trigger whenever the user mentions "deck," "slides," "presentation," or references a .pptx or .potx filename, regardless of what they plan to do with the content afterward. If a .pptx or .potx file needs to be opened, created, or touched, use this skill.Stars: 197kUpdated Claude CodeCodexVerifiedInstall