| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 | /* StarPU --- Runtime system for heterogeneous multicore architectures. * * Copyright (C) 2012  Centre National de la Recherche Scientifique * * 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 "complex_interface.h"#ifdef STARPU_USE_OPENCL#include <starpu_opencl.h>#endif#ifdef STARPU_USE_CUDAextern void copy_complex_codelet_cuda(void *descr[], __attribute__ ((unused)) void *_args);#endif#ifdef STARPU_USE_OPENCLextern void copy_complex_codelet_opencl(void *buffers[], void *args);#endifvoid compare_complex_codelet(void *descr[], __attribute__ ((unused)) void *_args){	int nx1 = STARPU_COMPLEX_GET_NX(descr[0]);	double *real1 = STARPU_COMPLEX_GET_REAL(descr[0]);	double *imaginary1 = STARPU_COMPLEX_GET_IMAGINARY(descr[0]);	int nx2 = STARPU_COMPLEX_GET_NX(descr[1]);	double *real2 = STARPU_COMPLEX_GET_REAL(descr[1]);	double *imaginary2 = STARPU_COMPLEX_GET_IMAGINARY(descr[1]);	int compare = (nx1 == nx2);	if (nx1 == nx2)	{		int i;		for(i=0 ; i<nx1 ; i++)		{			if (real1[i] != real2[i] || imaginary1[i] != imaginary2[i])			{				compare = 0;				break;			}		}	}	fprintf(stderr, "Complex numbers are%s similar\n", compare==0 ? " NOT" : "");}void display_complex_codelet(void *descr[], __attribute__ ((unused)) void *_args){	int nx = STARPU_COMPLEX_GET_NX(descr[0]);	double *real = STARPU_COMPLEX_GET_REAL(descr[0]);	double *imaginary = STARPU_COMPLEX_GET_IMAGINARY(descr[0]);	int i;	for(i=0 ; i<nx ; i++)	{		fprintf(stderr, "Complex[%d] = %3.2f + %3.2f i\n", i, real[i], imaginary[i]);	}}struct starpu_codelet cl_display ={	.cpu_funcs = {display_complex_codelet, NULL},	.nbuffers = 1,	.modes = {STARPU_R}};struct starpu_codelet cl_copy ={#ifdef STARPU_USE_CUDA	.cuda_funcs = {copy_complex_codelet_cuda, NULL},#endif#ifdef STARPU_USE_OPENCL	.opencl_funcs = {copy_complex_codelet_opencl, NULL},#endif	.nbuffers = 2,	.modes = {STARPU_R, STARPU_W}};struct starpu_codelet cl_compare ={	.cpu_funcs = {compare_complex_codelet, NULL},	.nbuffers = 2,	.modes = {STARPU_R, STARPU_R}};#ifdef STARPU_USE_OPENCLstruct starpu_opencl_program opencl_program;#endifint main(int argc, char **argv){	int ret = 0;	starpu_data_handle_t handle1;	starpu_data_handle_t handle2;	double real = 45.0;	double imaginary = 12.0;	double copy_real = 78.0;	double copy_imaginary = 78.0;	ret = starpu_init(NULL);	if (ret == -ENODEV) return 77;	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");#ifdef STARPU_USE_OPENCL	ret = starpu_opencl_load_opencl_from_file("examples/interface/complex_kernels.cl",						  &opencl_program, NULL);	STARPU_CHECK_RETURN_VALUE(ret, "starpu_opencl_load_opencl_from_file");#endif	starpu_complex_data_register(&handle1, 0, &real, &imaginary, 1);	starpu_complex_data_register(&handle2, 0, ©_real, ©_imaginary, 1);	ret = starpu_insert_task(&cl_display, STARPU_R, handle1, 0);	if (ret == -ENODEV) goto enodev;	STARPU_CHECK_RETURN_VALUE(ret, "starpu_insert_task");	ret = starpu_insert_task(&cl_display, STARPU_R, handle2, 0);	if (ret == -ENODEV) goto enodev;	STARPU_CHECK_RETURN_VALUE(ret, "starpu_insert_task");	ret = starpu_insert_task(&cl_compare,				 STARPU_R, handle1,				 STARPU_R, handle2,				 0);	if (ret == -ENODEV) goto enodev;	STARPU_CHECK_RETURN_VALUE(ret, "starpu_insert_task");	ret = starpu_insert_task(&cl_copy,				 STARPU_R, handle1,				 STARPU_W, handle2,				 0);	if (ret == -ENODEV) goto enodev;	STARPU_CHECK_RETURN_VALUE(ret, "starpu_insert_task");	ret = starpu_insert_task(&cl_display, STARPU_R, handle1, 0);	if (ret == -ENODEV) goto enodev;	STARPU_CHECK_RETURN_VALUE(ret, "starpu_insert_task");	ret = starpu_insert_task(&cl_display, STARPU_R, handle2, 0);	if (ret == -ENODEV) goto enodev;	STARPU_CHECK_RETURN_VALUE(ret, "starpu_insert_task");	ret = starpu_insert_task(&cl_compare,				 STARPU_R, handle1,				 STARPU_R, handle2,				 0);	if (ret == -ENODEV) goto enodev;	STARPU_CHECK_RETURN_VALUE(ret, "starpu_insert_task");	starpu_task_wait_for_all();#ifdef STARPU_USE_OPENCL        ret = starpu_opencl_unload_opencl(&opencl_program);        STARPU_CHECK_RETURN_VALUE(ret, "starpu_opencl_unload_opencl");#endif	starpu_shutdown();	return 0;enodev:#ifdef STARPU_USE_OPENCL        ret = starpu_opencl_unload_opencl(&opencl_program);        STARPU_CHECK_RETURN_VALUE(ret, "starpu_opencl_unload_opencl");#endif	starpu_data_unregister(handle1);	starpu_data_unregister(handle2);	starpu_shutdown();	return 77;}
 |