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.
context
context =
None
66
self.
config
config = config
67
self.
is_init
is_init =
False
68
self.
iter
iter = 0
69
70
if
(self.
config
config.p_loop.devices.size > 1):
71
self.
context
context = carmaWrap_context.get_instance_ngpu(
72
self.
config
config.p_loop.devices.size, self.
config
config.p_loop.devices)
73
else
:
74
self.
context
context = carmaWrap_context.get_instance_1gpu(
75
self.
config
config.p_loop.devices[0])
76
self.
force_context
force_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.
config
config
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.
iter
iter
95
96
def
force_context
(self) -> None:
97
""" Active all the GPU devices specified in the parameters file
98
"""
99
if
self.
context
context
is
not
None
:
100
current_device = self.
context
context.active_device
101
for
device
in
range(len(self.
config
config.p_loop.devices)):
102
self.
context
context.
set_active_device_force
(device)
103
self.
context
context.
set_active_device
(current_device)
104
105
@abstractmethod
106
def
_init_components(self) -> None:
107
""" Initialize all the components
108
"""
109
self.
is_init
is_init =
True
set_active_device
#define set_active_device(new_device, silent)
Definition:
carma_context.h:72
set_active_device_force
#define set_active_device_force(new_device, silent)
Definition:
carma_context.h:74
shesha.supervisor.genericSupervisor.GenericSupervisor.iter
iter
(int) : Frame counter
Definition:
genericSupervisor.py:79
shesha.supervisor.genericSupervisor.GenericSupervisor.context
context
(CarmaContext) : a CarmaContext instance
Definition:
genericSupervisor.py:76
shesha.supervisor.genericSupervisor.GenericSupervisor.is_init
is_init
(bool) : Flag equals to True if the supervisor has already been initialized
Definition:
genericSupervisor.py:78
shesha.supervisor.genericSupervisor.GenericSupervisor.force_context
None force_context(self)
Active all the GPU devices specified in the parameters file.
Definition:
genericSupervisor.py:109
shesha.supervisor.genericSupervisor.GenericSupervisor.__init__
def __init__(self, config)
Init the a supervisor.
Definition:
genericSupervisor.py:75
shesha.supervisor.genericSupervisor.GenericSupervisor._init_components
None _init_components(self)
Definition:
genericSupervisor.py:121
shesha.supervisor.genericSupervisor.GenericSupervisor.config
config
(config) : Parameters structure
Definition:
genericSupervisor.py:77
shesha.supervisor.genericSupervisor.GenericSupervisor.get_config
def get_config(self)
Returns the configuration in use, in a supervisor specific format ?
Definition:
genericSupervisor.py:96
shesha.supervisor.genericSupervisor.GenericSupervisor.get_frame_counter
int get_frame_counter(self)
Return the current iteration number of the loop.
Definition:
genericSupervisor.py:104
shesha.sutra_wrap
Definition:
sutra_wrap.py:1
shesha
shesha
supervisor
genericSupervisor.py
Generated by
1.9.1