Skip to content

Commit

Permalink
build success with llvm
Browse files Browse the repository at this point in the history
  • Loading branch information
PikachuHy committed Jan 2, 2024
1 parent ce74ecc commit 786d5d9
Show file tree
Hide file tree
Showing 6 changed files with 325 additions and 0 deletions.
1 change: 1 addition & 0 deletions .bazeliskrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
USE_BAZEL_VERSION=6.4.0
2 changes: 2 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ build --incompatible_strict_action_env
build --verbose_failures
build --workspace_status_command "python3 workspace_status.py"
build:macos --define client_type=macos
build:macos --cxxopt=-std=c++20 --host_cxxopt=-std=c++20
build:android --define client_type=android
common --noenable_bzlmod
50 changes: 50 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
load("version.bzl", "gen_pscm_version_info")
load("test.bzl", "collect_pscm_tests")
load("@llvm-project//mlir:tblgen.bzl", "gentbl_cc_library", "td_library")

py_binary(
name = "gen_cpp",
Expand Down Expand Up @@ -74,6 +75,40 @@ cc_library(
# "@optional",
# "@string-view-lite",
# "@variant",
"@llvm-project//llvm:Core",
"@llvm-project//llvm:OrcJIT",
"@llvm-project//llvm:Support",
"@llvm-project//mlir:AffineDialect",
"@llvm-project//mlir:AffineToStandard",
"@llvm-project//mlir:AffineTransforms",
"@llvm-project//mlir:AllPassesAndDialects",
"@llvm-project//mlir:Analysis",
"@llvm-project//mlir:ArithDialect",
"@llvm-project//mlir:ArithToLLVM",
"@llvm-project//mlir:BuiltinToLLVMIRTranslation",
"@llvm-project//mlir:CastInterfaces",
"@llvm-project//mlir:ControlFlowToLLVM",
"@llvm-project//mlir:ExecutionEngine",
"@llvm-project//mlir:ExecutionEngineUtils",
"@llvm-project//mlir:FuncDialect",
"@llvm-project//mlir:FuncExtensions",
"@llvm-project//mlir:FuncToLLVM",
"@llvm-project//mlir:IR",
"@llvm-project//mlir:LLVMCommonConversion",
"@llvm-project//mlir:LLVMDialect",
"@llvm-project//mlir:LLVMIRTransforms",
"@llvm-project//mlir:LLVMToLLVMIRTranslation",
"@llvm-project//mlir:MemRefDialect",
"@llvm-project//mlir:MemRefToLLVM",
"@llvm-project//mlir:Parser",
"@llvm-project//mlir:Pass",
"@llvm-project//mlir:SCFDialect",
"@llvm-project//mlir:SCFToControlFlow",
"@llvm-project//mlir:SideEffectInterfaces",
"@llvm-project//mlir:Support",
"@llvm-project//mlir:ToLLVMIRTranslation",
"@llvm-project//mlir:TransformUtils",
"@llvm-project//mlir:Transforms",
],
)

Expand All @@ -85,3 +120,18 @@ cc_binary(
)

collect_pscm_tests()

td_library(
name = "pscm-ops-td-files",
srcs = [
"include/pscm/Ops.td",
],
includes = ["include"],
deps = [
"@llvm-project//mlir:CallInterfacesTdFiles",
"@llvm-project//mlir:CastInterfacesTdFiles",
"@llvm-project//mlir:FunctionInterfacesTdFiles",
"@llvm-project//mlir:OpBaseTdFiles",
"@llvm-project//mlir:SideEffectInterfacesTdFiles",
],
)
85 changes: 85 additions & 0 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ workspace(name = "dev_pscm")

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")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

new_git_repository(
name = "cpp-linenoise",
Expand Down Expand Up @@ -237,3 +238,87 @@ git_repository(
commit = "1c1933fa1ebadd6954fe9eff18e8bb0d018594ff",
remote = "https://github.com/PikachuHy/icu.bazel.git",
)

new_git_repository(
name = "llvm-raw",
build_file_content = "# empty",
commit = "6009708b4367171ccdbf4b5905cb6a803753fe18",
remote = "https://github.com/llvm/llvm-project.git"
)

load("@llvm-raw//utils/bazel:configure.bzl", "llvm_configure")

llvm_configure(name = "llvm-project")

maybe(
http_archive,
name = "llvm_zlib",
build_file = "@llvm-raw//utils/bazel/third_party_build:zlib-ng.BUILD",
sha256 = "e36bb346c00472a1f9ff2a0a4643e590a254be6379da7cddd9daeb9a7f296731",
strip_prefix = "zlib-ng-2.0.7",
urls = [
"https://github.com/zlib-ng/zlib-ng/archive/refs/tags/2.0.7.zip",
],
)

maybe(
http_archive,
name = "vulkan_headers",
build_file = "@llvm-raw//utils/bazel/third_party_build:vulkan_headers.BUILD",
sha256 = "19f491784ef0bc73caff877d11c96a48b946b5a1c805079d9006e3fbaa5c1895",
strip_prefix = "Vulkan-Headers-9bd3f561bcee3f01d22912de10bb07ce4e23d378",
urls = [
"https://github.com/KhronosGroup/Vulkan-Headers/archive/9bd3f561bcee3f01d22912de10bb07ce4e23d378.tar.gz",
],
)

load("@llvm-raw//utils/bazel:vulkan_sdk.bzl", "vulkan_sdk_setup")

maybe(
vulkan_sdk_setup,
name = "vulkan_sdk",
)

maybe(
http_archive,
name = "gmp",
build_file = "@llvm-raw//utils/bazel/third_party_build:gmp.BUILD",
sha256 = "fd4829912cddd12f84181c3451cc752be224643e87fac497b69edddadc49b4f2",
strip_prefix = "gmp-6.2.1",
urls = [
"https://gmplib.org/download/gmp/gmp-6.2.1.tar.xz",
"https://ftp.gnu.org/gnu/gmp/gmp-6.2.1.tar.xz",
],
)

# https://www.mpfr.org/mpfr-current/
#
# When updating to a newer version, don't use URLs with "mpfr-current" in them.
# Instead, find a stable URL like the one used currently.
maybe(
http_archive,
name = "mpfr",
build_file = "@llvm-raw//utils/bazel/third_party_build:mpfr.BUILD",
sha256 = "9cbed5d0af0d9ed5e9f8dd013e17838eb15e1db9a6ae0d371d55d35f93a782a7",
strip_prefix = "mpfr-4.1.1",
urls = ["https://www.mpfr.org/mpfr-4.1.1/mpfr-4.1.1.tar.gz"],
)

maybe(
new_git_repository,
name = "pfm",
build_file = "@llvm-raw//utils/bazel/third_party_build:pfm.BUILD",
remote = "https://git.code.sf.net/p/perfmon2/libpfm4",
tag = "v4.12.1",
)

maybe(
http_archive,
name = "llvm_zstd",
build_file = "@llvm-raw//utils/bazel/third_party_build:zstd.BUILD",
sha256 = "7c42d56fac126929a6a85dbc73ff1db2411d04f104fae9bdea51305663a83fd0",
strip_prefix = "zstd-1.5.2",
urls = [
"https://github.com/facebook/zstd/releases/download/v1.5.2/zstd-1.5.2.tar.gz"
],
)
56 changes: 56 additions & 0 deletions include/pscm/Ops.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#ifndef PSCM_OPS
#define PSCM_OPS

def PSCM_Dialect : Dialect {
let name = "pscm";
let cppNamespace = "::mlir::toy"
let hasConstantMaterializer = 1;
let useDefaultTypePrinterParser = 1;
}

class PSCM_Op<string mnemonic, list<Trait> traits = []> :
Op<PSCM_Dialect, mnemonic, traits>;

def PSCM_Type : AnyTypeOf<[F64Tensor]>;

def ConstantOp : PSCM_Op<"constant",
[ConstantLike, Pure]> {
let summary = "constant";
let description = [{
Constant operation
}]
let arguments = (ins F64ElemetsAttr:$value);
let results = (outs F64Tensor)

let hasCustomAssemblyFormat = 1;

let builders = [
OpBuilder<(ins "DenseElementAttr":$value), [{
build($_builder, $_state, value.getType(), value);
}]>,
OpBuilder<(ins "double":$value)>
];

let hasVerifier = 1;

let hasFolder = 1;
}

def AddOp : PSCM_Op<"add",
[Pure]> {
let summary = "addition operation";
let description = [{
The "add" operation performs addidtion
}];

let arguments = (ins F64Tensor:$lhs, F64Tensor:$rhs);
let results = (outs F64Tensor);

let hasCustomAssemblyFormat = 1;

let builders = [
OpBuilder<(ins "Value":$lhs, "Value":$rhs)>
]

}
#endif
131 changes: 131 additions & 0 deletions src/mlir/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
load("@llvm-project//mlir:tblgen.bzl", "gentbl_cc_library", "td_library")

licenses(["notice"])

package(default_visibility = ["//visibility:public"])

# td_library(
# name = "ToyOpsTdFiles",
# srcs = [
# "include/toy/Ops.td",
# "include/toy/ShapeInferenceInterface.td",
# ],
# includes = ["include"],
# deps = [
# "//mlir:CallInterfacesTdFiles",
# "//mlir:CastInterfacesTdFiles",
# "//mlir:FunctionInterfacesTdFiles",
# "//mlir:OpBaseTdFiles",
# "//mlir:SideEffectInterfacesTdFiles",
# ],
# )

# gentbl_cc_library(
# name = "ToyInterfacesIncGen",
# tbl_outs = [
# (
# ["-gen-op-interface-decls"],
# "include/toy/ShapeInferenceOpInterfaces.h.inc",
# ),
# (
# ["-gen-op-interface-defs"],
# "include/toy/ShapeInferenceOpInterfaces.cpp.inc",
# ),
# ],
# tblgen = "//mlir:mlir-tblgen",
# td_file = "include/toy/ShapeInferenceInterface.td",
# deps = [":ToyOpsTdFiles"],
# )

# gentbl_cc_library(
# name = "ToyOpsIncGen",
# tbl_outs = [
# (
# ["-gen-op-decls"],
# "include/toy/Ops.h.inc",
# ),
# (
# ["-gen-op-defs"],
# "include/toy/Ops.cpp.inc",
# ),
# (
# ["-gen-dialect-decls"],
# "include/toy/Dialect.h.inc",
# ),
# (
# ["-gen-dialect-defs"],
# "include/toy/Dialect.cpp.inc",
# ),
# ],
# tblgen = "//mlir:mlir-tblgen",
# td_file = "include/toy/Ops.td",
# deps = [":ToyOpsTdFiles"],
# )

# gentbl_cc_library(
# name = "ToyCombineIncGen",
# strip_include_prefix = "mlir",
# tbl_outs = [
# (
# ["-gen-rewriters"],
# "mlir/ToyCombine.inc",
# ),
# ],
# tblgen = "//mlir:mlir-tblgen",
# td_file = "mlir/ToyCombine.td",
# deps = [":ToyOpsTdFiles"],
# )

cc_binary(
name = "toyc",
# srcs = [
# "mlir/Dialect.cpp",
# "mlir/LowerToAffineLoops.cpp",
# "mlir/LowerToLLVM.cpp",
# "mlir/MLIRGen.cpp",
# "mlir/ShapeInferencePass.cpp",
# "mlir/ToyCombine.cpp",
# "parser/AST.cpp",
# "toyc.cpp",
# ] + glob(["include/toy/*.h"]),
includes = ["include/"],
deps = [
# ":ToyCombineIncGen",
# ":ToyInterfacesIncGen",
# ":ToyOpsIncGen",
"@llvm-project//llvm:Core",
"@llvm-project//llvm:OrcJIT",
"@llvm-project//llvm:Support",
"@llvm-project//mlir:AffineDialect",
"@llvm-project//mlir:AffineToStandard",
"@llvm-project//mlir:AffineTransforms",
"@llvm-project//mlir:AllPassesAndDialects",
"@llvm-project//mlir:Analysis",
"@llvm-project//mlir:ArithDialect",
"@llvm-project//mlir:ArithToLLVM",
"@llvm-project//mlir:BuiltinToLLVMIRTranslation",
"@llvm-project//mlir:CastInterfaces",
"@llvm-project//mlir:ControlFlowToLLVM",
"@llvm-project//mlir:ExecutionEngine",
"@llvm-project//mlir:ExecutionEngineUtils",
"@llvm-project//mlir:FuncDialect",
"@llvm-project//mlir:FuncExtensions",
"@llvm-project//mlir:FuncToLLVM",
"@llvm-project//mlir:IR",
"@llvm-project//mlir:LLVMCommonConversion",
"@llvm-project//mlir:LLVMDialect",
"@llvm-project//mlir:LLVMIRTransforms",
"@llvm-project//mlir:LLVMToLLVMIRTranslation",
"@llvm-project//mlir:MemRefDialect",
"@llvm-project//mlir:MemRefToLLVM",
"@llvm-project//mlir:Parser",
"@llvm-project//mlir:Pass",
"@llvm-project//mlir:SCFDialect",
"@llvm-project//mlir:SCFToControlFlow",
"@llvm-project//mlir:SideEffectInterfaces",
"@llvm-project//mlir:Support",
"@llvm-project//mlir:ToLLVMIRTranslation",
"@llvm-project//mlir:TransformUtils",
"@llvm-project//mlir:Transforms",
],
)

0 comments on commit 786d5d9

Please sign in to comment.