diff options
author | Yang Zhang <yang.zhang@linaro.org> | 2016-09-23 11:17:15 +0800 |
---|---|---|
committer | Ningsheng Jian <ningsheng.jian@linaro.org> | 2016-11-02 04:15:17 +0000 |
commit | ead42d0823f9921041dbd44882ed2062c0a9f74f (patch) | |
tree | 0963333f8726b2acd8393224f4a84695f2db096f | |
parent | 7de7b54b6f037e54fa2ce5d3a2939357a2e2ebb7 (diff) |
Add samples to measure vector ldn/stn performance
Add the test cases as follows:
1. 2D vector add and mul for int/short
2. 3D vector add and mul for int/short
3. 4D vector add and mul for int/short
4. RGB To Cmyk for ld3/st4
Change-Id: I68079a8bb2f50bf0d07c3a382a1d7208b95ff9f7
4 files changed, 362 insertions, 0 deletions
diff --git a/src/main/java/org/linaro/benchmarks/TestRGBToCmyk.java b/src/main/java/org/linaro/benchmarks/TestRGBToCmyk.java new file mode 100644 index 0000000..b9bc897 --- /dev/null +++ b/src/main/java/org/linaro/benchmarks/TestRGBToCmyk.java @@ -0,0 +1,53 @@ +package org.linaro.benchmarks; + +import org.openjdk.jmh.annotations.*; +import java.util.concurrent.TimeUnit; + +@BenchmarkMode(Mode.AverageTime) +@OutputTimeUnit(TimeUnit.MICROSECONDS) +@State(Scope.Benchmark) + +public class TestRGBToCmyk +{ + static final int LENGTH = 256 * 1024; + static byte input[] = new byte[LENGTH*3]; + static byte output[] = new byte[LENGTH*4]; + + public static void TestRGBToCmykInit() + { + for (int i = 0; i < LENGTH*3; i++) { + input[i] = (byte)i; + } + } + + public static void RGBToCmyk(byte[] rgb, byte[] cmyk, int cnt) + { + int i; + int c, m, y, k; + for (i = 0; i < cnt; i++) { + /* calculate complementary colors */ + c = 255 - rgb[i*3]; + m = 255 - rgb[i*3+1]; + y = 255 - rgb[i*3+2]; + /* find the black level k */ + k = Math.min(Math.min(c, m), y); + /* correct complementary color lever based on k */ + cmyk[i*4] = (byte)(c - k); + cmyk[i*4+1] = (byte)(m - k); + cmyk[i*4+2] = (byte)(y - k); + cmyk[i*4+3] = (byte)(k); + } + } + + @Setup + public void setup() + { + TestRGBToCmykInit(); + } + + @Benchmark + public void testRGBToCmyk() { + RGBToCmyk(input, output, LENGTH); + } + +} diff --git a/src/main/java/org/linaro/benchmarks/TestSIMDLd2St2.java b/src/main/java/org/linaro/benchmarks/TestSIMDLd2St2.java new file mode 100644 index 0000000..68901ab --- /dev/null +++ b/src/main/java/org/linaro/benchmarks/TestSIMDLd2St2.java @@ -0,0 +1,95 @@ +package org.linaro.benchmarks; + +import org.openjdk.jmh.annotations.*; +import java.util.concurrent.TimeUnit; + +@BenchmarkMode(Mode.AverageTime) +@OutputTimeUnit(TimeUnit.MICROSECONDS) +@State(Scope.Benchmark) + +public class TestSIMDLd2St2 { + static final int VECT_LENGTH = 256 * 1024; + static final int DIM = 2; + static final int LENGTH = VECT_LENGTH * DIM; + static int [] in = new int[LENGTH]; + static int [] out = new int[LENGTH]; + static int [] c = new int[DIM]; + static short [] sin = new short[LENGTH]; + static short [] sout = new short[LENGTH]; + static short [] sc = new short[DIM]; + + public static void vect2DInit() { + int i; + for (i = 0; i < LENGTH; i++) { + in[i] = i + 3; + sin[i] = (short)(i + 3); + } + for (i = 0; i < DIM; i++) { + c[i] = i + 1; + sc[i] = (short)(i + 1); + } + } + + public static void vect2DAddInt( + int[] out, + int[] in, + int[] c) { + int c0 = c[0]; + int c1 = c[1]; + for (int i = 0; i < VECT_LENGTH; i++) { + out[i*DIM] = in[i*DIM] + c0; + out[i*DIM + 1] = in[i*DIM + 1] + c1; + } + } + + public static void vect2DMulInt( + int[] out, + int[] in, + int[] c) { + int c0 = c[0]; + int c1 = c[1]; + for (int i = 0; i < VECT_LENGTH; i++) { + out[i*DIM] = in[i*DIM] * c0; + out[i*DIM + 1] = in[i*DIM + 1] * c1; + } + } + + public static void vect2DAddShort( + short[] out, + short[] in, + short[] c) { + short c0 = c[0]; + short c1 = c[1]; + for (int i = 0; i < VECT_LENGTH; i++) { + out[i*DIM] = (short)(in[i*DIM] + c0); + out[i*DIM + 1] = (short)(in[i*DIM + 1] + c1); + } + } + + public static void vect2DMulShort( + short[] out, + short[] in, + short[] c) { + short c0 = c[0]; + short c1 = c[1]; + for (int i = 0; i < VECT_LENGTH; i++) { + out[i*DIM] = (short)(in[i*DIM] * c0); + out[i*DIM + 1] = (short)(in[i*DIM + 1] * c1); + } + } + + @Setup + public void setup() + { + vect2DInit(); + } + + @Benchmark + public void testVect2D() { + vect2DAddInt(out, in, c); + vect2DMulInt(out, in, c); + vect2DAddShort(sout, sin, sc); + vect2DMulShort(sout, sin, sc); + } + +} diff --git a/src/main/java/org/linaro/benchmarks/TestSIMDLd3St3.java b/src/main/java/org/linaro/benchmarks/TestSIMDLd3St3.java new file mode 100644 index 0000000..a691957 --- /dev/null +++ b/src/main/java/org/linaro/benchmarks/TestSIMDLd3St3.java @@ -0,0 +1,103 @@ +package org.linaro.benchmarks; + +import org.openjdk.jmh.annotations.*; +import java.util.concurrent.TimeUnit; + +@BenchmarkMode(Mode.AverageTime) +@OutputTimeUnit(TimeUnit.MICROSECONDS) +@State(Scope.Benchmark) + +public class TestSIMDLd3St3 { + static final int VECT_LENGTH = 256 * 1024; + static final int DIM = 3; + static final int LENGTH = VECT_LENGTH * DIM; + static int [] in = new int[LENGTH]; + static int [] out = new int[LENGTH]; + static int [] c = new int[DIM]; + static short [] sin = new short[LENGTH]; + static short [] sout = new short[LENGTH]; + static short [] sc = new short[DIM]; + + public static void vect3DInit() { + int i; + for (i = 0; i < LENGTH; i++) { + in[i] = i + 3; + sin[i] = (short)(i + 3); + } + for (i = 0; i < DIM; i++) { + c[i] = i + 1; + sc[i] = (short)(i + 1); + } + } + + public static void vect3DAddInt( + int[] out, + int[] in, + int[] c) { + int c0 = c[0]; + int c1 = c[1]; + int c2 = c[2]; + for (int i = 0; i < VECT_LENGTH; i++) { + out[i*DIM] = in[i*DIM] + c0; + out[i*DIM + 1] = in[i*DIM + 1] + c1; + out[i*DIM + 2] = in[i*DIM + 2] + c2; + } + } + + public static void vect3DMulInt( + int[] out, + int[] in, + int[] c) { + int c0 = c[0]; + int c1 = c[1]; + int c2 = c[2]; + for (int i = 0; i < VECT_LENGTH; i++) { + out[i*DIM] = in[i*DIM] * c0; + out[i*DIM + 1] = in[i*DIM + 1] * c1; + out[i*DIM + 2] = in[i*DIM + 2] * c2; + } + } + + public static void vect3DAddShort( + short[] out, + short[] in, + short[] c) { + short c0 = c[0]; + short c1 = c[1]; + short c2 = c[2]; + for (int i = 0; i < VECT_LENGTH; i++) { + out[i*DIM] = (short)(in[i*DIM] + c0); + out[i*DIM + 1] = (short)(in[i*DIM + 1] + c1); + out[i*DIM + 2] = (short)(in[i*DIM + 2] + c2); + } + } + + public static void vect3DMulShort( + short[] out, + short[] in, + short[] c) { + short c0 = c[0]; + short c1 = c[1]; + short c2 = c[2]; + for (int i = 0; i < VECT_LENGTH; i++) { + out[i*DIM] = (short)(in[i*DIM] * c0); + out[i*DIM + 1] = (short)(in[i*DIM + 1] * c1); + out[i*DIM + 2] = (short)(in[i*DIM + 2] * c2); + } + } + + @Setup + public void setup() + { + vect3DInit(); + } + + @Benchmark + public void testVect3D() { + vect3DAddInt(out, in, c); + vect3DMulInt(out, in, c); + vect3DAddShort(sout, sin, sc); + vect3DMulShort(sout, sin, sc); + } + +} diff --git a/src/main/java/org/linaro/benchmarks/TestSIMDLd4St4.java b/src/main/java/org/linaro/benchmarks/TestSIMDLd4St4.java new file mode 100644 index 0000000..fea4808 --- /dev/null +++ b/src/main/java/org/linaro/benchmarks/TestSIMDLd4St4.java @@ -0,0 +1,111 @@ +package org.linaro.benchmarks; + +import org.openjdk.jmh.annotations.*; +import java.util.concurrent.TimeUnit; + +@BenchmarkMode(Mode.AverageTime) +@OutputTimeUnit(TimeUnit.MICROSECONDS) +@State(Scope.Benchmark) + +public class TestSIMDLd4St4 { + static final int VECT_LENGTH = 256 * 1024; + static final int DIM = 4; + static final int LENGTH = VECT_LENGTH * DIM; + static int [] in = new int[LENGTH]; + static int [] out = new int[LENGTH]; + static int [] c = new int[DIM]; + static short [] sin = new short[LENGTH]; + static short [] sout = new short[LENGTH]; + static short [] sc = new short[DIM]; + + public static void vect4DInit() { + int i; + for (i = 0; i < LENGTH; i++) { + in[i] = i + 3; + sin[i] = (short)(i + 3); + } + for (i = 0; i < DIM; i++) { + c[i] = i + 1; + sc[i] = (short)(i + 1); + } + } + + public static void vect4DAddInt( + int[] out, + int[] in, + int[] c) { + int c0 = c[0]; + int c1 = c[1]; + int c2 = c[2]; + int c3 = c[3]; + for (int i = 0; i < VECT_LENGTH; i++) { + out[i*DIM] = in[i*DIM] + c0; + out[i*DIM + 1] = in[i*DIM + 1] + c1; + out[i*DIM + 2] = in[i*DIM + 2] + c2; + out[i*DIM + 3] = in[i*DIM + 3] + c3; + } + } + + public static void vect4DMulInt( + int[] out, + int[] in, + int[] c) { + int c0 = c[0]; + int c1 = c[1]; + int c2 = c[2]; + int c3 = c[3]; + for (int i = 0; i < VECT_LENGTH; i++) { + out[i*DIM] = in[i*DIM] * c0; + out[i*DIM + 1] = in[i*DIM + 1] * c1; + out[i*DIM + 2] = in[i*DIM + 2] * c2; + out[i*DIM + 3] = in[i*DIM + 3] * c3; + } + } + + public static void vect4DAddShort( + short[] out, + short[] in, + short[] c) { + short c0 = c[0]; + short c1 = c[1]; + short c2 = c[2]; + short c3 = c[3]; + for (int i = 0; i < VECT_LENGTH; i++) { + out[i*DIM] = (short)(in[i*DIM] + c0); + out[i*DIM + 1] = (short)(in[i*DIM + 1] + c1); + out[i*DIM + 2] = (short)(in[i*DIM + 2] + c2); + out[i*DIM + 3] = (short)(in[i*DIM + 3] + c3); + } + } + + public static void vect4DMulShort( + short[] out, + short[] in, + short[] c) { + short c0 = c[0]; + short c1 = c[1]; + short c2 = c[2]; + short c3 = c[3]; + for (int i = 0; i < VECT_LENGTH; i++) { + out[i*DIM] = (short)(in[i*DIM] * c0); + out[i*DIM + 1] = (short)(in[i*DIM + 1] * c1); + out[i*DIM + 2] = (short)(in[i*DIM + 2] * c2); + out[i*DIM + 3] = (short)(in[i*DIM + 3] * c3); + } + } + + @Setup + public void setup() + { + vect4DInit(); + } + + @Benchmark + public void testVect4D() { + vect4DAddInt(out, in, c); + vect4DMulInt(out, in, c); + vect4DAddShort(sout, sin, sc); + vect4DMulShort(sout, sin, sc); + } + +} |