Skip to content

Commit

Permalink
openroad: Create custom CPUHeavyGenrule to prevent running route stag…
Browse files Browse the repository at this point in the history
…e in parallel

Signed-off-by: Eryk Szpotanski <[email protected]>
  • Loading branch information
eszpotanski committed Jun 4, 2024
1 parent 8d70009 commit 526a016
Showing 1 changed file with 58 additions and 1 deletion.
59 changes: 58 additions & 1 deletion openroad.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,59 @@ def create_out_rule(name = "out_make_script"):
outs = ["out"],
)

def _resource_full_cpu(os_name, inputs):
"""
Returns resource set for `cpu_heavy_genrule`.
It has to be defined as top-level function.
Args:
os_name: Name of the OS
inputs: Number of inputs provided for genrule
Returns:
Dictionary with required resources (cpu, memory or local_test)
"""
return {
"cpu": 512,
}

def _cpu_heavy_genrule_impl(ctx):
"""
Implementation of `cpu_heavy_genrule` - should behave
like the normal genrule, but uses whole CPU.
Args:
ctx: rule context
Returns:
List with information providers of this rule
"""
converted_cmd = ctx.expand_location(ctx.attr.cmd)
converted_cmd = ctx.expand_make_variables("cmd", converted_cmd, {
"RULEDIR": ctx.var["BINDIR"] + ("/" + ctx.label.package if ctx.label.package else "")
})
ctx.actions.run_shell(
inputs = ctx.files.srcs,
tools = ctx.files.tools,
outputs = ctx.outputs.outs,
command = converted_cmd,
resource_set = _resource_full_cpu,
mnemonic = "CPUHeavyGenrule",
progress_message = "Execution CPUHeavyGenrule %{label}",
)
return [DefaultInfo(files = depset(ctx.outputs.outs))]

cpu_heavy_genrule = rule(
implementation = _cpu_heavy_genrule_impl,
attrs = {
"tools": attr.label_list(mandatory=True, allow_files=True),
"srcs": attr.label_list(mandatory=True, allow_files=True),
"cmd": attr.string(mandatory=True),
"outs": attr.output_list(mandatory=True),
},
)

def build_openroad(
name,
variant = "base",
Expand Down Expand Up @@ -795,8 +848,12 @@ def build_openroad(
stage_config = Label("@@//" + native.package_name() + ":" + target_name + "_" + stage + "_config.mk")
make_targets = get_make_targets(stage, False, mock_area)

if stage == "route":
genrule = cpu_heavy_genrule
else:
genrule = native.genrule
# Target building `target_name` `stage` and its dependencies
native.genrule(
genrule(
name = target_name + "_" + stage,
tools = select({
"@bazel-orfs//:remote_exec": [Label("//:orfs")],
Expand Down

0 comments on commit 526a016

Please sign in to comment.