offload_target.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 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. }
  39. }
  40. // Entry point for COI. Synchronously execute offloaded region given
  41. // the provided buffers, misc and return data.
  42. static void offload(
  43. uint32_t buffer_count,
  44. void** buffers,
  45. void* misc_data,
  46. uint16_t misc_data_len,
  47. void* return_data,
  48. uint16_t return_data_len
  49. );
  50. // scatters input data from in buffer to target variables
  51. void scatter_copyin_data();
  52. // gathers output data to the buffer
  53. void gather_copyout_data();
  54. // merges local variable descriptors with the descriptors received from
  55. // host
  56. void merge_var_descs(VarDesc *vars, VarDesc2 *vars2, int vars_total);
  57. int get_offload_number() const {
  58. return m_offload_number;
  59. }
  60. void set_offload_number(int number) {
  61. m_offload_number = number;
  62. }
  63. private:
  64. // Constructor
  65. OffloadDescriptor() : m_vars(0)
  66. {}
  67. private:
  68. typedef std::list<void*> BufferList;
  69. // The Marshaller for the inputs of the offloaded region.
  70. Marshaller m_in;
  71. // The Marshaller for the outputs of the offloaded region.
  72. Marshaller m_out;
  73. // List of buffers that are passed to dispatch call
  74. BufferList m_buffers;
  75. // Variable descriptors received from host
  76. VarDesc* m_vars;
  77. int m_vars_total;
  78. int m_offload_number;
  79. };
  80. // one time target initialization in main
  81. extern void __offload_target_init(void);
  82. // logical device index
  83. extern int mic_index;
  84. // total number of available logical devices
  85. extern int mic_engines_total;
  86. // device frequency (from COI)
  87. extern uint64_t mic_frequency;
  88. struct RefInfo {
  89. RefInfo(bool is_add, long amount):is_added(is_add),count(amount)
  90. {}
  91. bool is_added;
  92. long count;
  93. };
  94. #endif // OFFLOAD_TARGET_H_INCLUDED