21 | * Do not rely on anything tagged as unused, it will probably be retracted/refactored 22 | * 23 | * @author gfrost 24 | * 25 | */ 26 | public @interface Unused { 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/com/aparapi/codegen/test/ReturnByteArrayNew.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.aparapi.codegen.test; 17 | 18 | public class ReturnByteArrayNew { 19 | 20 | byte[] returnByteArrayNew() { 21 | return new byte[1024]; 22 | } 23 | 24 | public void run() { 25 | returnByteArrayNew(); 26 | } 27 | } 28 | /**{Throws{CodeGenException}Throws}**/ 29 | -------------------------------------------------------------------------------- /src/test/java/com/aparapi/codegen/test/ReturnLongArrayNew.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.aparapi.codegen.test; 17 | 18 | public class ReturnLongArrayNew { 19 | 20 | long[] returnLongArrayNew() { 21 | return new long[1024]; 22 | } 23 | 24 | public void run() { 25 | returnLongArrayNew(); 26 | } 27 | } 28 | /**{Throws{CodeGenException}Throws}**/ 29 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/annotation/Experimental.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.aparapi.annotation; 17 | 18 | /** 19 | * Used to tag experimental features (methods/fields) 20 | *
21 | * Do not rely on anything tagged as experimental, it will probably be retracted/refactored
22 | *
23 | * @author gfrost
24 | *
25 | */
26 | public @interface Experimental {
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/PostIncIntField.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | public class PostIncIntField {
19 |
20 | int _y = 2;
21 |
22 | int incInt(int a) {
23 | return a++;
24 | }
25 |
26 | public void run() {
27 |
28 | incInt(_y++);
29 |
30 | }
31 | }
32 | /**{Throws{ClassParseException}Throws}**/
33 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/ReturnFloatArrayNew.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | public class ReturnFloatArrayNew {
19 |
20 | float[] returnFloatArrayNew() {
21 | return new float[1024];
22 | }
23 |
24 | public void run() {
25 | returnFloatArrayNew();
26 | }
27 | }
28 | /**{Throws{CodeGenException}Throws}**/
29 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/ReturnShortArrayNew.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | public class ReturnShortArrayNew {
19 |
20 | short[] returnShortArrayNew() {
21 | return new short[1024];
22 | }
23 |
24 | public void run() {
25 | returnShortArrayNew();
26 | }
27 | }
28 | /**{Throws{CodeGenException}Throws}**/
29 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/PreIncIntField.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | public class PreIncIntField {
19 |
20 | int y = 2;
21 |
22 | int preIncInt(int _a) {
23 | return ++_a;
24 | }
25 |
26 | public void run() {
27 |
28 | preIncInt(++y);
29 |
30 | }
31 | }
32 | /**{Throws{ClassParseException}Throws}**/
33 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/ReturnDoubleArrayNew.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | public class ReturnDoubleArrayNew {
19 |
20 | double[] returnDoubleArrayNew() {
21 | return new double[1024];
22 | }
23 |
24 | public void run() {
25 | returnDoubleArrayNew();
26 | }
27 | }
28 | /**{Throws{CodeGenException}Throws}**/
29 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/AccessNested2DIntArray.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | public class AccessNested2DIntArray {
19 | int[] indices = new int[1024];
20 |
21 | int[][] ints = new int[1024][];
22 |
23 | public void run() {
24 | int value = ints[indices[0]][0];
25 | }
26 |
27 | }
28 | /**{Throws{ClassParseException}Throws}**/
29 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/PostIncByteField.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | public class PostIncByteField {
19 |
20 | byte z = (byte) 3;
21 |
22 | byte incByte(byte _a) {
23 | return _a++;
24 | }
25 |
26 | public void run() {
27 |
28 | z = incByte(z++);
29 |
30 | }
31 | }
32 | /**{Throws{ClassParseException}Throws}**/
33 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/PreIncByteField.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | public class PreIncByteField {
19 |
20 | byte z = (byte) 3;
21 |
22 | byte incByte(byte _a) {
23 | return ++_a;
24 | }
25 |
26 | public void run() {
27 |
28 | z = incByte(++z);
29 |
30 | }
31 | }
32 | /**{Throws{ClassParseException}Throws}**/
33 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/ReturnBooleanNewArray.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | public class ReturnBooleanNewArray {
19 |
20 | boolean[] returnBooleanNewArray() {
21 |
22 | return new boolean[1024];
23 | }
24 |
25 | public void run() {
26 | returnBooleanNewArray();
27 | }
28 | }
29 | /**{Throws{CodeGenException}Throws}**/
30 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/AssignAndPassAsParameterSimple.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | public class AssignAndPassAsParameterSimple {
19 |
20 | void actuallyDoIt(int a) {
21 |
22 | }
23 |
24 | public void run() {
25 | @SuppressWarnings("unused") int z;
26 | actuallyDoIt(z = 1);
27 | }
28 | }
29 | /**{Throws{CodeGenException}Throws}**/
30 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/ReturnLongArrayVar.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | public class ReturnLongArrayVar {
19 |
20 | long[] returnLongArrayVar() {
21 | long[] longs = new long[1024];
22 | return longs;
23 | }
24 |
25 | public void run() {
26 |
27 | returnLongArrayVar();
28 | }
29 | }
30 | /**{OpenCL{
31 |
32 | }OpenCL}**/
33 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/Break.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | public class Break {
19 | public void run() {
20 | @SuppressWarnings("unused") boolean pass = false;
21 | for (int i = 0; i < 10; i++) {
22 | if (i == 5) {
23 | break;
24 | }
25 | pass = true;
26 | }
27 | }
28 | }
29 | /**{Throws{ClassParseException}Throws}**/
30 |
--------------------------------------------------------------------------------
/src/main/java/com/aparapi/exception/CompileFailedException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.exception;
17 |
18 | import com.aparapi.internal.exception.AparapiException;
19 |
20 | @SuppressWarnings("serial")
21 | public class CompileFailedException extends AparapiException {
22 |
23 | public CompileFailedException(String reason) {
24 | super(reason);
25 | }
26 |
27 | public CompileFailedException(Throwable _t) {
28 | super(_t);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/ForEach.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | public class ForEach {
19 |
20 | int out[] = new int[10];
21 | int in[] = new int[10];
22 |
23 | public void run() {
24 | int max = Integer.MIN_VALUE;
25 | for (int i : in) {
26 | if (i > max)
27 | max = i;
28 | }
29 | out[0] = max;
30 | }
31 | }
32 | /**{Throws{ClassParseException}Throws}**/
33 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/EntrypointRecursion.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | import com.aparapi.Kernel;
19 |
20 | public class EntrypointRecursion extends Kernel {
21 |
22 | int[] values = new int[128];
23 |
24 | public void run() {
25 | int id = getGlobalId();
26 |
27 | values[id]++;
28 |
29 | if (values[id] < 20) {
30 | run();
31 | }
32 | }
33 |
34 | }
35 | /**{Throws{ClassParseException}Throws}**/
36 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/CallObject.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | import com.aparapi.Kernel;
19 |
20 | public class CallObject extends Kernel {
21 | Dummy dummy = new Dummy();
22 |
23 | ;
24 | int out[] = new int[2];
25 |
26 | public void run() {
27 | out[0] = dummy.foo();
28 | }
29 |
30 | static class Dummy {
31 | public int foo() {
32 | return 42;
33 | }
34 | }
35 | }
36 | /**{Throws{ClassParseException}Throws}**/
37 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/FusedMultiplyAdd.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | import com.aparapi.Kernel;
19 |
20 | public class FusedMultiplyAdd extends Kernel {
21 | public void run() {
22 | double d1 = 123.0, d2 = 0.456, d3 = 789.0;
23 | float f1 = 123.0f, f2 = 0.456f, f3 = 789.0f;
24 |
25 | @SuppressWarnings("unused") boolean pass = true;
26 | if ((fma(d1, d2, d3) != 845.088) || (fma(f1, f2, f3) != 845.088f))
27 | pass = false;
28 | }
29 | }
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/UseObject.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | import com.aparapi.Kernel;
19 |
20 | public class UseObject extends Kernel {
21 | Dummy dummy = new Dummy();
22 |
23 | ;
24 | int out[] = new int[2];
25 | int plainInt = -1;
26 |
27 | public void run() {
28 | out[0] = dummy.n;
29 | out[1] = plainInt;
30 | }
31 |
32 | class Dummy {
33 | public int n;
34 | }
35 |
36 | }
37 | /**{Throws{ClassParseException}Throws}**/
38 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/DirectRecursion.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | import com.aparapi.Kernel;
19 |
20 | public class DirectRecursion extends Kernel {
21 |
22 | int intout[] = new int[1];
23 |
24 | public void run() {
25 | intout[0] = fact(10);
26 | @SuppressWarnings("unused") boolean pass = false;
27 | }
28 |
29 | int fact(int n) {
30 | return (n <= 1 ? n : n * fact(n - 1));
31 | }
32 |
33 | }
34 | /**{Throws{ClassParseException}Throws}**/
35 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/runtime/PreDecrementTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.runtime;
17 |
18 | import com.aparapi.Kernel;
19 | import org.junit.Test;
20 |
21 |
22 | public class PreDecrementTest {
23 | @Test
24 | public void test() {
25 | PreDecrement kernel = new PreDecrement();
26 | kernel.execute(1);
27 | }
28 |
29 | public class PreDecrement extends Kernel {
30 | public void run() {
31 | int idx = 34;
32 | if(idx < 5) {
33 | }
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/ForBreak.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | public class ForBreak {
19 | public void run() {
20 | @SuppressWarnings("unused") boolean pass = false;
21 | for (int i = 0; i > 2 && i < 10; i++) {
22 | pass = false;
23 | if (i == 5 || i == 6) {
24 | if (i == 5) {
25 | pass = true;
26 | break;
27 | }
28 | }
29 | }
30 |
31 | }
32 | }
33 | /**{Throws{ClassParseException}Throws}**/
34 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/ObjectRefCopy.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | import com.aparapi.Kernel;
19 |
20 | public class ObjectRefCopy extends Kernel {
21 |
22 | final int size = 8;
23 |
24 | ;
25 | DummyOOA dummy[] = new DummyOOA[size];
26 |
27 | public void run() {
28 | int myId = getGlobalId();
29 | dummy[myId] = dummy[myId + 1];
30 | }
31 |
32 | final static class DummyOOA {
33 | int mem;
34 |
35 | float floatField;
36 | }
37 | }
38 |
39 | /**{Throws{ClassParseException}Throws}**/
40 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/Sequence.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | public class Sequence {
19 | public void run() {
20 | @SuppressWarnings("unused") boolean pass = false;
21 |
22 | }
23 | }
24 | /**{OpenCL{
25 | typedef struct This_s{
26 | int passid;
27 | }This;
28 | int get_pass_id(This *this){
29 | return this->passid;
30 | }
31 | __kernel void run(
32 | int passid
33 | ){
34 | This thisStruct;
35 | This* this=&thisStruct;
36 | this->passid = passid;
37 | {
38 | char pass = 0;
39 | return;
40 | }
41 | }
42 | }OpenCL}**/
43 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/WideInc.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | public class WideInc {
19 |
20 | public void run() {
21 | int value = 0;
22 | value += 128;
23 | }
24 | }
25 |
26 | /**{OpenCL{
27 | typedef struct This_s{
28 | int passid;
29 | }This;
30 | int get_pass_id(This *this){
31 | return this->passid;
32 | }
33 | __kernel void run(
34 | int passid
35 | ){
36 | This thisStruct;
37 | This* this=&thisStruct;
38 | this->passid = passid;
39 | {
40 | int value = 0;
41 | value+=128;
42 | return;
43 | }
44 | }
45 | }OpenCL}**/
46 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/Interface.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | public class Interface {
19 |
20 | double out[] = new double[1];
21 | Operator sa = new SimpleAdder();
22 |
23 | public void run() {
24 | out[0] = sa.operate(0.0);
25 | }
26 |
27 | public interface Operator {
28 | public double operate(double d);
29 | }
30 |
31 | public class SimpleAdder implements Operator {
32 | public double operate(double d) {
33 | return d + 1.0;
34 | }
35 | }
36 | }
37 | /**{Throws{ClassParseException}Throws}**/
38 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/EmptyWhileWithInc.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | public class EmptyWhileWithInc {
19 | public void run() {
20 | int x = 0;
21 | while (x++ < 10) {
22 | }
23 | }
24 | }
25 | /**{OpenCL{
26 | typedef struct This_s{
27 | int passid;
28 | }This;
29 | int get_pass_id(This *this){
30 | return this->passid;
31 | }
32 | __kernel void run(
33 | int passid
34 | ){
35 | This thisStruct;
36 | This* this=&thisStruct;
37 | this->passid = passid;
38 | {
39 | for (int x = 0; x++<10;){}
40 | return;
41 | }
42 | }
43 | }OpenCL}**/
44 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/PostIncLocalStandalone.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | public class PostIncLocalStandalone {
19 |
20 | public void run() {
21 |
22 | int i = 0;
23 | i++;
24 |
25 | }
26 | }
27 | /**{OpenCL{
28 | typedef struct This_s{
29 |
30 | int passid;
31 | }This;
32 | int get_pass_id(This *this){
33 | return this->passid;
34 | }
35 |
36 | __kernel void run(
37 | int passid
38 | ){
39 | This thisStruct;
40 | This* this=&thisStruct;
41 | this->passid = passid;
42 | {
43 | int i = 0;
44 | i++;
45 | return;
46 | }
47 | }
48 | }OpenCL}**/
49 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/PreIncLocalStandalone.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | public class PreIncLocalStandalone {
19 |
20 | public void run() {
21 |
22 | int i = 0;
23 | ++i;
24 |
25 | }
26 | }
27 | /**{OpenCL{
28 | typedef struct This_s{
29 |
30 | int passid;
31 | }This;
32 | int get_pass_id(This *this){
33 | return this->passid;
34 | }
35 |
36 | __kernel void run(
37 | int passid
38 | ){
39 | This thisStruct;
40 | This* this=&thisStruct;
41 | this->passid = passid;
42 | {
43 | int i = 0;
44 | i++;
45 | return;
46 | }
47 | }
48 | }OpenCL}**/
49 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/ForAsFirst.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | public class ForAsFirst {
19 |
20 | public void run() {
21 |
22 | for (int i = 0; i < 1; i++) {
23 |
24 | }
25 | }
26 | }
27 | /**{OpenCL{
28 | typedef struct This_s{
29 |
30 | int passid;
31 | }This;
32 | int get_pass_id(This *this){
33 | return this->passid;
34 | }
35 |
36 | __kernel void run(
37 | int passid
38 | ){
39 | This thisStruct;
40 | This* this=&thisStruct;
41 | this->passid = passid;
42 | {
43 | for (int i = 0; i<1; i++){
44 | }
45 | return;
46 | }
47 | }
48 | }OpenCL}**/
49 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/WhileEmptyLoop.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | public class WhileEmptyLoop {
19 | public void run() {
20 | int x = 10;
21 | while (x-- != 0) {
22 | }
23 | }
24 | }
25 | /**{OpenCL{
26 | typedef struct This_s{
27 |
28 | int passid;
29 | }This;
30 | int get_pass_id(This *this){
31 | return this->passid;
32 | }
33 |
34 | __kernel void run(
35 | int passid
36 | ){
37 | This thisStruct;
38 | This* this=&thisStruct;
39 | this->passid = passid;
40 | {
41 | for (int x = 10; x--!=0;){}
42 | return;
43 | }
44 | }
45 | }OpenCL}**/
46 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/WhileWithoutMutator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | public class WhileWithoutMutator {
19 | public void run() {
20 | int x = 0;
21 | while (x != 0) {
22 | }
23 | }
24 | }
25 | /**{OpenCL{
26 | typedef struct This_s{
27 | int passid;
28 | }This;
29 | int get_pass_id(This *this){
30 | return this->passid;
31 | }
32 |
33 | __kernel void run(
34 | int passid
35 | ){
36 | This thisStruct;
37 | This* this=&thisStruct;
38 | this->passid = passid;
39 | {
40 | int x = 0;
41 | for (; x!=0;){}
42 | return;
43 | }
44 | }
45 | }OpenCL}**/
46 |
--------------------------------------------------------------------------------
/src/main/java/com/aparapi/internal/model/CacheEnabler.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.internal.model;
17 |
18 | import com.aparapi.Kernel;
19 |
20 | public class CacheEnabler{
21 | private static volatile boolean cachesEnabled = true;
22 |
23 | public static void setCachesEnabled(boolean cachesEnabled) {
24 | if (CacheEnabler.cachesEnabled != cachesEnabled) {
25 | Kernel.invalidateCaches();
26 | ClassModel.invalidateCaches();
27 | }
28 |
29 | CacheEnabler.cachesEnabled = cachesEnabled;
30 | }
31 |
32 | public static boolean areCachesEnabled() {
33 | return cachesEnabled;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/VarargsForEach.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | public class VarargsForEach {
19 | int out[] = new int[1];
20 |
21 | public static int max(int... values) {
22 | if (values.length == 0) {
23 | return 0;
24 | }
25 |
26 | int max = Integer.MIN_VALUE;
27 | for (int i : values) {
28 | if (i > max)
29 | max = i;
30 | }
31 | return max;
32 | }
33 |
34 | public void run() {
35 | out[0] = max(1, 4, 5, 9, 3);
36 | }
37 |
38 | }
39 | /**{Throws{ClassParseException}Throws}**/
40 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/IndirectRecursion.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | import com.aparapi.Kernel;
19 |
20 | public class IndirectRecursion extends Kernel {
21 |
22 | int intout[] = new int[1];
23 |
24 | public void run() {
25 | intout[0] = foo(10);
26 | @SuppressWarnings("unused") boolean pass = false;
27 | }
28 |
29 | int foo(int n) {
30 | if (n > 0) {
31 | return bar(n);
32 | }
33 | return -1;
34 | }
35 |
36 | int bar(int n) {
37 | return foo(--n);
38 | }
39 |
40 | }
41 | /**{Throws{ClassParseException}Throws}**/
42 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/ObjectWithinObject.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | import com.aparapi.Kernel;
19 |
20 | public class ObjectWithinObject extends Kernel {
21 |
22 | final int size = 8;
23 |
24 | ;
25 | DummyOOA dummy[] = new DummyOOA[size];
26 |
27 | public void run() {
28 | int myId = getGlobalId();
29 | dummy[myId].mem = dummy[myId].next.mem + 4;
30 | }
31 |
32 | final static class DummyOOA {
33 | int mem;
34 |
35 | float floatField;
36 |
37 | DummyOOA next;
38 |
39 | }
40 | }
41 |
42 | /**{Throws{ClassParseException}Throws}**/
43 |
--------------------------------------------------------------------------------
/src/main/java/com/aparapi/internal/util/Reflection.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.internal.util;
17 |
18 | /**
19 | * Created by Barney on 03/09/2015.
20 | */
21 | public class Reflection {
22 |
23 | /** Avoids getting dumb empty names for anonymous inners. */
24 | public static String getSimpleName(Class> klass) {
25 | String simpleName = klass.getSimpleName();
26 | if (simpleName.isEmpty()) {
27 | String fullName = klass.getName();
28 | int index = fullName.lastIndexOf('.');
29 | simpleName = (index < 0) ? fullName : fullName.substring(index + 1);
30 | }
31 | return simpleName;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/CallGetPassId.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | import com.aparapi.Kernel;
19 |
20 | public class CallGetPassId extends Kernel {
21 | public void run() {
22 | int thePassId = getPassId();
23 | }
24 |
25 | }
26 | /**{OpenCL{
27 |
28 | typedef struct This_s{
29 | int passid;
30 | }This;
31 | int get_pass_id(This *this){
32 | return this->passid;
33 | }
34 | __kernel void run(
35 | int passid
36 | ){
37 | This thisStruct;
38 | This* this=&thisStruct;
39 | this->passid = passid;
40 | {
41 | int thePassId = get_pass_id(this);
42 | return;
43 | }
44 | }
45 |
46 | }OpenCL}**/
47 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/VarargsSimple.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | public class VarargsSimple {
19 | int out[] = new int[1];
20 |
21 | public static int max(int... values) {
22 | if (values.length == 0) {
23 | return 0;
24 | }
25 |
26 | int max = Integer.MIN_VALUE;
27 | for (int i = 0; i < values.length; i++) {
28 | if (values[i] > max)
29 | max = i;
30 | }
31 | return max;
32 | }
33 |
34 | public void run() {
35 | out[0] = max(1, 4, 5, 9, 3);
36 | }
37 |
38 | }
39 | /**{Throws{ClassParseException}Throws}**/
40 |
--------------------------------------------------------------------------------
/src/main/java/com/aparapi/internal/util/OpenCLUtil.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.internal.util;
17 |
18 | import java.util.List;
19 |
20 | import com.aparapi.internal.opencl.OpenCLPlatform;
21 |
22 | /**
23 | * This utility class encapsulates the necessary actions required to query underlying OpenCL information
24 | */
25 | public class OpenCLUtil{
26 |
27 | /**
28 | * Retrieve a list of available OpenCL Platforms
29 | *
30 | * @return Available OpenCL Platforms
31 | */
32 | public static List
21 | *
22 | * @author CoreRasurae
23 | */
24 | public interface IOpenCLDeviceConfigurator {
25 |
26 | /**
27 | * Called for each OpenCL device detected by Aparapi.
28 | * Gives the client application an opportunity to refine the device configuration parameters.
29 | *
30 | * @param device the OpenCL device to be configured
31 | */
32 | public void configure(OpenCLDevice device);
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/For.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | public class For {
19 | public void run() {
20 | @SuppressWarnings("unused") boolean pass = false;
21 | for (int i = 0; i < 10; i++) {
22 | pass = true;
23 | }
24 |
25 | }
26 | }
27 | /**{OpenCL{
28 | typedef struct This_s{
29 | int passid;
30 | }This;
31 | int get_pass_id(This *this){
32 | return this->passid;
33 | }
34 | __kernel void run(
35 | int passid
36 | ){
37 | This thisStruct;
38 | This* this=&thisStruct;
39 | this->passid = passid;
40 | {
41 | char pass = 0;
42 | for (int i = 0; i<10; i++){
43 | pass = 1;
44 | }
45 | return;
46 | }
47 | }
48 | }OpenCL}**/
49 |
--------------------------------------------------------------------------------
/src/main/java/com/aparapi/exception/AparapiJNIException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.exception;
17 |
18 | /**
19 | * This exception is thrown by underlying Aparapi JNI native code when the JNI call fails
20 | *
21 | * @author CoreRasurae
22 | */
23 | public class AparapiJNIException extends RuntimeException {
24 |
25 | public AparapiJNIException(String message) {
26 | super(message);
27 | }
28 |
29 | public AparapiJNIException(String message, Throwable cause) {
30 | super(message, cause);
31 | }
32 |
33 | public AparapiJNIException(String message, Throwable cause, boolean enableSuppression,
34 | boolean writableStackTrace) {
35 | super(message, cause, enableSuppression, writableStackTrace);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/com/aparapi/exception/QueryFailedException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.exception;
17 |
18 | import com.aparapi.internal.exception.AparapiException;
19 |
20 | /**
21 | * This exception is thrown when an unexpected behavior occurs while querying the OpenCL platform.
22 | *
23 | * @author CoreRasurae
24 | */
25 | @SuppressWarnings("serial")
26 | public class QueryFailedException extends AparapiException {
27 |
28 | public QueryFailedException(String reason) {
29 | super(reason);
30 | }
31 |
32 | public QueryFailedException(String reason, Throwable _t) {
33 | super(reason, _t);
34 | }
35 |
36 | public QueryFailedException(Throwable _t) {
37 | super(_t);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/runtime/RangeSizeTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.runtime;
17 |
18 | import com.aparapi.Range;
19 | import org.junit.Test;
20 |
21 | import static org.junit.Assert.assertTrue;
22 |
23 | public class RangeSizeTest {
24 |
25 | @Test
26 | public void test384x384() {
27 | Range range = Range.create2D(384, 384);
28 | assertTrue("Range > max work size", range.getLocalSize(0) * range.getLocalSize(1) <= range.getWorkGroupSize());
29 | }
30 |
31 | @Test
32 | public void test384x320() {
33 | Range range = Range.create2D(384, 320);
34 | assertTrue("Range > max work size", range.getLocalSize(0) * range.getLocalSize(1) <= range.getWorkGroupSize());
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/com/aparapi/internal/opencl/OpenCLMem.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.internal.opencl;
17 |
18 | public class OpenCLMem{
19 |
20 | public final static int MEM_DIRTY_BIT = 1 << 0x00F;
21 |
22 | public final static int MEM_COPY_BIT = 1 << 0x010;
23 |
24 | public final static int MEM_ENQUEUED_BIT = 1 << 0x011;
25 |
26 | public long bits; // dirty, copy, enqueued
27 |
28 | public int sizeInBytes;
29 |
30 | public long memId;
31 |
32 | public long address;
33 |
34 | public Object instance;
35 |
36 | public OpenCLProgram program;
37 |
38 | //Dummy JNI method just to ensure that above definition are generated for aparapi-native with newer Java > 8 compilers
39 | private native void dummyJNI();
40 | }
41 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/TernaryNested.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | public class TernaryNested {
19 | public void run() {
20 | boolean a = false, b = false, c = false;
21 | @SuppressWarnings("unused") int count = a ? b ? 1 : 2 : c ? 3 : 4;
22 | }
23 | }
24 | /**{OpenCL{
25 | typedef struct This_s{
26 | int passid;
27 | }This;
28 | int get_pass_id(This *this){
29 | return this->passid;
30 |
31 | }
32 | __kernel void run(
33 | int passid
34 | ){
35 | This thisStruct;
36 | This* this=&thisStruct;
37 | this->passid = passid;
38 | {
39 | char a = 0;
40 | char b = 0;
41 | char c = 0;
42 | int count = (a!=0)?(b!=0)?1:2:(c!=0)?3:4;
43 | return;
44 | }
45 | }
46 | }OpenCL}**/
47 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/PostDecLocal.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | public class PostDecLocal {
19 |
20 | public void run() {
21 | @SuppressWarnings("unused") boolean pass = false;
22 | int i = 0;
23 | if (i-- == 0)
24 | pass = true;
25 |
26 | }
27 | }
28 | /**{OpenCL{
29 | typedef struct This_s{
30 |
31 | int passid;
32 | }This;
33 | int get_pass_id(This *this){
34 | return this->passid;
35 | }
36 |
37 | __kernel void run(
38 | int passid
39 | ){
40 | This thisStruct;
41 | This* this=&thisStruct;
42 | this->passid = passid;
43 | {
44 | char pass = 0;
45 | int i = 0;
46 | if (i--==0){
47 | pass = 1;
48 | }
49 | return;
50 | }
51 | }
52 | }OpenCL}**/
53 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/PostIncLocal.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | public class PostIncLocal {
19 |
20 | public void run() {
21 | @SuppressWarnings("unused") boolean pass = false;
22 | int i = 0;
23 | if (i++ == 0)
24 | pass = true;
25 |
26 | }
27 | }
28 | /**{OpenCL{
29 | typedef struct This_s{
30 |
31 | int passid;
32 | }This;
33 | int get_pass_id(This *this){
34 | return this->passid;
35 | }
36 |
37 | __kernel void run(
38 | int passid
39 | ){
40 | This thisStruct;
41 | This* this=&thisStruct;
42 | this->passid = passid;
43 | {
44 | char pass = 0;
45 | int i = 0;
46 | if (i++==0){
47 | pass = 1;
48 | }
49 | return;
50 | }
51 | }
52 | }OpenCL}**/
53 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/ForAnd.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | public class ForAnd {
19 | public void run() {
20 | @SuppressWarnings("unused") boolean pass = false;
21 | for (int i = 0; i > 2 && i < 10; i++) {
22 | pass = true;
23 | }
24 |
25 | }
26 | }
27 | /**{OpenCL{
28 | typedef struct This_s{
29 |
30 | int passid;
31 | }This;
32 | int get_pass_id(This *this){
33 | return this->passid;
34 | }
35 |
36 | __kernel void run(
37 | int passid
38 | ){
39 | This thisStruct;
40 | This* this=&thisStruct;
41 | this->passid = passid;
42 | {
43 | char pass = 0;
44 | for (int i = 0; i>2 && i<10; i++){
45 | pass = 1;
46 | }
47 | return;
48 | }
49 | }
50 | }OpenCL}**/
51 |
--------------------------------------------------------------------------------
/src/test/java/com/aparapi/codegen/test/PreIncLocal.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 - 2018 Syncleus, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aparapi.codegen.test;
17 |
18 | public class PreIncLocal {
19 |
20 | public void run() {
21 | @SuppressWarnings("unused") boolean pass = false;
22 | int i = 0;
23 | if (++i == 1)
24 | pass = true;
25 |
26 | }
27 | }
28 | /**{OpenCL{
29 | typedef struct This_s{
30 |
31 | int passid;
32 | }This;
33 | int get_pass_id(This *this){
34 | return this->passid;
35 | }
36 |
37 | __kernel void run(
38 | int passid
39 | ){
40 | This thisStruct;
41 | This* this=&thisStruct;
42 | this->passid = passid;
43 | {
44 | char pass = 0;
45 | int i = 0;
46 | i++;
47 | if (i==1){
48 | pass = 1;
49 | }
50 | return;
51 | }
52 | }
53 | }OpenCL}**/
54 |
--------------------------------------------------------------------------------
/CONTRIBUTORS.md:
--------------------------------------------------------------------------------
1 | # Contributors
2 |
3 | * Jeffrey Phillips Freeman