Skip to content

Commit

Permalink
[WebNN] Fixed WebNN Module undefined issue (#22795)
Browse files Browse the repository at this point in the history
`Module.jsepRegisterMLConstant` will be shorten by Closure Compiler in
offical release, this would cause undefined error.

Fix it by using `Module['jsepRegisterMLConstant']`.
  • Loading branch information
Honry authored Nov 12, 2024
1 parent 0ad44d0 commit cdc8db9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion js/web/lib/wasm/jsep/backend-webnn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export class WebNNBackend {
return id;
}

// Register WebNN Constant operands from external data.
// Register a WebNN Constant operand from external data.
public registerMLConstant(
externalFilePath: string,
dataOffset: number,
Expand Down
17 changes: 17 additions & 0 deletions js/web/lib/wasm/wasm-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,23 @@ export declare namespace JSEP {
* @returns
*/
jsepCreateMLContext(optionsOrGpuDevice?: MLContextOptions | GPUDevice): Promise<MLContext>;

/**
* [exported from pre-jsep.js] Register a WebNN Constant operand from external data.
* @param externalFilePath - specify the external file path.
* @param dataOffset - specify the external data offset.
* @param dataLength - specify the external data length.
* @param builder - specify the MLGraphBuilder used for constructing the Constant.
* @param desc - specify the MLOperandDescriptor of the Constant.
* @returns the WebNN Constant operand for the specified external data.
*/
jsepRegisterMLConstant(
externalFilePath: string,
dataOffset: number,
dataLength: number,
builder: MLGraphBuilder,
desc: MLOperandDescriptor,
): MLOperand;
}
}

Expand Down
2 changes: 1 addition & 1 deletion onnxruntime/wasm/pre-jsep.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ Module['jsepInit'] = (name, params) => {
Module['jsepCreateMLContext'] = (optionsOrGpuDevice) => {
return backend['createMLContext'](optionsOrGpuDevice);
};
Module.jsepRegisterMLConstant = (externalFilePath, dataOffset, dataLength, builder, desc) => {
Module['jsepRegisterMLConstant'] = (externalFilePath, dataOffset, dataLength, builder, desc) => {
return backend['registerMLConstant'](
externalFilePath, dataOffset, dataLength, builder, desc, Module.MountedFiles);
};
Expand Down

0 comments on commit cdc8db9

Please sign in to comment.