add bazel support 1/10

This commit is contained in:
colin 2020-09-29 17:32:28 +08:00
parent 6bd9471262
commit c440bd4dba
16 changed files with 280 additions and 1 deletions

11
.bazelrc Normal file
View File

@ -0,0 +1,11 @@
build --cxxopt=-std=c++14
build --host_cxxopt=-std=c++14
build --spawn_strategy=standalone
build --host_force_python=PY2
build --incompatible_bzl_disallow_load_after_statement=false
test --host_force_python=PY2
test --incompatible_bzl_disallow_load_after_statement=false

1
.bazelversion Normal file
View File

@ -0,0 +1 @@
1.2.1

2
.gitignore vendored
View File

@ -182,3 +182,5 @@ dmypy.json
# Visual Studio Code Files # Visual Studio Code Files
.vscode .vscode
bazel-*

0
BUILD Normal file
View File

51
WORKSPACE Normal file
View File

@ -0,0 +1,51 @@
workspace(name = "onnxmlir")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository", "new_git_repository")
LLVM_COMMIT = "85763e0758fbd238c81f233c6f9510e81c7de177"
LLVM_BAZEL_TAG = "llvm-project-%s" % (LLVM_COMMIT,)
LLVM_BAZEL_SHA256 = "5d358075abc2db8192c138bdaa6ce74f2c59a0bde6d7d57813f3fc66d6b6da34"
http_archive(
name = "llvm-bazel",
sha256 = LLVM_BAZEL_SHA256,
strip_prefix = "llvm-bazel-{tag}/llvm-bazel".format(tag = LLVM_BAZEL_TAG),
url = "https://github.com/google/llvm-bazel/archive/{tag}.tar.gz".format(tag = LLVM_BAZEL_TAG),
)
LLVM_SHA256 = "f33108ba4bc81c6704753838ee4d85ad87e195fda3df991c2b00f18872a9e2dd"
LLVM_URLS = [
# "https://storage.googleapis.com/mirror.tensorflow.org/github.com/llvm/llvm-project/archive/{commit}.tar.gz".format(commit = LLVM_COMMIT),
"https://github.com/llvm/llvm-project/archive/{commit}.tar.gz".format(commit = LLVM_COMMIT),
]
http_archive(
name = "llvm-project-raw",
build_file_content = "#empty",
sha256 = LLVM_SHA256,
strip_prefix = "llvm-project-" + LLVM_COMMIT,
urls = LLVM_URLS,
)
load("@llvm-bazel//:configure.bzl", "llvm_configure")
llvm_configure(
name = "llvm-project",
src_path = ".",
src_workspace = "@llvm-project-raw//:WORKSPACE",
)
ONNX_MLIR_SHA256 = "f33108ba4bc81c6704753838ee4d85ad87e195fda3df991c2b00f18872a9e2dd"
http_archive(
name = "onnx-mlir-raw",
build_file_content = "#empty",
sha256 = ONNX_MLIR_SHA256,
strip_prefix = "src",
urls = [
"https://github.com/onnx/onnx-mlir.git",
],
)
load(":onnxmlir.bzl", "onnxmlir_deps")
onnxmlir_deps()

129
onnxmlir.bzl Normal file
View File

@ -0,0 +1,129 @@
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository", "new_git_repository")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
def clean_dep(dep):
return str(Label(dep))
def third_party_deps():
if "zlib_archive" not in native.existing_rules():
http_archive(
name = "zlib_archive",
build_file = "//third_party:zlib.BUILD",
sha256 = "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1",
strip_prefix = "zlib-1.2.11",
urls = [
"http://mirror.tensorflow.org/zlib.net/zlib-1.2.11.tar.gz",
"https://zlib.net/zlib-1.2.11.tar.gz",
],
)
if "gtest" not in native.existing_rules():
http_archive(
name = "gtest",
sha256 = "9cbca84c4256bed17df2c8f4d00c912c19d247c11c9ba6647cd6dd5b5c996b8d",
strip_prefix = "googletest-9816b96a6ddc0430671693df90192bbee57108b6",
urls = [
"https://mirror.bazel.build/github.com/google/googletest/archive/9816b96a6ddc0430671693df90192bbee57108b6.zip",
"https://github.com/google/googletest/archive/9816b96a6ddc0430671693df90192bbee57108b6.zip",
],
)
if "glog" not in native.existing_rules():
git_repository(
name = "glog",
commit = "41f4bf9cbc3e8995d628b459f6a239df43c2b84a",
remote = "https://github.com/google/glog",
)
if "com_github_gflags_gflags" not in native.existing_rules():
http_archive(
name = "com_github_gflags_gflags",
sha256 = "34af2f15cf7367513b352bdcd2493ab14ce43692d2dcd9dfc499492966c64dcf",
strip_prefix = "gflags-2.2.2",
urls = [
"https://github.com/gflags/gflags/archive/v2.2.2.tar.gz",
],
)
if "pybind11" not in native.existing_rules():
http_archive(
name = "pybind11",
build_file = "//third_party:pybind11.BUILD",
sha256 = "1eed57bc6863190e35637290f97a20c81cfe4d9090ac0a24f3bbf08f265eb71d",
strip_prefix = "pybind11-2.4.3",
urls = [
"https://github.com/pybind/pybind11/archive/v2.4.3.tar.gz",
],
)
if "eigen" not in native.existing_rules():
http_archive(
name = "eigen",
build_file = "//third_party:eigen.BUILD",
sha256 = "d56fbad95abf993f8af608484729e3d87ef611dd85b3380a8bad1d5cbc373a57",
strip_prefix = "eigen-3.3.7",
urls = ["https://gitlab.com/libeigen/eigen/-/archive/3.3.7/eigen-3.3.7.tar.gz"],
)
if "google_styleguide" not in native.existing_rules():
new_git_repository(
name = "google_styleguide",
build_file = "//third_party:google_styleguide.BUILD",
commit = "91d6e367e384b0d8aaaf7ce95029514fcdf38651",
remote = "https://github.com/google/styleguide",
)
if "onnx" not in native.existing_rules():
new_git_repository(
name = "onnx",
build_file = "//third_party:onnx.BUILD",
commit = "553df22c67bee5f0fe6599cff60f1afc6748c635",
remote = "https://github.com/onnx/onnx",
)
#if "rules_foreign_cc" not in native.existing_rules():
# http_archive(
# name = "rules_foreign_cc",
# strip_prefix = "rules_foreign_cc-master",
# url = "https://github.com/bazelbuild/rules_foreign_cc/archive/master.zip",
# )
if "cpp-taskflow" not in native.existing_rules():
http_archive(
name = "cpp-taskflow",
build_file = "//third_party:cpp-taskflow.BUILD",
sha256 = "e32168875e18182a5796e453751715c2a7ef7beefbebe57b1f55a705de223c1e",
strip_prefix = "taskflow-2.3.0",
urls = ["https://github.com/cpp-taskflow/cpp-taskflow/archive/v2.3.0.tar.gz"],
)
if "clang_binary" not in native.existing_rules():
http_archive(
name = "clang_binary",
build_file = "@Primo//:third_party/clang_binary.BUILD",
url = "http://swbuild.enflame.cn/clang/clang11-20200628.tar.gz",
sha256 = "b51a7e534f20fe0977c5f0096d4c44fd2c3bd28661c43f4149d217540aea700c",
)
if "scope_guard" not in native.existing_rules():
new_git_repository(
name = "scope_guard",
remote = "https://github.com/ricab/scope_guard",
commit = "760de0a9ea0fec980a5244604ffa5b1acff2db7a",
build_file = "//third_party:scope_guard.BUILD",
)
if "dlpack" not in native.existing_rules():
new_git_repository(
name = "dlpack",
remote = "https://github.com/dmlc/dlpack",
commit = "3ec04430e89a6834e5a1b99471f415fa939bf642",
build_file = "//third_party:dlpack.BUILD",
)
def internal_deps():
return
def onnxmlir_deps():
internal_deps()
third_party_deps()

35
src/BUILD Normal file
View File

@ -0,0 +1,35 @@
cc_binary(
name = "MainUtils",
srcs = ["MainUtils.hpp","MainUtils.cpp"],
copts = [],
deps = [
"@onnx",
"//Builder:OMBuilder",
OMKrnlOps
OMONNXOps
OMKrnlToAffine
OMKrnlToLLVM
OMONNXToKrnl
OMONNXRewrite
OMShapeInference
OMShapeInferenceOpInterface
OMAttributePromotion
OMPromotableConstOperandsOpInterface
OMResultTypeInferenceOpInterface
OMElideConstants
OMElideKrnlGlobalConstants
OMPackKrnlGlobalConstants
OMEnableMemoryPool
OMBundleMemoryPools
OMDisconnectKrnlDimFromAlloc
OMLowerKrnlShape
],
)
cc_binary(
name = "onnx-mlir",
srcs = ["main.cpp"],
copts = [],
deps = [":MainUtils"],
)

11
src/Builder/BUILD Normal file
View File

@ -0,0 +1,11 @@
cc_library(
name = "OMBuilder",
srcs = [
"FrontendDialectHelper.cpp",
"FrontendDialectHelper.hpp",
"FrontendDialectTransformer.cpp",
"FrontendDialectTransformer.hpp",
],
hdrs = ["header files"],
deps = ["header files"],
)

0
src/Conversion/BUILD Normal file
View File

0
src/Dialect/BUILD Normal file
View File

38
src/Dialect/Krnl/BUILD Normal file
View File

@ -0,0 +1,38 @@
load("@llvm-project//mlir:tblgen.bzl", "gentbl")
gentbl(
name = "OMKrnlOpsIncGen",
tbl_outs = [
("-gen-op-decls", "KrnlOps.hpp.inc"),
("-gen-op-defs", "KrnlOps.cpp.inc"),
],
tblgen = "@llvm-project//mlir:mlir-tblgen",
td_file = "KrnlOps.td",
td_includes = ["."],
td_srcs = [
"@llvm-project//mlir:TdFiles",
],
)
cc_library(
name = "OMKrnlOps",
srcs = [
"KrnlHelper.cpp",
"KrnlHelper.hpp",
"KrnlOps.cpp",
"KrnlOps.hpp",
"KrnlTypes.cpp",
"KrnlTypes.hpp",
],
hdrs = glob([
"**/*.h",
"**/*.inc",
]),
deps = [
":OMKrnlOpsIncGen",
"@llvm-project//mlir:Affine",
"@llvm-project//mlir:IR",
"@llvm-project//mlir:Shape",
"@llvm-project//mlir:TableGen",
],
)

0
src/Interface/BUILD Normal file
View File

0
src/Runtime/BUILD Normal file
View File

0
src/Tool/BUILD Normal file
View File

0
src/Transform/BUILD Normal file
View File

1
third_party/llvm-project vendored Submodule

@ -0,0 +1 @@
Subproject commit 1d01fc100bb5bef5f5eaf92520b2e52f64ee1d6e