Files
project_6/cccl_upstream/libcudacxx/codegen/generate_prologue_epilogue.py
EngineX CI 56fd68e7dd [INFRA] Import NVIDIA/CCCL upstream as optimization reference library
CCCL (CUDA C++ Core Libraries) provides:
- CUB: device/block/warp-level GPU primitives (reduce, scan, sort, topk)
- Thrust: high-level parallel algorithms (transform_reduce, sort, scan)
- libcudacxx: CUDA C++ standard library (atomics, barriers, memory)
- cudax: experimental features (memory resources, allocators)
- Tuning policies: per-SM hardware-specific algorithm parameters

Competition optimization vectors mapped to CCCL:
- Output TPS (83% weight): warp_reduce, block_reduce, device_topk
- Input TPS (14% weight): device_scan, block_load, prefetch
- Cache TPS (3% weight): prefix caching strategy patterns
- Memory (0.9 util): pooled/cached/buddy allocators

Source: https://github.com/NVIDIA/cccl (shallow clone, HEAD only)
License: Apache-2.0
2026-07-30 09:35:51 +00:00

246 lines
7.4 KiB
Python
Executable File

#!/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",
"lifetimebound",
"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)
// Suppress compiler warnings about C++ extensions.
#if _CCCL_COMPILER(GCC, >=, 12)
_CCCL_DIAG_SUPPRESS_GCC("-Wc++20-extensions")
_CCCL_DIAG_SUPPRESS_GCC("-Wc++23-extensions")
#endif // _CCCL_COMPILER(GCC, >=, 12)
#if _CCCL_COMPILER(GCC, >=, 14)
_CCCL_DIAG_SUPPRESS_GCC("-Wc++26-extensions")
#endif // _CCCL_COMPILER(GCC, >=, 14)
_CCCL_DIAG_SUPPRESS_CLANG("-Wc++20-extensions")
#if _CCCL_COMPILER(CLANG, >=, 17)
_CCCL_DIAG_SUPPRESS_CLANG("-Wc++23-extensions")
_CCCL_DIAG_SUPPRESS_CLANG("-Wc++26-extensions")
#else // ^^^ _CCCL_COMPILER(CLANG, >=, 17) ^^^ / vvv _CCCL_COMPILER(CLANG, <, 17) vvv
_CCCL_DIAG_SUPPRESS_CLANG("-Wc++2b-extensions")
#endif // ^^^ _CCCL_COMPILER(CLANG, <, 17) ^^^
// Suppress `if consteval`-related warnings.
_CCCL_DIAG_SUPPRESS_NVHPC(if_consteval_nonstandard)
_CCCL_DIAG_SUPPRESS_NVHPC(is_constant_evaluated_in_nonconstexpr_context)
_CCCL_DIAG_SUPPRESS_NVHPC(if_consteval_in_nonconstexpr_function)
_CCCL_DIAG_SUPPRESS_NVCC(3215) // "if consteval" and "if not consteval" are not standard in this mode
_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)