This is an archive of the discontinued LLVM Phabricator instance.

[test-suite] Fix clang build failure due to uniform_real_distribution in SLPVectorization
ClosedPublic

Authored by jsji on Jul 30 2021, 5:07 PM.

Details

Summary

The newly added file will cause build failure with clang.

test-suite/MicroBenchmarks/SLPVectorization/Versioning.cpp:10:37:
required from ‘void init_data(T*, unsigned int) [with T = int]’
test-suite/MicroBenchmarks/SLPVectorization/Versioning.cpp:28:12:
required from ‘void benchmark_xor_runtime_checks_pass(benchmark::State&)
[with unsigned int N = 4; T = int]’
test-suite/MicroBenchmarks/SLPVectorization/Versioning.cpp:70:1:
required from here
/usr/include/c++/7/bits/random.h:1704:7: error: static assertion failed:
result_type must be a floating point type

static_assert(std::is_floating_point<_RealType>::value,

Diff Detail

Repository
rT test-suite

Event Timeline

jsji requested review of this revision.Jul 30 2021, 5:07 PM
jsji created this revision.
jsji retitled this revision from Fix clang build failure due to uniform_real_distribution to [test-suite] Fix clang build failure due to uniform_real_distribution in SLPVectorization.Jul 30 2021, 5:07 PM
jsji added a comment.EditedJul 30 2021, 5:12 PM

This is breaking our internal buildbot.

Did you consider just casting the range to the desired type?

template <typename T> static void init_data(T *A, unsigned N) {
  std::uniform_real_distribution<T> dist((T)-100, (T)100);
  std::mt19937 rng(12345);
  for (unsigned i = 0; i < N; i++)
    A[i] = dist(rng);
}
jsji added a comment.EditedJul 30 2021, 6:46 PM

Did you consider just casting the range to the desired type?

template <typename T> static void init_data(T *A, unsigned N) {
  std::uniform_real_distribution<T> dist((T)-100, (T)100);
  std::mt19937 rng(12345);
  for (unsigned i = 0; i < N; i++)
    A[i] = dist(rng);
}

the problem is uniform_real_distribution require floating result_type ,
it will assert when T is int, so casting won't fix the problem.

jsji added a comment.Jul 30 2021, 7:21 PM

Casting the result is OK for me, if that is better for you.

template <typename T> static void init_data(T *A, unsigned N) {
  std::uniform_real_distribution<> dist(-100, 100);
  std::mt19937 rng(12345);
  for (unsigned i = 0; i < N; i++)
    A[i] = (T)dist(rng);
}
jsji updated this revision to Diff 363253.Jul 30 2021, 7:23 PM

Casting the result of distribution only.

jsji edited the summary of this revision. (Show Details)Jul 30 2021, 7:24 PM

LGTM; thanks!

MicroBenchmarks/SLPVectorization/Versioning.cpp
13

I think this is fine for the purposes of this benchmark (this doesn't need to be fully generic, e.g., for long double). Could alternatively go with explicitly using uniform_real_distribution<double> for double and uniform_int_distribution<int> for int.

This revision is now accepted and ready to land.Jul 31 2021, 8:31 AM
jsji added inline comments.Jul 31 2021, 8:51 AM
MicroBenchmarks/SLPVectorization/Versioning.cpp
13

:), that was my 1st version, but anyway, committing this version first.