Skip to content

Commit 86de861

Browse files
authored
Merge pull request #2554 from TendTo/feat/cuda
Allow CUDA build with bazel
2 parents 54b3012 + 44f5b6c commit 86de861

File tree

4 files changed

+62
-3
lines changed

4 files changed

+62
-3
lines changed

BUILD.bazel

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
12
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
23
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
4+
load("@rules_cuda//cuda:defs.bzl", "cuda_library", "requires_cuda")
35

46
copy_file(
57
name = "highs-config",
@@ -8,12 +10,43 @@ copy_file(
810
visibility = ["//visibility:public"],
911
)
1012

13+
bool_flag(
14+
name = "cupdlp_gpu",
15+
build_setting_default = False,
16+
visibility = ["//visibility:public"],
17+
)
18+
19+
config_setting(
20+
name = "cupdlp_gpu_enabled",
21+
flag_values = {
22+
"@rules_cuda//cuda:enable": "True",
23+
"@local_cuda//:valid_toolchain_found": "True",
24+
":cupdlp_gpu": "True",
25+
},
26+
)
27+
1128
cc_library(
1229
name = "config",
1330
srcs = ["HConfig.h"],
1431
visibility = ["//visibility:public"],
1532
)
1633

34+
cuda_library(
35+
name = "cupdlp",
36+
srcs = glob([
37+
"highs/pdlp/cupdlp/cuda/*.cu",
38+
]),
39+
hdrs = glob([
40+
"highs/pdlp/cupdlp/cuda/*.cuh",
41+
]),
42+
defines = ["CUPDLP_GPU"],
43+
target_compatible_with = requires_cuda(),
44+
deps = [
45+
"@local_cuda//:cublas",
46+
"@local_cuda//:cusparse",
47+
],
48+
)
49+
1750
cc_library(
1851
name = "highs",
1952
srcs = ["highs/interfaces/highs_c_api.cpp"] + glob([
@@ -49,6 +82,10 @@ cc_library(
4982
"-Wno-unused-but-set-variable",
5083
],
5184
}),
85+
defines = select({
86+
":cupdlp_gpu_enabled": ["CUPDLP_GPU"],
87+
"//conditions:default": ["CUPDLP_CPU"],
88+
}),
5289
includes = [
5390
"extern",
5491
# "extern/filereaderlp",
@@ -66,7 +103,6 @@ cc_library(
66103
# "highs/simplex",
67104
# "highs/test_kkt",
68105
# "highs/util",
69-
"bazel-bin",
70106
],
71107
linkopts = select({
72108
"@rules_cc//cc/compiler:msvc-cl": ["-DEFAULTLIB:shell32.lib"],
@@ -76,7 +112,10 @@ cc_library(
76112
deps = [
77113
"//:config",
78114
"@zlib",
79-
],
115+
] + select({
116+
":cupdlp_gpu_enabled": [":cupdlp"],
117+
"//conditions:default": [],
118+
}),
80119
)
81120

82121
cc_library(

MODULE.bazel

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,14 @@ bazel_dep(
1919
name = "zlib",
2020
version = "1.3.1.bcr.5",
2121
)
22+
23+
bazel_dep(
24+
name = "rules_cuda",
25+
version = "0.2.5",
26+
)
27+
28+
local_cuda = use_extension("@rules_cuda//cuda:extensions.bzl", "toolchain")
29+
local_cuda.local_toolchain(
30+
toolkit_path = "",
31+
)
32+
use_repo(local_cuda, "local_cuda")

highs/HConfig.h.bazel.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#define FAST_BUILD
55
/* #undef ZLIB_FOUND */
6-
#define CUPDLP_CPU
76
#define CMAKE_BUILD_TYPE "RELEASE"
87
#define HiGHSRELEASE
98
/* #undef HIGHSINT64 */

highs/pdlp/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,18 @@ When both work, on Linux, you should check that `/usr/local/cuda` exists.
4646

4747
#### Build
4848

49+
##### CMake
50+
4951
```
5052
cmake -S . -B build -DCUPDLP_GPU=ON -DALL_TESTS=ON ..
5153
cmake --build build --parallel
5254
```
5355

56+
##### Bazel
57+
58+
```bash
59+
# Will NOT build with CUDA, only CPU support
60+
bazel build //:highs
61+
# Will build with CUDA if a CUDA toolchain is detected
62+
bazel build //:highs --//:cupdlp_gpu
63+
```

0 commit comments

Comments
 (0)