Repository navigation
Lint the yamls, test op registration, and register the CPU runner's kernels (#24935) - #24935
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/24935
Note: Links to docs will display an error until the docs builds have been completed. ⏳ No Failures, 44 PendingAs of commit 9ada95e with merge base c81eb10 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@aliafzal has exported this pull request. If you are a Meta employee, you can view the originating Diff in D128295395. |
This PR needs a
|
…ernels (pytorch#24935) Summary: Pull Request resolved: pytorch#24935 The x86 `cadence_runner` couldn't load most programs the Cadence compiler produces for CPU, because `backends/cadence/aot/functions.yaml` didn't register their kernels, and nothing checked the yamls or the registry. This diff adds both checks and registers the missing kernels. The yaml lint, `aot/tests/test_functions_yaml.py`, checks every `functions*.yaml` for kernel names codegen can't resolve and for namespaces outside the libraries the backend builds. It found five bad entries, fixed here. `functions.yaml` registered `cadence::quantized_max_pool2d.out`, an op that no longer exists, instead of the `quantized_max_pool2d_nchw.out` the compiler emits. `functions_hifi.yaml` bound `quantize_per_tensor_asym16u` and `dequantize_per_tensor_asym32s` to the asym16s kernels, which clamp to int16 and read int32 as int16; on the simulator a round trip of 1.0 returned 0.65534 and alternating -0.31072 and 0.00001, and with the right kernels it returns 1.0, so this changes HiFi results for those two ops from wrong to correct. `functions_fusion_g3.yaml` had an extra `native::` in two names; Fusion G3 doesn't build against the pinned nnlib yet, so no CI result changes. The registry test, `cadence_op_registry_test`, links the ops library and checks with `registry_has_op_function` that every op codegen selected from the yaml is registered. It catches a dropped registration, an unlinked kernel library, or the kernel table filling up before every op is registered. It reads its expected ops from the same yaml, so it can't catch an op missing from the yaml altogether; the backend test suite catches that. It runs on the host for `functions.yaml`, where it shares the runner's codegen and yaml but not its link line, because the runner links `cadence_ops_lib` again in its second-stage build, and on the simulator for the HiFi cores. Vision isn't included because OSS has neither a Vision op-test job nor the `vision/operators/tests/CMakeLists.txt` that would supply gtest; with a stub CMakeLists the test passes on the Vision simulator, so adding it is a separate change with its own CI job. The diff registers the 7 Cadence ops the compiler emits for CPU (`conv1d`, `conv2d`, `avg_pool2d`, `fully_connected`, `transposed_im2row`, `transposed_convolution` and `_softmax_f32_f32`) against the existing generic kernels, and 38 ATen ops against their portable kernels. `conv3d` stays unregistered until a test covers it, and the 3-D pools have no portable kernel. `aten::linear.out` maps to the generic `fully_connected` kernel because the compiler keeps `aten.linear` on purpose and there is no portable linear kernel. `ReplaceLinearWithFullyConnectedOpPass` rewrites a linear to `fully_connected` only when it has one row, because the HiFi kernels compute one row, but the generic kernel computes every leading row with the same schema, and the kernel diff earlier in this stack added its dtype and shape checks. `cadence_ops_lib` now links `portable_kernels` instead of the hand-kept source list in `aten_ops_cadence`, which is removed, so `functions.yaml` is the only list. Registration still comes only from the yaml and the linker keeps only the kernels it references, so the runner grows from 3.1 MB to 4.4 MB. The HiFi, Vision and Fusion G3 builds don't change. Authored with Claude Code. Reviewed By: DrJessop Differential Revision: D128295395
1b04b38 to
e8bae98
Compare
…ernels (pytorch#24935) Summary: Pull Request resolved: pytorch#24935 The x86 `cadence_runner` couldn't load most programs the Cadence compiler produces for CPU, because `backends/cadence/aot/functions.yaml` didn't register their kernels, and nothing checked the yamls or the registry. This diff adds both checks and registers the missing kernels. The yaml lint, `aot/tests/test_functions_yaml.py`, checks every `functions*.yaml` for kernel names codegen can't resolve and for namespaces outside the libraries the backend builds. It found five bad entries, fixed here. `functions.yaml` registered `cadence::quantized_max_pool2d.out`, an op that no longer exists, instead of the `quantized_max_pool2d_nchw.out` the compiler emits. `functions_hifi.yaml` bound `quantize_per_tensor_asym16u` and `dequantize_per_tensor_asym32s` to the asym16s kernels, which clamp to int16 and read int32 as int16; on the simulator a round trip of 1.0 returned 0.65534 and alternating -0.31072 and 0.00001, and with the right kernels it returns 1.0, so this changes HiFi results for those two ops from wrong to correct. `functions_fusion_g3.yaml` had an extra `native::` in two names; Fusion G3 doesn't build against the pinned nnlib yet, so no CI result changes. The registry test, `cadence_op_registry_test`, links the ops library and checks with `registry_has_op_function` that every op codegen selected from the yaml is registered. It catches a dropped registration, an unlinked kernel library, or the kernel table filling up before every op is registered. It reads its expected ops from the same yaml, so it can't catch an op missing from the yaml altogether; the backend test suite catches that. It runs on the host for `functions.yaml`, where it shares the runner's codegen and yaml but not its link line, because the runner links `cadence_ops_lib` again in its second-stage build, and on the simulator for the HiFi cores. Vision isn't included because OSS has neither a Vision op-test job nor the `vision/operators/tests/CMakeLists.txt` that would supply gtest; with a stub CMakeLists the test passes on the Vision simulator, so adding it is a separate change with its own CI job. The diff registers the 7 Cadence ops the compiler emits for CPU (`conv1d`, `conv2d`, `avg_pool2d`, `fully_connected`, `transposed_im2row`, `transposed_convolution` and `_softmax_f32_f32`) against the existing generic kernels, and 38 ATen ops against their portable kernels. `conv3d` stays unregistered until a test covers it, and the 3-D pools have no portable kernel. `aten::linear.out` maps to the generic `fully_connected` kernel because the compiler keeps `aten.linear` on purpose and there is no portable linear kernel. `ReplaceLinearWithFullyConnectedOpPass` rewrites a linear to `fully_connected` only when it has one row, because the HiFi kernels compute one row, but the generic kernel computes every leading row with the same schema, and the kernel diff earlier in this stack added its dtype and shape checks. `cadence_ops_lib` now links `portable_kernels` instead of the hand-kept source list in `aten_ops_cadence`, which is removed, so `functions.yaml` is the only list. Registration still comes only from the yaml and the linker keeps only the kernels it references, so the runner grows from 3.1 MB to 4.4 MB. The HiFi, Vision and Fusion G3 builds don't change. Authored with Claude Code. Reviewed By: DrJessop Differential Revision: D128295395
…ernels (pytorch#24935) Summary: Pull Request resolved: pytorch#24935 The x86 `cadence_runner` couldn't load most programs the Cadence compiler produces for CPU, because `backends/cadence/aot/functions.yaml` didn't register their kernels, and nothing checked the yamls or the registry. This diff adds both checks and registers the missing kernels. The yaml lint, `aot/tests/test_functions_yaml.py`, checks every `functions*.yaml` for kernel names codegen can't resolve and for namespaces outside the libraries the backend builds. It found five bad entries, fixed here. `functions.yaml` registered `cadence::quantized_max_pool2d.out`, an op that no longer exists, instead of the `quantized_max_pool2d_nchw.out` the compiler emits. `functions_hifi.yaml` bound `quantize_per_tensor_asym16u` and `dequantize_per_tensor_asym32s` to the asym16s kernels, which clamp to int16 and read int32 as int16; on the simulator a round trip of 1.0 returned 0.65534 and alternating -0.31072 and 0.00001, and with the right kernels it returns 1.0, so this changes HiFi results for those two ops from wrong to correct. `functions_fusion_g3.yaml` had an extra `native::` in two names; Fusion G3 doesn't build against the pinned nnlib yet, so no CI result changes. The registry test, `cadence_op_registry_test`, links the ops library and checks with `registry_has_op_function` that every op codegen selected from the yaml is registered. It catches a dropped registration, an unlinked kernel library, or the kernel table filling up before every op is registered. It reads its expected ops from the same yaml, so it can't catch an op missing from the yaml altogether; the backend test suite catches that. It runs on the host for `functions.yaml`, where it shares the runner's codegen and yaml but not its link line, because the runner links `cadence_ops_lib` again in its second-stage build, and on the simulator for the HiFi cores. Vision isn't included because OSS has neither a Vision op-test job nor the `vision/operators/tests/CMakeLists.txt` that would supply gtest; with a stub CMakeLists the test passes on the Vision simulator, so adding it is a separate change with its own CI job. The diff registers the 7 Cadence ops the compiler emits for CPU (`conv1d`, `conv2d`, `avg_pool2d`, `fully_connected`, `transposed_im2row`, `transposed_convolution` and `_softmax_f32_f32`) against the existing generic kernels, and 38 ATen ops against their portable kernels. `conv3d` stays unregistered until a test covers it, and the 3-D pools have no portable kernel. `aten::linear.out` maps to the generic `fully_connected` kernel because the compiler keeps `aten.linear` on purpose and there is no portable linear kernel. `ReplaceLinearWithFullyConnectedOpPass` rewrites a linear to `fully_connected` only when it has one row, because the HiFi kernels compute one row, but the generic kernel computes every leading row with the same schema, and the kernel diff earlier in this stack added its dtype and shape checks. `cadence_ops_lib` now links `portable_kernels` instead of the hand-kept source list in `aten_ops_cadence`, which is removed, so `functions.yaml` is the only list. Registration still comes only from the yaml and the linker keeps only the kernels it references, so the runner grows from 3.1 MB to 4.4 MB. The HiFi, Vision and Fusion G3 builds don't change. Authored with Claude Code. Reviewed By: DrJessop Differential Revision: D128295395
…ernels (pytorch#24935) Summary: Pull Request resolved: pytorch#24935 The x86 `cadence_runner` couldn't load most programs the Cadence compiler produces for CPU, because `backends/cadence/aot/functions.yaml` didn't register their kernels, and nothing checked the yamls or the registry. This diff adds both checks and registers the missing kernels. The yaml lint, `aot/tests/test_functions_yaml.py`, checks every `functions*.yaml` for kernel names codegen can't resolve and for namespaces outside the libraries the backend builds. It found five bad entries, fixed here. `functions.yaml` registered `cadence::quantized_max_pool2d.out`, an op that no longer exists, instead of the `quantized_max_pool2d_nchw.out` the compiler emits. `functions_hifi.yaml` bound `quantize_per_tensor_asym16u` and `dequantize_per_tensor_asym32s` to the asym16s kernels, which clamp to int16 and read int32 as int16; on the simulator a round trip of 1.0 returned 0.65534 and alternating -0.31072 and 0.00001, and with the right kernels it returns 1.0, so this changes HiFi results for those two ops from wrong to correct. `functions_fusion_g3.yaml` had an extra `native::` in two names; Fusion G3 doesn't build against the pinned nnlib yet, so no CI result changes. The registry test, `cadence_op_registry_test`, links the ops library and checks with `registry_has_op_function` that every op codegen selected from the yaml is registered. It catches a dropped registration, an unlinked kernel library, or the kernel table filling up before every op is registered. It reads its expected ops from the same yaml, so it can't catch an op missing from the yaml altogether; the backend test suite catches that. It runs on the host for `functions.yaml`, where it shares the runner's codegen and yaml but not its link line, because the runner links `cadence_ops_lib` again in its second-stage build, and on the simulator for the HiFi cores. Vision isn't included because OSS has neither a Vision op-test job nor the `vision/operators/tests/CMakeLists.txt` that would supply gtest; with a stub CMakeLists the test passes on the Vision simulator, so adding it is a separate change with its own CI job. The diff registers the 7 Cadence ops the compiler emits for CPU (`conv1d`, `conv2d`, `avg_pool2d`, `fully_connected`, `transposed_im2row`, `transposed_convolution` and `_softmax_f32_f32`) against the existing generic kernels, and 38 ATen ops against their portable kernels. `conv3d` stays unregistered until a test covers it, and the 3-D pools have no portable kernel. `aten::linear.out` maps to the generic `fully_connected` kernel because the compiler keeps `aten.linear` on purpose and there is no portable linear kernel. `ReplaceLinearWithFullyConnectedOpPass` rewrites a linear to `fully_connected` only when it has one row, because the HiFi kernels compute one row, but the generic kernel computes every leading row with the same schema, and the kernel diff earlier in this stack added its dtype and shape checks. `cadence_ops_lib` now links `portable_kernels` instead of the hand-kept source list in `aten_ops_cadence`, which is removed, so `functions.yaml` is the only list. Registration still comes only from the yaml and the linker keeps only the kernels it references, so the runner grows from 3.1 MB to 4.4 MB. The HiFi, Vision and Fusion G3 builds don't change. Authored with Claude Code. Reviewed By: DrJessop Differential Revision: D128295395
e8bae98 to
b2ef6ae
Compare
Summary: Pull Request resolved: pytorch#24689 **Problem:** `EXIRATenDialectVerifier` and `EXIREdgeDialectVerifier` merge the config's `preserve_ops` and `_core_aten_ops_exception_list` into the lists the caller passes, in place. `to_edge` passes `compile_config.preserve_ops` itself, so each call appends the list to itself and it grows 4x per `to_edge` call. A caller that reuses one list grows it without bound: the Cadence compiler passes the module-level `TO_EDGE_PRESERVE_OPS` to every call, which holds 4, 16, 64 and 256 entries after 1 to 4 lowerings. Each lowering is slower than the last, and a test process that lowers hundreds of programs times out. **Fix:** copy both lists before merging. **Was the in-place merge intended?** No. Before the change that added `preserve_ops` to `EdgeCompileConfig`, the verifier built a new list (`config_list + (exception_list or [])`). That change switched to `_x = x or []` followed by `_x.extend(...)`, and `x or []` returns the caller's own list. This restores the earlier behavior. **Blast radius:** within one call, the verifier sees the same merged lists as before. The only difference is between calls: a reused list no longer collects duplicates, or entries from an earlier call's config. We found no caller that reads its list back after the call. **Follow-up, not in this diff:** `to_edge_transform_and_lower` reassigns `_core_aten_ops_exception_list` on the caller's config. Authored with Claude Code. Reviewed By: DrJessop, ethansfng Differential Revision: D128295391
…ly_connected (pytorch#24933) Summary: Pull Request resolved: pytorch#24933 OSS CI never ran the gtests for the Cadence generic (CPU reference) kernels, and 9 of the test files were not in the open-source tree. This diff moves those 9 files into `backends/cadence/generic/operators/tests/`, adds `.ci/scripts/test-cadence-generic.sh` to build and run `cadence_generic_op_tests` on the host, and runs that script from a new `cpu-op-test` job in `build-cadence-runner.yml`, with the same runner and permissions as `cpu-build`. `tests/CMakeLists.txt` now passes `-Qunused-arguments` only to Clang, because GCC rejects the flag. The tests found two kernel bugs. With `ceil_mode=True` and `count_include_pad=True`, the last `avg_pool2d` window can run past the padding, and PyTorch divides that window by the positions inside the padded input, but the kernel always divided by `kh * kw`; in the quantized path it also added the zero point for the positions past the padding. For width 4, kernel 3, stride 2 and padding 1, the last output was 2/3 of the expected value. The kernel now uses the window size inside the padded input for both the divisor and the zero point, so every other window computes the same value as before. Its dtype and layout checks also move from `ET_DCHECK_MSG`, which release builds compile out, to `ET_KERNEL_CHECK_MSG`, so a bad input fails with `InvalidArgument` instead of running anyway. The `fully_connected` kernel read every tensor as float, with no dtype or shape check. The registration diff later in this stack maps `cadence::fully_connected.out` and `aten::linear.out` to it, and with that registration a float64 linear gave values off by up to 4.2e201 and a float16 linear crashed the runner. The kernel now returns `InvalidArgument` unless all tensors are float, the weight is 2-D and the inner dimensions match. Float callers are unaffected. The diff also adds tests for the kernels that had none, taking the count from 66 to 102: the registered kernels no test reached (`quantized_add`, `quantized_mul`, `im2row`, `quantized_max_pool2d_nchw`, uint8 `quantized_matmul`, and uint8 cases for linear, fully_connected and conv2d NHWC), and kernels the CPU runner doesn't register (`rope`, `where_Scalar`, `quantized_embedding_byte`, `linalg_svd`, `sdpa_bitwise_causal_mask_gen` and `roi_align_box_processor`), because other users call those on CPU and a regression should fail OSS CI. Expected values come from `aot/ref_implementations.py`, or are worked out by hand where it has no reference or a wrong one. The `linalg_svd` test compares the singular values with `torch.linalg.svdvals` and checks that U and Vh are orthogonal and reconstruct A, since the singular vectors' signs aren't unique. One reference bug shows up here: `ref_implementations.py` computes the requantization scale as `-M / 2^31`, while the compiler and the kernels use `+M / 2^31` (in the kernels, `1 << 31` is `INT_MIN`). The tests follow the kernels, and fixing the reference is a follow-up. Authored with Claude Code. Reviewed By: DrJessop Differential Revision: D128295392
…h#24931) Summary: Pull Request resolved: pytorch#24931 Running the backend test suite through the Cadence compiler (later in this stack) found four compiler bugs. Each fix has unit tests. Fused quantized linear and conv add the int32 bias to an accumulator whose scale is `input_scale * weight_scale`. torchao's implicit sharing gives every call of a shared module one bias observer, so the bias is quantized once, and `QuantizableLSTM` calls the same `Linear` at every time step with a different input scale. In a 10-step int8 LSTM, 18 of 20 fused linears used a bias scaled 0.03x to 1.14x off, and outputs were up to 0.44 off. `bias_at_scale` now rescales the bias constant to the accumulator scale when the two differ, which brings the int8 LSTM outputs within 0.007 of the quantized reference. Fixing this in the quantizer would also unshare the activation and add a dequantize/quantize pair per call. The fusion is shared by every Cadence backend, but a bias already at the accumulator scale, the usual single-use case, passes through unchanged; the 1e-5 match tolerance on the scale ratio is far above the float32 against float64 rounding, which is under 6e-8. In `CompileMode.SIZE`, the dispatch of `quantized_conv2d_nhwc` passed the generic op's 15th argument, `offset`, to the 14-argument typed variants, so every int8 model with a 2-D convolution failed to compile. The dispatch now drops unset arguments that the typed op doesn't have, and raises if one of them is set. The compiler picks `fully_connected` when the input's leading dimensions multiply to 1, but its 6 metas checked `size(0) == 1`, so a 1-D input, where `size(0)` is the feature count, failed to compile. The metas now check the product of the leading dimensions, the same rule the compiler uses. Memory planning can turn a contiguous `select` into a view of its input. The check read the output shape with the raw `dim`, and since `select` drops its dimension, `select(dim=-2)` on `[3, 4, 5]` checked the wrong dimensions and became a view at the wrong offset. The check now normalizes `dim` against the input's rank and reads the input shape. Positive dims and slices are unaffected. Authored with Claude Code. Reviewed By: DrJessop Differential Revision: D128295394
…ernels (pytorch#24935) Summary: Pull Request resolved: pytorch#24935 The x86 `cadence_runner` couldn't load most programs the Cadence compiler produces for CPU, because `backends/cadence/aot/functions.yaml` didn't register their kernels, and nothing checked the yamls or the registry. This diff adds both checks and registers the missing kernels. The yaml lint, `aot/tests/test_functions_yaml.py`, checks every `functions*.yaml` for kernel names codegen can't resolve and for namespaces outside the libraries the backend builds. It found five bad entries, fixed here. `functions.yaml` registered `cadence::quantized_max_pool2d.out`, an op that no longer exists, instead of the `quantized_max_pool2d_nchw.out` the compiler emits. `functions_hifi.yaml` bound `quantize_per_tensor_asym16u` and `dequantize_per_tensor_asym32s` to the asym16s kernels, which clamp to int16 and read int32 as int16; on the simulator a round trip of 1.0 returned 0.65534 and alternating -0.31072 and 0.00001, and with the right kernels it returns 1.0, so this changes HiFi results for those two ops from wrong to correct. `functions_fusion_g3.yaml` had an extra `native::` in two names; Fusion G3 doesn't build against the pinned nnlib yet, so no CI result changes. The registry test, `cadence_op_registry_test`, links the ops library and checks with `registry_has_op_function` that every op codegen selected from the yaml is registered. It catches a dropped registration, an unlinked kernel library, or the kernel table filling up before every op is registered. It reads its expected ops from the same yaml, so it can't catch an op missing from the yaml altogether; the backend test suite catches that. It runs on the host for `functions.yaml`, where it shares the runner's codegen and yaml but not its link line, because the runner links `cadence_ops_lib` again in its second-stage build, and on the simulator for the HiFi cores. Vision isn't included because OSS has neither a Vision op-test job nor the `vision/operators/tests/CMakeLists.txt` that would supply gtest; with a stub CMakeLists the test passes on the Vision simulator, so adding it is a separate change with its own CI job. The diff registers the 7 Cadence ops the compiler emits for CPU (`conv1d`, `conv2d`, `avg_pool2d`, `fully_connected`, `transposed_im2row`, `transposed_convolution` and `_softmax_f32_f32`) against the existing generic kernels, and 38 ATen ops against their portable kernels. `conv3d` stays unregistered until a test covers it, and the 3-D pools have no portable kernel. `aten::linear.out` maps to the generic `fully_connected` kernel because the compiler keeps `aten.linear` on purpose and there is no portable linear kernel. `ReplaceLinearWithFullyConnectedOpPass` rewrites a linear to `fully_connected` only when it has one row, because the HiFi kernels compute one row, but the generic kernel computes every leading row with the same schema, and the kernel diff earlier in this stack added its dtype and shape checks. `cadence_ops_lib` now links `portable_kernels` instead of the hand-kept source list in `aten_ops_cadence`, which is removed, so `functions.yaml` is the only list. Registration still comes only from the yaml and the linker keeps only the kernels it references, so the runner grows from 3.1 MB to 4.4 MB. The HiFi, Vision and Fusion G3 builds don't change. Authored with Claude Code. Reviewed By: DrJessop Differential Revision: D128295395
…ernels (pytorch#24935) Summary: Pull Request resolved: pytorch#24935 The x86 `cadence_runner` couldn't load most programs the Cadence compiler produces for CPU, because `backends/cadence/aot/functions.yaml` didn't register their kernels, and nothing checked the yamls or the registry. This diff adds both checks and registers the missing kernels. The yaml lint, `aot/tests/test_functions_yaml.py`, checks every `functions*.yaml` for kernel names codegen can't resolve and for namespaces outside the libraries the backend builds. It found five bad entries, fixed here. `functions.yaml` registered `cadence::quantized_max_pool2d.out`, an op that no longer exists, instead of the `quantized_max_pool2d_nchw.out` the compiler emits. `functions_hifi.yaml` bound `quantize_per_tensor_asym16u` and `dequantize_per_tensor_asym32s` to the asym16s kernels, which clamp to int16 and read int32 as int16; on the simulator a round trip of 1.0 returned 0.65534 and alternating -0.31072 and 0.00001, and with the right kernels it returns 1.0, so this changes HiFi results for those two ops from wrong to correct. `functions_fusion_g3.yaml` had an extra `native::` in two names; Fusion G3 doesn't build against the pinned nnlib yet, so no CI result changes. The registry test, `cadence_op_registry_test`, links the ops library and checks with `registry_has_op_function` that every op codegen selected from the yaml is registered. It catches a dropped registration, an unlinked kernel library, or the kernel table filling up before every op is registered. It reads its expected ops from the same yaml, so it can't catch an op missing from the yaml altogether; the backend test suite catches that. It runs on the host for `functions.yaml`, where it shares the runner's codegen and yaml but not its link line, because the runner links `cadence_ops_lib` again in its second-stage build, and on the simulator for the HiFi cores. Vision isn't included because OSS has neither a Vision op-test job nor the `vision/operators/tests/CMakeLists.txt` that would supply gtest; with a stub CMakeLists the test passes on the Vision simulator, so adding it is a separate change with its own CI job. The diff registers the 7 Cadence ops the compiler emits for CPU (`conv1d`, `conv2d`, `avg_pool2d`, `fully_connected`, `transposed_im2row`, `transposed_convolution` and `_softmax_f32_f32`) against the existing generic kernels, and 38 ATen ops against their portable kernels. `conv3d` stays unregistered until a test covers it, and the 3-D pools have no portable kernel. `aten::linear.out` maps to the generic `fully_connected` kernel because the compiler keeps `aten.linear` on purpose and there is no portable linear kernel. `ReplaceLinearWithFullyConnectedOpPass` rewrites a linear to `fully_connected` only when it has one row, because the HiFi kernels compute one row, but the generic kernel computes every leading row with the same schema, and the kernel diff earlier in this stack added its dtype and shape checks. `cadence_ops_lib` now links `portable_kernels` instead of the hand-kept source list in `aten_ops_cadence`, which is removed, so `functions.yaml` is the only list. Registration still comes only from the yaml and the linker keeps only the kernels it references, so the runner grows from 3.1 MB to 4.4 MB. The HiFi, Vision and Fusion G3 builds don't change. Authored with Claude Code. Reviewed By: DrJessop Differential Revision: D128295395
…ernels (pytorch#24935) Summary: Pull Request resolved: pytorch#24935 The x86 `cadence_runner` couldn't load most programs the Cadence compiler produces for CPU, because `backends/cadence/aot/functions.yaml` didn't register their kernels, and nothing checked the yamls or the registry. This diff adds both checks and registers the missing kernels. The yaml lint, `aot/tests/test_functions_yaml.py`, checks every `functions*.yaml` for kernel names codegen can't resolve and for namespaces outside the libraries the backend builds. It found five bad entries, fixed here. `functions.yaml` registered `cadence::quantized_max_pool2d.out`, an op that no longer exists, instead of the `quantized_max_pool2d_nchw.out` the compiler emits. `functions_hifi.yaml` bound `quantize_per_tensor_asym16u` and `dequantize_per_tensor_asym32s` to the asym16s kernels, which clamp to int16 and read int32 as int16; on the simulator a round trip of 1.0 returned 0.65534 and alternating -0.31072 and 0.00001, and with the right kernels it returns 1.0, so this changes HiFi results for those two ops from wrong to correct. `functions_fusion_g3.yaml` had an extra `native::` in two names; Fusion G3 doesn't build against the pinned nnlib yet, so no CI result changes. The registry test, `cadence_op_registry_test`, links the ops library and checks with `registry_has_op_function` that every op codegen selected from the yaml is registered. It catches a dropped registration, an unlinked kernel library, or the kernel table filling up before every op is registered. It reads its expected ops from the same yaml, so it can't catch an op missing from the yaml altogether; the backend test suite catches that. It runs on the host for `functions.yaml`, where it shares the runner's codegen and yaml but not its link line, because the runner links `cadence_ops_lib` again in its second-stage build, and on the simulator for the HiFi cores. Vision isn't included because OSS has neither a Vision op-test job nor the `vision/operators/tests/CMakeLists.txt` that would supply gtest; with a stub CMakeLists the test passes on the Vision simulator, so adding it is a separate change with its own CI job. The diff registers the 7 Cadence ops the compiler emits for CPU (`conv1d`, `conv2d`, `avg_pool2d`, `fully_connected`, `transposed_im2row`, `transposed_convolution` and `_softmax_f32_f32`) against the existing generic kernels, and 38 ATen ops against their portable kernels. `conv3d` stays unregistered until a test covers it, and the 3-D pools have no portable kernel. `aten::linear.out` maps to the generic `fully_connected` kernel because the compiler keeps `aten.linear` on purpose and there is no portable linear kernel. `ReplaceLinearWithFullyConnectedOpPass` rewrites a linear to `fully_connected` only when it has one row, because the HiFi kernels compute one row, but the generic kernel computes every leading row with the same schema, and the kernel diff earlier in this stack added its dtype and shape checks. `cadence_ops_lib` now links `portable_kernels` instead of the hand-kept source list in `aten_ops_cadence`, which is removed, so `functions.yaml` is the only list. Registration still comes only from the yaml and the linker keeps only the kernels it references, so the runner grows from 3.1 MB to 4.4 MB. The HiFi, Vision and Fusion G3 builds don't change. Authored with Claude Code. Reviewed By: DrJessop Differential Revision: D128295395
c8f9deb to
6bca9f2
Compare
…d consolidate HUD reporting (#25989) ### Summary The Cadence uint8 tests for fully connected, linear, and matmul still describe a negated multiplier. Restore the three comments from #25953 that were overwritten when the kernel registry change landed in #24935. Bring the CUDA INT4 test fix from #24096 to `main`. Inductor can append a suffix to a generated kernel name. The test now finds that definition and checks that its autotune decorator contains exactly one configuration. Restore the Buck header namespace for the extension macro updated in #23939. This lets callers in other Buck packages use the same `executorch/extension/pybindings/...` includes as `pybindings.cpp`. Finish the HUD reporting cleanup from #24992. Linux CMake gets the reporter from the root pytest configuration. The standalone Cortex-M jobs added in #25798 use a separate pytest configuration, so they load the same reporting hook explicitly and retain their report names and seeding. This removes the shell helper and its dedicated tests. Authored with assistance from OpenAI Codex. ### Test plan ```bash python -m pytest -q .ci/scripts/tests/test_{torchci_*,cortex_m_reporting,coreml_markers}.py ``` All 190 tests passed. The Cortex-M test ran each workflow command against a smoke suite and checked the report prefix, repo-relative test ID, and selected target. Verified that the three Cadence files match #25953, exercised the CUDA source assertion with suffixed and unsuffixed names and failing inputs, and checked all three Buck header paths against the C++ includes. The GPU test and a full Buck build were not run locally.
Summary:
The x86
cadence_runnercouldn't load most programs the Cadence compiler produces for CPU, becausebackends/cadence/aot/functions.yamldidn't register their kernels, and nothing checked the yamls or the registry. This diff adds both checks and registers the missing kernels.The yaml lint,
aot/tests/test_functions_yaml.py, checks everyfunctions*.yamlfor kernel names codegen can't resolve and for namespaces outside the libraries the backend builds. It found five bad entries, fixed here.functions.yamlregisteredcadence::quantized_max_pool2d.out, an op that no longer exists, instead of thequantized_max_pool2d_nchw.outthe compiler emits.functions_hifi.yamlboundquantize_per_tensor_asym16uanddequantize_per_tensor_asym32sto the asym16s kernels, which clamp to int16 and read int32 as int16; on the simulator a round trip of 1.0 returned 0.65534 and alternating -0.31072 and 0.00001, and with the right kernels it returns 1.0, so this changes HiFi results for those two ops from wrong to correct.functions_fusion_g3.yamlhad an extranative::in two names; Fusion G3 doesn't build against the pinned nnlib yet, so no CI result changes.The registry test,
cadence_op_registry_test, links the ops library and checks withregistry_has_op_functionthat every op codegen selected from the yaml is registered. It catches a dropped registration, an unlinked kernel library, or the kernel table filling up before every op is registered. It reads its expected ops from the same yaml, so it can't catch an op missing from the yaml altogether; the backend test suite catches that. It runs on the host forfunctions.yaml, where it shares the runner's codegen and yaml but not its link line, because the runner linkscadence_ops_libagain in its second-stage build, and on the simulator for the HiFi cores. Vision isn't included because OSS has neither a Vision op-test job nor thevision/operators/tests/CMakeLists.txtthat would supply gtest; with a stub CMakeLists the test passes on the Vision simulator, so adding it is a separate change with its own CI job.The diff registers the 7 Cadence ops the compiler emits for CPU (
conv1d,conv2d,avg_pool2d,fully_connected,transposed_im2row,transposed_convolutionand_softmax_f32_f32) against the existing generic kernels, and 38 ATen ops against their portable kernels.conv3dstays unregistered until a test covers it, and the 3-D pools have no portable kernel.aten::linear.outmaps to the genericfully_connectedkernel because the compiler keepsaten.linearon purpose and there is no portable linear kernel.ReplaceLinearWithFullyConnectedOpPassrewrites a linear tofully_connectedonly when it has one row, because the HiFi kernels compute one row, but the generic kernel computes every leading row with the same schema, and the kernel diff earlier in this stack added its dtype and shape checks.cadence_ops_libnow linksportable_kernelsinstead of the hand-kept source list inaten_ops_cadence, which is removed, sofunctions.yamlis the only list. Registration still comes only from the yaml and the linker keeps only the kernels it references, so the runner grows from 3.1 MB to 4.4 MB. The HiFi, Vision and Fusion G3 builds don't change.Authored with Claude Code.
Reviewed By: DrJessop
Differential Revision: D128295395