Skip to content

Commit c2f8312

Browse files
committed
feat: scale cpu, gpu, memory with runtime
1 parent 0a175b0 commit c2f8312

1 file changed

Lines changed: 27 additions & 9 deletions

File tree

wfcommons/wfbench/bench.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ def create_benchmark_from_synthetic_workflow(
9090
:type save_dir: pathlib.Path
9191
:param workflow: The (synthetic) workflow to use as a benchmark.
9292
:type workflow: Workflow
93-
:param percent_cpu: The percentage of CPU threads.
93+
:param percent_cpu: The maximum percentage of CPU threads.
9494
:type percent_cpu: Union[float, Dict[str, float]]
95-
:param cpu_work: CPU work per workflow task.
95+
:param cpu_work: Maximum CPU work per workflow task.
9696
:type cpu_work: Union[int, Dict[str, int]]
97-
:param gpu_work: GPU work per workflow task.
97+
:param gpu_work: Maximum GPU work per workflow task.
9898
:type gpu_work: Union[int, Dict[str, int]]
9999
:param time: Time limit for running each task (in seconds).
100100
:type time: Optional[int]
@@ -116,20 +116,38 @@ def create_benchmark_from_synthetic_workflow(
116116
f"{self.workflow.name.lower()}-{self.num_tasks}").with_suffix(".json")
117117

118118
cores, lock = self._creating_lock_files(lock_files_folder)
119+
120+
max_runtime = max(task.runtime for task in self.workflow.tasks.values())
119121
for task in self.workflow.tasks.values():
122+
# scale argument parameters to achieve a runtime distribution
123+
runtime_factor = task.runtime / max_runtime
124+
task_percent_cpu = percent_cpu[task.category] if isinstance(percent_cpu, dict) else percent_cpu
125+
task_percent_cpu *= runtime_factor
126+
if cpu_work:
127+
task_cpu_work = cpu_work[task.category] if isinstance(cpu_work, dict) else cpu_work
128+
task_cpu_work = int(task_cpu_work * runtime_factor) if task_cpu_work else None
129+
else:
130+
task_cpu_work = None
131+
if gpu_work:
132+
task_gpu_work = gpu_work[task.category] if isinstance(gpu_work, dict) else gpu_work
133+
task_gpu_work *= runtime_factor
134+
else:
135+
task_gpu_work = None
136+
task_memory = int(mem * runtime_factor) if mem else None
120137
self._set_argument_parameters(
121138
task,
122-
percent_cpu,
123-
cpu_work * task.runtime, # scale cpu work to task runtime to achieve a runtime distribution
124-
gpu_work,
139+
task_percent_cpu,
140+
task_cpu_work,
141+
task_gpu_work,
125142
time,
126-
mem,
143+
task_memory,
127144
lock_files_folder,
128145
cores,
129146
lock
130147
)
131-
if mem:
132-
task.memory = mem
148+
task.cores = int(10 * task_percent_cpu * runtime_factor) # set number of cores to cpu threads in wfbench.py
149+
if task_memory:
150+
task.memory = task_memory
133151

134152
# create data footprint
135153
for task in self.workflow.tasks.values():

0 commit comments

Comments
 (0)