1 /* Copyright (C) 2018 Federico Simmross Wattenberg,
2 * Manuel Rodríguez Cayetano,
3 * Javier Royuela del Val,
4 * Elena Martín González,
6 * Marcos Martín Fernández and
7 * Carlos Alberola López
9 * This file is part of OpenCLIPER.
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.
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.
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/>.
26 * Federico Simmross Wattenberg
27 * E.T.S.I. Telecomunicación
28 * Universidad de Valladolid
30 * 47011 Valladolid, Spain.
33 #include <OpenCLIPER/processes/performanceTests/ArrayMultProcess.hpp>
34 #define CLASSNAME "OpenCLIPER::ArrayMultProcess"
36 namespace OpenCLIPER {
37 void ArrayMultProcess::init() {
38 kernel = getApp()->getKernel("arrayMult_kernel");
39 queue = getApp()->getCommandQueue();
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"));
51 cl::Buffer* pInBufB = getApp()->getData(inBufBDataHandle)->getNDArray(0)->getDeviceBuffer();
52 cl::Buffer* pOutBuf = getOutput()->getNDArray(0)->getDeviceBuffer();
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);
62 dimIndexType height = NDARRAYHEIGHT(getInput()->getNDArray(0));
63 dimIndexType width = NDARRAYWIDTH(getInput()->getNDArray(0));
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;
71 localSizes = getApp()->getMaxLocalWorkItemSizes(globalSizes);
74 localSizes = cl::NDRange();
77 localSizes = cl::NDRange(blockSize);
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;
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));
89 buildKernelProfilingInfo(profileParameters.profilingEnabled);
90 //stopProfiling(profileParameters.profilingEnabled);