# HG changeset patch # User Tom Rodriguez # Date 1390523757 28800 # Node ID 978587c9137375de930fc94725842b7323a32242 # Parent d96dbd96bb4518c80714c4b1633f84aae2d1aedc# Parent bfd61161d75233becf9b6d2fe4de85268a63e890 Merge diff -r d96dbd96bb45 -r 978587c91373 graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILCompilationResult.java --- a/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILCompilationResult.java Thu Jan 23 16:15:04 2014 -0800 +++ b/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILCompilationResult.java Thu Jan 23 16:35:57 2014 -0800 @@ -96,33 +96,6 @@ return getHSAILCompilationResult(graph); } - /** - * HSAIL doesn't have a calling convention as such. Function arguments are actually passed in - * memory but then loaded into registers in the function body. This routine makes sure that - * arguments to a kernel or function are loaded (by the kernel or function body) into registers - * of the appropriate sizes. For example, int and float parameters should appear in S registers, - * whereas double and long parameters should appear in d registers. - */ - public static CallingConvention getHSAILCallingConvention(CallingConvention.Type type, TargetDescription target, ResolvedJavaMethod method, boolean stackOnly) { - Signature sig = method.getSignature(); - JavaType retType = sig.getReturnType(null); - int sigCount = sig.getParameterCount(false); - JavaType[] argTypes; - int argIndex = 0; - if (!Modifier.isStatic(method.getModifiers())) { - argTypes = new JavaType[sigCount + 1]; - argTypes[argIndex++] = method.getDeclaringClass(); - } else { - argTypes = new JavaType[sigCount]; - } - for (int i = 0; i < sigCount; i++) { - argTypes[argIndex++] = sig.getParameterType(i, null); - } - - RegisterConfig registerConfig = backend.getProviders().getCodeCache().getRegisterConfig(); - return registerConfig.getCallingConvention(type, retType, argTypes, target, stackOnly); - } - public static HSAILCompilationResult getCompiledLambda(Class consumerClass) { /** * Find the accept() method in the IntConsumer, then use Graal API to find the target lambda @@ -168,7 +141,7 @@ PhaseSuite graphBuilderSuite = backend.getSuites().getDefaultGraphBuilderSuite().copy(); graphBuilderSuite.appendPhase(new HSAILPhase()); new HSAILPhase().apply(graph); - CallingConvention cc = getHSAILCallingConvention(Type.JavaCallee, target, graph.method(), false); + CallingConvention cc = CodeUtil.getCallingConvention(providers.getCodeCache(), Type.JavaCallee, graph.method(), false); SuitesProvider suitesProvider = backend.getSuites(); try { HSAILCompilationResult compResult = compileGraph(graph, cc, graph.method(), providers, backend, target, null, graphBuilderSuite, OptimisticOptimizations.NONE, getProfilingInfo(graph), diff -r d96dbd96bb45 -r 978587c91373 mx/projects --- a/mx/projects Thu Jan 23 16:15:04 2014 -0800 +++ b/mx/projects Thu Jan 23 16:35:57 2014 -0800 @@ -24,9 +24,15 @@ library@DACAPO_SCALA@path=lib/dacapo-scala-0.1.0-20120216.jar library@DACAPO_SCALA@urls=http://repo.scalabench.org/snapshots/org/scalabench/benchmarks/scala-benchmark-suite/0.1.0-SNAPSHOT/scala-benchmark-suite-0.1.0-20120216.103539-3.jar -library@OKRA@path=lib/okra-1.2.jar -library@OKRA@sourcePath=lib/okra-1.2.jar -library@OKRA@urls=http://cr.openjdk.java.net/~tdeneau/okra-1.2.jar +library@OKRA@path=lib/okra-1.5.jar +library@OKRA@urls=http://cr.openjdk.java.net/~tdeneau/okra-1.5.jar +library@OKRA@sourcePath=lib/okra-1.5-src.jar +library@OKRA@sourceUrls=http://cr.openjdk.java.net/~tdeneau/okra-1.5-src.jar + +library@OKRA_WITH_SIM@path=lib/okra-1.5-with-sim.jar +library@OKRA_WITH_SIM@urls=http://cr.openjdk.java.net/~tdeneau/okra-1.5-with-sim.jar +library@OKRA_WITH_SIM@sourcePath=lib/okra-1.5-with-sim-src.jar +library@OKRA_WITH_SIM@sourceUrls=http://cr.openjdk.java.net/~tdeneau/okra-1.5-with-sim-src.jar library@JRUBYPARSER@path=lib/jrubyparser-0.5.0.jar library@JRUBYPARSER@urls=http://repo1.maven.org/maven2/org/jruby/jrubyparser/0.5.0/jrubyparser-0.5.0.jar @@ -611,7 +617,7 @@ # graal.compiler.hsail.test.infra - HSAIL compiler test infrastructure project@com.oracle.graal.compiler.hsail.test.infra@subDir=graal project@com.oracle.graal.compiler.hsail.test.infra@sourceDirs=src -project@com.oracle.graal.compiler.hsail.test.infra@dependencies=com.oracle.graal.hotspot.hsail,JUNIT +project@com.oracle.graal.compiler.hsail.test.infra@dependencies=com.oracle.graal.hotspot.hsail,JUNIT,OKRA_WITH_SIM project@com.oracle.graal.compiler.hsail.test.infra@checkstyle=com.oracle.graal.graph project@com.oracle.graal.compiler.hsail.test.infra@javaCompliance=1.7 diff -r d96dbd96bb45 -r 978587c91373 src/gpu/hsail/vm/gpu_hsail.cpp --- a/src/gpu/hsail/vm/gpu_hsail.cpp Thu Jan 23 16:15:04 2014 -0800 +++ b/src/gpu/hsail/vm/gpu_hsail.cpp Thu Jan 23 16:35:57 2014 -0800 @@ -87,6 +87,12 @@ void *gpu::Hsail::generate_kernel(unsigned char *code, int code_len, const char *name) { + if (_okra_create_kernel == NULL) { + // probe linkage and we really need it to work this time + bool success = probe_linkage_internal(true); + guarantee(success, "[HSAIL] loading okra library"); + } + gpu::Hsail::register_heap(); // The kernel entrypoint is always run for the time being @@ -124,44 +130,66 @@ } \ bool gpu::Hsail::probe_linkage() { - if (okra_library_name != NULL) { - char *buffer = (char*)malloc(STD_BUFFER_SIZE); - if (TraceGPUInteraction) { - tty->print_cr("[HSAIL] library is %s", okra_library_name); - } - void *handle = os::dll_load(okra_library_name, buffer, STD_BUFFER_SIZE); - free(buffer); - if (handle != NULL) { + return probe_linkage_internal(false); +} - LOOKUP_OKRA_FUNCTION(okra_create_context, okra_create_context); - LOOKUP_OKRA_FUNCTION(okra_create_kernel, okra_create_kernel); - LOOKUP_OKRA_FUNCTION(okra_push_object, okra_push_object); - LOOKUP_OKRA_FUNCTION(okra_push_boolean, okra_push_boolean); - LOOKUP_OKRA_FUNCTION(okra_push_byte, okra_push_byte); - LOOKUP_OKRA_FUNCTION(okra_push_double, okra_push_double); - LOOKUP_OKRA_FUNCTION(okra_push_float, okra_push_float); - LOOKUP_OKRA_FUNCTION(okra_push_int, okra_push_int); - LOOKUP_OKRA_FUNCTION(okra_push_long, okra_push_long); - LOOKUP_OKRA_FUNCTION(okra_execute_with_range, okra_execute_with_range); - LOOKUP_OKRA_FUNCTION(okra_clearargs, okra_clearargs); - LOOKUP_OKRA_FUNCTION(okra_register_heap, okra_register_heap); - return true; - } else { - // Unable to dlopen okra - if (TraceGPUInteraction) { - tty->print_cr("[HSAIL] library load failed."); - } - return false; - } - } else { +bool gpu::Hsail::probe_linkage_internal(bool isRequired) { + if (okra_library_name == NULL) { if (TraceGPUInteraction) { tty->print_cr("Unsupported HSAIL platform"); } return false; } + + // here we know we have a valid okra_library_name to try to load + // the isRequired boolean specifies whether it is an error if the + // probe does not find the okra library + char *buffer = (char*)malloc(STD_BUFFER_SIZE); if (TraceGPUInteraction) { - tty->print_cr("Failed to find HSAIL linkage"); + tty->print_cr("[HSAIL] library is %s", okra_library_name); + } + void *handle = os::dll_load(okra_library_name, buffer, STD_BUFFER_SIZE); + // try alternate location if env variable set + char *okra_lib_name_from_env_var = getenv("_OKRA_SIM_LIB_PATH_"); + if ((handle == NULL) && (okra_lib_name_from_env_var != NULL)) { + handle = os::dll_load(okra_lib_name_from_env_var, buffer, STD_BUFFER_SIZE); + if ((handle != NULL) && TraceGPUInteraction) { + tty->print_cr("[HSAIL] using _OKRA_SIM_LIB_PATH_=%s", getenv("_OKRA_SIM_LIB_PATH_")); + } + } + free(buffer); + + if ((handle == NULL) && !isRequired) { + // return true for now but we will probe again later + if (TraceGPUInteraction) { + tty->print_cr("[HSAIL] library load not in PATH, waiting for Java to put in tmpdir."); + } + return true; } - return false; + + if ((handle == NULL) && isRequired) { + // Unable to dlopen okra + if (TraceGPUInteraction) { + tty->print_cr("[HSAIL] library load failed."); + } + return false; + } + + // at this point we know handle is valid and we can lookup the functions + LOOKUP_OKRA_FUNCTION(okra_create_context, okra_create_context); + LOOKUP_OKRA_FUNCTION(okra_create_kernel, okra_create_kernel); + LOOKUP_OKRA_FUNCTION(okra_push_object, okra_push_object); + LOOKUP_OKRA_FUNCTION(okra_push_boolean, okra_push_boolean); + LOOKUP_OKRA_FUNCTION(okra_push_byte, okra_push_byte); + LOOKUP_OKRA_FUNCTION(okra_push_double, okra_push_double); + LOOKUP_OKRA_FUNCTION(okra_push_float, okra_push_float); + LOOKUP_OKRA_FUNCTION(okra_push_int, okra_push_int); + LOOKUP_OKRA_FUNCTION(okra_push_long, okra_push_long); + LOOKUP_OKRA_FUNCTION(okra_execute_with_range, okra_execute_with_range); + LOOKUP_OKRA_FUNCTION(okra_clearargs, okra_clearargs); + LOOKUP_OKRA_FUNCTION(okra_register_heap, okra_register_heap); + + // if we made it this far, real success + return true; } diff -r d96dbd96bb45 -r 978587c91373 src/gpu/hsail/vm/gpu_hsail.hpp --- a/src/gpu/hsail/vm/gpu_hsail.hpp Thu Jan 23 16:15:04 2014 -0800 +++ b/src/gpu/hsail/vm/gpu_hsail.hpp Thu Jan 23 16:35:57 2014 -0800 @@ -56,6 +56,8 @@ typedef bool (*okra_execute_with_range_func_t)(void*, jint); typedef bool (*okra_clearargs_func_t)(void*); typedef bool (*okra_register_heap_func_t)(void*, size_t); + + static bool probe_linkage_internal(bool isRequired); public: static okra_create_context_func_t _okra_create_context; diff -r d96dbd96bb45 -r 978587c91373 src/share/vm/runtime/thread.cpp --- a/src/share/vm/runtime/thread.cpp Thu Jan 23 16:15:04 2014 -0800 +++ b/src/share/vm/runtime/thread.cpp Thu Jan 23 16:35:57 2014 -0800 @@ -3395,11 +3395,8 @@ if (parse_result != JNI_OK) return parse_result; #ifdef GRAAL - if (GPUOffload) { - // Probe for existance of supported GPU and initialize it if one - // exists. - gpu::init(); - } + // Probe for supported GPUs and initialize them. + gpu::init(); #endif os::init_before_ergo();