From 6d46060213efcedef519fbd83f493bf8f01feaa3 Mon Sep 17 00:00:00 2001 From: Daniel Williams Date: Tue, 20 Aug 2024 11:06:38 +0100 Subject: [PATCH 1/3] Updated the profiling tests. --- profiling/cuda_likelihood.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/profiling/cuda_likelihood.py b/profiling/cuda_likelihood.py index d2194f3..20b460e 100644 --- a/profiling/cuda_likelihood.py +++ b/profiling/cuda_likelihood.py @@ -3,12 +3,12 @@ from heron.models.lalnoise import AdvancedLIGO from heron.injection import make_injection_zero_noise from heron.detector import AdvancedLIGOHanford -from heron.likelihood import TimeDomainLikelihoodModelUncertaintyPyTorch +from heron.likelihood import TimeDomainLikelihoodPyTorch from heron.models.lalsimulation import IMRPhenomPv2, IMRPhenomPv2_FakeUncertainty -def profile_likelihood(): - waveform = IMRPhenomPv2_FakeUncertainty() +def profile_likelihood_pytorch_nouncert(): + waveform = IMRPhenomPv2() psd_model = AdvancedLIGO() injections = make_injection_zero_noise(waveform=IMRPhenomPv2, @@ -22,22 +22,21 @@ def profile_likelihood(): data = injections['H1'] - likelihood = TimeDomainLikelihoodModelUncertaintyPyTorch(data, psd=psd_model) + likelihood = TimeDomainLikelihoodPyTorch(data, psd=psd_model) print(likelihood.device) - for m1 in np.linspace(20, 50, 100): - test_waveform = waveform.time_domain(parameters={"m1": m1*u.solMass, - "m2": 30*u.solMass, - "gpstime": 4000, - "distance": 410 * u.megaparsec}, times=data.times) + test_waveform = waveform.time_domain(parameters={"m1": 30*u.solMass, + "m2": 30*u.solMass, + "gpstime": 4000, + "distance": 410 * u.megaparsec}, times=data.times) - projected_waveform = test_waveform.project(AdvancedLIGOHanford(), - ra=0, dec=0, - phi_0=0, psi=0, - iota=0) + projected_waveform = test_waveform.project(AdvancedLIGOHanford(), + ra=0, dec=0, + phi_0=0, psi=0, + iota=0) - log_like = likelihood.log_likelihood(projected_waveform) + log_like = likelihood.log_likelihood(projected_waveform) from torch.profiler import profile, record_function, ProfilerActivity @@ -45,7 +44,7 @@ def profile_likelihood(): with profile(activities=[ProfilerActivity.CPU, ProfilerActivity.CUDA], record_shapes=True) as prof: with record_function("model_likelihood"): - profile_likelihood() + profile_likelihood_pytorch_nouncert() print(prof.key_averages().table(sort_by="cpu_time_total", row_limit=10)) print(prof.key_averages().table(sort_by="cuda_time_total", row_limit=10)) From 967ac4e1d53e4d8f88ba044e17e8e3c21d543e26 Mon Sep 17 00:00:00 2001 From: Daniel Williams Date: Tue, 20 Aug 2024 11:19:19 +0100 Subject: [PATCH 2/3] Add cuda likelihood test. --- profiling/cuda/cuda_likelihood.py | 50 +++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 profiling/cuda/cuda_likelihood.py diff --git a/profiling/cuda/cuda_likelihood.py b/profiling/cuda/cuda_likelihood.py new file mode 100644 index 0000000..20b460e --- /dev/null +++ b/profiling/cuda/cuda_likelihood.py @@ -0,0 +1,50 @@ +import numpy as np +import astropy.units as u +from heron.models.lalnoise import AdvancedLIGO +from heron.injection import make_injection_zero_noise +from heron.detector import AdvancedLIGOHanford +from heron.likelihood import TimeDomainLikelihoodPyTorch +from heron.models.lalsimulation import IMRPhenomPv2, IMRPhenomPv2_FakeUncertainty + + +def profile_likelihood_pytorch_nouncert(): + waveform = IMRPhenomPv2() + psd_model = AdvancedLIGO() + + injections = make_injection_zero_noise(waveform=IMRPhenomPv2, + injection_parameters={"m1": 35*u.solMass, + "m2": 30*u.solMass, + "gpstime": 4000, + "distance": 410 * u.megaparsec}, + detectors={"AdvancedLIGOHanford": "AdvancedLIGO", + "AdvancedLIGOLivingston": "AdvancedLIGO"} + ) + + data = injections['H1'] + + likelihood = TimeDomainLikelihoodPyTorch(data, psd=psd_model) + print(likelihood.device) + + + test_waveform = waveform.time_domain(parameters={"m1": 30*u.solMass, + "m2": 30*u.solMass, + "gpstime": 4000, + "distance": 410 * u.megaparsec}, times=data.times) + + projected_waveform = test_waveform.project(AdvancedLIGOHanford(), + ra=0, dec=0, + phi_0=0, psi=0, + iota=0) + + log_like = likelihood.log_likelihood(projected_waveform) + + +from torch.profiler import profile, record_function, ProfilerActivity + +with profile(activities=[ProfilerActivity.CPU, ProfilerActivity.CUDA], record_shapes=True) as prof: + with record_function("model_likelihood"): + + profile_likelihood_pytorch_nouncert() + +print(prof.key_averages().table(sort_by="cpu_time_total", row_limit=10)) +print(prof.key_averages().table(sort_by="cuda_time_total", row_limit=10)) From 56eaba09e7ee56da9fb408f0b6505177dd4c6bc4 Mon Sep 17 00:00:00 2001 From: Daniel Williams Date: Tue, 20 Aug 2024 14:06:06 +0100 Subject: [PATCH 3/3] Moved cuda likelihood. --- profiling/cuda_likelihood.py | 50 ------------------------------------ 1 file changed, 50 deletions(-) delete mode 100644 profiling/cuda_likelihood.py diff --git a/profiling/cuda_likelihood.py b/profiling/cuda_likelihood.py deleted file mode 100644 index 20b460e..0000000 --- a/profiling/cuda_likelihood.py +++ /dev/null @@ -1,50 +0,0 @@ -import numpy as np -import astropy.units as u -from heron.models.lalnoise import AdvancedLIGO -from heron.injection import make_injection_zero_noise -from heron.detector import AdvancedLIGOHanford -from heron.likelihood import TimeDomainLikelihoodPyTorch -from heron.models.lalsimulation import IMRPhenomPv2, IMRPhenomPv2_FakeUncertainty - - -def profile_likelihood_pytorch_nouncert(): - waveform = IMRPhenomPv2() - psd_model = AdvancedLIGO() - - injections = make_injection_zero_noise(waveform=IMRPhenomPv2, - injection_parameters={"m1": 35*u.solMass, - "m2": 30*u.solMass, - "gpstime": 4000, - "distance": 410 * u.megaparsec}, - detectors={"AdvancedLIGOHanford": "AdvancedLIGO", - "AdvancedLIGOLivingston": "AdvancedLIGO"} - ) - - data = injections['H1'] - - likelihood = TimeDomainLikelihoodPyTorch(data, psd=psd_model) - print(likelihood.device) - - - test_waveform = waveform.time_domain(parameters={"m1": 30*u.solMass, - "m2": 30*u.solMass, - "gpstime": 4000, - "distance": 410 * u.megaparsec}, times=data.times) - - projected_waveform = test_waveform.project(AdvancedLIGOHanford(), - ra=0, dec=0, - phi_0=0, psi=0, - iota=0) - - log_like = likelihood.log_likelihood(projected_waveform) - - -from torch.profiler import profile, record_function, ProfilerActivity - -with profile(activities=[ProfilerActivity.CPU, ProfilerActivity.CUDA], record_shapes=True) as prof: - with record_function("model_likelihood"): - - profile_likelihood_pytorch_nouncert() - -print(prof.key_averages().table(sort_by="cpu_time_total", row_limit=10)) -print(prof.key_averages().table(sort_by="cuda_time_total", row_limit=10))