Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: Can't write in buffer

  1. #11
    Senior Member
    Join Date
    May 2010
    Location
    Toronto, Canada
    Posts
    845

    Re: Can't write in buffer

    Okay, since the explanation didn't work I will show one simple way to make it work (there are better ways):

    Code :
    __kernel void Closing_first(const __global unsigned char *in,
                                    __global unsigned char *out)
    {
        int row = get_global_id(1);
        int col = get_global_id(0);
        unsigned char pixel,neighborhood[9];
     
       // Read from input image
       if(row > 0 && row < HEIGHT-1 && col > 0 && col < WIDTH-1)
       {
          neighborhood[0]= in[(row-1)*WIDTH + col-1];
          neighborhood[1]= in[(row-1)*WIDTH + col];
          neighborhood[2]= in[(row-1)*WIDTH + col+1];
          ...
          pixel = Max(neighborhood, 9);   //dilate
       }
       else
       {
          pixel = in[row*WIDTH+col];
       }
     
       // Write into destination image.
       // Do not write into input image! You would destroy it and cause artifacts.
       out[row*WIDTH + col] = pixel ;
    }
     
     
    __kernel void Closing_second(const __global unsigned char *in,
                                    __global unsigned char *out)
    {
        int row = get_global_id(1);
        int col = get_global_id(0);
        unsigned char pixel,neighborhood[9];
     
       pixel = in[row*WIDTH+col];
     
       // Read from input image
       if(row > 0 && row < HEIGHT-1 && col > 0 && col < WIDTH-1)
       {
          neighborhood[0]= in[(row-1)*WIDTH + col-1];
          neighborhood[1]= in[(row-1)*WIDTH + col];
          neighborhood[2]= in[(row-1)*WIDTH + col+1];
          ...
     
          pixel = Min(neighborhood, 9);   //erode
       }
       else
       {
          pixel = in[row*WIDTH+col];
       }
     
       // Write into destination image.
       // Do not write into input image! You would destroy it and cause artifacts.
       out[row*WIDTH+col] = pixel;
    }

    From the API side you have to enqueue two kernels: one for Closing_first and then another for closing_second. Make sure that the output from Closing_first becomes the input of Closing_second.

    Once you get that version working, you can try a better algorithm using local memory. The idea is to store the intermediate result in local memory instead of having two enqueue two kernels.
    Disclaimer: Employee of Qualcomm Canada. Any opinions expressed here are personal and do not necessarily reflect the views of my employer. LinkedIn profile.

  2. #12

    Re: Can't write in buffer

    Yes, that's exactly what I meant by "transfer datas to GPU 2 times" and I did exactly what you wrote, and it had worked well.

    Once you get that version working, you can try a better algorithm using local memory. The idea is to store the intermediate result in local memory instead of having two enqueue two kernels.
    For now, I try to do some example on global memory only. Moreover, I have a real question about this, generally:
    - , should I do lot of example on global memory first for understand how kernels work, then improve them by working on local memory?
    - or, should I work on local memory as soon as possible, and not waste time. ?

    (I can ask the question on more appropriate thread ?)

  3. #13
    Senior Member
    Join Date
    May 2010
    Location
    Toronto, Canada
    Posts
    845

    Re: Can't write in buffer

    should I do lot of example on global memory first for understand how kernels work, then improve them by working on local memory?
    Yes, that's what I would do. It's easier to write a first version that works using global memory only. Also, it may be fast enough for what you need.

    This is a general rule for writing software that has worked well in the past: always start with the smallest and simplest version of your program that you can imagine. After you get that one working you can add features and complexity later.
    Disclaimer: Employee of Qualcomm Canada. Any opinions expressed here are personal and do not necessarily reflect the views of my employer. LinkedIn profile.

  4. #14

    Re: Can't write in buffer

    OK, thank you!

    And I'll remember (this kind of) trick you told me with local memory when I'll try to improve my code.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 5
    Last Post: 08-09-2011, 06:36 AM
  2. Replies: 3
    Last Post: 05-30-2011, 03:28 PM

Posting Permissions

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