-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpenCLEnvironment.cpp
More file actions
38 lines (33 loc) · 1.81 KB
/
OpenCLEnvironment.cpp
File metadata and controls
38 lines (33 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "OpenCLEnvironment.h"
#include <fstream>
#include <sstream>
#include <iostream>
OpenCLEnvironment::OpenCLEnvironment() {
std::ifstream infk("../kernels/program.cl");
std::stringstream stringbuffer;
stringbuffer << infk.rdbuf();
std::string kernelString = stringbuffer.str();
const char *kernelSource = kernelString.c_str();
cl_device_id devices[5];
cl_uint numDevices = 0;
clGetDeviceIDs(nullptr, CL_DEVICE_TYPE_GPU, 5, devices, &numDevices);
clContext = clCreateContext(nullptr, 1, &devices[1], nullptr, nullptr, nullptr);
clQueue = clCreateCommandQueue(clContext, devices[1], 0, nullptr);
clProgram = clCreateProgramWithSource(clContext, 1, &kernelSource, nullptr, nullptr);
cl_int buildError = clBuildProgram(clProgram, 0, nullptr, nullptr, nullptr, nullptr);
if (buildError == CL_BUILD_PROGRAM_FAILURE) {
size_t logSize = 0;
clGetProgramBuildInfo(clProgram, devices[1], CL_PROGRAM_BUILD_LOG, 0, nullptr, &logSize);
std::string log(logSize, '\0');
clGetProgramBuildInfo(clProgram, devices[1], CL_PROGRAM_BUILD_LOG, logSize, &log[0], nullptr);
std::cout << log << std::endl;
}
byteImageToComplexKernel = clCreateKernel(clProgram, "byteImageToComplex", nullptr);
fourierColsAndTransposeKernel = clCreateKernel(clProgram, "fourierColsAndTranspose", nullptr);
complexImageToLogMagnitudeKernel = clCreateKernel(clProgram, "complexImageToLogMagnitude", nullptr);
convolveKernel = clCreateKernel(clProgram, "convolve", nullptr);
grayscaleKernel = clCreateKernel(clProgram, "grayscale", nullptr);
mirrorHorizontalKernel = clCreateKernel(clProgram, "mirrorHorizontal", nullptr);
mirrorVerticalKernel = clCreateKernel(clProgram, "mirrorVertical", nullptr);
rotate90Kernel = clCreateKernel(clProgram, "rotate90", nullptr);
}