Skip to content

Commit bc03fc6

Browse files
committed
Add jupiter notebook
1 parent 8635b29 commit bc03fc6

File tree

4 files changed

+269
-0
lines changed

4 files changed

+269
-0
lines changed
19.2 KB
Loading

tests/opencl/j_stat/output.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
CONFIGS=-DNUM_CLUSTERS=1 -DNUM_CORES=4 -DNUM_WARPS=4 -DNUM_THREADS=4
2+
running: CONFIGS=-DNUM_CLUSTERS=1 -DNUM_CORES=4 -DNUM_WARPS=4 -DNUM_THREADS=4 make -C ./ci/../runtime/simx
3+
running: OPTS=-N16 -M16 -K16 make -C ./ci/../tests/opencl/kernel4 run-simx
4+
make: Entering directory '/home/jblab/ivan_khromov/release/vortex/build/tests/opencl/kernel4'
5+
cp /home/jblab/ivan_khromov/release/vortex/tests/opencl/kernel4/common.h common.h
6+
LD_LIBRARY_PATH=/home/jblab/tools/pocl/lib:/home/jblab/ivan_khromov/release/vortex/build/runtime:/home/jblab/tools/llvm-vortex/lib::/usr/local/lib POCL_VORTEX_XLEN=32 LLVM_PREFIX=/home/jblab/tools/llvm-vortex POCL_VORTEX_BINTOOL="OBJCOPY=/home/jblab/tools/llvm-vortex/bin/llvm-objcopy /home/jblab/ivan_khromov/release/vortex/kernel/scripts/vxbin.py" POCL_VORTEX_CFLAGS="-march=rv32imaf -mabi=ilp32f -O3 -mcmodel=medany --sysroot=/home/jblab/tools/riscv32-gnu-toolchain/riscv32-unknown-elf --gcc-toolchain=/home/jblab/tools/riscv32-gnu-toolchain -fno-rtti -fno-exceptions -nostartfiles -nostdlib -fdata-sections -ffunction-sections -I/home/jblab/ivan_khromov/release/vortex/build/hw -I/home/jblab/ivan_khromov/release/vortex/kernel/include -DXLEN_32 -DNDEBUG -Xclang -target-feature -Xclang +vortex -Xclang -target-feature -Xclang +zicond -mllvm -disable-loop-idiom-all" POCL_VORTEX_LDFLAGS="-Wl,-Bstatic,--gc-sections,-T/home/jblab/ivan_khromov/release/vortex/kernel/scripts/link32.ld,--defsym=STARTUP_ADDR=0x80000000 /home/jblab/ivan_khromov/release/vortex/build/kernel/libvortex.a -L/home/jblab/tools/libc32/lib -lm -lc /home/jblab/tools/libcrt32/lib/baremetal/libclang_rt.builtins-riscv32.a" VORTEX_DRIVER=simx ./kernel4 -N16 -M16 -K16
7+
Using device: Vortex OpenGPU
8+
Execute the kernel
9+
Elapsed time: 235 ms
10+
Verify result
11+
PASSED!
12+
PERF: core0: instrs=11548, cycles=40923, IPC=0.282189
13+
PERF: core1: instrs=11548, cycles=41559, IPC=0.277870
14+
PERF: core2: instrs=11548, cycles=41327, IPC=0.279430
15+
PERF: core3: instrs=11548, cycles=41707, IPC=0.276884
16+
PERF: instrs=46192, cycles=41707, IPC=1.107536
17+
make: Leaving directory '/home/jblab/ivan_khromov/release/vortex/build/tests/opencl/kernel4'

tests/opencl/j_stat/perf.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
kernel1
2+
--warps=8 --cores=8 --threads=8
3+
cycles=57927
Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"import subprocess\n",
10+
"import matplotlib.pyplot as plt\n",
11+
"from dataclasses import dataclass, field\n",
12+
"import pandas as pd\n",
13+
"from tqdm import tqdm"
14+
]
15+
},
16+
{
17+
"cell_type": "code",
18+
"execution_count": 2,
19+
"metadata": {},
20+
"outputs": [],
21+
"source": [
22+
"# architecture parameters\n",
23+
"@dataclass\n",
24+
"class arch:\n",
25+
" warps: int = 1\n",
26+
" cores: int = 1\n",
27+
" threads: int = 1\n",
28+
"# running parameters \n",
29+
"@dataclass\n",
30+
"class run:\n",
31+
" arch: arch\n",
32+
" kernel: str\n",
33+
" driver: str = \"simx\"\n",
34+
" args: dict = field(default_factory=dict)"
35+
]
36+
},
37+
{
38+
"cell_type": "code",
39+
"execution_count": 3,
40+
"metadata": {},
41+
"outputs": [],
42+
"source": [
43+
"path_to_vortex = \"/home/jblab/ivan_khromov/release/vortex\"\n",
44+
"tile_size = 'TS'\n",
45+
"work_per_thread = 'WPT'\n",
46+
"width = 'WIDTH'"
47+
]
48+
},
49+
{
50+
"cell_type": "code",
51+
"execution_count": 4,
52+
"metadata": {},
53+
"outputs": [],
54+
"source": [
55+
"def error_running (run_params: run, error_text: str) -> str:\n",
56+
" return f\"error in running in {run_params.kernel} : warps={run_params.arch.warps} cores={run_params.arch.cores} threads={run_params.arch.threads}\" \\\n",
57+
" f\" driver={run_params.driver} args=-N{run_params.args['N']} -M{run_params.args['M']} -K{run_params.args['K']} error message - {error_text}/n\""
58+
]
59+
},
60+
{
61+
"cell_type": "code",
62+
"execution_count": 5,
63+
"metadata": {},
64+
"outputs": [],
65+
"source": [
66+
"def error_verification (run_params: run, number_of_errors: str) -> str:\n",
67+
" return f\"error in verifing results {run_params.kernel} : warps={run_params.arch.warps} cores={run_params.arch.cores} threads={run_params.arch.threads}\" \\\n",
68+
" f\" driver={run_params.driver} args=-N{run_params.args['N']} -M{run_params.args['M']} -K{run_params.args['K']} Number of errors : {number_of_errors}'\\n'\" "
69+
]
70+
},
71+
{
72+
"cell_type": "code",
73+
"execution_count": 6,
74+
"metadata": {},
75+
"outputs": [],
76+
"source": [
77+
"def create_common_h (params: dict, kernel_name: str):\n",
78+
" file_name = f\"{path_to_vortex}/tests/opencl/{kernel_name}/common.h\"\n",
79+
" with open(file_name, 'w') as file:\n",
80+
" text = \"#ifndef COMMON_H\\n\" + \"#define COMMON_H\\n\" + \"\\n\" \n",
81+
" if tile_size in params:\n",
82+
" text += f\"#define TS {params[tile_size]}\\n\"\n",
83+
" if work_per_thread in params:\n",
84+
" text += f\"#define WPT {params[work_per_thread]}\\n\"\n",
85+
" text += \"#define RTS (TS/WPT)\\n\"\n",
86+
" if width in params:\n",
87+
" text += f\"#define WIDTH {params[width]}\\n\"\n",
88+
" text += '\\n' + \"#endif // COMMON_H\"\n",
89+
" file.write(text)\n",
90+
" # open main.cc file to recompile before run with new common.h\n",
91+
" with open(f\"{path_to_vortex}/tests/opencl/{kernel_name}/main.cc\", 'a') as main:\n",
92+
" main.write('')"
93+
]
94+
},
95+
{
96+
"cell_type": "code",
97+
"execution_count": 7,
98+
"metadata": {},
99+
"outputs": [],
100+
"source": [
101+
"def perf (run_params: run, path_to_output_file: str) -> pd.DataFrame:\n",
102+
" # run kernel\n",
103+
" vortex = f\"--warps={run_params.arch.warps} --cores={run_params.arch.cores} --threads={run_params.arch.threads}\"\n",
104+
" run_args = f\"-N{run_params.args['N']} -M{run_params.args['M']} -K{run_params.args['K']}\"\n",
105+
" command = f\"cd {path_to_vortex}/build && ./ci/blackbox.sh {vortex} --driver={run_params.driver} --app={run_params.kernel} --args=\\\"{run_args}\\\"\"\n",
106+
" print(command)\n",
107+
" subprocess.call(f\"{command} > {path_to_output_file}\", shell=True)\n",
108+
"\n",
109+
" # collect statistic \n",
110+
" with open(path_to_output_file, 'r') as file:\n",
111+
" lines = file.readlines()\n",
112+
" error_message = \"\"\n",
113+
" general_perf_stat = \"\"\n",
114+
" for line in lines:\n",
115+
" if \"PERF:\" in line:\n",
116+
" general_perf_stat = line\n",
117+
" # check for errors\n",
118+
" if \"FAILED\" in line: \n",
119+
" error_message = error_verification(run_params, line[line.find(\"FAILED! - \"):])\n",
120+
" if \"Error\" in line:\n",
121+
" error_message = error_running(run_params, line[line.find(\"Error:\"):])\n",
122+
" # pars string with general perf statistic of running kernel\n",
123+
" pairs = general_perf_stat.replace(\"PERF: \", \"\").split(\", \")\n",
124+
" perf_dict = {key_value.split(\"=\")[0]: float(key_value.split(\"=\")[1]) for key_value in pairs}\n",
125+
" if perf_dict[\"cycles\"] <= 0:\n",
126+
" error_message = error_running(run_params, \"Invalid number of cycles\")\n",
127+
" # write result to data frame\n",
128+
" run_result = pd.DataFrame([{\"kernel\": run_params.kernel[-1], \"driver\": run_params.driver, \"cores\": run_params.arch.cores, \n",
129+
" \"warps\": run_params.arch.warps, \"threads\": run_params.arch.threads, \"M\": run_params.args[\"M\"], \n",
130+
" \"N\": run_params.args[\"N\"], \"K\": run_params.args[\"K\"], \"instrs\": perf_dict[\"instrs\"], \"cycles\": perf_dict[\"cycles\"],\n",
131+
" \"IPC\": perf_dict[\"IPC\"], \"error\": error_message}])\n",
132+
" return run_result"
133+
]
134+
},
135+
{
136+
"cell_type": "code",
137+
"execution_count": 8,
138+
"metadata": {},
139+
"outputs": [],
140+
"source": [
141+
"def draw (data_frame: pd.DataFrame, x_label: str, y_label: str, title: str, path: str):\n",
142+
" data_frame.plot(kind = \"bar\", x = x_label, y = y_label)\n",
143+
" plt.title(title)\n",
144+
" plt.xlabel(x_label)\n",
145+
" plt.ylabel(y_label)\n",
146+
" plt.savefig(path)"
147+
]
148+
},
149+
{
150+
"cell_type": "code",
151+
"execution_count": 9,
152+
"metadata": {},
153+
"outputs": [
154+
{
155+
"name": "stderr",
156+
"output_type": "stream",
157+
"text": [
158+
" 0%| | 0/4 [00:00<?, ?it/s]/bin/sh: 1: cannot create /home/jblab/ivan_khromov/release/vortex/tests/opencl/j_stat: Is a directory\n",
159+
" 0%| | 0/4 [00:00<?, ?it/s]\n"
160+
]
161+
},
162+
{
163+
"name": "stdout",
164+
"output_type": "stream",
165+
"text": [
166+
"cd /home/jblab/ivan_khromov/release/vortex/build && ./ci/blackbox.sh --warps=4 --cores=4 --threads=4 --driver=simx --app=kernel1 --args=\"-N16 -M16 -K16\"\n"
167+
]
168+
},
169+
{
170+
"ename": "IsADirectoryError",
171+
"evalue": "[Errno 21] Is a directory: '/home/jblab/ivan_khromov/release/vortex/tests/opencl/j_stat'",
172+
"output_type": "error",
173+
"traceback": [
174+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
175+
"\u001b[0;31mIsADirectoryError\u001b[0m Traceback (most recent call last)",
176+
"Cell \u001b[0;32mIn[9], line 37\u001b[0m\n\u001b[1;32m 35\u001b[0m output_file \u001b[38;5;241m=\u001b[39m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mpath_to_vortex\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m/tests/opencl/j_stat\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 36\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m params \u001b[38;5;129;01min\u001b[39;00m tqdm(run_p):\n\u001b[0;32m---> 37\u001b[0m data_frames\u001b[38;5;241m.\u001b[39mappend(\u001b[43mperf\u001b[49m\u001b[43m(\u001b[49m\u001b[43mparams\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43moutput_file\u001b[49m\u001b[43m)\u001b[49m)\n\u001b[1;32m 38\u001b[0m data_frame \u001b[38;5;241m=\u001b[39m pd\u001b[38;5;241m.\u001b[39mconcat(data_frames, ignore_index\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n\u001b[1;32m 40\u001b[0m \u001b[38;5;66;03m# draw graph based on the recived statistic\u001b[39;00m\n",
177+
"Cell \u001b[0;32mIn[7], line 10\u001b[0m, in \u001b[0;36mperf\u001b[0;34m(run_params, path_to_output_file)\u001b[0m\n\u001b[1;32m 7\u001b[0m subprocess\u001b[38;5;241m.\u001b[39mcall(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mcommand\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m > \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mpath_to_output_file\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m, shell\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n\u001b[1;32m 9\u001b[0m \u001b[38;5;66;03m# collect statistic \u001b[39;00m\n\u001b[0;32m---> 10\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[38;5;28;43mopen\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mpath_to_output_file\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mr\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m \u001b[38;5;28;01mas\u001b[39;00m file:\n\u001b[1;32m 11\u001b[0m lines \u001b[38;5;241m=\u001b[39m file\u001b[38;5;241m.\u001b[39mreadlines()\n\u001b[1;32m 12\u001b[0m error_message \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m\"\u001b[39m\n",
178+
"File \u001b[0;32m~/.pyenv/versions/3.11.9/lib/python3.11/site-packages/IPython/core/interactiveshell.py:324\u001b[0m, in \u001b[0;36m_modified_open\u001b[0;34m(file, *args, **kwargs)\u001b[0m\n\u001b[1;32m 317\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m file \u001b[38;5;129;01min\u001b[39;00m {\u001b[38;5;241m0\u001b[39m, \u001b[38;5;241m1\u001b[39m, \u001b[38;5;241m2\u001b[39m}:\n\u001b[1;32m 318\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[1;32m 319\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mIPython won\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mt let you open fd=\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mfile\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m by default \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 320\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mas it is likely to crash IPython. If you know what you are doing, \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 321\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124myou can use builtins\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m open.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 322\u001b[0m )\n\u001b[0;32m--> 324\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mio_open\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfile\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
179+
"\u001b[0;31mIsADirectoryError\u001b[0m: [Errno 21] Is a directory: '/home/jblab/ivan_khromov/release/vortex/tests/opencl/j_stat'"
180+
]
181+
}
182+
],
183+
"source": [
184+
"# create common.h files for each kernel\n",
185+
"params1 = {\n",
186+
" tile_size: 4\n",
187+
"}\n",
188+
"create_common_h(params1, \"kernel1\")\n",
189+
"create_common_h(params1, \"kernel2\")\n",
190+
"\n",
191+
"params3 = {\n",
192+
" tile_size: 4,\n",
193+
" work_per_thread: 4\n",
194+
"}\n",
195+
"create_common_h(params3, \"kernel3\")\n",
196+
"\n",
197+
"params4 = {\n",
198+
" tile_size: 8,\n",
199+
" width: 4\n",
200+
"}\n",
201+
"create_common_h(params4, \"kernel4\")\n",
202+
"\n",
203+
"# fill running params data class for each kernel\n",
204+
"run_p = []\n",
205+
"arg = {\n",
206+
" \"M\": 16,\n",
207+
" \"N\": 16,\n",
208+
" \"K\": 16\n",
209+
"}\n",
210+
"arch_p = arch(threads=4, cores=4, warps=4)\n",
211+
"run_p.append(run(arch_p, kernel=\"kernel1\", driver=\"simx\", args=arg))\n",
212+
"run_p.append(run(arch_p, kernel=\"kernel2\", driver=\"simx\", args=arg))\n",
213+
"run_p.append(run(arch_p, kernel=\"kernel3\", driver=\"simx\", args=arg))\n",
214+
"run_p.append(run(arch_p, kernel=\"kernel4\", driver=\"simx\", args=arg))\n",
215+
"\n",
216+
"# run all kernels and collect statistic in data frame\n",
217+
"data_frames = []\n",
218+
"output_file = f\"{path_to_vortex}/tests/opencl/j_stat/output.txt\"\n",
219+
"for params in tqdm(run_p):\n",
220+
" data_frames.append(perf(params, output_file))\n",
221+
"data_frame = pd.concat(data_frames, ignore_index=True)\n",
222+
"\n",
223+
"# draw graph based on the recived statistic\n",
224+
"draw(data_frame, \"kernel\", \"cycles\", \"number of cycles per kernel\", \"graphics/graph.png\")"
225+
]
226+
}
227+
],
228+
"metadata": {
229+
"kernelspec": {
230+
"display_name": "Python 3",
231+
"language": "python",
232+
"name": "python3"
233+
},
234+
"language_info": {
235+
"codemirror_mode": {
236+
"name": "ipython",
237+
"version": 3
238+
},
239+
"file_extension": ".py",
240+
"mimetype": "text/x-python",
241+
"name": "python",
242+
"nbconvert_exporter": "python",
243+
"pygments_lexer": "ipython3",
244+
"version": "3.11.9"
245+
}
246+
},
247+
"nbformat": 4,
248+
"nbformat_minor": 2
249+
}

0 commit comments

Comments
 (0)