Skip to content

Commit

Permalink
Merge branch 'time_init_read' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
tom91136 committed Oct 7, 2023
2 parents 145e2a0 + 3cb01e7 commit a27abfe
Show file tree
Hide file tree
Showing 28 changed files with 435 additions and 136 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ All notable changes to this project will be documented in this file.
- Thrust managed memory.
- HIP managed memory.
- New implementation using SYCL2020 USM (sycl2020-acc) and renamed original `sycl2020` to `sycl2020-acc`.
- Data initialisation and read-back timing for all models, including Java, Scala, Julia, and Rust
- Add support for the latest Aparapi (3.0.0) and TornadoVM (0.15.x) for Java

### Changed
- RAJA CUDA CMake build issues resolved.
Expand All @@ -17,6 +19,7 @@ All notable changes to this project will be documented in this file.
- Number of thread-blocks in CUDA dot kernel implementation changed to 1024.
- Fix compatibility of `sycl2020` (now `sycl2020-acc`) with hipSYCL.
- Bumped Julia compat to 1.9
- Bumped Scala to 3.3.1
- Bumped Rust to 1.74.0-nightly (13e6f24b9 2023-09-23)


Expand Down
8 changes: 4 additions & 4 deletions src/java/java-stream/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<junit.version>5.7.2</junit.version>
<junit.version>5.9.2</junit.version>
</properties>

<repositories>
Expand All @@ -27,19 +27,19 @@
<dependency>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
<version>1.81</version>
<version>1.82</version>
</dependency>

<dependency>
<groupId>tornado</groupId>
<artifactId>tornado-api</artifactId>
<version>0.9</version>
<version>0.15.1</version>
</dependency>

<dependency>
<groupId>com.aparapi</groupId>
<artifactId>aparapi</artifactId>
<version>2.0.0</version>
<version>3.0.0</version>
<exclusions>
<!-- don't pull in the entire Scala ecosystem! -->
<exclusion>
Expand Down
14 changes: 11 additions & 3 deletions src/java/java-stream/src/main/java/javastream/JavaStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected JavaStream(Config<T> config) {

protected abstract T dot();

protected abstract Data<T> data();
protected abstract Data<T> readArrays();

public static class EnumeratedStream<T> extends JavaStream<T> {

Expand Down Expand Up @@ -113,8 +113,8 @@ public T dot() {
}

@Override
public Data<T> data() {
return actual.data();
public Data<T> readArrays() {
return actual.readArrays();
}
}

Expand All @@ -140,6 +140,14 @@ private static Duration timed(Runnable f) {
return Duration.ofNanos(end - start);
}

final Duration runInitArrays() {
return timed(this::initArrays);
}

final SimpleImmutableEntry<Duration, Data<T>> runReadArrays() {
return timed(this::readArrays);
}

final SimpleImmutableEntry<Timings<Duration>, T> runAll(int times) {
Timings<Duration> timings = new Timings<>();
T lastSum = null;
Expand Down
93 changes: 69 additions & 24 deletions src/java/java-stream/src/main/java/javastream/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,40 @@ static final class Implementation {
}
}

@SuppressWarnings("unchecked")
static void showInit(
int totalBytes, double megaScale, Options opt, Duration init, Duration read) {
List<Entry<String, Double>> setup =
Arrays.asList(
new SimpleImmutableEntry<>("Init", durationToSeconds(init)),
new SimpleImmutableEntry<>("Read", durationToSeconds(read)));
if (opt.csv) {
tabulateCsv(
true,
setup.stream()
.map(
x ->
Arrays.asList(
new SimpleImmutableEntry<>("function", x.getKey()),
new SimpleImmutableEntry<>("n_elements", opt.arraysize + ""),
new SimpleImmutableEntry<>("sizeof", totalBytes + ""),
new SimpleImmutableEntry<>(
"max_m" + (opt.mibibytes ? "i" : "") + "bytes_per_sec",
((megaScale * (double) totalBytes / x.getValue())) + ""),
new SimpleImmutableEntry<>("runtime", x.getValue() + "")))
.toArray(List[]::new));
} else {
for (Entry<String, Double> e : setup) {
System.out.printf(
"%s: %.5f s (%.5f M%sBytes/sec)%n",
e.getKey(),
e.getValue(),
megaScale * (double) totalBytes / e.getValue(),
opt.mibibytes ? "i" : "");
}
}
}

static <T extends Number> boolean run(
String name, Config<T> config, Function<Config<T>, JavaStream<T>> mkStream) {

Expand Down Expand Up @@ -183,35 +217,46 @@ static <T extends Number> boolean run(

JavaStream<T> stream = mkStream.apply(config);

stream.initArrays();

Duration init = stream.runInitArrays();
final boolean ok;
switch (config.benchmark) {
case ALL:
Entry<Timings<Duration>, T> results = stream.runAll(opt.numtimes);
ok = checkSolutions(stream.data(), config, Optional.of(results.getValue()));
Timings<Duration> timings = results.getKey();
tabulateCsv(
opt.csv,
mkCsvRow(timings.copy, "Copy", 2 * arrayBytes, megaScale, opt),
mkCsvRow(timings.mul, "Mul", 2 * arrayBytes, megaScale, opt),
mkCsvRow(timings.add, "Add", 3 * arrayBytes, megaScale, opt),
mkCsvRow(timings.triad, "Triad", 3 * arrayBytes, megaScale, opt),
mkCsvRow(timings.dot, "Dot", 2 * arrayBytes, megaScale, opt));
break;
{
Entry<Timings<Duration>, T> results = stream.runAll(opt.numtimes);
SimpleImmutableEntry<Duration, Data<T>> read = stream.runReadArrays();
showInit(totalBytes, megaScale, opt, init, read.getKey());
ok = checkSolutions(read.getValue(), config, Optional.of(results.getValue()));
Timings<Duration> timings = results.getKey();
tabulateCsv(
opt.csv,
mkCsvRow(timings.copy, "Copy", 2 * arrayBytes, megaScale, opt),
mkCsvRow(timings.mul, "Mul", 2 * arrayBytes, megaScale, opt),
mkCsvRow(timings.add, "Add", 3 * arrayBytes, megaScale, opt),
mkCsvRow(timings.triad, "Triad", 3 * arrayBytes, megaScale, opt),
mkCsvRow(timings.dot, "Dot", 2 * arrayBytes, megaScale, opt));
break;
}
case NSTREAM:
List<Duration> nstreamResults = stream.runNStream(opt.numtimes);
ok = checkSolutions(stream.data(), config, Optional.empty());
tabulateCsv(opt.csv, mkCsvRow(nstreamResults, "Nstream", 4 * arrayBytes, megaScale, opt));
break;
{
List<Duration> nstreamResults = stream.runNStream(opt.numtimes);
SimpleImmutableEntry<Duration, Data<T>> read = stream.runReadArrays();
showInit(totalBytes, megaScale, opt, init, read.getKey());
ok = checkSolutions(read.getValue(), config, Optional.empty());
tabulateCsv(opt.csv, mkCsvRow(nstreamResults, "Nstream", 4 * arrayBytes, megaScale, opt));
break;
}
case TRIAD:
Duration triadResult = stream.runTriad(opt.numtimes);
ok = checkSolutions(stream.data(), config, Optional.empty());
int triadTotalBytes = 3 * arrayBytes * opt.numtimes;
double bandwidth = megaScale * (triadTotalBytes / durationToSeconds(triadResult));
System.out.printf("Runtime (seconds): %.5f", durationToSeconds(triadResult));
System.out.printf("Bandwidth (%s/s): %.3f ", gigaSuffix, bandwidth);
break;
{
Duration triadResult = stream.runTriad(opt.numtimes);
SimpleImmutableEntry<Duration, Data<T>> read = stream.runReadArrays();
showInit(totalBytes, megaScale, opt, init, read.getKey());
ok = checkSolutions(read.getValue(), config, Optional.empty());
int triadTotalBytes = 3 * arrayBytes * opt.numtimes;
double bandwidth = megaScale * (triadTotalBytes / durationToSeconds(triadResult));
System.out.printf("Runtime (seconds): %.5f", durationToSeconds(triadResult));
System.out.printf("Bandwidth (%s/s): %.3f ", gigaSuffix, bandwidth);
break;
}
default:
throw new AssertionError();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public T dot() {
}

@Override
public Data<T> data() {
public Data<T> readArrays() {
return kernels.syncAndDispose();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public T dot() {
}

@Override
public Data<T> data() {
public Data<T> readArrays() {
return new Data<>(a, b, c);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public T dot() {
}

@Override
public Data<T> data() {
public Data<T> readArrays() {
return new Data<>(a, b, c);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public Double dot() {
}

@Override
public Data<Double> data() {
public Data<Double> readArrays() {
return new Data<>(boxed(a), boxed(b), boxed(c));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public Float dot() {
}

@Override
public Data<Float> data() {
public Data<Float> readArrays() {
return new Data<>(boxed(a), boxed(b), boxed(c));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public Double dot() {
}

@Override
public Data<Double> data() {
public Data<Double> readArrays() {
return new Data<>(boxed(a), boxed(b), boxed(c));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public Float dot() {
}

@Override
public Data<Float> data() {
public Data<Float> readArrays() {
return new Data<>(boxed(a), boxed(b), boxed(c));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@
import java.util.stream.Collectors;
import javastream.JavaStream;
import javastream.Main.Config;
import uk.ac.manchester.tornado.api.TaskSchedule;
import uk.ac.manchester.tornado.api.TornadoRuntimeCI;
import uk.ac.manchester.tornado.api.TornadoExecutionPlan;
import uk.ac.manchester.tornado.api.TornadoRuntimeInterface;
import uk.ac.manchester.tornado.api.common.TornadoDevice;
import uk.ac.manchester.tornado.api.runtime.TornadoRuntime;

abstract class GenericTornadoVMStream<T> extends JavaStream<T> {

protected final TornadoDevice device;

protected TaskSchedule copyTask;
protected TaskSchedule mulTask;
protected TaskSchedule addTask;
protected TaskSchedule triadTask;
protected TaskSchedule nstreamTask;
protected TaskSchedule dotTask;
protected TornadoExecutionPlan copyTask;
protected TornadoExecutionPlan mulTask;
protected TornadoExecutionPlan addTask;
protected TornadoExecutionPlan triadTask;
protected TornadoExecutionPlan nstreamTask;
protected TornadoExecutionPlan dotTask;

GenericTornadoVMStream(Config<T> config) {
super(config);

try {
TornadoRuntimeCI runtime = TornadoRuntime.getTornadoRuntime();
TornadoRuntimeInterface runtime = TornadoRuntime.getTornadoRuntime();
List<TornadoDevice> devices = TornadoVMStreams.enumerateDevices(runtime);
device = devices.get(config.options.device);

Expand All @@ -42,10 +42,6 @@ abstract class GenericTornadoVMStream<T> extends JavaStream<T> {
}
}

protected static TaskSchedule mkSchedule() {
return new TaskSchedule("");
}

@Override
public List<String> listDevices() {
return TornadoVMStreams.enumerateDevices(TornadoRuntime.getTornadoRuntime()).stream()
Expand All @@ -55,12 +51,12 @@ public List<String> listDevices() {

@Override
public void initArrays() {
this.copyTask.warmup();
this.mulTask.warmup();
this.addTask.warmup();
this.triadTask.warmup();
this.nstreamTask.warmup();
this.dotTask.warmup();
this.copyTask.withWarmUp();
this.mulTask.withWarmUp();
this.addTask.withWarmUp();
this.triadTask.withWarmUp();
this.nstreamTask.withWarmUp();
this.dotTask.withWarmUp();
}

@Override
Expand Down
Loading

0 comments on commit a27abfe

Please sign in to comment.