Commit 370ccb85 authored by Swann Perarnau's avatar Swann Perarnau
Browse files

Merge branch 'tiling_cleanup' into 'staging'

[fix] Cleanup tiling abstraction.

See merge request !157
parents ff0b6ea4 0d9103d2
Pipeline #11309 passed with stages
in 4 minutes and 40 seconds
......@@ -8,11 +8,14 @@
* SPDX-License-Identifier: BSD-3-Clause
******************************************************************************/
#include <excit.h>
#include <stdio.h>
#include <aml.h>
#include "aml/area/linux.h"
#include "aml/layout/dense.h"
#include "aml/tiling/resize.h"
#include <stdio.h>
void print_matrix(double *mat, size_t rows, size_t cols)
{
......@@ -24,53 +27,64 @@ void print_matrix(double *mat, size_t rows, size_t cols)
fprintf(stderr, "\n");
}
excit_t tiling_iterator(struct aml_tiling *tiling)
{
size_t ndims = aml_tiling_ndims(tiling);
size_t dims[ndims];
excit_t it, iterator = excit_alloc(EXCIT_PRODUCT);
assert(iterator != NULL);
assert(aml_tiling_dims(tiling, dims) == AML_SUCCESS);
for (size_t d = 0; d < ndims; d++) {
it = excit_alloc(EXCIT_RANGE);
assert(excit_range_init(it, 0, dims[d] - 1, 1) ==
EXCIT_SUCCESS);
assert(excit_product_add(iterator, it) == EXCIT_SUCCESS);
}
return iterator;
}
/* Initialize a given tiling with arbitrary values.
* Use of
* aml_tiling_ndims
* aml_tiling_tile_dims
* aml_tiling_dims
* aml_tiling_ntiles
* aml_tiling_index_byid
*
*/
int fill_tiling(struct aml_tiling *tiling)
{
int err;
size_t ndims = aml_tiling_ndims(tiling);
size_t ntiles = aml_tiling_ntiles(tiling);
size_t dims[ndims];
size_t tile_dims[ndims];
size_t coords[ndims];
double *a;
double count = 1;
err = aml_tiling_dims(tiling, dims);
if (err != AML_SUCCESS)
return err;
aml_tiling_tile_dims(tiling, tile_dims);
aml_tiling_tile_dims(tiling, NULL, dims);
// Create a tiling iterator
excit_t iterator = tiling_iterator(tiling);
// Going through the tiling tile by tile
for (size_t i = 0; i < ntiles; i++) {
struct aml_layout *ltile;
// We get the layout associated with the current tile
ltile = aml_tiling_index_byid(tiling, i);
struct aml_layout *ltile;
while (excit_next(iterator, (ssize_t *)coords) != EXCIT_STOPIT) {
ltile = aml_tiling_index(tiling, coords);
assert(ltile != NULL);
// Then we fill the layout element by element
for (size_t j = 0; j < tile_dims[0]; j++) {
for (size_t j = 0; j < dims[0]; j++) {
coords[0] = j;
for (size_t k = 0; k < tile_dims[1]; k++) {
for (size_t k = 0; k < dims[1]; k++) {
coords[1] = k;
a = aml_layout_deref(ltile, coords);
*a = count;
count++;
}
}
aml_layout_destroy(&ltile);
}
excit_free(iterator);
return AML_SUCCESS;
}
......
......@@ -76,8 +76,8 @@ int dgemm_tiled(struct aml_tiling *tiling_a, struct aml_tiling *tiling_b,
size_t tiling_b_dims[ndims];
size_t tiling_c_dims[ndims];
aml_tiling_tile_dims(tiling_a, tile_a_dims);
aml_tiling_tile_dims(tiling_b, tile_b_dims);
aml_tiling_tile_dims(tiling_a, NULL, tile_a_dims);
aml_tiling_tile_dims(tiling_b, NULL, tile_b_dims);
mt = tile_a_dims[0];
kt = tile_a_dims[1];
nt = tile_b_dims[1];
......
......@@ -735,9 +735,7 @@ struct aml_tiling_ops {
const size_t *coords);
void *(*rawptr)(const struct aml_tiling_data *t,
const size_t *coords);
int (*tileid)(const struct aml_tiling_data *t, const size_t *coords);
int (*order)(const struct aml_tiling_data *t);
int (*tile_dims)(const struct aml_tiling_data *t, size_t *dims);
int (*dims)(const struct aml_tiling_data *t, size_t *dims);
int (*dims_native)(const struct aml_tiling_data *t, size_t *dims);
size_t (*ndims)(const struct aml_tiling_data *t);
......@@ -785,15 +783,6 @@ int aml_tiling_order(const struct aml_tiling *tiling);
**/
int aml_tiling_dims(const struct aml_tiling *tiling, size_t *dims);
/**
* Return the dimensions of a tile in the tiling, in the user order.
* @param[in] tiling: An initialized tiling.
* @param[out] dims: A non-NULL array of dimensions to fill. It is
* supposed to be large enough to contain aml_tiling_ndims() elements.
* @return AML_SUCCESS on success, else an AML error code.
**/
int aml_tiling_tile_dims(const struct aml_tiling *tiling, size_t *dims);
/**
* Provide the number of dimensions in a tiling.
* @param tiling: an initialized tiling structure.
......@@ -801,6 +790,19 @@ int aml_tiling_tile_dims(const struct aml_tiling *tiling, size_t *dims);
**/
size_t aml_tiling_ndims(const struct aml_tiling *tiling);
/**
* Get the dimensions of a specific tile in the tiling.
* @param[in] tiling: The tiling to inspect.
* @param[in] coords: The coordinate of the tile to lookup.
* If NULL, the first tile is used.
* @param[out] dims: The tile dimensions.
* @return AML_SUCCESS on success.
* @return The result of aml_tiling_index on error.
*/
int aml_tiling_tile_dims(const struct aml_tiling *tiling,
const size_t *coords,
size_t *dims);
/**
* Provide the number of tiles in a tiling.
* @param tiling: an initialized tiling structure.
......@@ -825,23 +827,6 @@ struct aml_layout *aml_tiling_index(const struct aml_tiling *tiling,
*/
void *aml_tiling_rawptr(const struct aml_tiling *tiling, const size_t *coords);
/**
* Return a unique identifier for a tile based on coordinates in the tiling
* @param tiling: an initialized tiling
* @param coords: the coordinates for the tile
* @return a uuid for the tile.
*/
int aml_tiling_tileid(const struct aml_tiling *tiling, const size_t *coords);
/**
* Return the tile with this identifier
* @param tiling: an initialized tiling
* @param uuid: a unique identifier for this tile
* @return the tiling as a layout on success, NULL on error.
*/
struct aml_layout *aml_tiling_index_byid(const struct aml_tiling *tiling,
const int uuid);
/**
* Return the tile at the coordinates at the current position of the input
* iterator.
......
......@@ -20,12 +20,30 @@ int aml_tiling_order(const struct aml_tiling *t)
return t->ops->order(t->data);
}
int aml_tiling_tile_dims(const struct aml_tiling *t, size_t *dims)
int aml_tiling_tile_dims(const struct aml_tiling *t,
const size_t *coords,
size_t *dims)
{
if (t == NULL || t->ops == NULL || dims == NULL)
return -AML_EINVAL;
return t->ops->tile_dims(t->data, dims);
int err;
struct aml_layout *layout;
size_t ndims = aml_tiling_ndims(t);
size_t coordinates[ndims];
if (coords != NULL)
memcpy(coordinates, coords, ndims * sizeof(*coords));
else
for (size_t i = 0; i < ndims; i++)
coordinates[i] = 0;
layout = aml_tiling_index(t, coordinates);
if (layout == NULL)
return -aml_errno;
err = aml_layout_dims(layout, dims);
aml_layout_destroy(&layout);
return err;
}
int aml_tiling_dims(const struct aml_tiling *t, size_t *dims)
......@@ -73,16 +91,6 @@ void *aml_tiling_rawptr(const struct aml_tiling *t, const size_t *coords)
return t->ops->rawptr(t->data, coords);
}
int aml_tiling_tileid(const struct aml_tiling *t,
const size_t *coords)
{
if (t == NULL || t->ops == NULL || coords == NULL)
return -AML_EINVAL;
return t->ops->tileid(t->data, coords);
}
struct aml_layout *aml_tiling_index_native(const struct aml_tiling *t,
const size_t *coords)
{
......@@ -92,24 +100,6 @@ struct aml_layout *aml_tiling_index_native(const struct aml_tiling *t,
return t->ops->index_native(t->data, coords);
}
struct aml_layout *aml_tiling_index_byid(const struct aml_tiling *t,
int uuid)
{
if (t == NULL || t->ops == NULL || uuid < 0)
return NULL;
size_t ndims = aml_tiling_ndims(t);
size_t coords[ndims];
size_t dims[ndims];
aml_tiling_dims_native(t, dims);
for (size_t i = 0; i < ndims; i++) {
coords[i] = uuid % dims[i];
uuid /= dims[i];
}
return aml_tiling_index_native(t, coords);
}
struct aml_layout *aml_tiling_index_byiter(const struct aml_tiling *t,
const_excit_t iterator)
{
......
......@@ -199,37 +199,12 @@ void *aml_tiling_pad_column_rawptr(const struct aml_tiling_data *t,
return aml_layout_deref_native(d->layout, offsets);
}
int aml_tiling_pad_column_tileid(const struct aml_tiling_data *t,
const size_t *coords)
{
const struct aml_tiling_pad *d = (const struct aml_tiling_pad *)t;
assert(d != NULL);
int ret = 0;
size_t ndims = d->ndims;
for (size_t i = 0; i < ndims; i++)
ret = (ret * d->dims[i]) + coords[i];
return ret;
}
int aml_tiling_pad_column_order(const struct aml_tiling_data *t)
{
(void)t;
return AML_TILING_ORDER_COLUMN_MAJOR;
}
int aml_tiling_pad_column_tile_dims(const struct aml_tiling_data *t,
size_t *tile_dims)
{
const struct aml_tiling_pad *d = (const struct aml_tiling_pad *)t;
assert(d != NULL);
memcpy((void *)tile_dims, (void *)d->tile_dims,
sizeof(size_t)*d->ndims);
return 0;
}
int aml_tiling_pad_column_dims(const struct aml_tiling_data *t,
size_t *dims)
{
......@@ -291,9 +266,7 @@ struct aml_tiling_ops aml_tiling_pad_column_ops = {
aml_tiling_pad_column_index,
aml_tiling_pad_column_index,
aml_tiling_pad_column_rawptr,
aml_tiling_pad_column_tileid,
aml_tiling_pad_column_order,
aml_tiling_pad_column_tile_dims,
aml_tiling_pad_column_dims,
aml_tiling_pad_column_dims,
aml_tiling_pad_column_ndims,
......@@ -374,37 +347,12 @@ void *aml_tiling_pad_row_rawptr(const struct aml_tiling_data *t,
return aml_layout_deref_native(d->layout, offsets);
}
int aml_tiling_pad_row_tileid(const struct aml_tiling_data *t,
const size_t *coords)
{
const struct aml_tiling_pad *d = (const struct aml_tiling_pad *)t;
assert(d != NULL);
int ret = 0;
size_t ndims = d->ndims;
for (size_t i = 0; i < ndims; i++)
ret = (ret * d->dims[i]) + coords[ndims - i - 1];
return ret;
}
int aml_tiling_pad_row_order(const struct aml_tiling_data *t)
{
(void)t;
return AML_TILING_ORDER_ROW_MAJOR;
}
int aml_tiling_pad_row_tile_dims(const struct aml_tiling_data *t,
size_t *tile_dims)
{
const struct aml_tiling_pad *d = (const struct aml_tiling_pad *)t;
assert(d != NULL);
for (size_t i = 0; i < d->ndims; i++)
tile_dims[i] = d->tile_dims[d->ndims - i - 1];
return 0;
}
int aml_tiling_pad_row_dims(const struct aml_tiling_data *t,
size_t *dims)
{
......@@ -456,9 +404,7 @@ struct aml_tiling_ops aml_tiling_pad_row_ops = {
aml_tiling_pad_row_index,
aml_tiling_pad_column_index,
aml_tiling_pad_row_rawptr,
aml_tiling_pad_row_tileid,
aml_tiling_pad_row_order,
aml_tiling_pad_row_tile_dims,
aml_tiling_pad_row_dims,
aml_tiling_pad_column_dims,
aml_tiling_pad_row_ndims,
......
......@@ -160,39 +160,12 @@ void *aml_tiling_resize_column_rawptr(const struct aml_tiling_data *t,
return aml_layout_deref_native(d->layout, offsets);
}
int aml_tiling_resize_column_tileid(const struct aml_tiling_data *t,
const size_t *coords)
{
const struct aml_tiling_resize *d =
(const struct aml_tiling_resize *)t;
assert(d != NULL);
int ret = 0;
size_t ndims = d->ndims;
for (size_t i = 0; i < ndims; i++)
ret = (ret * d->dims[i]) + coords[i];
return ret;
}
int aml_tiling_resize_column_order(const struct aml_tiling_data *t)
{
(void)t;
return AML_TILING_ORDER_COLUMN_MAJOR;
}
int aml_tiling_resize_column_tile_dims(const struct aml_tiling_data *t,
size_t *tile_dims)
{
const struct aml_tiling_resize *d =
(const struct aml_tiling_resize *)t;
assert(d != NULL);
memcpy((void *)tile_dims, (void *)d->tile_dims,
sizeof(size_t)*d->ndims);
return 0;
}
int aml_tiling_resize_column_dims(const struct aml_tiling_data *l,
size_t *dims)
{
......@@ -255,9 +228,7 @@ struct aml_tiling_ops aml_tiling_resize_column_ops = {
aml_tiling_resize_column_index,
aml_tiling_resize_column_index,
aml_tiling_resize_column_rawptr,
aml_tiling_resize_column_tileid,
aml_tiling_resize_column_order,
aml_tiling_resize_column_tile_dims,
aml_tiling_resize_column_dims,
aml_tiling_resize_column_dims,
aml_tiling_resize_column_ndims,
......@@ -317,39 +288,12 @@ void *aml_tiling_resize_row_rawptr(const struct aml_tiling_data *t,
return aml_layout_deref_native(d->layout, offsets);
}
int aml_tiling_resize_row_tileid(const struct aml_tiling_data *t,
const size_t *coords)
{
const struct aml_tiling_resize *d =
(const struct aml_tiling_resize *)t;
assert(d != NULL);
int ret = 0;
size_t ndims = d->ndims;
for (size_t i = 0; i < ndims; i++)
ret = (ret * d->dims[i]) + coords[ndims - i - 1];
return ret;
}
int aml_tiling_resize_row_order(const struct aml_tiling_data *t)
{
(void)t;
return AML_TILING_ORDER_ROW_MAJOR;
}
int aml_tiling_resize_row_tile_dims(const struct aml_tiling_data *t,
size_t *tile_dims)
{
const struct aml_tiling_resize *d =
(const struct aml_tiling_resize *)t;
assert(d != NULL);
for (size_t i = 0; i < d->ndims; i++)
tile_dims[i] = d->tile_dims[d->ndims - i - 1];
return 0;
}
int aml_tiling_resize_row_dims(const struct aml_tiling_data *t,
size_t *dims)
{
......@@ -401,9 +345,7 @@ struct aml_tiling_ops aml_tiling_resize_row_ops = {
aml_tiling_resize_row_index,
aml_tiling_resize_column_index,
aml_tiling_resize_row_rawptr,
aml_tiling_resize_row_tileid,
aml_tiling_resize_row_order,
aml_tiling_resize_row_tile_dims,
aml_tiling_resize_row_dims,
aml_tiling_resize_column_dims,
aml_tiling_resize_row_ndims,
......
......@@ -169,7 +169,7 @@ void test_tiling_even(void)
size_t dims[3];
aml_tiling_tile_dims(t, dims);
aml_tiling_tile_dims(t, NULL, dims);
assert(memcmp(dims, dims_tile_col, 3*sizeof(size_t)) == 0);
aml_tiling_dims(t, dims);
assert(memcmp(dims, expected_dims_col, 3*sizeof(size_t)) == 0);
......@@ -212,7 +212,7 @@ void test_tiling_even(void)
assert(aml_tiling_order(t) == AML_TILING_ORDER_ROW_MAJOR);
assert(aml_tiling_ndims(t) == 3);
aml_tiling_tile_dims(t, dims);
aml_tiling_tile_dims(t, NULL, dims);
assert(memcmp(dims, dims_tile_row, 3*sizeof(size_t)) == 0);
aml_tiling_dims(t, dims);
assert(memcmp(dims, expected_dims_row, 3*sizeof(size_t)) == 0);
......@@ -373,7 +373,7 @@ void test_tiling_uneven(void)
size_t dims[3];
aml_tiling_tile_dims(t, dims);
aml_tiling_tile_dims(t, NULL, dims);
assert(memcmp(dims, dims_tile_col, 3*sizeof(size_t)) == 0);
aml_tiling_dims(t, dims);
assert(memcmp(dims, expected_dims_col, 3*sizeof(size_t)) == 0);
......@@ -415,7 +415,7 @@ void test_tiling_uneven(void)
assert(aml_tiling_order(t) == AML_TILING_ORDER_ROW_MAJOR);
assert(aml_tiling_ndims(t) == 3);
aml_tiling_tile_dims(t, dims);
aml_tiling_tile_dims(t, NULL, dims);
assert(memcmp(dims, dims_tile_row, 3*sizeof(size_t)) == 0);
aml_tiling_dims(t, dims);
assert(memcmp(dims, expected_dims_row, 3*sizeof(size_t)) == 0);
......@@ -498,7 +498,7 @@ void test_tiling_pad_even(void)
size_t dims[3];
aml_tiling_tile_dims(t, dims);
aml_tiling_tile_dims(t, NULL, dims);
assert(memcmp(dims, dims_tile_col, 3*sizeof(size_t)) == 0);
aml_tiling_dims(t, dims);
assert(memcmp(dims, expected_dims_col, 3*sizeof(size_t)) == 0);
......@@ -540,7 +540,7 @@ void test_tiling_pad_even(void)
assert(aml_tiling_order(t) == AML_TILING_ORDER_ROW_MAJOR);
assert(aml_tiling_ndims(t) == 3);
aml_tiling_tile_dims(t, dims);
aml_tiling_tile_dims(t, NULL, dims);
assert(memcmp(dims, dims_tile_row, 3*sizeof(size_t)) == 0);
aml_tiling_dims(t, dims);
assert(memcmp(dims, expected_dims_row, 3*sizeof(size_t)) == 0);
......@@ -628,7 +628,7 @@ void test_tiling_pad_uneven(void)
size_t dims[3];
aml_tiling_tile_dims(t, dims);
aml_tiling_tile_dims(t, NULL, dims);
assert(memcmp(dims, dims_tile_col, 3*sizeof(size_t)) == 0);
aml_tiling_dims(t, dims);
assert(memcmp(dims, expected_dims_col, 3*sizeof(size_t)) == 0);
......@@ -680,8 +680,7 @@ void test_tiling_pad_uneven(void)
assert(aml_tiling_order(t) == AML_TILING_ORDER_ROW_MAJOR);
assert(aml_tiling_ndims(t) == 3);
aml_tiling_tile_dims(t, dims);
aml_tiling_tile_dims(t, NULL, dims);
assert(memcmp(dims, dims_tile_row, 3*sizeof(size_t)) == 0);
aml_tiling_dims(t, dims);
assert(memcmp(dims, expected_dims_row, 3*sizeof(size_t)) == 0);
......
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