diff --git a/BUILD.bazel b/BUILD.bazel index cd97f3365a..71a1a9df9f 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,5 +1,7 @@ +load("@bazel_skylib//rules:common_settings.bzl", "bool_flag") load("@bazel_skylib//rules:copy_file.bzl", "copy_file") load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") +load("@rules_cuda//cuda:defs.bzl", "cuda_library", "requires_cuda") copy_file( name = "highs-config", @@ -8,12 +10,43 @@ copy_file( visibility = ["//visibility:public"], ) +bool_flag( + name = "cupdlp_gpu", + build_setting_default = False, + visibility = ["//visibility:public"], +) + +config_setting( + name = "cupdlp_gpu_enabled", + flag_values = { + "@rules_cuda//cuda:enable": "True", + "@local_cuda//:valid_toolchain_found": "True", + ":cupdlp_gpu": "True", + }, +) + cc_library( name = "config", srcs = ["HConfig.h"], visibility = ["//visibility:public"], ) +cuda_library( + name = "cupdlp", + srcs = glob([ + "highs/pdlp/cupdlp/cuda/*.cu", + ]), + hdrs = glob([ + "highs/pdlp/cupdlp/cuda/*.cuh", + ]), + defines = ["CUPDLP_GPU"], + target_compatible_with = requires_cuda(), + deps = [ + "@local_cuda//:cublas", + "@local_cuda//:cusparse", + ], +) + cc_library( name = "highs", srcs = ["highs/interfaces/highs_c_api.cpp"] + glob([ @@ -49,6 +82,10 @@ cc_library( "-Wno-unused-but-set-variable", ], }), + defines = select({ + ":cupdlp_gpu_enabled": ["CUPDLP_GPU"], + "//conditions:default": ["CUPDLP_CPU"], + }), includes = [ "extern", # "extern/filereaderlp", @@ -66,7 +103,6 @@ cc_library( # "highs/simplex", # "highs/test_kkt", # "highs/util", - "bazel-bin", ], linkopts = select({ "@rules_cc//cc/compiler:msvc-cl": ["-DEFAULTLIB:shell32.lib"], @@ -76,7 +112,10 @@ cc_library( deps = [ "//:config", "@zlib", - ], + ] + select({ + ":cupdlp_gpu_enabled": [":cupdlp"], + "//conditions:default": [], + }), ) cc_library( diff --git a/MODULE.bazel b/MODULE.bazel index ae55331b05..abe3b01f01 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -19,3 +19,14 @@ bazel_dep( name = "zlib", version = "1.3.1.bcr.5", ) + +bazel_dep( + name = "rules_cuda", + version = "0.2.5", +) + +local_cuda = use_extension("@rules_cuda//cuda:extensions.bzl", "toolchain") +local_cuda.local_toolchain( + toolkit_path = "", +) +use_repo(local_cuda, "local_cuda") diff --git a/highs/HConfig.h.bazel.in b/highs/HConfig.h.bazel.in index 584d65f4eb..456229e7e4 100644 --- a/highs/HConfig.h.bazel.in +++ b/highs/HConfig.h.bazel.in @@ -3,7 +3,6 @@ #define FAST_BUILD /* #undef ZLIB_FOUND */ -#define CUPDLP_CPU #define CMAKE_BUILD_TYPE "RELEASE" #define HiGHSRELEASE /* #undef HIGHSINT64 */ diff --git a/highs/pdlp/README.md b/highs/pdlp/README.md index 2e0222afcb..bd7865f050 100644 --- a/highs/pdlp/README.md +++ b/highs/pdlp/README.md @@ -46,8 +46,18 @@ When both work, on Linux, you should check that `/usr/local/cuda` exists. #### Build +##### CMake + ``` cmake -S . -B build -DCUPDLP_GPU=ON -DALL_TESTS=ON .. cmake --build build --parallel ``` +##### Bazel + +```bash +# Will NOT build with CUDA, only CPU support +bazel build //:highs +# Will build with CUDA if a CUDA toolchain is detected +bazel build //:highs --//:cupdlp_gpu +```