Results 1 to 6 of 6

Thread: Can i allocate memory inside kernel?

  1. #1

    Can i allocate memory inside kernel?

    Hi,

    I need to use a pointer inside of my kernel.
    Is it possible allocate memory to a __global pointer that i put inside of my kernel?

    Thanks,

  2. #2

    Re: Can i allocate memory inside kernel?

    short answer: no

    long answer: not yet

  3. #3
    Junior Member
    Join Date
    Dec 2010
    Posts
    18

    Re: Can i allocate memory inside kernel?

    One trick I have seen is to allocate a large block of __global memory using the host API, then use their favorite heap allocation algorithm inside the kernel to carve this memory up into smaller chunks.

  4. #4

    Re: Can i allocate memory inside kernel?

    Hi,

    Thanks, it works!

  5. #5

    What about this...

    I haven't had recourse to use this yet, so I haven't tried it. However the CL_MEM_ALLOC_HOST_PTR option for clCreateBuffer() seems to set up precisely what you want: allowing a kernel executing on a device to allocate host accessible (host?) memory. Here's the link to the specification:

    http://www.khronos.org/registry/cl/sdk/ ... uffer.html

    Or am I misunderstanding something entirely?

  6. #6

    Re: Can i allocate memory inside kernel?

    That means you're using a host pointer, or CPU memory, for your buffer. But right now you can't allocate any new memory (or free it) from within a kernel, only through the application API calls. ljbade's method is the best, until new OpenCL specs allow for dynamic memory within kernels.

Similar Threads

  1. Kernel Memory Error (illegal access inside kernel) - why?
    By Syndacate in forum OpenCL - parallel programming of heterogeneous systems
    Replies: 4
    Last Post: 08-06-2012, 01:18 AM
  2. Allocate __private memory inside a kernel
    By tehwalrus in forum OpenCL - parallel programming of heterogeneous systems
    Replies: 1
    Last Post: 11-23-2011, 03:58 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
  •