Rate This Document
Findability
Accuracy
Completeness
Readability

kupl_memcpy2d_async

Conduct asynchronous 2D memcpy from the src position to the dst position.

Interface Definition

int kupl_memcpy2d_async(void *dst, size_t dpitch, const void *src, size_t spitch, size_t width, size_t height, kupl_queue_h queue, kupl_event_h event);

  • The maximum width, height, and transfer interval supported by kupl_memcpy2d_async cannot exceed UINT32_MAX. That is, the maximum values of width, spitch-width, dpitch-width, and height are UINT32_MAX.
  • The values of spitch × height and dpitch × height must be less than the actual sizes of the memory pointed to by src and dst, respectively.

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_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_memcpy_async interface to determine the optimal memcpy method.

Parameters

Table 1 Parameter definition

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

queue

kupl_queue_h

Queue to which the 2D 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
34
35
#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 malloc_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;
    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_memcpy2d_async(dest, dpitch, src, spitch, width, height, 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 2D asynchronous memory copy process.
  • The kupl_memcpy2d_async function asynchronously 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.
  • 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.