Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

GH-115869: Reference implementation for hosting JIT stencils#129331

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
savannahostrowski wants to merge21 commits intopython:main
base:main
Choose a base branch
Loading
fromsavannahostrowski:host_jit
Draft
Changes from1 commit
Commits
Show all changes
21 commits
Select commitHold shift + click to select a range
a6105e6
Hosted stencil changes
savannahostrowskiJan 15, 2025
e9f5c47
Add stencils
savannahostrowskiJan 15, 2025
f7b87b4
Add digest file for local builds
savannahostrowskiJan 15, 2025
7ac3442
Use stencil path variable
savannahostrowskiJan 15, 2025
db4e940
Merge branch 'main' into host_jit
savannahostrowskiJan 26, 2025
047ab27
Fix debug builds
savannahostrowskiJan 26, 2025
9ea2666
Fix mypy
savannahostrowskiJan 26, 2025
b384ed1
Mypy
savannahostrowskiJan 26, 2025
b23f7e7
Update triple
savannahostrowskiJan 26, 2025
231cb23
Undo
savannahostrowskiJan 26, 2025
9f18b7e
Rename workflow step and apply stencils
savannahostrowskiJan 26, 2025
406e936
Remove windows aarch stencil and update README
savannahostrowskiJan 26, 2025
f5bf9cd
Debugging
savannahostrowskiJan 27, 2025
13bfc68
print config args
savannahostrowskiJan 27, 2025
a34fa62
Simplify flags for now
savannahostrowskiJan 27, 2025
3a3fa75
Update stencils
savannahostrowskiJan 27, 2025
9ceb522
📜🤖 Added by blurb_it.
blurb-it[bot]Jan 27, 2025
84b42f1
Fix typo
savannahostrowskiFeb 11, 2025
beab423
Merge branch 'main' into host_jit
savannahostrowskiFeb 11, 2025
d3508b2
Apply patch
savannahostrowskiFeb 12, 2025
b9fc9c6
Merge branch 'main' into host_jit
savannahostrowskiMar 4, 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
PrevPrevious commit
NextNext commit
Fix debug builds
  • Loading branch information
@savannahostrowski
savannahostrowski committedJan 26, 2025
commit047ab27ba63206f7fe764a2bbd3f184ce48141c4
69 changes: 53 additions & 16 deletionsTools/jit/_targets.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@
import re
import shutil
import sys
import sysconfig
import tempfile
import typing

Expand All@@ -27,6 +28,14 @@
CPYTHON = TOOLS.parent
PYTHON_EXECUTOR_CASES_C_H = CPYTHON / "Python" / "executor_cases.c.h"
TOOLS_JIT_TEMPLATE_C = TOOLS_JIT / "template.c"
SUPPORTED_TRIPLES = {
"aarch64-apple-darwin",
"aarch64-unknown-linux-gnu",
"i686-pc-windows-msvc",
"x86_64-apple-darwin",
"x86_64-pc-windows-msvc",
"x86_64-pc-linux-gnu",
}

_S = typing.TypeVar("_S", _schema.COFFSection, _schema.ELFSection, _schema.MachOSection)
_R = typing.TypeVar(
Expand All@@ -45,6 +54,7 @@ class _Target(typing.Generic[_S, _R]):
debug: bool = False
verbose: bool = False
known_symbols: dict[str, int] = dataclasses.field(default_factory=dict)
stencil_name: str = ""

def _compute_digest(self, out: pathlib.Path) -> str:
hasher = hashlib.sha256()
Expand DownExpand Up@@ -190,27 +200,49 @@ def build(self, out: pathlib.Path, *, force: bool = False) -> None:
digest = f"{self._compute_digest(out)}\n"
jit_stencils = out / "jit_stencils.h"
jit_stencils_digest = out / "jit_stencils.h.digest"
hosted_stencil = TOOLS_JIT_STENCILS / f"{self.stencil_name}.h"

if not force and jit_stencils_digest.exists() and jit_stencils.exists():
if (
not force
and jit_stencils_digest.exists()
and jit_stencils.exists()
and hosted_stencil.exists()
):
if jit_stencils_digest.read_text() == digest:
return

# We need to ignore the version number for Darwin targets
target = self.triple
darwin_index = target.find("-darwin")
if darwin_index != -1:
target = self.triple[: darwin_index + len("-darwin")]

jit_stencils = TOOLS_JIT_STENCILS / f"{target}.h"
stencil_groups = asyncio.run(self._build_stencils())
jit_stencils_new =TOOLS_JIT_STENCILS /f"{target}.h.new"
jit_stencils_new =out /"jit_stencils.h.new"
try:
with jit_stencils_new.open("w", newline="\n") as file:
for line in _writer.dump(stencil_groups, self.known_symbols):
file.write(f"{line}\n")
try:
jit_stencils_new.replace(jit_stencils)
shutil.copy(jit_stencils, out / "jit_stencils.h")

if "windows" in self.triple:
JIT_ARGS = {
"--experimental-jit"
} # TODO: Need to figure out the right flags here for Windows
copy_stencils = True

else:
JIT_ARGS = {
"--enable-experimental-jit",
"--with-lto",
"--enable-optimizations",
}
makefile = out / "Makefile"
config_args = re.search(
r"CONFIG_ARGS\s*=\s*'(.*)'", makefile.read_text()
).group(1)
copy_stencils = config_args and all(
arg in JIT_ARGS for arg in config_args.split()
)

copy_stencils = copy_stencils and self.triple in SUPPORTED_TRIPLES
if copy_stencils:
shutil.copy(jit_stencils, hosted_stencil)
except FileNotFoundError:
# another process probably already moved the file
if not jit_stencils.is_file():
Expand DownExpand Up@@ -495,9 +527,12 @@ def get_target(host: str) -> _COFF | _ELF | _MachO:
"""Build a _Target for the given host "triple" and options."""
target: _COFF | _ELF | _MachO
if re.fullmatch(r"aarch64-apple-darwin.*", host):
target = _MachO(host, alignment=8, prefix="_")
target = _MachO(
host, alignment=8, prefix="_", stencil_name="aarch64-apple-darwin"
)
elif re.fullmatch(r"aarch64-pc-windows-msvc", host):
args = ["-fms-runtime-lib=dll"]
# stencil_name is omitted since aarch64-pc-windows-msvc is Tier 3
target = _COFF(host, alignment=8, args=args)
elif re.fullmatch(r"aarch64-.*-linux-gnu", host):
args = [
Expand All@@ -506,22 +541,24 @@ def get_target(host: str) -> _COFF | _ELF | _MachO:
# was required to disable them.
"-mno-outline-atomics",
]
target = _ELF(host, alignment=8, args=args)
target = _ELF(
host, alignment=8, args=args, stencil_name="aarch64-unknown-linux-gnu"
)
elif re.fullmatch(r"i686-pc-windows-msvc", host):
args = [
"-DPy_NO_ENABLE_SHARED",
# __attribute__((preserve_none)) is not supported
"-Wno-ignored-attributes",
]
target = _COFF(host, args=args, prefix="_")
target = _COFF(host, args=args, prefix="_", stencil_name="i686-pc-windows-msvc")
elif re.fullmatch(r"x86_64-apple-darwin.*", host):
target = _MachO(host, prefix="_")
target = _MachO(host, prefix="_", stencil_name="x86_64-apple-darwin")
elif re.fullmatch(r"x86_64-pc-windows-msvc", host):
args = ["-fms-runtime-lib=dll"]
target = _COFF(host, args=args)
target = _COFF(host, args=args, stencil_name="x86_64-pc-windows-msvc")
elif re.fullmatch(r"x86_64-.*-linux-gnu", host):
args = ["-fpic"]
target = _ELF(host, args=args)
target = _ELF(host, args=args, stencil_name="x86_64-pc-linux-gnu")
else:
raise ValueError(host)
return target

[8]ページ先頭

©2009-2025 Movatter.jp