PR c++/85662
[official-gcc.git] / liboffloadmic / runtime / offload_target.h
blob8d2971b2418409753c0bf3da2b4c55c76235eff6
1 /*
2 Copyright (c) 2014-2016 Intel Corporation. All Rights Reserved.
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
6 are met:
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.
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.
31 // The parts of the offload library used only on the target
33 #ifndef OFFLOAD_TARGET_H_INCLUDED
34 #define OFFLOAD_TARGET_H_INCLUDED
36 #include "offload_common.h"
37 #include "coi/coi_server.h"
39 // The offload descriptor.
40 class OffloadDescriptor
42 public:
43 ~OffloadDescriptor() {
44 if (m_vars != 0) {
45 free(m_vars);
46 free(m_vars_extra);
50 // Entry point for COI. Synchronously execute offloaded region given
51 // the provided buffers, misc and return data.
52 static void offload(
53 uint32_t buffer_count,
54 void** buffers,
55 void* misc_data,
56 uint16_t misc_data_len,
57 void* return_data,
58 uint16_t return_data_len
61 // scatters input data from in buffer to target variables
62 void scatter_copyin_data();
64 // gathers output data to the buffer
65 void gather_copyout_data();
67 // merges local variable descriptors with the descriptors received from
68 // host
69 void merge_var_descs(VarDesc *vars, VarDesc2 *vars2, int vars_total);
71 int get_offload_number() const {
72 return m_offload_number;
75 void set_offload_number(int number) {
76 m_offload_number = number;
79 private:
80 // Constructor
81 OffloadDescriptor() : m_vars(0)
84 private:
85 typedef std::list<void*> BufferList;
87 // The Marshaller for the inputs of the offloaded region.
88 Marshaller m_in;
90 // The Marshaller for the outputs of the offloaded region.
91 Marshaller m_out;
93 // List of buffers that are passed to dispatch call
94 BufferList m_buffers;
96 // Variable descriptors received from host
97 VarDesc* m_vars;
98 int m_vars_total;
99 int m_offload_number;
101 // extra data associated with each variable descriptor
102 struct VarExtra {
103 uint16_t type_src;
104 uint16_t type_dst;
107 VarExtra* m_vars_extra;
110 // one time target initialization in main
111 DLL_LOCAL extern void __offload_target_init(void);
113 // logical device index
114 DLL_LOCAL extern int mic_index;
116 // total number of available logical devices
117 DLL_LOCAL extern int mic_engines_total;
119 // device frequency (from COI)
120 DLL_LOCAL extern uint64_t mic_frequency;
122 struct RefInfo {
123 RefInfo(bool is_add, long amount):is_added(is_add),count(amount)
125 bool is_added;
126 long count;
129 #endif // OFFLOAD_TARGET_H_INCLUDED