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 TestCross extends RSBaseCompute { 29 30 private ScriptC_TestCross script; 31 private ScriptC_TestCrossRelaxed scriptRelaxed; 32 33 @Override setUp()34 protected void setUp() throws Exception { 35 super.setUp(); 36 script = new ScriptC_TestCross(mRS); 37 scriptRelaxed = new ScriptC_TestCrossRelaxed(mRS); 38 } 39 40 @Override tearDown()41 protected void tearDown() throws Exception { 42 script.destroy(); 43 scriptRelaxed.destroy(); 44 super.tearDown(); 45 } 46 47 public class ArgumentsFloatNFloatNFloatN { 48 public float[] inLeftVector; 49 public float[] inRightVector; 50 public Target.Floaty[] out; 51 } 52 checkCrossFloat3Float3Float3()53 private void checkCrossFloat3Float3Float3() { 54 Allocation inLeftVector = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x3505ebf7382f1ad4l, false); 55 Allocation inRightVector = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xe9d27bf3de024b21l, false); 56 try { 57 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 58 script.set_gAllocInRightVector(inRightVector); 59 script.forEach_testCrossFloat3Float3Float3(inLeftVector, out); 60 verifyResultsCrossFloat3Float3Float3(inLeftVector, inRightVector, out, false); 61 out.destroy(); 62 } catch (Exception e) { 63 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCrossFloat3Float3Float3: " + e.toString()); 64 } 65 try { 66 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 67 scriptRelaxed.set_gAllocInRightVector(inRightVector); 68 scriptRelaxed.forEach_testCrossFloat3Float3Float3(inLeftVector, out); 69 verifyResultsCrossFloat3Float3Float3(inLeftVector, inRightVector, out, true); 70 out.destroy(); 71 } catch (Exception e) { 72 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCrossFloat3Float3Float3: " + e.toString()); 73 } 74 inLeftVector.destroy(); 75 inRightVector.destroy(); 76 } 77 verifyResultsCrossFloat3Float3Float3(Allocation inLeftVector, Allocation inRightVector, Allocation out, boolean relaxed)78 private void verifyResultsCrossFloat3Float3Float3(Allocation inLeftVector, Allocation inRightVector, Allocation out, boolean relaxed) { 79 float[] arrayInLeftVector = new float[INPUTSIZE * 4]; 80 Arrays.fill(arrayInLeftVector, (float) 42); 81 inLeftVector.copyTo(arrayInLeftVector); 82 float[] arrayInRightVector = new float[INPUTSIZE * 4]; 83 Arrays.fill(arrayInRightVector, (float) 42); 84 inRightVector.copyTo(arrayInRightVector); 85 float[] arrayOut = new float[INPUTSIZE * 4]; 86 Arrays.fill(arrayOut, (float) 42); 87 out.copyTo(arrayOut); 88 StringBuilder message = new StringBuilder(); 89 boolean errorFound = false; 90 for (int i = 0; i < INPUTSIZE; i++) { 91 ArgumentsFloatNFloatNFloatN args = new ArgumentsFloatNFloatNFloatN(); 92 // Create the appropriate sized arrays in args 93 args.inLeftVector = new float[3]; 94 args.inRightVector = new float[3]; 95 args.out = new Target.Floaty[3]; 96 // Fill args with the input values 97 for (int j = 0; j < 3 ; j++) { 98 args.inLeftVector[j] = arrayInLeftVector[i * 4 + j]; 99 } 100 for (int j = 0; j < 3 ; j++) { 101 args.inRightVector[j] = arrayInRightVector[i * 4 + j]; 102 } 103 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 104 CoreMathVerifier.computeCross(args, target); 105 106 // Compare the expected outputs to the actual values returned by RS. 107 boolean valid = true; 108 for (int j = 0; j < 3 ; j++) { 109 if (!args.out[j].couldBe(arrayOut[i * 4 + j])) { 110 valid = false; 111 } 112 } 113 if (!valid) { 114 if (!errorFound) { 115 errorFound = true; 116 for (int j = 0; j < 3 ; j++) { 117 message.append("Input inLeftVector: "); 118 appendVariableToMessage(message, arrayInLeftVector[i * 4 + j]); 119 message.append("\n"); 120 } 121 for (int j = 0; j < 3 ; j++) { 122 message.append("Input inRightVector: "); 123 appendVariableToMessage(message, arrayInRightVector[i * 4 + j]); 124 message.append("\n"); 125 } 126 for (int j = 0; j < 3 ; j++) { 127 message.append("Expected output out: "); 128 appendVariableToMessage(message, args.out[j]); 129 message.append("\n"); 130 message.append("Actual output out: "); 131 appendVariableToMessage(message, arrayOut[i * 4 + j]); 132 if (!args.out[j].couldBe(arrayOut[i * 4 + j])) { 133 message.append(" FAIL"); 134 } 135 message.append("\n"); 136 } 137 message.append("Errors at"); 138 } 139 message.append(" ["); 140 message.append(Integer.toString(i)); 141 message.append("]"); 142 } 143 } 144 assertFalse("Incorrect output for checkCrossFloat3Float3Float3" + 145 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 146 } 147 checkCrossFloat4Float4Float4()148 private void checkCrossFloat4Float4Float4() { 149 Allocation inLeftVector = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x15fc58a5906fbeffl, false); 150 Allocation inRightVector = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xb336bd3cb0ddde5al, false); 151 try { 152 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 153 script.set_gAllocInRightVector(inRightVector); 154 script.forEach_testCrossFloat4Float4Float4(inLeftVector, out); 155 verifyResultsCrossFloat4Float4Float4(inLeftVector, inRightVector, out, false); 156 out.destroy(); 157 } catch (Exception e) { 158 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCrossFloat4Float4Float4: " + e.toString()); 159 } 160 try { 161 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 162 scriptRelaxed.set_gAllocInRightVector(inRightVector); 163 scriptRelaxed.forEach_testCrossFloat4Float4Float4(inLeftVector, out); 164 verifyResultsCrossFloat4Float4Float4(inLeftVector, inRightVector, out, true); 165 out.destroy(); 166 } catch (Exception e) { 167 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCrossFloat4Float4Float4: " + e.toString()); 168 } 169 inLeftVector.destroy(); 170 inRightVector.destroy(); 171 } 172 verifyResultsCrossFloat4Float4Float4(Allocation inLeftVector, Allocation inRightVector, Allocation out, boolean relaxed)173 private void verifyResultsCrossFloat4Float4Float4(Allocation inLeftVector, Allocation inRightVector, Allocation out, boolean relaxed) { 174 float[] arrayInLeftVector = new float[INPUTSIZE * 4]; 175 Arrays.fill(arrayInLeftVector, (float) 42); 176 inLeftVector.copyTo(arrayInLeftVector); 177 float[] arrayInRightVector = new float[INPUTSIZE * 4]; 178 Arrays.fill(arrayInRightVector, (float) 42); 179 inRightVector.copyTo(arrayInRightVector); 180 float[] arrayOut = new float[INPUTSIZE * 4]; 181 Arrays.fill(arrayOut, (float) 42); 182 out.copyTo(arrayOut); 183 StringBuilder message = new StringBuilder(); 184 boolean errorFound = false; 185 for (int i = 0; i < INPUTSIZE; i++) { 186 ArgumentsFloatNFloatNFloatN args = new ArgumentsFloatNFloatNFloatN(); 187 // Create the appropriate sized arrays in args 188 args.inLeftVector = new float[4]; 189 args.inRightVector = new float[4]; 190 args.out = new Target.Floaty[4]; 191 // Fill args with the input values 192 for (int j = 0; j < 4 ; j++) { 193 args.inLeftVector[j] = arrayInLeftVector[i * 4 + j]; 194 } 195 for (int j = 0; j < 4 ; j++) { 196 args.inRightVector[j] = arrayInRightVector[i * 4 + j]; 197 } 198 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 199 CoreMathVerifier.computeCross(args, target); 200 201 // Compare the expected outputs to the actual values returned by RS. 202 boolean valid = true; 203 for (int j = 0; j < 4 ; j++) { 204 if (!args.out[j].couldBe(arrayOut[i * 4 + j])) { 205 valid = false; 206 } 207 } 208 if (!valid) { 209 if (!errorFound) { 210 errorFound = true; 211 for (int j = 0; j < 4 ; j++) { 212 message.append("Input inLeftVector: "); 213 appendVariableToMessage(message, arrayInLeftVector[i * 4 + j]); 214 message.append("\n"); 215 } 216 for (int j = 0; j < 4 ; j++) { 217 message.append("Input inRightVector: "); 218 appendVariableToMessage(message, arrayInRightVector[i * 4 + j]); 219 message.append("\n"); 220 } 221 for (int j = 0; j < 4 ; j++) { 222 message.append("Expected output out: "); 223 appendVariableToMessage(message, args.out[j]); 224 message.append("\n"); 225 message.append("Actual output out: "); 226 appendVariableToMessage(message, arrayOut[i * 4 + j]); 227 if (!args.out[j].couldBe(arrayOut[i * 4 + j])) { 228 message.append(" FAIL"); 229 } 230 message.append("\n"); 231 } 232 message.append("Errors at"); 233 } 234 message.append(" ["); 235 message.append(Integer.toString(i)); 236 message.append("]"); 237 } 238 } 239 assertFalse("Incorrect output for checkCrossFloat4Float4Float4" + 240 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 241 } 242 243 public class ArgumentsHalfNHalfNHalfN { 244 public short[] inLeftVector; 245 public double[] inLeftVectorDouble; 246 public short[] inRightVector; 247 public double[] inRightVectorDouble; 248 public Target.Floaty[] out; 249 } 250 checkCrossHalf3Half3Half3()251 private void checkCrossHalf3Half3Half3() { 252 Allocation inLeftVector = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0x4c2f586fc3afdafl, false); 253 Allocation inRightVector = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0xce931719cc0165eal, false); 254 try { 255 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE); 256 script.set_gAllocInRightVector(inRightVector); 257 script.forEach_testCrossHalf3Half3Half3(inLeftVector, out); 258 verifyResultsCrossHalf3Half3Half3(inLeftVector, inRightVector, out, false); 259 out.destroy(); 260 } catch (Exception e) { 261 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCrossHalf3Half3Half3: " + e.toString()); 262 } 263 try { 264 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE); 265 scriptRelaxed.set_gAllocInRightVector(inRightVector); 266 scriptRelaxed.forEach_testCrossHalf3Half3Half3(inLeftVector, out); 267 verifyResultsCrossHalf3Half3Half3(inLeftVector, inRightVector, out, true); 268 out.destroy(); 269 } catch (Exception e) { 270 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCrossHalf3Half3Half3: " + e.toString()); 271 } 272 inLeftVector.destroy(); 273 inRightVector.destroy(); 274 } 275 verifyResultsCrossHalf3Half3Half3(Allocation inLeftVector, Allocation inRightVector, Allocation out, boolean relaxed)276 private void verifyResultsCrossHalf3Half3Half3(Allocation inLeftVector, Allocation inRightVector, Allocation out, boolean relaxed) { 277 short[] arrayInLeftVector = new short[INPUTSIZE * 4]; 278 Arrays.fill(arrayInLeftVector, (short) 42); 279 inLeftVector.copyTo(arrayInLeftVector); 280 short[] arrayInRightVector = new short[INPUTSIZE * 4]; 281 Arrays.fill(arrayInRightVector, (short) 42); 282 inRightVector.copyTo(arrayInRightVector); 283 short[] arrayOut = new short[INPUTSIZE * 4]; 284 Arrays.fill(arrayOut, (short) 42); 285 out.copyTo(arrayOut); 286 StringBuilder message = new StringBuilder(); 287 boolean errorFound = false; 288 for (int i = 0; i < INPUTSIZE; i++) { 289 ArgumentsHalfNHalfNHalfN args = new ArgumentsHalfNHalfNHalfN(); 290 // Create the appropriate sized arrays in args 291 args.inLeftVector = new short[3]; 292 args.inLeftVectorDouble = new double[3]; 293 args.inRightVector = new short[3]; 294 args.inRightVectorDouble = new double[3]; 295 args.out = new Target.Floaty[3]; 296 // Fill args with the input values 297 for (int j = 0; j < 3 ; j++) { 298 args.inLeftVector[j] = arrayInLeftVector[i * 4 + j]; 299 args.inLeftVectorDouble[j] = Float16Utils.convertFloat16ToDouble(args.inLeftVector[j]); 300 } 301 for (int j = 0; j < 3 ; j++) { 302 args.inRightVector[j] = arrayInRightVector[i * 4 + j]; 303 args.inRightVectorDouble[j] = Float16Utils.convertFloat16ToDouble(args.inRightVector[j]); 304 } 305 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 306 CoreMathVerifier.computeCross(args, target); 307 308 // Compare the expected outputs to the actual values returned by RS. 309 boolean valid = true; 310 for (int j = 0; j < 3 ; j++) { 311 if (!args.out[j].couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 312 valid = false; 313 } 314 } 315 if (!valid) { 316 if (!errorFound) { 317 errorFound = true; 318 for (int j = 0; j < 3 ; j++) { 319 message.append("Input inLeftVector: "); 320 appendVariableToMessage(message, arrayInLeftVector[i * 4 + j]); 321 message.append("\n"); 322 } 323 for (int j = 0; j < 3 ; j++) { 324 message.append("Input inRightVector: "); 325 appendVariableToMessage(message, arrayInRightVector[i * 4 + j]); 326 message.append("\n"); 327 } 328 for (int j = 0; j < 3 ; j++) { 329 message.append("Expected output out: "); 330 appendVariableToMessage(message, args.out[j]); 331 message.append("\n"); 332 message.append("Actual output out: "); 333 appendVariableToMessage(message, arrayOut[i * 4 + j]); 334 message.append("\n"); 335 message.append("Actual output out (in double): "); 336 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j])); 337 if (!args.out[j].couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 338 message.append(" FAIL"); 339 } 340 message.append("\n"); 341 } 342 message.append("Errors at"); 343 } 344 message.append(" ["); 345 message.append(Integer.toString(i)); 346 message.append("]"); 347 } 348 } 349 assertFalse("Incorrect output for checkCrossHalf3Half3Half3" + 350 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 351 } 352 checkCrossHalf4Half4Half4()353 private void checkCrossHalf4Half4Half4() { 354 Allocation inLeftVector = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0x5d701318a8692054l, false); 355 Allocation inRightVector = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0xb3a70e91b7c137a1l, false); 356 try { 357 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE); 358 script.set_gAllocInRightVector(inRightVector); 359 script.forEach_testCrossHalf4Half4Half4(inLeftVector, out); 360 verifyResultsCrossHalf4Half4Half4(inLeftVector, inRightVector, out, false); 361 out.destroy(); 362 } catch (Exception e) { 363 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCrossHalf4Half4Half4: " + e.toString()); 364 } 365 try { 366 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE); 367 scriptRelaxed.set_gAllocInRightVector(inRightVector); 368 scriptRelaxed.forEach_testCrossHalf4Half4Half4(inLeftVector, out); 369 verifyResultsCrossHalf4Half4Half4(inLeftVector, inRightVector, out, true); 370 out.destroy(); 371 } catch (Exception e) { 372 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCrossHalf4Half4Half4: " + e.toString()); 373 } 374 inLeftVector.destroy(); 375 inRightVector.destroy(); 376 } 377 verifyResultsCrossHalf4Half4Half4(Allocation inLeftVector, Allocation inRightVector, Allocation out, boolean relaxed)378 private void verifyResultsCrossHalf4Half4Half4(Allocation inLeftVector, Allocation inRightVector, Allocation out, boolean relaxed) { 379 short[] arrayInLeftVector = new short[INPUTSIZE * 4]; 380 Arrays.fill(arrayInLeftVector, (short) 42); 381 inLeftVector.copyTo(arrayInLeftVector); 382 short[] arrayInRightVector = new short[INPUTSIZE * 4]; 383 Arrays.fill(arrayInRightVector, (short) 42); 384 inRightVector.copyTo(arrayInRightVector); 385 short[] arrayOut = new short[INPUTSIZE * 4]; 386 Arrays.fill(arrayOut, (short) 42); 387 out.copyTo(arrayOut); 388 StringBuilder message = new StringBuilder(); 389 boolean errorFound = false; 390 for (int i = 0; i < INPUTSIZE; i++) { 391 ArgumentsHalfNHalfNHalfN args = new ArgumentsHalfNHalfNHalfN(); 392 // Create the appropriate sized arrays in args 393 args.inLeftVector = new short[4]; 394 args.inLeftVectorDouble = new double[4]; 395 args.inRightVector = new short[4]; 396 args.inRightVectorDouble = new double[4]; 397 args.out = new Target.Floaty[4]; 398 // Fill args with the input values 399 for (int j = 0; j < 4 ; j++) { 400 args.inLeftVector[j] = arrayInLeftVector[i * 4 + j]; 401 args.inLeftVectorDouble[j] = Float16Utils.convertFloat16ToDouble(args.inLeftVector[j]); 402 } 403 for (int j = 0; j < 4 ; j++) { 404 args.inRightVector[j] = arrayInRightVector[i * 4 + j]; 405 args.inRightVectorDouble[j] = Float16Utils.convertFloat16ToDouble(args.inRightVector[j]); 406 } 407 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 408 CoreMathVerifier.computeCross(args, target); 409 410 // Compare the expected outputs to the actual values returned by RS. 411 boolean valid = true; 412 for (int j = 0; j < 4 ; j++) { 413 if (!args.out[j].couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 414 valid = false; 415 } 416 } 417 if (!valid) { 418 if (!errorFound) { 419 errorFound = true; 420 for (int j = 0; j < 4 ; j++) { 421 message.append("Input inLeftVector: "); 422 appendVariableToMessage(message, arrayInLeftVector[i * 4 + j]); 423 message.append("\n"); 424 } 425 for (int j = 0; j < 4 ; j++) { 426 message.append("Input inRightVector: "); 427 appendVariableToMessage(message, arrayInRightVector[i * 4 + j]); 428 message.append("\n"); 429 } 430 for (int j = 0; j < 4 ; j++) { 431 message.append("Expected output out: "); 432 appendVariableToMessage(message, args.out[j]); 433 message.append("\n"); 434 message.append("Actual output out: "); 435 appendVariableToMessage(message, arrayOut[i * 4 + j]); 436 message.append("\n"); 437 message.append("Actual output out (in double): "); 438 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j])); 439 if (!args.out[j].couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 440 message.append(" FAIL"); 441 } 442 message.append("\n"); 443 } 444 message.append("Errors at"); 445 } 446 message.append(" ["); 447 message.append(Integer.toString(i)); 448 message.append("]"); 449 } 450 } 451 assertFalse("Incorrect output for checkCrossHalf4Half4Half4" + 452 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 453 } 454 testCross()455 public void testCross() { 456 checkCrossFloat3Float3Float3(); 457 checkCrossFloat4Float4Float4(); 458 checkCrossHalf3Half3Half3(); 459 checkCrossHalf4Half4Half4(); 460 } 461 } 462