Commit 27460a5f authored by Swann Perarnau's avatar Swann Perarnau

Merge branch 'better-unit-tests' into 'master'

Improve speed and exhaustiveness of the unit tests.

See merge request !74
parents 3eb5ca16 f43d2d6d
Pipeline #8312 passed with stages
in 6 minutes and 16 seconds
...@@ -877,7 +877,7 @@ struct aml_dma_ops { ...@@ -877,7 +877,7 @@ struct aml_dma_ops {
* @return an AML error code. * @return an AML error code.
**/ **/
int (*destroy_request)(struct aml_dma_data *dma, int (*destroy_request)(struct aml_dma_data *dma,
struct aml_dma_request *req); struct aml_dma_request **req);
/** /**
* Wait for termination of a data movement and destroy the request * Wait for termination of a data movement and destroy the request
...@@ -888,7 +888,7 @@ struct aml_dma_ops { ...@@ -888,7 +888,7 @@ struct aml_dma_ops {
* @return an AML error code. * @return an AML error code.
**/ **/
int (*wait_request)(struct aml_dma_data *dma, int (*wait_request)(struct aml_dma_data *dma,
struct aml_dma_request *req); struct aml_dma_request **req);
}; };
/** /**
...@@ -931,7 +931,7 @@ int aml_dma_async_copy(struct aml_dma *dma, struct aml_dma_request **req, ...@@ -931,7 +931,7 @@ int aml_dma_async_copy(struct aml_dma *dma, struct aml_dma_request **req,
* @param req: a DMA request obtained using aml_dma_async_*() calls. * @param req: a DMA request obtained using aml_dma_async_*() calls.
* @return 0 if successful; an error code otherwise. * @return 0 if successful; an error code otherwise.
**/ **/
int aml_dma_wait(struct aml_dma *dma, struct aml_dma_request *req); int aml_dma_wait(struct aml_dma *dma, struct aml_dma_request **req);
/** /**
* Tears down an asynchronous DMA request before it completes. * Tears down an asynchronous DMA request before it completes.
...@@ -939,7 +939,7 @@ int aml_dma_wait(struct aml_dma *dma, struct aml_dma_request *req); ...@@ -939,7 +939,7 @@ int aml_dma_wait(struct aml_dma *dma, struct aml_dma_request *req);
* @param req: a DMA request obtained using aml_dma_async_*() calls. * @param req: a DMA request obtained using aml_dma_async_*() calls.
* @return 0 if successful; an error code otherwise. * @return 0 if successful; an error code otherwise.
**/ **/
int aml_dma_cancel(struct aml_dma *dma, struct aml_dma_request *req); int aml_dma_cancel(struct aml_dma *dma, struct aml_dma_request **req);
/** /**
* Generic helper to copy from one layout to another. * Generic helper to copy from one layout to another.
......
...@@ -50,7 +50,7 @@ struct aml_dma_linux_par_request_data { ...@@ -50,7 +50,7 @@ struct aml_dma_linux_par_request_data {
pthread_t thread; pthread_t thread;
}; };
/** Inside of a parallel request for linux movement. **/ /** Inside of a parallel dma for linux movement. **/
struct aml_dma_linux_par_data { struct aml_dma_linux_par_data {
struct aml_vector *requests; struct aml_vector *requests;
pthread_mutex_t lock; pthread_mutex_t lock;
......
...@@ -27,9 +27,9 @@ ...@@ -27,9 +27,9 @@
/** The type used to store bits **/ /** The type used to store bits **/
#define AML_BITMAP_TYPE unsigned long #define AML_BITMAP_TYPE unsigned long
/** The number of basic type elements used to store bits **/ /** The number of basic type elements used to store bits **/
#define AML_BITMAP_SIZE (AML_BITMAP_BYTES/sizeof(AML_BITMAP_TYPE)) #define AML_BITMAP_SIZE ((int)(AML_BITMAP_BYTES/sizeof(AML_BITMAP_TYPE)))
/** The number of bits held in each basic type element **/ /** The number of bits held in each basic type element **/
#define AML_BITMAP_NBITS (8 * sizeof(AML_BITMAP_TYPE)) #define AML_BITMAP_NBITS ((int)(8 * sizeof(AML_BITMAP_TYPE)))
/** /**
* aml_bitmap is a static array of elements wrapped in a structure. * aml_bitmap is a static array of elements wrapped in a structure.
...@@ -50,13 +50,13 @@ void aml_bitmap_copy(struct aml_bitmap *dst, const struct aml_bitmap *src); ...@@ -50,13 +50,13 @@ void aml_bitmap_copy(struct aml_bitmap *dst, const struct aml_bitmap *src);
* Empty a bitmap with all bits cleared. * Empty a bitmap with all bits cleared.
* @param bitmap: The bitmap to set. * @param bitmap: The bitmap to set.
**/ **/
void aml_bitmap_zero(struct aml_bitmap *bitmap); int aml_bitmap_zero(struct aml_bitmap *bitmap);
/** /**
* Fill a bitmap with all bits set. * Fill a bitmap with all bits set.
* @param bitmap: The bitmap to set. * @param bitmap: The bitmap to set.
**/ **/
void aml_bitmap_fill(struct aml_bitmap *bitmap); int aml_bitmap_fill(struct aml_bitmap *bitmap);
/** /**
* Check whether a bit in bitmap is set. * Check whether a bit in bitmap is set.
...@@ -135,7 +135,7 @@ int aml_bitmap_clear_range(struct aml_bitmap *bitmap, ...@@ -135,7 +135,7 @@ int aml_bitmap_clear_range(struct aml_bitmap *bitmap,
* @param bitmap: The bitmap to inspect. * @param bitmap: The bitmap to inspect.
* @return The number of bits set in bitmap. * @return The number of bits set in bitmap.
**/ **/
unsigned long aml_bitmap_nset(const struct aml_bitmap *bitmap); int aml_bitmap_nset(const struct aml_bitmap *bitmap);
/** /**
* Copy a unsigned long array used as a bitmap into an actual bitmap. * Copy a unsigned long array used as a bitmap into an actual bitmap.
......
...@@ -88,7 +88,9 @@ int aml_dma_copy(struct aml_dma *dma, int type, ...) ...@@ -88,7 +88,9 @@ int aml_dma_copy(struct aml_dma *dma, int type, ...)
va_start(ap, type); va_start(ap, type);
ret = dma->ops->create_request(dma->data, &req, type, ap); ret = dma->ops->create_request(dma->data, &req, type, ap);
va_end(ap); va_end(ap);
ret = dma->ops->wait_request(dma->data, req); if (ret != AML_SUCCESS)
return ret;
ret = dma->ops->wait_request(dma->data, &req);
return ret; return ret;
} }
...@@ -107,16 +109,16 @@ int aml_dma_async_copy(struct aml_dma *dma, struct aml_dma_request **req, ...@@ -107,16 +109,16 @@ int aml_dma_async_copy(struct aml_dma *dma, struct aml_dma_request **req,
return ret; return ret;
} }
int aml_dma_cancel(struct aml_dma *dma, struct aml_dma_request *req) int aml_dma_cancel(struct aml_dma *dma, struct aml_dma_request **req)
{ {
assert(dma != NULL); if (dma == NULL || req == NULL)
assert(req != NULL); return -AML_EINVAL;
return dma->ops->destroy_request(dma->data, req); return dma->ops->destroy_request(dma->data, req);
} }
int aml_dma_wait(struct aml_dma *dma, struct aml_dma_request *req) int aml_dma_wait(struct aml_dma *dma, struct aml_dma_request **req)
{ {
assert(dma != NULL); if (dma == NULL || req == NULL)
assert(req != NULL); return -AML_EINVAL;
return dma->ops->wait_request(dma->data, req); return dma->ops->wait_request(dma->data, req);
} }
...@@ -68,6 +68,7 @@ void *aml_dma_linux_par_do_thread(void *arg) ...@@ -68,6 +68,7 @@ void *aml_dma_linux_par_do_thread(void *arg)
struct aml_dma_linux_par_request_data *req = struct aml_dma_linux_par_request_data *req =
(struct aml_dma_linux_par_request_data *)arg; (struct aml_dma_linux_par_request_data *)arg;
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
if (req->type != AML_DMA_REQUEST_TYPE_INVALID) if (req->type != AML_DMA_REQUEST_TYPE_INVALID)
aml_copy_layout_generic(req->dest, req->src); aml_copy_layout_generic(req->dest, req->src);
return NULL; return NULL;
...@@ -91,6 +92,7 @@ int aml_dma_linux_par_create_request(struct aml_dma_data *d, ...@@ -91,6 +92,7 @@ int aml_dma_linux_par_create_request(struct aml_dma_data *d,
(struct aml_dma_linux_par *)d; (struct aml_dma_linux_par *)d;
struct aml_dma_request_linux_par *ret; struct aml_dma_request_linux_par *ret;
struct aml_dma_linux_par_request_data *req; struct aml_dma_linux_par_request_data *req;
int err = AML_SUCCESS;
pthread_mutex_lock(&dma->data.lock); pthread_mutex_lock(&dma->data.lock);
req = aml_vector_add(dma->data.requests); req = aml_vector_add(dma->data.requests);
...@@ -101,6 +103,10 @@ int aml_dma_linux_par_create_request(struct aml_dma_data *d, ...@@ -101,6 +103,10 @@ int aml_dma_linux_par_create_request(struct aml_dma_data *d,
dl = va_arg(ap, struct aml_layout *); dl = va_arg(ap, struct aml_layout *);
sl = va_arg(ap, struct aml_layout *); sl = va_arg(ap, struct aml_layout *);
if (dl == NULL || sl == NULL) {
err = -AML_EINVAL;
goto unlock;
}
aml_dma_linux_par_request_data_init(req, aml_dma_linux_par_request_data_init(req,
AML_DMA_REQUEST_TYPE_LAYOUT, AML_DMA_REQUEST_TYPE_LAYOUT,
dl, sl); dl, sl);
...@@ -112,17 +118,21 @@ int aml_dma_linux_par_create_request(struct aml_dma_data *d, ...@@ -112,17 +118,21 @@ int aml_dma_linux_par_create_request(struct aml_dma_data *d,
dp = va_arg(ap, void *); dp = va_arg(ap, void *);
sp = va_arg(ap, void *); sp = va_arg(ap, void *);
sz = va_arg(ap, size_t); 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 /* simple 1D layout, none of the parameters really matter, as
* long as the copy generates a single memcpy. * long as the copy generates a single memcpy.
*/ */
aml_layout_dense_create(&dl, dp, 0, sizeof(size_t), 1, aml_layout_dense_create(&dl, dp, 0, 1, 1, &sz, NULL, NULL);
&sz, NULL, NULL); aml_layout_dense_create(&sl, sp, 0, 1, 1, &sz, NULL, NULL);
aml_layout_dense_create(&sl, sp, 0, sizeof(size_t), 1,
&sz, NULL, NULL);
aml_dma_linux_par_request_data_init(req, aml_dma_linux_par_request_data_init(req,
AML_DMA_REQUEST_TYPE_PTR, AML_DMA_REQUEST_TYPE_PTR,
dl, sl); dl, sl);
} } else
err = -AML_EINVAL;
unlock:
pthread_mutex_unlock(&dma->data.lock); pthread_mutex_unlock(&dma->data.lock);
if (req->type != AML_DMA_REQUEST_TYPE_INVALID) { if (req->type != AML_DMA_REQUEST_TYPE_INVALID) {
int uuid = aml_vector_getid(dma->data.requests, req); int uuid = aml_vector_getid(dma->data.requests, req);
...@@ -131,21 +141,23 @@ int aml_dma_linux_par_create_request(struct aml_dma_data *d, ...@@ -131,21 +141,23 @@ int aml_dma_linux_par_create_request(struct aml_dma_data *d,
aml_dma_request_linux_par_create(&ret, uuid); aml_dma_request_linux_par_create(&ret, uuid);
*r = (struct aml_dma_request *)ret; *r = (struct aml_dma_request *)ret;
} }
return 0; return err;
} }
int aml_dma_linux_par_destroy_request(struct aml_dma_data *d, int aml_dma_linux_par_destroy_request(struct aml_dma_data *d,
struct aml_dma_request *r) struct aml_dma_request **r)
{ {
assert(d != NULL); assert(d != NULL);
assert(r != NULL); assert(r != NULL);
struct aml_dma_linux_par *dma = struct aml_dma_linux_par *dma =
(struct aml_dma_linux_par *)d; (struct aml_dma_linux_par *)d;
struct aml_dma_request_linux_par *req;
struct aml_dma_request_linux_par *req =
(struct aml_dma_request_linux_par *)r;
struct aml_dma_linux_par_request_data *inner_req; struct aml_dma_linux_par_request_data *inner_req;
if (*r == NULL)
return -AML_EINVAL;
req = (struct aml_dma_request_linux_par *)*r;
inner_req = aml_vector_get(dma->data.requests, req->uuid); inner_req = aml_vector_get(dma->data.requests, req->uuid);
if (inner_req == NULL) if (inner_req == NULL)
return -AML_EINVAL; return -AML_EINVAL;
...@@ -154,44 +166,49 @@ int aml_dma_linux_par_destroy_request(struct aml_dma_data *d, ...@@ -154,44 +166,49 @@ int aml_dma_linux_par_destroy_request(struct aml_dma_data *d,
if (inner_req->type != AML_DMA_REQUEST_TYPE_INVALID) { if (inner_req->type != AML_DMA_REQUEST_TYPE_INVALID) {
pthread_cancel(inner_req->thread); pthread_cancel(inner_req->thread);
pthread_join(inner_req->thread, NULL); pthread_join(inner_req->thread, NULL);
if (inner_req->type == AML_DMA_REQUEST_TYPE_PTR) { }
aml_layout_dense_destroy(&inner_req->dest);
aml_layout_dense_destroy(&inner_req->src); if (inner_req->type == AML_DMA_REQUEST_TYPE_PTR) {
} aml_layout_dense_destroy(&inner_req->dest);
aml_layout_dense_destroy(&inner_req->src);
} }
pthread_mutex_lock(&dma->data.lock); pthread_mutex_lock(&dma->data.lock);
aml_vector_remove(dma->data.requests, inner_req); aml_vector_remove(dma->data.requests, inner_req);
pthread_mutex_unlock(&dma->data.lock); pthread_mutex_unlock(&dma->data.lock);
aml_dma_request_linux_par_destroy(&req); aml_dma_request_linux_par_destroy(&req);
*r = NULL;
return 0; return 0;
} }
int aml_dma_linux_par_wait_request(struct aml_dma_data *d, int aml_dma_linux_par_wait_request(struct aml_dma_data *d,
struct aml_dma_request *r) struct aml_dma_request **r)
{ {
assert(d != NULL); assert(d != NULL);
assert(r != NULL); assert(r != NULL);
struct aml_dma_linux_par *dma = (struct aml_dma_linux_par *)d; struct aml_dma_linux_par *dma = (struct aml_dma_linux_par *)d;
struct aml_dma_request_linux_par *req = struct aml_dma_request_linux_par *req;
(struct aml_dma_request_linux_par *)r;
struct aml_dma_linux_par_request_data *inner_req; struct aml_dma_linux_par_request_data *inner_req;
if (*r == NULL)
return -AML_EINVAL;
req = (struct aml_dma_request_linux_par *)*r;
inner_req = aml_vector_get(dma->data.requests, req->uuid); inner_req = aml_vector_get(dma->data.requests, req->uuid);
if (inner_req == NULL) if (inner_req == NULL)
return -AML_EINVAL; return -AML_EINVAL;
if (inner_req->type != AML_DMA_REQUEST_TYPE_INVALID) { if (inner_req->type != AML_DMA_REQUEST_TYPE_INVALID)
pthread_join(inner_req->thread, NULL); pthread_join(inner_req->thread, NULL);
if (inner_req->type == AML_DMA_REQUEST_TYPE_PTR) {
aml_layout_dense_destroy(&inner_req->dest);
aml_layout_dense_destroy(&inner_req->src);
}
}
if (inner_req->type == AML_DMA_REQUEST_TYPE_PTR) {
aml_layout_dense_destroy(&inner_req->dest);
aml_layout_dense_destroy(&inner_req->src);
}
pthread_mutex_lock(&dma->data.lock); pthread_mutex_lock(&dma->data.lock);
aml_vector_remove(dma->data.requests, inner_req); aml_vector_remove(dma->data.requests, inner_req);
pthread_mutex_unlock(&dma->data.lock); pthread_mutex_unlock(&dma->data.lock);
aml_dma_request_linux_par_destroy(&req); aml_dma_request_linux_par_destroy(&req);
*r = NULL;
return 0; return 0;
} }
...@@ -236,22 +253,28 @@ int aml_dma_linux_par_create(struct aml_dma **dma, size_t nbreqs) ...@@ -236,22 +253,28 @@ int aml_dma_linux_par_create(struct aml_dma **dma, size_t nbreqs)
return 0; return 0;
} }
void aml_dma_linux_par_destroy(struct aml_dma **dma) void aml_dma_linux_par_destroy(struct aml_dma **d)
{ {
struct aml_dma *d; struct aml_dma_linux_par *dma;
struct aml_dma_linux_par *l;
if (dma == NULL) if (d == NULL || *d == NULL)
return;
d = *dma;
if (d == NULL)
return; return;
dma = (struct aml_dma_linux_par *)(*d)->data;
assert(d->data != NULL); for (size_t i = 0; i < aml_vector_size(dma->data.requests); i++) {
l = (struct aml_dma_linux_par *)d->data; struct aml_dma_linux_par_request_data *req;
aml_vector_destroy(&l->data.requests);
pthread_mutex_destroy(&l->data.lock); req = aml_vector_get(dma->data.requests, i);
if (req->type != AML_DMA_REQUEST_TYPE_INVALID) {
free(d); pthread_cancel(req->thread);
*dma = NULL; pthread_join(req->thread, NULL);
}
if (req->type == AML_DMA_REQUEST_TYPE_PTR) {
aml_layout_dense_destroy(&req->dest);
aml_layout_dense_destroy(&req->src);
}
}
aml_vector_destroy(&dma->data.requests);
pthread_mutex_destroy(&dma->data.lock);
free(*d);
*d = NULL;
} }
...@@ -90,6 +90,7 @@ int aml_dma_linux_seq_create_request(struct aml_dma_data *d, ...@@ -90,6 +90,7 @@ int aml_dma_linux_seq_create_request(struct aml_dma_data *d,
(struct aml_dma_linux_seq *)d; (struct aml_dma_linux_seq *)d;
struct aml_dma_request_linux_seq *ret; struct aml_dma_request_linux_seq *ret;
struct aml_dma_linux_seq_request_data *req; struct aml_dma_linux_seq_request_data *req;
int err = AML_SUCCESS;
pthread_mutex_lock(&dma->data.lock); pthread_mutex_lock(&dma->data.lock);
req = aml_vector_add(dma->data.requests); req = aml_vector_add(dma->data.requests);
...@@ -100,6 +101,10 @@ int aml_dma_linux_seq_create_request(struct aml_dma_data *d, ...@@ -100,6 +101,10 @@ int aml_dma_linux_seq_create_request(struct aml_dma_data *d,
dl = va_arg(ap, struct aml_layout *); dl = va_arg(ap, struct aml_layout *);
sl = va_arg(ap, struct aml_layout *); sl = va_arg(ap, struct aml_layout *);
if (dl == NULL || sl == NULL) {
err = -AML_EINVAL;
goto unlock;
}
aml_dma_linux_seq_request_data_init(req, aml_dma_linux_seq_request_data_init(req,
AML_DMA_REQUEST_TYPE_LAYOUT, AML_DMA_REQUEST_TYPE_LAYOUT,
dl, sl); dl, sl);
...@@ -111,38 +116,46 @@ int aml_dma_linux_seq_create_request(struct aml_dma_data *d, ...@@ -111,38 +116,46 @@ int aml_dma_linux_seq_create_request(struct aml_dma_data *d,
dp = va_arg(ap, void *); dp = va_arg(ap, void *);
sp = va_arg(ap, void *); sp = va_arg(ap, void *);
sz = va_arg(ap, size_t); 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 /* simple 1D layout, none of the parameters really matter, as
* long as the copy generates a single memcpy. * long as the copy generates a single memcpy.
*/ */
aml_layout_dense_create(&dl, dp, 0, sizeof(size_t), 1, aml_layout_dense_create(&dl, dp, 0, 1, 1, &sz, NULL, NULL);
&sz, NULL, NULL); aml_layout_dense_create(&sl, sp, 0, 1, 1, &sz, NULL, NULL);
aml_layout_dense_create(&sl, sp, 0, sizeof(size_t), 1,
&sz, NULL, NULL);
aml_dma_linux_seq_request_data_init(req, aml_dma_linux_seq_request_data_init(req,
AML_DMA_REQUEST_TYPE_PTR, AML_DMA_REQUEST_TYPE_PTR,
dl, sl); dl, sl);
} } else
int uuid = aml_vector_getid(dma->data.requests, req); err = -AML_EINVAL;
unlock:
assert(uuid != AML_DMA_REQUEST_TYPE_INVALID);
aml_dma_request_linux_seq_create(&ret, uuid);
*r = (struct aml_dma_request *)ret;
pthread_mutex_unlock(&dma->data.lock); pthread_mutex_unlock(&dma->data.lock);
return 0; if (req->type != AML_DMA_REQUEST_TYPE_INVALID) {
int uuid = aml_vector_getid(dma->data.requests, req);
assert(uuid != AML_DMA_REQUEST_TYPE_INVALID);
aml_dma_request_linux_seq_create(&ret, uuid);
*r = (struct aml_dma_request *)ret;
}
return err;
} }
int aml_dma_linux_seq_destroy_request(struct aml_dma_data *d, int aml_dma_linux_seq_destroy_request(struct aml_dma_data *d,
struct aml_dma_request *r) struct aml_dma_request **r)
{ {
assert(d != NULL); assert(d != NULL);
assert(r != NULL); assert(r != NULL);
struct aml_dma_linux_seq *dma = struct aml_dma_linux_seq *dma =
(struct aml_dma_linux_seq *)d; (struct aml_dma_linux_seq *)d;
struct aml_dma_request_linux_seq *req;
struct aml_dma_request_linux_seq *req =
(struct aml_dma_request_linux_seq *)r;
struct aml_dma_linux_seq_request_data *inner_req; struct aml_dma_linux_seq_request_data *inner_req;
if (*r == NULL)
return -AML_EINVAL;
req = (struct aml_dma_request_linux_seq *)*r;
inner_req = aml_vector_get(dma->data.requests, req->uuid); inner_req = aml_vector_get(dma->data.requests, req->uuid);
if (inner_req == NULL) if (inner_req == NULL)
return -AML_EINVAL; return -AML_EINVAL;
...@@ -153,23 +166,26 @@ int aml_dma_linux_seq_destroy_request(struct aml_dma_data *d, ...@@ -153,23 +166,26 @@ int aml_dma_linux_seq_destroy_request(struct aml_dma_data *d,
aml_layout_dense_destroy(&inner_req->src); aml_layout_dense_destroy(&inner_req->src);
} }
/* enough to remove from request vector */
aml_vector_remove(dma->data.requests, inner_req); aml_vector_remove(dma->data.requests, inner_req);
pthread_mutex_unlock(&dma->data.lock); pthread_mutex_unlock(&dma->data.lock);
aml_dma_request_linux_seq_destroy(&req); aml_dma_request_linux_seq_destroy(&req);
*r = NULL;
return 0; return 0;
} }
int aml_dma_linux_seq_wait_request(struct aml_dma_data *d, int aml_dma_linux_seq_wait_request(struct aml_dma_data *d,
struct aml_dma_request *r) struct aml_dma_request **r)
{ {
assert(d != NULL); assert(d != NULL);
assert(r != NULL); assert(r != NULL);
struct aml_dma_linux_seq *dma = (struct aml_dma_linux_seq *)d; struct aml_dma_linux_seq *dma = (struct aml_dma_linux_seq *)d;
struct aml_dma_request_linux_seq *req = struct aml_dma_request_linux_seq *req;
(struct aml_dma_request_linux_seq *)r;
struct aml_dma_linux_seq_request_data *inner_req; struct aml_dma_linux_seq_request_data *inner_req;
if (*r == NULL)
return -AML_EINVAL;
req = (struct aml_dma_request_linux_seq *)*r;
inner_req = aml_vector_get(dma->data.requests, req->uuid); inner_req = aml_vector_get(dma->data.requests, req->uuid);
if (inner_req == NULL) if (inner_req == NULL)
return -AML_EINVAL; return -AML_EINVAL;
......
...@@ -87,7 +87,8 @@ int aml_layout_dense_create(struct aml_layout **layout, ...@@ -87,7 +87,8 @@ int aml_layout_dense_create(struct aml_layout **layout,
struct aml_layout_dense *data; struct aml_layout_dense *data;
int err; int err;
if (layout == NULL) if (layout == NULL || ptr == NULL || !element_size || !ndims ||
dims == NULL)
return -AML_EINVAL; return -AML_EINVAL;
err = aml_layout_dense_alloc(&l, ndims); err = aml_layout_dense_alloc(&l, ndims);
...@@ -111,8 +112,6 @@ int aml_layout_dense_create(struct aml_layout **layout, ...@@ -111,8 +112,6 @@ int aml_layout_dense_create(struct aml_layout **layout,
else else
data->pitch[i] = dims[ndims-i-1]; data->pitch[i] = dims[ndims-i-1];
} }
for (size_t i = 1; i <= ndims; i++)
data->cpitch[i] = data->cpitch[i-1]*pitch[ndims-i];
break; break;
case AML_LAYOUT_ORDER_COLUMN_MAJOR: case AML_LAYOUT_ORDER_COLUMN_MAJOR:
...@@ -124,14 +123,14 @@ int aml_layout_dense_create(struct aml_layout **layout, ...@@ -124,14 +123,14 @@ int aml_layout_dense_create(struct aml_layout **layout,
memcpy(data->pitch, pitch, ndims * sizeof(size_t)); memcpy(data->pitch, pitch, ndims * sizeof(size_t));
else else
memcpy(data->pitch, dims, ndims * sizeof(size_t)); memcpy(data->pitch, dims, ndims * sizeof(size_t));
for (size_t i = 1; i <= ndims; i++)
data->cpitch[i] = data->cpitch[i-1]*data->pitch[i-1];
break; break;
default: default:
free(l); free(l);
return -AML_EINVAL; return -AML_EINVAL;
} }
for (size_t i = 1; i <= ndims; i++)
data->cpitch[i] = data->cpitch[i-1]*data->pitch[i-1];
*layout = l; *layout = l;
return AML_SUCCESS; return AML_SUCCESS;
......
...@@ -183,7 +183,7 @@ int aml_scratch_seq_destroy_request(struct aml_scratch_data *d, ...@@ -183,7 +183,7 @@ int aml_scratch_seq_destroy_request(struct aml_scratch_data *d,
return -AML_EINVAL; return -AML_EINVAL;
if (inner_req->type != AML_SCRATCH_REQUEST_TYPE_NOOP) if (inner_req->type != AML_SCRATCH_REQUEST_TYPE_NOOP)
aml_dma_cancel(scratch->data.dma, inner_req->dma_req); aml_dma_cancel(scratch->data.dma, &inner_req->dma_req);
/* destroy removes the tile from the scratch */ /* destroy removes the tile from the scratch */
if (inner_req->type == AML_SCRATCH_REQUEST_TYPE_PUSH) if (inner_req->type == AML_SCRATCH_REQUEST_TYPE_PUSH)
...@@ -215,7 +215,7 @@ int aml_scratch_seq_wait_request(struct aml_scratch_data *d, ...@@ -215,7 +215,7 @@ int aml_scratch_seq_wait_request(struct aml_scratch_data *d,
/* wait for completion of the request */ /* wait for completion of the request */
if (inner_req->type != AML_SCRATCH_REQUEST_TYPE_NOOP) if (inner_req->type != AML_SCRATCH_REQUEST_TYPE_NOOP)
aml_dma_wait(scratch->data.dma, inner_req->dma_req); aml_dma_wait(scratch->data.dma, &inner_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 */
pthread_mutex_lock(&scratch->data.lock); pthread_mutex_lock(&scratch->data.lock);
......
...@@ -50,13 +50,18 @@ void aml_bitmap_copy_to_ulong(const struct aml_bitmap *dst, ...@@ -50,13 +50,18 @@ void aml_bitmap_copy_to_ulong(const struct aml_bitmap *dst,
src[AML_BITMAP_NTH(i)] |= (1UL << AML_BITMAP_ITH(i)); src[AML_BITMAP_NTH(i)] |= (1UL << AML_BITMAP_ITH(i));
} }
void aml_bitmap_zero(struct aml_bitmap *bitmap) int aml_bitmap_zero(struct aml_bitmap *bitmap)
{ {
if (bitmap == NULL)
return -AML_EINVAL;
memset(bitmap, 0, sizeof(struct aml_bitmap)); memset(bitmap, 0, sizeof(struct aml_bitmap));
return 0;
} }
int aml_bitmap_iszero(const struct aml_bitmap *bitmap) int aml_bitmap_iszero(const struct aml_bitmap *bitmap)
{ {
if (bitmap == NULL)
return -AML_EINVAL;
for (unsigned int i = 0; i < AML_BITMAP_SIZE; i++) for (unsigned int i = 0; i < AML_BITMAP_SIZE; i++)
if (bitmap->mask[i] != AML_BITMAP_EMPTY) if (bitmap->mask[i] != AML_BITMAP_EMPTY)
return 0; return 0;
...@@ -65,35 +70,46 @@ int aml_bitmap_iszero(const struct aml_bitmap *bitmap) ...@@ -65,35 +70,46 @@ int aml_bitmap_iszero(const struct aml_bitmap *bitmap)
int aml_bitmap_isfull(const struct aml_bitmap *bitmap) int aml_bitmap_isfull(const struct aml_bitmap *bitmap)
{ {
if (bitmap == NULL)
return -AML_EINVAL;
for (unsigned int i = 0; i < AML_BITMAP_SIZE; i++) for (unsigned int i = 0; i < AML_BITMAP_SIZE; i++)
if (bitmap->mask[i] != AML_BITMAP_FULL) if (bitmap->mask[i] != AML_BITMAP_FULL)
return 0; return 0;
return 1; return 1;
} }
void aml_bitmap_fill(struct aml_bitmap *bitmap) int aml_bitmap_fill(struct aml_bitmap *bitmap)
{ {
if (bitmap == NULL)
return -AML_EINVAL;
memset(bitmap, ~0, sizeof(struct aml_bitmap)); memset(bitmap, ~0, sizeof(struct aml_bitmap));
return 0;
} }
int aml_bitmap_isset(const struct aml_bitmap *bitmap, const unsigned int i) int aml_bitmap_isset(const struct aml_bitmap *bitmap, const unsigned int i)