Commit d165fba
authored
CUDA Plugin EP: NHWC Cleanup & Hardening (#28612)
## Summary
Unifies the NHWC-eligible op allowlist between the bundled CUDA EP and
the CUDA plugin EP into a single shared header, adds kernel-miss
diagnostics, and expands NHWC test coverage from 4 ops to 11.
## Motivation
The bundled EP (`cuda_execution_provider.cc`) and the plugin EP
(`plugin/cuda_ep.cc`) independently maintained their own copies of the
NHWC allowlist. This created a maintenance hazard where ops could be
added to one but not the other, leading to silent divergence.
Additionally, there was no runtime diagnostic when the framework rewrote
a node to the NHWC domain but the plugin EP lacked a matching kernel —
failures were silent fallbacks to CPU.
## Key Changes
### Shared NHWC Allowlist (`cuda_nhwc_ops.h`)
| Item | Detail |
|------|--------|
| New file | `onnxruntime/core/providers/cuda/cuda_nhwc_ops.h` |
| Contents | `IsNhwcEligibleOnnxOp()`, `IsNhwcEligibleMsOp()`,
`IsNhwcEligible()` inline functions |
| Ops covered | AveragePool, BatchNormalization, Conv, ConvTranspose,
DepthToSpace, GlobalAveragePool, GlobalMaxPool, GridSample, LRN,
MaxPool, SpaceToDepth (+ MS-domain GridSample) |
### Bundled EP Refactor (`cuda_execution_provider.cc`)
- Removed the static `std::unordered_set<std::string_view>
cuda_nhwc_onnx_ops` and the inline domain check logic.
- Replaced with a single call to `cuda::IsNhwcEligible(node_domain,
node_op_type)`.
### Plugin EP Refactor & Diagnostics (`plugin/cuda_ep.cc`)
- `ShouldConvertDataLayoutForOpImpl`: Replaced ~20 lines of static set +
domain checks with a single `cuda::IsNhwcEligible()` call.
- `GetCapabilityImpl`: Added a WARNING-level diagnostic in the `else`
branch (kernel not found). When a node in the `com.ms.internal.nhwc`
domain has no registered kernel, the log emits the op type, domain,
version, and node name — making future NHWC registration gaps
immediately visible at session creation.
### Expanded NHWC Test Coverage (`test_cuda_plugin_ep.py`)
- Added `_assert_nhwc_domain_assigned()` helper that verifies NHWC
layout transformation occurred by checking for framework-inserted
Transpose nodes in the EP's assignment info.
- Added `_run_nhwc_model_test()` helper combining domain assertion +
numerical validation.
- Updated 4 existing NHWC tests (Conv, BatchNormalization, MaxPool,
AveragePool) to include structural assertions.
- Added 7 new NHWC test methods:
- `test_nhwc_conv_transpose`
- `test_nhwc_global_max_pool`
- `test_nhwc_global_average_pool`
- `test_nhwc_depth_to_space`
- `test_nhwc_space_to_depth`
- `test_nhwc_lrn`
- `test_nhwc_grid_sample`
## Testing Notes
Run the full CUDA plugin EP test suite with NHWC enabled:
```bash
bash .env/cuda13_plugin.sh --build --install --test_plugin
```
Or run only the NHWC tests directly:
```bash
cd onnxruntime/test/python/transformers
ORT_TEST_CUDA_PLUGIN_EP=1 python -m unittest \
test_cuda_plugin_ep.TestCudaPluginEP.test_nhwc_conv \
test_cuda_plugin_ep.TestCudaPluginEP.test_nhwc_batch_normalization \
test_cuda_plugin_ep.TestCudaPluginEP.test_nhwc_maxpool \
test_cuda_plugin_ep.TestCudaPluginEP.test_nhwc_avgpool \
test_cuda_plugin_ep.TestCudaPluginEP.test_nhwc_conv_transpose \
test_cuda_plugin_ep.TestCudaPluginEP.test_nhwc_global_max_pool \
test_cuda_plugin_ep.TestCudaPluginEP.test_nhwc_global_average_pool \
test_cuda_plugin_ep.TestCudaPluginEP.test_nhwc_depth_to_space \
test_cuda_plugin_ep.TestCudaPluginEP.test_nhwc_space_to_depth \
test_cuda_plugin_ep.TestCudaPluginEP.test_nhwc_lrn \
test_cuda_plugin_ep.TestCudaPluginEP.test_nhwc_grid_sample
```
All 86 tests in the suite pass (11 NHWC + 75 existing), with no
regressions.1 parent 6a517f5 commit d165fba
4 files changed
Lines changed: 355 additions & 49 deletions
File tree
- onnxruntime
- core/providers/cuda
- plugin
- test/python/transformers
Lines changed: 2 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
383 | 384 | | |
384 | 385 | | |
385 | 386 | | |
386 | | - | |
387 | | - | |
388 | | - | |
389 | | - | |
390 | | - | |
391 | | - | |
392 | | - | |
393 | | - | |
394 | | - | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
| 387 | + | |
403 | 388 | | |
404 | 389 | | |
405 | 390 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
214 | 215 | | |
215 | 216 | | |
216 | 217 | | |
217 | | - | |
| 218 | + | |
218 | 219 | | |
219 | 220 | | |
220 | 221 | | |
| |||
229 | 230 | | |
230 | 231 | | |
231 | 232 | | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
232 | 245 | | |
233 | 246 | | |
234 | 247 | | |
| |||
308 | 321 | | |
309 | 322 | | |
310 | 323 | | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | | - | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
| 324 | + | |
331 | 325 | | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
| 326 | + | |
| 327 | + | |
338 | 328 | | |
339 | | - | |
340 | | - | |
341 | 329 | | |
342 | 330 | | |
343 | 331 | | |
| |||
0 commit comments