Commit 9b9910e9 authored by Uldis Locans's avatar Uldis Locans

add seed to random number initialization

parent 244ad0b2
......@@ -48,14 +48,15 @@ CudaBase::~CudaBase() {
/*
create curandStates
*/
int CudaBase::cuda_createCurandStates(int size) {
int CudaBase::cuda_createCurandStates(int size, int seed) {
if (defaultRndSet == 1)
cuda_deleteCurandStates();
int threads = 128;
int blocks = size / threads + 1;
int seed = time(NULL);
if (seed == -1)
seed = time(NULL);
//std::cout << "sizeof: " << sizeof(curandState) << std::endl;
cudaMalloc(&defaultRndState, sizeof(curandState)*size);
......
......@@ -41,9 +41,10 @@ public:
* Init cuda random number (cuRand) states.
* Create an array of type curandState with "size" elements on the GPU
* 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
*/
int cuda_createCurandStates(int size);
int cuda_createCurandStates(int size, int seed = -1);
/**
* Delete curandState.
......
......@@ -127,17 +127,14 @@ DKSBase::DKSBase(const char* api_name, const char* device_name) {
#ifdef DKS_CUDA
cbase = new CudaBase();
cchi = new CudaChiSquare(cbase);
#endif
#ifdef DKS_OPENCL
oclbase = new OpenCLBase();
oclchi = new OpenCLChiSquare(oclbase);
#endif
#ifdef DKS_MIC
micbase = new MICBase();
miccol = new MICCollimatorPhysics(micbase);
#endif
}
......@@ -155,18 +152,15 @@ DKSBase::~DKSBase() {
delete[] m_function_name;
#ifdef DKS_CUDA
delete cchi;
delete cbase;
#endif
#ifdef DKS_OPENCL
delete oclchi;
delete oclbase;
#endif
#ifdef DKS_MIC
delete micchi;
delete micbase;
#endif
......@@ -446,9 +440,9 @@ int DKSBase::callCreateRandomNumbers(void *mem_ptr, int size) {
return DKS_ERROR;
}
int DKSBase::callInitRandoms(int size) {
int DKSBase::callInitRandoms(int size, int seed) {
if (apiCuda())
return CUDA_SAFECALL(cbase->cuda_createCurandStates(size));
return CUDA_SAFECALL(cbase->cuda_createCurandStates(size, seed));
else if (apiOpenCL())
return OPENCL_SAFECALL(oclbase->ocl_createRndStates(size));
else if (apiOpenMP())
......
......@@ -29,36 +29,17 @@
#endif
#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
#ifdef DKS_CUDA
#include "CUDA/CudaBase.cuh"
#include "CUDA/CudaFFT.cuh"
#include "CUDA/CudaGreensFunction.cuh"
#include "CUDA/CudaChiSquare.cuh"
#include "CUDA/CudaCollimatorPhysics.cuh"
#include "nvToolsExt.h"
#endif
#ifdef DKS_MIC
#include "MIC/MICBase.h"
#include "MIC/MICChiSquare.h"
#include "MIC/MICFFT.h"
#include "MIC/MICCollimatorPhysics.h"
#include "MIC/MICGreensFunction.hpp"
#endif
#include "Algorithms/GreensFunction.h"
#include "Algorithms/CollimatorPhysics.h"
#include "Algorithms/FFT.h"
#include "AutoTuning/DKSConfig.h"
/** DKSBase class for handling function calls to DKS library */
......@@ -78,17 +59,14 @@ private:
#ifdef DKS_OPENCL
OpenCLBase *oclbase;
OpenCLChiSquare *oclchi;
#endif
#ifdef DKS_CUDA
CudaBase *cbase;
CudaChiSquare *cchi;
#endif
#ifdef DKS_MIC
MICBase *micbase;
MICChiSquare *micchi;
#endif
protected:
......@@ -901,9 +879,10 @@ public:
/**
* 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.
*/
int callInitRandoms(int size);
int callInitRandoms(int size, int seed = -1);
/**
* Print memory information on device (total, used, available)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment