main.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. //========================================================================================================================================================================================================200
  2. //======================================================================================================================================================150
  3. //====================================================================================================100
  4. //==================================================50
  5. //========================================================================================================================================================================================================200
  6. // DEFINE / INCLUDE
  7. //========================================================================================================================================================================================================200
  8. //======================================================================================================================================================150
  9. // LIBRARIES
  10. //======================================================================================================================================================150
  11. #include <stdlib.h> // (in directory known to compiler)
  12. #include <math.h> // (in directory known to compiler)
  13. #include <string.h> // (in directory known to compiler)
  14. //======================================================================================================================================================150
  15. // MAIN FUNCTION HEADER
  16. //======================================================================================================================================================150
  17. #include "./main.h" // (in the main program folder) needed to recognized input parameters
  18. //======================================================================================================================================================150
  19. // UTILITIES
  20. //======================================================================================================================================================150
  21. #include "./util/avi/avilib.h" // (in directory) needed by avi functions
  22. #include "./util/avi/avimod.h" // (in directory) needed by avi functions
  23. //======================================================================================================================================================150
  24. // KERNEL
  25. //======================================================================================================================================================150
  26. #include "./kernel/kernel_gpu_opencl_wrapper.h"
  27. //======================================================================================================================================================150
  28. // END
  29. //======================================================================================================================================================150
  30. //========================================================================================================================================================================================================200
  31. // MAIN FUNCTION
  32. //========================================================================================================================================================================================================200
  33. int
  34. main( int argc,
  35. char* argv []){
  36. printf("WG size of kernel = %d \n", NUMBER_THREADS);
  37. //======================================================================================================================================================150
  38. // VARIABLES
  39. //======================================================================================================================================================150
  40. // time
  41. long long time0;
  42. long long time1;
  43. long long time2;
  44. long long time3;
  45. long long time4;
  46. long long time5;
  47. // other
  48. int i;
  49. avi_t* frames;
  50. // OpenCL platform and device selection
  51. int platform_id = 0;
  52. int device_id = 0;
  53. int use_gpu = 0;
  54. time0 = get_time();
  55. //======================================================================================================================================================150
  56. // STRUCTURES, GLOBAL STRUCTURE VARIABLES
  57. //======================================================================================================================================================150
  58. params_common common;
  59. common.common_mem = sizeof(params_common);
  60. //======================================================================================================================================================150
  61. // FRAME INFO
  62. //======================================================================================================================================================150
  63. // variables
  64. char* video_file_name;
  65. // open movie file
  66. video_file_name = (char *) "../../data/heartwall/test.avi";
  67. frames = (avi_t*)AVI_open_input_file(video_file_name, 1); // added casting
  68. if (frames == NULL) {
  69. AVI_print_error((char *) "Error with AVI_open_input_file");
  70. return -1;
  71. }
  72. // dimensions
  73. common.no_frames = AVI_video_frames(frames);
  74. common.frame_rows = AVI_video_height(frames);
  75. common.frame_cols = AVI_video_width(frames);
  76. common.frame_elem = common.frame_rows * common.frame_cols;
  77. common.frame_mem = sizeof(fp) * common.frame_elem;
  78. time1 = get_time();
  79. //======================================================================================================================================================150
  80. // CHECK INPUT ARGUMENTS
  81. //======================================================================================================================================================150
  82. if(argc!=5){
  83. printf("ERROR: missing argument (number of frames to processed) or too many arguments\n\
  84. Usage <number of frames> <platform_id> <device_id> <use_gpu>");
  85. return 0;
  86. }
  87. else{
  88. common.frames_processed = atoi(argv[1]);
  89. if(common.frames_processed<0 || common.frames_processed>common.no_frames){
  90. printf("ERROR: %d is an incorrect number of frames specified, select in the range of 0-%d\n", common.frames_processed, common.no_frames);
  91. return 0;
  92. }
  93. platform_id = atoi(argv[2]);
  94. device_id = atoi(argv[3]);
  95. use_gpu = atoi(argv[4]);
  96. }
  97. time2 = get_time();
  98. //======================================================================================================================================================150
  99. // INPUTS
  100. //======================================================================================================================================================150
  101. //====================================================================================================100
  102. // READ PARAMETERS FROM FILE
  103. //====================================================================================================100
  104. read_parameters( "../../data/heartwall/input.txt",
  105. &common.tSize,
  106. &common.sSize,
  107. &common.maxMove,
  108. &common.alpha);
  109. //====================================================================================================100
  110. // READ SIZE OF INPUTS FROM FILE
  111. //====================================================================================================100
  112. read_header( "../../data/heartwall/input.txt",
  113. &common.endoPoints,
  114. &common.epiPoints);
  115. common.allPoints = common.endoPoints + common.epiPoints;
  116. //====================================================================================================100
  117. // READ DATA FROM FILE
  118. //====================================================================================================100
  119. //==================================================50
  120. // ENDO POINTS MEMORY ALLOCATION
  121. //==================================================50
  122. common.endo_mem = sizeof(int) * common.endoPoints;
  123. int* endoRow;
  124. endoRow = (int*)malloc(common.endo_mem);
  125. int* endoCol;
  126. endoCol = (int*)malloc(common.endo_mem);
  127. int* tEndoRowLoc;
  128. tEndoRowLoc = (int*)malloc(common.endo_mem * common.no_frames);
  129. int* tEndoColLoc;
  130. tEndoColLoc = (int*)malloc(common.endo_mem * common.no_frames);
  131. //==================================================50
  132. // EPI POINTS MEMORY ALLOCATION
  133. //==================================================50
  134. common.epi_mem = sizeof(int) * common.epiPoints;
  135. int* epiRow;
  136. epiRow = (int *)malloc(common.epi_mem);
  137. int* epiCol;
  138. epiCol = (int *)malloc(common.epi_mem);
  139. int* tEpiRowLoc;
  140. tEpiRowLoc = (int *)malloc(common.epi_mem * common.no_frames);
  141. int* tEpiColLoc;
  142. tEpiColLoc = (int *)malloc(common.epi_mem * common.no_frames);
  143. //==================================================50
  144. // READ DATA FROM FILE
  145. //==================================================50
  146. read_data( "../../data/heartwall/input.txt",
  147. common.endoPoints,
  148. endoRow,
  149. endoCol,
  150. common.epiPoints,
  151. epiRow,
  152. epiCol);
  153. //==================================================50
  154. // End
  155. //==================================================50
  156. //====================================================================================================100
  157. // End
  158. //====================================================================================================100
  159. time3 = get_time();
  160. //======================================================================================================================================================150
  161. // KERNELL WRAPPER CALL
  162. //======================================================================================================================================================150
  163. kernel_gpu_opencl_wrapper( common,
  164. endoRow,
  165. endoCol,
  166. tEndoRowLoc,
  167. tEndoColLoc,
  168. epiRow,
  169. epiCol,
  170. tEpiRowLoc,
  171. tEpiColLoc,
  172. frames,
  173. platform_id,
  174. device_id,
  175. use_gpu);
  176. time4 = get_time();
  177. //==================================================50
  178. // DUMP DATA TO FILE
  179. //==================================================50
  180. #ifdef OUTPUT
  181. write_data( "result.txt",
  182. common.no_frames,
  183. common.frames_processed,
  184. common.endoPoints,
  185. tEndoRowLoc,
  186. tEndoColLoc,
  187. common.epiPoints,
  188. tEpiRowLoc,
  189. tEpiColLoc);
  190. #endif
  191. //==================================================50
  192. // End
  193. //==================================================50
  194. //======================================================================================================================================================150
  195. // DEALLOCATION
  196. //======================================================================================================================================================150
  197. //====================================================================================================100
  198. // endo points
  199. //====================================================================================================100
  200. free(endoRow);
  201. free(endoCol);
  202. free(tEndoRowLoc);
  203. free(tEndoColLoc);
  204. //====================================================================================================100
  205. // epi points
  206. //====================================================================================================100
  207. free(epiRow);
  208. free(epiCol);
  209. free(tEpiRowLoc);
  210. free(tEpiColLoc);
  211. //====================================================================================================100
  212. // End
  213. //====================================================================================================100
  214. time5= get_time();
  215. //======================================================================================================================================================150
  216. // DISPLAY TIMING
  217. //======================================================================================================================================================150
  218. printf("Time spent in different stages of the application:\n");
  219. printf("%15.12f s, %15.12f % : READ INITIAL VIDEO FRAME\n", (fp) (time1-time0) / 1000000, (fp) (time1-time0) / (fp) (time5-time0) * 100);
  220. printf("%15.12f s, %15.12f % : READ COMMAND LINE PARAMETERS\n", (fp) (time2-time1) / 1000000, (fp) (time2-time1) / (fp) (time5-time0) * 100);
  221. printf("%15.12f s, %15.12f % : READ INPUTS FROM FILE\n", (fp) (time3-time2) / 1000000, (fp) (time3-time2) / (fp) (time5-time0) * 100);
  222. printf("%15.12f s, %15.12f % : GPU ALLOCATION, COPYING, COMPUTATION\n", (fp) (time4-time3) / 1000000, (fp) (time4-time3) / (fp) (time5-time0) * 100);
  223. printf("%15.12f s, %15.12f % : FREE MEMORY\n", (fp) (time5-time4) / 1000000, (fp) (time5-time4) / (fp) (time5-time0) * 100);
  224. printf("Total time:\n");
  225. printf("%15.12f s\n", (fp) (time5-time0) / 1000000);
  226. //======================================================================================================================================================150
  227. // End
  228. //======================================================================================================================================================150
  229. //========================================================================================================================================================================================================200
  230. // End
  231. //========================================================================================================================================================================================================200
  232. }