0

EDIT

I did some tests on the char array inputs to the kernel. I noticed a rather odd behaviour: consider the Kernel program and accompanying PyOpenCL code:

#!/usr/bin/env python3

import pyopencl as cl
import numpy as np
import seq

# Write down our kernel as a multiline string.
kernel = """
__kernel void dragon(
    const int N,
    __global char *AplusB,   
    __global char *AminusB,
    __global char *plusMinus,   
    __global char *minusMinus,
    __global char *output
    )
{   
    int idx = get_global_id(0);

    if (idx < N){
        char b =AplusB[12];
                     printf("\\ %c \\n",b);

    }

}
"""
#declare constants
number_of_expansions = 4
total_probelem_size =7
resulting_str_size=62

# Step 1: Create a context.
# This will ask the user to select the device to be used.
context = cl.create_some_context()
# Create a queue to the device.
queue = cl.CommandQueue(context)
# Create the program.
program = cl.Program(context, kernel).build()
# Create the input string
AplusB =np.array(('FX+YF++-FX-YF+'))
AminusB= np.array(('FX+YF+--FX-YF+'))
plusMinus= np.array(('+-'))
minusMinus = np.array(('--'))

# Send the data to the guest memory.
mf = cl.mem_flags
AplusBBuf = cl.Buffer(context, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=AplusB)
AminusBBuf= cl.Buffer(context, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=AminusB)
plusMinusBuf = cl.Buffer(context, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=plusMinus)
minusMinusBuf = cl.Buffer(context, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=minusMinus)

# Create the memory on the device to put the result into.
out_buf = cl.Buffer(context, mf.WRITE_ONLY, size=resulting_str_size) 
copied_str = np.zeros(resulting_str_size)
# Initiate the kernel.
dragon = program.dragon
dragon.set_scalar_arg_dtypes([np.int32, None, None,None,None,None])

global_work_size = total_probelem_size
# Execute C = A * B.
dragon(queue, (global_work_size,), None,total_probelem_size,AplusBBuf, AminusBBuf,plusMinusBuf,minusMinusBuf,out_buf)
# Wait for the queue to be completely processed.
queue.finish()
# Read the array from the device.
cl.enqueue_copy(queue, copied_str, out_buf).wait()
print (copied_str)

"https://stackoverflow.com/questions/17603740/how-to-pass-a-list-of-strings-to-an-opencl-kernel-using-pyopencl"

Notice that in the kernel I try to print out characters inside the buffer AplusB. It appears I can only print out characters at indices 0, 4, 8,and 12. AplusBis of size 14. What could be the explanation of this behavior.

Gakuo
  • 845
  • 6
  • 26
  • I'm not familiar with pyopencl, so if it's a problem with the way you call into that I'm afraid I can't help you. One thing I will say is that OpenCL 1.0 implementations by default do not support bytewise writes (e.g. char/uchar) to global memory, unless they support the [cl_khr_byte_addressable_store](https://www.khronos.org/registry/OpenCL/sdk/1.0/docs/man/xhtml/cl_khr_byte_addressable_store.html) extension, *and it is enabled*. Nowadays, you're probably on a newer version than 1.0, but I suggest checking and making sure just in case. – pmdj Jul 25 '18 at 09:52
  • Another suggestion: make sure you check the return values for all OpenCL calls, including the kernel enqueueing call. I would not be surprised if the error happened earlier than where it's currently crashing. – pmdj Jul 25 '18 at 09:54
  • Further tests result in the behaviour shown above. Some indices of the char array inputs to the kernel are inaccessible. They return null. Which most likely explain the failure. – Gakuo Jul 25 '18 at 15:12
  • Have you checked the OpenCL version and byte addressable situation? This sounds like it might be the problem – pmdj Jul 25 '18 at 15:53

0 Answers0