Skip to content

Commit fad2ae6

Browse files
authored
Merge pull request #73 from hugooole/main
Add Bazel support and rename external to third_party
2 parents e01f9aa + d6e8c60 commit fad2ae6

File tree

19 files changed

+279
-8
lines changed

19 files changed

+279
-8
lines changed

.bazelrc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# +------------------------------------------------------------+
2+
# | Build Configurations |
3+
# +------------------------------------------------------------+
4+
# Do not show warnings from external dependencies.
5+
build --output_filter="^//"
6+
7+
build --show_timestamps
8+
9+
build --flag_alias=cuda_archs=@rules_cuda//cuda:archs
10+
11+
# Work around the sandbox issue.
12+
build --spawn_strategy=local
13+
14+
15+
# Consider warning as error.
16+
# inference is not included because tensorflow uses the same log macros with glog and it will
17+
# cause re-definition warning.
18+
build --per_file_copt="-\\.$@-Wall,-Wextra,-Werror"
19+
build --per_file_copt="-\\.$,external/.*@-w"
20+
build --per_file_copt="-\\.$,third_party/.*@-w"
21+
22+
# If a command fails, print out the full command line.
23+
build --verbose_failures
24+
25+
# Enable C++17
26+
build --cxxopt="-std=c++17"
27+
# Workaround as cpp toolchain: stop passing -std=c++0x per default · Issue #18181 · bazelbuild/bazel
28+
build --host_cxxopt="-std=c++17"
29+
# Enable colorful output of GCC
30+
build --cxxopt="-fdiagnostics-color=always"

.bazelversion

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
8.4.1

.gitignore

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,20 @@ vsxmake2022
1111
# CMake Cache
1212
CMakeBuild/
1313

14-
# IntelliJ IDEA
15-
.idea/
14+
# Bazel build
15+
bazel-*
16+
MODULE.bazel.lock
17+
18+
# JetBrains IDEs
19+
.idea/
20+
21+
.vs/
22+
23+
.cache
24+
25+
compile_commands.json
26+
27+
# //external is reserved by Bazel and needed for hedron_compile_commands
28+
external/
29+
30+
presubmit.yml

BUILD.bazel

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
2+
load("@rules_cc//cc:defs.bzl", "cc_library")
3+
load("@rules_license//rules:license.bzl", "license")
4+
5+
package(
6+
default_applicable_licenses = [":license"],
7+
default_visibility = ["//visibility:public"],
8+
)
9+
10+
license(
11+
name = "license",
12+
package_name = "hugooole_muda",
13+
package_url = "https://github.com/hugooole/muda",
14+
license_text = "LICENSE",
15+
license_kinds = ["@rules_license//licenses/spdx:Apache-2.0"],
16+
)
17+
18+
bool_flag(
19+
name = "muda_check",
20+
build_setting_default = True,
21+
)
22+
23+
config_setting(
24+
name = "muda_check_on",
25+
flag_values = {":muda_check": "True"},
26+
)
27+
28+
bool_flag(
29+
name = "muda_compute_graph",
30+
build_setting_default = False,
31+
)
32+
33+
config_setting(
34+
name = "muda_compute_graph_on",
35+
flag_values = {":muda_compute_graph": "True"},
36+
)
37+
38+
bool_flag(
39+
name = "muda_nvtx3",
40+
build_setting_default = False,
41+
)
42+
43+
config_setting(
44+
name = "muda_nvtx3_on",
45+
flag_values = {":muda_nvtx3": "True"},
46+
)
47+
48+
cc_library(
49+
name = "muda",
50+
hdrs = glob(
51+
[
52+
"src/**/*.h",
53+
"src/**/*.hpp",
54+
"src/**/*.inl",
55+
"src/**/*.cuh",
56+
],
57+
allow_empty = True,
58+
),
59+
copts = [
60+
"--expt-relaxed-constexpr",
61+
"--extended-lambda",
62+
],
63+
defines = select({
64+
":muda_check_on": ["MUDA_CHECK_ON"],
65+
"//conditions:default": ["MUDA_CHECK_ON=0"],
66+
}) + select({
67+
":muda_compute_graph_on": ["MUDA_COMPUTE_GRAPH_ON"],
68+
"//conditions:default": [],
69+
}) + select({
70+
":muda_nvtx3_on": ["MUDA_NVTX3_ON"],
71+
"//conditions:default": [],
72+
}),
73+
includes = ["src"],
74+
)

MODULE.bazel

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""muda"""
2+
3+
module(
4+
name = "hugooole_muda",
5+
version = "1.0.0-beta",
6+
compatibility_level = 1,
7+
)
8+
9+
bazel_dep(name = "rules_cc", version = "0.2.8")
10+
11+
bazel_dep(name = "rules_license", version = "1.0.0")
12+
13+
bazel_dep(name = "eigen", version = "3.4.1", dev_dependency = True)
14+
bazel_dep(name = "bazel_skylib", version = "1.8.2")
15+
16+
# rules_cuda is required for CUDA toolchain support
17+
bazel_dep(name = "rules_cuda", version = "0.2.4")
18+
git_override(
19+
module_name = "rules_cuda",
20+
remote = "https://github.com/bazel-contrib/rules_cuda.git",
21+
commit = "1bf21ef1eee98042c0b2c5f39365ac39a4217c53",
22+
)
23+
24+
25+
26+
cuda = use_extension("@rules_cuda//cuda:extensions.bzl", "toolchain")
27+
cuda.toolkit(
28+
name = "cuda",
29+
toolkit_path = "",
30+
)
31+
use_repo(cuda, "cuda")
32+
33+
# Optional for debug: Hedron's Compile Commands Extractor for Bazel
34+
# https://github.com/hedronvision/bazel-compile-commands-extractor
35+
# bazel_dep(name = "hedron_compile_commands", dev_dependency = True)
36+
# git_override(
37+
# module_name = "hedron_compile_commands",
38+
# remote = "https://github.com/hedronvision/bazel-compile-commands-extractor.git",
39+
# commit = "abb61a688167623088f8768cc9264798df6a9d10",
40+
# # Replace the commit hash (above) with the latest (https://github.com/hedronvision/bazel-compile-commands-extractor/commits/main).
41+
# # Even better, set up Renovate and let it do the work for you (see "Suggestion: Updates" in the README).
42+
# )

example/BUILD.bazel

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
load("@rules_cuda//cuda:defs.bzl", "cuda_binary")
2+
3+
cuda_binary(
4+
name = "examples",
5+
srcs = glob([
6+
"**/*.cu",
7+
"**/*.cpp",
8+
]),
9+
hdrs = [
10+
"example_common.h",
11+
],
12+
copts = [
13+
"-std=c++20",
14+
],
15+
includes = ["."],
16+
rdc = True,
17+
visibility = ["//:__pkg__"],
18+
deps = [
19+
"//:muda",
20+
"//third_party:catch2",
21+
"@eigen",
22+
],
23+
)

example/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ set_target_properties(muda_example PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
1919
# target_link_libraries(muda_example PRIVATE fmt::fmt-header-only)
2020
target_include_directories(muda_example PRIVATE
2121
"${PROJECT_SOURCE_DIR}/example"
22-
"${PROJECT_SOURCE_DIR}/external")
22+
"${PROJECT_SOURCE_DIR}/third_party")
2323
target_link_libraries(muda_example PRIVATE muda Eigen3::Eigen)
2424
source_group(TREE "${PROJECT_SOURCE_DIR}/example" PREFIX "example" FILES ${SOURCE_FILES})
2525
source_group(TREE "${PROJECT_SOURCE_DIR}/src" PREFIX "src" FILES ${MUDA_HEADER_FILES})

src/muda/launch/stream.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class Stream
7777
std::byte* workspace(size_t byte_size);
7878

7979
private:
80-
Stream(nullptr_t)
80+
Stream(std::nullptr_t)
8181
: m_handle(nullptr)
8282
{
8383
}

test/BUILD.bazel

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
load("@rules_cuda//cuda:defs.bzl", "cuda_test")
2+
3+
cuda_test(
4+
name = "muda_unit_test",
5+
srcs = glob([
6+
"unit_test/**/*.cu",
7+
"unit_test/**/*.cpp",
8+
]),
9+
copts = [
10+
"--expt-relaxed-constexpr",
11+
"--extended-lambda",
12+
"-std=c++20",
13+
],
14+
rdc = True,
15+
deps = [
16+
"//:muda",
17+
"//third_party:catch2",
18+
"@eigen",
19+
],
20+
)
21+
22+
cuda_test(
23+
name = "muda_eigen_test",
24+
srcs = glob([
25+
"eigen_test/**/*.cu",
26+
"eigen_test/**/*.cpp",
27+
]),
28+
hdrs = glob(
29+
[
30+
"eigen_test/**/*.h",
31+
"eigen_test/**/*.hpp",
32+
],
33+
allow_empty = True,
34+
),
35+
copts = [
36+
"--expt-relaxed-constexpr",
37+
"--extended-lambda",
38+
"-std=c++20",
39+
],
40+
rdc = True,
41+
deps = [
42+
"//:muda",
43+
"//third_party:catch2",
44+
"@eigen",
45+
],
46+
)
47+
48+
cuda_test(
49+
name = "muda_linear_system_test",
50+
srcs = glob([
51+
"linear_system_test/**/*.cu",
52+
"linear_system_test/**/*.cpp",
53+
]),
54+
hdrs = glob(
55+
[
56+
"linear_system_test/**/*.h",
57+
"linear_system_test/**/*.hpp",
58+
],
59+
allow_empty = True,
60+
),
61+
copts = [
62+
"--expt-relaxed-constexpr",
63+
"--extended-lambda",
64+
"-std=c++20",
65+
],
66+
rdc = True,
67+
deps = [
68+
"//:muda",
69+
"//third_party:catch2",
70+
"@eigen",
71+
"@cuda//:cublas",
72+
"@cuda//:cusolver",
73+
"@cuda//:cusparse",
74+
],
75+
)

test/eigen_test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ target_compile_features(muda_eigen_test PRIVATE cxx_std_20)
77
set_target_properties(muda_eigen_test PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
88
target_include_directories(muda_eigen_test PRIVATE
99
"${PROJECT_SOURCE_DIR}/test"
10-
"${PROJECT_SOURCE_DIR}/external")
10+
"${PROJECT_SOURCE_DIR}/third_party")
1111
target_link_libraries(muda_eigen_test PRIVATE muda Eigen3::Eigen)
1212
source_group(TREE "${PROJECT_SOURCE_DIR}/test" PREFIX "test" FILES ${SOURCE})
1313
source_group(TREE "${PROJECT_SOURCE_DIR}/src" PREFIX "src" FILES ${MUDA_HEADER_FILES})

0 commit comments

Comments
 (0)