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 TestNativeSincos extends RSBaseCompute { 29 30 private ScriptC_TestNativeSincos script; 31 private ScriptC_TestNativeSincosRelaxed scriptRelaxed; 32 33 @Override setUp()34 protected void setUp() throws Exception { 35 super.setUp(); 36 script = new ScriptC_TestNativeSincos(mRS); 37 scriptRelaxed = new ScriptC_TestNativeSincosRelaxed(mRS); 38 } 39 40 public class ArgumentsFloatFloatFloat { 41 public float inV; 42 public Target.Floaty outCos; 43 public Target.Floaty out; 44 } 45 checkNativeSincosFloatFloatFloat()46 private void checkNativeSincosFloatFloatFloat() { 47 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x6436cc13l, false); 48 try { 49 Allocation outCos = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 50 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 51 script.set_gAllocOutCos(outCos); 52 script.forEach_testNativeSincosFloatFloatFloat(inV, out); 53 verifyResultsNativeSincosFloatFloatFloat(inV, outCos, out, false); 54 } catch (Exception e) { 55 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeSincosFloatFloatFloat: " + e.toString()); 56 } 57 try { 58 Allocation outCos = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 59 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 60 scriptRelaxed.set_gAllocOutCos(outCos); 61 scriptRelaxed.forEach_testNativeSincosFloatFloatFloat(inV, out); 62 verifyResultsNativeSincosFloatFloatFloat(inV, outCos, out, true); 63 } catch (Exception e) { 64 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeSincosFloatFloatFloat: " + e.toString()); 65 } 66 } 67 verifyResultsNativeSincosFloatFloatFloat(Allocation inV, Allocation outCos, Allocation out, boolean relaxed)68 private void verifyResultsNativeSincosFloatFloatFloat(Allocation inV, Allocation outCos, Allocation out, boolean relaxed) { 69 float[] arrayInV = new float[INPUTSIZE * 1]; 70 Arrays.fill(arrayInV, (float) 42); 71 inV.copyTo(arrayInV); 72 float[] arrayOutCos = new float[INPUTSIZE * 1]; 73 Arrays.fill(arrayOutCos, (float) 42); 74 outCos.copyTo(arrayOutCos); 75 float[] arrayOut = new float[INPUTSIZE * 1]; 76 Arrays.fill(arrayOut, (float) 42); 77 out.copyTo(arrayOut); 78 StringBuilder message = new StringBuilder(); 79 boolean errorFound = false; 80 for (int i = 0; i < INPUTSIZE; i++) { 81 for (int j = 0; j < 1 ; j++) { 82 // Extract the inputs. 83 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); 84 args.inV = arrayInV[i]; 85 // Figure out what the outputs should have been. 86 Target target = new Target(Target.FunctionType.NATIVE, Target.ReturnType.FLOAT, relaxed); 87 CoreMathVerifier.computeNativeSincos(args, target); 88 // Validate the outputs. 89 boolean valid = true; 90 if (!args.outCos.couldBe(arrayOutCos[i * 1 + j], 0.0005)) { 91 valid = false; 92 } 93 if (!args.out.couldBe(arrayOut[i * 1 + j], 0.0005)) { 94 valid = false; 95 } 96 if (!valid) { 97 if (!errorFound) { 98 errorFound = true; 99 message.append("Input inV: "); 100 appendVariableToMessage(message, args.inV); 101 message.append("\n"); 102 message.append("Expected output outCos: "); 103 appendVariableToMessage(message, args.outCos); 104 message.append("\n"); 105 message.append("Actual output outCos: "); 106 appendVariableToMessage(message, arrayOutCos[i * 1 + j]); 107 if (!args.outCos.couldBe(arrayOutCos[i * 1 + j], 0.0005)) { 108 message.append(" FAIL"); 109 } 110 message.append("\n"); 111 message.append("Expected output out: "); 112 appendVariableToMessage(message, args.out); 113 message.append("\n"); 114 message.append("Actual output out: "); 115 appendVariableToMessage(message, arrayOut[i * 1 + j]); 116 if (!args.out.couldBe(arrayOut[i * 1 + j], 0.0005)) { 117 message.append(" FAIL"); 118 } 119 message.append("\n"); 120 message.append("Errors at"); 121 } 122 message.append(" ["); 123 message.append(Integer.toString(i)); 124 message.append(", "); 125 message.append(Integer.toString(j)); 126 message.append("]"); 127 } 128 } 129 } 130 assertFalse("Incorrect output for checkNativeSincosFloatFloatFloat" + 131 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 132 } 133 checkNativeSincosFloat2Float2Float2()134 private void checkNativeSincosFloat2Float2Float2() { 135 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xda676ea9l, false); 136 try { 137 Allocation outCos = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 138 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 139 script.set_gAllocOutCos(outCos); 140 script.forEach_testNativeSincosFloat2Float2Float2(inV, out); 141 verifyResultsNativeSincosFloat2Float2Float2(inV, outCos, out, false); 142 } catch (Exception e) { 143 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeSincosFloat2Float2Float2: " + e.toString()); 144 } 145 try { 146 Allocation outCos = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 147 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 148 scriptRelaxed.set_gAllocOutCos(outCos); 149 scriptRelaxed.forEach_testNativeSincosFloat2Float2Float2(inV, out); 150 verifyResultsNativeSincosFloat2Float2Float2(inV, outCos, out, true); 151 } catch (Exception e) { 152 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeSincosFloat2Float2Float2: " + e.toString()); 153 } 154 } 155 verifyResultsNativeSincosFloat2Float2Float2(Allocation inV, Allocation outCos, Allocation out, boolean relaxed)156 private void verifyResultsNativeSincosFloat2Float2Float2(Allocation inV, Allocation outCos, Allocation out, boolean relaxed) { 157 float[] arrayInV = new float[INPUTSIZE * 2]; 158 Arrays.fill(arrayInV, (float) 42); 159 inV.copyTo(arrayInV); 160 float[] arrayOutCos = new float[INPUTSIZE * 2]; 161 Arrays.fill(arrayOutCos, (float) 42); 162 outCos.copyTo(arrayOutCos); 163 float[] arrayOut = new float[INPUTSIZE * 2]; 164 Arrays.fill(arrayOut, (float) 42); 165 out.copyTo(arrayOut); 166 StringBuilder message = new StringBuilder(); 167 boolean errorFound = false; 168 for (int i = 0; i < INPUTSIZE; i++) { 169 for (int j = 0; j < 2 ; j++) { 170 // Extract the inputs. 171 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); 172 args.inV = arrayInV[i * 2 + j]; 173 // Figure out what the outputs should have been. 174 Target target = new Target(Target.FunctionType.NATIVE, Target.ReturnType.FLOAT, relaxed); 175 CoreMathVerifier.computeNativeSincos(args, target); 176 // Validate the outputs. 177 boolean valid = true; 178 if (!args.outCos.couldBe(arrayOutCos[i * 2 + j], 0.0005)) { 179 valid = false; 180 } 181 if (!args.out.couldBe(arrayOut[i * 2 + j], 0.0005)) { 182 valid = false; 183 } 184 if (!valid) { 185 if (!errorFound) { 186 errorFound = true; 187 message.append("Input inV: "); 188 appendVariableToMessage(message, args.inV); 189 message.append("\n"); 190 message.append("Expected output outCos: "); 191 appendVariableToMessage(message, args.outCos); 192 message.append("\n"); 193 message.append("Actual output outCos: "); 194 appendVariableToMessage(message, arrayOutCos[i * 2 + j]); 195 if (!args.outCos.couldBe(arrayOutCos[i * 2 + j], 0.0005)) { 196 message.append(" FAIL"); 197 } 198 message.append("\n"); 199 message.append("Expected output out: "); 200 appendVariableToMessage(message, args.out); 201 message.append("\n"); 202 message.append("Actual output out: "); 203 appendVariableToMessage(message, arrayOut[i * 2 + j]); 204 if (!args.out.couldBe(arrayOut[i * 2 + j], 0.0005)) { 205 message.append(" FAIL"); 206 } 207 message.append("\n"); 208 message.append("Errors at"); 209 } 210 message.append(" ["); 211 message.append(Integer.toString(i)); 212 message.append(", "); 213 message.append(Integer.toString(j)); 214 message.append("]"); 215 } 216 } 217 } 218 assertFalse("Incorrect output for checkNativeSincosFloat2Float2Float2" + 219 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 220 } 221 checkNativeSincosFloat3Float3Float3()222 private void checkNativeSincosFloat3Float3Float3() { 223 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xdc45704al, false); 224 try { 225 Allocation outCos = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 226 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 227 script.set_gAllocOutCos(outCos); 228 script.forEach_testNativeSincosFloat3Float3Float3(inV, out); 229 verifyResultsNativeSincosFloat3Float3Float3(inV, outCos, out, false); 230 } catch (Exception e) { 231 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeSincosFloat3Float3Float3: " + e.toString()); 232 } 233 try { 234 Allocation outCos = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 235 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 236 scriptRelaxed.set_gAllocOutCos(outCos); 237 scriptRelaxed.forEach_testNativeSincosFloat3Float3Float3(inV, out); 238 verifyResultsNativeSincosFloat3Float3Float3(inV, outCos, out, true); 239 } catch (Exception e) { 240 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeSincosFloat3Float3Float3: " + e.toString()); 241 } 242 } 243 verifyResultsNativeSincosFloat3Float3Float3(Allocation inV, Allocation outCos, Allocation out, boolean relaxed)244 private void verifyResultsNativeSincosFloat3Float3Float3(Allocation inV, Allocation outCos, Allocation out, boolean relaxed) { 245 float[] arrayInV = new float[INPUTSIZE * 4]; 246 Arrays.fill(arrayInV, (float) 42); 247 inV.copyTo(arrayInV); 248 float[] arrayOutCos = new float[INPUTSIZE * 4]; 249 Arrays.fill(arrayOutCos, (float) 42); 250 outCos.copyTo(arrayOutCos); 251 float[] arrayOut = new float[INPUTSIZE * 4]; 252 Arrays.fill(arrayOut, (float) 42); 253 out.copyTo(arrayOut); 254 StringBuilder message = new StringBuilder(); 255 boolean errorFound = false; 256 for (int i = 0; i < INPUTSIZE; i++) { 257 for (int j = 0; j < 3 ; j++) { 258 // Extract the inputs. 259 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); 260 args.inV = arrayInV[i * 4 + j]; 261 // Figure out what the outputs should have been. 262 Target target = new Target(Target.FunctionType.NATIVE, Target.ReturnType.FLOAT, relaxed); 263 CoreMathVerifier.computeNativeSincos(args, target); 264 // Validate the outputs. 265 boolean valid = true; 266 if (!args.outCos.couldBe(arrayOutCos[i * 4 + j], 0.0005)) { 267 valid = false; 268 } 269 if (!args.out.couldBe(arrayOut[i * 4 + j], 0.0005)) { 270 valid = false; 271 } 272 if (!valid) { 273 if (!errorFound) { 274 errorFound = true; 275 message.append("Input inV: "); 276 appendVariableToMessage(message, args.inV); 277 message.append("\n"); 278 message.append("Expected output outCos: "); 279 appendVariableToMessage(message, args.outCos); 280 message.append("\n"); 281 message.append("Actual output outCos: "); 282 appendVariableToMessage(message, arrayOutCos[i * 4 + j]); 283 if (!args.outCos.couldBe(arrayOutCos[i * 4 + j], 0.0005)) { 284 message.append(" FAIL"); 285 } 286 message.append("\n"); 287 message.append("Expected output out: "); 288 appendVariableToMessage(message, args.out); 289 message.append("\n"); 290 message.append("Actual output out: "); 291 appendVariableToMessage(message, arrayOut[i * 4 + j]); 292 if (!args.out.couldBe(arrayOut[i * 4 + j], 0.0005)) { 293 message.append(" FAIL"); 294 } 295 message.append("\n"); 296 message.append("Errors at"); 297 } 298 message.append(" ["); 299 message.append(Integer.toString(i)); 300 message.append(", "); 301 message.append(Integer.toString(j)); 302 message.append("]"); 303 } 304 } 305 } 306 assertFalse("Incorrect output for checkNativeSincosFloat3Float3Float3" + 307 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 308 } 309 checkNativeSincosFloat4Float4Float4()310 private void checkNativeSincosFloat4Float4Float4() { 311 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xde2371ebl, false); 312 try { 313 Allocation outCos = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 314 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 315 script.set_gAllocOutCos(outCos); 316 script.forEach_testNativeSincosFloat4Float4Float4(inV, out); 317 verifyResultsNativeSincosFloat4Float4Float4(inV, outCos, out, false); 318 } catch (Exception e) { 319 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeSincosFloat4Float4Float4: " + e.toString()); 320 } 321 try { 322 Allocation outCos = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 323 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 324 scriptRelaxed.set_gAllocOutCos(outCos); 325 scriptRelaxed.forEach_testNativeSincosFloat4Float4Float4(inV, out); 326 verifyResultsNativeSincosFloat4Float4Float4(inV, outCos, out, true); 327 } catch (Exception e) { 328 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeSincosFloat4Float4Float4: " + e.toString()); 329 } 330 } 331 verifyResultsNativeSincosFloat4Float4Float4(Allocation inV, Allocation outCos, Allocation out, boolean relaxed)332 private void verifyResultsNativeSincosFloat4Float4Float4(Allocation inV, Allocation outCos, Allocation out, boolean relaxed) { 333 float[] arrayInV = new float[INPUTSIZE * 4]; 334 Arrays.fill(arrayInV, (float) 42); 335 inV.copyTo(arrayInV); 336 float[] arrayOutCos = new float[INPUTSIZE * 4]; 337 Arrays.fill(arrayOutCos, (float) 42); 338 outCos.copyTo(arrayOutCos); 339 float[] arrayOut = new float[INPUTSIZE * 4]; 340 Arrays.fill(arrayOut, (float) 42); 341 out.copyTo(arrayOut); 342 StringBuilder message = new StringBuilder(); 343 boolean errorFound = false; 344 for (int i = 0; i < INPUTSIZE; i++) { 345 for (int j = 0; j < 4 ; j++) { 346 // Extract the inputs. 347 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); 348 args.inV = arrayInV[i * 4 + j]; 349 // Figure out what the outputs should have been. 350 Target target = new Target(Target.FunctionType.NATIVE, Target.ReturnType.FLOAT, relaxed); 351 CoreMathVerifier.computeNativeSincos(args, target); 352 // Validate the outputs. 353 boolean valid = true; 354 if (!args.outCos.couldBe(arrayOutCos[i * 4 + j], 0.0005)) { 355 valid = false; 356 } 357 if (!args.out.couldBe(arrayOut[i * 4 + j], 0.0005)) { 358 valid = false; 359 } 360 if (!valid) { 361 if (!errorFound) { 362 errorFound = true; 363 message.append("Input inV: "); 364 appendVariableToMessage(message, args.inV); 365 message.append("\n"); 366 message.append("Expected output outCos: "); 367 appendVariableToMessage(message, args.outCos); 368 message.append("\n"); 369 message.append("Actual output outCos: "); 370 appendVariableToMessage(message, arrayOutCos[i * 4 + j]); 371 if (!args.outCos.couldBe(arrayOutCos[i * 4 + j], 0.0005)) { 372 message.append(" FAIL"); 373 } 374 message.append("\n"); 375 message.append("Expected output out: "); 376 appendVariableToMessage(message, args.out); 377 message.append("\n"); 378 message.append("Actual output out: "); 379 appendVariableToMessage(message, arrayOut[i * 4 + j]); 380 if (!args.out.couldBe(arrayOut[i * 4 + j], 0.0005)) { 381 message.append(" FAIL"); 382 } 383 message.append("\n"); 384 message.append("Errors at"); 385 } 386 message.append(" ["); 387 message.append(Integer.toString(i)); 388 message.append(", "); 389 message.append(Integer.toString(j)); 390 message.append("]"); 391 } 392 } 393 } 394 assertFalse("Incorrect output for checkNativeSincosFloat4Float4Float4" + 395 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 396 } 397 398 public class ArgumentsHalfHalfHalf { 399 public short inV; 400 public double inVDouble; 401 public Target.Floaty outCos; 402 public Target.Floaty out; 403 } 404 checkNativeSincosHalfHalfHalf()405 private void checkNativeSincosHalfHalfHalf() { 406 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0x75ce8c9al, false); 407 try { 408 Allocation outCos = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE); 409 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE); 410 script.set_gAllocOutCos(outCos); 411 script.forEach_testNativeSincosHalfHalfHalf(inV, out); 412 verifyResultsNativeSincosHalfHalfHalf(inV, outCos, out, false); 413 } catch (Exception e) { 414 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeSincosHalfHalfHalf: " + e.toString()); 415 } 416 try { 417 Allocation outCos = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE); 418 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE); 419 scriptRelaxed.set_gAllocOutCos(outCos); 420 scriptRelaxed.forEach_testNativeSincosHalfHalfHalf(inV, out); 421 verifyResultsNativeSincosHalfHalfHalf(inV, outCos, out, true); 422 } catch (Exception e) { 423 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeSincosHalfHalfHalf: " + e.toString()); 424 } 425 } 426 verifyResultsNativeSincosHalfHalfHalf(Allocation inV, Allocation outCos, Allocation out, boolean relaxed)427 private void verifyResultsNativeSincosHalfHalfHalf(Allocation inV, Allocation outCos, Allocation out, boolean relaxed) { 428 short[] arrayInV = new short[INPUTSIZE * 1]; 429 Arrays.fill(arrayInV, (short) 42); 430 inV.copyTo(arrayInV); 431 short[] arrayOutCos = new short[INPUTSIZE * 1]; 432 Arrays.fill(arrayOutCos, (short) 42); 433 outCos.copyTo(arrayOutCos); 434 short[] arrayOut = new short[INPUTSIZE * 1]; 435 Arrays.fill(arrayOut, (short) 42); 436 out.copyTo(arrayOut); 437 StringBuilder message = new StringBuilder(); 438 boolean errorFound = false; 439 for (int i = 0; i < INPUTSIZE; i++) { 440 for (int j = 0; j < 1 ; j++) { 441 // Extract the inputs. 442 ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf(); 443 args.inV = arrayInV[i]; 444 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV); 445 // Figure out what the outputs should have been. 446 Target target = new Target(Target.FunctionType.NATIVE, Target.ReturnType.HALF, relaxed); 447 CoreMathVerifier.computeNativeSincos(args, target); 448 // Validate the outputs. 449 boolean valid = true; 450 if (!args.outCos.couldBe(Float16Utils.convertFloat16ToDouble(arrayOutCos[i * 1 + j]), 0.00048828125)) { 451 valid = false; 452 } 453 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j]), 0.00048828125)) { 454 valid = false; 455 } 456 if (!valid) { 457 if (!errorFound) { 458 errorFound = true; 459 message.append("Input inV: "); 460 appendVariableToMessage(message, args.inV); 461 message.append("\n"); 462 message.append("Expected output outCos: "); 463 appendVariableToMessage(message, args.outCos); 464 message.append("\n"); 465 message.append("Actual output outCos: "); 466 appendVariableToMessage(message, arrayOutCos[i * 1 + j]); 467 message.append("\n"); 468 message.append("Actual output outCos (in double): "); 469 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOutCos[i * 1 + j])); 470 if (!args.outCos.couldBe(Float16Utils.convertFloat16ToDouble(arrayOutCos[i * 1 + j]), 0.00048828125)) { 471 message.append(" FAIL"); 472 } 473 message.append("\n"); 474 message.append("Expected output out: "); 475 appendVariableToMessage(message, args.out); 476 message.append("\n"); 477 message.append("Actual output out: "); 478 appendVariableToMessage(message, arrayOut[i * 1 + j]); 479 message.append("\n"); 480 message.append("Actual output out (in double): "); 481 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j])); 482 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j]), 0.00048828125)) { 483 message.append(" FAIL"); 484 } 485 message.append("\n"); 486 message.append("Errors at"); 487 } 488 message.append(" ["); 489 message.append(Integer.toString(i)); 490 message.append(", "); 491 message.append(Integer.toString(j)); 492 message.append("]"); 493 } 494 } 495 } 496 assertFalse("Incorrect output for checkNativeSincosHalfHalfHalf" + 497 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 498 } 499 checkNativeSincosHalf2Half2Half2()500 private void checkNativeSincosHalf2Half2Half2() { 501 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 2, 0x9b1d1008l, false); 502 try { 503 Allocation outCos = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE); 504 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE); 505 script.set_gAllocOutCos(outCos); 506 script.forEach_testNativeSincosHalf2Half2Half2(inV, out); 507 verifyResultsNativeSincosHalf2Half2Half2(inV, outCos, out, false); 508 } catch (Exception e) { 509 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeSincosHalf2Half2Half2: " + e.toString()); 510 } 511 try { 512 Allocation outCos = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE); 513 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE); 514 scriptRelaxed.set_gAllocOutCos(outCos); 515 scriptRelaxed.forEach_testNativeSincosHalf2Half2Half2(inV, out); 516 verifyResultsNativeSincosHalf2Half2Half2(inV, outCos, out, true); 517 } catch (Exception e) { 518 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeSincosHalf2Half2Half2: " + e.toString()); 519 } 520 } 521 verifyResultsNativeSincosHalf2Half2Half2(Allocation inV, Allocation outCos, Allocation out, boolean relaxed)522 private void verifyResultsNativeSincosHalf2Half2Half2(Allocation inV, Allocation outCos, Allocation out, boolean relaxed) { 523 short[] arrayInV = new short[INPUTSIZE * 2]; 524 Arrays.fill(arrayInV, (short) 42); 525 inV.copyTo(arrayInV); 526 short[] arrayOutCos = new short[INPUTSIZE * 2]; 527 Arrays.fill(arrayOutCos, (short) 42); 528 outCos.copyTo(arrayOutCos); 529 short[] arrayOut = new short[INPUTSIZE * 2]; 530 Arrays.fill(arrayOut, (short) 42); 531 out.copyTo(arrayOut); 532 StringBuilder message = new StringBuilder(); 533 boolean errorFound = false; 534 for (int i = 0; i < INPUTSIZE; i++) { 535 for (int j = 0; j < 2 ; j++) { 536 // Extract the inputs. 537 ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf(); 538 args.inV = arrayInV[i * 2 + j]; 539 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV); 540 // Figure out what the outputs should have been. 541 Target target = new Target(Target.FunctionType.NATIVE, Target.ReturnType.HALF, relaxed); 542 CoreMathVerifier.computeNativeSincos(args, target); 543 // Validate the outputs. 544 boolean valid = true; 545 if (!args.outCos.couldBe(Float16Utils.convertFloat16ToDouble(arrayOutCos[i * 2 + j]), 0.00048828125)) { 546 valid = false; 547 } 548 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]), 0.00048828125)) { 549 valid = false; 550 } 551 if (!valid) { 552 if (!errorFound) { 553 errorFound = true; 554 message.append("Input inV: "); 555 appendVariableToMessage(message, args.inV); 556 message.append("\n"); 557 message.append("Expected output outCos: "); 558 appendVariableToMessage(message, args.outCos); 559 message.append("\n"); 560 message.append("Actual output outCos: "); 561 appendVariableToMessage(message, arrayOutCos[i * 2 + j]); 562 message.append("\n"); 563 message.append("Actual output outCos (in double): "); 564 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOutCos[i * 2 + j])); 565 if (!args.outCos.couldBe(Float16Utils.convertFloat16ToDouble(arrayOutCos[i * 2 + j]), 0.00048828125)) { 566 message.append(" FAIL"); 567 } 568 message.append("\n"); 569 message.append("Expected output out: "); 570 appendVariableToMessage(message, args.out); 571 message.append("\n"); 572 message.append("Actual output out: "); 573 appendVariableToMessage(message, arrayOut[i * 2 + j]); 574 message.append("\n"); 575 message.append("Actual output out (in double): "); 576 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j])); 577 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]), 0.00048828125)) { 578 message.append(" FAIL"); 579 } 580 message.append("\n"); 581 message.append("Errors at"); 582 } 583 message.append(" ["); 584 message.append(Integer.toString(i)); 585 message.append(", "); 586 message.append(Integer.toString(j)); 587 message.append("]"); 588 } 589 } 590 } 591 assertFalse("Incorrect output for checkNativeSincosHalf2Half2Half2" + 592 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 593 } 594 checkNativeSincosHalf3Half3Half3()595 private void checkNativeSincosHalf3Half3Half3() { 596 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0xf9bc20d7l, false); 597 try { 598 Allocation outCos = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE); 599 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE); 600 script.set_gAllocOutCos(outCos); 601 script.forEach_testNativeSincosHalf3Half3Half3(inV, out); 602 verifyResultsNativeSincosHalf3Half3Half3(inV, outCos, out, false); 603 } catch (Exception e) { 604 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeSincosHalf3Half3Half3: " + e.toString()); 605 } 606 try { 607 Allocation outCos = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE); 608 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE); 609 scriptRelaxed.set_gAllocOutCos(outCos); 610 scriptRelaxed.forEach_testNativeSincosHalf3Half3Half3(inV, out); 611 verifyResultsNativeSincosHalf3Half3Half3(inV, outCos, out, true); 612 } catch (Exception e) { 613 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeSincosHalf3Half3Half3: " + e.toString()); 614 } 615 } 616 verifyResultsNativeSincosHalf3Half3Half3(Allocation inV, Allocation outCos, Allocation out, boolean relaxed)617 private void verifyResultsNativeSincosHalf3Half3Half3(Allocation inV, Allocation outCos, Allocation out, boolean relaxed) { 618 short[] arrayInV = new short[INPUTSIZE * 4]; 619 Arrays.fill(arrayInV, (short) 42); 620 inV.copyTo(arrayInV); 621 short[] arrayOutCos = new short[INPUTSIZE * 4]; 622 Arrays.fill(arrayOutCos, (short) 42); 623 outCos.copyTo(arrayOutCos); 624 short[] arrayOut = new short[INPUTSIZE * 4]; 625 Arrays.fill(arrayOut, (short) 42); 626 out.copyTo(arrayOut); 627 StringBuilder message = new StringBuilder(); 628 boolean errorFound = false; 629 for (int i = 0; i < INPUTSIZE; i++) { 630 for (int j = 0; j < 3 ; j++) { 631 // Extract the inputs. 632 ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf(); 633 args.inV = arrayInV[i * 4 + j]; 634 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV); 635 // Figure out what the outputs should have been. 636 Target target = new Target(Target.FunctionType.NATIVE, Target.ReturnType.HALF, relaxed); 637 CoreMathVerifier.computeNativeSincos(args, target); 638 // Validate the outputs. 639 boolean valid = true; 640 if (!args.outCos.couldBe(Float16Utils.convertFloat16ToDouble(arrayOutCos[i * 4 + j]), 0.00048828125)) { 641 valid = false; 642 } 643 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]), 0.00048828125)) { 644 valid = false; 645 } 646 if (!valid) { 647 if (!errorFound) { 648 errorFound = true; 649 message.append("Input inV: "); 650 appendVariableToMessage(message, args.inV); 651 message.append("\n"); 652 message.append("Expected output outCos: "); 653 appendVariableToMessage(message, args.outCos); 654 message.append("\n"); 655 message.append("Actual output outCos: "); 656 appendVariableToMessage(message, arrayOutCos[i * 4 + j]); 657 message.append("\n"); 658 message.append("Actual output outCos (in double): "); 659 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOutCos[i * 4 + j])); 660 if (!args.outCos.couldBe(Float16Utils.convertFloat16ToDouble(arrayOutCos[i * 4 + j]), 0.00048828125)) { 661 message.append(" FAIL"); 662 } 663 message.append("\n"); 664 message.append("Expected output out: "); 665 appendVariableToMessage(message, args.out); 666 message.append("\n"); 667 message.append("Actual output out: "); 668 appendVariableToMessage(message, arrayOut[i * 4 + j]); 669 message.append("\n"); 670 message.append("Actual output out (in double): "); 671 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j])); 672 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]), 0.00048828125)) { 673 message.append(" FAIL"); 674 } 675 message.append("\n"); 676 message.append("Errors at"); 677 } 678 message.append(" ["); 679 message.append(Integer.toString(i)); 680 message.append(", "); 681 message.append(Integer.toString(j)); 682 message.append("]"); 683 } 684 } 685 } 686 assertFalse("Incorrect output for checkNativeSincosHalf3Half3Half3" + 687 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 688 } 689 checkNativeSincosHalf4Half4Half4()690 private void checkNativeSincosHalf4Half4Half4() { 691 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0x585b31a6l, false); 692 try { 693 Allocation outCos = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE); 694 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE); 695 script.set_gAllocOutCos(outCos); 696 script.forEach_testNativeSincosHalf4Half4Half4(inV, out); 697 verifyResultsNativeSincosHalf4Half4Half4(inV, outCos, out, false); 698 } catch (Exception e) { 699 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeSincosHalf4Half4Half4: " + e.toString()); 700 } 701 try { 702 Allocation outCos = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE); 703 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE); 704 scriptRelaxed.set_gAllocOutCos(outCos); 705 scriptRelaxed.forEach_testNativeSincosHalf4Half4Half4(inV, out); 706 verifyResultsNativeSincosHalf4Half4Half4(inV, outCos, out, true); 707 } catch (Exception e) { 708 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeSincosHalf4Half4Half4: " + e.toString()); 709 } 710 } 711 verifyResultsNativeSincosHalf4Half4Half4(Allocation inV, Allocation outCos, Allocation out, boolean relaxed)712 private void verifyResultsNativeSincosHalf4Half4Half4(Allocation inV, Allocation outCos, Allocation out, boolean relaxed) { 713 short[] arrayInV = new short[INPUTSIZE * 4]; 714 Arrays.fill(arrayInV, (short) 42); 715 inV.copyTo(arrayInV); 716 short[] arrayOutCos = new short[INPUTSIZE * 4]; 717 Arrays.fill(arrayOutCos, (short) 42); 718 outCos.copyTo(arrayOutCos); 719 short[] arrayOut = new short[INPUTSIZE * 4]; 720 Arrays.fill(arrayOut, (short) 42); 721 out.copyTo(arrayOut); 722 StringBuilder message = new StringBuilder(); 723 boolean errorFound = false; 724 for (int i = 0; i < INPUTSIZE; i++) { 725 for (int j = 0; j < 4 ; j++) { 726 // Extract the inputs. 727 ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf(); 728 args.inV = arrayInV[i * 4 + j]; 729 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV); 730 // Figure out what the outputs should have been. 731 Target target = new Target(Target.FunctionType.NATIVE, Target.ReturnType.HALF, relaxed); 732 CoreMathVerifier.computeNativeSincos(args, target); 733 // Validate the outputs. 734 boolean valid = true; 735 if (!args.outCos.couldBe(Float16Utils.convertFloat16ToDouble(arrayOutCos[i * 4 + j]), 0.00048828125)) { 736 valid = false; 737 } 738 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]), 0.00048828125)) { 739 valid = false; 740 } 741 if (!valid) { 742 if (!errorFound) { 743 errorFound = true; 744 message.append("Input inV: "); 745 appendVariableToMessage(message, args.inV); 746 message.append("\n"); 747 message.append("Expected output outCos: "); 748 appendVariableToMessage(message, args.outCos); 749 message.append("\n"); 750 message.append("Actual output outCos: "); 751 appendVariableToMessage(message, arrayOutCos[i * 4 + j]); 752 message.append("\n"); 753 message.append("Actual output outCos (in double): "); 754 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOutCos[i * 4 + j])); 755 if (!args.outCos.couldBe(Float16Utils.convertFloat16ToDouble(arrayOutCos[i * 4 + j]), 0.00048828125)) { 756 message.append(" FAIL"); 757 } 758 message.append("\n"); 759 message.append("Expected output out: "); 760 appendVariableToMessage(message, args.out); 761 message.append("\n"); 762 message.append("Actual output out: "); 763 appendVariableToMessage(message, arrayOut[i * 4 + j]); 764 message.append("\n"); 765 message.append("Actual output out (in double): "); 766 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j])); 767 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]), 0.00048828125)) { 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 checkNativeSincosHalf4Half4Half4" + 782 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 783 } 784 testNativeSincos()785 public void testNativeSincos() { 786 checkNativeSincosFloatFloatFloat(); 787 checkNativeSincosFloat2Float2Float2(); 788 checkNativeSincosFloat3Float3Float3(); 789 checkNativeSincosFloat4Float4Float4(); 790 checkNativeSincosHalfHalfHalf(); 791 checkNativeSincosHalf2Half2Half2(); 792 checkNativeSincosHalf3Half3Half3(); 793 checkNativeSincosHalf4Half4Half4(); 794 } 795 } 796