|
@@ -378,44 +378,6 @@ static unsigned try_to_reuse_mem_chunk(starpu_mem_chunk_t mc, unsigned node, sta
|
|
|
return success;
|
|
|
}
|
|
|
|
|
|
-/* this function looks for a memory chunk that matches a given footprint in the
|
|
|
- * list of mem chunk that need to be freed. This function must be called with
|
|
|
- * mc_rwlock[node] taken in write mode. */
|
|
|
-static unsigned try_to_find_reusable_mem_chunk(unsigned node, starpu_data_handle data, uint32_t footprint)
|
|
|
-{
|
|
|
- starpu_mem_chunk_t mc, next_mc;
|
|
|
-
|
|
|
- /* go through all buffers in the cache */
|
|
|
- mc = _starpu_memchunk_cache_lookup_locked(node, handle);
|
|
|
- if (mc)
|
|
|
- {
|
|
|
- /* We found an entry in the cache so we can reuse it */
|
|
|
- reuse_mem_chunk(node, data, mc, 0);
|
|
|
- return 1;
|
|
|
- }
|
|
|
-
|
|
|
- /* now look for some non essential data in the active list */
|
|
|
- for (mc = starpu_mem_chunk_list_begin(mc_list[node]);
|
|
|
- mc != starpu_mem_chunk_list_end(mc_list[node]);
|
|
|
- mc = next_mc)
|
|
|
- {
|
|
|
- /* there is a risk that the memory chunk is freed before next
|
|
|
- * iteration starts: so we compute the next element of the list
|
|
|
- * now */
|
|
|
- next_mc = starpu_mem_chunk_list_next(mc);
|
|
|
-
|
|
|
- if (mc->data->is_not_important && (mc->footprint == footprint))
|
|
|
- {
|
|
|
-// fprintf(stderr, "found a candidate ...\n");
|
|
|
- if (try_to_reuse_mem_chunk(mc, node, data, 1))
|
|
|
- return 1;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return 0;
|
|
|
-}
|
|
|
-#endif
|
|
|
-
|
|
|
static int _starpu_data_interface_compare(void *interface_a, struct starpu_data_interface_ops_t *ops_a,
|
|
|
void *interface_b, struct starpu_data_interface_ops_t *ops_b)
|
|
|
{
|
|
@@ -428,7 +390,7 @@ static int _starpu_data_interface_compare(void *interface_a, struct starpu_data_
|
|
|
}
|
|
|
|
|
|
/* This function must be called with mc_rwlock[node] taken in write mode */
|
|
|
-starpu_mem_chunk_t _starpu_memchunk_cache_lookup_locked(uint32_t node, starpu_data_handle handle)
|
|
|
+static starpu_mem_chunk_t _starpu_memchunk_cache_lookup_locked(uint32_t node, starpu_data_handle handle)
|
|
|
{
|
|
|
uint32_t footprint = _starpu_compute_data_footprint(handle);
|
|
|
|
|
@@ -456,24 +418,43 @@ starpu_mem_chunk_t _starpu_memchunk_cache_lookup_locked(uint32_t node, starpu_da
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
-starpu_mem_chunk_t _starpu_memchunk_cache_lookup(uint32_t node, starpu_data_handle handle)
|
|
|
+/* this function looks for a memory chunk that matches a given footprint in the
|
|
|
+ * list of mem chunk that need to be freed. This function must be called with
|
|
|
+ * mc_rwlock[node] taken in write mode. */
|
|
|
+static unsigned try_to_find_reusable_mem_chunk(unsigned node, starpu_data_handle data, uint32_t footprint)
|
|
|
{
|
|
|
- starpu_mem_chunk_t mc;
|
|
|
+ starpu_mem_chunk_t mc, next_mc;
|
|
|
|
|
|
- PTHREAD_RWLOCK_WRLOCK(&mc_rwlock[node]);
|
|
|
+ /* go through all buffers in the cache */
|
|
|
mc = _starpu_memchunk_cache_lookup_locked(node, handle);
|
|
|
- PTHREAD_RWLOCK_UNLOCK(&mc_rwlock[node]);
|
|
|
+ if (mc)
|
|
|
+ {
|
|
|
+ /* We found an entry in the cache so we can reuse it */
|
|
|
+ reuse_mem_chunk(node, data, mc, 0);
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
|
|
|
- return mc;
|
|
|
-}
|
|
|
+ /* now look for some non essential data in the active list */
|
|
|
+ for (mc = starpu_mem_chunk_list_begin(mc_list[node]);
|
|
|
+ mc != starpu_mem_chunk_list_end(mc_list[node]);
|
|
|
+ mc = next_mc)
|
|
|
+ {
|
|
|
+ /* there is a risk that the memory chunk is freed before next
|
|
|
+ * iteration starts: so we compute the next element of the list
|
|
|
+ * now */
|
|
|
+ next_mc = starpu_mem_chunk_list_next(mc);
|
|
|
|
|
|
-void _starpu_memchunk_cache_insert(uint32_t node, starpu_mem_chunk_t mc)
|
|
|
-{
|
|
|
- PTHREAD_RWLOCK_WRLOCK(&mc_rwlock[node]);
|
|
|
- mc->data = NULL;
|
|
|
- starpu_mem_chunk_list_push_front(memchunk_cache[node], mc);
|
|
|
- PTHREAD_RWLOCK_UNLOCK(&mc_rwlock[node]);
|
|
|
+ if (mc->data->is_not_important && (mc->footprint == footprint))
|
|
|
+ {
|
|
|
+// fprintf(stderr, "found a candidate ...\n");
|
|
|
+ if (try_to_reuse_mem_chunk(mc, node, data, 1))
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0;
|
|
|
}
|
|
|
+#endif
|
|
|
|
|
|
/*
|
|
|
* Free the memory chuncks that are explicitely tagged to be freed. The
|