Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/cuda/rodinia/3.1/cuda/dwt2d/main.cu
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,12 @@ int main(int argc, char **argv)
d->dwtLvls = dwtLvls;

// file names
d->srcFilename = (char *)malloc(strlen(argv[0]));
// need +1 for \0
d->srcFilename = (char *)malloc(strlen(argv[0]) + 1);
strcpy(d->srcFilename, argv[0]);
if (argc == 1) { // only one filename supplyed
d->outFilename = (char *)malloc(strlen(d->srcFilename)+4);
if (argc == 1) { // only one filename supplied
// need +1 for \0
d->outFilename = (char *)malloc(strlen(d->srcFilename)+1+4);
strcpy(d->outFilename, d->srcFilename);
strcpy(d->outFilename+strlen(d->srcFilename), ".dwt");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,15 @@ void check_error(cudaError e) {

void cuda_print_double_array(double *array_GPU, size_t size) {
//allocate temporary array for printing
double* mem = (double*) malloc(sizeof (double) *size);

double* mem = (double*)calloc(size, sizeof (double));
//transfer data from device
cudaMemcpy(mem, array_GPU, sizeof (double) *size, cudaMemcpyDeviceToHost);


printf("PRINTING ARRAY VALUES\n");
//print values in memory
for (size_t i = 0; i < size; ++i) {
printf("[%d]:%0.6f\n", i, mem[i]);
printf("[%ld]:%0.6f\n", i, mem[i]);
}
printf("FINISHED PRINTING ARRAY VALUES\n");

Expand Down Expand Up @@ -577,7 +576,7 @@ void videoSequence(unsigned char * I, int IszX, int IszY, int Nfr, int * seed) {
}

/*dilate matrix*/
unsigned char * newMatrix = (unsigned char *) malloc(sizeof (unsigned char) * IszX * IszY * Nfr);
unsigned char * newMatrix = (unsigned char *)calloc(IszX * IszY * Nfr, sizeof (unsigned char));
imdilate_disk(I, IszX, IszY, Nfr, 5, newMatrix);
int x, y;
for (x = 0; x < IszX; x++) {
Expand Down Expand Up @@ -640,7 +639,7 @@ void particleFilter(unsigned char * I, int IszX, int IszY, int Nfr, int * seed,
//expected object locations, compared to center
int radius = 5;
int diameter = radius * 2 - 1;
int * disk = (int*) malloc(diameter * diameter * sizeof (int));
int * disk = (int*)calloc(diameter * diameter, sizeof(int));
strelDisk(disk, radius);
int countOnes = 0;
int x, y;
Expand All @@ -650,21 +649,21 @@ void particleFilter(unsigned char * I, int IszX, int IszY, int Nfr, int * seed,
countOnes++;
}
}
int * objxy = (int *) malloc(countOnes * 2 * sizeof (int));
int * objxy = (int *)calloc(countOnes * 2, sizeof(int));
getneighbors(disk, countOnes, objxy, radius);
//initial weights are all equal (1/Nparticles)
double * weights = (double *) malloc(sizeof (double) *Nparticles);
double * weights = (double *)calloc(Nparticles, sizeof(double));
for (x = 0; x < Nparticles; x++) {
weights[x] = 1 / ((double) (Nparticles));
}

//initial likelihood to 0.0
double * likelihood = (double *) malloc(sizeof (double) *Nparticles);
double * arrayX = (double *) malloc(sizeof (double) *Nparticles);
double * arrayY = (double *) malloc(sizeof (double) *Nparticles);
double * xj = (double *) malloc(sizeof (double) *Nparticles);
double * yj = (double *) malloc(sizeof (double) *Nparticles);
double * CDF = (double *) malloc(sizeof (double) *Nparticles);
double * likelihood = (double *)calloc(Nparticles, sizeof (double));
double * arrayX = (double *)calloc(Nparticles, sizeof(double));
double * arrayY = (double *)calloc(Nparticles, sizeof(double));
double * xj = (double *)calloc(Nparticles, sizeof(double));
double * yj = (double *)calloc(Nparticles, sizeof(double));
double * CDF = (double *)calloc(Nparticles, sizeof(double));

//GPU copies of arrays
double * arrayX_GPU;
Expand All @@ -677,9 +676,9 @@ void particleFilter(unsigned char * I, int IszX, int IszY, int Nfr, int * seed,
double * weights_GPU;
int * objxy_GPU;

int * ind = (int*) malloc(sizeof (int) *countOnes * Nparticles);
int * ind = (int *)calloc(countOnes * Nparticles, sizeof(int));
int * ind_GPU;
double * u = (double *) malloc(sizeof (double) *Nparticles);
double * u = (double *)calloc(Nparticles, sizeof(double));
double * u_GPU;
int * seed_GPU;
double* partial_sums;
Expand Down Expand Up @@ -740,7 +739,7 @@ void particleFilter(unsigned char * I, int IszX, int IszY, int Nfr, int * seed,
}//end loop

//block till kernels are finished
cudaThreadSynchronize();
cudaDeviceSynchronize();
long long back_time = get_time();

cudaFree(xj_GPU);
Expand Down Expand Up @@ -786,6 +785,9 @@ void particleFilter(unsigned char * I, int IszX, int IszY, int Nfr, int * seed,
cudaFree(arrayX_GPU);

//free regular memory
free(disk);
free(objxy);
free(weights);
free(likelihood);
free(arrayX);
free(arrayY);
Expand Down Expand Up @@ -856,12 +858,12 @@ int main(int argc, char * argv[]) {
return 0;
}
//establish seed
int * seed = (int *) malloc(sizeof (int) *Nparticles);
int * seed = (int *)calloc(Nparticles, sizeof(int));
int i;
for (i = 0; i < Nparticles; i++)
seed[i] = time(0) * i;
//malloc matrix
unsigned char * I = (unsigned char *) malloc(sizeof (unsigned char) *IszX * IszY * Nfr);
unsigned char * I = (unsigned char *)calloc(IszX * IszY * Nfr, sizeof(unsigned char));
long long start = get_time();
//call video sequence
videoSequence(I, IszX, IszY, Nfr, seed);
Expand Down
Loading