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 TestStep extends RSBaseCompute { 29 30 private ScriptC_TestStep script; 31 private ScriptC_TestStepRelaxed scriptRelaxed; 32 33 @Override setUp()34 protected void setUp() throws Exception { 35 super.setUp(); 36 script = new ScriptC_TestStep(mRS); 37 scriptRelaxed = new ScriptC_TestStepRelaxed(mRS); 38 } 39 40 public class ArgumentsFloatFloatFloat { 41 public float inEdge; 42 public float inV; 43 public Target.Floaty out; 44 } 45 checkStepFloatFloatFloat()46 private void checkStepFloatFloatFloat() { 47 Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x9184fbfel, false); 48 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x832f44e9l, false); 49 try { 50 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 51 script.set_gAllocInV(inV); 52 script.forEach_testStepFloatFloatFloat(inEdge, out); 53 verifyResultsStepFloatFloatFloat(inEdge, inV, out, false); 54 } catch (Exception e) { 55 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloatFloatFloat: " + e.toString()); 56 } 57 try { 58 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 59 scriptRelaxed.set_gAllocInV(inV); 60 scriptRelaxed.forEach_testStepFloatFloatFloat(inEdge, out); 61 verifyResultsStepFloatFloatFloat(inEdge, inV, out, true); 62 } catch (Exception e) { 63 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloatFloatFloat: " + e.toString()); 64 } 65 } 66 verifyResultsStepFloatFloatFloat(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed)67 private void verifyResultsStepFloatFloatFloat(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) { 68 float[] arrayInEdge = new float[INPUTSIZE * 1]; 69 Arrays.fill(arrayInEdge, (float) 42); 70 inEdge.copyTo(arrayInEdge); 71 float[] arrayInV = new float[INPUTSIZE * 1]; 72 Arrays.fill(arrayInV, (float) 42); 73 inV.copyTo(arrayInV); 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.inEdge = arrayInEdge[i]; 84 args.inV = arrayInV[i]; 85 // Figure out what the outputs should have been. 86 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 87 CoreMathVerifier.computeStep(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 inEdge: "); 97 appendVariableToMessage(message, args.inEdge); 98 message.append("\n"); 99 message.append("Input inV: "); 100 appendVariableToMessage(message, args.inV); 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 checkStepFloatFloatFloat" + 122 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 123 } 124 checkStepFloat2Float2Float2()125 private void checkStepFloat2Float2Float2() { 126 Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x7df69504l, false); 127 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x8567f58bl, false); 128 try { 129 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 130 script.set_gAllocInV(inV); 131 script.forEach_testStepFloat2Float2Float2(inEdge, out); 132 verifyResultsStepFloat2Float2Float2(inEdge, inV, out, false); 133 } catch (Exception e) { 134 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloat2Float2Float2: " + e.toString()); 135 } 136 try { 137 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 138 scriptRelaxed.set_gAllocInV(inV); 139 scriptRelaxed.forEach_testStepFloat2Float2Float2(inEdge, out); 140 verifyResultsStepFloat2Float2Float2(inEdge, inV, out, true); 141 } catch (Exception e) { 142 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloat2Float2Float2: " + e.toString()); 143 } 144 } 145 verifyResultsStepFloat2Float2Float2(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed)146 private void verifyResultsStepFloat2Float2Float2(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) { 147 float[] arrayInEdge = new float[INPUTSIZE * 2]; 148 Arrays.fill(arrayInEdge, (float) 42); 149 inEdge.copyTo(arrayInEdge); 150 float[] arrayInV = new float[INPUTSIZE * 2]; 151 Arrays.fill(arrayInV, (float) 42); 152 inV.copyTo(arrayInV); 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.inEdge = arrayInEdge[i * 2 + j]; 163 args.inV = arrayInV[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.computeStep(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 inEdge: "); 176 appendVariableToMessage(message, args.inEdge); 177 message.append("\n"); 178 message.append("Input inV: "); 179 appendVariableToMessage(message, args.inV); 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 checkStepFloat2Float2Float2" + 201 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 202 } 203 checkStepFloat3Float3Float3()204 private void checkStepFloat3Float3Float3() { 205 Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x666a7a77l, false); 206 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x8745f72cl, false); 207 try { 208 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 209 script.set_gAllocInV(inV); 210 script.forEach_testStepFloat3Float3Float3(inEdge, out); 211 verifyResultsStepFloat3Float3Float3(inEdge, inV, out, false); 212 } catch (Exception e) { 213 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloat3Float3Float3: " + e.toString()); 214 } 215 try { 216 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 217 scriptRelaxed.set_gAllocInV(inV); 218 scriptRelaxed.forEach_testStepFloat3Float3Float3(inEdge, out); 219 verifyResultsStepFloat3Float3Float3(inEdge, inV, out, true); 220 } catch (Exception e) { 221 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloat3Float3Float3: " + e.toString()); 222 } 223 } 224 verifyResultsStepFloat3Float3Float3(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed)225 private void verifyResultsStepFloat3Float3Float3(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) { 226 float[] arrayInEdge = new float[INPUTSIZE * 4]; 227 Arrays.fill(arrayInEdge, (float) 42); 228 inEdge.copyTo(arrayInEdge); 229 float[] arrayInV = new float[INPUTSIZE * 4]; 230 Arrays.fill(arrayInV, (float) 42); 231 inV.copyTo(arrayInV); 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.inEdge = arrayInEdge[i * 4 + j]; 242 args.inV = arrayInV[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.computeStep(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 inEdge: "); 255 appendVariableToMessage(message, args.inEdge); 256 message.append("\n"); 257 message.append("Input inV: "); 258 appendVariableToMessage(message, args.inV); 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 checkStepFloat3Float3Float3" + 280 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 281 } 282 checkStepFloat4Float4Float4()283 private void checkStepFloat4Float4Float4() { 284 Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x4ede5feal, false); 285 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x8923f8cdl, false); 286 try { 287 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 288 script.set_gAllocInV(inV); 289 script.forEach_testStepFloat4Float4Float4(inEdge, out); 290 verifyResultsStepFloat4Float4Float4(inEdge, inV, out, false); 291 } catch (Exception e) { 292 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloat4Float4Float4: " + e.toString()); 293 } 294 try { 295 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 296 scriptRelaxed.set_gAllocInV(inV); 297 scriptRelaxed.forEach_testStepFloat4Float4Float4(inEdge, out); 298 verifyResultsStepFloat4Float4Float4(inEdge, inV, out, true); 299 } catch (Exception e) { 300 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloat4Float4Float4: " + e.toString()); 301 } 302 } 303 verifyResultsStepFloat4Float4Float4(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed)304 private void verifyResultsStepFloat4Float4Float4(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) { 305 float[] arrayInEdge = new float[INPUTSIZE * 4]; 306 Arrays.fill(arrayInEdge, (float) 42); 307 inEdge.copyTo(arrayInEdge); 308 float[] arrayInV = new float[INPUTSIZE * 4]; 309 Arrays.fill(arrayInV, (float) 42); 310 inV.copyTo(arrayInV); 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.inEdge = arrayInEdge[i * 4 + j]; 321 args.inV = arrayInV[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.computeStep(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 inEdge: "); 334 appendVariableToMessage(message, args.inEdge); 335 message.append("\n"); 336 message.append("Input inV: "); 337 appendVariableToMessage(message, args.inV); 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 checkStepFloat4Float4Float4" + 359 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 360 } 361 362 public class ArgumentsHalfHalfHalf { 363 public short inEdge; 364 public double inEdgeDouble; 365 public short inV; 366 public double inVDouble; 367 public Target.Floaty out; 368 } 369 checkStepHalfHalfHalf()370 private void checkStepHalfHalfHalf() { 371 Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0xe2c3f577l, false); 372 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0x3240702cl, false); 373 try { 374 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE); 375 script.set_gAllocInV(inV); 376 script.forEach_testStepHalfHalfHalf(inEdge, out); 377 verifyResultsStepHalfHalfHalf(inEdge, inV, out, false); 378 } catch (Exception e) { 379 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalfHalfHalf: " + e.toString()); 380 } 381 try { 382 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE); 383 scriptRelaxed.set_gAllocInV(inV); 384 scriptRelaxed.forEach_testStepHalfHalfHalf(inEdge, out); 385 verifyResultsStepHalfHalfHalf(inEdge, inV, out, true); 386 } catch (Exception e) { 387 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalfHalfHalf: " + e.toString()); 388 } 389 } 390 verifyResultsStepHalfHalfHalf(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed)391 private void verifyResultsStepHalfHalfHalf(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) { 392 short[] arrayInEdge = new short[INPUTSIZE * 1]; 393 Arrays.fill(arrayInEdge, (short) 42); 394 inEdge.copyTo(arrayInEdge); 395 short[] arrayInV = new short[INPUTSIZE * 1]; 396 Arrays.fill(arrayInV, (short) 42); 397 inV.copyTo(arrayInV); 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.inEdge = arrayInEdge[i]; 408 args.inEdgeDouble = Float16Utils.convertFloat16ToDouble(args.inEdge); 409 args.inV = arrayInV[i]; 410 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV); 411 // Figure out what the outputs should have been. 412 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 413 CoreMathVerifier.computeStep(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 inEdge: "); 423 appendVariableToMessage(message, args.inEdge); 424 message.append("\n"); 425 message.append("Input inV: "); 426 appendVariableToMessage(message, args.inV); 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 checkStepHalfHalfHalf" + 451 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 452 } 453 checkStepHalf2Half2Half2()454 private void checkStepHalf2Half2Half2() { 455 Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 2, 0xee08afadl, false); 456 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 2, 0xba1588del, false); 457 try { 458 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE); 459 script.set_gAllocInV(inV); 460 script.forEach_testStepHalf2Half2Half2(inEdge, out); 461 verifyResultsStepHalf2Half2Half2(inEdge, inV, out, false); 462 } catch (Exception e) { 463 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalf2Half2Half2: " + e.toString()); 464 } 465 try { 466 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE); 467 scriptRelaxed.set_gAllocInV(inV); 468 scriptRelaxed.forEach_testStepHalf2Half2Half2(inEdge, out); 469 verifyResultsStepHalf2Half2Half2(inEdge, inV, out, true); 470 } catch (Exception e) { 471 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalf2Half2Half2: " + e.toString()); 472 } 473 } 474 verifyResultsStepHalf2Half2Half2(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed)475 private void verifyResultsStepHalf2Half2Half2(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) { 476 short[] arrayInEdge = new short[INPUTSIZE * 2]; 477 Arrays.fill(arrayInEdge, (short) 42); 478 inEdge.copyTo(arrayInEdge); 479 short[] arrayInV = new short[INPUTSIZE * 2]; 480 Arrays.fill(arrayInV, (short) 42); 481 inV.copyTo(arrayInV); 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.inEdge = arrayInEdge[i * 2 + j]; 492 args.inEdgeDouble = Float16Utils.convertFloat16ToDouble(args.inEdge); 493 args.inV = arrayInV[i * 2 + j]; 494 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV); 495 // Figure out what the outputs should have been. 496 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 497 CoreMathVerifier.computeStep(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 inEdge: "); 507 appendVariableToMessage(message, args.inEdge); 508 message.append("\n"); 509 message.append("Input inV: "); 510 appendVariableToMessage(message, args.inV); 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 checkStepHalf2Half2Half2" + 535 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 536 } 537 checkStepHalf3Half3Half3()538 private void checkStepHalf3Half3Half3() { 539 Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0xe1ba008al, false); 540 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0x18b499adl, false); 541 try { 542 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE); 543 script.set_gAllocInV(inV); 544 script.forEach_testStepHalf3Half3Half3(inEdge, out); 545 verifyResultsStepHalf3Half3Half3(inEdge, inV, out, false); 546 } catch (Exception e) { 547 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalf3Half3Half3: " + e.toString()); 548 } 549 try { 550 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE); 551 scriptRelaxed.set_gAllocInV(inV); 552 scriptRelaxed.forEach_testStepHalf3Half3Half3(inEdge, out); 553 verifyResultsStepHalf3Half3Half3(inEdge, inV, out, true); 554 } catch (Exception e) { 555 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalf3Half3Half3: " + e.toString()); 556 } 557 } 558 verifyResultsStepHalf3Half3Half3(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed)559 private void verifyResultsStepHalf3Half3Half3(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) { 560 short[] arrayInEdge = new short[INPUTSIZE * 4]; 561 Arrays.fill(arrayInEdge, (short) 42); 562 inEdge.copyTo(arrayInEdge); 563 short[] arrayInV = new short[INPUTSIZE * 4]; 564 Arrays.fill(arrayInV, (short) 42); 565 inV.copyTo(arrayInV); 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.inEdge = arrayInEdge[i * 4 + j]; 576 args.inEdgeDouble = Float16Utils.convertFloat16ToDouble(args.inEdge); 577 args.inV = arrayInV[i * 4 + j]; 578 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV); 579 // Figure out what the outputs should have been. 580 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 581 CoreMathVerifier.computeStep(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 inEdge: "); 591 appendVariableToMessage(message, args.inEdge); 592 message.append("\n"); 593 message.append("Input inV: "); 594 appendVariableToMessage(message, args.inV); 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 checkStepHalf3Half3Half3" + 619 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 620 } 621 checkStepHalf4Half4Half4()622 private void checkStepHalf4Half4Half4() { 623 Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0xd56b5167l, false); 624 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0x7753aa7cl, false); 625 try { 626 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE); 627 script.set_gAllocInV(inV); 628 script.forEach_testStepHalf4Half4Half4(inEdge, out); 629 verifyResultsStepHalf4Half4Half4(inEdge, inV, out, false); 630 } catch (Exception e) { 631 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalf4Half4Half4: " + e.toString()); 632 } 633 try { 634 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE); 635 scriptRelaxed.set_gAllocInV(inV); 636 scriptRelaxed.forEach_testStepHalf4Half4Half4(inEdge, out); 637 verifyResultsStepHalf4Half4Half4(inEdge, inV, out, true); 638 } catch (Exception e) { 639 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalf4Half4Half4: " + e.toString()); 640 } 641 } 642 verifyResultsStepHalf4Half4Half4(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed)643 private void verifyResultsStepHalf4Half4Half4(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) { 644 short[] arrayInEdge = new short[INPUTSIZE * 4]; 645 Arrays.fill(arrayInEdge, (short) 42); 646 inEdge.copyTo(arrayInEdge); 647 short[] arrayInV = new short[INPUTSIZE * 4]; 648 Arrays.fill(arrayInV, (short) 42); 649 inV.copyTo(arrayInV); 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.inEdge = arrayInEdge[i * 4 + j]; 660 args.inEdgeDouble = Float16Utils.convertFloat16ToDouble(args.inEdge); 661 args.inV = arrayInV[i * 4 + j]; 662 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV); 663 // Figure out what the outputs should have been. 664 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 665 CoreMathVerifier.computeStep(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 inEdge: "); 675 appendVariableToMessage(message, args.inEdge); 676 message.append("\n"); 677 message.append("Input inV: "); 678 appendVariableToMessage(message, args.inV); 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 checkStepHalf4Half4Half4" + 703 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 704 } 705 checkStepFloat2FloatFloat2()706 private void checkStepFloat2FloatFloat2() { 707 Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x5b3d8b26l, false); 708 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xb6d48a21l, false); 709 try { 710 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 711 script.set_gAllocInV(inV); 712 script.forEach_testStepFloat2FloatFloat2(inEdge, out); 713 verifyResultsStepFloat2FloatFloat2(inEdge, inV, out, false); 714 } catch (Exception e) { 715 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloat2FloatFloat2: " + e.toString()); 716 } 717 try { 718 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 719 scriptRelaxed.set_gAllocInV(inV); 720 scriptRelaxed.forEach_testStepFloat2FloatFloat2(inEdge, out); 721 verifyResultsStepFloat2FloatFloat2(inEdge, inV, out, true); 722 } catch (Exception e) { 723 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloat2FloatFloat2: " + e.toString()); 724 } 725 } 726 verifyResultsStepFloat2FloatFloat2(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed)727 private void verifyResultsStepFloat2FloatFloat2(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) { 728 float[] arrayInEdge = new float[INPUTSIZE * 2]; 729 Arrays.fill(arrayInEdge, (float) 42); 730 inEdge.copyTo(arrayInEdge); 731 float[] arrayInV = new float[INPUTSIZE * 1]; 732 Arrays.fill(arrayInV, (float) 42); 733 inV.copyTo(arrayInV); 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.inEdge = arrayInEdge[i * 2 + j]; 744 args.inV = arrayInV[i]; 745 // Figure out what the outputs should have been. 746 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 747 CoreMathVerifier.computeStep(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 inEdge: "); 757 appendVariableToMessage(message, args.inEdge); 758 message.append("\n"); 759 message.append("Input inV: "); 760 appendVariableToMessage(message, args.inV); 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 checkStepFloat2FloatFloat2" + 782 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 783 } 784 checkStepFloat3FloatFloat3()785 private void checkStepFloat3FloatFloat3() { 786 Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xc68f43fal, false); 787 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xa53f7e7dl, false); 788 try { 789 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 790 script.set_gAllocInV(inV); 791 script.forEach_testStepFloat3FloatFloat3(inEdge, out); 792 verifyResultsStepFloat3FloatFloat3(inEdge, inV, out, false); 793 } catch (Exception e) { 794 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloat3FloatFloat3: " + e.toString()); 795 } 796 try { 797 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 798 scriptRelaxed.set_gAllocInV(inV); 799 scriptRelaxed.forEach_testStepFloat3FloatFloat3(inEdge, out); 800 verifyResultsStepFloat3FloatFloat3(inEdge, inV, out, true); 801 } catch (Exception e) { 802 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloat3FloatFloat3: " + e.toString()); 803 } 804 } 805 verifyResultsStepFloat3FloatFloat3(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed)806 private void verifyResultsStepFloat3FloatFloat3(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) { 807 float[] arrayInEdge = new float[INPUTSIZE * 4]; 808 Arrays.fill(arrayInEdge, (float) 42); 809 inEdge.copyTo(arrayInEdge); 810 float[] arrayInV = new float[INPUTSIZE * 1]; 811 Arrays.fill(arrayInV, (float) 42); 812 inV.copyTo(arrayInV); 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.inEdge = arrayInEdge[i * 4 + j]; 823 args.inV = arrayInV[i]; 824 // Figure out what the outputs should have been. 825 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 826 CoreMathVerifier.computeStep(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 inEdge: "); 836 appendVariableToMessage(message, args.inEdge); 837 message.append("\n"); 838 message.append("Input inV: "); 839 appendVariableToMessage(message, args.inV); 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 checkStepFloat3FloatFloat3" + 861 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 862 } 863 checkStepFloat4FloatFloat4()864 private void checkStepFloat4FloatFloat4() { 865 Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x31e0fccel, false); 866 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x93aa72d9l, false); 867 try { 868 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 869 script.set_gAllocInV(inV); 870 script.forEach_testStepFloat4FloatFloat4(inEdge, out); 871 verifyResultsStepFloat4FloatFloat4(inEdge, inV, out, false); 872 } catch (Exception e) { 873 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloat4FloatFloat4: " + e.toString()); 874 } 875 try { 876 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 877 scriptRelaxed.set_gAllocInV(inV); 878 scriptRelaxed.forEach_testStepFloat4FloatFloat4(inEdge, out); 879 verifyResultsStepFloat4FloatFloat4(inEdge, inV, out, true); 880 } catch (Exception e) { 881 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloat4FloatFloat4: " + e.toString()); 882 } 883 } 884 verifyResultsStepFloat4FloatFloat4(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed)885 private void verifyResultsStepFloat4FloatFloat4(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) { 886 float[] arrayInEdge = new float[INPUTSIZE * 4]; 887 Arrays.fill(arrayInEdge, (float) 42); 888 inEdge.copyTo(arrayInEdge); 889 float[] arrayInV = new float[INPUTSIZE * 1]; 890 Arrays.fill(arrayInV, (float) 42); 891 inV.copyTo(arrayInV); 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.inEdge = arrayInEdge[i * 4 + j]; 902 args.inV = arrayInV[i]; 903 // Figure out what the outputs should have been. 904 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 905 CoreMathVerifier.computeStep(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 inEdge: "); 915 appendVariableToMessage(message, args.inEdge); 916 message.append("\n"); 917 message.append("Input inV: "); 918 appendVariableToMessage(message, args.inV); 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 checkStepFloat4FloatFloat4" + 940 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 941 } 942 checkStepHalf2HalfHalf2()943 private void checkStepHalf2HalfHalf2() { 944 Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 2, 0x2f4438d3l, false); 945 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0x2d7ce0l, false); 946 try { 947 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE); 948 script.set_gAllocInV(inV); 949 script.forEach_testStepHalf2HalfHalf2(inEdge, out); 950 verifyResultsStepHalf2HalfHalf2(inEdge, inV, out, false); 951 } catch (Exception e) { 952 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalf2HalfHalf2: " + e.toString()); 953 } 954 try { 955 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE); 956 scriptRelaxed.set_gAllocInV(inV); 957 scriptRelaxed.forEach_testStepHalf2HalfHalf2(inEdge, out); 958 verifyResultsStepHalf2HalfHalf2(inEdge, inV, out, true); 959 } catch (Exception e) { 960 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalf2HalfHalf2: " + e.toString()); 961 } 962 } 963 verifyResultsStepHalf2HalfHalf2(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed)964 private void verifyResultsStepHalf2HalfHalf2(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) { 965 short[] arrayInEdge = new short[INPUTSIZE * 2]; 966 Arrays.fill(arrayInEdge, (short) 42); 967 inEdge.copyTo(arrayInEdge); 968 short[] arrayInV = new short[INPUTSIZE * 1]; 969 Arrays.fill(arrayInV, (short) 42); 970 inV.copyTo(arrayInV); 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.inEdge = arrayInEdge[i * 2 + j]; 981 args.inEdgeDouble = Float16Utils.convertFloat16ToDouble(args.inEdge); 982 args.inV = arrayInV[i]; 983 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV); 984 // Figure out what the outputs should have been. 985 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 986 CoreMathVerifier.computeStep(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 inEdge: "); 996 appendVariableToMessage(message, args.inEdge); 997 message.append("\n"); 998 message.append("Input inV: "); 999 appendVariableToMessage(message, args.inV); 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 checkStepHalf2HalfHalf2" + 1024 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 1025 } 1026 checkStepHalf3HalfHalf3()1027 private void checkStepHalf3HalfHalf3() { 1028 Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0xb3cf71ffl, false); 1029 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0xb2c70e84l, false); 1030 try { 1031 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE); 1032 script.set_gAllocInV(inV); 1033 script.forEach_testStepHalf3HalfHalf3(inEdge, out); 1034 verifyResultsStepHalf3HalfHalf3(inEdge, inV, out, false); 1035 } catch (Exception e) { 1036 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalf3HalfHalf3: " + e.toString()); 1037 } 1038 try { 1039 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE); 1040 scriptRelaxed.set_gAllocInV(inV); 1041 scriptRelaxed.forEach_testStepHalf3HalfHalf3(inEdge, out); 1042 verifyResultsStepHalf3HalfHalf3(inEdge, inV, out, true); 1043 } catch (Exception e) { 1044 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalf3HalfHalf3: " + e.toString()); 1045 } 1046 } 1047 verifyResultsStepHalf3HalfHalf3(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed)1048 private void verifyResultsStepHalf3HalfHalf3(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) { 1049 short[] arrayInEdge = new short[INPUTSIZE * 4]; 1050 Arrays.fill(arrayInEdge, (short) 42); 1051 inEdge.copyTo(arrayInEdge); 1052 short[] arrayInV = new short[INPUTSIZE * 1]; 1053 Arrays.fill(arrayInV, (short) 42); 1054 inV.copyTo(arrayInV); 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.inEdge = arrayInEdge[i * 4 + j]; 1065 args.inEdgeDouble = Float16Utils.convertFloat16ToDouble(args.inEdge); 1066 args.inV = arrayInV[i]; 1067 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV); 1068 // Figure out what the outputs should have been. 1069 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 1070 CoreMathVerifier.computeStep(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 inEdge: "); 1080 appendVariableToMessage(message, args.inEdge); 1081 message.append("\n"); 1082 message.append("Input inV: "); 1083 appendVariableToMessage(message, args.inV); 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 checkStepHalf3HalfHalf3" + 1108 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 1109 } 1110 checkStepHalf4HalfHalf4()1111 private void checkStepHalf4HalfHalf4() { 1112 Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0x385aab2bl, false); 1113 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0x6560a028l, false); 1114 try { 1115 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE); 1116 script.set_gAllocInV(inV); 1117 script.forEach_testStepHalf4HalfHalf4(inEdge, out); 1118 verifyResultsStepHalf4HalfHalf4(inEdge, inV, out, false); 1119 } catch (Exception e) { 1120 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalf4HalfHalf4: " + e.toString()); 1121 } 1122 try { 1123 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE); 1124 scriptRelaxed.set_gAllocInV(inV); 1125 scriptRelaxed.forEach_testStepHalf4HalfHalf4(inEdge, out); 1126 verifyResultsStepHalf4HalfHalf4(inEdge, inV, out, true); 1127 } catch (Exception e) { 1128 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalf4HalfHalf4: " + e.toString()); 1129 } 1130 } 1131 verifyResultsStepHalf4HalfHalf4(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed)1132 private void verifyResultsStepHalf4HalfHalf4(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) { 1133 short[] arrayInEdge = new short[INPUTSIZE * 4]; 1134 Arrays.fill(arrayInEdge, (short) 42); 1135 inEdge.copyTo(arrayInEdge); 1136 short[] arrayInV = new short[INPUTSIZE * 1]; 1137 Arrays.fill(arrayInV, (short) 42); 1138 inV.copyTo(arrayInV); 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.inEdge = arrayInEdge[i * 4 + j]; 1149 args.inEdgeDouble = Float16Utils.convertFloat16ToDouble(args.inEdge); 1150 args.inV = arrayInV[i]; 1151 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV); 1152 // Figure out what the outputs should have been. 1153 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 1154 CoreMathVerifier.computeStep(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 inEdge: "); 1164 appendVariableToMessage(message, args.inEdge); 1165 message.append("\n"); 1166 message.append("Input inV: "); 1167 appendVariableToMessage(message, args.inV); 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 checkStepHalf4HalfHalf4" + 1192 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 1193 } 1194 checkStepFloatFloat2Float2()1195 private void checkStepFloatFloat2Float2() { 1196 Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x664b1852l, false); 1197 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x44e2f7c5l, false); 1198 try { 1199 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 1200 script.set_gAllocInV(inV); 1201 script.forEach_testStepFloatFloat2Float2(inEdge, out); 1202 verifyResultsStepFloatFloat2Float2(inEdge, inV, out, false); 1203 } catch (Exception e) { 1204 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloatFloat2Float2: " + e.toString()); 1205 } 1206 try { 1207 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 1208 scriptRelaxed.set_gAllocInV(inV); 1209 scriptRelaxed.forEach_testStepFloatFloat2Float2(inEdge, out); 1210 verifyResultsStepFloatFloat2Float2(inEdge, inV, out, true); 1211 } catch (Exception e) { 1212 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloatFloat2Float2: " + e.toString()); 1213 } 1214 } 1215 verifyResultsStepFloatFloat2Float2(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed)1216 private void verifyResultsStepFloatFloat2Float2(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) { 1217 float[] arrayInEdge = new float[INPUTSIZE * 1]; 1218 Arrays.fill(arrayInEdge, (float) 42); 1219 inEdge.copyTo(arrayInEdge); 1220 float[] arrayInV = new float[INPUTSIZE * 2]; 1221 Arrays.fill(arrayInV, (float) 42); 1222 inV.copyTo(arrayInV); 1223 float[] arrayOut = new float[INPUTSIZE * 2]; 1224 Arrays.fill(arrayOut, (float) 42); 1225 out.copyTo(arrayOut); 1226 StringBuilder message = new StringBuilder(); 1227 boolean errorFound = false; 1228 for (int i = 0; i < INPUTSIZE; i++) { 1229 for (int j = 0; j < 2 ; j++) { 1230 // Extract the inputs. 1231 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); 1232 args.inEdge = arrayInEdge[i]; 1233 args.inV = arrayInV[i * 2 + j]; 1234 // Figure out what the outputs should have been. 1235 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 1236 CoreMathVerifier.computeStep(args, target); 1237 // Validate the outputs. 1238 boolean valid = true; 1239 if (!args.out.couldBe(arrayOut[i * 2 + j])) { 1240 valid = false; 1241 } 1242 if (!valid) { 1243 if (!errorFound) { 1244 errorFound = true; 1245 message.append("Input inEdge: "); 1246 appendVariableToMessage(message, args.inEdge); 1247 message.append("\n"); 1248 message.append("Input inV: "); 1249 appendVariableToMessage(message, args.inV); 1250 message.append("\n"); 1251 message.append("Expected output out: "); 1252 appendVariableToMessage(message, args.out); 1253 message.append("\n"); 1254 message.append("Actual output out: "); 1255 appendVariableToMessage(message, arrayOut[i * 2 + j]); 1256 if (!args.out.couldBe(arrayOut[i * 2 + j])) { 1257 message.append(" FAIL"); 1258 } 1259 message.append("\n"); 1260 message.append("Errors at"); 1261 } 1262 message.append(" ["); 1263 message.append(Integer.toString(i)); 1264 message.append(", "); 1265 message.append(Integer.toString(j)); 1266 message.append("]"); 1267 } 1268 } 1269 } 1270 assertFalse("Incorrect output for checkStepFloatFloat2Float2" + 1271 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 1272 } 1273 checkStepFloatFloat3Float3()1274 private void checkStepFloatFloat3Float3() { 1275 Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x91abcbccl, false); 1276 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x3afe18a3l, false); 1277 try { 1278 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 1279 script.set_gAllocInV(inV); 1280 script.forEach_testStepFloatFloat3Float3(inEdge, out); 1281 verifyResultsStepFloatFloat3Float3(inEdge, inV, out, false); 1282 } catch (Exception e) { 1283 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloatFloat3Float3: " + e.toString()); 1284 } 1285 try { 1286 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 1287 scriptRelaxed.set_gAllocInV(inV); 1288 scriptRelaxed.forEach_testStepFloatFloat3Float3(inEdge, out); 1289 verifyResultsStepFloatFloat3Float3(inEdge, inV, out, true); 1290 } catch (Exception e) { 1291 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloatFloat3Float3: " + e.toString()); 1292 } 1293 } 1294 verifyResultsStepFloatFloat3Float3(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed)1295 private void verifyResultsStepFloatFloat3Float3(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) { 1296 float[] arrayInEdge = new float[INPUTSIZE * 1]; 1297 Arrays.fill(arrayInEdge, (float) 42); 1298 inEdge.copyTo(arrayInEdge); 1299 float[] arrayInV = new float[INPUTSIZE * 4]; 1300 Arrays.fill(arrayInV, (float) 42); 1301 inV.copyTo(arrayInV); 1302 float[] arrayOut = new float[INPUTSIZE * 4]; 1303 Arrays.fill(arrayOut, (float) 42); 1304 out.copyTo(arrayOut); 1305 StringBuilder message = new StringBuilder(); 1306 boolean errorFound = false; 1307 for (int i = 0; i < INPUTSIZE; i++) { 1308 for (int j = 0; j < 3 ; j++) { 1309 // Extract the inputs. 1310 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); 1311 args.inEdge = arrayInEdge[i]; 1312 args.inV = arrayInV[i * 4 + j]; 1313 // Figure out what the outputs should have been. 1314 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 1315 CoreMathVerifier.computeStep(args, target); 1316 // Validate the outputs. 1317 boolean valid = true; 1318 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 1319 valid = false; 1320 } 1321 if (!valid) { 1322 if (!errorFound) { 1323 errorFound = true; 1324 message.append("Input inEdge: "); 1325 appendVariableToMessage(message, args.inEdge); 1326 message.append("\n"); 1327 message.append("Input inV: "); 1328 appendVariableToMessage(message, args.inV); 1329 message.append("\n"); 1330 message.append("Expected output out: "); 1331 appendVariableToMessage(message, args.out); 1332 message.append("\n"); 1333 message.append("Actual output out: "); 1334 appendVariableToMessage(message, arrayOut[i * 4 + j]); 1335 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 1336 message.append(" FAIL"); 1337 } 1338 message.append("\n"); 1339 message.append("Errors at"); 1340 } 1341 message.append(" ["); 1342 message.append(Integer.toString(i)); 1343 message.append(", "); 1344 message.append(Integer.toString(j)); 1345 message.append("]"); 1346 } 1347 } 1348 } 1349 assertFalse("Incorrect output for checkStepFloatFloat3Float3" + 1350 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 1351 } 1352 checkStepFloatFloat4Float4()1353 private void checkStepFloatFloat4Float4() { 1354 Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xbd0c7f46l, false); 1355 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x31193981l, false); 1356 try { 1357 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 1358 script.set_gAllocInV(inV); 1359 script.forEach_testStepFloatFloat4Float4(inEdge, out); 1360 verifyResultsStepFloatFloat4Float4(inEdge, inV, out, false); 1361 } catch (Exception e) { 1362 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloatFloat4Float4: " + e.toString()); 1363 } 1364 try { 1365 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 1366 scriptRelaxed.set_gAllocInV(inV); 1367 scriptRelaxed.forEach_testStepFloatFloat4Float4(inEdge, out); 1368 verifyResultsStepFloatFloat4Float4(inEdge, inV, out, true); 1369 } catch (Exception e) { 1370 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloatFloat4Float4: " + e.toString()); 1371 } 1372 } 1373 verifyResultsStepFloatFloat4Float4(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed)1374 private void verifyResultsStepFloatFloat4Float4(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) { 1375 float[] arrayInEdge = new float[INPUTSIZE * 1]; 1376 Arrays.fill(arrayInEdge, (float) 42); 1377 inEdge.copyTo(arrayInEdge); 1378 float[] arrayInV = new float[INPUTSIZE * 4]; 1379 Arrays.fill(arrayInV, (float) 42); 1380 inV.copyTo(arrayInV); 1381 float[] arrayOut = new float[INPUTSIZE * 4]; 1382 Arrays.fill(arrayOut, (float) 42); 1383 out.copyTo(arrayOut); 1384 StringBuilder message = new StringBuilder(); 1385 boolean errorFound = false; 1386 for (int i = 0; i < INPUTSIZE; i++) { 1387 for (int j = 0; j < 4 ; j++) { 1388 // Extract the inputs. 1389 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); 1390 args.inEdge = arrayInEdge[i]; 1391 args.inV = arrayInV[i * 4 + j]; 1392 // Figure out what the outputs should have been. 1393 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 1394 CoreMathVerifier.computeStep(args, target); 1395 // Validate the outputs. 1396 boolean valid = true; 1397 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 1398 valid = false; 1399 } 1400 if (!valid) { 1401 if (!errorFound) { 1402 errorFound = true; 1403 message.append("Input inEdge: "); 1404 appendVariableToMessage(message, args.inEdge); 1405 message.append("\n"); 1406 message.append("Input inV: "); 1407 appendVariableToMessage(message, args.inV); 1408 message.append("\n"); 1409 message.append("Expected output out: "); 1410 appendVariableToMessage(message, args.out); 1411 message.append("\n"); 1412 message.append("Actual output out: "); 1413 appendVariableToMessage(message, arrayOut[i * 4 + j]); 1414 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 1415 message.append(" FAIL"); 1416 } 1417 message.append("\n"); 1418 message.append("Errors at"); 1419 } 1420 message.append(" ["); 1421 message.append(Integer.toString(i)); 1422 message.append(", "); 1423 message.append(Integer.toString(j)); 1424 message.append("]"); 1425 } 1426 } 1427 } 1428 assertFalse("Incorrect output for checkStepFloatFloat4Float4" + 1429 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 1430 } 1431 checkStepHalfHalf2Half2()1432 private void checkStepHalfHalf2Half2() { 1433 Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0x915e1ddl, false); 1434 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 2, 0x9aa13beel, false); 1435 try { 1436 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE); 1437 script.set_gAllocInV(inV); 1438 script.forEach_testStepHalfHalf2Half2(inEdge, out); 1439 verifyResultsStepHalfHalf2Half2(inEdge, inV, out, false); 1440 } catch (Exception e) { 1441 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalfHalf2Half2: " + e.toString()); 1442 } 1443 try { 1444 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE); 1445 scriptRelaxed.set_gAllocInV(inV); 1446 scriptRelaxed.forEach_testStepHalfHalf2Half2(inEdge, out); 1447 verifyResultsStepHalfHalf2Half2(inEdge, inV, out, true); 1448 } catch (Exception e) { 1449 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalfHalf2Half2: " + e.toString()); 1450 } 1451 } 1452 verifyResultsStepHalfHalf2Half2(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed)1453 private void verifyResultsStepHalfHalf2Half2(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) { 1454 short[] arrayInEdge = new short[INPUTSIZE * 1]; 1455 Arrays.fill(arrayInEdge, (short) 42); 1456 inEdge.copyTo(arrayInEdge); 1457 short[] arrayInV = new short[INPUTSIZE * 2]; 1458 Arrays.fill(arrayInV, (short) 42); 1459 inV.copyTo(arrayInV); 1460 short[] arrayOut = new short[INPUTSIZE * 2]; 1461 Arrays.fill(arrayOut, (short) 42); 1462 out.copyTo(arrayOut); 1463 StringBuilder message = new StringBuilder(); 1464 boolean errorFound = false; 1465 for (int i = 0; i < INPUTSIZE; i++) { 1466 for (int j = 0; j < 2 ; j++) { 1467 // Extract the inputs. 1468 ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf(); 1469 args.inEdge = arrayInEdge[i]; 1470 args.inEdgeDouble = Float16Utils.convertFloat16ToDouble(args.inEdge); 1471 args.inV = arrayInV[i * 2 + j]; 1472 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV); 1473 // Figure out what the outputs should have been. 1474 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 1475 CoreMathVerifier.computeStep(args, target); 1476 // Validate the outputs. 1477 boolean valid = true; 1478 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) { 1479 valid = false; 1480 } 1481 if (!valid) { 1482 if (!errorFound) { 1483 errorFound = true; 1484 message.append("Input inEdge: "); 1485 appendVariableToMessage(message, args.inEdge); 1486 message.append("\n"); 1487 message.append("Input inV: "); 1488 appendVariableToMessage(message, args.inV); 1489 message.append("\n"); 1490 message.append("Expected output out: "); 1491 appendVariableToMessage(message, args.out); 1492 message.append("\n"); 1493 message.append("Actual output out: "); 1494 appendVariableToMessage(message, arrayOut[i * 2 + j]); 1495 message.append("\n"); 1496 message.append("Actual output out (in double): "); 1497 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j])); 1498 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) { 1499 message.append(" FAIL"); 1500 } 1501 message.append("\n"); 1502 message.append("Errors at"); 1503 } 1504 message.append(" ["); 1505 message.append(Integer.toString(i)); 1506 message.append(", "); 1507 message.append(Integer.toString(j)); 1508 message.append("]"); 1509 } 1510 } 1511 } 1512 assertFalse("Incorrect output for checkStepHalfHalf2Half2" + 1513 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 1514 } 1515 checkStepHalfHalf3Half3()1516 private void checkStepHalfHalf3Half3() { 1517 Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0x30b71f9l, false); 1518 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0xf9a900e2l, false); 1519 try { 1520 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE); 1521 script.set_gAllocInV(inV); 1522 script.forEach_testStepHalfHalf3Half3(inEdge, out); 1523 verifyResultsStepHalfHalf3Half3(inEdge, inV, out, false); 1524 } catch (Exception e) { 1525 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalfHalf3Half3: " + e.toString()); 1526 } 1527 try { 1528 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE); 1529 scriptRelaxed.set_gAllocInV(inV); 1530 scriptRelaxed.forEach_testStepHalfHalf3Half3(inEdge, out); 1531 verifyResultsStepHalfHalf3Half3(inEdge, inV, out, true); 1532 } catch (Exception e) { 1533 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalfHalf3Half3: " + e.toString()); 1534 } 1535 } 1536 verifyResultsStepHalfHalf3Half3(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed)1537 private void verifyResultsStepHalfHalf3Half3(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) { 1538 short[] arrayInEdge = new short[INPUTSIZE * 1]; 1539 Arrays.fill(arrayInEdge, (short) 42); 1540 inEdge.copyTo(arrayInEdge); 1541 short[] arrayInV = new short[INPUTSIZE * 4]; 1542 Arrays.fill(arrayInV, (short) 42); 1543 inV.copyTo(arrayInV); 1544 short[] arrayOut = new short[INPUTSIZE * 4]; 1545 Arrays.fill(arrayOut, (short) 42); 1546 out.copyTo(arrayOut); 1547 StringBuilder message = new StringBuilder(); 1548 boolean errorFound = false; 1549 for (int i = 0; i < INPUTSIZE; i++) { 1550 for (int j = 0; j < 3 ; j++) { 1551 // Extract the inputs. 1552 ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf(); 1553 args.inEdge = arrayInEdge[i]; 1554 args.inEdgeDouble = Float16Utils.convertFloat16ToDouble(args.inEdge); 1555 args.inV = arrayInV[i * 4 + j]; 1556 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV); 1557 // Figure out what the outputs should have been. 1558 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 1559 CoreMathVerifier.computeStep(args, target); 1560 // Validate the outputs. 1561 boolean valid = true; 1562 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 1563 valid = false; 1564 } 1565 if (!valid) { 1566 if (!errorFound) { 1567 errorFound = true; 1568 message.append("Input inEdge: "); 1569 appendVariableToMessage(message, args.inEdge); 1570 message.append("\n"); 1571 message.append("Input inV: "); 1572 appendVariableToMessage(message, args.inV); 1573 message.append("\n"); 1574 message.append("Expected output out: "); 1575 appendVariableToMessage(message, args.out); 1576 message.append("\n"); 1577 message.append("Actual output out: "); 1578 appendVariableToMessage(message, arrayOut[i * 4 + j]); 1579 message.append("\n"); 1580 message.append("Actual output out (in double): "); 1581 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j])); 1582 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 1583 message.append(" FAIL"); 1584 } 1585 message.append("\n"); 1586 message.append("Errors at"); 1587 } 1588 message.append(" ["); 1589 message.append(Integer.toString(i)); 1590 message.append(", "); 1591 message.append(Integer.toString(j)); 1592 message.append("]"); 1593 } 1594 } 1595 } 1596 assertFalse("Incorrect output for checkStepHalfHalf3Half3" + 1597 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 1598 } 1599 checkStepHalfHalf4Half4()1600 private void checkStepHalfHalf4Half4() { 1601 Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0xfd010215l, false); 1602 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0x58b0c5d6l, false); 1603 try { 1604 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE); 1605 script.set_gAllocInV(inV); 1606 script.forEach_testStepHalfHalf4Half4(inEdge, out); 1607 verifyResultsStepHalfHalf4Half4(inEdge, inV, out, false); 1608 } catch (Exception e) { 1609 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalfHalf4Half4: " + e.toString()); 1610 } 1611 try { 1612 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE); 1613 scriptRelaxed.set_gAllocInV(inV); 1614 scriptRelaxed.forEach_testStepHalfHalf4Half4(inEdge, out); 1615 verifyResultsStepHalfHalf4Half4(inEdge, inV, out, true); 1616 } catch (Exception e) { 1617 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalfHalf4Half4: " + e.toString()); 1618 } 1619 } 1620 verifyResultsStepHalfHalf4Half4(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed)1621 private void verifyResultsStepHalfHalf4Half4(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) { 1622 short[] arrayInEdge = new short[INPUTSIZE * 1]; 1623 Arrays.fill(arrayInEdge, (short) 42); 1624 inEdge.copyTo(arrayInEdge); 1625 short[] arrayInV = new short[INPUTSIZE * 4]; 1626 Arrays.fill(arrayInV, (short) 42); 1627 inV.copyTo(arrayInV); 1628 short[] arrayOut = new short[INPUTSIZE * 4]; 1629 Arrays.fill(arrayOut, (short) 42); 1630 out.copyTo(arrayOut); 1631 StringBuilder message = new StringBuilder(); 1632 boolean errorFound = false; 1633 for (int i = 0; i < INPUTSIZE; i++) { 1634 for (int j = 0; j < 4 ; j++) { 1635 // Extract the inputs. 1636 ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf(); 1637 args.inEdge = arrayInEdge[i]; 1638 args.inEdgeDouble = Float16Utils.convertFloat16ToDouble(args.inEdge); 1639 args.inV = arrayInV[i * 4 + j]; 1640 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV); 1641 // Figure out what the outputs should have been. 1642 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 1643 CoreMathVerifier.computeStep(args, target); 1644 // Validate the outputs. 1645 boolean valid = true; 1646 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 1647 valid = false; 1648 } 1649 if (!valid) { 1650 if (!errorFound) { 1651 errorFound = true; 1652 message.append("Input inEdge: "); 1653 appendVariableToMessage(message, args.inEdge); 1654 message.append("\n"); 1655 message.append("Input inV: "); 1656 appendVariableToMessage(message, args.inV); 1657 message.append("\n"); 1658 message.append("Expected output out: "); 1659 appendVariableToMessage(message, args.out); 1660 message.append("\n"); 1661 message.append("Actual output out: "); 1662 appendVariableToMessage(message, arrayOut[i * 4 + j]); 1663 message.append("\n"); 1664 message.append("Actual output out (in double): "); 1665 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j])); 1666 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 1667 message.append(" FAIL"); 1668 } 1669 message.append("\n"); 1670 message.append("Errors at"); 1671 } 1672 message.append(" ["); 1673 message.append(Integer.toString(i)); 1674 message.append(", "); 1675 message.append(Integer.toString(j)); 1676 message.append("]"); 1677 } 1678 } 1679 } 1680 assertFalse("Incorrect output for checkStepHalfHalf4Half4" + 1681 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 1682 } 1683 testStep()1684 public void testStep() { 1685 checkStepFloatFloatFloat(); 1686 checkStepFloat2Float2Float2(); 1687 checkStepFloat3Float3Float3(); 1688 checkStepFloat4Float4Float4(); 1689 checkStepHalfHalfHalf(); 1690 checkStepHalf2Half2Half2(); 1691 checkStepHalf3Half3Half3(); 1692 checkStepHalf4Half4Half4(); 1693 checkStepFloat2FloatFloat2(); 1694 checkStepFloat3FloatFloat3(); 1695 checkStepFloat4FloatFloat4(); 1696 checkStepHalf2HalfHalf2(); 1697 checkStepHalf3HalfHalf3(); 1698 checkStepHalf4HalfHalf4(); 1699 checkStepFloatFloat2Float2(); 1700 checkStepFloatFloat3Float3(); 1701 checkStepFloatFloat4Float4(); 1702 checkStepHalfHalf2Half2(); 1703 checkStepHalfHalf3Half3(); 1704 checkStepHalfHalf4Half4(); 1705 } 1706 } 1707