seq.h 5.01 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
	/** The source pointer of the data movement **/
38
	void *srcptr;
39
	/** The identifier of the source tile **/
40
	int srcid;
41
	/** The destination pointer of the data movement **/
42
	void *dstptr;
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
82
83
84
	int (*doit)(struct aml_scratch_seq_data *scratch,
		    struct aml_scratch_request_seq *req);
};

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
95
96
97
/**
 * Static declaration of a sequential scratchpad.
 * Needs to be initialized with aml_scratch_seq_init()
 * @see aml_scratch_seq_init()
 **/
98
99
100
101
102
#define AML_SCRATCH_SEQ_DECL(name) \
	struct aml_scratch_seq __ ##name## _inner_data; \
	struct aml_scratch name = { \
		&aml_scratch_seq_ops, \
		(struct aml_scratch_data *)&__ ## name ## _inner_data, \
103
	}
104

105
/** Static declaration of a sequential scratchpad size. **/
106
107
108
109
#define AML_SCRATCH_SEQ_ALLOCSIZE \
	(sizeof(struct aml_scratch_seq) + \
	 sizeof(struct aml_scratch))

110
/**
111
 * Allocates and initializes a new sequential scratchpad.
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
 *
 * @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);

/**
 * Initializes a new sequential scratchpad. Similar to the create.
 *
 * @param scratch a pointer to a scratch declared with AML_SCRATCH_SEQ_DECL.
 *
 * @return 0 if successful; an error code otherwise.
 **/
int aml_scratch_seq_init(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);

/**
 * Finalize a scratchpad.
 *
 * @param scratch a pointer to a scratch initialized by aml_scratch_seq_init
 **/
void aml_scratch_seq_fini(struct aml_scratch *scratch);

/**
153
 * Tears down an initialized sequential scratchpad.
154
155
 *
 * @param scratch an initialized scratchpad structure. NULL on return.
156
 */
157
void aml_scratch_seq_destroy(struct aml_scratch **scratch);
158

159
160
161
/**
 * @}
 **/
162
#endif // AML_SCRATCH_SEQ_H