This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

pyopencl on EVMK2H

Hi,

I have recently installed MCSDK-HPC on my EVMK2H and have run all the OpenCL examples on the board. My application requires real-time implementation hence I used the offline embedded compilation method using the offline compiler "clocl" with "-t" option mentioned here: 

I followed the example 'offline_embed' to write my code which creates context and en-queues kernel in a .cpp file. I have two questions

1) Can this process be implemented in python? using pyopencl? 

2) pyopencl setup guide available online is for HP m800 Moonshot, can I use the same guide for EVMK2H as they have the same SoC?

Regards,

Osama Toor

  • The pyopencl setup guide was targeted for the m800 moonshot and not the evm, because the m800 ships with a Ubuntu distribution and installing the dependencies needed for pyopencl is simple using apt-get.  The evm ships with an embedded linux distro and does not include some of the python dependencies needed for pyopencl.  

    As you state, it is the same SOC and therefore there are no technical reasons pyopencl that prevent pyopencl from running on the EVM.  You would need to replicate pyopencl, numpy, and some of the other python sub-dependencies in order to make it work.

    -Alan  

  • Thanks for replying!

    I have one more question. Is there some way to read the binary header file created by 'clocl -t {any_opencl_kernel}' in pyopencl?
  • clocl -t kernel.cl will generate a c/c++ file approprate for inclusion in a c or c++ program.  You would need to modify the content of that file to make it usable in python.

    However, you can still use offline compilation in python, by running clocl without the -t option.  This will generate a binary .out file.  to use that file your python would look something like this :

    ctx = cl.create_some_context()
    queue = cl.CommandQueue(ctx)
    device = queue.get_info(cl.command_queue_info.DEVICE)
    binary = open("kernel.out", "rb").read()
    prg = cl.Program(ctx, [device], [binary]).build(options="")

    The above will benefit from not performing the slow online compilation.  It will only entail a binary file read that should be quick.

    If you do want the -t option, you could modify the .dsp_h output that unmodified would look like this:

    unsigned int hello_dsp_bin_len = 3372;
    char hello_dsp_bin[] = { 0x7f
    , 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
    . . . 

    , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
    , 0x01, 0x00, 0x00, 0x00
    };

    To something that looked like this:

    binary = bytearray([ 0x7f
    , 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00

    . . . 

    , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
    , 0x01, 0x00, 0x00, 0x00
    ])

    then remove

    binary = open("kernel.out", "rb").read()

    from the example above