Generate random integers with uniform_int_distribution #677
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #688.
Random integer generation in
load_random_data
has a lot of bugs:float(uint64_t(2) << (type.size * 8))
performs a left shift by 64 bits when the type size is 8, and this results in Undefined Behaviour. On my system, the only generateduint64_t
values are 0, 1, and 18446744073709551615.float(uint64_t(2) << (type.size * 8))
calculation is also incorrect (twice as large as it should be) when the type size is smaller than 8, resulting in Undefined Behaviour when floating-point random values are cast to integers.int32_t
anduint32_t
values are multiples of 256.uint16_t
values are 0, 1, 2, 3, 4, 5, 6, 7, 65529, 65530, 65531, 65532, 65533, 65534, and 65535.Here I've fixed all these problems by replacing
std::uniform_real_distribution
withstd::uniform_int_distribution
.I had to keep
int16_t
generation in the range -7 .. +7, because various kernels added in #77 fail otherwise (due to differing integer overflow between implementations).In a separate commit, I also fixed the compiler warnings in qa_utils.cc:
icompare
, which I accidentally introduced in Fix undefined behaviour in dot product kernels #655