| 1 |
// This file contains all the tests for int8_multiply_and_add_bias intrinsic. It depends |
| 2 |
// on the CommonTestSetup.js script which contains the common functionality |
| 3 |
// that is required for testing all the intrinsics. |
| 4 |
const COMMON_TEST_SETUP_SCRIPT = "./CommonTestSetup.js" |
| 5 |
|
| 6 |
// All tests for this intrinsic as a string |
| 7 |
const ALL_TESTS_AS_STRING =` |
| 8 |
let {int8_multiply_and_add_bias} = instance.exports; |
| 9 |
|
| 10 |
const VALID = {inputA: 0, scaleA: 1.0, zeroPointA: 0.0, inputB: ARRAY_ALIGNMENT << 2, scaleB: 1.0, zeroPointB: 0.0, inputBiasPrepared: ARRAY_ALIGNMENT << 4, unquantMultiplier: -2.0, rowsA: ROWS_A_MULTIPLIER, width: ROWS_B_MULTIPLIER, colsB: COLUMNS_B_MULTIPLIER, output: ARRAY_ALIGNMENT << 5}; |
| 11 |
|
| 12 |
function testInvalidSize() { |
| 13 |
let invalidSize; |
| 14 |
|
| 15 |
// rowsA: 0 |
| 16 |
invalidSize = 0; |
| 17 |
assertErrorMessage(() => int8_multiply_and_add_bias(VALID.inputA, VALID.scaleA, VALID.zeroPointA, VALID.inputB, VALID.scaleB, VALID.zeroPointB, VALID.inputBiasPrepared, VALID.unquantMultiplier, invalidSize, VALID.width, VALID.colsB, VALID.output), WebAssembly.RuntimeError, /unreachable/); |
| 18 |
|
| 19 |
// width: 0 |
| 20 |
invalidSize = 0; |
| 21 |
assertErrorMessage(() => int8_multiply_and_add_bias(VALID.inputA, VALID.scaleA, VALID.zeroPointA, VALID.inputB, VALID.scaleB, VALID.zeroPointB, VALID.inputBiasPrepared, VALID.unquantMultiplier, VALID.rowsA, invalidSize, VALID.colsB, VALID.output), WebAssembly.RuntimeError, /unreachable/); |
| 22 |
|
| 23 |
// width: Not an integral multiple of ROWS_B_MULTIPLIER |
| 24 |
invalidSize = ROWS_B_MULTIPLIER + 1; |
| 25 |
assertErrorMessage(() => int8_multiply_and_add_bias(VALID.inputA, VALID.scaleA, VALID.zeroPointA, VALID.inputB, VALID.scaleB, VALID.zeroPointB, VALID.inputBiasPrepared, VALID.unquantMultiplier, VALID.rowsA, invalidSize, VALID.colsB, VALID.output), WebAssembly.RuntimeError, /unreachable/); |
| 26 |
|
| 27 |
// colB: 0 |
| 28 |
invalidSize = 0; |
| 29 |
assertErrorMessage(() => int8_multiply_and_add_bias(VALID.inputA, VALID.scaleA, VALID.zeroPointA, VALID.inputB, VALID.scaleB, VALID.zeroPointB, VALID.inputBiasPrepared, VALID.unquantMultiplier, VALID.rowsA, VALID.width, invalidSize, VALID.output), WebAssembly.RuntimeError, /unreachable/); |
| 30 |
|
| 31 |
// colB: Not an integral multiple of COLUMNS_B_MULTIPLIER |
| 32 |
invalidSize = COLUMNS_B_MULTIPLIER + 1; |
| 33 |
assertErrorMessage(() => int8_multiply_and_add_bias(VALID.inputA, VALID.scaleA, VALID.zeroPointA, VALID.inputB, VALID.scaleB, VALID.zeroPointB, VALID.inputBiasPrepared, VALID.unquantMultiplier, VALID.rowsA, VALID.width, invalidSize, VALID.output), WebAssembly.RuntimeError, /unreachable/); |
| 34 |
} |
| 35 |
|
| 36 |
function testInvalidAlignment() { |
| 37 |
let invalidAlignment = ARRAY_ALIGNMENT + 1; |
| 38 |
|
| 39 |
// inputA: Not an integral multiple of ARRAY_ALIGNMENT |
| 40 |
assertErrorMessage(() => int8_multiply_and_add_bias(invalidAlignment, VALID.scaleA, VALID.zeroPointA, VALID.inputB, VALID.scaleB, VALID.zeroPointB, VALID.inputBiasPrepared, VALID.unquantMultiplier, VALID.rowsA, VALID.width, VALID.colsB, VALID.output), WebAssembly.RuntimeError, /index out of bounds/); |
| 41 |
|
| 42 |
// inputB: Not an integral multiple of ARRAY_ALIGNMENT |
| 43 |
assertErrorMessage(() => int8_multiply_and_add_bias(VALID.inputA, VALID.scaleA, VALID.zeroPointA, invalidAlignment, VALID.scaleB, VALID.zeroPointB, VALID.inputBiasPrepared, VALID.unquantMultiplier, VALID.rowsA, VALID.width, VALID.colsB, VALID.output), WebAssembly.RuntimeError, /index out of bounds/); |
| 44 |
} |
| 45 |
|
| 46 |
function testOutOfBounds() { |
| 47 |
let outOfBound; |
| 48 |
|
| 49 |
// inputA: Out of Bounds |
| 50 |
outOfBound = PageSizeInBytes - ARRAY_ALIGNMENT; |
| 51 |
let rowsAForOutOfBound = ROWS_A_MULTIPLIER << 1; |
| 52 |
assertErrorMessage(() => int8_multiply_and_add_bias(outOfBound, VALID.scaleA, VALID.zeroPointA, VALID.inputB, VALID.scaleB, VALID.zeroPointB, VALID.inputBiasPrepared, VALID.unquantMultiplier, rowsAForOutOfBound, VALID.width, VALID.colsB, VALID.output), WebAssembly.RuntimeError, /index out of bounds/); |
| 53 |
|
| 54 |
// inputB: Out of Bounds |
| 55 |
outOfBound = PageSizeInBytes - ARRAY_ALIGNMENT; |
| 56 |
assertErrorMessage(() => int8_multiply_and_add_bias(VALID.inputA, VALID.scaleA, VALID.zeroPointA, outOfBound, VALID.scaleB, VALID.zeroPointB, VALID.inputBiasPrepared, VALID.unquantMultiplier, VALID.rowsA, VALID.width, VALID.colsB, VALID.output), WebAssembly.RuntimeError, /index out of bounds/); |
| 57 |
|
| 58 |
// inputBias: Out of Bounds |
| 59 |
outOfBound = PageSizeInBytes - VALID.colsB; |
| 60 |
assertErrorMessage(() => int8_multiply_and_add_bias(outOfBound, VALID.scaleA, VALID.zeroPointA, VALID.inputB, VALID.scaleB, VALID.zeroPointB, outOfBound, VALID.unquantMultiplier, VALID.rowsA, VALID.width, VALID.colsB, VALID.output), WebAssembly.RuntimeError, /index out of bounds/); |
| 61 |
|
| 62 |
// output: Out of Bounds |
| 63 |
outOfBound = PageSizeInBytes - VALID.colsB; |
| 64 |
assertErrorMessage(() => int8_multiply_and_add_bias(VALID.inputA, VALID.scaleA, VALID.zeroPointA, VALID.inputB, VALID.scaleB, VALID.zeroPointB, VALID.inputBiasPrepared, VALID.unquantMultiplier, VALID.rowsA, VALID.width, VALID.colsB, outOfBound), WebAssembly.RuntimeError, /index out of bounds/); |
| 65 |
} |
| 66 |
|
| 67 |
function testSuccessfulCall() { |
| 68 |
// We just test that with valid arguments the intrinsic executes without any error |
| 69 |
int8_multiply_and_add_bias(VALID.inputA, VALID.scaleA, VALID.zeroPointA, VALID.inputB, VALID.scaleB, VALID.zeroPointB, VALID.inputBiasPrepared, VALID.unquantMultiplier, VALID.rowsA, VALID.width, VALID.colsB, VALID.output); |
| 70 |
} |
| 71 |
|
| 72 |
testInvalidSize(); |
| 73 |
testInvalidAlignment(); |
| 74 |
testOutOfBounds(); |
| 75 |
testSuccessfulCall(); |
| 76 |
` |
| 77 |
|
| 78 |
// Run all the tests |
| 79 |
import(COMMON_TEST_SETUP_SCRIPT).then((importedModule) => { |
| 80 |
importedModule.runTest(importedModule.COMMON_TEST_SETUP_AS_STRING + ALL_TESTS_AS_STRING); |
| 81 |
}); |