Skip to content

Commit

Permalink
Merge pull request #45 from dominikgrewe/random_seed
Browse files Browse the repository at this point in the history
Initialize random seed during CUDA initialization.
  • Loading branch information
soumith committed Sep 25, 2014
2 parents c709fe3 + a8e5dc7 commit ced765b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
1 change: 0 additions & 1 deletion init.c
Expand Up @@ -39,7 +39,6 @@ static int cutorch_setDevice(lua_State *L)
{
int device = (int)luaL_checknumber(L, 1)-1;
THCudaCheck(cudaSetDevice(device));
THCRandom_manualSeed(THCRandom_initialSeed());
return 0;
}

Expand Down
31 changes: 15 additions & 16 deletions lib/THC/THCGeneral.c
@@ -1,5 +1,6 @@
#include "THCGeneral.h"
#include "TH.h"
#include "THCTensorRandom.h"

void THCudaInit(void)
{
Expand All @@ -9,28 +10,26 @@ void THCudaInit(void)
int count = 0;
THCudaCheck(cudaGetDeviceCount(&count));

if(count>1)
{
int device = 0;
THCudaCheck(cudaGetDevice(&device));
int device = 0;
THCudaCheck(cudaGetDevice(&device));

int i,j;
for(i=0; i < count; ++i)
int i,j;
for(i=0; i < count; ++i)
{
THCudaCheck(cudaSetDevice(i));
THCRandom_manualSeed(THCRandom_initialSeed());
for (j=0; j < count; ++j)
{
THCudaCheck(cudaSetDevice(i));
for (j=0; j < count; ++j)
if(i != j)
{
if(i != j)
{
int can = 0;
THCudaCheck(cudaDeviceCanAccessPeer(&can, i, j));
if(can)
THCudaCheck(cudaDeviceEnablePeerAccess(j, 0));
}
int can = 0;
THCudaCheck(cudaDeviceCanAccessPeer(&can, i, j));
if(can)
THCudaCheck(cudaDeviceEnablePeerAccess(j, 0));
}
}
THCudaCheck(cudaSetDevice(device));
}
THCudaCheck(cudaSetDevice(device));
}

void THCudaShutdown(void)
Expand Down

0 comments on commit ced765b

Please sign in to comment.