# HG changeset patch # User bharadwaj # Date 1378933360 14400 # Node ID 4f69a5189e778afd15ee02b3cca5d8760cdc3c37 # Parent 3676540f71cf83bcb4d8a0c628c2f11b342d9724 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring. diff -r 3676540f71cf -r 4f69a5189e77 src/gpu/ptx/vm/gpu_ptx.cpp --- a/src/gpu/ptx/vm/gpu_ptx.cpp Wed Sep 11 21:04:24 2013 +0200 +++ b/src/gpu/ptx/vm/gpu_ptx.cpp Wed Sep 11 17:02:40 2013 -0400 @@ -50,36 +50,6 @@ gpu::Ptx::cuda_cu_memcpy_dtoh_func_t gpu::Ptx::_cuda_cu_memcpy_dtoh; gpu::Ptx::cuda_cu_memfree_func_t gpu::Ptx::_cuda_cu_memfree; -void gpu::probe_linkage() { -#if defined(__APPLE__) || defined(LINUX) - set_gpu_linkage(gpu::Ptx::probe_linkage()); -#else - set_gpu_linkage(false); -#endif -} - -void gpu::initialize_gpu() { - if (gpu::has_gpu_linkage()) { - set_initialized(gpu::Ptx::initialize_gpu()); - } -} - -void * gpu::generate_kernel(unsigned char *code, int code_len, const char *name) { - if (gpu::has_gpu_linkage()) { - return (gpu::Ptx::generate_kernel(code, code_len, name)); - } else { - return NULL; - } -} - -bool gpu::execute_kernel(address kernel, PTXKernelArguments & ptxka, JavaValue& ret) { - if (gpu::has_gpu_linkage()) { - return (gpu::Ptx::execute_kernel(kernel, ptxka, ret)); - } else { - return false; - } -} - bool gpu::Ptx::initialize_gpu() { /* Initialize CUDA driver API */ diff -r 3676540f71cf -r 4f69a5189e77 src/os_gpu/bsd_ptx/vm/gpu_bsd.cpp --- a/src/os_gpu/bsd_ptx/vm/gpu_bsd.cpp Wed Sep 11 21:04:24 2013 +0200 +++ b/src/os_gpu/bsd_ptx/vm/gpu_bsd.cpp Wed Sep 11 17:02:40 2013 -0400 @@ -33,6 +33,7 @@ * a better detection solution for NVIDA PTX and AMD HSAIL. */ set_available(true); + set_target_il_type(gpu::PTX); if (TraceGPUInteraction) { tty->print_cr("gpu_bsd::probe_gpu(APPLE): %d", gpu::is_available()); } diff -r 3676540f71cf -r 4f69a5189e77 src/os_gpu/linux_ptx/vm/gpu_linux.cpp --- a/src/os_gpu/linux_ptx/vm/gpu_linux.cpp Wed Sep 11 21:04:24 2013 +0200 +++ b/src/os_gpu/linux_ptx/vm/gpu_linux.cpp Wed Sep 11 17:02:40 2013 -0400 @@ -39,32 +39,40 @@ */ static unsigned int nvidia_vendor_id = 0x10de; +static unsigned int amd_vendor_id = 0x1002; bool gpu::Linux::probe_gpu() { /* - * Open /proc/bus/pci/devices to look for the first CUDA enabled - * device. For now, finding the first CUDA device. Will need to - * revisit this to support execution on multiple CUDA devices if - * they exist. + * Open /proc/bus/pci/devices to look for the first GPU device. For + * now, we will just find the first GPU device. Will need to revisit + * this to support execution on multiple GPU devices, if they exist. */ FILE *pci_devices = fopen("/proc/bus/pci/devices", "r"); char contents[4096]; unsigned int bus_num_devfn_ign; unsigned int vendor; unsigned int device; - bool cuda_device_exists = false; + bool gpu_device_exists = false; if (pci_devices == NULL) { tty->print_cr("*** Failed to open /proc/bus/pci/devices"); - return cuda_device_exists; + return gpu_device_exists; } while (fgets(contents, sizeof(contents)-1, pci_devices)) { sscanf(contents, "%04x%04x%04x", &bus_num_devfn_ign, &vendor, &device); - /* Break after finding the first CUDA device. */ + /* Break after finding the first GPU device. */ if (vendor == nvidia_vendor_id) { - cuda_device_exists = true; + gpu_device_exists = true; + set_target_il_type(gpu::PTX); if (TraceGPUInteraction) { - tty->print_cr("Found supported nVidia CUDA device vendor : 0x%04x device 0x%04x", vendor, device); + tty->print_cr("Found supported nVidia GPU device vendor : 0x%04x device 0x%04x", vendor, device); + } + break; + } else if (vendor == amd_vendor_id) { + gpu_device_exists = true; + set_target_il_type(gpu::HSAIL); + if (TraceGPUInteraction) { + tty->print_cr("Found supported AMD GPU device vendor : 0x%04x device 0x%04x", vendor, device); } break; } @@ -73,5 +81,5 @@ // Close file pointer. fclose(pci_devices); - return cuda_device_exists; + return gpu_device_exists; } diff -r 3676540f71cf -r 4f69a5189e77 src/share/vm/graal/graalVMToCompiler.cpp --- a/src/share/vm/graal/graalVMToCompiler.cpp Wed Sep 11 21:04:24 2013 +0200 +++ b/src/share/vm/graal/graalVMToCompiler.cpp Wed Sep 11 17:02:40 2013 -0400 @@ -62,8 +62,14 @@ if (JNIHandles::resolve(_graalRuntimePermObject) == NULL) { #ifdef AMD64 Symbol* name = NULL; - if (UseGPU && gpu::is_available() && gpu::has_gpu_linkage()) { - name = vmSymbols::com_oracle_graal_hotspot_ptx_PTXHotSpotGraalRuntime(); + if (UseGPU) { + // Set name to PTXHotSpotRuntime if nVidia GPU was detected. + if ((gpu::get_target_il_type() == gpu::PTX) && + gpu::is_available() && gpu::has_gpu_linkage()) { + name = vmSymbols::com_oracle_graal_hotspot_ptx_PTXHotSpotGraalRuntime(); + } + // Set name to corresponding runtime classname for other + // supported GPU runtimes, here. } else { name = vmSymbols::com_oracle_graal_hotspot_amd64_AMD64HotSpotGraalRuntime(); } diff -r 3676540f71cf -r 4f69a5189e77 src/share/vm/runtime/gpu.cpp --- a/src/share/vm/runtime/gpu.cpp Wed Sep 11 21:04:24 2013 +0200 +++ b/src/share/vm/runtime/gpu.cpp Wed Sep 11 17:02:40 2013 -0400 @@ -25,14 +25,50 @@ #include "precompiled.hpp" #include "runtime/gpu.hpp" -bool gpu::_available = false; // does the hardware exist? -bool gpu::_gpu_linkage = false; // is the driver library to access the GPU installed -bool gpu::_initialized = false; // is the GPU device initialized +bool gpu::_available = false; // does the hardware exist? +bool gpu::_gpu_linkage = false; // is the driver library to access the GPU installed +bool gpu::_initialized = false; // is the GPU device initialized +gpu::TargetGPUIL gpu::_targetIL = gpu::NONE; // No GPU detected yet. void gpu::init() { #if defined(TARGET_OS_FAMILY_bsd) || defined(TARGET_OS_FAMILY_linux) gpu::probe_gpu(); + if (gpu::get_target_il_type() == gpu::PTX) { + set_gpu_linkage(gpu::Ptx::probe_linkage()); + } else { + set_gpu_linkage(false); + } #endif - // need multi-gpu TARGET ifdef - gpu::probe_linkage(); +} + +void gpu::initialize_gpu() { + if (gpu::has_gpu_linkage()) { + if (gpu::get_target_il_type() == gpu::PTX) { + set_initialized(gpu::Ptx::initialize_gpu()); + } + // Add initialization of other GPUs here + } } + +void * gpu::generate_kernel(unsigned char *code, int code_len, const char *name) { + if (gpu::has_gpu_linkage()) { + if (gpu::get_target_il_type() == gpu::PTX) { + return (gpu::Ptx::generate_kernel(code, code_len, name)); + } + } else { + // Add kernel generation functionality of other GPUs here + return NULL; + } +} + +bool gpu::execute_kernel(address kernel, PTXKernelArguments & ptxka, JavaValue& ret) { + if (gpu::has_gpu_linkage()) { + if (gpu::get_target_il_type() == gpu::PTX) { + return (gpu::Ptx::execute_kernel(kernel, ptxka, ret)); + } + } else { + // Add kernel execution functionality of other GPUs here + return false; + } +} + diff -r 3676540f71cf -r 4f69a5189e77 src/share/vm/runtime/gpu.hpp --- a/src/share/vm/runtime/gpu.hpp Wed Sep 11 21:04:24 2013 +0200 +++ b/src/share/vm/runtime/gpu.hpp Wed Sep 11 17:02:40 2013 -0400 @@ -36,12 +36,12 @@ class gpu: AllStatic { public: + + enum TargetGPUIL { NONE = 0, PTX = 1, HSAIL = 2}; static void init(void); static void probe_gpu(); - static void probe_linkage(); - static void initialize_gpu(); static void * generate_kernel(unsigned char *code, int code_len, const char *name); @@ -66,10 +66,19 @@ static bool has_gpu_linkage() { return _gpu_linkage; } + static void set_target_il_type(TargetGPUIL value) { + _targetIL = value; + } + + static enum gpu::TargetGPUIL get_target_il_type() { + return _targetIL; + } + protected: static bool _available; static bool _gpu_linkage; static bool _initialized; + static TargetGPUIL _targetIL; // Platform dependent stuff #ifdef TARGET_OS_FAMILY_linux