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
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"
38 #include "../offload_myo_target.h" // for __offload_myoLibInit/Fini
41 #if !defined(CPU_COUNT)
42 // if CPU_COUNT is not defined count number of CPUs manually
44 int my_cpu_count(cpu_set_t
const *cpu_set
)
47 for (int i
= 0; i
< sizeof(cpu_set_t
) / sizeof(__cpu_mask
); ++i
) {
48 res
+= __builtin_popcountl(cpu_set
->__bits
[i
]);
52 // Map CPU_COUNT to our function
53 #define CPU_COUNT(x) my_cpu_count(x)
59 uint32_t buffer_count
,
61 uint64_t* buffers_len
,
63 uint16_t misc_data_len
,
65 uint16_t return_data_len
68 OffloadDescriptor::offload(buffer_count
, buffers
,
69 misc_data
, misc_data_len
,
70 return_data
, return_data_len
);
75 uint32_t buffer_count
,
77 uint64_t* buffers_len
,
79 uint16_t misc_data_len
,
81 uint16_t return_data_len
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();
104 void server_var_table_size(
105 uint32_t buffer_count
,
107 uint64_t* buffers_len
,
109 uint16_t misc_data_len
,
111 uint16_t return_data_len
119 params
= static_cast<Params
*>(return_data
);
120 params
->length
= __offload_vars
.table_size(params
->nelems
);
124 void server_var_table_copy(
125 uint32_t buffer_count
,
127 uint64_t* buffers_len
,
129 uint16_t misc_data_len
,
131 uint16_t return_data_len
134 __offload_vars
.table_copy(buffers
[0], *static_cast<int64_t*>(misc_data
));
138 void server_set_stream_affinity(
139 uint32_t buffer_count
,
141 uint64_t* buffers_len
,
143 uint16_t misc_data_len
,
145 uint16_t return_data_len
148 /* kmp affinity is not supported by GCC. */
152 // temporary workaround for blocking behavior of myoiLibInit/Fini calls
155 uint32_t buffer_count
,
157 uint64_t* buffers_len
,
159 uint16_t misc_data_len
,
161 uint16_t return_data_len
164 __offload_myoLibInit();
169 uint32_t buffer_count
,
171 uint64_t* buffers_len
,
173 uint16_t misc_data_len
,
175 uint16_t return_data_len
178 __offload_myoLibFini();
180 #endif // MYO_SUPPORT