From c440bd4dba9ead2c599aefcff3b017a4662f7a7b Mon Sep 17 00:00:00 2001 From: colin Date: Tue, 29 Sep 2020 17:32:28 +0800 Subject: [PATCH] add bazel support 1/10 --- .bazelrc | 11 ++++ .bazelversion | 1 + .gitignore | 4 +- BUILD | 0 WORKSPACE | 51 ++++++++++++++++ onnxmlir.bzl | 129 +++++++++++++++++++++++++++++++++++++++ src/BUILD | 35 +++++++++++ src/Builder/BUILD | 11 ++++ src/Conversion/BUILD | 0 src/Dialect/BUILD | 0 src/Dialect/Krnl/BUILD | 38 ++++++++++++ src/Interface/BUILD | 0 src/Runtime/BUILD | 0 src/Tool/BUILD | 0 src/Transform/BUILD | 0 third_party/llvm-project | 1 + 16 files changed, 280 insertions(+), 1 deletion(-) create mode 100644 .bazelrc create mode 100644 .bazelversion create mode 100644 BUILD create mode 100644 WORKSPACE create mode 100644 onnxmlir.bzl create mode 100644 src/BUILD create mode 100644 src/Builder/BUILD create mode 100644 src/Conversion/BUILD create mode 100644 src/Dialect/BUILD create mode 100644 src/Dialect/Krnl/BUILD create mode 100644 src/Interface/BUILD create mode 100644 src/Runtime/BUILD create mode 100644 src/Tool/BUILD create mode 100644 src/Transform/BUILD create mode 160000 third_party/llvm-project diff --git a/.bazelrc b/.bazelrc new file mode 100644 index 0000000..a2d235f --- /dev/null +++ b/.bazelrc @@ -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 + + diff --git a/.bazelversion b/.bazelversion new file mode 100644 index 0000000..cb174d5 --- /dev/null +++ b/.bazelversion @@ -0,0 +1 @@ +1.2.1 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 792a047..6b790ef 100644 --- a/.gitignore +++ b/.gitignore @@ -181,4 +181,6 @@ dmypy.json *~ # Visual Studio Code Files -.vscode \ No newline at end of file +.vscode + +bazel-* \ No newline at end of file diff --git a/BUILD b/BUILD new file mode 100644 index 0000000..e69de29 diff --git a/WORKSPACE b/WORKSPACE new file mode 100644 index 0000000..47408e4 --- /dev/null +++ b/WORKSPACE @@ -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() \ No newline at end of file diff --git a/onnxmlir.bzl b/onnxmlir.bzl new file mode 100644 index 0000000..36f1026 --- /dev/null +++ b/onnxmlir.bzl @@ -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() diff --git a/src/BUILD b/src/BUILD new file mode 100644 index 0000000..b1106d5 --- /dev/null +++ b/src/BUILD @@ -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"], +) \ No newline at end of file diff --git a/src/Builder/BUILD b/src/Builder/BUILD new file mode 100644 index 0000000..fc9cfe9 --- /dev/null +++ b/src/Builder/BUILD @@ -0,0 +1,11 @@ +cc_library( + name = "OMBuilder", + srcs = [ + "FrontendDialectHelper.cpp", + "FrontendDialectHelper.hpp", + "FrontendDialectTransformer.cpp", + "FrontendDialectTransformer.hpp", + ], + hdrs = ["header files"], + deps = ["header files"], +) diff --git a/src/Conversion/BUILD b/src/Conversion/BUILD new file mode 100644 index 0000000..e69de29 diff --git a/src/Dialect/BUILD b/src/Dialect/BUILD new file mode 100644 index 0000000..e69de29 diff --git a/src/Dialect/Krnl/BUILD b/src/Dialect/Krnl/BUILD new file mode 100644 index 0000000..859eaa8 --- /dev/null +++ b/src/Dialect/Krnl/BUILD @@ -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", + ], +) diff --git a/src/Interface/BUILD b/src/Interface/BUILD new file mode 100644 index 0000000..e69de29 diff --git a/src/Runtime/BUILD b/src/Runtime/BUILD new file mode 100644 index 0000000..e69de29 diff --git a/src/Tool/BUILD b/src/Tool/BUILD new file mode 100644 index 0000000..e69de29 diff --git a/src/Transform/BUILD b/src/Transform/BUILD new file mode 100644 index 0000000..e69de29 diff --git a/third_party/llvm-project b/third_party/llvm-project new file mode 160000 index 0000000..1d01fc1 --- /dev/null +++ b/third_party/llvm-project @@ -0,0 +1 @@ +Subproject commit 1d01fc100bb5bef5f5eaf92520b2e52f64ee1d6e