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