File size: 10,130 Bytes
1276a5c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | """Fine-grained mutations aimed at the benchmark's weak original oracle.
The patterns are deliberately tied to CUDA spellings present in the accepted
substrates or ``problems_batch2.py``. Each substitution changes one narrow
site and remains valid CUDA/C++.
"""
from mutator import Rule
FINE_RULES = [
# Boundary faults: one tail lane or one term of a long reduction.
Rule("output-elements-one-extra-lane", "boundary",
r"if \(output_index >= output_elements\) return;",
r"if (output_index > output_elements) return;",
"Mechanism 3 (shape-alignment evasion): an exactly aligned launch has no lane at output_elements; a misaligned output plus a CUDA memory checker kills it."),
Rule("line-count-one-extra-lane", "boundary",
r"if \(line >= line_count\) return;",
r"if (line > line_count) return;",
"Mechanism 3 (shape-alignment evasion): aligned line counts launch no extra lane; a non-multiple line count with guarded allocation kills it."),
Rule("flat-n-one-extra-lane", "boundary",
r"if \(idx < n\) (\{\{?) float val = x\[idx\];",
r"if (idx <= n) \1 float val = x[idx];",
"Mechanism 3 (shape-alignment evasion): n is block-aligned in the original elementwise case; a misaligned n kills it by exposing the one-past-end access."),
Rule("matmul-a-last-k-drop", "boundary",
r"row < M && a_k < K",
r"row < M && a_k + 1 < K",
"Mechanism 1 (tolerance absorption): one of hundreds of positive dot-product terms is lost (<1%); a last-K spike kills it."),
Rule("matmul-a-transposed-last-k-drop", "boundary",
r"a_k < K && row < M",
r"a_k + 1 < K && row < M",
"Mechanism 1 (tolerance absorption): only the last term of a long dot product is removed; a dominant last A term kills it."),
Rule("matmul-b-last-k-drop", "boundary",
r"b_k < K && col < N",
r"b_k + 1 < K && col < N",
"Mechanism 1 (tolerance absorption): one reduction term among hundreds is zeroed; a last-K spike in B kills it."),
Rule("arg-reduction-last-row-drop", "boundary",
r"for \(int r = 1; r < R; r\+\+\)",
r"for (int r = 1; r + 1 < R; r++)",
"Mechanism 2 (input-domain evasion): the final row is almost never the unique random extremum; forcing the extremum into the final row kills it."),
Rule("min-reduction-last-row-drop", "boundary",
r"for \(int r = 0; r < R; r\+\+\)",
r"for (int r = 0; r + 1 < R; r++)",
"Mechanism 2 (input-domain evasion): a random final row is rarely the minimum; placing the unique minimum there kills it."),
Rule("cumsum-last-output-drop", "boundary",
r"scan_index < scan_size; scan_index\+\+",
r"scan_index + 1 < scan_size; scan_index++",
"Mechanism 1 (tolerance absorption): only the last prefix output is omitted and its missing term is tiny relative to a long positive sum; a short scan or last-position spike kills it."),
Rule("pool2d-last-tap-drop", "boundary",
r"kernel_x < 11; kernel_x\+\+",
r"kernel_x < 10; kernel_x++",
"Mechanism 1 (tolerance absorption): one of 121 comparable positive pooling terms is lost (~0.83%); a large value in the omitted tap kills it."),
Rule("groupnorm-sum-tail-scalar-drop", "boundary",
r"if \(i < group_size\) \{ local_sum \+= x\[group_start \+ i\]; \}",
r"if (i + 1 < group_size) { local_sum += x[group_start + i]; }",
"Mechanism 1 (tolerance absorption): one scalar among a huge group is absent from the mean; a dominant final scalar kills it."),
Rule("groupnorm-sqdev-tail-scalar-drop", "boundary",
r"if \(i < group_size\) \{\s*float centered = x\[group_start \+ i\] - mean;",
r"if (i + 1 < group_size) {\n float centered = x[group_start + i] - mean;",
"Mechanism 1 (tolerance absorption): one of many variance contributions is omitted; a high-leverage final outlier kills it."),
# Synchronization faults, restricted to named barriers actually present.
Rule("matmul-after-load-warp-barrier", "sync",
r"__syncthreads\(\); // sync-after-load",
r"__syncwarp(); // sync-after-load",
"Mechanism 4 (benign race): warp-local progress often sees similar positive tiles; lane/warp-skewed tile values kill it."),
Rule("matmul-after-compute-warp-barrier", "sync",
r"__syncthreads\(\); // sync-after-compute",
r"__syncwarp(); // sync-after-compute",
"Mechanism 4 (benign race): stale and next-tile random values are statistically similar; a tile-alternating high/low input kills it."),
Rule("groupnorm-sum-store-warp-barrier", "sync",
r"__syncthreads\(\); // sync-after-sum-store",
r"__syncwarp(); // sync-after-sum-store",
"Mechanism 4 (benign race): similar lane partials mask cross-warp publication races; lane-chunk contrast kills it."),
Rule("groupnorm-sqdev-store-warp-barrier", "sync",
r"__syncthreads\(\); // sync-after-sqdev-store",
r"__syncwarp(); // sync-after-sqdev-store",
"Mechanism 4 (benign race): uniform inputs give similar squared-deviation partials; a lane-localized outlier kills it."),
Rule("groupnorm-final-output-warp-barrier", "sync",
r"__syncthreads\(\); // sync-before-output",
r"__syncwarp(); // sync-before-output",
"Mechanism 4 (benign race): the preceding reduction barrier normally makes this nearly redundant; adversarial scheduling with divergent lanes kills it."),
Rule("batchnorm-local-stats-warp-barrier", "sync",
r"__syncthreads\(\); // sync-after-local-statistics",
r"__syncwarp(); // sync-after-local-statistics",
"Mechanism 4 (benign race): uniform random lane statistics are close; per-lane distributions with very different means kill it."),
Rule("batchnorm-merge-warp-barrier", "sync",
r"__syncthreads\(\); // sync-after-welford-merge",
r"__syncwarp(); // sync-after-welford-merge",
"Mechanism 4 (benign race): similar Welford partials hide stale cross-warp merges; alternating lane chunks kill it."),
Rule("batchnorm-output-warp-barrier", "sync",
r"__syncthreads\(\); // sync-before-output-pass",
r"__syncwarp(); // sync-before-output-pass",
"Mechanism 4 (benign race): statistics are already reduced before this mostly redundant barrier; forced warp skew kills it."),
# Small numerical perturbations kept well inside the 1% oracle slack.
Rule("avgpool121-denom-perturb", "precision", r"sum / 121\.0f",
r"sum / 121.01f",
"Mechanism 1 (tolerance absorption): the relative scale error is below 0.01%; a much tighter tolerance kills it."),
Rule("hardsigmoid-six-denom-perturb", "precision", r"val / 6\.0f",
r"val / 6.001f",
"Mechanism 1 (tolerance absorption): the slope error is ~0.017%; a tight oracle near the linear-region edge kills it."),
Rule("hardsigmoid-half-ulpish-perturb", "precision", r"\+ 0\.5f, 0\.0f\)",
r"+ 0.5001f, 0.0f)",
"Mechanism 1 (tolerance absorption): a 1e-4 offset is below atol; a sub-1e-4 tolerance kills it."),
Rule("softplus-cutoff-tiny-shift", "precision", r"val > 20\.0f \?",
r"val > 19.99f ?",
"Mechanism 2 (input-domain evasion): original values never approach the large branch cutoff; values in [19.99,20] kill it."),
Rule("selu-scale-small-perturb", "precision",
r"1\.0507009873554805f \* \(val > 0\.0f",
r"1.0506009873554805f * (val > 0.0f",
"Mechanism 1 (tolerance absorption): the global relative error is under 0.01%; a tighter relative tolerance kills it."),
Rule("selu-alpha-small-perturb", "precision",
r"1\.6732632423543772f \* \(expf\(val\)",
r"1.6731632423543772f * (expf(val)",
"Mechanism 2 (input-domain evasion): the alpha is unused for positive originals; negative SELU inputs kill it."),
Rule("groupnorm-epsilon-halved", "precision", r"\+ 1\.0e-5f\)",
r"+ 5.0e-6f)",
"Mechanism 1 (tolerance absorption): ordinary random variance dwarfs epsilon; nearly constant inputs with variance below 1e-5 kill it."),
Rule("batchnorm-epsilon-small-bias", "precision", r"channel_variance \+ eps",
r"channel_variance + eps * 0.99f",
"Mechanism 1 (tolerance absorption): variance dominates a 1% epsilon perturbation; sub-epsilon variance kills it."),
Rule("matmul-acc-store-fma-nudge", "precision", r"= acc; \}",
r"= acc * 0.9999f; }",
"Mechanism 1 (tolerance absorption): a 0.01% store-scale error is hidden by rtol; a tighter relative oracle kills it."),
# Index and semantic faults which activate only on rare/domain-specific data.
Rule("argmax-final-row-alias", "indexing", r"best_row = \(long long\)r;",
r"best_row = (long long)(r == R - 1 ? r - 1 : r);",
"Mechanism 2 (input-domain evasion): it differs only when the unique maximum is in the final row; a final-row spike kills it."),
Rule("argmax-final-row-value-alias", "indexing", r"x\[base \+ \(long long\)r \* C\]",
r"x[base + (long long)(r == R - 1 ? r - 1 : r) * C]",
"Mechanism 2 (input-domain evasion): only the last candidate is misindexed and is rarely maximal; a final-row spike kills it."),
Rule("selu-positive-cutoff-nudge", "semantic", r"val > 0\.0f \? val :",
r"val > -1.0e-6f ? val :",
"Mechanism 2 (input-domain evasion): ordinary positive values avoid the moved cutoff; tiny negative values in [-1e-6,0] kill it."),
Rule("elu-positive-cutoff-nudge", "semantic",
r"val > 0\.0f \? val : \(expf\(val\) - 1\.0f\)",
r"val > -1.0e-6f ? val : (expf(val) - 1.0f)",
"Mechanism 2 (input-domain evasion): positive originals take the same branch; tiny negative values kill it."),
Rule("softsign-positive-fabs-elide", "semantic", r"1\.0f \+ fabsf\(val\)",
r"1.0f + val",
"Mechanism 2 (input-domain evasion): fabs is identical for positive originals; any negative input kills it."),
]
|