PULSAR  0.1
Parallel Unified Linear Algebra with Systolic Arrays
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
prt_vdp.c
Go to the documentation of this file.
1 
11 #include "prt_vdp.h"
12 
14 
27  int *tuple, int counter,
28  prt_vdp_function_t function,
29  size_t local_store_size,
30  int num_inputs, int num_outputs, int color)
31 {
32  // Allocate the VDP.
33  prt_vdp_t *vdp = (prt_vdp_t*)malloc(sizeof(prt_vdp_t));
34  prt_assert(vdp != NULL, "malloc failed");
35 
36  // Check parameters.
37  prt_assert(tuple != NULL, "NULL tuple");
38  prt_assert(function != NULL, "NULL function");
39  prt_assert(counter > 0, "counter less or equal zero");
40 
41  // Initialize the VDP.
42  vdp->thread = NULL;
43  vdp->tuple = tuple;
44  vdp->counter = counter;
45  vdp->function = function;
46  vdp->color = color;
47 
48  // Initialize input channels.
49  vdp->num_inputs = num_inputs;
50  if (vdp->num_inputs > 0) {
51  vdp->input = (prt_channel_t**)calloc(vdp->num_inputs, sizeof(prt_channel_t*));
52  prt_assert(vdp->input != NULL, "malloc failed");
53  }
54  // Initialize output channels.
55  vdp->num_outputs = num_outputs;
56  if (vdp->num_outputs > 0) {
57  vdp->output = (prt_channel_t**)calloc(vdp->num_outputs, sizeof(prt_channel_t*));
58  prt_assert(vdp->output != NULL, "malloc failed");
59  }
60  // Allocate local store.
61  if (local_store_size > 0) {
62  vdp->local_store = (void*)malloc(local_store_size);
63  prt_assert(vdp->local_store != NULL, "malloc failed");
64  }
65  // Return the VDP.
66  return vdp;
67 }
68 
70 
78 {
79  // Check for a NULL VDP.
80  prt_assert(vdp != NULL, "NULL VDP");
81 
82  // Delete the tuple.
83  prt_assert(vdp->tuple != NULL, "NULL tuple");
84  prt_tuple_delete(vdp->tuple);
85 
86  int i;
87  // Delete local output channels.
88  for (i = 0; i < vdp->num_outputs; i++) {
89  prt_channel_t *channel = vdp->output[i];
90  if (channel != NULL)
91  if (channel->dst_node == channel->vdp->thread->vsa->node_rank)
92  prt_channel_delete(channel);
93  }
94  // Free array of inputs.
95  if (vdp->num_inputs > 0)
96  free(vdp->input);
97 
98  // Free array of outputs.
99  if (vdp->num_outputs > 0)
100  free(vdp->output);
101 
102  // Free local store.
103  if (vdp->local_store != NULL)
104  free(vdp->local_store);
105 
106  // Free the VDP.
107  free(vdp);
108 }
109 
111 
120  prt_vdp_t *vdp, prt_channel_t *channel,
121  prt_channel_direction_t direction, int slot)
122 {
123  // Check input parameters.
124  prt_assert(vdp != NULL, "inserting in a NULL VDP");
125  prt_assert(channel != NULL, "inserting a NULL channel");
126  prt_assert(direction == PrtInputChannel || direction == PrtOutputChannel,
127  "wrong channel direction");
128 
129  if (direction == PrtInputChannel) {
130  // Check if channel destination tuple equals VDP's tuple.
131  int cmp = prt_tuple_compare(channel->dst_tuple, vdp->tuple);
132  prt_assert(cmp == 0,
133  "input channel destination tuple does not match VDP tuple");
134  // Check if channel slot empty.
135  prt_assert(vdp->input[slot] == NULL,
136  "inserting channel in occupied input slot");
137  // Check the slot.
138  // Link the channel.
139  prt_assert(slot >= 0 && slot < vdp->num_inputs, "slot out of range");
140  vdp->input[slot] = channel;
141  channel->vdp = vdp;
142  }
143  else {
144  // Check if channel source tuple equals VDP's tuple.
145  int cmp = prt_tuple_compare(channel->src_tuple, vdp->tuple);
146  prt_assert(cmp == 0,
147  "output channel source tuple does not match VDP tuple");
148  // Check if channel slot empty.
149  prt_assert(vdp->output[slot] == NULL,
150  "inserting channel in occupied output slot");
151  // Check the slot.
152  // Link the channel.
153  prt_assert(slot >= 0 && slot < vdp->num_outputs, "slot out of range");
154  vdp->output[slot] = channel;
155  channel->vdp = vdp;
156  }
157 }
158 
160 
171 {
172  // Check for a NULL VDP.
173  prt_assert(vdp != NULL, "NULL VDP");
174 
175  int i;
176  // FOR each input channel.
177  for (i = 0; i < vdp->num_inputs; i++)
178  // IF the channel was established.
179  if (vdp->input[i] != NULL)
180  // IF the list of packets is empty.
181  if (prt_channel_empty(vdp->input[i]))
182  // Return "not ready".
183  return 0;
184 
185  // Return "ready".
186  return 1;
187 }
int color
Definition: prt_vdp.h:47
prt_vdp_function_t function
Definition: prt_vdp.h:45
int prt_tuple_compare(void *tuple_a, void *tuple_b)
tuple comparison
Definition: prt_tuple.c:135
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:26
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:170
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:150
Virtual Data Processor (VDP)
void prt_channel_delete(prt_channel_t *channel)
channel destructor
Definition: prt_channel.c:63
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 Delete all local output channels. All local input channels are destroyed as output cha...
Definition: prt_vdp.c:77
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.
struct prt_thread_s * thread
Definition: prt_vdp.h:38
struct prt_channel_s ** output
Definition: prt_vdp.h:44
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:119
int * tuple
Definition: prt_vdp.h:39
struct prt_vdp_s * vdp
Definition: prt_channel.h:30