summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYang Ni <yangni@google.com>2015-06-18 15:57:56 -0700
committerYang Ni <yangni@google.com>2015-06-22 15:00:12 -0700
commita999049af32c9f2e2989685a86843eaeff312f0b (patch)
treef7f9806a70246c83ab9c2b1097fa5d66db850f53
parent6b3e1831ee29f23452816752a9bb87fca5a8b013 (diff)
downloadrs-a999049af32c9f2e2989685a86843eaeff312f0b.tar.gz
Check for kernel chaining in ScriptGroup
b/21958851 bcc expects kernels chained up via input and output. Check this in the runtime before passing ScriptGroup to bcc for compiler fusion. Change-Id: I6004d577410ea1684f5043babadc1e1b885c4f6a
-rw-r--r--cpu_ref/rsCpuScriptGroup2.cpp21
-rw-r--r--java/tests/RsTest/src/com/android/rs/test/RSTestCore.java1
-rw-r--r--java/tests/RsTest/src/com/android/rs/test/UT_script_group2_nochain.java93
-rw-r--r--java/tests/RsTest/src/com/android/rs/test/increment2.rs25
4 files changed, 139 insertions, 1 deletions
diff --git a/cpu_ref/rsCpuScriptGroup2.cpp b/cpu_ref/rsCpuScriptGroup2.cpp
index b1453110..8923c651 100644
--- a/cpu_ref/rsCpuScriptGroup2.cpp
+++ b/cpu_ref/rsCpuScriptGroup2.cpp
@@ -128,7 +128,26 @@ bool Batch::conflict(CPUClosure* cpuClosure) const {
}
}
- return false;
+ // The compiler fusion pass in bcc expects that kernels chained up through
+ // (1st) input and output.
+
+ const Closure* lastBatched = mClosures.back()->mClosure;
+ const auto& it = argDeps.find(lastBatched);
+
+ if (it == argDeps.end()) {
+ return true;
+ }
+
+ const auto& args = (*it).second;
+ for (const auto &p1 : *args) {
+ if (p1.first == 0 && p1.second.get() == nullptr) {
+ // The new closure depends on the last batched closure's return
+ // value (fieldId being nullptr) for its first argument (argument 0)
+ return false;
+ }
+ }
+
+ return true;
}
CpuScriptGroup2Impl::CpuScriptGroup2Impl(RsdCpuReferenceImpl *cpuRefImpl,
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 504ed640..3294aed2 100644
--- a/java/tests/RsTest/src/com/android/rs/test/RSTestCore.java
+++ b/java/tests/RsTest/src/com/android/rs/test/RSTestCore.java
@@ -87,6 +87,7 @@ public class RSTestCore {
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_script_group2_nochain(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_nochain.java b/java/tests/RsTest/src/com/android/rs/test/UT_script_group2_nochain.java
new file mode 100644
index 00000000..18cf8023
--- /dev/null
+++ b/java/tests/RsTest/src/com/android/rs/test/UT_script_group2_nochain.java
@@ -0,0 +1,93 @@
+/*
+ * 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_nochain extends UnitTest {
+ private Resources mRes;
+
+ private static final int ARRAY_SIZE = 256;
+
+ private static final String TAG = "ScritGroup2 (nochain)";
+
+ protected UT_script_group2_nochain(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_increment2 s_inc2 = new ScriptC_increment2(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);
+
+ ScriptGroup.Builder2 builder = new ScriptGroup.Builder2(pRS);
+
+ ScriptGroup.Input unbound = builder.addInput();
+
+ ScriptGroup.Closure c0 =
+ builder.addKernel(s_inc.getKernelID_increment(),
+ Type.createX(pRS, Element.I32_4(pRS), ARRAY_SIZE),
+ unbound);
+
+ ScriptGroup.Closure c1 =
+ builder.addKernel(s_inc2.getKernelID_increment2(),
+ Type.createX(pRS, Element.I32_4(pRS), ARRAY_SIZE),
+ unbound,
+ new ScriptGroup.Binding(s_inc2.getFieldID_a(), unbound));
+
+ ScriptGroup.Closure c2 =
+ builder.addKernel(s_double.getKernelID_doubleKernel(),
+ Type.createX(pRS, Element.I32_4(pRS), ARRAY_SIZE),
+ unbound);
+
+ ScriptGroup group = builder.create("AddDouble2", c2.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/increment2.rs b/java/tests/RsTest/src/com/android/rs/test/increment2.rs
new file mode 100644
index 00000000..19129cd8
--- /dev/null
+++ b/java/tests/RsTest/src/com/android/rs/test/increment2.rs
@@ -0,0 +1,25 @@
+/*
+ * 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;
+
+void RS_KERNEL increment2(int4 in, int x)
+{
+ rsSetElementAt_int4(a, in + 1, x);
+}