kupl_memcpy2d
Copy the 2D memory at the src position to the dst position. The following figure shows the process.

Interface Definition
int kupl_memcpy2d(void *dst, size_t dpitch, const void *src, size_t spitch, size_t width, size_t height);
- The maximum width, height, and transfer interval supported by kupl_memcpy2d cannot exceed UINT32_MAX. That is, the maximum values of width, spitch-width, dpitch-width, and height are UINT32_MAX.
- The following conditions must be met: spitch × height < actual size of the memory pointed to by src, and dpitch × height < actual size of the memory pointed to by dst.
Environment Variables
KUPL uses KUPL_MEMCPY_MT_THRESHOLD and KUPL_SDMA_MEMCPY_THRESHOLD to determine the packet size thresholds for the multi-thread memcpy capability and the SDMA memcpy capability, respectively. By default, the multi-thread memcpy threshold is 512 KB, and the SDMA memcpy threshold is 2 MB.
kupl_memcpy2d supports three methods: single-thread glibc memcpy, SDMA memcpy, and multi-thread memcpy. If SDMA is enabled in the environment, determine a memcpy method based on KUPL_SDMA_MEMCPY_THRESHOLD. Data packets smaller than this threshold use glibc memcpy; otherwise, SDMA memcpy is utilized. Similarly, if SDMA is disabled, use KUPL_MEMCPY_MT_THRESHOLD to determine a memcpy method. Data packets smaller than this threshold use glibc memcpy; otherwise, multi-thread memcpy is utilized.
You can define the thresholds for multi-thread memcpy and SDMA memcpy by configuring KUPL_MEMCPY_MT_THRESHOLD and KUPL_SDMA_MEMCPY_THRESHOLD. These configurations are also used by the kupl_memcpy interface to determine the optimal memcpy method.
Parameters
|
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
|
dst |
void * |
Pointer to the destination location of the copied memory. |
Input/Output |
|
dpitch |
size_t |
Pitch between the destination memory, that is, the offset for storing width data each time. |
Input |
|
src |
const void * |
Pointer to the source location of memory to be copied. |
Input |
|
spitch |
size_t |
Pitch between the source memory, that is, the offset for fetching width data each time. |
Input |
|
width |
size_t |
Width of the memory to be copied. |
Input |
|
height |
size_t |
Height of the memory to be copied. |
Input |
Return Value
- Success: KUPL_OK
- Failure: KUPL_ERROR
Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
#include <stdio.h> #include <stdlib.h> #include <assert.h> #include "kupl.h" int main() { int len = 65536; double *src = (double *)kupl_malloc(KUPL_MEM_DEFAULT, len); double *dest = (double *)kupl_malloc(KUPL_MEM_DEFAULT, len); if (src == nullptr || dest == nullptr) { goto error; } for (int i = 0; i < len / sizeof(double); i++) { src[i] = i ; dest[i] = 0; } int height = 2, width = 200; int spitch = 300, dpitch = 400; int ret = kupl_memcpy2d(dest, dpitch, src, spitch, width, height); assert(ret == KUPL_OK); error: kupl_free(KUPL_MEM_DEFAULT, src); kupl_free(KUPL_MEM_DEFAULT, dest); return 0; } |
- The preceding example demonstrates the 2D memory copy process.
- The kupl_memcpy2d function copies the content in the src array to the dest array. The offset for each width data extracted from the src position is 300.
- The offset for each width data stored at the dest position is 400.
- The width and height of the copied data are 200 and 2, respectively.