Commit c220aede authored by Nicolas Denoyelle's avatar Nicolas Denoyelle
Browse files

Clang format

parent 1cf95954
Pipeline #10691 passed with stages
in 3 minutes and 29 seconds
......@@ -9,11 +9,11 @@
******************************************************************************/
#include <aml.h>
#include <aml/dma/linux-par.h>
#include <aml/layout/dense.h>
static inline void
CHK_ABORT(int err, const char *message)
static inline void CHK_ABORT(int err, const char *message)
{
if (err != AML_SUCCESS) {
fprintf(stderr, "%s: %s\n", message, aml_strerror(err));
......@@ -21,8 +21,7 @@ CHK_ABORT(int err, const char *message)
}
}
int
main(void)
int main(void)
{
int err;
......@@ -33,40 +32,34 @@ main(void)
CHK_ABORT(err, "aml_dma_linux_par_create:");
// The source data for the move.
double src[8] = {1, 2, 3, 4, 5, 6, 7, 8};
double src[8] = {1, 2, 3, 4, 5, 6, 7, 8};
size_t src_dims[1] = {8};
struct aml_layout *src_layout;
err = aml_layout_dense_create(&src_layout,
src,
AML_LAYOUT_ORDER_COLUMN_MAJOR,
sizeof(*src), // size of 1 element
1, // only 1 dimension: flat array
src_dims,
NULL, // data is not strided
NULL); // data has no pitch.
err = aml_layout_dense_create(&src_layout, src,
AML_LAYOUT_ORDER_COLUMN_MAJOR,
sizeof(*src), // size of 1 element
1, // only 1 dimension: flat array
src_dims,
NULL, // data is not strided
NULL); // data has no pitch.
CHK_ABORT(err, "aml_layout_dense_create:");
// The destination data for the move.
double dst[8] = {0, 0, 0, 0, 0, 0, 0, 0};
double dst[8] = {0, 0, 0, 0, 0, 0, 0, 0};
size_t dst_dims[1] = {8};
struct aml_layout *dst_layout;
err = aml_layout_dense_create(&dst_layout,
dst,
AML_LAYOUT_ORDER_COLUMN_MAJOR,
sizeof(*dst),
1,
dst_dims,
NULL,
NULL);
err = aml_layout_dense_create(&dst_layout, dst,
AML_LAYOUT_ORDER_COLUMN_MAJOR,
sizeof(*dst), 1, dst_dims, NULL, NULL);
CHK_ABORT(err, "aml_layout_dense_create:");
// Handle to the dma request we are about to issue.
struct aml_dma_request *request;
err = aml_dma_async_copy(
dma, &request, dst_layout, src_layout, NULL, NULL);
err = aml_dma_async_copy(dma, &request, dst_layout, src_layout, NULL,
NULL);
CHK_ABORT(err, "aml_dma_async_copy_custom:");
// Wait request
......
......@@ -9,12 +9,12 @@
******************************************************************************/
#include <aml.h>
#include <aml/dma/linux-par.h>
#include <aml/layout/dense.h>
/** Error checking and printing. Should not be triggered **/
static inline void
CHK_ABORT(int err, const char *message)
static inline void CHK_ABORT(int err, const char *message)
{
if (err != AML_SUCCESS) {
fprintf(stderr, "%s: %s\n", message, aml_strerror(err));
......@@ -25,8 +25,7 @@ CHK_ABORT(int err, const char *message)
/**
* The ddot function
**/
static inline double
ddot(const double *x, const double *y, const size_t n)
static inline double ddot(const double *x, const double *y, const size_t n)
{
double result = 0.0;
......@@ -35,8 +34,7 @@ ddot(const double *x, const double *y, const size_t n)
return result;
}
int
main(void)
int main(void)
{
int err;
......@@ -48,49 +46,27 @@ main(void)
CHK_ABORT(err, "aml_dma_linux_par_create:");
// Defining 'a' vector: {0.534, 65.4543, 0, 913.2} with a stride of 2.
double a[8] = {
0.534, 6.3424, 65.4543, 4.543e12, 0.0, 1.0, 9.132e2, 23.657};
size_t a_dims[1] = {4}; // a has only 4 elements.
double a[8] = {0.534, 6.3424, 65.4543, 4.543e12,
0.0, 1.0, 9.132e2, 23.657};
size_t a_dims[1] = {4}; // a has only 4 elements.
size_t a_stride[1] = {2}; // elements are strided by 2.
struct aml_layout *a_layout;
err = aml_layout_dense_create(&a_layout,
a,
AML_LAYOUT_ORDER_COLUMN_MAJOR,
sizeof(*a),
1,
a_dims,
a_stride,
NULL);
err = aml_layout_dense_create(&a_layout, a,
AML_LAYOUT_ORDER_COLUMN_MAJOR, sizeof(*a),
1, a_dims, a_stride, NULL);
CHK_ABORT(err, "aml_layout_dense_create:");
// Defining 'b' vector { 1.0, 1.0, 1.0, 1.0 } with a stride of 3.
double b[12] = {
1.0,
0.0,
0.0,
1.0,
0.0,
0.0,
1.0,
0.0,
0.0,
1.0,
0.0,
0.0,
1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0,
};
size_t b_dims[1] = {4}; // b has 4 elements as well.
size_t b_dims[1] = {4}; // b has 4 elements as well.
size_t b_stride[1] = {3}; // b elements are strided by 3.
struct aml_layout *b_layout;
aml_layout_dense_create(&b_layout,
b,
AML_LAYOUT_ORDER_COLUMN_MAJOR,
sizeof(*b),
1,
b_dims,
b_stride,
NULL);
aml_layout_dense_create(&b_layout, b, AML_LAYOUT_ORDER_COLUMN_MAJOR,
sizeof(*b), 1, b_dims, b_stride, NULL);
//----------------- Defining ddot continous layouts
//-----------------------
......@@ -101,24 +77,16 @@ main(void)
struct aml_layout *a_continuous_layout;
struct aml_layout *b_continuous_layout;
err = aml_layout_dense_create(&a_continuous_layout,
continuous_a,
AML_LAYOUT_ORDER_COLUMN_MAJOR,
sizeof(*continuous_a),
1,
continuous_dims,
NULL,
NULL);
err = aml_layout_dense_create(&a_continuous_layout, continuous_a,
AML_LAYOUT_ORDER_COLUMN_MAJOR,
sizeof(*continuous_a), 1, continuous_dims,
NULL, NULL);
CHK_ABORT(err, "aml_layout_dense_create:");
err = aml_layout_dense_create(&b_continuous_layout,
continuous_b,
AML_LAYOUT_ORDER_COLUMN_MAJOR,
sizeof(*continuous_b),
1,
continuous_dims,
NULL,
NULL);
err = aml_layout_dense_create(&b_continuous_layout, continuous_b,
AML_LAYOUT_ORDER_COLUMN_MAJOR,
sizeof(*continuous_b), 1, continuous_dims,
NULL, NULL);
CHK_ABORT(err, "aml_layout_dense_create:");
//----------------- Transform 'a' and 'b' to be continuous
......@@ -129,12 +97,12 @@ main(void)
struct aml_dma_request *b_request;
// Schedule requests
err =
aml_dma_async_copy_helper(dma, &a_request, a_continuous_layout, a_layout);
err = aml_dma_async_copy_helper(dma, &a_request, a_continuous_layout,
a_layout);
CHK_ABORT(err, "aml_dma_async_copy_custom:");
err =
aml_dma_async_copy_helper(dma, &b_request, b_continuous_layout, b_layout);
err = aml_dma_async_copy_helper(dma, &b_request, b_continuous_layout,
b_layout);
CHK_ABORT(err, "aml_dma_async_copy_custom:");
// Wait for the requests to complete
......
This diff is collapsed.
......@@ -6,7 +6,7 @@
* For more info, see https://xgitlab.cels.anl.gov/argo/aml
*
* SPDX-License-Identifier: BSD-3-Clause
*******************************************************************************/
*******************************************************************************/
#ifndef AML_DMA_LINUX_SEQ_H
#define AML_DMA_LINUX_SEQ_H 1
......@@ -79,7 +79,7 @@ struct aml_dma_linux_seq_inner_ops {
* @see aml_area
**/
int (*do_copy)(struct aml_dma_linux_seq_data *dma,
struct aml_dma_request_linux_seq *req);
struct aml_dma_request_linux_seq *req);
};
/**
......@@ -92,7 +92,6 @@ struct aml_dma_linux_seq {
struct aml_dma_linux_seq_data data;
};
/**
* Allocates and initializes a new sequential DMA.
*
......@@ -105,8 +104,10 @@ struct aml_dma_linux_seq {
*
* @return 0 if successful; an error code otherwise.
**/
int aml_dma_linux_seq_create(struct aml_dma **dma, size_t nbreqs,
aml_dma_operator op, void *op_arg);
int aml_dma_linux_seq_create(struct aml_dma **dma,
size_t nbreqs,
aml_dma_operator op,
void *op_arg);
/**
* Tears down a sequential DMA created with aml_dma_linux_seq_create.
......@@ -121,7 +122,7 @@ void aml_dma_linux_seq_destroy(struct aml_dma **dma);
* @return 0 if successful; an error code otherwise.
**/
int aml_dma_linux_seq_do_copy(struct aml_dma_linux_seq_data *dma,
struct aml_dma_request_linux_seq *req);
struct aml_dma_request_linux_seq *req);
/**
* Generic helper to copy from one layout to another.
......@@ -131,9 +132,9 @@ int aml_dma_linux_seq_do_copy(struct aml_dma_linux_seq_data *dma,
* @param[out] out: A pointer where to store output of the function.
*/
int aml_copy_layout_generic(struct aml_layout *dst,
const struct aml_layout *src,
void *arg,
void **out);
const struct aml_layout *src,
void *arg,
void **out);
/**
* @}
......
......@@ -6,12 +6,13 @@
* For more info, see https://xgitlab.cels.anl.gov/argo/aml
*
* SPDX-License-Identifier: BSD-3-Clause
*******************************************************************************/
*******************************************************************************/
#include <assert.h>
#include "aml.h"
#include "aml/layout/native.h"
#include <assert.h>
#include "aml/layout/native.h"
/*******************************************************************************
* Generic DMA API:
......@@ -22,8 +23,11 @@
* abstract the request creation after this layer.
******************************************************************************/
int aml_dma_copy(struct aml_dma *dma, struct aml_layout *dest,
struct aml_layout *src, aml_dma_operator op, void *op_arg)
int aml_dma_copy(struct aml_dma *dma,
struct aml_layout *dest,
struct aml_layout *src,
aml_dma_operator op,
void *op_arg)
{
int ret;
struct aml_dma_request *req;
......@@ -38,9 +42,12 @@ int aml_dma_copy(struct aml_dma *dma, struct aml_layout *dest,
return ret;
}
int aml_dma_async_copy(struct aml_dma *dma, struct aml_dma_request **req,
struct aml_layout *dest, struct aml_layout *src,
aml_dma_operator op, void *op_arg)
int aml_dma_async_copy(struct aml_dma *dma,
struct aml_dma_request **req,
struct aml_layout *dest,
struct aml_layout *src,
aml_dma_operator op,
void *op_arg)
{
if (dma == NULL || req == NULL || dest == NULL || src == NULL)
return -AML_EINVAL;
......@@ -62,8 +69,7 @@ int aml_dma_wait(struct aml_dma *dma, struct aml_dma_request **req)
return dma->ops->wait_request(dma->data, req);
}
int aml_dma_fprintf(FILE *stream, const char *prefix,
const struct aml_dma *dma)
int aml_dma_fprintf(FILE *stream, const char *prefix, const struct aml_dma *dma)
{
assert(dma != NULL && dma->ops != NULL && stream != NULL);
......
......@@ -6,17 +6,18 @@
* For more info, see https://xgitlab.cels.anl.gov/argo/aml
*
* SPDX-License-Identifier: BSD-3-Clause
*******************************************************************************/
#include "aml.h"
#include "aml/dma/linux-seq.h"
#include "aml/dma/linux-par.h"
#include "aml/layout/dense.h"
*******************************************************************************/
#include <assert.h>
#include <errno.h>
#include <sys/mman.h>
#include "aml.h"
#include "aml/dma/linux-par.h"
#include "aml/dma/linux-seq.h"
#include "aml/layout/dense.h"
/*******************************************************************************
* Linux-backed, paruential dma
* The dma itself is organized into several different components
......@@ -31,9 +32,10 @@
******************************************************************************/
int aml_dma_request_linux_par_copy_init(struct aml_dma_request_linux_par *req,
struct aml_layout *dest,
struct aml_layout *src,
aml_dma_operator op, void *op_arg)
struct aml_layout *dest,
struct aml_layout *src,
aml_dma_operator op,
void *op_arg)
{
assert(req != NULL);
req->type = AML_DMA_REQUEST_TYPE_LAYOUT;
......@@ -57,7 +59,7 @@ int aml_dma_request_linux_par_copy_destroy(struct aml_dma_request_linux_par *r)
void *aml_dma_linux_par_do_thread(void *arg)
{
struct aml_dma_request_linux_par *req =
(struct aml_dma_request_linux_par *)arg;
(struct aml_dma_request_linux_par *)arg;
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
if (req->type != AML_DMA_REQUEST_TYPE_INVALID)
......@@ -66,7 +68,7 @@ void *aml_dma_linux_par_do_thread(void *arg)
}
struct aml_dma_linux_par_inner_ops aml_dma_linux_par_inner_ops = {
aml_dma_linux_par_do_thread,
aml_dma_linux_par_do_thread,
};
/*******************************************************************************
......@@ -74,18 +76,18 @@ struct aml_dma_linux_par_inner_ops aml_dma_linux_par_inner_ops = {
******************************************************************************/
int aml_dma_linux_par_create_request(struct aml_dma_data *d,
struct aml_dma_request **r,
struct aml_layout *dest,
struct aml_layout *src,
aml_dma_operator op, void *op_arg)
struct aml_dma_request **r,
struct aml_layout *dest,
struct aml_layout *src,
aml_dma_operator op,
void *op_arg)
{
/* NULL checks done by the generic API */
assert(d != NULL);
assert(r != NULL);
assert(dest != NULL);
assert(src != 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;
if (op == NULL)
......@@ -103,12 +105,11 @@ int aml_dma_linux_par_create_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(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;
if (*r == NULL)
......@@ -133,7 +134,7 @@ int aml_dma_linux_par_destroy_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(r != NULL);
......@@ -156,7 +157,8 @@ int aml_dma_linux_par_wait_request(struct aml_dma_data *d,
}
int aml_dma_linux_par_fprintf(const struct aml_dma_data *data,
FILE *stream, const char *prefix)
FILE *stream,
const char *prefix)
{
const struct aml_dma_linux_par *d;
size_t vsize;
......@@ -170,7 +172,7 @@ int aml_dma_linux_par_fprintf(const struct aml_dma_data *data,
vsize = aml_vector_size(d->data.requests);
/* ugly cast because ISO C forbids function pointer to void * */
fprintf(stream, "%s: op: %p\n", prefix,
(void *) (intptr_t) d->data.default_op);
(void *)(intptr_t)d->data.default_op);
fprintf(stream, "%s: op-arg: %p\n", prefix, d->data.default_op_arg);
fprintf(stream, "%s: requests: %zu\n", prefix, vsize);
for (size_t i = 0; i < vsize; i++) {
......@@ -182,30 +184,32 @@ int aml_dma_linux_par_fprintf(const struct aml_dma_data *data,
continue;
fprintf(stream, "%s: layout-dest: %p\n", prefix,
(void *)r->dest);
(void *)r->dest);
aml_layout_fprintf(stream, prefix, r->dest);
fprintf(stream, "%s: layout-src: %p\n", prefix, (void *)r->src);
aml_layout_fprintf(stream, prefix, r->src);
fprintf(stream, "%s: op: %p\n", prefix,
(void *) (intptr_t)r->op);
(void *)(intptr_t)r->op);
fprintf(stream, "%s: op-arg: %p\n", prefix, (void *)r->op_arg);
}
return AML_SUCCESS;
}
struct aml_dma_ops aml_dma_linux_par_ops = {
aml_dma_linux_par_create_request,
aml_dma_linux_par_destroy_request,
aml_dma_linux_par_wait_request,
aml_dma_linux_par_fprintf,
aml_dma_linux_par_create_request,
aml_dma_linux_par_destroy_request,
aml_dma_linux_par_wait_request,
aml_dma_linux_par_fprintf,
};
/*******************************************************************************
* Init functions:
******************************************************************************/
int aml_dma_linux_par_create(struct aml_dma **dma, size_t nbreqs,
aml_dma_operator op, void *op_arg)
int aml_dma_linux_par_create(struct aml_dma **dma,
size_t nbreqs,
aml_dma_operator op,
void *op_arg)
{
struct aml_dma *ret = NULL;
struct aml_dma_linux_par *d;
......@@ -219,9 +223,8 @@ int aml_dma_linux_par_create(struct aml_dma **dma, size_t nbreqs,
if (ret == NULL)
return -AML_ENOMEM;
ret->data = AML_INNER_MALLOC_GET_FIELD(ret, 2,
struct aml_dma,
struct aml_dma_linux_par);
ret->data = AML_INNER_MALLOC_GET_FIELD(ret, 2, struct aml_dma,
struct aml_dma_linux_par);
ret->ops = &aml_dma_linux_par_ops;
d = (struct aml_dma_linux_par *)ret->data;
d->ops = aml_dma_linux_par_inner_ops;
......@@ -235,9 +238,9 @@ int aml_dma_linux_par_create(struct aml_dma **dma, size_t nbreqs,
/* allocate request array */
aml_vector_create(&d->data.requests, nbreqs,
sizeof(struct aml_dma_request_linux_par),
offsetof(struct aml_dma_request_linux_par, type),
AML_DMA_REQUEST_TYPE_INVALID);
sizeof(struct aml_dma_request_linux_par),
offsetof(struct aml_dma_request_linux_par, type),
AML_DMA_REQUEST_TYPE_INVALID);
pthread_mutex_init(&d->data.lock, NULL);
*dma = ret;
......
......@@ -6,17 +6,18 @@
* For more info, see https://xgitlab.cels.anl.gov/argo/aml
*
* SPDX-License-Identifier: BSD-3-Clause
*******************************************************************************/
*******************************************************************************/
#include <assert.h>
#include <errno.h>
#include <sys/mman.h>
#include "aml.h"
#include "aml/dma/linux-seq.h"
#include "aml/layout/dense.h"
#include "aml/layout/native.h"
#include <assert.h>
#include <errno.h>
#include <sys/mman.h>
/*******************************************************************************
* Generic DMA Copy/Transform implementations
*
......@@ -25,33 +26,32 @@
******************************************************************************/
static inline void aml_copy_layout_generic_helper(size_t d,
struct aml_layout *dst,
const struct aml_layout *src,
const size_t *elem_number,
size_t elem_size,
size_t *coords)
struct aml_layout *dst,
const struct aml_layout *src,
const size_t *elem_number,
size_t elem_size,
size_t *coords)
{
if (d == 1) {
for (size_t i = 0; i < elem_number[0]; i += 1) {
coords[0] = i;
memcpy(aml_layout_deref_native(dst, coords),
aml_layout_deref_native(src, coords),
elem_size);
aml_layout_deref_native(src, coords), elem_size);
}
} else {
for (size_t i = 0; i < elem_number[d - 1]; i += 1) {
coords[d - 1] = i;
aml_copy_layout_generic_helper(d - 1, dst, src,
elem_number, elem_size,
coords);
elem_number, elem_size,
coords);
}
}
}
int aml_copy_layout_generic(struct aml_layout *dst,
const struct aml_layout *src,
void *arg,
void **out)
const struct aml_layout *src,
void *arg,
void **out)
{
size_t d;
size_t elem_size;
......@@ -72,44 +72,41 @@ int aml_copy_layout_generic(struct aml_layout *dst,
for (size_t i = 0; i < d; i += 1)
assert(elem_number[i] == elem_number2[i]);
aml_copy_layout_generic_helper(d, dst, src, elem_number, elem_size,
coords);
coords);
return 0;
}
static inline void aml_copy_layout_transform_generic_helper(
size_t d,
struct aml_layout *dst,
const struct aml_layout *src,
const size_t *elem_number,
size_t elem_size,
size_t *coords,
size_t *coords_out,
const size_t *target_dims)
static inline void
aml_copy_layout_transform_generic_helper(size_t d,
struct aml_layout *dst,
const struct aml_layout *src,
const size_t *elem_number,
size_t elem_size,
size_t *coords,
size_t *coords_out,
const size_t *target_dims)
{
if (d == 1)
for (siz