/* 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 #ifdef __APPLE_CC__ #include #else #include #endif #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);\n\ size_t y = get_global_id(1);\n\ size_t w = get_global_size(0); \n\ int idx = y*w+x; \n\ #ifdef SOCL_DEVICE_TYPE_GPU \n\ d[idx] = s1[idx] + s2[idx];\n\ #endif \n\ #ifdef SOCL_DEVICE_TYPE_CPU \n\ d[idx] = s1[idx] + 2* s2[idx];\n\ #endif \n\ #ifdef SOCL_DEVICE_TYPE_ACCELERATOR \n\ d[idx] = s1[idx] + 3 * s2[idx];\n\ #endif \n\ #ifdef SOCL_DEVICE_TYPE_UNKNOWN \n\ d[idx] = s1[idx] + 4 * s2[idx];\n\ #endif \n\ }"; 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; unsigned int i; TYPE s1[SIZE],s2[SIZE],d[SIZE]; { for (i=0; i