Skip to content

Commit

Permalink
Merge pull request #1 from Iainmon/no-remote-vars
Browse files Browse the repository at this point in the history
Remove and reimplement remote variables to support CPU and GPU operations.
  • Loading branch information
Iainmon authored Aug 23, 2024
2 parents 0470b9e + 0a7598c commit affbc30
Show file tree
Hide file tree
Showing 58 changed files with 2,150 additions and 1,535 deletions.
1 change: 1 addition & 0 deletions .timedata/f32_fast_kernel.json
Original file line number Diff line number Diff line change
@@ -0,0 +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]}
1 change: 1 addition & 0 deletions .timedata/f64_fast_kernel.json
Original file line number Diff line number Diff line change
@@ -0,0 +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]}
1 change: 1 addition & 0 deletions .timedata/f64_old_kernel.json
Original file line number Diff line number Diff line change
@@ -0,0 +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]}
1 change: 1 addition & 0 deletions .timedata/old.json
Original file line number Diff line number Diff line change
@@ -0,0 +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]}
14 changes: 10 additions & 4 deletions MNISTNet.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import Time;

config param layerDebug = false;

type dtype = real(32);

class CNN : Module(?) {
var conv1: owned Conv2D(eltType);
var conv2: owned Conv2D(eltType);
Expand All @@ -18,7 +20,7 @@ class CNN : Module(?) {
var fc1: owned Linear(eltType);
var fc2: owned Linear(eltType);

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


var cnn = new CNN(real);
var cnn = new CNN(dtype);


for (n,m) in cnn.moduleFields() {
writeln(n);
}

var model = Network.loadModel(specFile="scripts/models/cnn/specification.json",
weightsFolder="scripts/models/cnn/",
dtype=dtype);


config const testImgSize = 28;

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

config const imageCount = 0;

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

config const numTimes = 1;
Expand All @@ -186,7 +192,7 @@ for i in 0..<numTimes {
// x = conv2(x);
// var output = x;
// pred = output.runtimeRank;
var output: Tensor(real) = cnn(img);
var output: Tensor(dtype) = model(img);
pred = output.argmax();
// writeln((i, pred));
}
Expand Down
76 changes: 76 additions & 0 deletions MultiLocaleInference.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
use Tensor;

use Network;

use BlockDist;

import Time;

config const detach = true;

Tensor.detachMode(detach);

type dtype = real(32);

// Load an array of images.
config const numImages = 1;

// Create distributed domain for images.
const imagesD = blockDist.createDomain({0..<numImages});

// Load distributed array of images.
var images = forall i in imagesD do
Tensor.load("data/datasets/mnist/image_idx_" + i:string + ".chdata") : dtype;

// Create distributed domain for models.
const localeModelsD = blockDist.createDomain(Locales.domain);

// Load distributed array of models.
var localeModels = forall li in localeModelsD do
loadModel(specFile="scripts/models/cnn/specification.json",
weightsFolder="scripts/models/cnn/",
dtype=dtype);

// Create distributed array of output results.
var preds: [imagesD] int;


config const numTries = 1;

var totalTime: real;

for i in 0..<numTries {

var st = new Time.stopwatch();
st.start();

// coforall loc in Locales {
// on loc {
// const myAD = A.domain.localIndices();
// forall i in myAD;
// }
// }
forall (image,pred) in zip(images,preds) {
var model = localeModels[here.id].borrow();
pred = model(image).argmax();
}

st.stop();
const tm = st.elapsed();
totalTime += tm;

writeln("Trial ", i + 1, " of ", numTries," took ", tm, " seconds for ", numImages, " images on ", Locales.size, " nodes.");
}

const averageTime = totalTime / numTries;


config const printResults = false;
if printResults {
for i in images.domain {
writeln((i, preds[i]));
}
}

writeln("The average inference time for batch of size ", numImages, " was ", averageTime, " seconds on ", Locales.size, " nodes.");
writeln("The total inference time for batch of size ", numImages, " was ", totalTime, " seconds on ", Locales.size, " nodes.");
11 changes: 11 additions & 0 deletions cw.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// proc myWarning(param s, type t = string) {
// compilerWarning(s);
// }

proc somethingElse(x1) {
compilerWarning("idx");
}
// somethingElse(1);
somethingElse(true);

somethingElse(true);
26 changes: 26 additions & 0 deletions definit.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

use Reflection;


proc (class).defaultInit(args...?nargs) {
param numFields = getNumFields(this.type);
if numFields != nargs then compilerError("Fields must match args");

for param i in 0..<numFields {
getField(this, i) = args(i);
}
}



class C {
var x: int;
var y: bool;

proc init() {
this.defaultInit(1,true);
}
}

var c = new owned C();
writeln(c);
Loading

0 comments on commit affbc30

Please sign in to comment.