Commit d4fa5289 authored by Swann Perarnau's avatar Swann Perarnau

[refactor] remove tiling_2d, rename 2d_contig

Tiling 2d and its interfaces wasn't the right way of looking at 2d grids
of tiles. Rename the contig ones to provide the required features.
parent 22d43bfd
......@@ -9,8 +9,8 @@
#include <math.h>
#include <stdlib.h>
AML_TILING_2D_CONTIG_ROWMAJOR_DECL(tiling_row);
AML_TILING_2D_CONTIG_COLMAJOR_DECL(tiling_col);
AML_TILING_2D_ROWMAJOR_DECL(tiling_row);
AML_TILING_2D_COLMAJOR_DECL(tiling_col);
AML_AREA_LINUX_DECL(slow);
AML_AREA_LINUX_DECL(fast);
......@@ -65,9 +65,9 @@ int main(int argc, char* argv[])
tilesize = sizeof(double)*T*T;
/* the initial tiling, of 2D square tiles */
assert(!aml_tiling_init(&tiling_row, AML_TILING_TYPE_2D_CONTIG_ROWMAJOR,
assert(!aml_tiling_init(&tiling_row, AML_TILING_TYPE_2D_ROWMAJOR,
tilesize, memsize, N/T , N/T));
assert(!aml_tiling_init(&tiling_col, AML_TILING_TYPE_2D_CONTIG_COLMAJOR,
assert(!aml_tiling_init(&tiling_col, AML_TILING_TYPE_2D_COLMAJOR,
tilesize, memsize, N/T , N/T));
assert(!aml_arena_jemalloc_init(&arns, AML_ARENA_JEMALLOC_TYPE_REGULAR));
......@@ -154,8 +154,8 @@ int main(int argc, char* argv[])
aml_area_free(&fast, c);
aml_area_linux_destroy(&slow);
aml_area_linux_destroy(&fast);
aml_tiling_destroy(&tiling_row, AML_TILING_TYPE_2D_CONTIG_ROWMAJOR);
aml_tiling_destroy(&tiling_col, AML_TILING_TYPE_2D_CONTIG_ROWMAJOR);
aml_tiling_destroy(&tiling_row, AML_TILING_TYPE_2D_ROWMAJOR);
aml_tiling_destroy(&tiling_col, AML_TILING_TYPE_2D_ROWMAJOR);
aml_finalize();
return 0;
}
......@@ -9,8 +9,8 @@
#include <math.h>
#include <stdlib.h>
AML_TILING_2D_CONTIG_ROWMAJOR_DECL(tiling_row);
AML_TILING_2D_CONTIG_COLMAJOR_DECL(tiling_col);
AML_TILING_2D_ROWMAJOR_DECL(tiling_row);
AML_TILING_2D_COLMAJOR_DECL(tiling_col);
AML_TILING_1D_DECL(tiling_prefetch);
AML_AREA_LINUX_DECL(slow);
AML_AREA_LINUX_DECL(fast);
......@@ -85,9 +85,9 @@ int main(int argc, char* argv[])
tilesize = sizeof(double)*T*T;
/* the initial tiling, 2d grid of tiles */
assert(!aml_tiling_init(&tiling_row, AML_TILING_TYPE_2D_CONTIG_ROWMAJOR,
assert(!aml_tiling_init(&tiling_row, AML_TILING_TYPE_2D_ROWMAJOR,
tilesize, memsize, N/T , N/T));
assert(!aml_tiling_init(&tiling_col, AML_TILING_TYPE_2D_CONTIG_COLMAJOR,
assert(!aml_tiling_init(&tiling_col, AML_TILING_TYPE_2D_COLMAJOR,
tilesize, memsize, N/T , N/T));
/* the prefetch tiling, 1D sequence of columns of tiles */
assert(!aml_tiling_init(&tiling_prefetch, AML_TILING_TYPE_1D,
......@@ -183,8 +183,8 @@ int main(int argc, char* argv[])
aml_area_free(&fast, c);
aml_area_linux_destroy(&slow);
aml_area_linux_destroy(&fast);
aml_tiling_destroy(&tiling_row, AML_TILING_TYPE_2D_CONTIG_ROWMAJOR);
aml_tiling_destroy(&tiling_col, AML_TILING_TYPE_2D_CONTIG_ROWMAJOR);
aml_tiling_destroy(&tiling_row, AML_TILING_TYPE_2D_ROWMAJOR);
aml_tiling_destroy(&tiling_col, AML_TILING_TYPE_2D_ROWMAJOR);
aml_tiling_destroy(&tiling_prefetch, AML_TILING_TYPE_1D);
aml_finalize();
return 0;
......
......@@ -12,8 +12,7 @@ AREA_POSIX_CSOURCES = area_posix.c
TILING_CSOURCES = tiling.c \
tiling_1d.c \
tiling_2d.c \
tiling_2d_contig.c
tiling_2d.c
BINDING_CSOURCES = binding.c \
binding_single.c \
......
......@@ -781,8 +781,6 @@ struct aml_tiling_ops {
int (*destroy_iterator)(struct aml_tiling_data *tiling,
struct aml_tiling_iterator *iterator);
size_t (*tilesize)(const struct aml_tiling_data *tiling, int tileid);
size_t (*tilerowsize)(const struct aml_tiling_data *tiling, int tileid);
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);
......@@ -802,24 +800,6 @@ struct aml_tiling {
*/
size_t aml_tiling_tilesize(const struct aml_tiling *tiling, int tileid);
/*
* Provides the information on the size of a tile row.
* "tiling": an initialized tiling structure.
* "tileid": an identifier of a tile (a value between 0 and the number of tiles
* minus 1).
* Returns the size of a tile row.
*/
size_t aml_tiling_tilerowsize(const struct aml_tiling *tiling, int tileid);
/*
* Provides the information on the size of a tile column.
* "tiling": an initialized tiling structure.
* "tileid": an identifier of a tile (a value between 0 and the number of tiles
* minus 1).
* Returns the size of a tile column.
*/
size_t aml_tiling_tilecolsize(const struct aml_tiling *tiling, int tileid);
/*
* Provides the information on the location of a tile in memory.
* "tiling": an initialized tiling structure.
......@@ -917,9 +897,8 @@ 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 2
#define AML_TILING_TYPE_2D_CONTIG_ROWMAJOR 3
#define AML_TILING_TYPE_2D_CONTIG_COLMAJOR 4
#define AML_TILING_TYPE_2D_ROWMAJOR 1
#define AML_TILING_TYPE_2D_COLMAJOR 2
/*
* Allocates and initializes a new tiling.
......@@ -931,13 +910,12 @@ int aml_tiling_iterator_get(const struct aml_tiling_iterator *iterator, ...);
* - "tilesize": an argument of type size_t; provides the size of each tile.
* - "totalsize": an argument of type size_t; provides the size of the
* complete user data structure to be tiled.
* - if "type" equals AML_TILING_TYPE_2D, three additional arguments are needed:
* - "rowsize": an argument of type size_t; provides the size of the row of
* each tile.
* - "columnsize": an argument of type size_t; provides the size of the column
* of each tile.
* - if "type" equals AML_TILING_TYPE_2D, four additional arguments are needed:
* - "tilesize": an argument of type size_t; provides the size of a tile.
* - "totalsize": an argument of type size_t; provides the size of the
* complete user data structure to be tiled.
* - "rowsize": an argument of type size_t; the number of tiles in a row
* - "colsize": an argument of type size_t; the number of tiles in a column
* Returns 0 if successful; an error code otherwise.
*/
int aml_tiling_create(struct aml_tiling **tiling, int type, ...);
......@@ -1006,16 +984,17 @@ struct aml_tiling_iterator_1d_data {
/*******************************************************************************
* Tiling 2D:
* a contiguous memory area composed of contiguous tiles arranged in 2D grid.
******************************************************************************/
extern struct aml_tiling_ops aml_tiling_2d_ops;
extern struct aml_tiling_ops aml_tiling_2d_rowmajor_ops;
extern struct aml_tiling_ops aml_tiling_2d_colmajor_ops;
extern struct aml_tiling_iterator_ops aml_tiling_iterator_2d_ops;
struct aml_tiling_2d_data {
size_t blocksize;
size_t tilerowsize;
size_t tilecolsize;
size_t totalsize;
size_t ndims[2]; /* # number of rows, # number of cols (in tiles) */
};
struct aml_tiling_iterator_2d_data {
......@@ -1023,10 +1002,17 @@ struct aml_tiling_iterator_2d_data {
struct aml_tiling_2d_data *tiling;
};
#define AML_TILING_2D_DECL(name) \
#define AML_TILING_2D_ROWMAJOR_DECL(name) \
struct aml_tiling_2d_data __ ##name## _inner_data; \
struct aml_tiling name = { \
&aml_tiling_2d_rowmajor_ops, \
(struct aml_tiling_data *)&__ ## name ## _inner_data, \
};
#define AML_TILING_2D_COLMAJOR_DECL(name) \
struct aml_tiling_2d_data __ ##name## _inner_data; \
struct aml_tiling name = { \
&aml_tiling_2d_ops, \
&aml_tiling_2d_colmajor_ops, \
(struct aml_tiling_data *)&__ ## name ## _inner_data, \
};
......@@ -1044,54 +1030,6 @@ 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_rowmajor_ops;
extern struct aml_tiling_ops aml_tiling_2d_contig_colmajor_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_ROWMAJOR_DECL(name) \
struct aml_tiling_2d_contig_data __ ##name## _inner_data; \
struct aml_tiling name = { \
&aml_tiling_2d_contig_rowmajor_ops, \
(struct aml_tiling_data *)&__ ## name ## _inner_data, \
};
#define AML_TILING_2D_CONTIG_COLMAJOR_DECL(name) \
struct aml_tiling_2d_contig_data __ ##name## _inner_data; \
struct aml_tiling name = { \
&aml_tiling_2d_contig_colmajor_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
......
......@@ -10,18 +10,6 @@ size_t aml_tiling_tilesize(const struct aml_tiling *t, int tileid)
return t->ops->tilesize(t->data, tileid);
}
size_t aml_tiling_tilerowsize(const struct aml_tiling *t, int tileid)
{
assert(t != NULL);
return t->ops->tilerowsize(t->data, tileid);
}
size_t aml_tiling_tilecolsize(const struct aml_tiling *t, int tileid)
{
assert(t != NULL);
return t->ops->tilecolsize(t->data, tileid);
}
void* aml_tiling_tilestart(const struct aml_tiling *t, const void *ptr, int tileid)
{
assert(t != NULL);
......@@ -128,9 +116,9 @@ int aml_tiling_create(struct aml_tiling **t, int type, ...)
err = aml_tiling_vinit(ret, type, ap);
}
else if(type == AML_TILING_TYPE_2D)
else if(type == AML_TILING_TYPE_2D_ROWMAJOR ||
type == AML_TILING_TYPE_2D_COLMAJOR)
{
/* alloc, only difference is using AML_TILING_2D_ALLOCSIZE instead fo 1D */
baseptr = (intptr_t) calloc(1, AML_TILING_2D_ALLOCSIZE);
dataptr = baseptr + sizeof(struct aml_tiling);
......@@ -139,17 +127,6 @@ 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_ROWMAJOR ||
type == AML_TILING_TYPE_2D_CONTIG_COLMAJOR)
{
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;
......@@ -169,37 +146,22 @@ 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;
}
//This is equivalent to the 1D except the arguments will be the dimensions for the tile.
//An optimization that could be made is having the exact same declaration of 1D
//The caveat is that the block size must be a perfect square. For now, we will allow non-square blocks
else if(type == AML_TILING_TYPE_2D)
else if(type == AML_TILING_TYPE_2D_ROWMAJOR)
{
t->ops = &aml_tiling_2d_ops;
t->ops = &aml_tiling_2d_rowmajor_ops;
struct aml_tiling_2d_data *data =
(struct aml_tiling_2d_data *)t->data;
data->tilerowsize = va_arg(ap, size_t);
data->tilecolsize = va_arg(ap, size_t);
data->blocksize = data->tilerowsize * data->tilecolsize / sizeof(unsigned long);
data->totalsize = va_arg(ap, size_t);
err = data->blocksize > data->totalsize;
}
else if(type == AML_TILING_TYPE_2D_CONTIG_ROWMAJOR)
{
t->ops = &aml_tiling_2d_contig_rowmajor_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;
}
else if(type == AML_TILING_TYPE_2D_CONTIG_COLMAJOR)
else if(type == AML_TILING_TYPE_2D_COLMAJOR)
{
t->ops = &aml_tiling_2d_contig_colmajor_ops;
struct aml_tiling_2d_contig_data *data =
(struct aml_tiling_2d_contig_data *)t->data;
t->ops = &aml_tiling_2d_colmajor_ops;
struct aml_tiling_2d_data *data =
(struct aml_tiling_2d_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);
......
......@@ -56,21 +56,6 @@ size_t aml_tiling_1d_tilesize(const struct aml_tiling_data *t, int tileid)
return data->blocksize;
}
//A 1-D array is technically just a multidimensional array with all dimensions except the row size equal to 1
//See aml_tiling_1d_colsize to understand.
size_t aml_tiling_1d_tilerowsize(const struct aml_tiling_data *t, int tileid)
{
const struct aml_tiling_1d_data *data =
(const struct aml_tiling_1d_data *)t;
return data->blocksize;
}
size_t aml_tiling_1d_tilecolsize(const struct aml_tiling_data *t, int tileid)
{
return 8;
}
void* aml_tiling_1d_tilestart(const struct aml_tiling_data *t, const void *ptr, int tileid)
{
const struct aml_tiling_1d_data *data =
......@@ -129,8 +114,6 @@ struct aml_tiling_ops aml_tiling_1d_ops = {
aml_tiling_1d_init_iterator,
aml_tiling_1d_destroy_iterator,
aml_tiling_1d_tilesize,
aml_tiling_1d_tilerowsize,
aml_tiling_1d_tilecolsize,
aml_tiling_1d_tilestart,
aml_tiling_1d_ndims,
};
......@@ -5,8 +5,6 @@
* 2D Iterator
******************************************************************************/
int aml_tiling_iterator_2d_reset(struct aml_tiling_iterator_data *data)
{
struct aml_tiling_iterator_2d_data *it =
......@@ -40,7 +38,6 @@ int aml_tiling_iterator_2d_get(const struct aml_tiling_iterator_data *data,
return 0;
}
struct aml_tiling_iterator_ops aml_tiling_iterator_2d_ops = {
aml_tiling_iterator_2d_reset,
aml_tiling_iterator_2d_next,
......@@ -50,6 +47,7 @@ struct aml_tiling_iterator_ops aml_tiling_iterator_2d_ops = {
/*******************************************************************************
* 2D ops
* Tileids are always in rowmajor: for NM matrix[i][j], tileid = i*M + j
******************************************************************************/
size_t aml_tiling_2d_tilesize(const struct aml_tiling_data *t, int tileid)
......@@ -59,26 +57,33 @@ size_t aml_tiling_2d_tilesize(const struct aml_tiling_data *t, int tileid)
return data->blocksize;
}
size_t aml_tiling_2d_tilerowsize(const struct aml_tiling_data *t, int tileid)
void* aml_tiling_2d_rowmajor_tilestart(const struct aml_tiling_data *t,
const void *ptr, int tileid)
{
const struct aml_tiling_2d_data *data =
(const struct aml_tiling_2d_data *)t;
return data->tilerowsize;
}
size_t aml_tiling_2d_tilecolsize(const struct aml_tiling_data *t, int tileid)
{
const struct aml_tiling_2d_data *data =
(const struct aml_tiling_2d_data *)t;
return data->tilecolsize;
intptr_t p = (intptr_t)ptr;
size_t i = tileid/data->ndims[1];
size_t j = tileid % data->ndims[1];
if(i >= data->ndims[0] || j >= data->ndims[1])
return NULL;
else
return (void *)(p + tileid*data->blocksize);
}
void* aml_tiling_2d_tilestart(const struct aml_tiling_data *t, const void *ptr, int tileid)
void* aml_tiling_2d_colmajor_tilestart(const struct aml_tiling_data *t,
const void *ptr, int tileid)
{
const struct aml_tiling_2d_data *data =
(const struct aml_tiling_2d_data *)t;
intptr_t p = (intptr_t)ptr;
return (void *)(p + tileid*data->blocksize);
size_t i = tileid/data->ndims[1];
size_t j = tileid % data->ndims[1];
size_t offset = j*data->ndims[0] + i;
if(i >= data->ndims[0] || j >= data->ndims[1])
return NULL;
else
return (void *)(p + offset*data->blocksize);
}
int aml_tiling_2d_ndims(const struct aml_tiling_data *t, va_list ap)
......@@ -88,17 +93,16 @@ int aml_tiling_2d_ndims(const struct aml_tiling_data *t, va_list ap)
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);
*x = data->ndims[0];
*y = data->ndims[1];
return 0;
}
int aml_tiling_2d_init_iterator(struct aml_tiling_data *t,
struct aml_tiling_iterator *it, int flags)
{
assert(it->data != NULL);
struct aml_tiling_iterator_1d_data *data =
struct aml_tiling_iterator_2d_data *data =
(struct aml_tiling_iterator_2d_data *)it->data;
it->ops = &aml_tiling_iterator_2d_ops;
data->i = 0;
......@@ -106,8 +110,6 @@ int aml_tiling_2d_init_iterator(struct aml_tiling_data *t,
return 0;
}
int aml_tiling_2d_create_iterator(struct aml_tiling_data *t,
struct aml_tiling_iterator **it, int flags)
{
......@@ -132,12 +134,20 @@ int aml_tiling_2d_destroy_iterator(struct aml_tiling_data *t,
}
struct aml_tiling_ops aml_tiling_2d_ops = {
struct aml_tiling_ops aml_tiling_2d_rowmajor_ops = {
aml_tiling_2d_create_iterator,
aml_tiling_2d_init_iterator,
aml_tiling_2d_destroy_iterator,
aml_tiling_2d_tilesize,
aml_tiling_2d_rowmajor_tilestart,
aml_tiling_2d_ndims,
};
struct aml_tiling_ops aml_tiling_2d_colmajor_ops = {
aml_tiling_2d_create_iterator,
aml_tiling_2d_init_iterator,
aml_tiling_2d_destroy_iterator,
aml_tiling_2d_tilesize,
aml_tiling_2d_tilerowsize,
aml_tiling_2d_tilecolsize,
aml_tiling_2d_tilestart,
aml_tiling_2d_colmajor_tilestart,
aml_tiling_2d_ndims,
};
#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
* Tileids are always in rowmajor: for NM matrix[i][j], tileid = i*M + j
******************************************************************************/
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_rowmajor_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;
size_t i = tileid/data->ndims[1];
size_t j = tileid % data->ndims[1];
if(i >= data->ndims[0] || j >= data->ndims[1])
return NULL;
else
return (void *)(p + tileid*data->blocksize);
}
void* aml_tiling_2d_contig_colmajor_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;
size_t i = tileid/data->ndims[1];
size_t j = tileid % data->ndims[1];
size_t offset = j*data->ndims[0] + i;
if(i >= data->ndims[0] || j >= data->ndims[1])
return NULL;
else
return (void *)(p + offset*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_rowmajor_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_rowmajor_tilestart,
aml_tiling_2d_contig_ndims,
};
struct aml_tiling_ops aml_tiling_2d_contig_colmajor_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_colmajor_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