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

NativeAOT SuperPMI collections #91037

Merged
merged 37 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
3e789e8
Initial superpmi.py work for nativeaot collections
TIHan Aug 22, 2023
40d8321
SPMI: Fix recording/replay of getExactClasses
jakobbotsch Aug 22, 2023
5ac1332
Feedback
jakobbotsch Aug 22, 2023
a10acf2
Merge remote-tracking branch 'jakob/fix-spmi-GetExactClasses' into na…
TIHan Aug 23, 2023
a820e8e
Use ilc-published
TIHan Aug 23, 2023
1ce9633
Merge branch 'nativeaot-collections' into nativeaot-collections-with-…
TIHan Aug 23, 2023
7666b20
Path fixes
TIHan Aug 23, 2023
80091e8
Merge branch 'nativeaot-collections' into nativeaot-collections-with-…
TIHan Aug 23, 2023
3a63fbb
Will this work?
TIHan Aug 23, 2023
9ee9f24
Copy ilc-published and aotsdk to Core_Root. Update superpmi.py to ref…
TIHan Aug 24, 2023
345135f
Change yml
TIHan Aug 25, 2023
45a10a2
Trying to add smoke_tests
TIHan Aug 25, 2023
64d7bd5
Building nativeaot tests in superpmi collect setup
TIHan Aug 26, 2023
432dc35
Do not check input_directory on nativeaot
TIHan Aug 26, 2023
6f2f731
Exclude native folder
TIHan Aug 26, 2023
ad12d8c
Using .ilc.rsp files for superpmi.py nativeaot
TIHan Aug 26, 2023
70a695d
Fix input directory
TIHan Aug 26, 2023
4315567
Making a copy of the rsp file
TIHan Aug 26, 2023
213cc4f
Fixing up references. Fixed architecture switch.
TIHan Aug 28, 2023
20d9c58
Fixing pinvokelist
TIHan Aug 28, 2023
19be152
Fix build
TIHan Aug 28, 2023
65be2c8
Cleanup. Stop overloading -assemblies to include ilc.rsp files, creat…
TIHan Aug 29, 2023
902c37b
Use paren
TIHan Aug 29, 2023
f12e59b
Let us try to skipnative since CI linux does not like the CLR test co…
TIHan Aug 29, 2023
1b9c698
Revert skipnative
TIHan Aug 30, 2023
f8a3c77
Build only smoketests, which skips the CustomMain native build. Fixup…
TIHan Sep 2, 2023
9e7a959
Merge branch 'main' into nativeaot-collections-with-jakob-fix
TIHan Sep 2, 2023
2f48356
Revert skipnative again...
TIHan Sep 2, 2023
81be4e2
Merge remote-tracking branch 'upstream/main' into nativeaot-collectio…
TIHan Sep 6, 2023
36e4d9e
Fix linux path
TIHan Sep 6, 2023
2b6bdeb
Add so.1 extension
TIHan Sep 6, 2023
3534f80
Feedback. Fix pmi libraries collections
TIHan Sep 7, 2023
62ab033
Include more file extensions for superpmi collections
TIHan Sep 7, 2023
e2cfc91
Fix yml
TIHan Sep 7, 2023
22a3d10
Fix-up more file paths that are located within the test's directories
TIHan Sep 8, 2023
f228db9
Fix paths again
TIHan Sep 8, 2023
3942328
Remove version
TIHan Sep 8, 2023
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
Prev Previous commit
Next Next commit
Using .ilc.rsp files for superpmi.py nativeaot
  • Loading branch information
TIHan committed Aug 26, 2023
commit ad12d8cefd837df9e2a83f4a93dd23085d9c8eda
66 changes: 15 additions & 51 deletions src/coreclr/scripts/superpmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,9 +861,17 @@ def set_and_report_env(env, root_env, dotnet_env = None):
# If we need them, collect all the assemblies we're going to use for the collection(s).
# Remove the files matching the `-exclude` arguments (case-insensitive) from the list.
if self.coreclr_args.pmi or self.coreclr_args.crossgen2 or self.coreclr_args.nativeaot:

def filter_assembly(file):
if self.coreclr_args.nativeaot:
extensions = [".ilc.rsp"]
else:
extensions = [".dll", ".exe"]
return any(file.endswith(extension) for extension in extensions) and (self.exclude is None or not any(e.lower() in file.lower() for e in self.exclude))

assemblies = []
for item in self.assemblies:
assemblies += get_files_from_path(item, match_func=lambda file: any(file.endswith(extension) for extension in [".dll", ".exe"]) and (self.exclude is None or not any(e.lower() in file.lower() for e in self.exclude)))
assemblies += get_files_from_path(item, match_func=filter_assembly)
if len(assemblies) == 0:
logging.error("No assemblies found using `-assemblies` and `-exclude` arguments!")
else:
Expand Down Expand Up @@ -1114,51 +1122,9 @@ async def run_crossgen2(print_prefix, assembly, self):
if self.coreclr_args.nativeaot is True:
logging.debug("Starting collection using nativeaot")

async def run_nativeaot(print_prefix, assembly, self):
""" Run nativeaot over all dlls
"""

root_nativeaot_output_filename = make_safe_filename("nativeaot_" + assembly) + ".out.dll"
nativeaot_output_assembly_filename = os.path.join(self.temp_location, root_nativeaot_output_filename)
try:
if os.path.exists(nativeaot_output_assembly_filename):
os.remove(nativeaot_output_assembly_filename)
except OSError as ose:
if "[WinError 32] The process cannot access the file because it is being used by another " \
"process:" in format(ose):
logging.warning("Skipping file %s. Got error: %s", nativeaot_output_assembly_filename, ose)
return
else:
raise ose

root_output_filename = make_safe_filename("nativeaot_" + assembly + "_")

# Create a temporary response file to put all the arguments to nativeaot (otherwise the path length limit could be exceeded):
#
# <dll to compile>
# -o:<output dll>
# -r:<Core_Root>\System.*.dll
# -r:<Core_Root>\Microsoft.*.dll
# -r:<Core_Root>\System.Private.CoreLib.dll
# -r:<Core_Root>\netstandard.dll
# --jitpath:<self.collection_shim_name>
# --codegenopt:<option>=<value> /// for each member of dotnet_env
#
# invoke with:
#
# ilc.exe @<temp.rsp>
#

rsp_file_handle, rsp_filepath = tempfile.mkstemp(suffix=".rsp", prefix=root_output_filename, dir=self.temp_location)
with open(rsp_file_handle, "w") as rsp_write_handle:
rsp_write_handle.write(assembly + "\n")
rsp_write_handle.write("-o:" + nativeaot_output_assembly_filename + "\n")
rsp_write_handle.write("-r:" + os.path.join(self.coreclr_args.nativeaot_aotsdk_path, "System.*.dll") + "\n")
rsp_write_handle.write("-r:" + os.path.join(self.core_root, "System.*.dll") + "\n")
rsp_write_handle.write("-r:" + os.path.join(self.core_root, "Microsoft.*.dll") + "\n")
rsp_write_handle.write("-r:" + os.path.join(self.core_root, "mscorlib.dll") + "\n")
rsp_write_handle.write("-r:" + os.path.join(self.core_root, "netstandard.dll") + "\n")
rsp_write_handle.write("--parallelism:1" + "\n")
async def run_nativeaot(print_prefix, rsp_filepath, self):
rsp_filepath = assembly
with open(rsp_filepath, "a") as rsp_write_handle:
rsp_write_handle.write("--jitpath:" + os.path.join(self.core_root, self.collection_shim_name) + "\n")
for var, value in dotnet_env.items():
rsp_write_handle.write("--codegenopt:" + var + "=" + value + "\n")
Expand All @@ -1172,6 +1138,8 @@ async def run_nativeaot(print_prefix, assembly, self):

begin_time = datetime.datetime.now()

root_output_filename = assembly

# Save the stdout and stderr to files, so we can see if nativeaot wrote any interesting messages.
# Use the name of the assembly as the basename of the file. mkstemp() will ensure the file
# is unique.
Expand Down Expand Up @@ -1222,11 +1190,7 @@ async def run_nativeaot(print_prefix, assembly, self):
old_env = os.environ.copy()
os.environ.update(nativeaot_command_env)

# Note: nativeaot compiles in parallel by default. However, it seems to lead to sharing violations
# in SuperPMI collection, accessing the MC file. So, disable nativeaot parallism by using
# the "--parallelism:1" switch, and allowing coarse-grained (per-assembly) parallelism here.
# It turns out this works better anyway, as there is a lot of non-parallel time between
# nativeaot parallel compilations.
assemblies = list(filter(lambda assembly: assembly.endswith(".ilc.rsp"), assemblies))
helper = AsyncSubprocessHelper(assemblies, verbose=True)
helper.run_to_completion(run_nativeaot, self)

Expand Down
13 changes: 4 additions & 9 deletions src/coreclr/scripts/superpmi_collect_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def sorter_by_size(pair):

if not os.path.isfile(curr_file_path):
continue
if not name.endswith(".dll") and not name.endswith(".exe"):
if not name.endswith(".dll") and not name.endswith(".exe") and not name.endswith(".ilc.rsp"):
continue

size = os.path.getsize(curr_file_path)
Expand Down Expand Up @@ -558,9 +558,9 @@ def make_readable(folder_name):
print('Ignoring PermissionError: {0}'.format(pe_error))

# Build nativeaot tests
# if coreclr_args.collection_type == "nativeaot":
# tests_build_file = "build.cmd" if is_windows else "build.sh"
# run_command([os.path.join(tests_directory, tests_build_file), "nativeaot", coreclr_args.build_type, "tree", "nativeaot"], source_directory)
if coreclr_args.collection_type == "nativeaot":
tests_build_file = "build.cmd" if is_windows else "build.sh"
run_command([os.path.join(tests_directory, tests_build_file), "nativeaot", coreclr_args.build_type, "tree", "nativeaot"], source_directory)

# NOTE: we can't use the build machine ".dotnet" to run on all platforms. E.g., the Windows x86 build uses a
# Windows x64 .dotnet\dotnet.exe that can't load a 32-bit shim. Thus, we always use corerun from Core_Root to invoke crossgen2.
Expand Down Expand Up @@ -591,11 +591,6 @@ def make_readable(folder_name):
exclude_files += [item for item in os.listdir(core_root_dir)
if os.path.isfile(os.path.join(core_root_dir, item)) and (item.endswith(".dll") or item.endswith(".exe"))]

if coreclr_args.collection_type == "nativeaot":
# do not include the test wrappers
exclude_files += ["Coreclr.TestWrapper.dll", "nativeaot.SmokeTests.XUnitWrapper.dll"]
exclude_directories += ['native']

partition_files(coreclr_args.input_directory, input_artifacts, coreclr_args.max_size, exclude_directories,
exclude_files)

Expand Down