Skip to content

Commit 1275138

Browse files
authored
Fix reduction op compilation on Firefox Linux (tensorflow#1477)
Due to glsl 300, WebGL on Firefox on Linux can't compile 1.0 / 0.0, thus we use 1.0 / 1e-20. Relevant discussion: tensorflow#1421 (comment) BUG <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/tensorflow/tfjs-core/1477) <!-- Reviewable:end -->
1 parent 1b475ac commit 1275138

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/kernels/webgl/pool_gpu.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ export class Pool2DProgram implements GPGPUProgram {
4545

4646
let initializationValue = '0.0';
4747
if (!isAvgPool) {
48-
initializationValue = '-1.0 / 0.0';
48+
// WebGL on Firefox Linux can't compile 1/0 so we do 1/eps.
49+
initializationValue = '-1.0 / 1e-20';
4950
}
5051

5152
if (computePositions) {

src/kernels/webgl/reduce_gpu.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@ export class ReduceProgram implements GPGPUProgram {
3838
if (reduceType === 'prod') {
3939
initializationValue = '1.0';
4040
} else if (reduceType === 'min') {
41-
initializationValue = '1.0 / 0.0';
41+
// WebGL on Firefox Linux can't compile 1/0 so we do 1/eps.
42+
initializationValue = '1.0 / 1e-20';
4243
compareOp = `min`;
4344
} else if (reduceType === 'max') {
44-
initializationValue = '-1.0 / 0.0';
45+
// WebGL on Firefox Linux can't compile 1/0 so we do 1/eps.
46+
initializationValue = '-1.0 / 1e-20';
4547
compareOp = `max`;
4648
}
4749

0 commit comments

Comments
 (0)