binding_interleave.c 2.57 KB
Newer Older
Swann Perarnau's avatar
Swann Perarnau committed
1 2 3 4 5 6 7 8 9 10
/*******************************************************************************
 * 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
*******************************************************************************/

11
#include "aml.h"
12 13 14 15 16 17 18
#include <assert.h>

/*******************************************************************************
 * interleave Binding
 * Pages interleaved across all nodes
 ******************************************************************************/

Kamil Iskra's avatar
Kamil Iskra committed
19
int aml_binding_interleave_getinfo(const struct aml_binding_data *data,
20
			       intptr_t *start, intptr_t *end,
Kamil Iskra's avatar
Kamil Iskra committed
21
			       const struct aml_tiling *tiling, const void *ptr,
22
			       int tileid)
23 24 25
{
	assert(data != NULL);
	assert(tiling != NULL);
26 27
	size_t size = aml_tiling_tilesize(tiling, tileid);
	*start = (intptr_t) aml_tiling_tilestart(tiling, ptr, tileid);
28 29 30 31 32 33 34 35 36 37
	*end = *start + size;

	/* include first and last pages */
	*start -= *start % PAGE_SIZE;
	*end += (PAGE_SIZE - (*end % PAGE_SIZE)) % PAGE_SIZE;

	return (*end - *start) / PAGE_SIZE; 
}


Kamil Iskra's avatar
Kamil Iskra committed
38 39
int aml_binding_interleave_nbpages(const struct aml_binding_data *data,
			       const struct aml_tiling *tiling, const void *ptr,
40
			       int tileid)
41 42 43 44
{
	assert(data != NULL);
	assert(tiling != NULL);
	intptr_t start, end;
45
	return aml_binding_interleave_getinfo(data, &start, &end, tiling, ptr, tileid);
46 47
}

Kamil Iskra's avatar
Kamil Iskra committed
48 49
int aml_binding_interleave_pages(const struct aml_binding_data *data, void **pages,
			     const struct aml_tiling *tiling, const void *ptr,
50
			     int tileid)
51 52 53 54 55 56
{
	assert(data != NULL);
	assert(pages != NULL);
	assert(tiling != NULL);
	intptr_t start, end;
	int i, count;
57
	count = aml_binding_interleave_getinfo(data, &start, &end, tiling, ptr, tileid);
58 59 60 61 62
	for(i = 0; i < count; i++)
		pages[i] = (void *)(start + i * PAGE_SIZE);
	return 0;
}

Kamil Iskra's avatar
Kamil Iskra committed
63 64
int aml_binding_interleave_nodes(const struct aml_binding_data *data, int *nodes,
			     const struct aml_tiling *tiling, const void *ptr,
65
			     int tileid)
66 67 68 69 70 71 72 73
{
	assert(data != NULL);
	assert(nodes != NULL);
	assert(tiling != NULL);
	struct aml_binding_interleave_data *binding =
		(struct aml_binding_interleave_data *)data;
	intptr_t start, end;
	int i, count;
74
	count = aml_binding_interleave_getinfo(data, &start, &end, tiling, ptr, tileid);
75 76 77 78 79 80 81 82 83 84
	for(i = 0; i < count; i++)
		nodes[i] = binding->nodes[i%binding->count];
	return 0;
}

struct aml_binding_ops aml_binding_interleave_ops = {
	aml_binding_interleave_nbpages,
	aml_binding_interleave_pages,
	aml_binding_interleave_nodes,
};