| OpenCL provides full code functional portability and is the ideal programming model for heterogeneous systems, which consist of a host with multiple computing devices.However, in order to make full use of the computing capacity of such systems, programmers have to explicitly distribute the workload between different devices and manage data transfer between multiple devices. Both of these jobs are tedious for programmers. So in this paper, an OpenCL Multi-device Shared Memory(OMSM) is proposed, which can relieve programmers of managing data transfer explicitly.Two main tasks of OMSM is workload distribution and buffer management. Owing to the independence of work group which built inside the OpenCL programming model,these tasks can be automated. All the work groups in the index space is independent, so the workload distribution process can be simply performed by assigning different amount of work groups to different devices. And the write regions of work groups can not overlap,which make the regions in regular shape.The automation of memory access analysis is the key to automate the two tasks. In this paper, we first analyze the memory access patterns of work groups and the features of kernel codes. Then, we propose constrained linear representation to describe memory access patterns of work groups. For efficiency, we design several manipulations: intersection, normalization, independent variable elimination and solution. Based on LLVM infrastructure, a memory access analyzer is implemented to get memory access patterns automatically. With memory access information, OMSM runtime executes in two stages:one is profiling which can balance the workload. The other is automatic buffer management with segment table which maintain the distribution of each data.Our experimental results show that the applicability of OMSM for kernels without indirect accesses is good, and the performance on both isomorphic and heterogeneous platform is high. |