From 6187e22ec03859842f886175ffd1ee2ff66532cd Mon Sep 17 00:00:00 2001 From: erubow Date: Thu, 17 Jan 2008 21:06:06 +0000 Subject: [PATCH] First attempt at porting a java benchmark. Not working yet... --- .../section2/JGFCryptBenchSizeA.java | 53 ++ .../threadv1.0/section2/crypt/IDEATest.java | 562 ++++++++++++++++++ .../section2/crypt/JGFCryptBench.java | 98 +++ .../section2/jgfutil/JGFInstrumentor.java | 211 +++++++ .../threadv1.0/section2/jgfutil/JGFTimer.java | 129 ++++ .../Prefetch/threadv1.0/section2/makefile | 11 + 6 files changed, 1064 insertions(+) create mode 100644 Robust/src/Benchmarks/Prefetch/threadv1.0/section2/JGFCryptBenchSizeA.java create mode 100644 Robust/src/Benchmarks/Prefetch/threadv1.0/section2/crypt/IDEATest.java create mode 100644 Robust/src/Benchmarks/Prefetch/threadv1.0/section2/crypt/JGFCryptBench.java create mode 100644 Robust/src/Benchmarks/Prefetch/threadv1.0/section2/jgfutil/JGFInstrumentor.java create mode 100644 Robust/src/Benchmarks/Prefetch/threadv1.0/section2/jgfutil/JGFTimer.java create mode 100644 Robust/src/Benchmarks/Prefetch/threadv1.0/section2/makefile diff --git a/Robust/src/Benchmarks/Prefetch/threadv1.0/section2/JGFCryptBenchSizeA.java b/Robust/src/Benchmarks/Prefetch/threadv1.0/section2/JGFCryptBenchSizeA.java new file mode 100644 index 00000000..74bd2834 --- /dev/null +++ b/Robust/src/Benchmarks/Prefetch/threadv1.0/section2/JGFCryptBenchSizeA.java @@ -0,0 +1,53 @@ +/************************************************************************** +* * +* Java Grande Forum Benchmark Suite - Thread Version 1.0 * +* * +* produced by * +* * +* Java Grande Benchmarking Project * +* * +* at * +* * +* Edinburgh Parallel Computing Centre * +* * +* email: epcc-javagrande@epcc.ed.ac.uk * +* * +* * +* This version copyright (c) The University of Edinburgh, 2001. * +* All rights reserved. * +* * +**************************************************************************/ +/************************************************************************** +* Ported for DSTM Benchmark * +**************************************************************************/ + + +import crypt.*; +import jgfutil.*; + +public class JGFCryptBenchSizeA{ + + global JGFIntrumentor instr; + + public static void main(String argv[]){ + + int nthreads; + + if(argv.length != 0 ) { + nthreads = Integer.parseInt(argv[0]); + } else { + System.printString("The no of threads has not been specified, defaulting to 1"); + System.printString(" "); + nthreads = 1; + } + + instr = new JGFInstrumentor(); + instr.printHeader(2,0,nthreads); + + JGFCryptBench cb = new JGFCryptBench(nthreads, instr); + cb.JGFrun(0); + + } +} + + diff --git a/Robust/src/Benchmarks/Prefetch/threadv1.0/section2/crypt/IDEATest.java b/Robust/src/Benchmarks/Prefetch/threadv1.0/section2/crypt/IDEATest.java new file mode 100644 index 00000000..940c8598 --- /dev/null +++ b/Robust/src/Benchmarks/Prefetch/threadv1.0/section2/crypt/IDEATest.java @@ -0,0 +1,562 @@ +/************************************************************************** +* * +* Java Grande Forum Benchmark Suite - Thread Version 1.0 * +* * +* produced by * +* * +* Java Grande Benchmarking Project * +* * +* at * +* * +* Edinburgh Parallel Computing Centre * +* * +* email: epcc-javagrande@epcc.ed.ac.uk * +* * +* Original version of this code by * +* Gabriel Zachmann (zach@igd.fhg.de) * +* * +* This version copyright (c) The University of Edinburgh, 2001. * +* All rights reserved. * +* * +**************************************************************************/ +/************************************************************************** +* Ported for DSTM Benchmark * +**************************************************************************/ + + +/** +* Class IDEATest +* +* This test performs IDEA encryption then decryption. IDEA stands +* for International Data Encryption Algorithm. The test is based +* on code presented in Applied Cryptography by Bruce Schnier, +* which was based on code developed by Xuejia Lai and James L. +* Massey. + +**/ + +package crypt; + +import java.util.*; +import jgfutil.*; + +class IDEATest +{ + +// Declare class data. Byte buffer plain1 holds the original +// data for encryption, crypt1 holds the encrypted data, and +// plain2 holds the decrypted data, which should match plain1 +// byte for byte. + +int array_rows; + +byte [] plain1; // Buffer for plaintext data. +byte [] crypt1; // Buffer for encrypted data. +byte [] plain2; // Buffer for decrypted data. + +short [] userkey; // Key for encryption/decryption. +int [] Z; // Encryption subkey (userkey derived). +int [] DK; // Decryption subkey (userkey derived). + + + +void Do() +{ + + IDEARunner th[] = new IDEARunner [JGFCryptBench.nthreads]; + + // Start the stopwatch. + JGFInstrumentor.startTimer("Section2:Crypt:Kernel"); + + // Encrypt plain1. + for(int i=1;i>>9) | (Z[i-6]<<7)) // Shift and combine. + & 0xFFFF; // Just 16 bits. + continue; // Next iteration. + } + + if (j == 6) // Wrap to beginning for second chunk. + { + Z[i] = ((Z[i -7]>>>9) | (Z[i-14]<<7)) + & 0xFFFF; + continue; + } + + // j == 7 so wrap to beginning for both chunks. + + Z[i] = ((Z[i -15]>>>9) | (Z[i-14]<<7)) + & 0xFFFF; + } +} + +/* +* calcDecryptKey +* +* Builds the 52 16-bit encryption subkeys DK[] from the encryption- +* subkeys Z[]. DK[] is a 32-bit int array holding 16-bit values as +* unsigned. +*/ + +private void calcDecryptKey() +{ + int j, k; // Index counters. + int t1, t2, t3; // Temps to hold decrypt subkeys. + + t1 = inv(Z[0]); // Multiplicative inverse (mod x10001). + t2 = - Z[1] & 0xffff; // Additive inverse, 2nd encrypt subkey. + t3 = - Z[2] & 0xffff; // Additive inverse, 3rd encrypt subkey. + + DK[51] = inv(Z[3]); // Multiplicative inverse (mod x10001). + DK[50] = t3; + DK[49] = t2; + DK[48] = t1; + + j = 47; // Indices into temp and encrypt arrays. + k = 4; + for (int i = 0; i < 7; i++) + { + t1 = Z[k++]; + DK[j--] = Z[k++]; + DK[j--] = t1; + t1 = inv(Z[k++]); + t2 = -Z[k++] & 0xffff; + t3 = -Z[k++] & 0xffff; + DK[j--] = inv(Z[k++]); + DK[j--] = t2; + DK[j--] = t3; + DK[j--] = t1; + } + + t1 = Z[k++]; + DK[j--] = Z[k++]; + DK[j--] = t1; + t1 = inv(Z[k++]); + t2 = -Z[k++] & 0xffff; + t3 = -Z[k++] & 0xffff; + DK[j--] = inv(Z[k++]); + DK[j--] = t3; + DK[j--] = t2; + DK[j--] = t1; +} + + + + + +/* +* mul +* +* Performs multiplication, modulo (2**16)+1. This code is structured +* on the assumption that untaken branches are cheaper than taken +* branches, and that the compiler doesn't schedule branches. +* Java: Must work with 32-bit int and one 64-bit long to keep +* 16-bit values and their products "unsigned." The routine assumes +* that both a and b could fit in 16 bits even though they come in +* as 32-bit ints. Lots of "& 0xFFFF" masks here to keep things 16-bit. +* Also, because the routine stores mod (2**16)+1 results in a 2**16 +* space, the result is truncated to zero whenever the result would +* zero, be 2**16. And if one of the multiplicands is 0, the result +* is not zero, but (2**16) + 1 minus the other multiplicand (sort +* of an additive inverse mod 0x10001). + +* NOTE: The java conversion of this routine works correctly, but +* is half the speed of using Java's modulus division function (%) +* on the multiplication with a 16-bit masking of the result--running +* in the Symantec Caje IDE. So it's not called for now; the test +* uses Java % instead. +*/ + +private int mul(int a, int b) +{ + int ret; + long p; // Large enough to catch 16-bit multiply + // without hitting sign bit. + if (a != 0) + { + if(b != 0) + { + p = (long) a * b; + b = (int) p & 0xFFFF; // Lower 16 bits. + a = (int) p >>> 16; // Upper 16 bits. + if (b < a) + return (b - a + 1) & 0xFFFF; + else + return (b - a) & 0xFFFF; + } + else + return ((1 - a) & 0xFFFF); // If b = 0, then same as + // 0x10001 - a. + } + else // If a = 0, then return + return((1 - b) & 0xFFFF); // same as 0x10001 - b. +} + +/* +* inv +* +* Compute multiplicative inverse of x, modulo (2**16)+1 using +* extended Euclid's GCD (greatest common divisor) algorithm. +* It is unrolled twice to avoid swapping the meaning of +* the registers. And some subtracts are changed to adds. +* Java: Though it uses signed 32-bit ints, the interpretation +* of the bits within is strictly unsigned 16-bit. +*/ + +private int inv(int x) +{ + int t0, t1; + int q, y; + + if (x <= 1) // Assumes positive x. + return(x); // 0 and 1 are self-inverse. + + t1 = 0x10001 / x; // (2**16+1)/x; x is >= 2, so fits 16 bits. + y = 0x10001 % x; + if (y == 1) + return((1 - t1) & 0xFFFF); + + t0 = 1; + do { + q = x / y; + x = x % y; + t0 += q * t1; + if (x == 1) return(t0); + q = y / x; + y = y % x; + t1 += q * t0; + } while (y != 1); + + return((1 - t1) & 0xFFFF); +} + +/* +* freeTestData +* +* Nulls arrays and forces garbage collection to free up memory. +*/ + +void freeTestData() +{ + plain1 = null; + crypt1 = null; + plain2 = null; + userkey = null; + Z = null; + DK = null; + + //System.gc(); // Force garbage collection. +} + + +} + + + +class IDEARunner extends Thread { + + int id,key[]; + byte text1[],text2[]; + + public IDEARunner(int id, byte [] text1, byte [] text2, int [] key) { + this.id = id; + this.text1=text1; + this.text2=text2; + this.key=key; + } +/* +* run() +* +* IDEA encryption/decryption algorithm. It processes plaintext in +* 64-bit blocks, one at a time, breaking the block into four 16-bit +* unsigned subblocks. It goes through eight rounds of processing +* using 6 new subkeys each time, plus four for last step. The source +* text is in array text1, the destination text goes into array text2 +* The routine represents 16-bit subblocks and subkeys as type int so +* that they can be treated more easily as unsigned. Multiplication +* modulo 0x10001 interprets a zero sub-block as 0x10000; it must to +* fit in 16 bits. +*/ + + public void run() { + int ilow, iupper, slice, tslice, ttslice; + + tslice = text1.length / 8; + ttslice = (tslice + JGFCryptBench.nthreads-1) / JGFCryptBench.nthreads; + slice = ttslice*8; + + ilow = id*slice; + iupper = (id+1)*slice; + if(iupper > text1.length) iupper = text1.length; + +int i1 = ilow; // Index into first text array. +int i2 = ilow; // Index into second text array. +int ik; // Index into key array. +int x1, x2, x3, x4, t1, t2; // Four "16-bit" blocks, two temps. +int r; // Eight rounds of processing. + + for (int i =ilow ; i >> 8); + text2[i2++] = (byte) x3; // x3 and x2 are switched + text2[i2++] = (byte) (x3 >>> 8); // only in name. + text2[i2++] = (byte) x2; + text2[i2++] = (byte) (x2 >>> 8); + text2[i2++] = (byte) x4; + text2[i2++] = (byte) (x4 >>> 8); + +} // End for loop. + + } // End routine. + +} // End of class + + + + + + + + + diff --git a/Robust/src/Benchmarks/Prefetch/threadv1.0/section2/crypt/JGFCryptBench.java b/Robust/src/Benchmarks/Prefetch/threadv1.0/section2/crypt/JGFCryptBench.java new file mode 100644 index 00000000..d80e0631 --- /dev/null +++ b/Robust/src/Benchmarks/Prefetch/threadv1.0/section2/crypt/JGFCryptBench.java @@ -0,0 +1,98 @@ +/************************************************************************** +* * +* Java Grande Forum Benchmark Suite - Thread Version 1.0 * +* * +* produced by * +* * +* Java Grande Benchmarking Project * +* * +* at * +* * +* Edinburgh Parallel Computing Centre * +* * +* email: epcc-javagrande@epcc.ed.ac.uk * +* * +* * +* This version copyright (c) The University of Edinburgh, 2001. * +* All rights reserved. * +* * +**************************************************************************/ +/************************************************************************** +* Ported for DSTM Benchmark * +**************************************************************************/ + + +package crypt; +import jgfutil.*; + + +public class JGFCryptBench extends IDEATest { + + private int size; + private int datasizes[]; + public int nthreads; + global JGFInstrumentor instr; + + public JGFCryptBench(int nthreads, JGFInstrumentor instr) + { + this.nthreads = nthreads; + this.instr = instr; + datasizes = new int[3]; + datasizes[0] = 3000000; + datasizes[1] = 20000000; + datasizes[2] = 50000000; + } + + + public void JGFsetsize(int size){ + this.size = size; + } + + public void JGFinitialise(){ + array_rows = datasizes[size]; + buildTestData(); + } + + public void JGFkernel(){ + Do(); + } + + public void JGFvalidate(){ + boolean error; + + error = false; + for (int i = 0; i < array_rows; i++){ + error = (plain1 [i] != plain2 [i]); + if (error){ + System.printString("Validation failed"); + System.printString("Original Byte " + i + " = " + plain1[i]); + System.printString("Encrypted Byte " + i + " = " + crypt1[i]); + System.printString("Decrypted Byte " + i + " = " + plain2[i]); + //break; + } + } + } + + + public void JGFtidyup(){ + freeTestData(); + } + + + + public void JGFrun(int size){ + + + instr.addTimer("Section2:Crypt:Kernel", "Kbyte",size); + + JGFsetsize(size); + JGFinitialise(); + JGFkernel(); + JGFvalidate(); + JGFtidyup(); + + + instr.addOpsToTimer("Section2:Crypt:Kernel", (2*array_rows)/1000.); + instr.printTimer("Section2:Crypt:Kernel"); + } +} diff --git a/Robust/src/Benchmarks/Prefetch/threadv1.0/section2/jgfutil/JGFInstrumentor.java b/Robust/src/Benchmarks/Prefetch/threadv1.0/section2/jgfutil/JGFInstrumentor.java new file mode 100644 index 00000000..e9c0906f --- /dev/null +++ b/Robust/src/Benchmarks/Prefetch/threadv1.0/section2/jgfutil/JGFInstrumentor.java @@ -0,0 +1,211 @@ +/************************************************************************** +* * +* Java Grande Forum Benchmark Suite - Thread Version 1.0 * +* * +* produced by * +* * +* Java Grande Benchmarking Project * +* * +* at * +* * +* Edinburgh Parallel Computing Centre * +* * +* email: epcc-javagrande@epcc.ed.ac.uk * +* * +* * +* This version copyright (c) The University of Edinburgh, 1999. * +* All rights reserved. * +* * +**************************************************************************/ +/************************************************************************** +* Ported for DSTM Benchmark * +**************************************************************************/ + + +package jgfutil; + +import java.util.*; + +public class JGFInstrumentor{ + + private HashMap timers; + private HashMap data; + + public JGFIntrumentor() + { + timers = new HashMap(); + data = new HashMap(); + } + + public void addTimer (String name){ + + if (timers.containsKey(name)) { + System.printString("JGFInstrumentor.addTimer: warning - timer " + name + + " already exists"); + } + else { + timers.put(name, new JGFTimer(name)); + } + } + + public void addTimer (String name, String opname){ + + if (timers.containsKey(name)) { + System.printString("JGFInstrumentor.addTimer: warning - timer " + name + + " already exists"); + } + else { + timers.put(name, new JGFTimer(name,opname)); + } + + } + + public void addTimer (String name, String opname, int size){ + + if (timers.containsKey(name)) { + System.printString("JGFInstrumentor.addTimer: warning - timer " + name + + " already exists"); + } + else { + timers.put(name, new JGFTimer(name,opname,size)); + } + + } + + public void startTimer(String name){ + if (timers.containsKey(name)) { + ((JGFTimer) timers.get(name)).start(); + } + else { + System.printString("JGFInstrumentor.startTimer: failed - timer " + name + + " does not exist"); + } + + } + + public void stopTimer(String name){ + if (timers.containsKey(name)) { + ((JGFTimer) timers.get(name)).stop(); + } + else { + System.printString("JGFInstrumentor.stopTimer: failed - timer " + name + + " does not exist"); + } + } + + public void addOpsToTimer(String name, double count){ + if (timers.containsKey(name)) { + ((JGFTimer) timers.get(name)).addops(count); + } + else { + System.printString("JGFInstrumentor.addOpsToTimer: failed - timer " + name + + " does not exist"); + } + } + + public void addTimeToTimer(String name, double added_time){ + if (timers.containsKey(name)) { + ((JGFTimer) timers.get(name)).addtime(added_time); + } + else { + System.printString("JGFInstrumentor.addTimeToTimer: failed - timer " + name + + " does not exist"); + } + + + + } + + public double readTimer(String name){ + double time; + if (timers.containsKey(name)) { + time = ((JGFTimer) timers.get(name)).time; + } + else { + System.printString("JGFInstrumentor.readTimer: failed - timer " + name + + " does not exist"); + time = 0.0; + } + return time; + } + + public void resetTimer(String name){ + if (timers.containsKey(name)) { + ((JGFTimer) timers.get(name)).reset(); + } + else { + System.printString("JGFInstrumentor.resetTimer: failed - timer " + name + + " does not exist"); + } + } + + public void printTimer(String name){ + if (timers.containsKey(name)) { + ((JGFTimer) timers.get(name)).print(); + } + else { + System.printString("JGFInstrumentor.printTimer: failed - timer " + name + + " does not exist"); + } + } + + public void printperfTimer(String name){ + if (timers.containsKey(name)) { + ((JGFTimer) timers.get(name)).printperf(); + } + else { + System.printString("JGFInstrumentor.printTimer: failed - timer " + name + + " does not exist"); + } + } + + public void storeData(String name, Object obj){ + data.put(name,obj); + } + + public void retrieveData(String name, Object obj){ + obj = data.get(name); + } + + public static void printHeader(int section, int size,int nthreads) { + + String header, base; + + header = ""; + base = "Java Grande Forum Thread Benchmark Suite - Version 1.0 - Section "; + + if (section == 1) + { + header = base + "1"; + } + else if (section == 2) + { + if (size == 0) + header = base + "2 - Size A"; + else if (size == 1) + header = base + "2 - Size B"; + else if (size == 2) + header = base + "2 - Size C"; + } + else if (section == 3) + { + if (size == 0) + header = base + "3 - Size A"; + else if (size == 1) + header = base + "3 - Size B"; + } + + System.printString(header); + + if (nthreads == 1) { + System.printString("Executing on " + nthreads + " thread"); + } + else { + System.printString("Executing on " + nthreads + " threads"); + } + + System.printString(""); + + } + +} diff --git a/Robust/src/Benchmarks/Prefetch/threadv1.0/section2/jgfutil/JGFTimer.java b/Robust/src/Benchmarks/Prefetch/threadv1.0/section2/jgfutil/JGFTimer.java new file mode 100644 index 00000000..0ea93c88 --- /dev/null +++ b/Robust/src/Benchmarks/Prefetch/threadv1.0/section2/jgfutil/JGFTimer.java @@ -0,0 +1,129 @@ +/************************************************************************** +* * +* Java Grande Forum Benchmark Suite - Thread Version 1.0 * +* * +* produced by * +* * +* Java Grande Benchmarking Project * +* * +* at * +* * +* Edinburgh Parallel Computing Centre * +* * +* email: epcc-javagrande@epcc.ed.ac.uk * +* * +* * +* This version copyright (c) The University of Edinburgh, 1999. * +* All rights reserved. * +* * +**************************************************************************/ +/************************************************************************** +* Ported for DSTM Benchmark * +**************************************************************************/ + + +package jgfutil; + +public class JGFTimer { + + public String name; + public String opname; + public double time; + public double opcount; + public long calls; + public int size = -1; + + private long start_time; + private boolean on; + + public JGFTimer(String name, String opname){ + this.name = name; + this.opname = opname; + reset(); + } + + public JGFTimer(String name, String opname, int size){ + this.name = name; + this.opname = opname; + this.size = size; + reset(); + } + + public JGFTimer(String name){ + this.name = name; + this.opname = ""; + reset(); + } + + + + public void start(){ + if (on) System.printString("Warning timer " + name + " was already turned on"); + on = true; + start_time = System.currentTimeMillis(); + } + + + public void stop(){ + time += (double) (System.currentTimeMillis()-start_time) / 1000.; + if (!on) System.printString("Warning timer " + name + " wasn't turned on"); + calls++; + on = false; + } + + public void addops(double count){ + opcount += count; + } + + public void addtime(double added_time){ + time += added_time; + } + + public void reset(){ + time = 0.0; + calls = 0; + opcount = 0; + on = false; + } + + public double perf(){ + return opcount / time; + } + + public void longprint(){ + System.printString("Timer Calls Time(s) Performance("+opname+"/s)"); + System.printString(name + " " + calls + " " + time + " " + this.perf()); + } + + public void print(){ + if (opname.equals("")) + { + System.printString(name + " " + time + " (s)"); + } + else + { + if(size == 0) + System.printString(name + ":SizeA" + "\t" + time + " (s) \t " + (float)this.perf() + "\t" + " ("+opname+"/s)"); + else if (size == 1) + System.printString(name + ":SizeB" + "\t" + time + " (s) \t " + (float)this.perf() + "\t" + " ("+opname+"/s)"); + else if (size == 2) + System.printString(name + ":SizeC" + "\t" + time + " (s) \t " + (float)this.perf() + "\t" + " ("+opname+"/s)"); + else + System.printString(name + "\t" + time + " (s) \t " + (float)this.perf() + "\t" + " ("+opname+"/s)"); + } + } + + + public void printperf(){ + + String name; + name = this.name; + + // pad name to 40 characters + while ( name.length() < 40 ) name = name + " "; + + System.printString(name + "\t" + (float)this.perf() + "\t" + + " ("+opname+"/s)"); + } + +} diff --git a/Robust/src/Benchmarks/Prefetch/threadv1.0/section2/makefile b/Robust/src/Benchmarks/Prefetch/threadv1.0/section2/makefile new file mode 100644 index 00000000..763ad545 --- /dev/null +++ b/Robust/src/Benchmarks/Prefetch/threadv1.0/section2/makefile @@ -0,0 +1,11 @@ +MAINCLASS=JGFCryptBenchSizeA +SRC=${MAINCLASS}.java \ +jgfutil/JGFInstrumentor.java \ +jgfutil/JGFTimer.java \ +crypt/IDEATest.java \ +crypt/JGFCryptBench.java +FLAGS=-dsm -thread -mainclass ${MAINCLASS} -o ${MAINCLASS} + +default: + ../../../../buildscript ${FLAGS} ${SRC} + -- 2.34.1