Advertisement
Guest User

Untitled

a guest
Oct 12th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.93 KB | None | 0 0
  1.  
  2. #if defined(INTELFPGA_CL)
  3. #define UTL_ENABLE_CHANNELS _Pragma("OPENCL EXTENSION cl_intel_channels : enable")
  4. #define UTL_READ_CH(ch) read_channel_intel(ch)
  5. #define UTL_WRITE_CH(ch, dat) write_channel_intel(ch, dat)
  6. #else
  7. #define UTL_ENABLE_CHANNELS _Pragma("OPENCL_EXTENSION cl_altera_channels : enable")
  8. #define UTL_READ_CH(ch) read_channel_altera(ch)
  9. #define UTL_WRITE_CH(ch, dat) write_channel_altera(ch, dat)
  10. #endif
  11.  
  12. UTL_ENABLE_CHANNELS
  13.  
  14. #define DATA_SIZE 4
  15. #define VEC_SIZE 4
  16.  
  17. typedef struct {
  18.     char d[DATA_SIZE];
  19. } data_t;
  20.  
  21. typedef struct {
  22.     data_t v[VEC_SIZE];
  23. } data_ch_t;
  24.  
  25. typedef struct {
  26.     char v[VEC_SIZE];
  27. } ch_t;
  28.  
  29. channel ch_t ch_1 __attribute((depth(0)));
  30. channel data_ch_t ch_2 __attribute((depth(0)));
  31. channel data_ch_t ch_3 __attribute((depth(0)));
  32. channel ch_t ch_4 __attribute((depth(0)));
  33.  
  34. __kernel
  35. __attribute((task))
  36. void k1(__global const ch_t* restrict data1,
  37.         __global const data_ch_t* restrict data2,
  38.         __global const data_t* restrict data3,
  39.         const int l1,
  40.         const int l2) {
  41.     data_t buf_d3[2][2];
  42.     data_ch_t buf_d2[8];
  43.  
  44.     #pragma loop_coalesce 2
  45.     for (int i = 0; i < l1; ++i) {
  46.         for (int j = 0; j < l2; ++j) {
  47.             buf_d3[0][j] = data3[j];
  48.             buf_d2[j] = data2[j];
  49.  
  50.             UTL_WRITE_CH(ch_1, data1[j]);
  51.             UTL_WRITE_CH(ch_2, buf_d2[i]);
  52.  
  53.             data_ch_t dch;
  54.             dch.v[0] = buf_d3[0][j];
  55.             UTL_WRITE_CH(ch_3, dch);
  56.         }
  57.     }
  58. }
  59.  
  60. __kernel
  61. __attribute((task))
  62. void k2(const int l1, const int l2) {
  63.     for (int i = 0; i < l1; ++i) {
  64.         ch_t t;
  65.         for (int j = 0; j < l2; ++j) {
  66.             const data_ch_t d3 = UTL_READ_CH(ch_3);
  67.             const data_ch_t d2 = UTL_READ_CH(ch_2);
  68.             t.v[0] += d2.v[0].d[0] * d3.v[0].d[0];
  69.  
  70.             const ch_t d1 = UTL_READ_CH(ch_1);
  71.             t.v[0] += d1.v[0];
  72.         }
  73.  
  74.         UTL_WRITE_CH(ch_4, t);
  75.     }
  76. }
  77.  
  78. __kernel
  79. __attribute((task))
  80. void k3(__global char* restrict output, const int l1) {
  81.     for (int j = 0; j < l1; ++j) {
  82.         ch_t dat = UTL_READ_CH(ch_4);
  83.         output[j] = dat.v[0];
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement