Results 1 to 2 of 2

Thread: Problem with moving an array pointer in the Kernel

  1. #1
    Junior Member
    Join Date
    May 2010
    Posts
    2

    Problem with moving an array pointer in the Kernel

    Hello @all,

    iam working with OpenCL since around 2 months. I already solved a lot or problems by moving existing code
    from c++ to OpenCL. But no i stuck on a relay simple operation by moving a array-pointer ????

    Maybe somebody was already dealing with the same problem and can help me !!

    The Existing C++ Code :

    Code :
    int height = 200;
    int width  = 200;
    int yPos = 0;
    int *y = new int[width*height];
    int *buff = new int[width*height];
    int pich = width;
     
    w2 = (width + 7) / 8;  // 25
     
    for (int h=0; h < height; h++) {
    	for (int w=0; w < w2; w++) {
    		y[yPos++] = buff[w];
    	}
    	buff += pitch;	
    }

    My OpenCL implementation currently "Not Working"
    In the original implementation every filed up to height*w2 of "y" is filled, done
    by increasing yPos.
    The OpenCL implementation leaves fields empty , and i can just not find the workaround

    Code :
    __kernel void convert(__global const unsigned char* buff,__global unsigned char* y) {
     
     
      int x = get_global_id(0);  // width   globalWorkSize[0] = 200; 
      int y = get_global_id(1);  // height globalWorkSize[1] = 200; 
     
      int w2 = (get_global_size(0) + 7) / 8;
      long pos = y * get_global_size(0) + ( x ) ;
     
      if ( x < w2 )
    	y[pos] = buff[pos];
     
    }

  2. #2
    Junior Member
    Join Date
    Mar 2010
    Posts
    22

    Re: Problem with moving an array pointer in the Kernel

    Code :
    int height = 200;
    int width  = 200;
    int yPos = 0;
    int *y = new int[width*height];
    int *buff = new int[width*height];
    int pich = width;
     
    w2 = (width + 7) / 8;  // 25
     
    for (int h=0; h < height; h++) {
    	for (int w=0; w < w2; w++) {
    		y[yPos++] = buff[w];
    	}
    	buff += pitch;	
    }
    Well in this code it seems that you are concatenating height times the first w2 values of buff, in the middle you do buff += pitch but buff is an array and pitch is a value, this is not possible.....

    Code :
    __kernel void convert(__global const unsigned char* buff,__global unsigned char* y) {
     
     
      int x = get_global_id(0);  // width   globalWorkSize[0] = 200; 
      int y = get_global_id(1);  // height globalWorkSize[1] = 200; 
     
      int w2 = (get_global_size(0) + 7) / 8;
      long pos = y * get_global_size(0) + ( x ) ;
     
      if ( x < w2 )
    	y[pos] = buff[pos];
     
    }
    First, i suggest calculate only one time w2. Then, i think y[pos] is y[y*w2+x], and buff[y*get_global_size(0)+x] is OK because this is what the first code (C++ file) is doing.

Similar Threads

  1. Problem when moving object in Z coord...
    By lm2s in forum OpenGL ES 2X - for programmable 3D graphics pipelines
    Replies: 3
    Last Post: 04-23-2011, 03:44 AM
  2. Normal Pointer Array Size
    By NikLever in forum OpenGL ES 1.X - fixed function hardware
    Replies: 2
    Last Post: 06-10-2009, 09:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •