Skip to content

Commit

Permalink
Added JPGS version
Browse files Browse the repository at this point in the history
  • Loading branch information
cadebrown committed Sep 17, 2016
1 parent e434070 commit 6d992f0
Show file tree
Hide file tree
Showing 8 changed files with 266 additions and 9 deletions.
11 changes: 8 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@
/run.build/
/workloads/*
!/workloads/test.workload
/program/output/*
!/program/output/
/output/*
!/output/
*.dat
*.vscode
/build/
/build/
/JPGS/build/
/JPGS/nbproject/
/JPGS/test/
/nbproject/private/
/JPGS/dist/
2 changes: 1 addition & 1 deletion CPGS/PGS.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void get_primes(const char *primefile) {
int main(int argc, char *argv[])
{
//Ranges
int r0 = 1000, r1 = 1000, r2 = 1000;
int r0 = 2000, r1 = 2000, r2 = 2000;
//Offsets
int o0 = 0, o1 = 0, o2 = 0;
char *fn = "./primes.dat";
Expand Down
73 changes: 73 additions & 0 deletions JPGS/build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<!-- By default, only the Clean and Build commands use this build script. -->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="JPGS" default="default" basedir=".">
<description>Builds, tests, and runs the project JPGS.</description>
<import file="nbproject/build-impl.xml"/>
<!--
There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. They are:
-pre-init: called before initialization of project properties
-post-init: called after initialization of project properties
-pre-compile: called before javac compilation
-post-compile: called after javac compilation
-pre-compile-single: called before javac compilation of single file
-post-compile-single: called after javac compilation of single file
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test
-pre-jar: called before JAR building
-post-jar: called after JAR building
-post-clean: called after cleaning build products
(Targets beginning with '-' are not intended to be called on their own.)
Example of inserting an obfuscator after compilation could look like this:
<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Another way to customize the build is by overriding existing main targets.
The targets of interest are:
-init-macrodef-javac: defines macro for javac compilation
-init-macrodef-junit: defines macro for junit execution
-init-macrodef-debug: defines macro for class debugging
-init-macrodef-java: defines macro for class execution
-do-jar: JAR building
run: execution of project
-javadoc-build: Javadoc generation
test-report: JUnit report generation
An example of overriding the target for project execution could look like this:
<target name="run" depends="JPGS-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
</target>
Notice that the overridden target depends on the jar target and not only on
the compile target as the regular run target does. Again, for a list of available
properties which you can use, check the target you are overriding in the
nbproject/build-impl.xml file.
-->
</project>
3 changes: 3 additions & 0 deletions JPGS/manifest.mf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

172 changes: 172 additions & 0 deletions JPGS/src/jpgs/JPGS.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
/*
* Copyright (C) 2016 ChemicalDevelopment
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package jpgs;

/**
*
* @author cade
*/

import com.nativelibs4java.opencl.CLBuffer;
import com.nativelibs4java.opencl.CLContext;
import com.nativelibs4java.opencl.CLEvent;
import com.nativelibs4java.opencl.CLKernel;
import com.nativelibs4java.opencl.CLMem;
import com.nativelibs4java.opencl.CLPlatform;
import com.nativelibs4java.opencl.CLPlatform.DeviceFeature;
import com.nativelibs4java.opencl.CLProgram;
import com.nativelibs4java.opencl.CLQueue;
import com.nativelibs4java.opencl.JavaCL;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.bridj.Pointer;
import sun.misc.IOUtils;

public class JPGS {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
String fileName = "./primes.dat";
int[] ranges = new int[] { 1000, 1000, 1000 };
int[] offsets = new int[] {0, 0, 0};
String deviceFeature = "GPU";
if (args.length > 0) fileName = args[0];
if (args.length > 1) ranges[0] = Integer.parseInt(args[1]);
if (args.length > 2) ranges[1] = Integer.parseInt(args[2]);
if (args.length > 3) ranges[2] = Integer.parseInt(args[3]);
if (args.length > 4) offsets[0] = Integer.parseInt(args[4]);
if (args.length > 5) offsets[1] = Integer.parseInt(args[5]);
if (args.length > 6) offsets[2] = Integer.parseInt(args[6]);
if (args.length > 7) deviceFeature = args[7];
test_quad(ranges, offsets, getPrimeArray(fileName), DeviceFeature.valueOf(deviceFeature.toUpperCase()));
}


public static Pointer<Integer> getPrimeArray(String fileName) throws FileNotFoundException, IOException {
File fi = new File(fileName);
int len = (int)fi.length();
InputStream f = new FileInputStream(fileName);
Path path = Paths.get(fileName);
byte[] bitset = Files.readAllBytes(path);
Pointer<Integer> prime_ptr = Pointer.allocateInts(len / 4 + 1);
return prime_ptr.setBytes(bitset);
}


public static void test_quad(int[] ranges, int offsets[], Pointer<Integer> prime_array, DeviceFeature d) {
CLContext context = JavaCL.createBestContext(d);
CLQueue queue = context.createDefaultQueue();

Pointer<Integer> offset_ptr = Pointer.allocateInts(3);
offset_ptr.setInts(offsets);

CLBuffer<Integer> prime_buff = context.createBuffer(CLMem.Usage.Input, prime_array);
CLBuffer<Integer> offset_buff = context.createBuffer(CLMem.Usage.Input, offset_ptr);

prime_buff.write(queue, prime_array, true);
offset_buff.write(queue, offset_ptr, true);

CLProgram program = context.createProgram(kernelCode);
long start = System.nanoTime();
{
CLKernel kernel = program.createKernel("test_quadratics", prime_buff, offset_buff); //, inp_p0, inp_p1, inp_p2);
CLEvent kernelCompletion = kernel.enqueueNDRange(queue, ranges);
kernelCompletion.waitFor();
}
long end = System.nanoTime();

System.out.format("Done! (%f%s)\n", (end - start) / Math.pow(10, 9), "s");
}

public static String kernelCode = "/*\n" +
"\n" +
"General purpose functions\n" +
"\n" +
"*/\n" +
"\n" +
"//Returns bit\n" +
"int chbit(int x, int b) {\n" +
" return (x >> b) & 1;\n" +
"}\n" +
"\n" +
"/*\n" +
"\n" +
"Kernel for testing quadratics against a prime array.\n" +
"\n" +
"*/\n" +
"__kernel void test_quadratics(__constant int *pr, __constant int *offsets) {\n" +
" int i = get_global_id(0) + offsets[0];\n" +
" int j = get_global_id(1) + offsets[1];\n" +
" int k = get_global_id(2) + offsets[2];\n" +
"\n" +
" int x, y;\n" +
" int evals[101];\n" +
" int inarow = 0;\n" +
"\n" +
" evals[0] = abs(i); //i + 0 * j + 0 * 0 * k\n" +
" if (chbit(pr[evals[0] >> 5], evals[0] % 32) == 0) return;\n" +
" evals[1] = abs(i + j + k); //i + j * 1 + k * 1 * 1\n" +
" if (chbit(pr[evals[1] >> 5], evals[1] % 32) == 0) return;\n" +
" inarow = 2;\n" +
"\n" +
" for (x = 2; x < 101; ++x) {\n" +
" evals[x] = abs(i + x * (j + k * x));\n" +
" if (chbit(pr[evals[x] >> 5], evals[x] % 32) == 1) {\n" +
" inarow = x + 1;\n" +
" } else {\n" +
" break;\n" +
" }\n" +
" }\n" +
" \n" +
" if (inarow < 40) {\n" +
" return;\n" +
" }\n" +
"\n" +
" int distinct;\n" +
" int hbd = 1;\n" +
" for (x = 0; x <= inarow; ++x) {\n" +
" if (hbd == 0 || x == inarow) {\n" +
" if (x == inarow) {\n" +
" distinct = x;\n" +
" }\n" +
" break;\n" +
" }\n" +
" for (y = 0; y < x; ++y) {\n" +
" if (evals[y] == evals[x]) {\n" +
" hbd = 0;\n" +
" distinct = x;\n" +
" break;\n" +
" }\n" +
" }\n" +
" }\n" +
" if ((inarow >= 60 || distinct >= 40) && distinct > 1) {\n" +
" printf(\"PGSO: %d, %d; [%d, %d, %d]\\n\", inarow, distinct, i, j, k);\n" +
" }\n" +
"}\n" +
"\n" +
"__kernel void foo(__constant int * pr) {\n" +
" //int i = get_global_id(0);\n" +
" //printf(\"%d isp %d\\n\", i, chbit(pr[i / 8], i % 8));\n" +
"}";
}
9 changes: 8 additions & 1 deletion PGS.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,17 @@ function runOnline() {
// Read and process task data
console.log("Now Processing: ");
console.dir(data);
var data_t = data;
data_t.timestamp = new Date().getTime();
var wref = db.ref('/user_data/' + usr.uid + "/current_workloads/").push(data_t);

var oncomplete = function() {
data_t.timestamp = new Date().getTime();
db.ref('/user_data/' + usr.uid + "/workloads/").push(data_t);
wref.set({});
setTimeout(function() {
resolve();
}, 1000);
}, 50);
};

doWorkload(data, false, oncomplete, progress);
Expand Down Expand Up @@ -271,6 +277,7 @@ process.on('SIGINT', function() {
//queue[i].shutdown().then(function() {
console.log('Shutdown thread ' + j++);
if (j == queue.length) {
// console.dir(queue[i]);
process.exit();
}
//});
Expand Down
4 changes: 0 additions & 4 deletions output/output.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
PGSO: 40, 40; [41, 1, 1]PGSO: 40, 40; [41, 1, 1]PGSO: 40, 40; [41, 1, 1]
PGSO: 40, 40; [41, 1, 1]
PGSO: 40, 40; [41, 1, 1]
PGSO: 40, 40; [41, 1, 1]
PGSO: 40, 40; [41, 1, 1]
PGSO: 40, 40; [41, 1, 1]
PGSO: 40, 40; [41, 1, 1]
1 change: 1 addition & 0 deletions run_jcl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
java -jar ./JPGS/dist/JPGS.jar $1 $2 $3 $4 $5 $6 $7 $8

0 comments on commit 6d992f0

Please sign in to comment.