1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 // Don't edit this file! It is auto-generated by frameworks/rs/api/gen_runtime. 18 19 package android.renderscript.cts; 20 21 import android.renderscript.Allocation; 22 import android.renderscript.RSRuntimeException; 23 import android.renderscript.Element; 24 25 public class TestMad extends RSBaseCompute { 26 27 private ScriptC_TestMad script; 28 private ScriptC_TestMadRelaxed scriptRelaxed; 29 30 @Override 31 protected void setUp() throws Exception { 32 super.setUp(); 33 script = new ScriptC_TestMad(mRS); 34 scriptRelaxed = new ScriptC_TestMadRelaxed(mRS); 35 } 36 37 public class ArgumentsFloatFloatFloatFloat { 38 public float inA; 39 public float inB; 40 public float inC; 41 public Target.Floaty out; 42 } 43 44 private void checkMadFloatFloatFloatFloat() { 45 Allocation inA = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xb3b9b8429c37eacl, false); 46 Allocation inB = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xb3b9b8429c37eadl, false); 47 Allocation inC = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xb3b9b8429c37eael, false); 48 try { 49 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 50 script.set_gAllocInB(inB); 51 script.set_gAllocInC(inC); 52 script.forEach_testMadFloatFloatFloatFloat(inA, out); 53 verifyResultsMadFloatFloatFloatFloat(inA, inB, inC, out, false); 54 } catch (Exception e) { 55 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMadFloatFloatFloatFloat: " + e.toString()); 56 } 57 try { 58 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 59 scriptRelaxed.set_gAllocInB(inB); 60 scriptRelaxed.set_gAllocInC(inC); 61 scriptRelaxed.forEach_testMadFloatFloatFloatFloat(inA, out); 62 verifyResultsMadFloatFloatFloatFloat(inA, inB, inC, out, true); 63 } catch (Exception e) { 64 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMadFloatFloatFloatFloat: " + e.toString()); 65 } 66 } 67 68 private void verifyResultsMadFloatFloatFloatFloat(Allocation inA, Allocation inB, Allocation inC, Allocation out, boolean relaxed) { 69 float[] arrayInA = new float[INPUTSIZE * 1]; 70 inA.copyTo(arrayInA); 71 float[] arrayInB = new float[INPUTSIZE * 1]; 72 inB.copyTo(arrayInB); 73 float[] arrayInC = new float[INPUTSIZE * 1]; 74 inC.copyTo(arrayInC); 75 float[] arrayOut = new float[INPUTSIZE * 1]; 76 out.copyTo(arrayOut); 77 for (int i = 0; i < INPUTSIZE; i++) { 78 for (int j = 0; j < 1 ; j++) { 79 // Extract the inputs. 80 ArgumentsFloatFloatFloatFloat args = new ArgumentsFloatFloatFloatFloat(); 81 args.inA = arrayInA[i]; 82 args.inB = arrayInB[i]; 83 args.inC = arrayInC[i]; 84 // Figure out what the outputs should have been. 85 Target target = new Target(relaxed); 86 CoreMathVerifier.computeMad(args, target); 87 // Validate the outputs. 88 boolean valid = true; 89 if (!args.out.couldBe(arrayOut[i * 1 + j])) { 90 valid = false; 91 } 92 if (!valid) { 93 StringBuilder message = new StringBuilder(); 94 message.append("Input inA: "); 95 message.append(String.format("%14.8g {%8x} %15a", 96 args.inA, Float.floatToRawIntBits(args.inA), args.inA)); 97 message.append("\n"); 98 message.append("Input inB: "); 99 message.append(String.format("%14.8g {%8x} %15a", 100 args.inB, Float.floatToRawIntBits(args.inB), args.inB)); 101 message.append("\n"); 102 message.append("Input inC: "); 103 message.append(String.format("%14.8g {%8x} %15a", 104 args.inC, Float.floatToRawIntBits(args.inC), args.inC)); 105 message.append("\n"); 106 message.append("Expected output out: "); 107 message.append(args.out.toString()); 108 message.append("\n"); 109 message.append("Actual output out: "); 110 message.append(String.format("%14.8g {%8x} %15a", 111 arrayOut[i * 1 + j], Float.floatToRawIntBits(arrayOut[i * 1 + j]), arrayOut[i * 1 + j])); 112 if (!args.out.couldBe(arrayOut[i * 1 + j])) { 113 message.append(" FAIL"); 114 } 115 message.append("\n"); 116 assertTrue("Incorrect output for checkMadFloatFloatFloatFloat" + 117 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); 118 } 119 } 120 } 121 } 122 123 private void checkMadFloat2Float2Float2Float2() { 124 Allocation inA = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x44d6ec3d0f2030a4l, false); 125 Allocation inB = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x44d6ec3d0f2030a5l, false); 126 Allocation inC = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x44d6ec3d0f2030a6l, false); 127 try { 128 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 129 script.set_gAllocInB(inB); 130 script.set_gAllocInC(inC); 131 script.forEach_testMadFloat2Float2Float2Float2(inA, out); 132 verifyResultsMadFloat2Float2Float2Float2(inA, inB, inC, out, false); 133 } catch (Exception e) { 134 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMadFloat2Float2Float2Float2: " + e.toString()); 135 } 136 try { 137 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 138 scriptRelaxed.set_gAllocInB(inB); 139 scriptRelaxed.set_gAllocInC(inC); 140 scriptRelaxed.forEach_testMadFloat2Float2Float2Float2(inA, out); 141 verifyResultsMadFloat2Float2Float2Float2(inA, inB, inC, out, true); 142 } catch (Exception e) { 143 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMadFloat2Float2Float2Float2: " + e.toString()); 144 } 145 } 146 147 private void verifyResultsMadFloat2Float2Float2Float2(Allocation inA, Allocation inB, Allocation inC, Allocation out, boolean relaxed) { 148 float[] arrayInA = new float[INPUTSIZE * 2]; 149 inA.copyTo(arrayInA); 150 float[] arrayInB = new float[INPUTSIZE * 2]; 151 inB.copyTo(arrayInB); 152 float[] arrayInC = new float[INPUTSIZE * 2]; 153 inC.copyTo(arrayInC); 154 float[] arrayOut = new float[INPUTSIZE * 2]; 155 out.copyTo(arrayOut); 156 for (int i = 0; i < INPUTSIZE; i++) { 157 for (int j = 0; j < 2 ; j++) { 158 // Extract the inputs. 159 ArgumentsFloatFloatFloatFloat args = new ArgumentsFloatFloatFloatFloat(); 160 args.inA = arrayInA[i * 2 + j]; 161 args.inB = arrayInB[i * 2 + j]; 162 args.inC = arrayInC[i * 2 + j]; 163 // Figure out what the outputs should have been. 164 Target target = new Target(relaxed); 165 CoreMathVerifier.computeMad(args, target); 166 // Validate the outputs. 167 boolean valid = true; 168 if (!args.out.couldBe(arrayOut[i * 2 + j])) { 169 valid = false; 170 } 171 if (!valid) { 172 StringBuilder message = new StringBuilder(); 173 message.append("Input inA: "); 174 message.append(String.format("%14.8g {%8x} %15a", 175 args.inA, Float.floatToRawIntBits(args.inA), args.inA)); 176 message.append("\n"); 177 message.append("Input inB: "); 178 message.append(String.format("%14.8g {%8x} %15a", 179 args.inB, Float.floatToRawIntBits(args.inB), args.inB)); 180 message.append("\n"); 181 message.append("Input inC: "); 182 message.append(String.format("%14.8g {%8x} %15a", 183 args.inC, Float.floatToRawIntBits(args.inC), args.inC)); 184 message.append("\n"); 185 message.append("Expected output out: "); 186 message.append(args.out.toString()); 187 message.append("\n"); 188 message.append("Actual output out: "); 189 message.append(String.format("%14.8g {%8x} %15a", 190 arrayOut[i * 2 + j], Float.floatToRawIntBits(arrayOut[i * 2 + j]), arrayOut[i * 2 + j])); 191 if (!args.out.couldBe(arrayOut[i * 2 + j])) { 192 message.append(" FAIL"); 193 } 194 message.append("\n"); 195 assertTrue("Incorrect output for checkMadFloat2Float2Float2Float2" + 196 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); 197 } 198 } 199 } 200 } 201 202 private void checkMadFloat3Float3Float3Float3() { 203 Allocation inA = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x1a508fd7e1876a40l, false); 204 Allocation inB = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x1a508fd7e1876a41l, false); 205 Allocation inC = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x1a508fd7e1876a42l, false); 206 try { 207 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 208 script.set_gAllocInB(inB); 209 script.set_gAllocInC(inC); 210 script.forEach_testMadFloat3Float3Float3Float3(inA, out); 211 verifyResultsMadFloat3Float3Float3Float3(inA, inB, inC, out, false); 212 } catch (Exception e) { 213 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMadFloat3Float3Float3Float3: " + e.toString()); 214 } 215 try { 216 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 217 scriptRelaxed.set_gAllocInB(inB); 218 scriptRelaxed.set_gAllocInC(inC); 219 scriptRelaxed.forEach_testMadFloat3Float3Float3Float3(inA, out); 220 verifyResultsMadFloat3Float3Float3Float3(inA, inB, inC, out, true); 221 } catch (Exception e) { 222 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMadFloat3Float3Float3Float3: " + e.toString()); 223 } 224 } 225 226 private void verifyResultsMadFloat3Float3Float3Float3(Allocation inA, Allocation inB, Allocation inC, Allocation out, boolean relaxed) { 227 float[] arrayInA = new float[INPUTSIZE * 4]; 228 inA.copyTo(arrayInA); 229 float[] arrayInB = new float[INPUTSIZE * 4]; 230 inB.copyTo(arrayInB); 231 float[] arrayInC = new float[INPUTSIZE * 4]; 232 inC.copyTo(arrayInC); 233 float[] arrayOut = new float[INPUTSIZE * 4]; 234 out.copyTo(arrayOut); 235 for (int i = 0; i < INPUTSIZE; i++) { 236 for (int j = 0; j < 3 ; j++) { 237 // Extract the inputs. 238 ArgumentsFloatFloatFloatFloat args = new ArgumentsFloatFloatFloatFloat(); 239 args.inA = arrayInA[i * 4 + j]; 240 args.inB = arrayInB[i * 4 + j]; 241 args.inC = arrayInC[i * 4 + j]; 242 // Figure out what the outputs should have been. 243 Target target = new Target(relaxed); 244 CoreMathVerifier.computeMad(args, target); 245 // Validate the outputs. 246 boolean valid = true; 247 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 248 valid = false; 249 } 250 if (!valid) { 251 StringBuilder message = new StringBuilder(); 252 message.append("Input inA: "); 253 message.append(String.format("%14.8g {%8x} %15a", 254 args.inA, Float.floatToRawIntBits(args.inA), args.inA)); 255 message.append("\n"); 256 message.append("Input inB: "); 257 message.append(String.format("%14.8g {%8x} %15a", 258 args.inB, Float.floatToRawIntBits(args.inB), args.inB)); 259 message.append("\n"); 260 message.append("Input inC: "); 261 message.append(String.format("%14.8g {%8x} %15a", 262 args.inC, Float.floatToRawIntBits(args.inC), args.inC)); 263 message.append("\n"); 264 message.append("Expected output out: "); 265 message.append(args.out.toString()); 266 message.append("\n"); 267 message.append("Actual output out: "); 268 message.append(String.format("%14.8g {%8x} %15a", 269 arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j])); 270 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 271 message.append(" FAIL"); 272 } 273 message.append("\n"); 274 assertTrue("Incorrect output for checkMadFloat3Float3Float3Float3" + 275 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); 276 } 277 } 278 } 279 } 280 281 private void checkMadFloat4Float4Float4Float4() { 282 Allocation inA = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xefca3372b3eea3dcl, false); 283 Allocation inB = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xefca3372b3eea3ddl, false); 284 Allocation inC = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xefca3372b3eea3del, false); 285 try { 286 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 287 script.set_gAllocInB(inB); 288 script.set_gAllocInC(inC); 289 script.forEach_testMadFloat4Float4Float4Float4(inA, out); 290 verifyResultsMadFloat4Float4Float4Float4(inA, inB, inC, out, false); 291 } catch (Exception e) { 292 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMadFloat4Float4Float4Float4: " + e.toString()); 293 } 294 try { 295 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 296 scriptRelaxed.set_gAllocInB(inB); 297 scriptRelaxed.set_gAllocInC(inC); 298 scriptRelaxed.forEach_testMadFloat4Float4Float4Float4(inA, out); 299 verifyResultsMadFloat4Float4Float4Float4(inA, inB, inC, out, true); 300 } catch (Exception e) { 301 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMadFloat4Float4Float4Float4: " + e.toString()); 302 } 303 } 304 305 private void verifyResultsMadFloat4Float4Float4Float4(Allocation inA, Allocation inB, Allocation inC, Allocation out, boolean relaxed) { 306 float[] arrayInA = new float[INPUTSIZE * 4]; 307 inA.copyTo(arrayInA); 308 float[] arrayInB = new float[INPUTSIZE * 4]; 309 inB.copyTo(arrayInB); 310 float[] arrayInC = new float[INPUTSIZE * 4]; 311 inC.copyTo(arrayInC); 312 float[] arrayOut = new float[INPUTSIZE * 4]; 313 out.copyTo(arrayOut); 314 for (int i = 0; i < INPUTSIZE; i++) { 315 for (int j = 0; j < 4 ; j++) { 316 // Extract the inputs. 317 ArgumentsFloatFloatFloatFloat args = new ArgumentsFloatFloatFloatFloat(); 318 args.inA = arrayInA[i * 4 + j]; 319 args.inB = arrayInB[i * 4 + j]; 320 args.inC = arrayInC[i * 4 + j]; 321 // Figure out what the outputs should have been. 322 Target target = new Target(relaxed); 323 CoreMathVerifier.computeMad(args, target); 324 // Validate the outputs. 325 boolean valid = true; 326 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 327 valid = false; 328 } 329 if (!valid) { 330 StringBuilder message = new StringBuilder(); 331 message.append("Input inA: "); 332 message.append(String.format("%14.8g {%8x} %15a", 333 args.inA, Float.floatToRawIntBits(args.inA), args.inA)); 334 message.append("\n"); 335 message.append("Input inB: "); 336 message.append(String.format("%14.8g {%8x} %15a", 337 args.inB, Float.floatToRawIntBits(args.inB), args.inB)); 338 message.append("\n"); 339 message.append("Input inC: "); 340 message.append(String.format("%14.8g {%8x} %15a", 341 args.inC, Float.floatToRawIntBits(args.inC), args.inC)); 342 message.append("\n"); 343 message.append("Expected output out: "); 344 message.append(args.out.toString()); 345 message.append("\n"); 346 message.append("Actual output out: "); 347 message.append(String.format("%14.8g {%8x} %15a", 348 arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j])); 349 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 350 message.append(" FAIL"); 351 } 352 message.append("\n"); 353 assertTrue("Incorrect output for checkMadFloat4Float4Float4Float4" + 354 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); 355 } 356 } 357 } 358 } 359 360 public void testMad() { 361 checkMadFloatFloatFloatFloat(); 362 checkMadFloat2Float2Float2Float2(); 363 checkMadFloat3Float3Float3Float3(); 364 checkMadFloat4Float4Float4Float4(); 365 } 366 } 367