Last active
January 25, 2016 16:51
-
-
Save zeryx/1066f6d2a70caa686cb6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void NetworkGenetic::allocateHostAndGPUObjects( size_t deviceRam, size_t hostRam){ | |
long int hostGenSize = hostRam; | |
long int deviceGenSize = deviceRam; | |
std::cerr<<"total free device ram : "<<deviceRam<<std::endl; | |
std::cerr<<"total free host ram : "<<hostRam<<std::endl; | |
//this block below makes sure that the number of objects in stream is exactly half of the total amount of allocatable space on the GPU | |
_streamSize = deviceGenSize/(sizeof(double)*2); | |
while(_streamSize%_hostParams.array[2] || (_streamSize/_hostParams.array[2])&(_streamSize/_hostParams.array[2]-1)) // get the largest number divisible by the individual size, the threads in a block, and the size of a double | |
_streamSize= _streamSize -1; | |
CUDA_SAFE_CALL(cudaHostAlloc((void**)&host_genetics.array, hostGenSize, cudaHostAllocWriteCombined)); | |
CUDA_SAFE_CALL(cudaMalloc((void**) &device_genetics.array, deviceGenSize)); | |
std::fill(host_genetics.array, host_genetics.array+host_genetics.size, 0); | |
CUDA_SAFE_CALL(cudaMemset(device_genetics.array, 0, deviceGenSize)); | |
_stream.resize(_numOfStreams); | |
for(int i=0; i<_numOfStreams; i++){ | |
CUDA_SAFE_CALL(cudaStreamCreate(&_stream.at(i))); | |
CUDA_SAFE_CALL( cudaStreamQuery(_stream.at(i))); | |
} | |
this->confDeviceParams(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment