apps.backup.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940
  1. #include "apps.h"
  2. #include "scc_signals.h"
  3. #include "libfunctions.h"
  4. #include "my_rtrm.h"
  5. #define SWAP(a,b) {float tmp; tmp=a; a=b; b=tmp;}
  6. #define FFT_MAX 136192
  7. #define PAGE_SIZE 4096
  8. /*
  9. static float input_vector[25][10] = {
  10. {-0.390695, -0.381094, -0.341754, -0.272043, -0.588159, 2.297114, -0.116822, -0.507031, -0.563574, -0.534119},
  11. {-0.250457, -0.240673, -0.210423, -0.217804, -0.453731, 1.784484, -0.142005, -0.230148, -0.339593, -0.298467},
  12. {-0.177671, -0.183887, -0.191644, -0.205313, -0.441613, 1.599526, 0.023297, -0.322458, -0.539978, -0.457565},
  13. {-0.149024, -0.140364, -0.142723, -0.066651, -0.344126, 1.830863, 0.154307, -0.171898, -0.343950, -0.379533},
  14. {-0.155498, -0.154145, -0.181875, -0.189322, -0.122244, -3.037579, -1.476675, -0.089878, 0.004249, 0.169941},
  15. {-1.786535, -1.809749, -1.445913, -1.050310, -0.095173, 2.964720, 4.706277, -0.649227, -1.362017, -1.447784},
  16. {0.034026, 0.038159, -0.018497, -0.067303, 0.059710, -2.908602, -1.484229, 0.108804, 0.292757, 0.566575},
  17. {0.527511, 0.518252, 0.762342, 1.148066, 0.772846, -2.113671, -2.704303, -0.664257, 0.460104, 1.295371},
  18. {1.370790, 1.383803, 1.340450, 0.634441, -0.596868, -2.427651, -2.352223, 0.454767, 1.405430, 1.838241},
  19. {1.455314, 1.464866, 2.487861, 2.464788, 1.963237, 0.324097, -1.869693, -2.554004, -2.022594, 1.114752},
  20. {-0.664593, -0.687087, -0.075215, 0.583554, 0.927597, 3.671647, 3.835722, 0.694133, -2.007198, -2.345115},
  21. {-0.343777, -0.344074, -0.221304, -0.153775, -0.494637, 1.743759, -0.590775, -0.413656, -0.389204, -0.221876},
  22. {-0.159571, -0.163080, -0.513428, -0.775665, -0.891170, -3.118664, -1.247074, 0.913688, 1.009656, 1.170559},
  23. {-0.761538, -0.755972, -0.773967, -0.674253, -0.978258, 1.514730, -0.145977, -0.620700, -0.857082, -0.765523},
  24. {1.344641, 1.329151, 1.633256, 2.020196, 1.777348, -1.744907, -5.928727, -4.032057, -0.585966, 1.072364},
  25. {-0.468882, -0.486856, 0.935241, 2.032263, 2.219547, -0.225632, -3.438104, -4.412505, -0.550391, 2.234320},
  26. {3.177341, 3.204259, 2.749250, 1.741244, 1.197538, -2.985864, -6.084715, -1.447878, 0.904210, 1.495579},
  27. {-0.998953, -1.005918, -0.988911, -0.863153, -1.003750, 1.256336, -0.471785, -0.860056, -0.872804, -0.629210},
  28. {1.957319, 1.966453, 1.840960, 1.405216, 1.313205, -0.956540, -3.535391, -2.280320, -1.179478, -0.458734},
  29. {-0.326054, -0.331524, -0.134208, -0.218622, -0.158037, 3.128528, 4.020623, -1.129257, -1.524952, -1.377990},
  30. {-0.632187, -0.629597, -0.560808, -0.439143, -0.550906, -3.344673, -1.389866, 0.268649, 0.664319, 1.150327},
  31. {-0.205756, -0.210472, -0.151426, -0.121347, 0.196067, -3.136218, -2.621049, -0.026517, 0.358534, 0.714117},
  32. {-0.418011, -0.424854, -0.461205, -0.428858, -0.801747, 1.933860, -0.129047, -0.674498, -0.880092, -0.752953},
  33. {-0.625461, -0.633598, -0.651167, -0.621632, -0.312866, -3.908468, -2.380095, -0.118114, 0.233478, 0.722539},
  34. {-0.525633, -0.521436, -0.552314, -0.527505, -0.233392, -3.763046, -2.487090, -0.133160, 0.156544, 0.642195},
  35. };
  36. */
  37. /*
  38. static float input_vector[2][D_sv] = {
  39. {-0.390695, -0.381094, -0.341754, -0.272043, -0.588159, 2.297114, -0.116822, -0.507031, -0.563574, -0.534119,
  40. -0.250457, -0.240673, -0.210423, -0.217804, -0.453731, 1.784484, -0.142005, -0.230148, -0.339593, -0.298467,
  41. -0.177671, -0.183887, -0.191644, -0.205313, -0.441613, 1.599526, 0.023297, -0.322458, -0.539978, -0.457565,
  42. -0.149024, -0.140364, -0.142723, -0.066651, -0.344126, 1.830863, 0.154307, -0.171898, -0.343950, -0.379533,
  43. -0.155498, -0.154145, -0.181875, -0.189322, -0.122244, -3.037579, -1.476675, -0.089878, 0.004249, 0.169941,
  44. -1.786535, -1.809749, -1.445913, -1.050310, -0.095173, 2.964720, 4.706277, -0.649227, -1.362017, -1.447784,
  45. 0.034026, 0.038159, -0.018497, -0.067303, 0.059710, -2.908602, -1.484229, 0.108804, 0.292757, 0.566575,
  46. 0.527511, 0.518252, 0.762342, 1.148066, 0.772846, -2.113671, -2.704303, -0.664257, 0.460104, 1.295371,
  47. 1.370790, 1.383803, 1.340450, 0.634441, -0.596868, -2.427651, -2.352223, 0.454767, 1.405430, 1.838241,
  48. 1.455314, 1.464866, 2.487861, 2.464788, 1.963237, 0.324097, -1.869693, -2.554004, -2.022594, 1.114752},
  49. {-0.664593, -0.687087, -0.075215, 0.583554, 0.927597, 3.671647, 3.835722, 0.694133, -2.007198, -2.345115,
  50. -0.343777, -0.344074, -0.221304, -0.153775, -0.494637, 1.743759, -0.590775, -0.413656, -0.389204, -0.221876,
  51. -0.159571, -0.163080, -0.513428, -0.775665, -0.891170, -3.118664, -1.247074, 0.913688, 1.009656, 1.170559,
  52. -0.761538, -0.755972, -0.773967, -0.674253, -0.978258, 1.514730, -0.145977, -0.620700, -0.857082, -0.765523,
  53. 1.344641, 1.329151, 1.633256, 2.020196, 1.777348, -1.744907, -5.928727, -4.032057, -0.585966, 1.072364,
  54. -0.468882, -0.486856, 0.935241, 2.032263, 2.219547, -0.225632, -3.438104, -4.412505, -0.550391, 2.234320,
  55. 3.177341, 3.204259, 2.749250, 1.741244, 1.197538, -2.985864, -6.084715, -1.447878, 0.904210, 1.495579,
  56. -0.998953, -1.005918, -0.988911, -0.863153, -1.003750, 1.256336, -0.471785, -0.860056, -0.872804, -0.629210,
  57. 1.957319, 1.966453, 1.840960, 1.405216, 1.313205, -0.956540, -3.535391, -2.280320, -1.179478, -0.458734,
  58. -0.326054, -0.331524, -0.134208, -0.218622, -0.158037, 3.128528, 4.020623, -1.129257, -1.524952, -1.377990},
  59. };
  60. */
  61. static float input_vector[1][D_sv] = {
  62. {-0.390695, -0.381094, -0.341754, -0.272043, -0.588159, 2.297114, -0.116822, -0.507031, -0.563574, -0.534119,
  63. -0.250457, -0.240673, -0.210423, -0.217804, -0.453731, 1.784484, -0.142005, -0.230148, -0.339593, -0.298467,
  64. -0.177671, -0.183887, -0.191644, -0.205313, -0.441613, 1.599526, 0.023297, -0.322458, -0.539978, -0.457565,
  65. -0.149024, -0.140364, -0.142723, -0.066651, -0.344126, 1.830863, 0.154307, -0.171898, -0.343950, -0.379533,
  66. -0.155498, -0.154145, -0.181875, -0.189322, -0.122244, -3.037579, -1.476675, -0.089878, 0.004249, 0.169941,
  67. -1.786535, -1.809749, -1.445913, -1.050310, -0.095173, 2.964720, 4.706277, -0.649227, -1.362017, -1.447784,
  68. 0.034026, 0.038159, -0.018497, -0.067303, 0.059710, -2.908602, -1.484229, 0.108804, 0.292757, 0.566575,
  69. 0.527511, 0.518252, 0.762342, 1.148066, 0.772846, -2.113671, -2.704303, -0.664257, 0.460104, 1.295371,
  70. 1.370790, 1.383803, 1.340450, 0.634441, -0.596868, -2.427651, -2.352223, 0.454767, 1.405430, 1.838241,
  71. 1.455314, 1.464866, 2.487861, 2.464788, 1.963237, 0.324097, -1.869693, -2.554004, -2.022594, 1.114752,
  72. -0.664593, -0.687087, -0.075215, 0.583554, 0.927597, 3.671647, 3.835722, 0.694133, -2.007198, -2.345115,
  73. -0.343777, -0.344074, -0.221304, -0.153775, -0.494637, 1.743759, -0.590775, -0.413656, -0.389204, -0.221876,
  74. -0.159571, -0.163080, -0.513428, -0.775665, -0.891170, -3.118664, -1.247074, 0.913688, 1.009656, 1.170559,
  75. -0.761538, -0.755972, -0.773967, -0.674253, -0.978258, 1.514730, -0.145977, -0.620700, -0.857082, -0.765523,
  76. 1.344641, 1.329151, 1.633256, 2.020196, 1.777348, -1.744907, -5.928727, -4.032057, -0.585966, 1.072364,
  77. -0.468882, -0.486856, 0.935241, 2.032263, 2.219547, -0.225632, -3.438104, -4.412505, -0.550391, 2.234320,
  78. 3.177341, 3.204259, 2.749250, 1.741244, 1.197538, -2.985864, -6.084715, -1.447878, 0.904210, 1.495579,
  79. -0.998953, -1.005918, -0.988911, -0.863153, -1.003750, 1.256336, -0.471785, -0.860056, -0.872804, -0.629210,
  80. 1.957319, 1.966453, 1.840960, 1.405216, 1.313205, -0.956540, -3.535391, -2.280320, -1.179478, -0.458734,
  81. -0.326054, -0.331524, -0.134208, -0.218622, -0.158037, 3.128528, 4.020623, -1.129257, -1.524952, -1.377990,
  82. -0.390695, -0.381094, -0.341754, -0.272043, -0.588159, 2.297114, -0.116822, -0.507031, -0.563574, -0.534119,
  83. -0.250457, -0.240673, -0.210423, -0.217804, -0.453731, 1.784484, -0.142005, -0.230148, -0.339593, -0.298467,
  84. -0.177671, -0.183887, -0.191644, -0.205313, -0.441613, 1.599526, 0.023297, -0.322458, -0.539978, -0.457565,
  85. -0.149024, -0.140364, -0.142723, -0.066651, -0.344126, 1.830863, 0.154307, -0.171898, -0.343950, -0.379533,
  86. -0.155498, -0.154145, -0.181875, -0.189322, -0.122244, -3.037579, -1.476675, -0.089878, 0.004249, 0.169941,
  87. -1.786535, -1.809749, -1.445913, -1.050310, -0.095173, 2.964720, 4.706277, -0.649227, -1.362017, -1.447784,
  88. 0.034026, 0.038159, -0.018497, -0.067303, 0.059710, -2.908602, -1.484229, 0.108804, 0.292757, 0.566575,
  89. 0.527511, 0.518252, 0.762342, 1.148066, 0.772846, -2.113671, -2.704303, -0.664257, 0.460104, 1.295371,
  90. 1.370790, 1.383803, 1.340450, 0.634441, -0.596868, -2.427651, -2.352223, 0.454767, 1.405430, 1.838241,
  91. 1.455314, 1.464866, 2.487861, 2.464788, 1.963237, 0.324097, -1.869693, -2.554004, -2.022594, 1.114752,
  92. -0.664593, -0.687087, -0.075215, 0.583554, 0.927597, 3.671647, 3.835722, 0.694133, -2.007198, -2.345115,
  93. -0.343777, -0.344074, -0.221304, -0.153775, -0.494637, 1.743759, -0.590775, -0.413656, -0.389204, -0.221876,
  94. -0.159571, -0.163080, -0.513428, -0.775665, -0.891170, -3.118664, -1.247074, 0.913688, 1.009656, 1.170559,
  95. -0.761538, -0.755972, -0.773967, -0.674253, -0.978258, 1.514730, -0.145977, -0.620700, -0.857082, -0.765523,
  96. 1.344641, 1.329151, 1.633256, 2.020196, 1.777348, -1.744907, -5.928727, -4.032057, -0.585966, 1.072364,
  97. -0.468882, -0.486856, 0.935241, 2.032263, 2.219547, -0.225632, -3.438104, -4.412505, -0.550391, 2.234320,
  98. 3.177341, 3.204259, 2.749250, 1.741244, 1.197538, -2.985864, -6.084715, -1.447878, 0.904210, 1.495579,
  99. -0.998953, -1.005918, -0.988911, -0.863153, -1.003750, 1.256336, -0.471785, -0.860056, -0.872804, -0.629210,
  100. 1.957319, 1.966453, 1.840960, 1.405216, 1.313205, -0.956540, -3.535391, -2.280320, -1.179478, -0.458734,
  101. -0.326054, -0.331524, -0.134208, -0.218622, -0.158037, 3.128528, 4.020623, -1.129257, -1.524952, -1.377990,
  102. -0.390695, -0.381094, -0.341754, -0.272043, -0.588159, 2.297114, -0.116822, -0.507031, -0.563574, -0.534119,
  103. -0.250457, -0.240673, -0.210423, -0.217804, -0.453731, 1.784484, -0.142005, -0.230148, -0.339593, -0.298467,
  104. -0.177671, -0.183887, -0.191644, -0.205313, -0.441613, 1.599526, 0.023297, -0.322458, -0.539978, -0.457565,
  105. -0.149024, -0.140364, -0.142723, -0.066651, -0.344126, 1.830863, 0.154307, -0.171898, -0.343950, -0.379533,
  106. -0.155498, -0.154145, -0.181875, -0.189322, -0.122244, -3.037579, -1.476675, -0.089878, 0.004249, 0.169941,
  107. -1.786535, -1.809749, -1.445913, -1.050310, -0.095173, 2.964720, 4.706277, -0.649227, -1.362017, -1.447784,
  108. 0.034026, 0.038159, -0.018497, -0.067303, 0.059710, -2.908602, -1.484229, 0.108804, 0.292757, 0.566575,
  109. 0.527511, 0.518252, 0.762342, 1.148066, 0.772846, -2.113671, -2.704303, -0.664257, 0.460104, 1.295371,
  110. 1.370790, 1.383803, 1.340450, 0.634441, -0.596868, -2.427651, -2.352223, 0.454767, 1.405430, 1.838241,
  111. 1.455314, 1.464866, 2.487861, 2.464788, 1.963237, 0.324097, -1.869693, -2.554004, -2.022594, 1.114752,
  112. -0.664593, -0.687087, -0.075215, 0.583554, 0.927597, 3.671647, 3.835722, 0.694133, -2.007198, -2.345115,
  113. -0.343777, -0.344074, -0.221304, -0.153775, -0.494637, 1.743759, -0.590775, -0.413656, -0.389204, -0.221876,
  114. -0.159571, -0.163080, -0.513428, -0.775665, -0.891170, -3.118664, -1.247074, 0.913688, 1.009656, 1.170559,
  115. -0.761538, -0.755972, -0.773967, -0.674253, -0.978258, 1.514730, -0.145977, -0.620700, -0.857082, -0.765523,
  116. 1.344641, 1.329151, 1.633256, 2.020196, 1.777348, -1.744907, -5.928727, -4.032057, -0.585966, 1.072364,
  117. -0.468882, -0.486856, 0.935241, 2.032263, 2.219547, -0.225632, -3.438104, -4.412505, -0.550391, 2.234320,
  118. 3.177341, 3.204259, 2.749250, 1.741244, 1.197538, -2.985864, -6.084715, -1.447878, 0.904210, 1.495579,
  119. -0.998953, -1.005918, -0.988911, -0.863153, -1.003750, 1.256336, -0.471785, -0.860056, -0.872804, -0.629210,
  120. 1.957319, 1.966453, 1.840960, 1.405216, 1.313205, -0.956540, -3.535391, -2.280320, -1.179478, -0.458734,
  121. -0.326054, -0.331524, -0.134208, -0.218622, -0.158037, 3.128528, 4.020623, -1.129257, -1.524952, -1.377990,
  122. -0.390695, -0.381094, -0.341754, -0.272043, -0.588159, 2.297114, -0.116822, -0.507031, -0.563574, -0.534119,
  123. -0.250457, -0.240673, -0.210423, -0.217804, -0.453731, 1.784484, -0.142005, -0.230148, -0.339593, -0.298467,
  124. -0.177671, -0.183887, -0.191644, -0.205313, -0.441613, 1.599526, 0.023297, -0.322458, -0.539978, -0.457565,
  125. -0.149024, -0.140364, -0.142723, -0.066651, -0.344126, 1.830863, 0.154307, -0.171898, -0.343950, -0.379533,
  126. -0.155498, -0.154145, -0.181875, -0.189322, -0.122244, -3.037579, -1.476675, -0.089878, 0.004249, 0.169941,
  127. -1.786535, -1.809749, -1.445913, -1.050310, -0.095173, 2.964720, 4.706277, -0.649227, -1.362017, -1.447784,
  128. 0.034026, 0.038159, -0.018497, -0.067303, 0.059710, -2.908602, -1.484229, 0.108804, 0.292757, 0.566575,
  129. 0.527511, 0.518252, 0.762342, 1.148066, 0.772846, -2.113671, -2.704303, -0.664257, 0.460104, 1.295371,
  130. 1.370790, 1.383803, 1.340450, 0.634441, -0.596868, -2.427651, -2.352223, 0.454767, 1.405430, 1.838241,
  131. 1.455314, 1.464866, 2.487861, 2.464788, 1.963237, 0.324097, -1.869693, -2.554004, -2.022594, 1.114752,
  132. -0.664593, -0.687087, -0.075215, 0.583554, 0.927597, 3.671647, 3.835722, 0.694133, -2.007198, -2.345115,
  133. -0.343777, -0.344074, -0.221304, -0.153775, -0.494637, 1.743759, -0.590775, -0.413656, -0.389204, -0.221876,
  134. -0.159571, -0.163080, -0.513428, -0.775665, -0.891170, -3.118664, -1.247074, 0.913688, 1.009656, 1.170559,
  135. -0.761538, -0.755972, -0.773967, -0.674253, -0.978258, 1.514730, -0.145977, -0.620700, -0.857082, -0.765523,
  136. 1.344641, 1.329151, 1.633256, 2.020196, 1.777348, -1.744907, -5.928727, -4.032057, -0.585966, 1.072364,
  137. -0.468882, -0.486856, 0.935241, 2.032263, 2.219547, -0.225632, -3.438104, -4.412505, -0.550391, 2.234320,
  138. 3.177341, 3.204259, 2.749250, 1.741244, 1.197538, -2.985864, -6.084715, -1.447878, 0.904210, 1.495579,
  139. -0.998953, -1.005918, -0.988911, -0.863153, -1.003750, 1.256336, -0.471785, -0.860056, -0.872804, -0.629210,
  140. 1.957319, 1.966453, 1.840960, 1.405216, 1.313205, -0.956540, -3.535391, -2.280320, -1.179478, -0.458734,
  141. -0.326054, -0.331524, -0.134208, -0.218622, -0.158037, 3.128528, 4.020623, -1.129257, -1.524952, -1.377990,
  142. -0.390695, -0.381094, -0.341754, -0.272043, -0.588159, 2.297114, -0.116822, -0.507031, -0.563574, -0.534119,
  143. -0.250457, -0.240673, -0.210423, -0.217804, -0.453731, 1.784484, -0.142005, -0.230148, -0.339593, -0.298467,
  144. -0.177671, -0.183887, -0.191644, -0.205313, -0.441613, 1.599526, 0.023297, -0.322458, -0.539978, -0.457565,
  145. -0.149024, -0.140364, -0.142723, -0.066651, -0.344126, 1.830863, 0.154307, -0.171898, -0.343950, -0.379533,
  146. -0.155498, -0.154145, -0.181875, -0.189322, -0.122244, -3.037579, -1.476675, -0.089878, 0.004249, 0.169941,
  147. -1.786535, -1.809749, -1.445913, -1.050310, -0.095173, 2.964720, 4.706277, -0.649227, -1.362017, -1.447784,
  148. 0.034026, 0.038159, -0.018497, -0.067303, 0.059710, -2.908602, -1.484229, 0.108804, 0.292757, 0.566575,
  149. 0.527511, 0.518252, 0.762342, 1.148066, 0.772846, -2.113671, -2.704303, -0.664257, 0.460104, 1.295371,
  150. 1.370790, 1.383803, 1.340450, 0.634441, -0.596868, -2.427651, -2.352223, 0.454767, 1.405430, 1.838241,
  151. 1.455314, 1.464866, 2.487861, 2.464788, 1.963237, 0.324097, -1.869693, -2.554004, -2.022594, 1.114752,
  152. -0.664593, -0.687087, -0.075215, 0.583554, 0.927597, 3.671647, 3.835722, 0.694133, -2.007198, -2.345115,
  153. -0.343777, -0.344074, -0.221304, -0.153775, -0.494637, 1.743759, -0.590775, -0.413656, -0.389204, -0.221876,
  154. -0.159571, -0.163080, -0.513428, -0.775665, -0.891170, -3.118664, -1.247074, 0.913688, 1.009656, 1.170559,
  155. -0.761538, -0.755972, -0.773967, -0.674253, -0.978258, 1.514730, -0.145977, -0.620700, -0.857082, -0.765523,
  156. 1.344641, 1.329151, 1.633256, 2.020196, 1.777348, -1.744907, -5.928727, -4.032057, -0.585966, 1.072364,
  157. -0.468882, -0.486856, 0.935241, 2.032263, 2.219547, -0.225632, -3.438104, -4.412505, -0.550391, 2.234320,
  158. 3.177341, 3.204259, 2.749250, 1.741244, 1.197538, -2.985864, -6.084715, -1.447878, 0.904210, 1.495579,
  159. -0.998953, -1.005918, -0.988911, -0.863153, -1.003750, 1.256336, -0.471785, -0.860056, -0.872804, -0.629210,
  160. 1.957319, 1.966453, 1.840960, 1.405216, 1.313205, -0.956540, -3.535391, -2.280320, -1.179478, -0.458734,
  161. -0.326054, -0.331524, -0.134208, -0.218622, -0.158037, 3.128528, 4.020623, -1.129257, -1.524952, -1.377990
  162. },
  163. };
  164. static float **svm_vectors, *svm_coef;
  165. static int *vector, **matrix;
  166. //static float matr_speedup[NUM_OF_MATRICES][MAX_WORKERS_COUNT];
  167. //static int matr_times[NUM_OF_MATRICES][MAX_WORKERS_COUNT];
  168. static float Exec_Speedup[MAX_WORKERS_COUNT];
  169. static int Exec_Latencies[MAX_WORKERS_COUNT];
  170. //static float **vectors, *coef;
  171. //2*(N+rootN*pad_length)*sizeof(float)+PAGE_SIZE);
  172. static int P = 1; /* DEFAULT_P = 1 */
  173. static int M = 16; /* DEFAULT_M = 10 */
  174. static int N = 65536; /* N = 2^M */
  175. static int rootN = 256; /* rootN = sqrt(N) */
  176. static int num_cache_lines = 65536;
  177. #define PADLENGTH 2
  178. static float *x_local; /* x is the original time-domain data */
  179. static float *trans; /* trans is used as scratch space */
  180. static float *umain; /* umain is roots of unity for 1D FFTs */
  181. static float *umain2; /* umain2 is entire roots of unity matrix*/
  182. static float *upriv;
  183. void execute_workload_svm (int lower_bound, int upper_bound);
  184. void execute_workload_matrix (int lower_bound, int upper_bound);
  185. void matrix_transpose(int n1, float *src, float *dest, int node_id, int myFirst, int myLast, int pad_length);
  186. void FFT1D(int direction, int M, int N, float *x, float *scratch, float *upriv, float *umain2, int node_id, int myFirst, int myLast, int pad_length, int P);
  187. void copyColumn(int n1, float *src, float *dest);
  188. void single_FFT1D(int direction, int M, int N, float *u, float *x);
  189. void twiddle_Col(int direction, int n1, int N, int j, float *u, float *x, int pad_length);
  190. void reverse(int N, int M, float *x);
  191. int reverse_bit(int M, int k);
  192. void execute_workload_svm (int lower_bound, int upper_bound) {
  193. int i = 0, j = 0;
  194. float diff = 0, norma = 0, local_sum[N_sv];
  195. int vector_id = 0;
  196. if (base_offset == -1) {
  197. base_offset = cur_agent.my_agent * N_sv;
  198. //fprintf(log_file, "My agent is %d. Calculated base_offset is %d\n",cur_agent.my_agent,base_offset);
  199. }
  200. for (i = lower_bound; i <= upper_bound; i++) {
  201. local_sum[i] = 0;
  202. scc_signals_check();
  203. for (j = 0; j < D_sv; j++){
  204. diff = input_vector[vector_id][j] - svm_vectors[j][i];
  205. norma += diff*diff;
  206. }
  207. local_sum[i] += (float) (exp((double) (-gamma*norma))*svm_coef[i]);
  208. norma = 0;
  209. }
  210. /*
  211. for (i=lower_bound; i<=upper_bound; i++)
  212. manager_result_out[base_offset+i] = (int) local_sum[i];
  213. */
  214. }
  215. void execute_workload_matrix (int lower_bound, int upper_bound) {
  216. int i, j, local_sum[MAX_ARRAY_SIZE];
  217. if (base_offset == -1) {
  218. //matrix_out = (int*) shmat (cur_agent.segment_id, NULL, 0);
  219. base_offset = cur_agent.my_agent * MAX_ARRAY_SIZE;
  220. }
  221. for (i=lower_bound; i<=upper_bound; i++) {
  222. local_sum[i] = 0;
  223. scc_signals_check();
  224. //signals_enable();
  225. for (j=0; j<cur_agent.array_size; j++)
  226. local_sum[i] += matrix[i][j] * vector[j];
  227. //signals_disable();
  228. }
  229. for (i=lower_bound; i<=upper_bound; i++)
  230. manager_result_out[base_offset+i] = local_sum[i];
  231. }
  232. void execute_workload_fft (int lower_bound, int upper_bound) {
  233. int work_id = 0, pad_length = PADLENGTH;
  234. if ((lower_bound == 0) && (upper_bound == FFT_MAX)) {
  235. P = 1;
  236. } else {
  237. P = 2;
  238. }
  239. /* FIXME works only because fft is restricted to two workers */
  240. if (lower_bound > 0) {
  241. work_id = 1;
  242. }
  243. FFT1D(1, M, N, x_local, trans, upriv, umain2, work_id, lower_bound, upper_bound, pad_length, P); //HACK node_id - 1 important!!
  244. }
  245. void execute_workload (int lower_bound, int upper_bound) {
  246. if (executed_app == MATRIX_MUL) {
  247. execute_workload_matrix (lower_bound, upper_bound);
  248. } else if (executed_app == SVM) {
  249. execute_workload_svm (lower_bound, upper_bound);
  250. } else if (executed_app == FFT) {
  251. execute_workload_fft (lower_bound, upper_bound);
  252. }
  253. }
  254. void init_speedup_structs (void) {
  255. if (executed_app == MATRIX_MUL) {
  256. if (MATRIX_ARRAY_SIZE == 1024) {
  257. #ifdef PLAT_SCC
  258. Exec_Speedup[0] = 1.0;
  259. Exec_Speedup[1] = 1.188;
  260. Exec_Speedup[2] = 2.264;
  261. Exec_Speedup[3] = 3.0;
  262. Exec_Speedup[4] = 3.429;
  263. Exec_Speedup[5] = 4.0;
  264. Exec_Speedup[6] = 8.0;
  265. Exec_Speedup[7] = 0.0;
  266. Exec_Latencies[0] = 120;//29352;
  267. Exec_Latencies[1] = 101;//15112;
  268. Exec_Latencies[2] = 53;//11194;
  269. Exec_Latencies[3] = 40;//10313;
  270. Exec_Latencies[4] = 35;//8645;
  271. Exec_Latencies[5] = 30;//7871;
  272. Exec_Latencies[6] = 15;//6715;
  273. #else
  274. Exec_Speedup[0] = 1.0;
  275. Exec_Speedup[1] = 1.065;
  276. Exec_Speedup[2] = 1.270;
  277. Exec_Speedup[3] = 0.0;
  278. Exec_Speedup[4] = 0.0;
  279. Exec_Speedup[5] = 0.0;
  280. Exec_Speedup[6] = 0.0;
  281. Exec_Speedup[7] = 0.0;
  282. Exec_Latencies[0] = 100000000;//29352;
  283. Exec_Latencies[1] = 31;//15112;
  284. Exec_Latencies[2] = 29;//11194;
  285. Exec_Latencies[3] = 24;//10313;
  286. Exec_Latencies[4] = 0;//8645;
  287. Exec_Latencies[5] = 0;//7871;
  288. Exec_Latencies[6] = 0;//6715;
  289. Exec_Latencies[7] = 0;//7014;
  290. #endif
  291. } else if (MATRIX_ARRAY_SIZE == 2048) {
  292. #ifdef PLAT_SCC
  293. Exec_Speedup[0] = 1.0;
  294. Exec_Speedup[1] = 1.091;
  295. Exec_Speedup[2] = 1.2;
  296. Exec_Speedup[3] = 1.491;
  297. Exec_Speedup[4] = 1.791;
  298. Exec_Speedup[5] = 2.824;
  299. Exec_Speedup[6] = 3.0;
  300. Exec_Latencies[0] = 240;//112276;
  301. Exec_Latencies[1] = 220;//58880;
  302. Exec_Latencies[2] = 200;//40305;
  303. Exec_Latencies[3] = 161;//31705;
  304. Exec_Latencies[4] = 134;//28309;
  305. Exec_Latencies[5] = 85;//24512;
  306. Exec_Latencies[6] = 80;//22239;
  307. //matr_times[1][7] = 23;//20332;
  308. #else
  309. Exec_Speedup[0] = 1.0;
  310. Exec_Speedup[1] = 1.331;
  311. Exec_Speedup[2] = 2.009;
  312. Exec_Speedup[3] = 2.315;
  313. Exec_Speedup[4] = 2.572;
  314. Exec_Speedup[5] = 0.0;
  315. Exec_Speedup[6] = 0.0;
  316. Exec_Speedup[7] = 0.0;//5.522;
  317. Exec_Latencies[0] = 100000000;//112276;
  318. Exec_Latencies[1] = 116;//58880;
  319. Exec_Latencies[2] = 87;//40305;
  320. Exec_Latencies[3] = 58;//31705;
  321. Exec_Latencies[4] = 50;//28309;
  322. Exec_Latencies[5] = 45;//24512;
  323. Exec_Latencies[6] = 0;//22239;
  324. Exec_Latencies[7] = 0;//20332;
  325. #endif
  326. } else if (MATRIX_ARRAY_SIZE == 4096) {
  327. #ifdef PLAT_SCC
  328. Exec_Speedup[0] = 1.0;
  329. Exec_Speedup[1] = 2.001;
  330. Exec_Speedup[2] = 2.976;
  331. Exec_Speedup[3] = 4.032;
  332. Exec_Speedup[4] = 5.034;
  333. Exec_Speedup[5] = 6.25;
  334. Exec_Speedup[6] = 6.678;
  335. Exec_Speedup[7] = 6.819;
  336. Exec_Latencies[0] = 750;//384005;
  337. Exec_Latencies[1] = 374;//231583;
  338. Exec_Latencies[2] = 252;//157966;
  339. Exec_Latencies[3] = 186;//121222;
  340. Exec_Latencies[4] = 149;//101208;
  341. Exec_Latencies[5] = 120;//87852;
  342. Exec_Latencies[6] = 110;//78093;
  343. #else
  344. Exec_Speedup[0] = 1.0;
  345. Exec_Speedup[1] = 1.517;
  346. Exec_Speedup[2] = 1.958;
  347. Exec_Speedup[3] = 2.112;
  348. Exec_Speedup[4] = 2.878;
  349. Exec_Speedup[5] = 3.338;
  350. Exec_Speedup[6] = 4.241;
  351. Exec_Speedup[7] = 0.0;//5.073;
  352. Exec_Latencies[0] = 100000000;//384005;
  353. Exec_Latencies[1] = 431;//231583;
  354. Exec_Latencies[2] = 284;//157966;
  355. Exec_Latencies[3] = 220;//121222;
  356. Exec_Latencies[4] = 204;//101208;
  357. Exec_Latencies[5] = 150;//87852;
  358. Exec_Latencies[6] = 129;//78093;
  359. Exec_Latencies[7] = 102;//75690;
  360. #endif
  361. } else {
  362. printf("Unknown array size\n");
  363. exit(0);
  364. }
  365. } else if (executed_app == SVM) {
  366. Exec_Speedup[0] = 1.0; /* 1 worker */
  367. Exec_Speedup[1] = 2.006;
  368. Exec_Speedup[2] = 2.814;
  369. Exec_Speedup[3] = 3.469;
  370. Exec_Speedup[4] = 4.029;
  371. Exec_Speedup[5] = 4.285;
  372. Exec_Speedup[6] = 4.646;
  373. Exec_Speedup[7] = 0.0;
  374. Exec_Latencies[0] = 28;
  375. Exec_Latencies[1] = 14;
  376. Exec_Latencies[2] = 10;
  377. Exec_Latencies[3] = 8;
  378. Exec_Latencies[4] = 7;
  379. Exec_Latencies[5] = 7;
  380. Exec_Latencies[6] = 6;
  381. Exec_Latencies[7] = 6;
  382. } else if (executed_app == FFT) {
  383. Exec_Speedup[0] = 1.0; /* 1 worker */
  384. Exec_Speedup[1] = 1.55;
  385. Exec_Speedup[2] = 0;
  386. Exec_Speedup[3] = 0;
  387. Exec_Speedup[4] = 0;
  388. Exec_Speedup[5] = 0;
  389. Exec_Speedup[6] = 0;
  390. Exec_Speedup[7] = 0;
  391. Exec_Latencies[0] = 772;
  392. Exec_Latencies[1] = 498;
  393. Exec_Latencies[2] = 0;
  394. Exec_Latencies[3] = 0;
  395. Exec_Latencies[4] = 0;
  396. Exec_Latencies[5] = 0;
  397. Exec_Latencies[6] = 0;
  398. Exec_Latencies[7] = 0;
  399. }
  400. }
  401. void app_init (char scen_directory[SCEN_DIR_SIZE], char scen_num[SCEN_NUM_SIZE]) {
  402. int i, j, pad_length = PADLENGTH;
  403. char buf[MAX_STR_NAME_SIZE], *buffer;
  404. FILE *matrix_input, *support_vectors_file, *coef_file, *umain_file, *umain2_file, *x_local_file;
  405. size_t bufsize = 32;
  406. if (executed_app == MATRIX_MUL) {
  407. cur_agent.array_size = MATRIX_ARRAY_SIZE;
  408. matrix = (int **) malloc(cur_agent.array_size * sizeof(int *));
  409. #ifdef PLAT_SCC
  410. strcpy(buf, "/shared/herc/");
  411. #else
  412. strcpy(buf, "../");
  413. #endif
  414. strcat(buf, scen_directory);
  415. strcat(buf, "/MATRIX-inputs/");
  416. strcat(buf, itoa(cur_agent.array_size));
  417. fprintf(log_file,"matrix file path = %s\n",buf);
  418. if ((matrix_input = fopen(buf, "r")) == NULL){
  419. printf("Cannot open input file with file path = %s ",buf);
  420. perror("open matrix_input");
  421. }
  422. for (i=0; i<cur_agent.array_size; i++) {
  423. matrix[i] = (int *) malloc(cur_agent.array_size * sizeof(int));
  424. for (j=0; j<cur_agent.array_size; j++)
  425. fscanf(matrix_input,"%d",&matrix[i][j]);
  426. }
  427. vector = (int *) malloc(cur_agent.array_size * sizeof(int));
  428. for (j=0; j<cur_agent.array_size; j++)
  429. fscanf(matrix_input,"%d",&vector[j]);
  430. fclose(matrix_input);
  431. } else if (executed_app == SVM) {
  432. #ifdef PLAT_SCC
  433. strcpy(buf, "/shared/herc/");
  434. #else
  435. strcpy(buf, "../");
  436. #endif
  437. strcat(buf,scen_directory);
  438. //strcat(buf,"/");
  439. //strcat(buf,scen_num);
  440. strcat(buf,"/SVM-inputs/support_vectors_N_sv_");
  441. strcat(buf,itoa(N_sv));
  442. strcat(buf,"_D_sv_");
  443. strcat(buf,itoa(D_sv));
  444. strcat(buf,".dat");
  445. fprintf(log_file,"svm file path = %s\n",buf);
  446. if ((support_vectors_file = fopen(buf,"r")) == NULL){
  447. printf("Cannot open input file with file path = %s ",buf);
  448. perror("open svm_input");
  449. }
  450. #ifdef PLAT_SCC
  451. strcpy(buf, "/shared/herc/");
  452. #else
  453. strcpy(buf, "../");
  454. #endif
  455. strcat(buf,scen_directory);
  456. //strcat(buf,"/");
  457. //strcat(buf,scen_num);
  458. strcat(buf,"/SVM-inputs/sv_coef_N_sv_");
  459. strcat(buf,itoa(N_sv));
  460. strcat(buf,"_D_sv_");
  461. strcat(buf,itoa(D_sv));
  462. strcat(buf,".dat");
  463. fprintf(log_file,"svm_coef file path = %s\n",buf);
  464. if ((coef_file = fopen(buf,"r")) == NULL){
  465. printf("Cannot open input file with file path = %s ",buf);
  466. perror("open svm_input");
  467. }
  468. cur_agent.array_size = N_sv;
  469. svm_vectors = (float **)malloc((D_sv)*sizeof(float *));
  470. if (svm_vectors == NULL){
  471. printf("--%d-- svm_vectors malloc fail!!\n", node_id);
  472. perror("malloc error");
  473. }
  474. svm_coef = (float *)malloc((cur_agent.array_size)*sizeof(float));
  475. if (svm_coef == NULL){
  476. printf("--%d-- svm_coef malloc fail!!\n", node_id);
  477. perror("malloc error");
  478. }
  479. buffer = (char *)malloc(bufsize * sizeof(char));
  480. for (i = 0; i < D_sv; i++) {
  481. svm_vectors[i] = (float *)malloc((cur_agent.array_size)*sizeof(float));
  482. if (svm_vectors[i] == NULL) {
  483. printf("--%d-- svm_vectors[%d] malloc fail!!\n", node_id, i);
  484. perror("malloc error");
  485. } else {
  486. for (j = 0; j < N_sv; j++) {
  487. /* Read support svm_vectors */
  488. if (j < cur_agent.array_size){
  489. fscanf(support_vectors_file,"%f",&svm_vectors[i][j]);
  490. fgetc(support_vectors_file);
  491. }else{
  492. getline(&buffer,&bufsize,support_vectors_file);
  493. }
  494. }
  495. }
  496. }
  497. for (j = 0; j < N_sv; j++) {
  498. /* Read coefficients */
  499. fscanf(coef_file,"%f",&svm_coef[j]);
  500. fgetc(coef_file);
  501. }
  502. cur_agent.array_size = -1;
  503. fclose(support_vectors_file);
  504. fclose(coef_file);
  505. free(buffer);
  506. } else if (executed_app == FFT) {
  507. fprintf(log_file,"Initializing FFT application\n");
  508. x_local = (float *)malloc(2*(N+rootN*pad_length)*sizeof(float)+PAGE_SIZE);
  509. if (x_local == NULL){
  510. printf("Malloc error for x_local\n");
  511. perror("malloc error");
  512. exit(-1);
  513. }
  514. trans = (float *)malloc(2*(N+rootN*pad_length)*sizeof(float)+PAGE_SIZE);
  515. if (trans == NULL){
  516. printf("Malloc error for trans\n");
  517. perror("malloc error");
  518. exit(-1);
  519. }
  520. umain = (float *)malloc(2*rootN*sizeof(float));
  521. if (umain == NULL){
  522. printf("Malloc error for umain\n");
  523. perror("malloc error");
  524. exit(-1);
  525. }
  526. umain2 = (float *)malloc(2*(N+rootN*pad_length)*sizeof(float)+PAGE_SIZE);
  527. if (umain2 == NULL){
  528. printf("Malloc error for umain2\n");
  529. perror("malloc error");
  530. exit(-1);
  531. }
  532. upriv = (float *)malloc(2*(rootN-1)*sizeof(float));
  533. if (upriv == NULL){
  534. printf("--%d-- Malloc error for upriv\n", node_id);
  535. perror("malloc error");
  536. exit(-1);
  537. }
  538. #ifdef PLAT_SCC
  539. strcpy(buf, "/shared/herc/");
  540. #else
  541. strcpy(buf, "../");
  542. #endif
  543. strcat(buf,scen_directory);
  544. //strcat(buf,"/");
  545. //strcat(buf,scen_num);
  546. strcat(buf,"/FFT-inputs/umain_file");
  547. fprintf(log_file,"umain_file file path = %s\n",buf);
  548. if ((umain_file = fopen(buf,"r")) == NULL){
  549. printf("Cannot open input file with file path = %s ",buf);
  550. perror("open fft_input");
  551. }
  552. for (i=0; i<2*rootN; i++) {
  553. fscanf(umain_file,"%f",&umain[i]);
  554. }
  555. fclose(umain_file);
  556. #ifdef PLAT_SCC
  557. strcpy(buf, "/shared/herc/");
  558. #else
  559. strcpy(buf, "../");
  560. #endif
  561. strcat(buf,scen_directory);
  562. //strcat(buf,"/");
  563. //strcat(buf,scen_num);
  564. strcat(buf,"/FFT-inputs/umain2_file");
  565. fprintf(log_file,"umain2_file file path = %s\n",buf);
  566. if ((umain2_file = fopen(buf,"r")) == NULL){
  567. printf("Cannot open input file with file path = %s ",buf);
  568. perror("open umain_file");
  569. }
  570. //for (i=0; i<2*(N+rootN*pad_length)+PAGE_SIZE; i++) {
  571. for (i=0; i<2*(N+rootN*pad_length); i++) {
  572. fscanf(umain2_file,"%f",&umain2[i]);
  573. }
  574. fclose(umain2_file);
  575. #ifdef PLAT_SCC
  576. strcpy(buf, "/shared/herc/");
  577. #else
  578. strcpy(buf, "../");
  579. #endif
  580. strcat(buf,scen_directory);
  581. //strcat(buf,"/");
  582. //strcat(buf,scen_num);
  583. strcat(buf,"/FFT-inputs/x_local_file");
  584. fprintf(log_file,"x_local_file file path = %s\n",buf);
  585. if ((x_local_file = fopen(buf,"r")) == NULL){
  586. printf("Cannot open input file with file path = %s ",buf);
  587. perror("open x_local_file");
  588. }
  589. //for (i=0;i<2*(N+rootN*pad_length)+PAGE_SIZE;i++) {
  590. for (i=0; i<2*(N+rootN*pad_length); i++) {
  591. fscanf(x_local_file,"%f",&x_local[i]);
  592. }
  593. fclose(x_local_file);
  594. for (i = 0; i < 2*(rootN-1); i++){
  595. upriv[i] = umain[i];
  596. }
  597. }
  598. }
  599. int get_max_cores_count(app cur_app){
  600. /*if (cur_app.var < 1.0)
  601. return (int) ceilf(2.0*cur_app.A - 1);
  602. else
  603. return (int) ceilf(cur_app.A + cur_app.A*cur_app.var - cur_app.var);*/
  604. #ifdef SINGLE_WORKER
  605. return 2;
  606. #else
  607. if (executed_app == FFT) {
  608. return 3;
  609. } else {
  610. return MAX_WORKERS_COUNT;
  611. }
  612. #endif
  613. }
  614. float Speedup(app cur_app, int num_of_cores) {
  615. /*
  616. int type;
  617. if (cur_app.array_size == 1024) type = 0;
  618. else if (cur_app.array_size == 2048) type = 1;
  619. else if (cur_app.array_size == 4096) type = 2;
  620. else {
  621. fprintf(log_file, "Unknown array size = %d\n",cur_app.array_size);
  622. fflush(log_file);
  623. return 0.0;
  624. }
  625. return matr_speedup[type][num_of_cores-1];
  626. */
  627. if (num_of_cores > get_max_cores_count(cur_app)) {
  628. return 0;
  629. } else {
  630. return Exec_Speedup[num_of_cores-2];
  631. }
  632. }
  633. int get_times(app cur_app, int num_of_cores) {
  634. /*
  635. int type;
  636. if (cur_app.array_size == 1024) type = 0;
  637. else if (cur_app.array_size == 2048) type = 1;
  638. else if (cur_app.array_size == 4096) type = 2;
  639. else {
  640. fprintf(log_file, "Unknown array size = %d\n",cur_app.array_size);
  641. fflush(log_file);
  642. return 0.0;
  643. }
  644. return (cur_app.workld * matr_times[type][num_of_cores-2]);
  645. */
  646. return (cur_app.workld * Exec_Latencies[num_of_cores-2]);
  647. }
  648. void matrix_transpose(int n1, float *src, float *dest, int node_id, int myFirst, int myLast, int pad_length){
  649. int i;
  650. int j;
  651. int k;
  652. int l;
  653. int m;
  654. int blksize;
  655. int numblks;
  656. int firstfirst;
  657. int h_off;
  658. int v_off;
  659. int v;
  660. int h;
  661. int n1p;
  662. int row_count;
  663. //fprintf(log_file,"I am inside matrix_transpose-0 node_id is %d n1 %d\n",node_id,n1);
  664. blksize = myLast-myFirst;
  665. numblks = (2*blksize)/num_cache_lines;
  666. if (numblks * num_cache_lines != 2 * blksize) {
  667. numblks ++;
  668. }
  669. blksize = blksize / numblks;
  670. firstfirst = myFirst;
  671. row_count = n1/P;
  672. n1p = n1+pad_length;
  673. for (l=node_id+1;l<P;l++) {
  674. v_off = l*row_count;
  675. for (k=0; k<numblks; k++) {
  676. h_off = firstfirst;
  677. for (m=0; m<numblks; m++) {
  678. for (i=0; i<blksize; i++) {
  679. v = v_off + i;
  680. for (j=0; j<blksize; j++) {
  681. h = h_off + j;
  682. //fprintf(log_file,"Index dest is %d\n",2*(h*n1p+v));
  683. //fprintf(log_file,"Index src is %d\n",2*(v*n1p+h));
  684. //fprintf(log_file,"src = %f\n",src[2*(v*n1p+h)]);
  685. //fprintf(log_file,"src + 1 = %f\n",src[2*(v*n1p+h)+1]);
  686. //fprintf(log_file,"dest = %f\n",dest[2*(h*n1p+v)]);
  687. //fprintf(log_file,"dest + 1 = %f\n",dest[2*(h*n1p+v)+1]);
  688. //fflush(log_file);
  689. dest[2*(h*n1p+v)] = src[2*(v*n1p+h)];
  690. dest[2*(h*n1p+v)+1] = src[2*(v*n1p+h)+1];
  691. //fprintf(log_file,"yolo\n");
  692. }
  693. }
  694. h_off += blksize;
  695. }
  696. v_off+=blksize;
  697. }
  698. }
  699. //fprintf(log_file,"I am inside matrix_transpose-A\n");
  700. for (l=0;l<node_id;l++) {
  701. v_off = l*row_count;
  702. for (k=0; k<numblks; k++) {
  703. h_off = firstfirst;
  704. for (m=0; m<numblks; m++) {
  705. for (i=0; i<blksize; i++) {
  706. v = v_off + i;
  707. for (j=0; j<blksize; j++) {
  708. h = h_off + j;
  709. dest[2*(h*n1p+v)] = src[2*(v*n1p+h)];
  710. dest[2*(h*n1p+v)+1] = src[2*(v*n1p+h)+1];
  711. }
  712. }
  713. h_off += blksize;
  714. }
  715. v_off+=blksize;
  716. }
  717. }
  718. //fprintf(log_file,"I am inside matrix_transpose-B\n");
  719. v_off = node_id*row_count;
  720. for (k=0; k<numblks; k++) {
  721. h_off = firstfirst;
  722. for (m=0; m<numblks; m++) {
  723. for (i=0; i<blksize; i++) {
  724. v = v_off + i;
  725. for (j=0; j<blksize; j++) {
  726. h = h_off + j;
  727. dest[2*(h*n1p+v)] = src[2*(v*n1p+h)];
  728. dest[2*(h*n1p+v)+1] = src[2*(v*n1p+h)+1];
  729. }
  730. }
  731. h_off += blksize;
  732. }
  733. v_off+=blksize;
  734. }
  735. //fprintf(log_file,"I am inside matrix_transpose-C\n");
  736. }
  737. //FFT1D(1, M, N, x_local, trans, upriv, umain2, work_id, lower_bound, upper_bound, pad_length, P);
  738. void FFT1D(int direction, int M, int N, float *x, float *scratch, float *upriv, float *umain2, int node_id, int myFirst, int myLast, int pad_length, int P){
  739. int j, m1, n1;
  740. printf("I am %d and I am inside FFT1D\n",node_id);
  741. //fprintf(log_file,"I am inside FFT1D-A myFirst=%d myLast=%d\n",myFirst,myLast);
  742. m1 = M/2;
  743. n1 = 1 << m1;
  744. matrix_transpose(n1, x, scratch, node_id, myFirst, myLast, pad_length);
  745. //fprintf(log_file,"I am inside FFT1D-B\n");
  746. /* do n1 1D FFTs on columns */
  747. for (j = myFirst; j < myLast; j++){
  748. single_FFT1D(direction, m1, n1, upriv, &scratch[2*j*(n1+pad_length)]);
  749. twiddle_Col(direction, n1, N, j, umain2, &scratch[2*j*(n1+pad_length)],pad_length);
  750. }
  751. //fprintf(log_file,"I am inside FFT1D-C\n");
  752. matrix_transpose(n1, scratch, x, node_id, myFirst, myLast, pad_length);
  753. //fprintf(log_file,"I am inside FFT1D-D\n");
  754. /* do n1 1D FFTs on columns again */
  755. for (j = myFirst; j < myLast; j++) {
  756. single_FFT1D(direction, m1, n1, upriv, &x[2*j*(n1+pad_length)]);
  757. }
  758. //fprintf(log_file,"I am inside FFT1D-E\n");
  759. matrix_transpose(n1, x, scratch, node_id, myFirst, myLast, pad_length);
  760. //fprintf(log_file,"I am inside FFT1D-F\n");
  761. /*for (j = myFirst; j < myLast; j++){
  762. copyColumn(n1, &scratch[2*j*(n1+pad_length)], &x_shared[2*j*(n1+pad_length)]);
  763. }*/
  764. return;
  765. }
  766. void copyColumn(int n1, float *src, float *dest){
  767. int i;
  768. for (i = 0; i < n1; i++) {
  769. dest[2*i] = src[2*i];
  770. dest[2*i+1] = src[2*i+1];
  771. }
  772. }
  773. void single_FFT1D(int direction, int M, int N, float *u, float *x){
  774. int j, k, q, L, r, Lstar;
  775. float *u1, *x1, *x2;
  776. float omega_r, omega_c, tau_r, tau_c, x_r, x_c;
  777. reverse(N, M, x);
  778. for (q=1; q<=M; q++) {
  779. L = 1<<q; r = N/L; Lstar = L/2;
  780. u1 = &u[2*(Lstar-1)];
  781. for (k=0; k<r; k++) {
  782. x1 = &x[2*(k*L)];
  783. x2 = &x[2*(k*L+Lstar)];
  784. for (j=0; j<Lstar; j++) {
  785. omega_r = u1[2*j];
  786. omega_c = direction*u1[2*j+1];
  787. x_r = x2[2*j];
  788. x_c = x2[2*j+1];
  789. tau_r = omega_r*x_r - omega_c*x_c;
  790. tau_c = omega_r*x_c + omega_c*x_r;
  791. x_r = x1[2*j];
  792. x_c = x1[2*j+1];
  793. x2[2*j] = x_r - tau_r;
  794. x2[2*j+1] = x_c - tau_c;
  795. x1[2*j] = x_r + tau_r;
  796. x1[2*j+1] = x_c + tau_c;
  797. }
  798. }
  799. }
  800. return;
  801. }
  802. void twiddle_Col(int direction, int n1, int N, int j, float *u, float *x, int pad_length){
  803. int i;
  804. float omega_c, omega_r, x_r, x_c;
  805. for (i = 0; i < n1; i++) {
  806. omega_r = u[2*(j*(n1+pad_length)+i)];
  807. omega_c = direction*u[2*(j*(n1+pad_length)+i)+1];
  808. x_r = x[2*i];
  809. x_c = x[2*i+1];
  810. x[2*i] = omega_r*x_r - omega_c*x_c;
  811. x[2*i+1] = omega_r*x_c + omega_c*x_r;
  812. }
  813. return;
  814. }
  815. void reverse(int N, int M, float *x){
  816. int j, k;
  817. for (k = 0; k < N; k++){
  818. j = reverse_bit(M, k);
  819. if (j > k){
  820. SWAP(x[2*j], x[2*k]);
  821. SWAP(x[2*j+1], x[2*k+1]);
  822. }
  823. }
  824. return;
  825. }
  826. int reverse_bit(int M, int k){
  827. int i, j = 0, tmp = k;
  828. for (i = 0; i < M; i++){
  829. j = 2*j + (tmp&0x1);
  830. tmp = tmp >> 1;
  831. }
  832. return j;
  833. }