Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ivan khromov #1

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions blackbox.simx.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-DNUM_CLUSTERS=1 -DNUM_CORES=16 -DNUM_WARPS=16 -DNUM_THREADS=16 +0+0
22 changes: 21 additions & 1 deletion tests/opencl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ all:
$(MAKE) -C sgemm2
$(MAKE) -C sgemm3
$(MAKE) -C psum
$(MAKE) -C kernel1
$(MAKE) -C kernel2
$(MAKE) -C kernel3
$(MAKE) -C kernel4

run-simx:
$(MAKE) -C vecadd run-simx
Expand All @@ -43,6 +47,10 @@ run-simx:
$(MAKE) -C sgemm2 run-simx
$(MAKE) -C sgemm3 run-simx
$(MAKE) -C psum run-simx
$(MAKE) -C kernel1 run-simx
$(MAKE) -C kernel2 run-simx
$(MAKE) -C kernel3 run-simx
$(MAKE) -C kernel4 run-simx

run-rtlsim:
$(MAKE) -C vecadd run-rtlsim
Expand All @@ -64,6 +72,10 @@ run-rtlsim:
$(MAKE) -C sgemm2 run-rtlsim
$(MAKE) -C sgemm3 run-rtlsim
$(MAKE) -C psum run-rtlsim
$(MAKE) -C kernel1 run-rtlsimy
$(MAKE) -C kernel2 run-rtlsimy
$(MAKE) -C kernel3 run-rtlsimy
$(MAKE) -C kernel4 run-rtlsimy

run-opae:
$(MAKE) -C vecadd run-opae
Expand All @@ -85,6 +97,10 @@ run-opae:
$(MAKE) -C sgemm2 run-opae
$(MAKE) -C sgemm3 run-opae
$(MAKE) -C psum run-opae
$(MAKE) -C kernel1 run-opae
$(MAKE) -C kernel2 run-opae
$(MAKE) -C kernel3 run-opae
$(MAKE) -C kernel4 run-opae

clean:
$(MAKE) -C vecadd clean
Expand All @@ -106,4 +122,8 @@ clean:
$(MAKE) -C bfs clean
$(MAKE) -C sgemm2 clean
$(MAKE) -C sgemm3 clean
$(MAKE) -C psum clean
$(MAKE) -C psum clean
$(MAKE) -C kernel1 clean
$(MAKE) -C kernel2 clean
$(MAKE) -C kernel3 clean
$(MAKE) -C kernel4 clean
268 changes: 268 additions & 0 deletions tests/opencl/j_stat/statistic.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,268 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [],
"source": [
"import subprocess\n",
"import matplotlib.pyplot as plt\n",
"from dataclasses import dataclass, field\n",
"import pandas as pd\n",
"from tqdm import tqdm\n",
"from pathlib import Path"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {},
"outputs": [],
"source": [
"# architecture parameters\n",
"@dataclass\n",
"class arch:\n",
" warps: int = 1\n",
" cores: int = 1\n",
" threads: int = 1\n",
"# running parameters \n",
"@dataclass\n",
"class run:\n",
Comment on lines +27 to +31
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
" cores: int = 1\n",
" threads: int = 1\n",
"# running parameters \n",
"@dataclass\n",
"class run:\n",
" cores: int = 1\n",
" threads: int = 1\n",
"\n",
"# running parameters \n",
"@dataclass\n",
"class run:\n",

" arch: arch\n",
" kernel: str\n",
" driver: str = \"simx\"\n",
" args: dict = field(default_factory=dict)"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {},
"outputs": [],
"source": [
"path_to_vortex = Path.cwd().parent.parent.parent\n",
"tile_size = 'TS'\n",
"work_per_thread = 'WPT'\n",
"width = 'WIDTH'"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [],
"source": [
"def error_running (run_params: run, error_text: str) -> str:\n",
" 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",
" 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\""
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {},
"outputs": [],
"source": [
"def error_verification (run_params: run, number_of_errors: str) -> str:\n",
" 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",
" 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'\" "
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {},
"outputs": [],
"source": [
"def create_common_h (params: dict, kernel_name: str):\n",
" file_name = f\"{path_to_vortex}/tests/opencl/{kernel_name}/common.h\"\n",
" with open(file_name, 'w') as file:\n",
" file.write(\"#ifndef COMMON_H\\n\" + \"#define COMMON_H\\n\" + \"\\n\")\n",
" if tile_size in params:\n",
" file.write(f\"#define TS {params[tile_size]}\\n\")\n",
" if work_per_thread in params:\n",
" file.write(f\"#define WPT {params[work_per_thread]}\\n\")\n",
" file.write(\"#define RTS (TS/WPT)\\n\")\n",
" if width in params:\n",
" file.write(f\"#define WIDTH {params[width]}\\n\")\n",
" file.write('\\n' + \"#endif // COMMON_H\")\n",
" # open main.cc file to recompile before run with new common.h\n",
" Path(f\"{path_to_vortex}/tests/opencl/{kernel_name}/main.cc\").touch(exist_ok=True)"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {},
"outputs": [],
"source": [
"def perf (run_params: run, path_to_output_file: str) -> pd.DataFrame:\n",
" # run kernel\n",
" vortex = f\"--warps={run_params.arch.warps} --cores={run_params.arch.cores} --threads={run_params.arch.threads}\"\n",
" run_args = f\"-N{run_params.args['N']} -M{run_params.args['M']} -K{run_params.args['K']}\"\n",
" command = f\"cd {path_to_vortex}/build && ./ci/blackbox.sh {vortex} --driver={run_params.driver} --app={run_params.kernel} --args=\\\"{run_args}\\\"\"\n",
" print(command)\n",
" result = subprocess.run(f\"{command} > {path_to_output_file}\", shell=True)\n",
"\n",
" # collect statistic \n",
" with open(path_to_output_file, 'r') as file:\n",
" lines = file.readlines()\n",
" error_message = \"\"\n",
" general_perf_stat = \"\"\n",
" for line in lines:\n",
" if \"PERF:\" in line:\n",
" general_perf_stat = line\n",
" # check for errors\n",
" if result != 0:\n",
" if \"FAILED\" in line: \n",
" error_message = error_verification(run_params, line[line.find(\"FAILED! - \"):])\n",
" if \"Error\" in line:\n",
" error_message = error_running(run_params, line[line.find(\"Error:\"):])\n",
" # pars string with general perf statistic of running kernel\n",
" pairs = general_perf_stat.replace(\"PERF: \", \"\").split(\", \")\n",
" perf_dict = {key_value.split(\"=\")[0]: float(key_value.split(\"=\")[1]) for key_value in pairs}\n",
" if perf_dict[\"cycles\"] <= 0:\n",
" error_message = error_running(run_params, \"Invalid number of cycles\")\n",
" # write result to data frame\n",
" run_result = pd.DataFrame([{\"kernel\": run_params.kernel[-1], \"driver\": run_params.driver, \"cores\": run_params.arch.cores, \n",
" \"warps\": run_params.arch.warps, \"threads\": run_params.arch.threads, \"M\": run_params.args[\"M\"], \n",
" \"N\": run_params.args[\"N\"], \"K\": run_params.args[\"K\"], \"instrs\": perf_dict[\"instrs\"], \"cycles\": perf_dict[\"cycles\"],\n",
" \"IPC\": perf_dict[\"IPC\"], \"error\": error_message}])\n",
" return run_result"
]
},
{
"cell_type": "code",
"execution_count": 44,
"metadata": {},
"outputs": [],
"source": [
"def draw (data_frame: pd.DataFrame, x_label: str, y_label: str, title: str, path: str):\n",
" data_frame.plot(kind = \"bar\", x = x_label, y = y_label)\n",
" plt.title(title)\n",
" plt.xlabel(x_label)\n",
" plt.ylabel(y_label)\n",
" plt.savefig(path)"
]
},
{
"cell_type": "code",
"execution_count": 45,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
" 0%| | 0/4 [00:00<?, ?it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"cd /home/jblab/ivan_khromov/release/vortex/build && ./ci/blackbox.sh --warps=2 --cores=1 --threads=8 --driver=simx --app=kernel1 --args=\"-N16 -M16 -K16\"\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"In file included from /home/jblab/tools/pocl/include/CL/cl.h:20,\n",
" from /home/jblab/tools/pocl/include/CL/opencl.h:24,\n",
" from /home/jblab/ivan_khromov/release/vortex/tests/opencl/kernel1/main.cc:1:\n",
"/home/jblab/tools/pocl/include/CL/cl_version.h:22:104: note: #pragma message: cl_version.h: CL_TARGET_OPENCL_VERSION is not defined. Defaulting to 300 (OpenCL 3.0)\n",
" 22 | #pragma message(\"cl_version.h: CL_TARGET_OPENCL_VERSION is not defined. Defaulting to 300 (OpenCL 3.0)\")\n",
" | ^\n",
"/home/jblab/ivan_khromov/release/vortex/tests/opencl/kernel1/main.cc: In function ‘int main(int, char**)’:\n",
"/home/jblab/ivan_khromov/release/vortex/tests/opencl/kernel1/main.cc:161:25: warning: unused variable ‘context_properties’ [-Wunused-variable]\n",
" 161 | cl_context_properties context_properties[]{\n",
" | ^~~~~~~~~~~~~~~~~~\n",
"/home/jblab/ivan_khromov/release/vortex/tests/opencl/kernel1/main.cc:163:16: warning: unused variable ‘devices’ [-Wunused-variable]\n",
" 163 | cl_device_id devices[]{device_id};\n",
" | ^~~~~~~\n",
" 0%| | 0/4 [00:23<?, ?it/s]\n"
]
},
{
"ename": "IndexError",
"evalue": "list index out of range",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mIndexError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[45], 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/output.txt\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",
"Cell \u001b[0;32mIn[43], line 26\u001b[0m, in \u001b[0;36mperf\u001b[0;34m(run_params, path_to_output_file)\u001b[0m\n\u001b[1;32m 24\u001b[0m \u001b[38;5;66;03m# pars string with general perf statistic of running kernel\u001b[39;00m\n\u001b[1;32m 25\u001b[0m pairs \u001b[38;5;241m=\u001b[39m general_perf_stat\u001b[38;5;241m.\u001b[39mreplace(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mPERF: \u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m\"\u001b[39m)\u001b[38;5;241m.\u001b[39msplit(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m, \u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m---> 26\u001b[0m perf_dict \u001b[38;5;241m=\u001b[39m \u001b[43m{\u001b[49m\u001b[43mkey_value\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msplit\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mfloat\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mkey_value\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msplit\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m)\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mfor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mkey_value\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01min\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mpairs\u001b[49m\u001b[43m}\u001b[49m\n\u001b[1;32m 27\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m perf_dict[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcycles\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m<\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;241m0\u001b[39m:\n\u001b[1;32m 28\u001b[0m error_message \u001b[38;5;241m=\u001b[39m error_running(run_params, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInvalid number of cycles\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
"Cell \u001b[0;32mIn[43], line 26\u001b[0m, in \u001b[0;36m<dictcomp>\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 24\u001b[0m \u001b[38;5;66;03m# pars string with general perf statistic of running kernel\u001b[39;00m\n\u001b[1;32m 25\u001b[0m pairs \u001b[38;5;241m=\u001b[39m general_perf_stat\u001b[38;5;241m.\u001b[39mreplace(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mPERF: \u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m\"\u001b[39m)\u001b[38;5;241m.\u001b[39msplit(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m, \u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m---> 26\u001b[0m perf_dict \u001b[38;5;241m=\u001b[39m {key_value\u001b[38;5;241m.\u001b[39msplit(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m=\u001b[39m\u001b[38;5;124m\"\u001b[39m)[\u001b[38;5;241m0\u001b[39m]: \u001b[38;5;28mfloat\u001b[39m(\u001b[43mkey_value\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msplit\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m]\u001b[49m) \u001b[38;5;28;01mfor\u001b[39;00m key_value \u001b[38;5;129;01min\u001b[39;00m pairs}\n\u001b[1;32m 27\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m perf_dict[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcycles\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m<\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;241m0\u001b[39m:\n\u001b[1;32m 28\u001b[0m error_message \u001b[38;5;241m=\u001b[39m error_running(run_params, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInvalid number of cycles\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
"\u001b[0;31mIndexError\u001b[0m: list index out of range"
]
}
],
"source": [
"# create common.h files for each kernel\n",
"params1 = {\n",
" tile_size: 4\n",
"}\n",
"create_common_h(params1, \"kernel1\")\n",
"create_common_h(params1, \"kernel2\")\n",
"\n",
"params3 = {\n",
" tile_size: 4,\n",
" work_per_thread: 4\n",
"}\n",
"create_common_h(params3, \"kernel3\")\n",
"\n",
"params4 = {\n",
" tile_size: 8,\n",
" width: 4\n",
"}\n",
"create_common_h(params4, \"kernel4\")\n",
"\n",
"# fill running params data class for each kernel\n",
"run_p = []\n",
"arg = {\n",
" \"M\": 16,\n",
" \"N\": 16,\n",
" \"K\": 16\n",
"}\n",
"arch_p = arch(threads=8, cores=1, warps=2)\n",
"run_p.append(run(arch_p, kernel=\"kernel1\", driver=\"simx\", args=arg))\n",
"run_p.append(run(arch_p, kernel=\"kernel2\", driver=\"simx\", args=arg))\n",
"run_p.append(run(arch_p, kernel=\"kernel3\", driver=\"simx\", args=arg))\n",
"run_p.append(run(arch_p, kernel=\"kernel4\", driver=\"simx\", args=arg))\n",
"\n",
"# run all kernels and collect statistic in data frame\n",
"data_frames = []\n",
"output_file = f\"{path_to_vortex}/tests/opencl/j_stat/output.txt\"\n",
"for params in tqdm(run_p):\n",
" data_frames.append(perf(params, output_file))\n",
"data_frame = pd.concat(data_frames, ignore_index=True)\n",
"\n",
"# draw graph based on the recived statistic\n",
"draw(data_frame, \"kernel\", \"cycles\", \"number of cycles per kernel\", f\"graphics/graph.png\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
17 changes: 17 additions & 0 deletions tests/opencl/kernel1/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ROOT_DIR := $(realpath ../../..)
include $(ROOT_DIR)/config.mk

PROJECT := kernel1

SRC_DIR := $(VORTEX_HOME)/tests/opencl/$(PROJECT)

SRCS := $(SRC_DIR)/main.cc

kernel.cl: $(SRC_DIR)/kernel.cl
cp $< $@

KERNEL_SRCS := kernel.cl

OPTS ?=

include ../common.mk
6 changes: 6 additions & 0 deletions tests/opencl/kernel1/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef COMMON_H
#define COMMON_H

#define TS 4

#endif // COMMON_H
18 changes: 18 additions & 0 deletions tests/opencl/kernel1/kernel.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
__kernel void myGEMM1(const int M, const int N, const int K,
const __global float* A,
const __global float* B,
__global float* C) {
// Thread identifiers
const int globalRow = get_global_id(0); // Row ID of C (0..M)
const int globalCol = get_global_id(1); // Col ID of C (0..N)

// Compute a single element (loop over K)
float acc = 0.0f;
for (int k=0; k<K; k++) {
acc += A[k*M + globalRow] * B[globalCol*K + k];
}

// Store the result
C[globalCol*M + globalRow] = acc;
}

Loading