COMPASS  5.0.0
End-to-end AO simulation tool using GPU acceleration
timing_rtc_pyramid.py
1 import numpy as np
2 import naga as ng
3 import matplotlib.pyplot as plt
4 plt.ion()
5 import os
6 from shesha.sutra_wrap import Rtc_FFF as Rtc, Rtc_FHF as RtcH
7 from shesha.supervisor.compassSupervisor import CompassSupervisor as Supervisor
8 import carmaWrap
9 from tqdm import tqdm
10 
11 dec = 5
12 sup = Supervisor(
13  os.getenv("COMPASS_ROOT") + "/shesha/data/par/MICADO/micado_39m_PYR_ELTPupil.py")
14 sup.config.p_controller0.set_type("generic")
15 sup.config.p_centroider0.set_type("maskedpix")
16 sup.config.p_wfs0.roket = False
17 sup.init()
18 sup.next()
19 xvalid = np.array(sup.rtc.rtc.d_centro[0].d_validx)
20 yvalid = np.array(sup.rtc.rtc.d_centro[0].d_validy)
21 cmat = sup.rtc.get_command_matrix(0)
22 frame = sup.wfs.get_wfs_image(0)
23 frame /= frame.max()
24 
25 rtc = Rtc()
26 rtc.add_centroider(sup.context, sup.config.p_wfs0._nvalid,
27  sup.config.p_wfs0.npix / 2 - 0.5, sup.config.p_wfs0.pixsize, False, 0,
28  "maskedpix")
29 rtc.add_controller(sup.context, sup.config.p_wfs0._nvalid,
30  sup.config.p_controller0.nslope, sup.config.p_controller0.nactu,
31  sup.config.p_controller0.delay, 0, "generic", idx_centro=np.zeros(1), ncentro=1)
32 rtc.d_centro[0].set_npix(sup.config.p_wfs0.npix)
33 rtc.d_centro[0].load_validpos(xvalid, yvalid, xvalid.size)
34 rtc.d_control[0].set_cmat(cmat)
35 rtc.d_control[0].set_gain(sup.config.p_controller0.gain)
36 rtc.d_centro[0].load_img(frame, frame.shape[0])
37 
38 rtcH = RtcH()
39 rtcH.add_centroider(sup.context, sup.config.p_wfs0._nvalid,
40  sup.config.p_wfs0.npix / 2 - 0.5, sup.config.p_wfs0.pixsize, False, 0,
41  "maskedpix")
42 rtcH.add_controller(sup.context, sup.config.p_wfs0._nvalid,
43  sup.config.p_controller0.nslope, sup.config.p_controller0.nactu,
44  sup.config.p_controller0.delay, 0, "generic", idx_centro=np.zeros(1), ncentro=1)
45 rtcH.d_centro[0].set_npix(sup.config.p_wfs0.npix)
46 rtcH.d_centro[0].load_validpos(xvalid, yvalid, xvalid.size)
47 rtcH.d_control[0].set_cmat(cmat)
48 rtcH.d_control[0].set_gain(sup.config.p_controller0.gain)
49 rtcH.d_centro[0].load_img(frame, frame.shape[0])
50 
51 timer = carmaWrap.timer()
52 niter = 100000
53 FP32 = np.zeros(niter)
54 FP16 = np.zeros(niter)
55 FP16TC = np.zeros(niter)
56 
57 timer.start()
58 rtc.do_centroids(0)
59 rtc.do_control(0)
60 timer.stop()
61 timer.reset()
62 
63 for k in tqdm(range(niter)):
64  timer.start()
65  rtc.do_centroids(0)
66  rtc.do_control(0)
67  timer.stop()
68  FP32[k] = timer.total_time
69  timer.reset()
70 
71 timer.start()
72 rtcH.do_centroids(0)
73 rtcH.do_control(0)
74 timer.stop()
75 timer.reset()
76 
77 for k in tqdm(range(niter)):
78  timer.start()
79  rtcH.do_centroids(0)
80  rtcH.do_control(0)
81  timer.stop()
82  FP16[k] = timer.total_time
83  timer.reset()
84 
85 sup._sim.c.activate_tensor_cores(True)
86 timer.start()
87 rtcH.do_centroids(0)
88 rtcH.do_control(0)
89 timer.stop()
90 timer.reset()
91 
92 for k in tqdm(range(niter)):
93  timer.start()
94  rtcH.do_centroids(0)
95  rtcH.do_control(0)
96  timer.stop()
97  FP16TC[k] = timer.total_time
98  timer.reset()
shesha.supervisor.compassSupervisor
Initialization and execution of a COMPASS supervisor.
Definition: compassSupervisor.py:1
shesha.sutra_wrap
Definition: sutra_wrap.py:1