COMPASS  5.4.4
End-to-end AO simulation tool using GPU acceleration
genericSupervisor.py
1 
37 
38 from abc import ABC, abstractmethod
39 from shesha.sutra_wrap import carmaWrap_context
40 
41 
42 class GenericSupervisor(ABC):
43  """ This class defines generic methods and behavior of a supervisor
44  It is not intended to be instantiated as it is : prefer to build
45  a supervisor class inheriting from it. This approach allows to build multiple
46  supervisors with various components and less effort
47 
48  Attributes:
49  context : (CarmaContext) : a CarmaContext instance
50 
51  config : (config) : Parameters structure
52 
53  is_init : (bool) : Flag equals to True if the supervisor has already been initialized
54 
55  iter : (int) : Frame counter
56  """
57 
58  def __init__(self, config):
59  """ Init the a supervisor
60 
61  Args:
62  config : (config module) : Configuration module
63 
64  """
65  self.contextcontext = None
66  self.configconfig = config
67  self.is_initis_init = False
68  self.iteriter = 0
69 
70  if (self.configconfig.p_loop.devices.size > 1):
71  self.contextcontext = carmaWrap_context.get_instance_ngpu(
72  self.configconfig.p_loop.devices.size, self.configconfig.p_loop.devices)
73  else:
74  self.contextcontext = carmaWrap_context.get_instance_1gpu(
75  self.configconfig.p_loop.devices[0])
76  self.force_contextforce_context()
77 
78  self._init_components_init_components()
79 
80  def get_config(self):
81  """ Returns the configuration in use, in a supervisor specific format ?
82 
83  Returns:
84  config : (config module) : Current supervisor configuration
85  """
86  return self.configconfig
87 
88  def get_frame_counter(self) -> int:
89  """Return the current iteration number of the loop
90 
91  Returns:
92  framecounter : (int) : Number of iteration already performed
93  """
94  return self.iteriter
95 
96  def force_context(self) -> None:
97  """ Active all the GPU devices specified in the parameters file
98  """
99  if self.contextcontext is not None:
100  current_device = self.contextcontext.active_device
101  for device in range(len(self.configconfig.p_loop.devices)):
102  self.contextcontext.set_active_device_force(device)
103  self.contextcontext.set_active_device(current_device)
104 
105  @abstractmethod
106  def _init_components(self) -> None:
107  """ Initialize all the components
108  """
109  self.is_initis_init = True
#define set_active_device(new_device, silent)
Definition: carma_context.h:72
#define set_active_device_force(new_device, silent)
Definition: carma_context.h:74
context
(CarmaContext) : a CarmaContext instance
is_init
(bool) : Flag equals to True if the supervisor has already been initialized
None force_context(self)
Active all the GPU devices specified in the parameters file.
def __init__(self, config)
Init the a supervisor.
def get_config(self)
Returns the configuration in use, in a supervisor specific format ?
int get_frame_counter(self)
Return the current iteration number of the loop.