Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: support building with clang on ubuntu #414

Merged
merged 4 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/how_to_use/how_to_build.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,28 @@ export CXX=/usr/bin/g++-10
export GCC_HOST_COMPILER_PATH=/usr/bin/gcc-10
```

### Building with Clang on Ubuntu 22.04

To utilize features like [always_inline](https://releases.llvm.org/15.0.0/tools/clang/docs/AttributeReference.html#always-inline-force-inline),
you'll need clang++ at version 15 or higher. By default, Ubuntu 22.04 installs `clang-14` via `apt install clang`,
so you'll need to manually install a newer version of clang and update `openmp` accordingly.

First, install `clang-15` and the appropriate OpenMP libraries:

```shell
sudo apt install clang-15 libomp5-15 libomp-15-dev
```

Next, update `CC` and `CXX` to point to the newly installed `clang-15` and `clang++-15`:

```shell
export CC=/usr/bin/clang-15
export CXX=/usr/bin/clang++-15
```

Make sure `CC` and `CXX` are properly updated to `clang-15` and `clang++-15`.
These commands ensure that your build environment uses clang version 15 for compilation.

### Build CUDA with rust toolchain

You may run into the following problem:
Expand Down
2 changes: 2 additions & 0 deletions tachyon/base/openmp_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
#endif // defined(TACHYON_HAS_OPENMP)

#if defined(TACHYON_HAS_OPENMP)
#define OPENMP_CONSTEXPR
#define OPENMP_PARALLEL_FOR(expr) _Pragma("omp parallel for") for (expr)
#define OPENMP_PARALLEL_NESTED_FOR(expr) \
_Pragma("omp parallel for collapse(2)") for (expr)
#define OPENMP_FOR(expr) _Pragma("omp for") for (expr)
#else
#define OPENMP_CONSTEXPR constexpr
#define OPENMP_PARALLEL_FOR(expr) for (expr)
#define OPENMP_PARALLEL_NESTED_FOR(expr) for (expr)
#define OPENMP_FOR(expr) for (expr)
Expand Down
4 changes: 2 additions & 2 deletions tachyon/base/threading/platform_thread_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ long sched_setattr(pid_t pid,
#endif // BUILDFLAG(IS_CHROMEOS)

#if !BUILDFLAG(IS_NACL)
/*
TODO(chokobole):
TomTaehoonKim marked this conversation as resolved.
Show resolved Hide resolved
const char kCgroupDirectory[] =
"/sys/fs/cgroup";
ashjeong marked this conversation as resolved.
Show resolved Hide resolved

/*
TODO(chokobole):
FilePath ThreadTypeToCgroupDirectory(const FilePath& cgroup_filepath,
ThreadType thread_type) {
switch (thread_type) {
Expand Down
6 changes: 3 additions & 3 deletions tachyon/math/base/groups.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ class MultiplicativeGroup : public MultiplicativeSemigroup<G> {
// https://github.com/arkworks-rs/algebra/blob/5dfeedf560da6937a5de0a2163b7958bd32cd551/ff/src/fields/mod.rs#L355-L418.
// Batch inverse: [a₁, a₂, ..., aₙ] -> [a₁⁻¹, a₂⁻¹, ... , aₙ⁻¹]
template <typename InputContainer, typename OutputContainer>
[[nodiscard]] constexpr static bool BatchInverse(const InputContainer& groups,
OutputContainer* inverses,
const G& coeff = G::One()) {
[[nodiscard]] OPENMP_CONSTEXPR static bool BatchInverse(
const InputContainer& groups, OutputContainer* inverses,
const G& coeff = G::One()) {
size_t size = std::size(groups);
if (size != std::size(*inverses)) {
LOG(ERROR) << "Size of |groups| and |inverses| do not match";
Expand Down
17 changes: 8 additions & 9 deletions tachyon/math/base/semigroups.h
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,9 @@ class AdditiveSemigroup {
// Multi Scalar Multi Base
template <typename ScalarContainer, typename BaseContainer,
typename OutputContainer>
constexpr static bool MultiScalarMulMSMB(const ScalarContainer& scalars,
const BaseContainer& bases,
OutputContainer* outputs) {
OPENMP_CONSTEXPR static bool MultiScalarMulMSMB(
const ScalarContainer& scalars, const BaseContainer& bases,
OutputContainer* outputs) {
size_t size = scalars.size();
if (size != std::size(bases)) return false;
if (size != std::size(*outputs)) return false;
Expand All @@ -455,9 +455,8 @@ class AdditiveSemigroup {

// Multi Scalar Single Base
template <typename ScalarContainer, typename OutputContainer>
constexpr static bool MultiScalarMulMSSB(const ScalarContainer& scalars,
const G& base,
OutputContainer* outputs) {
OPENMP_CONSTEXPR static bool MultiScalarMulMSSB(
const ScalarContainer& scalars, const G& base, OutputContainer* outputs) {
size_t size = std::size(scalars);
if (size != std::size(*outputs)) return false;
if (size == 0) {
Expand All @@ -472,9 +471,9 @@ class AdditiveSemigroup {

// Single Scalar Multi Base
template <typename Scalar, typename BaseContainer, typename OutputContainer>
constexpr static bool MultiScalarMulSSMB(const Scalar& scalar,
const BaseContainer& bases,
OutputContainer* outputs) {
OPENMP_CONSTEXPR static bool MultiScalarMulSSMB(const Scalar& scalar,
const BaseContainer& bases,
OutputContainer* outputs) {
size_t size = std::size(bases);
if (size != std::size(*outputs)) return false;
if (size == 0) {
Expand Down
2 changes: 1 addition & 1 deletion tachyon/math/elliptic_curves/msm/fixed_base_msm.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class FixedBaseMSM {
std::move(outputs_first), std::move(outputs_last));
}

constexpr void UpdateWindowTable(const Point& base) {
OPENMP_CONSTEXPR void UpdateWindowTable(const Point& base) {
AddResult window_base;
if constexpr (std::is_same_v<AddResult, Point>) {
window_base = base;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class JacobianPoint<
}

template <typename JacobianContainer, typename AffineContainer>
[[nodiscard]] constexpr static bool BatchNormalize(
[[nodiscard]] OPENMP_CONSTEXPR static bool BatchNormalize(
const JacobianContainer& jacobian_points,
AffineContainer* affine_points) {
size_t size = std::size(jacobian_points);
Expand Down
6 changes: 3 additions & 3 deletions tachyon/math/elliptic_curves/short_weierstrass/point_xyzz.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class PointXYZZ<_Curve,
}

template <typename PointXYZZContainer, typename AffineContainer>
[[nodiscard]] constexpr static bool BatchNormalize(
[[nodiscard]] OPENMP_CONSTEXPR static bool BatchNormalize(
const PointXYZZContainer& point_xyzzs, AffineContainer* affine_points) {
size_t size = std::size(point_xyzzs);
if (size != std::size(*affine_points)) {
Expand Down Expand Up @@ -300,8 +300,8 @@ class PointXYZZ<_Curve,
private:
constexpr static void DoAdd(const PointXYZZ& a, const PointXYZZ& b,
PointXYZZ& c);
constexpr static void DoAdd(const PointXYZZ& a, const AffinePoint<Curve>& b,
PointXYZZ& c);
OPENMP_CONSTEXPR static void DoAdd(const PointXYZZ& a,
const AffinePoint<Curve>& b, PointXYZZ& c);
constexpr static void DoDoubleImpl(const PointXYZZ& a, PointXYZZ& b);

BaseField x_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ constexpr CLASS& CLASS::AddInPlace(const AffinePoint<Curve>& other) {

// static
template <typename Curve>
constexpr void CLASS::DoAdd(const PointXYZZ& a, const AffinePoint<Curve>& b,
PointXYZZ& c) {
OPENMP_CONSTEXPR void CLASS::DoAdd(const PointXYZZ& a,
const AffinePoint<Curve>& b, PointXYZZ& c) {
// https://hyperelliptic.org/EFD/g1p/auto-shortw-xyzz.html#addition-madd-2008-s

// P = X2 * ZZ1 - X1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class ProjectivePoint<
}

template <typename ProjectiveContainer, typename AffineContainer>
[[nodiscard]] constexpr static bool BatchNormalize(
[[nodiscard]] OPENMP_CONSTEXPR static bool BatchNormalize(
const ProjectiveContainer& projective_points,
AffineContainer* affine_points) {
size_t size = std::size(projective_points);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class MixedRadixEvaluationDomain
}

// UnivariateEvaluationDomain methods
constexpr void DoIFFT(DensePoly& poly) const override {
OPENMP_CONSTEXPR void DoIFFT(DensePoly& poly) const override {
poly.coefficients_.coefficients_.resize(this->size_, F::Zero());
BestFFT(poly, this->group_gen_inv_);
if (this->offset_.IsOne()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class Radix2EvaluationDomain : public UnivariateEvaluationDomain<F, MaxDegree> {
FFTHelperInPlace(evals);
}

constexpr void InOrderIFFTInPlace(DensePoly& poly) const {
OPENMP_CONSTEXPR void InOrderIFFTInPlace(DensePoly& poly) const {
IFFTHelperInPlace(poly);
if (this->offset_.IsOne()) {
// clang-format off
Expand Down Expand Up @@ -179,8 +179,9 @@ class Radix2EvaluationDomain : public UnivariateEvaluationDomain<F, MaxDegree> {
}

template <FFTOrder Order, typename PolyOrEvals>
constexpr static void ApplyButterfly(PolyOrEvals& poly_or_evals,
absl::Span<const F> roots, size_t gap) {
OPENMP_CONSTEXPR static void ApplyButterfly(PolyOrEvals& poly_or_evals,
absl::Span<const F> roots,
size_t gap) {
void (*fn)(F&, F&, const F&);

if constexpr (Order == FFTOrder::kInOut) {
Expand Down Expand Up @@ -218,7 +219,7 @@ class Radix2EvaluationDomain : public UnivariateEvaluationDomain<F, MaxDegree> {
// [1],
// ]
// clang-format on
constexpr void PrepareRootsVecCache() {
OPENMP_CONSTEXPR void PrepareRootsVecCache() {
if (this->log_size_of_group_ == 0) return;

roots_vec_.resize(this->log_size_of_group_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class UnivariateDenseCoefficients {
// multiplying either set of coefficients by a specified random field |r|,
// and summing them together.
template <bool MulRandomWithEvens>
constexpr UnivariateDenseCoefficients Fold(const Field& r) const {
OPENMP_CONSTEXPR UnivariateDenseCoefficients Fold(const Field& r) const {
size_t size = coefficients_.size();
std::vector<F> coefficients((size + 1) >> 1);
OPENMP_PARALLEL_FOR(size_t i = 0; i < size; i += 2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ class UnivariateEvaluationDomain : public EvaluationDomain<F, MaxDegree> {
protected:
// Multiply the i-th element of |poly_or_evals| with |c|*|g|ⁱ.
template <typename PolyOrEvals>
constexpr static void DistributePowersAndMulByConst(
OPENMP_CONSTEXPR static void DistributePowersAndMulByConst(
PolyOrEvals& poly_or_evals, const F& g, const F& c) {
#if defined(TACHYON_HAS_OPENMP)
size_t thread_nums = static_cast<size_t>(omp_get_max_threads());
Expand Down Expand Up @@ -462,8 +462,8 @@ class UnivariateEvaluationDomain : public EvaluationDomain<F, MaxDegree> {
}

template <typename PolyOrEvals>
constexpr static void SwapElements(PolyOrEvals& poly_or_evals, size_t size,
uint32_t log_len) {
OPENMP_CONSTEXPR static void SwapElements(PolyOrEvals& poly_or_evals,
size_t size, uint32_t log_len) {
OPENMP_PARALLEL_FOR(size_t idx = 1; idx < size; ++idx) {
size_t ridx = base::bits::BitRev(idx) >> (sizeof(size_t) * 8 - log_len);
if (idx < ridx) {
Expand Down
6 changes: 3 additions & 3 deletions vendors/halo2/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
load("@crate_index//:defs.bzl", "aliases", "all_crate_deps")
load("@cxx.rs//tools/bazel:rust_cxx_bridge.bzl", "rust_cxx_bridge")
load("@local_config_cuda//cuda:build_defs.bzl", "if_cuda")
load("//bazel:tachyon.bzl", "if_gpu_is_configured", "if_has_openmp")
load("//bazel:tachyon_cc.bzl", "tachyon_cc_library")
load("//bazel:tachyon.bzl", "if_gpu_is_configured")
load("//bazel:tachyon_cc.bzl", "tachyon_cc_library", "tachyon_openmp_linkopts")
load("//bazel:tachyon_rust.bzl", "tachyon_rust_library", "tachyon_rust_test")

FEATURES = if_gpu_is_configured(["gpu"])
Expand Down Expand Up @@ -37,7 +37,7 @@ tachyon_rust_library(
# rustc_flags = if_has_openmp(["-lgomp"]),
cc_library(
name = "openmp",
linkopts = if_has_openmp(["-fopenmp"]),
linkopts = tachyon_openmp_linkopts(),
)

tachyon_rust_test(
Expand Down
Loading