From ec96a49751bac0cab2deea3049e4bd3ca431f5dd Mon Sep 17 00:00:00 2001 From: Mahrud Sayrafi Date: Tue, 1 Jun 2021 13:23:36 -0500 Subject: [PATCH] rename actors6.dd -> chrono.dd --- M2/Macaulay2/d/CMakeLists.txt | 2 +- M2/Macaulay2/d/Makefile.files.in | 2 +- M2/Macaulay2/d/actors2.dd | 18 -------- M2/Macaulay2/d/actors5.d | 15 ------ M2/Macaulay2/d/actors6.dd | 36 --------------- M2/Macaulay2/d/chrono.dd | 78 ++++++++++++++++++++++++++++++++ 6 files changed, 80 insertions(+), 71 deletions(-) delete mode 100644 M2/Macaulay2/d/actors6.dd create mode 100644 M2/Macaulay2/d/chrono.dd diff --git a/M2/Macaulay2/d/CMakeLists.txt b/M2/Macaulay2/d/CMakeLists.txt index 10023228859..20fbb477c5a 100644 --- a/M2/Macaulay2/d/CMakeLists.txt +++ b/M2/Macaulay2/d/CMakeLists.txt @@ -83,7 +83,7 @@ set(DLIST # tasks.d xmlactors.d # removed unless WITH_XML actors5.d - actors6.dd + chrono.dd threads.dd python.d # removed unless WITH_PYTHON interface.dd interface2.d diff --git a/M2/Macaulay2/d/Makefile.files.in b/M2/Macaulay2/d/Makefile.files.in index e8472fa45fa..7b8e4c617c3 100644 --- a/M2/Macaulay2/d/Makefile.files.in +++ b/M2/Macaulay2/d/Makefile.files.in @@ -87,7 +87,7 @@ else M2_SRCFILES += xmlactors.d endif M2_DFILES += actors5.d -M2_DFILES += actors6.dd +M2_DFILES += chrono.dd M2_DFILES += threads.dd ifeq (@PYTHON@,yes) diff --git a/M2/Macaulay2/d/actors2.dd b/M2/Macaulay2/d/actors2.dd index 8f5d0aca3c0..1f8b7de3d3d 100644 --- a/M2/Macaulay2/d/actors2.dd +++ b/M2/Macaulay2/d/actors2.dd @@ -666,24 +666,6 @@ unSingleton(e:Expr):Expr := ( else e); setupfun("unsequence",unSingleton); -cpuTime(e:Expr):Expr := ( - when e - is s:Sequence do if length(s) == 0 then toExpr(cpuTime()) - else WrongNumArgs(0) - else WrongNumArgs(0)); -setupfun("cpuTime",cpuTime); - --- TODO: should "timing" return thread and gc times like "time"? --- (moved to actors5.d for gc time) -timefun(a:Code):Expr := ( - v := cpuTime(); - ret := eval(a); - x := cpuTime(); - when ret - is Error do ret - else list(timeClass,Sequence(toExpr(x-v),ret))); -setupop(timingS,timefun); - exponent(e:Expr):Expr := ( when e is x:ZZcell do toExpr(exponent(x.v)) -- # typical value: size2, ZZ, ZZ diff --git a/M2/Macaulay2/d/actors5.d b/M2/Macaulay2/d/actors5.d index 3a8c0c05167..fdde6bcd9ae 100644 --- a/M2/Macaulay2/d/actors5.d +++ b/M2/Macaulay2/d/actors5.d @@ -2136,21 +2136,6 @@ GCstats(e:Expr):Expr := ( else WrongNumArgs(0)); setupfun("GCstats",GCstats); -showtimefun(a:Code):Expr := ( - cpuStart := cpuTime(); - threadStart := threadTime(); - gcStart := gcTime(); - ret := eval(a); - cpuEnd := cpuTime(); - threadEnd := threadTime(); - gcEnd := gcTime(); - stdError << " -- used " - << cpuEnd - cpuStart << "s (cpu); " - << threadEnd - threadStart << "s (thread); " - << gcEnd - gcStart << "s (gc)" << endl; - ret); -setupop(timeS,showtimefun); - header "extern void set_gftable_dir(char *); /* defined in library factory, as patched by us */"; setFactoryGFtableDirectory(e:Expr):Expr := ( when e is d:stringCell do ( diff --git a/M2/Macaulay2/d/actors6.dd b/M2/Macaulay2/d/actors6.dd deleted file mode 100644 index 9ec030cb198..00000000000 --- a/M2/Macaulay2/d/actors6.dd +++ /dev/null @@ -1,36 +0,0 @@ --- Copyright 2016 by Daniel R. Grayson -use actors5; - -declarations " -#include -"; - --- The typedef from this type declaration is put into the include file actors6-exports.h, --- so that means we can write "use actors6;" only in a *.dd file, not in a *.d file. --- That's why we are renaming interp.d to interp.dd. Eventually all *.d files should --- be renamed. -Chrono := Type "std::chrono::steady_clock::time_point" ; -- or use clock_gettime(CLOCK_MONOTONIC, &ts) - -elapsedTimefun(a:Code):Expr := ( - time1 := Ccode(Chrono, "std::chrono::steady_clock::now()"); - ret := eval(a); - time2 := Ccode(Chrono, "std::chrono::steady_clock::now()"); - d := Ccode(uint64_t, "(time2-time1).count()"); - x := double(d)/1000000000.; - when ret - is Error do ret - else list(timeClass,Sequence(toExpr(x),ret))); -setupop(elapsedTimingS,elapsedTimefun); -showElapsedTimefun(a:Code):Expr := ( - time3 := Ccode(Chrono, "std::chrono::steady_clock::now()"); - ret := eval(a); - time4 := Ccode(Chrono, "std::chrono::steady_clock::now()"); - d := Ccode(uint64_t, "(time4-time3).count()"); - x := double(d)/1000000000.; - stdError << " -- " << x << " seconds elapsed" << endl; - ret); -setupop(elapsedTimeS,showElapsedTimefun); - --- Local Variables: --- compile-command: "echo \"make: Entering directory \\`$M2BUILDDIR/Macaulay2/d'\" && make -C $M2BUILDDIR/Macaulay2/d actors6.o " --- End: diff --git a/M2/Macaulay2/d/chrono.dd b/M2/Macaulay2/d/chrono.dd new file mode 100644 index 00000000000..038f3aae0e2 --- /dev/null +++ b/M2/Macaulay2/d/chrono.dd @@ -0,0 +1,78 @@ +-- TODO: get core time: number of cpu clock ticks spent in the core/libraries +-- TODO: define time and elapsedTime in the top level instead, and print in the AfterPrint +-- TODO: auto-calibrate spin based on the wall time + +use arithmetic; -- for types +use binding; -- for symbols +use evaluate; -- for eval +use expr; -- for timeClass +use struct; -- for Sequence +use system; -- for cpuTime +use stdio; -- for tostringRR +use actors5; -- for gcTime + +declarations "#include "; + +-- The typedef from this type declaration is put into the include file chrono-exports.h, +-- so that means we can write "use chrono;" only in a *.dd file, not in a *.d file. +-- That's why we are renaming interp.d to interp.dd. Eventually all *.d files should +-- be renamed. +Chrono := Type "std::chrono::steady_clock::time_point" ; + +----------------------------------------------------------------------------- +-- Top level timing functions +----------------------------------------------------------------------------- + +cpuTime(e:Expr):Expr := ( + when e is s:Sequence do + if length(s) == 0 then toExpr(cpuTime()) + else WrongNumArgs(0) + else WrongNumArgs(0)); +setupfun("cpuTime", cpuTime); + +cpuTimer(c:Code):Sequence := ( + T0 := cpuTime(); + ret := eval(c); + T1 := cpuTime(); + Sequence(toExpr(T1 - T0), ret)); + +wallTimer(c:Code):Sequence := ( + T0 := Ccode(Chrono, "std::chrono::steady_clock::now()"); + ret := eval(c); + T1 := Ccode(Chrono, "std::chrono::steady_clock::now()"); + dT := double(Ccode(uint64_t, "(", T1, " - ", T0, ").count()")); + dT = dT/1000000000.; + Sequence(toExpr(dT), ret)); + +showtimefun(a:Code):Expr := ( + cpuStart := cpuTime(); + threadStart := threadTime(); + gcStart := gcTime(); + ret := eval(a); + cpuEnd := cpuTime(); + threadEnd := threadTime(); + gcEnd := gcTime(); + stdError << " -- used " + << cpuEnd - cpuStart << "s (cpu); " + << threadEnd - threadStart << "s (thread); " + << gcEnd - gcStart << "s (gc)" << endl; + ret); +setupop(timeS,showtimefun); + +-- TODO: should "timing" return thread and gc times like "time"? +timingfun(c:Code):Expr := ( + s := cpuTimer(c); + when s.1 is Error do s.1 else list(timeClass, s)); +setupop(timingS, timingfun); + +elapsedTimefun(c:Code):Expr := ( + s := wallTimer(c); + when s.0 is dT:RRcell do ( + stdError << " -- " << tostringRR(dT.v) << "s elapsed" << endl;) + else nothing; s.1); +setupop(elapsedTimeS,elapsedTimefun); + +elapsedTimingfun(c:Code):Expr := ( + s := wallTimer(c); + when s.1 is Error do s.1 else list(timeClass, s)); +setupop(elapsedTimingS,elapsedTimingfun);