Skip to content

Commit affbc30

Browse files
authored
Merge pull request #1 from Iainmon/no-remote-vars
Remove and reimplement remote variables to support CPU and GPU operations.
2 parents 0470b9e + 0a7598c commit affbc30

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2150
-1535
lines changed

Diff for: .timedata/f32_fast_kernel.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"avg": 1.203106, "stddev": 0.008578116576498592, "times": [1.21923, 1.19135, 1.20671, 1.19214, 1.20526, 1.20393, 1.2009, 1.2122, 1.2063, 1.19304]}

Diff for: .timedata/f64_fast_kernel.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"avg": 1.2119130000000002, "stddev": 0.005646131507501363, "times": [1.22538, 1.21134, 1.21124, 1.20609, 1.2136, 1.21643, 1.2142, 1.20709, 1.20729, 1.20647]}

Diff for: .timedata/f64_old_kernel.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"avg": 1.9952400000000001, "stddev": 0.005532747961004563, "times": [2.00349, 2.00492, 1.99984, 1.99339, 1.98599, 1.99134, 1.99441, 1.99439, 1.9928, 1.99183]}

Diff for: .timedata/old.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"avg": 2.000039, "stddev": 0.024113097042893505, "times": [1.99821, 2.0665, 1.9849, 1.98276, 1.98553, 1.99033, 1.99006, 2.01721, 1.99753, 1.98736]}

Diff for: MNISTNet.chpl

+10-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import Time;
99

1010
config param layerDebug = false;
1111

12+
type dtype = real(32);
13+
1214
class CNN : Module(?) {
1315
var conv1: owned Conv2D(eltType);
1416
var conv2: owned Conv2D(eltType);
@@ -18,7 +20,7 @@ class CNN : Module(?) {
1820
var fc1: owned Linear(eltType);
1921
var fc2: owned Linear(eltType);
2022

21-
proc init(type eltType = real) {
23+
proc init(type eltType = dtype) {
2224
super.init(eltType);
2325
// (1,3,3) x 32
2426
this.conv1 = new Conv2D(eltType,channels=1,features=32,kernel=3,stride=1); // (1,X,X) -> (32,Y,Y)
@@ -142,13 +144,17 @@ if diag {
142144
}
143145

144146

145-
var cnn = new CNN(real);
147+
var cnn = new CNN(dtype);
146148

147149

148150
for (n,m) in cnn.moduleFields() {
149151
writeln(n);
150152
}
151153

154+
var model = Network.loadModel(specFile="scripts/models/cnn/specification.json",
155+
weightsFolder="scripts/models/cnn/",
156+
dtype=dtype);
157+
152158

153159
config const testImgSize = 28;
154160

@@ -167,7 +173,7 @@ cnn.loadPyTorchDump(modelPath);
167173

168174
config const imageCount = 0;
169175

170-
var images = forall i in 0..<imageCount do Tensor.load("data/datasets/mnist/image_idx_" + i:string + ".chdata");
176+
var images = forall i in 0..<imageCount do Tensor.load("data/datasets/mnist/image_idx_" + i:string + ".chdata") : dtype;
171177
var preds: [images.domain] int;
172178

173179
config const numTimes = 1;
@@ -186,7 +192,7 @@ for i in 0..<numTimes {
186192
// x = conv2(x);
187193
// var output = x;
188194
// pred = output.runtimeRank;
189-
var output: Tensor(real) = cnn(img);
195+
var output: Tensor(dtype) = model(img);
190196
pred = output.argmax();
191197
// writeln((i, pred));
192198
}

Diff for: MultiLocaleInference.chpl

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
use Tensor;
2+
3+
use Network;
4+
5+
use BlockDist;
6+
7+
import Time;
8+
9+
config const detach = true;
10+
11+
Tensor.detachMode(detach);
12+
13+
type dtype = real(32);
14+
15+
// Load an array of images.
16+
config const numImages = 1;
17+
18+
// Create distributed domain for images.
19+
const imagesD = blockDist.createDomain({0..<numImages});
20+
21+
// Load distributed array of images.
22+
var images = forall i in imagesD do
23+
Tensor.load("data/datasets/mnist/image_idx_" + i:string + ".chdata") : dtype;
24+
25+
// Create distributed domain for models.
26+
const localeModelsD = blockDist.createDomain(Locales.domain);
27+
28+
// Load distributed array of models.
29+
var localeModels = forall li in localeModelsD do
30+
loadModel(specFile="scripts/models/cnn/specification.json",
31+
weightsFolder="scripts/models/cnn/",
32+
dtype=dtype);
33+
34+
// Create distributed array of output results.
35+
var preds: [imagesD] int;
36+
37+
38+
config const numTries = 1;
39+
40+
var totalTime: real;
41+
42+
for i in 0..<numTries {
43+
44+
var st = new Time.stopwatch();
45+
st.start();
46+
47+
// coforall loc in Locales {
48+
// on loc {
49+
// const myAD = A.domain.localIndices();
50+
// forall i in myAD;
51+
// }
52+
// }
53+
forall (image,pred) in zip(images,preds) {
54+
var model = localeModels[here.id].borrow();
55+
pred = model(image).argmax();
56+
}
57+
58+
st.stop();
59+
const tm = st.elapsed();
60+
totalTime += tm;
61+
62+
writeln("Trial ", i + 1, " of ", numTries," took ", tm, " seconds for ", numImages, " images on ", Locales.size, " nodes.");
63+
}
64+
65+
const averageTime = totalTime / numTries;
66+
67+
68+
config const printResults = false;
69+
if printResults {
70+
for i in images.domain {
71+
writeln((i, preds[i]));
72+
}
73+
}
74+
75+
writeln("The average inference time for batch of size ", numImages, " was ", averageTime, " seconds on ", Locales.size, " nodes.");
76+
writeln("The total inference time for batch of size ", numImages, " was ", totalTime, " seconds on ", Locales.size, " nodes.");

Diff for: cw.chpl

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// proc myWarning(param s, type t = string) {
2+
// compilerWarning(s);
3+
// }
4+
5+
proc somethingElse(x1) {
6+
compilerWarning("idx");
7+
}
8+
// somethingElse(1);
9+
somethingElse(true);
10+
11+
somethingElse(true);

Diff for: definit.chpl

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
use Reflection;
3+
4+
5+
proc (class).defaultInit(args...?nargs) {
6+
param numFields = getNumFields(this.type);
7+
if numFields != nargs then compilerError("Fields must match args");
8+
9+
for param i in 0..<numFields {
10+
getField(this, i) = args(i);
11+
}
12+
}
13+
14+
15+
16+
class C {
17+
var x: int;
18+
var y: bool;
19+
20+
proc init() {
21+
this.defaultInit(1,true);
22+
}
23+
}
24+
25+
var c = new owned C();
26+
writeln(c);

0 commit comments

Comments
 (0)