| 1 |
// This file contains all the tests for int8_prepare_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_prepare_bias} = instance.exports; |
| 9 |
|
| 10 |
const VALID = {input: 0, scaleA: 1.0, zeroPointA: 0.0, scaleB: 1.0, zeroPointB: 0.0, rows: ROWS_B_MULTIPLIER, cols: COLUMNS_B_MULTIPLIER, inputBias: ARRAY_ALIGNMENT << 4, output: ARRAY_ALIGNMENT << 5}; |
| 11 |
|
| 12 |
function testInvalidSize() { |
| 13 |
let invalidSize; |
| 14 |
|
| 15 |
// row: 0 |
| 16 |
invalidSize = 0; |
| 17 |
assertErrorMessage(() => int8_prepare_bias(VALID.input, VALID.scaleA, VALID.zeroPointA, VALID.scaleB, VALID.zeroPointB, invalidSize, VALID.cols, VALID.inputBias, VALID.output), WebAssembly.RuntimeError, /unreachable/); |
| 18 |
|
| 19 |
// row: Not an integral multiple of ROWS_B_MULTIPLIER |
| 20 |
invalidSize = ROWS_B_MULTIPLIER + 1; |
| 21 |
assertErrorMessage(() => int8_prepare_bias(VALID.input, VALID.scaleA, VALID.zeroPointA, VALID.scaleB, VALID.zeroPointB, invalidSize, VALID.cols, VALID.inputBias, VALID.output), WebAssembly.RuntimeError, /unreachable/); |
| 22 |
|
| 23 |
// col: 0 |
| 24 |
invalidSize = 0; |
| 25 |
assertErrorMessage(() => int8_prepare_bias(VALID.input, VALID.scaleA, VALID.zeroPointA, VALID.scaleB, VALID.zeroPointB, VALID.rows, invalidSize, VALID.inputBias, VALID.output), WebAssembly.RuntimeError, /unreachable/); |
| 26 |
|
| 27 |
// col: Not an integral multiple of COLUMNS_B_MULTIPLIER |
| 28 |
invalidSize = COLUMNS_B_MULTIPLIER + 1; |
| 29 |
assertErrorMessage(() => int8_prepare_bias(VALID.input, VALID.scaleA, VALID.zeroPointA, VALID.scaleB, VALID.zeroPointB, VALID.rows, invalidSize, VALID.inputBias, VALID.output), WebAssembly.RuntimeError, /unreachable/); |
| 30 |
} |
| 31 |
|
| 32 |
function testInvalidAlignment() { |
| 33 |
let invalidAlignment = ARRAY_ALIGNMENT + 1; |
| 34 |
|
| 35 |
// input: Not an integral multiple of ARRAY_ALIGNMENT |
| 36 |
assertErrorMessage(() => int8_prepare_bias(invalidAlignment, VALID.scaleA, VALID.zeroPointA, VALID.scaleB, VALID.zeroPointB, VALID.rows, VALID.cols, VALID.inputBias, VALID.output), WebAssembly.RuntimeError, /index out of bounds/); |
| 37 |
} |
| 38 |
|
| 39 |
function testOutOfBounds() { |
| 40 |
let outOfBound; |
| 41 |
|
| 42 |
// input: Out of Bounds |
| 43 |
outOfBound = PageSizeInBytes - ARRAY_ALIGNMENT; |
| 44 |
assertErrorMessage(() => int8_prepare_bias(outOfBound, VALID.scaleA, VALID.zeroPointA, VALID.scaleB, VALID.zeroPointB, VALID.rows, VALID.cols, VALID.inputBias, VALID.output), WebAssembly.RuntimeError, /index out of bounds/); |
| 45 |
|
| 46 |
// inputBias: Out of Bounds |
| 47 |
outOfBound = PageSizeInBytes - VALID.cols; |
| 48 |
assertErrorMessage(() => int8_prepare_bias(VALID.input, VALID.scaleA, VALID.zeroPointA, VALID.scaleB, VALID.zeroPointB, VALID.rows, VALID.cols, outOfBound, VALID.output), WebAssembly.RuntimeError, /index out of bounds/); |
| 49 |
|
| 50 |
// output: Out of Bounds |
| 51 |
outOfBound = PageSizeInBytes - VALID.cols; |
| 52 |
assertErrorMessage(() => int8_prepare_bias(VALID.input, VALID.scaleA, VALID.zeroPointA, VALID.scaleB, VALID.zeroPointB, VALID.rows, VALID.cols, VALID.inputBias, outOfBound), WebAssembly.RuntimeError, /index out of bounds/); |
| 53 |
} |
| 54 |
|
| 55 |
function testSuccessfulCall() { |
| 56 |
// We just test that with valid arguments the intrinsic executes without any error |
| 57 |
int8_prepare_bias(VALID.input, VALID.scaleA, VALID.zeroPointA, VALID.scaleB, VALID.zeroPointB, VALID.rows, VALID.cols, VALID.inputBias, VALID.output); |
| 58 |
} |
| 59 |
|
| 60 |
testInvalidSize(); |
| 61 |
testInvalidAlignment(); |
| 62 |
testOutOfBounds(); |
| 63 |
testSuccessfulCall(); |
| 64 |
` |
| 65 |
|
| 66 |
// Run all the tests |
| 67 |
import(COMMON_TEST_SETUP_SCRIPT).then((importedModule) => { |
| 68 |
importedModule.runTest(importedModule.COMMON_TEST_SETUP_AS_STRING + ALL_TESTS_AS_STRING); |
| 69 |
}); |