COMPASS  5.0.0
End-to-end AO simulation tool using GPU acceleration
timing_rtc.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/par4bench/scao_sh_80x80_8pix.py")
14 sup.config.p_controller0.set_type("generic")
15 sup.init()
16 sup.next()
17 xvalid = np.array(sup.rtc.rtc.d_centro[0].d_validx)
18 yvalid = np.array(sup.rtc.rtc.d_centro[0].d_validy)
19 cmat = sup.rtc.get_command_matrix(0)
20 frame = sup.wfs.get_wfs_image(0)
21 frame /= frame.max()
22 
23 rtc = Rtc()
24 rtc.add_centroider(sup.context, sup.config.p_wfs0._nvalid,
25  sup.config.p_wfs0.npix / 2 - 0.5, sup.config.p_wfs0.pixsize, False, 0, "cog")
26 rtc.add_controller(sup.context, sup.config.p_wfs0._nvalid, sup.config.p_wfs0._nvalid * 2,
27  sup.config.p_controller0.nactu, sup.config.p_controller0.delay, 0,
28  "generic", idx_centro=np.zeros(1), ncentro=1)
29 rtc.d_centro[0].set_npix(sup.config.p_wfs0.npix)
30 rtc.d_centro[0].load_validpos(xvalid, yvalid, xvalid.size)
31 rtc.d_control[0].set_cmat(cmat)
32 rtc.d_control[0].set_gain(sup.config.p_controller0.gain)
33 rtc.d_centro[0].load_img(frame, frame.shape[0])
34 
35 rtcH = RtcH()
36 rtcH.add_centroider(sup.context, sup.config.p_wfs0._nvalid,
37  sup.config.p_wfs0.npix / 2 - 0.5, sup.config.p_wfs0.pixsize, False, 0,
38  "cog")
39 rtcH.add_controller(sup.context, sup.config.p_wfs0._nvalid, sup.config.p_wfs0._nvalid * 2,
40  sup.config.p_controller0.nactu, sup.config.p_controller0.delay, 0,
41  "generic", idx_centro=np.zeros(1), ncentro=1)
42 rtcH.d_centro[0].set_npix(sup.config.p_wfs0.npix)
43 rtcH.d_centro[0].load_validpos(xvalid, yvalid, xvalid.size)
44 rtcH.d_control[0].set_cmat(cmat)
45 rtcH.d_control[0].set_gain(sup.config.p_controller0.gain)
46 rtcH.d_centro[0].load_img(frame, frame.shape[0])
47 
48 timer = carmaWrap.timer()
49 niter = 100000
50 FP32 = np.zeros(niter)
51 FP16 = np.zeros(niter)
52 FP16TC = np.zeros(niter)
53 
54 timer.start()
55 rtc.do_centroids(0)
56 rtc.do_control(0)
57 timer.stop()
58 timer.reset()
59 
60 for k in tqdm(range(niter)):
61  timer.start()
62  rtc.do_centroids(0)
63  rtc.do_control(0)
64  timer.stop()
65  FP32[k] = timer.total_time
66  timer.reset()
67 
68 timer.start()
69 rtcH.do_centroids(0)
70 rtcH.do_control(0)
71 timer.stop()
72 timer.reset()
73 
74 for k in tqdm(range(niter)):
75  timer.start()
76  rtcH.do_centroids(0)
77  rtcH.do_control(0)
78  timer.stop()
79  FP16[k] = timer.total_time
80  timer.reset()
81 
82 sup._sim.c.activate_tensor_cores(True)
83 timer.start()
84 rtcH.do_centroids(0)
85 rtcH.do_control(0)
86 timer.stop()
87 timer.reset()
88 
89 for k in tqdm(range(niter)):
90  timer.start()
91  rtcH.do_centroids(0)
92  rtcH.do_control(0)
93  timer.stop()
94  FP16TC[k] = timer.total_time
95  timer.reset()
shesha.supervisor.compassSupervisor
Initialization and execution of a COMPASS supervisor.
Definition: compassSupervisor.py:1
shesha.sutra_wrap
Definition: sutra_wrap.py:1