coi_common.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. Copyright (c) 2014 Intel Corporation. All Rights Reserved.
  3. Redistribution and use in source and binary forms, with or without
  4. modification, are permitted provided that the following conditions
  5. are met:
  6. * Redistributions of source code must retain the above copyright
  7. notice, this list of conditions and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. * Neither the name of Intel Corporation nor the names of its
  12. contributors may be used to endorse or promote products derived
  13. from this software without specific prior written permission.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  15. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  16. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  17. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  18. HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  19. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  20. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  21. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  22. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #ifndef COI_COMMON_H_INCLUDED
  27. #define COI_COMMON_H_INCLUDED
  28. #include <common/COIMacros_common.h>
  29. #include <common/COIPerf_common.h>
  30. #include <source/COIEngine_source.h>
  31. #include <source/COIProcess_source.h>
  32. #include <source/COIPipeline_source.h>
  33. #include <source/COIBuffer_source.h>
  34. #include <source/COIEvent_source.h>
  35. #include <assert.h>
  36. #include <dirent.h>
  37. #include <dlfcn.h>
  38. #include <errno.h>
  39. #include <fcntl.h>
  40. #include <pthread.h>
  41. #include <signal.h>
  42. #include <stdio.h>
  43. #include <stdlib.h>
  44. #include <string.h>
  45. #include <sys/mman.h>
  46. #include <sys/stat.h>
  47. #include <unistd.h>
  48. /* Environment variable for path to 'target' files. */
  49. #define MIC_DIR_ENV "OFFLOAD_MIC_DIR"
  50. /* Environment variable for engine index. */
  51. #define MIC_INDEX_ENV "OFFLOAD_MIC_INDEX"
  52. /* Environment variable for target executable run command. */
  53. #define OFFLOAD_EMUL_RUN_ENV "OFFLOAD_EMUL_RUN"
  54. /* Environment variable for number ok KNC devices. */
  55. #define OFFLOAD_EMUL_KNC_NUM_ENV "OFFLOAD_EMUL_KNC_NUM"
  56. /* Path to engine directory. */
  57. #define ENGINE_PATH "/tmp/offload_XXXXXX"
  58. /* Relative path to directory with pipes. */
  59. #define PIPES_PATH "/pipes"
  60. /* Relative path to target-to-host pipe. */
  61. #define PIPE_HOST_PATH PIPES_PATH"/host"
  62. /* Relative path to host-to-target pipe. */
  63. #define PIPE_TARGET_PATH PIPES_PATH"/target"
  64. /* Non-numerical part of shared memory file name. */
  65. #define SHM_NAME "/offload_shm_"
  66. /* Use secure getenv if it's supported. */
  67. #ifdef HAVE_SECURE_GETENV
  68. #define getenv(x) secure_getenv(x)
  69. #elif HAVE___SECURE_GETENV
  70. #define getenv(x) __secure_getenv(x)
  71. #endif
  72. /* Wrapper for malloc. */
  73. #define MALLOC(type, ptr, size) \
  74. { \
  75. type p = (type) malloc (size); \
  76. if (p == NULL) \
  77. COIERROR ("Cannot allocate memory."); \
  78. ptr = p; \
  79. }
  80. /* Wrapper for strdup. */
  81. #define STRDUP(ptr, str) \
  82. { \
  83. char *p = strdup (str); \
  84. if (p == NULL) \
  85. COIERROR ("Cannot allocate memory."); \
  86. ptr = p; \
  87. }
  88. /* Wrapper for pipe reading. */
  89. #define READ(pipe, ptr, size) \
  90. { \
  91. int s = (int) size; \
  92. if (read (pipe, ptr, s) != s) \
  93. COIERROR ("Cannot read from pipe."); \
  94. }
  95. /* Wrapper for pipe writing. */
  96. #define WRITE(pipe, ptr, size) \
  97. { \
  98. int s = (int) size; \
  99. if (write (pipe, ptr, s) != s) \
  100. COIERROR ("Cannot write in pipe."); \
  101. }
  102. /* Command codes enum. */
  103. typedef enum
  104. {
  105. CMD_BUFFER_COPY,
  106. CMD_BUFFER_MAP,
  107. CMD_BUFFER_UNMAP,
  108. CMD_GET_FUNCTION_HANDLE,
  109. CMD_OPEN_LIBRARY,
  110. CMD_RUN_FUNCTION,
  111. CMD_SHUTDOWN
  112. } cmd_t;
  113. #endif // COI_COMMON_H_INCLUDED