THCState* THCState_alloc(void)
{
- THCState* state = (THCState*) malloc(sizeof(THCState));
- memset(state, 0, sizeof(THCState));
+ THCState* state = (THCState*) calloc(1, sizeof(THCState));
return state;
}
THCudaCheck(cudaGetDevice(&device));
state->resourcesPerDevice = (THCCudaResourcesPerDevice*)
- malloc(numDevices * sizeof(THCCudaResourcesPerDevice));
- memset(state->resourcesPerDevice, 0, numDevices * sizeof(THCCudaResourcesPerDevice));
+ calloc(numDevices, sizeof(THCCudaResourcesPerDevice));
state->deviceProperties =
(struct cudaDeviceProp*)malloc(numDevices * sizeof(struct cudaDeviceProp));
// "-1" (unknown).
// Currently the max number of gpus in P2P group is 8, so if there are more
// we enable P2P in groups of 8
- state->p2pAccessEnabled = (int**) malloc(sizeof(int*) * numDevices);
+ state->p2pAccessEnabled = (int**) calloc(numDevices, sizeof(int*));
for (int i = 0; i < numDevices; ++i) {
- state->p2pAccessEnabled[i] = (int*) malloc(sizeof(int) * numDevices);
+ state->p2pAccessEnabled[i] = (int*) calloc(numDevices, sizeof(int));
for (int j = 0; j < numDevices; ++j)
if (i == j)
state->p2pAccessEnabled[i][j] = 1;
- else if (j / THC_CUDA_MAX_PEER_SIZE != i / THC_CUDA_MAX_PEER_SIZE)
- state->p2pAccessEnabled[i][j] = 0;
else
state->p2pAccessEnabled[i][j] = -1;
}