PULSAR  2.0.0
Parallel Ultra-Light Systolic Array Runtime
 All Data Structures Files Functions Typedefs Enumerations Macros Groups
prt_device.c
Go to the documentation of this file.
1 
11 #include "prt_device.h"
12 
14 
23 prt_device_t* prt_device_new(int rank, int accelerator, int agent_rank)
24 {
25  // Allocate the device.
26  prt_device_t *device = (prt_device_t*)malloc(sizeof(prt_device_t));
27  prt_assert(device != NULL, "malloc failed");
28 
29  // Initialize the device.
30  device->rank = rank;
31  device->accelerator = accelerator;
32  device->finished = 0;
33  device->node = NULL;
34 
35  // Create the list of VDPs.
36  device->vdps = icl_list_new();
37  prt_assert(device->vdps != NULL, "icl_list_new failed");
38 
39  // Return the device.
40  return device;
41 }
42 
44 
50 {
51  // Destroy the list of VDPs.
52  int size = icl_list_size(device->vdps);
53  prt_assert(size == 0, "destroying non-empty list");
54  int status = icl_list_destroy(device->vdps, NULL);
55  prt_assert(status == 0, "icl_list_destroy failed");
56 
57  // Free the device.
58  free(device);
59 }
60 
62 
68 {
69  // Return if finished.
70  if (device->finished)
71  return;
72 
73  // Assign node if NULL.
74  if (device->node == NULL) {
75  device->node = icl_list_first(device->vdps);
76  // Return if list empty.
77  if (device->node == NULL) {
78  device->finished = 1;
79  return;
80  }
81  }
82  // Set the device.
83  cudaError_t error = cudaSetDevice(device->rank);
84  prt_assert(error == cudaSuccess, cudaGetErrorString(error));
85 
86  prt_vdp_t *vdp = (prt_vdp_t*)device->node->data;
87  // IF not finished and inputs ready.
88  if (vdp->counter > 0 && prt_vdp_ready(vdp)) {
89  // Fire and decrement.
90  svg_trace_start_gpu(vdp->stream);
91  vdp->function(vdp);
92  svg_trace_stop_gpu(vdp->stream, vdp->color);
93  vdp->counter--;
94  }
95  // IF finished or lazy scheduling.
96  if (vdp->counter == 0 ||
97  device->vsa->config->vdp_scheduling == PRT_VDP_SCHEDULING_LAZY) {
98  // Advance.
99  icl_list_t *prev = device->node;
100  device->node = icl_list_next(device->vdps, device->node);
101  // IF burned out.
102  if (vdp->counter == 0)
103  // Remove the VDP from the list
104  // Do not destroy the VDP itself.
105  icl_list_delete(device->vdps, prev, NULL);
106  }
107 }