The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

jb4652 (9) [Avatar] Offline
1. In order to run Listing 6.1, you need libpng and zlib. The corresponding binaries from gnuwin32 can not be directly used in VS2010. However, use src there and compile them with VS2010 is easy.
You have to comment this line
//#include <unistd.h> /* for SEEK_* and off_t */

2. Unluckily, the output of the program is a pure dark image. By debugging the host program, I found the (void*)pixels become NULL after clEnqueueReadImage function call.

3. After several hours' struggle, I found something interesting. As described in the spec1.1, if image_channel_data_type = CL_UNORM_INT16;
we have no choices but use read_imagef & write_imagef in the kernel functions(Sec. The however used read_imageui & write_imageui.

4. After modifying the kernel, it is still not working. Given pixel.x=0.5f(expecting gray) will still NULL the (void*)pixels, but pixel.x=0.1f seems generating some color like gray.
Using Google, I found that some parameters are not supported by hardware, e.g. CL_MEM_WRITE_ONLY is not supported for Intel CPU for some image format. (
Nvidia GPU seems support them but the result is still not correct.
Also I test CL_FLOAT, but does not work either...

5. A strange thing is the forbidden CL_UNSIGNED_INT16 plus read_imageui & write_imageui can result in figure 6.2 ...

Filling the image data array with color directly instead of reading from image file may prevent the supporting issues. Output can also be simple image format like .bmp. Then libpng and zlib can be omitted...

simple_image.c Line14
#include <Windows.h> seems no use...

Line 123
*data = malloc(*h * png_get_rowbytes(png_ptr, info_ptr));
should be
*data = (png_byte*)malloc(*h * png_get_rowbytes(png_ptr, info_ptr));

One question:
err |= clSetKernelArg(kernel, 1, sizeof(cl_mem), &output_image);
What is the different between "|=" and "=" ?
jb4652 (9) [Avatar] Offline
Re: Questions about Listing 6.1

float2 input_coord = (float2)
(get_global_id(0) + (1.0f/(SCALE*2)),
get_global_id(1) + (1.0f/(SCALE*2)));
What is the purpose of + (1.0f/(SCALE*2)