On Mon, Nov 30, 2015 at 21:49:02 +0100, Jakub Jelinek wrote: > On Mon, Nov 30, 2015 at 11:29:34PM +0300, Ilya Verbin wrote: > > You're right, it doesn't deallocate memory on the device if DSO leaves > > nonzero > > refcount. And currently host compiler doesn't set MSB in host_var_table, > > it's > > set only by accel compiler. But it's possible to do splay_tree_lookup for > > each > > var to determine whether is it linked or not, like in the patch bellow. > > Or do you prefer to set the bit in host compiler too? It requires > > lookup_attribute ("omp declare target link") for all vars in the table > > during > > compilation, but allows to do splay_tree_lookup at run-time only for vars > > with > > MSB set in host_var_table. > > Unfortunately, calling gomp_exit_data from gomp_unload_image_from_device > > works > > only for DSO, but it crashed when an executable leaves nonzero refcount, > > because > > target device may be already uninitialized from plugin's __run_exit_handlers > > (and it is in case of intelmic), so gomp_exit_data cannot run free_func. > > Is it possible do add some atexit (...) to libgomp, which will set > > shutting_down > > flag, and just do nothing in gomp_unload_image_from_device if it is set? > > Sorry, I didn't mean you should call gomp_exit_data, what I meant was that > you perform the same action as would delete(var) do in that case. > Calling gomp_exit_data e.g. looks it up again etc. > Supposedly having the MSB in host table too is useful, so if you could > handle that, it would be nice. And splay_tree_lookup only if the MSB is > set. > So, > if (!host_data_has_msb_set) > splay_tree_remove (&devicep->mem_map, &k); > else > { > splay_tree_key n = splay_tree_lookup (&devicep->mem_map, &k); > if (n->link_key) > { > n->refcount = 0; > n->link_key = NULL; > splay_tree_remove (&devicep->mem_map, n); > if (n->tgt->refcount > 1) > n->tgt->refcount--; > else > gomp_unmap_tgt (n->tgt); > } > else > splay_tree_remove (&devicep->mem_map, n); > } > or so.
Ok, but it doesn't solve the issue with doing it for the executable, because gomp_unmap_tgt (n->tgt) will want to run free_func on uninitialized device. -- Ilya