-
Notifications
You must be signed in to change notification settings - Fork 321
Use pathlib in cuda.bindings build hooks and tests (part 6 of #2410) #2501
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
Open
LeSingh1
wants to merge
2
commits into
NVIDIA:main
Choose a base branch
from
LeSingh1:pathlib/cuda-bindings-hooks
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -85,31 +85,33 @@ def _get_cuda_path() -> str: | |
|
|
||
|
|
||
| def _rename_architecture_specific_files(): | ||
| path = os.path.join("cuda", "bindings", "_internal") | ||
| path = Path("cuda", "bindings", "_internal") | ||
| if sys.platform == "linux": | ||
| src_files = glob.glob(os.path.join(path, "*_linux.pyx")) | ||
| src_files = path.glob("*_linux.pyx") | ||
| elif sys.platform == "win32": | ||
| src_files = glob.glob(os.path.join(path, "*_windows.pyx")) | ||
| src_files = path.glob("*_windows.pyx") | ||
| else: | ||
| raise RuntimeError(f"platform is unrecognized: {sys.platform}") | ||
| dst_files = [] | ||
| for src in src_files: | ||
| with tempfile.NamedTemporaryFile(delete=False, dir=".") as f: | ||
| shutil.copy2(src, f.name) | ||
| f_name = f.name | ||
| dst = src.replace("_linux", "").replace("_windows", "") | ||
| os.replace(f_name, f"./{dst}") | ||
| dst = src.with_name(src.name.replace("_linux", "").replace("_windows", "")) | ||
| os.replace(f_name, dst) | ||
| dst_files.append(dst) | ||
| return dst_files | ||
|
|
||
|
|
||
| def _prep_extensions(sources, libraries, include_dirs, library_dirs, extra_compile_args, extra_link_args): | ||
| pattern = sources[0] | ||
| # sources[0] is a pattern rooted anywhere, not a directory to search, so | ||
| # there is no Path.glob() form for it. | ||
| pattern = str(sources[0]) | ||
| files = glob.glob(pattern) | ||
| libraries = libraries if libraries else [] | ||
| exts = [] | ||
| for pyx in files: | ||
| mod_name = pyx.replace(".pyx", "").replace(os.sep, ".").replace("/", ".") | ||
| mod_name = ".".join(Path(pyx).with_suffix("").parts) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| exts.append( | ||
| Extension( | ||
| mod_name, | ||
|
|
@@ -155,16 +157,16 @@ def _build_cuda_bindings(debug=False): | |
| compile_for_coverage = bool(int(os.environ.get("CUDA_PYTHON_COVERAGE", "0"))) | ||
|
|
||
| # Prepare compile/link arguments | ||
| include_path_list = [os.path.join(cuda_path, "include")] | ||
| include_path_list = [str(Path(cuda_path, "include"))] | ||
| include_dirs = [ | ||
| os.path.dirname(sysconfig.get_path("include")), | ||
| str(Path(sysconfig.get_path("include")).parent), | ||
| ] + include_path_list | ||
| library_dirs = [sysconfig.get_path("platlib"), os.path.join(os.sys.prefix, "lib")] | ||
| library_dirs = [sysconfig.get_path("platlib"), str(Path(os.sys.prefix, "lib"))] | ||
| if sys.platform == "win32": | ||
| cudalib_subdirs = [r"lib\arm64"] if sysconfig.get_platform() == "win-arm64" else [r"lib\x64"] | ||
| else: | ||
| cudalib_subdirs = ["lib64", "lib"] | ||
| library_dirs.extend(os.path.join(cuda_path, subdir) for subdir in cudalib_subdirs) | ||
| library_dirs.extend(str(Path(cuda_path, subdir)) for subdir in cudalib_subdirs) | ||
|
|
||
| extra_compile_args = [] | ||
| extra_link_args = [] | ||
|
|
@@ -207,7 +209,7 @@ def _cleanup_dst_files(): | |
| cuda_bindings_files = [f for f in cuda_bindings_files if "cufile" not in f] | ||
|
|
||
| def get_static_libraries(f): | ||
| if os.path.basename(f) in ("runtime.pyx", "runtime_ptds.pyx"): | ||
| if f.name in ("runtime.pyx", "runtime_ptds.pyx"): | ||
| if sys.platform == "linux": | ||
| return ["cudart_static", "rt"] | ||
| else: | ||
|
|
@@ -221,7 +223,7 @@ def get_static_libraries(f): | |
| *(([f], None) for f in cuda_bindings_files), | ||
| # internal files used by generated bindings | ||
| (["cuda/bindings/_internal/utils.pyx"], None), | ||
| *(([f], get_static_libraries(f)) for f in dst_files if f.endswith(".pyx")), | ||
| *(([f], get_static_libraries(f)) for f in dst_files if f.suffix == ".pyx"), | ||
| ] | ||
|
|
||
| for sources, libraries in sources_list: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this comment. Would
Path().glob(pattern)not work?