1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
/* StarPU --- Runtime system for heterogeneous multicore architectures.
*
* Copyright (C) 2012, 2013 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 <starpu.h>
#include "complex_interface.h"
#include "complex_codelet.h"
static int can_execute(unsigned workerid, struct starpu_task *task, unsigned nimpl)
{
if (starpu_worker_get_type(workerid) == STARPU_OPENCL_WORKER)
return 1;
#ifdef STARPU_USE_CUDA
#ifdef STARPU_SIMGRID
/* We don't know, let's assume it can */
return 1;
#else
/* Cuda device */
const struct cudaDeviceProp *props;
props = starpu_cuda_get_device_properties(workerid);
if (props->major >= 2 || props->minor >= 3)
{
/* At least compute capability 1.3, supports doubles */
return 1;
}
else
{
/* Old card does not support doubles */
return 0;
}
#endif
#else
return 1;
#endif
}
#ifdef STARPU_USE_CUDA
extern void copy_complex_codelet_cuda(void *descr[], STARPU_ATTRIBUTE_UNUSED void *_args);
#endif
#ifdef STARPU_USE_OPENCL
extern void copy_complex_codelet_opencl(void *buffers[], void *args);
#endif
struct starpu_codelet cl_copy =
{
#ifdef STARPU_USE_CUDA
.cuda_funcs = {copy_complex_codelet_cuda},
.cuda_flags = {STARPU_CUDA_ASYNC},
#endif
#ifdef STARPU_USE_OPENCL
.opencl_funcs = {copy_complex_codelet_opencl},
.opencl_flags = {STARPU_OPENCL_ASYNC},
#endif
.nbuffers = 2,
.modes = {STARPU_R, STARPU_W},
.can_execute = can_execute,
.name = "cl_copy"
};
#ifdef STARPU_USE_OPENCL
struct starpu_opencl_program opencl_program;
#endif
int 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;
int compare;
int *compare_ptr = &compare;
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, STARPU_MAIN_RAM, &real, &imaginary, 1);
starpu_complex_data_register(&handle2, STARPU_MAIN_RAM, ©_real, ©_imaginary, 1);
ret = starpu_task_insert(&cl_display, STARPU_VALUE, "handle1", strlen("handle1")+1, STARPU_R, handle1, 0);
if (ret == -ENODEV) goto end;
STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
ret = starpu_task_insert(&cl_display, STARPU_VALUE, "handle2", strlen("handle2")+1, STARPU_R, handle2, 0);
if (ret == -ENODEV) goto end;
STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
ret = starpu_task_insert(&cl_compare,
STARPU_R, handle1,
STARPU_R, handle2,
STARPU_VALUE, &compare_ptr, sizeof(compare_ptr),
0);
if (ret == -ENODEV) goto end;
STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
starpu_task_wait_for_all();
if (compare != 0)
{
FPRINTF(stderr, "Complex numbers should NOT be similar\n");
goto end;
}
ret = starpu_task_insert(&cl_copy,
STARPU_R, handle1,
STARPU_W, handle2,
0);
if (ret == -ENODEV) goto end;
STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
ret = starpu_task_insert(&cl_display, STARPU_VALUE, "handle1", strlen("handle1")+1, STARPU_R, handle1, 0);
if (ret == -ENODEV) goto end;
STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
ret = starpu_task_insert(&cl_display, STARPU_VALUE, "handle2", strlen("handle2")+1, STARPU_R, handle2, 0);
if (ret == -ENODEV) goto end;
STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
ret = starpu_task_insert(&cl_compare,
STARPU_R, handle1,
STARPU_R, handle2,
STARPU_VALUE, &compare_ptr, sizeof(compare_ptr),
0);
if (ret == -ENODEV) goto end;
STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
starpu_task_wait_for_all();
if (compare != 1)
{
FPRINTF(stderr, "Complex numbers should be similar\n");
}
end:
#ifdef STARPU_USE_OPENCL
{
int ret2 = starpu_opencl_unload_opencl(&opencl_program);
STARPU_CHECK_RETURN_VALUE(ret2, "starpu_opencl_unload_opencl");
}
#endif
starpu_data_unregister(handle1);
starpu_data_unregister(handle2);
starpu_shutdown();
if (ret == -ENODEV) return 77; else return !compare;
}
|