Forum Discussion
Altera_Forum
Honored Contributor
10 years agoHi matt.weber,
HPS and FPGA do have shared memory. The best way to access it is to allocate OpenCL buffer using clCreateBuffer() command with CL_MEM_ALLOC_HOST_PTR flag. To access this buffer in the kernel, simply pass returned cl_mem object as a kernel argument. To access it from the host, first map it into user pointer with clEnqueueMapBuffer(). The (virtual) pointer returned by clEnqueueMapBuffer() will point to the same physical location as cl_mem object returned by clCreateBuffer(). See "Allocating Shared Memory for OpenCL Kernels Targeting SoCs" section in Altera SDK for OpenCLProgramming Guide. Note that Cyclone V SoC (and Arria V SoC) have shared *physical* memory but not shared *virtual* memory. This means that the FPGA core has access to the same DDR controller as the HPS but FPGA cannot access HPS's page tables that map virtual pointers to physical. clCreateBuffer() with ALLOC_HOST_PTR allocates physically contiguous memory and stores its physical address inside opaque cl_mem object. clEnqueueMapBuffer() on such cl_mem object simply converts the physical pointer into virtual pointer using some Linux driver magic.