diff options
author | Stephen Hines <srhines@google.com> | 2014-07-12 01:41:52 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-07-12 01:41:52 +0000 |
commit | c562a29b2c221c22792cdbb7deeadca3fc0a6edd (patch) | |
tree | 0231395116e73304a65d0b83512aabb07c1474a9 /java | |
parent | eaff410b9ba00927aeaad92dbbe72a45ff9e00aa (diff) | |
parent | db69bf0117c44d8996a3d179cc3b7a98bf8726ea (diff) | |
download | rs-c562a29b2c221c22792cdbb7deeadca3fc0a6edd.tar.gz |
am db69bf01: Merge "Adds support for multi-input kernels to Frameworks/RS."
* commit 'db69bf0117c44d8996a3d179cc3b7a98bf8726ea':
Adds support for multi-input kernels to Frameworks/RS.
Diffstat (limited to 'java')
4 files changed, 221 insertions, 0 deletions
diff --git a/java/tests/RsTest/Android.mk b/java/tests/RsTest/Android.mk index 198693c9..787e740d 100644 --- a/java/tests/RsTest/Android.mk +++ b/java/tests/RsTest/Android.mk @@ -21,6 +21,8 @@ LOCAL_MODULE_TAGS := tests LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-renderscript-files-under, src) +LOCAL_RENDERSCRIPT_FLAGS := -target-api 0 + LOCAL_PACKAGE_NAME := RSTest include $(BUILD_PACKAGE) 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 e9d5268a..3047a563 100644 --- a/java/tests/RsTest/src/com/android/rs/test/RSTestCore.java +++ b/java/tests/RsTest/src/com/android/rs/test/RSTestCore.java @@ -93,6 +93,7 @@ public class RSTestCore { /*unitTests.add(new UT_program_store(this, mRes, mCtx)); unitTests.add(new UT_program_raster(this, mRes, mCtx)); unitTests.add(new UT_mesh(this, mRes, mCtx));*/ + unitTests.add(new UT_foreach_multi(this, mRes, mCtx)); unitTests.add(new UT_fp_mad(this, mRes, mCtx)); /* diff --git a/java/tests/RsTest/src/com/android/rs/test/UT_foreach_multi.java b/java/tests/RsTest/src/com/android/rs/test/UT_foreach_multi.java new file mode 100644 index 00000000..e2095f6c --- /dev/null +++ b/java/tests/RsTest/src/com/android/rs/test/UT_foreach_multi.java @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2014 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; + +public class UT_foreach_multi extends UnitTest { + private Resources mRes; + private Allocation Ain0; + private Allocation Ain1; + private Allocation Ain2; + private Allocation Ain3; + + private Allocation Out0; + private Allocation Out1; + private Allocation Out2; + + protected UT_foreach_multi(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "Foreach Multi-input", ctx); + mRes = res; + } + + private void initializeGlobals(RenderScript RS, ScriptC_foreach_multi s) { + Type.Builder type32Builder = new Type.Builder(RS, Element.U32(RS)); + Type.Builder type16Builder = new Type.Builder(RS, Element.U16(RS)); + + int Xdim = 5; + s.set_dimX(Xdim); + type32Builder.setX(Xdim); + type16Builder.setX(Xdim); + + // 32-bit input allocations + + Ain0 = Allocation.createTyped(RS, type32Builder.create()); + s.set_ain0(Ain0); + s.forEach_init_uint32_alloc(Ain0); + + Ain1 = Allocation.createTyped(RS, type32Builder.create()); + s.set_ain1(Ain1); + s.forEach_init_uint32_alloc(Ain1); + + Ain2 = Allocation.createTyped(RS, type32Builder.create()); + s.set_ain2(Ain2); + s.forEach_init_uint32_alloc(Ain2); + + // 16-bit input allocation + + Ain3 = Allocation.createTyped(RS, type16Builder.create()); + s.set_ain3(Ain3); + s.forEach_init_uint16_alloc(Ain3); + + // 32-bit output allocations + + Out0 = Allocation.createTyped(RS, type32Builder.create()); + s.set_aout0(Out0); + + Out1 = Allocation.createTyped(RS, type32Builder.create()); + s.set_aout1(Out1); + + Out2 = Allocation.createTyped(RS, type32Builder.create()); + s.set_aout2(Out2); + + return; + } + + public void run() { + RenderScript pRS = RenderScript.create(mCtx); + ScriptC_foreach_multi s = new ScriptC_foreach_multi(pRS); + + pRS.setMessageHandler(mRsMessage); + + initializeGlobals(pRS, s); + + s.forEach_sum2(Ain0, Ain1, Out0); + s.forEach_sum3(Ain0, Ain1, Ain2, Out1); + s.forEach_sum_mixed(Ain0, Ain3, Out2); + + s.invoke_test_outputs(); + s.invoke_check_test_results(); + + pRS.finish(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/java/tests/RsTest/src/com/android/rs/test/foreach_multi.rs b/java/tests/RsTest/src/com/android/rs/test/foreach_multi.rs new file mode 100644 index 00000000..025d19d4 --- /dev/null +++ b/java/tests/RsTest/src/com/android/rs/test/foreach_multi.rs @@ -0,0 +1,116 @@ +#include "shared.rsh" + +rs_allocation ain0, ain1, ain2; +rs_allocation ain3; + +rs_allocation aout0, aout1, aout2; + +uint32_t dimX; + +static bool failed = false; + +uint32_t RS_KERNEL init_uint32_alloc(uint32_t x) { + return x; +} + +uint16_t RS_KERNEL init_uint16_alloc(uint32_t x) { + return x; +} + +uint32_t RS_KERNEL sum2(uint32_t in0, uint32_t in1, uint32_t x) { + _RS_ASSERT(in0 == x); + _RS_ASSERT(in1 == x); + + return in0 + in1; +} + +uint32_t RS_KERNEL sum3(uint32_t in0, uint32_t in1, uint32_t in2, uint32_t x) { + _RS_ASSERT(in0 == x); + _RS_ASSERT(in1 == x); + _RS_ASSERT(in2 == x); + + return in0 + in1 + in2; +} + + +uint32_t RS_KERNEL sum_mixed(uint32_t in0, uint16_t in1, uint32_t x) { + _RS_ASSERT(in0 == x); + _RS_ASSERT(in1 == x); + + return in0 + in1; +} + +static bool test_sum2_output() { + bool failed = false; + uint32_t i; + + for (i = 0; i < dimX; i++) { + _RS_ASSERT(rsGetElementAt_uint(aout0, i) == + (rsGetElementAt_uint(ain0, i) + + rsGetElementAt_uint(ain1, i))); + } + + if (failed) { + rsDebug("test_sum2_output FAILED", 0); + } + else { + rsDebug("test_sum2_output PASSED", 0); + } + + return failed; +} + +static bool test_sum3_output() { + bool failed = false; + uint32_t i; + + for (i = 0; i < dimX; i++) { + _RS_ASSERT(rsGetElementAt_uint(aout1, i) == + (rsGetElementAt_uint(ain0, i) + + rsGetElementAt_uint(ain1, i) + + rsGetElementAt_uint(ain2, i))); + } + + if (failed) { + rsDebug("test_sum3_output FAILED", 0); + } + else { + rsDebug("test_sum3_output PASSED", 0); + } + + return failed; +} + +static bool test_sum_mixed_output() { + bool failed = false; + uint32_t i; + + for (i = 0; i < dimX; i++) { + _RS_ASSERT(rsGetElementAt_uint(aout2, i) == + (rsGetElementAt_uint(ain0, i) + + rsGetElementAt_ushort(ain3, i))); + } + + if (failed) { + rsDebug("test_sum_mixed_output FAILED", 0); + } + else { + rsDebug("test_sum_mixed_output PASSED", 0); + } + + return failed; +} + +void test_outputs() { + failed |= test_sum2_output(); + failed |= test_sum3_output(); + failed |= test_sum_mixed_output(); +} + +void check_test_results() { + if (failed) { + rsSendToClientBlocking(RS_MSG_TEST_FAILED); + } else { + rsSendToClientBlocking(RS_MSG_TEST_PASSED); + } +} |