Browse Source

factorize complex array example

Samuel Thibault 12 years ago
parent
commit
95c0fba186
1 changed files with 12 additions and 123 deletions
  1. 12 123
      examples/interface/complex_interface.c

+ 12 - 123
examples/interface/complex_interface.c

@@ -146,139 +146,28 @@ static int complex_unpack_data(starpu_data_handle_t handle, unsigned node, void
 	return 0;
 }
 
-#ifdef STARPU_USE_CUDA
-static int copy_cuda_async_sync(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, enum cudaMemcpyKind kind, cudaStream_t stream)
+static int copy_any_to_any(void *src_interface, unsigned src_node,
+			   void *dst_interface, unsigned dst_node,
+			   void *async_data)
 {
 	struct starpu_complex_interface *src_complex = src_interface;
 	struct starpu_complex_interface *dst_complex = dst_interface;
-
-	cudaStream_t sstream = stream;
-	int ret;
-
-	ret = starpu_cuda_copy_async_sync((void *)src_complex->real, src_node, (void *)dst_complex->real, dst_node,
-					  src_complex->nx*sizeof(src_complex->real[0]), sstream, kind);
-	if (ret == 0) sstream = NULL;
-
-	ret = starpu_cuda_copy_async_sync((char *)src_complex->imaginary, src_node, (char *)dst_complex->imaginary, dst_node,
-					  src_complex->nx*sizeof(src_complex->imaginary[0]), sstream, kind);
-	return ret;
-}
-
-static int copy_ram_to_cuda(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node)
-{
-     return copy_cuda_async_sync(src_interface, src_node, dst_interface, dst_node, cudaMemcpyHostToDevice, NULL);
-}
-
-static int copy_ram_to_cuda_async(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, cudaStream_t stream)
-{
-	return copy_cuda_async_sync(src_interface, src_node, dst_interface, dst_node, cudaMemcpyHostToDevice, stream);
-}
-
-static int copy_cuda_to_ram(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node)
-{
-	return copy_cuda_async_sync(src_interface, src_node, dst_interface, dst_node, cudaMemcpyDeviceToHost, NULL);
-}
-
-static int copy_cuda_to_ram_async(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, cudaStream_t stream)
-{
-	return copy_cuda_async_sync(src_interface, src_node, dst_interface, dst_node, cudaMemcpyDeviceToHost, stream);
-}
-#endif
-
-#ifdef STARPU_USE_OPENCL
-static int copy_ram_to_opencl_async(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, cl_event *event)
-{
-	struct starpu_complex_interface *src_complex = src_interface;
-	struct starpu_complex_interface *dst_complex = dst_interface;
-	cl_int err;
 	int ret;
 
-	err = starpu_opencl_copy_ram_to_opencl(src_complex->real,
-					       src_node,
-					       (cl_mem) dst_complex->real,
-					       dst_node,
-					       src_complex->nx * sizeof(src_complex->real[0]),
-					       0,
-					       event,
-					       &ret);
-	if (STARPU_UNLIKELY(err != CL_SUCCESS))
-		STARPU_OPENCL_REPORT_ERROR(err);
-	if (ret == 0)
-		event = NULL;
-
-	err = starpu_opencl_copy_ram_to_opencl(src_complex->imaginary,
-					       src_node,
-					       (cl_mem) dst_complex->imaginary,
-					       dst_node,
-					       src_complex->nx * sizeof(src_complex->imaginary[0]),
-					       0,
-					       event,
-					       &ret);
-	if (STARPU_UNLIKELY(err != CL_SUCCESS))
-		STARPU_OPENCL_REPORT_ERROR(err);
-
+	ret = starpu_interface_copy((uintptr_t) src_complex->real, 0, src_node,
+				    (uintptr_t) dst_complex->real, 0, dst_node,
+				     src_complex->nx*sizeof(src_complex->real[0]),
+				     async_data);
+	ret = starpu_interface_copy((uintptr_t) src_complex->imaginary, 0, src_node,
+				    (uintptr_t) dst_complex->imaginary, 0, dst_node,
+				     src_complex->nx*sizeof(src_complex->imaginary[0]),
+				     async_data);
 	return ret;
 }
 
-static int copy_ram_to_opencl(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node)
-{
-        return copy_ram_to_opencl_async(src_interface, src_node, dst_interface, dst_node, NULL);
-}
-
-static int copy_opencl_to_ram_async(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, cl_event *event)
-{
-	struct starpu_complex_interface *src_complex = src_interface;
-	struct starpu_complex_interface *dst_complex = dst_interface;
-	cl_int err;
-	int ret;
-
-	err = starpu_opencl_copy_opencl_to_ram((cl_mem) src_complex->real,
-					       src_node,
-					       dst_complex->real,
-					       dst_node,
-					       src_complex->nx * sizeof(src_complex->real[0]),
-					       0,
-					       event,
-					       &ret);
-	if (STARPU_UNLIKELY(err != CL_SUCCESS))
-		STARPU_OPENCL_REPORT_ERROR(err);
-	if (ret == 0)
-		event = NULL;
-
-	err = starpu_opencl_copy_opencl_to_ram((cl_mem) src_complex->imaginary,
-					       src_node,
-					       dst_complex->imaginary,
-					       dst_node,
-					       src_complex->nx * sizeof(src_complex->imaginary[0]),
-					       0,
-					       event,
-					       &ret);
-	if (STARPU_UNLIKELY(err != CL_SUCCESS))
-		STARPU_OPENCL_REPORT_ERROR(err);
-
-	return ret;
-}
-
-static int copy_opencl_to_ram(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node)
-{
-        return copy_opencl_to_ram_async(src_interface, src_node, dst_interface, dst_node, NULL);
-}
-#endif
-
 static const struct starpu_data_copy_methods complex_copy_methods =
 {
-#ifdef STARPU_USE_CUDA
-	.ram_to_cuda = copy_ram_to_cuda,
-	.cuda_to_ram = copy_cuda_to_ram,
-	.ram_to_cuda_async = copy_ram_to_cuda_async,
-	.cuda_to_ram_async = copy_cuda_to_ram_async,
-#endif
-#ifdef STARPU_USE_OPENCL
-	.ram_to_opencl = copy_ram_to_opencl,
-	.opencl_to_ram = copy_opencl_to_ram,
-	.ram_to_opencl_async = copy_ram_to_opencl_async,
-	.opencl_to_ram_async = copy_opencl_to_ram_async,
-#endif
+	.any_to_any = copy_any_to_any
 };
 
 static struct starpu_data_interface_ops interface_complex_ops =