Skip to content

Commit

Permalink
update GPU unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
a-sevin committed Aug 9, 2023
1 parent ecf601f commit 8d3dbe0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
2 changes: 1 addition & 1 deletion ImCreate_test_gpuipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ int main()

// image will be in shared memory
shared = 1;
location = -1; // on GPU0
location = 0; // on GPU0

// allocate space for 10 keywords
NBkw = 1;
Expand Down
51 changes: 28 additions & 23 deletions ImCreate_test_gpuipc2.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,36 @@ int main()

// create an image in shared memory
ImageStreamIO_read_sharedmem_image_toIMAGE("imtest00", &imarray[0]);
void *d_ptr = ImageStreamIO_get_image_d_ptr(&imarray[0]);
if(imarray[0].md[0].location<0) {
printf("this ISIO is not a GPU SMH\n");
} else {
void *d_ptr = ImageStreamIO_get_image_d_ptr(&imarray[0]);

float *h_ptr = (float*)malloc(imarray[0].md[0].size[0]*imarray[0].md[0].size[1]*sizeof(float));
cudaMemcpy(h_ptr, d_ptr, imarray[0].md[0].size[0]*imarray[0].md[0].size[1]*sizeof(float),
cudaMemcpyDeviceToHost);

printf("ImCreate_test_gpuipc2 read in SHM\n");
for(int i=0; i<10 /*imsize[0]*imsize[1]*/; i++){
printf("%f ", h_ptr[i]);
}
printf("\n");

for(int i=0; i<imarray[0].md[0].size[0]*imarray[0].md[0].size[1]; i++){
h_ptr[i]=i;
}
cudaMemcpy(d_ptr, h_ptr, imarray[0].md[0].size[0]*imarray[0].md[0].size[1]*sizeof(float),
cudaMemcpyHostToDevice);

printf("ImCreate_test_gpuipc2 wrote in SHM\n");
for(int i=0; i<10 /*imsize[0]*imsize[1]*/; i++){
printf("%f ", h_ptr[i]);
}
printf("\n");

free(h_ptr);

float *h_ptr = (float*)malloc(imarray[0].md[0].size[0]*imarray[0].md[0].size[1]*sizeof(float));
cudaMemcpy(h_ptr, d_ptr, imarray[0].md[0].size[0]*imarray[0].md[0].size[1]*sizeof(float),
cudaMemcpyDeviceToHost);

printf("ImCreate_test_gpuipc2 read in SHM\n");
for(int i=0; i<10 /*imsize[0]*imsize[1]*/; i++){
printf("%f ", h_ptr[i]);
}
printf("\n");

for(int i=0; i<imarray[0].md[0].size[0]*imarray[0].md[0].size[1]; i++){
h_ptr[i]=i;
}
cudaMemcpy(d_ptr, h_ptr, imarray[0].md[0].size[0]*imarray[0].md[0].size[1]*sizeof(float),
cudaMemcpyHostToDevice);

printf("ImCreate_test_gpuipc2 wrote in SHM\n");
for(int i=0; i<10 /*imsize[0]*imsize[1]*/; i++){
printf("%f ", h_ptr[i]);
}
printf("\n");

// POST ALL SEMAPHORES
printf("ImCreate_test_gpuipc2 is sending update\n");
ImageStreamIO_sempost(&imarray[0], -1);
Expand All @@ -75,7 +81,6 @@ int main()
imarray[0].md[0].cnt0++;
imarray[0].md[0].cnt1++;

free(h_ptr);
free(imarray);

return 0;
Expand Down

0 comments on commit 8d3dbe0

Please sign in to comment.