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

[Profiler] eDSL support for source info table + eDSL-level flame graphs #2397

Merged
merged 74 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
98af046
Commit rust changes from other branch
ayakayorihiro Jan 27, 2025
b7885e7
sed metadata_table source_info_table
ayakayorihiro Jan 27, 2025
9c2ddf2
porting more changes
ayakayorihiro Jan 27, 2025
6e199c6
forgot a file
ayakayorihiro Jan 27, 2025
815e9d8
make parser and clorpy happy
ayakayorihiro Jan 27, 2025
f1cdd50
update fud2 tests with new pass
ayakayorihiro Jan 27, 2025
cc3e6bd
python formatting
ayakayorihiro Jan 27, 2025
aa4f44c
try python linting again
ayakayorihiro Jan 27, 2025
74c5094
Add expect file for new test
ayakayorihiro Jan 27, 2025
0304c3b
adjust fud2 to use new calyx-py state
ayakayorihiro Jan 28, 2025
42c50a0
Use Calyx construct names when quick lookup fails in fileinfo_emitter
ayakayorihiro Jan 28, 2025
559759e
Toggle sourceinfo emitting off
ayakayorihiro Jan 28, 2025
e9c85b3
make black happy
ayakayorihiro Jan 28, 2025
c48fd04
Update fud2 tests
ayakayorihiro Jan 28, 2025
cd856df
forgor to add new fud2 test
ayakayorihiro Jan 28, 2025
9514d74
additional checking
ayakayorihiro Jan 28, 2025
0213284
move source loc stuff completely out of builder
ayakayorihiro Jan 28, 2025
a60261b
keep black happy
ayakayorihiro Jan 28, 2025
025e16c
emit original metadata
ayakayorihiro Jan 28, 2025
b42d035
only emit metadata when we have it
ayakayorihiro Jan 28, 2025
22bf078
Fix bugs
ayakayorihiro Jan 28, 2025
76d7b84
use environment variables to toggle sourceloc info
ayakayorihiro Jan 29, 2025
7aa3e84
make black happy
ayakayorihiro Jan 29, 2025
40c255a
make attributes into a set
ayakayorihiro Jan 29, 2025
6417c50
Fix bugs and make source-loc file optional to profiler-process
ayakayorihiro Jan 31, 2025
3b4e563
fix comment
ayakayorihiro Jan 31, 2025
34acbd8
add documentation comments
ayakayorihiro Jan 31, 2025
6804ec5
update dictionary contents comment
ayakayorihiro Jan 31, 2025
f36907c
make test with pos attributes
ayakayorihiro Jan 31, 2025
34f8fc2
remove file
ayakayorihiro Jan 31, 2025
ccc86a2
attributes are sets now
ayakayorihiro Jan 31, 2025
33e29f4
tabs --> 2 spaces
ayakayorihiro Jan 31, 2025
f2c3c2e
sort attributes by name
ayakayorihiro Jan 31, 2025
97758d2
massage and use block() from utils.py when generating source-loc meta…
ayakayorihiro Jan 31, 2025
6d076fb
update test
ayakayorihiro Jan 31, 2025
2b3d850
update var name
ayakayorihiro Jan 31, 2025
12eba81
fix attribute bug
ayakayorihiro Jan 31, 2025
b5cbe81
update expect file
ayakayorihiro Jan 31, 2025
2801e2c
update fileloc to reflect ci?
ayakayorihiro Jan 31, 2025
9d241f9
use environment variable to toggle relative paths
ayakayorihiro Jan 31, 2025
e0986ab
Merge branch 'main' into calyx-py-metadata-fr
ayakayorihiro Jan 31, 2025
3109a09
trying to appease CI...
ayakayorihiro Jan 31, 2025
0903bd2
Emitting fileinfo by default, using builder argument to toggle absolu…
ayakayorihiro Feb 3, 2025
90d9c3f
Merge branch 'main' into calyx-py-metadata-fr
ayakayorihiro Feb 3, 2025
250932e
fix dependency on fileinfo_emitter tool
ayakayorihiro Feb 3, 2025
fa582bd
update calyx-py tests
ayakayorihiro Feb 7, 2025
b06bdd6
fixed NTT tests
ayakayorihiro Feb 7, 2025
e0ebb32
update gen_exp tests
ayakayorihiro Feb 7, 2025
6f1b99b
WIP; Updating wrt relay and systolic?
ayakayorihiro Feb 7, 2025
8d0873f
fix parser error
ayakayorihiro Feb 12, 2025
846b023
update tests
ayakayorihiro Feb 12, 2025
081f77b
emit relative paths from relay_visitor
ayakayorihiro Feb 12, 2025
b375c1a
Update dahlia emitter for relay and corresponding runt tests
ayakayorihiro Feb 12, 2025
3cd05a3
make black happy again
ayakayorihiro Feb 12, 2025
36febf3
update ntt-pipeline tests
ayakayorihiro Feb 12, 2025
785956b
merge
ayakayorihiro Feb 12, 2025
79a5219
create attrbutes for components when locations are being tracked
ayakayorihiro Feb 12, 2025
19c09d4
actually fix ntt tests
ayakayorihiro Feb 12, 2025
f0f1f23
fix relay tests
ayakayorihiro Feb 12, 2025
09d7ea1
fix builder tests
ayakayorihiro Feb 12, 2025
a8bf9d3
update systolic test
ayakayorihiro Feb 12, 2025
b352732
make black happy
ayakayorihiro Feb 12, 2025
0b81617
update after python format changes
ayakayorihiro Feb 12, 2025
06573d7
fix all but two tests
ayakayorihiro Feb 13, 2025
f2f2649
fix the mypy warning that has been yelling at me for an eternity
EclecticGriffin Feb 13, 2025
cfd824d
add another code block to prevent the tools from choking
EclecticGriffin Feb 13, 2025
fd4ebb6
fix the formatting since mine accidentally broke it
EclecticGriffin Feb 13, 2025
1c0bc22
Option to not emit sourceloc
ayakayorihiro Feb 14, 2025
ff4ff5d
do not produce sourceloc info for yxi
ayakayorihiro Feb 14, 2025
2270179
fix exp tests from formatting changes
ayakayorihiro Feb 14, 2025
a464a63
Changes from Griffin's PR suggestions
ayakayorihiro Feb 14, 2025
09c97b1
merge with main
ayakayorihiro Feb 14, 2025
681c1a5
fix failing tests
ayakayorihiro Feb 14, 2025
e15309b
reformatting
ayakayorihiro Feb 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions calyx-py/calyx/py_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@
import inspect
import os

EMIT_FILEINFO = "CALYX_PY_SOURCELOC" in os.environ and bool(
os.environ.get("CALYX_PY_SOURCELOC")
"""
The global variable "CALYX_PY_SOURCELOC" determines whether, and how, source-location metadata will be emitted.

The modes are
"" (empty string): Omit sourceloc information
"test": Output sourceloc information with relative paths (should only be used for testing)
otherwise, output sourceloc information with absolute paths
ayakayorihiro marked this conversation as resolved.
Show resolved Hide resolved
"""
FILEINFO_OPT = "CALYX_PY_SOURCELOC" in os.environ and os.environ.get(
"CALYX_PY_SOURCELOC"
)


Expand Down Expand Up @@ -66,7 +74,13 @@ def determine_source_loc() -> Optional[int]:
if user is None:
return None

return PosTable.add_entry(frame.filename, frame.lineno)
# filename depends on whether we're testing or not.
if FILEINFO_OPT == "test":
filename = os.path.relpath(frame.filename)
else:
filename = frame.filename

return PosTable.add_entry(filename, frame.lineno)

@staticmethod
def add_entry(filename, line_num):
Expand Down Expand Up @@ -109,7 +123,7 @@ def doc(self) -> str:
for key, val in self.meta.items():
out += f"{key}: {val}\n"
out += "}#"
if EMIT_FILEINFO and len(FileTable.table) > 0 and len(PosTable.table) > 0:
if bool(FILEINFO_OPT) and len(FileTable.table) > 0 and len(PosTable.table) > 0:
out += "\n\nsourceinfo #{\n"
out += FileTable.emit_fileinfo_metadata()
out += PosTable.emit_fileinfo_metadata()
Expand Down Expand Up @@ -173,7 +187,7 @@ def doc(self) -> str:
latency_annotation = (
f"static<{self.latency}> " if self.latency is not None else ""
)
if EMIT_FILEINFO and self.loc is not None:
if bool(FILEINFO_OPT) and self.loc is not None:
self.attributes.add(CompAttribute("pos", self.loc))
attribute_annotation = (
f"<{', '.join([f'{a.doc()}' for a in sorted(self.attributes, key=lambda a: a.name)])}>"
Expand Down Expand Up @@ -259,7 +273,7 @@ def __hash__(self):

def doc(self) -> str:
if self.name == "pos":
return f'"{self.name}"={{{self.value}}}' if EMIT_FILEINFO else ""
return f'"{self.name}"={{{self.value}}}' if bool(FILEINFO_OPT) else ""
else:
return f'"{self.name}"={self.value}'

Expand All @@ -276,7 +290,7 @@ def doc(self) -> str:
if self.value is None:
return f"@{self.name}"
elif self.name == "pos":
return f"@{self.name}{{{self.value}}}" if EMIT_FILEINFO else ""
return f"@{self.name}{{{self.value}}}" if bool(FILEINFO_OPT) else ""
else:
return f"@{self.name}({self.value})"

Expand All @@ -291,7 +305,7 @@ def __hash__(self):

def doc(self) -> str:
if self.name == "pos":
return f'"{self.name}"={{{self.value}}}' if EMIT_FILEINFO else ""
return f'"{self.name}"={{{self.value}}}' if bool(FILEINFO_OPT) else ""
else:
return f'"{self.name}"={self.value}'

Expand Down Expand Up @@ -416,7 +430,7 @@ def doc(self) -> str:
), "Cell cannot be both a ref and external"
if self.is_external:
self.attributes.add(CellAttribute("external"))
if EMIT_FILEINFO and self.loc is not None:
if bool(FILEINFO_OPT) and self.loc is not None:
self.attributes.add(CellAttribute("pos", self.loc))
attribute_annotation = (
f"{' '.join([f'{a.doc()}' for a in sorted(self.attributes, key=lambda a: a.name)])} "
Expand Down Expand Up @@ -454,7 +468,7 @@ class Group(Structure):
def doc(self) -> str:
if self.static_delay is not None:
self.attributes.add(GroupAttribute("promotable", self.static_delay))
if EMIT_FILEINFO and self.loc is not None:
if bool(FILEINFO_OPT) and self.loc is not None:
self.attributes.add(GroupAttribute("pos", self.loc))
attribute_annotation = (
f"<{', '.join([f'{a.doc()}' for a in sorted(self.attributes, key=lambda a: a.name)])}>"
Expand Down Expand Up @@ -608,7 +622,7 @@ class Control(Emittable):

def ctrl_with_pos_attribute(source: str, loc: Optional[int]) -> str:
"""adds the @pos attribute of loc is not None"""
if loc is None or not EMIT_FILEINFO:
if loc is None or not bool(FILEINFO_OPT):
return source
else:
return f"@pos{{{loc}}} {source}"
Expand Down
2 changes: 1 addition & 1 deletion calyx-py/test/source-loc/invoke-with-builder.expect
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ component foo<"pos"={4}>(a: 32) -> (out: 32) {

sourceinfo #{
ayakayorihiro marked this conversation as resolved.
Show resolved Hide resolved
FILES
0: /home/calyx/calyx-py/test/source-loc/invoke-with-builder.py
0: calyx-py/test/source-loc/invoke-with-builder.py
POSITIONS
0: 0 26
1: 0 29
Expand Down
2 changes: 1 addition & 1 deletion runt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ python3 {} |\
name = "[calyx-py] source-loc"
paths = ["calyx-py/test/source-loc/*.py"]
cmd = """
export CALYX_PY_SOURCELOC=true && python3 {}
export CALYX_PY_SOURCELOC=test && python3 {}
"""

##### Correctness Tests #####
Expand Down
Loading