Commit e443f935 authored by Swann Perarnau's avatar Swann Perarnau
Browse files

[feature] add tiling indexing by iterator

parent 3a44fa9e
......@@ -842,6 +842,16 @@ int aml_tiling_tileid(const struct aml_tiling *tiling, const size_t *coords);
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.
* @param[in] tiling: an initialized tiling
* @param[in] iterator: an initialized iterator
* @return the tile as a layout on success, NULL on error.
*/
struct aml_layout *aml_tiling_index_byiter(const struct aml_tiling *tiling,
const_excit_t iterator);
/**
* Print on the file handle the metadata associated with this tiling.
* @param stream the stream to print on
......
......@@ -110,6 +110,25 @@ struct aml_layout *aml_tiling_index_byid(const struct aml_tiling *t,
return aml_tiling_index_native(t, coords);
}
struct aml_layout *aml_tiling_index_byiter(const struct aml_tiling *t,
const_excit_t iterator)
{
if (t == NULL || t->ops == NULL || iterator == NULL)
return NULL;
ssize_t ncoords;
size_t ndims = aml_tiling_ndims(t);
assert(!excit_dimension(iterator, &ncoords));
if ((size_t)ncoords != ndims)
return NULL;
ssize_t coords[ncoords];
assert(!excit_peek(iterator, coords));
return aml_tiling_index_native(t, (size_t *)coords);
}
int aml_tiling_fprintf(FILE *stream, const char *prefix,
const struct aml_tiling *tiling)
{
......
......@@ -247,6 +247,84 @@ void test_tiling_even(void)
}
void test_tiling_excit(void)
{
int memory[9][10][8];
int memoryres[9][10][8];
size_t dims_col[3] = {8, 10, 9};
size_t stride[3] = {1, 1, 1};
size_t dims_tile_col[3] = {4, 10, 3};
int l = 0;
for (size_t i = 0; i < 9; i++)
for (size_t j = 0; j < 10; j++)
for (size_t k = 0; k < 8; k++, l++) {
memory[i][j][k] = l;
memoryres[i][j][k] = 0.0;
}
struct aml_layout *a, *ares;
aml_layout_dense_create(&a, memory, AML_LAYOUT_ORDER_COLUMN_MAJOR,
sizeof(int), 3, dims_col, stride, dims_col);
aml_layout_dense_create(&ares, memoryres, AML_LAYOUT_ORDER_COLUMN_MAJOR,
sizeof(int), 3, dims_col, stride, dims_col);
struct aml_tiling *t, *tres;
aml_tiling_resize_create(&t, AML_TILING_ORDER_COLUMN_MAJOR, a, 3,
dims_tile_col);
aml_tiling_resize_create(&tres, AML_TILING_ORDER_COLUMN_MAJOR, ares, 3,
dims_tile_col);
excit_t it, iter;
it = excit_alloc(EXCIT_RANGE);
iter = excit_alloc(EXCIT_PRODUCT);
assert(!excit_range_init(it, 0, 1, 1));
assert(!excit_product_add(iter, it));
it = excit_alloc(EXCIT_RANGE);
assert(!excit_range_init(it, 0, 0, 1));
assert(!excit_product_add(iter, it));
it = excit_alloc(EXCIT_RANGE);
assert(!excit_range_init(it, 0, 2, 1));
assert(!excit_product_add(iter, it));
for (ssize_t coords[3]; !excit_next(iter, coords);) {
struct aml_layout *b, *bres;
b = aml_tiling_index(t, (size_t *)coords);
bres = aml_tiling_index(tres, (size_t *)coords);
aml_copy_layout_generic(bres, b, NULL);
aml_layout_destroy(&b);
aml_layout_destroy(&bres);
}
assert(memcmp(memory, memoryres, 8 * 10 * 9 * sizeof(int)) == 0);
memset(memoryres, 0, 8 * 10 * 9 * sizeof(int));
assert(!excit_rewind(iter));
for (; !excit_peek(iter, NULL); excit_next(iter, NULL)) {
struct aml_layout *b, *bres;
b = aml_tiling_index_byiter(t, iter);
bres = aml_tiling_index_byiter(tres, iter);
aml_copy_layout_generic(bres, b, NULL);
aml_layout_destroy(&b);
aml_layout_destroy(&bres);
}
assert(memcmp(memory, memoryres, 8 * 10 * 9 * sizeof(int)) == 0);
excit_free(iter);
aml_layout_destroy(&a);
aml_layout_destroy(&ares);
aml_tiling_resize_destroy(&t);
aml_tiling_resize_destroy(&tres);
}
void test_tiling_uneven(void)
{
......@@ -656,6 +734,7 @@ int main(int argc, char *argv[])
test_tiling_pad_even();
test_tiling_pad_uneven();
test_tiling_excit();
aml_finalize();
return 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