main.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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. time0 = get_time();
  51. //======================================================================================================================================================150
  52. // STRUCTURES, GLOBAL STRUCTURE VARIABLES
  53. //======================================================================================================================================================150
  54. params_common common;
  55. common.common_mem = sizeof(params_common);
  56. //======================================================================================================================================================150
  57. // FRAME INFO
  58. //======================================================================================================================================================150
  59. // variables
  60. char* video_file_name;
  61. // open movie file
  62. video_file_name = (char *) "../../data/heartwall/test.avi";
  63. frames = (avi_t*)AVI_open_input_file(video_file_name, 1); // added casting
  64. if (frames == NULL) {
  65. AVI_print_error((char *) "Error with AVI_open_input_file");
  66. return -1;
  67. }
  68. // dimensions
  69. common.no_frames = AVI_video_frames(frames);
  70. common.frame_rows = AVI_video_height(frames);
  71. common.frame_cols = AVI_video_width(frames);
  72. common.frame_elem = common.frame_rows * common.frame_cols;
  73. common.frame_mem = sizeof(fp) * common.frame_elem;
  74. time1 = get_time();
  75. //======================================================================================================================================================150
  76. // CHECK INPUT ARGUMENTS
  77. //======================================================================================================================================================150
  78. if(argc!=2){
  79. printf("ERROR: missing argument (number of frames to processed) or too many arguments\n");
  80. return 0;
  81. }
  82. else{
  83. common.frames_processed = atoi(argv[1]);
  84. if(common.frames_processed<0 || common.frames_processed>common.no_frames){
  85. printf("ERROR: %d is an incorrect number of frames specified, select in the range of 0-%d\n", common.frames_processed, common.no_frames);
  86. return 0;
  87. }
  88. }
  89. time2 = get_time();
  90. //======================================================================================================================================================150
  91. // INPUTS
  92. //======================================================================================================================================================150
  93. //====================================================================================================100
  94. // READ PARAMETERS FROM FILE
  95. //====================================================================================================100
  96. read_parameters( "../../data/heartwall/input.txt",
  97. &common.tSize,
  98. &common.sSize,
  99. &common.maxMove,
  100. &common.alpha);
  101. //====================================================================================================100
  102. // READ SIZE OF INPUTS FROM FILE
  103. //====================================================================================================100
  104. read_header( "../../data/heartwall/input.txt",
  105. &common.endoPoints,
  106. &common.epiPoints);
  107. common.allPoints = common.endoPoints + common.epiPoints;
  108. //====================================================================================================100
  109. // READ DATA FROM FILE
  110. //====================================================================================================100
  111. //==================================================50
  112. // ENDO POINTS MEMORY ALLOCATION
  113. //==================================================50
  114. common.endo_mem = sizeof(int) * common.endoPoints;
  115. int* endoRow;
  116. endoRow = (int*)malloc(common.endo_mem);
  117. int* endoCol;
  118. endoCol = (int*)malloc(common.endo_mem);
  119. int* tEndoRowLoc;
  120. tEndoRowLoc = (int*)malloc(common.endo_mem * common.no_frames);
  121. int* tEndoColLoc;
  122. tEndoColLoc = (int*)malloc(common.endo_mem * common.no_frames);
  123. //==================================================50
  124. // EPI POINTS MEMORY ALLOCATION
  125. //==================================================50
  126. common.epi_mem = sizeof(int) * common.epiPoints;
  127. int* epiRow;
  128. epiRow = (int *)malloc(common.epi_mem);
  129. int* epiCol;
  130. epiCol = (int *)malloc(common.epi_mem);
  131. int* tEpiRowLoc;
  132. tEpiRowLoc = (int *)malloc(common.epi_mem * common.no_frames);
  133. int* tEpiColLoc;
  134. tEpiColLoc = (int *)malloc(common.epi_mem * common.no_frames);
  135. //==================================================50
  136. // READ DATA FROM FILE
  137. //==================================================50
  138. read_data( "../../data/heartwall/input.txt",
  139. common.endoPoints,
  140. endoRow,
  141. endoCol,
  142. common.epiPoints,
  143. epiRow,
  144. epiCol);
  145. //==================================================50
  146. // End
  147. //==================================================50
  148. //====================================================================================================100
  149. // End
  150. //====================================================================================================100
  151. time3 = get_time();
  152. //======================================================================================================================================================150
  153. // KERNELL WRAPPER CALL
  154. //======================================================================================================================================================150
  155. kernel_gpu_opencl_wrapper( common,
  156. endoRow,
  157. endoCol,
  158. tEndoRowLoc,
  159. tEndoColLoc,
  160. epiRow,
  161. epiCol,
  162. tEpiRowLoc,
  163. tEpiColLoc,
  164. frames);
  165. time4 = get_time();
  166. //==================================================50
  167. // DUMP DATA TO FILE
  168. //==================================================50
  169. #ifdef OUTPUT
  170. write_data( "result.txt",
  171. common.no_frames,
  172. common.frames_processed,
  173. common.endoPoints,
  174. tEndoRowLoc,
  175. tEndoColLoc,
  176. common.epiPoints,
  177. tEpiRowLoc,
  178. tEpiColLoc);
  179. #endif
  180. //==================================================50
  181. // End
  182. //==================================================50
  183. //======================================================================================================================================================150
  184. // DEALLOCATION
  185. //======================================================================================================================================================150
  186. //====================================================================================================100
  187. // endo points
  188. //====================================================================================================100
  189. free(endoRow);
  190. free(endoCol);
  191. free(tEndoRowLoc);
  192. free(tEndoColLoc);
  193. //====================================================================================================100
  194. // epi points
  195. //====================================================================================================100
  196. free(epiRow);
  197. free(epiCol);
  198. free(tEpiRowLoc);
  199. free(tEpiColLoc);
  200. //====================================================================================================100
  201. // End
  202. //====================================================================================================100
  203. time5= get_time();
  204. //======================================================================================================================================================150
  205. // DISPLAY TIMING
  206. //======================================================================================================================================================150
  207. printf("Time spent in different stages of the application:\n");
  208. printf("%15.12f s, %15.12f % : READ INITIAL VIDEO FRAME\n", (fp) (time1-time0) / 1000000, (fp) (time1-time0) / (fp) (time5-time0) * 100);
  209. printf("%15.12f s, %15.12f % : READ COMMAND LINE PARAMETERS\n", (fp) (time2-time1) / 1000000, (fp) (time2-time1) / (fp) (time5-time0) * 100);
  210. printf("%15.12f s, %15.12f % : READ INPUTS FROM FILE\n", (fp) (time3-time2) / 1000000, (fp) (time3-time2) / (fp) (time5-time0) * 100);
  211. printf("%15.12f s, %15.12f % : GPU ALLOCATION, COPYING, COMPUTATION\n", (fp) (time4-time3) / 1000000, (fp) (time4-time3) / (fp) (time5-time0) * 100);
  212. printf("%15.12f s, %15.12f % : FREE MEMORY\n", (fp) (time5-time4) / 1000000, (fp) (time5-time4) / (fp) (time5-time0) * 100);
  213. printf("Total time:\n");
  214. printf("%15.12f s\n", (fp) (time5-time0) / 1000000);
  215. //======================================================================================================================================================150
  216. // End
  217. //======================================================================================================================================================150
  218. //========================================================================================================================================================================================================200
  219. // End
  220. //========================================================================================================================================================================================================200
  221. }