Jim Cownie | 33f7b24 | 2014-04-09 15:40:23 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.txt for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | |
| 11 | // The parts of the offload library used only on the target |
| 12 | |
| 13 | #ifndef OFFLOAD_TARGET_H_INCLUDED |
| 14 | #define OFFLOAD_TARGET_H_INCLUDED |
| 15 | |
| 16 | #include "offload_common.h" |
| 17 | #include "coi/coi_server.h" |
| 18 | |
| 19 | // The offload descriptor. |
| 20 | class OffloadDescriptor |
| 21 | { |
| 22 | public: |
| 23 | ~OffloadDescriptor() { |
| 24 | if (m_vars != 0) { |
| 25 | free(m_vars); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | // Entry point for COI. Synchronously execute offloaded region given |
| 30 | // the provided buffers, misc and return data. |
| 31 | static void offload( |
| 32 | uint32_t buffer_count, |
| 33 | void** buffers, |
| 34 | void* misc_data, |
| 35 | uint16_t misc_data_len, |
| 36 | void* return_data, |
| 37 | uint16_t return_data_len |
| 38 | ); |
| 39 | |
| 40 | // scatters input data from in buffer to target variables |
| 41 | void scatter_copyin_data(); |
| 42 | |
| 43 | // gathers output data to the buffer |
| 44 | void gather_copyout_data(); |
| 45 | |
| 46 | // merges local variable descriptors with the descriptors received from |
| 47 | // host |
| 48 | void merge_var_descs(VarDesc *vars, VarDesc2 *vars2, int vars_total); |
| 49 | |
| 50 | int get_offload_number() const { |
| 51 | return m_offload_number; |
| 52 | } |
| 53 | |
| 54 | void set_offload_number(int number) { |
| 55 | m_offload_number = number; |
| 56 | } |
| 57 | |
| 58 | private: |
| 59 | // Constructor |
| 60 | OffloadDescriptor() : m_vars(0) |
| 61 | {} |
| 62 | |
| 63 | private: |
| 64 | typedef std::list<void*> BufferList; |
| 65 | |
| 66 | // The Marshaller for the inputs of the offloaded region. |
| 67 | Marshaller m_in; |
| 68 | |
| 69 | // The Marshaller for the outputs of the offloaded region. |
| 70 | Marshaller m_out; |
| 71 | |
| 72 | // List of buffers that are passed to dispatch call |
| 73 | BufferList m_buffers; |
| 74 | |
| 75 | // Variable descriptors received from host |
| 76 | VarDesc* m_vars; |
| 77 | int m_vars_total; |
| 78 | int m_offload_number; |
| 79 | }; |
| 80 | |
| 81 | // one time target initialization in main |
| 82 | extern void __offload_target_init(void); |
| 83 | |
| 84 | // logical device index |
| 85 | extern int mic_index; |
| 86 | |
| 87 | // total number of available logical devices |
| 88 | extern int mic_engines_total; |
| 89 | |
| 90 | // device frequency (from COI) |
| 91 | extern uint64_t mic_frequency; |
| 92 | |
| 93 | struct RefInfo { |
| 94 | RefInfo(bool is_add, long amount):is_added(is_add),count(amount) |
| 95 | {} |
| 96 | bool is_added; |
| 97 | long count; |
| 98 | }; |
| 99 | |
| 100 | #endif // OFFLOAD_TARGET_H_INCLUDED |