Implement requesting device by index
For now main goal is to be able to request specific Vega card. In the longer term we can use this to select compute device which is a non-display, or the one which is on specific PCI slot or so.
This commit is contained in:
@@ -16,7 +16,8 @@ def setUseRequestedDevice(context,
|
||||
cpref,
|
||||
device_type,
|
||||
requested_device,
|
||||
device_single):
|
||||
device_single,
|
||||
requested_device_index):
|
||||
import _cycles
|
||||
# Empty device type means we'l ltry to render on a single card,
|
||||
# preferably non-display one.
|
||||
@@ -44,38 +45,60 @@ def setUseRequestedDevice(context,
|
||||
device_found = True
|
||||
else:
|
||||
device_found = False
|
||||
device_index = 0
|
||||
for device in cpref.devices:
|
||||
device_name = device.name.replace(" (Display)", "")
|
||||
if device_name == requested_device:
|
||||
if not device_found or not device_single:
|
||||
if requested_device_index != -1:
|
||||
if device_index == requested_device_index:
|
||||
device.use = True
|
||||
device_found = True
|
||||
else:
|
||||
device.use = False
|
||||
elif not device_found or not device_single:
|
||||
device.use = True
|
||||
device_found = True
|
||||
else:
|
||||
device.use = False
|
||||
device_index += 1
|
||||
else:
|
||||
device.use = False
|
||||
return device_found
|
||||
|
||||
|
||||
def setDeviceCUDA(context, cpref, requested_device, device_single):
|
||||
def setDeviceCUDA(context,
|
||||
cpref,
|
||||
requested_device,
|
||||
device_single,
|
||||
requested_device_index):
|
||||
cpref.compute_device_type = 'CUDA'
|
||||
return setUseRequestedDevice(context,
|
||||
cpref,
|
||||
'CUDA',
|
||||
requested_device,
|
||||
device_single)
|
||||
device_single,
|
||||
requested_device_index)
|
||||
|
||||
|
||||
def setDeviceOpenCL(context, cpref, requested_device, device_single):
|
||||
def setDeviceOpenCL(context,
|
||||
cpref,
|
||||
requested_device,
|
||||
device_single,
|
||||
requested_device_index):
|
||||
cpref.compute_device_type = 'OPENCL'
|
||||
return setUseRequestedDevice(context,
|
||||
cpref,
|
||||
'OPENCL',
|
||||
requested_device,
|
||||
device_single)
|
||||
device_single,
|
||||
requested_device_index)
|
||||
|
||||
|
||||
def setDeviceGPU(context, cpref, requested_device, device_single):
|
||||
def setDeviceGPU(context,
|
||||
cpref,
|
||||
requested_device,
|
||||
device_single,
|
||||
requested_device_index):
|
||||
import _cycles
|
||||
has_cuda = has_opencl = False
|
||||
for device in _cycles.available_devices():
|
||||
@@ -85,9 +108,17 @@ def setDeviceGPU(context, cpref, requested_device, device_single):
|
||||
has_opencl = True
|
||||
|
||||
if has_cuda:
|
||||
return setDeviceCUDA(context, cpref, requested_device, device_single)
|
||||
return setDeviceCUDA(context,
|
||||
cpref,
|
||||
requested_device,
|
||||
device_single,
|
||||
requested_device_index)
|
||||
if has_opencl:
|
||||
return setDeviceOpenCL(context, cpref, requested_device, device_single)
|
||||
return setDeviceOpenCL(context,
|
||||
cpref,
|
||||
requested_device,
|
||||
device_single,
|
||||
requested_device_index)
|
||||
return False
|
||||
|
||||
|
||||
@@ -145,6 +176,9 @@ def main():
|
||||
help="Use single device when multiple are found",
|
||||
action='store_true',
|
||||
default=False)
|
||||
parser.add_argument("--benchmark-device-index",
|
||||
help="Use device of a given index whe nusing single device",
|
||||
default=-1)
|
||||
parser.add_argument("--benchmark-system-info",
|
||||
help="Dump whole system information",
|
||||
action='store_true',
|
||||
@@ -182,17 +216,20 @@ def main():
|
||||
device_ok = setDeviceCUDA(context,
|
||||
cpref,
|
||||
args.benchmark_device,
|
||||
args.benchmark_device_single)
|
||||
args.benchmark_device_single,
|
||||
int(args.benchmark_device_index))
|
||||
elif args.benchmark_device_type == 'OPENCL':
|
||||
device_ok = setDeviceOpenCL(context,
|
||||
cpref,
|
||||
args.benchmark_device,
|
||||
args.benchmark_device_single)
|
||||
args.benchmark_device_single,
|
||||
int(args.benchmark_device_index))
|
||||
elif args.benchmark_device_type == 'GPU':
|
||||
device_ok = setDeviceGPU(context,
|
||||
cpref,
|
||||
args.benchmark_device,
|
||||
args.benchmark_device_single)
|
||||
args.benchmark_device_single,
|
||||
int(args.benchmark_device_index))
|
||||
if not device_ok:
|
||||
sys.exit(1)
|
||||
|
||||
|
Reference in New Issue
Block a user