Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement differentiation time statistics upon setting clang -ftime-report #769

Closed
vgvassilev opened this issue Feb 16, 2024 · 2 comments · Fixed by #779
Closed

Implement differentiation time statistics upon setting clang -ftime-report #769

vgvassilev opened this issue Feb 16, 2024 · 2 comments · Fixed by #779

Comments

@vgvassilev
Copy link
Owner

The -ftime-report flag in clang enables several timers that produce statistics about how much time the compiler spent in each major compilation phase. If that flag is set and if clad is attached we should print out stats about differentiation times.

@vgvassilev vgvassilev modified the milestone: v1.4 Feb 16, 2024
@DeadSpheroid
Copy link
Contributor

DeadSpheroid commented Feb 19, 2024

Hi, id love to work on this issue,
is this the kind of output thats expected?

===-------------------------------------------------------------------------===
                             Timers for clad funcs
===-------------------------------------------------------------------------===
  Total Execution Time: 0.0306 seconds (0.0320 wall clock)

   ---User Time---   --System Time--   --User+System--   ---Wall Time---  --- Name ---
   0.0257 ( 84.0%)   0.0000 (100.0%)   0.0257 ( 84.0%)   0.0271 ( 84.7%)  fn
   0.0049 ( 16.0%)   0.0000 (  0.0%)   0.0049 ( 16.0%)   0.0049 ( 15.3%)  fnr
   0.0306 (100.0%)   0.0000 (100.0%)   0.0306 (100.0%)   0.0320 (100.0%)  Total

===-------------------------------------------------------------------------===
                             Timers for clad funcs
===-------------------------------------------------------------------------===
  Total Execution Time: 0.0073 seconds (0.0073 wall clock)

   ---User Time---   --User+System--   ---Wall Time---  --- Name ---
   0.0073 (100.0%)   0.0073 (100.0%)   0.0073 (100.0%)  fn2
   0.0073 (100.0%)   0.0073 (100.0%)   0.0073 (100.0%)  Total

===-------------------------------------------------------------------------===
                          Pass execution timing report
===-------------------------------------------------------------------------===
  Total Execution Time: 0.0007 seconds (0.0007 wall clock)

   ---User Time---   --User+System--   ---Wall Time---  --- Name ---
   0.0004 ( 54.3%)   0.0004 ( 54.3%)   0.0004 ( 54.2%)  AnnotationRemarksPass
   0.0002 ( 35.2%)   0.0002 ( 35.2%)   0.0002 ( 35.3%)  AlwaysInlinerPass
   0.0001 ( 10.5%)   0.0001 ( 10.5%)   0.0001 ( 10.5%)  CoroConditionalWrapper
   0.0007 (100.0%)   0.0007 (100.0%)   0.0007 (100.0%)  Total

===-------------------------------------------------------------------------===
                        Analysis execution timing report
===-------------------------------------------------------------------------===
  Total Execution Time: 0.0002 seconds (0.0002 wall clock)

   ---User Time---   --User+System--   ---Wall Time---  --- Name ---
   0.0001 ( 72.8%)   0.0001 ( 72.8%)   0.0001 ( 72.7%)  TargetLibraryAnalysis

where fn and fn2 are the differentiated functions in the source file

#include "clad/Differentiator/Differentiator.h"
#include <iostream>
double fnr(double c){
  return c*3*c;
}

double fn(double x, double y) {
  return x*x*x*x + 2*y*fnr(y);
}

double fn2(double a, double b) {
  return 3*a*a + b * b * b;
}


int main() {
  // differentiate 'fn' w.r.t 'x'.
  auto d_fn_1 = clad::differentiate(fn, "x");
  auto d_fn_2 = clad::differentiate(fn2, "a");

  // computes derivative of 'fn' w.r.t 'x' when (x, y) = (3, 4).
  std::cout<<d_fn_1.execute(3, 4)<<"\n";
  std::cout<<d_fn_2.execute(2, 4)<<"\n";
  return 0;
}

@vgvassilev
Copy link
Owner Author

Yes, that looks good. Maybe we should have a single Timers for clad funcs section with all functions being differentiated.

DeadSpheroid added a commit to DeadSpheroid/clad that referenced this issue Feb 29, 2024
…vassilev#769

Clad will now print a timings report for all clad function calls
Adds CladTimerGroup class to time the clad functions
Repurposes LIBCLAD_TIMING flag to print only the timings report for clad
DeadSpheroid added a commit to DeadSpheroid/clad that referenced this issue Feb 29, 2024
…vassilev#769

Clad will now print a timings report for all clad function calls
Adds CladTimerGroup class to time the clad functions
Repurposes LIBCLAD_TIMING flag to print only the timings report for clad
vgvassilev pushed a commit that referenced this issue Feb 29, 2024
Clad will now print a timings report for all clad function calls
Adds CladTimerGroup class to time the clad functions
Repurposes LIBCLAD_TIMING flag to print only the timings report for clad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants