소스 검색

tests: add testcase for creation of tasks within a specific sched_ctx

Nathalie Furmento 8 년 전
부모
커밋
2f91070513
2개의 변경된 파일158개의 추가작업 그리고 1개의 파일을 삭제
  1. 5 1
      tests/Makefile.am
  2. 153 0
      tests/sched_ctx/sched_ctx_hierarchy.c

+ 5 - 1
tests/Makefile.am

@@ -1,7 +1,7 @@
 # StarPU --- Runtime system for heterogeneous multicore architectures.
 #
 # Copyright (C) 2009-2017  Université de Bordeaux
-# Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016  CNRS
+# Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017  CNRS
 # Copyright (C) 2010, 2011, 2012  INRIA
 #
 # StarPU is free software; you can redistribute it and/or modify
@@ -153,6 +153,7 @@ myPROGRAMS +=				\
 	microbenchs/display_structures_size	\
 	microbenchs/local_pingpong		\
 	sched_ctx/sched_ctx_list		\
+	sched_ctx/sched_ctx_hierarchy		\
 	perfmodels/value_nan
 
 if !STARPU_SIMGRID
@@ -575,6 +576,9 @@ endif
 sched_ctx_sched_ctx_list_SOURCES =	\
 	sched_ctx/sched_ctx_list.c
 
+sched_ctx_sched_ctx_hierarchy_SOURCES =	\
+	sched_ctx/sched_ctx_hierarchy.c
+
 openmp_init_exit_01_SOURCES = 	\
 	openmp/init_exit_01.c
 

+ 153 - 0
tests/sched_ctx/sched_ctx_hierarchy.c

@@ -0,0 +1,153 @@
+/* StarPU --- Runtime system for heterogeneous multicore architectures.
+ *
+ * Copyright (C) 2017  CNRS
+ *
+ * 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 <config.h>
+#include <starpu.h>
+#include "../helper.h"
+
+struct starpu_codelet mycodelet_bis;
+void func_cpu_bis(void *descr[], void *_args)
+{
+	char msg;
+	char worker_name[256];
+	int worker_id = starpu_worker_get_id();
+	int worker_id_expected;
+	int ntasks;
+
+	starpu_worker_get_name(worker_id, worker_name, 256);
+	starpu_codelet_unpack_args(_args, &msg, &ntasks, &worker_id_expected);
+
+	STARPU_ASSERT(worker_id == worker_id_expected);
+
+	FPRINTF(stderr, "[msg '%c'] [worker id %d] [worker name %s] [tasks %d]\n", msg, worker_id, worker_name, ntasks);
+	if (ntasks > 0)
+	{
+		int nntasks = ntasks - 1;
+		starpu_task_insert(&mycodelet_bis,
+				   STARPU_VALUE, &msg, sizeof(msg),
+				   STARPU_VALUE, &nntasks, sizeof(ntasks),
+				   STARPU_VALUE, &worker_id, sizeof(worker_id),
+				   0);
+	}
+}
+
+struct starpu_codelet mycodelet_bis =
+{
+	.cpu_funcs = {func_cpu_bis},
+	.cpu_funcs_name = {"func_cpu_bis"},
+};
+
+void func_cpu(void *descr[], void *_args)
+{
+	char msg;
+	char worker_name[256];
+	int worker_id = starpu_worker_get_id();
+	int worker_id_expected;
+	int ntasks;
+	unsigned sched_ctx_id;
+	unsigned *sched_ctx_id_p = malloc(sizeof(unsigned));
+
+	starpu_worker_get_name(worker_id, worker_name, 256);
+	starpu_codelet_unpack_args(_args, &msg, &ntasks, &sched_ctx_id, &worker_id_expected);
+
+	STARPU_ASSERT(worker_id == worker_id_expected);
+
+	*sched_ctx_id_p = sched_ctx_id;
+	starpu_sched_ctx_set_context(sched_ctx_id_p);
+
+	FPRINTF(stderr, "[msg '%c'] [worker id %d] [worker name %s] [sched_ctx_id %u] [tasks %d]\n", msg, worker_id, worker_name, sched_ctx_id, ntasks);
+	if (ntasks > 0)
+	{
+		int nntasks = ntasks - 1;
+		starpu_task_insert(&mycodelet_bis,
+				   STARPU_VALUE, &msg, sizeof(msg),
+				   STARPU_VALUE, &nntasks, sizeof(nntasks),
+				   STARPU_VALUE, &worker_id, sizeof(worker_id),
+				   0);
+	}
+}
+
+struct starpu_codelet mycodelet =
+{
+	.cpu_funcs = {func_cpu},
+	.cpu_funcs_name = {"func_cpu"},
+};
+
+int main(int argc, char **argv)
+{
+        int i, ret;
+	int nprocs, nprocs_per_context=1;
+        int procs[STARPU_NMAXWORKERS];
+	int ntasks=10;
+	char msg[2] = "ab";
+
+	ret = starpu_init(NULL);
+	if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
+	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
+
+        nprocs = starpu_cpu_worker_get_count();
+	if (nprocs < 2) goto enodev;
+
+	nprocs_per_context = 1;
+	FPRINTF(stderr, "# Workers = %d -> %d worker for each sched context\n", nprocs, nprocs_per_context);
+        starpu_worker_get_ids_by_type(STARPU_CPU_WORKER, procs, nprocs);
+
+	unsigned sched_ctx_0 = starpu_sched_ctx_create(procs, nprocs_per_context, "ctx_0", 0);
+	unsigned sched_ctx_1 = starpu_sched_ctx_create(&procs[nprocs_per_context], nprocs_per_context, "ctx_1", 0);
+
+	if (!getenv("STARPU_SSILENT"))
+	{
+		char name0[256];
+		char name1[256];
+
+		starpu_worker_get_name(procs[0], name0, 256);
+		starpu_worker_get_name(procs[1], name1, 256);
+
+		FPRINTF(stderr, "Creating first sched_ctx with %d worker [id %d name %s]\n", nprocs_per_context, procs[0], name0);
+		FPRINTF(stderr, "Creating second sched_ctx with %d worker [id %d name %s]\n", nprocs_per_context, procs[1], name1);
+
+		starpu_sched_ctx_display_workers(sched_ctx_0, stderr);
+		starpu_sched_ctx_display_workers(sched_ctx_1, stderr);
+	}
+
+	ret = starpu_task_insert(&mycodelet, STARPU_SCHED_CTX, sched_ctx_0,
+				 STARPU_VALUE, &msg[0], sizeof(msg[0]),
+				 STARPU_VALUE, &ntasks, sizeof(ntasks),
+				 STARPU_VALUE, &sched_ctx_0, sizeof(sched_ctx_0),
+				 STARPU_VALUE, &procs[0], sizeof(procs[0]),
+				 0);
+	STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
+	ret = starpu_task_insert(&mycodelet, STARPU_SCHED_CTX, sched_ctx_1,
+				 STARPU_VALUE, &msg[1], sizeof(msg[1]),
+				 STARPU_VALUE, &ntasks, sizeof(ntasks),
+				 STARPU_VALUE, &sched_ctx_1, sizeof(sched_ctx_1),
+				 STARPU_VALUE, &procs[1], sizeof(procs[1]),
+				 0);
+	STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
+
+	starpu_task_wait_for_all();
+	starpu_sched_ctx_delete(sched_ctx_0);
+	starpu_sched_ctx_delete(sched_ctx_1);
+	starpu_shutdown();
+	return 0;
+
+enodev:
+	starpu_shutdown();
+	fprintf(stderr, "WARNING: No one can execute this task\n");
+	/* yes, we do not perform the computation but we did detect that no one
+ 	 * could perform the kernel, so this is not an error from StarPU */
+	return STARPU_TEST_SKIPPED;
+}