test_dma_linux_seq.c 3.01 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"
Swann Perarnau's avatar
Swann Perarnau committed
12
#include "aml/layout/dense.h"
13
#include "aml/dma/linux-seq.h"
14
15
16
17
#include <assert.h>

int main(int argc, char *argv[])
{
18
	struct aml_dma *dma;
Swann Perarnau's avatar
Swann Perarnau committed
19
20
21
22
	size_t isz = 1<<16;
	int idest[isz];
	int isrc[isz];
	struct aml_layout *idl, *isl;
23
24
25
26

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

Swann Perarnau's avatar
Swann Perarnau committed
27
28
29
30
31
32
33
34
35
36
37
38
39
	/* support data structures */
	assert(!aml_layout_dense_create(&idl, idest, 0, sizeof(int), 1, &isz,
					NULL, NULL));
	assert(!aml_layout_dense_create(&isl, isrc, 0, sizeof(int), 1, &isz,
					NULL, NULL));
	for (size_t i = 0; i < isz; i++) {
		idest[i] = 42;
		isrc[i] = 24;
	}
	/* invalid create input */
	assert(aml_dma_linux_seq_create(NULL, 1) == -AML_EINVAL);

	/* invalid requests */
40
	assert(!aml_dma_linux_seq_create(&dma, 1));
Swann Perarnau's avatar
Swann Perarnau committed
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
	assert(aml_dma_copy(dma, 42) == -AML_EINVAL);
	assert(aml_dma_copy(dma, AML_DMA_REQUEST_TYPE_LAYOUT, NULL, isl) ==
	       -AML_EINVAL);
	assert(aml_dma_copy(dma, AML_DMA_REQUEST_TYPE_LAYOUT, idl, NULL) ==
	       -AML_EINVAL);

	struct aml_dma_request *r1, *r2;
	/* force dma to increase its requests queue */
	assert(!aml_dma_async_copy(dma, &r1, AML_DMA_REQUEST_TYPE_LAYOUT,
				   idl, isl));
	assert(!aml_dma_async_copy(dma, &r2, AML_DMA_REQUEST_TYPE_LAYOUT,
				   idl, isl));

	assert(aml_dma_wait(dma, NULL) == -AML_EINVAL);
	assert(!aml_dma_wait(dma, &r1));
	assert(!aml_dma_wait(dma, &r2));
57

Swann Perarnau's avatar
Swann Perarnau committed
58
59
60
61
62
	/* cancel a request on the fly */
	assert(aml_dma_cancel(dma, NULL) == -AML_EINVAL);
	assert(!aml_dma_async_copy(dma, &r1, AML_DMA_REQUEST_TYPE_LAYOUT,
				   idl, isl));
	assert(!aml_dma_cancel(dma, &r1));
63

64

Swann Perarnau's avatar
Swann Perarnau committed
65
66
67
68
69
70
71
72
	/* destroy a running dma */
	assert(!aml_dma_async_copy(dma, &r1, AML_DMA_REQUEST_TYPE_LAYOUT,
				   idl, isl));
	aml_dma_linux_seq_destroy(&dma);

	/* move data around */
	assert(!aml_dma_linux_seq_create(&dma, 1));
	struct aml_dma_request *requests[16];
73
	struct aml_layout *layouts[16][2];
Swann Perarnau's avatar
Swann Perarnau committed
74
75
76
77
78
	for (int i = 0; i < 16; i++) {
		size_t sz = isz/16;
		size_t off = i*sz;
		void *dptr = (void *)&(idest[off]);
		void *sptr = (void *)&(isrc[off]);
79
80
81
82
		aml_layout_dense_create(&layouts[i][0], dptr, 0, sizeof(int),
					1, &sz, NULL, NULL);
		aml_layout_dense_create(&layouts[i][1], sptr, 0, sizeof(int),
					1, &sz, NULL, NULL);
83
		assert(!aml_dma_async_copy(dma, &requests[i],
84
85
					   AML_DMA_REQUEST_TYPE_LAYOUT,
					   layouts[i][0], layouts[i][1]));
86
		assert(requests[i] != NULL);
87
	}
88
	for(int i = 0; i < 16; i++) {
Swann Perarnau's avatar
Swann Perarnau committed
89
		assert(!aml_dma_wait(dma, &requests[i]));
90
91
92
		aml_layout_dense_destroy(&layouts[i][0]);
		aml_layout_dense_destroy(&layouts[i][1]);
	}
Swann Perarnau's avatar
Swann Perarnau committed
93
	assert(!memcmp(isrc, idest, isz*sizeof(int)));
94

95
	/* delete everything */
96
	aml_dma_linux_seq_destroy(&dma);
97
98
	aml_layout_dense_destroy(&idl);
	aml_layout_dense_destroy(&isl);
99
100
101
	aml_finalize();
	return 0;
}