Skip to content
Snippets Groups Projects
Commit 4f585f7c authored by Jean-François's avatar Jean-François Committed by Jean-François Geyelin
Browse files

Throw when ScriptC is used on unsupported ABIs

ScriptC won't be supported on any new architecture (for example riscv64), so
throw an exception when it is used on an unsupported architecture.

Note that using `Build.SUPPORTED_ABIS` includes ABIs supported due to
dynamic binary translation, which do not support ScriptC. So we can't
use `Build.SUPPORTED_ABIS` to determine if ScriptC is supported or
not.

Instead we attempt loading `libRS.so`.
`libRS.so` is not present on riscv64 images, so this allows us to know
if we are on a riscv64 system.
A problem occurs on x86 images with binary translation for riscv64
(aka berberis): when running a riscv64 binary, the binary translation
system will fallback to the x86 version of the libraries via what is
called a "native bridge". This means that `libRS.so` would successfully
load on those system, which we do not want because even though it would load it wouldn't run properly.
This is why a separate CL in the binary translation codebase was landed that explicitly refuses to load `libRS.so`:
https://android-review.git.corp.google.com/c/platform/frameworks/libs/binary_translation/+/2971952

Bug: 206676167
Test: atest CtsRsBlasTestCases:android.cts.rsblas.IntrinsicBLAS#test_L3_SGEMM_API -- --abi x86_64

Change-Id: I2ed2e2ae531046d1d00e9a2d2f864375b0bb3570
parent f647472f
No related branches found
No related tags found
No related merge requests found
...@@ -101,7 +101,19 @@ public class ScriptC extends Script { ...@@ -101,7 +101,19 @@ public class ScriptC extends Script {
setID(id); setID(id);
} }
private static void throwExceptionIfSDKTooHigh() { private static void throwExceptionIfScriptCUnsupported() {
// Checks that this device actually does have an ABI that supports ScriptC.
//
// For an explanation as to why `System.loadLibrary` is used, see discussion at
// https://android-review.googlesource.com/c/platform/frameworks/base/+/2957974/comment/2f908b80_a05292ee
try {
System.loadLibrary("RS");
} catch (UnsatisfiedLinkError e) {
String s = "This device does not have an ABI that supports ScriptC.";
throw new UnsupportedOperationException(s);
}
// Throw an exception if the target API is 35 or above
String message = String message =
"ScriptC scripts are not supported when targeting an API Level >= 35. Please refer " "ScriptC scripts are not supported when targeting an API Level >= 35. Please refer "
+ "to https://developer.android.com/guide/topics/renderscript/migration-guide " + "to https://developer.android.com/guide/topics/renderscript/migration-guide "
...@@ -113,7 +125,7 @@ public class ScriptC extends Script { ...@@ -113,7 +125,7 @@ public class ScriptC extends Script {
} }
private static synchronized long internalCreate(RenderScript rs, Resources resources, int resourceID) { private static synchronized long internalCreate(RenderScript rs, Resources resources, int resourceID) {
throwExceptionIfSDKTooHigh(); throwExceptionIfScriptCUnsupported();
byte[] pgm; byte[] pgm;
int pgmLength; int pgmLength;
InputStream is = resources.openRawResource(resourceID); InputStream is = resources.openRawResource(resourceID);
...@@ -150,7 +162,7 @@ public class ScriptC extends Script { ...@@ -150,7 +162,7 @@ public class ScriptC extends Script {
private static synchronized long internalStringCreate(RenderScript rs, String resName, byte[] bitcode) { private static synchronized long internalStringCreate(RenderScript rs, String resName, byte[] bitcode) {
// Log.v(TAG, "Create script for resource = " + resName); // Log.v(TAG, "Create script for resource = " + resName);
throwExceptionIfSDKTooHigh(); throwExceptionIfScriptCUnsupported();
return rs.nScriptCCreate(resName, RenderScript.getCachePath(), bitcode, bitcode.length); return rs.nScriptCCreate(resName, RenderScript.getCachePath(), bitcode, bitcode.length);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment