-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathACLModule.h
executable file
·234 lines (191 loc) · 8.77 KB
/
ACLModule.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
//==============================================================================
// Copyright (c) 2012-2016 Advanced Micro Devices, Inc. All rights reserved.
/// \author AMD Developer Tools
/// \file
/// \brief This class manages the dynamic loading of amdoclcl{32,64}.dll
//==============================================================================
#ifndef _ACL_MODULE_H_
#define _ACL_MODULE_H_
//#define WITH_VERSION_0_9 1
#define WITH_VERSION_0_8 1
/*
Notes on discussion with Laurent about versioning of the ACL symbols on Linux:
- the actual exported symbols on Linux will be appended with a version string:
i.e. aclReadFromMem@@ACL_0.8
- when moving to a new version of the library, any new entry-points will have a
new version string (i.e. aclSomeFunction@@ACL_0.9).
- if an existing function changes semantically, then the library would actually
export two versions: aclReadFromMem@@ACL_0.8 and aclReadFromMem@@ACL_0.9
- apparently, dlsym knows how to deal with this, and by default will always
return the address of the oldest version:
i.e. using the above example of two versions of "aclReadFromMem", by default
the call to dlsym(RTLD_NEXT, "aclReadFromMem") will return the address of
aclReadFromMem@@ACL_0.8. If there is only a single version, then dlsym will,
of course, return just the address of that single symbol.
- in order to override this default behavior (and thus bind to a newer version),
you can use dlvsym in place of dlsym:
dlvsym(RTLD_NEXT, "aclReadFromMem", "ACL_0.9");
- it is expected that the presence of multiple versions of a single symbol will be
quite rare
*/
#include "acl.h"
#include "DynamicLibraryModule.h"
typedef aclTargetInfo(ACL_API_ENTRY
*aclGetTargetInfoProc)(const char* arch,
const char* device,
acl_error* error_code);
typedef aclCompiler* (ACL_API_ENTRY
*aclCompilerInitProc)(aclCompilerOptions* opts, acl_error* error_code);
typedef acl_error(ACL_API_ENTRY
*aclCompilerFiniProc)(aclCompiler* cl);
typedef aclBinary* (ACL_API_ENTRY
*aclReadFromMemProc)(const void* mem,
size_t size, acl_error* error_code);
typedef aclBinary* (ACL_API_ENTRY
*aclReadFromFileProc)(const char* str,
acl_error* error_code);
typedef aclBinary* (ACL_API_ENTRY
*aclBinaryInitProc)(
size_t struct_version,
const aclTargetInfo* target,
const aclBinaryOptions* options,
acl_error* error_code);
typedef acl_error(ACL_API_ENTRY
*aclBinaryFiniProc)(aclBinary* bin);
typedef acl_error(ACL_API_ENTRY
*aclWriteToMemProc)(aclBinary* bin,
void** mem, size_t* size);
typedef acl_error(ACL_API_ENTRY
*aclWriteToFileProc)(aclBinary* bin,
const char* str);
typedef acl_error(ACL_API_ENTRY
*aclInsertSectionProc)(aclCompiler* cl,
aclBinary* binary,
const void* data,
size_t data_size,
aclSections id);
typedef const void* (ACL_API_ENTRY
*aclExtractSectionProc)(aclCompiler* cl,
const aclBinary* binary,
size_t* size,
aclSections id,
acl_error* error_code);
typedef const void* (ACL_API_ENTRY
*aclExtractSymbolProc)(aclCompiler* cl,
const aclBinary* binary,
size_t* size,
aclSections id,
const char* symbol,
acl_error* error_code);
typedef acl_error(ACL_API_ENTRY
*aclRemoveSymbolProc)(aclCompiler* cl,
aclBinary* binary,
aclSections id,
const char* symbol);
typedef acl_error(ACL_API_ENTRY
*aclInsertSymbolProc)(aclCompiler* cl,
aclBinary* binary,
const void* data,
size_t data_size,
aclSections id,
const char* symbol);
typedef acl_error(ACL_API_ENTRY
*aclRemoveSectionProc)(aclCompiler* cl,
aclBinary* binary,
aclSections id);
#ifdef WITH_VERSION_0_9
typedef acl_error(ACL_API_ENTRY
*aclQueryInfoProc)(aclCompiler* cl,
const aclBinary* binary,
aclQueryType query,
const char* kernel,
void* data_ptr,
size_t* ptr_size);
#else
typedef acl_error(ACL_API_ENTRY
*aclQueryInfoProc)(aclCompiler* cl,
const aclBinary* binary,
aclQueryType query,
const char* kernel,
void* data_ptr,
size_t* ptr_size);
#endif
typedef acl_error(ACL_API_ENTRY
*aclDbgAddArgumentProc)(aclCompiler* cl,
aclBinary* binary,
const char* kernel,
const char* name,
bool byVal);
typedef acl_error(ACL_API_ENTRY
*aclCompileProc)(aclCompiler* cl,
aclBinary* bin,
const char* options,
aclType from,
aclType to,
aclLogFunction compile_callback);
typedef acl_error(ACL_API_ENTRY
*aclDisassembleProc)(aclCompiler* cl,
aclBinary* bin,
const char* kernel,
aclLogFunction disasm_callback);
#define ACL_API_TABLE \
X(GetTargetInfo) \
X(CompilerInit) \
X(CompilerFini) \
X(ReadFromMem) \
X(ReadFromFile) \
X(BinaryInit) \
X(BinaryFini) \
X(WriteToMem) \
X(WriteToFile) \
X(InsertSection) \
X(ExtractSection) \
X(RemoveSection) \
X(QueryInfo) \
X(DbgAddArgument) \
X(ExtractSymbol) \
X(InsertSymbol) \
X(RemoveSymbol) \
X(Compile) \
X(Disassemble)
/// This class handles the dynamic loading of the compiler library from either 1) amdoclcl.dll/libamdoclcl.so,
/// 2) amdhsacl.dll/libamdhsacl.so or 3) amdocl.dll/libamdocl.so
class ACLModule
{
public:
/// Constructor
ACLModule(void);
/// Destructor
~ACLModule(void);
/// Default name to use for construction.
/// This is usually amdocl12cl.dll or libamdocl12cl.so.
static const char* s_DefaultModuleName;
/// Pre-15.20 compiler library module. This is amdoclcl.dll or libamdoclcl.so.
static const char* s_OldDefaultModuleName;
/// HSA compiler library name (amdhsacl.dll)
static const char* s_HSA_COMPILER_LIB_NAME;
/// fallback compiler library name (amdocl.dll)
static const char* s_TMP_MODULE_NAME;
/// fallback compiler library for ORCA path on Linux amdgpu (libamdocl-orca64.so)
static const char* s_TMP_ORCA_MODULE_NAME;
/// Load module.
/// \param[in] name The module name.
/// \return true if successful, false otherwise
bool LoadModule(const std::string& name = s_DefaultModuleName);
/// Unload the compiler lib shared image.
void UnloadModule();
/// Have we successfully loaded the cal module?
/// \returns enumeration value to answer query.
bool IsLoaded() { return m_bModuleLoaded; }
#define X(SYM) acl##SYM##Proc SYM;
ACL_API_TABLE;
#undef X
private:
/// Initialize the internal data
void Initialize();
/// Have we loaded the compiler lib module?
bool m_bModuleLoaded;
/// Helper.
DynamicLibraryModule m_DynamicLibraryHelper;
};
#endif //_ACL_MODULE_H_