0

When I run the random module in succession it gives me the same results. Any way I can fix this? The documentation on Alea is really sparse in some places.

let cudaRandom = XorShift7.CUDA.DefaultUniformRandomModuleF32.Default.Create(1,1,uint32 DateTime.Now.Millisecond) :> IRandom<float32>
let createRandomUniformMatrix weights_num_rows weights_num_cols (scaling_factor : float32) location =
    let weights_total_size = weights_num_rows*weights_num_cols

    let cudaBuffer = cudaRandom.AllocCUDAStreamBuffer weights_total_size
    cudaRandom.Fill(0,weights_total_size,cudaBuffer,scaling_factor,location*scaling_factor/2.0f)

    {num_rows = weights_num_rows; num_cols = weights_num_cols; dArray = cudaBuffer}

let weights = createRandomUniformMatrix 1 4 1.0f 0.0f
let bias = createRandomUniformMatrix 1 4 1.0f 0.0f

let t1 = bias.dArray.Gather()
let t2 = weights.dArray.Gather()

printfn "%A" t1
printfn "%A" t2
//val t1 : float32 [] = [|0.680722952f; 0.597810984f; 0.318799376f; 0.726549625f|]
//val t2 : float32 [] = [|0.680722952f; 0.597810984f; 0.318799376f; 0.726549625f|]
Marko Grdinić
  • 3,798
  • 3
  • 18
  • 21
  • actually, you are generating random number with same seed and same stream id, and it should be same. Alea GPU's random module is designed follow the SPRNG library (http://www.sprng.org/). – Xiang Zhang Aug 19 '15 at 03:21
  • Thanks. I never head about the SPRNG library before. Also, this would be a good time to ask just how expensive are these streams in terms of memory and computation? – Marko Grdinić Aug 19 '15 at 13:37
  • the idea is, say you want 1M random numbers, and you don't want create GPU memory for 1M numbers. So one solution could be, you use 2 streams: `let rng = RandomModule.Create(streams=2, seed=time)`, then `rng.AllocCUDAStreamBuffer` will allocate memory fo 0.5M numbers. Then you `rng.Fill(streamId=0, buffer)`. It will fill the buffer with the first 0.5M numbers. set streamId=1 fills the next 0.5M numbers. So in this filling operation, no new GPU memory is allocated, you just fill it. – Xiang Zhang Aug 20 '15 at 02:22

0 Answers0