Mercurial > hg > graal-jvmci-8
comparison src/gpu/hsail/vm/gpu_hsail.cpp @ 13740:bfd61161d752
HSAIL: support for using Okra simulator without needing to configure PATH and LD_LIBRARY_PATH
Contributed-by: Tom Deneau <tom.deneau@amd.com>
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Fri, 24 Jan 2014 00:52:06 +0100 |
parents | 166ed1584f30 |
children | 49db2c1e3bee |
comparison
equal
deleted
inserted
replaced
13739:ac1e626432f9 | 13740:bfd61161d752 |
---|---|
85 return success; | 85 return success; |
86 } | 86 } |
87 | 87 |
88 void *gpu::Hsail::generate_kernel(unsigned char *code, int code_len, const char *name) { | 88 void *gpu::Hsail::generate_kernel(unsigned char *code, int code_len, const char *name) { |
89 | 89 |
90 if (_okra_create_kernel == NULL) { | |
91 // probe linkage and we really need it to work this time | |
92 bool success = probe_linkage_internal(true); | |
93 guarantee(success, "[HSAIL] loading okra library"); | |
94 } | |
95 | |
90 gpu::Hsail::register_heap(); | 96 gpu::Hsail::register_heap(); |
91 | 97 |
92 // The kernel entrypoint is always run for the time being | 98 // The kernel entrypoint is always run for the time being |
93 const char* entryPointName = "&run"; | 99 const char* entryPointName = "&run"; |
94 | 100 |
122 tty->print_cr("[HSAIL] ***** Error: Failed to lookup %s in %s, wrong version of OKRA?", STRINGIFY(name), okra_library_name); \ | 128 tty->print_cr("[HSAIL] ***** Error: Failed to lookup %s in %s, wrong version of OKRA?", STRINGIFY(name), okra_library_name); \ |
123 return 0; \ | 129 return 0; \ |
124 } \ | 130 } \ |
125 | 131 |
126 bool gpu::Hsail::probe_linkage() { | 132 bool gpu::Hsail::probe_linkage() { |
127 if (okra_library_name != NULL) { | 133 return probe_linkage_internal(false); |
128 char *buffer = (char*)malloc(STD_BUFFER_SIZE); | 134 } |
129 if (TraceGPUInteraction) { | |
130 tty->print_cr("[HSAIL] library is %s", okra_library_name); | |
131 } | |
132 void *handle = os::dll_load(okra_library_name, buffer, STD_BUFFER_SIZE); | |
133 free(buffer); | |
134 if (handle != NULL) { | |
135 | 135 |
136 LOOKUP_OKRA_FUNCTION(okra_create_context, okra_create_context); | |
137 LOOKUP_OKRA_FUNCTION(okra_create_kernel, okra_create_kernel); | |
138 LOOKUP_OKRA_FUNCTION(okra_push_object, okra_push_object); | |
139 LOOKUP_OKRA_FUNCTION(okra_push_boolean, okra_push_boolean); | |
140 LOOKUP_OKRA_FUNCTION(okra_push_byte, okra_push_byte); | |
141 LOOKUP_OKRA_FUNCTION(okra_push_double, okra_push_double); | |
142 LOOKUP_OKRA_FUNCTION(okra_push_float, okra_push_float); | |
143 LOOKUP_OKRA_FUNCTION(okra_push_int, okra_push_int); | |
144 LOOKUP_OKRA_FUNCTION(okra_push_long, okra_push_long); | |
145 LOOKUP_OKRA_FUNCTION(okra_execute_with_range, okra_execute_with_range); | |
146 LOOKUP_OKRA_FUNCTION(okra_clearargs, okra_clearargs); | |
147 LOOKUP_OKRA_FUNCTION(okra_register_heap, okra_register_heap); | |
148 | 136 |
149 return true; | 137 bool gpu::Hsail::probe_linkage_internal(bool isRequired) { |
150 } else { | 138 if (okra_library_name == NULL) { |
151 // Unable to dlopen okra | |
152 if (TraceGPUInteraction) { | |
153 tty->print_cr("[HSAIL] library load failed."); | |
154 } | |
155 return false; | |
156 } | |
157 } else { | |
158 if (TraceGPUInteraction) { | 139 if (TraceGPUInteraction) { |
159 tty->print_cr("Unsupported HSAIL platform"); | 140 tty->print_cr("Unsupported HSAIL platform"); |
160 } | 141 } |
161 return false; | 142 return false; |
162 } | 143 } |
144 | |
145 // here we know we have a valid okra_library_name to try to load | |
146 // the isRequired boolean specifies whether it is an error if the | |
147 // probe does not find the okra library | |
148 char *buffer = (char*)malloc(STD_BUFFER_SIZE); | |
163 if (TraceGPUInteraction) { | 149 if (TraceGPUInteraction) { |
164 tty->print_cr("Failed to find HSAIL linkage"); | 150 tty->print_cr("[HSAIL] library is %s", okra_library_name); |
165 } | 151 } |
166 return false; | 152 void *handle = os::dll_load(okra_library_name, buffer, STD_BUFFER_SIZE); |
153 // try alternate location if env variable set | |
154 char *okra_lib_name_from_env_var = getenv("_OKRA_SIM_LIB_PATH_"); | |
155 if ((handle == NULL) && (okra_lib_name_from_env_var != NULL)) { | |
156 handle = os::dll_load(okra_lib_name_from_env_var, buffer, STD_BUFFER_SIZE); | |
157 if ((handle != NULL) && TraceGPUInteraction) { | |
158 tty->print_cr("[HSAIL] using _OKRA_SIM_LIB_PATH_=%s", getenv("_OKRA_SIM_LIB_PATH_")); | |
159 } | |
160 } | |
161 free(buffer); | |
162 | |
163 if ((handle == NULL) && !isRequired) { | |
164 // return true for now but we will probe again later | |
165 if (TraceGPUInteraction) { | |
166 tty->print_cr("[HSAIL] library load not in PATH, waiting for Java to put in tmpdir."); | |
167 } | |
168 return true; | |
169 } | |
170 | |
171 if ((handle == NULL) && isRequired) { | |
172 // Unable to dlopen okra | |
173 if (TraceGPUInteraction) { | |
174 tty->print_cr("[HSAIL] library load failed."); | |
175 } | |
176 return false; | |
177 } | |
178 | |
179 // at this point we know handle is valid and we can lookup the functions | |
180 LOOKUP_OKRA_FUNCTION(okra_create_context, okra_create_context); | |
181 LOOKUP_OKRA_FUNCTION(okra_create_kernel, okra_create_kernel); | |
182 LOOKUP_OKRA_FUNCTION(okra_push_object, okra_push_object); | |
183 LOOKUP_OKRA_FUNCTION(okra_push_boolean, okra_push_boolean); | |
184 LOOKUP_OKRA_FUNCTION(okra_push_byte, okra_push_byte); | |
185 LOOKUP_OKRA_FUNCTION(okra_push_double, okra_push_double); | |
186 LOOKUP_OKRA_FUNCTION(okra_push_float, okra_push_float); | |
187 LOOKUP_OKRA_FUNCTION(okra_push_int, okra_push_int); | |
188 LOOKUP_OKRA_FUNCTION(okra_push_long, okra_push_long); | |
189 LOOKUP_OKRA_FUNCTION(okra_execute_with_range, okra_execute_with_range); | |
190 LOOKUP_OKRA_FUNCTION(okra_clearargs, okra_clearargs); | |
191 LOOKUP_OKRA_FUNCTION(okra_register_heap, okra_register_heap); | |
192 | |
193 // if we made it this far, real success | |
194 return true; | |
167 } | 195 } |