Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion tfjs-backend-webgpu/src/backend_webgpu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,14 @@ export class WebGPUBackend extends KernelBackend {
convInfo.strideHeight, convInfo.strideWidth
];

return this.compileAndRun(program, [input, filter], output, dimensions);
const inputs: Tensor[] = [input, filter];
if (hasBias) {
inputs.push(bias);
}
if (hasPreluActivationWeights) {
inputs.push(preluActivationWeights);
}
return this.compileAndRun(program, inputs, output, dimensions);
}

private argMinMaxReduce(x: Tensor, axis: number, reduceType: 'min'|'max'):
Expand Down
10 changes: 6 additions & 4 deletions tfjs-backend-webgpu/src/kernels/conv2d_mm_webgpu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ export class Conv2DMMProgram implements WebGPUProgram {
util.assert(
tileInner % this.workGroupSize[0] === 0 &&
tileInner % this.workGroupSize[1] === 0,
() => `tileInner must be multiple of workgroupsize.x and
workgroupsize.y`);
() =>
// tslint:disable-next-line: max-line-length
'tileInner must be multiple of workgroupsize.x and workgroupsize.y');
const tileSizeA = [tileAOuter, tileInner];
const tileSizeB = [tileInner, tileBOuter];
const dimAOuter = this.outputShape[1] * this.outputShape[2];
Expand Down Expand Up @@ -92,7 +93,7 @@ export class Conv2DMMProgram implements WebGPUProgram {
}`;
} else {
activationSnippet = `
float activation(float x) {
float activation(float a) {
${activation}
}
`;
Expand Down Expand Up @@ -155,6 +156,7 @@ export class Conv2DMMProgram implements WebGPUProgram {
mm_matMul(dimAOuter, dimInner, dimBOuter);
}
`;
this.shaderKey = `conv2dmm'${elementsPerThread.join('')}${fitA}${fitB}`;
this.shaderKey = `conv2dmm'${elementsPerThread.join('')}${fitA}${fitB}${
addBiasSnippet}${activationSnippet}`;
}
}
4 changes: 2 additions & 2 deletions tfjs-backend-webgpu/src/kernels/unary_op_webgpu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import {WebGPUProgram} from './webgpu_program';

export const RELU = 'return max(a, 0.0);';
export const RELU6 = 'return (a < 0.0) ? 0.0 : min(6.0, a);';
export const LINEAR = `return x;`;
export const ELU = `return (x >= 0.0) ? x : (exp(x) - 1.0);`;
export const LINEAR = `return a;`;
export const ELU = `return (a >= 0.0) ? a : (exp(a) - 1.0);`;

export const SIGMOID = `return 1.0 / (1.0 + exp(-1.0 * a));`;
export const ABS = `return abs(a);`;
Expand Down
10 changes: 10 additions & 0 deletions tfjs-backend-webgpu/src/setup_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ const TEST_FILTERS: TestFilter[] = [
'fused', // Not yet implemented.
]
},
{
include: 'fused conv2d',
excludes: [
'im2row with prelu', // Actual != expected.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, how big is the error? I'm surprised that these tests needed to be excluded.

Copy link
Contributor Author

@axinging axinging Mar 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reported error is like this on Mac:
Arrays differ: actual[7] = 0, expected[7] = -2.5.

Please noted that even with this 𝑃𝑅, some case may fail, I add the followup here: https://github.com/tensorflow/tfjs/pull/2846/files#diff-dcb528c192f70859b8f4333e400b445fR813

'pointwise with prelu', // Actual != expected.
'gradient x=[2,3,3,1] f=[2,2,1,1] s=1 p=0', // conv2dDerInput not yet
// implemented
'fused matmul with relu6', // step not yet implemented
]
},
{
include: 'fromPixels',
excludes: [
Expand Down