comparison src/gpu/hsail/vm/gpu_hsail.cpp @ 15067:0e689f20706e

HSAIL: avoid loading native Okra library twice Contributed-by: Tom Deneau <tom.deneau@amd.com>
author Doug Simon <doug.simon@oracle.com>
date Fri, 11 Apr 2014 17:44:40 +0200
parents 2cae21d9f122
children 2c940b1a48d8
comparison
equal deleted inserted replaced
15066:2cae21d9f122 15067:0e689f20706e
486 486
487 #define STRINGIFY(x) #x 487 #define STRINGIFY(x) #x
488 488
489 #define LOOKUP_OKRA_FUNCTION(name, alias) \ 489 #define LOOKUP_OKRA_FUNCTION(name, alias) \
490 _##alias = \ 490 _##alias = \
491 CAST_TO_FN_PTR(alias##_func_t, os::dll_lookup(handle, STRINGIFY(name))); \ 491 CAST_TO_FN_PTR(alias##_func_t, os::dll_lookup(okra_lib_handle, STRINGIFY(name))); \
492 if (_##alias == NULL) { \ 492 if (_##alias == NULL) { \
493 tty->print_cr("[HSAIL] ***** Error: Failed to lookup %s in %s, wrong version of OKRA?", STRINGIFY(name), okra_library_name); \ 493 tty->print_cr("[HSAIL] ***** Error: Failed to lookup %s in %s, wrong version of OKRA?", STRINGIFY(name), okra_library_name); \
494 return false; \ 494 return false; \
495 } \ 495 } \
496 496
502 return false; 502 return false;
503 } 503 }
504 504
505 // here we know we have a valid okra_library_name to try to load 505 // here we know we have a valid okra_library_name to try to load
506 char ebuf[O_BUFLEN]; 506 char ebuf[O_BUFLEN];
507 char *okra_lib_name_from_env_var = getenv("_OKRA_SIM_LIB_PATH_");
508 if (okra_lib_name_from_env_var != NULL) {
509 okra_library_name = okra_lib_name_from_env_var;
510 }
507 if (TraceGPUInteraction) { 511 if (TraceGPUInteraction) {
508 tty->print_cr("[HSAIL] library is %s", okra_library_name); 512 tty->print_cr("[HSAIL] library is %s", okra_library_name);
509 } 513 }
510 514 void *okra_lib_handle = NULL;
511 void *handle = os::dll_load(okra_library_name, ebuf, O_BUFLEN); 515 #if defined(LINUX)
512 // try alternate location if env variable set 516 // Check first if the Okra library is already loaded.
513 char *okra_lib_name_from_env_var = getenv("_OKRA_SIM_LIB_PATH_"); 517 // TODO: Figure out how to do this on other OSes.
514 if ((handle == NULL) && (okra_lib_name_from_env_var != NULL)) { 518 okra_lib_handle = ::dlopen(okra_library_name, RTLD_LAZY | RTLD_NOLOAD);
515 handle = os::dll_load(okra_lib_name_from_env_var, ebuf, O_BUFLEN); 519 #endif
516 if ((handle != NULL) && TraceGPUInteraction) { 520 // If Okra library is not already loaded, load it here
517 tty->print_cr("[HSAIL] using _OKRA_SIM_LIB_PATH_=%s", getenv("_OKRA_SIM_LIB_PATH_")); 521 if (okra_lib_handle == NULL) {
518 } 522 okra_lib_handle = os::dll_load(okra_library_name, ebuf, O_BUFLEN);
519 } 523 }
520 524 if (okra_lib_handle == NULL) {
521 if (handle == NULL) { 525 // Unable to open Okra library
522 // Unable to dlopen okra
523 if (TraceGPUInteraction) { 526 if (TraceGPUInteraction) {
524 tty->print_cr("[HSAIL] library load failed."); 527 tty->print_cr("[HSAIL] library load failed.");
525 } 528 }
526 return false; 529 return false;
527 } 530 }
528 531
529 guarantee(_okra_create_context == NULL, "cannot repeat GPU initialization"); 532 guarantee(_okra_create_context == NULL, "cannot repeat GPU initialization");
530 533
531 // at this point we know handle is valid and we can lookup the functions 534 // at this point we know okra_lib_handle is valid whether we loaded
535 // here or earlier. In either case, we can lookup the functions
532 LOOKUP_OKRA_FUNCTION(okra_create_context, okra_create_context); 536 LOOKUP_OKRA_FUNCTION(okra_create_context, okra_create_context);
533 LOOKUP_OKRA_FUNCTION(okra_create_kernel, okra_create_kernel); 537 LOOKUP_OKRA_FUNCTION(okra_create_kernel, okra_create_kernel);
534 LOOKUP_OKRA_FUNCTION(okra_push_object, okra_push_object); 538 LOOKUP_OKRA_FUNCTION(okra_push_object, okra_push_object);
535 LOOKUP_OKRA_FUNCTION(okra_push_boolean, okra_push_boolean); 539 LOOKUP_OKRA_FUNCTION(okra_push_boolean, okra_push_boolean);
536 LOOKUP_OKRA_FUNCTION(okra_push_byte, okra_push_byte); 540 LOOKUP_OKRA_FUNCTION(okra_push_byte, okra_push_byte);