blob: 88fb9d99a4c0911c066a03e00f47cfd69719df53 [file] [log] [blame]
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Don't edit this file! It is auto-generated by frameworks/rs/api/generate.sh.
package android.renderscript.cts;
import android.renderscript.Allocation;
import android.renderscript.RSRuntimeException;
import android.renderscript.Element;
import android.renderscript.cts.Target;
import java.util.Arrays;
public class TestStep extends RSBaseCompute {
private ScriptC_TestStep script;
private ScriptC_TestStepRelaxed scriptRelaxed;
@Override
protected void setUp() throws Exception {
super.setUp();
script = new ScriptC_TestStep(mRS);
scriptRelaxed = new ScriptC_TestStepRelaxed(mRS);
}
@Override
protected void tearDown() throws Exception {
script.destroy();
scriptRelaxed.destroy();
super.tearDown();
}
public class ArgumentsFloatFloatFloat {
public float inEdge;
public float inV;
public Target.Floaty out;
}
private void checkStepFloatFloatFloat() {
Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x598900c49184fbfel, false);
Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x9aefccaa832f44e9l, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
script.set_gAllocInV(inV);
script.forEach_testStepFloatFloatFloat(inEdge, out);
verifyResultsStepFloatFloatFloat(inEdge, inV, out, false);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloatFloatFloat: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
scriptRelaxed.set_gAllocInV(inV);
scriptRelaxed.forEach_testStepFloatFloatFloat(inEdge, out);
verifyResultsStepFloatFloatFloat(inEdge, inV, out, true);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloatFloatFloat: " + e.toString());
}
inEdge.destroy();
inV.destroy();
}
private void verifyResultsStepFloatFloatFloat(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) {
float[] arrayInEdge = new float[INPUTSIZE * 1];
Arrays.fill(arrayInEdge, (float) 42);
inEdge.copyTo(arrayInEdge);
float[] arrayInV = new float[INPUTSIZE * 1];
Arrays.fill(arrayInV, (float) 42);
inV.copyTo(arrayInV);
float[] arrayOut = new float[INPUTSIZE * 1];
Arrays.fill(arrayOut, (float) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 1 ; j++) {
// Extract the inputs.
ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat();
args.inEdge = arrayInEdge[i];
args.inV = arrayInV[i];
// Figure out what the outputs should have been.
Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
CoreMathVerifier.computeStep(args, target);
// Validate the outputs.
boolean valid = true;
if (!args.out.couldBe(arrayOut[i * 1 + j])) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inEdge: ");
appendVariableToMessage(message, args.inEdge);
message.append("\n");
message.append("Input inV: ");
appendVariableToMessage(message, args.inV);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 1 + j]);
if (!args.out.couldBe(arrayOut[i * 1 + j])) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkStepFloatFloatFloat" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkStepFloat2Float2Float2() {
Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x6efefa297df69504l, false);
Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x12eb000b8567f58bl, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
script.set_gAllocInV(inV);
script.forEach_testStepFloat2Float2Float2(inEdge, out);
verifyResultsStepFloat2Float2Float2(inEdge, inV, out, false);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloat2Float2Float2: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
scriptRelaxed.set_gAllocInV(inV);
scriptRelaxed.forEach_testStepFloat2Float2Float2(inEdge, out);
verifyResultsStepFloat2Float2Float2(inEdge, inV, out, true);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloat2Float2Float2: " + e.toString());
}
inEdge.destroy();
inV.destroy();
}
private void verifyResultsStepFloat2Float2Float2(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) {
float[] arrayInEdge = new float[INPUTSIZE * 2];
Arrays.fill(arrayInEdge, (float) 42);
inEdge.copyTo(arrayInEdge);
float[] arrayInV = new float[INPUTSIZE * 2];
Arrays.fill(arrayInV, (float) 42);
inV.copyTo(arrayInV);
float[] arrayOut = new float[INPUTSIZE * 2];
Arrays.fill(arrayOut, (float) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 2 ; j++) {
// Extract the inputs.
ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat();
args.inEdge = arrayInEdge[i * 2 + j];
args.inV = arrayInV[i * 2 + j];
// Figure out what the outputs should have been.
Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
CoreMathVerifier.computeStep(args, target);
// Validate the outputs.
boolean valid = true;
if (!args.out.couldBe(arrayOut[i * 2 + j])) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inEdge: ");
appendVariableToMessage(message, args.inEdge);
message.append("\n");
message.append("Input inV: ");
appendVariableToMessage(message, args.inV);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 2 + j]);
if (!args.out.couldBe(arrayOut[i * 2 + j])) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkStepFloat2Float2Float2" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkStepFloat3Float3Float3() {
Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x9e548cd666a7a77l, false);
Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x674fde2b8745f72cl, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
script.set_gAllocInV(inV);
script.forEach_testStepFloat3Float3Float3(inEdge, out);
verifyResultsStepFloat3Float3Float3(inEdge, inV, out, false);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloat3Float3Float3: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
scriptRelaxed.set_gAllocInV(inV);
scriptRelaxed.forEach_testStepFloat3Float3Float3(inEdge, out);
verifyResultsStepFloat3Float3Float3(inEdge, inV, out, true);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloat3Float3Float3: " + e.toString());
}
inEdge.destroy();
inV.destroy();
}
private void verifyResultsStepFloat3Float3Float3(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) {
float[] arrayInEdge = new float[INPUTSIZE * 4];
Arrays.fill(arrayInEdge, (float) 42);
inEdge.copyTo(arrayInEdge);
float[] arrayInV = new float[INPUTSIZE * 4];
Arrays.fill(arrayInV, (float) 42);
inV.copyTo(arrayInV);
float[] arrayOut = new float[INPUTSIZE * 4];
Arrays.fill(arrayOut, (float) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 3 ; j++) {
// Extract the inputs.
ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat();
args.inEdge = arrayInEdge[i * 4 + j];
args.inV = arrayInV[i * 4 + j];
// Figure out what the outputs should have been.
Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
CoreMathVerifier.computeStep(args, target);
// Validate the outputs.
boolean valid = true;
if (!args.out.couldBe(arrayOut[i * 4 + j])) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inEdge: ");
appendVariableToMessage(message, args.inEdge);
message.append("\n");
message.append("Input inV: ");
appendVariableToMessage(message, args.inV);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 4 + j]);
if (!args.out.couldBe(arrayOut[i * 4 + j])) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkStepFloat3Float3Float3" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkStepFloat4Float4Float4() {
Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xa4cb97714ede5feal, false);
Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xbbb4bc4b8923f8cdl, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
script.set_gAllocInV(inV);
script.forEach_testStepFloat4Float4Float4(inEdge, out);
verifyResultsStepFloat4Float4Float4(inEdge, inV, out, false);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloat4Float4Float4: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
scriptRelaxed.set_gAllocInV(inV);
scriptRelaxed.forEach_testStepFloat4Float4Float4(inEdge, out);
verifyResultsStepFloat4Float4Float4(inEdge, inV, out, true);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloat4Float4Float4: " + e.toString());
}
inEdge.destroy();
inV.destroy();
}
private void verifyResultsStepFloat4Float4Float4(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) {
float[] arrayInEdge = new float[INPUTSIZE * 4];
Arrays.fill(arrayInEdge, (float) 42);
inEdge.copyTo(arrayInEdge);
float[] arrayInV = new float[INPUTSIZE * 4];
Arrays.fill(arrayInV, (float) 42);
inV.copyTo(arrayInV);
float[] arrayOut = new float[INPUTSIZE * 4];
Arrays.fill(arrayOut, (float) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 4 ; j++) {
// Extract the inputs.
ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat();
args.inEdge = arrayInEdge[i * 4 + j];
args.inV = arrayInV[i * 4 + j];
// Figure out what the outputs should have been.
Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
CoreMathVerifier.computeStep(args, target);
// Validate the outputs.
boolean valid = true;
if (!args.out.couldBe(arrayOut[i * 4 + j])) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inEdge: ");
appendVariableToMessage(message, args.inEdge);
message.append("\n");
message.append("Input inV: ");
appendVariableToMessage(message, args.inV);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 4 + j]);
if (!args.out.couldBe(arrayOut[i * 4 + j])) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkStepFloat4Float4Float4" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
public class ArgumentsHalfHalfHalf {
public short inEdge;
public double inEdgeDouble;
public short inV;
public double inVDouble;
public Target.Floaty out;
}
private void checkStepHalfHalfHalf() {
Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0x5b86b69ee2c3f577l, false);
Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0xba03c0b83240702cl, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE);
script.set_gAllocInV(inV);
script.forEach_testStepHalfHalfHalf(inEdge, out);
verifyResultsStepHalfHalfHalf(inEdge, inV, out, false);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalfHalfHalf: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE);
scriptRelaxed.set_gAllocInV(inV);
scriptRelaxed.forEach_testStepHalfHalfHalf(inEdge, out);
verifyResultsStepHalfHalfHalf(inEdge, inV, out, true);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalfHalfHalf: " + e.toString());
}
inEdge.destroy();
inV.destroy();
}
private void verifyResultsStepHalfHalfHalf(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) {
short[] arrayInEdge = new short[INPUTSIZE * 1];
Arrays.fill(arrayInEdge, (short) 42);
inEdge.copyTo(arrayInEdge);
short[] arrayInV = new short[INPUTSIZE * 1];
Arrays.fill(arrayInV, (short) 42);
inV.copyTo(arrayInV);
short[] arrayOut = new short[INPUTSIZE * 1];
Arrays.fill(arrayOut, (short) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 1 ; j++) {
// Extract the inputs.
ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf();
args.inEdge = arrayInEdge[i];
args.inEdgeDouble = Float16Utils.convertFloat16ToDouble(args.inEdge);
args.inV = arrayInV[i];
args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV);
// Figure out what the outputs should have been.
Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
CoreMathVerifier.computeStep(args, target);
// Validate the outputs.
boolean valid = true;
if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j]))) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inEdge: ");
appendVariableToMessage(message, args.inEdge);
message.append("\n");
message.append("Input inV: ");
appendVariableToMessage(message, args.inV);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 1 + j]);
message.append("\n");
message.append("Actual output out (in double): ");
appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j]));
if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j]))) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkStepHalfHalfHalf" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkStepHalf2Half2Half2() {
Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 2, 0x670e5805ee08afadl, false);
Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 2, 0x6a600ec7ba1588del, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE);
script.set_gAllocInV(inV);
script.forEach_testStepHalf2Half2Half2(inEdge, out);
verifyResultsStepHalf2Half2Half2(inEdge, inV, out, false);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalf2Half2Half2: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE);
scriptRelaxed.set_gAllocInV(inV);
scriptRelaxed.forEach_testStepHalf2Half2Half2(inEdge, out);
verifyResultsStepHalf2Half2Half2(inEdge, inV, out, true);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalf2Half2Half2: " + e.toString());
}
inEdge.destroy();
inV.destroy();
}
private void verifyResultsStepHalf2Half2Half2(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) {
short[] arrayInEdge = new short[INPUTSIZE * 2];
Arrays.fill(arrayInEdge, (short) 42);
inEdge.copyTo(arrayInEdge);
short[] arrayInV = new short[INPUTSIZE * 2];
Arrays.fill(arrayInV, (short) 42);
inV.copyTo(arrayInV);
short[] arrayOut = new short[INPUTSIZE * 2];
Arrays.fill(arrayOut, (short) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 2 ; j++) {
// Extract the inputs.
ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf();
args.inEdge = arrayInEdge[i * 2 + j];
args.inEdgeDouble = Float16Utils.convertFloat16ToDouble(args.inEdge);
args.inV = arrayInV[i * 2 + j];
args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV);
// Figure out what the outputs should have been.
Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
CoreMathVerifier.computeStep(args, target);
// Validate the outputs.
boolean valid = true;
if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inEdge: ");
appendVariableToMessage(message, args.inEdge);
message.append("\n");
message.append("Input inV: ");
appendVariableToMessage(message, args.inV);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 2 + j]);
message.append("\n");
message.append("Actual output out (in double): ");
appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]));
if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkStepHalf2Half2Half2" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkStepHalf3Half3Half3() {
Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0xa098639be1ba008al, false);
Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0x90148eb118b499adl, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE);
script.set_gAllocInV(inV);
script.forEach_testStepHalf3Half3Half3(inEdge, out);
verifyResultsStepHalf3Half3Half3(inEdge, inV, out, false);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalf3Half3Half3: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE);
scriptRelaxed.set_gAllocInV(inV);
scriptRelaxed.forEach_testStepHalf3Half3Half3(inEdge, out);
verifyResultsStepHalf3Half3Half3(inEdge, inV, out, true);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalf3Half3Half3: " + e.toString());
}
inEdge.destroy();
inV.destroy();
}
private void verifyResultsStepHalf3Half3Half3(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) {
short[] arrayInEdge = new short[INPUTSIZE * 4];
Arrays.fill(arrayInEdge, (short) 42);
inEdge.copyTo(arrayInEdge);
short[] arrayInV = new short[INPUTSIZE * 4];
Arrays.fill(arrayInV, (short) 42);
inV.copyTo(arrayInV);
short[] arrayOut = new short[INPUTSIZE * 4];
Arrays.fill(arrayOut, (short) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 3 ; j++) {
// Extract the inputs.
ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf();
args.inEdge = arrayInEdge[i * 4 + j];
args.inEdgeDouble = Float16Utils.convertFloat16ToDouble(args.inEdge);
args.inV = arrayInV[i * 4 + j];
args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV);
// Figure out what the outputs should have been.
Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
CoreMathVerifier.computeStep(args, target);
// Validate the outputs.
boolean valid = true;
if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inEdge: ");
appendVariableToMessage(message, args.inEdge);
message.append("\n");
message.append("Input inV: ");
appendVariableToMessage(message, args.inV);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 4 + j]);
message.append("\n");
message.append("Actual output out (in double): ");
appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]));
if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkStepHalf3Half3Half3" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkStepHalf4Half4Half4() {
Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0xda226f31d56b5167l, false);
Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0xb5c90e9a7753aa7cl, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE);
script.set_gAllocInV(inV);
script.forEach_testStepHalf4Half4Half4(inEdge, out);
verifyResultsStepHalf4Half4Half4(inEdge, inV, out, false);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalf4Half4Half4: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE);
scriptRelaxed.set_gAllocInV(inV);
scriptRelaxed.forEach_testStepHalf4Half4Half4(inEdge, out);
verifyResultsStepHalf4Half4Half4(inEdge, inV, out, true);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalf4Half4Half4: " + e.toString());
}
inEdge.destroy();
inV.destroy();
}
private void verifyResultsStepHalf4Half4Half4(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) {
short[] arrayInEdge = new short[INPUTSIZE * 4];
Arrays.fill(arrayInEdge, (short) 42);
inEdge.copyTo(arrayInEdge);
short[] arrayInV = new short[INPUTSIZE * 4];
Arrays.fill(arrayInV, (short) 42);
inV.copyTo(arrayInV);
short[] arrayOut = new short[INPUTSIZE * 4];
Arrays.fill(arrayOut, (short) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 4 ; j++) {
// Extract the inputs.
ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf();
args.inEdge = arrayInEdge[i * 4 + j];
args.inEdgeDouble = Float16Utils.convertFloat16ToDouble(args.inEdge);
args.inV = arrayInV[i * 4 + j];
args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV);
// Figure out what the outputs should have been.
Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
CoreMathVerifier.computeStep(args, target);
// Validate the outputs.
boolean valid = true;
if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inEdge: ");
appendVariableToMessage(message, args.inEdge);
message.append("\n");
message.append("Input inV: ");
appendVariableToMessage(message, args.inV);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 4 + j]);
message.append("\n");
message.append("Actual output out (in double): ");
appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]));
if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkStepHalf4Half4Half4" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkStepFloat2FloatFloat2() {
Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xb0ac06c45b3d8b26l, false);
Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xfa7d66f2b6d48a21l, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
script.set_gAllocInV(inV);
script.forEach_testStepFloat2FloatFloat2(inEdge, out);
verifyResultsStepFloat2FloatFloat2(inEdge, inV, out, false);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloat2FloatFloat2: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
scriptRelaxed.set_gAllocInV(inV);
scriptRelaxed.forEach_testStepFloat2FloatFloat2(inEdge, out);
verifyResultsStepFloat2FloatFloat2(inEdge, inV, out, true);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloat2FloatFloat2: " + e.toString());
}
inEdge.destroy();
inV.destroy();
}
private void verifyResultsStepFloat2FloatFloat2(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) {
float[] arrayInEdge = new float[INPUTSIZE * 2];
Arrays.fill(arrayInEdge, (float) 42);
inEdge.copyTo(arrayInEdge);
float[] arrayInV = new float[INPUTSIZE * 1];
Arrays.fill(arrayInV, (float) 42);
inV.copyTo(arrayInV);
float[] arrayOut = new float[INPUTSIZE * 2];
Arrays.fill(arrayOut, (float) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 2 ; j++) {
// Extract the inputs.
ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat();
args.inEdge = arrayInEdge[i * 2 + j];
args.inV = arrayInV[i];
// Figure out what the outputs should have been.
Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
CoreMathVerifier.computeStep(args, target);
// Validate the outputs.
boolean valid = true;
if (!args.out.couldBe(arrayOut[i * 2 + j])) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inEdge: ");
appendVariableToMessage(message, args.inEdge);
message.append("\n");
message.append("Input inV: ");
appendVariableToMessage(message, args.inV);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 2 + j]);
if (!args.out.couldBe(arrayOut[i * 2 + j])) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkStepFloat2FloatFloat2" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkStepFloat3FloatFloat3() {
Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x304ed837c68f43fal, false);
Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x4fcd1a0aa53f7e7dl, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
script.set_gAllocInV(inV);
script.forEach_testStepFloat3FloatFloat3(inEdge, out);
verifyResultsStepFloat3FloatFloat3(inEdge, inV, out, false);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloat3FloatFloat3: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
scriptRelaxed.set_gAllocInV(inV);
scriptRelaxed.forEach_testStepFloat3FloatFloat3(inEdge, out);
verifyResultsStepFloat3FloatFloat3(inEdge, inV, out, true);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloat3FloatFloat3: " + e.toString());
}
inEdge.destroy();
inV.destroy();
}
private void verifyResultsStepFloat3FloatFloat3(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) {
float[] arrayInEdge = new float[INPUTSIZE * 4];
Arrays.fill(arrayInEdge, (float) 42);
inEdge.copyTo(arrayInEdge);
float[] arrayInV = new float[INPUTSIZE * 1];
Arrays.fill(arrayInV, (float) 42);
inV.copyTo(arrayInV);
float[] arrayOut = new float[INPUTSIZE * 4];
Arrays.fill(arrayOut, (float) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 3 ; j++) {
// Extract the inputs.
ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat();
args.inEdge = arrayInEdge[i * 4 + j];
args.inV = arrayInV[i];
// Figure out what the outputs should have been.
Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
CoreMathVerifier.computeStep(args, target);
// Validate the outputs.
boolean valid = true;
if (!args.out.couldBe(arrayOut[i * 4 + j])) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inEdge: ");
appendVariableToMessage(message, args.inEdge);
message.append("\n");
message.append("Input inV: ");
appendVariableToMessage(message, args.inV);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 4 + j]);
if (!args.out.couldBe(arrayOut[i * 4 + j])) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkStepFloat3FloatFloat3" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkStepFloat4FloatFloat4() {
Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xaff1a9ab31e0fccel, false);
Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xa51ccd2293aa72d9l, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
script.set_gAllocInV(inV);
script.forEach_testStepFloat4FloatFloat4(inEdge, out);
verifyResultsStepFloat4FloatFloat4(inEdge, inV, out, false);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloat4FloatFloat4: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
scriptRelaxed.set_gAllocInV(inV);
scriptRelaxed.forEach_testStepFloat4FloatFloat4(inEdge, out);
verifyResultsStepFloat4FloatFloat4(inEdge, inV, out, true);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloat4FloatFloat4: " + e.toString());
}
inEdge.destroy();
inV.destroy();
}
private void verifyResultsStepFloat4FloatFloat4(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) {
float[] arrayInEdge = new float[INPUTSIZE * 4];
Arrays.fill(arrayInEdge, (float) 42);
inEdge.copyTo(arrayInEdge);
float[] arrayInV = new float[INPUTSIZE * 1];
Arrays.fill(arrayInV, (float) 42);
inV.copyTo(arrayInV);
float[] arrayOut = new float[INPUTSIZE * 4];
Arrays.fill(arrayOut, (float) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 4 ; j++) {
// Extract the inputs.
ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat();
args.inEdge = arrayInEdge[i * 4 + j];
args.inV = arrayInV[i];
// Figure out what the outputs should have been.
Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
CoreMathVerifier.computeStep(args, target);
// Validate the outputs.
boolean valid = true;
if (!args.out.couldBe(arrayOut[i * 4 + j])) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inEdge: ");
appendVariableToMessage(message, args.inEdge);
message.append("\n");
message.append("Input inV: ");
appendVariableToMessage(message, args.inV);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 4 + j]);
if (!args.out.couldBe(arrayOut[i * 4 + j])) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkStepFloat4FloatFloat4" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkStepHalf2HalfHalf2() {
Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 2, 0x5690fcfb2f4438d3l, false);
Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0x974fa6ac002d7ce0l, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE);
script.set_gAllocInV(inV);
script.forEach_testStepHalf2HalfHalf2(inEdge, out);
verifyResultsStepHalf2HalfHalf2(inEdge, inV, out, false);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalf2HalfHalf2: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE);
scriptRelaxed.set_gAllocInV(inV);
scriptRelaxed.forEach_testStepHalf2HalfHalf2(inEdge, out);
verifyResultsStepHalf2HalfHalf2(inEdge, inV, out, true);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalf2HalfHalf2: " + e.toString());
}
inEdge.destroy();
inV.destroy();
}
private void verifyResultsStepHalf2HalfHalf2(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) {
short[] arrayInEdge = new short[INPUTSIZE * 2];
Arrays.fill(arrayInEdge, (short) 42);
inEdge.copyTo(arrayInEdge);
short[] arrayInV = new short[INPUTSIZE * 1];
Arrays.fill(arrayInV, (short) 42);
inV.copyTo(arrayInV);
short[] arrayOut = new short[INPUTSIZE * 2];
Arrays.fill(arrayOut, (short) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 2 ; j++) {
// Extract the inputs.
ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf();
args.inEdge = arrayInEdge[i * 2 + j];
args.inEdgeDouble = Float16Utils.convertFloat16ToDouble(args.inEdge);
args.inV = arrayInV[i];
args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV);
// Figure out what the outputs should have been.
Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
CoreMathVerifier.computeStep(args, target);
// Validate the outputs.
boolean valid = true;
if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inEdge: ");
appendVariableToMessage(message, args.inEdge);
message.append("\n");
message.append("Input inV: ");
appendVariableToMessage(message, args.inV);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 2 + j]);
message.append("\n");
message.append("Actual output out (in double): ");
appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]));
if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkStepHalf2HalfHalf2" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkStepHalf3HalfHalf3() {
Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0xaaf41201b3cf71ffl, false);
Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0xc1dcc72ab2c70e84l, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE);
script.set_gAllocInV(inV);
script.forEach_testStepHalf3HalfHalf3(inEdge, out);
verifyResultsStepHalf3HalfHalf3(inEdge, inV, out, false);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalf3HalfHalf3: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE);
scriptRelaxed.set_gAllocInV(inV);
scriptRelaxed.forEach_testStepHalf3HalfHalf3(inEdge, out);
verifyResultsStepHalf3HalfHalf3(inEdge, inV, out, true);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalf3HalfHalf3: " + e.toString());
}
inEdge.destroy();
inV.destroy();
}
private void verifyResultsStepHalf3HalfHalf3(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) {
short[] arrayInEdge = new short[INPUTSIZE * 4];
Arrays.fill(arrayInEdge, (short) 42);
inEdge.copyTo(arrayInEdge);
short[] arrayInV = new short[INPUTSIZE * 1];
Arrays.fill(arrayInV, (short) 42);
inV.copyTo(arrayInV);
short[] arrayOut = new short[INPUTSIZE * 4];
Arrays.fill(arrayOut, (short) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 3 ; j++) {
// Extract the inputs.
ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf();
args.inEdge = arrayInEdge[i * 4 + j];
args.inEdgeDouble = Float16Utils.convertFloat16ToDouble(args.inEdge);
args.inV = arrayInV[i];
args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV);
// Figure out what the outputs should have been.
Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
CoreMathVerifier.computeStep(args, target);
// Validate the outputs.
boolean valid = true;
if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inEdge: ");
appendVariableToMessage(message, args.inEdge);
message.append("\n");
message.append("Input inV: ");
appendVariableToMessage(message, args.inV);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 4 + j]);
message.append("\n");
message.append("Actual output out (in double): ");
appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]));
if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkStepHalf3HalfHalf3" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkStepHalf4HalfHalf4() {
Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0xff572708385aab2bl, false);
Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0xec69e7a96560a028l, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE);
script.set_gAllocInV(inV);
script.forEach_testStepHalf4HalfHalf4(inEdge, out);
verifyResultsStepHalf4HalfHalf4(inEdge, inV, out, false);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalf4HalfHalf4: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE);
scriptRelaxed.set_gAllocInV(inV);
scriptRelaxed.forEach_testStepHalf4HalfHalf4(inEdge, out);
verifyResultsStepHalf4HalfHalf4(inEdge, inV, out, true);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalf4HalfHalf4: " + e.toString());
}
inEdge.destroy();
inV.destroy();
}
private void verifyResultsStepHalf4HalfHalf4(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) {
short[] arrayInEdge = new short[INPUTSIZE * 4];
Arrays.fill(arrayInEdge, (short) 42);
inEdge.copyTo(arrayInEdge);
short[] arrayInV = new short[INPUTSIZE * 1];
Arrays.fill(arrayInV, (short) 42);
inV.copyTo(arrayInV);
short[] arrayOut = new short[INPUTSIZE * 4];
Arrays.fill(arrayOut, (short) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 4 ; j++) {
// Extract the inputs.
ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf();
args.inEdge = arrayInEdge[i * 4 + j];
args.inEdgeDouble = Float16Utils.convertFloat16ToDouble(args.inEdge);
args.inV = arrayInV[i];
args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV);
// Figure out what the outputs should have been.
Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
CoreMathVerifier.computeStep(args, target);
// Validate the outputs.
boolean valid = true;
if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inEdge: ");
appendVariableToMessage(message, args.inEdge);
message.append("\n");
message.append("Input inV: ");
appendVariableToMessage(message, args.inV);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 4 + j]);
message.append("\n");
message.append("Actual output out (in double): ");
appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]));
if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkStepHalf4HalfHalf4" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkStepFloatFloat2Float2() {
Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x70a0554e664b1852l, false);
Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xdd7f0d444e2f7c5l, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
script.set_gAllocInV(inV);
script.forEach_testStepFloatFloat2Float2(inEdge, out);
verifyResultsStepFloatFloat2Float2(inEdge, inV, out, false);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloatFloat2Float2: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
scriptRelaxed.set_gAllocInV(inV);
scriptRelaxed.forEach_testStepFloatFloat2Float2(inEdge, out);
verifyResultsStepFloatFloat2Float2(inEdge, inV, out, true);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloatFloat2Float2: " + e.toString());
}
inEdge.destroy();
inV.destroy();
}
private void verifyResultsStepFloatFloat2Float2(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) {
float[] arrayInEdge = new float[INPUTSIZE * 1];
Arrays.fill(arrayInEdge, (float) 42);
inEdge.copyTo(arrayInEdge);
float[] arrayInV = new float[INPUTSIZE * 2];
Arrays.fill(arrayInV, (float) 42);
inV.copyTo(arrayInV);
float[] arrayOut = new float[INPUTSIZE * 2];
Arrays.fill(arrayOut, (float) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 2 ; j++) {
// Extract the inputs.
ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat();
args.inEdge = arrayInEdge[i];
args.inV = arrayInV[i * 2 + j];
// Figure out what the outputs should have been.
Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
CoreMathVerifier.computeStep(args, target);
// Validate the outputs.
boolean valid = true;
if (!args.out.couldBe(arrayOut[i * 2 + j])) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inEdge: ");
appendVariableToMessage(message, args.inEdge);
message.append("\n");
message.append("Input inV: ");
appendVariableToMessage(message, args.inV);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 2 + j]);
if (!args.out.couldBe(arrayOut[i * 2 + j])) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkStepFloatFloat2Float2" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkStepFloatFloat3Float3() {
Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x9b2d75ce91abcbccl, false);
Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xdd9b9ef3afe18a3l, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
script.set_gAllocInV(inV);
script.forEach_testStepFloatFloat3Float3(inEdge, out);
verifyResultsStepFloatFloat3Float3(inEdge, inV, out, false);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloatFloat3Float3: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
scriptRelaxed.set_gAllocInV(inV);
scriptRelaxed.forEach_testStepFloatFloat3Float3(inEdge, out);
verifyResultsStepFloatFloat3Float3(inEdge, inV, out, true);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloatFloat3Float3: " + e.toString());
}
inEdge.destroy();
inV.destroy();
}
private void verifyResultsStepFloatFloat3Float3(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) {
float[] arrayInEdge = new float[INPUTSIZE * 1];
Arrays.fill(arrayInEdge, (float) 42);
inEdge.copyTo(arrayInEdge);
float[] arrayInV = new float[INPUTSIZE * 4];
Arrays.fill(arrayInV, (float) 42);
inV.copyTo(arrayInV);
float[] arrayOut = new float[INPUTSIZE * 4];
Arrays.fill(arrayOut, (float) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 3 ; j++) {
// Extract the inputs.
ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat();
args.inEdge = arrayInEdge[i];
args.inV = arrayInV[i * 4 + j];
// Figure out what the outputs should have been.
Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
CoreMathVerifier.computeStep(args, target);
// Validate the outputs.
boolean valid = true;
if (!args.out.couldBe(arrayOut[i * 4 + j])) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inEdge: ");
appendVariableToMessage(message, args.inEdge);
message.append("\n");
message.append("Input inV: ");
appendVariableToMessage(message, args.inV);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 4 + j]);
if (!args.out.couldBe(arrayOut[i * 4 + j])) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkStepFloatFloat3Float3" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkStepFloatFloat4Float4() {
Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xc5ba964ebd0c7f46l, false);
Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xddb830a31193981l, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
script.set_gAllocInV(inV);
script.forEach_testStepFloatFloat4Float4(inEdge, out);
verifyResultsStepFloatFloat4Float4(inEdge, inV, out, false);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloatFloat4Float4: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
scriptRelaxed.set_gAllocInV(inV);
scriptRelaxed.forEach_testStepFloatFloat4Float4(inEdge, out);
verifyResultsStepFloatFloat4Float4(inEdge, inV, out, true);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepFloatFloat4Float4: " + e.toString());
}
inEdge.destroy();
inV.destroy();
}
private void verifyResultsStepFloatFloat4Float4(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) {
float[] arrayInEdge = new float[INPUTSIZE * 1];
Arrays.fill(arrayInEdge, (float) 42);
inEdge.copyTo(arrayInEdge);
float[] arrayInV = new float[INPUTSIZE * 4];
Arrays.fill(arrayInV, (float) 42);
inV.copyTo(arrayInV);
float[] arrayOut = new float[INPUTSIZE * 4];
Arrays.fill(arrayOut, (float) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 4 ; j++) {
// Extract the inputs.
ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat();
args.inEdge = arrayInEdge[i];
args.inV = arrayInV[i * 4 + j];
// Figure out what the outputs should have been.
Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
CoreMathVerifier.computeStep(args, target);
// Validate the outputs.
boolean valid = true;
if (!args.out.couldBe(arrayOut[i * 4 + j])) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inEdge: ");
appendVariableToMessage(message, args.inEdge);
message.append("\n");
message.append("Input inV: ");
appendVariableToMessage(message, args.inV);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 4 + j]);
if (!args.out.couldBe(arrayOut[i * 4 + j])) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkStepFloatFloat4Float4" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkStepHalfHalf2Half2() {
Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0xecb0cdca0915e1ddl, false);
Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 2, 0x851a02469aa13beel, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE);
script.set_gAllocInV(inV);
script.forEach_testStepHalfHalf2Half2(inEdge, out);
verifyResultsStepHalfHalf2Half2(inEdge, inV, out, false);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalfHalf2Half2: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE);
scriptRelaxed.set_gAllocInV(inV);
scriptRelaxed.forEach_testStepHalfHalf2Half2(inEdge, out);
verifyResultsStepHalfHalf2Half2(inEdge, inV, out, true);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalfHalf2Half2: " + e.toString());
}
inEdge.destroy();
inV.destroy();
}
private void verifyResultsStepHalfHalf2Half2(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) {
short[] arrayInEdge = new short[INPUTSIZE * 1];
Arrays.fill(arrayInEdge, (short) 42);
inEdge.copyTo(arrayInEdge);
short[] arrayInV = new short[INPUTSIZE * 2];
Arrays.fill(arrayInV, (short) 42);
inV.copyTo(arrayInV);
short[] arrayOut = new short[INPUTSIZE * 2];
Arrays.fill(arrayOut, (short) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 2 ; j++) {
// Extract the inputs.
ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf();
args.inEdge = arrayInEdge[i];
args.inEdgeDouble = Float16Utils.convertFloat16ToDouble(args.inEdge);
args.inV = arrayInV[i * 2 + j];
args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV);
// Figure out what the outputs should have been.
Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
CoreMathVerifier.computeStep(args, target);
// Validate the outputs.
boolean valid = true;
if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inEdge: ");
appendVariableToMessage(message, args.inEdge);
message.append("\n");
message.append("Input inV: ");
appendVariableToMessage(message, args.inV);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 2 + j]);
message.append("\n");
message.append("Actual output out (in double): ");
appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]));
if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkStepHalfHalf2Half2" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkStepHalfHalf3Half3() {
Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0xf9965187030b71f9l, false);
Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0x851a0ce7f9a900e2l, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE);
script.set_gAllocInV(inV);
script.forEach_testStepHalfHalf3Half3(inEdge, out);
verifyResultsStepHalfHalf3Half3(inEdge, inV, out, false);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalfHalf3Half3: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE);
scriptRelaxed.set_gAllocInV(inV);
scriptRelaxed.forEach_testStepHalfHalf3Half3(inEdge, out);
verifyResultsStepHalfHalf3Half3(inEdge, inV, out, true);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalfHalf3Half3: " + e.toString());
}
inEdge.destroy();
inV.destroy();
}
private void verifyResultsStepHalfHalf3Half3(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) {
short[] arrayInEdge = new short[INPUTSIZE * 1];
Arrays.fill(arrayInEdge, (short) 42);
inEdge.copyTo(arrayInEdge);
short[] arrayInV = new short[INPUTSIZE * 4];
Arrays.fill(arrayInV, (short) 42);
inV.copyTo(arrayInV);
short[] arrayOut = new short[INPUTSIZE * 4];
Arrays.fill(arrayOut, (short) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 3 ; j++) {
// Extract the inputs.
ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf();
args.inEdge = arrayInEdge[i];
args.inEdgeDouble = Float16Utils.convertFloat16ToDouble(args.inEdge);
args.inV = arrayInV[i * 4 + j];
args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV);
// Figure out what the outputs should have been.
Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
CoreMathVerifier.computeStep(args, target);
// Validate the outputs.
boolean valid = true;
if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inEdge: ");
appendVariableToMessage(message, args.inEdge);
message.append("\n");
message.append("Input inV: ");
appendVariableToMessage(message, args.inV);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 4 + j]);
message.append("\n");
message.append("Actual output out (in double): ");
appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]));
if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkStepHalfHalf3Half3" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkStepHalfHalf4Half4() {
Allocation inEdge = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0x67bd543fd010215l, false);
Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0x851a178958b0c5d6l, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE);
script.set_gAllocInV(inV);
script.forEach_testStepHalfHalf4Half4(inEdge, out);
verifyResultsStepHalfHalf4Half4(inEdge, inV, out, false);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalfHalf4Half4: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE);
scriptRelaxed.set_gAllocInV(inV);
scriptRelaxed.forEach_testStepHalfHalf4Half4(inEdge, out);
verifyResultsStepHalfHalf4Half4(inEdge, inV, out, true);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testStepHalfHalf4Half4: " + e.toString());
}
inEdge.destroy();
inV.destroy();
}
private void verifyResultsStepHalfHalf4Half4(Allocation inEdge, Allocation inV, Allocation out, boolean relaxed) {
short[] arrayInEdge = new short[INPUTSIZE * 1];
Arrays.fill(arrayInEdge, (short) 42);
inEdge.copyTo(arrayInEdge);
short[] arrayInV = new short[INPUTSIZE * 4];
Arrays.fill(arrayInV, (short) 42);
inV.copyTo(arrayInV);
short[] arrayOut = new short[INPUTSIZE * 4];
Arrays.fill(arrayOut, (short) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 4 ; j++) {
// Extract the inputs.
ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf();
args.inEdge = arrayInEdge[i];
args.inEdgeDouble = Float16Utils.convertFloat16ToDouble(args.inEdge);
args.inV = arrayInV[i * 4 + j];
args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV);
// Figure out what the outputs should have been.
Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
CoreMathVerifier.computeStep(args, target);
// Validate the outputs.
boolean valid = true;
if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inEdge: ");
appendVariableToMessage(message, args.inEdge);
message.append("\n");
message.append("Input inV: ");
appendVariableToMessage(message, args.inV);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 4 + j]);
message.append("\n");
message.append("Actual output out (in double): ");
appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]));
if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkStepHalfHalf4Half4" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
public void testStep() {
checkStepFloatFloatFloat();
checkStepFloat2Float2Float2();
checkStepFloat3Float3Float3();
checkStepFloat4Float4Float4();
checkStepHalfHalfHalf();
checkStepHalf2Half2Half2();
checkStepHalf3Half3Half3();
checkStepHalf4Half4Half4();
checkStepFloat2FloatFloat2();
checkStepFloat3FloatFloat3();
checkStepFloat4FloatFloat4();
checkStepHalf2HalfHalf2();
checkStepHalf3HalfHalf3();
checkStepHalf4HalfHalf4();
checkStepFloatFloat2Float2();
checkStepFloatFloat3Float3();
checkStepFloatFloat4Float4();
checkStepHalfHalf2Half2();
checkStepHalfHalf3Half3();
checkStepHalfHalf4Half4();
}
}