tiling_1d.c 3.28 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <aml.h>
#include <assert.h>

/*******************************************************************************
 * 1D Iterator
 ******************************************************************************/

int aml_tiling_iterator_1d_reset(struct aml_tiling_iterator_data *data)
{
	struct aml_tiling_iterator_1d_data *it =
		(struct aml_tiling_iterator_1d_data *)data;
	it->i = 0;
	return 0;
}

Kamil Iskra's avatar
Kamil Iskra committed
16
int aml_tiling_iterator_1d_end(const struct aml_tiling_iterator_data *data)
17
{
Kamil Iskra's avatar
Kamil Iskra committed
18 19
	const struct aml_tiling_iterator_1d_data *it =
		(const struct aml_tiling_iterator_1d_data *)data;
20 21 22 23 24 25 26 27 28 29 30
	return it->i * it->tiling->blocksize >= it->tiling->totalsize;
}

int aml_tiling_iterator_1d_next(struct aml_tiling_iterator_data *data)
{
	struct aml_tiling_iterator_1d_data *it =
		(struct aml_tiling_iterator_1d_data *)data;
	it->i++;
	return 0;
}

Kamil Iskra's avatar
Kamil Iskra committed
31
int aml_tiling_iterator_1d_get(const struct aml_tiling_iterator_data *data,
32 33
			       va_list args)
{
Kamil Iskra's avatar
Kamil Iskra committed
34 35
	const struct aml_tiling_iterator_1d_data *it =
		(const struct aml_tiling_iterator_1d_data *)data;
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
	unsigned long *x = va_arg(args, unsigned long *);
	*x = it->i;
	return 0;
}

struct aml_tiling_iterator_ops aml_tiling_iterator_1d_ops = {
	aml_tiling_iterator_1d_reset,
	aml_tiling_iterator_1d_next,
	aml_tiling_iterator_1d_end,
	aml_tiling_iterator_1d_get,
};

/*******************************************************************************
 * 1D ops
 ******************************************************************************/

Kamil Iskra's avatar
Kamil Iskra committed
52
size_t aml_tiling_1d_tilesize(const struct aml_tiling_data *t, int tileid)
53
{
Kamil Iskra's avatar
Kamil Iskra committed
54 55
	const struct aml_tiling_1d_data *data =
		(const struct aml_tiling_1d_data *)t;
56 57 58
	return data->blocksize;
}

Kamil Iskra's avatar
Kamil Iskra committed
59
void* aml_tiling_1d_tilestart(const struct aml_tiling_data *t, const void *ptr, int tileid)
60
{
Kamil Iskra's avatar
Kamil Iskra committed
61 62
	const struct aml_tiling_1d_data *data =
		(const struct aml_tiling_1d_data *)t;
63
	intptr_t p = (intptr_t)ptr;
64
	return (void *)(p + tileid*data->blocksize);
65 66
}

67 68 69 70 71 72 73 74 75 76 77
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;
}

78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
int aml_tiling_1d_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_1d_data *)it->data;
	it->ops = &aml_tiling_iterator_1d_ops;
	data->i = 0;
	data->tiling = (struct aml_tiling_1d_data *)t;
	return 0;
}

int aml_tiling_1d_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_1D_ALLOCSIZE);
	dataptr = baseptr + sizeof(struct aml_tiling_iterator);
	
	ret = (struct aml_tiling_iterator *)baseptr;
	ret->data = (struct aml_tiling_iterator_data *)dataptr;

	aml_tiling_1d_init_iterator(t, ret, flags);
	*it = ret;
	return 0;
}

int aml_tiling_1d_destroy_iterator(struct aml_tiling_data *t,
				   struct aml_tiling_iterator *it)
{
	return 0;
}

struct aml_tiling_ops aml_tiling_1d_ops = {
	aml_tiling_1d_create_iterator,
	aml_tiling_1d_init_iterator,
	aml_tiling_1d_destroy_iterator,
	aml_tiling_1d_tilesize,
	aml_tiling_1d_tilestart,
118
	aml_tiling_1d_ndims,
119
};