Initial public release.
[OpenCLIPER] / src / processes / performanceTests / ArrayMultProcess.cpp
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/processes/performanceTests/ArrayMultProcess.hpp>
34 #define CLASSNAME "OpenCLIPER::ArrayMultProcess"
35
36 namespace OpenCLIPER {
37 void ArrayMultProcess::init() {
38     kernel = getApp()->getKernel("arrayMult_kernel");
39     queue = getApp()->getCommandQueue();
40 }
41
42 void ArrayMultProcess::launch(ProfileParameters profileParameters) {
43     // Set input and output OpenCL buffers on device memory
44     auto pLP = dynamic_pointer_cast<LaunchParameters>(pLaunchParameters);
45     cl::Buffer* pInBufA = getInput()->getNDArray(0)->getDeviceBuffer();
46     DataHandle inBufBDataHandle = pLP->inHandleB;
47     if (inBufBDataHandle == INVALIDDATAHANDLE) {
48         throw invalid_argument(std::string(CLASSNAME) + std::string("::launch: non-existing second array"));
49     }
50
51     cl::Buffer* pInBufB = getApp()->getData(inBufBDataHandle)->getNDArray(0)->getDeviceBuffer();
52     cl::Buffer* pOutBuf = getOutput()->getNDArray(0)->getDeviceBuffer();
53
54     // Set kernel parameters
55     kernel.setArg(0, *pInBufA);
56     kernel.setArg(1, *pInBufB);
57     kernel.setArg(2, *pOutBuf);
58     kernel.setArg(3, pLP->RowsA);
59     kernel.setArg(4, pLP->ColsA);
60     kernel.setArg(5, pLP->ColsB);
61
62     dimIndexType height = NDARRAYHEIGHT(getInput()->getNDArray(0));
63     dimIndexType width = NDARRAYWIDTH(getInput()->getNDArray(0));
64
65     //cl::NDRange globalSizes = cl::NDRange(height, width);
66     cl::NDRange globalSizes = cl::NDRange(height * width);
67     cl::NDRange localSizes;
68     unsigned int blockSize = pLP->blockSize;
69     switch (blockSize) {
70         case -1:
71             localSizes = getApp()->getMaxLocalWorkItemSizes(globalSizes);
72             break;
73         case 0:
74             localSizes = cl::NDRange();
75             break;
76         default:
77             localSizes = cl::NDRange(blockSize);
78     }
79     cerr << "globalSizes: " << globalSizes[0] << ", " << globalSizes[1] << std::endl;
80     cerr << "localsizes: " << localSizes[0] << ", " << localSizes[1] << std::endl;
81     cerr << "globalSizes: " << globalSizes[0] << ", " << globalSizes[1] << std::endl;
82     cerr << "localsizes: " << localSizes[0] << ", " << localSizes[1] << std::endl;
83     // Execute kernel
84     //startProfiling(profileParameters.profilingEnabled);
85     eventsVector.resize(profileParameters.numOfRepetitions);
86     for (unsigned long i = 0; i < profileParameters.numOfRepetitions; i++) {
87         queue.enqueueNDRangeKernel(kernel, cl::NullRange, globalSizes, cl::NDRange(), NULL, &eventsVector.at(i));
88     }
89     buildKernelProfilingInfo(profileParameters.profilingEnabled);    
90     //stopProfiling(profileParameters.profilingEnabled);
91 }
92 }