hughperkins / cltorch

An OpenCL backend for torch.
Other
289 stars 26 forks source link

Add seeding methods #33

Closed hery closed 8 years ago

hery commented 8 years ago

I can try to take that on– looking into where to start. cutorch equivalent:

https://github.com/torch/cutorch/blob/50bfa8da4f08c610a07c2cd00b01edeb73b99b8e/init.c#L757 https://github.com/torch/cutorch/blame/50bfa8da4f08c610a07c2cd00b01edeb73b99b8e/README.md#L24-L25

hughperkins commented 8 years ago

Hmmm.... seeding works already, since random numbers are generated on the cpu. Use like this:

require 'cltorch'
torch.manualSeed(123)
print(torch.ClTensor(3):uniform())
torch.manualSeed(123)
print(torch.ClTensor(3):uniform())

Output:

Using NVIDIA Corporation , OpenCL platform: NVIDIA CUDA
Using OpenCL device: GeForce 940M
 0.6965
 0.7130
 0.2861
[torch.ClTensor of size 3]

 0.6965
 0.7130
 0.2861
[torch.ClTensor of size 3]
hughperkins commented 8 years ago

Note: personally, I'd use like this, marginally faster perhaps:

require 'cltorch'
torch.manualSeed(123)
print(torch.Tensor(3):uniform():cl())

(output is the same)

hery commented 8 years ago

I see. Maybe it was only ported to cutorch for performance? @clementfarabet mentions those functions were ported from cuRAND, and cuRAND's primary benefit seems to be mostly acceleration.

Anyway, thanks for your feedback, I was afraid I'd get concurrency issues with my seeds.

hughperkins commented 8 years ago

Generating random numbers needs a lot of state, and is not trivially parallelizable, since the next number depends on the previous one, so it's not clear to me that generating on the gpu will be a clear win. I also have yet to hit a situation where the random number generation is a clear bottleneck (I mostly deal with convnets). If you are in such a situation, it might make sense to compare the generation speed, eg using cuda on aws, since needs no dev work to test. Depending on results, it might then make sense to implement random number generation on the gpu.

hughperkins commented 8 years ago

Ok to close this for now? You can raise a new issue if/when you decide you want to start implementing random sampling methods on the GPU.