|
@@ -83,8 +83,6 @@ static struct starpu_codelet malloc_pinned_cl =
|
|
|
|
|
|
int starpu_malloc(void **A, size_t dim)
|
|
|
{
|
|
|
- void *ptr;
|
|
|
- size_t dimsize;
|
|
|
int ret=0;
|
|
|
|
|
|
if (STARPU_UNLIKELY(!_starpu_worker_may_perform_blocking_calls()))
|
|
@@ -92,13 +90,10 @@ int starpu_malloc(void **A, size_t dim)
|
|
|
|
|
|
STARPU_ASSERT(A);
|
|
|
|
|
|
- // We want to allocate extra space to store the size
|
|
|
- dimsize = dim + sizeof(size_t);
|
|
|
-
|
|
|
- if (_starpu_memory_manager_can_allocate_size(dimsize, 0) == 0)
|
|
|
+ if (_starpu_memory_manager_can_allocate_size(dim, 0) == 0)
|
|
|
{
|
|
|
size_t freed;
|
|
|
- size_t reclaim = 2 * dimsize;
|
|
|
+ size_t reclaim = 2 * dim;
|
|
|
_STARPU_DEBUG("There is not enough memory left, we are going to reclaim %ld\n", reclaim);
|
|
|
_STARPU_TRACE_START_MEMRECLAIM(0);
|
|
|
freed = _starpu_memory_reclaim_generic(0, 0, reclaim);
|
|
@@ -117,7 +112,7 @@ int starpu_malloc(void **A, size_t dim)
|
|
|
#ifdef STARPU_USE_CUDA
|
|
|
#ifdef HAVE_CUDA_MEMCPY_PEER
|
|
|
cudaError_t cures;
|
|
|
- cures = cudaHostAlloc(&ptr, dimsize, cudaHostAllocPortable);
|
|
|
+ cures = cudaHostAlloc(A, dim, cudaHostAllocPortable);
|
|
|
if (STARPU_UNLIKELY(cures))
|
|
|
STARPU_CUDA_REPORT_ERROR(cures);
|
|
|
#else
|
|
@@ -125,8 +120,8 @@ int starpu_malloc(void **A, size_t dim)
|
|
|
|
|
|
struct malloc_pinned_codelet_struct s =
|
|
|
{
|
|
|
- .ptr = &ptr,
|
|
|
- .dim = dimsize
|
|
|
+ .ptr = A,
|
|
|
+ .dim = dim
|
|
|
};
|
|
|
|
|
|
malloc_pinned_cl.where = STARPU_CUDA;
|
|
@@ -151,8 +146,8 @@ int starpu_malloc(void **A, size_t dim)
|
|
|
//
|
|
|
// struct malloc_pinned_codelet_struct s =
|
|
|
// {
|
|
|
-// .ptr = &ptr,
|
|
|
-// .dim = dimsize
|
|
|
+// .ptr = A,
|
|
|
+// .dim = dim
|
|
|
// };
|
|
|
//
|
|
|
// malloc_pinned_cl.where = STARPU_OPENCL;
|
|
@@ -175,30 +170,28 @@ int starpu_malloc(void **A, size_t dim)
|
|
|
#ifdef STARPU_HAVE_POSIX_MEMALIGN
|
|
|
if (malloc_align != sizeof(void*))
|
|
|
{
|
|
|
- if (posix_memalign(&ptr, malloc_align, dimsize))
|
|
|
+ if (posix_memalign(A, malloc_align, dim))
|
|
|
{
|
|
|
ret = -ENOMEM;
|
|
|
- ptr = NULL;
|
|
|
+ *A = NULL;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
#elif defined(STARPU_HAVE_MEMALIGN)
|
|
|
if (malloc_align != sizeof(void*))
|
|
|
{
|
|
|
- ptr = memalign(malloc_align, dimsize);
|
|
|
+ *A = memalign(malloc_align, dim);
|
|
|
}
|
|
|
else
|
|
|
#endif /* STARPU_HAVE_POSIX_MEMALIGN */
|
|
|
{
|
|
|
- ptr = malloc(dimsize);
|
|
|
+ *A = malloc(dim);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (ret == 0)
|
|
|
{
|
|
|
- STARPU_ASSERT(ptr);
|
|
|
- memcpy(ptr, &dim, sizeof(size_t));
|
|
|
- *A = ptr + sizeof(size_t);
|
|
|
+ STARPU_ASSERT(*A);
|
|
|
}
|
|
|
|
|
|
return ret;
|
|
@@ -243,15 +236,10 @@ static struct starpu_codelet free_pinned_cl =
|
|
|
|
|
|
int starpu_free(void *A)
|
|
|
{
|
|
|
- void *ptr = A - sizeof(size_t);
|
|
|
- size_t dim;
|
|
|
-
|
|
|
- memcpy(&dim, ptr, sizeof(size_t));
|
|
|
-
|
|
|
if (STARPU_UNLIKELY(!_starpu_worker_may_perform_blocking_calls()))
|
|
|
return -EDEADLK;
|
|
|
|
|
|
- _starpu_memory_manager_deallocate_size(dim, 0);
|
|
|
+ //_starpu_memory_manager_deallocate_size(dim, 0);
|
|
|
|
|
|
#ifndef STARPU_SIMGRID
|
|
|
#ifdef STARPU_USE_CUDA
|
|
@@ -264,7 +252,7 @@ int starpu_free(void *A)
|
|
|
/* This is especially useful when starpu_free is called from
|
|
|
* the GCC-plugin. starpu_shutdown will probably have already
|
|
|
* been called, so we will not be able to submit a task. */
|
|
|
- cudaError_t err = cudaFreeHost(ptr);
|
|
|
+ cudaError_t err = cudaFreeHost(A);
|
|
|
if (STARPU_UNLIKELY(err))
|
|
|
STARPU_CUDA_REPORT_ERROR(err);
|
|
|
#ifndef HAVE_CUDA_MEMCPY_PEER
|
|
@@ -277,7 +265,7 @@ int starpu_free(void *A)
|
|
|
struct starpu_task *task = starpu_task_create();
|
|
|
task->callback_func = NULL;
|
|
|
task->cl = &free_pinned_cl;
|
|
|
- task->cl_arg = ptr;
|
|
|
+ task->cl_arg = A;
|
|
|
|
|
|
task->synchronous = 1;
|
|
|
|
|
@@ -296,7 +284,7 @@ int starpu_free(void *A)
|
|
|
// struct starpu_task *task = starpu_task_create();
|
|
|
// task->callback_func = NULL;
|
|
|
// task->cl = &free_pinned_cl;
|
|
|
-// task->cl_arg = ptr;
|
|
|
+// task->cl_arg = A;
|
|
|
//
|
|
|
// task->synchronous = 1;
|
|
|
//
|
|
@@ -310,7 +298,7 @@ int starpu_free(void *A)
|
|
|
#endif
|
|
|
#endif
|
|
|
{
|
|
|
- free(ptr);
|
|
|
+ free(A);
|
|
|
}
|
|
|
|
|
|
return 0;
|