Commit db42696f authored by Brice Videau's avatar Brice Videau Committed by Swann Perarnau
Browse files

Uniforming and correcting of ROW_MAJOR/C COLUMN_MAJOR/FORTRAN naming.

parent daff557a
......@@ -51,7 +51,7 @@ int main(int argc, char **argv)
// We start with a straighforward layout
assert(!aml_layout_dense_create(&lay_part, particles,
AML_LAYOUT_ORDER_C,
AML_LAYOUT_ORDER_COLUMN_MAJOR, //FORTRAN
sizeof(struct particle), 2,
(size_t[]){size_1, size_2}, NULL,
NULL));
......@@ -60,7 +60,7 @@ int main(int argc, char **argv)
// We need a finer layout
assert(!aml_layout_dense_create(&layout_elements, particles,
AML_LAYOUT_ORDER_C,
AML_LAYOUT_ORDER_COLUMN_MAJOR, //FORTRAN
sizeof(size_t), 3,
(size_t[]){4, size_1, size_2},
NULL, NULL));
......@@ -89,7 +89,7 @@ int main(int argc, char **argv)
array_coords = malloc(sizeof(struct particle) * size);
assert(!aml_layout_dense_create(&new_layout, array_coords,
AML_LAYOUT_ORDER_C,
AML_LAYOUT_ORDER_COLUMN_MAJOR, //FORTRAN
sizeof(size_t), 3,
(size_t[]){size_1, size_2, 4},
NULL, NULL));
......
......@@ -96,8 +96,8 @@ Layout API:
aml_layout_order(layout_f));
The order of the first layout is `AML_LAYOUT_ORDER_C`, which in AML is
represented by the value 0, and the order of the second layout is
`AML_LAYOUT_ORDER_FORTRAN`, and the above function would return 1.
represented by the value 1, and the order of the second layout is
`AML_LAYOUT_ORDER_FORTRAN`, and the above function would return 0.
Destroying an AML layout
~~~~~~~~~~~~~~~~~~~~~~~~
......@@ -179,7 +179,7 @@ Changing the shape of a layout
You can also change the shape of your layout, creating a new layout with a
different number of dimensions.
Let's take the previous layout `layout_c`, that had two dimensions `{x, y}`,
Let's take the previous layout `layout_f`, that had two dimensions `{x, y}`,
and create a new layout with three dimensions, basically splitting the first
dimension in two:
......@@ -187,10 +187,10 @@ dimension in two:
size_t new_dims[3] = { x/2, x/2, y };
struct aml_layout *reshape_layout;
aml_layout_reshape(layout_c, &reshape_layout, 3, new_dims));
aml_layout_reshape(layout_f, &reshape_layout, 3, new_dims));
The new layout is ordered in the same order as the previous layout, in this
case `AML_LAYOUT_ORDER_C`.
case `AML_LAYOUT_ORDER_FORTRAN`.
You can also want to mix up the order of the dimensions of your layout.
This cannot be done with the `reshape` function. You need to allocate a new
......@@ -211,9 +211,9 @@ right dimensions, we would use `aml_copy_layout_transform_generic`
array_2 = (double *)aml_area_mmap(area, sizeof(double) * size_0 * size_1 * size_2, NULL);
struct aml_layout *layout_3, *new_layout;
aml_layout_dense_create(&layout_3, array_1, AML_LAYOUT_ORDER_C, sizeof(size_t), 3, (size_t[]){size_0, size_1, size_2}, NULL, NULL));
aml_layout_dense_create(&layout_3, array_1, AML_LAYOUT_ORDER_FORTRAN, sizeof(size_t), 3, (size_t[]){size_0, size_1, size_2}, NULL, NULL));
aml_layout_dense_create(&new_layout, array_2, AML_LAYOUT_ORDER_C, sizeof(size_t), 3, (size_t[]){size_1, size_2, size_0}, NULL, NULL));
aml_layout_dense_create(&new_layout, array_2, AML_LAYOUT_ORDER_FORTRAN, sizeof(size_t), 3, (size_t[]){size_1, size_2, size_0}, NULL, NULL));
aml_copy_layout_transform_generic(new_layout, layout_3, (size_t[]){1, 2, 0}));
......@@ -245,7 +245,7 @@ Based on the above layout, a straightforward layout on this array could be:
.. code-block:: c
struct aml_layout *layout_part;
aml_layout_dense_create(&layout_part, particles, AML_LAYOUT_ORDER_C, sizeof(struct particle), 2, (size_t[]){size_1, size_2}, NULL, NULL));
aml_layout_dense_create(&layout_part, particles, AML_LAYOUT_ORDER_FORTRAN, sizeof(struct particle), 2, (size_t[]){size_1, size_2}, NULL, NULL));
The issue with this layout is that it does not give us a fine enough control on
the attributes of the particles. We need to be able to index each field of the
......@@ -256,7 +256,7 @@ all fields have the same storage size here):
struct aml_layout *layout_elements;
aml_layout_dense_create(&layout_elements, particles, AML_LAYOUT_ORDER_C, sizeof(size_t), 3, (size_t[]){4, size_1, size_2}, NULL, NULL));
aml_layout_dense_create(&layout_elements, particles, AML_LAYOUT_ORDER_FORTRAN, sizeof(size_t), 3, (size_t[]){4, size_1, size_2}, NULL, NULL));
Now we can create another layout, with a similar granularity, but with the
dimensions flipped so that we have one array for each attribute of all the
......
......@@ -12,8 +12,9 @@ As such, the main function of a tiling is to provide an index into
subcomponents of a layout.
As for the layouts, both the C and Fortran indexing orders are available for
the tilings, with similar names: `AML_TILING_ORDER_C` and
`AML_TILING_ORDER_FORTRAN`.
the tilings, with similar names: `AML_TILING_ORDER_C`
(`AML_TILING_ORDER_ROW_MAJOR`) and `AML_TILING_ORDER_FORTRAN`
(`AML_TILING_ORDER_COLUMN_MAJOR`).
Creating an AML tiling
~~~~~~~~~~~~~~~~~~~~~~
......
......@@ -236,6 +236,9 @@ int aml_area_fprintf(FILE *stream, const char *prefix,
* * A stride in between elements of a dimension.
* * A pitch indicating the space between contiguous elements of a dimension.
*
* For a definition of row and columns of matrices see :
* https://en.wikipedia.org/wiki/Matrix_(mathematics)
*
* The figure below describes a 2D layout with a sub-layout
* (obtained with aml_layout_slice()) operation. The sub-layout has a stride
* of 1 element along the second dimension. The slice has an offset of 1 element
......@@ -249,12 +252,13 @@ int aml_area_fprintf(FILE *stream, const char *prefix,
* Access to specific elements of a layout can be done with
* the aml_layout_deref() function. Access to an element is always done
* relatively to the dimensions order set by at creation time.
* However, internally, the library will store dimensions from the last
* dimension to the first dimension such that elements along the first dimension
* are contiguous in memory. This order is defined called with the value
* AML_LAYOUT_ORDER_FORTRAN. Therefore, AML provides access to elements
* without the overhead of user order choice through function suffixed
* with "native".
* However, internally, the library will always store dimensions in such a way
* that elements along the first dimension
* are contiguous in memory. This order is defined with the value
* AML_LAYOUT_ORDER_COLUMN_MAJOR (AML_LAYOUT_ORDER_FORTRAN). See:
* https://en.wikipedia.org/wiki/Row-_and_column-major_order
* Additionally, AML provides access to elements without the overhead of user
* order choice through function suffixed with "native".
* @see aml_layout_deref()
* @see aml_layout_deref_native()
* @see aml_layout_dims_native()
......@@ -456,7 +460,7 @@ struct aml_layout_ops {
* This tag will store dimensions in the order provided by the user,
* i.e., elements of the last dimension will be contiguous in memory.
**/
#define AML_LAYOUT_ORDER_C (0<<0)
#define AML_LAYOUT_ORDER_FORTRAN (0<<0)
/**
* Tag specifying user storage of dimensions inside a layout.
......@@ -467,17 +471,17 @@ struct aml_layout_ops {
* in memory. This storage is the actual storage used by the library
* inside the structure.
**/
#define AML_LAYOUT_ORDER_FORTRAN (1<<0)
#define AML_LAYOUT_ORDER_C (1<<0)
/**
* This is equivalent to AML_LAYOUT_ORDER_C.
* @see AML_LAYOUT_ORDER_C
* This is equivalent to AML_LAYOUT_ORDER_FORTRAN.
* @see AML_LAYOUT_ORDER_FORTRAN
**/
#define AML_LAYOUT_ORDER_COLUMN_MAJOR (0<<0)
/**
* This is equivalent to AML_LAYOUT_ORDER_FORTRAN.
* @see AML_LAYOUT_ORDER_FORTRAN
* This is equivalent to AML_LAYOUT_ORDER_C.
* @see AML_LAYOUT_ORDER_C
**/
#define AML_LAYOUT_ORDER_ROW_MAJOR (1<<0)
......@@ -638,7 +642,7 @@ int aml_layout_fprintf(FILE *stream, const char *prefix,
* This tag will store dimensions in the order provided by the user,
* i.e elements of the last dimension will be contiguous in memory.
**/
#define AML_TILING_ORDER_C (0<<0)
#define AML_TILING_ORDER_FORTRAN (0<<0)
/**
* Tag specifying user storage of dimensions inside a layout.
......@@ -649,17 +653,17 @@ int aml_layout_fprintf(FILE *stream, const char *prefix,
* in memory. This storage is the actual storage used by the library
* inside the structure.
**/
#define AML_TILING_ORDER_FORTRAN (1<<0)
#define AML_TILING_ORDER_C (1<<0)
/**
* This is equivalent to AML_TILING_ORDER_C.
* @see AML_TILING_ORDER_C
* This is equivalent to AML_TILING_ORDER_FORTRAN.
* @see AML_TILING_ORDER_FORTRAN
**/
#define AML_TILING_ORDER_COLUMN_MAJOR (0<<0)
/**
* This is equivalent to AML_TILING_ORDER_FORTRAN.
* @see AML_TILING_ORDER_FORTRAN
* This is equivalent to AML_TILING_ORDER_C.
* @see AML_TILING_ORDER_C
**/
#define AML_TILING_ORDER_ROW_MAJOR (1<<0)
......
......@@ -173,7 +173,7 @@ aml_tiling_pad_column_index(const struct aml_tiling_data *t,
size_t row_dims[ndims];
for (size_t i = 0; i < ndims; i++)
row_dims[i] = d->tile_dims[i];
row_dims[i] = d->tile_dims[ndims - i - 1];
/* WARNING: OWNERSHIP!!! */
aml_layout_pad_create(&p_layout,
AML_LAYOUT_ORDER_ROW_MAJOR,
......
......@@ -266,7 +266,7 @@ struct aml_tiling_ops aml_tiling_resize_column_ops = {
};
/*******************************************************************************
* Column Implementation
* Row Implementation
******************************************************************************/
struct aml_layout*
......
......@@ -31,9 +31,9 @@ void test_pad(int (*layout_create) (struct aml_layout **layout,
float one = 1.0;
size_t ret_dims[2];
assert(!layout_create(&a, (void *)memory, AML_LAYOUT_ORDER_C,
assert(!layout_create(&a, (void *)memory, AML_LAYOUT_ORDER_ROW_MAJOR,
sizeof(float), 2, dims, NULL, NULL));
assert(!aml_layout_pad_create(&b, AML_LAYOUT_ORDER_C, a,
assert(!aml_layout_pad_create(&b, AML_LAYOUT_ORDER_ROW_MAJOR, a,
dims_pad, &one));
assert(aml_layout_ndims(b) == 2);
......
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