|
| 1 | +.. meta:: |
| 2 | + :description: Explains how TransferBench validates transfer correctness by comparing destination memory against precomputed expected values derived from source buffers. |
| 3 | + :keywords: TransferBench data validation, TransferBench correctness, ValidateAllTransfers, PrepareReference, destination buffer, source buffer |
| 4 | + |
| 5 | +.. _transferbench-data-validation: |
| 6 | + |
| 7 | +============================== |
| 8 | +TransferBench data validation |
| 9 | +============================== |
| 10 | + |
| 11 | +TransferBench validates the transfer results by comparing the destination (DST) memory to |
| 12 | +precomputed expected values. For each transfer, the DST buffer must equal the element-wise sum of all SRC buffers, or zero if there are no sources. A transfer is correct if, for every element ``i``, the value matches the expected value given in the following table: |
| 13 | + |
| 14 | +.. list-table:: |
| 15 | + :header-rows: 1 |
| 16 | + |
| 17 | + * - Number of sources |
| 18 | + - Expected value |
| 19 | + |
| 20 | + * - 0 |
| 21 | + - ``dst[i] == 0`` (or memset value) |
| 22 | + |
| 23 | + * - 1 |
| 24 | + - ``dst[i] == src0[i]`` |
| 25 | + |
| 26 | + * - N |
| 27 | + - ``dst[i] == src0[i] + src1[i] + ... + srcN-1[i]`` |
| 28 | + |
| 29 | +Source data preparation |
| 30 | +======================= |
| 31 | + |
| 32 | +Before any transfers run, TransferBench prepares the SRC and DST memories as discussed in the following sections: |
| 33 | + |
| 34 | +Expected source pattern |
| 35 | +----------------------- |
| 36 | + |
| 37 | +Before any transfers run, TransferBench builds reference SRC buffers on the host using |
| 38 | +``PrepareReference(cfg, cpuBuffer, bufferIdx)``. |
| 39 | + |
| 40 | +The pattern used depends on the configuration: |
| 41 | + |
| 42 | +.. list-table:: |
| 43 | + :header-rows: 1 |
| 44 | + |
| 45 | + * - Configuration |
| 46 | + - Behavior |
| 47 | + |
| 48 | + * - ``fillCompress`` (non-empty) |
| 49 | + - Mix of random floats with optional zeroing per 64-byte line: |
| 50 | + ``0`` = random, ``1`` = 1B0, ``2`` = 2B0, ``3`` = 4B0, ``4`` = 32B0. |
| 51 | + Percentages control the mix. For details, see |
| 52 | + :ref:`data-validation-var`. |
| 53 | + |
| 54 | + * - ``fillPattern`` (non-empty) |
| 55 | + - Repeats the given ``vector<float>`` over all SRC buffers. |
| 56 | + |
| 57 | + * - Default |
| 58 | + - Pseudo-random: ``PrepSrcValue(bufferIdx, i) = (((i % 383) * 517) % 383 + 31) * (bufferIdx + 1)`` |
| 59 | + |
| 60 | + ``bufferIdx`` is the SRC index (0, 1, …) so each SRC buffer gets a different pattern. |
| 61 | + |
| 62 | +Expected destination (``dstReference``) |
| 63 | +---------------------------------------- |
| 64 | + |
| 65 | +The expected destination is computed once before the iteration loop: |
| 66 | + |
| 67 | +.. code-block:: text |
| 68 | +
|
| 69 | + dstReference[0] = memset to MEMSET_CHAR # used when numSrcs == 0 |
| 70 | + dstReference[1] = srcReference[0] # 1 source |
| 71 | + dstReference[2] = dstReference[1] + srcReference[1] # 2 sources |
| 72 | + dstReference[k] = dstReference[k-1] + srcReference[k-1] # k sources |
| 73 | +
|
| 74 | +``dstReference[numSrcs]`` is the expected result for a transfer with ``numSrcs`` sources. |
| 75 | + |
| 76 | +Initializing source and destination memories |
| 77 | +--------------------------------------------- |
| 78 | + |
| 79 | +For each transfer, the SRC memory on the rank that owns it is filled from the corresponding |
| 80 | +``srcReference`` buffer via ``hipMemcpy`` (host-to-device or device-to-device as appropriate). |
| 81 | +DST memory is zeroed (or memset) before transfers run. |
| 82 | + |
| 83 | +How validation is timed |
| 84 | +======================== |
| 85 | + |
| 86 | +The timing of validation is controlled by the ``alwaysValidate`` option. By default |
| 87 | +(``alwaysValidate = 0``), validation runs once after all timed iterations complete, |
| 88 | +minimizing overhead during benchmarking. When ``alwaysValidate = 1``, validation is |
| 89 | +performed after every iteration; any detected error immediately stops the run. |
| 90 | + |
| 91 | +.. list-table:: |
| 92 | + :header-rows: 1 |
| 93 | + |
| 94 | + * - Option |
| 95 | + - When |
| 96 | + - Behavior |
| 97 | + |
| 98 | + * - ``alwaysValidate = 0`` (default) |
| 99 | + - Once at the end of all iterations |
| 100 | + - ``ValidateAllTransfers`` called after the iteration loop. |
| 101 | + |
| 102 | + * - ``alwaysValidate = 1`` |
| 103 | + - After every timed iteration |
| 104 | + - ``ValidateAllTransfers`` called inside the loop; any error stops the run. |
| 105 | + |
| 106 | +How validation (``ValidateAllTransfers``) works |
| 107 | +================================================ |
| 108 | + |
| 109 | +For each transfer and each DST, the following steps are performed: |
| 110 | + |
| 111 | +1. **Rank check:** Only the rank that owns the destination performs validation. |
| 112 | + |
| 113 | +2. **Get the actual output:** |
| 114 | + |
| 115 | + - **CPU destination** or ``validateDirect = 1``: Point directly at the destination memory. |
| 116 | + - **GPU destination** and ``validateDirect = 0``: Copy destination to a host ``outputBuffer`` |
| 117 | + via ``hipMemcpy``, then compare against ``outputBuffer``. |
| 118 | + |
| 119 | +3. **Comparison:** Performed using ``memcmp(output, expected, numBytes)``. On mismatch, the code finds the first differing index and returns an error with the index, expected value, and actual value. |
| 120 | + |
| 121 | +4. **Expected values:** Calculated using ``expected = dstReference[t.srcs.size()].data()``. The precomputed sum for the number of sources. |
| 122 | + |
| 123 | +Validation options |
| 124 | +================== |
| 125 | + |
| 126 | +The following options control when and how validation is performed. They can be set as |
| 127 | +environment variables or in a configuration file. |
| 128 | + |
| 129 | +.. list-table:: |
| 130 | + :header-rows: 1 |
| 131 | + |
| 132 | + * - Option |
| 133 | + - Environment variable |
| 134 | + - Description |
| 135 | + |
| 136 | + * - ``alwaysValidate`` |
| 137 | + - ``ALWAYS_VALIDATE`` |
| 138 | + - To validate after each iteration, set to ``1``. To validate once at the end, set to ``0``. |
| 139 | + |
| 140 | + * - ``validateDirect`` |
| 141 | + - ``VALIDATE_DIRECT`` |
| 142 | + - To compare GPU DST directly, set to ``1``. Supported on AMD hardware only and requires no host copy. |
| 143 | + To copy to host and compare, set to ``0``. |
| 144 | + |
| 145 | + * - ``validateSource`` |
| 146 | + - ``VALIDATE_SOURCE`` |
| 147 | + - To validate the SRC memory right after it's initialized, set to ``1`` (optional early check). |
| 148 | + |
| 149 | +.. note:: |
| 150 | + |
| 151 | + ``validateDirect`` is not supported on NVIDIA. The code falls back to copying to host. |
0 commit comments