@@ -90,6 +90,31 @@ namespace CLAMP {
90
90
// //////////////////////////////////////////////////////////
91
91
// Class declaration
92
92
// //////////////////////////////////////////////////////////
93
+
94
+ static std::string& get_library_path ()
95
+ {
96
+ static std::string library_path;
97
+ static std::once_flag once;
98
+ std::call_once (once, [] () {
99
+ // determine the search path for libmcwamp_hsa based on the
100
+ // path of this library
101
+ dl_iterate_phdr ([](struct dl_phdr_info * info, size_t size, void * data) {
102
+ if (info->dlpi_name ) {
103
+ std::string p (info->dlpi_name );
104
+ auto pos = p.find (" libmcwamp.so" );
105
+ if (pos != std::string::npos) {
106
+ p.erase (p.begin ()+pos, p.end ());
107
+ library_path = std::move (p);
108
+ return 1 ;
109
+ }
110
+ }
111
+ return 0 ;
112
+ } , nullptr );
113
+ });
114
+
115
+ return library_path;
116
+ }
117
+
93
118
/* *
94
119
* \brief Base class of platform detection
95
120
*/
@@ -132,7 +157,7 @@ class PlatformDetect {
132
157
*/
133
158
class HSAPlatformDetect : public PlatformDetect {
134
159
public:
135
- HSAPlatformDetect () : PlatformDetect(" HSA" , LIB_NAME_WITH_VERSION(" libmcwamp_hsa.so" ), nullptr ) {}
160
+ HSAPlatformDetect () : PlatformDetect(" HSA" , get_library_path() + LIB_NAME_WITH_VERSION(" libmcwamp_hsa.so" ), nullptr ) {}
136
161
};
137
162
138
163
@@ -146,7 +171,8 @@ static RuntimeImpl* LoadHSARuntime() {
146
171
// load HSA C++AMP runtime
147
172
if (mcwamp_verbose)
148
173
std::cout << " Use HSA runtime" << std::endl;
149
- runtimeImpl = new RuntimeImpl (LIB_NAME_WITH_VERSION (" libmcwamp_hsa.so" ));
174
+ std::string lib = get_library_path () + LIB_NAME_WITH_VERSION (" libmcwamp_hsa.so" );
175
+ runtimeImpl = new RuntimeImpl (lib.c_str ());
150
176
if (!runtimeImpl->m_RuntimeHandle ) {
151
177
std::cerr << " Can't load HSA runtime!" << std::endl;
152
178
delete runtimeImpl;
@@ -162,7 +188,8 @@ static RuntimeImpl* LoadCPURuntime() {
162
188
// load CPU runtime
163
189
if (mcwamp_verbose)
164
190
std::cout << " Use CPU runtime" << std::endl;
165
- runtimeImpl = new RuntimeImpl (LIB_NAME_WITH_VERSION (" libmcwamp_cpu.so" ));
191
+ std::string lib = get_library_path () + LIB_NAME_WITH_VERSION (" libmcwamp_cpu.so" );
192
+ runtimeImpl = new RuntimeImpl (lib.c_str ());
166
193
if (!runtimeImpl->m_RuntimeHandle ) {
167
194
std::cerr << " Can't load CPU runtime!" << std::endl;
168
195
delete runtimeImpl;
@@ -428,6 +455,7 @@ KalmarContext *getContext() {
428
455
class KalmarBootstrap {
429
456
public:
430
457
KalmarBootstrap () {
458
+
431
459
bool to_init = false ;
432
460
char * lazyinit_env = getenv (" HCC_LAZYINIT" );
433
461
if (lazyinit_env != nullptr ) {
0 commit comments