11use Tensor;
22use Layer;
3- import Utilities as utils ;
3+ import Utilities as util ;
44
55
66export proc square(x: int ): int {
@@ -64,6 +64,7 @@ var runningSum: real = 0;
6464var windowSum: real = 0 ;
6565var fpsBuffer: [ 0 ..< windowSize] real ;
6666
67+ config const copyStrat: int = 1 ;
6768
6869
6970export proc getNewFrame(ref frame: [] real (32 ),height: int , width: int ,channels: int ): [] real (32 ) {
@@ -86,19 +87,51 @@ export proc getNewFrame(ref frame: [] real(32),height: int, width: int,channels:
8687 fpsBuffer[ idx] = fps;
8788 const currentWindowSize = min (frameCount, windowSize);
8889 const windowAvgFPS = windowSum / currentWindowSize;
89- writeln (" FPS: " , fps, " avg FPS: " , windowAvgFPS);
90+ writeln (" FPS: " , fps, " avg FPS: " , windowAvgFPS, " max window FPS: " , max reduce fpsBuffer );
9091
9192 const shape = (height,width,channels);
92- const frameDom = utils .domainFromShape((...shape));
93+ const frameDom = util .domainFromShape((...shape));
9394 // const frameArr = reshape(frame,frameDom);
9495
9596 if chaiImpl {
96- const dtInput = (new dynamicTensor(frame)).reshape((...shape));
97+
98+ var ndframe = new ndarray(real (32 ),shape);
99+ ref ndframeData = ndframe.data;
100+ forall idx in frameDom do
101+ ndframeData[ idx] = frame[ util.linearIdx(shape,idx)] ;
102+ const dtInput = new dynamicTensor(ndframe); // 20 fps
97103 const dtOutput = modelLayer!.forward(dtInput);
98- // const outputFrame = dtOutput.rankedData(1);
99104 const outputFrame = dtOutput.flatten().toArray(1 );
100105 lastFrame = getTime();
101106 return outputFrame;
107+
108+ // 2 (no)
109+ // if copyStrat == 1 {
110+ // var ndframe = new ndarray(real(32),shape);
111+ // ref ndframeData = ndframe.data;
112+ // forall idx in frameDom do
113+ // ndframeData[idx] = frame[util.linearIdx(shape,idx)];
114+ // const dtInput = new dynamicTensor(ndframe); // 20 fps
115+ // const dtOutput = modelLayer!.forward(dtInput);
116+ // const outputFrame = dtOutput.flatten().toArray(1);
117+ // lastFrame = getTime();
118+ // return outputFrame;
119+ // } else {
120+ // const dtInput = (new dynamicTensor(frame)).reshape((...shape));
121+ // const dtOutput = modelLayer!.forward(dtInput);
122+ // const outputFrame = dtOutput.flatten().toArray(1);
123+ // lastFrame = getTime();
124+ // return outputFrame;
125+ // }
126+
127+
128+ // const dtInput = new dynamicTensor(reshape(frame,frameDom)); // Way slower
129+
130+ // const dtOutput = modelLayer!.forward(dtInput);
131+ // // const outputFrame = dtOutput.rankedData(1);
132+ // const outputFrame = dtOutput.flatten().toArray(1);
133+ // lastFrame = getTime();
134+ // return outputFrame;
102135 } else {
103136 var btFrame: Bridge.bridge_tensor_t = Bridge.createBridgeTensorWithShape(frame,shape);
104137 var bt: Bridge.bridge_tensor_t;
0 commit comments