Beginning host/GPU detection for OpenCL

这个提交包含在:
Craig Warren
2021-06-01 11:30:18 +01:00
父节点 46ab45660c
当前提交 adebdfc580
共有 2 个文件被更改,包括 53 次插入29 次删除

查看文件

@@ -28,7 +28,7 @@ from scipy.constants import c
from scipy.constants import epsilon_0 as e0
from scipy.constants import mu_0 as m0
from .utilities.host_info import detect_gpus, get_host_info
from .utilities.host_info import detect_cuda_gpus, get_host_info
from .utilities.utilities import get_terminal_width
logger = logging.getLogger(__name__)
@@ -236,7 +236,7 @@ class SimulationConfig:
if sys.platform == 'win32': self.cuda['nvcc_opts'] = ['-w']
# List of GPU objects of available GPUs
self.cuda['gpus'] = detect_gpus()
self.cuda['gpus'] = detect_cuda_gpus()
# Subgrid parameter may not exist if user enters via CLI
try:

查看文件

@@ -302,32 +302,30 @@ def mem_check_all(grids):
class GPU:
"""GPU information."""
def __init__(self, deviceID):
"""
Args:
deviceID (int): Device ID for GPU.
"""
def __init__(self):
self.deviceID = deviceID
self.deviceID = None
self.name = None
self.pcibusID = None
self.constmem = None
self.totalmem = None
def get_gpu_info(self, drv):
def get_cuda_gpu_info(self, drv, deviceID):
"""Set information about GPU.
Args:
drv (object): PyCuda driver.
drv (object): pycuda driver.
deviceID (int): Device ID for GPU.
"""
self.deviceID = deviceID
self.name = drv.Device(self.deviceID).name()
self.pcibusID = drv.Device(self.deviceID).pci_bus_id()
self.constmem = drv.Device(self.deviceID).total_constant_memory
self.totalmem = drv.Device(self.deviceID).total_memory()
def detect_gpus():
def detect_cuda_gpus():
"""Get information about Nvidia GPU(s).
Returns:
@@ -336,9 +334,12 @@ def detect_gpus():
try:
import pycuda.driver as drv
has_pycuda = True
except ImportError:
logger.exception('To use gprMax in GPU mode the pycuda package must be installed, and you must have a NVIDIA CUDA-Enabled GPU (https://developer.nvidia.com/cuda-gpus).')
raise
logger.warning('pycuda not detected - to use gprMax in GPU mode the pycuda package must be installed, and you must have a NVIDIA CUDA-Enabled GPU (https://developer.nvidia.com/cuda-gpus).')
has_pycuda = False
if has_pycuda:
drv.init()
# Check and list any CUDA-Enabled GPUs
@@ -354,8 +355,31 @@ def detect_gpus():
# Gather information about detected GPUs
gpus = []
for ID in deviceIDsavail:
gpu = GPU(deviceID=ID)
gpu.get_gpu_info(drv)
gpu = GPU()
gpu.get_cuda_gpu_info(drv, ID)
gpus.append(gpu)
else:
gpus = None
return gpus
def detect_opencl():
"""Get information about OpenCL platforms and devices.
Returns:
gpus (list): Detected GPU(s) object(s).
"""
try:
import pyopencl as cl
has_pyopencl = True
except ImportError:
logger.warning('pyopencl not detected - to use gprMax with OpenCL, the pyopencl package must be installed, and you must have at least one OpenCL capable platform.')
has_pyopencl = False
if has_pyopencl:
platforms = cl.get_platforms()
platform_names = [p.name for p in platforms]
logger.info(platform_names)