# HG changeset patch # User Doug Simon # Date 1390521126 -3600 # Node ID bfd61161d75233becf9b6d2fe4de85268a63e890 # Parent ac1e626432f94f8b9c9dbfe9e178cf99d1881f5f HSAIL: support for using Okra simulator without needing to configure PATH and LD_LIBRARY_PATH Contributed-by: Tom Deneau diff -r ac1e626432f9 -r bfd61161d752 mx/projects --- a/mx/projects Fri Jan 24 00:49:10 2014 +0100 +++ b/mx/projects Fri Jan 24 00:52:06 2014 +0100 @@ -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 ac1e626432f9 -r bfd61161d752 src/gpu/hsail/vm/gpu_hsail.cpp --- a/src/gpu/hsail/vm/gpu_hsail.cpp Fri Jan 24 00:49:10 2014 +0100 +++ b/src/gpu/hsail/vm/gpu_hsail.cpp Fri Jan 24 00:52:06 2014 +0100 @@ -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 ac1e626432f9 -r bfd61161d752 src/gpu/hsail/vm/gpu_hsail.hpp --- a/src/gpu/hsail/vm/gpu_hsail.hpp Fri Jan 24 00:49:10 2014 +0100 +++ b/src/gpu/hsail/vm/gpu_hsail.hpp Fri Jan 24 00:52:06 2014 +0100 @@ -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;