Ascend schedule analysis

From kali20gakki/msAgent · View interactive version

Ascend schedule analysis is an AI agent skill from the GitHub repository kali20gakki/msAgent. Analyze Ascend NPU schedule, operator dispatch, operator launch, and Host Bound profiling issues in Ascend profiling data. Use when need to diagnose device Free time, framework/operator dispatch latency, launch latency, PYTORCH_API/CANN_API launch gaps, aclrtSynchronizeStream stalls, task queue beha

How to use this skill

Skill file

Ascend Schedule Analysis

Analyze NPU scheduling issues from evidence first. Do not start with tuning suggestions. Establish whether the workload is actually Host Bound, then separate model-side dispatch pressure from CPU runtime scheduling interference and environment/configuration issues.

Core Workflow

  1. Validate the profiling format and available artifacts.
  2. Establish whether Host Bound exists.
  3. Split Free time into preparation, in-step gaps, and post-dispatch queueing behavior.
  4. Identify the dominant cause category.
  5. Map each finding to the smallest practical optimization experiment.

Prefer DB profiling data with ascend_pytorch_profiler_{rank_id}.db. For DB data, first try to create or use the dispatch view through msprof_mcp-create_dispatch_view. If the view is unavailable, fall back to direct DB queries only for the fields required by the current question.

For cluster profiling data, rank candidates by device Free time first. Prefer analyzing the rank with the longest Free time, because it is the most likely Host Bound suspect. When the evidence is ambiguous or when a fast/slow-rank explanation is needed, compare dispatch APIs between a long-Free rank and a short-Free rank in the same step range.

Evidence Standard

Treat a schedule issue as Host Bound only when the evidence shows device starvation:

Do not infer Host Bound from high API latency alone. A slow API can still be device-bound if the device already has queued work.

Always report:

Split Free Time

For one step, split device Free time into three parts:

Before manually reconstructing gaps, first look for the step-level summary. Both device Free time and Preparation time are usually available in analysis.db/StepTraceTime or step_trace_time.csv.

  1. Preparation time: from step start to first device task. Prefer analysis.db/StepTraceTime or step_trace_time.csv.
  2. In-step Free gaps: from the first device kernel/task to the last kernel/task, identify large empty intervals. Use msprof-analyze -m free_analysis when the input path is a cluster path or a single-card parent directory.
  3. Tail or boundary effects: time after the last relevant device task. Treat this separately from dispatch bottlenecks unless it blocks the next step.

For free_analysis, remember the path limitation: do not pass the single-card directory directly; pass the cluster data path or the single-card parent directory.

Typical command:

msprof-analyze -m free_analysis -d <cluster_or_parent_path> -o <output_dir> --agent

Interpret Dispatch Geometry

Use the relationship between framework call, kernel launch, and device execution:

call ops -> kernel launch -> kernel run

For PyTorch on Ascend, PYTORCH_API usually represents framework/operator calls that enqueue work into a task queue. An async acl_thread in the CANN layer dequeues and launches concrete launch work onto the device.

When looking at dispatch lines or paired API/task timing:

Check Abnormally Slow APIs

Before assigning the gap to CPU scheduling or model structure, check whether any same-kind API has abnormal latency.

Scope:

Procedure:

  1. Group APIs by normalized name or prefix plus exact name when available.
  2. Compute count, total duration, average duration, p95/p99, max duration, and the timestamp of the max event.
  3. Flag an API when its max or high percentile is much larger than the same API on neighboring steps, the same rank outside the gap, or a short-Free rank in cluster data.
  4. Correlate the flagged API timestamp with device Free intervals and dispatch-to-run geometry.

Interpretation:

Root Cause Buckets

Classify findings into one or more buckets.

Model-side dispatch pressure

Look for:

Actions:

Synchronization breaks

Look for:

Actions:

CPU-only work

Look for:

Actions:

CPU scheduling interference

Look for:

Actions:

GC, locks, and allocator effects

Look for:

Actions:

Optimization Map

Use the least invasive action that matches the evidence.

TASK_QUEUE_ENABLE

Use when the evidence shows host dispatch work is not sufficiently overlapped with device execution, especially when CANN/aclnn launch work appears on the critical path and device Free time is waiting for the next task.

Official behavior: TASK_QUEUE_ENABLE configures whether the task_queue operator dispatch queue is enabled and which optimization level is used.

Values:

Recommended experiment:

export TASK_QUEUE_ENABLE=2

Interpretation rules:

CPU affinity

Use when dispatch threads are preempted, migrate across cores/NUMA nodes, or fast/slow-rank symptoms suggest CPU scheduling instability.

Official environment variable:

export CPU_AFFINITY_CONF=<mode>,npu<card_id>:<start_core>-<end_core>

Modes:

Examples:

export CPU_AFFINITY_CONF=1
export CPU_AFFINITY_CONF=2
export CPU_AFFINITY_CONF=1,npu0:0-1,npu1:2-5,npu3:6-6

Before recommending custom core ranges, check NPU/NUMA affinity with:

npu-smi info -t topo

Warn that cross-NUMA memory access can hide the benefit of binding.

Compile optimization

Use when the host-side framework/runtime overhead is broad rather than tied to one API. Ascend PyTorch documentation describes compiler-based optimization with Bisheng, including LTO and PGO, across Python, PyTorch, and torch_npu compatibility combinations.

Treat this as a larger environment experiment, not a first-line code fix. Recommend it after high-frequency small ops, sync points, and CPU scheduling are checked.

High-performance memory allocator

Use when host memory allocation overhead or lock contention is visible. The official PyTorch tuning doc recommends tcmalloc through LD_PRELOAD.

Example:

LD_PRELOAD="/usr/local/lib/libtcmalloc.so" python train_script.py

Verify with:

ldd $(which python)

Do not recommend allocator replacement solely because a workload is Host Bound.

ACLNN cache

Use when the dispatch bottleneck appears in first-level pipeline or dynamic-shape operator API execution.

Official behavior: ACLNN_CACHE_LIMIT configures the number of single-operator Host-side cache entries. The cache stores information such as workspace size, executor, and tiling data. The documented range is [1,10000000], and the default is 10000.

Example:

export ACLNN_CACHE_LIMIT=100000

Warn that increasing the cache raises Host memory usage. This is most plausible for dynamic-shape workloads with a large shape range.

Search Policy

If more external documentation is needed, first use the links already present in this skill or the official Ascend documentation. Strongly prefer Tavily only when the user has configured TAVILY_API_KEY. If the key is unavailable and the user did not explicitly ask for web search, do not proactively search.

Useful official references:

Output Shape

Write the final analysis in this order:

  1. Conclusion: Host Bound, device-bound queueing, mixed, or inconclusive.
  2. Evidence: rank/step, Free ratio, key intervals, API/task names, dispatch geometry.
  3. Cause bucket: small-op launch pressure, sync break, CPU-only work, CPU scheduling, GC/lock/allocator, or mixed.
  4. Optimization experiments: list only actions supported by evidence.
  5. Missing evidence: state exactly what would improve confidence.

Keep recommendations concrete and testable. Prefer "try ACLNN_CACHE_LIMIT=100000 for this dynamic-shape first-level dispatch bottleneck and compare Free time" over broad statements like "optimize scheduling".

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.