MCPcopy Index your code
hub / github.com/tensorflow/tfjs / computeBytes

Function computeBytes

tfjs-backend-webgl/src/texture_manager.ts:207–233  ·  view source on GitHub ↗
(
    shape: [number, number], physicalTexType: PhysicalTextureType,
    gl: WebGLRenderingContext, textureConfig: TextureConfig,
    isPacked: boolean)

Source from the content-addressed store, hash-verified

205}
206
207export function computeBytes(
208 shape: [number, number], physicalTexType: PhysicalTextureType,
209 gl: WebGLRenderingContext, textureConfig: TextureConfig,
210 isPacked: boolean): number {
211 // It is not possible to infer packed status from the texture type because
212 // depending on the textureConfig, different texture types may resolve to the
213 // same internal format (e.g. in WebGL1, the internal format for
214 // UNPACKED_FLOAT16 textures is gl.RGBA). Therefore we pass in `isPacked`
215 // explicitly.
216 const internalFormat =
217 internalFormatForPhysicalTexType(physicalTexType, textureConfig);
218
219 let numElements: number;
220 if (isPacked) {
221 const [packedWidth, packedHeight] =
222 getPackedMatrixTextureShapeWidthHeight(shape[0], shape[1]);
223 numElements = packedWidth * packedHeight;
224
225 } else {
226 const [width, height] =
227 getUnpackedMatrixTextureShapeWidthHeight(shape[0], shape[1]);
228 numElements = width * height;
229 }
230
231 const bytesPerElement = numBytesForInternalFormat(gl, internalFormat);
232 return numElements * bytesPerElement;
233}
234
235function internalFormatForPhysicalTexType(
236 physicalTexType: PhysicalTextureType,

Callers 3

acquireTextureMethod · 0.85
releaseTextureMethod · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…