Browse Source

Allow to call starpu_sched_ctx_set_policy_data on the main scheduler context

Nathalie Furmento 8 years ago
parent
commit
19cb8109bd
5 changed files with 71 additions and 2 deletions
  1. 2 0
      ChangeLog
  2. 1 1
      src/core/sched_ctx.c
  3. 1 1
      src/core/workers.h
  4. 4 0
      tests/Makefile.am
  5. 63 0
      tests/sched_ctx/sched_ctx_policy_data.c

+ 2 - 0
ChangeLog

@@ -49,6 +49,8 @@ Changes:
 
 
 Small changes:
 Small changes:
   * Use asynchronous transfers for task data fetches with were not prefetched.
   * Use asynchronous transfers for task data fetches with were not prefetched.
+  * Allow to call starpu_sched_ctx_set_policy_data on the main
+    scheduler context
 
 
 StarPU 1.2.2 (svn revision xxx)
 StarPU 1.2.2 (svn revision xxx)
 ==============================================
 ==============================================

+ 1 - 1
src/core/sched_ctx.c

@@ -1541,7 +1541,7 @@ void _starpu_init_all_sched_ctxs(struct _starpu_machine_config *config)
 	nobind = starpu_get_env_number("STARPU_WORKERS_NOBIND");
 	nobind = starpu_get_env_number("STARPU_WORKERS_NOBIND");
 
 
 	unsigned i;
 	unsigned i;
-	for(i = 0; i < STARPU_NMAX_SCHED_CTXS; i++)
+	for(i = 0; i <= STARPU_NMAX_SCHED_CTXS; i++)
 		config->sched_ctxs[i].id = STARPU_NMAX_SCHED_CTXS;
 		config->sched_ctxs[i].id = STARPU_NMAX_SCHED_CTXS;
 
 
 	return;
 	return;

+ 1 - 1
src/core/workers.h

@@ -538,7 +538,7 @@ static inline struct _starpu_worker *_starpu_get_worker_struct(unsigned id)
  * specified ctx */
  * specified ctx */
 static inline struct _starpu_sched_ctx *_starpu_get_sched_ctx_struct(unsigned id)
 static inline struct _starpu_sched_ctx *_starpu_get_sched_ctx_struct(unsigned id)
 {
 {
-	if(id == STARPU_NMAX_SCHED_CTXS) return NULL;
+	if(id > STARPU_NMAX_SCHED_CTXS) return NULL;
 	return &_starpu_config.sched_ctxs[id];
 	return &_starpu_config.sched_ctxs[id];
 }
 }
 
 

+ 4 - 0
tests/Makefile.am

@@ -160,6 +160,7 @@ myPROGRAMS +=					\
 	microbenchs/display_structures_size	\
 	microbenchs/display_structures_size	\
 	microbenchs/local_pingpong		\
 	microbenchs/local_pingpong		\
 	sched_ctx/sched_ctx_list		\
 	sched_ctx/sched_ctx_list		\
+	sched_ctx/sched_ctx_policy_data		\
 	perfmodels/value_nan
 	perfmodels/value_nan
 
 
 if !STARPU_SIMGRID
 if !STARPU_SIMGRID
@@ -602,6 +603,9 @@ endif
 sched_ctx_sched_ctx_list_SOURCES =	\
 sched_ctx_sched_ctx_list_SOURCES =	\
 	sched_ctx/sched_ctx_list.c
 	sched_ctx/sched_ctx_list.c
 
 
+sched_ctx_sched_ctx_policy_data_SOURCES =	\
+	sched_ctx/sched_ctx_policy_data.c
+
 sched_ctx_sched_ctx_hierarchy_SOURCES =	\
 sched_ctx_sched_ctx_hierarchy_SOURCES =	\
 	sched_ctx/sched_ctx_hierarchy.c
 	sched_ctx/sched_ctx_hierarchy.c
 
 

+ 63 - 0
tests/sched_ctx/sched_ctx_policy_data.c

@@ -0,0 +1,63 @@
+/* StarPU --- Runtime system for heterogeneous multicore architectures.
+ *
+ * Copyright (C) 2015  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 <config.h>
+#include <starpu.h>
+#include "../helper.h"
+
+int main(int argc, char **argv)
+{
+	int ret;
+	int nprocs;
+	int *procs;
+
+	unsigned sched_ctx;
+	unsigned main_sched_ctx;
+	int *ptr;
+	int *main_ptr;
+
+	ret = starpu_init(NULL);
+	if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
+	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
+
+	nprocs = starpu_worker_get_count();
+	procs = (int*)malloc(nprocs*sizeof(int));
+	starpu_worker_get_ids_by_type(STARPU_ANY_WORKER, procs, nprocs);
+
+	sched_ctx = starpu_sched_ctx_create(procs, nprocs, "my_context", 0);
+	ptr = starpu_sched_ctx_get_policy_data(sched_ctx);
+	STARPU_ASSERT_MSG(ptr == NULL, "The policy data for the sched ctx should be NULL\n");
+
+	starpu_sched_ctx_set_policy_data(sched_ctx, procs);
+	ptr = starpu_sched_ctx_get_policy_data(sched_ctx);
+	FPRINTF(stderr, "sched_ctx %d : data %p (procs %p)\n", sched_ctx, ptr, procs);
+	STARPU_ASSERT_MSG(ptr == procs, "The policy data for the sched ctx is incorrect\n");
+
+	main_sched_ctx = starpu_sched_ctx_get_context();
+	main_ptr = starpu_sched_ctx_get_policy_data(main_sched_ctx);
+	STARPU_ASSERT_MSG(main_ptr == NULL, "The policy data for the sched ctx should be NULL\n");
+
+	starpu_sched_ctx_set_policy_data(main_sched_ctx, procs);
+	main_ptr = starpu_sched_ctx_get_policy_data(sched_ctx);
+	FPRINTF(stderr, "sched_ctx %d : data %p (procs %p)\n", main_sched_ctx, main_ptr, procs);
+	STARPU_ASSERT_MSG(main_ptr == procs, "The policy data for the sched ctx is incorrect\n");
+
+	starpu_sched_ctx_delete(sched_ctx);
+	free(procs);
+	starpu_shutdown();
+
+	return (ptr == procs) ? 0 : 1;
+}