Hi,


I have a problem with PyOpenCL using the ATI Stream SDK 2.2. I have a double 
precision ndarray a. I'm casting it to single precision using

a.astype(np.float32) before I transfer it to the device. If I allocate the 
buffer a_dev using the COPY_HOST_PTR flag and hostbuf=a.astype(np.float32) 
everything works fine, but if I first allocate memory and then use 
enqueue_write_buffer to transfer the data, the first couple of entries on the 
device contain junk. Starting with a_dev[4] (32 bit) or a_dev[8] (64 bit) 
everything is correct again. The problem occurs no matter if the device is a 
CPU or GPU. It does not show up with the NVIDIA SDK.



Here's a code example that shows the problem.



# -*- coding: utf-8 -*-

import pyopencl as cl

import numpy as np



kernel = """/// Simple copy kernel

    __kernel void copy(__global float* a, __global float* b){

        int i = get_global_id(0);

        b[i] = a[i];

    }

"""



def testCopy():

    ctx = cl.create_some_context()

    queue = cl.CommandQueue(ctx, properties =

        cl.command_queue_properties.PROFILING_ENABLE)

    prg = cl.Program(ctx, kernel).build(options="-g")

    mf = cl.mem_flags

    orig = np.random.random(1024)

    a = orig.astype(np.float32)

    b = np.zeros_like(a)

    b2 = np.zeros_like(a)

    a_dev = cl.Buffer(ctx, mf.READ_ONLY, a.nbytes)

    a2_dev = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR,

        hostbuf = orig.astype(np.float32)) # This works

    b_dev = cl.Buffer(ctx, mf.WRITE_ONLY, a.nbytes)

    b2_dev = cl.Buffer(ctx, mf.WRITE_ONLY, a.nbytes)

    cl.enqueue_write_buffer(queue, a_dev, orig.astype(np.float32))

#    cl.enqueue_write_buffer(queue, a_dev, a) # This works, too

    prg.copy(queue, a.shape, None, a_dev, b_dev)

    prg.copy(queue, a.shape, None, a2_dev, b2_dev)

    cl.enqueue_read_buffer(queue, b_dev, b).wait()

    cl.enqueue_read_buffer(queue, b2_dev, b2).wait()

    print np.sum(a), np.sum(b), np.sum(b2) # Results differ



if __name__ == "__main__":

    testCopy()



Any idea what's going on?


Jan

------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------
Forschungszentrum Juelich GmbH
52425 Juelich
Sitz der Gesellschaft: Juelich
Eingetragen im Handelsregister des Amtsgerichts Dueren Nr. HR B 3498
Vorsitzender des Aufsichtsrats: MinDirig Dr. Karl Eugen Huthmacher
Geschaeftsfuehrung: Prof. Dr. Achim Bachem (Vorsitzender),
Dr. Ulrich Krafft (stellv. Vorsitzender), Prof. Dr.-Ing. Harald Bolt,
Prof. Dr. Sebastian M. Schmidt
------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------
_______________________________________________
PyOpenCL mailing list
[email protected]
http://lists.tiker.net/listinfo/pyopencl

Reply via email to