Skip to content

af::randn creates duplicates with CUDA backend [BUG] #2972

@willat343

Description

@willat343

When creating large af::arrays with af::randn, the resulting sequence is not a truly random sequence, but in fact contains at least 2 of every number for large arrays.

Description

  • I originally became aware of the issue because I was listening to sequence, expected white noise however it had a distinct "harsh" audio quality compared to af::randu and using my workaround, this quality disappeared. Testing with an array of length 32768, I found that not a single number in the sequence was present an odd number of times, but some multiple of 2. I was able to verify this with a very small bin histogram plot of the data. I'm using the CUDA backend with a 2080.
  • My theory: The CUDA backend generates this sequence by creating blocks of normally distributed random numbers in many threads and then recombines the data together, BUT each of these threads appears to be initiated with the same seed, and therefore the random sequences in the threads are the same. Possible then a fix is to set different seeds in each thread.
  • I originally produced this error on 3.6.2 but then confirmed the issue is indeed still present in 3.7.2.
  • I used the official installers to install arrayfire.
  • I have reproduced this error using all three Random Engines; PHILOX, MERSENNE and THREEFLY.
  • As a workaround, I am creating many blocks of size 128 and using af::join to combine them, with each block having a different random seed. This is obviously slow (by ~100 times on my machine).
  • I have comfirmed that af::randu does not seem to suffer the same issue.
  • This is very reproducible - it always occurs.
  • I've put a screenshot below. Top left is the raw signal with a moving average in yellow. Top right is a fft done in matlab which seems somewhat suspicous. Bottom left is the clincher - histogram with tiny tiny bin width showing that each number occurs in a multiple of 2 (possibly pairs)

arrayfire-randn-32768-points

Reproducible Code and/or Steps

  • af::array my_array = af::randn(32768, f32);
  • Plot a histogram (e.g. with small bin size) to see even number in every bin.

System Information

  • 3.7.2 and 3.6.2 tested
  • Output of nvidia-smi --query-gpu="name,memory.total,driver_version" --format=csv -i 0: name, memory.total [MiB], driver_version GeForce RTX 2080 SUPER, 7981 MiB, 440.100

Checklist

  • [x ] Using the latest available ArrayFire release
  • [x ] GPU drivers are up to date

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions