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 29 /** 30 * Unit test that simulates the Mandelbrot application. The run method here is a static method 31 * version of the original mandel kernel and the invoke parameters are for the starting point of the 32 * mandel demo. Note: this will likely not pass the junit test on real hardware, but should pass on 33 * the simulator. 34 */ 35 public class StaticMandelTest extends GraalKernelTester { 36 37 static final int initWidth = 768; 38 static final int initHeight = initWidth; 39 static final int maxIterations = 64; 40 static final int range = initWidth * initHeight; 41 @Result private int[] rgb = new int[range]; 42 43 public static void run(int[] rgb, int[] pallette, float xoffset, float yoffset, float scale, int gid) { 44 final int width = initWidth; 45 final int height = initHeight; 46 float lx = (((gid % width * scale) - ((scale / 2) * width)) / width) + xoffset; 47 float ly = (((gid / width * scale) - ((scale / 2) * height)) / height) + yoffset; 48 int count = 0; 49 float zx = lx; 50 float zy = ly; 51 float newzx = 0f; 52 53 // Iterate until the algorithm converges or until maxIterations are reached. 54 while (count < maxIterations && zx * zx + zy * zy < 8) { 55 newzx = zx * zx - zy * zy + lx; 56 zy = 2 * zx * zy + ly; 57 zx = newzx; 58 count++; 59 } 60 rgb[gid] = pallette[count]; 61 } 62 63 void setupPalette(int[] in) { 64 for (int i = 0; i < in.length; i++) { 65 in[i] = i; 66 } 67 } 68 69 @Override 70 public void runTest() { 71 int[] palette = new int[256]; 72 setupPalette(palette); 73 /** 74 * Call it for a range, specifying testmethod args (but not the fields it uses or the gid 75 * argument). 76 */ 77 dispatchMethodKernel(range, rgb, palette, -1f, 0f, 3f); 78 } 79 80 @Test 81 public void test() { 82 testGeneratedHsail(); 83 } 84 }