diff --git a/.bazelrc b/.bazelrc new file mode 100644 index 00000000..201e7c7e --- /dev/null +++ b/.bazelrc @@ -0,0 +1,30 @@ +# +------------------------------------------------------------+ +# | Build Configurations | +# +------------------------------------------------------------+ +# Do not show warnings from external dependencies. +build --output_filter="^//" + +build --show_timestamps + +build --flag_alias=cuda_archs=@rules_cuda//cuda:archs + +# Work around the sandbox issue. +build --spawn_strategy=local + + +# Consider warning as error. +# inference is not included because tensorflow uses the same log macros with glog and it will +# cause re-definition warning. +build --per_file_copt="-\\.$@-Wall,-Wextra,-Werror" +build --per_file_copt="-\\.$,external/.*@-w" +build --per_file_copt="-\\.$,third_party/.*@-w" + +# If a command fails, print out the full command line. +build --verbose_failures + +# Enable C++17 +build --cxxopt="-std=c++17" +# Workaround as cpp toolchain: stop passing -std=c++0x per default · Issue #18181 · bazelbuild/bazel +build --host_cxxopt="-std=c++17" +# Enable colorful output of GCC +build --cxxopt="-fdiagnostics-color=always" diff --git a/.bazelversion b/.bazelversion new file mode 100644 index 00000000..f4131375 --- /dev/null +++ b/.bazelversion @@ -0,0 +1 @@ +8.4.1 \ No newline at end of file diff --git a/.gitignore b/.gitignore index b3a2b78a..a28581a2 100644 --- a/.gitignore +++ b/.gitignore @@ -11,5 +11,20 @@ vsxmake2022 # CMake Cache CMakeBuild/ -# IntelliJ IDEA -.idea/ +# Bazel build +bazel-* +MODULE.bazel.lock + +# JetBrains IDEs +.idea/ + +.vs/ + +.cache + +compile_commands.json + +# //external is reserved by Bazel and needed for hedron_compile_commands +external/ + +presubmit.yml diff --git a/BUILD.bazel b/BUILD.bazel new file mode 100644 index 00000000..2bad480b --- /dev/null +++ b/BUILD.bazel @@ -0,0 +1,74 @@ +load("@bazel_skylib//rules:common_settings.bzl", "bool_flag") +load("@rules_cc//cc:defs.bzl", "cc_library") +load("@rules_license//rules:license.bzl", "license") + +package( + default_applicable_licenses = [":license"], + default_visibility = ["//visibility:public"], +) + +license( + name = "license", + package_name = "hugooole_muda", + package_url = "https://github.com/hugooole/muda", + license_text = "LICENSE", + license_kinds = ["@rules_license//licenses/spdx:Apache-2.0"], +) + +bool_flag( + name = "muda_check", + build_setting_default = True, +) + +config_setting( + name = "muda_check_on", + flag_values = {":muda_check": "True"}, +) + +bool_flag( + name = "muda_compute_graph", + build_setting_default = False, +) + +config_setting( + name = "muda_compute_graph_on", + flag_values = {":muda_compute_graph": "True"}, +) + +bool_flag( + name = "muda_nvtx3", + build_setting_default = False, +) + +config_setting( + name = "muda_nvtx3_on", + flag_values = {":muda_nvtx3": "True"}, +) + +cc_library( + name = "muda", + hdrs = glob( + [ + "src/**/*.h", + "src/**/*.hpp", + "src/**/*.inl", + "src/**/*.cuh", + ], + allow_empty = True, + ), + copts = [ + "--expt-relaxed-constexpr", + "--extended-lambda", + ], + defines = select({ + ":muda_check_on": ["MUDA_CHECK_ON"], + "//conditions:default": ["MUDA_CHECK_ON=0"], + }) + select({ + ":muda_compute_graph_on": ["MUDA_COMPUTE_GRAPH_ON"], + "//conditions:default": [], + }) + select({ + ":muda_nvtx3_on": ["MUDA_NVTX3_ON"], + "//conditions:default": [], + }), + includes = ["src"], +) diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 00000000..9a5b5602 --- /dev/null +++ b/MODULE.bazel @@ -0,0 +1,42 @@ +"""muda""" + +module( + name = "hugooole_muda", + version = "1.0.0-beta", + compatibility_level = 1, +) + +bazel_dep(name = "rules_cc", version = "0.2.8") + +bazel_dep(name = "rules_license", version = "1.0.0") + +bazel_dep(name = "eigen", version = "3.4.1", dev_dependency = True) +bazel_dep(name = "bazel_skylib", version = "1.8.2") + +# rules_cuda is required for CUDA toolchain support +bazel_dep(name = "rules_cuda", version = "0.2.4") +git_override( + module_name = "rules_cuda", + remote = "https://github.com/bazel-contrib/rules_cuda.git", + commit = "1bf21ef1eee98042c0b2c5f39365ac39a4217c53", +) + + + +cuda = use_extension("@rules_cuda//cuda:extensions.bzl", "toolchain") +cuda.toolkit( + name = "cuda", + toolkit_path = "", +) +use_repo(cuda, "cuda") + +# Optional for debug: Hedron's Compile Commands Extractor for Bazel +# https://github.com/hedronvision/bazel-compile-commands-extractor +# bazel_dep(name = "hedron_compile_commands", dev_dependency = True) +# git_override( +# module_name = "hedron_compile_commands", +# remote = "https://github.com/hedronvision/bazel-compile-commands-extractor.git", +# commit = "abb61a688167623088f8768cc9264798df6a9d10", +# # Replace the commit hash (above) with the latest (https://github.com/hedronvision/bazel-compile-commands-extractor/commits/main). +# # Even better, set up Renovate and let it do the work for you (see "Suggestion: Updates" in the README). +# ) \ No newline at end of file diff --git a/example/BUILD.bazel b/example/BUILD.bazel new file mode 100644 index 00000000..4b6f6c6a --- /dev/null +++ b/example/BUILD.bazel @@ -0,0 +1,23 @@ +load("@rules_cuda//cuda:defs.bzl", "cuda_binary") + +cuda_binary( + name = "examples", + srcs = glob([ + "**/*.cu", + "**/*.cpp", + ]), + hdrs = [ + "example_common.h", + ], + copts = [ + "-std=c++20", + ], + includes = ["."], + rdc = True, + visibility = ["//:__pkg__"], + deps = [ + "//:muda", + "//third_party:catch2", + "@eigen", + ], +) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 767f4fad..9f21716d 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -19,7 +19,7 @@ set_target_properties(muda_example PROPERTIES CUDA_SEPARABLE_COMPILATION ON) # target_link_libraries(muda_example PRIVATE fmt::fmt-header-only) target_include_directories(muda_example PRIVATE "${PROJECT_SOURCE_DIR}/example" - "${PROJECT_SOURCE_DIR}/external") + "${PROJECT_SOURCE_DIR}/third_party") target_link_libraries(muda_example PRIVATE muda Eigen3::Eigen) source_group(TREE "${PROJECT_SOURCE_DIR}/example" PREFIX "example" FILES ${SOURCE_FILES}) source_group(TREE "${PROJECT_SOURCE_DIR}/src" PREFIX "src" FILES ${MUDA_HEADER_FILES}) diff --git a/src/muda/launch/stream.h b/src/muda/launch/stream.h index ffc23d45..d23c2435 100644 --- a/src/muda/launch/stream.h +++ b/src/muda/launch/stream.h @@ -77,7 +77,7 @@ class Stream std::byte* workspace(size_t byte_size); private: - Stream(nullptr_t) + Stream(std::nullptr_t) : m_handle(nullptr) { } diff --git a/test/BUILD.bazel b/test/BUILD.bazel new file mode 100644 index 00000000..3f0a34e9 --- /dev/null +++ b/test/BUILD.bazel @@ -0,0 +1,75 @@ +load("@rules_cuda//cuda:defs.bzl", "cuda_test") + +cuda_test( + name = "muda_unit_test", + srcs = glob([ + "unit_test/**/*.cu", + "unit_test/**/*.cpp", + ]), + copts = [ + "--expt-relaxed-constexpr", + "--extended-lambda", + "-std=c++20", + ], + rdc = True, + deps = [ + "//:muda", + "//third_party:catch2", + "@eigen", + ], +) + +cuda_test( + name = "muda_eigen_test", + srcs = glob([ + "eigen_test/**/*.cu", + "eigen_test/**/*.cpp", + ]), + hdrs = glob( + [ + "eigen_test/**/*.h", + "eigen_test/**/*.hpp", + ], + allow_empty = True, + ), + copts = [ + "--expt-relaxed-constexpr", + "--extended-lambda", + "-std=c++20", + ], + rdc = True, + deps = [ + "//:muda", + "//third_party:catch2", + "@eigen", + ], +) + +cuda_test( + name = "muda_linear_system_test", + srcs = glob([ + "linear_system_test/**/*.cu", + "linear_system_test/**/*.cpp", + ]), + hdrs = glob( + [ + "linear_system_test/**/*.h", + "linear_system_test/**/*.hpp", + ], + allow_empty = True, + ), + copts = [ + "--expt-relaxed-constexpr", + "--extended-lambda", + "-std=c++20", + ], + rdc = True, + deps = [ + "//:muda", + "//third_party:catch2", + "@eigen", + "@cuda//:cublas", + "@cuda//:cusolver", + "@cuda//:cusparse", + ], +) diff --git a/test/eigen_test/CMakeLists.txt b/test/eigen_test/CMakeLists.txt index 3f68f249..ea278c2c 100644 --- a/test/eigen_test/CMakeLists.txt +++ b/test/eigen_test/CMakeLists.txt @@ -7,7 +7,7 @@ target_compile_features(muda_eigen_test PRIVATE cxx_std_20) set_target_properties(muda_eigen_test PROPERTIES CUDA_SEPARABLE_COMPILATION ON) target_include_directories(muda_eigen_test PRIVATE "${PROJECT_SOURCE_DIR}/test" - "${PROJECT_SOURCE_DIR}/external") + "${PROJECT_SOURCE_DIR}/third_party") target_link_libraries(muda_eigen_test PRIVATE muda Eigen3::Eigen) source_group(TREE "${PROJECT_SOURCE_DIR}/test" PREFIX "test" FILES ${SOURCE}) source_group(TREE "${PROJECT_SOURCE_DIR}/src" PREFIX "src" FILES ${MUDA_HEADER_FILES}) diff --git a/test/linear_system_test/CMakeLists.txt b/test/linear_system_test/CMakeLists.txt index f7c8e64f..bbe5fd7b 100644 --- a/test/linear_system_test/CMakeLists.txt +++ b/test/linear_system_test/CMakeLists.txt @@ -10,7 +10,7 @@ target_compile_features(muda_linear_system_test PRIVATE cxx_std_20) set_target_properties(muda_linear_system_test PROPERTIES CUDA_SEPARABLE_COMPILATION ON) target_include_directories(muda_linear_system_test PRIVATE "${PROJECT_SOURCE_DIR}/test" - "${PROJECT_SOURCE_DIR}/external") + "${PROJECT_SOURCE_DIR}/third_party") target_link_libraries(muda_linear_system_test PRIVATE muda cusparse cublas cusolver Eigen3::Eigen) source_group(TREE "${PROJECT_SOURCE_DIR}/test" PREFIX "test" FILES ${SOURCE}) source_group(TREE "${PROJECT_SOURCE_DIR}/src" PREFIX "src" FILES ${MUDA_HEADER_FILES}) diff --git a/test/spgrid_test/CMakeLists.txt b/test/spgrid_test/CMakeLists.txt index 3048418a..61e36ccb 100644 --- a/test/spgrid_test/CMakeLists.txt +++ b/test/spgrid_test/CMakeLists.txt @@ -11,7 +11,7 @@ target_compile_features(muda_spgrid_test PRIVATE cxx_std_20) set_target_properties(muda_spgrid_test PROPERTIES CUDA_SEPARABLE_COMPILATION ON) target_include_directories(muda_spgrid_test PRIVATE "${PROJECT_SOURCE_DIR}/test" - "${PROJECT_SOURCE_DIR}/external") + "${PROJECT_SOURCE_DIR}/third_party") target_link_libraries(muda_spgrid_test PRIVATE muda Eigen3::Eigen) add_test(NAME muda_spgrid_test COMMAND muda_spgrid_test) diff --git a/test/unit_test/CMakeLists.txt b/test/unit_test/CMakeLists.txt index 6f1b86bc..79fb23a6 100644 --- a/test/unit_test/CMakeLists.txt +++ b/test/unit_test/CMakeLists.txt @@ -10,7 +10,7 @@ target_compile_features(muda_unit_test PRIVATE cxx_std_20) set_target_properties(muda_unit_test PROPERTIES CUDA_SEPARABLE_COMPILATION ON) target_include_directories(muda_unit_test PRIVATE "${PROJECT_SOURCE_DIR}/test" - "${PROJECT_SOURCE_DIR}/external") + "${PROJECT_SOURCE_DIR}/third_party") target_link_libraries(muda_unit_test PRIVATE muda cusparse cublas cusolver Eigen3::Eigen) target_compile_definitions(muda_unit_test PRIVATE "-DMUDA_TEST_DATA_DIR=R\"(${PROJECT_SOURCE_DIR}/test/data)\"") source_group(TREE "${PROJECT_SOURCE_DIR}/test" PREFIX "test" FILES ${SOURCE}) diff --git a/third_party/BUILD.bazel b/third_party/BUILD.bazel new file mode 100644 index 00000000..b57b88fd --- /dev/null +++ b/third_party/BUILD.bazel @@ -0,0 +1,11 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") + +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "catch2", + hdrs = glob([ + "catch2/**/*.hpp", + ]), + includes = ["."], +) diff --git a/external/catch2/catch.hpp b/third_party/catch2/catch.hpp similarity index 100% rename from external/catch2/catch.hpp rename to third_party/catch2/catch.hpp diff --git a/external/catch2/catch_reporter_automake.hpp b/third_party/catch2/catch_reporter_automake.hpp similarity index 100% rename from external/catch2/catch_reporter_automake.hpp rename to third_party/catch2/catch_reporter_automake.hpp diff --git a/external/catch2/catch_reporter_sonarqube.hpp b/third_party/catch2/catch_reporter_sonarqube.hpp similarity index 100% rename from external/catch2/catch_reporter_sonarqube.hpp rename to third_party/catch2/catch_reporter_sonarqube.hpp diff --git a/external/catch2/catch_reporter_tap.hpp b/third_party/catch2/catch_reporter_tap.hpp similarity index 100% rename from external/catch2/catch_reporter_tap.hpp rename to third_party/catch2/catch_reporter_tap.hpp diff --git a/external/catch2/catch_reporter_teamcity.hpp b/third_party/catch2/catch_reporter_teamcity.hpp similarity index 100% rename from external/catch2/catch_reporter_teamcity.hpp rename to third_party/catch2/catch_reporter_teamcity.hpp