Blame view

cpp/cudafunc.cu 2.55 KB
a744d027   Laila Saadatifard   upload the ivote3...
1
  
c9aba18a   Laila Saadatifard   ivote3 on the GPU...
2
3
  #include "gaussian_blur3.cuh"
  #include "gradient3.cuh"
f12505fb   Laila Saadatifard   upload the ivote ...
4
  #include "mag3.cuh"
a744d027   Laila Saadatifard   upload the ivote3...
5
  #include "vote3_atomic_aabb.cuh"
1f55a874   Laila Saadatifard   upload the fixed ...
6
  #include "update_dir3_aabb.cuh"
f12505fb   Laila Saadatifard   upload the ivote ...
7
  #include "local_max3.cuh"
310a1698   Laila Saadatifard   update the ivote3...
8
  #include <fstream>
c9aba18a   Laila Saadatifard   ivote3 on the GPU...
9
  
2558ee86   Laila Saadatifard   updating ivote3 t...
10
  void ivote3(float* img, float sigma[], float phi, float d_phi, unsigned int r[],
310a1698   Laila Saadatifard   update the ivote3...
11
  			int iter, float t, unsigned int conn[], size_t x, size_t y, size_t z){
f12505fb   Laila Saadatifard   upload the ivote ...
12
  
94d437dd   Laila Saadatifard   ivote3 code compi...
13
  	
310a1698   Laila Saadatifard   update the ivote3...
14
  	size_t bytes = x * y * z * sizeof(float);				// compute the number of bytes in the input data
f12505fb   Laila Saadatifard   upload the ivote ...
15
  
1f55a874   Laila Saadatifard   upload the fixed ...
16
  	float* gpuI0;											//assign memory on gpu for the input data
f12505fb   Laila Saadatifard   upload the ivote ...
17
  	cudaMalloc(&gpuI0, bytes);	
1f55a874   Laila Saadatifard   upload the fixed ...
18
  	cudaMemcpy(gpuI0, img, bytes, cudaMemcpyHostToDevice);				//copy the image data to the GPU.
f12505fb   Laila Saadatifard   upload the ivote ...
19
  
1f55a874   Laila Saadatifard   upload the fixed ...
20
  	gpu_gaussian_blur3<float>(gpuI0, sigma, x, y, z);							//call the blurring function from the gpu.
f12505fb   Laila Saadatifard   upload the ivote ...
21
22
  	cudaDeviceSynchronize();
  		
1f55a874   Laila Saadatifard   upload the fixed ...
23
  	float* gpu_grad;												//assign memory on the gpu for the gradient along the X, y, z.
c9aba18a   Laila Saadatifard   ivote3 on the GPU...
24
25
  	cudaMalloc(&gpu_grad, bytes*3);
  	
310a1698   Laila Saadatifard   update the ivote3...
26
  	gpu_gradient3<float>(gpu_grad, gpuI0, x, y, z);				//call the gradient function from the gpu.
f12505fb   Laila Saadatifard   upload the ivote ...
27
28
  	cudaFree(gpuI0);
  	
f12505fb   Laila Saadatifard   upload the ivote ...
29
30
  	float* gpu_vote;
  	cudaMalloc(&gpu_vote, bytes);
c9aba18a   Laila Saadatifard   ivote3 on the GPU...
31
  
f12505fb   Laila Saadatifard   upload the ivote ...
32
  	float cos_phi = cos(phi);
310a1698   Laila Saadatifard   update the ivote3...
33
  	
f12505fb   Laila Saadatifard   upload the ivote ...
34
35
  	//call the vote function.
  	for (int i = 0; i < iter; i++){
a744d027   Laila Saadatifard   upload the ivote3...
36
37
  	
  		cudaMemset(gpu_vote, 0, bytes);
1f55a874   Laila Saadatifard   upload the fixed ...
38
  		gpu_vote3<float>(gpu_vote, gpu_grad, phi, cos_phi, r, x, y, z);
f12505fb   Laila Saadatifard   upload the ivote ...
39
  		cudaDeviceSynchronize();
310a1698   Laila Saadatifard   update the ivote3...
40
41
42
43
44
45
46
47
48
49
50
51
  		if (i == 0) {
  			cudaMemcpy(img, gpu_vote, bytes, cudaMemcpyDeviceToHost);
  			std::ofstream fvote("00-vote1_aabb.vol", std::ofstream::out | std::ofstream::binary);
  			fvote.write((char*)img, bytes);
  			fvote.close();
  		}
  		if (i == 1) {
  			cudaMemcpy(img, gpu_vote, bytes, cudaMemcpyDeviceToHost);
  			std::ofstream fvote("00-vote2_aabb.vol", std::ofstream::out | std::ofstream::binary);
  			fvote.write((char*)img, bytes);
  			fvote.close();
  		}
1f55a874   Laila Saadatifard   upload the fixed ...
52
  			gpu_update_dir3<float>(gpu_grad, gpu_vote, phi, cos_phi, r, x, y, z);
310a1698   Laila Saadatifard   update the ivote3...
53
54
55
  		cudaDeviceSynchronize();
  		phi = phi - d_phi;
  		cos_phi = cos(phi);
f12505fb   Laila Saadatifard   upload the ivote ...
56
  	}
c9aba18a   Laila Saadatifard   ivote3 on the GPU...
57
  
2558ee86   Laila Saadatifard   updating ivote3 t...
58
  	cudaFree(gpu_grad);
46820b25   Laila Saadatifard   create an obj fil...
59
  	cudaMemcpy(img, gpu_vote, bytes, cudaMemcpyDeviceToHost);
2558ee86   Laila Saadatifard   updating ivote3 t...
60
  	
46820b25   Laila Saadatifard   create an obj fil...
61
62
63
64
65
  	cudaFree(gpu_vote);
  	//cudaFree(gpu_output);
  	
  }
  
310a1698   Laila Saadatifard   update the ivote3...
66
  void lmax(float* out, float* in, float t, unsigned int conn[], size_t x, size_t y, size_t z){
46820b25   Laila Saadatifard   create an obj fil...
67
68
  	unsigned int bytes = x * y * z * sizeof(float);
  
c986ebb7   Laila Saadatifard   fix ivote3 to work
69
  	cudaSetDevice(0);
a744d027   Laila Saadatifard   upload the ivote3...
70
  
1f55a874   Laila Saadatifard   upload the fixed ...
71
72
  	
  	float* gpuV;					//assign memory on gpu for the input data.
46820b25   Laila Saadatifard   create an obj fil...
73
74
  	cudaMalloc(&gpuV, bytes);	
  
1f55a874   Laila Saadatifard   upload the fixed ...
75
  	cudaMemcpy(gpuV, in, bytes, cudaMemcpyHostToDevice);			//copy the image data to the GPU.
46820b25   Laila Saadatifard   create an obj fil...
76
77
78
  
  	float* gpuOut;
  	cudaMalloc(&gpuOut, bytes);
f12505fb   Laila Saadatifard   upload the ivote ...
79
  
1f55a874   Laila Saadatifard   upload the fixed ...
80
  	gpu_local_max3<float>(gpuOut, gpuV, t, conn, x, y, z);				//call the local max function
f12505fb   Laila Saadatifard   upload the ivote ...
81
  
1f55a874   Laila Saadatifard   upload the fixed ...
82
  	cudaMemcpy(out, gpuOut, bytes, cudaMemcpyDeviceToHost);				//copy the final result to the cpu.
f12505fb   Laila Saadatifard   upload the ivote ...
83
  	
46820b25   Laila Saadatifard   create an obj fil...
84
85
  	cudaFree(gpuV);
  	cudaFree(gpuOut);
310a1698   Laila Saadatifard   update the ivote3...
86
  }