Commit 508c4695 authored by Swann Perarnau's avatar Swann Perarnau
Browse files

[feature] add 2d tiling of contiguous tiles

Add a tiling representing a 2d array of contiguous tiles. Also add a
ndims function to retrieve the dimensions in tiles of the tiling.

It also became quite obvious that the iterators are useless right now.
We should think about changing that.
parent 0da98aca
......@@ -10,7 +10,10 @@ AREA_LINUX_CSOURCES = area_linux.c \
AREA_POSIX_CSOURCES = area_posix.c
TILING_CSOURCES = tiling.c tiling_1d.c tiling_2d.c
TILING_CSOURCES = tiling.c \
tiling_1d.c \
tiling_2d.c \
tiling_2d_contig.c
BINDING_CSOURCES = binding.c \
binding_single.c \
......
......@@ -773,6 +773,7 @@ struct aml_tiling_ops {
size_t (*tilecolsize)(const struct aml_tiling_data *tiling, int tileid);
void* (*tilestart)(const struct aml_tiling_data *tiling,
const void *ptr, int tileid);
int (*ndims)(const struct aml_tiling_data *tiling, va_list);
};
struct aml_tiling {
......@@ -820,6 +821,16 @@ size_t aml_tiling_tilecolsize(const struct aml_tiling *tiling, int tileid);
void* aml_tiling_tilestart(const struct aml_tiling *tiling, const void *ptr,
int tileid);
/*
* Provides the dimensions of the entire tiling in tiles.
* "tiling": an initialized tiling structure.
* Variadic arguments:
* - a list of (size_t *), one per dimension of the tiling.
* Will contain the size of each dimension in tiles upon return.
* Returns 0 if successful, an error code otherwise.
*/
int aml_tiling_ndims(const struct aml_tiling *tiling, ...);
/*
* Allocates and initializes a new tiling iterator.
* "tiling": an initialized tiling structure.
......@@ -894,6 +905,7 @@ int aml_tiling_iterator_get(const struct aml_tiling_iterator *iterator, ...);
/* Tiling types passed to the tiling create()/init()/vinit() routines. */
/* Regular, linear tiling with uniform tile sizes. */
#define AML_TILING_TYPE_1D 0
#define AML_TILING_TYPE_2D_CONTIG 1
#define AML_TILING_TYPE_2D 2
/*
......@@ -1019,6 +1031,46 @@ struct aml_tiling_iterator_2d_data {
(sizeof(struct aml_tiling_iterator_2d_data) + \
sizeof(struct aml_tiling_iterator))
/*******************************************************************************
* Tiling 2D CONTIG:
* a contiguous memory area composed of contiguous tiles arranged in 2D grid.
******************************************************************************/
extern struct aml_tiling_ops aml_tiling_2d_contig_ops;
extern struct aml_tiling_iterator_ops aml_tiling_iterator_2d_contig_ops;
struct aml_tiling_2d_contig_data {
size_t blocksize;
size_t totalsize;
size_t ndims[2]; /* # of rows in tiles, # of columns in tiles */
};
struct aml_tiling_iterator_2d_contig_data {
size_t i;
struct aml_tiling_2d_contig_data *tiling;
};
#define AML_TILING_2D_CONTIG_DECL(name) \
struct aml_tiling_2d_contig_data __ ##name## _inner_data; \
struct aml_tiling name = { \
&aml_tiling_2d_contig_ops, \
(struct aml_tiling_data *)&__ ## name ## _inner_data, \
};
#define AML_TILING_ITERATOR_2D_CONTIG_DECL(name) \
struct aml_tiling_iterator_2d_contig_data __ ##name## _inner_data; \
struct aml_tiling_iterator name = { \
&aml_tiling_iterator_2d_contig_ops, \
(struct aml_tiling_iterator_data *)&__ ## name ## _inner_data, \
};
#define AML_TILING_2D_CONTIG_ALLOCSIZE (sizeof(struct aml_tiling_2d_contig_data) + \
sizeof(struct aml_tiling))
#define AML_TILING_ITERATOR_2D_CONTIG_ALLOCSIZE \
(sizeof(struct aml_tiling_iterator_2d_contig_data) + \
sizeof(struct aml_tiling_iterator))
/*******************************************************************************
* Binding:
* Representation of page bindings in an area
......
......@@ -28,6 +28,17 @@ void* aml_tiling_tilestart(const struct aml_tiling *t, const void *ptr, int tile
return t->ops->tilestart(t->data, ptr, tileid);
}
int aml_tiling_ndims(const struct aml_tiling *t, ...)
{
assert(t != NULL);
va_list ap;
int err;
va_start(ap, t);
err = t->ops->ndims(t->data, ap);
va_end(ap);
return err;
}
/*******************************************************************************
* Tiling Iterator functions
******************************************************************************/
......@@ -128,6 +139,16 @@ int aml_tiling_create(struct aml_tiling **t, int type, ...)
err = aml_tiling_vinit(ret, type, ap);
}
else if(type == AML_TILING_TYPE_2D_CONTIG)
{
baseptr = (intptr_t) calloc(1, AML_TILING_2D_CONTIG_ALLOCSIZE);
dataptr = baseptr + sizeof(struct aml_tiling);
ret = (struct aml_tiling *)baseptr;
ret->data = (struct aml_tiling_data *)dataptr;
err = aml_tiling_vinit(ret, type, ap);
}
va_end(ap);
*t = ret;
......@@ -162,6 +183,17 @@ int aml_tiling_vinit(struct aml_tiling *t, int type, va_list ap)
data->totalsize = va_arg(ap, size_t);
err = data->blocksize > data->totalsize;
}
else if(type == AML_TILING_TYPE_2D_CONTIG)
{
t->ops = &aml_tiling_2d_contig_ops;
struct aml_tiling_2d_contig_data *data =
(struct aml_tiling_2d_contig_data *)t->data;
data->blocksize = va_arg(ap, size_t);
data->totalsize = va_arg(ap, size_t);
data->ndims[0] = va_arg(ap, size_t);
data->ndims[1] = va_arg(ap, size_t);
err = data->blocksize > data->totalsize;
}
return err;
}
......
......@@ -79,6 +79,17 @@ void* aml_tiling_1d_tilestart(const struct aml_tiling_data *t, const void *ptr,
return (void *)(p + tileid*data->blocksize);
}
int aml_tiling_1d_ndims(const struct aml_tiling_data *t, va_list ap)
{
const struct aml_tiling_1d_data *data =
(const struct aml_tiling_1d_data *)t;
size_t *x = va_arg(ap, size_t *);
*x = data->totalsize/data->blocksize;
if(data->totalsize % data->blocksize != 0)
*x++;
return 0;
}
int aml_tiling_1d_init_iterator(struct aml_tiling_data *t,
struct aml_tiling_iterator *it, int flags)
{
......@@ -121,4 +132,5 @@ struct aml_tiling_ops aml_tiling_1d_ops = {
aml_tiling_1d_tilerowsize,
aml_tiling_1d_tilecolsize,
aml_tiling_1d_tilestart,
aml_tiling_1d_ndims,
};
......@@ -81,6 +81,18 @@ void* aml_tiling_2d_tilestart(const struct aml_tiling_data *t, const void *ptr,
return (void *)(p + tileid*data->blocksize);
}
int aml_tiling_2d_ndims(const struct aml_tiling_data *t, va_list ap)
{
const struct aml_tiling_2d_data *data =
(const struct aml_tiling_2d_data *)t;
size_t *x = va_arg(ap, size_t *);
size_t *y = va_arg(ap, size_t *);
/* looks totally wrong */
*x = data->totalsize/(data->blocksize*data->tilecolsize);
*y = data->totalsize/(data->blocksize*data->tilerowsize);
return 0;
}
int aml_tiling_2d_init_iterator(struct aml_tiling_data *t,
struct aml_tiling_iterator *it, int flags)
......
#include <aml.h>
#include <assert.h>
/*******************************************************************************
* 2D Iterator
******************************************************************************/
int aml_tiling_iterator_2d_contig_reset(struct aml_tiling_iterator_data *data)
{
struct aml_tiling_iterator_2d_contig_data *it =
(struct aml_tiling_iterator_2d_contig_data *)data;
it->i = 0;
return 0;
}
int aml_tiling_iterator_2d_contig_end(const struct aml_tiling_iterator_data *data)
{
const struct aml_tiling_iterator_2d_contig_data *it =
(const struct aml_tiling_iterator_2d_contig_data *)data;
return it->i * it->tiling->blocksize >= it->tiling->totalsize;
}
int aml_tiling_iterator_2d_contig_next(struct aml_tiling_iterator_data *data)
{
struct aml_tiling_iterator_2d_contig_data *it =
(struct aml_tiling_iterator_2d_contig_data *)data;
it->i++;
return 0;
}
int aml_tiling_iterator_2d_contig_get(const struct aml_tiling_iterator_data *data,
va_list args)
{
const struct aml_tiling_iterator_2d_contig_data *it =
(const struct aml_tiling_iterator_2d_contig_data *)data;
unsigned long *x = va_arg(args, unsigned long *);
*x = it->i;
return 0;
}
struct aml_tiling_iterator_ops aml_tiling_iterator_2d_contig_ops = {
aml_tiling_iterator_2d_contig_reset,
aml_tiling_iterator_2d_contig_next,
aml_tiling_iterator_2d_contig_end,
aml_tiling_iterator_2d_contig_get,
};
/*******************************************************************************
* 2D ops
******************************************************************************/
size_t aml_tiling_2d_contig_tilesize(const struct aml_tiling_data *t, int tileid)
{
const struct aml_tiling_2d_contig_data *data =
(const struct aml_tiling_2d_contig_data *)t;
return data->blocksize;
}
void* aml_tiling_2d_contig_tilestart(const struct aml_tiling_data *t, const void *ptr, int tileid)
{
const struct aml_tiling_2d_contig_data *data =
(const struct aml_tiling_2d_contig_data *)t;
intptr_t p = (intptr_t)ptr;
return (void *)(p + tileid*data->blocksize);
}
int aml_tiling_2d_contig_ndims(const struct aml_tiling_data *t, va_list ap)
{
const struct aml_tiling_2d_contig_data *data =
(const struct aml_tiling_2d_contig_data *)t;
size_t *x = va_arg(ap, size_t *);
size_t *y = va_arg(ap, size_t *);
/* looks totally wrong */
*x = data->ndims[0];
*y = data->ndims[1];
return 0;
}
int aml_tiling_2d_contig_init_iterator(struct aml_tiling_data *t,
struct aml_tiling_iterator *it, int flags)
{
assert(it->data != NULL);
struct aml_tiling_iterator_2d_contig_data *data =
(struct aml_tiling_iterator_2d_contig_data *)it->data;
it->ops = &aml_tiling_iterator_2d_contig_ops;
data->i = 0;
data->tiling = (struct aml_tiling_2d_contig_data *)t;
return 0;
}
int aml_tiling_2d_contig_create_iterator(struct aml_tiling_data *t,
struct aml_tiling_iterator **it, int flags)
{
intptr_t baseptr, dataptr;
struct aml_tiling_iterator *ret;
baseptr = (intptr_t) calloc(1, AML_TILING_ITERATOR_2D_CONTIG_ALLOCSIZE);
dataptr = baseptr + sizeof(struct aml_tiling_iterator);
ret = (struct aml_tiling_iterator *)baseptr;
ret->data = (struct aml_tiling_iterator_data *)dataptr;
aml_tiling_2d_contig_init_iterator(t, ret, flags);
*it = ret;
return 0;
}
int aml_tiling_2d_contig_destroy_iterator(struct aml_tiling_data *t,
struct aml_tiling_iterator *it)
{
return 0;
}
struct aml_tiling_ops aml_tiling_2d_contig_ops = {
aml_tiling_2d_contig_create_iterator,
aml_tiling_2d_contig_init_iterator,
aml_tiling_2d_contig_destroy_iterator,
aml_tiling_2d_contig_tilesize,
NULL,
NULL,
aml_tiling_2d_contig_tilestart,
aml_tiling_2d_contig_ndims,
};
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