Skip to content

Add D3D12 agility SDK dependency to fix crashes on long prompts - #612

Merged
Patrice Vignola (PatriceVignola) merged 3 commits into
mainfrom
user/pavignol/add-d3d12-agility-sdk
Jun 18, 2024
Merged

Add D3D12 agility SDK dependency to fix crashes on long prompts#612
Patrice Vignola (PatriceVignola) merged 3 commits into
mainfrom
user/pavignol/add-d3d12-agility-sdk

Conversation

@PatriceVignola

Copy link
Copy Markdown
Contributor

No description provided.

@PatriceVignola
Patrice Vignola (PatriceVignola) requested a review from a team June 17, 2024 18:31

@baijumeswani Baiju Meswani (baijumeswani) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will need to merge #613 to get the CIs green.

Comment thread src/models/model.cpp
@PatriceVignola
Patrice Vignola (PatriceVignola) deleted the user/pavignol/add-d3d12-agility-sdk branch June 18, 2024 09:29
kunal-vaishnavi pushed a commit that referenced this pull request Jul 13, 2026
…tory cannot create a device (#2280)

### Problem

`CreateDmlObjects` (`src/dml/dml_helpers.cpp`) tries the Agility SDK
device factory first and **throws on any `CreateDevice` failure**
instead of reaching the existing system-runtime fallback branch:

```cpp
if (SUCCEEDED(D3D12GetInterface(...)) && SUCCEEDED(sdk_config->CreateDeviceFactory(614, module_path, ...))) {
  THROW_IF_FAILED(d3d12_factory->CreateDevice(...));   // throws — fallback below is unreachable
} else {
  ...
  THROW_IF_FAILED(D3D12CreateDevice(...));
}
```

A known failure is `DXGI_ERROR_ALREADY_EXISTS` (0x887A0036): the process
already holds a D3D12 device created with the system runtime — e.g. the
XAML/WinUI compositor in a packaged app creates one at
`Window.Activate()` — and devices from different D3D12 runtimes cannot
coexist in one process. The plain `D3D12CreateDevice` branch handles
exactly this situation, but is unreachable.

Whether this bites is **OS-dependent**: if the in-box D3D12 is older
than the requested SDK version (614), `CreateDeviceFactory` itself fails
and the fallback runs — an OS update silently flips the branch and
breaks `OgaCreateModel` in XAML hosts.

### Fix

Treat a factory `CreateDevice` failure like a factory creation failure:
log a warning with the HRESULT and fall back to `D3D12CreateDevice`.

No regression for #612 (which introduced the Agility path): the new
fallback only runs when the in-box runtime is >= the requested SDK
version — i.e. the system runtime already contains the fixes the Agility
dependency was added for. Related: #1054 (the pre-existing fallback
branch for factory-creation failure).

### Validation (real hardware)

Xbox Series S, Dev Mode UWP (OS 26100), ORT GenAI 0.13.2 DirectML + ORT
1.24.4, SmolLM2-360M INT4 (DML model built with the model builder):

| Scenario | vanilla DLL | patched DLL |
|---|---|---|
| XAML app + DML EP | `887A0036` at `OgaCreateModel` (reproduced 3x) |
loads in 886 ms, weights resident on GPU (315 MB), full decode (739
tokens) |
| XAML app + CPU EP | works | works (67.2 tok/s, unchanged) |
| Headless (no compositor) + DML EP | works via Agility path | works via
Agility path |

---------

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants