Opencl Memory Object-global memory (1)

Source: Internet
Author: User

This log is a summary of the amd opencl document.

Opencl uses memory object to transmit data between host and device. Memory Object is managed by Runtime (part of the Runtime Library and driver.

The memory objects in opencl include buffer and image. buffer is a collection of One-dimensional data elements. Image is mainly used to store one-dimensional, two-dimensional, three-dimensional images, textures, or framebuffer. [GPU Optimization for image objects, such as L1 cache and tile mode address]

Let's draw a picture first, and then learn about various memory concepts:

Host memory:

It refers to the system memory. The CPU can access the system memory at full speed, but the GPU cannot directly access it.

Pinned host memory (page locked ):

Is a part of the host memory. The operating system determines its resident location. Its physical address is fixed and cannot be changed. Runtime limits the number of pinned memory used by opencl memory objects. Note: As the name suggests, pinned memory cannot be switched out of memory, which is page locked. The CPU can access the pinned memory at full speed, and the CPU cache must be consistent. GPU accesses pinned memory through PCIe, and cache consistency must also be maintained.

Device visible host memory:

As part of the pinned memory, you do not need to maintain the CPU cache consistency during GPU access, which can speed up GPU access. However, because there is no cache consistency, CPU read of these memory slows down, because combined write can be used (that is, write operations are performed through many adjacent addresses through a memory access), the CPU write operation speed is not slow.

Device memory:

Dgpu has its own device memory. The GPU can be accessed with high bandwidth, but the CPU cannot be accessed directly.

Host visible device memroy:

As part of dgpu, the GPU can access it at full speed. The memory is mapped to the CPU address space. As the cache-free memory, the CPU can directly access it through PCIe, of course, the speed is much slower than the system memory, but since it can be combined write (scatter write), The write speed depends on the PCIe bandwidth.

For APU, there is no separate global memory. It uses device visible memory as global memory.

The following describes how to transmit data between system memory and device memory:

When the data in system memory is to be copied to device memory, opencl runtime performs the following operations:

1. When the transmitted data is less than 32 KB, the CPU copies the data to the pinned memory buffer that can be accessed by the runtime, And the DMA engine executes the corresponding transmission. The opposite process is the same, data is transmitted from device memory to pinned memory buffer, and then copied to the specified system memory block.

2. When the data transmitted is greater than 32 KB and less than 16 MB, the top of the physical memory of the data is locked by the pinned (Lock page), the DMA engine performs the transfer operation, and the memory block is unpinned.

3. When the transmitted data is larger than 16 MB, the staging buffer of the host pinned memory is used, and the data is copied to the staging buffer in batches, and then transmitted to the device memory. Note: Dual-buffering is used, so that the DMA can copy data to the device, and the CPU can copy data to the stage buffer for parallel execution.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.