Skip to content

Commit 0c09d37

Browse files
authored
Merge pull request #55 from dividiti/issue-54
gpu issue #54
2 parents b5ecbf6 + 16648a4 commit 0c09d37

File tree

4 files changed

+100
-14
lines changed

4 files changed

+100
-14
lines changed

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

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,41 @@ synchronized public static String getResultURL() {
364364
return appConfig.getResultURL();
365365
}
366366

367+
synchronized public static void updateGPU(String value) {
368+
AppConfig appConfig = loadAppConfig();
369+
if (appConfig == null) {
370+
appConfig = new AppConfig();
371+
}
372+
appConfig.setGpu(value);
373+
saveAppConfig(appConfig);
374+
}
375+
376+
synchronized public static String getGPU() {
377+
AppConfig appConfig = loadAppConfig();
378+
if (appConfig == null) {
379+
return "";
380+
}
381+
return appConfig.getGpu();
382+
}
383+
384+
synchronized public static void updateGPUVendor(String value) {
385+
AppConfig appConfig = loadAppConfig();
386+
if (appConfig == null) {
387+
appConfig = new AppConfig();
388+
}
389+
appConfig.setGpuVendor(value);
390+
saveAppConfig(appConfig);
391+
}
392+
393+
synchronized public static String getGPUVendor() {
394+
AppConfig appConfig = loadAppConfig();
395+
if (appConfig == null) {
396+
return "";
397+
}
398+
return appConfig.getGpuVendor();
399+
}
400+
401+
367402
public static void saveAppConfig(AppConfig appConfig) {
368403
try {
369404
JSONObject scenariosJSON = appConfig.toJSONObject();
@@ -409,6 +444,9 @@ public enum State {
409444
public static final String STATE_PARAM = "state";
410445
public static final String LOCAL_APP_PATH = "local_app_path";
411446
public static final String RESULT_URL = "result_url";
447+
public static final String GPU_VENDOR = "gpu_vendor";
448+
public static final String GPU = "gpu";
449+
412450

413451
private String email;
414452
private String actualImagePath;
@@ -423,6 +461,8 @@ public enum State {
423461
private String localAppPath;
424462
private String previewRecognitionText;
425463
private String resultURL;
464+
private String gpu = "";
465+
private String gpuVendor = "";
426466

427467
public String getEmail() {
428468
return email;
@@ -520,6 +560,22 @@ public void setResultURL(String resultURL) {
520560
this.resultURL = resultURL;
521561
}
522562

563+
public String getGpu() {
564+
return gpu;
565+
}
566+
567+
public void setGpu(String gpu) {
568+
this.gpu = gpu;
569+
}
570+
571+
public String getGpuVendor() {
572+
return gpuVendor;
573+
}
574+
575+
public void setGpuVendor(String gpuVendor) {
576+
this.gpuVendor = gpuVendor;
577+
}
578+
523579
public JSONObject toJSONObject() {
524580
JSONObject jsonObject = new JSONObject();
525581
try {
@@ -535,6 +591,9 @@ public JSONObject toJSONObject() {
535591
jsonObject.put(LOCAL_APP_PATH, getLocalAppPath());
536592
jsonObject.put(PREVIEW_RECOGNITION_TEXT, getPreviewRecognitionText());
537593
jsonObject.put(RESULT_URL, getResultURL());
594+
jsonObject.put(GPU, getGPU());
595+
jsonObject.put(GPU_VENDOR, getGpuVendor());
596+
538597
} catch (JSONException e) {
539598
AppLogger.logMessage("ERROR could not serialize app config to json format");
540599
}
@@ -619,6 +678,19 @@ public static AppConfig fromJSONObject(JSONObject jsonObject) {
619678
} catch (JSONException e) {
620679
// optional param
621680
}
681+
682+
try {
683+
appConfig.setGpu(jsonObject.getString(GPU));
684+
} catch (JSONException e) {
685+
// optional param
686+
}
687+
688+
try {
689+
appConfig.setGpuVendor(jsonObject.getString(GPU_VENDOR));
690+
} catch (JSONException e) {
691+
// optional param
692+
}
693+
622694
return appConfig;
623695
}
624696
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,6 @@ public class MainActivity extends android.app.Activity implements GLSurfaceView.
104104

105105
private GLSurfaceView glSurfaceView;
106106

107-
static String pf_gpu = "";
108-
static String pf_gpu_vendor = "";
109-
110107
private GoogleApiClient client;
111108

112109
String curlCached;
@@ -509,7 +506,8 @@ private JSONObject getCPUFreqsJSON(List<Double[]> cpus) {
509506

510507
@Override
511508
public void onSurfaceCreated(GL10 gl10, EGLConfig eglConfig) {
512-
pf_gpu_vendor = gl10.glGetString(GL10.GL_VENDOR);
509+
String pf_gpu_vendor = gl10.glGetString(GL10.GL_VENDOR);
510+
String pf_gpu = "";
513511
if (pf_gpu_vendor.equals("null")) pf_gpu_vendor = "";
514512

515513
String x = gl10.glGetString(GL10.GL_RENDERER);
@@ -522,6 +520,9 @@ public void run() {
522520
glSurfaceView.setVisibility(View.GONE);
523521
}
524522
});
523+
524+
AppConfigService.updateGPU(pf_gpu);
525+
AppConfigService.updateGPUVendor(pf_gpu_vendor);
525526
}
526527

527528
@Override

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
import static openscience.crowdsource.video.experiments.AppConfigService.cachedPlatformFeaturesFilePath;
1313
import static openscience.crowdsource.video.experiments.AppConfigService.path_opencl;
1414
import static openscience.crowdsource.video.experiments.AppConfigService.repo_uoa;
15-
import static openscience.crowdsource.video.experiments.MainActivity.pf_gpu;
16-
import static openscience.crowdsource.video.experiments.MainActivity.pf_gpu_vendor;
1715
import static openscience.crowdsource.video.experiments.Utils.exchange_info_with_ck_server;
1816
import static openscience.crowdsource.video.experiments.Utils.get_cpu_freqs;
1917

@@ -472,8 +470,10 @@ public static JSONObject loadPlatformFeaturesFromServer() {
472470

473471
AppLogger.logMessage(x + "\n");
474472
}
475-
AppLogger.logMessage("GPU: " + pf_gpu + "\n");
476-
AppLogger.logMessage("* VENDOR: " + pf_gpu_vendor + "\n");
473+
String gpu = AppConfigService.getGPU();
474+
String gpuVendor = AppConfigService.getGPUVendor();
475+
AppLogger.logMessage("GPU: " + gpu + "\n");
476+
AppLogger.logMessage("* VENDOR: " + gpuVendor + "\n");
477477
AppLogger.logMessage("* OPENCL: " + pf_gpu_opencl + "\n");
478478

479479
//Delay program for 1 sec
@@ -569,22 +569,24 @@ public static JSONObject loadPlatformFeaturesFromServer() {
569569
}
570570

571571
// GPU ******
572-
if (!pf_gpu.equals("") && AppConfigService.getRemoteServerURL() != null) {
572+
gpu = AppConfigService.getGPU();
573+
gpuVendor = AppConfigService.getGPUVendor();
574+
if (!gpu.equals("") && AppConfigService.getRemoteServerURL() != null) {
573575
AppLogger.logMessage(" Exchanging GPU info ...\n");
574576

575577
try {
576578
ft_gpu = new JSONObject();
577579

578-
ft_gpu.put("name", pf_gpu);
579-
ft_gpu.put("vendor", pf_gpu_vendor);
580+
ft_gpu.put("name", gpu);
581+
ft_gpu.put("vendor", gpuVendor);
580582

581583
platformFeatures.put("features", ft_gpu);
582584

583585
requestObject.put("remote_server_url", AppConfigService.getRemoteServerURL());//
584586
requestObject.put("action", "exchange");
585587
requestObject.put("module_uoa", "platform");
586588
requestObject.put("sub_module_uoa", "platform.gpu");
587-
requestObject.put("data_name", pf_gpu);
589+
requestObject.put("data_name", gpu );
588590
requestObject.put("repo_uoa", repo_uoa);
589591
requestObject.put("all", "yes");
590592
requestObject.put("dict", platformFeatures);

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
import org.json.JSONException;
1212

13+
import java.util.ArrayList;
14+
1315
import static openscience.crowdsource.video.experiments.MainActivity.setTaskBarColored;
1416
import static openscience.crowdsource.video.experiments.RecognitionScenarioService.getScenarioDescriptionHTML;
1517

@@ -36,11 +38,20 @@ public void onClick(View v) {
3638
}
3739
});
3840
TextView selectScenarioText = (TextView)findViewById(R.id.topSelectedScenarioText);
39-
selectScenarioText.setText(getIntent().getStringExtra(ScenariosActivity.SELECTED_SCENARIO_TITLE));
41+
String selectedScenarioTitle = getIntent().getStringExtra(ScenariosActivity.SELECTED_SCENARIO_TITLE);
42+
selectScenarioText.setText(selectedScenarioTitle);
43+
44+
RecognitionScenario selectedScenario = null;
45+
ArrayList<RecognitionScenario> sortedRecognitionScenarios = RecognitionScenarioService.getSortedRecognitionScenarios();
46+
for (RecognitionScenario sortedRecognitionScenario : sortedRecognitionScenarios) {
47+
if (sortedRecognitionScenario.getTitle().equalsIgnoreCase(selectedScenarioTitle)) {
48+
selectedScenario = sortedRecognitionScenario;
49+
}
50+
}
4051

4152
TextView scenarioInfoText = (TextView)findViewById(R.id.scenarioInfoText);
4253
try {
43-
scenarioInfoText.setText(Html.fromHtml(getScenarioDescriptionHTML(RecognitionScenarioService.getSelectedRecognitionScenario())));
54+
scenarioInfoText.setText(Html.fromHtml(getScenarioDescriptionHTML(selectedScenario)));
4455
} catch (JSONException e) {
4556
AppLogger.logMessage("Error " + e.getLocalizedMessage());
4657
}

0 commit comments

Comments
 (0)