[JS/Web]Adding support for WebGL v1 (#7906)

* Adding support for WebGL v1

* enabling a few tests

* Minor changes for README.md
This commit is contained in:
Du Li 2021-06-03 21:30:42 -07:00 committed by GitHub
parent ab973dce33
commit 6a9023f47d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 12 additions and 83 deletions

View file

@ -34,13 +34,13 @@ Refer to the following links for development information:
### Compatibility
| OS/Browser | Chrome | Edge | Safari | Electron | Node.js |
| :--------------: | :---------: | :---------: | :----: | :---------: | :-----: |
| Windows 10 | wasm, webgl | wasm, webgl | - | wasm, webgl | wasm |
| macOS | wasm | - | wasm | wasm | wasm |
| Ubuntu LTS 18.04 | wasm | - | - | wasm | wasm |
| iOS | wasm | wasm | wasm | - | - |
| Android | wasm | - | - | - | - |
| OS/Browser | Chrome | Edge | Safari | Electron | Node.js |
| :--------------: | :---------: | :---------: | :---------: | :---------: | :-----: |
| Windows 10 | wasm, webgl | wasm, webgl | - | wasm, webgl | wasm |
| macOS | wasm, webgl | - | wasm, webgl | wasm, webgl | wasm |
| Ubuntu LTS 18.04 | wasm | - | - | wasm | wasm |
| iOS | wasm | wasm | wasm | - | - |
| Android | wasm | - | - | - | - |
### Operators

View file

@ -2,6 +2,7 @@
// Licensed under the MIT License.
import {Tensor} from '../../../tensor';
import {getGlsl} from '../glsl-source';
import {WebGLInferenceHandler} from '../inference-handler';
import {ProgramInfo, RunData, WebGLOperator} from '../types';
import {unpackFromChannel} from './packing-utils';
@ -38,6 +39,7 @@ export class WebGLIm2ColPacked implements WebGLOperator {
const im2colShape = [wshape[1] * wshape[2] * wshape[3], this.convOutputShape[2] * this.convOutputShape[3]];
const kernelSize = wshape[2] * wshape[3];
const unpackChannel = unpackFromChannel();
const glsl = getGlsl(inferenceHandler.session.backend.glContext.version);
let unrolled = '';
for (let row = 0; row <= 1; row++) {
@ -78,7 +80,7 @@ export class WebGLIm2ColPacked implements WebGLOperator {
int blockIndex, pos, offsetY, d0, offsetX, d1, ch;
vec2 innerDims;
${unrolled}
outputColor = result;
${glsl.output} = result;
}
`;
return {

View file

@ -84,7 +84,7 @@ function getA(allGlChannels: string[], rank: number): string {
res += `rc.${allGlChannels[i]}, `;
}
res += `rc.${allGlChannels[rank - 2]}, ` +
'i<<1';
'i*2';
return res;
}
@ -93,7 +93,7 @@ function getB(allGlChannels: string[], rank: number): string {
for (let i = 0; i < rank - 2; i++) {
res += `rc.${allGlChannels[i]}, `;
}
res += 'i<<1, ' +
res += 'i*2, ' +
`rc.${allGlChannels[rank - 1]}`;
return res;
}

View file

@ -448,28 +448,6 @@ export class TensorResultValidator {
}
}
// TODO fix the reshape and flatten ops to be compatible with webgl1
const UNSUPPORTED_WEBGL_1_TESTS = [
'test_flatten_axis0', 'test_flatten_axis1', 'test_flatten_axis2',
'test_flatten_default_axis', 'test_reshape_extended_dims', 'test_reshape_negative_dim',
'test_reshape_one_dim', 'test_reshape_reduced_dims', 'test_flatten_axis0',
'test_flatten_axis1', 'test_flatten_axis2', 'test_flatten_default_axis',
'test_reshape_extended_dims', 'test_reshape_negative_dim', 'test_reshape_one_dim',
'test_reshape_reduced_dims', 'test_flatten_axis0', 'test_flatten_axis1',
'test_flatten_axis2', 'test_flatten_default_axis', 'test_reshape_extended_dims',
'test_reshape_negative_dim', 'test_reshape_one_dim', 'test_reshape_reduced_dims',
'test_reshape_reordered_dims', 'test_flatten_axis0', 'test_flatten_axis1',
'test_flatten_axis2', 'test_flatten_default_axis', 'test_reshape_extended_dims',
'test_reshape_negative_dim', 'test_reshape_one_dim', 'test_reshape_reduced_dims',
'test_reshape_reordered_dims', 'test_flatten_axis0', 'test_flatten_axis1',
'test_flatten_axis2', 'test_flatten_default_axis', 'test_reshape_extended_dims',
'test_reshape_negative_dim', 'test_reshape_one_dim', 'test_reshape_reduced_dims',
'test_reshape_reordered_dims', 'test_flatten_axis0', 'test_flatten_axis1',
'test_flatten_axis2', 'test_flatten_default_axis', 'test_reshape_extended_dims',
'test_reshape_negative_dim', 'test_reshape_one_dim', 'test_reshape_reduced_dims',
'test_reshape_reordered_dims',
];
/**
* run a single model test case. the inputs/outputs tensors should already been prepared.
*/
@ -479,15 +457,6 @@ export async function runModelTestSet(
Logger.verbose('TestRunner', `Start to run test data from folder: ${testCase.name}`);
const validator = new TensorResultValidator(context.backend);
try {
if (context.backend === 'webgl') {
// TODO skipping incompatible tests for now
if (createWebGLContext(ort.env.webgl.contextId).version === 1 &&
UNSUPPORTED_WEBGL_1_TESTS.indexOf(testName) !== -1) {
Logger.info('TestRunner', `Found incompatible test on webgl 1: ${testName} - ${testCase.name}. Skipping.`);
return;
}
}
const feeds: Record<string, ort.Tensor> = {};
testCase.inputs!.forEach((tensor, i) => feeds[context.session.inputNames[i]] = tensor);
const start = now();

View file

@ -217,12 +217,6 @@ describe('#UnitTest# - packed concat - Tensor concat', () => {
it('Test packed concat kernel ', () => {
const webglInferenceHandler = inferenceHandler as WebGLInferenceHandler;
// TODO support WebGl 1.0
if (webglInferenceHandler.session.textureManager.glContext.version === 1) {
console.log('Running packed concat with webgl1 is not supported. Skipping.');
return;
}
if (!env.webgl.pack) {
console.log('Skipping in unpacked texture mode.');
return;

View file

@ -131,12 +131,6 @@ describe('#UnitTest# - unpacked WebGLDepthToSpace - Tensor WebGLDepthToSpace', (
it('Test depth to space ', () => {
const webglInferenceHandler = inferenceHandler as WebGLInferenceHandler;
// TODO support WebGl 1.0
if (webglInferenceHandler.session.textureManager.glContext.version === 1) {
console.log('Running depth to space with webgl1 is not supported. Skipping.');
return;
}
const op = new WebGLDepthToSpace();
const attributes = new Attribute(undefined);
const blocksize = testData.blocksize;

View file

@ -151,12 +151,6 @@ describe('#UnitTest# - packed matmul - Tensor matmul', () => {
it('Test packed matmul kernel ', () => {
const webglInferenceHandler = inferenceHandler as WebGLInferenceHandler;
// TODO support WebGl 1.0
if (webglInferenceHandler.session.textureManager.glContext.version === 1) {
console.log('Running packed matmul with webgl1 is not supported. Skipping.');
return;
}
if (!env.webgl.pack) {
console.log('Skipping in unpacked texture mode.');
return;

View file

@ -219,12 +219,6 @@ describe('#UnitTest# - pack - Tensor pack', () => {
it(`Test pack kernal ${textureLayout[w]} ${JSON.stringify(testData)}`, () => {
const webglInferenceHandler = inferenceHandler as WebGLInferenceHandler;
// TODO support WebGl 1.0
if (webglInferenceHandler.session.textureManager.glContext.version === 1) {
console.log('Running pack with webgl1 is not supported. Skipping.');
return;
}
const op = new WebGLPack();
const elementCount = testData.elementCount;
@ -287,12 +281,6 @@ describe('#UnitTest# - unpack - Tensor unpack', () => {
it(`Test unpack kernal ${testData.inputShape}`, () => {
const webglInferenceHandler = inferenceHandler as WebGLInferenceHandler;
// TODO support WebGl 1.0
if (webglInferenceHandler.session.textureManager.glContext.version === 1) {
console.log('Running unpack with webgl1 is not supported. Skipping.');
return;
}
const op = new WebGLUnpack();
const elementCount = testData.elementCount;
@ -370,12 +358,6 @@ describe('#UnitTest# - pack-unpack round trip', () => {
it(`Test pack-unpack round trip ${JSON.stringify(testData)}`, () => {
const webglInferenceHandler = inferenceHandler as WebGLInferenceHandler;
// TODO support WebGl 1.0
if (webglInferenceHandler.session.textureManager.glContext.version === 1) {
console.log('Running pack with webgl1 is not supported. Skipping.');
return;
}
const packOp = new WebGLPack();
const elementCount = testData.elementCount;

View file

@ -121,12 +121,6 @@ describe('#UnitTest# - reshape - packed', () => {
it(`Test packed reshape kernel ${JSON.stringify(testData.outputShape)}`, () => {
const webglInferenceHandler = inferenceHandler as WebGLInferenceHandler;
// TODO support WebGl 1.0
if (webglInferenceHandler.session.textureManager.glContext.version === 1) {
console.log('Running packed concat with webgl1 is not supported. Skipping.');
return;
}
if (!env.webgl.pack) {
console.log('Skipping in unpacked texture mode.');
return;