Browse Source

add logic depth example

main
Stefan Holst 4 years ago
parent
commit
765cb70ca3
  1. 198
      UsageExamples.ipynb

198
UsageExamples.ipynb

@ -430,6 +430,122 @@
" print(c.kind, c.name)" " print(c.kind, c.name)"
] ]
}, },
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Determining Logic Depth of Nodes"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<Circuit 'b14' with 31715 nodes, 46891 lines, 91 ports>"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from kyupy import verilog\n",
"\n",
"b14 = verilog.parse('tests/b14.v.gz')\n",
"b14"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Calculate logic level (logic depth, distance from inputs or scan flip-flops) for each node in the circuit.\n",
"Inputs and flip-flops themselves are level 0, **cells** driven by just inputs and flip-flops are level 1, and so on.\n",
"**Fork** nodes have the same level as their driver, because they do not increase the logic depth."
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Maximum logic depth: 112\n"
]
}
],
"source": [
"import numpy as np\n",
"\n",
"levels = np.zeros(len(b14.nodes), dtype='uint16') # store level for each node.\n",
"\n",
"for cell in b14.topological_order():\n",
" if 'DFF' in cell.kind or 'input' == cell.kind:\n",
" levels[cell.index] = 0\n",
" elif '__fork__' == cell.kind:\n",
" levels[cell.index] = levels[cell.ins[0].driver.index] # forks only have exactly one driver\n",
" else:\n",
" levels[cell.index] = max([levels[line.driver.index] for line in cell.ins]) + 1\n",
" \n",
"print(f'Maximum logic depth: {np.max(levels)}')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"List nodes with the highest depth and which nodes they are driving."
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"depth: 112 node: __fork__ n2692 driving: SDFFARX1_RVT reg1_reg_29_ \n",
"depth: 112 node: NAND2X0_RVT U465 driving: __fork__ n2692 \n",
"depth: 112 node: NAND2X0_RVT U562 driving: __fork__ n2724 \n",
"depth: 112 node: __fork__ n2724 driving: SDFFARX1_RVT reg0_reg_29_ \n",
"depth: 112 node: __fork__ n2608 driving: SDFFARX1_RVT B_reg \n",
"depth: 112 node: NAND2X0_RVT U170 driving: __fork__ n2608 \n",
"depth: 111 node: NAND2X0_RVT U5550 driving: __fork__ n2693 \n",
"depth: 111 node: __fork__ n2660 driving: SDFFARX1_RVT reg2_reg_29_ \n",
"depth: 111 node: AND2X2_RVT U5560 driving: __fork__ n2660 \n",
"depth: 111 node: __fork__ n2725 driving: SDFFARX1_RVT reg0_reg_28_ \n",
"depth: 111 node: __fork__ n2693 driving: SDFFARX1_RVT reg1_reg_28_ \n",
"depth: 111 node: __fork__ n362 driving: NAND2X0_RVT U170 \n",
"depth: 111 node: NAND2X0_RVT U173 driving: __fork__ n362 \n",
"depth: 111 node: __fork__ n600 driving: NAND2X0_RVT U562 \n",
"depth: 111 node: NAND2X0_RVT U563 driving: __fork__ n600 \n",
"depth: 111 node: NAND2X0_RVT U565 driving: __fork__ n2725 \n",
"depth: 111 node: NAND2X0_RVT U466 driving: __fork__ n535 \n",
"depth: 111 node: __fork__ n535 driving: NAND2X0_RVT U465 \n",
"depth: 110 node: __fork__ n4691 driving: AND2X2_RVT U5560 \n",
"depth: 110 node: NAND2X0_RVT U5736 driving: __fork__ n790 \n"
]
}
],
"source": [
"nodes_by_depth = np.argsort(levels)[::-1]\n",
"\n",
"for n_idx in nodes_by_depth[:20]:\n",
" n = b14.nodes[n_idx]\n",
" readers = ', '.join([f'{l.reader.kind:12s} {l.reader.name:14s}' for l in n.outs])\n",
" print(f'depth: {levels[n_idx]} node: {n.kind:12s} {n.name:6s} driving: {readers}')"
]
},
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
@ -446,7 +562,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 15, "execution_count": 18,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -469,7 +585,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 16, "execution_count": 19,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -478,7 +594,7 @@
"<PackedVectors nvectors=1081, width=306, vdim=2>" "<PackedVectors nvectors=1081, width=306, vdim=2>"
] ]
}, },
"execution_count": 16, "execution_count": 19,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -496,7 +612,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 17, "execution_count": 20,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -505,7 +621,7 @@
"(306, 2, 136)" "(306, 2, 136)"
] ]
}, },
"execution_count": 17, "execution_count": 20,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -523,7 +639,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 18, "execution_count": 21,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -532,7 +648,7 @@
"'-0--------------------11011111011001100111010101011101----------------------------------00-10111011010110011101110010111010111011101100010000110101111111011010101001010101010101010101001010110101001010101010101010110100000111111111111111011010100100101010010010101101010101001010100111010001010010000011100'" "'-0--------------------11011111011001100111010101011101----------------------------------00-10111011010110011101110010111010111011101100010000110101111111011010101001010101010101010101001010110101001010101010101010110100000111111111111111011010100100101010010010101101010101001010100111010001010010000011100'"
] ]
}, },
"execution_count": 18, "execution_count": 21,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -543,7 +659,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 19, "execution_count": 22,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -552,7 +668,7 @@
"'--10000010010100010111--------------------------------0101010010101010110101001001010100--011111110011011111000111010101010111011101100010000110101111111011010101001010101010101010101001010110101001010101010101010110100000111111111111111011010100100101010010010101101010101001010101000111111111111111011101'" "'--10000010010100010111--------------------------------0101010010101010110101001001010100--011111110011011111000111010101010111011101100010000110101111111011010101001010101010101010101001010110101001010101010101010110100000111111111111111011010100100101010010010101101010101001010101000111111111111111011101'"
] ]
}, },
"execution_count": 19, "execution_count": 22,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -570,7 +686,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 20, "execution_count": 23,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -583,7 +699,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 21, "execution_count": 24,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -592,7 +708,7 @@
"'--10000010010100010111--------------------------------0101010010101010110101001001010100--011111110011011111000111010101010111011101100010000110101111111011010101001010101010101010101001010110101001010101010101010110100000111111111111111011010100100101010010010101101010101001010101000111111111111111011101'" "'--10000010010100010111--------------------------------0101010010101010110101001001010100--011111110011011111000111010101010111011101100010000110101111111011010101001010101010101010101001010110101001010101010101010110100000111111111111111011010100100101010010010101101010101001010101000111111111111111011101'"
] ]
}, },
"execution_count": 21, "execution_count": 24,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -610,7 +726,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 22, "execution_count": 25,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -641,7 +757,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 23, "execution_count": 26,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -659,7 +775,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 24, "execution_count": 27,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -668,7 +784,7 @@
"<PackedVectors nvectors=1392, width=306, vdim=3>" "<PackedVectors nvectors=1392, width=306, vdim=3>"
] ]
}, },
"execution_count": 24, "execution_count": 27,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -686,7 +802,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 25, "execution_count": 28,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -695,7 +811,7 @@
"'-0--------------------RRRRRRFRRRRRRRRRRRFFRFRRRRRRRRRR----------------------------------00-00000001110100011111011010000000000000000011001001100101111110101110110001000100010100110111111101101000000111110011100010111000111R1111111111111111111111110001100100000110100000111010101110RFF00F000F0F00F00000FF01F'" "'-0--------------------RRRRRRFRRRRRRRRRRRFFRFRRRRRRRRRR----------------------------------00-00000001110100011111011010000000000000000011001001100101111110101110110001000100010100110111111101101000000111110011100010111000111R1111111111111111111111110001100100000110100000111010101110RFF00F000F0F00F00000FF01F'"
] ]
}, },
"execution_count": 25, "execution_count": 28,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -713,7 +829,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 26, "execution_count": 29,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -726,7 +842,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 27, "execution_count": 30,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -735,7 +851,7 @@
"'--F00000F00F0F000F00FF--------------------------------01110101011100000101100000100110R0--0RRRRRRRNNNRNRPRNNNNNRFFRFRRRRRRR000000000011001001100101111110101110110001000100010100110111111101101000000111110011100010111000NNNNNNNNNNNNNNNNNNNNNNNNNNNNP0011001000001101000001110101011101RRRRRRRRRRRRRRRRRRRRP01R'" "'--F00000F00F0F000F00FF--------------------------------01110101011100000101100000100110R0--0RRRRRRRNNNRNRPRNNNNNRFFRFRRRRRRR000000000011001001100101111110101110110001000100010100110111111101101000000111110011100010111000NNNNNNNNNNNNNNNNNNNNNNNNNNNNP0011001000001101000001110101011101RRRRRRRRRRRRRRRRRRRRP01R'"
] ]
}, },
"execution_count": 27, "execution_count": 30,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -753,7 +869,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 28, "execution_count": 31,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -791,7 +907,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 29, "execution_count": 32,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -811,7 +927,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 30, "execution_count": 33,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -820,7 +936,7 @@
"(46891, 2, 2)" "(46891, 2, 2)"
] ]
}, },
"execution_count": 30, "execution_count": 33,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -838,7 +954,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 31, "execution_count": 34,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -847,7 +963,7 @@
"119676" "119676"
] ]
}, },
"execution_count": 31, "execution_count": 34,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -875,7 +991,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 32, "execution_count": 35,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -894,7 +1010,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 33, "execution_count": 36,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -933,7 +1049,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 34, "execution_count": 37,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -963,7 +1079,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 35, "execution_count": 38,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -972,7 +1088,7 @@
"(306, 128, 7)" "(306, 128, 7)"
] ]
}, },
"execution_count": 35, "execution_count": 38,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -990,7 +1106,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 36, "execution_count": 39,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -1023,7 +1139,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 37, "execution_count": 40,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -1032,7 +1148,7 @@
"2.0610005855560303" "2.0610005855560303"
] ]
}, },
"execution_count": 37, "execution_count": 40,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -1050,7 +1166,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 38, "execution_count": 41,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -1059,7 +1175,7 @@
"0.0" "0.0"
] ]
}, },
"execution_count": 38, "execution_count": 41,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -1077,7 +1193,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 39, "execution_count": 42,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -1086,7 +1202,7 @@
"0.0" "0.0"
] ]
}, },
"execution_count": 39, "execution_count": 42,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -1114,7 +1230,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 40, "execution_count": 43,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -1136,7 +1252,7 @@
"True" "True"
] ]
}, },
"execution_count": 40, "execution_count": 43,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }

Loading…
Cancel
Save