Commit f7ec7762 authored by Swann Perarnau's avatar Swann Perarnau

[refactor] make scratch work with new tilings

Only works for scratch_seq right now.
parent ac8d9bb3
Pipeline #8415 failed with stages
in 5 minutes and 19 seconds
...@@ -957,7 +957,8 @@ struct aml_scratch_ops { ...@@ -957,7 +957,8 @@ struct aml_scratch_ops {
**/ **/
int (*create_request)(struct aml_scratch_data *scratch, int (*create_request)(struct aml_scratch_data *scratch,
struct aml_scratch_request **req, int type, struct aml_scratch_request **req, int type,
va_list args); struct aml_layout **dest, int *destid,
struct aml_layout *src, int srcid);
/** /**
* \todo Doc * \todo Doc
**/ **/
...@@ -968,10 +969,6 @@ struct aml_scratch_ops { ...@@ -968,10 +969,6 @@ struct aml_scratch_ops {
**/ **/
int (*wait_request)(struct aml_scratch_data *scratch, int (*wait_request)(struct aml_scratch_data *scratch,
struct aml_scratch_request *req); struct aml_scratch_request *req);
/**
* \todo Doc
**/
void *(*baseptr)(const struct aml_scratch_data *scratch);
/** /**
* \todo Doc * \todo Doc
**/ **/
...@@ -1003,7 +1000,9 @@ struct aml_scratch { ...@@ -1003,7 +1000,9 @@ struct aml_scratch {
* @see aml_scratch_baseptr() * @see aml_scratch_baseptr()
* @return 0 if successful; an error code otherwise. * @return 0 if successful; an error code otherwise.
**/ **/
int aml_scratch_pull(struct aml_scratch *scratch, ...); int aml_scratch_pull(struct aml_scratch *scratch,
struct aml_layout **dest, int *scratchid,
struct aml_layout *src, int srcid);
/** /**
* Requests a pull from regular memory to the scratchpad. This is an * Requests a pull from regular memory to the scratchpad. This is an
...@@ -1016,7 +1015,9 @@ int aml_scratch_pull(struct aml_scratch *scratch, ...); ...@@ -1016,7 +1015,9 @@ int aml_scratch_pull(struct aml_scratch *scratch, ...);
* @see aml_scratch_pull() * @see aml_scratch_pull()
**/ **/
int aml_scratch_async_pull(struct aml_scratch *scratch, int aml_scratch_async_pull(struct aml_scratch *scratch,
struct aml_scratch_request **req, ...); struct aml_scratch_request **req,
struct aml_layout **scratch_layout, int *scratchid,
struct aml_layout *src_layout, int srcid);
/** /**
* Requests a synchronous push from the scratchpad to regular memory. * Requests a synchronous push from the scratchpad to regular memory.
* @param scratch: an initialized scratchpad structure. * @param scratch: an initialized scratchpad structure.
...@@ -1030,7 +1031,9 @@ int aml_scratch_async_pull(struct aml_scratch *scratch, ...@@ -1030,7 +1031,9 @@ int aml_scratch_async_pull(struct aml_scratch *scratch,
* @return 0 if successful; an error code otherwise. * @return 0 if successful; an error code otherwise.
* @see aml_scratch_baseptr() * @see aml_scratch_baseptr()
**/ **/
int aml_scratch_push(struct aml_scratch *scratch, ...); int aml_scratch_push(struct aml_scratch *scratch,
struct aml_layout **dest_layout, int *destid,
struct aml_layout *scratch_layout, int scratchid);
/** /**
* Requests a push from the scratchpad to regular memory. This is an * Requests a push from the scratchpad to regular memory. This is an
...@@ -1043,7 +1046,9 @@ int aml_scratch_push(struct aml_scratch *scratch, ...); ...@@ -1043,7 +1046,9 @@ int aml_scratch_push(struct aml_scratch *scratch, ...);
* @see aml_scratch_push() * @see aml_scratch_push()
**/ **/
int aml_scratch_async_push(struct aml_scratch *scratch, int aml_scratch_async_push(struct aml_scratch *scratch,
struct aml_scratch_request **req, ...); struct aml_scratch_request **req,
struct aml_layout **dest_layout, int *destid,
struct aml_layout *scratch_layout, int scratchid);
/** /**
* Waits for an asynchronous scratch request to complete. * Waits for an asynchronous scratch request to complete.
* @param scratch: an initialized scratchpad structure. * @param scratch: an initialized scratchpad structure.
......
...@@ -32,15 +32,11 @@ struct aml_scratch_request_seq { ...@@ -32,15 +32,11 @@ struct aml_scratch_request_seq {
* @see <aml.h> * @see <aml.h>
**/ **/
int type; int type;
/** The tiling used for data organization in source and destination **/
struct aml_tiling *tiling;
/** The source layout of the data movement **/ /** The source layout of the data movement **/
struct aml_layout *src; struct aml_layout *src;
/** The identifier of the source tile **/
int srcid; int srcid;
/** The destination pointer of the data movement **/ /** The destination pointer of the data movement **/
struct aml_layout *dst; struct aml_layout *dst;
/** The identifier of the destination tile **/
int dstid; int dstid;
/** The request used for movement **/ /** The request used for movement **/
struct aml_dma_request *dma_req; struct aml_dma_request *dma_req;
...@@ -48,22 +44,11 @@ struct aml_scratch_request_seq { ...@@ -48,22 +44,11 @@ struct aml_scratch_request_seq {
/** Inner data of the sequential scratchpad implementation **/ /** Inner data of the sequential scratchpad implementation **/
struct aml_scratch_seq_data { struct aml_scratch_seq_data {
/** The source area where data comes from **/ struct aml_tiling *src_tiling;
struct aml_area *src_area; struct aml_tiling *scratch_tiling;
/** The destination area where data temporariliy goes to **/
struct aml_area *sch_area;
/**
* The data organisation.
* /todo why can't source and destination tiling vary?
**/
struct aml_tiling *tiling;
/** \todo What is this? **/
size_t scratch_size;
/** The dma engine in charge of the transfer **/ /** The dma engine in charge of the transfer **/
struct aml_dma *dma; struct aml_dma *dma;
/** Pointer to data in scratch destination **/ /** Map of tiles src layouts to scratch ids **/
void *sch_ptr;
/** The tilings involved in ongoing scratch requests **/
struct aml_vector *tilemap; struct aml_vector *tilemap;
/** The set of dma requests submitted to the dma to mode data **/ /** The set of dma requests submitted to the dma to mode data **/
struct aml_vector *requests; struct aml_vector *requests;
...@@ -96,21 +81,17 @@ struct aml_scratch_seq { ...@@ -96,21 +81,17 @@ struct aml_scratch_seq {
* @param scratch an address where the pointer to the newly allocated scratchpad * @param scratch an address where the pointer to the newly allocated scratchpad
* structure will be stored. * structure will be stored.
* *
* @param scratch_area the memory area where the scratchpad will be allocated.
* @param source_area the memory area containing the user data structure.
* @param dma the DMA that will be used for migrating data to and from * @param dma the DMA that will be used for migrating data to and from
* the scratchpad. * the scratchpad.
* @param tiling the tiling to use on the user data structure and the scratch. * @param src_tiling the tiling on the source memory
* @param nbtiles number of tiles to divide the scratchpad into. * @param scratch_tiling the tiling to use on the scratch
* @param nbreqs the initial number of slots for asynchronous request that * @param nbreqs the initial number of slots for asynchronous request that
* are in-flight (will be increased automatically if necessary). * are in-flight (will be increased automatically if necessary).
* @return 0 if successful; an error code otherwise. * @return 0 if successful; an error code otherwise.
**/ **/
int aml_scratch_seq_create(struct aml_scratch **scratch, int aml_scratch_seq_create(struct aml_scratch **scratch,
struct aml_area *scratch_area, struct aml_dma *dma, struct aml_tiling *src_tiling,
struct aml_area *src_area, struct aml_tiling *scratch_tiling, size_t nbreqs);
struct aml_dma *dma, struct aml_tiling *tiling,
size_t nbtiles, size_t nbreqs);
/** /**
* Tears down an initialized sequential scratchpad. * Tears down an initialized sequential scratchpad.
......
...@@ -20,91 +20,94 @@ ...@@ -20,91 +20,94 @@
* abstract the request creation after this layer. * abstract the request creation after this layer.
******************************************************************************/ ******************************************************************************/
int aml_scratch_pull(struct aml_scratch *scratch, ...) int aml_scratch_pull(struct aml_scratch *scratch,
struct aml_layout **dest, int *scratchid,
struct aml_layout *src, int srcid)
{ {
assert(scratch != NULL);
va_list ap;
int ret;
struct aml_scratch_request *req; struct aml_scratch_request *req;
int ret;
va_start(ap, scratch); if (scratch == NULL || dest == NULL || scratchid == NULL
|| src == NULL)
return -AML_EINVAL;
ret = scratch->ops->create_request(scratch->data, &req, ret = scratch->ops->create_request(scratch->data, &req,
AML_SCRATCH_REQUEST_TYPE_PULL, ap); AML_SCRATCH_REQUEST_TYPE_PULL,
va_end(ap); dest, scratchid, src, srcid);
ret = scratch->ops->wait_request(scratch->data, req); if (ret)
return ret; return ret;
return scratch->ops->wait_request(scratch->data, req);
} }
int aml_scratch_async_pull(struct aml_scratch *scratch, int aml_scratch_async_pull(struct aml_scratch *scratch,
struct aml_scratch_request **req, ...) struct aml_scratch_request **req,
struct aml_layout **dest, int *scratchid,
struct aml_layout *src, int srcid)
{ {
assert(scratch != NULL); if (scratch == NULL || dest == NULL || scratchid == NULL
assert(req != NULL); || src == NULL)
va_list ap; return -AML_EINVAL;
int ret;
va_start(ap, req); return scratch->ops->create_request(scratch->data, req,
ret = scratch->ops->create_request(scratch->data, req, AML_SCRATCH_REQUEST_TYPE_PULL,
AML_SCRATCH_REQUEST_TYPE_PULL, ap); dest, scratchid, src, srcid);
va_end(ap);
return ret;
} }
int aml_scratch_push(struct aml_scratch *scratch, ...) int aml_scratch_push(struct aml_scratch *scratch,
struct aml_layout **dest, int *destid,
struct aml_layout *src, int srcid)
{ {
assert(scratch != NULL);
struct aml_scratch_request *req; struct aml_scratch_request *req;
va_list ap;
int ret; int ret;
va_start(ap, scratch); if (scratch == NULL || dest == NULL || destid == NULL
|| src == NULL)
return -AML_EINVAL;
ret = scratch->ops->create_request(scratch->data, &req, ret = scratch->ops->create_request(scratch->data, &req,
AML_SCRATCH_REQUEST_TYPE_PUSH, ap); AML_SCRATCH_REQUEST_TYPE_PUSH,
va_end(ap); dest, destid, src, srcid);
ret = scratch->ops->wait_request(scratch->data, req); if (ret)
return ret; return ret;
return scratch->ops->wait_request(scratch->data, req);
} }
int aml_scratch_async_push(struct aml_scratch *scratch, int aml_scratch_async_push(struct aml_scratch *scratch,
struct aml_scratch_request **req, ...) struct aml_scratch_request **req,
struct aml_layout **dest, int *destid,
struct aml_layout *src, int srcid)
{ {
assert(scratch != NULL); if (scratch == NULL || dest == NULL || destid == NULL
assert(req != NULL); || src == NULL)
va_list ap; return -AML_EINVAL;
int ret;
va_start(ap, req); return scratch->ops->create_request(scratch->data, req,
ret = scratch->ops->create_request(scratch->data, req, AML_SCRATCH_REQUEST_TYPE_PUSH,
AML_SCRATCH_REQUEST_TYPE_PUSH, ap); dest, destid, src, srcid);
va_end(ap);
return ret;
} }
int aml_scratch_cancel(struct aml_scratch *scratch, int aml_scratch_cancel(struct aml_scratch *scratch,
struct aml_scratch_request *req) struct aml_scratch_request *req)
{ {
assert(scratch != NULL); if (scratch == NULL || req == NULL)
assert(req != NULL); return -AML_EINVAL;
return scratch->ops->destroy_request(scratch->data, req); return scratch->ops->destroy_request(scratch->data, req);
} }
int aml_scratch_wait(struct aml_scratch *scratch, int aml_scratch_wait(struct aml_scratch *scratch,
struct aml_scratch_request *req) struct aml_scratch_request *req)
{ {
assert(scratch != NULL); if (scratch == NULL || req == NULL)
assert(req != NULL); return -AML_EINVAL;
return scratch->ops->wait_request(scratch->data, req); return scratch->ops->wait_request(scratch->data, req);
} }
void *aml_scratch_baseptr(const struct aml_scratch *scratch)
{
assert(scratch != NULL);
return scratch->ops->baseptr(scratch->data);
}
int aml_scratch_release(struct aml_scratch *scratch, int scratchid) int aml_scratch_release(struct aml_scratch *scratch, int scratchid)
{ {
assert(scratch != NULL); if (scratch == NULL)
return -AML_EINVAL;
return scratch->ops->release(scratch->data, scratchid); return scratch->ops->release(scratch->data, scratchid);
} }
...@@ -27,31 +27,23 @@ ...@@ -27,31 +27,23 @@
******************************************************************************/ ******************************************************************************/
int aml_scratch_request_seq_init(struct aml_scratch_request_seq *req, int type, int aml_scratch_request_seq_init(struct aml_scratch_request_seq *req, int type,
struct aml_tiling *t, void *dstptr, int dstid, struct aml_layout *dest, int destid,
void *srcptr, int srcid) struct aml_layout *src, int srcid)
{ {
assert(req != NULL); assert(req != NULL);
void *dp, *sp;
size_t size;
req->type = type; req->type = type;
req->tiling = t; req->src = src;
req->srcid = srcid; req->srcid = srcid;
req->dstid = dstid; req->dst = dest;
dp = aml_tiling_tilestart(req->tiling, dstptr, dstid); req->dstid = destid;
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;
} }
...@@ -75,11 +67,11 @@ struct aml_scratch_seq_ops aml_scratch_seq_inner_ops = { ...@@ -75,11 +67,11 @@ struct aml_scratch_seq_ops aml_scratch_seq_inner_ops = {
* Public API * Public API
******************************************************************************/ ******************************************************************************/
/* TODO: not thread-safe */
int aml_scratch_seq_create_request(struct aml_scratch_data *d, int aml_scratch_seq_create_request(struct aml_scratch_data *d,
struct aml_scratch_request **r, struct aml_scratch_request **r,
int type, va_list ap) int type,
struct aml_layout **dest, int *destid,
struct aml_layout *src, int srcid)
{ {
assert(d != NULL); assert(d != NULL);
assert(r != NULL); assert(r != NULL);
...@@ -92,45 +84,24 @@ int aml_scratch_seq_create_request(struct aml_scratch_data *d, ...@@ -92,45 +84,24 @@ int aml_scratch_seq_create_request(struct aml_scratch_data *d,
req = aml_vector_add(scratch->data.requests); req = aml_vector_add(scratch->data.requests);
/* init the request */ /* init the request */
if (type == AML_SCRATCH_REQUEST_TYPE_PUSH) { if (type == AML_SCRATCH_REQUEST_TYPE_PUSH) {
int scratchid;
int *srcid;
void *srcptr;
void *scratchptr;
srcptr = va_arg(ap, void *);
srcid = va_arg(ap, int *);
scratchptr = va_arg(ap, void *);
scratchid = va_arg(ap, int);
/* find destination tile */ /* find destination tile */
int *slot = aml_vector_get(scratch->data.tilemap, scratchid); int *slot = aml_vector_get(scratch->data.tilemap, srcid);
assert(slot != NULL); assert(slot != NULL);
*srcid = *slot; *destid = *slot;
*dest = aml_tiling_index_linear(scratch->data.src_tiling,
*destid);
/* init request */ /* init request */
aml_scratch_request_seq_init(req, type, aml_scratch_request_seq_init(req, type, *dest, *destid,
scratch->data.tiling, src, srcid);
srcptr, *srcid,
scratchptr, scratchid);
} else if (type == AML_SCRATCH_REQUEST_TYPE_PULL) { } else if (type == AML_SCRATCH_REQUEST_TYPE_PULL) {
int *scratchid;
int srcid;
void *srcptr;
void *scratchptr;
int slot, *tile; int slot, *tile;
scratchptr = va_arg(ap, void *);
scratchid = va_arg(ap, int *);
srcptr = va_arg(ap, void *);
srcid = va_arg(ap, int);
/* find destination tile /* find destination tile
* We don't use add here because adding a tile means allocating * We don't use add here because adding a tile means allocating
* new tiles on the sch_area too. */ * new tiles on the sch_area too. */
/* TODO: this is kind of a bug: we reuse a tile, instead of
* creating a no-op request
*/
slot = aml_vector_find(scratch->data.tilemap, srcid); slot = aml_vector_find(scratch->data.tilemap, srcid);
if (slot == -1) { if (slot == -1) {
slot = aml_vector_find(scratch->data.tilemap, -1); slot = aml_vector_find(scratch->data.tilemap, -1);
...@@ -141,12 +112,13 @@ int aml_scratch_seq_create_request(struct aml_scratch_data *d, ...@@ -141,12 +112,13 @@ int aml_scratch_seq_create_request(struct aml_scratch_data *d,
type = AML_SCRATCH_REQUEST_TYPE_NOOP; type = AML_SCRATCH_REQUEST_TYPE_NOOP;
/* save the key */ /* save the key */
*scratchid = slot; *destid = slot;
*dest = aml_tiling_index_linear(scratch->data.scratch_tiling,
slot);
/* init request */ /* init request */
aml_scratch_request_seq_init(req, type, scratch->data.tiling, aml_scratch_request_seq_init(req, type, *dest, *destid,
scratchptr, *scratchid, src, srcid);
srcptr, srcid);
} }
pthread_mutex_unlock(&scratch->data.lock); pthread_mutex_unlock(&scratch->data.lock);
if (req->type != AML_SCRATCH_REQUEST_TYPE_NOOP) if (req->type != AML_SCRATCH_REQUEST_TYPE_NOOP)
...@@ -210,15 +182,6 @@ int aml_scratch_seq_wait_request(struct aml_scratch_data *d, ...@@ -210,15 +182,6 @@ int aml_scratch_seq_wait_request(struct aml_scratch_data *d,
return 0; return 0;
} }
void *aml_scratch_seq_baseptr(const struct aml_scratch_data *d)
{
assert(d != NULL);
const struct aml_scratch_seq *scratch =
(const struct aml_scratch_seq *)d;
return scratch->data.sch_ptr;
}
int aml_scratch_seq_release(struct aml_scratch_data *d, int scratchid) int aml_scratch_seq_release(struct aml_scratch_data *d, int scratchid)
{ {
assert(d != NULL); assert(d != NULL);
...@@ -237,7 +200,6 @@ struct aml_scratch_ops aml_scratch_seq_ops = { ...@@ -237,7 +200,6 @@ struct aml_scratch_ops aml_scratch_seq_ops = {
aml_scratch_seq_create_request, aml_scratch_seq_create_request,
aml_scratch_seq_destroy_request, aml_scratch_seq_destroy_request,
aml_scratch_seq_wait_request, aml_scratch_seq_wait_request,
aml_scratch_seq_baseptr,
aml_scratch_seq_release, aml_scratch_seq_release,
}; };
...@@ -246,17 +208,14 @@ struct aml_scratch_ops aml_scratch_seq_ops = { ...@@ -246,17 +208,14 @@ struct aml_scratch_ops aml_scratch_seq_ops = {
******************************************************************************/ ******************************************************************************/
int aml_scratch_seq_create(struct aml_scratch **scratch, int aml_scratch_seq_create(struct aml_scratch **scratch,
struct aml_area *scratch_area, struct aml_dma *dma, struct aml_tiling *src_tiling,
struct aml_area *src_area, struct aml_tiling *scratch_tiling, size_t nbreqs)
struct aml_dma *dma, struct aml_tiling *tiling,
size_t nbtiles, size_t nbreqs)
{ {
struct aml_scratch *ret = NULL; struct aml_scratch *ret = NULL;
struct aml_scratch_seq *s; struct aml_scratch_seq *s;
if (scratch == NULL if (scratch == NULL || dma == NULL || src_tiling == NULL
|| scratch_area == NULL || src_area == NULL || scratch_tiling == NULL)
|| dma == NULL || tiling == NULL)
return -AML_EINVAL; return -AML_EINVAL;
*scratch = NULL; *scratch = NULL;
...@@ -271,10 +230,9 @@ int aml_scratch_seq_create(struct aml_scratch **scratch, ...@@ -271,10 +230,9 @@ int aml_scratch_seq_create(struct aml_scratch **scratch,
s = (struct aml_scratch_seq *)ret->data; s = (struct aml_scratch_seq *)ret->data;
s->ops = aml_scratch_seq_inner_ops; s->ops = aml_scratch_seq_inner_ops;
s->data.sch_area = scratch_area;
s->data.src_area = src_area;
s->data.dma = dma; s->data.dma = dma;
s->data.tiling = tiling; s->data.src_tiling = src_tiling;
s->data.scratch_tiling = scratch_tiling;
/* allocate request array */ /* allocate request array */
aml_vector_create(&s->data.requests, nbreqs, aml_vector_create(&s->data.requests, nbreqs,
...@@ -282,14 +240,9 @@ int aml_scratch_seq_create(struct aml_scratch **scratch, ...@@ -282,14 +240,9 @@ int aml_scratch_seq_create(struct aml_scratch **scratch,
offsetof(struct aml_scratch_request_seq, type), offsetof(struct aml_scratch_request_seq, type),
AML_SCRATCH_REQUEST_TYPE_INVALID); AML_SCRATCH_REQUEST_TYPE_INVALID);
/* s init */ /* "hashmap for src to scratch tiles */
size_t nbtiles = aml_tiling_ntiles(scratch_tiling);
aml_vector_create(&s->data.tilemap, nbtiles, sizeof(int), 0, -1); aml_vector_create(&s->data.tilemap, nbtiles, sizeof(int), 0, -1);
size_t tilesize = aml_tiling_tilesize(s->data.tiling, 0);
s->data.scratch_size = nbtiles * tilesize;
s->data.sch_ptr = aml_area_mmap(s->data.sch_area,
s->data.scratch_size,
NULL);
pthread_mutex_init(&s->data.lock, NULL); pthread_mutex_init(&s->data.lock, NULL);
*scratch = ret; *scratch = ret;
...@@ -311,9 +264,6 @@ void aml_scratch_seq_destroy(struct aml_scratch **scratch) ...@@ -311,9 +264,6 @@ void aml_scratch_seq_destroy(struct aml_scratch **scratch)
inner = (struct aml_scratch_seq *)s->data; inner = (struct aml_scratch_seq *)s->data;
aml_vector_destroy(&inner->data.requests); aml_vector_destroy(&inner->data.requests);
aml_vector_destroy(&inner->data.tilemap); aml_vector_destroy(&inner->data.tilemap);
aml_area_munmap(inner->data.sch_area,
inner->data.sch_ptr,
inner->data.scratch_size);
pthread_mutex_destroy(&inner->data.lock); pthread_mutex_destroy(&inner->data.lock);
free(s); free(s);
*scratch = NULL; *scratch = NULL;
......
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