Skip to content

Commit

Permalink
clean up glTextureFragmentsAsColStack after use to prevent downstream…
Browse files Browse the repository at this point in the history
… effects on running shader programs on fragments
  • Loading branch information
transcranial committed Nov 27, 2017
1 parent 7097036 commit 28231a7
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/Tensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,18 @@ export default class Tensor {
gl.deleteFramebuffer(fbo)
}

/**
* Removes glTextureFragmentsAsColStack
*/
removeGLTextureFragmentsAsColStack() {
if (this.glTextureFragmentsAsColStack) {
const gl = webgl2.context
gl.deleteTexture(this.glTextureFragmentsAsColStack)
delete this.glTextureFragmentsAsColStack
delete this.glTextureFragmentsAsColStackShape
}
}

/**
* Deletes WebGLTexture
*/
Expand Down
3 changes: 3 additions & 0 deletions src/layers/convolutional/Conv2D.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,9 @@ export default class Conv2D extends Layer {
],
supportsTextureFragments: true
})
if (hasFragments) {
x.removeGLTextureFragmentsAsColStack()
}
} else {
// run matrix multiply on result of im2col
const matMulInputs = [{ input: this.imColsMat, name: 'A' }, { input: this.weights['kernel'], name: 'B' }]
Expand Down
4 changes: 3 additions & 1 deletion src/layers/convolutional/Conv2DTranspose.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,6 @@ export default class Conv2DTranspose extends Layer {
)
this.convTransposeProgram = webgl2.compileProgram(convTransposeProgramSource)
}

webgl2.runProgram({
program: this.convTransposeProgram,
output: this.activation === 'linear' ? this.output : this.outputPreactiv,
Expand All @@ -482,6 +481,9 @@ export default class Conv2DTranspose extends Layer {
],
supportsTextureFragments: true
})
if (hasFragments) {
this.matMulResult.removeGLTextureFragmentsAsColStack()
}

// Activation
if (this.activation !== 'linear') {
Expand Down
3 changes: 3 additions & 0 deletions src/layers/convolutional/Conv3D.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,9 @@ export default class Conv3D extends Layer {
],
supportsTextureFragments: true
})
if (hasFragments) {
x.removeGLTextureFragmentsAsColStack()
}
} else {
// run matrix multiply on result of vol2col
const matMulInputs = [{ input: this.volColsMat, name: 'A' }, { input: this.weights['kernel'], name: 'B' }]
Expand Down
3 changes: 3 additions & 0 deletions src/layers/convolutional/SeparableConv2D.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ class _DepthwiseConv2D extends Conv2D {
uniforms: [{ value: this.output.glTextureShape[1], type: 'int', name: 'inputCols' }],
supportsTextureFragments: true
})
if (this.output.glTextureFragments) {
this.output.removeGLTextureFragmentsAsColStack()
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/layers/core/Flatten.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ export default class Flatten extends Layer {

if (x.glTextureFragments) {
x.convert2DRowFragmentedGLTextureToColStack()
console.log(x)
webgl2.runProgram({
program: this.flattenFragmentsProgram,
output: this.output,
Expand All @@ -88,6 +87,7 @@ export default class Flatten extends Layer {
],
supportsTextureFragments: true
})
x.removeGLTextureFragmentsAsColStack()
} else {
webgl2.runProgram({
program: this.flattenProgram,
Expand Down
1 change: 1 addition & 0 deletions src/layers/pooling/_Pooling1D.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export default class _Pooling1D extends Layer {
uniforms: programUniforms,
supportsTextureFragments: true
})
x.removeGLTextureFragmentsAsColStack()
} else {
webgl2.runProgram({
program: this.poolingProgram,
Expand Down
1 change: 1 addition & 0 deletions src/layers/pooling/_Pooling2D.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ export default class _Pooling2D extends Layer {
uniforms: programUniforms,
supportsTextureFragments: true
})
input.removeGLTextureFragmentsAsColStack()
} else {
webgl2.runProgram({
program: this.poolingProgram,
Expand Down
1 change: 1 addition & 0 deletions src/layers/pooling/_Pooling3D.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ export default class _Pooling3D extends Layer {
uniforms: programUniforms,
supportsTextureFragments: true
})
input.removeGLTextureFragmentsAsColStack()
} else {
webgl2.runProgram({
program: this.poolingProgram,
Expand Down

0 comments on commit 28231a7

Please sign in to comment.