Skip to content

Commit 82f5822

Browse files
committed
Add more to chapel-webcam demo.
1 parent 16d0e7d commit 82f5822

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

demos/video/chapel-webcam/smol.chpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ export proc globalLoadModel() {
5555

5656
var lastFrame = startTime;
5757

58-
param chaiImpl = true;
58+
config const chaiImpl = true;
5959

6060

61-
const windowSize = 20;
61+
const windowSize = 5;
6262
var frameCount = 0;
6363
var runningSum: real = 0;
6464
var windowSum: real = 0;
@@ -95,11 +95,11 @@ export proc getNewFrame(ref frame: [] real(32),height: int, width: int,channels:
9595
if chaiImpl {
9696
const dtInput = (new dynamicTensor(frame)).reshape((...shape));
9797
const dtOutput = modelLayer!.forward(dtInput);
98+
// const outputFrame = dtOutput.rankedData(1);
9899
const outputFrame = dtOutput.flatten().toArray(1);
99100
lastFrame = getTime();
100101
return outputFrame;
101102
} else {
102-
103103
var btFrame: Bridge.bridge_tensor_t = Bridge.createBridgeTensorWithShape(frame,shape);
104104
var bt: Bridge.bridge_tensor_t;
105105
if modelPath == "sobel.pt" then

lib/DynamicTensor.chpl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ record dynamicTensor : serializable {
141141
return (this.meta.borrow() : borrowed BaseTensorResource(eltType, rank)).grad;
142142

143143
inline proc ref rankedData(param rank: int) ref : [] eltType do
144-
return (this.meta.borrow() : borrowed BaseTensorResource(eltType, rank)).data;
144+
return (this.meta.borrow() : borrowed BaseTensorResource(eltType, rank)).array.data;
145145

146146
inline proc rankedData(param rank: int): [] eltType do
147-
return (this.meta.borrow() : borrowed BaseTensorResource(eltType, rank)).data;
147+
return (this.meta.borrow() : borrowed BaseTensorResource(eltType, rank)).array.data;
148148

149149

150150
proc toNDArray(param rank: int) : ndarray(rank,eltType) {
@@ -189,7 +189,7 @@ operator :(in t: dynamicTensor(?eltType), type toType: ndarray(?rank,?toEltType)
189189
operator :(in t: dynamicTensor(?eltType), type btType: Bridge.tensorHandle(eltType)): Bridge.tensorHandle(eltType) {
190190
for param rank in 1..maxRank do
191191
if t.checkRank(rank) then
192-
return t.forceRank(rank) : btType;
192+
return t.forceRank(rank).array : btType;
193193
halt("Could not identify rank for this: ", t);
194194
}
195195

@@ -200,6 +200,12 @@ operator :(bt: Bridge.tensorHandle(real(32)), type tType: dynamicTensor(?eltType
200200
halt("Could not identify rank for this: ", tType:string);
201201
}
202202

203+
// proc type dynamicTensor.fromBridgeTensor(handle: Bridge.tensorHandle(defaultEltType)): dynamicTensor(defaultEltType) {
204+
// for param rank in 1..maxRank do
205+
// if bt.dim == rank then
206+
// return
207+
// }
208+
203209
proc type dynamicTensor.detachMode() param : bool {
204210
return defaultDetachedMode;
205211
}

0 commit comments

Comments
 (0)