PyOpenCL: how to create a local memory buffer?

Probably extremely simple question here, but I’ve been searching for it for hours with nothing to show for.

I have this piece of code, I’d like to have a 256-bit (8 uint32) bitstring_gpu as a localmemory pointer in the device:

def Get_Bitstring_GPU_Buffer(ctx, bitstring):
    bitstring_gpu = cl.Buffer(ctx, mem_flags.READ_ONLY | mem_flags.COPY_HOST_PTR, hostbuf=bitstring)
return bitstring_gpu

This is later used on a kernel call:

prg.get_active_hard_locations_64bit(queue, (HARD_LOCATIONS,), None,, bitstring_gpu,, ).wait()

… and bitstring is just a random 256-bit bitstring (generated through sha256, then transformed into a numpy array.

def Get_Random_Bitstring():    
    bitstring = address_space_through_sha256_SDM.get_bitstring(str(random.randrange(2**32-1)))
return bitstring

How can I make bitstring_buf go to fast, local memory?

Related, but different question; here the buffer is being created inside the kernel…

How to create variable sized __local memory in pyopencl?

Source: c#

Leave a Reply