test_dma_linux_seq.c 2.24 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
#include "aml/dma/linux-seq.h"
13
14
15
16
17
18
19
20
21
22
23
24
#include <assert.h>

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

int main(int argc, char *argv[])
{
	AML_BINDING_SINGLE_DECL(binding);
	AML_TILING_1D_DECL(tiling);
	AML_ARENA_JEMALLOC_DECL(arena);
	AML_AREA_LINUX_DECL(area);
	AML_DMA_LINUX_SEQ_DECL(dma);
25
	struct aml_bitmap nodemask;
26
27
28
29
30
31
32
33
34
	void *dst, *src;

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

	/* initialize all the supporting struct */
	assert(!aml_binding_init(&binding, AML_BINDING_TYPE_SINGLE, 0));
	assert(!aml_tiling_init(&tiling, AML_TILING_TYPE_1D, TILESIZE*PAGE_SIZE,
				TILESIZE*PAGE_SIZE*NBTILES));
35
36
	aml_bitmap_zero(&nodemask);
	aml_bitmap_set(&nodemask, 0);
37
38
39
40
41
42
	assert(!aml_arena_jemalloc_init(&arena, AML_ARENA_JEMALLOC_TYPE_REGULAR));

	assert(!aml_area_linux_init(&area,
				    AML_AREA_LINUX_MANAGER_TYPE_SINGLE,
				    AML_AREA_LINUX_MBIND_TYPE_REGULAR,
				    AML_AREA_LINUX_MMAP_TYPE_ANONYMOUS,
43
				    &arena, MPOL_BIND, &nodemask));
44
45
46
47
48

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

	/* allocate some memory */
49
	src = aml_area_malloc(&area, TILESIZE*PAGE_SIZE*NBTILES);
50
	assert(src != NULL);
51
	dst = aml_area_malloc(&area, TILESIZE*PAGE_SIZE*NBTILES);
52
53
	assert(dst != NULL);

54
55
56
	memset(src, 42, TILESIZE*PAGE_SIZE*NBTILES);
	memset(dst, 24, TILESIZE*PAGE_SIZE*NBTILES);

57
58
59
60
	/* move some stuff by copy */
	for(int i = 0; i < NBTILES; i++)
		aml_dma_copy(&dma, &tiling, dst, i, &tiling, src, i);

61
62
	assert(!memcmp(src, dst, TILESIZE*PAGE_SIZE*NBTILES));

63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
	/* now move it by pages */
	for(int i = 0; i < NBTILES; i++)
		aml_dma_move(&dma, &area, &tiling, src, i);

	/* delete everything */
	aml_dma_linux_seq_destroy(&dma);
	aml_area_free(&area, dst);
	aml_area_free(&area, src);
	aml_area_linux_destroy(&area);
	aml_tiling_destroy(&tiling, AML_TILING_TYPE_1D);
	aml_binding_destroy(&binding, AML_BINDING_TYPE_SINGLE);

	aml_finalize();
	return 0;
}