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:
2018-08-10 10:21:04 +02:00
parent 26f5978aae
commit 0e1d2810fe
4 changed files with 77 additions and 18 deletions

View File

@@ -16,7 +16,8 @@ def setUseRequestedDevice(context,
cpref, cpref,
device_type, device_type,
requested_device, requested_device,
device_single): device_single,
requested_device_index):
import _cycles import _cycles
# Empty device type means we'l ltry to render on a single card, # Empty device type means we'l ltry to render on a single card,
# preferably non-display one. # preferably non-display one.
@@ -44,38 +45,60 @@ def setUseRequestedDevice(context,
device_found = True device_found = True
else: else:
device_found = False device_found = False
device_index = 0
for device in cpref.devices: for device in cpref.devices:
device_name = device.name.replace(" (Display)", "") device_name = device.name.replace(" (Display)", "")
if device_name == requested_device: 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.use = True
device_found = True device_found = True
else: else:
device.use = False device.use = False
device_index += 1
else: else:
device.use = False device.use = False
return device_found 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' cpref.compute_device_type = 'CUDA'
return setUseRequestedDevice(context, return setUseRequestedDevice(context,
cpref, cpref,
'CUDA', 'CUDA',
requested_device, 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' cpref.compute_device_type = 'OPENCL'
return setUseRequestedDevice(context, return setUseRequestedDevice(context,
cpref, cpref,
'OPENCL', 'OPENCL',
requested_device, 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 import _cycles
has_cuda = has_opencl = False has_cuda = has_opencl = False
for device in _cycles.available_devices(): for device in _cycles.available_devices():
@@ -85,9 +108,17 @@ def setDeviceGPU(context, cpref, requested_device, device_single):
has_opencl = True has_opencl = True
if has_cuda: 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: if has_opencl:
return setDeviceOpenCL(context, cpref, requested_device, device_single) return setDeviceOpenCL(context,
cpref,
requested_device,
device_single,
requested_device_index)
return False return False
@@ -145,6 +176,9 @@ def main():
help="Use single device when multiple are found", help="Use single device when multiple are found",
action='store_true', action='store_true',
default=False) 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", parser.add_argument("--benchmark-system-info",
help="Dump whole system information", help="Dump whole system information",
action='store_true', action='store_true',
@@ -182,17 +216,20 @@ def main():
device_ok = setDeviceCUDA(context, device_ok = setDeviceCUDA(context,
cpref, cpref,
args.benchmark_device, args.benchmark_device,
args.benchmark_device_single) args.benchmark_device_single,
int(args.benchmark_device_index))
elif args.benchmark_device_type == 'OPENCL': elif args.benchmark_device_type == 'OPENCL':
device_ok = setDeviceOpenCL(context, device_ok = setDeviceOpenCL(context,
cpref, cpref,
args.benchmark_device, args.benchmark_device,
args.benchmark_device_single) args.benchmark_device_single,
int(args.benchmark_device_index))
elif args.benchmark_device_type == 'GPU': elif args.benchmark_device_type == 'GPU':
device_ok = setDeviceGPU(context, device_ok = setDeviceGPU(context,
cpref, cpref,
args.benchmark_device, args.benchmark_device,
args.benchmark_device_single) args.benchmark_device_single,
int(args.benchmark_device_index))
if not device_ok: if not device_ok:
sys.exit(1) sys.exit(1)

View File

@@ -32,6 +32,8 @@ def constructBenchmarkCommand(ctx, scene, blendfile, output_folder, cfra):
command.extend(["--benchmark-device", ctx.device_name]) command.extend(["--benchmark-device", ctx.device_name])
if ctx.device_single: if ctx.device_single:
command.extend(["--benchmark-device-single"]) command.extend(["--benchmark-device-single"])
if ctx.device_index != -1:
command.extend(["--benchmark-device-index", ctx.device_index])
return command return command
@@ -156,6 +158,8 @@ def benchmarkGetDeviceInfo(ctx):
command.extend(["--benchmark-device", ctx.device_name]) command.extend(["--benchmark-device", ctx.device_name])
if ctx.device_single: if ctx.device_single:
command.extend(["--benchmark-device-single"]) command.extend(["--benchmark-device-single"])
if ctx.device_index != -1:
command.extend(["--benchmark-device-index", ctx.device_index])
process = subprocess.Popen(command, process = subprocess.Popen(command,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT) stderr=subprocess.STDOUT)

View File

@@ -8,6 +8,7 @@ class Context:
'device_type', 'device_type',
'device_name', 'device_name',
'device_single', 'device_single',
'device_index',
'scenes', 'scenes',
'scenes_dir', 'scenes_dir',
'configure_script', 'configure_script',
@@ -23,6 +24,8 @@ class Context:
self.device_name = 'NAME' self.device_name = 'NAME'
# Use single device when there are multiple one matching the name # Use single device when there are multiple one matching the name
self.device_single = False self.device_single = False
# Use specified device index when device_single is truth.
self.device_index = -1
# By default we use empty list, it is up to the user to fill it in. # By default we use empty list, it is up to the user to fill it in.
self.scenes = [] self.scenes = []
# It is up to the user to provide proper path to scenes. # It is up to the user to provide proper path to scenes.

View File

@@ -417,7 +417,7 @@ def modify_system_info(system_info):
def modify_device_info(device_info): def modify_device_info(device_info):
compute_device = bpy.context.scene.compute_device compute_device = bpy.context.scene.compute_device
device_type, device_name, compute_units = compute_device.split(":") device_type, device_name, compute_units, device_index = compute_device.split(":")
if device_info["device_type"] == "OPENCL": if device_info["device_type"] == "OPENCL":
compute_devices = [] compute_devices = []
for device in device_info["compute_devices"]: for device in device_info["compute_devices"]:
@@ -686,7 +686,7 @@ class BENCHMARK_OT_run_base(bpy.types.Operator):
if global_cancel: if global_cancel:
global_result_dict = None global_result_dict = None
reset_global_state() reset_global_state()
else: elif global_result_dict:
global_result_stats = "" global_result_stats = ""
for name_stat in global_result_dict["scenes"]: for name_stat in global_result_dict["scenes"]:
stat = name_stat["stats"] stat = name_stat["stats"]
@@ -699,6 +699,8 @@ class BENCHMARK_OT_run_base(bpy.types.Operator):
else: else:
global_result_stats += "{}: {}" . format(name_stat['name'], global_result_stats += "{}: {}" . format(name_stat['name'],
stat["result"]) stat["result"])
else:
global_result_stats = ""
# TOGO(sergey): Use some more nice picture for the final slide. # TOGO(sergey): Use some more nice picture for the final slide.
global global_background_image_path global global_background_image_path
global_background_image_path = "" global_background_image_path = ""
@@ -730,7 +732,7 @@ class BENCHMARK_OT_run_base(bpy.types.Operator):
context.area.tag_redraw() context.area.tag_redraw()
compute_device = context.scene.compute_device compute_device = context.scene.compute_device
device_type, device_name, compute_units = compute_device.split(":") device_type, device_name, compute_units, device_index = compute_device.split(":")
self.tmpdir = tempfile.TemporaryDirectory(prefix="blender_benchmark_") self.tmpdir = tempfile.TemporaryDirectory(prefix="blender_benchmark_")
@@ -756,6 +758,7 @@ class BENCHMARK_OT_run_base(bpy.types.Operator):
# one of the mis to be enabled. Or when requesting GPU render without # one of the mis to be enabled. Or when requesting GPU render without
# specifying GPU name. # specifying GPU name.
ctx.device_single = True ctx.device_single = True
ctx.device_index = device_index
# ctx.image_output_dir = "/tmp/" # ctx.image_output_dir = "/tmp/"
self.benchmark_context = ctx self.benchmark_context = ctx
# Create thread for the actual benchmark. # Create thread for the actual benchmark.
@@ -910,15 +913,23 @@ def compute_device_list_get(self, context):
global global_cached_compute_devices global global_cached_compute_devices
if global_cached_compute_devices: if global_cached_compute_devices:
return global_cached_compute_devices return global_cached_compute_devices
compute_devices = [('CPU::', "CPU", "")] compute_devices = [('CPU:::', "CPU", "")]
if not global_cached_system_info: if not global_cached_system_info:
ctx = benchmark_context.Context() ctx = benchmark_context.Context()
ctx.blender = blender_executable_get() ctx.blender = blender_executable_get()
ctx.configure_script = configure_script_get() ctx.configure_script = configure_script_get()
global_cached_system_info = system_info_get(ctx) global_cached_system_info = system_info_get(ctx)
compute_units = query_opencl_compute_units() compute_units = query_opencl_compute_units()
device_indices = {}
for device in global_cached_system_info["devices"]: for device in global_cached_system_info["devices"]:
raw_device_name = device["name"]
device_type = device["type"] device_type = device["type"]
if raw_device_name in device_indices:
device_indices[raw_device_name] += 1
device_index = device_indices[raw_device_name]
else:
device_indices[raw_device_name] = 0
device_index = 0
if device_type == "CPU": if device_type == "CPU":
continue continue
elif device_type == "OPENCL": elif device_type == "OPENCL":
@@ -930,11 +941,15 @@ def compute_device_list_get(self, context):
device_name += " " + compute_units[index][1] device_name += " " + compute_units[index][1]
device_compute_units = str(compute_units[index][1]) device_compute_units = str(compute_units[index][1])
del compute_units[index] del compute_units[index]
device_id = "{}:{}:{}" . format(device_type, device["name"], device_compute_units) device_id = "{}:{}:{}" . format(device_type,
device["name"],
device_compute_units)
compute_devices.append((device_id, device_name, "")) compute_devices.append((device_id, device_name, ""))
elif device_type == "CUDA": elif device_type == "CUDA":
device_name = correct_device_name(device["name"]) device_name = correct_device_name(device["name"])
device_id = "{}:{}:" . format(device_type, device["name"]) device_id = "{}:{}::{}" . format(device_type,
device["name"],
device_index)
compute_devices.append((device_id, device_name, "")) compute_devices.append((device_id, device_name, ""))
global_cached_compute_devices = compute_devices global_cached_compute_devices = compute_devices
return compute_devices return compute_devices