/* StarPU --- Runtime system for heterogeneous multicore architectures. * * Copyright (C) 2010,2011 University of 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 #include #include #include #include #define error(...) do { fprintf(stderr, "Error: " __VA_ARGS__); exit(EXIT_FAILURE); } while(0) #define check(err, str) do { if(err != CL_SUCCESS) { fprintf(stderr, "OpenCL Error (%d): %s\n",err, str); exit(EXIT_FAILURE); }} while(0) #ifdef UNUSED #elif defined(__GNUC__) # define UNUSED(x) UNUSED_ ## x __attribute__((unused)) #else # define UNUSED(x) x #endif #define SIZE 1024 #define TYPE float #define REALSIZE (SIZE * sizeof(TYPE)) const char * kernel_src = "__kernel void add(__global float*s1, __global float*s2, __global float*d) { \ size_t x = get_global_id(0);\ size_t y = get_global_id(1);\ size_t w = get_global_size(0); \ int idx = y*w+x; \ d[idx] = s1[idx] + s2[idx];\ }"; int main(int UNUSED(argc), char** UNUSED(argv)) { cl_platform_id platforms[15]; cl_uint num_platforms; cl_device_id devices[15]; cl_uint num_devices; cl_context context; cl_program program; cl_kernel kernel; cl_mem s1m, s2m, dm; cl_command_queue cq; cl_int err; TYPE s1[SIZE],s2[SIZE],d[SIZE]; { int i; for (i=0; i