RCCE.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. //
  2. // Copyright 2010 Intel Corporation
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. #ifndef RCCE_H
  17. #define RCCE_H
  18. #include <stdlib.h>
  19. #include <stdio.h>
  20. #define RCCE_VERSION "1.1.0.x"
  21. #define _RCCE
  22. // little trick to allow the application to be called "RCCE_APP" under
  23. // OpenMP, and "main" otherwise
  24. #ifndef _OPENMP
  25. #define RCCE_APP main
  26. #endif
  27. // modify next line for Intel BareMetal, which supports stdout, but not stdferr
  28. #define STDERR stdout
  29. #define LOG2_LINE_SIZE 5
  30. #define RCCE_LINE_SIZE (1<<LOG2_LINE_SIZE)
  31. // RCCE_BUFF_SIZE_MAX is space per UE, which is half of the space per tile
  32. #define RCCE_BUFF_SIZE_MAX (1<<13)
  33. #ifdef SHMADD
  34. //64MB
  35. //#define RCCE_SHM_SIZE_MAX 0x4000000
  36. // 128MB
  37. //#define RCCE_SHM_SIZE_MAX 0x8000000
  38. // 256MB
  39. //#define RCCE_SHM_SIZE_MAX 0x10000000
  40. // 512MB
  41. #define RCCE_SHM_SIZE_MAX 0x20000000
  42. // 960MB
  43. //#define RCCE_SHM_SIZE_MAX 0x3C000000
  44. #else
  45. // 64MB
  46. #define RCCE_SHM_SIZE_MAX (1<<26)
  47. #endif
  48. #define RCCE_MAXNP 48
  49. #define RCCE_SUCCESS 0
  50. #define RCCE_ERROR_BASE 1234321
  51. #define RCCE_ERROR_TARGET (RCCE_ERROR_BASE + 1)
  52. #define RCCE_ERROR_SOURCE (RCCE_ERROR_BASE + 2)
  53. #define RCCE_ERROR_ID (RCCE_ERROR_BASE + 3)
  54. #define RCCE_ERROR_MESSAGE_LENGTH (RCCE_ERROR_BASE + 4)
  55. #define RCCE_ERROR_FLAG_UNDEFINED (RCCE_ERROR_BASE + 5)
  56. #define RCCE_ERROR_NUM_UES (RCCE_ERROR_BASE + 6)
  57. #define RCCE_ERROR_DATA_OVERLAP (RCCE_ERROR_BASE + 7)
  58. #define RCCE_ERROR_ALIGNMENT (RCCE_ERROR_BASE + 8)
  59. #define RCCE_ERROR_DEBUG_FLAG (RCCE_ERROR_BASE + 9)
  60. #define RCCE_ERROR_FLAG_NOT_IN_COMM_BUFFER (RCCE_ERROR_BASE + 10)
  61. #define RCCE_ERROR_FLAG_STATUS_UNDEFINED (RCCE_ERROR_BASE + 11)
  62. #define RCCE_ERROR_FLAG_NOT_ALLOCATED (RCCE_ERROR_BASE + 12)
  63. #define RCCE_ERROR_VAL_UNDEFINED (RCCE_ERROR_BASE + 13)
  64. #define RCCE_ERROR_INVALID_ERROR_CODE (RCCE_ERROR_BASE + 14)
  65. #define RCCE_ERROR_RPC_NOT_ALLOCATED (RCCE_ERROR_BASE + 15)
  66. #define RCCE_ERROR_RPC_INTERNAL (RCCE_ERROR_BASE + 16)
  67. #define RCCE_ERROR_MULTIPLE_RPC_REQUESTS (RCCE_ERROR_BASE + 17)
  68. #define RCCE_ERROR_FDIVIDER (RCCE_ERROR_BASE + 18)
  69. #define RCCE_ERROR_FREQUENCY_EXCEEDED (RCCE_ERROR_BASE + 19)
  70. #define RCCE_ERROR_NO_ACTIVE_RPC_REQUEST (RCCE_ERROR_BASE + 20)
  71. #define RCCE_ERROR_STALE_RPC_REQUEST (RCCE_ERROR_BASE + 21)
  72. #define RCCE_ERROR_COMM_UNDEFINED (RCCE_ERROR_BASE + 22)
  73. #define RCCE_ERROR_ILLEGAL_OP (RCCE_ERROR_BASE + 23)
  74. #define RCCE_ERROR_ILLEGAL_TYPE (RCCE_ERROR_BASE + 24)
  75. #define RCCE_ERROR_MALLOC (RCCE_ERROR_BASE + 25)
  76. #define RCCE_ERROR_COMM_INITIALIZED (RCCE_ERROR_BASE + 26)
  77. #define RCCE_ERROR_CORE_NOT_IN_HOSTFILE (RCCE_ERROR_BASE + 27)
  78. #define RCCE_MAX_ERROR_STRING 45
  79. #define RCCE_DEBUG_ALL 111111
  80. #define RCCE_DEBUG_SYNCH 111444
  81. #define RCCE_DEBUG_COMM 111555
  82. #define RCCE_DEBUG_RPC 111666
  83. #define RCCE_DEBUG_DEBUG 111888
  84. #define RCCE_FLAG_SET 1
  85. #define RCCE_FLAG_UNSET 0
  86. #define RCCE_NUM_OPS 4
  87. #define RCCE_OP_BASE 23232323
  88. #define RCCE_SUM (RCCE_OP_BASE)
  89. #define RCCE_MIN (RCCE_OP_BASE+1)
  90. #define RCCE_MAX (RCCE_OP_BASE+2)
  91. #define RCCE_PROD (RCCE_OP_BASE+3)
  92. #define RCCE_TYPE_BASE 63636363
  93. #define RCCE_INT (RCCE_TYPE_BASE)
  94. #define RCCE_LONG (RCCE_TYPE_BASE+1)
  95. #define RCCE_FLOAT (RCCE_TYPE_BASE+2)
  96. #define RCCE_DOUBLE (RCCE_TYPE_BASE+3)
  97. // MPB pointer type
  98. typedef volatile unsigned char* t_vcharp;
  99. typedef struct {
  100. int location; /* location of flag within line (0-31 or 0-255) */
  101. t_vcharp flag_addr; /* address of byte containing flag inside cache line */
  102. t_vcharp line_address; /* start of cache line containing flag */
  103. } RCCE_FLAG;
  104. typedef int RCCE_FLAG_STATUS;
  105. typedef struct {
  106. int size;
  107. int my_rank;
  108. int initialized;
  109. int member[RCCE_MAXNP];
  110. RCCE_FLAG gather;
  111. RCCE_FLAG release;
  112. } RCCE_COMM;
  113. #ifdef RC_POWER_MANAGEMENT
  114. typedef struct{
  115. int release;
  116. int old_voltage_level;
  117. int new_voltage_level;
  118. int old_frequency_divider;
  119. int new_frequency_divider;
  120. long long start_cycle;
  121. } RCCE_REQUEST;
  122. int RCCE_power_domain(void);
  123. int RCCE_iset_power(int, RCCE_REQUEST *, int *, int *);
  124. int RCCE_wait_power(RCCE_REQUEST *);
  125. int RCCE_set_frequency_divider(int, int *);
  126. int RCCE_power_domain_master(void);
  127. int RCCE_power_domain_size(void);
  128. #endif
  129. int RCCE_init(int *, char***);
  130. int RCCE_finalize(void);
  131. double RCCE_wtime(void);
  132. int RCCE_ue(void);
  133. int RCCE_num_ues(void);
  134. #ifdef GORY
  135. t_vcharp RCCE_malloc(size_t);
  136. t_vcharp RCCE_malloc_request(size_t, size_t *);
  137. void RCCE_free(t_vcharp);
  138. int RCCE_put(t_vcharp, t_vcharp, int, int);
  139. int RCCE_get(t_vcharp, t_vcharp, int, int);
  140. int RCCE_put_char(t_vcharp, t_vcharp, int);
  141. int RCCE_get_char(t_vcharp, t_vcharp, int);
  142. int RCCE_wait_until(RCCE_FLAG, RCCE_FLAG_STATUS);
  143. int RCCE_flag_alloc(RCCE_FLAG *);
  144. int RCCE_flag_free(RCCE_FLAG *);
  145. int RCCE_flag_write(RCCE_FLAG *, RCCE_FLAG_STATUS, int);
  146. int RCCE_flag_read(RCCE_FLAG, RCCE_FLAG_STATUS *, int);
  147. int RCCE_send(char *, t_vcharp, size_t, RCCE_FLAG *, RCCE_FLAG *, size_t, int);
  148. int RCCE_recv(char *, t_vcharp, size_t, RCCE_FLAG *, RCCE_FLAG *, size_t, int);
  149. int RCCE_recv_test(char *, t_vcharp, size_t, RCCE_FLAG *, RCCE_FLAG *,
  150. size_t, int, int *);
  151. #else
  152. int RCCE_send(char *, size_t, int);
  153. int RCCE_recv(char *, size_t, int);
  154. int RCCE_recv_test(char *, size_t, int, int *);
  155. int RCCE_allreduce(char *, char *, int, int, int, RCCE_COMM);
  156. int RCCE_reduce(char *, char *, int, int, int, int, RCCE_COMM);
  157. int RCCE_bcast(char *, size_t, int, RCCE_COMM);
  158. #endif
  159. t_vcharp RCCE_shmalloc(size_t);
  160. void RCCE_shfree(t_vcharp);
  161. void RCCE_shflush(void);
  162. #ifdef SHMADD_CACHEABLE
  163. int RCCE_DCMflush();
  164. #endif
  165. int RCCE_acquire_lock(int);
  166. int RCCE_release_lock(int);
  167. int RCCE_comm_split(int (*)(int, void *), void *, RCCE_COMM *);
  168. int RCCE_comm_free(RCCE_COMM *);
  169. int RCCE_comm_size(RCCE_COMM, int *);
  170. int RCCE_comm_rank(RCCE_COMM, int *);
  171. void RCCE_fence(void);
  172. int RCCE_barrier(RCCE_COMM *);
  173. int RCCE_error_string(int, char *, int *);
  174. int RCCE_debug_set(int);
  175. int RCCE_debug_unset(int);
  176. extern RCCE_COMM RCCE_COMM_WORLD;
  177. #ifdef RC_POWER_MANAGEMENT
  178. extern RCCE_COMM RCCE_P_COMM;
  179. #define RCCE_POWER_DEFAULT -99999
  180. #endif
  181. #ifdef _OPENMP
  182. #pragma omp threadprivate (RCCE_COMM_WORLD)
  183. #ifdef RC_POWER_MANAGEMENT
  184. #pragma omp threadprivate (RCCE_P_COMM)
  185. #endif
  186. #endif
  187. #endif