Commit 12e946e0 authored by Swann Perarnau's avatar Swann Perarnau
Browse files

[test] add working test for dma_linux_par

Add working implementation of copy and move to dma_linux_par, and
corresponding unit test.
parent 7bfa666c
......@@ -87,7 +87,18 @@ int aml_dma_linux_par_do_copy(struct aml_dma_linux_par_data *dma,
{
assert(dma != NULL);
assert(req != NULL);
memcpy(req->dest, req->src, req->size);
/* chunk memory */
size_t nbthreads = dma->nbthreads;
size_t chunksize = req->size / nbthreads;
void *dest = (void*)((intptr_t)req->dest + tid * chunksize);
void *src = (void*)((intptr_t)req->src + tid * chunksize);
if(tid == nbthreads - 1 && req->size > chunksize * nbthreads)
chunksize += req->size % nbthreads;
memcpy(dest, src, chunksize);
return 0;
}
......@@ -96,10 +107,19 @@ int aml_dma_linux_par_do_move(struct aml_dma_linux_par_data *dma,
{
assert(dma != NULL);
assert(req != NULL);
int status[req->count];
size_t nbthreads = dma->nbthreads;
size_t chunksize = req->count / nbthreads;
size_t idx = tid * chunksize;
if(tid == nbthreads - 1 && req->count > chunksize * nbthreads)
chunksize += req->count % nbthreads;
int status[chunksize];
int err;
err = move_pages(0, req->count, req->pages, req->nodes, status,
MPOL_MF_MOVE);
err = move_pages(0, chunksize, &req->pages[idx], &req->nodes[idx],
status, MPOL_MF_MOVE);
if(err)
{
perror("move_pages:");
......
......@@ -22,7 +22,8 @@ TILING_TESTS = tiling
BINDING_TESTS = binding
DMA_LINUX_TESTS = dma_linux_seq
DMA_LINUX_TESTS = dma_linux_seq \
dma_linux_par
# unit tests
UNIT_TESTS = $(ARENA_JEMALLOC_TESTS) \
......
#include <aml.h>
#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);
unsigned long nodemask[AML_NODEMASK_SZ];
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));
AML_NODEMASK_ZERO(nodemask);
AML_NODEMASK_SET(nodemask, 0);
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,
&arena, MPOL_BIND, nodemask));
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);
dst = aml_area_malloc(&area, TILESIZE*PAGE_SIZE*NBTILES);
assert(dst != NULL);
memset(src, 42, TILESIZE*PAGE_SIZE*NBTILES);
memset(dst, 24, TILESIZE*PAGE_SIZE*NBTILES);
/* move some stuff by copy */
for(int i = 0; i < NBTILES; i++)
aml_dma_copy(&dma, &tiling, dst, i, &tiling, src, i);
assert(!memcmp(src, dst, TILESIZE*PAGE_SIZE*NBTILES));
/* 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_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;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment