Skip to content

Commit

Permalink
rename actors6.dd -> chrono.dd
Browse files Browse the repository at this point in the history
  • Loading branch information
mahrud committed Aug 23, 2024
1 parent 69f2f50 commit ec96a49
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 71 deletions.
2 changes: 1 addition & 1 deletion M2/Macaulay2/d/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion M2/Macaulay2/d/Makefile.files.in
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 0 additions & 18 deletions M2/Macaulay2/d/actors2.dd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 0 additions & 15 deletions M2/Macaulay2/d/actors5.d
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
36 changes: 0 additions & 36 deletions M2/Macaulay2/d/actors6.dd

This file was deleted.

78 changes: 78 additions & 0 deletions M2/Macaulay2/d/chrono.dd
Original file line number Diff line number Diff line change
@@ -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 <chrono>";

-- 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);

0 comments on commit ec96a49

Please sign in to comment.