offload_target.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. Copyright (c) 2014-2016 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 parts of the offload library used only on the target
  27. #ifndef OFFLOAD_TARGET_H_INCLUDED
  28. #define OFFLOAD_TARGET_H_INCLUDED
  29. #include "offload_common.h"
  30. #include "coi/coi_server.h"
  31. // The offload descriptor.
  32. class OffloadDescriptor
  33. {
  34. public:
  35. ~OffloadDescriptor() {
  36. if (m_vars != 0) {
  37. free(m_vars);
  38. free(m_vars_extra);
  39. }
  40. }
  41. // Entry point for COI. Synchronously execute offloaded region given
  42. // the provided buffers, misc and return data.
  43. static void offload(
  44. uint32_t buffer_count,
  45. void** buffers,
  46. void* misc_data,
  47. uint16_t misc_data_len,
  48. void* return_data,
  49. uint16_t return_data_len
  50. );
  51. // scatters input data from in buffer to target variables
  52. void scatter_copyin_data();
  53. // gathers output data to the buffer
  54. void gather_copyout_data();
  55. // merges local variable descriptors with the descriptors received from
  56. // host
  57. void merge_var_descs(VarDesc *vars, VarDesc2 *vars2, int vars_total);
  58. int get_offload_number() const {
  59. return m_offload_number;
  60. }
  61. void set_offload_number(int number) {
  62. m_offload_number = number;
  63. }
  64. private:
  65. // Constructor
  66. OffloadDescriptor() : m_vars(0)
  67. {}
  68. private:
  69. typedef std::list<void*> BufferList;
  70. // The Marshaller for the inputs of the offloaded region.
  71. Marshaller m_in;
  72. // The Marshaller for the outputs of the offloaded region.
  73. Marshaller m_out;
  74. // List of buffers that are passed to dispatch call
  75. BufferList m_buffers;
  76. // Variable descriptors received from host
  77. VarDesc* m_vars;
  78. int m_vars_total;
  79. int m_offload_number;
  80. // extra data associated with each variable descriptor
  81. struct VarExtra {
  82. uint16_t type_src;
  83. uint16_t type_dst;
  84. };
  85. VarExtra* m_vars_extra;
  86. };
  87. // one time target initialization in main
  88. DLL_LOCAL extern void __offload_target_init(void);
  89. // logical device index
  90. DLL_LOCAL extern int mic_index;
  91. // total number of available logical devices
  92. DLL_LOCAL extern int mic_engines_total;
  93. // device frequency (from COI)
  94. DLL_LOCAL extern uint64_t mic_frequency;
  95. struct RefInfo {
  96. RefInfo(bool is_add, long amount):is_added(is_add),count(amount)
  97. {}
  98. bool is_added;
  99. long count;
  100. };
  101. #endif // OFFLOAD_TARGET_H_INCLUDED