1 /* 2 * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package com.oracle.graal.compiler.hsail.test; 25 26 import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; 27 import org.junit.Test; 28 import static org.junit.Assume.*; 29 30 /** 31 * Unit test that simulates the Mandelbrot application. The run method here is a static method 32 * version of the original mandel kernel and the invoke parameters are for the starting point of the 33 * mandel demo. Note: this will likely not pass the junit test on real hardware, but should pass on 34 * the simulator. 35 */ 36 public class StaticMandelTest extends GraalKernelTester { 37 38 static final int initWidth = 768; 39 static final int initHeight = initWidth; 40 static final int maxIterations = 64; 41 static final int range = initWidth * initHeight; 42 @Result private int[] rgb = new int[range]; 43 44 public static void run(int[] rgb, int[] pallette, float xoffset, float yoffset, float scale, int gid) { 45 final int width = initWidth; 46 final int height = initHeight; 47 float lx = (((gid % width * scale) - ((scale / 2) * width)) / width) + xoffset; 48 float ly = (((gid / width * scale) - ((scale / 2) * height)) / height) + yoffset; 49 int count = 0; 50 float zx = lx; 51 float zy = ly; 52 float newzx = 0f; 53 54 // Iterate until the algorithm converges or until maxIterations are reached. 55 while (count < maxIterations && zx * zx + zy * zy < 8) { 56 newzx = zx * zx - zy * zy + lx; 57 zy = 2 * zx * zy + ly; 58 zx = newzx; 59 count++; 60 } 61 rgb[gid] = pallette[count]; 62 } 63 64 void setupPalette(int[] in) { 65 for (int i = 0; i < in.length; i++) { 66 in[i] = i; 67 } 68 } 69 70 @Override 71 public void runTest() { 72 int[] palette = new int[256]; 73 setupPalette(palette); 74 /** 75 * Call it for a range, specifying testmethod args (but not the fields it uses or the gid 76 * argument). 77 */ 78 dispatchMethodKernel(range, rgb, palette, -1f, 0f, 3f); 79 } 80 81 @Test 82 public void test() { 83 assumeTrue(runningOnSimulator()); 84 testGeneratedHsail(); 85 } 86 } --- EOF ---