Skip to content

Commit

Permalink
build: switch to clang (PROOF-620) (#13)
Browse files Browse the repository at this point in the history
* ci: replace gcc with clang in build env setup ( PROOF-633 )

* ci: undo gcc compiler option removal ( PROOF-633 )

* ci: update the Docker image tag ( PROOF-638 )

* bump bazel version

* port base package

* migrate base

* migrate memory

* port cbindings

* get cbindings building

* fix linking

* make linking portable

* port benchmarks

* migrate examples

* fix format

* drop legacy cuda rules

* fix gpu image

* clean up build

* rename

* clean up bazel rules

* clean up bazel options

* undo

* clean up

* clean up

* clean up

* clean up

* clean up

* fix

---------

Co-authored-by: Jacob Trombetta <[email protected]>
  • Loading branch information
rnburn and jacobtrombetta authored Sep 14, 2023
1 parent 66cfb31 commit c203823
Show file tree
Hide file tree
Showing 125 changed files with 253 additions and 8,065 deletions.
50 changes: 24 additions & 26 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
build --cxxopt -std=c++20
build --config=cuda
build --experimental_cc_implementation_deps

build --copt -fPIC

build:portable_glibc --copt -fPIC
build:portable_glibc --define SXT_PORTABLE_GLIBC=1
build:portable_glibc --action_env=BAZEL_LINKLIBS='-l%:libstdc++.a'
build:portable_glibc --action_env=BAZEL_LINKOPTS='-static-libstdc++ -static-libgcc'

build --flag_alias=enable_cuda=@rules_cuda//cuda:enable
build --flag_alias=cuda_archs=@rules_cuda//cuda:archs
build --flag_alias=cuda_compiler=@rules_cuda//cuda:compiler
build --flag_alias=cuda_copts=@rules_cuda//cuda:copts
build --flag_alias=cuda_host_copts=@rules_cuda//cuda:host_copts
build --flag_alias=cuda_runtime=@rules_cuda//cuda:runtime

build --@rules_cuda//cuda:archs=compute_70:compute_70,sm_70
build --@rules_cuda//cuda:runtime=@local_cuda//:cuda_runtime_static

build --enable_cuda=True

# Use --config=clang to build with clang instead of gcc and nvcc.
build:clang --repo_env=CC=clang
build:clang --@rules_cuda//cuda:compiler=clang
build:clang --copt=-stdlib=libstdc++
build:clang --action_env CC=/usr/bin/clang-18
build:clang --action_env CXX=/usr/bin/clang++-18
build --config=clang


build:asan --copt -fsanitize=address
build:asan --linkopt -fsanitize=address
Expand All @@ -22,35 +42,13 @@ build:asan --workspace_status_command=./ci/lsan_hack.sh
run:asan --action_env=LSAN_OPTIONS=suppressions=/tmp/sxt-blitzar-lsan.supp
test:asan --action_env=LSAN_OPTIONS=suppressions=/tmp/sxt-blitzar-lsan.supp

build:cuda --crosstool_top=@local_config_cuda//crosstool:toolchain
build:cuda --define=using_cuda=true --define=using_cuda_nvcc=true --define=using_cuda_clang=false

build:cuda_clang --crosstool_top=@local_config_cuda//crosstool:toolchain
build:cuda_clang --define=using_cuda=true --define=using_cuda_clang=true

build:win-cuda --define=using_cuda=true --define=using_cuda_nvcc=true

build:opt --cxxopt=-march=native --copt=-march=native
build --action_env TF_NEED_CUDA="1"
build --action_env TF_NEED_OPENCL="1"
build --action_env TF_CUDA_CLANG="0"
build --action_env HOST_CXX_COMPILER="/usr/bin/gcc"
build --action_env HOST_C_COMPILER="/usr/bin/gcc"
build --action_env GCC_HOST_COMPILER_PATH="/usr/bin/gcc"

build --action_env CUDA_TOOLKIT_PATH="/usr/local/cuda"
build --action_env PYTHON_BIN_PATH="/usr/bin/python3"
build --action_env TF_CUDA_VERSION="12.2"
build --action_env TF_CUDA_COMPUTE_CAPABILITIES="7.0"
build --action_env COMPUTECPP_TOOLKIT_PATH="/usr/local/computecpp"
build --action_env TMP="/tmp"

# For machines with many cpu cores available, we could not compile
# the code. Many times (not always) the following error was launched:
# `ptxas /tmp/tmpfxt_00000017_00000000-0, line 1; fatal : Missing .version...`
# See https://github.com/bazelbuild/bazel/issues/14410#issuecomment-997843606
# for more information.
# To fix the problem, we added the following line:
build --sandbox_add_mount_pair=.:/tmp
build --spawn_strategy local

test --test_output=errors
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.2.1
6.3.2
21 changes: 12 additions & 9 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@ http_archive(
],
)

local_repository(
name = "build_bazel_rules_cuda",
path = "third_party/rules_cuda",
)

load("@build_bazel_rules_cuda//gpus:cuda_configure.bzl", "cuda_configure")

cuda_configure(name = "local_config_cuda")

git_repository(
name = "com_github_catchorg_catch2",
commit = "6f21a3609cea360846a0ca93be55877cca14c86d",
remote = "https://github.com/catchorg/Catch2",
)

git_repository(
name = "rules_cuda",
commit = "22a46e6",
remote = "https://github.com/bazel-contrib/rules_cuda",
)

load("@rules_cuda//cuda:repositories.bzl", "register_detected_cuda_toolchains", "rules_cuda_dependencies")

rules_cuda_dependencies()

register_detected_cuda_toolchains()
7 changes: 6 additions & 1 deletion bazel/sxt_benchmark.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
load(
"//bazel:sxt_build_system.bzl",
"sxt_cc_binary",
)

# Taken from https://github.com/bazelbuild/bazel/issues/2670#issuecomment-369674735
# with modifications.
def sxt_private_include_copts(includes, is_system = False):
Expand Down Expand Up @@ -76,7 +81,7 @@ def sxt_cc_benchmark(
cmd_bash = "$(location //tools/benchmark:bench_profile) callgrind $$PWD/$(location :%s) $@" % name,
)

native.cc_binary(
sxt_cc_binary(
name = name,
srcs = srcs,
copts = copts + sxt_copts() + select({
Expand Down
103 changes: 103 additions & 0 deletions bazel/sxt_build_system.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
load("@rules_cuda//cuda:defs.bzl", "cuda_library", "cuda_objects")

# We add this -std=c++20 flag, because
# benchmarks could not be compiled without it.
# The `build --cxxopt -std=c++20` flag set in the
# `.bazelrc` file was not passed to the compiler.
# However, this flag is relevant to some modules.
def sxt_copts():
return [
"-std=c++20",
"-Wno-unknown-cuda-version",
]

def sxt_cc_component(
name,
copts = [],
is_cuda = False,
with_test = True,
alwayslink = False,
test_deps = [],
deps = [],
impl_deps = [],
**kwargs):
cuda_objects(
name = name,
hdrs = [
name + ".h",
],
srcs = [
name + ".cc",
],
copts = sxt_copts(),
deps = deps + impl_deps + [
"@local_cuda//:cuda_runtime_static",
],
visibility = ["//visibility:public"],
**kwargs
)
if with_test:
test_lib = name + ".t-lib"
deps_p = [
":" + name,
] + deps + test_deps
cuda_library(
name = test_lib,
copts = sxt_copts(),
deps = [
":" + name,
] + test_deps,
srcs = [
name + ".t.cc",
],
rdc = True,
)
native.cc_test(
name = name + ".t",
copts = sxt_copts() + copts,
deps = [
":" + test_lib,
] + test_deps + [
"@com_github_catchorg_catch2//:catch2",
"@com_github_catchorg_catch2//:catch2_main",
],
visibility = ["//visibility:public"],
**kwargs
)

def sxt_cc_library(
name,
copts = [],
deps = [],
impl_deps = [],
**kwargs):
cuda_objects(
name = name,
copts = sxt_copts(),
deps = deps + impl_deps,
visibility = ["//visibility:public"],
**kwargs
)

def sxt_cc_binary(
name,
srcs = [],
copts = [],
deps = [],
**kwargs):
libname = name + "-lib"
cuda_library(
name = libname,
srcs = srcs,
copts = sxt_copts() + copts,
deps = deps,
rdc = True,
**kwargs
)
native.cc_binary(
name = name,
deps = [
":" + libname,
] + deps,
**kwargs
)
105 changes: 0 additions & 105 deletions bazel/sxt_component.bzl

This file was deleted.

6 changes: 1 addition & 5 deletions benchmark/inner_product_proof/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load(
"//bazel:sxt_component.bzl",
"//bazel:sxt_build_system.bzl",
"sxt_cc_component",
)
load("//bazel:sxt_benchmark.bzl", "sxt_cc_benchmark")
Expand All @@ -23,10 +23,6 @@ sxt_cc_benchmark(
srcs = [
"benchmark.m.cc",
],
linkopts = [
"-x",
"cuda",
],
visibility = ["//visibility:public"],
deps = [
":params",
Expand Down
4 changes: 0 additions & 4 deletions benchmark/multi_commitment/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ sxt_cc_benchmark(
srcs = [
"benchmark.m.cc",
],
linkopts = [
"-x",
"cuda",
],
visibility = ["//visibility:public"],
deps = [
"//sxt/base/container:span",
Expand Down
Loading

0 comments on commit c203823

Please sign in to comment.