| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907 | 
							- /* StarPU --- Runtime system for heterogeneous multicore architectures.
 
-  *
 
-  * Copyright (C) 2011-2013,2017                           Inria
 
-  * Copyright (C) 2011-2015,2017                           CNRS
 
-  * Copyright (C) 2011-2013,2015,2017,2018                 Université de Bordeaux
 
-  *
 
-  * 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>
 
- /* XXX Why cant we dereference a handle without this one ? */
 
- #include <core/sched_policy.h>
 
- #include <assert.h>
 
- #include "test_interfaces.h"
 
- #include "../../helper.h"
 
- /*
 
-  * This is definitely note thread-safe.
 
-  */
 
- static struct test_config *current_config;
 
- /* TODO :
 
- - OpenCL to OpenCL support
 
- */
 
- static char *
 
- enum_to_string(int exit_code)
 
- {
 
- 	switch (exit_code)
 
- 	{
 
- 		case SUCCESS:
 
- 			return "Success";
 
- 		case FAILURE:
 
- 			return "Failure";
 
- 		case UNTESTED:
 
- 			return "Untested";
 
- 		case TASK_CREATION_FAILURE:
 
- 			return "Task creation failed";
 
- 		case TASK_SUBMISSION_FAILURE:
 
- 			return "Task submission failed";
 
- 		default:
 
- 			assert(0);
 
- 	}
 
- }
 
- struct data_interface_test_summary
 
- {
 
- 	int success;
 
- 	/* Copy methods */
 
- #ifdef STARPU_USE_CPU
 
- 	int cpu_to_cpu;
 
- #endif
 
- #ifdef STARPU_USE_CUDA
 
- 	int cpu_to_cuda;
 
- 	int cuda_to_cuda;
 
- 	int cuda_to_cpu;
 
- 	int cpu_to_cuda_async;
 
- 	int cuda_to_cpu_async;
 
- 	int cuda_to_cuda_async;
 
- #endif
 
- #ifdef STARPU_USE_OPENCL
 
- 	int cpu_to_opencl;
 
- 	int opencl_to_cpu;
 
- 	int cpu_to_opencl_async;
 
- 	int opencl_to_cpu_async;
 
- #endif
 
- #ifdef STARPU_USE_MIC
 
- 	int cpu_to_mic;
 
- 	int mic_to_cpu;
 
- 	int cpu_to_mic_async;
 
- 	int mic_to_cpu_async;
 
- #endif
 
- 	/* Other stuff */
 
- 	int compare;
 
- #ifdef STARPU_USE_CPU
 
- 	int to_pointer;
 
- 	int pointer_is_inside;
 
- #endif
 
- };
 
- void data_interface_test_summary_print(FILE *f,
 
- 				       struct data_interface_test_summary *s)
 
- {
 
- 	if (!f)
 
- 		f = stderr;
 
- 	FPRINTF(f, "%s : %s\n",
 
- 		current_config->name, enum_to_string(s->success));
 
- 	FPRINTF(f, "Asynchronous :\n");
 
- #ifdef STARPU_USE_CUDA
 
- 	FPRINTF(f, "\tCPU    -> CUDA   : %s\n",
 
- 		enum_to_string(s->cpu_to_cuda_async));
 
- 	FPRINTF(f, "\tCUDA   -> CUDA   : %s\n",
 
- 			enum_to_string(s->cuda_to_cuda_async));
 
- 	FPRINTF(f, "\tCUDA   -> CPU    : %s\n",
 
- 			enum_to_string(s->cuda_to_cpu_async));
 
- #endif /* !STARPU_USE_CUDA */
 
- #ifdef STARPU_USE_OPENCL
 
- 	FPRINTF(f, "\tCPU    -> OpenCl : %s\n",
 
- 		enum_to_string(s->cpu_to_opencl_async));
 
- 	FPRINTF(f, "\tOpenCl -> CPU    : %s\n",
 
- 		enum_to_string(s->opencl_to_cpu_async));
 
- #endif /* !STARPU_USE_OPENCL */
 
- #ifdef STARPU_USE_MIC
 
- 	FPRINTF(f, "\tCPU	-> MIC : %s\n",
 
- 		enum_to_string(s->cpu_to_mic_async));
 
- 	FPRINTF(f, "\tMIC	-> CPU : %s\n",
 
- 		enum_to_string(s->mic_to_cpu_async));
 
- #endif
 
- 	FPRINTF(f, "Synchronous :\n");
 
- #ifdef STARPU_USE_CUDA
 
- 	FPRINTF(f, "\tCPU    -> CUDA   ; %s\n",
 
- 		enum_to_string(s->cpu_to_cuda));
 
- 	FPRINTF(f, "\tCUDA   -> CUDA   : %s\n",
 
- 		enum_to_string(s->cuda_to_cuda));
 
- 	FPRINTF(f, "\tCUDA   -> CPU    : %s\n",
 
- 		enum_to_string(s->cuda_to_cpu));
 
- #endif /* !STARPU_USE_CUDA */
 
- #ifdef STARPU_USE_OPENCL
 
- 	FPRINTF(f, "\tCPU    -> OpenCl : %s\n",
 
- 		enum_to_string(s->cpu_to_opencl));
 
- 	FPRINTF(f, "\tOpenCl -> CPU    : %s\n",
 
- 		enum_to_string(s->opencl_to_cpu));
 
- #endif /* !STARPU_USE_OPENCL */
 
- #ifdef STARPU_USE_MIC
 
- 	FPRINTF(f, "\tCPU	-> MIC : %s\n",
 
- 		enum_to_string(s->cpu_to_mic));
 
- 	FPRINTF(f, "\tMIC	-> CPU : %s\n",
 
- 		enum_to_string(s->mic_to_cpu));
 
- #endif
 
- #ifdef STARPU_USE_CPU
 
- 	FPRINTF(f, "CPU    -> CPU    : %s\n",
 
- 		enum_to_string(s->cpu_to_cpu));
 
- 	FPRINTF(f, "to_pointer() : %s\n",
 
- 		enum_to_string(s->to_pointer));
 
- 	FPRINTF(f, "pointer_is_inside() : %s\n",
 
- 		enum_to_string(s->pointer_is_inside));
 
- #endif /* !STARPU_USE_CPU */
 
- 	FPRINTF(f, "compare()        : %s\n",
 
- 		enum_to_string(s->compare));
 
- }
 
- int
 
- data_interface_test_summary_success(data_interface_test_summary *s)
 
- {
 
- 	return s->success;
 
- }
 
- enum operation
 
- {
 
- #ifdef STARPU_USE_CUDA
 
- 	CPU_TO_CUDA,
 
- 	CUDA_TO_CUDA,
 
- 	CUDA_TO_CPU,
 
- #endif /* !STARPU_USE_CUDA */
 
- #ifdef STARPU_USE_OPENCL
 
- 	CPU_TO_OPENCL,
 
- 	OPENCL_TO_CPU,
 
- #endif /* !STARPU_USE_OPENCL */
 
- #ifdef STARPU_USE_MIC
 
- 	CPU_TO_MIC,
 
- 	MIC_TO_CPU,
 
- #endif
 
- 	CPU_TO_CPU
 
- };
 
- static int*
 
- get_field(struct data_interface_test_summary *s, int async, enum operation op)
 
- {
 
- 	switch (op)
 
- 	{
 
- #ifdef STARPU_USE_CPU
 
- 	case CPU_TO_CPU:
 
- 		return &s->cpu_to_cpu;
 
- #endif
 
- #ifdef STARPU_USE_CUDA
 
- 	case CPU_TO_CUDA:
 
- 		return async?&s->cpu_to_cuda_async:&s->cpu_to_cuda;
 
- 	case CUDA_TO_CUDA:
 
- 		return async?&s->cuda_to_cuda_async:&s->cuda_to_cuda;
 
- 	case CUDA_TO_CPU:
 
- 		return async?&s->cuda_to_cpu_async:&s->cuda_to_cpu;
 
- #endif /* !STARPU_USE_CUDA */
 
- #ifdef STARPU_USE_OPENCL
 
- 	case CPU_TO_OPENCL:
 
- 		return async?&s->cpu_to_opencl_async:&s->cpu_to_opencl;
 
- 	case OPENCL_TO_CPU:
 
- 		return async?&s->opencl_to_cpu_async:&s->opencl_to_cpu;
 
- #endif /* !STARPU_USE_OPENCL */
 
- #ifdef STARPU_USE_MIC
 
- 	case CPU_TO_MIC:
 
- 		return async?&s->cpu_to_mic_async:&s->cpu_to_mic;
 
- 	case MIC_TO_CPU:
 
- 		return async?&s->mic_to_cpu_async:&s->mic_to_cpu;
 
- #endif
 
- 	default:
 
- 		STARPU_ABORT();
 
- 	}
 
- 	/* that instruction should never be reached */
 
- 	return NULL;
 
- }
 
- static void
 
- set_field(struct data_interface_test_summary *s, int async,
 
- 	  enum operation op, int ret)
 
- {
 
- 	int *field = get_field(s, async, op);
 
- 	switch (ret)
 
- 	{
 
- 		case SUCCESS:
 
- 			*field = SUCCESS;
 
- 			break;
 
- 		case FAILURE:
 
- 			*field = FAILURE;
 
- 			s->success = FAILURE;
 
- 			break;
 
- 		case UNTESTED:
 
- 			*field = UNTESTED;
 
- 			break;
 
- 		case TASK_CREATION_FAILURE:
 
- 			*field = TASK_CREATION_FAILURE;
 
- 			break;
 
- 		case TASK_SUBMISSION_FAILURE:
 
- 			*field = TASK_SUBMISSION_FAILURE;
 
- 			break;
 
- 		default:
 
- 			STARPU_ABORT();
 
- 	}
 
- }
 
- static struct data_interface_test_summary summary =
 
- {
 
- #ifdef STARPU_USE_CPU
 
- 	.cpu_to_cpu            = UNTESTED,
 
- 	.compare               = UNTESTED,
 
- #endif
 
- #ifdef STARPU_USE_CUDA
 
- 	.cpu_to_cuda           = UNTESTED,
 
- 	.cuda_to_cuda          = UNTESTED,
 
- 	.cuda_to_cpu           = UNTESTED,
 
- 	.cpu_to_cuda_async     = UNTESTED,
 
- 	.cuda_to_cpu_async     = UNTESTED,
 
- 	.cuda_to_cuda_async    = UNTESTED,
 
- #endif
 
- #ifdef STARPU_USE_OPENCL
 
- 	.cpu_to_opencl         = UNTESTED,
 
- 	.opencl_to_cpu         = UNTESTED,
 
- 	.cpu_to_opencl_async   = UNTESTED,
 
- 	.opencl_to_cpu_async   = UNTESTED,
 
- #endif
 
- #ifdef STARPU_USE_MIC
 
- 	.cpu_to_mic            = UNTESTED,
 
- 	.mic_to_cpu            = UNTESTED,
 
- 	.cpu_to_mic_async      = UNTESTED,
 
- 	.mic_to_cpu_async      = UNTESTED,
 
- #endif
 
- #ifdef STARPU_USE_CPU
 
- 	.to_pointer            = UNTESTED,
 
- 	.pointer_is_inside     = UNTESTED,
 
- #endif
 
- 	.success               = SUCCESS
 
- };
 
- /*
 
-  * This variable has to be either -1 or 1.
 
-  * The kernels should check that the ith value stored in the data interface is
 
-  * equal to i, if factor == 1, or -i, if factor == -1.
 
-  */
 
- static int factor = -1;
 
- /*
 
-  * Creates a complete task, only knowing on what device it should be executed.
 
-  * Note that the global variable <current_config> is heavily used here.
 
-  * Arguments :
 
-  *	- taskp : a pointer to a valid task
 
-  *	- type : STARPU_{CPU,CUDA,OPENCL}_WORKER.
 
-  *      - id   : -1 if you dont care about the device where the task will be
 
-  *		 executed, as long as it has the right type.
 
-  *		 >= 0 if you want to make sure the task will be executed on the
 
-  *		 idth device that has the specified type.
 
-  * Return values :
 
-  * 	-ENODEV
 
-  *	0 : success.
 
-  */
 
- static int
 
- create_task(struct starpu_task **taskp, enum starpu_worker_archtype type, int id)
 
- {
 
- 	static int cpu_workers[STARPU_MAXCPUS];
 
- #ifdef STARPU_USE_CUDA
 
- 	static int cuda_workers[STARPU_MAXCUDADEVS];
 
- #endif
 
- #ifdef STARPU_USE_OPENCL
 
- 	static int opencl_workers[STARPU_MAXOPENCLDEVS];
 
- #endif
 
- #ifdef STARPU_USE_MIC
 
- 	static int mic_workers[STARPU_MAXMICDEVS];
 
- #endif
 
- 	static int n_cpus = -1;
 
- #ifdef STARPU_USE_CUDA
 
- 	static int n_cudas = -1;
 
- #endif
 
- #ifdef STARPU_USE_OPENCL
 
- 	static int n_opencls = -1;
 
- #endif
 
- #ifdef STARPU_USE_MIC
 
- 	static int n_mics = -1;
 
- #endif
 
- 	if (n_cpus == -1) /* First time here */
 
- 	{
 
- 		/* We do not check the return values of the calls to
 
- 		 * starpu_worker_get_ids_by_type now, because it is simpler to
 
- 		 * detect a problem in the switch that comes right after this 
 
- 		 * block of code. */
 
- 		n_cpus = starpu_worker_get_ids_by_type(STARPU_CPU_WORKER,
 
- 							cpu_workers,
 
- 							STARPU_MAXCPUS);
 
- #ifdef STARPU_USE_CUDA
 
- 		n_cudas = starpu_worker_get_ids_by_type(STARPU_CUDA_WORKER,
 
- 							cuda_workers,
 
- 							STARPU_MAXCUDADEVS);
 
- #endif
 
- #ifdef STARPU_USE_OPENCL
 
- 		n_opencls = starpu_worker_get_ids_by_type(STARPU_OPENCL_WORKER,
 
- 							opencl_workers,
 
- 							STARPU_MAXOPENCLDEVS);
 
- #endif
 
- #ifdef STARPU_USE_MIC
 
- 		n_mics = starpu_worker_get_ids_by_type(STARPU_MIC_WORKER,
 
- 							mic_workers,
 
- 							STARPU_MAXMICDEVS);
 
- #endif
 
- 	}
 
- 	int workerid=0;
 
- 	static struct starpu_codelet cl;
 
- 	cl.nbuffers = 1;
 
- 	cl.modes[0] = STARPU_RW;
 
- 	switch (type)
 
- 	{
 
- 		case STARPU_CPU_WORKER:
 
- 			if (id != -1)
 
- 			{
 
- 				if (id >= n_cpus)
 
- 				{
 
- 					FPRINTF(stderr, "Not enough CPU workers\n");
 
- 					return -ENODEV;
 
- 				}
 
- 				workerid = *(cpu_workers + id);
 
- 			}
 
- 			cl.where = STARPU_CPU;
 
- 			cl.cpu_funcs[0] = current_config->cpu_func;
 
- 			break;
 
- #ifdef STARPU_USE_CUDA
 
- 		case STARPU_CUDA_WORKER:
 
- 			if (id != -1)
 
- 			{
 
- 				if (id >= n_cudas)
 
- 				{
 
- 					FPRINTF(stderr, "Not enough CUDA workers\n");
 
- 					return -ENODEV;
 
- 				}
 
- 				workerid = cuda_workers[id];
 
- 			}
 
- 			cl.where = STARPU_CUDA;
 
- 			cl.cuda_funcs[0] = current_config->cuda_func;
 
- 			break;
 
- #endif /* !STARPU_USE_CUDA */
 
- #ifdef STARPU_USE_OPENCL
 
- 		case STARPU_OPENCL_WORKER:
 
- 			if (id != -1)
 
- 			{
 
- 				if (id >= n_opencls)
 
- 				{
 
- 					FPRINTF(stderr, "Not enough OpenCL workers\n");
 
- 					return -ENODEV;
 
- 				}
 
- 				workerid = *(opencl_workers + id);
 
- 			}
 
- 			cl.where = STARPU_OPENCL;
 
- 			cl.opencl_funcs[0] = current_config->opencl_func;
 
- 			break;
 
- #endif /* ! STARPU_USE_OPENCL */
 
- #ifdef STARPU_USE_MIC
 
- 		case STARPU_MIC_WORKER:
 
- 		if (id != -1)
 
- 		{
 
- 			if (id >= n_mics)
 
- 			{
 
- 				FPRINTF(stderr, "Not enough MIC workers\n");
 
- 				return -ENODEV;
 
- 			}
 
- 			workerid = mic_workers[id];
 
- 		}
 
- 		cl.where = STARPU_MIC;
 
- 		cl.cpu_funcs_name[0] = current_config->cpu_func_name;
 
- 		break;
 
- #endif
 
- 		default:
 
- 			return -ENODEV;
 
- 	}
 
- 	struct starpu_task *task = starpu_task_create();
 
- 	task->synchronous = 1;
 
- 	task->cl = &cl;
 
- 	task->handles[0] = *current_config->handle;
 
- 	task->destroy = 0;
 
- 	if (id != -1)
 
- 	{
 
- 		task->execute_on_a_specific_worker = 1;
 
- 		task->workerid = workerid;
 
- 	}
 
- 	factor = -factor;
 
- 	task->cl_arg = &factor;
 
- 	task->cl_arg_size = sizeof(factor);
 
- 	*taskp = task;
 
- 	return 0;
 
- }
 
- /*
 
-  * <device1>_to_<device2> functions.
 
-  * They all create and submit a task that has to be executed on <device2>,
 
-  * forcing a copy between <device1> and <device2>.
 
-  * XXX : could we sometimes use starpu_task_insert() ? It seems hars because we
 
-  * need to set the execute_on_a_specific_worker field...
 
-  */
 
- #ifdef STARPU_USE_CUDA
 
- static enum exit_code
 
- ram_to_cuda(void)
 
- {
 
- 	int err;
 
- 	struct starpu_task *task;
 
- 	err = create_task(&task, STARPU_CUDA_WORKER, 0);
 
- 	if (err != 0)
 
- 		return TASK_CREATION_FAILURE;
 
- 	err = starpu_task_submit(task);
 
- 	if (err != 0)
 
- 		return TASK_SUBMISSION_FAILURE;
 
- 	FPRINTF(stderr, "[%s] : %d\n", __starpu_func__, current_config->copy_failed);
 
- 	return current_config->copy_failed;
 
- }
 
- #ifdef STARPU_HAVE_CUDA_MEMCPY_PEER
 
- static enum exit_code
 
- cuda_to_cuda(void)
 
- {
 
- 	int err;
 
- 	struct starpu_task *task;
 
- 	err = create_task(&task, STARPU_CUDA_WORKER, 1);
 
- 	if (err != 0)
 
- 		return TASK_CREATION_FAILURE;
 
- 	err = starpu_task_submit(task);
 
- 	if (err != 0)
 
- 		return TASK_SUBMISSION_FAILURE;
 
- 	FPRINTF(stderr, "[%s] : %d\n", __starpu_func__, current_config->copy_failed);
 
- 	return current_config->copy_failed;
 
- }
 
- #endif
 
- static enum exit_code
 
- cuda_to_ram(void)
 
- {
 
- 	int err;
 
- 	struct starpu_task *task;
 
- 	err = create_task(&task, STARPU_CPU_WORKER, -1);
 
- 	if (err != 0)
 
- 		return TASK_CREATION_FAILURE;
 
- 	err = starpu_task_submit(task);
 
- 	if (err != 0)
 
- 		return TASK_SUBMISSION_FAILURE;
 
- 	FPRINTF(stderr, "[%s] : %d\n", __starpu_func__, current_config->copy_failed);
 
- 	return current_config->copy_failed;
 
- }
 
- #endif /* !STARPU_USE_CUDA */
 
- #ifdef STARPU_USE_OPENCL
 
- static enum exit_code
 
- ram_to_opencl(void)
 
- {
 
- 	int err;
 
- 	struct starpu_task *task;
 
- 	err = create_task(&task, STARPU_OPENCL_WORKER, 0);
 
- 	if (err != 0)
 
- 		return TASK_CREATION_FAILURE;
 
- 	err = starpu_task_submit(task);
 
- 	if (err != 0)
 
- 		return TASK_SUBMISSION_FAILURE;
 
- 	FPRINTF(stderr, "[%s] : %d\n", __starpu_func__, current_config->copy_failed);
 
- 	return current_config->copy_failed;
 
- }
 
- static enum exit_code
 
- opencl_to_ram(void)
 
- {
 
- 	int err;
 
- 	struct starpu_task *task;
 
- 	err = create_task(&task, STARPU_CPU_WORKER, -1);
 
- 	if (err != 0)
 
- 		return TASK_CREATION_FAILURE;
 
- 	err = starpu_task_submit(task);
 
- 	if (err != 0)
 
- 		return TASK_SUBMISSION_FAILURE;
 
- 	FPRINTF(stderr, "[%s] : %d\n", __starpu_func__, current_config->copy_failed);
 
- 	return current_config->copy_failed;
 
- }
 
- #endif /* !STARPU_USE_OPENCL */
 
- #ifdef STARPU_USE_MIC
 
- static enum exit_code
 
- ram_to_mic()
 
- {
 
- 	int err;
 
- 	struct starpu_task *task;
 
- 	err = create_task(&task, STARPU_MIC_WORKER, 0);
 
- 	if (err != 0)
 
- 		return TASK_CREATION_FAILURE;
 
- 	err = starpu_task_submit(task);
 
- 	if (err != 0)
 
- 		return TASK_SUBMISSION_FAILURE;
 
- 	FPRINTF(stderr, "[%s] : %d\n", __func__, current_config->copy_failed);
 
- 	return current_config->copy_failed;
 
- }
 
- static enum exit_code
 
- mic_to_ram()
 
- {
 
- 	int err;
 
- 	struct starpu_task *task;
 
- 	err = create_task(&task, STARPU_CPU_WORKER, -1);
 
- 	if (err != 0)
 
- 		return TASK_CREATION_FAILURE;
 
- 	
 
- 	err = starpu_task_submit(task);
 
- 	if (err != 0)
 
- 		return TASK_SUBMISSION_FAILURE;
 
- 	FPRINTF(stderr, "[%s] : %d\n", __func__, current_config->copy_failed);
 
- 	return current_config->copy_failed;
 
- }
 
- #endif
 
- /* End of the <device1>_to_<device2> functions. */
 
- #ifdef STARPU_USE_CUDA
 
- static void
 
- run_cuda(int async)
 
- {
 
- 	/* RAM -> CUDA (-> CUDA) -> RAM */
 
- 	int err;
 
- 	err = ram_to_cuda();
 
- 	set_field(&summary, async, CPU_TO_CUDA, err);
 
- 	/* If this failed, there is no point in continuing. */
 
- 	if (err != SUCCESS)
 
- 		return;
 
- #ifdef STARPU_HAVE_CUDA_MEMCPY_PEER
 
- 	if (starpu_cuda_worker_get_count() >= 2)
 
- 	{
 
- 		err = cuda_to_cuda();
 
- 		set_field(&summary, async, CUDA_TO_CUDA, err);
 
- 		/* Even if cuda_to_cuda() failed, a valid copy is left on the first
 
- 		 * cuda device, which means we can safely test cuda_to_ram() */
 
- 	}
 
- 	else
 
- 	{
 
- 		summary.cuda_to_cuda_async = UNTESTED;
 
- 	}
 
- #else
 
- 	summary.cuda_to_cuda_async = UNTESTED;
 
- #endif /* !STARPU_HAVE_CUDA_MEMCPY_PEER */
 
- #ifdef STARPU_USE_CPU
 
- 	err = cuda_to_ram();
 
- 	set_field(&summary, async, CUDA_TO_CPU, err);
 
- #endif /* !STARPU_USE_CPU */
 
- }
 
- #endif /* !STARPU_USE_CUDA */
 
- #ifdef STARPU_USE_OPENCL
 
- static void
 
- run_opencl(int async)
 
- {
 
- 	/* RAM -> OpenCL -> RAM */
 
- 	int err;
 
- 	err = ram_to_opencl();
 
- 	set_field(&summary, async, CPU_TO_OPENCL, err);
 
- 	if (err != SUCCESS)
 
- 		return;
 
- #ifdef STARPU_USE_CPU
 
- 	err = opencl_to_ram();
 
- 	set_field(&summary, async, OPENCL_TO_CPU, err);
 
- #endif /*!STARPU_USE_CPU */
 
- }
 
- #endif /* !STARPU_USE_OPENCL */
 
- #ifdef STARPU_USE_MIC
 
- static void
 
- run_mic(int async)
 
- {
 
- 	int err;
 
- 	err = ram_to_mic();
 
- 	set_field(&summary, async, CPU_TO_MIC, err);
 
- 	if (err != SUCCESS)
 
- 		return;
 
- #ifdef STARPU_USE_CPU
 
- 	err = mic_to_ram();
 
- 	set_field(&summary, async, MIC_TO_CPU, err);
 
- #endif
 
- }
 
- #endif /* STARPU_USE_PIC */
 
- #ifdef STARPU_USE_CPU
 
- /* Valid data should be in RAM before calling this function */
 
- static void
 
- ram_to_ram(void)
 
- {
 
- 	int err;
 
- 	struct starpu_task *task;
 
- 	starpu_data_handle_t src, dst;
 
- 	void *src_interface, *dst_interface;
 
- 	src = *current_config->handle;
 
- 	dst = *current_config->dummy_handle;
 
- 	/* We do not care about the nodes */
 
- 	src_interface = starpu_data_get_interface_on_node(src, STARPU_MAIN_RAM);
 
- 	dst_interface = starpu_data_get_interface_on_node(dst, STARPU_MAIN_RAM);
 
- 	if (src->ops->copy_methods->ram_to_ram)
 
- 		src->ops->copy_methods->ram_to_ram(src_interface, STARPU_MAIN_RAM, dst_interface, STARPU_MAIN_RAM);
 
- 	else
 
- 		src->ops->copy_methods->any_to_any(src_interface, STARPU_MAIN_RAM, dst_interface, STARPU_MAIN_RAM, NULL);
 
- 	err = create_task(&task, STARPU_CPU_WORKER, -1);
 
- 	if (err != 0)
 
- 		goto out;
 
- 	task->handles[0] = dst;
 
- 	err = starpu_task_submit(task);
 
- 	starpu_task_destroy(task);
 
- 	if (err != 0)
 
- 	{
 
- 		err = TASK_SUBMISSION_FAILURE;
 
- 		goto out;
 
- 	}
 
- 	FPRINTF(stderr, "[%s] : %d\n", __starpu_func__, current_config->copy_failed);
 
- 	err = current_config->copy_failed;
 
- out:
 
- 	set_field(&summary, 0, CPU_TO_CPU, err);
 
- }
 
- #endif /* !STARPU_USE_CPU */
 
- static void
 
- run_async(void)
 
- {
 
- 	int async = starpu_asynchronous_copy_disabled();
 
- 	if (async == 1)
 
- 	{
 
- 		FPRINTF(stderr, "Asynchronous copies have been disabled\n");
 
- 		return;
 
- 	}
 
- #ifdef STARPU_USE_CUDA
 
- 	run_cuda(1);
 
- #endif /* !STARPU_USE_CUDA */
 
- #ifdef STARPU_USE_OPENCL
 
- 	run_opencl(1);
 
- #endif /* !STARPU_USE_OPENCL */
 
- #ifdef STARPU_USE_MIC
 
- 	run_mic(1);
 
- #endif
 
- }
 
- static void
 
- run_sync(void)
 
- {
 
- 	starpu_data_handle_t handle = *current_config->handle;
 
- 	struct starpu_data_copy_methods new_copy_methods;
 
- 	struct starpu_data_copy_methods *old_copy_methods;
 
- 	old_copy_methods = (struct starpu_data_copy_methods *) handle->ops->copy_methods;
 
- 	memcpy(&new_copy_methods,
 
- 		old_copy_methods,
 
- 		sizeof(struct starpu_data_copy_methods));
 
- #ifdef STARPU_USE_CUDA
 
- 	new_copy_methods.ram_to_cuda_async = NULL;
 
- 	new_copy_methods.cuda_to_cuda_async = NULL;
 
- 	new_copy_methods.cuda_to_ram_async = NULL;
 
- #endif /* !STARPU_USE_CUDA */
 
- #ifdef STARPU_USE_OPENCL
 
- 	new_copy_methods.ram_to_opencl_async = NULL;
 
- 	new_copy_methods.opencl_to_ram_async = NULL;
 
- #endif /* !STARPU_USE_OPENCL */
 
- #ifdef STARPU_USE_MIC
 
- 	new_copy_methods.ram_to_mic_async = NULL;
 
- 	new_copy_methods.mic_to_ram_async = NULL;
 
- #endif
 
- 	handle->ops->copy_methods = &new_copy_methods;
 
- #ifdef STARPU_USE_CUDA
 
- 	run_cuda(0);
 
- #endif /* !STARPU_USE_CUDA */
 
- #ifdef STARPU_USE_OPENCL
 
- 	run_opencl(0);
 
- #endif /* !STARPU_USE_OPENCL */
 
- #ifdef STARPU_USE_MIC
 
- 	run_mic(0);
 
- #endif
 
- 	handle->ops->copy_methods = old_copy_methods;
 
- }
 
- static void
 
- compare(void)
 
- {
 
- 	int err;
 
- 	void *interface_a, *interface_b;
 
- 	starpu_data_handle_t handle, dummy_handle;
 
- 	handle = *current_config->handle;
 
- 	dummy_handle = *current_config->dummy_handle;
 
- 	interface_a = starpu_data_get_interface_on_node(handle, STARPU_MAIN_RAM);
 
- 	interface_b = starpu_data_get_interface_on_node(dummy_handle, STARPU_MAIN_RAM);
 
- 	err = handle->ops->compare(interface_a, interface_b);
 
- 	if (err == 0)
 
- 	{
 
- 		summary.compare = FAILURE;
 
- 		summary.success = FAILURE;
 
- 	}
 
- 	else
 
- 	{
 
- 		summary.compare = SUCCESS;
 
- 	}
 
- }
 
- #ifdef STARPU_USE_CPU
 
- static void
 
- to_pointer(void)
 
- {
 
- 	void *ptr;
 
- 	unsigned int node;
 
- 	unsigned int tests = 0;
 
- 	starpu_data_handle_t handle;
 
- 	void * data_interface;
 
- 	handle = *current_config->handle;
 
- 	if (!handle->ops->to_pointer)
 
- 		return;
 
- 	for (node = 0; node < STARPU_MAXNODES; node++)
 
- 	{
 
- 		if (starpu_node_get_kind(node) != STARPU_CPU_RAM)
 
- 			continue;
 
- 		if (!starpu_data_test_if_allocated_on_node(handle, node))
 
- 			continue;
 
- 		data_interface = starpu_data_get_interface_on_node(handle, node);
 
- 		ptr = handle->ops->to_pointer(data_interface, node);
 
- 		if (starpu_data_lookup(ptr) != handle)
 
- 		{
 
- 			summary.to_pointer = FAILURE;
 
- 			return;
 
- 		}
 
- 		tests++;
 
- 	}
 
- 	if (tests > 0)
 
- 		summary.to_pointer = SUCCESS;
 
- }
 
- static void
 
- pointer_is_inside(void)
 
- {
 
- 	void *ptr;
 
- 	unsigned int node;
 
- 	unsigned int tests = 0;
 
- 	starpu_data_handle_t handle;
 
- 	void * data_interface;
 
- 	handle = *current_config->handle;
 
- 	if (!handle->ops->pointer_is_inside || !handle->ops->to_pointer)
 
- 		return;
 
- 	for (node = 0; node < STARPU_MAXNODES; node++)
 
- 	{
 
- 		if (starpu_node_get_kind(node) != STARPU_CPU_RAM)
 
- 			continue;
 
- 		if (!starpu_data_test_if_allocated_on_node(handle, node))
 
- 			continue;
 
- 		data_interface = starpu_data_get_interface_on_node(handle, node);
 
- 		ptr = handle->ops->to_pointer(data_interface, node);
 
- 		if (starpu_data_lookup(ptr) != handle)
 
- 		{
 
- 			summary.pointer_is_inside = FAILURE;
 
- 			return;
 
- 		}
 
- 		if (!starpu_data_pointer_is_inside(handle, node, ptr))
 
- 		{
 
- 			summary.pointer_is_inside = FAILURE;
 
- 			return;
 
- 		}
 
- 		tests++;
 
- 	}
 
- 	if (tests > 0)
 
- 		summary.pointer_is_inside = SUCCESS;
 
- }
 
- #endif /* !STARPU_USE_CPU */
 
- static int
 
- load_conf(struct test_config *config)
 
- {
 
- 	if (!config ||
 
- #ifdef STARPU_USE_CPU
 
- 	    !config->cpu_func ||
 
- 	    !config->dummy_handle ||
 
- #endif
 
- #ifdef STARPU_USE_CUDA
 
- 	    !config->cuda_func ||
 
- #endif
 
- #ifdef STARPU_USE_OPENCL
 
- 	    !config->opencl_func ||
 
- #endif
 
- #ifdef STARPU_USE_MIC
 
- 		!config->cpu_func_name ||
 
- #endif
 
- 	    !config->handle)
 
- 	{
 
- 		return 1;
 
- 	}
 
- 	current_config = config;
 
- 	return 0;
 
- }
 
- data_interface_test_summary*
 
- run_tests(struct test_config *conf)
 
- {
 
- 	if (load_conf(conf) == 1)
 
- 	{
 
- 		FPRINTF(stderr, "Failed to load conf.\n");
 
- 		return NULL;
 
- 	}
 
- 	run_async();
 
- 	run_sync();
 
- #ifdef STARPU_USE_CPU
 
- 	ram_to_ram();
 
- 	compare();
 
- 	to_pointer();
 
- 	pointer_is_inside();
 
- #endif
 
- 	return &summary;
 
- }
 
 
  |