Forráskód Böngészése

CUDA Driver: add function to copy data

	int starpu_cuda_copy_async_sync (void *src_ptr, unsigned src_node, void *dst_ptr, unsigned dst_node, size_t ssize, cudaStream_t stream, enum cudaMemcpyKind kind)

	Copy ssize bytes from the pointer src_ptr on
 	src_node to the pointer dst_ptr on dst_node.
	The function first tries to copy the data asynchronous (unless
	stream is NULL. If the asynchronous copy fails or if
	stream is NULL, it copies the data synchronously.
	The function returns -EAGAIN if the asynchronous copy was
	successfull. It returns 0 if the synchronous copy was successful, or
	fails otherwise.
Nathalie Furmento 13 éve
szülő
commit
462e9d0032
3 módosított fájl, 42 hozzáadás és 2 törlés
  1. 11 0
      doc/chapters/basic-api.texi
  2. 3 1
      include/starpu_cuda.h
  3. 28 1
      src/drivers/cuda/driver_cuda.c

+ 11 - 0
doc/chapters/basic-api.texi

@@ -2106,6 +2106,17 @@ Calls starpu_cuda_report_error, passing the current function, file and line
 position.
 @end defmac
 
+@deftypefun int starpu_cuda_copy_async_sync ({void *}@var{src_ptr}, unsigned @var{src_node}, {void *}@var{dst_ptr}, unsigned @var{dst_node}, size_t @var{ssize}, cudaStream_t @var{stream}, {enum cudaMemcpyKind} @var{kind})
+Copy @var{ssize} bytes from the pointer @var{src_ptr} on
+@var{src_node} to the pointer @var{dst_ptr} on @var{dst_node}.
+The function first tries to copy the data asynchronous (unless
+@var{stream} is @code{NULL}. If the asynchronous copy fails or if
+@var{stream} is @code{NULL}, it copies the data synchronously.
+The function returns @code{-EAGAIN} if the asynchronous copy was
+successfull. It returns 0 if the synchronous copy was successful, or
+fails otherwise.
+@end deftypefun
+
 @deftypefun void starpu_helper_cublas_init (void)
 This function initializes CUBLAS on every CUDA device.
 The CUBLAS library must be initialized prior to any CUBLAS call. Calling

+ 3 - 1
include/starpu_cuda.h

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2010-2011  Université de Bordeaux 1
- * Copyright (C) 2010, 2011  Centre National de la Recherche Scientifique
+ * Copyright (C) 2010, 2011, 2012  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -44,6 +44,8 @@ cudaStream_t starpu_cuda_get_local_stream(void);
 
 const struct cudaDeviceProp *starpu_cuda_get_device_properties(unsigned workerid);
 
+int starpu_cuda_copy_async_sync(void *src_ptr, unsigned src_node, void *dst_ptr, unsigned dst_node, size_t ssize, cudaStream_t stream, enum cudaMemcpyKind kind);
+
 #ifdef __cplusplus
 }
 #endif

+ 28 - 1
src/drivers/cuda/driver_cuda.c

@@ -2,7 +2,7 @@
  *
  * Copyright (C) 2009, 2010, 2011-2012  Université de Bordeaux 1
  * Copyright (C) 2010  Mehdi Juhoor <mjuhoor@gmail.com>
- * Copyright (C) 2010, 2011  Centre National de la Recherche Scientifique
+ * Copyright (C) 2010, 2011, 2012  Centre National de la Recherche Scientifique
  * Copyright (C) 2011  Télécom-SudParis
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -422,3 +422,30 @@ void starpu_cuda_report_error(const char *func, const char *file, int line, cuda
 	printf("oops in %s (%s:%u)... %d: %s \n", func, file, line, status, errormsg);
 	STARPU_ASSERT(0);
 }
+
+int starpu_cuda_copy_async_sync(void *src_ptr, unsigned src_node STARPU_ATTRIBUTE_UNUSED, void *dst_ptr, unsigned dst_node STARPU_ATTRIBUTE_UNUSED, size_t ssize, cudaStream_t stream, enum cudaMemcpyKind kind)
+{
+	cudaError_t cures = 0;
+
+	if (stream)
+	{
+	     _STARPU_TRACE_START_DRIVER_COPY_ASYNC(src_node, dst_node);
+	     cures = cudaMemcpyAsync((char *)dst_ptr, (char *)src_ptr, ssize, kind, stream);
+	     _STARPU_TRACE_END_DRIVER_COPY_ASYNC(src_node, dst_node);
+	}
+	/* Test if the asynchronous copy has failed or if the caller only asked for a synchronous copy */
+	if (stream == NULL || cures)
+	{
+		/* do it in a synchronous fashion */
+		cures = cudaMemcpy((char *)dst_ptr, (char *)src_ptr, ssize, kind);
+
+		if (STARPU_UNLIKELY(cures))
+			STARPU_CUDA_REPORT_ERROR(cures);
+
+		return 0;
+	}
+
+	_STARPU_TRACE_DATA_COPY(src_node, dst_node, ssize);
+
+	return -EAGAIN;
+}