OpenCL* for CPU
Ask questions and share information on Intel® SDK for OpenCL™ Applications and OpenCL™ implementations for Intel® CPU.
Announcements
This forum covers OpenCL* for CPU only. OpenCL* for GPU questions can be asked in the GPU Compute Software forum. Intel® FPGA SDK for OpenCL™ questions can be ask in the FPGA Intel® High Level Design forum.

how to use work_item function, barrier function, mem_fence in built-in fucntions

kerotankcn_ne_jp
Beginner
1,210 Views
Hi,

I have been studying a parallel programing with IntelOpenCLSDK 1.5 onIntel core processor. When I read OpenCL specification, there are some functions to execute aparallel program with vector-typed data. As there is not a sample program in Intel OpenCL SDK 1.5, I cannot understand how to use work_item functions, barrier function, and mem_fence function. If I will use these functions, will my program run faster? My PC's environment is as follows:
-------------
OS: Windows 7 Professional
Processor:Intel Core i7-2640M CPU
Tool: Microsoft Visual Studio 2010
-------------
Best Wishes,
Noriko Etani
0 Kudos
2 Replies
Raghupathi_M_Intel
1,210 Views
Hi Noriko,

To use barrier and mem_fence you need to understand parallel execution and synchronization. barrier() function ensures correct ordering of local/global memory operations (depending on what flag you pass to it - CLK_LOCAL_MEM_FENCE or CLK_GLOBAL_MEM_FENCE). Basically barriers synchronize threads in the same workgroup, butnot across workgroups.

According to the OpenCL spec,a mem_fence() ensures ordering between memory operations of a work-item. Meaning loads and stores operations before the mem_fence will be committed to memory before any loads

and stores following the mem_fence.

These routines won't make your program run faster, but help in ensuring correct behavior of parallel execution. There are a lot of caveats using synchronization functions. I suggest you grab an OpenCL book or look at the spec to understand what to do and what to avoid.

The work_item functions let you query the number of dimensions, the local and global ids of a work-item, number of local and global work-items etc.

Unfortunately our SDK doesn't have any samples demonstrating these functions. But there are a lot of examples out there, if you search online.

If you still need code samples, feel free to post and I'll point you to some resources. In the future we'll try to add more examples to the SDK where and when possible.

Thanks,
Raghu

0 Kudos
qually_j_
Beginner
1,210 Views

Hi Raghu,

I looked around and I can get a ton of good example of barrier. However for mem_fence, I can't really get a good example. 

Regards,
Qually

0 Kudos
Reply