coi_server.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. // The COI interface on the target
  27. #include "coi_server.h"
  28. #include "../offload_target.h"
  29. #include "../offload_timer.h"
  30. #ifdef MYO_SUPPORT
  31. #include "../offload_myo_target.h" // for __offload_myoLibInit/Fini
  32. #endif // MYO_SUPPORT
  33. COINATIVELIBEXPORT
  34. void server_compute(
  35. uint32_t buffer_count,
  36. void** buffers,
  37. uint64_t* buffers_len,
  38. void* misc_data,
  39. uint16_t misc_data_len,
  40. void* return_data,
  41. uint16_t return_data_len
  42. )
  43. {
  44. OffloadDescriptor::offload(buffer_count, buffers,
  45. misc_data, misc_data_len,
  46. return_data, return_data_len);
  47. }
  48. COINATIVELIBEXPORT
  49. void server_init(
  50. uint32_t buffer_count,
  51. void** buffers,
  52. uint64_t* buffers_len,
  53. void* misc_data,
  54. uint16_t misc_data_len,
  55. void* return_data,
  56. uint16_t return_data_len
  57. )
  58. {
  59. struct init_data {
  60. int device_index;
  61. int devices_total;
  62. int console_level;
  63. int offload_report_level;
  64. } *data = (struct init_data*) misc_data;
  65. // set device index and number of total devices
  66. mic_index = data->device_index;
  67. mic_engines_total = data->devices_total;
  68. // initialize trace level
  69. console_enabled = data->console_level;
  70. offload_report_level = data->offload_report_level;
  71. // return back the process id
  72. *((pid_t*) return_data) = getpid();
  73. }
  74. COINATIVELIBEXPORT
  75. void server_var_table_size(
  76. uint32_t buffer_count,
  77. void** buffers,
  78. uint64_t* buffers_len,
  79. void* misc_data,
  80. uint16_t misc_data_len,
  81. void* return_data,
  82. uint16_t return_data_len
  83. )
  84. {
  85. struct Params {
  86. int64_t nelems;
  87. int64_t length;
  88. } *params;
  89. params = static_cast<Params*>(return_data);
  90. params->length = __offload_vars.table_size(params->nelems);
  91. }
  92. COINATIVELIBEXPORT
  93. void server_var_table_copy(
  94. uint32_t buffer_count,
  95. void** buffers,
  96. uint64_t* buffers_len,
  97. void* misc_data,
  98. uint16_t misc_data_len,
  99. void* return_data,
  100. uint16_t return_data_len
  101. )
  102. {
  103. __offload_vars.table_copy(buffers[0], *static_cast<int64_t*>(misc_data));
  104. }
  105. #ifdef MYO_SUPPORT
  106. // temporary workaround for blocking behavior of myoiLibInit/Fini calls
  107. COINATIVELIBEXPORT
  108. void server_myoinit(
  109. uint32_t buffer_count,
  110. void** buffers,
  111. uint64_t* buffers_len,
  112. void* misc_data,
  113. uint16_t misc_data_len,
  114. void* return_data,
  115. uint16_t return_data_len
  116. )
  117. {
  118. __offload_myoLibInit();
  119. }
  120. COINATIVELIBEXPORT
  121. void server_myofini(
  122. uint32_t buffer_count,
  123. void** buffers,
  124. uint64_t* buffers_len,
  125. void* misc_data,
  126. uint16_t misc_data_len,
  127. void* return_data,
  128. uint16_t return_data_len
  129. )
  130. {
  131. __offload_myoLibFini();
  132. }
  133. #endif // MYO_SUPPORT