1 /* 2 * Copyright (C) 2016 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/generate.sh. 18 19 package android.renderscript.cts; 20 21 import android.renderscript.Allocation; 22 import android.renderscript.RSRuntimeException; 23 import android.renderscript.Element; 24 import android.renderscript.cts.Target; 25 26 import java.util.Arrays; 27 28 public class TestFmax extends RSBaseCompute { 29 30 private ScriptC_TestFmax script; 31 private ScriptC_TestFmaxRelaxed scriptRelaxed; 32 33 @Override setUp()34 protected void setUp() throws Exception { 35 super.setUp(); 36 script = new ScriptC_TestFmax(mRS); 37 scriptRelaxed = new ScriptC_TestFmaxRelaxed(mRS); 38 } 39 40 @Override tearDown()41 protected void tearDown() throws Exception { 42 script.destroy(); 43 scriptRelaxed.destroy(); 44 super.tearDown(); 45 } 46 47 public class ArgumentsFloatFloatFloat { 48 public float inA; 49 public float inB; 50 public Target.Floaty out; 51 } 52 checkFmaxFloatFloatFloat()53 private void checkFmaxFloatFloatFloat() { 54 Allocation inA = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xe6ec75a46e6fdd7al, false); 55 Allocation inB = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xe6ec75a46e6fdd7bl, false); 56 try { 57 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 58 script.set_gAllocInB(inB); 59 script.forEach_testFmaxFloatFloatFloat(inA, out); 60 verifyResultsFmaxFloatFloatFloat(inA, inB, out, false); 61 out.destroy(); 62 } catch (Exception e) { 63 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFmaxFloatFloatFloat: " + e.toString()); 64 } 65 try { 66 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 67 scriptRelaxed.set_gAllocInB(inB); 68 scriptRelaxed.forEach_testFmaxFloatFloatFloat(inA, out); 69 verifyResultsFmaxFloatFloatFloat(inA, inB, out, true); 70 out.destroy(); 71 } catch (Exception e) { 72 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFmaxFloatFloatFloat: " + e.toString()); 73 } 74 inA.destroy(); 75 inB.destroy(); 76 } 77 verifyResultsFmaxFloatFloatFloat(Allocation inA, Allocation inB, Allocation out, boolean relaxed)78 private void verifyResultsFmaxFloatFloatFloat(Allocation inA, Allocation inB, Allocation out, boolean relaxed) { 79 float[] arrayInA = new float[INPUTSIZE * 1]; 80 Arrays.fill(arrayInA, (float) 42); 81 inA.copyTo(arrayInA); 82 float[] arrayInB = new float[INPUTSIZE * 1]; 83 Arrays.fill(arrayInB, (float) 42); 84 inB.copyTo(arrayInB); 85 float[] arrayOut = new float[INPUTSIZE * 1]; 86 Arrays.fill(arrayOut, (float) 42); 87 out.copyTo(arrayOut); 88 StringBuilder message = new StringBuilder(); 89 boolean errorFound = false; 90 for (int i = 0; i < INPUTSIZE; i++) { 91 for (int j = 0; j < 1 ; j++) { 92 // Extract the inputs. 93 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); 94 args.inA = arrayInA[i]; 95 args.inB = arrayInB[i]; 96 // Figure out what the outputs should have been. 97 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 98 CoreMathVerifier.computeFmax(args, target); 99 // Validate the outputs. 100 boolean valid = true; 101 if (!args.out.couldBe(arrayOut[i * 1 + j])) { 102 valid = false; 103 } 104 if (!valid) { 105 if (!errorFound) { 106 errorFound = true; 107 message.append("Input inA: "); 108 appendVariableToMessage(message, args.inA); 109 message.append("\n"); 110 message.append("Input inB: "); 111 appendVariableToMessage(message, args.inB); 112 message.append("\n"); 113 message.append("Expected output out: "); 114 appendVariableToMessage(message, args.out); 115 message.append("\n"); 116 message.append("Actual output out: "); 117 appendVariableToMessage(message, arrayOut[i * 1 + j]); 118 if (!args.out.couldBe(arrayOut[i * 1 + j])) { 119 message.append(" FAIL"); 120 } 121 message.append("\n"); 122 message.append("Errors at"); 123 } 124 message.append(" ["); 125 message.append(Integer.toString(i)); 126 message.append(", "); 127 message.append(Integer.toString(j)); 128 message.append("]"); 129 } 130 } 131 } 132 assertFalse("Incorrect output for checkFmaxFloatFloatFloat" + 133 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 134 } 135 checkFmaxFloat2Float2Float2()136 private void checkFmaxFloat2Float2Float2() { 137 Allocation inA = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xa99eaa6dd458a0c8l, false); 138 Allocation inB = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xa99eaa6dd458a0c9l, false); 139 try { 140 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 141 script.set_gAllocInB(inB); 142 script.forEach_testFmaxFloat2Float2Float2(inA, out); 143 verifyResultsFmaxFloat2Float2Float2(inA, inB, out, false); 144 out.destroy(); 145 } catch (Exception e) { 146 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFmaxFloat2Float2Float2: " + e.toString()); 147 } 148 try { 149 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 150 scriptRelaxed.set_gAllocInB(inB); 151 scriptRelaxed.forEach_testFmaxFloat2Float2Float2(inA, out); 152 verifyResultsFmaxFloat2Float2Float2(inA, inB, out, true); 153 out.destroy(); 154 } catch (Exception e) { 155 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFmaxFloat2Float2Float2: " + e.toString()); 156 } 157 inA.destroy(); 158 inB.destroy(); 159 } 160 verifyResultsFmaxFloat2Float2Float2(Allocation inA, Allocation inB, Allocation out, boolean relaxed)161 private void verifyResultsFmaxFloat2Float2Float2(Allocation inA, Allocation inB, Allocation out, boolean relaxed) { 162 float[] arrayInA = new float[INPUTSIZE * 2]; 163 Arrays.fill(arrayInA, (float) 42); 164 inA.copyTo(arrayInA); 165 float[] arrayInB = new float[INPUTSIZE * 2]; 166 Arrays.fill(arrayInB, (float) 42); 167 inB.copyTo(arrayInB); 168 float[] arrayOut = new float[INPUTSIZE * 2]; 169 Arrays.fill(arrayOut, (float) 42); 170 out.copyTo(arrayOut); 171 StringBuilder message = new StringBuilder(); 172 boolean errorFound = false; 173 for (int i = 0; i < INPUTSIZE; i++) { 174 for (int j = 0; j < 2 ; j++) { 175 // Extract the inputs. 176 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); 177 args.inA = arrayInA[i * 2 + j]; 178 args.inB = arrayInB[i * 2 + j]; 179 // Figure out what the outputs should have been. 180 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 181 CoreMathVerifier.computeFmax(args, target); 182 // Validate the outputs. 183 boolean valid = true; 184 if (!args.out.couldBe(arrayOut[i * 2 + j])) { 185 valid = false; 186 } 187 if (!valid) { 188 if (!errorFound) { 189 errorFound = true; 190 message.append("Input inA: "); 191 appendVariableToMessage(message, args.inA); 192 message.append("\n"); 193 message.append("Input inB: "); 194 appendVariableToMessage(message, args.inB); 195 message.append("\n"); 196 message.append("Expected output out: "); 197 appendVariableToMessage(message, args.out); 198 message.append("\n"); 199 message.append("Actual output out: "); 200 appendVariableToMessage(message, arrayOut[i * 2 + j]); 201 if (!args.out.couldBe(arrayOut[i * 2 + j])) { 202 message.append(" FAIL"); 203 } 204 message.append("\n"); 205 message.append("Errors at"); 206 } 207 message.append(" ["); 208 message.append(Integer.toString(i)); 209 message.append(", "); 210 message.append(Integer.toString(j)); 211 message.append("]"); 212 } 213 } 214 } 215 assertFalse("Incorrect output for checkFmaxFloat2Float2Float2" + 216 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 217 } 218 checkFmaxFloat3Float3Float3()219 private void checkFmaxFloat3Float3Float3() { 220 Allocation inA = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xfe03888dd636a269l, false); 221 Allocation inB = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xfe03888dd636a26al, false); 222 try { 223 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 224 script.set_gAllocInB(inB); 225 script.forEach_testFmaxFloat3Float3Float3(inA, out); 226 verifyResultsFmaxFloat3Float3Float3(inA, inB, out, false); 227 out.destroy(); 228 } catch (Exception e) { 229 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFmaxFloat3Float3Float3: " + e.toString()); 230 } 231 try { 232 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 233 scriptRelaxed.set_gAllocInB(inB); 234 scriptRelaxed.forEach_testFmaxFloat3Float3Float3(inA, out); 235 verifyResultsFmaxFloat3Float3Float3(inA, inB, out, true); 236 out.destroy(); 237 } catch (Exception e) { 238 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFmaxFloat3Float3Float3: " + e.toString()); 239 } 240 inA.destroy(); 241 inB.destroy(); 242 } 243 verifyResultsFmaxFloat3Float3Float3(Allocation inA, Allocation inB, Allocation out, boolean relaxed)244 private void verifyResultsFmaxFloat3Float3Float3(Allocation inA, Allocation inB, Allocation out, boolean relaxed) { 245 float[] arrayInA = new float[INPUTSIZE * 4]; 246 Arrays.fill(arrayInA, (float) 42); 247 inA.copyTo(arrayInA); 248 float[] arrayInB = new float[INPUTSIZE * 4]; 249 Arrays.fill(arrayInB, (float) 42); 250 inB.copyTo(arrayInB); 251 float[] arrayOut = new float[INPUTSIZE * 4]; 252 Arrays.fill(arrayOut, (float) 42); 253 out.copyTo(arrayOut); 254 StringBuilder message = new StringBuilder(); 255 boolean errorFound = false; 256 for (int i = 0; i < INPUTSIZE; i++) { 257 for (int j = 0; j < 3 ; j++) { 258 // Extract the inputs. 259 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); 260 args.inA = arrayInA[i * 4 + j]; 261 args.inB = arrayInB[i * 4 + j]; 262 // Figure out what the outputs should have been. 263 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 264 CoreMathVerifier.computeFmax(args, target); 265 // Validate the outputs. 266 boolean valid = true; 267 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 268 valid = false; 269 } 270 if (!valid) { 271 if (!errorFound) { 272 errorFound = true; 273 message.append("Input inA: "); 274 appendVariableToMessage(message, args.inA); 275 message.append("\n"); 276 message.append("Input inB: "); 277 appendVariableToMessage(message, args.inB); 278 message.append("\n"); 279 message.append("Expected output out: "); 280 appendVariableToMessage(message, args.out); 281 message.append("\n"); 282 message.append("Actual output out: "); 283 appendVariableToMessage(message, arrayOut[i * 4 + j]); 284 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 285 message.append(" FAIL"); 286 } 287 message.append("\n"); 288 message.append("Errors at"); 289 } 290 message.append(" ["); 291 message.append(Integer.toString(i)); 292 message.append(", "); 293 message.append(Integer.toString(j)); 294 message.append("]"); 295 } 296 } 297 } 298 assertFalse("Incorrect output for checkFmaxFloat3Float3Float3" + 299 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 300 } 301 checkFmaxFloat4Float4Float4()302 private void checkFmaxFloat4Float4Float4() { 303 Allocation inA = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x526866add814a40al, false); 304 Allocation inB = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x526866add814a40bl, false); 305 try { 306 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 307 script.set_gAllocInB(inB); 308 script.forEach_testFmaxFloat4Float4Float4(inA, out); 309 verifyResultsFmaxFloat4Float4Float4(inA, inB, out, false); 310 out.destroy(); 311 } catch (Exception e) { 312 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFmaxFloat4Float4Float4: " + e.toString()); 313 } 314 try { 315 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 316 scriptRelaxed.set_gAllocInB(inB); 317 scriptRelaxed.forEach_testFmaxFloat4Float4Float4(inA, out); 318 verifyResultsFmaxFloat4Float4Float4(inA, inB, out, true); 319 out.destroy(); 320 } catch (Exception e) { 321 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFmaxFloat4Float4Float4: " + e.toString()); 322 } 323 inA.destroy(); 324 inB.destroy(); 325 } 326 verifyResultsFmaxFloat4Float4Float4(Allocation inA, Allocation inB, Allocation out, boolean relaxed)327 private void verifyResultsFmaxFloat4Float4Float4(Allocation inA, Allocation inB, Allocation out, boolean relaxed) { 328 float[] arrayInA = new float[INPUTSIZE * 4]; 329 Arrays.fill(arrayInA, (float) 42); 330 inA.copyTo(arrayInA); 331 float[] arrayInB = new float[INPUTSIZE * 4]; 332 Arrays.fill(arrayInB, (float) 42); 333 inB.copyTo(arrayInB); 334 float[] arrayOut = new float[INPUTSIZE * 4]; 335 Arrays.fill(arrayOut, (float) 42); 336 out.copyTo(arrayOut); 337 StringBuilder message = new StringBuilder(); 338 boolean errorFound = false; 339 for (int i = 0; i < INPUTSIZE; i++) { 340 for (int j = 0; j < 4 ; j++) { 341 // Extract the inputs. 342 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); 343 args.inA = arrayInA[i * 4 + j]; 344 args.inB = arrayInB[i * 4 + j]; 345 // Figure out what the outputs should have been. 346 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 347 CoreMathVerifier.computeFmax(args, target); 348 // Validate the outputs. 349 boolean valid = true; 350 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 351 valid = false; 352 } 353 if (!valid) { 354 if (!errorFound) { 355 errorFound = true; 356 message.append("Input inA: "); 357 appendVariableToMessage(message, args.inA); 358 message.append("\n"); 359 message.append("Input inB: "); 360 appendVariableToMessage(message, args.inB); 361 message.append("\n"); 362 message.append("Expected output out: "); 363 appendVariableToMessage(message, args.out); 364 message.append("\n"); 365 message.append("Actual output out: "); 366 appendVariableToMessage(message, arrayOut[i * 4 + j]); 367 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 368 message.append(" FAIL"); 369 } 370 message.append("\n"); 371 message.append("Errors at"); 372 } 373 message.append(" ["); 374 message.append(Integer.toString(i)); 375 message.append(", "); 376 message.append(Integer.toString(j)); 377 message.append("]"); 378 } 379 } 380 } 381 assertFalse("Incorrect output for checkFmaxFloat4Float4Float4" + 382 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 383 } 384 385 public class ArgumentsHalfHalfHalf { 386 public short inA; 387 public double inADouble; 388 public short inB; 389 public double inBDouble; 390 public Target.Floaty out; 391 } 392 checkFmaxHalfHalfHalf()393 private void checkFmaxHalfHalfHalf() { 394 Allocation inA = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0x788f378e6dad4699l, false); 395 Allocation inB = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0x788f378e6dad469al, false); 396 try { 397 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE); 398 script.set_gAllocInB(inB); 399 script.forEach_testFmaxHalfHalfHalf(inA, out); 400 verifyResultsFmaxHalfHalfHalf(inA, inB, out, false); 401 out.destroy(); 402 } catch (Exception e) { 403 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFmaxHalfHalfHalf: " + e.toString()); 404 } 405 try { 406 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE); 407 scriptRelaxed.set_gAllocInB(inB); 408 scriptRelaxed.forEach_testFmaxHalfHalfHalf(inA, out); 409 verifyResultsFmaxHalfHalfHalf(inA, inB, out, true); 410 out.destroy(); 411 } catch (Exception e) { 412 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFmaxHalfHalfHalf: " + e.toString()); 413 } 414 inA.destroy(); 415 inB.destroy(); 416 } 417 verifyResultsFmaxHalfHalfHalf(Allocation inA, Allocation inB, Allocation out, boolean relaxed)418 private void verifyResultsFmaxHalfHalfHalf(Allocation inA, Allocation inB, Allocation out, boolean relaxed) { 419 short[] arrayInA = new short[INPUTSIZE * 1]; 420 Arrays.fill(arrayInA, (short) 42); 421 inA.copyTo(arrayInA); 422 short[] arrayInB = new short[INPUTSIZE * 1]; 423 Arrays.fill(arrayInB, (short) 42); 424 inB.copyTo(arrayInB); 425 short[] arrayOut = new short[INPUTSIZE * 1]; 426 Arrays.fill(arrayOut, (short) 42); 427 out.copyTo(arrayOut); 428 StringBuilder message = new StringBuilder(); 429 boolean errorFound = false; 430 for (int i = 0; i < INPUTSIZE; i++) { 431 for (int j = 0; j < 1 ; j++) { 432 // Extract the inputs. 433 ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf(); 434 args.inA = arrayInA[i]; 435 args.inADouble = Float16Utils.convertFloat16ToDouble(args.inA); 436 args.inB = arrayInB[i]; 437 args.inBDouble = Float16Utils.convertFloat16ToDouble(args.inB); 438 // Figure out what the outputs should have been. 439 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 440 CoreMathVerifier.computeFmax(args, target); 441 // Validate the outputs. 442 boolean valid = true; 443 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j]))) { 444 valid = false; 445 } 446 if (!valid) { 447 if (!errorFound) { 448 errorFound = true; 449 message.append("Input inA: "); 450 appendVariableToMessage(message, args.inA); 451 message.append("\n"); 452 message.append("Input inB: "); 453 appendVariableToMessage(message, args.inB); 454 message.append("\n"); 455 message.append("Expected output out: "); 456 appendVariableToMessage(message, args.out); 457 message.append("\n"); 458 message.append("Actual output out: "); 459 appendVariableToMessage(message, arrayOut[i * 1 + j]); 460 message.append("\n"); 461 message.append("Actual output out (in double): "); 462 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j])); 463 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j]))) { 464 message.append(" FAIL"); 465 } 466 message.append("\n"); 467 message.append("Errors at"); 468 } 469 message.append(" ["); 470 message.append(Integer.toString(i)); 471 message.append(", "); 472 message.append(Integer.toString(j)); 473 message.append("]"); 474 } 475 } 476 } 477 assertFalse("Incorrect output for checkFmaxHalfHalfHalf" + 478 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 479 } 480 checkFmaxHalf2Half2Half2()481 private void checkFmaxHalf2Half2Half2() { 482 Allocation inA = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 2, 0xb65cb7c1a556216fl, false); 483 Allocation inB = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 2, 0xb65cb7c1a5562170l, false); 484 try { 485 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE); 486 script.set_gAllocInB(inB); 487 script.forEach_testFmaxHalf2Half2Half2(inA, out); 488 verifyResultsFmaxHalf2Half2Half2(inA, inB, out, false); 489 out.destroy(); 490 } catch (Exception e) { 491 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFmaxHalf2Half2Half2: " + e.toString()); 492 } 493 try { 494 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE); 495 scriptRelaxed.set_gAllocInB(inB); 496 scriptRelaxed.forEach_testFmaxHalf2Half2Half2(inA, out); 497 verifyResultsFmaxHalf2Half2Half2(inA, inB, out, true); 498 out.destroy(); 499 } catch (Exception e) { 500 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFmaxHalf2Half2Half2: " + e.toString()); 501 } 502 inA.destroy(); 503 inB.destroy(); 504 } 505 verifyResultsFmaxHalf2Half2Half2(Allocation inA, Allocation inB, Allocation out, boolean relaxed)506 private void verifyResultsFmaxHalf2Half2Half2(Allocation inA, Allocation inB, Allocation out, boolean relaxed) { 507 short[] arrayInA = new short[INPUTSIZE * 2]; 508 Arrays.fill(arrayInA, (short) 42); 509 inA.copyTo(arrayInA); 510 short[] arrayInB = new short[INPUTSIZE * 2]; 511 Arrays.fill(arrayInB, (short) 42); 512 inB.copyTo(arrayInB); 513 short[] arrayOut = new short[INPUTSIZE * 2]; 514 Arrays.fill(arrayOut, (short) 42); 515 out.copyTo(arrayOut); 516 StringBuilder message = new StringBuilder(); 517 boolean errorFound = false; 518 for (int i = 0; i < INPUTSIZE; i++) { 519 for (int j = 0; j < 2 ; j++) { 520 // Extract the inputs. 521 ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf(); 522 args.inA = arrayInA[i * 2 + j]; 523 args.inADouble = Float16Utils.convertFloat16ToDouble(args.inA); 524 args.inB = arrayInB[i * 2 + j]; 525 args.inBDouble = Float16Utils.convertFloat16ToDouble(args.inB); 526 // Figure out what the outputs should have been. 527 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 528 CoreMathVerifier.computeFmax(args, target); 529 // Validate the outputs. 530 boolean valid = true; 531 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) { 532 valid = false; 533 } 534 if (!valid) { 535 if (!errorFound) { 536 errorFound = true; 537 message.append("Input inA: "); 538 appendVariableToMessage(message, args.inA); 539 message.append("\n"); 540 message.append("Input inB: "); 541 appendVariableToMessage(message, args.inB); 542 message.append("\n"); 543 message.append("Expected output out: "); 544 appendVariableToMessage(message, args.out); 545 message.append("\n"); 546 message.append("Actual output out: "); 547 appendVariableToMessage(message, arrayOut[i * 2 + j]); 548 message.append("\n"); 549 message.append("Actual output out (in double): "); 550 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j])); 551 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) { 552 message.append(" FAIL"); 553 } 554 message.append("\n"); 555 message.append("Errors at"); 556 } 557 message.append(" ["); 558 message.append(Integer.toString(i)); 559 message.append(", "); 560 message.append(Integer.toString(j)); 561 message.append("]"); 562 } 563 } 564 } 565 assertFalse("Incorrect output for checkFmaxHalf2Half2Half2" + 566 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 567 } 568 checkFmaxHalf3Half3Half3()569 private void checkFmaxHalf3Half3Half3() { 570 Allocation inA = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0xdc1137ab03f5323el, false); 571 Allocation inB = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0xdc1137ab03f5323fl, false); 572 try { 573 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE); 574 script.set_gAllocInB(inB); 575 script.forEach_testFmaxHalf3Half3Half3(inA, out); 576 verifyResultsFmaxHalf3Half3Half3(inA, inB, out, false); 577 out.destroy(); 578 } catch (Exception e) { 579 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFmaxHalf3Half3Half3: " + e.toString()); 580 } 581 try { 582 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE); 583 scriptRelaxed.set_gAllocInB(inB); 584 scriptRelaxed.forEach_testFmaxHalf3Half3Half3(inA, out); 585 verifyResultsFmaxHalf3Half3Half3(inA, inB, out, true); 586 out.destroy(); 587 } catch (Exception e) { 588 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFmaxHalf3Half3Half3: " + e.toString()); 589 } 590 inA.destroy(); 591 inB.destroy(); 592 } 593 verifyResultsFmaxHalf3Half3Half3(Allocation inA, Allocation inB, Allocation out, boolean relaxed)594 private void verifyResultsFmaxHalf3Half3Half3(Allocation inA, Allocation inB, Allocation out, boolean relaxed) { 595 short[] arrayInA = new short[INPUTSIZE * 4]; 596 Arrays.fill(arrayInA, (short) 42); 597 inA.copyTo(arrayInA); 598 short[] arrayInB = new short[INPUTSIZE * 4]; 599 Arrays.fill(arrayInB, (short) 42); 600 inB.copyTo(arrayInB); 601 short[] arrayOut = new short[INPUTSIZE * 4]; 602 Arrays.fill(arrayOut, (short) 42); 603 out.copyTo(arrayOut); 604 StringBuilder message = new StringBuilder(); 605 boolean errorFound = false; 606 for (int i = 0; i < INPUTSIZE; i++) { 607 for (int j = 0; j < 3 ; j++) { 608 // Extract the inputs. 609 ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf(); 610 args.inA = arrayInA[i * 4 + j]; 611 args.inADouble = Float16Utils.convertFloat16ToDouble(args.inA); 612 args.inB = arrayInB[i * 4 + j]; 613 args.inBDouble = Float16Utils.convertFloat16ToDouble(args.inB); 614 // Figure out what the outputs should have been. 615 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 616 CoreMathVerifier.computeFmax(args, target); 617 // Validate the outputs. 618 boolean valid = true; 619 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 620 valid = false; 621 } 622 if (!valid) { 623 if (!errorFound) { 624 errorFound = true; 625 message.append("Input inA: "); 626 appendVariableToMessage(message, args.inA); 627 message.append("\n"); 628 message.append("Input inB: "); 629 appendVariableToMessage(message, args.inB); 630 message.append("\n"); 631 message.append("Expected output out: "); 632 appendVariableToMessage(message, args.out); 633 message.append("\n"); 634 message.append("Actual output out: "); 635 appendVariableToMessage(message, arrayOut[i * 4 + j]); 636 message.append("\n"); 637 message.append("Actual output out (in double): "); 638 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j])); 639 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 640 message.append(" FAIL"); 641 } 642 message.append("\n"); 643 message.append("Errors at"); 644 } 645 message.append(" ["); 646 message.append(Integer.toString(i)); 647 message.append(", "); 648 message.append(Integer.toString(j)); 649 message.append("]"); 650 } 651 } 652 } 653 assertFalse("Incorrect output for checkFmaxHalf3Half3Half3" + 654 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 655 } 656 checkFmaxHalf4Half4Half4()657 private void checkFmaxHalf4Half4Half4() { 658 Allocation inA = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0x1c5b7946294430dl, false); 659 Allocation inB = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0x1c5b7946294430el, false); 660 try { 661 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE); 662 script.set_gAllocInB(inB); 663 script.forEach_testFmaxHalf4Half4Half4(inA, out); 664 verifyResultsFmaxHalf4Half4Half4(inA, inB, out, false); 665 out.destroy(); 666 } catch (Exception e) { 667 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFmaxHalf4Half4Half4: " + e.toString()); 668 } 669 try { 670 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE); 671 scriptRelaxed.set_gAllocInB(inB); 672 scriptRelaxed.forEach_testFmaxHalf4Half4Half4(inA, out); 673 verifyResultsFmaxHalf4Half4Half4(inA, inB, out, true); 674 out.destroy(); 675 } catch (Exception e) { 676 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFmaxHalf4Half4Half4: " + e.toString()); 677 } 678 inA.destroy(); 679 inB.destroy(); 680 } 681 verifyResultsFmaxHalf4Half4Half4(Allocation inA, Allocation inB, Allocation out, boolean relaxed)682 private void verifyResultsFmaxHalf4Half4Half4(Allocation inA, Allocation inB, Allocation out, boolean relaxed) { 683 short[] arrayInA = new short[INPUTSIZE * 4]; 684 Arrays.fill(arrayInA, (short) 42); 685 inA.copyTo(arrayInA); 686 short[] arrayInB = new short[INPUTSIZE * 4]; 687 Arrays.fill(arrayInB, (short) 42); 688 inB.copyTo(arrayInB); 689 short[] arrayOut = new short[INPUTSIZE * 4]; 690 Arrays.fill(arrayOut, (short) 42); 691 out.copyTo(arrayOut); 692 StringBuilder message = new StringBuilder(); 693 boolean errorFound = false; 694 for (int i = 0; i < INPUTSIZE; i++) { 695 for (int j = 0; j < 4 ; j++) { 696 // Extract the inputs. 697 ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf(); 698 args.inA = arrayInA[i * 4 + j]; 699 args.inADouble = Float16Utils.convertFloat16ToDouble(args.inA); 700 args.inB = arrayInB[i * 4 + j]; 701 args.inBDouble = Float16Utils.convertFloat16ToDouble(args.inB); 702 // Figure out what the outputs should have been. 703 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 704 CoreMathVerifier.computeFmax(args, target); 705 // Validate the outputs. 706 boolean valid = true; 707 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 708 valid = false; 709 } 710 if (!valid) { 711 if (!errorFound) { 712 errorFound = true; 713 message.append("Input inA: "); 714 appendVariableToMessage(message, args.inA); 715 message.append("\n"); 716 message.append("Input inB: "); 717 appendVariableToMessage(message, args.inB); 718 message.append("\n"); 719 message.append("Expected output out: "); 720 appendVariableToMessage(message, args.out); 721 message.append("\n"); 722 message.append("Actual output out: "); 723 appendVariableToMessage(message, arrayOut[i * 4 + j]); 724 message.append("\n"); 725 message.append("Actual output out (in double): "); 726 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j])); 727 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 728 message.append(" FAIL"); 729 } 730 message.append("\n"); 731 message.append("Errors at"); 732 } 733 message.append(" ["); 734 message.append(Integer.toString(i)); 735 message.append(", "); 736 message.append(Integer.toString(j)); 737 message.append("]"); 738 } 739 } 740 } 741 assertFalse("Incorrect output for checkFmaxHalf4Half4Half4" + 742 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 743 } 744 checkFmaxFloat2FloatFloat2()745 private void checkFmaxFloat2FloatFloat2() { 746 Allocation inA = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xce5ddc06dc631102l, false); 747 Allocation inB = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xce5ddc06dc631103l, false); 748 try { 749 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 750 script.set_gAllocInB(inB); 751 script.forEach_testFmaxFloat2FloatFloat2(inA, out); 752 verifyResultsFmaxFloat2FloatFloat2(inA, inB, out, false); 753 out.destroy(); 754 } catch (Exception e) { 755 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFmaxFloat2FloatFloat2: " + e.toString()); 756 } 757 try { 758 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 759 scriptRelaxed.set_gAllocInB(inB); 760 scriptRelaxed.forEach_testFmaxFloat2FloatFloat2(inA, out); 761 verifyResultsFmaxFloat2FloatFloat2(inA, inB, out, true); 762 out.destroy(); 763 } catch (Exception e) { 764 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFmaxFloat2FloatFloat2: " + e.toString()); 765 } 766 inA.destroy(); 767 inB.destroy(); 768 } 769 verifyResultsFmaxFloat2FloatFloat2(Allocation inA, Allocation inB, Allocation out, boolean relaxed)770 private void verifyResultsFmaxFloat2FloatFloat2(Allocation inA, Allocation inB, Allocation out, boolean relaxed) { 771 float[] arrayInA = new float[INPUTSIZE * 2]; 772 Arrays.fill(arrayInA, (float) 42); 773 inA.copyTo(arrayInA); 774 float[] arrayInB = new float[INPUTSIZE * 1]; 775 Arrays.fill(arrayInB, (float) 42); 776 inB.copyTo(arrayInB); 777 float[] arrayOut = new float[INPUTSIZE * 2]; 778 Arrays.fill(arrayOut, (float) 42); 779 out.copyTo(arrayOut); 780 StringBuilder message = new StringBuilder(); 781 boolean errorFound = false; 782 for (int i = 0; i < INPUTSIZE; i++) { 783 for (int j = 0; j < 2 ; j++) { 784 // Extract the inputs. 785 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); 786 args.inA = arrayInA[i * 2 + j]; 787 args.inB = arrayInB[i]; 788 // Figure out what the outputs should have been. 789 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 790 CoreMathVerifier.computeFmax(args, target); 791 // Validate the outputs. 792 boolean valid = true; 793 if (!args.out.couldBe(arrayOut[i * 2 + j])) { 794 valid = false; 795 } 796 if (!valid) { 797 if (!errorFound) { 798 errorFound = true; 799 message.append("Input inA: "); 800 appendVariableToMessage(message, args.inA); 801 message.append("\n"); 802 message.append("Input inB: "); 803 appendVariableToMessage(message, args.inB); 804 message.append("\n"); 805 message.append("Expected output out: "); 806 appendVariableToMessage(message, args.out); 807 message.append("\n"); 808 message.append("Actual output out: "); 809 appendVariableToMessage(message, arrayOut[i * 2 + j]); 810 if (!args.out.couldBe(arrayOut[i * 2 + j])) { 811 message.append(" FAIL"); 812 } 813 message.append("\n"); 814 message.append("Errors at"); 815 } 816 message.append(" ["); 817 message.append(Integer.toString(i)); 818 message.append(", "); 819 message.append(Integer.toString(j)); 820 message.append("]"); 821 } 822 } 823 } 824 assertFalse("Incorrect output for checkFmaxFloat2FloatFloat2" + 825 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 826 } 827 checkFmaxFloat3FloatFloat3()828 private void checkFmaxFloat3FloatFloat3() { 829 Allocation inA = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x23ad8f1ecace055el, false); 830 Allocation inB = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x23ad8f1ecace055fl, false); 831 try { 832 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 833 script.set_gAllocInB(inB); 834 script.forEach_testFmaxFloat3FloatFloat3(inA, out); 835 verifyResultsFmaxFloat3FloatFloat3(inA, inB, out, false); 836 out.destroy(); 837 } catch (Exception e) { 838 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFmaxFloat3FloatFloat3: " + e.toString()); 839 } 840 try { 841 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 842 scriptRelaxed.set_gAllocInB(inB); 843 scriptRelaxed.forEach_testFmaxFloat3FloatFloat3(inA, out); 844 verifyResultsFmaxFloat3FloatFloat3(inA, inB, out, true); 845 out.destroy(); 846 } catch (Exception e) { 847 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFmaxFloat3FloatFloat3: " + e.toString()); 848 } 849 inA.destroy(); 850 inB.destroy(); 851 } 852 verifyResultsFmaxFloat3FloatFloat3(Allocation inA, Allocation inB, Allocation out, boolean relaxed)853 private void verifyResultsFmaxFloat3FloatFloat3(Allocation inA, Allocation inB, Allocation out, boolean relaxed) { 854 float[] arrayInA = new float[INPUTSIZE * 4]; 855 Arrays.fill(arrayInA, (float) 42); 856 inA.copyTo(arrayInA); 857 float[] arrayInB = new float[INPUTSIZE * 1]; 858 Arrays.fill(arrayInB, (float) 42); 859 inB.copyTo(arrayInB); 860 float[] arrayOut = new float[INPUTSIZE * 4]; 861 Arrays.fill(arrayOut, (float) 42); 862 out.copyTo(arrayOut); 863 StringBuilder message = new StringBuilder(); 864 boolean errorFound = false; 865 for (int i = 0; i < INPUTSIZE; i++) { 866 for (int j = 0; j < 3 ; j++) { 867 // Extract the inputs. 868 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); 869 args.inA = arrayInA[i * 4 + j]; 870 args.inB = arrayInB[i]; 871 // Figure out what the outputs should have been. 872 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 873 CoreMathVerifier.computeFmax(args, target); 874 // Validate the outputs. 875 boolean valid = true; 876 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 877 valid = false; 878 } 879 if (!valid) { 880 if (!errorFound) { 881 errorFound = true; 882 message.append("Input inA: "); 883 appendVariableToMessage(message, args.inA); 884 message.append("\n"); 885 message.append("Input inB: "); 886 appendVariableToMessage(message, args.inB); 887 message.append("\n"); 888 message.append("Expected output out: "); 889 appendVariableToMessage(message, args.out); 890 message.append("\n"); 891 message.append("Actual output out: "); 892 appendVariableToMessage(message, arrayOut[i * 4 + j]); 893 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 894 message.append(" FAIL"); 895 } 896 message.append("\n"); 897 message.append("Errors at"); 898 } 899 message.append(" ["); 900 message.append(Integer.toString(i)); 901 message.append(", "); 902 message.append(Integer.toString(j)); 903 message.append("]"); 904 } 905 } 906 } 907 assertFalse("Incorrect output for checkFmaxFloat3FloatFloat3" + 908 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 909 } 910 checkFmaxFloat4FloatFloat4()911 private void checkFmaxFloat4FloatFloat4() { 912 Allocation inA = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x78fd4236b938f9bal, false); 913 Allocation inB = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x78fd4236b938f9bbl, false); 914 try { 915 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 916 script.set_gAllocInB(inB); 917 script.forEach_testFmaxFloat4FloatFloat4(inA, out); 918 verifyResultsFmaxFloat4FloatFloat4(inA, inB, out, false); 919 out.destroy(); 920 } catch (Exception e) { 921 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFmaxFloat4FloatFloat4: " + e.toString()); 922 } 923 try { 924 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 925 scriptRelaxed.set_gAllocInB(inB); 926 scriptRelaxed.forEach_testFmaxFloat4FloatFloat4(inA, out); 927 verifyResultsFmaxFloat4FloatFloat4(inA, inB, out, true); 928 out.destroy(); 929 } catch (Exception e) { 930 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFmaxFloat4FloatFloat4: " + e.toString()); 931 } 932 inA.destroy(); 933 inB.destroy(); 934 } 935 verifyResultsFmaxFloat4FloatFloat4(Allocation inA, Allocation inB, Allocation out, boolean relaxed)936 private void verifyResultsFmaxFloat4FloatFloat4(Allocation inA, Allocation inB, Allocation out, boolean relaxed) { 937 float[] arrayInA = new float[INPUTSIZE * 4]; 938 Arrays.fill(arrayInA, (float) 42); 939 inA.copyTo(arrayInA); 940 float[] arrayInB = new float[INPUTSIZE * 1]; 941 Arrays.fill(arrayInB, (float) 42); 942 inB.copyTo(arrayInB); 943 float[] arrayOut = new float[INPUTSIZE * 4]; 944 Arrays.fill(arrayOut, (float) 42); 945 out.copyTo(arrayOut); 946 StringBuilder message = new StringBuilder(); 947 boolean errorFound = false; 948 for (int i = 0; i < INPUTSIZE; i++) { 949 for (int j = 0; j < 4 ; j++) { 950 // Extract the inputs. 951 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); 952 args.inA = arrayInA[i * 4 + j]; 953 args.inB = arrayInB[i]; 954 // Figure out what the outputs should have been. 955 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 956 CoreMathVerifier.computeFmax(args, target); 957 // Validate the outputs. 958 boolean valid = true; 959 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 960 valid = false; 961 } 962 if (!valid) { 963 if (!errorFound) { 964 errorFound = true; 965 message.append("Input inA: "); 966 appendVariableToMessage(message, args.inA); 967 message.append("\n"); 968 message.append("Input inB: "); 969 appendVariableToMessage(message, args.inB); 970 message.append("\n"); 971 message.append("Expected output out: "); 972 appendVariableToMessage(message, args.out); 973 message.append("\n"); 974 message.append("Actual output out: "); 975 appendVariableToMessage(message, arrayOut[i * 4 + j]); 976 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 977 message.append(" FAIL"); 978 } 979 message.append("\n"); 980 message.append("Errors at"); 981 } 982 message.append(" ["); 983 message.append(Integer.toString(i)); 984 message.append(", "); 985 message.append(Integer.toString(j)); 986 message.append("]"); 987 } 988 } 989 } 990 assertFalse("Incorrect output for checkFmaxFloat4FloatFloat4" + 991 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 992 } 993 checkFmaxHalf2HalfHalf2()994 private void checkFmaxHalf2HalfHalf2() { 995 Allocation inA = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 2, 0xd49cf7ff3546cdbdl, false); 996 Allocation inB = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0xd49cf7ff3546cdbel, false); 997 try { 998 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE); 999 script.set_gAllocInB(inB); 1000 script.forEach_testFmaxHalf2HalfHalf2(inA, out); 1001 verifyResultsFmaxHalf2HalfHalf2(inA, inB, out, false); 1002 out.destroy(); 1003 } catch (Exception e) { 1004 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFmaxHalf2HalfHalf2: " + e.toString()); 1005 } 1006 try { 1007 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE); 1008 scriptRelaxed.set_gAllocInB(inB); 1009 scriptRelaxed.forEach_testFmaxHalf2HalfHalf2(inA, out); 1010 verifyResultsFmaxHalf2HalfHalf2(inA, inB, out, true); 1011 out.destroy(); 1012 } catch (Exception e) { 1013 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFmaxHalf2HalfHalf2: " + e.toString()); 1014 } 1015 inA.destroy(); 1016 inB.destroy(); 1017 } 1018 verifyResultsFmaxHalf2HalfHalf2(Allocation inA, Allocation inB, Allocation out, boolean relaxed)1019 private void verifyResultsFmaxHalf2HalfHalf2(Allocation inA, Allocation inB, Allocation out, boolean relaxed) { 1020 short[] arrayInA = new short[INPUTSIZE * 2]; 1021 Arrays.fill(arrayInA, (short) 42); 1022 inA.copyTo(arrayInA); 1023 short[] arrayInB = new short[INPUTSIZE * 1]; 1024 Arrays.fill(arrayInB, (short) 42); 1025 inB.copyTo(arrayInB); 1026 short[] arrayOut = new short[INPUTSIZE * 2]; 1027 Arrays.fill(arrayOut, (short) 42); 1028 out.copyTo(arrayOut); 1029 StringBuilder message = new StringBuilder(); 1030 boolean errorFound = false; 1031 for (int i = 0; i < INPUTSIZE; i++) { 1032 for (int j = 0; j < 2 ; j++) { 1033 // Extract the inputs. 1034 ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf(); 1035 args.inA = arrayInA[i * 2 + j]; 1036 args.inADouble = Float16Utils.convertFloat16ToDouble(args.inA); 1037 args.inB = arrayInB[i]; 1038 args.inBDouble = Float16Utils.convertFloat16ToDouble(args.inB); 1039 // Figure out what the outputs should have been. 1040 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 1041 CoreMathVerifier.computeFmax(args, target); 1042 // Validate the outputs. 1043 boolean valid = true; 1044 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) { 1045 valid = false; 1046 } 1047 if (!valid) { 1048 if (!errorFound) { 1049 errorFound = true; 1050 message.append("Input inA: "); 1051 appendVariableToMessage(message, args.inA); 1052 message.append("\n"); 1053 message.append("Input inB: "); 1054 appendVariableToMessage(message, args.inB); 1055 message.append("\n"); 1056 message.append("Expected output out: "); 1057 appendVariableToMessage(message, args.out); 1058 message.append("\n"); 1059 message.append("Actual output out: "); 1060 appendVariableToMessage(message, arrayOut[i * 2 + j]); 1061 message.append("\n"); 1062 message.append("Actual output out (in double): "); 1063 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j])); 1064 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) { 1065 message.append(" FAIL"); 1066 } 1067 message.append("\n"); 1068 message.append("Errors at"); 1069 } 1070 message.append(" ["); 1071 message.append(Integer.toString(i)); 1072 message.append(", "); 1073 message.append(Integer.toString(j)); 1074 message.append("]"); 1075 } 1076 } 1077 } 1078 assertFalse("Incorrect output for checkFmaxHalf2HalfHalf2" + 1079 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 1080 } 1081 checkFmaxHalf3HalfHalf3()1082 private void checkFmaxHalf3HalfHalf3() { 1083 Allocation inA = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0xff2a187de7e05f61l, false); 1084 Allocation inB = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0xff2a187de7e05f62l, false); 1085 try { 1086 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE); 1087 script.set_gAllocInB(inB); 1088 script.forEach_testFmaxHalf3HalfHalf3(inA, out); 1089 verifyResultsFmaxHalf3HalfHalf3(inA, inB, out, false); 1090 out.destroy(); 1091 } catch (Exception e) { 1092 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFmaxHalf3HalfHalf3: " + e.toString()); 1093 } 1094 try { 1095 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE); 1096 scriptRelaxed.set_gAllocInB(inB); 1097 scriptRelaxed.forEach_testFmaxHalf3HalfHalf3(inA, out); 1098 verifyResultsFmaxHalf3HalfHalf3(inA, inB, out, true); 1099 out.destroy(); 1100 } catch (Exception e) { 1101 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFmaxHalf3HalfHalf3: " + e.toString()); 1102 } 1103 inA.destroy(); 1104 inB.destroy(); 1105 } 1106 verifyResultsFmaxHalf3HalfHalf3(Allocation inA, Allocation inB, Allocation out, boolean relaxed)1107 private void verifyResultsFmaxHalf3HalfHalf3(Allocation inA, Allocation inB, Allocation out, boolean relaxed) { 1108 short[] arrayInA = new short[INPUTSIZE * 4]; 1109 Arrays.fill(arrayInA, (short) 42); 1110 inA.copyTo(arrayInA); 1111 short[] arrayInB = new short[INPUTSIZE * 1]; 1112 Arrays.fill(arrayInB, (short) 42); 1113 inB.copyTo(arrayInB); 1114 short[] arrayOut = new short[INPUTSIZE * 4]; 1115 Arrays.fill(arrayOut, (short) 42); 1116 out.copyTo(arrayOut); 1117 StringBuilder message = new StringBuilder(); 1118 boolean errorFound = false; 1119 for (int i = 0; i < INPUTSIZE; i++) { 1120 for (int j = 0; j < 3 ; j++) { 1121 // Extract the inputs. 1122 ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf(); 1123 args.inA = arrayInA[i * 4 + j]; 1124 args.inADouble = Float16Utils.convertFloat16ToDouble(args.inA); 1125 args.inB = arrayInB[i]; 1126 args.inBDouble = Float16Utils.convertFloat16ToDouble(args.inB); 1127 // Figure out what the outputs should have been. 1128 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 1129 CoreMathVerifier.computeFmax(args, target); 1130 // Validate the outputs. 1131 boolean valid = true; 1132 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 1133 valid = false; 1134 } 1135 if (!valid) { 1136 if (!errorFound) { 1137 errorFound = true; 1138 message.append("Input inA: "); 1139 appendVariableToMessage(message, args.inA); 1140 message.append("\n"); 1141 message.append("Input inB: "); 1142 appendVariableToMessage(message, args.inB); 1143 message.append("\n"); 1144 message.append("Expected output out: "); 1145 appendVariableToMessage(message, args.out); 1146 message.append("\n"); 1147 message.append("Actual output out: "); 1148 appendVariableToMessage(message, arrayOut[i * 4 + j]); 1149 message.append("\n"); 1150 message.append("Actual output out (in double): "); 1151 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j])); 1152 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 1153 message.append(" FAIL"); 1154 } 1155 message.append("\n"); 1156 message.append("Errors at"); 1157 } 1158 message.append(" ["); 1159 message.append(Integer.toString(i)); 1160 message.append(", "); 1161 message.append(Integer.toString(j)); 1162 message.append("]"); 1163 } 1164 } 1165 } 1166 assertFalse("Incorrect output for checkFmaxHalf3HalfHalf3" + 1167 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 1168 } 1169 checkFmaxHalf4HalfHalf4()1170 private void checkFmaxHalf4HalfHalf4() { 1171 Allocation inA = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0x29b738fc9a79f105l, false); 1172 Allocation inB = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0x29b738fc9a79f106l, false); 1173 try { 1174 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE); 1175 script.set_gAllocInB(inB); 1176 script.forEach_testFmaxHalf4HalfHalf4(inA, out); 1177 verifyResultsFmaxHalf4HalfHalf4(inA, inB, out, false); 1178 out.destroy(); 1179 } catch (Exception e) { 1180 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFmaxHalf4HalfHalf4: " + e.toString()); 1181 } 1182 try { 1183 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE); 1184 scriptRelaxed.set_gAllocInB(inB); 1185 scriptRelaxed.forEach_testFmaxHalf4HalfHalf4(inA, out); 1186 verifyResultsFmaxHalf4HalfHalf4(inA, inB, out, true); 1187 out.destroy(); 1188 } catch (Exception e) { 1189 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFmaxHalf4HalfHalf4: " + e.toString()); 1190 } 1191 inA.destroy(); 1192 inB.destroy(); 1193 } 1194 verifyResultsFmaxHalf4HalfHalf4(Allocation inA, Allocation inB, Allocation out, boolean relaxed)1195 private void verifyResultsFmaxHalf4HalfHalf4(Allocation inA, Allocation inB, Allocation out, boolean relaxed) { 1196 short[] arrayInA = new short[INPUTSIZE * 4]; 1197 Arrays.fill(arrayInA, (short) 42); 1198 inA.copyTo(arrayInA); 1199 short[] arrayInB = new short[INPUTSIZE * 1]; 1200 Arrays.fill(arrayInB, (short) 42); 1201 inB.copyTo(arrayInB); 1202 short[] arrayOut = new short[INPUTSIZE * 4]; 1203 Arrays.fill(arrayOut, (short) 42); 1204 out.copyTo(arrayOut); 1205 StringBuilder message = new StringBuilder(); 1206 boolean errorFound = false; 1207 for (int i = 0; i < INPUTSIZE; i++) { 1208 for (int j = 0; j < 4 ; j++) { 1209 // Extract the inputs. 1210 ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf(); 1211 args.inA = arrayInA[i * 4 + j]; 1212 args.inADouble = Float16Utils.convertFloat16ToDouble(args.inA); 1213 args.inB = arrayInB[i]; 1214 args.inBDouble = Float16Utils.convertFloat16ToDouble(args.inB); 1215 // Figure out what the outputs should have been. 1216 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 1217 CoreMathVerifier.computeFmax(args, target); 1218 // Validate the outputs. 1219 boolean valid = true; 1220 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 1221 valid = false; 1222 } 1223 if (!valid) { 1224 if (!errorFound) { 1225 errorFound = true; 1226 message.append("Input inA: "); 1227 appendVariableToMessage(message, args.inA); 1228 message.append("\n"); 1229 message.append("Input inB: "); 1230 appendVariableToMessage(message, args.inB); 1231 message.append("\n"); 1232 message.append("Expected output out: "); 1233 appendVariableToMessage(message, args.out); 1234 message.append("\n"); 1235 message.append("Actual output out: "); 1236 appendVariableToMessage(message, arrayOut[i * 4 + j]); 1237 message.append("\n"); 1238 message.append("Actual output out (in double): "); 1239 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j])); 1240 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 1241 message.append(" FAIL"); 1242 } 1243 message.append("\n"); 1244 message.append("Errors at"); 1245 } 1246 message.append(" ["); 1247 message.append(Integer.toString(i)); 1248 message.append(", "); 1249 message.append(Integer.toString(j)); 1250 message.append("]"); 1251 } 1252 } 1253 } 1254 assertFalse("Incorrect output for checkFmaxHalf4HalfHalf4" + 1255 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 1256 } 1257 testFmax()1258 public void testFmax() { 1259 checkFmaxFloatFloatFloat(); 1260 checkFmaxFloat2Float2Float2(); 1261 checkFmaxFloat3Float3Float3(); 1262 checkFmaxFloat4Float4Float4(); 1263 checkFmaxHalfHalfHalf(); 1264 checkFmaxHalf2Half2Half2(); 1265 checkFmaxHalf3Half3Half3(); 1266 checkFmaxHalf4Half4Half4(); 1267 checkFmaxFloat2FloatFloat2(); 1268 checkFmaxFloat3FloatFloat3(); 1269 checkFmaxFloat4FloatFloat4(); 1270 checkFmaxHalf2HalfHalf2(); 1271 checkFmaxHalf3HalfHalf3(); 1272 checkFmaxHalf4HalfHalf4(); 1273 } 1274 } 1275