test_dma_linux_seq.c 1.76 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"
Nicolas Denoyelle's avatar
Nicolas Denoyelle committed
12
#include "aml/area/linux.h"
13
#include "aml/dma/linux-seq.h"
14
#include "aml/tiling/1d.h"
15 16 17 18 19 20 21 22 23
#include <assert.h>

#define TILESIZE (2)
#define NBTILES (4)

int main(int argc, char *argv[])
{
	AML_TILING_1D_DECL(tiling);
	AML_DMA_LINUX_SEQ_DECL(dma);
24
	struct aml_bitmap nodemask;
25 26 27 28 29 30 31 32
	void *dst, *src;

	/* library initialization */
	aml_init(&argc, &argv);

	/* initialize all the supporting struct */
	assert(!aml_tiling_init(&tiling, AML_TILING_TYPE_1D, TILESIZE*PAGE_SIZE,
				TILESIZE*PAGE_SIZE*NBTILES));
33 34
	aml_bitmap_zero(&nodemask);
	aml_bitmap_set(&nodemask, 0);
35 36 37 38 39

	size_t maxrequests = NBTILES;
	assert(!aml_dma_linux_seq_init(&dma, maxrequests));

	/* allocate some memory */
Nicolas Denoyelle's avatar
Nicolas Denoyelle committed
40
	src = aml_area_mmap(&aml_area_linux, NULL, TILESIZE*PAGE_SIZE*NBTILES);
41
	assert(src != NULL);
Nicolas Denoyelle's avatar
Nicolas Denoyelle committed
42
	dst = aml_area_mmap(&aml_area_linux, NULL, TILESIZE*PAGE_SIZE*NBTILES);
43 44
	assert(dst != NULL);

45 46 47
	memset(src, 42, TILESIZE*PAGE_SIZE*NBTILES);
	memset(dst, 24, TILESIZE*PAGE_SIZE*NBTILES);

48 49 50 51
	/* move some stuff by copy */
	for(int i = 0; i < NBTILES; i++)
		aml_dma_copy(&dma, &tiling, dst, i, &tiling, src, i);

52 53
	assert(!memcmp(src, dst, TILESIZE*PAGE_SIZE*NBTILES));

54
	/* delete everything */
55
	aml_dma_linux_seq_fini(&dma);
Nicolas Denoyelle's avatar
Nicolas Denoyelle committed
56 57
	aml_area_munmap(&aml_area_linux, dst, TILESIZE*PAGE_SIZE*NBTILES);
	aml_area_munmap(&aml_area_linux, src, TILESIZE*PAGE_SIZE*NBTILES);
58 59 60 61 62
	aml_tiling_destroy(&tiling, AML_TILING_TYPE_1D);

	aml_finalize();
	return 0;
}