add seed to random number initialization
This commit is contained in:
@ -48,14 +48,15 @@ CudaBase::~CudaBase() {
|
|||||||
/*
|
/*
|
||||||
create curandStates
|
create curandStates
|
||||||
*/
|
*/
|
||||||
int CudaBase::cuda_createCurandStates(int size) {
|
int CudaBase::cuda_createCurandStates(int size, int seed) {
|
||||||
|
|
||||||
if (defaultRndSet == 1)
|
if (defaultRndSet == 1)
|
||||||
cuda_deleteCurandStates();
|
cuda_deleteCurandStates();
|
||||||
|
|
||||||
int threads = 128;
|
int threads = 128;
|
||||||
int blocks = size / threads + 1;
|
int blocks = size / threads + 1;
|
||||||
int seed = time(NULL);
|
if (seed == -1)
|
||||||
|
seed = time(NULL);
|
||||||
|
|
||||||
//std::cout << "sizeof: " << sizeof(curandState) << std::endl;
|
//std::cout << "sizeof: " << sizeof(curandState) << std::endl;
|
||||||
cudaMalloc(&defaultRndState, sizeof(curandState)*size);
|
cudaMalloc(&defaultRndState, sizeof(curandState)*size);
|
||||||
|
@ -41,9 +41,10 @@ public:
|
|||||||
* Init cuda random number (cuRand) states.
|
* Init cuda random number (cuRand) states.
|
||||||
* Create an array of type curandState with "size" elements on the GPU
|
* Create an array of type curandState with "size" elements on the GPU
|
||||||
* and create a curandState with different seed for each array entry.
|
* and create a curandState with different seed for each array entry.
|
||||||
|
* If no seed is given create a seed based on current time.
|
||||||
* Return success or error code
|
* Return success or error code
|
||||||
*/
|
*/
|
||||||
int cuda_createCurandStates(int size);
|
int cuda_createCurandStates(int size, int seed = -1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete curandState.
|
* Delete curandState.
|
||||||
|
@ -127,17 +127,14 @@ DKSBase::DKSBase(const char* api_name, const char* device_name) {
|
|||||||
|
|
||||||
#ifdef DKS_CUDA
|
#ifdef DKS_CUDA
|
||||||
cbase = new CudaBase();
|
cbase = new CudaBase();
|
||||||
cchi = new CudaChiSquare(cbase);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DKS_OPENCL
|
#ifdef DKS_OPENCL
|
||||||
oclbase = new OpenCLBase();
|
oclbase = new OpenCLBase();
|
||||||
oclchi = new OpenCLChiSquare(oclbase);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DKS_MIC
|
#ifdef DKS_MIC
|
||||||
micbase = new MICBase();
|
micbase = new MICBase();
|
||||||
miccol = new MICCollimatorPhysics(micbase);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -155,18 +152,15 @@ DKSBase::~DKSBase() {
|
|||||||
delete[] m_function_name;
|
delete[] m_function_name;
|
||||||
|
|
||||||
#ifdef DKS_CUDA
|
#ifdef DKS_CUDA
|
||||||
delete cchi;
|
|
||||||
delete cbase;
|
delete cbase;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DKS_OPENCL
|
#ifdef DKS_OPENCL
|
||||||
delete oclchi;
|
|
||||||
delete oclbase;
|
delete oclbase;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef DKS_MIC
|
#ifdef DKS_MIC
|
||||||
delete micchi;
|
|
||||||
delete micbase;
|
delete micbase;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -446,9 +440,9 @@ int DKSBase::callCreateRandomNumbers(void *mem_ptr, int size) {
|
|||||||
return DKS_ERROR;
|
return DKS_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DKSBase::callInitRandoms(int size) {
|
int DKSBase::callInitRandoms(int size, int seed) {
|
||||||
if (apiCuda())
|
if (apiCuda())
|
||||||
return CUDA_SAFECALL(cbase->cuda_createCurandStates(size));
|
return CUDA_SAFECALL(cbase->cuda_createCurandStates(size, seed));
|
||||||
else if (apiOpenCL())
|
else if (apiOpenCL())
|
||||||
return OPENCL_SAFECALL(oclbase->ocl_createRndStates(size));
|
return OPENCL_SAFECALL(oclbase->ocl_createRndStates(size));
|
||||||
else if (apiOpenMP())
|
else if (apiOpenMP())
|
||||||
|
@ -29,36 +29,17 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "OpenCL/OpenCLBase.h"
|
#include "OpenCL/OpenCLBase.h"
|
||||||
#include "OpenCL/OpenCLChiSquare.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef DKS_AMD
|
|
||||||
#include "OpenCL/OpenCLFFT.h"
|
|
||||||
#include "OpenCL/OpenCLCollimatorPhysics.h"
|
|
||||||
#include "OpenCL/OpenCLGreensFunction.h"
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DKS_CUDA
|
#ifdef DKS_CUDA
|
||||||
#include "CUDA/CudaBase.cuh"
|
#include "CUDA/CudaBase.cuh"
|
||||||
#include "CUDA/CudaFFT.cuh"
|
|
||||||
#include "CUDA/CudaGreensFunction.cuh"
|
|
||||||
#include "CUDA/CudaChiSquare.cuh"
|
|
||||||
#include "CUDA/CudaCollimatorPhysics.cuh"
|
|
||||||
#include "nvToolsExt.h"
|
#include "nvToolsExt.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DKS_MIC
|
#ifdef DKS_MIC
|
||||||
#include "MIC/MICBase.h"
|
#include "MIC/MICBase.h"
|
||||||
#include "MIC/MICChiSquare.h"
|
|
||||||
#include "MIC/MICFFT.h"
|
|
||||||
#include "MIC/MICCollimatorPhysics.h"
|
|
||||||
#include "MIC/MICGreensFunction.hpp"
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "Algorithms/GreensFunction.h"
|
|
||||||
#include "Algorithms/CollimatorPhysics.h"
|
|
||||||
#include "Algorithms/FFT.h"
|
|
||||||
|
|
||||||
#include "AutoTuning/DKSConfig.h"
|
#include "AutoTuning/DKSConfig.h"
|
||||||
|
|
||||||
/** DKSBase class for handling function calls to DKS library */
|
/** DKSBase class for handling function calls to DKS library */
|
||||||
@ -78,17 +59,14 @@ private:
|
|||||||
|
|
||||||
#ifdef DKS_OPENCL
|
#ifdef DKS_OPENCL
|
||||||
OpenCLBase *oclbase;
|
OpenCLBase *oclbase;
|
||||||
OpenCLChiSquare *oclchi;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DKS_CUDA
|
#ifdef DKS_CUDA
|
||||||
CudaBase *cbase;
|
CudaBase *cbase;
|
||||||
CudaChiSquare *cchi;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DKS_MIC
|
#ifdef DKS_MIC
|
||||||
MICBase *micbase;
|
MICBase *micbase;
|
||||||
MICChiSquare *micchi;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -901,9 +879,10 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Init random number states and save for reuse on device.
|
* Init random number states and save for reuse on device.
|
||||||
|
* If seed is -1, a random seed based on current time is taken.
|
||||||
* TODO: opencl and mic implementations.
|
* TODO: opencl and mic implementations.
|
||||||
*/
|
*/
|
||||||
int callInitRandoms(int size);
|
int callInitRandoms(int size, int seed = -1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print memory information on device (total, used, available)
|
* Print memory information on device (total, used, available)
|
||||||
|
Reference in New Issue
Block a user