OpenCl in Action: Chapter 2
If you are reading OpenCL in Action and get stuck on section 2.3.3 (titled “Code example: testing device extensions”), it’s because there are several bugs in the code that will manifest themselves at runtime.
Line 30 contains the following line:
The issue is that the third parameter indicates that this function
call should read one device into the fourth parameter, which is
NULL. As this call is only trying to retrieve the number of devices
available, the simple fix is to replace it with:
If you run the code now however, you’ll run into a segmentation fault. Using gdb (or your debugger of choice) and stepping through the code, you’ll find that the segfault happens on line 50:
The clear bug here is that the third argument is the size of
ext_data which is a 4096 character array. It should be a
(the type of
addr_data). Replacing this code with:
will fix the problem. I will be posting fixes like this to this blog and committing the changes to this repository.
I may also end up porting all the sample code to use the C++ bindings.