-
Notifications
You must be signed in to change notification settings - Fork 320
Generator for prologue/epilogue #7099
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
Merged
Merged
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
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 |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| ##===----------------------------------------------------------------------===## | ||
| ## | ||
| ## Part of libcu++, the C++ Standard Library for your entire system, | ||
| ## under the Apache License v2.0 with LLVM Exceptions. | ||
| ## See https://llvm.org/LICENSE.txt for license information. | ||
| ## SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| ## SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. | ||
| ## | ||
| ##===----------------------------------------------------------------------===## | ||
|
|
||
| import os | ||
|
|
||
| LIBCUDACXX_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
|
|
||
| LIBCUDACXX_CMAKE_DIR = os.path.join(LIBCUDACXX_DIR, "cmake") | ||
| LIBCUDACXX_CODEGEN_DIR = os.path.join(LIBCUDACXX_DIR, "codegen") | ||
| LIBCUDACXX_INCLUDE_DIR = os.path.join(LIBCUDACXX_DIR, "include") | ||
| LIBCUDACXX_TEST_DIR = os.path.join(LIBCUDACXX_DIR, "test") | ||
|
|
||
| DOCS_DIR = os.path.dirname(LIBCUDACXX_DIR) | ||
| DOCS_LIBCUDACXX_DIR = os.path.join(DOCS_DIR, "libcudacxx") |
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 |
|---|---|---|
| @@ -0,0 +1,236 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| ##===----------------------------------------------------------------------===## | ||
| ## | ||
| ## Part of libcu++, the C++ Standard Library for your entire system, | ||
| ## under the Apache License v2.0 with LLVM Exceptions. | ||
| ## See https://llvm.org/LICENSE.txt for license information. | ||
| ## SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| ## SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. | ||
| ## | ||
| ##===----------------------------------------------------------------------===## | ||
|
|
||
| import datetime | ||
| import os | ||
|
|
||
| import cccl_paths | ||
|
|
||
| PROLOGUE_FILE = os.path.join( | ||
| cccl_paths.LIBCUDACXX_INCLUDE_DIR, "cuda", "std", "__cccl", "prologue.h" | ||
| ) | ||
| EPILOGUE_FILE = os.path.join( | ||
| cccl_paths.LIBCUDACXX_INCLUDE_DIR, "cuda", "std", "__cccl", "epilogue.h" | ||
| ) | ||
|
|
||
| HEADER = f"""\ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of libcu++, the C++ Standard Library for your entire system, | ||
| // under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // SPDX-FileCopyrightText: Copyright (c) {datetime.datetime.now().year} NVIDIA CORPORATION & AFFILIATES. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // !!! DO NOT EDIT THIS FILE !!! This file is generated by utils/generate_prologue_epilogue.py. | ||
|
|
||
| // NO include guards here (this file is included multiple times)""" | ||
|
|
||
| FOOTER = """\ | ||
| // NO include guards here (this file is included multiple times) | ||
| """ | ||
|
|
||
| PUSH_POP_MACROS = { | ||
| "__declspec modifiers": [ | ||
| "align", | ||
| "allocate", | ||
| "allocator", | ||
| "appdomain", | ||
| "code_seg", | ||
| "deprecated", | ||
| "dllimport", | ||
| "dllexport", | ||
| "empty_bases", | ||
| "hybrid_patchable", | ||
| "jitintrinsic", | ||
| "naked", | ||
| "noalias", | ||
| "noinline", | ||
| "noreturn", | ||
| "nothrow", | ||
| "novtable", | ||
| "no_sanitize_address", | ||
| "process", | ||
| "property", | ||
| "restrict", | ||
| "safebuffers", | ||
| "selectany", | ||
| "spectre", | ||
| "thread", | ||
| "uuid", | ||
| ], | ||
| "[[msvc::attribute]] attributes": [ | ||
| "msvc", | ||
| "flatten", | ||
| "forceinline", | ||
| "forceinline_calls", | ||
| "intrinsic", | ||
| "noinline", | ||
| "noinline_calls", | ||
| "no_tls_guard", | ||
| ], | ||
| "Windows nasty macros": ["min", "max", "interface"], | ||
| "sal.h on Windows": ["__valid", "__callback"], | ||
| "other macros": ["clang"], | ||
| "sys/sysmacros.h on linux": ["major", "minor", "makedev"], | ||
| } | ||
|
|
||
|
|
||
| def write_section(file, section): | ||
| file.write(section) | ||
| file.write("\n\n") | ||
|
|
||
|
|
||
| def make_prologue(file): | ||
| # Write common header. | ||
| write_section(file, HEADER) | ||
|
|
||
| # Add prologue/epilogue include logic check. | ||
| write_section( | ||
| file, | ||
| """\ | ||
| #if defined(_CCCL_PROLOGUE_INCLUDED) | ||
| # error \\ | ||
| "cccl internal error: <cuda/std/__cccl/epilogue.h> must be included before next <cuda/std/__cccl/prologue.h> is reincluded" | ||
| #endif | ||
| #define _CCCL_PROLOGUE_INCLUDED() 1""", | ||
| ) | ||
|
|
||
| # Add necessary includes. | ||
| write_section( | ||
| file, | ||
| """\ | ||
| #include <cuda/std/__cccl/compiler.h> | ||
| #include <cuda/std/__cccl/diagnostic.h> | ||
| #include <cuda/std/__cccl/dialect.h>""", | ||
| ) | ||
|
|
||
| # Add push macros. | ||
| for group_name, macros in PUSH_POP_MACROS.items(): | ||
| write_section(file, f"// {group_name}") | ||
| for macro in macros: | ||
| write_section( | ||
| file, | ||
| f'''\ | ||
| #if defined({macro}) | ||
| # pragma push_macro("{macro}") | ||
| # undef {macro} | ||
| # define _CCCL_POP_MACRO_{macro} | ||
| #endif // defined({macro})''', | ||
| ) | ||
|
|
||
| # Add warnings suppressions. | ||
| write_section( | ||
| file, | ||
| '''\ | ||
| _CCCL_DIAG_PUSH | ||
| _CCCL_NV_DIAG_PUSH() | ||
|
|
||
| // disable some msvc warnings | ||
| // https://github.com/microsoft/STL/blob/master/stl/inc/yvals_core.h#L353 | ||
| // warning C4100: 'quack': unreferenced formal parameter | ||
| // warning C4127: conditional expression is constant | ||
| // warning C4180: qualifier applied to function type has no meaning; ignored | ||
| // warning C4197: 'purr': top-level volatile in cast is ignored | ||
| // warning C4324: 'roar': structure was padded due to alignment specifier | ||
| // warning C4455: literal suffix identifiers that do not start with an underscore are reserved | ||
| // warning C4503: 'hum': decorated name length exceeded, name was truncated | ||
| // warning C4522: 'woof' : multiple assignment operators specified | ||
| // warning C4668: 'meow' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif' | ||
| // warning C4800: 'boo': forcing value to bool 'true' or 'false' (performance warning) | ||
| // warning C4996: 'meow': was declared deprecated | ||
| _CCCL_DIAG_SUPPRESS_MSVC(4100 4127 4180 4197 4296 4324 4455 4503 4522 4668 4800 4996) | ||
|
|
||
| // disable warnings about using C++23 features in C++20 (needed for if consteval) | ||
| #if _CCCL_HAS_IF_CONSTEVAL_IN_CXX20() | ||
| # if _CCCL_COMPILER(GCC, >=, 12) | ||
| _CCCL_DIAG_SUPPRESS_GCC("-Wc++23-extensions") | ||
| # endif // _CCCL_COMPILER(GCC, >=, 12) | ||
| # if _CCCL_COMPILER(CLANG, >=, 17) | ||
| _CCCL_DIAG_SUPPRESS_CLANG("-Wc++23-extensions") | ||
| # else // ^^^ _CCCL_COMPILER(CLANG, >=, 17) ^^^ / vvv _CCCL_COMPILER(CLANG, <, 17) vvv | ||
| _CCCL_DIAG_SUPPRESS_CLANG("-Wc++2b-extensions") | ||
| # endif // ^^^ _CCCL_COMPILER(CLANG, <, 17) ^^^ | ||
| _CCCL_DIAG_SUPPRESS_NVHPC(if_consteval_nonstandard) | ||
|
|
||
| _CCCL_DIAG_SUPPRESS_NVCC(3215) // "if consteval" and "if not consteval" are not standard in this mode | ||
| #endif // _CCCL_HAS_IF_CONSTEVAL_IN_CXX20() | ||
|
|
||
| _CCCL_DIAG_SUPPRESS_NVHPC(is_constant_evaluated_in_nonconstexpr_context) | ||
|
|
||
| _CCCL_DIAG_SUPPRESS_NVCC(3206) // "if consteval" and "if not consteval" are meaningless in a non-constexpr function | ||
| _CCCL_DIAG_SUPPRESS_NVCC(3060) // call to __builtin_is_constant_evaluated appearing in a non-constexpr function always | ||
| // produces "false"''', | ||
| ) | ||
|
|
||
| # Write the common footer. | ||
| file.write(FOOTER) | ||
|
|
||
|
|
||
| def make_epilogue(file): | ||
| # Write common header. | ||
| write_section(file, HEADER) | ||
|
|
||
| # Write includes. | ||
| write_section( | ||
| file, | ||
| """\ | ||
| #include <cuda/std/__cccl/compiler.h> | ||
| #include <cuda/std/__cccl/diagnostic.h>""", | ||
| ) | ||
|
|
||
| # Add prologue/epilogue include logic check. | ||
| write_section( | ||
| file, | ||
| """\ | ||
| #if !defined(_CCCL_PROLOGUE_INCLUDED) | ||
| # error "cccl internal error: <cuda/std/__cccl/prologue.h> must be included before <cuda/std/__cccl/epilogue.h>" | ||
| #endif | ||
| #undef _CCCL_PROLOGUE_INCLUDED""", | ||
| ) | ||
|
|
||
| # Pop warning suppressions. | ||
| write_section( | ||
| file, | ||
| """\ | ||
| _CCCL_NV_DIAG_POP() | ||
| _CCCL_DIAG_POP""", | ||
| ) | ||
|
|
||
| # Add pop macros. | ||
| for group_name, macros in PUSH_POP_MACROS.items(): | ||
| write_section(file, f"// {group_name}") | ||
| for macro in macros: | ||
| write_section( | ||
| file, | ||
| f'''\ | ||
| #if defined({macro}) | ||
| # error \\ | ||
| "cccl internal error: macro `{macro}` was redefined between <cuda/std/__cccl/prologue.h> and <cuda/std/__cccl/epilogue.h>" | ||
| #elif defined(_CCCL_POP_MACRO_{macro}) | ||
| # pragma pop_macro("{macro}") | ||
| # undef _CCCL_POP_MACRO_{macro} | ||
| #endif''', | ||
| ) | ||
|
|
||
| # Write the common footer. | ||
| file.write(FOOTER) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| with open(PROLOGUE_FILE, "w") as file: | ||
| make_prologue(file) | ||
|
|
||
| with open(EPILOGUE_FILE, "w") as file: | ||
| make_epilogue(file) |
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
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.
Uh oh!
There was an error while loading. Please reload this page.