1 /* 2 * Copyright (C) 2014 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/gen_runtime. 18 19 package android.renderscript.cts; 20 21 import android.renderscript.Allocation; 22 import android.renderscript.RSRuntimeException; 23 import android.renderscript.Element; 24 25 public class TestRemquo extends RSBaseCompute { 26 27 private ScriptC_TestRemquo script; 28 private ScriptC_TestRemquoRelaxed scriptRelaxed; 29 30 @Override 31 protected void setUp() throws Exception { 32 super.setUp(); 33 script = new ScriptC_TestRemquo(mRS); 34 scriptRelaxed = new ScriptC_TestRemquoRelaxed(mRS); 35 } 36 37 public class ArgumentsFloatFloatIntFloat { 38 public float inB; 39 public float inC; 40 public int outD; 41 public float out; 42 } 43 44 private void checkRemquoFloatFloatIntFloat() { 45 Allocation inB = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x118af9b82db63b13l, false); 46 Allocation inC = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x118af9b82db63b14l, false); 47 try { 48 Allocation outD = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 1), INPUTSIZE); 49 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 50 script.set_gAllocInC(inC); 51 script.set_gAllocOutD(outD); 52 script.forEach_testRemquoFloatFloatIntFloat(inB, out); 53 verifyResultsRemquoFloatFloatIntFloat(inB, inC, outD, out, false); 54 } catch (Exception e) { 55 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testRemquoFloatFloatIntFloat: " + e.toString()); 56 } 57 try { 58 Allocation outD = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 1), INPUTSIZE); 59 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 60 scriptRelaxed.set_gAllocInC(inC); 61 scriptRelaxed.set_gAllocOutD(outD); 62 scriptRelaxed.forEach_testRemquoFloatFloatIntFloat(inB, out); 63 verifyResultsRemquoFloatFloatIntFloat(inB, inC, outD, out, true); 64 } catch (Exception e) { 65 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testRemquoFloatFloatIntFloat: " + e.toString()); 66 } 67 } 68 69 private void verifyResultsRemquoFloatFloatIntFloat(Allocation inB, Allocation inC, Allocation outD, Allocation out, boolean relaxed) { 70 float[] arrayInB = new float[INPUTSIZE * 1]; 71 inB.copyTo(arrayInB); 72 float[] arrayInC = new float[INPUTSIZE * 1]; 73 inC.copyTo(arrayInC); 74 int[] arrayOutD = new int[INPUTSIZE * 1]; 75 outD.copyTo(arrayOutD); 76 float[] arrayOut = new float[INPUTSIZE * 1]; 77 out.copyTo(arrayOut); 78 for (int i = 0; i < INPUTSIZE; i++) { 79 for (int j = 0; j < 1 ; j++) { 80 // Extract the inputs. 81 ArgumentsFloatFloatIntFloat args = new ArgumentsFloatFloatIntFloat(); 82 args.inB = arrayInB[i]; 83 args.inC = arrayInC[i]; 84 // Extract the outputs. 85 args.outD = arrayOutD[i * 1 + j]; 86 args.out = arrayOut[i * 1 + j]; 87 // Ask the CoreMathVerifier to validate. 88 Target target = new Target(relaxed); 89 String errorMessage = CoreMathVerifier.verifyRemquo(args, target); 90 boolean valid = errorMessage == null; 91 if (!valid) { 92 StringBuilder message = new StringBuilder(); 93 message.append("Input inB: "); 94 message.append(String.format("%14.8g {%8x} %15a", 95 args.inB, Float.floatToRawIntBits(args.inB), args.inB)); 96 message.append("\n"); 97 message.append("Input inC: "); 98 message.append(String.format("%14.8g {%8x} %15a", 99 args.inC, Float.floatToRawIntBits(args.inC), args.inC)); 100 message.append("\n"); 101 message.append("Output outD: "); 102 message.append(String.format("%d", args.outD)); 103 message.append("\n"); 104 message.append("Output out: "); 105 message.append(Float.toString(args.out)); 106 message.append("\n"); 107 message.append(errorMessage); 108 assertTrue("Incorrect output for checkRemquoFloatFloatIntFloat" + 109 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); 110 } 111 } 112 } 113 } 114 115 private void checkRemquoFloat2Float2Int2Float2() { 116 Allocation inB = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x9b98a1a6b125f903l, false); 117 Allocation inC = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x9b98a1a6b125f904l, false); 118 try { 119 Allocation outD = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 2), INPUTSIZE); 120 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 121 script.set_gAllocInC(inC); 122 script.set_gAllocOutD(outD); 123 script.forEach_testRemquoFloat2Float2Int2Float2(inB, out); 124 verifyResultsRemquoFloat2Float2Int2Float2(inB, inC, outD, out, false); 125 } catch (Exception e) { 126 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testRemquoFloat2Float2Int2Float2: " + e.toString()); 127 } 128 try { 129 Allocation outD = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 2), INPUTSIZE); 130 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 131 scriptRelaxed.set_gAllocInC(inC); 132 scriptRelaxed.set_gAllocOutD(outD); 133 scriptRelaxed.forEach_testRemquoFloat2Float2Int2Float2(inB, out); 134 verifyResultsRemquoFloat2Float2Int2Float2(inB, inC, outD, out, true); 135 } catch (Exception e) { 136 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testRemquoFloat2Float2Int2Float2: " + e.toString()); 137 } 138 } 139 140 private void verifyResultsRemquoFloat2Float2Int2Float2(Allocation inB, Allocation inC, Allocation outD, Allocation out, boolean relaxed) { 141 float[] arrayInB = new float[INPUTSIZE * 2]; 142 inB.copyTo(arrayInB); 143 float[] arrayInC = new float[INPUTSIZE * 2]; 144 inC.copyTo(arrayInC); 145 int[] arrayOutD = new int[INPUTSIZE * 2]; 146 outD.copyTo(arrayOutD); 147 float[] arrayOut = new float[INPUTSIZE * 2]; 148 out.copyTo(arrayOut); 149 for (int i = 0; i < INPUTSIZE; i++) { 150 for (int j = 0; j < 2 ; j++) { 151 // Extract the inputs. 152 ArgumentsFloatFloatIntFloat args = new ArgumentsFloatFloatIntFloat(); 153 args.inB = arrayInB[i * 2 + j]; 154 args.inC = arrayInC[i * 2 + j]; 155 // Extract the outputs. 156 args.outD = arrayOutD[i * 2 + j]; 157 args.out = arrayOut[i * 2 + j]; 158 // Ask the CoreMathVerifier to validate. 159 Target target = new Target(relaxed); 160 String errorMessage = CoreMathVerifier.verifyRemquo(args, target); 161 boolean valid = errorMessage == null; 162 if (!valid) { 163 StringBuilder message = new StringBuilder(); 164 message.append("Input inB: "); 165 message.append(String.format("%14.8g {%8x} %15a", 166 args.inB, Float.floatToRawIntBits(args.inB), args.inB)); 167 message.append("\n"); 168 message.append("Input inC: "); 169 message.append(String.format("%14.8g {%8x} %15a", 170 args.inC, Float.floatToRawIntBits(args.inC), args.inC)); 171 message.append("\n"); 172 message.append("Output outD: "); 173 message.append(String.format("%d", args.outD)); 174 message.append("\n"); 175 message.append("Output out: "); 176 message.append(Float.toString(args.out)); 177 message.append("\n"); 178 message.append(errorMessage); 179 assertTrue("Incorrect output for checkRemquoFloat2Float2Int2Float2" + 180 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); 181 } 182 } 183 } 184 } 185 186 private void checkRemquoFloat3Float3Int3Float3() { 187 Allocation inB = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xa049a00a6911ca8fl, false); 188 Allocation inC = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xa049a00a6911ca90l, false); 189 try { 190 Allocation outD = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 3), INPUTSIZE); 191 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 192 script.set_gAllocInC(inC); 193 script.set_gAllocOutD(outD); 194 script.forEach_testRemquoFloat3Float3Int3Float3(inB, out); 195 verifyResultsRemquoFloat3Float3Int3Float3(inB, inC, outD, out, false); 196 } catch (Exception e) { 197 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testRemquoFloat3Float3Int3Float3: " + e.toString()); 198 } 199 try { 200 Allocation outD = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 3), INPUTSIZE); 201 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 202 scriptRelaxed.set_gAllocInC(inC); 203 scriptRelaxed.set_gAllocOutD(outD); 204 scriptRelaxed.forEach_testRemquoFloat3Float3Int3Float3(inB, out); 205 verifyResultsRemquoFloat3Float3Int3Float3(inB, inC, outD, out, true); 206 } catch (Exception e) { 207 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testRemquoFloat3Float3Int3Float3: " + e.toString()); 208 } 209 } 210 211 private void verifyResultsRemquoFloat3Float3Int3Float3(Allocation inB, Allocation inC, Allocation outD, Allocation out, boolean relaxed) { 212 float[] arrayInB = new float[INPUTSIZE * 4]; 213 inB.copyTo(arrayInB); 214 float[] arrayInC = new float[INPUTSIZE * 4]; 215 inC.copyTo(arrayInC); 216 int[] arrayOutD = new int[INPUTSIZE * 4]; 217 outD.copyTo(arrayOutD); 218 float[] arrayOut = new float[INPUTSIZE * 4]; 219 out.copyTo(arrayOut); 220 for (int i = 0; i < INPUTSIZE; i++) { 221 for (int j = 0; j < 3 ; j++) { 222 // Extract the inputs. 223 ArgumentsFloatFloatIntFloat args = new ArgumentsFloatFloatIntFloat(); 224 args.inB = arrayInB[i * 4 + j]; 225 args.inC = arrayInC[i * 4 + j]; 226 // Extract the outputs. 227 args.outD = arrayOutD[i * 4 + j]; 228 args.out = arrayOut[i * 4 + j]; 229 // Ask the CoreMathVerifier to validate. 230 Target target = new Target(relaxed); 231 String errorMessage = CoreMathVerifier.verifyRemquo(args, target); 232 boolean valid = errorMessage == null; 233 if (!valid) { 234 StringBuilder message = new StringBuilder(); 235 message.append("Input inB: "); 236 message.append(String.format("%14.8g {%8x} %15a", 237 args.inB, Float.floatToRawIntBits(args.inB), args.inB)); 238 message.append("\n"); 239 message.append("Input inC: "); 240 message.append(String.format("%14.8g {%8x} %15a", 241 args.inC, Float.floatToRawIntBits(args.inC), args.inC)); 242 message.append("\n"); 243 message.append("Output outD: "); 244 message.append(String.format("%d", args.outD)); 245 message.append("\n"); 246 message.append("Output out: "); 247 message.append(Float.toString(args.out)); 248 message.append("\n"); 249 message.append(errorMessage); 250 assertTrue("Incorrect output for checkRemquoFloat3Float3Int3Float3" + 251 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); 252 } 253 } 254 } 255 } 256 257 private void checkRemquoFloat4Float4Int4Float4() { 258 Allocation inB = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xa4fa9e6e20fd9c1bl, false); 259 Allocation inC = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xa4fa9e6e20fd9c1cl, false); 260 try { 261 Allocation outD = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 4), INPUTSIZE); 262 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 263 script.set_gAllocInC(inC); 264 script.set_gAllocOutD(outD); 265 script.forEach_testRemquoFloat4Float4Int4Float4(inB, out); 266 verifyResultsRemquoFloat4Float4Int4Float4(inB, inC, outD, out, false); 267 } catch (Exception e) { 268 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testRemquoFloat4Float4Int4Float4: " + e.toString()); 269 } 270 try { 271 Allocation outD = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 4), INPUTSIZE); 272 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 273 scriptRelaxed.set_gAllocInC(inC); 274 scriptRelaxed.set_gAllocOutD(outD); 275 scriptRelaxed.forEach_testRemquoFloat4Float4Int4Float4(inB, out); 276 verifyResultsRemquoFloat4Float4Int4Float4(inB, inC, outD, out, true); 277 } catch (Exception e) { 278 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testRemquoFloat4Float4Int4Float4: " + e.toString()); 279 } 280 } 281 282 private void verifyResultsRemquoFloat4Float4Int4Float4(Allocation inB, Allocation inC, Allocation outD, Allocation out, boolean relaxed) { 283 float[] arrayInB = new float[INPUTSIZE * 4]; 284 inB.copyTo(arrayInB); 285 float[] arrayInC = new float[INPUTSIZE * 4]; 286 inC.copyTo(arrayInC); 287 int[] arrayOutD = new int[INPUTSIZE * 4]; 288 outD.copyTo(arrayOutD); 289 float[] arrayOut = new float[INPUTSIZE * 4]; 290 out.copyTo(arrayOut); 291 for (int i = 0; i < INPUTSIZE; i++) { 292 for (int j = 0; j < 4 ; j++) { 293 // Extract the inputs. 294 ArgumentsFloatFloatIntFloat args = new ArgumentsFloatFloatIntFloat(); 295 args.inB = arrayInB[i * 4 + j]; 296 args.inC = arrayInC[i * 4 + j]; 297 // Extract the outputs. 298 args.outD = arrayOutD[i * 4 + j]; 299 args.out = arrayOut[i * 4 + j]; 300 // Ask the CoreMathVerifier to validate. 301 Target target = new Target(relaxed); 302 String errorMessage = CoreMathVerifier.verifyRemquo(args, target); 303 boolean valid = errorMessage == null; 304 if (!valid) { 305 StringBuilder message = new StringBuilder(); 306 message.append("Input inB: "); 307 message.append(String.format("%14.8g {%8x} %15a", 308 args.inB, Float.floatToRawIntBits(args.inB), args.inB)); 309 message.append("\n"); 310 message.append("Input inC: "); 311 message.append(String.format("%14.8g {%8x} %15a", 312 args.inC, Float.floatToRawIntBits(args.inC), args.inC)); 313 message.append("\n"); 314 message.append("Output outD: "); 315 message.append(String.format("%d", args.outD)); 316 message.append("\n"); 317 message.append("Output out: "); 318 message.append(Float.toString(args.out)); 319 message.append("\n"); 320 message.append(errorMessage); 321 assertTrue("Incorrect output for checkRemquoFloat4Float4Int4Float4" + 322 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); 323 } 324 } 325 } 326 } 327 328 public void testRemquo() { 329 checkRemquoFloatFloatIntFloat(); 330 checkRemquoFloat2Float2Int2Float2(); 331 checkRemquoFloat3Float3Int3Float3(); 332 checkRemquoFloat4Float4Int4Float4(); 333 } 334 } 335