Skip to content

Commit f3b7586

Browse files
author
Daniil Efremov
committed
Support old phones for OpenCL scenarios #80
1 parent c76487a commit f3b7586

File tree

3 files changed

+57
-38
lines changed

3 files changed

+57
-38
lines changed

app/src/main/java/openscience/crowdsource/video/experiments/AppConfigService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ public class AppConfigService {
4242

4343
public static final String path_opencl = "/system/vendor/lib/libOpenCL.so";
4444

45+
public static final String libOpenCLFileName = "libOpenCL.so";
46+
public static final String maliGLESFilePaths[] = new String[]{
47+
"/system/vendor/lib/egl/libGLES_mali.so",
48+
"/system/vendor/egl/libGLES_mali.so"
49+
};
50+
4551
public static final String url_cserver = "http://cTuning.org/shared-computing-resources-json/ck.json";
4652

4753
public static final String repo_uoa = "upload";

app/src/main/java/openscience/crowdsource/video/experiments/MainActivity.java

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,12 @@
7575
import static openscience.crowdsource.video.experiments.AppConfigService.externalSDCardOpenscienceTmpPath;
7676
import static openscience.crowdsource.video.experiments.AppConfigService.externalSDCardPath;
7777
import static openscience.crowdsource.video.experiments.AppConfigService.initAppConfig;
78+
import static openscience.crowdsource.video.experiments.AppConfigService.libOpenCLFileName;
79+
import static openscience.crowdsource.video.experiments.AppConfigService.maliGLESFilePaths;
7880
import static openscience.crowdsource.video.experiments.AppConfigService.parsePredictionRawResult;
7981
import static openscience.crowdsource.video.experiments.AppConfigService.url_cserver;
8082
import static openscience.crowdsource.video.experiments.RecognitionScenarioService.PRELOADING_TEXT;
8183
import static openscience.crowdsource.video.experiments.Utils.createDirIfNotExist;
82-
import static openscience.crowdsource.video.experiments.Utils.getABI;
8384
import static openscience.crowdsource.video.experiments.Utils.validateReturnCode;
8485

8586
/**
@@ -930,7 +931,7 @@ public void println(String text) {
930931

931932
//patrh open cl version
932933
String openCLlibPath = null;
933-
// openCLlibPath = patchOpenCL(); temporary disabled
934+
openCLlibPath = patchOpenCLIfRequired();
934935

935936
if (openCLlibPath != null) {
936937
libPath = libPath + ":" + openCLlibPath;
@@ -1147,47 +1148,53 @@ private void showIsThatCorrectDialog(final String recognitionResultText, final S
11471148
openResultActivity();
11481149
}
11491150

1150-
private String patchOpenCL() {
1151-
String libOpenCLFileName = "libOpenCL.so";
1152-
String fromFilePath = "/system/vendor/lib/egl/libGLES_mali.so";
1151+
private String patchOpenCLIfRequired() {
1152+
if (PlatformFeaturesService.isOpenCLSupported()) {
1153+
// patch is not required
1154+
return null;
1155+
}
11531156

1154-
String targetAppFileDir = AppConfigService.getLocalAppPath() + File.separator + "openscience" + File.separator + "code/libopencl/armeabi-v7a";
1155-
String targetAppFilePath = targetAppFileDir + File.separator + libOpenCLFileName;
1157+
for (String fromFilePath : maliGLESFilePaths) {
11561158

1157-
String[] rmResult = openme.openme_run_program("rm " + targetAppFilePath, null, targetAppFileDir);
1158-
if (rmResult[0].isEmpty() && rmResult[1].isEmpty() && rmResult[2].isEmpty()) {
1159-
publishProgress(" * File " + targetAppFilePath + " successfully removed...\n");
1160-
} else {
1161-
publishProgress("\nError removing file " + fromFilePath + " ..." + rmResult[0] + " " + rmResult[1] + " " + rmResult[2]);
1162-
}
1159+
String targetAppFileDir = AppConfigService.getLocalAppPath() + File.separator + "openscience" + File.separator + "code/libopencl";
1160+
String targetAppFilePath = targetAppFileDir + File.separator + libOpenCLFileName;
11631161

1162+
String[] rmResult = openme.openme_run_program("rm " + targetAppFilePath, null, targetAppFileDir);
1163+
if (rmResult[0].isEmpty() && rmResult[1].isEmpty() && rmResult[2].isEmpty()) {
1164+
publishProgress(" * File " + targetAppFilePath + " successfully removed...\n");
1165+
} else {
1166+
publishProgress("\nError removing file " + fromFilePath + " ..." + rmResult[0] + " " + rmResult[1] + " " + rmResult[2]);
1167+
}
11641168

1165-
File appfp = new File(targetAppFileDir);
1166-
if (!appfp.exists()) {
1167-
if (!appfp.mkdirs()) {
1168-
publishProgress("\nError creating dir (" + targetAppFileDir + ") ...");
1169-
return null;
1169+
1170+
File appfp = new File(targetAppFileDir);
1171+
if (!appfp.exists()) {
1172+
if (!appfp.mkdirs()) {
1173+
publishProgress("\nError creating dir (" + targetAppFileDir + ") ...");
1174+
return null;
1175+
}
11701176
}
1171-
}
11721177

11731178

1174-
try {
1175-
copy_bin_file(fromFilePath, targetAppFilePath);
1176-
publishProgress("\n * File " + fromFilePath + " successfully copied to " + targetAppFilePath);
1177-
} catch (IOException e) {
1178-
e.printStackTrace();
1179-
publishProgress("\nError copying file " + fromFilePath + " to " + targetAppFilePath + " ..." + e.getLocalizedMessage());
1180-
return null;
1181-
}
1179+
try {
1180+
copy_bin_file(fromFilePath, targetAppFilePath);
1181+
publishProgress("\n * File " + fromFilePath + " successfully copied to " + targetAppFilePath);
1182+
} catch (IOException e) {
1183+
e.printStackTrace();
1184+
publishProgress("\nError copying file " + fromFilePath + " to " + targetAppFilePath + " ..." + e.getLocalizedMessage());
1185+
return null;
1186+
}
11821187

1183-
String[] chmodResult = openme.openme_run_program(COMMAND_CHMOD_744 + " " + targetAppFilePath, null, targetAppFileDir);
1184-
if (chmodResult[0].isEmpty() && chmodResult[1].isEmpty() && chmodResult[2].isEmpty()) {
1185-
publishProgress(" * File " + targetAppFilePath + " successfully set as executable ...\n");
1186-
} else {
1187-
publishProgress("\nError setting file " + fromFilePath + " as executable ...");
1188-
return null;
1188+
String[] chmodResult = openme.openme_run_program(COMMAND_CHMOD_744 + " " + targetAppFilePath, null, targetAppFileDir);
1189+
if (chmodResult[0].isEmpty() && chmodResult[1].isEmpty() && chmodResult[2].isEmpty()) {
1190+
publishProgress(" * File " + targetAppFilePath + " successfully set as executable ...\n");
1191+
} else {
1192+
publishProgress("\nError setting file " + fromFilePath + " as executable ...");
1193+
return null;
1194+
}
1195+
return targetAppFileDir;
11891196
}
1190-
return targetAppFileDir;
1197+
return null;
11911198
}
11921199
}
11931200

app/src/main/java/openscience/crowdsource/video/experiments/PlatformFeaturesService.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,9 @@ public static JSONObject loadPlatformFeaturesFromServer() {
430430
if (ix > 0) pf_os_bits = "64";
431431

432432
//Get OpenCL info **************************************************
433-
File fopencl = new File(path_opencl);
434-
long lfopencl = fopencl.length();
435-
436-
if (lfopencl > 0) {
433+
if (isOpenCLSupported()) {
434+
File fopencl = new File(path_opencl);
435+
long lfopencl = fopencl.length();
437436
pf_gpu_opencl = "libOpenCL.so - found (" + Long.toString(lfopencl) + " bytes)";
438437
pf_gpu_openclx = "yes";
439438
} else {
@@ -859,4 +858,11 @@ public static JSONObject getPlatformFeaturesJSONObject(String pf_gpu_openclx, JS
859858
ft.put("platform_uoa", deviceInfo.getJ_sys_uid());
860859
return ft;
861860
}
861+
862+
// Get OpenCL info
863+
public static boolean isOpenCLSupported() {
864+
File fopencl = new File(path_opencl);
865+
long lfopencl = fopencl.length();
866+
return (lfopencl > 0);
867+
}
862868
}

0 commit comments

Comments
 (0)