Commit e02e5a22 authored by Swann Perarnau's avatar Swann Perarnau
Browse files

Merge branch 'no-op-requests' into 'master'

Add No-op request capability to Scratch

Closes #18

See merge request !31
parents 998c1db7 5370c068
Pipeline #6868 passed with stage
in 9 minutes and 40 seconds
...@@ -1406,6 +1406,8 @@ struct aml_scratch_data; ...@@ -1406,6 +1406,8 @@ struct aml_scratch_data;
#define AML_SCRATCH_REQUEST_TYPE_PUSH 0 #define AML_SCRATCH_REQUEST_TYPE_PUSH 0
/* Pull from regular memory to the scratchpad. */ /* Pull from regular memory to the scratchpad. */
#define AML_SCRATCH_REQUEST_TYPE_PULL 1 #define AML_SCRATCH_REQUEST_TYPE_PULL 1
/* No-op/empty request */
#define AML_SCRATCH_REQUEST_TYPE_NOOP 2
struct aml_scratch_ops { struct aml_scratch_ops {
int (*create_request)(struct aml_scratch_data *scratch, int (*create_request)(struct aml_scratch_data *scratch,
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include <assert.h> #include <assert.h>
/******************************************************************************* /*******************************************************************************
* Sequential scratchpad * Parallel scratchpad
* The scratch itself is organized into several different components * The scratch itself is organized into several different components
* - request types: push and pull * - request types: push and pull
* - implementation of the request * - implementation of the request
...@@ -25,11 +25,13 @@ ...@@ -25,11 +25,13 @@
******************************************************************************/ ******************************************************************************/
int aml_scratch_request_par_init(struct aml_scratch_request_par *req, int type, int aml_scratch_request_par_init(struct aml_scratch_request_par *req, int type,
struct aml_scratch_par *scratch,
void *dstptr, int dstid, void *srcptr, int srcid) void *dstptr, int dstid, void *srcptr, int srcid)
{ {
assert(req != NULL); assert(req != NULL);
req->type = type; req->type = type;
req->scratch = scratch;
req->srcptr = srcptr; req->srcptr = srcptr;
req->srcid = srcid; req->srcid = srcid;
req->dstptr = dstptr; req->dstptr = dstptr;
...@@ -98,7 +100,7 @@ int aml_scratch_par_create_request(struct aml_scratch_data *d, ...@@ -98,7 +100,7 @@ int aml_scratch_par_create_request(struct aml_scratch_data *d,
*srcid = *slot; *srcid = *slot;
/* init request */ /* init request */
aml_scratch_request_par_init(req, type, srcptr, *srcid, aml_scratch_request_par_init(req, type, scratch, srcptr, *srcid,
scratchptr, scratchid); scratchptr, scratchid);
} }
else if(type == AML_SCRATCH_REQUEST_TYPE_PULL) else if(type == AML_SCRATCH_REQUEST_TYPE_PULL)
...@@ -116,25 +118,29 @@ int aml_scratch_par_create_request(struct aml_scratch_data *d, ...@@ -116,25 +118,29 @@ int aml_scratch_par_create_request(struct aml_scratch_data *d,
/* 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
*/
int slot = aml_vector_find(&scratch->data.tilemap, srcid); int 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);
assert(slot != -1); assert(slot != -1);
int *tile = aml_vector_get(&scratch->data.tilemap, slot); int *tile = aml_vector_get(&scratch->data.tilemap, slot);
*tile = srcid; *tile = srcid;
}
else
type = AML_SCRATCH_REQUEST_TYPE_NOOP;
/* save the key */
*scratchid = slot; *scratchid = slot;
/* init request */ /* init request */
aml_scratch_request_par_init(req, type, scratchptr, *scratchid, aml_scratch_request_par_init(req, type, scratch,
scratchptr, *scratchid,
srcptr, srcid); srcptr, srcid);
} }
pthread_mutex_unlock(&scratch->data.lock); pthread_mutex_unlock(&scratch->data.lock);
/* thread creation */ /* thread creation */
req->scratch = scratch; if(req->type != AML_SCRATCH_REQUEST_TYPE_NOOP)
pthread_create(&req->thread, NULL, scratch->ops.do_thread, req); pthread_create(&req->thread, NULL, scratch->ops.do_thread, req);
*r = (struct aml_scratch_request *)req; *r = (struct aml_scratch_request *)req;
return 0; return 0;
} }
...@@ -151,8 +157,11 @@ int aml_scratch_par_destroy_request(struct aml_scratch_data *d, ...@@ -151,8 +157,11 @@ int aml_scratch_par_destroy_request(struct aml_scratch_data *d,
(struct aml_scratch_request_par *)r; (struct aml_scratch_request_par *)r;
int *tile; int *tile;
pthread_cancel(req->thread); if(req->type != AML_SCRATCH_REQUEST_TYPE_NOOP)
pthread_join(req->thread, NULL); {
pthread_cancel(req->thread);
pthread_join(req->thread, NULL);
}
aml_scratch_request_par_destroy(req); aml_scratch_request_par_destroy(req);
...@@ -179,7 +188,8 @@ int aml_scratch_par_wait_request(struct aml_scratch_data *d, ...@@ -179,7 +188,8 @@ int aml_scratch_par_wait_request(struct aml_scratch_data *d,
int *tile; int *tile;
/* wait for completion of the request */ /* wait for completion of the request */
pthread_join(req->thread, NULL); if(req->type != AML_SCRATCH_REQUEST_TYPE_NOOP)
pthread_join(req->thread, NULL);
/* cleanup a completed request. In case of push, free up the tile */ /* cleanup a completed request. In case of push, free up the tile */
aml_scratch_request_par_destroy(req); aml_scratch_request_par_destroy(req);
......
...@@ -100,7 +100,8 @@ int aml_scratch_seq_create_request(struct aml_scratch_data *d, ...@@ -100,7 +100,8 @@ int aml_scratch_seq_create_request(struct aml_scratch_data *d,
*srcid = *slot; *srcid = *slot;
/* init request */ /* init request */
aml_scratch_request_seq_init(req, type, scratch->data.tiling, aml_scratch_request_seq_init(req, type,
scratch->data.tiling,
srcptr, *srcid, srcptr, *srcid,
scratchptr, scratchid); scratchptr, scratchid);
} }
...@@ -124,20 +125,26 @@ int aml_scratch_seq_create_request(struct aml_scratch_data *d, ...@@ -124,20 +125,26 @@ int aml_scratch_seq_create_request(struct aml_scratch_data *d,
*/ */
int slot = aml_vector_find(&scratch->data.tilemap, srcid); int 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);
assert(slot != -1); assert(slot != -1);
int *tile = aml_vector_get(&scratch->data.tilemap, slot); int *tile = aml_vector_get(&scratch->data.tilemap, slot);
*tile = srcid; *tile = srcid;
}
else
type = AML_SCRATCH_REQUEST_TYPE_NOOP;
/* save the key */
*scratchid = slot; *scratchid = slot;
/* init request */ /* init request */
aml_scratch_request_seq_init(req, type, aml_scratch_request_seq_init(req, type, scratch->data.tiling,
scratch->data.tiling,
scratchptr, *scratchid, scratchptr, *scratchid,
srcptr, srcid); srcptr, srcid);
} }
pthread_mutex_unlock(&scratch->data.lock); pthread_mutex_unlock(&scratch->data.lock);
scratch->ops.doit(&scratch->data, req); if(req->type != AML_SCRATCH_REQUEST_TYPE_NOOP)
scratch->ops.doit(&scratch->data, req);
*r = (struct aml_scratch_request *)req; *r = (struct aml_scratch_request *)req;
return 0; return 0;
...@@ -155,7 +162,8 @@ int aml_scratch_seq_destroy_request(struct aml_scratch_data *d, ...@@ -155,7 +162,8 @@ int aml_scratch_seq_destroy_request(struct aml_scratch_data *d,
(struct aml_scratch_request_seq *)r; (struct aml_scratch_request_seq *)r;
int *tile; int *tile;
aml_dma_cancel(scratch->data.dma, req->dma_req); if(req->type != AML_SCRATCH_REQUEST_TYPE_NOOP)
aml_dma_cancel(scratch->data.dma, req->dma_req);
aml_scratch_request_seq_destroy(req); aml_scratch_request_seq_destroy(req);
/* destroy removes the tile from the scratch */ /* destroy removes the tile from the scratch */
...@@ -181,7 +189,8 @@ int aml_scratch_seq_wait_request(struct aml_scratch_data *d, ...@@ -181,7 +189,8 @@ int aml_scratch_seq_wait_request(struct aml_scratch_data *d,
int *tile; int *tile;
/* wait for completion of the request */ /* wait for completion of the request */
aml_dma_wait(scratch->data.dma, req->dma_req); if(req->type != AML_SCRATCH_REQUEST_TYPE_NOOP)
aml_dma_wait(scratch->data.dma, req->dma_req);
/* cleanup a completed request. In case of push, free up the tile */ /* cleanup a completed request. In case of push, free up the tile */
aml_scratch_request_seq_destroy(req); aml_scratch_request_seq_destroy(req);
......
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