multithread find_merge_pairs

This commit is contained in:
Jan Petykiewicz 2022-04-07 22:10:30 -07:00
parent e68051ccc6
commit 0adb5e6cf8

View File

@ -4,6 +4,7 @@ Main connectivity-checking functionality for `snarled`
from typing import Tuple, List, Dict, Set, Optional, Union, Sequence, Mapping, Callable from typing import Tuple, List, Dict, Set, Optional, Union, Sequence, Mapping, Callable
from collections import defaultdict from collections import defaultdict
from pprint import pformat from pprint import pformat
from concurrent.futures import ThreadPoolExecutor
import logging import logging
import numpy import numpy
@ -308,6 +309,8 @@ def find_merge_pairs(
logger.warning(f'No vias between layers {top_layer}, {bot_layer}') logger.warning(f'No vias between layers {top_layer}, {bot_layer}')
return merge_pairs return merge_pairs
tested_pairs = set()
with ThreadPoolExecutor() as executor:
for top_name in nets.keys(): for top_name in nets.keys():
top_polys = nets[top_name][top_layer] top_polys = nets[top_name][top_layer]
if not top_polys: if not top_polys:
@ -318,13 +321,30 @@ def find_merge_pairs(
continue continue
name_pair: Tuple[NetName, NetName] = tuple(sorted((top_name, bot_name))) #type: ignore name_pair: Tuple[NetName, NetName] = tuple(sorted((top_name, bot_name))) #type: ignore
if name_pair in merge_pairs: if name_pair in tested_pairs:
continue continue
tested_pairs.add(name_pair)
bot_polys = nets[bot_name][bot_layer] bot_polys = nets[bot_name][bot_layer]
if not bot_polys: if not bot_polys:
continue continue
executor.submit(check_overlap, top_polys, via_polys, bot_polys, clipper_scale_factor,
lambda np=name_pair: merge_pairs.add(np))
return merge_pairs
def check_overlap(
top_polys: Sequence[contour_t],
via_polys: Optional[Sequence[NDArray[numpy.float64]]],
bot_polys: Sequence[contour_t],
clipper_scale_factor: int,
action: Callable[[], None],
) -> None:
"""
Check for interaction between top and bottom polys, mediated by via polys if present.
"""
if via_polys is not None: if via_polys is not None:
top_bot = intersection_evenodd(top_polys, bot_polys) top_bot = intersection_evenodd(top_polys, bot_polys)
descaled = scale_from_clipper(top_bot, clipper_scale_factor) descaled = scale_from_clipper(top_bot, clipper_scale_factor)
@ -333,12 +353,12 @@ def find_merge_pairs(
# via_polys = difference_evenodd(via_polys, overlap) # reduce set of via polys for future nets # via_polys = difference_evenodd(via_polys, overlap) # reduce set of via polys for future nets
else: else:
# overlap = intersection_evenodd(top_polys, bot_polys) # TODO verify there aren't any suspicious corner cases for this # overlap = intersection_evenodd(top_polys, bot_polys) # TODO verify there aren't any suspicious corner cases for this
overlap = check_any_intersection(scale_from_clipper(top_polys, clipper_scale_factor), scale_from_clipper(bot_polys, clipper_scale_factor)) overlap = check_any_intersection(
scale_from_clipper(top_polys, clipper_scale_factor),
scale_from_clipper(bot_polys, clipper_scale_factor))
if overlap: if overlap:
merge_pairs.add(name_pair) action()
return merge_pairs
def check_any_intersection(polys_a, polys_b) -> bool: def check_any_intersection(polys_a, polys_b) -> bool: