Commit 2b3a44c8 authored by Swann Perarnau's avatar Swann Perarnau
Browse files

[removal] remove pointer support in DMA requests

Remove support for direct pointers in a DMA request, with the goal to
remove va_args in the entire DMA API soon. As scratchs still work with
pointers, also modify scratchs to convert tiles in layouts.
parent e62db7b2
...@@ -820,11 +820,6 @@ int aml_layout_slice(const struct aml_layout *layout, ...@@ -820,11 +820,6 @@ int aml_layout_slice(const struct aml_layout *layout,
**/ **/
#define AML_DMA_REQUEST_TYPE_LAYOUT 0 #define AML_DMA_REQUEST_TYPE_LAYOUT 0
/**
* The request is in the format (dest ptr, src ptr, size)
*/
#define AML_DMA_REQUEST_TYPE_PTR 1
/** /**
* aml_dma is mainly used to asynchronously move data. * aml_dma is mainly used to asynchronously move data.
* aml_dma_request is an opaque structure containing information * aml_dma_request is an opaque structure containing information
......
...@@ -33,11 +33,11 @@ struct aml_scratch_request_par { ...@@ -33,11 +33,11 @@ struct aml_scratch_request_par {
**/ **/
int type; int type;
/** The source pointer of the data movement **/ /** The source pointer of the data movement **/
void *srcptr; struct aml_layout *src;
/** The tile identifier in source pointer **/ /** The tile identifier in source pointer **/
int srcid; int srcid;
/** The destination pointer of the data movement **/ /** The destination pointer of the data movement **/
void *dstptr; struct aml_layout *dst;
/** The tile identifier in destination pointer **/ /** The tile identifier in destination pointer **/
int dstid; int dstid;
/** The scratchpad handling this request **/ /** The scratchpad handling this request **/
......
...@@ -34,12 +34,12 @@ struct aml_scratch_request_seq { ...@@ -34,12 +34,12 @@ struct aml_scratch_request_seq {
int type; int type;
/** The tiling used for data organization in source and destination **/ /** The tiling used for data organization in source and destination **/
struct aml_tiling *tiling; struct aml_tiling *tiling;
/** The source pointer of the data movement **/ /** The source layout of the data movement **/
void *srcptr; struct aml_layout *src;
/** The identifier of the source tile **/ /** The identifier of the source tile **/
int srcid; int srcid;
/** The destination pointer of the data movement **/ /** The destination pointer of the data movement **/
void *dstptr; struct aml_layout *dst;
/** The identifier of the destination tile **/ /** The identifier of the destination tile **/
int dstid; int dstid;
/** The request used for movement **/ /** The request used for movement **/
......
...@@ -44,10 +44,6 @@ int aml_dma_request_linux_par_copy_init(struct aml_dma_request_linux_par *req, ...@@ -44,10 +44,6 @@ 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) int aml_dma_request_linux_par_copy_destroy(struct aml_dma_request_linux_par *r)
{ {
assert(r != NULL); assert(r != NULL);
if (r->type == AML_DMA_REQUEST_TYPE_PTR) {
aml_layout_dense_destroy(&r->dest);
aml_layout_dense_destroy(&r->src);
}
return 0; return 0;
} }
...@@ -101,26 +97,6 @@ int aml_dma_linux_par_create_request(struct aml_dma_data *d, ...@@ -101,26 +97,6 @@ int aml_dma_linux_par_create_request(struct aml_dma_data *d,
aml_dma_request_linux_par_copy_init(req, aml_dma_request_linux_par_copy_init(req,
AML_DMA_REQUEST_TYPE_LAYOUT, AML_DMA_REQUEST_TYPE_LAYOUT,
dl, sl); dl, sl);
} else if (type == AML_DMA_REQUEST_TYPE_PTR) {
struct aml_layout *dl, *sl;
void *dp, *sp;
size_t sz;
dp = va_arg(ap, void *);
sp = va_arg(ap, void *);
sz = va_arg(ap, size_t);
if (dp == NULL || sp == NULL || sz == 0) {
err = -AML_EINVAL;
goto unlock;
}
/* simple 1D layout, none of the parameters really matter, as
* long as the copy generates a single memcpy.
*/
aml_layout_dense_create(&dl, dp, 0, 1, 1, &sz, NULL, NULL);
aml_layout_dense_create(&sl, sp, 0, 1, 1, &sz, NULL, NULL);
aml_dma_request_linux_par_copy_init(req,
AML_DMA_REQUEST_TYPE_PTR,
dl, sl);
} else } else
err = -AML_EINVAL; err = -AML_EINVAL;
unlock: unlock:
......
...@@ -95,26 +95,6 @@ int aml_dma_linux_seq_create_request(struct aml_dma_data *d, ...@@ -95,26 +95,6 @@ int aml_dma_linux_seq_create_request(struct aml_dma_data *d,
aml_dma_request_linux_seq_copy_init(req, aml_dma_request_linux_seq_copy_init(req,
AML_DMA_REQUEST_TYPE_LAYOUT, AML_DMA_REQUEST_TYPE_LAYOUT,
dl, sl); dl, sl);
} else if (type == AML_DMA_REQUEST_TYPE_PTR) {
struct aml_layout *dl, *sl;
void *dp, *sp;
size_t sz;
dp = va_arg(ap, void *);
sp = va_arg(ap, void *);
sz = va_arg(ap, size_t);
if (dp == NULL || sp == NULL || sz == 0) {
err = -AML_EINVAL;
goto unlock;
}
/* simple 1D layout, none of the parameters really matter, as
* long as the copy generates a single memcpy.
*/
aml_layout_dense_create(&dl, dp, 0, 1, 1, &sz, NULL, NULL);
aml_layout_dense_create(&sl, sp, 0, 1, 1, &sz, NULL, NULL);
aml_dma_request_linux_seq_copy_init(req,
AML_DMA_REQUEST_TYPE_PTR,
dl, sl);
} else } else
err = -AML_EINVAL; err = -AML_EINVAL;
unlock: unlock:
...@@ -137,14 +117,7 @@ int aml_dma_linux_seq_destroy_request(struct aml_dma_data *d, ...@@ -137,14 +117,7 @@ int aml_dma_linux_seq_destroy_request(struct aml_dma_data *d,
return -AML_EINVAL; return -AML_EINVAL;
req = (struct aml_dma_request_linux_seq *)*r; req = (struct aml_dma_request_linux_seq *)*r;
if (req->type == AML_DMA_REQUEST_TYPE_LAYOUT) aml_dma_request_linux_seq_copy_destroy(req);
aml_dma_request_linux_seq_copy_destroy(req);
else if (req->type == AML_DMA_REQUEST_TYPE_PTR) {
aml_layout_dense_destroy(&req->dest);
aml_layout_dense_destroy(&req->src);
aml_dma_request_linux_seq_copy_destroy(req);
}
pthread_mutex_lock(&dma->data.lock); pthread_mutex_lock(&dma->data.lock);
aml_vector_remove(dma->data.requests, req); aml_vector_remove(dma->data.requests, req);
pthread_mutex_unlock(&dma->data.lock); pthread_mutex_unlock(&dma->data.lock);
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
*******************************************************************************/ *******************************************************************************/
#include "aml.h" #include "aml.h"
#include "aml/layout/dense.h"
#include "aml/scratch/par.h" #include "aml/scratch/par.h"
#include <assert.h> #include <assert.h>
...@@ -32,18 +33,26 @@ int aml_scratch_request_par_init(struct aml_scratch_request_par *req, int type, ...@@ -32,18 +33,26 @@ int aml_scratch_request_par_init(struct aml_scratch_request_par *req, int type,
{ {
assert(req != NULL); assert(req != NULL);
void *dp, *sp;
size_t size;
req->type = type; req->type = type;
req->scratch = scratch; req->scratch = scratch;
req->srcptr = srcptr;
req->srcid = srcid; req->srcid = srcid;
req->dstptr = dstptr;
req->dstid = dstid; req->dstid = dstid;
dp = aml_tiling_tilestart(scratch->data.tiling, dstptr, dstid);
sp = aml_tiling_tilestart(scratch->data.tiling, srcptr, srcid);
size = aml_tiling_tilesize(scratch->data.tiling, srcid);
aml_layout_dense_create(&req->dst, dp, 0, 1, 1, &size, NULL, NULL);
aml_layout_dense_create(&req->src, sp, 0, 1, 1, &size, NULL, NULL);
return 0; return 0;
} }
int aml_scratch_request_par_destroy(struct aml_scratch_request_par *r) int aml_scratch_request_par_destroy(struct aml_scratch_request_par *r)
{ {
assert(r != NULL); assert(r != NULL);
aml_layout_dense_destroy(&r->dst);
aml_layout_dense_destroy(&r->src);
return 0; return 0;
} }
...@@ -56,17 +65,8 @@ void *aml_scratch_par_do_thread(void *arg) ...@@ -56,17 +65,8 @@ void *aml_scratch_par_do_thread(void *arg)
(struct aml_scratch_request_par *)arg; (struct aml_scratch_request_par *)arg;
struct aml_scratch_par *scratch = req->scratch; struct aml_scratch_par *scratch = req->scratch;
void *dest, *src; aml_dma_copy(scratch->data.dma, AML_DMA_REQUEST_TYPE_LAYOUT,
size_t size; req->dst, req->src);
dest = aml_tiling_tilestart(scratch->data.tiling,
req->dstptr, req->dstid);
src = aml_tiling_tilestart(scratch->data.tiling,
req->srcptr, req->srcid);
size = aml_tiling_tilesize(scratch->data.tiling, req->srcid);
aml_dma_copy(scratch->data.dma, AML_DMA_REQUEST_TYPE_PTR,
dest, src, size);
return NULL; return NULL;
} }
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
*******************************************************************************/ *******************************************************************************/
#include "aml.h" #include "aml.h"
#include "aml/layout/dense.h"
#include "aml/scratch/seq.h" #include "aml/scratch/seq.h"
#include <assert.h> #include <assert.h>
...@@ -31,18 +32,26 @@ int aml_scratch_request_seq_init(struct aml_scratch_request_seq *req, int type, ...@@ -31,18 +32,26 @@ int aml_scratch_request_seq_init(struct aml_scratch_request_seq *req, int type,
{ {
assert(req != NULL); assert(req != NULL);
void *dp, *sp;
size_t size;
req->type = type; req->type = type;
req->tiling = t; req->tiling = t;
req->srcptr = srcptr;
req->srcid = srcid; req->srcid = srcid;
req->dstptr = dstptr;
req->dstid = dstid; req->dstid = dstid;
dp = aml_tiling_tilestart(req->tiling, dstptr, dstid);
sp = aml_tiling_tilestart(req->tiling, srcptr, srcid);
size = aml_tiling_tilesize(req->tiling, srcid);
aml_layout_dense_create(&req->dst, dp, 0, 1, 1, &size, NULL, NULL);
aml_layout_dense_create(&req->src, sp, 0, 1, 1, &size, NULL, NULL);
return 0; return 0;
} }
int aml_scratch_request_seq_destroy(struct aml_scratch_request_seq *r) int aml_scratch_request_seq_destroy(struct aml_scratch_request_seq *r)
{ {
assert(r != NULL); assert(r != NULL);
aml_layout_dense_destroy(&r->dst);
aml_layout_dense_destroy(&r->src);
return 0; return 0;
} }
...@@ -54,14 +63,9 @@ int aml_scratch_seq_doit(struct aml_scratch_seq_data *scratch, ...@@ -54,14 +63,9 @@ int aml_scratch_seq_doit(struct aml_scratch_seq_data *scratch,
{ {
assert(scratch != NULL); assert(scratch != NULL);
assert(req != NULL); assert(req != NULL);
void *dest, *src;
size_t size;
dest = aml_tiling_tilestart(req->tiling, req->dstptr, req->dstid);
src = aml_tiling_tilestart(req->tiling, req->srcptr, req->srcid);
size = aml_tiling_tilesize(req->tiling, req->srcid);
return aml_dma_async_copy(scratch->dma, &req->dma_req, return aml_dma_async_copy(scratch->dma, &req->dma_req,
AML_DMA_REQUEST_TYPE_PTR, dest, src, size); AML_DMA_REQUEST_TYPE_LAYOUT,
req->dst, req->src);
} }
struct aml_scratch_seq_ops aml_scratch_seq_inner_ops = { struct aml_scratch_seq_ops aml_scratch_seq_inner_ops = {
......
...@@ -39,12 +39,6 @@ int main(int argc, char *argv[]) ...@@ -39,12 +39,6 @@ int main(int argc, char *argv[])
/* invalid requests */ /* invalid requests */
assert(!aml_dma_linux_par_create(&dma, 1)); assert(!aml_dma_linux_par_create(&dma, 1));
assert(aml_dma_copy(dma, 42) == -AML_EINVAL); assert(aml_dma_copy(dma, 42) == -AML_EINVAL);
assert(aml_dma_copy(dma, AML_DMA_REQUEST_TYPE_PTR, NULL, isrc, isz) ==
-AML_EINVAL);
assert(aml_dma_copy(dma, AML_DMA_REQUEST_TYPE_PTR, idest, NULL, isz) ==
-AML_EINVAL);
assert(aml_dma_copy(dma, AML_DMA_REQUEST_TYPE_PTR, idest, isrc, 0) ==
-AML_EINVAL);
assert(aml_dma_copy(dma, AML_DMA_REQUEST_TYPE_LAYOUT, NULL, isl) == assert(aml_dma_copy(dma, AML_DMA_REQUEST_TYPE_LAYOUT, NULL, isl) ==
-AML_EINVAL); -AML_EINVAL);
assert(aml_dma_copy(dma, AML_DMA_REQUEST_TYPE_LAYOUT, idl, NULL) == assert(aml_dma_copy(dma, AML_DMA_REQUEST_TYPE_LAYOUT, idl, NULL) ==
...@@ -77,20 +71,26 @@ int main(int argc, char *argv[]) ...@@ -77,20 +71,26 @@ int main(int argc, char *argv[])
/* move data around */ /* move data around */
assert(!aml_dma_linux_par_create(&dma, 1)); assert(!aml_dma_linux_par_create(&dma, 1));
struct aml_dma_request *requests[16]; struct aml_dma_request *requests[16];
struct aml_layout *layouts[16][2];
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
size_t sz = isz/16; size_t sz = isz/16;
size_t off = i*sz; size_t off = i*sz;
void *dptr = (void *)&(idest[off]); void *dptr = (void *)&(idest[off]);
void *sptr = (void *)&(isrc[off]); void *sptr = (void *)&(isrc[off]);
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], assert(!aml_dma_async_copy(dma, &requests[i],
AML_DMA_REQUEST_TYPE_PTR, AML_DMA_REQUEST_TYPE_LAYOUT,
dptr, sptr, sz*sizeof(int))); layouts[i][0], layouts[i][1]));
assert(requests[i] != NULL); assert(requests[i] != NULL);
} }
for(int i = 0; i < 16; i++) for(int i = 0; i < 16; i++) {
assert(!aml_dma_wait(dma, &requests[i])); assert(!aml_dma_wait(dma, &requests[i]));
aml_layout_dense_destroy(&layouts[i][0]);
aml_layout_dense_destroy(&layouts[i][1]);
}
assert(!memcmp(isrc, idest, isz*sizeof(int))); assert(!memcmp(isrc, idest, isz*sizeof(int)));
/* delete everything */ /* delete everything */
......
...@@ -39,12 +39,6 @@ int main(int argc, char *argv[]) ...@@ -39,12 +39,6 @@ int main(int argc, char *argv[])
/* invalid requests */ /* invalid requests */
assert(!aml_dma_linux_seq_create(&dma, 1)); assert(!aml_dma_linux_seq_create(&dma, 1));
assert(aml_dma_copy(dma, 42) == -AML_EINVAL); assert(aml_dma_copy(dma, 42) == -AML_EINVAL);
assert(aml_dma_copy(dma, AML_DMA_REQUEST_TYPE_PTR, NULL, isrc, isz) ==
-AML_EINVAL);
assert(aml_dma_copy(dma, AML_DMA_REQUEST_TYPE_PTR, idest, NULL, isz) ==
-AML_EINVAL);
assert(aml_dma_copy(dma, AML_DMA_REQUEST_TYPE_PTR, idest, isrc, 0) ==
-AML_EINVAL);
assert(aml_dma_copy(dma, AML_DMA_REQUEST_TYPE_LAYOUT, NULL, isl) == assert(aml_dma_copy(dma, AML_DMA_REQUEST_TYPE_LAYOUT, NULL, isl) ==
-AML_EINVAL); -AML_EINVAL);
assert(aml_dma_copy(dma, AML_DMA_REQUEST_TYPE_LAYOUT, idl, NULL) == assert(aml_dma_copy(dma, AML_DMA_REQUEST_TYPE_LAYOUT, idl, NULL) ==
...@@ -76,24 +70,32 @@ int main(int argc, char *argv[]) ...@@ -76,24 +70,32 @@ int main(int argc, char *argv[])
/* move data around */ /* move data around */
assert(!aml_dma_linux_seq_create(&dma, 1)); assert(!aml_dma_linux_seq_create(&dma, 1));
struct aml_dma_request *requests[16]; struct aml_dma_request *requests[16];
struct aml_layout *layouts[16][2];
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
size_t sz = isz/16; size_t sz = isz/16;
size_t off = i*sz; size_t off = i*sz;
void *dptr = (void *)&(idest[off]); void *dptr = (void *)&(idest[off]);
void *sptr = (void *)&(isrc[off]); void *sptr = (void *)&(isrc[off]);
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], assert(!aml_dma_async_copy(dma, &requests[i],
AML_DMA_REQUEST_TYPE_PTR, AML_DMA_REQUEST_TYPE_LAYOUT,
dptr, sptr, sz*sizeof(int))); layouts[i][0], layouts[i][1]));
assert(requests[i] != NULL); assert(requests[i] != NULL);
} }
for(int i = 0; i < 16; i++) for(int i = 0; i < 16; i++) {
assert(!aml_dma_wait(dma, &requests[i])); assert(!aml_dma_wait(dma, &requests[i]));
aml_layout_dense_destroy(&layouts[i][0]);
aml_layout_dense_destroy(&layouts[i][1]);
}
assert(!memcmp(isrc, idest, isz*sizeof(int))); assert(!memcmp(isrc, idest, isz*sizeof(int)));
/* delete everything */ /* delete everything */
aml_dma_linux_seq_destroy(&dma); aml_dma_linux_seq_destroy(&dma);
aml_layout_dense_destroy(&idl);
aml_layout_dense_destroy(&isl);
aml_finalize(); aml_finalize();
return 0; return 0;
} }
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