Skip to content

Commit b3c5bed

Browse files
committed
adding flowcept and IO for swift/t
1 parent 5d3a56d commit b3c5bed

2 files changed

Lines changed: 28 additions & 24 deletions

File tree

wfcommons/wfbench/translator/swift_t.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ def translate(self, output_folder: pathlib.Path) -> None:
7676
in_count = 0
7777
self.output_folder = output_folder
7878
self.cpu_benchmark = output_folder.joinpath("./bin/cpu-benchmark").absolute()
79-
self.script = f"string root_in_files[];\n"
79+
self.script = f"string fs = sprintf(flowcept_start, \"{self.workflow.workflow_id}\");\npython_persist(fs);\n\n" if self.workflow.workflow_id else ""
80+
self.script += "string root_in_files[];\n"
8081

8182
for task_name in self.root_task_names:
8283
task = self.tasks[task_name]
@@ -99,6 +100,10 @@ def translate(self, output_folder: pathlib.Path) -> None:
99100
for category in self.categories_list:
100101
self._add_tasks(category)
101102

103+
# flowcept stop
104+
if self.workflow.workflow_id:
105+
self.script += "string fss = sprintf(flowcept_stop);\npython_persist(fss);"
106+
102107
run_workflow_code = self._merge_codelines("templates/swift_t_templates/workflow.swift", self.script)
103108

104109
# write benchmark files
@@ -213,7 +218,7 @@ def _add_tasks(self, category: str) -> None:
213218
self.script += f"foreach i in [0:{num_tasks - 1}] {{\n" \
214219
f" string of = sprintf(\"{self.output_folder.absolute()}/data/{category}_%i_output.txt\", i);\n" \
215220
f" string cmd_{self.cmd_counter} = sprintf(command, \"{self.cpu_benchmark}\", \"{category}\", {args});\n" \
216-
f" string co_{self.cmd_counter} = python_persist(cmd_{self.cmd_counter});\n" \
221+
f" string co_{self.cmd_counter} = python(cmd_{self.cmd_counter});\n" \
217222
f" string of_{self.cmd_counter} = sprintf(\"0%s\", co_{self.cmd_counter});\n" \
218223
f" {category}__out[i] = string2int(of_{self.cmd_counter});\n" \
219224
"}\n\n"
@@ -222,7 +227,7 @@ def _add_tasks(self, category: str) -> None:
222227
args = args.replace(
223228
", of", f", \"{self.output_folder.absolute()}/data/{category}_0_output.txt\"").replace("[i]", "[0]")
224229
self.script += f"string cmd_{self.cmd_counter} = sprintf(command, \"{self.cpu_benchmark}\", \"{category}\", {args});\n" \
225-
f"string co_{self.cmd_counter} = python_persist(cmd_{self.cmd_counter});\n" \
230+
f"string co_{self.cmd_counter} = python(cmd_{self.cmd_counter});\n" \
226231
f"string of_{self.cmd_counter} = sprintf(\"0%s\", co_{self.cmd_counter});\n" \
227232
f"{category}__out[0] = string2int(of_{self.cmd_counter});\n\n"
228233

wfcommons/wfbench/translator/templates/swift_t_templates/workflow.swift

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,26 @@ import python;
44
import string;
55
import unix;
66

7+
string flowcept_start =
8+
"""
9+
logging.info("Running with Flowcept.")
10+
workflow_id = "%s"
11+
from flowcept import Flowcept, FlowceptTask
12+
flowcept_agent = Flowcept(workflow_id=workflow_id,
13+
bundle_exec_id=workflow_id,
14+
start_persistence=False, save_workflow=False)
15+
flowcept_agent.start()
16+
flowcept_task = FlowceptTask(workflow_id=workflow_id, used={
17+
"workflow_id": workflow_id
18+
})
19+
"""
20+
21+
string flowcept_stop =
22+
"""
23+
flowcept_task.end()
24+
flowcept_agent.stop()
25+
"""
26+
727
string command =
828
"""
929
import logging
@@ -32,23 +52,6 @@ output_data = {"%s": int(%i)}
3252
dep = %i
3353
workflow_id = "%s"
3454
35-
if workflow_id:
36-
logging.info("Running with Flowcept.")
37-
from flowcept import Flowcept, FlowceptTask
38-
flowcept_agent = Flowcept(workflow_id=workflow_id,
39-
bundle_exec_id=workflow_id,
40-
start_persistence=False, save_workflow=False)
41-
flowcept_agent.start()
42-
flowcept_task = FlowceptTask(workflow_id=workflow_id, used={
43-
"name": task_name,
44-
"inputs": files_list,
45-
"gpu_work": gpu_work,
46-
"cpu_work": cpu_work,
47-
"cpu_threads": cpu_threads,
48-
"outputs": output_data,
49-
"workflow_id": workflow_id
50-
})
51-
5255
logging.info(f"Starting {task_name} Benchmark on {socket.gethostname()}")
5356
5457
procs = []
@@ -176,10 +179,6 @@ if cpu_work > 0:
176179
177180
logging.debug("Completed CPU and Memory Benchmarks!")
178181
179-
if workflow_id:
180-
flowcept_task.end()
181-
flowcept_agent.stop()
182-
183182
logging.info(f"Benchmark {task_name} completed!")
184183
""";
185184

0 commit comments

Comments
 (0)