[C++ PATCH] initializer_list diagnostic
[official-gcc.git] / liboffloadmic / runtime / coi / coi_server.cpp
blob67aa991eebbcb09fd154d543cc3e43838e420ca7
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 COI interface on the target
33 #include "coi_server.h"
35 #include "../offload_target.h"
36 #include "../offload_timer.h"
37 #ifdef MYO_SUPPORT
38 #include "../offload_myo_target.h" // for __offload_myoLibInit/Fini
39 #endif // MYO_SUPPORT
41 #if !defined(CPU_COUNT)
42 // if CPU_COUNT is not defined count number of CPUs manually
43 static
44 int my_cpu_count(cpu_set_t const *cpu_set)
46 int res = 0;
47 for (int i = 0; i < sizeof(cpu_set_t) / sizeof(__cpu_mask); ++i) {
48 res += __builtin_popcountl(cpu_set->__bits[i]);
50 return res;
52 // Map CPU_COUNT to our function
53 #define CPU_COUNT(x) my_cpu_count(x)
55 #endif
57 COINATIVELIBEXPORT
58 void server_compute(
59 uint32_t buffer_count,
60 void** buffers,
61 uint64_t* buffers_len,
62 void* misc_data,
63 uint16_t misc_data_len,
64 void* return_data,
65 uint16_t return_data_len
68 OffloadDescriptor::offload(buffer_count, buffers,
69 misc_data, misc_data_len,
70 return_data, return_data_len);
73 COINATIVELIBEXPORT
74 void server_init(
75 uint32_t buffer_count,
76 void** buffers,
77 uint64_t* buffers_len,
78 void* misc_data,
79 uint16_t misc_data_len,
80 void* return_data,
81 uint16_t return_data_len
84 struct init_data {
85 int device_index;
86 int devices_total;
87 int console_level;
88 int offload_report_level;
89 } *data = (struct init_data*) misc_data;
91 // set device index and number of total devices
92 mic_index = data->device_index;
93 mic_engines_total = data->devices_total;
95 // initialize trace level
96 console_enabled = data->console_level;
97 offload_report_level = data->offload_report_level;
99 // return back the process id
100 *((pid_t*) return_data) = getpid();
103 COINATIVELIBEXPORT
104 void server_var_table_size(
105 uint32_t buffer_count,
106 void** buffers,
107 uint64_t* buffers_len,
108 void* misc_data,
109 uint16_t misc_data_len,
110 void* return_data,
111 uint16_t return_data_len
114 struct Params {
115 int64_t nelems;
116 int64_t length;
117 } *params;
119 params = static_cast<Params*>(return_data);
120 params->length = __offload_vars.table_size(params->nelems);
123 COINATIVELIBEXPORT
124 void server_var_table_copy(
125 uint32_t buffer_count,
126 void** buffers,
127 uint64_t* buffers_len,
128 void* misc_data,
129 uint16_t misc_data_len,
130 void* return_data,
131 uint16_t return_data_len
134 __offload_vars.table_copy(buffers[0], *static_cast<int64_t*>(misc_data));
137 COINATIVELIBEXPORT
138 void server_set_stream_affinity(
139 uint32_t buffer_count,
140 void** buffers,
141 uint64_t* buffers_len,
142 void* misc_data,
143 uint16_t misc_data_len,
144 void* return_data,
145 uint16_t return_data_len
148 /* kmp affinity is not supported by GCC. */
151 #ifdef MYO_SUPPORT
152 // temporary workaround for blocking behavior of myoiLibInit/Fini calls
153 COINATIVELIBEXPORT
154 void server_myoinit(
155 uint32_t buffer_count,
156 void** buffers,
157 uint64_t* buffers_len,
158 void* misc_data,
159 uint16_t misc_data_len,
160 void* return_data,
161 uint16_t return_data_len
164 __offload_myoLibInit();
167 COINATIVELIBEXPORT
168 void server_myofini(
169 uint32_t buffer_count,
170 void** buffers,
171 uint64_t* buffers_len,
172 void* misc_data,
173 uint16_t misc_data_len,
174 void* return_data,
175 uint16_t return_data_len
178 __offload_myoLibFini();
180 #endif // MYO_SUPPORT