]> git.ipfire.org Git - thirdparty/gcc.git/blame - liboffloadmic/runtime/emulator/coi_common.h
backport: Makefile.am (liboffloadmic_host_la_DEPENDENCIES): Remove libcoi_host and...
[thirdparty/gcc.git] / liboffloadmic / runtime / emulator / coi_common.h
CommitLineData
5f520819 1/*
2eab9666 2 Copyright (c) 2014-2015 Intel Corporation. All Rights Reserved.
5f520819
KY
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#ifndef COI_COMMON_H_INCLUDED
31#define COI_COMMON_H_INCLUDED
32
33#include <common/COIMacros_common.h>
34#include <common/COIPerf_common.h>
35#include <source/COIEngine_source.h>
36#include <source/COIProcess_source.h>
37#include <source/COIPipeline_source.h>
38#include <source/COIBuffer_source.h>
39#include <source/COIEvent_source.h>
40
41#include <assert.h>
42#include <dirent.h>
43#include <dlfcn.h>
44#include <errno.h>
45#include <fcntl.h>
46#include <pthread.h>
47#include <signal.h>
48#include <stdio.h>
49#include <stdlib.h>
50#include <string.h>
51#include <sys/mman.h>
52#include <sys/stat.h>
53#include <unistd.h>
54
55
56/* Environment variable for path to 'target' files. */
57#define MIC_DIR_ENV "OFFLOAD_MIC_DIR"
58
59/* Environment variable for engine index. */
60#define MIC_INDEX_ENV "OFFLOAD_MIC_INDEX"
61
62/* Environment variable for target executable run command. */
63#define OFFLOAD_EMUL_RUN_ENV "OFFLOAD_EMUL_RUN"
64
2eab9666
IV
65/* Environment variable for number of emulated devices. */
66#define OFFLOAD_EMUL_NUM_ENV "OFFLOAD_EMUL_NUM"
5f520819
KY
67
68
69/* Path to engine directory. */
70#define ENGINE_PATH "/tmp/offload_XXXXXX"
71
72/* Relative path to directory with pipes. */
73#define PIPES_PATH "/pipes"
74
75/* Relative path to target-to-host pipe. */
76#define PIPE_HOST_PATH PIPES_PATH"/host"
77
78/* Relative path to host-to-target pipe. */
79#define PIPE_TARGET_PATH PIPES_PATH"/target"
80
81/* Non-numerical part of shared memory file name. */
82#define SHM_NAME "/offload_shm_"
83
84
85/* Use secure getenv if it's supported. */
86#ifdef HAVE_SECURE_GETENV
87 #define getenv(x) secure_getenv(x)
88#elif HAVE___SECURE_GETENV
89 #define getenv(x) __secure_getenv(x)
90#endif
91
92
93/* Wrapper for malloc. */
94#define MALLOC(type, ptr, size) \
95{ \
96 type p = (type) malloc (size); \
97 if (p == NULL) \
98 COIERROR ("Cannot allocate memory."); \
99 ptr = p; \
100}
101
102/* Wrapper for strdup. */
103#define STRDUP(ptr, str) \
104{ \
105 char *p = strdup (str); \
106 if (p == NULL) \
107 COIERROR ("Cannot allocate memory."); \
108 ptr = p; \
109}
110
111/* Wrapper for pipe reading. */
112#define READ(pipe, ptr, size) \
113{ \
114 int s = (int) size; \
115 if (read (pipe, ptr, s) != s) \
116 COIERROR ("Cannot read from pipe."); \
117}
118
119/* Wrapper for pipe writing. */
120#define WRITE(pipe, ptr, size) \
121{ \
122 int s = (int) size; \
123 if (write (pipe, ptr, s) != s) \
124 COIERROR ("Cannot write in pipe."); \
125}
126
127
128/* Command codes enum. */
129typedef enum
130{
131 CMD_BUFFER_COPY,
132 CMD_BUFFER_MAP,
133 CMD_BUFFER_UNMAP,
134 CMD_GET_FUNCTION_HANDLE,
135 CMD_OPEN_LIBRARY,
2eab9666 136 CMD_CLOSE_LIBRARY,
5f520819
KY
137 CMD_RUN_FUNCTION,
138 CMD_SHUTDOWN
139} cmd_t;
140
141#endif // COI_COMMON_H_INCLUDED