.. meta::
    :description: Find device-to-host copies that leave the device idle in a Neuron Explorer system profile, and remove them by reducing results on the device before copying them back.
    :date-modified: 11/09/2026

.. _neuron-explorer-reduce-device-to-host-transfer-overhead:

How to identify and reduce device-to-host transfer overhead
===========================================================

A device-to-host (D2H) transfer copies a tensor from the device's HBM back to host memory over PCIe. PyTorch issues one whenever Python needs a device value: ``.cpu()``, ``.item()``, ``.tolist()``, ``print(tensor)``, ``int(tensor)``, or a comparison used in an ``if``. Each of these also synchronizes: the host thread waits for every execution the tensor depends on, then waits for the copy, and the device sits idle until the host has launched the next execution.

This guide shows how to recognize that pattern in a Neuron Explorer system profile, how to measure what each copy costs, and how to remove the copies by reducing results on the device and copying back only what the host needs. For copies in the other direction, see the :doc:`H2D guide <how-to-reduce-host-to-device-transfer-overhead>`. For data movement *inside* a device execution, see the :doc:`DMA guide <how-to-reduce-inefficient-dma-transfers>`.

When to suspect device-to-host transfers
----------------------------------------

Look for this bottleneck when:

* A loop runs a compiled graph and then makes a decision on the host every iteration: picking the next token, checking a stopping condition, computing a metric, or logging a loss.
* The main thread spends most of an iteration in ``aten::to`` / ``aten::_to_copy`` or ``aten::item`` / ``aten::_local_scalar_dense``, while the compiled region itself is short.
* A large output (logits, hidden states, an attention map) is copied back when the host only needs a scalar or a slice of it.
* Results are copied back inside the loop (``losses.append(loss.item())``) when they could be collected on the device and copied once after it.

The cost has two parts. The copy itself is proportional to the bytes moved: on the trn2.3xlarge used below, 39 MB takes about 9.8 ms from request to completion. The synchronization is paid even for 8 bytes: the host cannot queue the next execution until the value has arrived, so the device idles for the copy plus the host's turnaround (here about 2 ms per iteration).

What a copy looks like in the system profile
--------------------------------------------

One ``x.cpu()`` produces events on three rows of the System Trace Viewer:

1. The main thread runs ``aten::to`` → ``aten::_to_copy`` (for ``.item()``: ``aten::item`` → ``aten::_local_scalar_dense`` → ``aten::to``). The block starts when the copy is requested and ends when the data is on the host, so it also covers any execution the tensor was still waiting for. The Neuron backend records ``neuron::copy::neuron_to_cpu`` on a framework thread.
2. The Neuron Runtime row (``neuron_rt/.../NC0``) shows ``kbl_exec_wait`` while the host waits for the execution to finish, then ``nrta_tensor_read``, the runtime call that reads the tensor out of HBM.
3. The ``device_to_host_transfers`` row shows the data movement itself as ``io_xu_complete``: the DMA from HBM into host memory, with its size, direction and achieved bandwidth in **Event Details**.

The transfer bandwidth row (``NC:0/device_to_host/transfer_bandwidth``) plots the PCIe bandwidth these copies used over time. The events are linked: clicking an ``io_xu_complete`` draws an arrow to the ``nrta_tensor_read`` that requested it, and the **Dependency Chain Viewer** lists that event as its upstream; clicking the ``nrta_tensor_read`` in turn lists the ``neuron::copy::neuron_to_cpu`` framework op on the backend thread (see :ref:`Linking Transfers to Framework Operations <neuron-explorer-system-profile-transfer-linking>` in the System Trace Viewer overview).

Capture a system profile
------------------------

Capture with ``torch.profiler.profile`` and a ``NeuronConfig`` in ``RUNTIME`` mode, as described in :doc:`Capture PyTorch profiles <how-to-profile-pytorch>`. ``ProfileMode.RUNTIME`` records the Neuron Runtime events, including the transfer events, and ``ProfilerActivity.PrivateUse1`` adds them to the trace next to the CPU ops. The schedule runs the loop three times and records only the third run, so compilation and first-time allocation are not in the profile. Wrap each iteration in ``torch.profiler.record_function`` so the profile has a labeled block per iteration:

.. code-block:: python

   import torch
   from torch.profiler import ProfilerActivity, profile, record_function
   from torch_neuronx.profiling import NeuronConfig, NeuronProfiler, ProfileMode

   config = NeuronConfig(modes=[ProfileMode.RUNTIME], profile_output_dir="./profiles/baseline", capture_enabled_for_nc="0")
   with profile(activities=[ProfilerActivity.CPU, ProfilerActivity.PrivateUse1],
                experimental_config=config, on_trace_ready=NeuronProfiler(config).export_trace,
                schedule=torch.profiler.schedule(wait=1, warmup=1, active=1)) as prof:
       for _ in range(3):
           generate(prompt)              # the loop under test; each token is inside record_function(f"token {i}")
           torch.neuron.synchronize()
           prof.step()

   print(prof.key_averages().table(sort_by="cpu_time_total", row_limit=12))

The ``record_function`` labels appear on the main thread row in Neuron Explorer and as rows in ``prof.key_averages()``, so the same profile can be read with PyTorch's own tools. For the other modes and parameters, see :doc:`how-to-profile-pytorch`.

Open the profile in Neuron Explorer
-----------------------------------

The profile directory holds the PyTorch trace (``trace.json``) and the runtime trace (``ntrace.pb``). Serve it:

.. code-block:: bash

   neuron-explorer view -d ./profiles/baseline

Open the profile and the **System Timeline**. The rows, grouped by instance and process:

.. list-table::
   :header-rows: 1
   :widths: 36 64

   * - Row
     - What it shows
   * - ``framework/TID:0``
     - The profiler session: ``PyTorch Profiler`` and ``__neuron_profiler__`` spans.
   * - ``framework/TID:<main thread>``
     - Your Python code: ``ProfilerStep#N``, the ``record_function`` labels, ``aten::`` ops, ``TorchDynamo Cache Lookup``, ``Torch-Compiled Region``.
   * - other ``framework/TID:*`` rows
     - Backend threads: ``neuron::copy::neuron_to_cpu`` and ``neuron::copy::cpu_to_neuron`` (copies), ``model_default`` (a compiled graph being executed), ``RuntimeWorker::sleep`` (the runtime worker waiting).
   * - ``framework/Stream:*``
     - The same backend work grouped by device stream.
   * - ``neuron_rt/worker:0/NC0``
     - Neuron Runtime calls for NeuronCore 0: ``nrta_execute_schedule`` and ``nrt_model_submit`` (launch), ``kbl_exec_wait`` (host waiting for the execution), ``nrta_tensor_read`` (copy request), ``nrta_tensor_write`` (the H2D copy of the input buffer).
   * - ``neuron_hw/worker:0/NC0:4``, ``NC0:5``
     - ``nc_exec_running``: a NEFF executing on the two physical cores of logical NeuronCore 0. Click one to open its device profile.
   * - ``worker:0/device_to_host_transfers``
     - The transfer events track: one ``io_xu_complete`` per D2H copy, with size, direction and bandwidth.
   * - ``worker:0/host_to_device_transfers``
     - The same for H2D copies.
   * - ``NC:0/device_to_host/transfer_bandwidth``, ``host_to_device/transfer_bandwidth``
     - The transfer bandwidth tracks: PCIe bandwidth used by each direction over time.

Find the bottleneck, step by step
---------------------------------

1. **Pin the rows that matter.** In the System Trace Viewer, hover over a row name and click the pin icon that appears next to it. Pin the two ``neuron_hw`` rows, ``neuron_rt/.../NC0`` and ``device_to_host_transfers``; pinned rows stay at the top while you scroll through the framework threads.
2. **Find the idle time.** Zoom to two or three iterations (the ``record_function`` labels on the main thread mark them). Compare the width of each label with the ``nc_exec_running`` block inside it. The difference is time the device is not computing.
3. **See what fills it.** Read the main thread between two executions. An ``aten::to`` / ``aten::_to_copy`` (or ``aten::item``) block that starts before the execution ends and runs on past it, with ``nrta_tensor_read`` on the runtime row and ``io_xu_complete`` on ``device_to_host_transfers`` in the same span, means the host is waiting for data from the device. If that wait takes most of the gap, this guide applies.
4. **Measure one copy.** Hover over the ``io_xu_complete`` block to read its duration; click it and open **Event Details** for ``size``, ``transfer_direction`` and ``bandwidth_bytes_per_sec``. The click also draws an arrow to the ``nrta_tensor_read`` on the ``neuron_rt`` row that requested the copy; the **Dependency Chain Viewer** lists it, and clicking it there leads on to the ``neuron::copy::neuron_to_cpu`` op. Read the time from the start of ``nrta_tensor_read`` to the end of ``io_xu_complete`` as the cost of the copy.
5. **Count the copies.** In the **Search** widget, set the field to ``name``, enter ``io_xu_complete`` and choose **Submit**. Every transfer in the profile is listed with its ``size`` and ``transfer_direction``, and **Focus** jumps the timeline to it. Or read the ``# of Calls`` column of ``neuron::copy::neuron_to_cpu`` in ``prof.key_averages()``. A large copy on every iteration of a loop is the pattern to remove.

Example: a generation loop
--------------------------

A greedy generation loop on Qwen3-0.6B running on a trn2.3xlarge. The forward pass is compiled once and runs on a fixed-size buffer of 128 tokens:

.. code-block:: python

   import torch
   from torch.profiler import record_function
   from transformers import AutoModelForCausalLM, AutoTokenizer

   device = torch.device("neuron")
   tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen3-0.6B")
   model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen3-0.6B", dtype=torch.bfloat16).to(device).eval()

   prompt = tokenizer("Explain what a KV cache is in two sentences.").input_ids
   L, NEW_TOKENS = 128, 32          # a fixed-size token buffer keeps one compiled graph

   @torch.compile(backend="neuron", fullgraph=True)
   def forward(buf):
       return model(input_ids=buf, use_cache=False).logits      # [1, 128, vocab]

Profile 1: Baseline
-------------------

``generate()`` copies the logits to the host and picks the next token there:

.. code-block:: python

   def generate(prompt):
       tokens = list(prompt)
       for i in range(NEW_TOKENS):
           with record_function(f"token {i}"):                            # labels the iteration in the profile
               buf = torch.tensor([tokens + [0] * (L - len(tokens))]).to(device)
               logits = forward(buf).cpu()                                # 39 MB of logits to the host, every token
               tokens.append(int(logits[0, len(tokens) - 1].argmax()))   # next token picked on the host
       return tokenizer.decode(tokens[len(prompt):])

**32 tokens: 710 ms (22.2 ms per token).**

What the profile shows
~~~~~~~~~~~~~~~~~~~~~~

The whole recorded step (``ProfilerStep#2``, 736 ms) in the **System Trace Viewer**, with four rows pinned to the top: ``neuron_hw/.../NC0:4``, ``neuron_hw/.../NC0:5``, ``neuron_rt/.../NC0`` and ``device_to_host_transfers``. Below them are the first two framework rows, ``TID:0`` (the profiler session) and ``TID:13`` (the main thread):

.. image:: ./images/d2h-profile1-step.png
   :alt: Neuron Explorer system timeline of the whole Profile 1 step, 736 ms, with the NC0:4, NC0:5, neuron_rt and device_to_host_transfers rows pinned at the top: 32 evenly spaced pink nc_exec_running blocks, a blue kbl_exec_wait and a green nrta_tensor_read after each on the runtime row, 32 purple io_xu_complete blocks, and on the main thread 32 colored token N bars each with an aten::to bar under it

Reading the rows from the top:

* **Pinned rows** ``neuron_hw/.../NC0:4`` **and** ``NC0:5``: 32 pink ``nc_exec_running`` blocks, one per token, 8.3 ms each, 23 ms apart. Together they are 266 ms of the 736 ms step: the device is computing 36% of the time.
* **Pinned row** ``neuron_rt/.../NC0``: after each execution, a blue ``kbl_exec_wait`` (the host waiting for the execution) followed by a green ``nrta_tensor_read`` (the runtime reading a tensor out of HBM).
* **Pinned row** ``device_to_host_transfers``: one purple ``io_xu_complete`` per token, 32 in all, each at the end of a ``nrta_tensor_read``.
* **Main thread** ``framework/TID:13``: the 32 colored bars labeled ``token 0`` … ``token 31`` are the ``record_function(f"token {i}")`` labels from the code, about 23 ms each. The long ``aten::to`` bar under each one is ``forward(buf).cpu()``.

How we identified the bottleneck
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1. **Where is the device idle?** In the image above, each 23 ms ``token N`` bar contains one 8.3 ms ``nc_exec_running`` block. For the other 14 ms of every token the two ``neuron_hw`` rows are empty, and the pinned ``neuron_rt`` and transfer rows show what the device is waiting for: a ``nrta_tensor_read`` and an ``io_xu_complete``.

2. **What fills the gap?** Zoom to one token (``token 16``, a 25 ms window). The tooltip in the image is the hover over the ``io_xu_complete`` on the pinned transfer row:

   .. image:: ./images/d2h-profile1-one-token.png
      :alt: Neuron Explorer system timeline of one Profile 1 token, 25 ms, with the pinned rows at the top: an 8.3 ms nc_exec_running block, kbl_exec_wait and then a 7.4 ms nrta_tensor_read on the neuron_rt row, an io_xu_complete on device_to_host_transfers with a hover tooltip reading Duration 2,591,752 ns, and on the main thread the token 16 bar filled by one aten::to and aten::_to_copy that span both the execution and the copy

   Left to right on the main thread row, under the ``token 16`` bar:

   .. list-table::
      :header-rows: 1
      :widths: 34 12 54

      * - Block
        - Duration
        - What it is
      * - ``aten::to`` (``aten::_to_copy`` under it)
        - 18.7 ms
        - ``forward(buf).cpu()``. It starts when the copy is requested, spans the 8.3 ms execution (the copy has to wait for the logits), then the 7.4 ms ``nrta_tensor_read`` and the 2.6 ms ``io_xu_complete`` on the pinned rows.
      * - ``aten::argmax``
        - 0.6 ms
        - picking the next token on the host
      * - ``TorchDynamo Cache Lookup``, ``Torch-Compiled Region`` (start of the next ``token`` bar)
        - 2.5 ms
        - the next ``forward`` call; the next ``nc_exec_running`` block starts here

   Of the 23 ms token, 18.7 ms is the host waiting in ``.cpu()``: 8.3 ms for the execution it depends on and about 10 ms for the copy.

3. **How big is the copy?** Click the ``io_xu_complete`` block and open the **Event Details** tab in the bottom panel:

   .. image:: ./images/d2h-profile1-event-details.png
      :alt: Neuron Explorer Event Details table for the clicked io_xu_complete event: bandwidth_bytes_per_sec 15007460590, direction d2h, duration_ns 2.5918 ms, name io_xu_complete, size 38895616, trace_event_source neuron_rt, transfer_direction device_to_host

   ``size`` is 38,895,616 bytes: 128 positions × 151,936 vocabulary entries × 2 bytes, the whole logits tensor, of which the host reads one row. ``duration_ns`` (2.59 ms) and ``bandwidth_bytes_per_sec`` (15.0 GB/s) cover the completion event only; the copy as the host experiences it runs from the start of ``nrta_tensor_read`` to the end of ``io_xu_complete``, 9.8 ms. Clicking the event also draws an arrow to that ``nrta_tensor_read`` on the ``neuron_rt`` row; the **Dependency Chain Viewer** tab lists it as the upstream event, and clicking it there lists the ``neuron::copy::neuron_to_cpu`` op on the backend thread, which is what the ``aten::to`` on the main thread is waiting for.

4. **How often?** In the **Search** widget, searching field ``name`` for ``io_xu_complete`` lists every transfer in the profile with its ``size`` and ``transfer_direction``: 32 of 38.9 MB in the step, one per token. The copies account for about 310 ms of the 736 ms step; the executions for 266 ms.

The same numbers from PyTorch's own report, ``prof.key_averages().table(sort_by="cpu_time_total")`` (excerpt):

.. code-block:: text

   Name                              CPU total    # of Calls
   ProfilerStep*                     735.622ms             1
   aten::to                          599.922ms            96
   aten::_to_copy                    599.611ms            64
   neuron::copy::neuron_to_cpu       316.152ms            64
   model_default                     274.692ms            64
   token 16                           24.516ms             1
   token 25                           24.394ms             1

``aten::to`` takes 81% of the step: 32 copies of the logits, each also waiting for its execution, plus the 32 small copies of ``buf`` to the device.

Profile 2: Keep the result on the device
----------------------------------------

The loop only needs the token id. Compute it inside the compiled function and copy back only that:

.. code-block:: python

   @torch.compile(backend="neuron", fullgraph=True)
   def forward(buf):
       return model(input_ids=buf, use_cache=False).logits.argmax(dim=-1)   # changed: token ids, on the device

   def generate(prompt):
       tokens = list(prompt)
       for i in range(NEW_TOKENS):
           with record_function(f"token {i}"):
               buf = torch.tensor([tokens + [0] * (L - len(tokens))]).to(device)
               next_ids = forward(buf)                                    # changed: no .cpu() of the logits
               tokens.append(int(next_ids[0, len(tokens) - 1]))           # changed: 8 bytes back
       return tokenizer.decode(tokens[len(prompt):])

**32 tokens: 378 ms (11.8 ms per token), 1.9x faster.**

Why this works
~~~~~~~~~~~~~~

The host still needs one value per token, so one synchronization per token stays. What changes is how much data that synchronization carries:

* **The copy shrinks from 39 MB to 8 bytes.** ``argmax`` runs on the device, inside the compiled graph, and the only tensor the host reads is one ``int64`` per position. On the pinned rows, ``nrta_tensor_read`` takes 11 µs and ``io_xu_complete`` 1 to 1.5 µs instead of 7.4 ms and 2.4 ms.
* **The execution grows by 1.1 ms** (8.3 → 9.4 ms): the ``argmax`` over 128 × 151,936 logits is now device work. That is the price for removing 9.8 ms of copy per token.
* **The host's share of each token drops to the dispatch.** ``aten::item`` on the main thread now spans only the execution it waits for (10.2 ms) and the 8-byte read; the rest of the ``token`` label is 1.1 ms of ``TorchDynamo Cache Lookup`` and ``Torch-Compiled Region``.

One token, same pinned rows, hovering the token-id copy on ``device_to_host_transfers``: ``io_xu_complete``, 969 ns. ``kbl_exec_wait`` on the runtime row still spans the execution, but the ``nrta_tensor_read`` that follows it has shrunk from 7.4 ms to 11 µs:

.. image:: ./images/d2h-profile2-one-token.png
   :alt: Neuron Explorer system timeline of one Profile 2 token over 12 ms: a 9.4 ms nc_exec_running block on the pinned NC0:4 and NC0:5 rows, kbl_exec_wait spanning it on the neuron_rt row, a single tiny event on device_to_host_transfers with a tooltip reading io_xu_complete, Duration 969 ns, and on the main thread the token 16 label filled by aten::item, aten::_local_scalar_dense, aten::to and aten::_to_copy

Three tokens of the recorded step, same pinned rows. The ``nc_exec_running`` blocks follow each other with 2 ms gaps, and the transfer row shows only the tiny token-id copies:

.. image:: ./images/d2h-profile2-three-tokens.png
   :alt: Neuron Explorer system timeline of three Profile 2 tokens over 35 ms: three 9.4 ms nc_exec_running blocks separated by 2 ms gaps on the pinned NC0:4 and NC0:5 rows, kbl_exec_wait spanning each execution on the neuron_rt row, three tiny events on device_to_host_transfers, and token 15, 16, 17 labels on the main thread each filled by aten::item

What improved
-------------

.. list-table::
   :header-rows: 1
   :widths: 34 22 22 22

   * - 
     - Profile 1: Baseline
     - Profile 2: result on the device
     - Change
   * - Copied to the host per token
     - 39 MB of logits
     - 8 bytes (one token id)
     - 
   * - Time for 32 tokens (host-timed, median of 3)
     - 710 ms
     - 378 ms
     - 1.9x
   * - Per token
     - 22.2 ms
     - 11.8 ms
     - 
   * - Device execution per token (``nc_exec_running``)
     - 8.3 ms
     - 9.4 ms
     - +1.1 ms (``argmax`` moved to the device)
   * - Device idle between executions
     - 14.4 ms
     - 2.1 ms
     - 
   * - Device busy during the step
     - 36%
     - 82%
     - 

Both versions generate the same tokens. Reduce on the device first (``argmax``, ``top-k``, ``sum``, ``mean``), and copy back only what the host needs. If the host needs results from every iteration, keep them on the device and copy them once after the loop.

Do this with an agent
---------------------

The readback in Profile 1 is one of the cases the `Neuron Agentic Development <https://github.com/aws-neuron/neuron-agentic-development>`__ Profile Analysis skill checks for (see :ref:`Getting Started <neuron-agentic-development-getting-started>` to install the skills). The skill is written for captures of a vLLM Neuron server, but this check is a query on the ``SystemProfileEvents`` table, which every system profile has:

.. list-table::
   :header-rows: 1
   :widths: 38 62

   * - Skill
     - What it does
   * - ``neuron-framework-profile-analysis-vllm-neuron``
     - Analyzes a capture starting from the system trace (:ref:`deep dive <neuron-framework-profile-analysis-vllm-neuron>`). Its session analysis measures the gaps between executions, and its host-side readback check reads the size and count of the runtime's tensor-read events to find a tensor that is copied back whole when the host only needs a reduction of it: the pattern in Profile 1. The agent, ``neuron-framework-profile-analysis-vllm-neuron-agent``, also carries ``neuron-nki-profile-querying`` (serves a profile with ``neuron-explorer`` and runs SQL against it) and ``neuron-explorer-profile-schema`` (what each field means).
   * - ``neuron-framework-profiling-vllm-neuron``
     - Captures the profile when the workload is a vLLM Neuron server (:ref:`deep dive <neuron-framework-profiling-vllm-neuron>`). For a workload like the one in this guide, capture as shown above and point the agent at the output directory.

A prompt for Profile 1:

.. code-block:: text

   Analyze the system profile in ./profiles/baseline. The device is idle between executions;
   check whether a device-to-host readback is the cause. For the longest ProfilerStep, report
   the device busy share, then list the nrta_tensor_read and io_xu_complete events grouped
   by size, with count, average and total duration, and which main-thread aten op under
   each "token N" label waits for them.

After the fix:

.. code-block:: text

   Do the same for ./profiles/fixed and compare the two profiles: device busy share, bytes
   copied back per token, and the duration of the "token N" labels.

The two queries behind those numbers, on ``SystemProfileEvents``, both scoped to the recorded step through its ``ProfilerStep#2`` event. The first counts the executions on one of the two ``neuron_hw`` rows (``pcore_idx`` 4), skipping the sub-millisecond helper graphs; the second is the readback check. (If you send them to the ``databaseExplorerQuery`` endpoint the querying skill uses, put each statement on one line.)

.. code-block:: sql

   SELECT COUNT(*) AS n_exec, ROUND(AVG(e.duration_ns) / 1e6, 1) AS avg_ms,
          ROUND(100.0 * SUM(e.duration_ns) / MAX(step.duration_ns), 1) AS busy_pct
   FROM SystemProfileEvents AS e,
        (SELECT start_ts, end_ts, duration_ns FROM SystemProfileEvents
         WHERE name LIKE 'ProfilerStep#2%') AS step
   WHERE e.name = 'nc_exec_running' AND e.pcore_idx = 4 AND e.duration_ns > 1000000
     AND e.start_ts >= step.start_ts AND e.end_ts <= step.end_ts;
   -- Profile 1: 32 executions, 8.3 ms each, busy_pct 36.2
   -- Profile 2: 32 executions, 9.4 ms each, busy_pct 81.6

   SELECT e.name, json_extract(e.extra_attributes_json, '$.size') AS size_bytes,
          COUNT(*) AS n, ROUND(AVG(e.duration_ns) / 1e6, 2) AS avg_ms,
          ROUND(SUM(e.duration_ns) / 1e6, 1) AS total_ms
   FROM SystemProfileEvents AS e,
        (SELECT start_ts, end_ts FROM SystemProfileEvents
         WHERE name LIKE 'ProfilerStep#2%') AS step
   WHERE e.name IN ('nrta_tensor_read', 'io_xu_complete')
     AND e.start_ts >= step.start_ts AND e.end_ts <= step.end_ts
   GROUP BY 1, 2 ORDER BY total_ms DESC;
   -- Profile 1: nrta_tensor_read, 38895616 B, 32 events, 7.52 ms each, 240.7 ms in total
   --            io_xu_complete,   38895616 B, 32 events, 2.29 ms each,  73.2 ms in total
   -- Profile 2: both events 8 B x 32, under 0.5 ms in total

One event name to watch: the skill's reference query filters on ``nrt_tensor_read``, the event of the runtime's synchronous copy path. The copies in this guide go through the asynchronous path and appear as ``nrta_tensor_read``, as in the query above, so a query on the synchronous name finds none of them (see "Different event names" under Common issues).

Common issues
-------------

``device_to_host_transfers`` is empty
   Make sure ``ProfileMode.RUNTIME`` is in ``NeuronConfig(modes=...)`` and ``ProfilerActivity.PrivateUse1`` is in ``activities``.

Different event names
   A copy made through the runtime's synchronous path appears as ``nrt_tensor_read`` on the ``neuron_rt`` row and ``dmem_buf_copyout`` on the transfer row, instead of ``nrta_tensor_read`` and ``io_xu_complete``. A profile can show both paths; the large copies this guide is about use the asynchronous one. The analysis is the same.

Related information
-------------------

* PyTorch Performance Tuning Guide: `Avoid unnecessary CPU-GPU synchronization <https://docs.pytorch.org/tutorials/recipes/recipes/tuning_guide.html#avoid-unnecessary-cpu-gpu-synchronization>`__. The same advice applies to Neuron: ``.item()``, ``.cpu()``, ``print(tensor)`` and Python control flow on device values all make the host wait for the device.
* :doc:`System Trace Viewer <overview-system-profiles>`: the transfer tracks, and how transfers are linked to the framework ops that issued them.
* :doc:`Capture PyTorch profiles <how-to-profile-pytorch>`: ``NeuronConfig`` modes and parameters.
* :doc:`Analyze profile output <how-to-analyze-profile-output>`: the Parquet tables and CSV exports, to analyze a profile programmatically. A system profile is one table, :ref:`SystemProfileEvents <profile-schema-systemprofileevents>`, with each copy's ``size`` and ``transfer_direction`` in its ``extra_attributes_json`` column.
* :doc:`Neuron Agentic Development </tools/neuron-agentic-development/index>`: the skills and agents, with deep dives on :ref:`capturing <neuron-framework-profiling-vllm-neuron>` and :ref:`analyzing <neuron-framework-profile-analysis-vllm-neuron>` profiles of vLLM Neuron workloads (see "Do this with an agent" above).
* :doc:`H2D guide <how-to-reduce-host-to-device-transfer-overhead>`: copies from the host to the device (system profile).
* :doc:`DMA guide <how-to-reduce-inefficient-dma-transfers>`: data movement inside a device execution (device profile).
