Commit e02e5a22 authored by Swann Perarnau's avatar Swann Perarnau

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;
#define AML_SCRATCH_REQUEST_TYPE_PUSH 0
/* Pull from regular memory to the scratchpad. */
#define AML_SCRATCH_REQUEST_TYPE_PULL 1
/* No-op/empty request */
#define AML_SCRATCH_REQUEST_TYPE_NOOP 2
struct aml_scratch_ops {
int (*create_request)(struct aml_scratch_data *scratch,
......
......@@ -12,7 +12,7 @@
#include <assert.h>
/*******************************************************************************
* Sequential scratchpad
* Parallel scratchpad
* The scratch itself is organized into several different components
* - request types: push and pull
* - implementation of the request
......@@ -25,11 +25,13 @@
******************************************************************************/
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)
{
assert(req != NULL);
req->type = type;
req->scratch = scratch;
req->srcptr = srcptr;
req->srcid = srcid;
req->dstptr = dstptr;
......@@ -98,7 +100,7 @@ int aml_scratch_par_create_request(struct aml_scratch_data *d,
*srcid = *slot;
/* init request */
aml_scratch_request_par_init(req, type, srcptr, *srcid,
aml_scratch_request_par_init(req, type, scratch, srcptr, *srcid,
scratchptr, scratchid);
}
else if(type == AML_SCRATCH_REQUEST_TYPE_PULL)
......@@ -116,25 +118,29 @@ int aml_scratch_par_create_request(struct aml_scratch_data *d,
/* find destination tile
* We don't use add here because adding a tile means allocating
* 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);
if(slot == -1)
{
slot = aml_vector_find(&scratch->data.tilemap, -1);
assert(slot != -1);
int *tile = aml_vector_get(&scratch->data.tilemap, slot);
*tile = srcid;
assert(slot != -1);
int *tile = aml_vector_get(&scratch->data.tilemap, slot);
*tile = srcid;
}
else
type = AML_SCRATCH_REQUEST_TYPE_NOOP;
/* save the key */
*scratchid = slot;
/* init request */
aml_scratch_request_par_init(req, type, scratchptr, *scratchid,
aml_scratch_request_par_init(req, type, scratch,
scratchptr, *scratchid,
srcptr, srcid);
}
pthread_mutex_unlock(&scratch->data.lock);
/* thread creation */
req->scratch = scratch;
pthread_create(&req->thread, NULL, scratch->ops.do_thread, req);
if(req->type != AML_SCRATCH_REQUEST_TYPE_NOOP)
pthread_create(&req->thread, NULL, scratch->ops.do_thread, req);
*r = (struct aml_scratch_request *)req;
return 0;
}
......@@ -151,8 +157,11 @@ int aml_scratch_par_destroy_request(struct aml_scratch_data *d,
(struct aml_scratch_request_par *)r;
int *tile;
pthread_cancel(req->thread);
pthread_join(req->thread, NULL);
if(req->type != AML_SCRATCH_REQUEST_TYPE_NOOP)
{
pthread_cancel(req->thread);
pthread_join(req->thread, NULL);
}
aml_scratch_request_par_destroy(req);
......@@ -179,7 +188,8 @@ int aml_scratch_par_wait_request(struct aml_scratch_data *d,
int *tile;
/* 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 */
aml_scratch_request_par_destroy(req);
......
......@@ -100,7 +100,8 @@ int aml_scratch_seq_create_request(struct aml_scratch_data *d,
*srcid = *slot;
/* init request */
aml_scratch_request_seq_init(req, type, scratch->data.tiling,
aml_scratch_request_seq_init(req, type,
scratch->data.tiling,
srcptr, *srcid,
scratchptr, scratchid);
}
......@@ -124,20 +125,26 @@ int aml_scratch_seq_create_request(struct aml_scratch_data *d,
*/
int slot = aml_vector_find(&scratch->data.tilemap, srcid);
if(slot == -1)
{
slot = aml_vector_find(&scratch->data.tilemap, -1);
assert(slot != -1);
int *tile = aml_vector_get(&scratch->data.tilemap, slot);
*tile = srcid;
assert(slot != -1);
int *tile = aml_vector_get(&scratch->data.tilemap, slot);
*tile = srcid;
}
else
type = AML_SCRATCH_REQUEST_TYPE_NOOP;
/* save the key */
*scratchid = slot;
/* init request */
aml_scratch_request_seq_init(req, type,
scratch->data.tiling,
aml_scratch_request_seq_init(req, type, scratch->data.tiling,
scratchptr, *scratchid,
srcptr, srcid);
}
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;
return 0;
......@@ -155,7 +162,8 @@ int aml_scratch_seq_destroy_request(struct aml_scratch_data *d,
(struct aml_scratch_request_seq *)r;
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);
/* destroy removes the tile from the scratch */
......@@ -181,7 +189,8 @@ int aml_scratch_seq_wait_request(struct aml_scratch_data *d,
int *tile;
/* 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 */
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