MCPcopy
hub / github.com/tensorflow/tfjs / TransformProgram

Class TransformProgram

tfjs-backend-webgpu/src/transform_webgpu.ts:21–159  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19import {computeDispatch, flatDispatchLayout} from './webgpu_util';
20
21export class TransformProgram implements WebGPUProgram {
22 variableNames = ['Image', 'Transforms'];
23 outputShape: number[];
24 uniforms = 'interpolationModeId : i32, fillModeId : i32, fillValue : f32,';
25 shaderKey: string;
26 dispatchLayout: {x: number[]};
27 dispatch: [number, number, number];
28 workgroupSize: [number, number, number] = [64, 1, 1];
29 size = true;
30
31 constructor(outShape: [number, number, number, number]) {
32 this.outputShape = outShape;
33 this.dispatchLayout = flatDispatchLayout(this.outputShape);
34 this.dispatch = computeDispatch(
35 this.dispatchLayout, this.outputShape, this.workgroupSize);
36 this.shaderKey = 'transform';
37 }
38
39 getUserCode(): string {
40 const userCode = `
41 fn mapCoord(outCoord : f32, len : f32) -> f32{
42 var inCoord = outCoord;
43 if(uniforms.fillModeId == 2) {
44 if (inCoord < 0.0) {
45 if (len <= 1.0) {
46 inCoord = 0.0;
47 } else {
48 let sz2 = 2.0 * len;
49 if (inCoord < sz2) {
50 inCoord = sz2 * f32(i32(f32(-inCoord / sz2))) +
51 inCoord;
52 }
53 if (inCoord < -len) {
54 inCoord = inCoord + sz2;
55 } else {
56 inCoord = -inCoord - 1.0;
57 }
58 }
59 } else if (inCoord > len - 1.0) {
60 if (len <= 1.0) {
61 inCoord = 0.0;
62 } else {
63 let sz2 = 2.0 * len;
64 inCoord = inCoord - sz2 * f32(i32(f32(inCoord / sz2)));
65 if (inCoord >= len) {
66 inCoord = sz2 - inCoord - 1.0;
67 }
68 }
69 }
70 return clamp(inCoord, 0.0, len - 1.0);
71 } else if (uniforms.fillModeId == 3) {
72 if (inCoord < 0.0) {
73 if (len <= 1.0) {
74 inCoord = 0.0;
75 } else {
76 let sz = len - 1.0;
77 inCoord = inCoord + len * (f32(i32(f32(-inCoord / sz))) + 1.0);
78 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…