aws-neuron/neuron-agentic-development/neuron-nki-profiling
Claude Code and agent skill by aws-neuron/neuron-agentic-development
- community
Checking that the SKILL.md file is still in the repository.
This skill guides using the cli to generate NKI kernel profiles (NEFF + NTFF pairs) to analyze performance on Neuron hardware. Use when encountering "profile kernel", "capture execution trace", "generate NEFF", "get summary-json", or asking "how to profile NKI kernel".
Install
npx vskill@latest install aws-neuron/neuron-agentic-development/neuron-nki-profilingSKILL.md
Profiling NKI Kernels
This skill provides a complete workflow for profiling NKI kernel execution on Trainium/Inferentia hardware using Neuron profiling tools.
Quick Start
Minimal workflow to profile a kernel:
The workflow generates two key artifacts:
- NEFF file: Compiled kernel binary, generated during execution
- NTFF file: Execution trace captured by neuron-explorer
Where outputs go (the shared project-root contract)
$NEURON_PROJECT_ROOT names the PROJECT directory this analysis belongs to; everything this skill generates lands under <root>/agent_artifacts/, and it defaults to the cwd, so an ordinary interactive run needs no extra input. It is the SAME input the rest of this family takes — the parallelism-planner and hardware-entitlement skills accept it as --project-root, the vllm-neuron profiling skill writes its profiles under it — which is what lets one run's plan, per-operator floor, profile and ingested parquet sit in a single evidence trail instead of four unrelated directories.
The relative paths in the examples below (./profiles/run_001/profile.ntff) are relative to the project root. Capture must run on the Trainium box that owns the device, so when that box is not your project directory, pass the output path explicitly and copy the pair back into <root>/agent_artifacts/data/profiles/ — the querying skill then finds it where every other skill looks.
Prerequisites
Before profiling kernels, resolve the NKI virtual environment path:
- Check environment:
echo $NKI_VENV_PATH - If empty, read
.claude/nki-dev-suite.local.mdand extractnki_venv_pathfrom YAML frontmatter - If still not found, report: "NKI_VENV_PATH not configured. Set the environment variable or create .claude/nki-dev-suite.local.md with nki_venv_path in frontmatter."
Activate before running any profiling commands:
Hardware requirement: Profiling requires execution on actual Trainium/Inferentia hardware.
Complete Profiling Workflow
Step 1: Set Environment Variables
Add these environment variables in your Python script before kernel execution:
| Environment Variable | Description | |
|---|---|---|
NEURON_RT_INSPECT_ENABLE | Enable runtime inspection | |
NEURON_RT_INSPECT_DEVICE_PROFILE | Enable device-level profiling | |
NEURON_RT_INSPECT_OUTPUT_DIR | Directory for NEFF output | |
NEURON_RT_VISIBLE_CORES | Pin to specific core(s) — prevents contention when multiple agents profile concurrently |
Step 2: Execute Kernel
Run your kernel script. This compiles and executes the kernel, generating the NEFF file in the output directory.
Important: Compute references on CPU. If the test script computes a reference result (e.g., torch.matmul for comparison), do it on CPU — not on the XLA device. Every XLA graph compiled on-device generates a separate NEFF. Running reference operations on-device creates extra NEFFs that make it hard to identify the NKI kernel's NEFF.
The runtime creates a subdirectory with instance and process ID naming:
Step 3: Create Dedicated Profile Folder
Create a dedicated folder for this profiling iteration. This prevents confusion when comparing multiple optimization attempts:
Organize profile iterations:
Step 4: Capture Profile with neuron-explorer
Locate the NKI kernel NEFF and capture execution profile:
| Flag | Description | |
|---|---|---|
-n | Path to NEFF file | |
-s | Output path for NTFF trace file | |
--profile-nth-exec=2 | Profile the 2nd execution (skip warmup) | |
--enable-dge-notifs | Enable DMA engine notifications for detailed analysis |
Step 5: View Results with neuron-explorer (JSON)
Generate a JSON summary of the profile results:
This outputs structured JSON with all metrics. Parse for specific values:
Common JSON queries:
Save the full JSON output for later comparison:
Step 6: Querying the profile and/or profile analysis (optional)
For detailed analysis of the kernel profile, use the /neuron-nki-profile-querying skill. It allows for high level performance bounds analysis, as well as zoomed in, instruction level investigation of specific inefficiencies through python on parquet.
Output Directory Structure
Understanding the generated file structure:
The instance/pid subdirectory naming (i-xxx_pid_xxx) is automatic and includes the EC2 instance ID and process ID for traceability.
NEFF Identification
When the output directory contains multiple NEFFs (from multiple on-device operations), use the included identify-neffs.py script to identify which NEFF belongs to which kernel:
How it works: Each NEFF embeds its compile workdir path (/tmp/.../neuroncc_compile_workdir/<uuid>/). The script reads the HLO module in that workdir. NKI kernels appear as custom-call ops with AwsNeuronCustomNativeKernel and carry a base64-encoded JSON blob containing func_name, input_names, and output_names.
Limitation: Depends on compile workdirs in /tmp/ still existing. Run promptly after kernel execution.
Key Metrics Quick Reference
| Metric | Description | Target | |
|---|---|---|---|
latency | Total kernel execution time (ms) | Lower is better | |
tensor_engine_active_time_percent | TensorE utilization | >90% for compute-bound | |
hbm_read_bytes | HBM read traffic | Minimize | |
hbm_write_bytes | HBM write traffic | Minimize | |
mm_arithmetic_intensity | FLOPs per byte of memory traffic | Compare to peak ratio |
Comparing Optimization Iterations
When optimizing a kernel, compare metrics across iterations:
Optimization tracking table:
| Iteration | Change | Latency (ms) | TensorE (%) | |
|---|---|---|---|---|
| Baseline | - | 1.23 | 45% | |
| Larger tiles | Increased tile 64→128 | 0.95 | 72% | |
| Double buffer | Added prefetching | 0.78 | 89% |
Keep notes on what changed between iterations to correlate optimizations with metric improvements.
Complete Example
See examples/basic-profiling-workflow.py for a complete end-to-end profiling script demonstrating all steps: environment setup, kernel execution, NEFF identification, profile capture, and JSON metric extraction.
Configuration
Required settings:
| Setting | Source | Description | |
|---|---|---|---|
nki_venv_path | .claude/nki-dev-suite.local.md or NKI_VENV_PATH | Python venv with neuronx packages |
Environment variables (set in kernel script):
| Variable | Value | Purpose | |
|---|---|---|---|
NEURON_RT_INSPECT_ENABLE | 1 | Enable runtime inspection | |
NEURON_RT_INSPECT_DEVICE_PROFILE | 1 | Enable device profiling | |
NEURON_RT_INSPECT_OUTPUT_DIR | Path | NEFF output directory |
Related Skills
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/neuron-nki-profiling/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/aws-neuron/neuron-agentic-development/neuron-nki-profiling)