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 NX 16
22 : : #define NY NX
23 : : #define NZ NX
24 : :
25 : : /* Prototypes */
26 : : static void register_data(void);
27 : : static void unregister_data(void);
28 : : static void test_block_cpu_func(void *buffers[], void *args);
29 : : #ifdef STARPU_USE_CUDA
30 : : extern void test_block_cuda_func(void *buffers[], void *_args);
31 : : #endif
32 : : #ifdef STARPU_USE_OPENCL
33 : : extern void test_block_opencl_func(void *buffers[], void *args);
34 : : #endif
35 : :
36 : :
37 : : static starpu_data_handle_t _block_handle;
38 : : static starpu_data_handle_t _block2_handle;
39 : :
40 : : struct test_config block_config =
41 : : {
42 : : .cpu_func = test_block_cpu_func,
43 : : #ifdef STARPU_USE_CUDA
44 : : .cuda_func = test_block_cuda_func,
45 : : #endif
46 : : #ifdef STARPU_USE_OPENCL
47 : : .opencl_func = test_block_opencl_func,
48 : : #endif
49 : : .handle = &_block_handle,
50 : : .dummy_handle = &_block2_handle,
51 : : .copy_failed = SUCCESS,
52 : : .name = "block_interface"
53 : : };
54 : :
55 : : static int _block[NX*NY*NZ];
56 : : static int _block2[NX*NY*NZ];
57 : :
58 : : static void
59 : 1 : register_data(void)
60 : : {
61 : : /* Initializing data */
62 : 1 : int val = 0;
63 : : int i, j, k;
64 [ + + ]: 17 : for (k = 0; k < NZ; k++)
65 [ + + ]: 272 : for (j = 0; j < NY; j++)
66 [ + + ]: 4352 : for (i = 0; i < NX; i++)
67 : 4096 : _block[(k*NX*NY)+(j*NX)+i] = val++;
68 : :
69 : : /* Registering data */
70 : 1 : starpu_block_data_register(&_block_handle,
71 : : 0,
72 : : (uintptr_t)_block,
73 : : NX,
74 : : NX * NY,
75 : : NX,
76 : : NY,
77 : : NZ,
78 : : sizeof(_block[0]));
79 : 1 : starpu_block_data_register(&_block2_handle,
80 : : 0,
81 : : (uintptr_t)_block2,
82 : : NX,
83 : : NX * NY,
84 : : NX,
85 : : NY,
86 : : NZ,
87 : : sizeof(_block2[0]));
88 : 1 : }
89 : :
90 : : static void
91 : 1 : unregister_data(void)
92 : : {
93 : 1 : starpu_data_unregister(_block_handle);
94 : 1 : starpu_data_unregister(_block2_handle);
95 : 1 : }
96 : :
97 : 5 : static void test_block_cpu_func(void *buffers[], void *args)
98 : : {
99 [ - + ][ # # ]: 5 : STARPU_SKIP_IF_VALGRIND;
[ # # ]
100 : :
101 : 5 : int factor = *(int*)args;
102 : 5 : int nx = STARPU_BLOCK_GET_NX(buffers[0]);
103 : 5 : int ny = STARPU_BLOCK_GET_NY(buffers[0]);
104 : 5 : int nz = STARPU_BLOCK_GET_NZ(buffers[0]);
105 : 5 : unsigned ldy = STARPU_BLOCK_GET_LDY(buffers[0]);
106 : 5 : unsigned ldz = STARPU_BLOCK_GET_LDZ(buffers[0]);
107 : 5 : int *block = (int *) STARPU_BLOCK_GET_PTR(buffers[0]);
108 : : int i, j, k;
109 : 5 : int val = 0;
110 : 5 : block_config.copy_failed = SUCCESS;
111 [ + + ]: 85 : for (k = 0; k < nz; k++)
112 : : {
113 [ + + ]: 1360 : for (j = 0; j < ny; j++)
114 : : {
115 [ + + ]: 21760 : for (i = 0; i < nx; i++)
116 : : {
117 [ - + ]: 20480 : if (block[(k*ldz)+(j*ldy)+i] != factor * val)
118 : : {
119 : 0 : block_config.copy_failed = FAILURE;
120 : 0 : return;
121 : : }
122 : : else
123 : : {
124 : 20480 : block[(k*ldz)+(j*ldy)+i] *= -1;
125 : 20480 : val++;
126 : : }
127 : : }
128 : : }
129 : : }
130 : : }
131 : :
132 : : int
133 : 1 : main(void)
134 : : {
135 : : data_interface_test_summary *summary;
136 : : struct starpu_conf conf;
137 : 1 : starpu_conf_init(&conf);
138 : 1 : conf.ncuda = 2;
139 : 1 : conf.nopencl = 1;
140 : :
141 [ + - ][ + - ]: 1 : if (starpu_init(&conf) == -ENODEV || starpu_cpu_worker_get_count() == 0)
142 : : goto enodev;
143 : :
144 : 1 : register_data();
145 : :
146 : 1 : summary = run_tests(&block_config);
147 [ - + ]: 1 : if (!summary)
148 : 0 : exit(EXIT_FAILURE);
149 : :
150 : 1 : unregister_data();
151 : :
152 : 1 : starpu_shutdown();
153 : :
154 : 1 : data_interface_test_summary_print(stderr, summary);
155 : :
156 : 1 : return data_interface_test_summary_success(summary);
157 : :
158 : : enodev:
159 : 1 : return STARPU_TEST_SKIPPED;
160 : : }
161 : :
|