test_scratch_seq.c 2.61 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-par.h"
13
#include "aml/scratch/seq.h"
14 15 16 17 18 19 20 21 22 23 24 25 26
#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_PAR_DECL(dma);
	AML_SCRATCH_SEQ_DECL(scratch);
27
	struct aml_bitmap nodemask;
28 29 30 31 32 33 34 35 36
	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));
37 38
	aml_bitmap_zero(&nodemask);
	aml_bitmap_set(&nodemask, 0);
39 40 41 42 43 44
	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,
45
				    &arena, MPOL_BIND, &nodemask));
46 47 48 49 50 51 52 53 54 55 56 57

	size_t maxrequests = NBTILES;
	size_t maxthreads = 4;
	assert(!aml_dma_linux_par_init(&dma, maxrequests, maxthreads));

	/* allocate some memory */
	src = aml_area_malloc(&area, TILESIZE*PAGE_SIZE*NBTILES);
	assert(src != NULL);

	memset(src, 42, TILESIZE*PAGE_SIZE*NBTILES);

	/* create scratchpad */
58
	assert(!aml_scratch_seq_init(&scratch, &area, &area, &dma, &tiling,
59
				     (size_t)NBTILES, (size_t)NBTILES));
60
	dst = aml_scratch_baseptr(&scratch);
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
	/* move some stuff */
	for(int i = 0; i < NBTILES; i++)
	{
		int di, si;
		void *dp, *sp;
		aml_scratch_pull(&scratch, dst, &di, src, i);
	
		dp = aml_tiling_tilestart(&tiling, dst, di);
		sp = aml_tiling_tilestart(&tiling, src, i);

		assert(!memcmp(sp, dp, TILESIZE*PAGE_SIZE));

		memset(dp, 33, TILESIZE*PAGE_SIZE);
	
		aml_scratch_push(&scratch, src, &si, dst, di);
		assert(si == i);

		sp = aml_tiling_tilestart(&tiling, src, si);

		assert(!memcmp(sp, dp, TILESIZE*PAGE_SIZE));
	}

	/* delete everything */
	aml_scratch_seq_destroy(&scratch);
	aml_dma_linux_par_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;
}