Ejemplo n.º 1
0
def remove_constant(db_config, table):
    db = ArkDBMySQL(db_config_file=db_config)
    query = f'DELETE FROM {table} WHERE CELL_BSF_UNIFIED=%s'
    db.run_sql(query, ['0'])
    db.run_sql(query, ['1'])

    print(get_cell_cnt(db_config, table))
Ejemplo n.º 2
0
def get_cell_cnt(db_config, table):
    db = ArkDBMySQL(db_config_file=db_config)
    query = f'SELECT COUNT(*) AS CNT FROM {table} WHERE CELL_PMOS_CNT+CELL_NMOS_CNT=%s'
    ret = dict()
    for i in range(1, 6):
        ret[i] = db.get_query_value('CNT', query, [i])
    return ret
Ejemplo n.º 3
0
def analyze_resistive_defect(db_config, table):
    db = ArkDBMySQL(db_config_file=db_config)
    db.set_table(table)

    id_list = [
        row['idCELL'] for row in
        db.run_query_get_all_row(f"SELECT idCELL FROM {db.get_table()}")
    ]

    resistive_defect_analyzer = ResistiveDefect(db)
    for id_cell in tqdm(id_list, desc='Resistive_defect'):
        resistive_defect_analyzer.insert_defect_details_for_id_cell(id_cell)
Ejemplo n.º 4
0
class MyTestCase(unittest.TestCase):
    def setUp(self):
        self.db_ = ArkDBMySQL(
            db_config_file='/Users/Ark/.db_configs/db_config_local_cadis.txt')
        self.db_.set_table('WORK_LIB')

    def test_get_bsf_with_csim(self):
        str_netlist = "M0001 OUT01 VDD IN001 GND NMOS\n"
        test_cell = Cell(self.db_)
        test_cell.init_based_on_netlist(str_netlist)
        test_cell.cal_bsf()
        self.assertEqual(test_cell.bsf_, '01')

    def test_get_id(self):
        test_cell = Cell(self.db_)
        str_netlist = "M0001 OUT01 VDD IN001 GND NMOS\n"
        test_cell.init_based_on_netlist(str_netlist)
        test_cell.cal_bsf()
        self.assertEqual(1, test_cell.get_id())

    def test_get_family(self):
        cell = Cell(self.db_)
        cell.init_based_on_id(2)
        self.assertEqual('ULM', cell.get_family())

    def test_get_family_none(self):
        cell = Cell(self.db_)
        str_netlist = "M0001 IN005 VDD IN001 GND NMOS\n"
        cell.init_based_on_netlist(str_netlist)
        self.assertIsNone(cell.get_family())

    def test_clear_family(self):
        cell = Cell(self.db_)
        cell.init_based_on_id(1)
        cell.clear_family()
        self.assertIsNone(cell.get_family())

    def test_add_family(self):
        cell = Cell(self.db_)
        cell.init_based_on_id(1)

        cell.clear_family()
        cell.add_to_family('SingleTx')
        self.assertEqual('SingleTx', cell.get_family())

        # check adding same content twice, this should not affect the value
        cell.add_to_family('SingleTx')
        self.assertEqual('SingleTx', cell.get_family())
        cell.clear_family()
Ejemplo n.º 5
0
def tag_extended_ulm_cell(db_config, table):
    db = ArkDBMySQL(db_config_file=db_config)
    db.set_table(table)

    ulm_cell = ULMCell()
    cell = Cell(db)

    for netlist in tqdm(list(ulm_cell.construct_extended_ulm_cells()), desc='EXT-ULM-cell'):
        # search for those ulm-cells in lib and tag them
        cell.init_based_on_netlist(netlist)
        cell.add_to_family('EXT_ULM')

    for netlist in tqdm(list(ulm_cell.construct_extended_ulm_inv_polarity_cells()), desc='EXT-ULM_inv_pol-cell'):
        cell.init_based_on_netlist(netlist)
        cell.add_to_family('EXT_ULM_INV_POL')
Ejemplo n.º 6
0
def remove_non_shared_multi_cells(db_config, table):
    db = ArkDBMySQL(db_config_file=db_config)
    db.set_table(table)
    id_list = [
        row['idCELL'] for row in
        db.run_query_get_all_row(f"SELECT idCELL FROM {db.get_table()} WHERE CELL_FAMILY like '%MultiCellIsoInput%'")
    ]
    for id_cell in id_list:
        db.delete(id_cell, 'idCELL')
    if len(id_list) != 0:
        db.commit()
    print(get_cell_cnt(db_config, table))
class NonminimalEliminator:
    def __init__(self, db_config, table):
        self.db_ = ArkDBMySQL(db_config_file=db_config)
        self.table_ = table
        self.db_.set_table(self.table_)
        self.hypo_checker_ = StructuralHypoChecker()
        self.hypo_checker_.set_strategy(NonminimalityStrategy())

    def eliminate_nonminimal_cells(self,
                                   start,
                                   cnt,
                                   is_checking_bsf_weak=True):
        query = f'SELECT idCELL, CELL_NETLIST FROM {self.table_} LIMIT {start},{cnt}'
        nonminimal_cell_ids = list()
        runner_idx = start // cnt
        for row in tqdm(self.db_.run_query_get_all_row(query),
                        desc=f'Eliminating nonminimal[{runner_idx:02}]:'):
            self.hypo_checker_.set_netlist(row['CELL_NETLIST'])
            self.hypo_checker_.check()

            if is_checking_bsf_weak:
                is_non_minimal = not self.hypo_checker_.is_all_bsf_weak_diff()
            else:
                is_non_minimal = not self.hypo_checker_.is_all_bsf_diff()

            if is_non_minimal:
                self.db_.delete_nocommit(row['idCELL'], 'idCELL')
                nonminimal_cell_ids.append(row['idCELL'])
        self.db_.commit()
class ISOEliminator:
    def __init__(self, db_config, table):
        self.db_ = ArkDBMySQL(db_config_file=db_config)
        self.table_ = table
        self.db_.set_table(self.table_)
        self.cell_ = Cell(self.db_)

    def get_iso_cell_ids_based_on_id(self, id_cell):
        self.cell_.init_based_on_id(id_cell)
        id_list = self.cell_.fetch_ids()
        id_list.remove(id_cell)
        return id_list

    def eliminate_iso(self, start, cnt):
        query = f'SELECT DISTINCT CELL_BSF_UNIFIED FROM {self.table_} LIMIT {start},{cnt}'
        bsf_uni_list = list()
        for row in self.db_.run_query_get_all_row(query):
            bsf_uni_list.append(row['CELL_BSF_UNIFIED'].decode("utf-8"))

        runner_idx = start // cnt
        for bsf in tqdm(bsf_uni_list, desc=f'Eliminating str iso[{runner_idx:02}]:'):
            query = f'SELECT idCELL FROM {self.table_} WHERE CELL_BSF_UNIFIED=%s'
            id_list = list()
            removed_ids = set()
            for row in self.db_.run_query_get_all_row(query, [bsf]):
                id_list.append(row['idCELL'])
            for id_cell in tqdm(id_list, desc=f'Cells in {bsf}: '):
                if id_cell in removed_ids:
                    continue
                dup_ids = self.get_iso_cell_ids_based_on_id(id_cell)
                removed_ids.update(dup_ids)
                if len(dup_ids) != 0:
                    str_temp = ', '.join([str(x) for x in dup_ids])
                    query = f'DELETE FROM {self.table_} WHERE idCELL IN ({str_temp})'
                    self.db_.run_sql_nocommit(query)
Ejemplo n.º 9
0
def tag_multi_cell(db_config, table):
    db = ArkDBMySQL(db_config_file=db_config)
    db.set_table(table)
    cell = Cell(db)

    # select all 1~3 tx cells
    netlists = [
        row['CELL_NETLIST'] for row in
        db.run_query_get_all_row(f'SELECT CELL_NETLIST FROM {db.get_table()} WHERE CELL_PMOS_CNT+CELL_NMOS_CNT<=2')
    ]

    # for every two of them, construct multi-cells
    for two_netlists in tqdm(list(product(netlists, repeat=2)), desc='Multi-cell'):
        multi_cell = MultiCell()
        iso_multi, shared_multi = multi_cell.construct(two_netlists[0], two_netlists[1])

        # search for those multi-cells in lib and tag them
        for str_netlist in iso_multi:
            cell.init_based_on_netlist(str_netlist)
            cell.add_to_family('MultiCellIsoInput')
        for str_netlist in shared_multi:
            cell.init_based_on_netlist(str_netlist)
            cell.add_to_family('MultiCellSharedInput')
Ejemplo n.º 10
0
def create_bsf_table(input_cnt, db_config_file):
    db = ArkDBMySQL(db_config_file=db_config_file)

    # db.run_sql(f'DROP TABLE IF EXISTS BSF_LIB')
    create_table_sql = 'CREATE TABLE IF NOT EXISTS `CADisCMOS`.`BSF_LIB` (\
        `BSF` VARCHAR(256) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,\
        `BSF_UNI` VARCHAR(256) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL NOT NULL,\
        PRIMARY KEY (`BSF`))\
        ENGINE = InnoDB'

    # create the BSF_LIB table if it does not exist
    db.run_sql(create_table_sql)
    db.set_table('BSF_LIB')

    uni_bsf_dict = get_uni_dict(input_cnt, ['0', '1', 'o', 'i', 'Z', 'X', 'R', 'r'])

    for key in tqdm(uni_bsf_dict.keys(), desc='Insert into DB'):
        rec = dict()
        rec['BSF_UNI'] = key
        for bsf in uni_bsf_dict[key]:
            rec['BSF'] = bsf
            db.insert_nocommit(rec)
    db.commit()
Ejemplo n.º 11
0
def update_bsf_uni_for_table(bsf_col, db_config_file, target_lib, start, cnt, force=False):
    db = ArkDBMySQL(db_config_file=db_config_file)

    if not force:
        unset_entry_cnt = db.get_query_value('CNT', f'SELECT COUNT(*) AS CNT FROM {target_lib} '
                                                    f'WHERE {bsf_col}_UNIFIED is null')
        if unset_entry_cnt == 0:
            print(f'{bsf_col}_UNIFIED column is set for all entries, skipping...')
            return

    # TODO: add fast mode, in which only null entries are selected and updated
    query = f'SELECT * FROM BSF_LIB LIMIT {start},{cnt}'
    uni_bsf_arr = db.run_query_get_all_row(query)

    runner_idx = start // cnt
    for row in tqdm(uni_bsf_arr, desc=f'Update {bsf_col}_UNI[{runner_idx:02}]'):
        db.run_sql_nocommit(f'UPDATE {target_lib} SET {bsf_col}_UNIFIED = %s WHERE {bsf_col} = %s',
                            [row['BSF_UNI'].decode("utf-8"), row['BSF'].decode("utf-8")])
    db.commit()
Ejemplo n.º 12
0
def duplicate_table(db_config, new_table, source_table, copy_indexes_n_triggers=True):
    db = ArkDBMySQL(db_config_file=db_config)
    if db.is_table_exist(new_table):
        print(f'table {new_table} already exists')
        return
    if copy_indexes_n_triggers:
        query = f'CREATE TABLE {new_table} LIKE {source_table}'
        db.run_sql(query)
        if db.get_error():
            exit(1)
        query = f'INSERT {new_table} SELECT * FROM {source_table}'
        db.run_sql(query)
        if db.get_error():
            exit(1)
    else:
        query = f'CREATE TABLE {new_table} AS SELECT * FROM {source_table}'
        db.run_sql(query)
        if db.get_error():
            exit(1)
Ejemplo n.º 13
0
def prepare(db_config, query, n_jobs):
    db = ArkDBMySQL(db_config_file=db_config)
    item_cnt = db.get_query_value('CNT', query)
    return gen_limits(item_cnt, n_jobs)
 def __init__(self, db_config, table):
     self.db_ = ArkDBMySQL(db_config_file=db_config)
     self.table_ = table
     self.db_.set_table(self.table_)
     self.cell_ = Cell(self.db_)
 def __init__(self, db_config, table):
     self.db_ = ArkDBMySQL(db_config_file=db_config)
     self.table_ = table
     self.db_.set_table(self.table_)
     self.hypo_checker_ = StructuralHypoChecker()
     self.hypo_checker_.set_strategy(NonminimalityStrategy())
Ejemplo n.º 16
0
def remove_indexes(db_config, table, index_list):
    db = ArkDBMySQL(db_config_file=db_config)
    db.set_table(table)
    for index in index_list:
        db.remove_index(index)
Ejemplo n.º 17
0
    return itertools.product(sizing_options, repeat=tx_cnt)


def gen_sizes(tx_cnt, sizing_options):
    for size_desc in gen_size_desc(tx_cnt, sizing_options):
        str_size_desc = ''
        area = 0
        for size in size_desc:
            str_size_desc += str(size)
            area += int(size)
        yield str_size_desc, area


if __name__ == '__main__':
    db_config = sys.argv[1]
    db = ArkDBMySQL(db_config_file=db_config)

    create_table_sql = 'CREATE TABLE IF NOT EXISTS `CADisCMOS`.`SIZE_LIB` (\
        `idSIZE_LIB` INT NOT NULL AUTO_INCREMENT,\
        `SIZE_DESC` VARCHAR(45) NOT NULL,\
        `TX_CNT` INT NOT NULL,\
        `SIZE_AREA` INT NULL,\
        PRIMARY KEY (`idSIZE_LIB`))\
        ENGINE = InnoDB'

    # create the SIZE_LIB table if it does not exist
    db.run_sql(create_table_sql)
    db.set_table('SIZE_LIB')

    for i in range(1, 8):
        rec = {'TX_CNT': i}
Ejemplo n.º 18
0
 def setUp(self):
     self.db_ = ArkDBMySQL(
         db_config_file='/Users/Ark/.db_configs/db_config_local_cadis.txt')
     self.db_.set_table('WORK_LIB')
Ejemplo n.º 19
0
def remove_redundant_input(db_config, table):
    db = ArkDBMySQL(db_config_file=db_config)
    query = f'DELETE FROM {table} WHERE length(CELL_BSF) > length(CELL_BSF_UNIFIED)'
    db.run_sql(query)

    print(get_cell_cnt(db_config, table))