|
|
@@ -24,6 +24,15 @@
|
|
|
#include <starpu_cuda.h>
|
|
|
#include <drivers/opencl/driver_opencl.h>
|
|
|
|
|
|
+static size_t malloc_align = sizeof(void*);
|
|
|
+
|
|
|
+void starpu_malloc_set_align(size_t align)
|
|
|
+{
|
|
|
+ STARPU_ASSERT_MSG(!(align & (align - 1)), "Alignment given to starpu_malloc_set_align must be a power of two");
|
|
|
+ if (malloc_align < align)
|
|
|
+ malloc_align = align;
|
|
|
+}
|
|
|
+
|
|
|
#if (defined(STARPU_USE_CUDA) && !defined(HAVE_CUDA_MEMCPY_PEER))// || defined(STARPU_USE_OPENCL)
|
|
|
struct malloc_pinned_codelet_struct
|
|
|
{
|
|
|
@@ -32,6 +41,8 @@ struct malloc_pinned_codelet_struct
|
|
|
};
|
|
|
#endif
|
|
|
|
|
|
+/* Would be difficult to do it this way, we need to remember the cl_mem to be able to free it later... */
|
|
|
+
|
|
|
//#ifdef STARPU_USE_OPENCL
|
|
|
//static void malloc_pinned_opencl_codelet(void *buffers[] STARPU_ATTRIBUTE_UNUSED, void *arg)
|
|
|
//{
|
|
|
@@ -144,7 +155,23 @@ int starpu_malloc(void **A, size_t dim)
|
|
|
else
|
|
|
#endif
|
|
|
{
|
|
|
- *A = malloc(dim);
|
|
|
+#ifdef STARPU_HAVE_POSIX_MEMALIGN
|
|
|
+ if (malloc_align != sizeof(void*))
|
|
|
+ {
|
|
|
+ if (posix_memalign(A, malloc_align, dim))
|
|
|
+ *A = NULL;
|
|
|
+ }
|
|
|
+ else
|
|
|
+#elif defined(STARPU_HAVE_MEMALIGN)
|
|
|
+ if (malloc_align != sizeof(void*))
|
|
|
+ {
|
|
|
+ *A = memalign(malloc_align, dim);
|
|
|
+ }
|
|
|
+ else
|
|
|
+#endif
|
|
|
+ {
|
|
|
+ *A = malloc(dim);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
STARPU_ASSERT(*A);
|