1 /*
2 * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package hat.test;
26
27 import hat.Accelerator;
28 import hat.ComputeContext;
29 import hat.NDRange;
30 import hat.KernelContext;
31 import hat.backend.Backend;
32 import hat.buffer.S32Array;
33 import hat.ifacemapper.MappableIface.RO;
34 import jdk.incubator.code.CodeReflection;
35 import hat.test.annotation.HatTest;
36 import hat.test.engine.HATAsserts;
37
38 import java.lang.invoke.MethodHandles;
39
40 import static hat.ifacemapper.MappableIface.RW;
41
42 public class TestParenthesis {
43
44 @CodeReflection
45 public static void compute(@RO KernelContext context, @RW S32Array data) {
46 final int TN = 2;
47 final int TF = 128;
48 final int MAX = 1024;
49 int c = MAX / (TN * TF);
50 data.array(context.gix, c);
51 }
52
53 @CodeReflection
54 public static void compute2(@RO KernelContext context, @RW S32Array data) {
55 final int TN = 2;
56 final int TF = 128;
57 final int MAX = 1024;
58 int c = MAX / ((TN * TF) / (TN * TN));
59 data.array(context.gix, c);
60 }
61
62 @CodeReflection
63 public static void compute3(@RO KernelContext context, @RW S32Array data) {
64 final int TN = 2;
65 final int TF = 128;
66 final int MAX = 1024;
67 int c = MAX * (TF + 2) / ((TN * TF) / (TN * TN));
68 data.array(context.gix, c);
69 }
70
71 @CodeReflection
72 public static void compute(@RO ComputeContext cc, @RW S32Array data) {
73 NDRange ndRange = NDRange.of(NDRange.Global1D.of(data.length()));
74 cc.dispatchKernel(ndRange,kc -> compute(kc, data));
75 }
76
77 @CodeReflection
78 public static void compute2(@RO ComputeContext cc, @RW S32Array data) {
79 NDRange ndRange = NDRange.of(NDRange.Global1D.of(data.length()));
80 cc.dispatchKernel(ndRange,kc -> compute2(kc, data));
81 }
82
83 @CodeReflection
84 public static void compute3(@RO ComputeContext cc, @RW S32Array data) {
85 NDRange ndRange = NDRange.of(NDRange.Global1D.of(data.length()));
86 cc.dispatchKernel(ndRange,kc -> compute3(kc, data));
87 }
88
89 @HatTest
90 public static void testParenthesis01() {
91 final int size = 1;
92 var accelerator = new Accelerator(MethodHandles.lookup(), Backend.FIRST);
93 var data = S32Array.create(accelerator, size);
94
95 // Initialize array
96 data.fill(_ -> 0);
97
98 accelerator.compute(cc -> TestParenthesis.compute(cc, data));
99
100 final int TN = 2;
101 final int TF = 128;
102 final int MAX = 1024;
103 int c = MAX / (TN * TF);
104 HATAsserts.assertEquals(c, data.array(0));
105 }
106
107 @HatTest
108 public static void testParenthesis02() {
109 final int size = 1;
110 var accelerator = new Accelerator(MethodHandles.lookup(), Backend.FIRST);
111 var data = S32Array.create(accelerator, size);
112
113 // Initialize array
114 data.fill(_ -> 0);
115
116 accelerator.compute(cc -> TestParenthesis.compute2(cc, data));
117
118 final int TN = 2;
119 final int TF = 128;
120 final int MAX = 1024;
121 int c = MAX / ((TN * TF) / (TN * TN));
122 HATAsserts.assertEquals(c, data.array(0));
123 }
124
125 @HatTest
126 public static void testParenthesis03() {
127 final int size = 1;
128 var accelerator = new Accelerator(MethodHandles.lookup(), Backend.FIRST);
129 var data = S32Array.create(accelerator, size);
130
131 // Initialize array
132 data.fill(_ -> 0);
133
134 accelerator.compute(cc -> TestParenthesis.compute3(cc, data));
135
136 final int TN = 2;
137 final int TF = 128;
138 final int MAX = 1024;
139 int c = MAX * (TF + 2) / ((TN * TF) / (TN * TN));
140 HATAsserts.assertEquals(c, data.array(0));
141 }
142
143 }