BMEVIIIMB01
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

61 lines
1.9 KiB

#include <iostream>
#include "Common.h"
#include "Tests.h"
Square::Square() {
for (size_t index = 0; index < data_size; ++index)
{
gpuHostBuffer.push_back(static_cast<float>(index));
sourceData.push_back(static_cast<float>(index));
}
}
void Square::gpu_compute(cl::Context* context, cl::CommandQueue* queue, cl::Program* program, cl::Event* Event) {
cl_int err = CL_SUCCESS;
// Get the kernel handle
cl::Kernel kernel(*program, "square", &err);
CheckCLError(err);
clInputBuffer = cl::Buffer(*context, CL_MEM_READ_ONLY, sizeof(float) * data_size, NULL, &err);
queue->enqueueWriteBuffer(clInputBuffer,
true, // Blocking!
0, sizeof(float) * data_size, gpuHostBuffer.data());
// Allocate the output data
clResultBuffer = cl::Buffer(*context, CL_MEM_WRITE_ONLY, sizeof(float) * data_size, NULL, &err);
// Set the kernel parameters
kernel.setArg(0, clInputBuffer); // kernel FV paraméterei sorrendben
kernel.setArg(1, clResultBuffer);
// Enqueue the kernel
queue->enqueueNDRangeKernel(kernel,
cl::NullRange, // Indexek nem eloffszetelve
cl::NDRange(data_size, 1), // Minden elemet egy szál
cl::NullRange, // Workgroup méret? - ez az auto, ha nem indul, 1024-re, onnan csökkent, amig elindul
NULL, //
Event); // Õ jlezi hogy vége, lsd lent
}
void Square::cpu_compute()
{
for (size_t index = 0; index < data_size; index++) {
cpuResult.push_back(sourceData[index] * sourceData[index]);
}
}
void Square::collect_results(cl::CommandQueue* queue) {
queue->enqueueReadBuffer(clResultBuffer, true, 0, sizeof(float) * data_size, gpuHostBuffer.data());
}
bool Square::validate_results() {
for (size_t index = 0; index < data_size; index++) {
if (cpuResult[index] != gpuHostBuffer[index]) {
std::cout << "Wrong result at [" << index << "]: " << gpuHostBuffer[index] << "!=" << cpuResult[index] << std::endl;
return false;
}
}
std::cout << "Test \"Square\" completed." << std::endl;
return true;
}