Commit dfac0800 authored by Swann Perarnau's avatar Swann Perarnau

[feature] add padded tilings

Continue the work of merging the new tilings API, now with padded
tilings.
parent c11701cd
...@@ -24,6 +24,7 @@ include_aml_scratch_HEADERS = \ ...@@ -24,6 +24,7 @@ include_aml_scratch_HEADERS = \
include_aml_tilingdir=$(includedir)/aml/tiling include_aml_tilingdir=$(includedir)/aml/tiling
include_aml_tiling_HEADERS = \ include_aml_tiling_HEADERS = \
aml/tiling/native.h \ aml/tiling/native.h \
aml/tiling/pad.h \
aml/tiling/resize.h aml/tiling/resize.h
......
/*******************************************************************************
* Copyright 2019 UChicago Argonne, LLC.
* (c.f. AUTHORS, LICENSE)
*
* This file is part of the AML project.
* For more info, see https://xgitlab.cels.anl.gov/argo/aml
*
* SPDX-License-Identifier: BSD-3-Clause
*******************************************************************************/
#ifndef AML_TILING_PAD_H
#define AML_TILING_PAD_H 1
/**
* @defgroup aml_tiling_pad "AML Padded Tiling"
* @brief tiling with padding at the border
*
* Implementation of a tiling for which the border tiles are padded up to the
* requested size.
* @{
**/
/** Initialized structure containing operations for a tiling in column order.**/
extern struct aml_tiling_ops aml_tiling_pad_column_ops;
/** Initialized structure containing operations for a tiling in row order. **/
extern struct aml_tiling_ops aml_tiling_pad_row_ops;
struct aml_tiling_pad {
int tags;
const struct aml_layout *layout;
size_t ndims;
size_t *tile_dims;
size_t *dims;
size_t *border_tile_dims;
size_t *pad;
void *neutral;
};
int aml_tiling_pad_create(struct aml_tiling **t, int tags,
const struct aml_layout *l, size_t ndims,
const size_t *tile_dims, void *neutral);
void aml_tiling_pad_destroy(struct aml_tiling **t);
/**
* @}
**/
#endif /* AML_TILING_PAD_H */
...@@ -28,6 +28,7 @@ SCRATCH_SOURCES = \ ...@@ -28,6 +28,7 @@ SCRATCH_SOURCES = \
TILING_SOURCES = \ TILING_SOURCES = \
tiling/tiling.c \ tiling/tiling.c \
tiling/tiling_pad.c \
tiling/tiling_resize.c tiling/tiling_resize.c
UTILS_SOURCES = \ UTILS_SOURCES = \
......
This diff is collapsed.
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "aml/layout/dense.h" #include "aml/layout/dense.h"
#include "aml/layout/native.h" #include "aml/layout/native.h"
#include "aml/tiling/resize.h" #include "aml/tiling/resize.h"
#include "aml/tiling/pad.h"
#include <assert.h> #include <assert.h>
void test_tiling_even_mixed(void) void test_tiling_even_mixed(void)
...@@ -353,6 +354,267 @@ void test_tiling_uneven(void) ...@@ -353,6 +354,267 @@ void test_tiling_uneven(void)
aml_tiling_resize_destroy(&tres); aml_tiling_resize_destroy(&tres);
} }
void test_tiling_pad_even(void)
{
int memory[9][10][8];
int memoryres[9][10][8];
size_t dims_col[3] = {8, 10, 9};
size_t dims_row[3] = {9, 10, 8};
size_t stride[3] = {1, 1, 1};
size_t dims_tile_col[3] = {4, 10, 3};
size_t dims_tile_row[3] = {3, 10, 4};
size_t expected_dims_col[3] = {2, 1, 3};
size_t expected_dims_row[3] = {3, 1, 2};
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;
int neutral = 0xdeadbeef;
aml_tiling_pad_create(&t, AML_TILING_ORDER_COLUMN_MAJOR,
a, 3, dims_tile_col, &neutral);
aml_tiling_pad_create(&tres, AML_TILING_ORDER_COLUMN_MAJOR,
ares, 3, dims_tile_col, &neutral);
assert(aml_tiling_order(t) == AML_TILING_ORDER_COLUMN_MAJOR);
assert(aml_tiling_ndims(t) == 3);
size_t dims[3];
aml_tiling_tile_dims(t, 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);
for (size_t i = 0; i < expected_dims_col[2]; i++)
for (size_t j = 0; j < expected_dims_col[1]; j++)
for (size_t k = 0; k < expected_dims_col[0]; k++) {
struct aml_layout *b, *bres;
b = aml_tiling_index(t, (size_t[]){k, j, i});
bres = aml_tiling_index(tres,
(size_t[]){k, j, i});
aml_copy_layout_generic(bres, b, NULL);
free(b);
free(bres);
}
assert(memcmp(memory, memoryres, 8 * 10 * 9 * sizeof(int)) == 0);
aml_layout_dense_destroy(&a);
aml_layout_dense_destroy(&ares);
aml_tiling_pad_destroy(&t);
aml_tiling_pad_destroy(&tres);
aml_layout_dense_create(&a, memory,
AML_LAYOUT_ORDER_ROW_MAJOR,
sizeof(int), 3, dims_row, stride, dims_row);
aml_layout_dense_create(&ares, memoryres,
AML_LAYOUT_ORDER_ROW_MAJOR,
sizeof(int), 3, dims_row, stride, dims_row);
aml_tiling_pad_create(&t, AML_TILING_ORDER_ROW_MAJOR,
a, 3, dims_tile_row, &neutral);
aml_tiling_pad_create(&tres, AML_TILING_ORDER_ROW_MAJOR,
ares, 3, dims_tile_row, &neutral);
assert(aml_tiling_order(t) == AML_TILING_ORDER_ROW_MAJOR);
assert(aml_tiling_ndims(t) == 3);
aml_tiling_tile_dims(t, 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);
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++)
memoryres[i][j][k] = 0.0;
for (size_t i = 0; i < expected_dims_col[2]; i++)
for (size_t j = 0; j < expected_dims_col[1]; j++)
for (size_t k = 0; k < expected_dims_col[0]; k++) {
struct aml_layout *b, *bres;
b = aml_tiling_index(t, (size_t[]){i, j, k});
bres = aml_tiling_index(tres,
(size_t[]){i, j, k});
aml_copy_layout_generic(bres, b, NULL);
free(b);
free(bres);
}
assert(memcmp(memory, memoryres, 8 * 10 * 9 * sizeof(int)) == 0);
aml_layout_dense_destroy(&a);
aml_layout_dense_destroy(&ares);
aml_tiling_pad_destroy(&t);
aml_tiling_pad_destroy(&tres);
}
void test_tiling_pad_uneven(void)
{
int memory[8][10][7];
int memoryres[9][10][8];
size_t dims_col[3] = {7, 10, 8};
size_t dims_row[3] = {8, 10, 7};
size_t dims_col_res[3] = {8, 10, 9};
size_t dims_row_res[3] = {9, 10, 8};
size_t stride[3] = {1, 1, 1};
size_t dims_tile_col[3] = {4, 10, 3};
size_t dims_tile_row[3] = {3, 10, 4};
size_t expected_dims_col[3] = {2, 1, 3};
size_t expected_dims_row[3] = {3, 1, 2};
int l = 0;
for (size_t i = 0; i < 8; i++)
for (size_t j = 0; j < 10; j++)
for (size_t k = 0; k < 7; k++, l++)
memory[i][j][k] = l;
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++)
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_res,
stride, dims_col_res);
struct aml_tiling *t, *tres;
int neutral = 0xdeadbeef;
aml_tiling_pad_create(&t, AML_TILING_ORDER_COLUMN_MAJOR,
a, 3, dims_tile_col, &neutral);
aml_tiling_pad_create(&tres, AML_TILING_ORDER_COLUMN_MAJOR,
ares, 3, dims_tile_col, &neutral);
assert(aml_tiling_order(t) == AML_TILING_ORDER_COLUMN_MAJOR);
assert(aml_tiling_ndims(t) == 3);
size_t dims[3];
aml_tiling_tile_dims(t, 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);
for (size_t i = 0; i < expected_dims_col[2]; i++)
for (size_t j = 0; j < expected_dims_col[1]; j++)
for (size_t k = 0; k < expected_dims_col[0]; k++) {
struct aml_layout *b, *bres;
b = aml_tiling_index(t, (size_t[]){k, j, i});
bres = aml_tiling_index(tres,
(size_t[]){k, j, i});
aml_copy_layout_generic(bres, b, NULL);
free(b);
free(bres);
}
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++)
if (k >= 7 || i >= 8)
assert(memoryres[i][j][k] ==
neutral);
else
assert(memoryres[i][j][k] ==
memory[i][j][k]);
aml_layout_dense_destroy(&a);
aml_layout_dense_destroy(&ares);
aml_tiling_pad_destroy(&t);
aml_tiling_pad_destroy(&tres);
aml_layout_dense_create(&a, memory,
AML_LAYOUT_ORDER_ROW_MAJOR,
sizeof(int), 3, dims_row, stride, dims_row);
aml_layout_dense_create(&ares, memoryres,
AML_LAYOUT_ORDER_ROW_MAJOR,
sizeof(int), 3, dims_row_res,
stride, dims_row_res);
aml_tiling_pad_create(&t, AML_TILING_ORDER_ROW_MAJOR,
a, 3, dims_tile_row, &neutral);
aml_tiling_pad_create(&tres, AML_TILING_ORDER_ROW_MAJOR,
ares, 3, dims_tile_row, &neutral);
assert(aml_tiling_order(t) == AML_TILING_ORDER_ROW_MAJOR);
assert(aml_tiling_ndims(t) == 3);
aml_tiling_tile_dims(t, 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);
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++)
memoryres[i][j][k] = 0.0;
for (size_t i = 0; i < expected_dims_col[2]; i++)
for (size_t j = 0; j < expected_dims_col[1]; j++)
for (size_t k = 0; k < expected_dims_col[0]; k++) {
struct aml_layout *b, *bres;
b = aml_tiling_index(t, (size_t[]){i, j, k});
bres = aml_tiling_index(tres,
(size_t[]){i, j, k});
aml_copy_layout_generic(bres, b, NULL);
free(b);
free(bres);
}
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++)
if (k >= 7 || i >= 8)
assert(memoryres[i][j][k] ==
neutral);
else
assert(memoryres[i][j][k] ==
memory[i][j][k]);
aml_layout_dense_destroy(&a);
aml_layout_dense_destroy(&ares);
aml_tiling_pad_destroy(&t);
aml_tiling_pad_destroy(&tres);
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
/* library initialization */ /* library initialization */
...@@ -361,7 +623,10 @@ int main(int argc, char *argv[]) ...@@ -361,7 +623,10 @@ int main(int argc, char *argv[])
test_tiling_even(); test_tiling_even();
test_tiling_uneven(); test_tiling_uneven();
test_tiling_even_mixed(); test_tiling_even_mixed();
test_tiling_pad_even();
test_tiling_pad_uneven();
aml_finalize();
return 0; 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