kupl_memcpy_async
Asynchronously copy the memory from the src position to the dst position.
Interface Definition
int kupl_memcpy_async(void *dst, const void *src, size_t count, kupl_queue_h queue, kupl_event_h event);
- Currently, the maximum copy length supported by kupl_memcpy_async is UINT32_MAX. That is, the value of count cannot exceed UINT32_MAX.
- The value of count must be less than the actual size of the memory to which src and dst point.
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_memcpy_async supports three methods: single-thread glibc memcpy, SDMA memcpy, and multi-thread memcpy. If SDMA is enabled in the environment, SDMA memcpy is used by default. 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 threshold for multi-thread memcpy by configuring KUPL_MEMCPY_MT_THRESHOLD. The configuration is also used by the kupl_memcpy2d_async 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 |
src |
const void * |
Pointer to the source location of memory to be copied. |
Input |
count |
size_t |
Size of the memory to be copied. |
Input |
queue |
kupl_queue_h |
Queue to which the memcpy task is submitted. |
Input |
event |
kupl_event_h |
Event parameters passed for subsequent synchronization. |
Input/Output |
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 27 28 29 30 31 32 33 | #include <stdio.h> #include <stdlib.h> #include <assert.h> #include "kupl.h" int main() { int len = 1024; char *src = (char *)kupl_malloc(KUPL_MEM_DEFAULT, len); char *dest = (char *)kupl_malloc(KUPL_MEM_DEFAULT, len); if (src == nullptr || dest == nullptr) { goto malloc_error; } for (int i = 0; i < len / sizeof(char); i++) { src[i] = i ; dest[i] = 0; } kupl_queue_h queue = kupl_queue_create(); kupl_event_h event = kupl_event_create(); if (queue == nullptr || event == nullptr) { goto queue_event_error; } int ret = kupl_memcpy_async(dest, src, len, queue, event); assert(ret == KUPL_OK); kupl_event_wait(event); queue_event_error: kupl_event_destroy(event); kupl_queue_destroy(queue); malloc_error: kupl_free(KUPL_MEM_DEFAULT, src); kupl_free(KUPL_MEM_DEFAULT, dest); return 0; } |
- The preceding example demonstrates the asynchronous memory copy process.
- The kupl_memcpy_async function asynchronously copies the content in the src array to the dest array. len represents the size of the copied memory, and event is used for asynchronous copy and subsequent synchronization.
- Only SDMA memcpy supports asynchronous memcpy. Consequently, a warning will be printed if other memcpy methods are used.