Initial public release.
[OpenCLIPER] / src / kernels / performanceTests / arrayMult.cl
1 /* Copyright (C) 2018 Federico Simmross Wattenberg,
2  *                    Manuel Rodríguez Cayetano,
3  *                    Javier Royuela del Val,
4  *                    Elena Martín González,
5  *                    Elisa Moya Sáez,
6  *                    Marcos Martín Fernández and
7  *                    Carlos Alberola López
8  *
9  * This file is part of OpenCLIPER.
10  *
11  * OpenCLIPER is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; version 3 of the License.
14  *
15  * OpenCLIPER is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with OpenCLIPER; If not, see <http://www.gnu.org/licenses/>.
22  *
23  *
24  *  Contact:
25  *
26  *  Federico Simmross Wattenberg
27  *  E.T.S.I. Telecomunicación
28  *  Universidad de Valladolid
29  *  Paseo de Belén 15
30  *  47011 Valladolid, Spain.
31  *  fedsim@tel.uva.es
32  */
33 #include <OpenCLIPER/kernels/hostKernelFunctions.h>
34
35 __kernel void arrayMult_kernel(__global realType* arrayA, __global realType* arrayB, __global realType* arrayC,
36                                unsigned int RowsA, unsigned int ColsA, unsigned int ColsB) {
37     // int row = get_global_id(0);
38     int row = get_global_id(0) / ColsA;
39     // int col = get_global_id(1);
40     int col = get_global_id(0) - row * ColsA;
41 #ifdef KERNEL_DEBUG
42     printf("global_size(0): %d\tglobal_size(1): %d\n", get_global_size(0), get_global_size(1));
43     printf("row : %d\tcol: %d\n", row, col);
44 #endif
45     if ((row < RowsA) && (col < ColsA)){
46 #ifdef KERNEL_DEBUG
47         printf("Calc C[%d,%d]\n", row, col);
48 #endif
49         unsigned int ColsC = ColsB;
50         float res = 0.0;
51         for (unsigned int k = 0; k < ColsA; k ++) {
52             res += arrayA[row*ColsA+k] * arrayB[k*ColsB+col];
53         }
54         arrayC[row*ColsC+col] = res;
55     } else {
56 #ifdef KERNEL_DEBUG
57         printf("Exiting without work, row: %d\tcol: %d\n", row, col);
58 #endif
59         return;
60     }
61 }