-
Notifications
You must be signed in to change notification settings - Fork 12
/
AparapiRunner.java
118 lines (109 loc) · 4.12 KB
/
AparapiRunner.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* JPPF.
* Copyright (C) 2005-2019 JPPF Team.
* http://www.jppf.org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jppf.example.aparapi;
import java.util.List;
import org.jppf.client.JPPFClient;
import org.jppf.client.JPPFJob;
import org.jppf.node.protocol.Task;
import org.jppf.utils.JPPFConfiguration;
import org.jppf.utils.StringUtils;
import org.jppf.utils.TypedProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author Laurent Cohen
*/
public class AparapiRunner {
/**
* Logger for this class.
*/
private static Logger log = LoggerFactory.getLogger(AparapiRunner.class);
/**
* The JPPF client singleton.
*/
private static JPPFClient client = null;
/**
* Entry poit for this applications.
* @param args command line arguments are not used.
* @throws Throwable if any error occurs.
*/
public static void main(final String[] args) throws Throwable {
try {
print("creating client");
client = new JPPFClient();
perform();
} catch (final Exception e) {
e.printStackTrace();
} finally {
client.close();
}
}
/**
* Submit matrix multiplication jobs to the grid, for execution on a GPU on the nodes' machines.
* @throws Throwable if any error occurs.
*/
public static void perform() throws Throwable {
final TypedProperties config = JPPFConfiguration.getProperties();
final int iterations = config.getInt("iterations", 10);
final int tasksPerJob = config.getInt("tasksPerJob", 1);
final int matrixSize = config.getInt("matrixSize", 1500);
String execMode = config.getString("execMode", "GPU");
if (!"GPU".equalsIgnoreCase(execMode) && !"JTP".equalsIgnoreCase(execMode)) execMode = "GPU";
print("starting GPU test with " + iterations + " jobs, " + tasksPerJob + " tasks per job and a matrix size of " + matrixSize + ", execution mode: " + execMode);
// initial values for execution timing stats
long totalIterationTime = 0L;
long min = Long.MAX_VALUE;
long max = 0L;
// one job per iteration
for (int n = 0; n < iterations; n++) {
final SquareMatrix matrixA = new SquareMatrix(matrixSize);
matrixA.assignRandomValues();
final SquareMatrix matrixB = new SquareMatrix(matrixSize);
matrixB.assignRandomValues();
final long start = System.nanoTime();
final JPPFJob job = new JPPFJob();
job.setName("gpu_job_" + n);
for (int i = 0; i < tasksPerJob; i++)
job.add(new AparapiTask(matrixA, matrixB, execMode));
// submit and get the results
final List<Task<?>> results = client.submit(job);
for (final Task<?> task : results) {
if (task.getThrowable() != null) throw task.getThrowable();
final AparapiTask t = (AparapiTask) task;
assert t.getResult() instanceof SquareMatrix;
//print("result for " + task.getId() + ": " + task.getResult());
}
final long elapsed = (System.nanoTime() - start) / 1000000;
if (elapsed < min) min = elapsed;
if (elapsed > max) max = elapsed;
totalIterationTime += elapsed;
print("Iteration #" + (n + 1) + " performed in " + StringUtils.toStringDuration(elapsed));
}
print("total time: " + StringUtils.toStringDuration(totalIterationTime) + ", average time: " + StringUtils.toStringDuration(totalIterationTime / iterations) + ", min = "
+ StringUtils.toStringDuration(min) + ", max = " + StringUtils.toStringDuration(max));
}
/**
* Print a message to the log and to the console.
* @param msg the message to print.
*/
private static void print(final String msg) {
System.out.println(msg);
log.info(msg);
}
}