How to transfer C++ std::vector to openCL kernels? -


i have implement matrix class using 2 dimensional vectors in c++ (vector<vector<float>>()). want optimize code using gpgpu using opencl. runing in problems every miniute. please me , give me tips this.

my requirements follows

  1. since want use matrix library implement machine learning algo there may huge matrix, 1000*400.
  2. can use 2 dimensional vectors , transfer them opencl kernels (because if can use vectors implement class more easy implementing these scratch using array).

one of code segments follows, here in kernal try add 10 every element.

but output shows change values in frist vector[0][n] elemets.

this segment in host program....

int in_vec_size = 100; int out_vec_size = 100;  vector<vector<float>> in_vec(10,vector<float>(10)); vector<vector<float>> out_vec(10, vector<float>(10)); int k = 0;  //initialize input vec (int i=0; < 10;i++) {     (int j = 0; j < 10;j++)     {         in_vec[i][j] = k++;         out_vec[i][j] = 0;     } }  //creating bufferes cl::buffer inbuff(context, cl_mem_read_only | cl_mem_copy_host_ptr, in_vec_size*4, &in_vec[0][0]); cl::buffer outbuff(context, cl_mem_write_only, out_vec_size*4, null);  //set kernal args kernal.setarg(0, inbuff); kernal.setarg(1, outbuff); kernal.setarg(2, in_vec_size);  cl::commandqueue queue(context, devices_gpu[0]);  queue.enqueuetask(kernal); queue.enqueuewritebuffer(inbuff, cl_true, 0, in_vec_size*4, &in_vec[0][0]); queue.enqueuereadbuffer(outbuff, cl_true, 0, out_vec_size*4, &out_vec[0][0]);  (int = 0; < 10; i++) {     (int j = 0; j < 10; j++)     {         cout << out_vec[i][j] << endl;     } }  __kernel void add(__global float*in,__global float*out,int x)  {    // i=get_global_id(0);    for(int i=0;i<x;i++)    {       out[i] = in[i]+10;    } } 

you're using multdimensonal vector.

it means, outer vector contains inner vectors in continuous fashion. content class, not plain data. so, data, initialize opencl memory objects with, isn't continuous. initialize cl_mem insides of vector class implementation data, not matrix data.

use single vector of size mxn instead. take @ this questionon.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -