Note that there are some explanatory texts on larger screens.

plurals
  1. POopenCL - difference in handling array and scalar
    primarykey
    data
    text
    <p>I'm trying to dig into openCL. At the moment I'm asking myself why a scalar differs from array when it comes to transferring to GPU.</p> <p>Below there are two inputs. A scalar and a array. Why is there such a big difference in transferring them to the GPU?</p> <p>Thanks in advance!</p> <pre><code>// input size int input_size = 4; err = clSetKernelArg(kernel, 0, sizeof(unsigned int), &amp;_input_size); if (err != CL_SUCCESS) { throw std::runtime_error("Failed to set kernel arguments!"); } // input int input[input_size]; input[0] = 1; input[1] = 2; input[2] = 3; input[3] = 4; cl_mem cl_input = clCreateBuffer(context, CL_MEM_READ_ONLY, sizeof(int) * _input_size, NULL, NULL); if (!cl_input) { throw std::runtime_error("Failed to allocate device memory!"); } err = clSetKernelArg(kernel, 1, sizeof(cl_mem), &amp;cl_input); if (err != CL_SUCCESS) { throw std::runtime_error("Failed to set kernel arguments!"); } err = clEnqueueWriteBuffer(commands, cl_input, CL_TRUE, 0, sizeof(int) * _input_size, _input, 0, NULL, NULL); if (err != CL_SUCCESS) { throw std::runtime_error("Failed to write to source array!"); } // output int output_size = 4; int output[output_size]; cl_mem cl_output = clCreateBuffer(context, CL_MEM_WRITE_ONLY, sizeof(int) * _output_size, NULL, NULL); if (!cl_output) { throw std::runtime_error("Failed to allocate device memory!"); } err = clSetKernelArg(kernel, 2, sizeof(cl_mem), &amp;cl_output); if (err != CL_SUCCESS) { throw std::runtime_error("Failed to set kernel arguments!" ); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload