test_dma_linux_seq.c 1.74 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
15
16
17
18
19
20
21
22
#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);
23
	struct aml_bitmap nodemask;
24
25
26
27
28
29
30
31
	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));
32
33
	aml_bitmap_zero(&nodemask);
	aml_bitmap_set(&nodemask, 0);
34
35
36
37
38

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

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

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

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

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

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

	aml_finalize();
	return 0;
}