Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

webgl: texture leak fix #139

Merged
merged 10 commits into from
May 11, 2019
Merged

Conversation

fs-eire
Copy link
Contributor

@fs-eire fs-eire commented Apr 23, 2019

This change fixes the texture leak bug that happened in some operators.

adjustedKernelShape, 4, [adjustedKernelShape[0], adjustedKernelShape[1] * 4], {breakAxis: 1});

let bLayout: TextureLayout|undefined;
const rank = outputShape.length;

const inputLayouts = [im2colLayout, kLayout];
if (inputs.length === 3) {
bLayout = inferenceHandler.createBasicTextureLayout(inputs[2].dims.slice());
bLayout = inferenceHandler.createTextureLayoutFromShape(inputs[2].dims.slice());
Copy link
Member

Choose a reason for hiding this comment

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

There seem to be a lot of unnecessary slicing (copying) of dims in general - as long as the methodd accepts const dims and guarantees that any given dims will not be mutated - can we avoid creating copies unnecessarily ? Granted -it should be only adding to the warm up overhead, but it still kind of stands out...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for figuring out this. actually there are quite some unnecessary calls to Array.prototype.slice in a lot of places in the code base.

I think it worth another separated change to optimize that

Copy link
Member

Choose a reason for hiding this comment

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

Oh yeah, I seem to have this comment already - too many slice calls :)


/**
* Create a TextureLayout object from a tensor. If a related texture data is found, returns the cached texture layout.
*/
getOrCreateTextureLayout(tensor: Tensor, channels = 1, unpackedShape?: ReadonlyArray<number>): TextureLayout {
Copy link
Member

@hariharans29 hariharans29 May 8, 2019

Choose a reason for hiding this comment

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

Nit: This name is slightly misleading. I would expect that getOrCreateTexturelayout() to only focus on Layout creation. There is a step that looks into the cache preceding it. Any possible better names for this function ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is what the function is doing: try to get (find from cache) the texture layout of the given tensor; if failed to find then create a new one.. so from the naming perspective I cannot find a better name for it. This is the same for getOrCreateTextureData.


/**
* Create a TextureData object, using the given texture.
* This function does not create new texture. Usually used in scenarios using texture sharing. (eg. Reshape)
Copy link
Member

Choose a reason for hiding this comment

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

Can you expand on texture sharing for my understanding please ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A WebGLTexture object represents a texture in GPU.

A TextureData object represents a corresponding texture to a tensor. It contains a WebGLTexture object, a reference to the tensor and the texture layout.

A Tensor.Id object represents a unique data unit, regardless where the data is hold (it can be in memory, ie. TypedArray, or in GPU, ie. a texture).

A Tensor object represent a value node in the model graph. It's one of those:

  • a model input
  • a model initializer
  • a model output
  • an intermedia value through the model execution
    A Tensor object can have multiple way to connect to the data that its tensorId mapped to:
  • a cached result (TypedArray instance)
  • a data provider function ( a function that returns a TypedArray instance )
  • an async data provider function (this is not supported yet)

Logically, WebGLTexture objects should be 1:1 mapping to Tensor.Id objects, and TextureData objects should be a 1:1 mapping to Tensor objects.

Some operators, for example, Reshape, will not modify any data of its input. In this case, we are creating a new Tensor object with different dims, using the same Tensor.Id. This is the sharing scenario. We extend this scenario with the equivalent concepts in webgl.

@hariharans29
Copy link
Member

Overall looks good to me - I focussed on the "core" WebGL related changes. I skimmed through the related WebGL operator changes that needs to align with the base change itself. I just need to understand the concept of createSharedTextureData() and its uses. I ll chat with you offline and we can merge this.

@fs-eire fs-eire merged commit 453f469 into microsoft:master May 11, 2019
@fs-eire fs-eire deleted the webgl-texture-leak-fix branch May 11, 2019 00:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants