Fix WebGPU context memory identity and test host-owned caches (#33110)
## Summary
Native external-Dawn hosts can supply a Dawn instance and device with a
positive
ORT context ID. WebGPU allocators previously advertised memory-device ID
zero
regardless of that context, leaving allocator lookup, streams, and
transfer
routing unable to distinguish separate Dawn memory domains. Plugin
stream
validation exposed this mismatch during custom-context session
initialization.
This PR fixes the identity mismatch rather than weakening the stream
check:
- Propagate the context ID through WebGPU session allocators and the
plugin's
default memory device, with range validation before context creation.
- Forward the requested memory device to plugin stream creation and
retain the
owning-context identity check.
- Route shared WebGPU transfers using tensor memory-device IDs and
reject GPU
copies between distinct contexts or foreign GPU vendors.
- Extend the native external-host test with host-created devices,
synchronized
cache callbacks, cache isolation keys, lifetime checks, and failure
cases.
- Keep default and host-owned sessions alive together; verify distinct
allocator
and GPU-output IDs, CPU/GPU and same-context GPU/GPU transfers, and
rejection
of cross-context copies.
- Exercise the native host through existing Windows source-based,
package-backed
built-in, and plugin CI paths, and document device/callback ownership.
Our current deployment uses built-in WebGPU with external Dawn and a
host-owned
device. Plugin and concurrent-context tests are additional regression
coverage,
not a claim that the deployment has migrated to plugins or requires a
default
session alongside the host-owned session. Context IDs identify Dawn
memory
domains, not physical GPU indices. No new public API is introduced.
## Validation
Windows x64 Release with native Dawn:
- Refreshed source-based built-in, package-backed built-in, and
package-backed
plugin builds passed all five host modes, with CPU fallback disabled.
- All three exercised default/custom context allocation and GPU-bound
outputs,
same-context transfers, and cross-context rejection.
- All three observed three actual warm-cache hits and no additional hits
under a
different isolation key, and verified host-device use after ORT
teardown.
- Required-feature rejection, callback failure containment, and
missing-proc-table
rejection passed with their expected diagnostics.
- All 35 plugin framework tests passed, including the requested
stream-device
forwarding regression.
- All four WebGPU transfer tests and the device-ID parser rejection test
passed.
- All 15 changed C++ files passed scoped ORT lintrunner formatting
checks.
Other native platforms remain unvalidated locally. Cache reuse is tested
across
devices within one process; persistence across process restarts is not
covered.