[WebNN] Fixed WebNN Module undefined issue (#22795)

`Module.jsepRegisterMLConstant` will be shorten by Closure Compiler in
offical release, this would cause undefined error.

Fix it by using `Module['jsepRegisterMLConstant']`.
This commit is contained in:
Wanming Lin 2024-11-12 13:31:24 +08:00 committed by GitHub
parent 0ad44d0f79
commit cdc8db9984
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 2 deletions

View file

@ -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,

View file

@ -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;
}
}

View file

@ -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);
};