Hello opencl community,
I just started learning opencl. In the last few days, I solved my programing problems by myself. Since yesterday, I have a problem I cannot solve by myself. So, I ask for your help.
After some hello-world tutorial programs I started with little complex tasks. I want to use an implemented opencl kernel to encrypt some short passwords.
My frist question is, whether I have to buffer a single value variable (for expl. a single factor) the same way as arrays/pointers to pass it to the kernel.
I wrote this program:
#define __CL_ENABLE_EXCEPTIONS
#include <fstream>
#include <iostream>
#include <iterator>
#include <CL/cl.hpp>
#include <CL/opencl.h>
using namespace std;
int main () {
vector<cl::Platform> platforms;
vector<cl::Device> devices;
vector<cl::Kernel> kernels;
try {
// create platform
cl::Platform::get(&platforms);
platforms[0].getDevices(CL_DEVICE_TYPE_GPU, &devices);
// create context
cl::Context context(devices);
// create command queue
cl::CommandQueue queue(context, devices[0]);
// load opencl source
ifstream cl_file("pbkdf2_kernel.cl");
string cl_string(istreambuf_iterator<char>(cl_file), (istreambuf_iterator<char>()));
cl::Program::Sources source(1, make_pair(cl_string.c_str(),
cl_string.length() + 1));
// create program
cl::Program program(context, source);
// compile opencl source
program.build(devices);
// load named kernel from opencl source
cl::Kernel kernel(program, "PBKDF2");
// create a message to send to kernel ----------------------------------------------------------------
char* password = "C & OpenCL is cool";
//unsigned int keyBytes = 18; // keyBytes
cl_int keyBytes = 18; // keyBytes
char* passwordSalt = "12345678901234567890123456789012";
cl_int passwordSaltLen = 32;
cl_int passwordIterations = 2;
// ---------------------------------------------------------------------------------------------------
// allocate device buffer to hold message
cl::Buffer bufferA(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(char) * keyBytes, password);
cl::Buffer bufferB(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(char) * passwordSaltLen, passwordSalt);
cl::Buffer bufferC(context, CL_MEM_WRITE_ONLY, sizeof(char) * keyBytes);
queue.enqueueWriteBuffer(bufferA, CL_TRUE, 0, keyBytes * sizeof(char), password);
queue.enqueueWriteBuffer(bufferB, CL_TRUE, 0, passwordSaltLen * sizeof(char), passwordSalt);
//void PBKDF2 ( const __global unsigned int *pass_global,
// const __global unsigned int *salt, int usrlen, uint num_keys, __global unsigned int *out_global)
// set message as kernel argument
kernel.setArg(0, bufferA);
kernel.setArg(1, bufferB);
kernel.setArg(2, passwordIterations);
kernel.setArg(3, keyBytes);
// execute kernel
queue.enqueueTask(kernel);
// wait for completion
queue.finish();
// ----------------------
char* out_global = " !";
queue.enqueueReadBuffer(bufferC, CL_TRUE, 0, keyBytes * sizeof(char), out_global);
cout << "Output " << out_global << endl;
// ----------------------
cout << endl;
} catch (cl::Error e) {
cout << endl << e.what() << " : " << e.err() << endl;
}
return 0;
}
Well, the used implementation of pbkdf2-hmac-sha1 can be accessed by the function:
void PBKDF2 ( const __global unsigned int *pass_global, const __global unsigned int *salt, int usrlen, uint num_keys, __global unsigned int *out_global) {
...
}
The used implementation of pbkdf2-hmac-sha1 is written by Sayantan Datta.
I get to following error msg, I cannot handle:
clEnqueueTask : -52
Can someone help, please?
Thank you,
Regards,
Pit