{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Directory Structure","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19"}},{"cell_type":"code","source":"import numpy as np\nfrom glob import glob","metadata":{"execution":{"iopub.status.busy":"2023-10-03T09:22:40.202956Z","iopub.execute_input":"2023-10-03T09:22:40.203329Z","iopub.status.idle":"2023-10-03T09:22:40.260832Z","shell.execute_reply.started":"2023-10-03T09:22:40.203299Z","shell.execute_reply":"2023-10-03T09:22:40.259778Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!tree -I *.npz /kaggle/input/predict-ai-model-runtime/npz_all","metadata":{"execution":{"iopub.status.busy":"2023-10-03T09:22:40.262458Z","iopub.execute_input":"2023-10-03T09:22:40.263048Z","iopub.status.idle":"2023-10-03T09:22:44.021777Z","shell.execute_reply.started":"2023-10-03T09:22:40.263018Z","shell.execute_reply":"2023-10-03T09:22:44.020423Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!tree -I *.pb /kaggle/input/predict-ai-model-runtime/pb","metadata":{"execution":{"iopub.status.busy":"2023-10-03T09:22:44.023917Z","iopub.execute_input":"2023-10-03T09:22:44.024249Z","iopub.status.idle":"2023-10-03T09:22:45.444017Z","shell.execute_reply.started":"2023-10-03T09:22:44.024209Z","shell.execute_reply":"2023-10-03T09:22:45.442737Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"npz_layout_files = glob('/kaggle/input/predict-ai-model-runtime/npz_all/npz/layout/*/*/*/*.npz')\nnpz_tile_files = glob('/kaggle/input/predict-ai-model-runtime/npz_all/npz/tile/*/*/*.npz')\npb_layout_files = glob('/kaggle/input/predict-ai-model-runtime/pb/*/*/*/*/*/*.pb')\n\nlen(npz_layout_files), len(npz_tile_files), len(pb_layout_files)","metadata":{"execution":{"iopub.status.busy":"2023-10-03T09:22:45.447058Z","iopub.execute_input":"2023-10-03T09:22:45.447394Z","iopub.status.idle":"2023-10-03T09:22:45.503962Z","shell.execute_reply.started":"2023-10-03T09:22:45.447367Z","shell.execute_reply":"2023-10-03T09:22:45.502809Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"num_examples = 10\n\nprint(\"=\" * 50)\nprint(\"Example NPZ LAYOUT files\")\nprint(\"=\" * 50)\nprint('\\n'.join([file.split('/')[-1] for file in npz_layout_files[:num_examples]]))\n\nprint(\"=\" * 50)\nprint(\"Example NPZ TILE files\")\nprint(\"=\" * 50)\nprint('\\n'.join([file.split('/')[-1] for file in npz_tile_files[:num_examples]]))\n\nprint(\"=\" * 50)\nprint(\"Example PB LAYOUT files\")\nprint(\"=\" * 50)\nprint('\\n'.join([file.split('/')[-1] for file in pb_layout_files[:num_examples]]))\n","metadata":{"execution":{"iopub.status.busy":"2023-10-03T09:53:27.783934Z","iopub.execute_input":"2023-10-03T09:53:27.784551Z","iopub.status.idle":"2023-10-03T09:53:27.791466Z","shell.execute_reply.started":"2023-10-03T09:53:27.784518Z","shell.execute_reply":"2023-10-03T09:53:27.790816Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Explore NPZ Structure","metadata":{"execution":{"iopub.status.busy":"2023-10-02T15:33:20.469736Z","iopub.execute_input":"2023-10-02T15:33:20.470285Z","iopub.status.idle":"2023-10-02T15:33:20.476240Z","shell.execute_reply.started":"2023-10-02T15:33:20.470245Z","shell.execute_reply":"2023-10-02T15:33:20.475291Z"}}},{"cell_type":"code","source":"example_npz_layout = npz_layout_files[0]\nprint(f\"Exploring NPZ LAYOUT file:\\n\\t{example_npz_layout}\")\n\nexample_npz_tile = npz_tile_files[0]\nprint(f\"Exploring NPZ TILE file:\\n\\t{example_npz_tile}\")","metadata":{"execution":{"iopub.status.busy":"2023-10-03T10:06:46.360337Z","iopub.execute_input":"2023-10-03T10:06:46.360719Z","iopub.status.idle":"2023-10-03T10:06:46.366993Z","shell.execute_reply.started":"2023-10-03T10:06:46.360690Z","shell.execute_reply":"2023-10-03T10:06:46.365579Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Layout \n\nRepresenting a grpah (the **entire program**) with ```n``` nodes, ```m``` edges, and ```c``` configurations, where ```nc``` of the nodes are configurable.","metadata":{}},{"cell_type":"code","source":"npz_layout = np.load(example_npz_layout)\nfor key, value in npz_layout.items():\n    print(f\"{key}:\\n\\tType: {value.dtype}\\n\\tShape: {value.shape}\")","metadata":{"execution":{"iopub.status.busy":"2023-10-03T10:06:52.888321Z","iopub.execute_input":"2023-10-03T10:06:52.888663Z","iopub.status.idle":"2023-10-03T10:06:53.831611Z","shell.execute_reply.started":"2023-10-03T10:06:52.888637Z","shell.execute_reply":"2023-10-03T10:06:53.830261Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Representing a graph with ```n=1316``` nodes, ```m=2010``` directed edges, and ```c=100040``` configurations, where ```nc=72``` of the nodes are configurable:\n- ```edge_index```: **Directed edge pair** ```(u, v)``` for each of the ```m=2010``` edges, where ```u``` is the **destination** node index and ```v``` is the **source** node index.\n- ```node_feat```: **Feature vector** of size ```140``` for each of the ```n=1316``` nodes.\n- ```node_opcode```: **Node opcode** for each of the ```n=1316``` nodes.\n- ```node_config_feat```: **Feature vector** of size ```18``` for each of the ```nc=72``` configurable nodes, for each of the ```c=100040``` configurations.\n- ```node_config_ids```: **Node id** for each of the ```nc=72``` configurable nodes.\n- ```node_splits```:\n- ```config_runtime```: **Runtime** in ```milliseconds``` for each of the ```c=100040``` configurations.","metadata":{}},{"cell_type":"markdown","source":"## Tile\n\nRepresenting a graph (a **kernel**) with ```n``` nodes, ```m``` edges, and ```c``` configurations.","metadata":{}},{"cell_type":"code","source":"npz_tile = np.load(example_npz_tile)\nfor key, value in npz_tile.items():\n    print(f\"{key}:\\n\\tType: {value.dtype}\\n\\tShape: {value.shape}\")","metadata":{"execution":{"iopub.status.busy":"2023-10-03T10:07:04.839086Z","iopub.execute_input":"2023-10-03T10:07:04.839445Z","iopub.status.idle":"2023-10-03T10:07:04.851543Z","shell.execute_reply.started":"2023-10-03T10:07:04.839419Z","shell.execute_reply":"2023-10-03T10:07:04.850591Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Representing a graph with ```n=80``` nodes, ```m=86``` directed edges, and ```c=3246``` configurations:\n- ```node_feat```: **Feature vector** of size ```140``` for each of the ```n=80``` nodes.\n- ```node_opcode```: **Node opcode** for each of the ```n=80``` nodes.\n- ```edge_index```: **Directed edge pair** ```(u, v)``` for each of the ```m=86``` edges, where ```u``` is the **destination** node index and ```v``` is the -**source** node index.\n- ```config_feat```: **Feature vector** of size ```24``` for each of the ```c=3246``` configurations.\n- ```config_runtime```: **Runtime** in ```milliseconds``` for each of the ```c=3246``` configurations.\n- ```config_runtime_normalizers```: **Runtime** in ```milliseconds``` for each of the ```c=3246``` configurations, using a **deafult** configurations.","metadata":{}}]}