MCPcopy Create free account
hub / github.com/tensorflow/tfjs / setOutputSnippet

Function setOutputSnippet

tfjs-backend-webgpu/src/webgpu_program.ts:791–827  ·  view source on GitHub ↗
(
    outShape: number[], outBufferType: DataType, component: number)

Source from the content-addressed store, hash-verified

789}
790
791function setOutputSnippet(
792 outShape: number[], outBufferType: DataType, component: number): string {
793 const outRank = outShape.length;
794 const gpuType = dataTypeToGPUType(outBufferType, component);
795 let snippet =
796 `fn setOutputAtIndex(flatIndex : i32, value : ${typeSnippet(component)}) {
797 result[flatIndex] = ${gpuType}(value);
798 }
799
800 fn setOutputAtIndexI32(flatIndex : i32, value : ${
801 typeSnippet(component, 'i32')}) {
802 result[flatIndex] = ${gpuType}(value);
803 }
804 `;
805 if (outRank >= 2) {
806 const dims = ['d0', 'd1', 'd2', 'd3', 'd4', 'd5'].slice(0, outRank);
807 const type = getCoordsDataType(outRank);
808
809 snippet += `
810 fn setOutputAtCoords(${dims.map(d => `${d} : i32`).join(', ')}, value : ${
811 typeSnippet(component)}) {
812 let flatIndex = getOutputIndexFromCoords(${type}(${dims.join(', ')}));
813 setOutputAtIndex(flatIndex${
814 component === 1 ? '' : ` / ${component}`}, value);
815 }
816 fn setOutputAtCoordsI32(${
817 dims.map(d => `${d} : i32`).join(', ')}, value : ${
818 typeSnippet(component, 'i32')}) {
819 let flatIndex = getOutputIndexFromCoords(${type}(${dims.join(', ')}));
820 setOutputAtIndexI32(flatIndex${
821 component === 1 ? '' : ` / ${component}`}, value);
822 }
823 `;
824 }
825
826 return snippet;
827}
828
829function insertAlignment(uniformShader: string) {
830 // insert alignment when current pattern is vec5 or vec6

Callers 1

makeShaderFunction · 0.85

Calls 5

dataTypeToGPUTypeFunction · 0.85
typeSnippetFunction · 0.85
joinMethod · 0.80
getCoordsDataTypeFunction · 0.70
sliceMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…