diff options
author | Yang Ni <yangni@google.com> | 2015-03-25 20:09:09 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-03-25 20:09:09 +0000 |
commit | a83c4b982a1ba58817bc7021630491fc56ee21c0 (patch) | |
tree | 2aa43c8ac0e762b4b678d38d940130dc72baafb6 /java | |
parent | 792ec4fd21a345b8ebdaa77542ac763a6614d389 (diff) | |
parent | 9889f6db2bf2fdf8ef348ac0f582ea6e3a849e4a (diff) | |
download | rs-a83c4b982a1ba58817bc7021630491fc56ee21c0.tar.gz |
am 9889f6db: am be8c8954: Merge "Added tests for ScriptGroup2 API to RsTest"
* commit '9889f6db2bf2fdf8ef348ac0f582ea6e3a849e4a':
Added tests for ScriptGroup2 API to RsTest
Diffstat (limited to 'java')
6 files changed, 285 insertions, 0 deletions
diff --git a/java/tests/RsTest/src/com/android/rs/test/RSTestCore.java b/java/tests/RsTest/src/com/android/rs/test/RSTestCore.java index e2de83ac..6a8d23c9 100644 --- a/java/tests/RsTest/src/com/android/rs/test/RSTestCore.java +++ b/java/tests/RsTest/src/com/android/rs/test/RSTestCore.java @@ -85,6 +85,8 @@ public class RSTestCore { unitTests.add(new UT_foreach(this, mRes, mCtx)); unitTests.add(new UT_foreach_bounds(this, mRes, mCtx)); unitTests.add(new UT_noroot(this, mRes, mCtx)); + unitTests.add(new UT_script_group2_pointwise(this, mRes, mCtx)); + unitTests.add(new UT_script_group2_gatherscatter(this, mRes, mCtx)); unitTests.add(new UT_atomic(this, mRes, mCtx)); unitTests.add(new UT_struct(this, mRes, mCtx)); unitTests.add(new UT_math(this, mRes, mCtx)); diff --git a/java/tests/RsTest/src/com/android/rs/test/UT_script_group2_gatherscatter.java b/java/tests/RsTest/src/com/android/rs/test/UT_script_group2_gatherscatter.java new file mode 100644 index 00000000..1e74e14e --- /dev/null +++ b/java/tests/RsTest/src/com/android/rs/test/UT_script_group2_gatherscatter.java @@ -0,0 +1,123 @@ +/* + * Copyright (C) 2015 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. + */ + +package com.android.rs.test; + +import android.content.Context; +import android.content.res.Resources; +import android.renderscript.*; +import android.util.Log; +import java.lang.Thread; +import java.util.HashMap; + +public class UT_script_group2_gatherscatter extends UnitTest { + private Resources mRes; + + private static final int ARRAY_SIZE = 256; + + private static final String TAG = "ScriptGroup2 (GatherScatter)"; + + int[] mArray; + + protected UT_script_group2_gatherscatter(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, TAG, ctx); + mRes = res; + } + + public void initializeGlobals(RenderScript RS, ScriptC_addup s) { + mArray = new int[ARRAY_SIZE * 4]; + + for (int i = 0; i < ARRAY_SIZE; i++) { + mArray[i*4] = i * 7; + mArray[i*4 + 1] = i * 7 + 1; + mArray[i*4 + 2] = i * 7 + 2; + mArray[i*4 + 3] = i * 7 + 3; + } + } + + // This test tests ScriptGroup2 API for handling gather scatter operations + // on global allocations that are passed across kernels in a script group. + // The test sums up all elements in the input int4 array of size ARRAY_SIZE. + // To do so, it adds up the second half of the array to its first half using + // kernel function add() in addsup.rs, and then repeatedly applies the same + // kernel function to the shrinking result arrays until the result is a + // single int4 value. + // These steps are created as a script group by repeatedly adding the + // same kernel function, with the input of one kernel being the output of + // the previous added kernel function. + // Since the kernel function relies on rsGetElementAt to access the counterpart + // of the current element in the second half of the array, the compiler cannot + // fuse it with the other kernel that it dependes on. + // This test verifies an ScriptGroup2 implementation correctly handles such + // a case. + public void run() { + RenderScript pRS = RenderScript.create(mCtx); + ScriptC_addup s = new ScriptC_addup(pRS); + pRS.setMessageHandler(mRsMessage); + initializeGlobals(pRS, s); + + Allocation input = Allocation.createSized(pRS, Element.I32_4(pRS), ARRAY_SIZE); + input.copyFrom(mArray); + + ScriptGroup2.Builder builder = new ScriptGroup2.Builder(pRS); + + HashMap<Script.FieldID, Object> map = new HashMap<Script.FieldID, Object>(); + + ScriptGroup2.UnboundValue unbound = builder.addInput(); + + ScriptGroup2.Closure c = null; + ScriptGroup2.Future f = null; + int stride; + for (stride = ARRAY_SIZE / 2; stride >= 1; stride >>= 1) { + map.put(s.getFieldID_reduction_stride(), new Integer(stride)); + if (f == null) { + map.put(s.getFieldID_a_in(), unbound); + } else { + map.put(s.getFieldID_a_in(), f); + } + c = builder.addKernel(s.getKernelID_add(), + Type.createX(pRS, Element.I32_4(pRS), stride), + new Object[0], + map); + f = c.getReturn(); + } + + ScriptGroup2 group = builder.create(c.getReturn()); + + if (c == null) { + return; + } + + int[] a = new int[4]; + ((Allocation)group.execute(input)[0]).copyTo(a); + + pRS.finish(); + pRS.destroy(); + + boolean failed = false; + for (int i = 0; i < 4; i++) { + if (failed == false && + a[i] != ARRAY_SIZE * (ARRAY_SIZE - 1) * 7 / 2 + i * ARRAY_SIZE) { + Log.e(TAG, "a["+i+"]="+a[i]+", should be "+ + (ARRAY_SIZE * (ARRAY_SIZE - 1) * 7 / 2 + i * ARRAY_SIZE)); + failed = true; + } + } + if (failed) { + failTest(); + return; + } + passTest(); + } +} diff --git a/java/tests/RsTest/src/com/android/rs/test/UT_script_group2_pointwise.java b/java/tests/RsTest/src/com/android/rs/test/UT_script_group2_pointwise.java new file mode 100644 index 00000000..c02ae204 --- /dev/null +++ b/java/tests/RsTest/src/com/android/rs/test/UT_script_group2_pointwise.java @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2015 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. + */ + +package com.android.rs.test; + +import android.content.Context; +import android.content.res.Resources; +import android.renderscript.*; +import android.util.Log; +import java.lang.Thread; +import java.util.HashMap; + +public class UT_script_group2_pointwise extends UnitTest { + private Resources mRes; + + private static final int ARRAY_SIZE = 256; + + private static final String TAG = "ScritGroup2 (Pointwise)"; + + protected UT_script_group2_pointwise(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, TAG, ctx); + mRes = res; + } + + public void run() { + RenderScript pRS = RenderScript.create(mCtx); + ScriptC_increment s_inc = new ScriptC_increment(pRS); + ScriptC_double s_double = new ScriptC_double(pRS); + pRS.setMessageHandler(mRsMessage); + + int[] array = new int[ARRAY_SIZE * 4]; + + for (int i = 0; i < ARRAY_SIZE * 4; i++) { + array[i] = i; + } + + Allocation input = Allocation.createSized(pRS, Element.I32_4(pRS), ARRAY_SIZE); + input.copyFrom(array); + + ScriptGroup2.Builder builder = new ScriptGroup2.Builder(pRS); + + HashMap<Script.FieldID, Object> map = new HashMap<Script.FieldID, Object>(); + + ScriptGroup2.UnboundValue unbound = builder.addInput(); + + ScriptGroup2.Closure c0 = + builder.addKernel(s_inc.getKernelID_increment(), + Type.createX(pRS, Element.I32_4(pRS), ARRAY_SIZE), + new Object[]{unbound}, map); + + ScriptGroup2.Closure c1 = + builder.addKernel(s_double.getKernelID_doubleKernel(), + Type.createX(pRS, Element.I32_4(pRS), ARRAY_SIZE), + new Object[]{c0.getReturn()}, map); + + ScriptGroup2 group = builder.create(c1.getReturn()); + + int[] a = new int[ARRAY_SIZE * 4]; + ((Allocation)group.execute(input)[0]).copyTo(a); + + pRS.finish(); + pRS.destroy(); + + boolean failed = false; + for (int i = 0; i < ARRAY_SIZE * 4; i++) { + if (a[i] != (i+1) * 2) { + Log.e(TAG, "a["+i+"]="+a[i]+", should be "+ ((i+1) * 2)); + failed = true; + } + } + if (failed) { + failTest(); + return; + } + passTest(); + } +} diff --git a/java/tests/RsTest/src/com/android/rs/test/addup.rs b/java/tests/RsTest/src/com/android/rs/test/addup.rs new file mode 100644 index 00000000..afc6a08c --- /dev/null +++ b/java/tests/RsTest/src/com/android/rs/test/addup.rs @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2015 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. + */ + +#pragma version(1) +#pragma rs java_package_name(com.android.rs.test) + +rs_allocation a_in; +int reduction_stride; + +int4 RS_KERNEL add(uint x) +{ + return rsGetElementAt_int4(a_in, x) + rsGetElementAt_int4(a_in, x + reduction_stride); +} diff --git a/java/tests/RsTest/src/com/android/rs/test/double.rs b/java/tests/RsTest/src/com/android/rs/test/double.rs new file mode 100644 index 00000000..a1b7097f --- /dev/null +++ b/java/tests/RsTest/src/com/android/rs/test/double.rs @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2015 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. + */ + +#pragma version(1) +#pragma rs java_package_name(com.android.rs.test) + +int4 RS_KERNEL doubleKernel(int4 in) +{ + return in * 2; +}
\ No newline at end of file diff --git a/java/tests/RsTest/src/com/android/rs/test/increment.rs b/java/tests/RsTest/src/com/android/rs/test/increment.rs new file mode 100644 index 00000000..0c5de01d --- /dev/null +++ b/java/tests/RsTest/src/com/android/rs/test/increment.rs @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2015 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. + */ + +#pragma version(1) +#pragma rs java_package_name(com.android.rs.test) + +int4 RS_KERNEL increment(int4 in) +{ + return in + 1; +} |