Blame view

cpp/cudafunc.cu 2.56 KB
c9aba18a   Laila Saadatifard   ivote3 on the GPU...
1
2
  #include "gaussian_blur3.cuh"
  #include "gradient3.cuh"
f12505fb   Laila Saadatifard   upload the ivote ...
3
4
5
6
  #include "mag3.cuh"
  #include "vote3.cuh"
  #include "update_dir3.cuh"
  #include "local_max3.cuh"
c9aba18a   Laila Saadatifard   ivote3 on the GPU...
7
8
  
  
46820b25   Laila Saadatifard   create an obj fil...
9
  void ivote3(float* img, float sigma[], float anisotropy, float phi, float d_phi, unsigned int r[],
f12505fb   Laila Saadatifard   upload the ivote ...
10
11
  			int iter, float t, unsigned int conn[], unsigned int x, unsigned int y, unsigned int z){
  
94d437dd   Laila Saadatifard   ivote3 code compi...
12
13
  	
  	cudaSetDevice(0);
f12505fb   Laila Saadatifard   upload the ivote ...
14
  	// compute the number of bytes in the input data
c9aba18a   Laila Saadatifard   ivote3 on the GPU...
15
  	unsigned int bytes = x * y * z * sizeof(float);
f12505fb   Laila Saadatifard   upload the ivote ...
16
17
  
  	//assign memory on gpu for the input data.
c9aba18a   Laila Saadatifard   ivote3 on the GPU...
18
  	float* gpuI0;
f12505fb   Laila Saadatifard   upload the ivote ...
19
20
21
  	cudaMalloc(&gpuI0, bytes);	
  
  	//copy the image data to the GPU.
c9aba18a   Laila Saadatifard   ivote3 on the GPU...
22
23
  	cudaMemcpy(gpuI0, img, bytes, cudaMemcpyHostToDevice);
  
f12505fb   Laila Saadatifard   upload the ivote ...
24
  	//call the blurring function from the gpu.
c9aba18a   Laila Saadatifard   ivote3 on the GPU...
25
  	gpu_gaussian_blur3<float>(gpuI0, sigma, x, y, z);
94d437dd   Laila Saadatifard   ivote3 code compi...
26
  	//cudaMemcpy(img, gpuI0, bytes, cudaMemcpyDeviceToHost);
f12505fb   Laila Saadatifard   upload the ivote ...
27
28
  	cudaDeviceSynchronize();
  		
f12505fb   Laila Saadatifard   upload the ivote ...
29
  	//assign memory on the gpu for the gradient along the X, y, z.
c9aba18a   Laila Saadatifard   ivote3 on the GPU...
30
31
32
  	float* gpu_grad;
  	cudaMalloc(&gpu_grad, bytes*3);
  	
f12505fb   Laila Saadatifard   upload the ivote ...
33
  	//call the gradient function from the gpu.
94d437dd   Laila Saadatifard   ivote3 code compi...
34
  	gpu_gradient3<float>(gpu_grad, gpuI0, anisotropy, x, y, z);
f12505fb   Laila Saadatifard   upload the ivote ...
35
36
  	cudaFree(gpuI0);
  	
f12505fb   Laila Saadatifard   upload the ivote ...
37
38
  	float* gpu_vote;
  	cudaMalloc(&gpu_vote, bytes);
c9aba18a   Laila Saadatifard   ivote3 on the GPU...
39
  
f12505fb   Laila Saadatifard   upload the ivote ...
40
41
42
43
44
  	float cos_phi = cos(phi);
  
  	//call the vote function.
  	for (int i = 0; i < iter; i++){
  
02fb26b3   Laila Saadatifard   change the vote a...
45
  		gpu_vote3<float>(gpu_vote, gpu_grad, cos_phi, r, x, y, z);
f12505fb   Laila Saadatifard   upload the ivote ...
46
  		cudaDeviceSynchronize();
46820b25   Laila Saadatifard   create an obj fil...
47
48
  		/*if (i==7)
  			cudaMemcpy(img, gpu_vote, bytes, cudaMemcpyDeviceToHost);*/
f12505fb   Laila Saadatifard   upload the ivote ...
49
50
51
52
53
54
55
56
57
  		
  		if (phi >= d_phi){	
  			gpu_update_dir3<float>(gpu_grad, gpu_vote, cos_phi, r, x, y, z);
  			cudaDeviceSynchronize();
  			phi = phi - d_phi;
  			cos_phi = cos(phi);
  		}
  	
  	}
c9aba18a   Laila Saadatifard   ivote3 on the GPU...
58
  
02fb26b3   Laila Saadatifard   change the vote a...
59
  	cudaFree(gpu_grad);	
46820b25   Laila Saadatifard   create an obj fil...
60
  	cudaMemcpy(img, gpu_vote, bytes, cudaMemcpyDeviceToHost);
f12505fb   Laila Saadatifard   upload the ivote ...
61
62
  
  	//allocate space on the gpu for the final detected cells.
46820b25   Laila Saadatifard   create an obj fil...
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
  	//float* gpu_output;
  	//cudaMalloc(&gpu_output, bytes);
  
  	////call the local max function
  	//gpu_local_max3<float>(gpu_output, gpu_vote, t, conn, x, y, z);
  
  	////copy the final result to the cpu.
  	//cudaMemcpy(center, gpu_output, bytes, cudaMemcpyDeviceToHost);
  	//	
  	//
  	cudaFree(gpu_vote);
  	//cudaFree(gpu_output);
  	
  }
  
  void lmax(float* out, float* in, float t, unsigned int conn[], unsigned int x, unsigned int y, unsigned int z){
  	unsigned int bytes = x * y * z * sizeof(float);
  
  	//assign memory on gpu for the input data.
  	float* gpuV;
  	cudaMalloc(&gpuV, bytes);	
  
  	//copy the image data to the GPU.
  	cudaMemcpy(gpuV, in, bytes, cudaMemcpyHostToDevice);
  
  	float* gpuOut;
  	cudaMalloc(&gpuOut, bytes);
f12505fb   Laila Saadatifard   upload the ivote ...
90
91
  
  	//call the local max function
46820b25   Laila Saadatifard   create an obj fil...
92
  	gpu_local_max3<float>(gpuOut, gpuV, t, conn, x, y, z);
f12505fb   Laila Saadatifard   upload the ivote ...
93
94
  
  	//copy the final result to the cpu.
46820b25   Laila Saadatifard   create an obj fil...
95
  	cudaMemcpy(out, gpuOut, bytes, cudaMemcpyDeviceToHost);
f12505fb   Laila Saadatifard   upload the ivote ...
96
  	
46820b25   Laila Saadatifard   create an obj fil...
97
98
  	cudaFree(gpuV);
  	cudaFree(gpuOut);
c9aba18a   Laila Saadatifard   ivote3 on the GPU...
99
  }