Commit 808a12d1 authored by Swann Perarnau's avatar Swann Perarnau
Browse files

[feature/fix] copy layouts internally for dmas

If necessary, dma implementations copy the source and destination
layouts to avoid issues where the user would like to lose track of the
layout once the dma request has been launched.

Fixes #51.
parent 6228d2de
Pipeline #11070 passed with stages
in 3 minutes and 30 seconds
......@@ -986,6 +986,10 @@ struct aml_dma {
/**
* Requests a synchronous data copy between two different buffers.
*
* Layouts are copied internally if necessary, avoiding the need for users to
* keep the layouts alive during the request.
*
* @param dma: an initialized DMA structure.
* @param dest: layout describing the destination.
* @param src: layout describing the source.
......@@ -999,6 +1003,10 @@ int aml_dma_copy_custom(struct aml_dma *dma, struct aml_layout *dest,
/**
* Requests a data copy between two different buffers.This is an asynchronous
* version of aml_dma_copy().
*
* Layouts are copied internally if necessary, avoiding the need for users to
* keep the layouts alive during the request.
*
* @param dma: an initialized DMA structure.
* @param req: an address where the pointer to the newly assigned DMA request
* will be stored.
......
......@@ -36,8 +36,8 @@ int aml_dma_request_linux_par_copy_init(struct aml_dma_request_linux_par *req,
{
assert(req != NULL);
req->type = AML_DMA_REQUEST_TYPE_LAYOUT;
req->dest = dest;
req->src = src;
aml_layout_duplicate(dest, &req->dest);
aml_layout_duplicate(src, &req->src);
req->op = op;
req->op_arg = op_arg;
return 0;
......@@ -46,6 +46,8 @@ int aml_dma_request_linux_par_copy_init(struct aml_dma_request_linux_par *req,
int aml_dma_request_linux_par_copy_destroy(struct aml_dma_request_linux_par *r)
{
assert(r != NULL);
aml_layout_destroy(&r->src);
aml_layout_destroy(&r->dest);
return 0;
}
......
......@@ -37,8 +37,8 @@ int aml_dma_request_linux_seq_copy_init(struct aml_dma_request_linux_seq *req,
{
assert(req != NULL);
req->type = AML_DMA_REQUEST_TYPE_LAYOUT;
req->dest = dest;
req->src = src;
aml_layout_duplicate(dest, &req->dest);
aml_layout_duplicate(src, &req->src);
req->op = op;
req->op_arg = op_arg;
return 0;
......@@ -47,6 +47,8 @@ int aml_dma_request_linux_seq_copy_init(struct aml_dma_request_linux_seq *req,
int aml_dma_request_linux_seq_copy_destroy(struct aml_dma_request_linux_seq *r)
{
assert(r != NULL);
aml_layout_destroy(&r->src);
aml_layout_destroy(&r->dest);
return 0;
}
......@@ -229,21 +231,22 @@ int aml_dma_linux_seq_create(struct aml_dma **dma, size_t nbreqs,
return 0;
}
void aml_dma_linux_seq_destroy(struct aml_dma **dma)
void aml_dma_linux_seq_destroy(struct aml_dma **d)
{
struct aml_dma *d;
struct aml_dma_linux_seq *l;
struct aml_dma_linux_seq *dma;
if (dma == NULL)
return;
d = *dma;
if (d == NULL)
if (d == NULL || *d == NULL)
return;
assert(d->data != NULL);
l = (struct aml_dma_linux_seq *)d->data;
aml_vector_destroy(&l->data.requests);
pthread_mutex_destroy(&l->data.lock);
free(d);
*dma = NULL;
dma = (struct aml_dma_linux_seq *)(*d)->data;
for (size_t i = 0; i < aml_vector_size(dma->data.requests); i++) {
struct aml_dma_request_linux_seq *req;
req = aml_vector_get(dma->data.requests, i);
aml_dma_request_linux_seq_copy_destroy(req);
}
aml_vector_destroy(&dma->data.requests);
pthread_mutex_destroy(&dma->data.lock);
free(*d);
*d = NULL;
}
......@@ -63,27 +63,26 @@ int main(int argc, char *argv[])
/* move data around */
assert(!aml_dma_linux_seq_create(&dma, 1, NULL, NULL));
struct aml_dma_request *requests[16];
struct aml_layout *layouts[16][2];
for (int i = 0; i < 16; i++) {
size_t sz = isz/16;
size_t off = i*sz;
void *dptr = (void *)&(idest[off]);
void *sptr = (void *)&(isrc[off]);
struct aml_layout *src, *dest;
aml_layout_dense_create(&layouts[i][0], dptr, 0, sizeof(int),
1, &sz, NULL, NULL);
aml_layout_dense_create(&layouts[i][1], sptr, 0, sizeof(int),
1, &sz, NULL, NULL);
assert(!aml_dma_async_copy(dma, &requests[i],
layouts[i][0], layouts[i][1]));
aml_layout_dense_create(&dest, dptr, 0, sizeof(int), 1, &sz,
NULL, NULL);
aml_layout_dense_create(&src, sptr, 0, sizeof(int), 1, &sz,
NULL, NULL);
assert(!aml_dma_async_copy(dma, &requests[i], dest, src));
assert(requests[i] != NULL);
aml_layout_destroy(&dest);
aml_layout_destroy(&src);
}
assert(!aml_dma_fprintf(stderr, "test", dma));
for (int i = 0; i < 16; i++) {
assert(!aml_dma_wait(dma, &requests[i]));
aml_layout_destroy(&layouts[i][0]);
aml_layout_destroy(&layouts[i][1]);
}
assert(!memcmp(isrc, idest, isz*sizeof(int)));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment