intel / webml-polyfill

Deprecated, the Web Neural Network Polyfill project has been moved to https://github.com/webmachinelearning/webnn-polyfill
Apache License 2.0
161 stars 42 forks source link

[webml/MPS] No exception is thrown when an argument passed to setOperandValue() is incompatible with the type expected #67

Closed Christywl closed 5 years ago

Christywl commented 6 years ago

Test Env: Chromium Version : nightly build 65.0.3324.0 (revision f9e1a31) OS : Mac OS X 10.13.4

Expected Result:

Actual Result: No exception is thrown when an argument passed to setOperandValue() is incompatible with the type expected

How to reproduce: Set the following incompatible value:

    an Int8Array data
    an Uint8ClampedArray data
    an Int16Array data
    an Uint16Array data
    a Float64Array data
    a DataView data
    an Int8Array data
    an Uint8ClampedArray data
    an Int16Array data
    an Uint16Array data
    a Float64Array data
    a DataView data

For example:

  1. set an Int8Array data for a FLOAT32 scalar
    it('raise error when setting an Int8Array data for a FLOAT32 scalar', function() {
    return nn.createModel(options).then((model)=>{
    model.addOperand({type: nn.FLOAT32});
    assert.throws(() => {
      model.setOperandValue(0, new Int8Array([0]));
    });
    });
    });
  2. set a Float32Array data which length > 1 for a FLOAT32 scalar
    it('raise error when setting a Float32Array data which length > 1 for a FLOAT32 scalar', function() {
    return nn.createModel(options).then((model)=>{
    model.addOperand({type: nn.FLOAT32});
    assert.throws(() => {
      model.setOperandValue(0, new Float32Array([0, 0]));
    });
    });
    });
sunlin-link commented 6 years ago

Should add more check for the details of operand based on Android NN API

sunlin-link commented 6 years ago

@Christywl Fixed. Please verify

Christywl commented 6 years ago

@sunlin-link , I tried the chromium nightly build 313c1c2, most negative tests passed except for the following case:

Steps: Run https://brucedai.github.io/nt/testm/index-local.html?backend=mps, check the tests in #setOperandValue API:

Christywl commented 5 years ago

This issue was fixed on nightly build 8e6c6d1.