PULSAR  1.0.0
Parallel Ultra Light Systolic Array Runtime
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
prt_vdp.c
Go to the documentation of this file.
1 
11 #include "prt_vdp.h"
12 
14 
28  int *tuple, int counter,
29  prt_vdp_function_t function,
30  size_t local_store_size,
31  int num_inputs, int num_outputs, int color)
32 {
33  // Allocate the VDP.
34  prt_vdp_t *vdp = (prt_vdp_t*)malloc(sizeof(prt_vdp_t));
35  prt_assert(vdp != NULL, "malloc failed");
36 
37  // Check parameters.
38  prt_assert(tuple != NULL, "NULL tuple");
39  prt_assert(function != NULL, "NULL function");
40  prt_assert(counter > 0, "counter less or equal zero");
41 
42  // Initialize the VDP.
43  vdp->thread = NULL;
44  vdp->tuple = tuple;
45  vdp->counter = counter;
46  vdp->function = function;
47  vdp->color = color;
48 
49  // Initialize input channels.
50  vdp->num_inputs = num_inputs;
51  if (vdp->num_inputs > 0) {
52  vdp->input = (prt_channel_t**)calloc(vdp->num_inputs, sizeof(prt_channel_t*));
53  prt_assert(vdp->input != NULL, "malloc failed");
54  }
55  // Initialize output channels.
56  vdp->num_outputs = num_outputs;
57  if (vdp->num_outputs > 0) {
58  vdp->output = (prt_channel_t**)calloc(vdp->num_outputs, sizeof(prt_channel_t*));
59  prt_assert(vdp->output != NULL, "malloc failed");
60  }
61  // Allocate local store.
62  if (local_store_size > 0) {
63  vdp->local_store = (void*)malloc(local_store_size);
64  prt_assert(vdp->local_store != NULL, "malloc failed");
65  }
66  // Return the VDP.
67  return vdp;
68 }
69 
71 
81 {
82  // Check for a NULL VDP.
83  prt_assert(vdp != NULL, "NULL VDP");
84 
85  // Delete the tuple.
86  prt_assert(vdp->tuple != NULL, "NULL tuple");
87  prt_tuple_delete(vdp->tuple);
88 
89  int i;
90  // Delete all input channels.
91  for (i = 0; i < vdp->num_inputs; i++) {
92  prt_channel_t *channel = vdp->input[i];
93  if (channel != NULL)
94  prt_channel_delete(channel);
95  }
96  // Delete dangling output channels.
97  for (i = 0; i < vdp->num_outputs; i++) {
98  prt_channel_t *channel = vdp->output[i];
99  if (channel != NULL)
100  if (channel->dst_node != vdp->thread->vsa->node_rank)
101  prt_channel_delete(channel);
102  }
103  // Free array of inputs.
104  if (vdp->num_inputs > 0)
105  free(vdp->input);
106 
107  // Free array of outputs.
108  if (vdp->num_outputs > 0)
109  free(vdp->output);
110 
111  // Free local store.
112  if (vdp->local_store != NULL)
113  free(vdp->local_store);
114 
115  // Free the VDP.
116  free(vdp);
117 }
118 
120 
129 {
130  // Check for a NULL VDP.
131  prt_assert(vdp != NULL, "NULL VDP");
132 
133  // Delete the tuple.
134  prt_assert(vdp->tuple != NULL, "NULL tuple");
135  prt_tuple_delete(vdp->tuple);
136 
137  int i;
138  // Delete all input channels.
139  for (i = 0; i < vdp->num_inputs; i++) {
140  prt_channel_t *channel = vdp->input[i];
141  if (channel != NULL)
142  prt_channel_delete(channel);
143  }
144  // Delete all output channels.
145  for (i = 0; i < vdp->num_outputs; i++) {
146  prt_channel_t *channel = vdp->output[i];
147  if (channel != NULL)
148  prt_channel_delete(channel);
149  }
150  // Free array of inputs.
151  if (vdp->num_inputs > 0)
152  free(vdp->input);
153 
154  // Free array of outputs.
155  if (vdp->num_outputs > 0)
156  free(vdp->output);
157 
158  // Free local store.
159  if (vdp->local_store != NULL)
160  free(vdp->local_store);
161 
162  // Free the VDP.
163  free(vdp);
164 }
165 
167 
177  prt_vdp_t *vdp, prt_channel_t *channel,
178  prt_channel_direction_t direction, int slot)
179 {
180  // Check input parameters.
181  prt_assert(vdp != NULL, "inserting in a NULL VDP");
182  prt_assert(channel != NULL, "inserting a NULL channel");
183  prt_assert(direction == PrtInputChannel || direction == PrtOutputChannel,
184  "wrong channel direction");
185 
186  if (direction == PrtInputChannel) {
187  // Check if channel destination tuple equals VDP's tuple.
188  prt_assert(prt_tuple_equal(channel->dst_tuple, vdp->tuple),
189  "input channel destination tuple does not match VDP tuple");
190  // Check if channel slot empty.
191  prt_assert(vdp->input[slot] == NULL,
192  "inserting channel in occupied input slot");
193  // Check the slot.
194  // Link the channel.
195  prt_assert(slot >= 0 && slot < vdp->num_inputs, "slot out of range");
196  vdp->input[slot] = channel;
197  channel->vdp = vdp;
198  }
199  else {
200  // Check if channel source tuple equals VDP's tuple.
201  prt_assert(prt_tuple_equal(channel->src_tuple, vdp->tuple),
202  "output channel source tuple does not match VDP tuple");
203  // Check if channel slot empty.
204  prt_assert(vdp->output[slot] == NULL,
205  "inserting channel in occupied output slot");
206  // Check the slot.
207  // Link the channel.
208  prt_assert(slot >= 0 && slot < vdp->num_outputs, "slot out of range");
209  vdp->output[slot] = channel;
210  channel->vdp = vdp;
211  }
212 }
213 
215 
226 {
227  // Check for a NULL VDP.
228  prt_assert(vdp != NULL, "NULL VDP");
229 
230  int i;
231  // FOR each input channel.
232  for (i = 0; i < vdp->num_inputs; i++)
233  // IF the channel was established.
234  if (vdp->input[i] != NULL)
235  // IF the list of packets is empty.
236  if (prt_channel_empty(vdp->input[i]))
237  // Return "not ready".
238  return 0;
239 
240  // Return "ready".
241  return 1;
242 }
void prt_vdp_channel_insert(prt_vdp_t *vdp, prt_channel_t *channel, prt_channel_direction_t direction, int slot)
Insert a new channel into a VDP.
Definition: prt_vdp.c:176
int color
Definition: prt_vdp.h:47
prt_vdp_function_t function
Definition: prt_vdp.h:45
struct prt_channel_s ** input
Definition: prt_vdp.h:42
void(* prt_vdp_function_t)(int *, int, struct prt_channel_s **, struct prt_channel_s **, void *, void *)
VDP&#39;s function pointer Defines the type of the pointer to the VDP&#39;s function.
Definition: prt_vdp.h:28
struct prt_vsa_s * vsa
Definition: prt_thread.h:28
int prt_vdp_ready(prt_vdp_t *vdp)
Check if a VDP is ready to fire. Only checks established channels. (NULL channels don&#39;t prevent firin...
Definition: prt_vdp.c:225
prt_vdp_t * prt_vdp_new(int *tuple, int counter, prt_vdp_function_t function, size_t local_store_size, int num_inputs, int num_outputs, int color)
VDP constructor.
Definition: prt_vdp.c:27
int * dst_tuple
Definition: prt_channel.h:35
void * local_store
Definition: prt_vdp.h:46
void prt_tuple_delete(int *tuple)
tuple destructor
Definition: prt_tuple.c:95
int counter
Definition: prt_vdp.h:40
int * src_tuple
Definition: prt_channel.h:33
int prt_channel_empty(prt_channel_t *channel)
Checks if a channel is empty.
Definition: prt_channel.c:153
Virtual Data Processor (VDP)
void prt_channel_delete(prt_channel_t *channel)
channel destructor
Definition: prt_channel.c:64
VDP&#39;s data channel Implements a data link between a pair of VDPs. Identifies the source and destinati...
Definition: prt_channel.h:29
void prt_vdp_delete(prt_vdp_t *vdp)
VDP destructor Used for destruction of local VDPs. Destroy all input channels. Destroy all dangling o...
Definition: prt_vdp.c:80
int num_inputs
Definition: prt_vdp.h:41
int num_outputs
Definition: prt_vdp.h:43
int node_rank
Definition: prt_vsa.h:46
#define prt_assert(cond, msg)
Definition: prt_assert.h:30
Virtual Data Processor (VDP) Is uniquely identified by a tuple. Fires for a predefined number of cycl...
Definition: prt_vdp.h:37
enum prt_channel_direction_e prt_channel_direction_t
VDP&#39;s data channel direction Identifies the direction of a VDP channel during insertion.
void prt_vdp_annihilate(prt_vdp_t *vdp)
VDP annihilator Used for complete annihilation of VDPs that don&#39;t belong. Destroy all input channels...
Definition: prt_vdp.c:128
int prt_tuple_equal(void *tuple_a, void *tuple_b)
tuple equality check Check if tuples are identical in length and content.
Definition: prt_tuple.c:161
struct prt_thread_s * thread
Definition: prt_vdp.h:38
struct prt_channel_s ** output
Definition: prt_vdp.h:44
int * tuple
Definition: prt_vdp.h:39
struct prt_vdp_s * vdp
Definition: prt_channel.h:30