seq.h 3.94 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
/*******************************************************************************
 * 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
*******************************************************************************/

#ifndef AML_SCRATCH_SEQ_H
#define AML_SCRATCH_SEQ_H 1

14
15
16
17
/**
 * @defgroup aml_scratch_seq "AML Sequential Scaratchpad"
 * @brief Sequential Scratchpad implementation.
 *
18
 * Scratchpad uses calling thread to trigger asynchronous dma movements.
19
20
 * @{
 **/
21

22
23
24
25
/**
 * Default table of scratchpad operations for linux
 * sequential dma.
 **/
26
27
extern struct aml_scratch_ops aml_scratch_seq_ops;

28
/** Inside of a sequential scratch request with linux dma. **/
29
struct aml_scratch_request_seq {
30
31
32
33
	/**
	 * The type of scratchpad request
	 * @see <aml.h>
	 **/
34
	int type;
35
	/** The tiling used for data organization in source and destination **/
36
	struct aml_tiling *tiling;
37
38
	/** The source layout of the data movement **/
	struct aml_layout *src;
39
	/** The identifier of the source tile **/
40
	int srcid;
41
	/** The destination pointer of the data movement **/
42
	struct aml_layout *dst;
43
	/** The identifier of the destination tile **/
44
	int dstid;
45
	/** The request used for movement **/
46
47
48
	struct aml_dma_request *dma_req;
};

49
/** Inner data of the sequential scratchpad implementation **/
50
struct aml_scratch_seq_data {
51
52
53
54
55
56
57
58
	/** The source area where data comes from **/
	struct aml_area *src_area;
	/** The destination area where data temporariliy goes to **/
	struct aml_area *sch_area;
	/**
	 * The data organisation.
	 * /todo why can't source and destination tiling vary?
	 **/
59
	struct aml_tiling *tiling;
60
	/** \todo What is this? **/
Nicolas Denoyelle's avatar
Nicolas Denoyelle committed
61
	size_t scratch_size;
62
	/** The dma engine in charge of the transfer **/
63
	struct aml_dma *dma;
64
	/** Pointer to data in scratch destination **/
65
	void *sch_ptr;
66
	/** The tilings involved in ongoing scratch requests **/
67
	struct aml_vector *tilemap;
68
	/** The set of dma requests submitted to the dma to mode data  **/
69
	struct aml_vector *requests;
70
	/** A lock to submit concurrent dma requests via the scratchpad **/
71
72
73
	pthread_mutex_t lock;
};

74
/** The set of operation embeded in the sequential scratchpad **/
75
struct aml_scratch_seq_ops {
76
77
78
79
80
	/**
	 * Function to submit a scratchpad request.
	 * @param scratch: The scratchpad used for the request
	 * @param req: The request to execute.
	 **/
81
	int (*doit)(struct aml_scratch_seq_data *scratch,
82
		    struct aml_scratch_request_seq *req);
83
84
};

85
/** Sequential implementation of a scratchpad **/
86
struct aml_scratch_seq {
87
	/** Set of operations embeded in the scratchpad **/
88
	struct aml_scratch_seq_ops ops;
89
	/** Data embeded in the scratchpad **/
90
91
92
	struct aml_scratch_seq_data data;
};

93
/**
94
 * Allocates and initializes a new sequential scratchpad.
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
 *
 * @param scratch an address where the pointer to the newly allocated scratchpad
 * structure will be stored.
 *
 * @param scratch_area the memory area where the scratchpad will be allocated.
 * @param source_area the memory area containing the user data structure.
 * @param dma the DMA that will be used for migrating data to and from
 * the scratchpad.
 * @param tiling the tiling to use on the user data structure and the scratch.
 * @param nbtiles number of tiles to divide the scratchpad into.
 * @param nbreqs the initial number of slots for asynchronous request that
 * are in-flight (will be increased automatically if necessary).
 * @return 0 if successful; an error code otherwise.
 **/
int aml_scratch_seq_create(struct aml_scratch **scratch,
			   struct aml_area *scratch_area,
			   struct aml_area *src_area,
			   struct aml_dma *dma, struct aml_tiling *tiling,
			   size_t nbtiles, size_t nbreqs);

/**
116
 * Tears down an initialized sequential scratchpad.
117
118
 *
 * @param scratch an initialized scratchpad structure. NULL on return.
119
 */
120
void aml_scratch_seq_destroy(struct aml_scratch **scratch);
121

122
123
124
/**
 * @}
 **/
125
#endif // AML_SCRATCH_SEQ_H