# HG changeset patch # User Gilles Duboscq # Date 1408612358 -7200 # Node ID bbb987aec58dc671b92123e1db1bf40960c456fd # Parent 6adb14d2320c1569755629591974dc08e8e898b2 HSAIL: pass the number of argument to the JavaCallArguments constructor. Add TraceTime for kernel creation. Contributed-by: Eric Caspole diff -r 6adb14d2320c -r bbb987aec58d graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/MoreThanEightArgsTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/MoreThanEightArgsTest.java Thu Aug 21 11:12:38 2014 +0200 @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.compiler.hsail.test.lambda; + +import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; + +import org.junit.*; + +public class MoreThanEightArgsTest extends GraalKernelTester { + + int[] makeIntArray(int size) { + int[] out = new int[size]; + + for (int i = 0; i < size; i++) { + out[i] = 1; + } + return out; + } + + final int rows = 4096; + final int cols = 4096; + final int loops = 2; + + @Result int[] result; + + void innerTest(int[] res, int[] a, int[] b, int[] c, int[] d, int base, int stride) { + final int resCols = a.length; + final int resRows = res.length; + final int limit = resCols - stride; + + dispatchLambdaKernel(resRows, (row) -> { + res[row] = 0; + if (a != null) { + for (int col = base; col < limit; col += 4) { + int p0 = 0; + int p1 = 0; + int p2 = 0; + int p3 = 0; + p0 = a[col] + b[col] + c[col] + d[col] + stride; + p1 = a[col + 1] + b[col + 1] + c[col + 1] + d[col + 1]; + p2 = a[col + 2] + b[col + 2] + c[col + 2] + d[col + 2]; + p3 = a[col + 3] + b[col + 3] + c[col + 3] + d[col + 3]; + res[row] += p0 + p1 + p2 + p3; + } + } + }); + } + + @Override + public void runTest() { + int[] a; + int[] b; + int[] c; + int[] d; + + result = makeIntArray(rows); + a = makeIntArray(cols); + b = makeIntArray(cols); + c = makeIntArray(cols); + d = makeIntArray(cols); + for (int i = 0; i < loops; i++) { + innerTest(result, a, b, c, d, 0, 4); + } + } + + @Test + public void test() { + testGeneratedHsail(); + } + + @Test + public void testUsingLambdaMethod() { + testGeneratedHsailUsingLambdaMethod(); + } +} diff -r 6adb14d2320c -r bbb987aec58d src/gpu/hsail/vm/gpu_hsail.cpp --- a/src/gpu/hsail/vm/gpu_hsail.cpp Wed Aug 20 17:10:13 2014 +0200 +++ b/src/gpu/hsail/vm/gpu_hsail.cpp Thu Aug 21 11:12:38 2014 +0200 @@ -140,6 +140,8 @@ jint num_tlabs, int allocBytesPerWorkitem, jobject oop_map_array, TRAPS) { ResourceMark rm(THREAD); objArrayOop argsArray = (objArrayOop) JNIHandles::resolve(args); + // Note this length does not include the iteration variable since it is replaced by the HSA workitemid + int argsArrayLength = argsArray->length(); assert(THREAD->is_Java_thread(), "must be a JavaThread"); // We avoid HSAILAllocationInfo logic if kernel does not allocate @@ -296,7 +298,8 @@ KlassHandle methKlass = mh->method_holder(); Thread* THREAD = Thread::current(); JavaValue result(T_VOID); - JavaCallArguments javaArgs; + // Add the iteration variable to the HSA args length + JavaCallArguments javaArgs(argsArrayLength + 1); // re-resolve the args_handle here objArrayOop resolvedArgsArray = (objArrayOop) JNIHandles::resolve(args); @@ -344,8 +347,11 @@ // The kernel entrypoint is always run for the time being const char* entryPointName = "&run"; jlong okra_kernel; - jint okra_status = _okra_create_kernel(_device_context, code, entryPointName, (void**)&okra_kernel); - guarantee(okra_status==0, "_okra_create_kernel failed"); + { + TraceTime t("generate kernel ", TraceGPUInteraction); + jint okra_status = _okra_create_kernel(_device_context, code, entryPointName, (void**)&okra_kernel); + guarantee(okra_status==0, "_okra_create_kernel failed"); + } return (jlong) okra_kernel; GPU_END