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.ComputeRange; 30 import hat.GlobalMesh1D; 31 import hat.KernelContext; 32 import hat.backend.Backend; 33 import hat.buffer.S32Array; 34 import hat.ifacemapper.MappableIface.RO; 35 import jdk.incubator.code.CodeReflection; 36 import hat.test.annotation.HatTest; 37 import hat.test.engine.HatAsserts; 38 39 import java.lang.invoke.MethodHandles; 40 41 import static hat.ifacemapper.MappableIface.*; 42 43 public class TestParenthesis { 44 45 @CodeReflection 46 public static void compute(@RO KernelContext context, @RW S32Array data) { 47 final int TN = 2; 48 final int TF = 128; 49 final int MAX = 1024; 50 int c = MAX / (TN * TF); 51 data.array(context.x, c); 52 } 53 54 @CodeReflection 55 public static void compute2(@RO KernelContext context, @RW S32Array data) { 56 final int TN = 2; 57 final int TF = 128; 58 final int MAX = 1024; 59 int c = MAX / ((TN * TF) / (TN * TN)); 60 data.array(context.x, c); 61 } 62 63 @CodeReflection 64 public static void compute3(@RO KernelContext context, @RW S32Array data) { 65 final int TN = 2; 66 final int TF = 128; 67 final int MAX = 1024; 68 int c = MAX * (TF + 2) / ((TN * TF) / (TN * TN)); 69 data.array(context.x, c); 70 } 71 72 @CodeReflection 73 public static void compute(@RO ComputeContext cc, @RW S32Array data) { 74 ComputeRange computeRange = new ComputeRange(new GlobalMesh1D(data.length())); 75 cc.dispatchKernel(computeRange,kc -> compute(kc, data)); 76 } 77 78 @CodeReflection 79 public static void compute2(@RO ComputeContext cc, @RW S32Array data) { 80 ComputeRange computeRange = new ComputeRange(new GlobalMesh1D(data.length())); 81 cc.dispatchKernel(computeRange,kc -> compute2(kc, data)); 82 } 83 84 @CodeReflection 85 public static void compute3(@RO ComputeContext cc, @RW S32Array data) { 86 ComputeRange computeRange = new ComputeRange(new GlobalMesh1D(data.length())); 87 cc.dispatchKernel(computeRange,kc -> compute3(kc, data)); 88 } 89 90 @HatTest 91 public static void testParenthesis01() { 92 final int size = 1; 93 var accelerator = new Accelerator(MethodHandles.lookup(), Backend.FIRST); 94 var data = S32Array.create(accelerator, size); 95 96 // Initialize array 97 data.fill(_ -> 0); 98 99 accelerator.compute(cc -> TestParenthesis.compute(cc, data)); 100 101 final int TN = 2; 102 final int TF = 128; 103 final int MAX = 1024; 104 int c = MAX / (TN * TF); 105 HatAsserts.assertEquals(c, data.array(0)); 106 } 107 108 @HatTest 109 public static void testParenthesis02() { 110 final int size = 1; 111 var accelerator = new Accelerator(MethodHandles.lookup(), Backend.FIRST); 112 var data = S32Array.create(accelerator, size); 113 114 // Initialize array 115 data.fill(_ -> 0); 116 117 accelerator.compute(cc -> TestParenthesis.compute2(cc, data)); 118 119 final int TN = 2; 120 final int TF = 128; 121 final int MAX = 1024; 122 int c = MAX / ((TN * TF) / (TN * TN)); 123 HatAsserts.assertEquals(c, data.array(0)); 124 } 125 126 @HatTest 127 public static void testParenthesis03() { 128 final int size = 1; 129 var accelerator = new Accelerator(MethodHandles.lookup(), Backend.FIRST); 130 var data = S32Array.create(accelerator, size); 131 132 // Initialize array 133 data.fill(_ -> 0); 134 135 accelerator.compute(cc -> TestParenthesis.compute3(cc, data)); 136 137 final int TN = 2; 138 final int TF = 128; 139 final int MAX = 1024; 140 int c = MAX * (TF + 2) / ((TN * TF) / (TN * TN)); 141 HatAsserts.assertEquals(c, data.array(0)); 142 } 143 144 }