瀏覽代碼

Add starpu_data_dup_ro()

Samuel Thibault 4 年之前
父節點
當前提交
b88202175b
共有 5 個文件被更改,包括 111 次插入0 次删除
  1. 1 0
      ChangeLog
  2. 14 0
      include/starpu_helper.h
  3. 8 0
      src/util/starpu_data_cpy.c
  4. 1 0
      tests/Makefile.am
  5. 87 0
      tests/helper/starpu_data_dup_ro.c

+ 1 - 0
ChangeLog

@@ -41,6 +41,7 @@ New features:
     StarPU.
   * Add a task prefetch level, to improve retaining data in accelerators so we
     can make prefetch more aggressive.
+  * Add starpu_data_dup_ro().
 
 Small changes:
   * Use the S4U interface of Simgrid instead of xbt and MSG.

+ 14 - 0
include/starpu_helper.h

@@ -187,6 +187,20 @@ double starpu_timing_now(void);
 int starpu_data_cpy(starpu_data_handle_t dst_handle, starpu_data_handle_t src_handle, int asynchronous, void (*callback_func)(void*), void *callback_arg);
 
 /**
+   Create a copy of \p src_handle, and return a new handle in \p dst_handle,
+   which is to be used only for read accesses. This allows StarPU to optimize it
+   by not actually copying the data whenever possible.
+   The parameter \p asynchronous indicates whether the function should block
+   or not. In the case of an asynchronous call, it is possible to synchronize
+   with the termination of this operation either by the means of implicit
+   dependencies (if enabled) or by calling starpu_task_wait_for_all(). If
+   \p callback_func is not <c>NULL</c>, this callback function is executed after
+   the handle has been copied, and it is given the pointer \p
+   callback_arg as argument.
+*/
+int starpu_data_dup_ro(starpu_data_handle_t *dst_handle, starpu_data_handle_t src_handle, int asynchronous, void (*callback_func)(void*), void *callback_arg);
+
+/**
    Call hwloc-ps to display binding of each processus and thread running on
    the machine.<br>
    Use the environment variable \ref STARPU_DISPLAY_BINDINGS to automatically

+ 8 - 0
src/util/starpu_data_cpy.c

@@ -175,3 +175,11 @@ int starpu_data_cpy(starpu_data_handle_t dst_handle, starpu_data_handle_t src_ha
 {
 	return _starpu_data_cpy(dst_handle, src_handle, asynchronous, callback_func, callback_arg, 0, NULL);
 }
+
+int starpu_data_dup_ro(starpu_data_handle_t *dst_handle, starpu_data_handle_t src_handle,
+			int asynchronous, void (*callback_func)(void*), void *callback_arg)
+{
+	/* TODO: optimize when src_handle is already a read-only handle or already has a read-only duplicate */
+	starpu_data_register_same(dst_handle, src_handle);
+	return _starpu_data_cpy(*dst_handle, src_handle, asynchronous, callback_func, callback_arg, 0, NULL);
+}

+ 1 - 0
tests/Makefile.am

@@ -344,6 +344,7 @@ myPROGRAMS +=				\
 	errorcheck/workers_cpuid		\
 	fault-tolerance/retry			\
 	helper/starpu_data_cpy			\
+	helper/starpu_data_dup_ro		\
 	helper/starpu_create_sync_task		\
 	microbenchs/async_tasks_overhead	\
 	microbenchs/sync_tasks_overhead		\

+ 87 - 0
tests/helper/starpu_data_dup_ro.c

@@ -0,0 +1,87 @@
+/* StarPU --- Runtime system for heterogeneous multicore architectures.
+ *
+ * Copyright (C) 2010-2020  Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
+ *
+ * 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
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * StarPU is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * See the GNU Lesser General Public License in COPYING.LGPL for more details.
+ */
+
+#include <starpu.h>
+#include "../helper.h"
+
+/*
+ * Test starpu_data_dup_ro
+ */
+
+int main(int argc, char **argv)
+{
+	int ret;
+	int var1, *var2, *var3, *var4;
+	starpu_data_handle_t var1_handle, var2_handle, var3_handle, var4_handle;
+
+	ret = starpu_initialize(NULL, &argc, &argv);
+	if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
+	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
+
+	var1 = 42;
+
+	starpu_variable_data_register(&var1_handle, STARPU_MAIN_RAM, (uintptr_t)&var1, sizeof(var1));
+
+	/* Make a duplicate of the original data */
+	ret = starpu_data_dup_ro(&var2_handle, var1_handle, 1, NULL, NULL);
+	STARPU_CHECK_RETURN_VALUE(ret, "starpu_data_dup_ro");
+
+	/* Make a second duplicate of the original data */
+	ret = starpu_data_dup_ro(&var3_handle, var1_handle, 1, NULL, NULL);
+	STARPU_CHECK_RETURN_VALUE(ret, "starpu_data_dup_ro");
+
+	/* Make a duplicate of a duplicate */
+	ret = starpu_data_dup_ro(&var4_handle, var2_handle, 1, NULL, NULL);
+	STARPU_CHECK_RETURN_VALUE(ret, "starpu_data_dup_ro");
+
+	starpu_data_acquire(var2_handle, STARPU_R);
+	var2 = starpu_data_get_local_ptr(var2_handle);
+	ret = EXIT_SUCCESS;
+	if (*var2 != var1)
+	{
+	     FPRINTF(stderr, "var2 is %d but it should be %d\n", *var2, var1);
+	     ret = EXIT_FAILURE;
+	}
+	starpu_data_release(var2_handle);
+
+	starpu_data_acquire(var3_handle, STARPU_R);
+	var3 = starpu_data_get_local_ptr(var3_handle);
+	ret = EXIT_SUCCESS;
+	if (*var3 != var1)
+	{
+	     FPRINTF(stderr, "var3 is %d but it should be %d\n", *var3, var1);
+	     ret = EXIT_FAILURE;
+	}
+	starpu_data_release(var3_handle);
+
+	starpu_data_acquire(var4_handle, STARPU_R);
+	var4 = starpu_data_get_local_ptr(var4_handle);
+	ret = EXIT_SUCCESS;
+	if (*var4 != var1)
+	{
+	     FPRINTF(stderr, "var4 is %d but it should be %d\n", *var4, var1);
+	     ret = EXIT_FAILURE;
+	}
+	starpu_data_release(var4_handle);
+
+	starpu_data_unregister(var1_handle);
+	starpu_data_unregister(var2_handle);
+	starpu_data_unregister(var3_handle);
+	starpu_data_unregister(var4_handle);
+	starpu_shutdown();
+
+	STARPU_RETURN(ret);
+}