Skip to content

Commit deff617

Browse files
committed
test: benchgc: initial commit for benchgc
1 parent 277e55c commit deff617

File tree

21 files changed

+3135
-0
lines changed

21 files changed

+3135
-0
lines changed

test/benchgc/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dist/
2+
src/benchgc.egg-info/
3+
build

test/benchgc/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# benchgc - benchmark tool for graph compiler

test/benchgc/cases/add.mlir

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module {
2+
func.func @f32(%arg0: tensor<128x256xf32>, %arg1: tensor<128x256xf32>) -> tensor<128x256xf32> {
3+
%0 = onednn_graph.add %arg0, %arg1 : (tensor<128x256xf32>, tensor<128x256xf32>) -> tensor<128x256xf32>
4+
return %0 : tensor<128x256xf32>
5+
}
6+
}

test/benchgc/cases/mlp.mlir

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module {
2+
func.func @bf16_layer2(%in: tensor<128x512xbf16>,
3+
%weight0: tensor<512x256xbf16>, %bias0: tensor<256xbf16>,
4+
%weight1: tensor<256x64xbf16>, %bias1: tensor<64xbf16>) -> tensor<128x64xbf16> {
5+
// layer 0
6+
%0 = onednn_graph.matmul %in, %weight0, %bias0 : (tensor<128x512xbf16>, tensor<512x256xbf16>, tensor<256xbf16>) -> tensor<128x256xbf16>
7+
%1 = onednn_graph.relu %0 : (tensor<128x256xbf16>) -> tensor<128x256xbf16>
8+
// layer 1
9+
%2 = onednn_graph.matmul %1, %weight1, %bias1 : (tensor<128x256xbf16>, tensor<256x64xbf16>, tensor<64xbf16>) -> tensor<128x64xbf16>
10+
%3 = onednn_graph.relu %2 : (tensor<128x64xbf16>) -> tensor<128x64xbf16>
11+
return %3 : tensor<128x64xbf16>
12+
}
13+
}

test/benchgc/setup.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
################################################################################
2+
# Copyright 2024 Intel Corporation
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
################################################################################
16+
17+
import pathlib
18+
import sys
19+
import setuptools
20+
import os
21+
import subprocess
22+
from typing import List
23+
24+
build_dir: pathlib.Path = pathlib.Path.cwd() / "build_temp"
25+
if not build_dir.exists():
26+
build_dir.mkdir(parents=True)
27+
28+
cmake_args: List[str] = [
29+
f"-DPYTHON_EXECUTABLE={sys.executable}",
30+
"-DCMAKE_BUILD_TYPE=Debug",
31+
"-DMLIR_ENABLE_BINDINGS_PYTHON=ON",
32+
]
33+
if "SC_MLIR" in os.environ:
34+
cmake_args.append(f"-DMLIR_DIR={os.environ['SC_MLIR']}")
35+
36+
subprocess.run(["cmake", "../../../mlir", *cmake_args], cwd=build_dir, check=True)
37+
subprocess.run(["make", "-j"], cwd=build_dir, check=True)
38+
39+
setuptools.setup(
40+
name="benchgc",
41+
description="benchmark tool for graph compiler",
42+
package_dir={
43+
"benchgc": "src/benchgc",
44+
"gcext": "build_temp/python_packages/gcext_core/gcext",
45+
},
46+
packages=setuptools.find_packages("src")
47+
+ setuptools.find_packages("build_temp/python_packages/gcext_core"),
48+
package_data={"gcext": ["_mlir_libs/*.so"]},
49+
install_requires=["torch", "numpy"],
50+
)

test/benchgc/src/benchgc/__init__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
################################################################################
2+
# Copyright 2024 Intel Corporation
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
################################################################################
16+
17+
import sys
18+
import pathlib
19+
20+
# add the path to $PYTHONPATH where pysc shared object is located
21+
sys.path.append(pathlib.Path(__file__).parent.resolve().__str__())

test/benchgc/src/benchgc/__main__.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
################################################################################
2+
# Copyright 2024 Intel Corporation
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
################################################################################
16+
17+
18+
import json
19+
import sys
20+
import argparse
21+
import gcext.ir
22+
import gcext.dialects.onednn_graph
23+
from . import graph, runner, gapi, util
24+
25+
try:
26+
parser = argparse.ArgumentParser(prog="benchmark tool for graph compiler")
27+
parser.add_argument("--mlir", required=True, help="a mlir case file", type=str)
28+
parser.add_argument("--entry", required=True, help="main entry function", type=str)
29+
parser.add_argument(
30+
"--json",
31+
default=None,
32+
help="dump graph api json file into the specified file name",
33+
type=str,
34+
)
35+
parser.add_argument(
36+
"--seed",
37+
required=False,
38+
default=0,
39+
type=int,
40+
help="a seed value to generate data filling",
41+
)
42+
parser.add_argument(
43+
"--verbose",
44+
type=int,
45+
default=util.NO_VERBOSE,
46+
help="verbose level",
47+
choices=[
48+
util.NO_VERBOSE,
49+
util.COMPARE_VERBOSE,
50+
util.ERROR_OUTPUT_VERBOSE,
51+
util.OUTPUT_VERBOSE,
52+
util.INPUT_VERBOSE,
53+
],
54+
)
55+
56+
args = parser.parse_args()
57+
util.set_seed(args.seed)
58+
except argparse.ArgumentError:
59+
sys.stderr.write("Argument parse failed\n")
60+
sys.exit(1)
61+
62+
with open(args.mlir, "r") as mlir_file:
63+
with gcext.ir.Context() as ctx:
64+
gcext.dialects.onednn_graph.register_dialect()
65+
module = gcext.ir.Module.parse(mlir_file.read())
66+
g = gapi.MLIRGraph(module)
67+
graph_object = g.convert_to_json('"' + args.entry + '"')
68+
if args.json is not None:
69+
with open(args.json, "w") as json_file:
70+
json.dump(graph_object, json_file)

0 commit comments

Comments
 (0)