Skip to content

Commit

Permalink
updates and some testing:
Browse files Browse the repository at this point in the history
- edge embedding support in gnnbuilder lib
- new working GINE, not integrated end-to-end yet
- some initial testing and debugging for V2
  • Loading branch information
stefanpie committed Dec 8, 2023
1 parent 7f84c02 commit c39f81f
Show file tree
Hide file tree
Showing 537 changed files with 88,884 additions and 918 deletions.
73 changes: 70 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,75 @@
"scheme": "file"
}
],
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
// "editor.formatOnSave": true,
// "editor.codeActionsOnSave": {
// "source.organizeImports": true
// },
"[python]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": true,
"source.organizeImports": true
},
"editor.defaultFormatter": "charliermarsh.ruff"
},
"files.associations": {
"*.v": "systemverilog",
"chrono": "cpp",
"random": "cpp",
"limits": "cpp",
"bitset": "cpp",
"set": "cpp",
"cmath": "cpp",
"string": "cpp",
"array": "cpp",
"atomic": "cpp",
"strstream": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"cfenv": "cpp",
"clocale": "cpp",
"complex": "cpp",
"condition_variable": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"list": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"ratio": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"memory": "cpp",
"mutex": "cpp",
"new": "cpp",
"ostream": "cpp",
"numeric": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"cinttypes": "cpp",
"utility": "cpp",
"typeindex": "cpp",
"typeinfo": "cpp",
"hashtable": "cpp"
},
}
33 changes: 18 additions & 15 deletions demos/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
dataset = MoleculeNet(root="./tmp/MoleculeNet", name="hiv").index_select(
list(range(1000))
)

print(dataset)
print(f"dataset.num_classes={dataset.num_classes}")
print(f"dataset.num_features={dataset.num_features}")
Expand All @@ -59,27 +60,27 @@
model = gnnb.GNNModel(
graph_input_feature_dim=dataset.num_features,
graph_input_edge_dim=dataset.num_edge_features,
gnn_hidden_dim=16,
gnn_num_layers=2,
gnn_output_dim=8,
gnn_hidden_dim=128,
gnn_num_layers=6,
gnn_output_dim=64,
gnn_conv=gnnb.SAGEConv_GNNB,
gnn_activation=nn.ReLU,
gnn_skip_connection=True,
global_pooling=gnnb.GlobalPooling(["add", "mean", "max"]),
mlp_head=gnnb.MLP(
in_dim=8 * 3,
in_dim=64 * 3,
out_dim=dataset.num_classes,
hidden_dim=8,
hidden_layers=3,
hidden_dim=64,
hidden_layers=4,
activation=nn.ReLU,
p_in=8,
p_hidden=4,
p_hidden=8,
p_out=1,
),
output_activation=None,
gnn_p_in=1,
gnn_p_hidden=8,
gnn_p_out=4,
gnn_p_hidden=16,
gnn_p_out=8,
)

MAX_NODES = 600
Expand All @@ -90,7 +91,7 @@
)

PROJECT_NAME = "gnn_model"
VITIS_HLS_PATH = Path("/tools/software/xilinx/Vitis_HLS/2022.2/")
VITIS_HLS_PATH = Path("/tools/software/xilinx/Vitis_HLS/2023.1/")
BUILD_DIR_PROJECT = BUILD_DIR / PROJECT_NAME

print(f"Project Name: {PROJECT_NAME}")
Expand All @@ -111,19 +112,21 @@
num_edges_guess=num_edges_guess,
degree_guess=dataset_average_degree,
float_or_fixed="fixed",
fpx=FPX(32, 16),
fpx=FPX(16, 10),
fpga_part="xcu280-fsvh2892-2L-e",
n_jobs=32,
cosim_wave_debug=True,
)

proj.gen_hw_model()
proj.gen_testbench()
proj.gen_makefile()
proj.gen_vitis_hls_tcl_script()
proj.gen_vitis_hls_cosim_tcl_script()
proj.gen_makefile_vitis()

# tb_data = proj.build_and_run_testbench()
# print(tb_data)
tb_data = proj.build_and_run_testbench()
print(tb_data)

# synth_data = proj.run_vitis_hls_synthesis()
# print(synth_data)
synth_data = proj.run_vitis_hls_synthesis()
print(synth_data)
145 changes: 145 additions & 0 deletions demos/simple_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import logging
import os
import random
from pathlib import Path

import torch
import torch.nn as nn
from dotenv import dotenv_values
from torch_geometric.datasets import FakeDataset

import gnnbuilder as gnnb
from gnnbuilder.code_gen import FPX

logging.basicConfig(
level=logging.DEBUG,
format="[%(levelname)s][%(name)s][%(asctime)s] %(message)s",
handlers=[
logging.StreamHandler(),
],
)
logger = logging.getLogger("gnnb")

CURRENT_SCRIPT_DIR = Path(__file__).parent

env_config = dotenv_values("./.env")
if "BUILD_DIR" not in env_config:
raise ValueError("BUILD_DIR not defined in env_config")
else:
if env_config["BUILD_DIR"] is None:
raise ValueError("BUILD_DIR not defined in env_config")
else:
build_dir_str = env_config["BUILD_DIR"]
if not os.path.isdir(build_dir_str):
raise ValueError(f"BUILD_DIR={build_dir_str} is not a valid path")
else:
BUILD_DIR = Path(build_dir_str)
if "VITIS_HLS_BIN" not in env_config:
VITIS_HLS_BIN = "vitis_hls"
else:
VITIS_HLS_BIN = env_config["VITIS_HLS_BIN"]
if VITIS_HLS_BIN is None:
VITIS_HLS_BIN = "vitis_hls"


torch.manual_seed(0)
random.seed(0)


dataset = FakeDataset(
num_graphs=1,
avg_num_nodes=20,
avg_degree=5,
num_channels=8,
num_classes=10,
task="graph",
is_undirected=False,
)


print(dataset)
for data in dataset:
print(data)
print(f"dataset.num_classes={dataset.num_classes}")
print(f"dataset.num_features={dataset.num_features}")

dataset_max_node, dataset_max_edge = gnnb.compute_max_nodes_and_edges(dataset)
print(f"dataset_max_node={dataset_max_node}")
print(f"dataset_max_edge={dataset_max_edge}")

dataset_average_degree = gnnb.utils.compute_average_degree(dataset, round_val=True)
print(f"dataset_average_degree={dataset_average_degree}")


model = gnnb.GNNModel(
graph_input_feature_dim=dataset.num_features,
graph_input_edge_dim=dataset.num_edge_features,
gnn_hidden_dim=dataset.num_features * 2,
gnn_num_layers=3,
gnn_output_dim=dataset.num_features,
gnn_conv=gnnb.SAGEConv_GNNB,
gnn_activation=nn.ReLU,
gnn_skip_connection=True,
global_pooling=gnnb.GlobalPooling(["add", "mean", "max"]),
mlp_head=gnnb.MLP(
in_dim=dataset.num_features * 3,
out_dim=dataset.num_classes,
hidden_dim=dataset.num_features,
hidden_layers=2,
activation=nn.ReLU,
p_in=8,
p_hidden=4,
p_out=1,
),
output_activation=None,
gnn_p_in=1,
gnn_p_hidden=4,
gnn_p_out=4,
)

MAX_NODES = 100
MAX_EDGES = 200

num_nodes_guess, num_edges_guess = gnnb.compute_average_nodes_and_edges(
dataset, round_val=True
)

PROJECT_NAME = "gnn_model_simple_test"
VITIS_HLS_PATH = Path("/tools/software/xilinx/Vitis_HLS/2023.1/")

print(f"Project Name: {PROJECT_NAME}")
print(f"Vitis HLS Path: {VITIS_HLS_PATH}")
print(f"Build Directory: {BUILD_DIR}/{PROJECT_NAME}")


proj = gnnb.Project(
PROJECT_NAME,
model,
"classification_integer",
VITIS_HLS_PATH,
BUILD_DIR,
dataset=dataset,
max_nodes=MAX_NODES,
max_edges=MAX_EDGES,
num_nodes_guess=num_nodes_guess,
num_edges_guess=num_edges_guess,
degree_guess=dataset_average_degree,
float_or_fixed="fixed",
fpx=FPX(32, 10),
fpga_part="xcu280-fsvh2892-2L-e",
n_jobs=32,
cosim_wave_debug=True,
)

proj.gen_hw_model()
proj.gen_testbench()
proj.gen_makefile()
proj.gen_vitis_hls_tcl_script()
proj.gen_vitis_hls_cosim_tcl_script()
proj.gen_makefile_vitis()

tb_data = proj.build_and_run_testbench()
print(tb_data)

synth_data = proj.run_vitis_hls_synthesis()
print(synth_data)
8 changes: 4 additions & 4 deletions experiments/build_base_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,9 @@ def compute_pyg_gpu_benchmark(


if __name__ == "__main__":
RESULTS_DIR = Path("./results_batch")
RESULTS_DIR = Path("./results_testing")
os.makedirs(RESULTS_DIR, exist_ok=True)

# compute_pyg_cpu_benchmark(combos, RESULTS_DIR, trials=5, batch_size=1, cpu_idx=0)
# compute_pyg_gpu_benchmark(combos, RESULTS_DIR, trials=5, batch_size=1, gpu_idx=2)
# compute_pyg_gpu_benchmark(combos, RESULTS_DIR, trials=5, batch_size=4, gpu_idx=2)
compute_pyg_cpu_benchmark(combos, RESULTS_DIR, trials=5, batch_size=1, cpu_idx=0)
compute_pyg_gpu_benchmark(combos, RESULTS_DIR, trials=5, batch_size=1, gpu_idx=2)
compute_pyg_gpu_benchmark(combos, RESULTS_DIR, trials=5, batch_size=4, gpu_idx=2)
21 changes: 14 additions & 7 deletions experiments/build_gnnbuilder_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,18 +491,25 @@ def compute_fpga_par_benchmark(


if __name__ == "__main__":
RESULTS_DIR = Path("./results_gnnb/")
RESULTS_DIR = Path("./results_testing_fpga/")
os.makedirs(RESULTS_DIR, exist_ok=True)

BUILD_DIR = Path("/usr/scratch/skaram7/gnnb_main_builds/")
BUILD_DIR = Path("/usr/scratch/skaram7/gnnb_testing_fpga/")
os.makedirs(BUILD_DIR, exist_ok=True)

VITIS_HLS_PATH = Path("/tools/software/xilinx/Vitis_HLS/2022.2/")
VITIS_HLS_PATH = Path("/tools/software/xilinx/Vitis_HLS/2023.1/")

# compute_cpp_cpu_benchmark(combos, RESULTS_DIR, BUILD_DIR, VITIS_HLS_PATH, n_jobs=24)
# compute_fpga_base_benchmark(
# combos, RESULTS_DIR, BUILD_DIR, VITIS_HLS_PATH, n_jobs=24
# )
# print(len(combos))

print("Computing C++ CPU benchmark")
compute_cpp_cpu_benchmark(combos, RESULTS_DIR, BUILD_DIR, VITIS_HLS_PATH, n_jobs=24)

print("Computing FPGA base benchmark")
compute_fpga_base_benchmark(
combos, RESULTS_DIR, BUILD_DIR, VITIS_HLS_PATH, n_jobs=24
)

print("Computing FPGA parallel benchmark")
compute_fpga_par_benchmark(
combos, RESULTS_DIR, BUILD_DIR, VITIS_HLS_PATH, n_jobs=24
)
Loading

0 comments on commit c39f81f

Please sign in to comment.