123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- @c -*-texinfo-*-
- @c This file is part of the StarPU Handbook.
- @c Copyright (C) 2009-2011 Université de Bordeaux 1
- @c Copyright (C) 2010, 2011, 2012 Centre National de la Recherche Scientifique
- @c See the file starpu.texi for copying conditions.
- @smallexample
- extern void scal_cpu_func(void *buffers[], void *_args)
- extern void scal_sse_func(void *buffers[], void *_args)
- extern void scal_cuda_func(void *buffers[], void *_args)
- extern void scal_opencl_func(void *buffers[], void *_args)
- static struct starpu_codelet cl = @{
- .where = STARPU_CPU | STARPU_CUDA | STARPU_OPENCL,
-
- .cpu_funcs = @{ scal_cpu_func, scal_sse_func, NULL @},
-
- .cuda_funcs = @{ scal_cuda_func, NULL @},
-
- .opencl_funcs = @{ scal_opencl_func, NULL @},
- .nbuffers = 1,
- .modes = @{ STARPU_RW @}
- @}
- struct starpu_opencl_program programs
- int main(int argc, char **argv)
- @{
-
- float vector[NX]
- unsigned i
- for (i = 0
- vector[i] = 1.0f
- fprintf(stderr, "BEFORE: First element was %f\n", vector[0])
-
- starpu_init(NULL)
- starpu_opencl_load_opencl_from_file(
- "examples/basic_examples/vector_scal_opencl_kernel.cl", &programs, NULL)
-
- starpu_data_handle_t vector_handle
- starpu_vector_data_register(&vector_handle, 0, (uintptr_t)vector,
- NX, sizeof(vector[0]))
- float factor = 3.14
-
- struct starpu_task *task = starpu_task_create()
- task->synchronous = 1
- task->cl = &cl
-
- task->handles[0] = vector_handle
-
- task->cl_arg = &factor
- task->cl_arg_size = sizeof(factor)
-
- starpu_task_submit(task)
-
- starpu_data_unregister(vector_handle)
- starpu_opencl_unload_opencl(&programs)
-
- starpu_shutdown()
- fprintf(stderr, "AFTER First element is %f\n", vector[0])
- return 0
- @}
- @end smallexample
|