你已经派生过 gprMax
镜像自地址
https://gitee.com/sunhf/gprMax.git
已同步 2025-08-08 07:24:19 +08:00
Beginning host/GPU detection for OpenCL
这个提交包含在:
@@ -28,7 +28,7 @@ from scipy.constants import c
|
|||||||
from scipy.constants import epsilon_0 as e0
|
from scipy.constants import epsilon_0 as e0
|
||||||
from scipy.constants import mu_0 as m0
|
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
|
from .utilities.utilities import get_terminal_width
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -236,7 +236,7 @@ class SimulationConfig:
|
|||||||
if sys.platform == 'win32': self.cuda['nvcc_opts'] = ['-w']
|
if sys.platform == 'win32': self.cuda['nvcc_opts'] = ['-w']
|
||||||
|
|
||||||
# List of GPU objects of available GPUs
|
# 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
|
# Subgrid parameter may not exist if user enters via CLI
|
||||||
try:
|
try:
|
||||||
|
@@ -302,32 +302,30 @@ def mem_check_all(grids):
|
|||||||
class GPU:
|
class GPU:
|
||||||
"""GPU information."""
|
"""GPU information."""
|
||||||
|
|
||||||
def __init__(self, deviceID):
|
def __init__(self):
|
||||||
"""
|
|
||||||
Args:
|
|
||||||
deviceID (int): Device ID for GPU.
|
|
||||||
"""
|
|
||||||
|
|
||||||
self.deviceID = deviceID
|
self.deviceID = None
|
||||||
self.name = None
|
self.name = None
|
||||||
self.pcibusID = None
|
self.pcibusID = None
|
||||||
self.constmem = None
|
self.constmem = None
|
||||||
self.totalmem = None
|
self.totalmem = None
|
||||||
|
|
||||||
def get_gpu_info(self, drv):
|
def get_cuda_gpu_info(self, drv, deviceID):
|
||||||
"""Set information about GPU.
|
"""Set information about GPU.
|
||||||
|
|
||||||
Args:
|
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.name = drv.Device(self.deviceID).name()
|
||||||
self.pcibusID = drv.Device(self.deviceID).pci_bus_id()
|
self.pcibusID = drv.Device(self.deviceID).pci_bus_id()
|
||||||
self.constmem = drv.Device(self.deviceID).total_constant_memory
|
self.constmem = drv.Device(self.deviceID).total_constant_memory
|
||||||
self.totalmem = drv.Device(self.deviceID).total_memory()
|
self.totalmem = drv.Device(self.deviceID).total_memory()
|
||||||
|
|
||||||
|
|
||||||
def detect_gpus():
|
def detect_cuda_gpus():
|
||||||
"""Get information about Nvidia GPU(s).
|
"""Get information about Nvidia GPU(s).
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
@@ -336,26 +334,52 @@ def detect_gpus():
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
import pycuda.driver as drv
|
import pycuda.driver as drv
|
||||||
|
has_pycuda = True
|
||||||
except ImportError:
|
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).')
|
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).')
|
||||||
raise
|
has_pycuda = False
|
||||||
drv.init()
|
|
||||||
|
if has_pycuda:
|
||||||
|
drv.init()
|
||||||
|
|
||||||
|
# Check and list any CUDA-Enabled GPUs
|
||||||
|
if drv.Device.count() == 0:
|
||||||
|
logger.exception('No NVIDIA CUDA-Enabled GPUs detected (https://developer.nvidia.com/cuda-gpus)')
|
||||||
|
raise ValueError
|
||||||
|
elif 'CUDA_VISIBLE_DEVICES' in os.environ:
|
||||||
|
deviceIDsavail = os.environ.get('CUDA_VISIBLE_DEVICES')
|
||||||
|
deviceIDsavail = [int(s) for s in deviceIDsavail.split(',')]
|
||||||
|
else:
|
||||||
|
deviceIDsavail = range(drv.Device.count())
|
||||||
|
|
||||||
|
# Gather information about detected GPUs
|
||||||
|
gpus = []
|
||||||
|
for ID in deviceIDsavail:
|
||||||
|
gpu = GPU()
|
||||||
|
gpu.get_cuda_gpu_info(drv, ID)
|
||||||
|
gpus.append(gpu)
|
||||||
|
|
||||||
# Check and list any CUDA-Enabled GPUs
|
|
||||||
if drv.Device.count() == 0:
|
|
||||||
logger.exception('No NVIDIA CUDA-Enabled GPUs detected (https://developer.nvidia.com/cuda-gpus)')
|
|
||||||
raise ValueError
|
|
||||||
elif 'CUDA_VISIBLE_DEVICES' in os.environ:
|
|
||||||
deviceIDsavail = os.environ.get('CUDA_VISIBLE_DEVICES')
|
|
||||||
deviceIDsavail = [int(s) for s in deviceIDsavail.split(',')]
|
|
||||||
else:
|
else:
|
||||||
deviceIDsavail = range(drv.Device.count())
|
gpus = None
|
||||||
|
|
||||||
# Gather information about detected GPUs
|
|
||||||
gpus = []
|
|
||||||
for ID in deviceIDsavail:
|
|
||||||
gpu = GPU(deviceID=ID)
|
|
||||||
gpu.get_gpu_info(drv)
|
|
||||||
gpus.append(gpu)
|
|
||||||
|
|
||||||
return gpus
|
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)
|
||||||
|
在新工单中引用
屏蔽一个用户