LCOV - code coverage report
Current view: top level - tests/datawizard/interfaces/multiformat - multiformat_opencl.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 38 47 80.9 %
Date: 2013-06-19 Functions: 1 1 100.0 %
Branches: 13 30 43.3 %

           Branch data     Line data    Source code
       1                 :            : /* StarPU --- Runtime system for heterogeneous multicore architectures.
       2                 :            :  *
       3                 :            :  * Copyright (C) 2011  Institut National de Recherche en Informatique et Automatique
       4                 :            :  *
       5                 :            :  * StarPU is free software; you can redistribute it and/or modify
       6                 :            :  * it under the terms of the GNU Lesser General Public License as published by
       7                 :            :  * the Free Software Foundation; either version 2.1 of the License, or (at
       8                 :            :  * your option) any later version.
       9                 :            :  *
      10                 :            :  * StarPU is distributed in the hope that it will be useful, but
      11                 :            :  * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
      12                 :            :  *
      13                 :            :  * See the GNU Lesser General Public License in COPYING.LGPL for more details.
      14                 :            :  */
      15                 :            : 
      16                 :            : #include <config.h>
      17                 :            : #include <starpu.h>
      18                 :            : #include "../test_interfaces.h"
      19                 :            : 
      20                 :            : #define KERNEL_LOCATION "tests/datawizard/interfaces/multiformat/multiformat_opencl_kernel.cl"
      21                 :            : 
      22                 :            : extern struct test_config multiformat_config;
      23                 :            : static struct starpu_opencl_program multiformat_program;
      24                 :            : 
      25                 :          2 : void test_multiformat_opencl_func(void *buffers[], void *args)
      26                 :            : {
      27 [ -  + ][ #  # ]:          4 :         STARPU_SKIP_IF_VALGRIND;
                 [ #  # ]
      28                 :            : 
      29                 :            :         int id, devid, factor, ret;
      30                 :            :         unsigned int n;
      31                 :            : 
      32                 :            :         cl_int             err;
      33                 :            :         cl_kernel          kernel;
      34                 :            :         cl_command_queue   queue;
      35                 :            :         cl_event           event;
      36                 :            :         cl_context         context;
      37                 :            :         cl_mem             val, fail;
      38                 :            : 
      39                 :          2 :         ret = starpu_opencl_load_opencl_from_file(KERNEL_LOCATION,
      40                 :            :                                                   &multiformat_program,
      41                 :            :                                                   NULL);
      42         [ -  + ]:          2 :         STARPU_CHECK_RETURN_VALUE(ret, "starpu_opencl_load_opencl_from_file");
      43                 :            : 
      44                 :          2 :         factor = *(int *)args;
      45                 :          2 :         n = STARPU_MULTIFORMAT_GET_NX(buffers[0]);
      46                 :          2 :         val = (cl_mem)STARPU_MULTIFORMAT_GET_OPENCL_PTR(buffers[0]);
      47                 :            : 
      48                 :          2 :         id = starpu_worker_get_id();
      49                 :          2 :         devid = starpu_worker_get_devid(id);
      50                 :          2 :         starpu_opencl_get_context(devid, &context);
      51                 :            : 
      52                 :          2 :         err = starpu_opencl_load_kernel(&kernel,
      53                 :            :                                         &queue,
      54                 :            :                                         &multiformat_program,
      55                 :            :                                         "multiformat_opencl",
      56                 :            :                                         devid);
      57         [ -  + ]:          2 :         if (err != CL_SUCCESS)
      58                 :          0 :                 STARPU_OPENCL_REPORT_ERROR(err);
      59                 :            : 
      60                 :          2 :         fail = clCreateBuffer(context, CL_MEM_COPY_HOST_PTR,
      61                 :            :                 sizeof(int), &multiformat_config.copy_failed, &err);
      62         [ -  + ]:          2 :         if (err != CL_SUCCESS)
      63                 :          0 :                 STARPU_OPENCL_REPORT_ERROR(err);
      64                 :            : 
      65                 :            :         /* Setting args */
      66                 :          2 :         err  = clSetKernelArg(kernel, 0, sizeof(val), &val);
      67         [ -  + ]:          2 :         if (err != CL_SUCCESS)
      68                 :          0 :                 STARPU_OPENCL_REPORT_ERROR(err);
      69                 :            : 
      70                 :          2 :         err = clSetKernelArg(kernel, 1, sizeof(n), &n);
      71         [ -  + ]:          2 :         if (err)
      72                 :          0 :                 STARPU_OPENCL_REPORT_ERROR(err);
      73                 :            : 
      74                 :          2 :         err = clSetKernelArg(kernel, 2, sizeof(fail), &fail);
      75         [ -  + ]:          2 :         if (err)
      76                 :          0 :                 STARPU_OPENCL_REPORT_ERROR(err);
      77                 :            : 
      78                 :          2 :         err = clSetKernelArg(kernel, 3, sizeof(factor), &factor);
      79         [ -  + ]:          2 :         if (err)
      80                 :          0 :                 STARPU_OPENCL_REPORT_ERROR(err);
      81                 :            : 
      82                 :            :         {
      83                 :          2 :                 size_t global=n;
      84                 :            :                 size_t local;
      85                 :            :                 size_t s;
      86                 :            :                 cl_device_id device;
      87                 :            : 
      88                 :          2 :                 starpu_opencl_get_device(devid, &device);
      89                 :            : 
      90                 :          2 :                 err = clGetKernelWorkGroupInfo (kernel,
      91                 :            :                                                 device,
      92                 :            :                                                 CL_KERNEL_WORK_GROUP_SIZE,
      93                 :            :                                                 sizeof(local),
      94                 :            :                                                 &local,
      95                 :            :                                                 &s);
      96         [ -  + ]:          2 :                 if (err != CL_SUCCESS)
      97                 :          0 :                         STARPU_OPENCL_REPORT_ERROR(err);
      98                 :            : 
      99         [ +  - ]:          2 :                 if (local > global)
     100                 :          2 :                         local = global;
     101                 :            : 
     102                 :          2 :                 err = clEnqueueNDRangeKernel(queue,
     103                 :            :                                         kernel,
     104                 :            :                                         1,
     105                 :            :                                         NULL,
     106                 :            :                                         &global,
     107                 :            :                                         &local,
     108                 :            :                                         0,
     109                 :            :                                         NULL,
     110                 :            :                                         &event);
     111                 :            : 
     112         [ -  + ]:          2 :                 if (err != CL_SUCCESS)
     113                 :          0 :                         STARPU_OPENCL_REPORT_ERROR(err);
     114                 :            :         }
     115                 :            : 
     116                 :          2 :         err = clEnqueueReadBuffer(queue,
     117                 :            :                                   fail,
     118                 :            :                                   CL_TRUE,
     119                 :            :                                   0, 
     120                 :            :                                   sizeof(int),
     121                 :            :                                   &multiformat_config.copy_failed,
     122                 :            :                                   0,
     123                 :            :                                   NULL,
     124                 :            :                                   NULL);
     125         [ -  + ]:          2 :         if (err != CL_SUCCESS)
     126                 :          0 :                 STARPU_OPENCL_REPORT_ERROR(err);
     127                 :            : 
     128                 :          2 :         clFinish(queue);
     129                 :          2 :         starpu_opencl_collect_stats(event);
     130                 :          2 :         clReleaseEvent(event);
     131                 :            : 
     132                 :          2 :         starpu_opencl_release_kernel(kernel);
     133                 :          2 :         ret = starpu_opencl_unload_opencl(&multiformat_program);
     134         [ -  + ]:          2 :         STARPU_CHECK_RETURN_VALUE(ret, "starpu_opencl_unload_opencl");
     135                 :            : }

Generated by: LCOV version 1.9