From 9d6406ecf7c2cb12211a25b24fa305b63c801893 Mon Sep 17 00:00:00 2001 From: John McMaster Date: Wed, 17 Oct 2018 20:02:33 -0700 Subject: [PATCH] 018-clbram: query SLICEM instead of guessing Signed-off-by: John McMaster --- fuzzers/018-clbram/top.py | 37 ++------------------ prjxray/util.py | 73 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 34 deletions(-) create mode 100644 prjxray/util.py diff --git a/fuzzers/018-clbram/top.py b/fuzzers/018-clbram/top.py index b2cac6c7..d185a107 100644 --- a/fuzzers/018-clbram/top.py +++ b/fuzzers/018-clbram/top.py @@ -19,48 +19,17 @@ import random random.seed(0) import os import re - - -def slice_xy(): - '''Return (X1, X2), (Y1, Y2) from XRAY_ROI, exclusive end (for xrange)''' - # SLICE_X12Y100:SLICE_X27Y149 - # Note XRAY_ROI_GRID_* is something else - m = re.match( - r'SLICE_X([0-9]*)Y([0-9]*):SLICE_X([0-9]*)Y([0-9]*)', - os.getenv('XRAY_ROI')) - ms = [int(m.group(i + 1)) for i in range(4)] - return ((ms[0], ms[2] + 1), (ms[1], ms[3] + 1)) - +from prjxray import util CLBN = 50 -SLICEX, SLICEY = slice_xy() -# 800 -SLICEN = (SLICEY[1] - SLICEY[0]) * (SLICEX[1] - SLICEX[0]) -print('//SLICEX: %s' % str(SLICEX)) -print('//SLICEY: %s' % str(SLICEY)) -print('//SLICEN: %s' % str(SLICEN)) print('//Requested CLBs: %s' % str(CLBN)) # Rearranged to sweep Y so that carry logic is easy to allocate # XXX: careful...if odd number of Y in ROI will break carry def gen_slicems(): - ''' - SLICEM at the following: - SLICE_XxY* - Where Y any value - x - Always even (ie 100, 102, 104, etc) - In our ROI - x = 6, 8, 10, 12, 14 - ''' - # TODO: generate this from DB - assert ((12, 28) == SLICEX) - for slicex in (12, 14): - for slicey in range(*SLICEY): - # caller may reject position if needs more room - #yield ("SLICE_X%dY%d" % (slicex, slicey), (slicex, slicey)) - yield "SLICE_X%dY%d" % (slicex, slicey) + for _tile_name, site_name, _site_type in util.gen_sites(['SLICEM']): + yield site_name DIN_N = CLBN * 8 diff --git a/prjxray/util.py b/prjxray/util.py new file mode 100644 index 00000000..a4b936fe --- /dev/null +++ b/prjxray/util.py @@ -0,0 +1,73 @@ +import os +import re +import os +import json + +DB_PATH = "%s/%s" % ( + os.getenv("XRAY_DATABASE_DIR"), os.getenv("XRAY_DATABASE")) + + +def roi_xy(): + x1 = int(os.getenv('XRAY_ROI_GRID_X1')) + x2 = int(os.getenv('XRAY_ROI_GRID_X2')) + y1 = int(os.getenv('XRAY_ROI_GRID_Y1')) + y2 = int(os.getenv('XRAY_ROI_GRID_Y2')) + + return (x1, x2), (y1, y2) + + +(ROI_X1, ROI_X2), (ROI_Y1, ROI_Y2) = roi_xy() + + +def slice_xy(): + '''Return (X1, X2), (Y1, Y2) from XRAY_ROI, exclusive end (for xrange)''' + # SLICE_X12Y100:SLICE_X27Y149 + # Note XRAY_ROI_GRID_* is something else + m = re.match( + r'SLICE_X([0-9]*)Y([0-9]*):SLICE_X([0-9]*)Y([0-9]*)', + os.getenv('XRAY_ROI')) + ms = [int(m.group(i + 1)) for i in range(4)] + return ((ms[0], ms[2] + 1), (ms[1], ms[3] + 1)) + + +def tile_in_roi(tilej): + x = int(tilej['grid_x']) + y = int(tilej['grid_y']) + return ROI_X1 <= x <= ROI_X2 and ROI_Y1 <= y <= ROI_Y2 + + +def load_tilegrid(): + return json.load(open('%s/tilegrid.json' % DB_PATH)) + + +def gen_tiles(tile_types=None, tilegrid=None): + ''' + tile_types: list of tile types to keep, or None for all + tilegrid: cache the tilegrid database + ''' + tilegrid = tilegrid or load_tilegrid() + + for tile_name, tilej in tilegrid.items(): + if tile_in_roi(tilej) and (tile_types is None + or tilej['type'] in tile_types): + yield (tile_name, tilej) + + +def gen_sites(site_types=None, tilegrid=None): + ''' + site_types: list of site types to keep, or None for all + tilegrid: cache the tilegrid database + ''' + tilegrid = tilegrid or load_tilegrid() + + for tile_name, tilej in tilegrid.items(): + if not tile_in_roi(tilej): + continue + for site_name, site_type in tilej['sites'].items(): + if site_types is None or site_type in site_types: + yield (tile_name, site_name, site_type) + + +#print(list(gen_tiles(['CLBLL_L', 'CLBLL_R', 'CLBLM_L', 'CLBLM_R']))) +#print(list(gen_sites(['SLICEL', 'SLICEM']))) +#print(list(gen_sites(['SLICEM'])))