Skip to content

Commit 8746cf7

Browse files
committed
Merge branch 'feature_axi_stream' into develop
2 parents 0ecae52 + 1b486f0 commit 8746cf7

13 files changed

+9289
-26
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
TARGET=$(shell ls *.py | grep -v test | grep -v parsetab.py)
2+
ARGS=
3+
4+
PYTHON=python3
5+
#PYTHON=python
6+
#OPT=-m pdb
7+
#OPT=-m cProfile -s time
8+
#OPT=-m cProfile -o profile.rslt
9+
10+
.PHONY: all
11+
all: test
12+
13+
.PHONY: run
14+
run:
15+
$(PYTHON) $(OPT) $(TARGET) $(ARGS)
16+
17+
.PHONY: test
18+
test:
19+
$(PYTHON) -m pytest -vv
20+
21+
.PHONY: check
22+
check:
23+
$(PYTHON) $(OPT) $(TARGET) $(ARGS) > tmp.v
24+
iverilog -tnull -Wall tmp.v
25+
rm -f tmp.v
26+
27+
.PHONY: clean
28+
clean:
29+
rm -rf *.pyc __pycache__ parsetab.py .cache *.out *.png *.dot tmp.v uut.vcd
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [
8+
{
9+
"data": {
10+
"application/javascript": [
11+
"\n",
12+
"require(['notebook/js/codecell'], function(codecell) {\n",
13+
" codecell.CodeCell.options_default.highlight_modes[\n",
14+
" 'magic_text/x-csrc'] = {'reg':[/^%%microblaze/]};\n",
15+
" Jupyter.notebook.events.one('kernel_ready.Kernel', function(){\n",
16+
" Jupyter.notebook.get_cells().map(function(cell){\n",
17+
" if (cell.cell_type == 'code'){ cell.auto_highlight(); } }) ;\n",
18+
" });\n",
19+
"});\n"
20+
]
21+
},
22+
"metadata": {},
23+
"output_type": "display_data"
24+
}
25+
],
26+
"source": [
27+
"from pynq import Overlay, allocate\n",
28+
"import numpy as np"
29+
]
30+
},
31+
{
32+
"cell_type": "code",
33+
"execution_count": 2,
34+
"metadata": {},
35+
"outputs": [
36+
{
37+
"data": {
38+
"text/plain": [
39+
"dict_keys(['axi_dma', 'blinkled_0'])"
40+
]
41+
},
42+
"execution_count": 2,
43+
"metadata": {},
44+
"output_type": "execute_result"
45+
}
46+
],
47+
"source": [
48+
"bitfile = \"thread_stream_axi_stream_fifo_ipxact.bit\"\n",
49+
"overlay = Overlay(bitfile)\n",
50+
"overlay.ip_dict.keys()"
51+
]
52+
},
53+
{
54+
"cell_type": "code",
55+
"execution_count": 3,
56+
"metadata": {},
57+
"outputs": [],
58+
"source": [
59+
"dma = overlay.axi_dma\n",
60+
"blinkled = overlay.blinkled_0"
61+
]
62+
},
63+
{
64+
"cell_type": "code",
65+
"execution_count": 4,
66+
"metadata": {},
67+
"outputs": [],
68+
"source": [
69+
"reduce_size = 8\n",
70+
"read_size = 1024\n",
71+
"write_size = read_size // reduce_size\n",
72+
"\n",
73+
"src = allocate(shape=(read_size,), dtype=np.int32)\n",
74+
"dst = allocate(shape=(write_size,), dtype=np.int32)\n",
75+
"bias = allocate(shape=(write_size,), dtype=np.int32)\n",
76+
"\n",
77+
"bias_addr = bias.physical_address"
78+
]
79+
},
80+
{
81+
"cell_type": "code",
82+
"execution_count": 5,
83+
"metadata": {},
84+
"outputs": [
85+
{
86+
"name": "stdout",
87+
"output_type": "stream",
88+
"text": [
89+
"[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]\n"
90+
]
91+
}
92+
],
93+
"source": [
94+
"src[:] = np.arange(read_size, dtype=np.int32)\n",
95+
"dst[:] = np.zeros([write_size], dtype=np.int32)\n",
96+
"bias[:] = np.ones([write_size], dtype=np.int32)\n",
97+
"print(dst[-16:])"
98+
]
99+
},
100+
{
101+
"cell_type": "code",
102+
"execution_count": 6,
103+
"metadata": {},
104+
"outputs": [],
105+
"source": [
106+
"dma.sendchannel.transfer(src)\n",
107+
"dma.recvchannel.transfer(dst)\n",
108+
"\n",
109+
"# read_size, write_size, reduce_size, offset\n",
110+
"blinkled.write(2 * 4, read_size)\n",
111+
"blinkled.write(3 * 4, write_size)\n",
112+
"blinkled.write(4 * 4, reduce_size)\n",
113+
"blinkled.write(5 * 4, bias_addr)\n",
114+
"\n",
115+
"# start\n",
116+
"blinkled.write(0 * 4, 1)\n",
117+
"\n",
118+
"# busy wait\n",
119+
"while True:\n",
120+
" busy = blinkled.read(1 * 4)\n",
121+
" if not busy:\n",
122+
" break"
123+
]
124+
},
125+
{
126+
"cell_type": "code",
127+
"execution_count": 7,
128+
"metadata": {},
129+
"outputs": [
130+
{
131+
"name": "stdout",
132+
"output_type": "stream",
133+
"text": [
134+
"[6472845 6588493 6705165 6822861 6941581 7061325 7182093 7303885 7426701\n",
135+
" 7550541 7675405 7801293 7928205 8056141 8185101 8315085]\n"
136+
]
137+
}
138+
],
139+
"source": [
140+
"print(dst[-16:])"
141+
]
142+
},
143+
{
144+
"cell_type": "code",
145+
"execution_count": 8,
146+
"metadata": {},
147+
"outputs": [
148+
{
149+
"name": "stdout",
150+
"output_type": "stream",
151+
"text": [
152+
"[6472845 6588493 6705165 6822861 6941581 7061325 7182093 7303885 7426701\n",
153+
" 7550541 7675405 7801293 7928205 8056141 8185101 8315085]\n"
154+
]
155+
}
156+
],
157+
"source": [
158+
"expected = np.sum(np.multiply(src, src).reshape([-1, reduce_size]), axis=-1) + bias\n",
159+
"print(expected[-16:])"
160+
]
161+
},
162+
{
163+
"cell_type": "code",
164+
"execution_count": 9,
165+
"metadata": {},
166+
"outputs": [
167+
{
168+
"name": "stdout",
169+
"output_type": "stream",
170+
"text": [
171+
"0\n"
172+
]
173+
}
174+
],
175+
"source": [
176+
"diff_sum = np.sum(expected - dst)\n",
177+
"print(diff_sum)"
178+
]
179+
},
180+
{
181+
"cell_type": "code",
182+
"execution_count": null,
183+
"metadata": {},
184+
"outputs": [],
185+
"source": []
186+
}
187+
],
188+
"metadata": {
189+
"kernelspec": {
190+
"display_name": "Python 3",
191+
"language": "python",
192+
"name": "python3"
193+
},
194+
"language_info": {
195+
"codemirror_mode": {
196+
"name": "ipython",
197+
"version": 3
198+
},
199+
"file_extension": ".py",
200+
"mimetype": "text/x-python",
201+
"name": "python",
202+
"nbconvert_exporter": "python",
203+
"pygments_lexer": "ipython3",
204+
"version": "3.6.5"
205+
}
206+
},
207+
"nbformat": 4,
208+
"nbformat_minor": 2
209+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
2+
# coding: utf-8
3+
4+
# In[1]:
5+
6+
7+
from pynq import Overlay, allocate
8+
import numpy as np
9+
10+
11+
# In[2]:
12+
13+
14+
bitfile = "thread_stream_axi_stream_fifo_ipxact.bit"
15+
overlay = Overlay(bitfile)
16+
overlay.ip_dict.keys()
17+
18+
19+
# In[3]:
20+
21+
22+
dma = overlay.axi_dma
23+
blinkled = overlay.blinkled_0
24+
25+
26+
# In[4]:
27+
28+
29+
reduce_size = 8
30+
read_size = 1024
31+
write_size = read_size // reduce_size
32+
33+
src = allocate(shape=(read_size,), dtype=np.int32)
34+
dst = allocate(shape=(write_size,), dtype=np.int32)
35+
bias = allocate(shape=(write_size,), dtype=np.int32)
36+
37+
bias_addr = bias.physical_address
38+
39+
40+
# In[5]:
41+
42+
43+
src[:] = np.arange(read_size, dtype=np.int32)
44+
dst[:] = np.zeros([write_size], dtype=np.int32)
45+
bias[:] = np.ones([write_size], dtype=np.int32)
46+
print(dst[-16:])
47+
48+
49+
# In[6]:
50+
51+
52+
dma.sendchannel.transfer(src)
53+
dma.recvchannel.transfer(dst)
54+
55+
# read_size, write_size, reduce_size, offset
56+
blinkled.write(2 * 4, read_size)
57+
blinkled.write(3 * 4, write_size)
58+
blinkled.write(4 * 4, reduce_size)
59+
blinkled.write(5 * 4, bias_addr)
60+
61+
# start
62+
blinkled.write(0 * 4, 1)
63+
64+
# busy wait
65+
while True:
66+
busy = blinkled.read(1 * 4)
67+
if not busy:
68+
break
69+
70+
71+
# In[7]:
72+
73+
74+
print(dst[-16:])
75+
76+
77+
# In[8]:
78+
79+
80+
expected = np.sum(np.multiply(src, src).reshape([-1, reduce_size]), axis=-1) + bias
81+
print(expected[-16:])
82+
83+
84+
# In[9]:
85+
86+
87+
diff_sum = np.sum(expected - dst)
88+
print(diff_sum)
89+

0 commit comments

Comments
 (0)