]> git.ipfire.org Git - thirdparty/gcc.git/blob - liboffloadmic/runtime/offload_target.h
5638796f2d1d623ca76a7ae860a26d08e328568b
[thirdparty/gcc.git] / liboffloadmic / runtime / offload_target.h
1 /*
2 Copyright (c) 2014-2015 Intel Corporation. All Rights Reserved.
3
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
6 are met:
7
8 * Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 * Neither the name of Intel Corporation nor the names of its
14 contributors may be used to endorse or promote products derived
15 from this software without specific prior written permission.
16
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30
31 // The parts of the offload library used only on the target
32
33 #ifndef OFFLOAD_TARGET_H_INCLUDED
34 #define OFFLOAD_TARGET_H_INCLUDED
35
36 #include "offload_common.h"
37 #include "coi/coi_server.h"
38
39 // The offload descriptor.
40 class OffloadDescriptor
41 {
42 public:
43 ~OffloadDescriptor() {
44 if (m_vars != 0) {
45 free(m_vars);
46 }
47 }
48
49 // Entry point for COI. Synchronously execute offloaded region given
50 // the provided buffers, misc and return data.
51 static void offload(
52 uint32_t buffer_count,
53 void** buffers,
54 void* misc_data,
55 uint16_t misc_data_len,
56 void* return_data,
57 uint16_t return_data_len
58 );
59
60 // scatters input data from in buffer to target variables
61 void scatter_copyin_data();
62
63 // gathers output data to the buffer
64 void gather_copyout_data();
65
66 // merges local variable descriptors with the descriptors received from
67 // host
68 void merge_var_descs(VarDesc *vars, VarDesc2 *vars2, int vars_total);
69
70 int get_offload_number() const {
71 return m_offload_number;
72 }
73
74 void set_offload_number(int number) {
75 m_offload_number = number;
76 }
77
78 private:
79 // Constructor
80 OffloadDescriptor() : m_vars(0)
81 {}
82
83 private:
84 typedef std::list<void*> BufferList;
85
86 // The Marshaller for the inputs of the offloaded region.
87 Marshaller m_in;
88
89 // The Marshaller for the outputs of the offloaded region.
90 Marshaller m_out;
91
92 // List of buffers that are passed to dispatch call
93 BufferList m_buffers;
94
95 // Variable descriptors received from host
96 VarDesc* m_vars;
97 int m_vars_total;
98 int m_offload_number;
99 };
100
101 // one time target initialization in main
102 DLL_LOCAL extern void __offload_target_init(void);
103
104 // logical device index
105 DLL_LOCAL extern int mic_index;
106
107 // total number of available logical devices
108 DLL_LOCAL extern int mic_engines_total;
109
110 // device frequency (from COI)
111 DLL_LOCAL extern uint64_t mic_frequency;
112
113 struct RefInfo {
114 RefInfo(bool is_add, long amount):is_added(is_add),count(amount)
115 {}
116 bool is_added;
117 long count;
118 };
119
120 #endif // OFFLOAD_TARGET_H_INCLUDED