LCOV - code coverage report
Current view: top level - tests/datawizard/interfaces/matrix - matrix_interface.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 31 34 91.2 %
Date: 2012-04-11 Functions: 4 4 100.0 %
Branches: 9 18 50.0 %

           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
      12                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
      13                 :            :  *
      14                 :            :  * See the GNU Lesser General Public License in COPYING.LGPL for more details.
      15                 :            :  */
      16                 :            : #include <config.h>
      17                 :            : #include <starpu.h>
      18                 :            : #include "../test_interfaces.h"
      19                 :            : #include "../../../helper.h"
      20                 :            : 
      21                 :            : #define WIDTH  16
      22                 :            : #define HEIGHT 16
      23                 :            : 
      24                 :            : #ifdef STARPU_USE_CPU
      25                 :            : static void test_matrix_cpu_func(void *buffers[], void *args);
      26                 :            : #endif /* !STARPU_USE_CPU */
      27                 :            : #ifdef STARPU_USE_CUDA
      28                 :            : extern void test_matrix_cuda_func(void *buffers[], void *_args);
      29                 :            : #endif
      30                 :            : #ifdef STARPU_USE_OPENCL
      31                 :            : extern void test_matrix_opencl_func(void *buffers[], void *args);
      32                 :            : #endif
      33                 :            : 
      34                 :            : 
      35                 :            : static starpu_data_handle_t matrix_handle;
      36                 :            : static starpu_data_handle_t matrix2_handle;
      37                 :            : 
      38                 :            : struct test_config matrix_config =
      39                 :            : {
      40                 :            : #ifdef STARPU_USE_CPU
      41                 :            :         .cpu_func      = test_matrix_cpu_func,
      42                 :            : #endif /* ! STARPU_USE_CPU */
      43                 :            : #ifdef STARPU_USE_CUDA
      44                 :            :         .cuda_func     = test_matrix_cuda_func,
      45                 :            : #endif
      46                 :            : #ifdef STARPU_USE_OPENCL
      47                 :            :         .opencl_func   = test_matrix_opencl_func,
      48                 :            : #endif
      49                 :            :         .handle        = &matrix_handle,
      50                 :            :         .dummy_handle  = &matrix2_handle,
      51                 :            :         .copy_failed   = 0,
      52                 :            :         .name          = "matrix_interface"
      53                 :            : };
      54                 :            : 
      55                 :            : static int matrix[WIDTH * HEIGHT];
      56                 :            : static int matrix2[WIDTH * HEIGHT];
      57                 :            : 
      58                 :            : static void
      59                 :          1 : register_data(void)
      60                 :            : {
      61                 :            :         int i;
      62                 :          1 :         int size = WIDTH * HEIGHT;
      63         [ +  + ]:        257 :         for (i = 0; i < size; i++)
      64                 :        256 :                 matrix[i] = i;
      65                 :            : 
      66                 :          1 :         starpu_matrix_data_register(&matrix_handle,
      67                 :            :                                     0,
      68                 :            :                                     (uintptr_t) matrix,
      69                 :            :                                     WIDTH, /* ld */
      70                 :            :                                     WIDTH,
      71                 :            :                                     HEIGHT,
      72                 :            :                                     sizeof(matrix[0]));
      73                 :          1 :         starpu_matrix_data_register(&matrix2_handle,
      74                 :            :                                     0,
      75                 :            :                                     (uintptr_t) matrix2,
      76                 :            :                                     WIDTH, /* ld */
      77                 :            :                                     WIDTH,
      78                 :            :                                     HEIGHT,
      79                 :            :                                     sizeof(matrix[0]));
      80                 :          1 : }
      81                 :            : 
      82                 :            : static void
      83                 :          1 : unregister_data(void)
      84                 :            : {
      85                 :          1 :         starpu_data_unregister(matrix_handle);
      86                 :          1 :         starpu_data_unregister(matrix2_handle);
      87                 :          1 : }
      88                 :            : 
      89                 :            : static void
      90                 :          5 : test_matrix_cpu_func(void *buffers[], void *args)
      91                 :            : {
      92 [ -  + ][ #  # ]:          5 :         STARPU_SKIP_IF_VALGRIND;
                 [ #  # ]
      93                 :            : 
      94                 :            :         int *val;
      95                 :            :         int factor;
      96                 :            :         int i;
      97                 :            :         unsigned int nx, ny;
      98                 :            : 
      99                 :          5 :         nx = STARPU_MATRIX_GET_NX(buffers[0]);
     100                 :          5 :         ny = STARPU_MATRIX_GET_NY(buffers[0]);
     101                 :          5 :         val = (int *) STARPU_MATRIX_GET_PTR(buffers[0]);
     102                 :          5 :         factor = *(int *) args;
     103                 :            : 
     104         [ +  + ]:       1285 :         for (i = 0; i < nx*ny; i++)
     105                 :            :         {
     106         [ -  + ]:       1280 :                 if (val[i] != i * factor)
     107                 :            :                 {
     108                 :          0 :                         matrix_config.copy_failed = 1;
     109                 :          0 :                         return;
     110                 :            :                 }
     111                 :       1280 :                 val[i] *= -1;
     112                 :            :         }
     113                 :            : }
     114                 :            : 
     115                 :            : int
     116                 :          1 : main(void)
     117                 :            : {
     118                 :            :         data_interface_test_summary *summary;
     119                 :          1 :         struct starpu_conf conf =
     120                 :            :         {
     121                 :            :                 .ncpus   = -1,
     122                 :            :                 .ncuda   = 2,
     123                 :            :                 .nopencl = 1
     124                 :            :         };
     125                 :            : 
     126 [ +  - ][ +  - ]:          1 :         if (starpu_init(&conf) == -ENODEV || starpu_cpu_worker_get_count() == 0)
     127                 :            :                 goto enodev;
     128                 :            : 
     129                 :          1 :         register_data();
     130                 :            : 
     131                 :          1 :         summary = run_tests(&matrix_config);
     132         [ -  + ]:          1 :         if (!summary)
     133                 :          0 :                 exit(EXIT_FAILURE);
     134                 :            : 
     135                 :          1 :         unregister_data();
     136                 :            : 
     137                 :          1 :         starpu_shutdown();
     138                 :            : 
     139                 :          1 :         data_interface_test_summary_print(stderr, summary);
     140                 :            : 
     141                 :          1 :         return data_interface_test_summary_success(summary);
     142                 :            : 
     143                 :            : enodev:
     144                 :          1 :         return STARPU_TEST_SKIPPED;
     145                 :            : }

Generated by: LCOV version 1.9