Skip to content

Commit

Permalink
Reland "WebNN: Handle WebNN context lost error"
Browse files Browse the repository at this point in the history
This is a reland of commit a240af8bb2c11c08a6649388afdd4896818bf336

Included needed fix:
1. Move calling `ID3D12Device::GetDeviceRemovedReason` before
calling `WebNNContextImpl::OnLost` which will release the context to
avoid UAF for `Adapter`. Because the `Adapter` is referenced by
contexts, it will be released when all contexts are released.
2. Remove two invalid cases for `MLContext::writeBuffer` which will
call `ID3D12Device::CreateCommittedResource` on DirectML with size 0
to avoid crash.

Original change's description:
> WebNN: Handle WebNN context lost error
>
> This CL is to handle the WebNN context lost error and has implemented
> for DirectML backend.
>
> 1. Defined `MLContextLostInfo` dictionary in the WebIDL to expose the
> context lost information.
> 2. Defined `Promise<MLContextLostInfo> lost` of `MLContext` interface
> in the WebIDL, when the lost error is captured, the promise will be
> resolved with the `MLContextLostInfo`.
> 3. Defined `WebNNContextClient` mojom interface and it's method
> `OnLost(string message)` to send the context lost message to
> the renderer process when the `MLContext` object lost error in the
> GPU process is captured. The renderer process will override this
> method to handle the lost error.
> 4. Implemented the context lost handling feature in DirectML backend.
>
> Bug: 40281640, 41492165
> Change-Id: I16775ac8cdbd508e04025c22740d13f01e591b0d
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5602134
> Reviewed-by: Reilly Grant <[email protected]>
> Reviewed-by: ningxin hu <[email protected]>
> Reviewed-by: Rafael Cintron <[email protected]>
> Commit-Queue: Mingming1 Xu <[email protected]>
> Cr-Commit-Position: refs/heads/main@{#1322573}

Bug: 40281640, 41492165
Change-Id: I3eaeb413c3c10e72416ab2932e182be3a01b99e0
Cq-Include-Trybots: luci.chromium.try:win11-blink-rel
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5673825
Reviewed-by: Alex Gough <[email protected]>
Reviewed-by: ningxin hu <[email protected]>
Reviewed-by: Reilly Grant <[email protected]>
Commit-Queue: Mingming1 Xu <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1324640}
  • Loading branch information
mingmingtasd authored and chromium-wpt-export-bot committed Jul 9, 2024
1 parent 2c22eb6 commit 46aa444
Showing 1 changed file with 0 additions and 36 deletions.
36 changes: 0 additions & 36 deletions webnn/resources/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1287,22 +1287,6 @@ const testWriteWebNNBuffer = (testName) => {
ml_buffer, new Uint8Array(sizeOfDescriptor(descriptor))));
}, `${testName} / destroy`);

promise_test(async () => {
const descriptor = {dataType: 'int32', dimensions: [2, 2]};
let ml_buffer = createBuffer(ml_context, descriptor);

// MLBuffer was unsupported for the deviceType.
if (ml_buffer === undefined) {
return;
}

const array_buffer = new ArrayBuffer(sizeOfDescriptor(descriptor));
const detached_buffer = array_buffer.transfer();
assert_true(array_buffer.detached, 'array buffer should be detached.');

ml_context.writeBuffer(ml_buffer, array_buffer);
}, `${testName} / detached`);

promise_test(async () => {
const bufferDescriptor = {dataType: 'int32', dimensions: [2, 3]};
let ml_buffer = createBuffer(ml_context, bufferDescriptor);
Expand Down Expand Up @@ -1397,26 +1381,6 @@ const testReadWebNNBuffer = (testName) => {
ml_context, ml_buffer, Uint8Array.from([0xBB, 0xBB, 0xAA, 0xAA]));
}, `${testName} / src_offset_only`);

promise_test(async () => {
let ml_buffer =
createBuffer(ml_context, {dataType: 'int32', dimensions: [1]});

// MLBuffer was unsupported for the deviceType.
if (ml_buffer === undefined) {
return;
}

// Initialize the buffer.
const input_data = [0xAA, 0xAA, 0xAA, 0xAA];
ml_context.writeBuffer(ml_buffer, Uint8Array.from(input_data));

// Writing zero bytes at the end of the buffer.
ml_context.writeBuffer(
ml_buffer, Uint32Array.from([0xBBBBBBBB]), /*srcOffset=*/ 1);
await assert_buffer_data_equals(
ml_context, ml_buffer, Uint8Array.from(input_data));
}, `${testName} / zero_write`);

promise_test(async () => {
let ml_buffer =
createBuffer(ml_context, {dataType: 'int32', dimensions: [1]});
Expand Down

0 comments on commit 46aa444

Please sign in to comment.