Skip to content

Commit 5cd831f

Browse files
added threading
1 parent cccb757 commit 5cd831f

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

app/src/main/java/com/lib/androidgpu/MainActivity.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,32 @@ protected void onCreate(Bundle savedInstanceState) {
1515
setContentView(R.layout.activity_main);
1616

1717
try {
18-
AndroidGPU androidGPU = new AndroidGPU(this, "compute.glsl");
19-
/*androidGPU = new AndroidGPU("#version 430\n" +
18+
//AndroidGPU androidGPU = new AndroidGPU(this, "compute.glsl");
19+
int dim = 1024000;
20+
AndroidGPU androidGPU = new AndroidGPU("#version 430\n" +
2021
"\n" +
2122
"layout (local_size_x = 256) in;\n" +
2223
"\n" +
2324
"layout(set = 0, binding = 0) readonly buffer InputBuffer {\n" +
2425
" double buff[];\n" +
2526
"} input_data;\n" +
2627
"\n" +
27-
"layout(set = 0, binding = 1) buffer OutputBuffer {\n" +
28+
"layout(set = 0, binding = 1) readonly buffer ParamsBuffer {\n" +
29+
" double buff[];\n" +
30+
"} params_data;\n" +
31+
"\n" +
32+
"layout(set = 0, binding = 2) writeonly buffer OutputBuffer {\n" +
2833
" double buff[];\n" +
2934
"} output_data;\n" +
3035
"\n" +
3136
"void main() {\n" +
3237
"\n" +
3338
" uint gID = gl_GlobalInvocationID.x;\n" +
34-
" if (gID < 256) {\n" +
35-
" output_data.buff[gID] = input_data.buff[gID];\n" +
39+
" if (gID < " + dim + ") {\n" +
40+
" output_data.buff[gID] = input_data.buff[gID] + params_data.buff[0] + params_data.buff[1] + params_data.buff[2];\n" +
3641
" }\n" +
37-
"}");*/
42+
"}");
3843

39-
int dim = 1024;
4044
Double[] input = new Double[dim];
4145
Double[] output = new Double[dim];
4246
Double[] params = new Double[]{1.0, 2.0, 3.0};
@@ -45,9 +49,10 @@ protected void onCreate(Bundle savedInstanceState) {
4549
input[i] = (double) i;
4650
}
4751
androidGPU.run(this, () -> {
48-
for (double d : output) {
52+
/*for (double d : output) {
4953
Log.i("####", Double.toString(d));
50-
}
54+
}*/
55+
Log.i("####", "Done");
5156
}, dim, 1, 1, 256, 1, 1, output, input, params);
5257

5358
} catch (Exception e) {

0 commit comments

Comments
 (0)