diff --git a/.gitattributes b/.gitattributes index ffdb50485e44c1b0d3bad8d9b0878c73b4fd14e2..46e6a7fcee0bdb7ca457e6b49a6eb5392d988d0a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1770,3 +1770,4 @@ vllm/lib/python3.10/site-packages/cupy/_core/_accelerator.cpython-310-x86_64-lin vllm/lib/python3.10/site-packages/cupy/_core/_fusion_kernel.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text vllm/lib/libcrypto.so filter=lfs diff=lfs merge=lfs -text vllm/lib/libcrypto.a filter=lfs diff=lfs merge=lfs -text +vllm/lib/python3.10/site-packages/cupy/_core/_routines_statistics.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text diff --git a/videollama2/lib/python3.10/site-packages/pip/_internal/utils/__pycache__/packaging.cpython-310.pyc b/videollama2/lib/python3.10/site-packages/pip/_internal/utils/__pycache__/packaging.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..35b7d5329b0e12b4bd90ee2bd96b27cb0e91ba44 Binary files /dev/null and b/videollama2/lib/python3.10/site-packages/pip/_internal/utils/__pycache__/packaging.cpython-310.pyc differ diff --git a/videollama2/lib/python3.10/site-packages/pip/_internal/utils/__pycache__/unpacking.cpython-310.pyc b/videollama2/lib/python3.10/site-packages/pip/_internal/utils/__pycache__/unpacking.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4d0e588c2501ff3f2f023701e283c1adbacdcb0c Binary files /dev/null and b/videollama2/lib/python3.10/site-packages/pip/_internal/utils/__pycache__/unpacking.cpython-310.pyc differ diff --git a/videollama2/lib/python3.10/site-packages/pip/_internal/utils/compatibility_tags.py b/videollama2/lib/python3.10/site-packages/pip/_internal/utils/compatibility_tags.py new file mode 100644 index 0000000000000000000000000000000000000000..2e7b7450dcea5b3bbcfe118f2e4cbe3fc16a7b1a --- /dev/null +++ b/videollama2/lib/python3.10/site-packages/pip/_internal/utils/compatibility_tags.py @@ -0,0 +1,188 @@ +"""Generate and work with PEP 425 Compatibility Tags. +""" + +import re +from typing import List, Optional, Tuple + +from pip._vendor.packaging.tags import ( + PythonVersion, + Tag, + compatible_tags, + cpython_tags, + generic_tags, + interpreter_name, + interpreter_version, + ios_platforms, + mac_platforms, +) + +_apple_arch_pat = re.compile(r"(.+)_(\d+)_(\d+)_(.+)") + + +def version_info_to_nodot(version_info: Tuple[int, ...]) -> str: + # Only use up to the first two numbers. + return "".join(map(str, version_info[:2])) + + +def _mac_platforms(arch: str) -> List[str]: + match = _apple_arch_pat.match(arch) + if match: + name, major, minor, actual_arch = match.groups() + mac_version = (int(major), int(minor)) + arches = [ + # Since we have always only checked that the platform starts + # with "macosx", for backwards-compatibility we extract the + # actual prefix provided by the user in case they provided + # something like "macosxcustom_". It may be good to remove + # this as undocumented or deprecate it in the future. + "{}_{}".format(name, arch[len("macosx_") :]) + for arch in mac_platforms(mac_version, actual_arch) + ] + else: + # arch pattern didn't match (?!) + arches = [arch] + return arches + + +def _ios_platforms(arch: str) -> List[str]: + match = _apple_arch_pat.match(arch) + if match: + name, major, minor, actual_multiarch = match.groups() + ios_version = (int(major), int(minor)) + arches = [ + # Since we have always only checked that the platform starts + # with "ios", for backwards-compatibility we extract the + # actual prefix provided by the user in case they provided + # something like "ioscustom_". It may be good to remove + # this as undocumented or deprecate it in the future. + "{}_{}".format(name, arch[len("ios_") :]) + for arch in ios_platforms(ios_version, actual_multiarch) + ] + else: + # arch pattern didn't match (?!) + arches = [arch] + return arches + + +def _custom_manylinux_platforms(arch: str) -> List[str]: + arches = [arch] + arch_prefix, arch_sep, arch_suffix = arch.partition("_") + if arch_prefix == "manylinux2014": + # manylinux1/manylinux2010 wheels run on most manylinux2014 systems + # with the exception of wheels depending on ncurses. PEP 599 states + # manylinux1/manylinux2010 wheels should be considered + # manylinux2014 wheels: + # https://www.python.org/dev/peps/pep-0599/#backwards-compatibility-with-manylinux2010-wheels + if arch_suffix in {"i686", "x86_64"}: + arches.append("manylinux2010" + arch_sep + arch_suffix) + arches.append("manylinux1" + arch_sep + arch_suffix) + elif arch_prefix == "manylinux2010": + # manylinux1 wheels run on most manylinux2010 systems with the + # exception of wheels depending on ncurses. PEP 571 states + # manylinux1 wheels should be considered manylinux2010 wheels: + # https://www.python.org/dev/peps/pep-0571/#backwards-compatibility-with-manylinux1-wheels + arches.append("manylinux1" + arch_sep + arch_suffix) + return arches + + +def _get_custom_platforms(arch: str) -> List[str]: + arch_prefix, arch_sep, arch_suffix = arch.partition("_") + if arch.startswith("macosx"): + arches = _mac_platforms(arch) + elif arch.startswith("ios"): + arches = _ios_platforms(arch) + elif arch_prefix in ["manylinux2014", "manylinux2010"]: + arches = _custom_manylinux_platforms(arch) + else: + arches = [arch] + return arches + + +def _expand_allowed_platforms(platforms: Optional[List[str]]) -> Optional[List[str]]: + if not platforms: + return None + + seen = set() + result = [] + + for p in platforms: + if p in seen: + continue + additions = [c for c in _get_custom_platforms(p) if c not in seen] + seen.update(additions) + result.extend(additions) + + return result + + +def _get_python_version(version: str) -> PythonVersion: + if len(version) > 1: + return int(version[0]), int(version[1:]) + else: + return (int(version[0]),) + + +def _get_custom_interpreter( + implementation: Optional[str] = None, version: Optional[str] = None +) -> str: + if implementation is None: + implementation = interpreter_name() + if version is None: + version = interpreter_version() + return f"{implementation}{version}" + + +def get_supported( + version: Optional[str] = None, + platforms: Optional[List[str]] = None, + impl: Optional[str] = None, + abis: Optional[List[str]] = None, +) -> List[Tag]: + """Return a list of supported tags for each version specified in + `versions`. + + :param version: a string version, of the form "33" or "32", + or None. The version will be assumed to support our ABI. + :param platform: specify a list of platforms you want valid + tags for, or None. If None, use the local system platform. + :param impl: specify the exact implementation you want valid + tags for, or None. If None, use the local interpreter impl. + :param abis: specify a list of abis you want valid + tags for, or None. If None, use the local interpreter abi. + """ + supported: List[Tag] = [] + + python_version: Optional[PythonVersion] = None + if version is not None: + python_version = _get_python_version(version) + + interpreter = _get_custom_interpreter(impl, version) + + platforms = _expand_allowed_platforms(platforms) + + is_cpython = (impl or interpreter_name()) == "cp" + if is_cpython: + supported.extend( + cpython_tags( + python_version=python_version, + abis=abis, + platforms=platforms, + ) + ) + else: + supported.extend( + generic_tags( + interpreter=interpreter, + abis=abis, + platforms=platforms, + ) + ) + supported.extend( + compatible_tags( + python_version=python_version, + interpreter=interpreter, + platforms=platforms, + ) + ) + + return supported diff --git a/videollama2/lib/python3.10/site-packages/pip/_internal/utils/datetime.py b/videollama2/lib/python3.10/site-packages/pip/_internal/utils/datetime.py new file mode 100644 index 0000000000000000000000000000000000000000..8668b3b0ec1deec2aeb7ff6bd94265d6705e05bf --- /dev/null +++ b/videollama2/lib/python3.10/site-packages/pip/_internal/utils/datetime.py @@ -0,0 +1,11 @@ +"""For when pip wants to check the date or time. +""" + +import datetime + + +def today_is_later_than(year: int, month: int, day: int) -> bool: + today = datetime.date.today() + given = datetime.date(year, month, day) + + return today > given diff --git a/videollama2/lib/python3.10/site-packages/pip/_internal/utils/deprecation.py b/videollama2/lib/python3.10/site-packages/pip/_internal/utils/deprecation.py new file mode 100644 index 0000000000000000000000000000000000000000..0911147e784737f58f174dce98ecae32b615c7b7 --- /dev/null +++ b/videollama2/lib/python3.10/site-packages/pip/_internal/utils/deprecation.py @@ -0,0 +1,124 @@ +""" +A module that implements tooling to enable easy warnings about deprecations. +""" + +import logging +import warnings +from typing import Any, Optional, TextIO, Type, Union + +from pip._vendor.packaging.version import parse + +from pip import __version__ as current_version # NOTE: tests patch this name. + +DEPRECATION_MSG_PREFIX = "DEPRECATION: " + + +class PipDeprecationWarning(Warning): + pass + + +_original_showwarning: Any = None + + +# Warnings <-> Logging Integration +def _showwarning( + message: Union[Warning, str], + category: Type[Warning], + filename: str, + lineno: int, + file: Optional[TextIO] = None, + line: Optional[str] = None, +) -> None: + if file is not None: + if _original_showwarning is not None: + _original_showwarning(message, category, filename, lineno, file, line) + elif issubclass(category, PipDeprecationWarning): + # We use a specially named logger which will handle all of the + # deprecation messages for pip. + logger = logging.getLogger("pip._internal.deprecations") + logger.warning(message) + else: + _original_showwarning(message, category, filename, lineno, file, line) + + +def install_warning_logger() -> None: + # Enable our Deprecation Warnings + warnings.simplefilter("default", PipDeprecationWarning, append=True) + + global _original_showwarning + + if _original_showwarning is None: + _original_showwarning = warnings.showwarning + warnings.showwarning = _showwarning + + +def deprecated( + *, + reason: str, + replacement: Optional[str], + gone_in: Optional[str], + feature_flag: Optional[str] = None, + issue: Optional[int] = None, +) -> None: + """Helper to deprecate existing functionality. + + reason: + Textual reason shown to the user about why this functionality has + been deprecated. Should be a complete sentence. + replacement: + Textual suggestion shown to the user about what alternative + functionality they can use. + gone_in: + The version of pip does this functionality should get removed in. + Raises an error if pip's current version is greater than or equal to + this. + feature_flag: + Command-line flag of the form --use-feature={feature_flag} for testing + upcoming functionality. + issue: + Issue number on the tracker that would serve as a useful place for + users to find related discussion and provide feedback. + """ + + # Determine whether or not the feature is already gone in this version. + is_gone = gone_in is not None and parse(current_version) >= parse(gone_in) + + message_parts = [ + (reason, f"{DEPRECATION_MSG_PREFIX}{{}}"), + ( + gone_in, + ( + "pip {} will enforce this behaviour change." + if not is_gone + else "Since pip {}, this is no longer supported." + ), + ), + ( + replacement, + "A possible replacement is {}.", + ), + ( + feature_flag, + ( + "You can use the flag --use-feature={} to test the upcoming behaviour." + if not is_gone + else None + ), + ), + ( + issue, + "Discussion can be found at https://github.com/pypa/pip/issues/{}", + ), + ] + + message = " ".join( + format_str.format(value) + for value, format_str in message_parts + if format_str is not None and value is not None + ) + + # Raise as an error if this behaviour is deprecated. + if is_gone: + raise PipDeprecationWarning(message) + + warnings.warn(message, category=PipDeprecationWarning, stacklevel=2) diff --git a/videollama2/lib/python3.10/site-packages/pip/_internal/utils/direct_url_helpers.py b/videollama2/lib/python3.10/site-packages/pip/_internal/utils/direct_url_helpers.py new file mode 100644 index 0000000000000000000000000000000000000000..66020d3964ad4d8bc55893380383b271642471f7 --- /dev/null +++ b/videollama2/lib/python3.10/site-packages/pip/_internal/utils/direct_url_helpers.py @@ -0,0 +1,87 @@ +from typing import Optional + +from pip._internal.models.direct_url import ArchiveInfo, DirectUrl, DirInfo, VcsInfo +from pip._internal.models.link import Link +from pip._internal.utils.urls import path_to_url +from pip._internal.vcs import vcs + + +def direct_url_as_pep440_direct_reference(direct_url: DirectUrl, name: str) -> str: + """Convert a DirectUrl to a pip requirement string.""" + direct_url.validate() # if invalid, this is a pip bug + requirement = name + " @ " + fragments = [] + if isinstance(direct_url.info, VcsInfo): + requirement += ( + f"{direct_url.info.vcs}+{direct_url.url}@{direct_url.info.commit_id}" + ) + elif isinstance(direct_url.info, ArchiveInfo): + requirement += direct_url.url + if direct_url.info.hash: + fragments.append(direct_url.info.hash) + else: + assert isinstance(direct_url.info, DirInfo) + requirement += direct_url.url + if direct_url.subdirectory: + fragments.append("subdirectory=" + direct_url.subdirectory) + if fragments: + requirement += "#" + "&".join(fragments) + return requirement + + +def direct_url_for_editable(source_dir: str) -> DirectUrl: + return DirectUrl( + url=path_to_url(source_dir), + info=DirInfo(editable=True), + ) + + +def direct_url_from_link( + link: Link, source_dir: Optional[str] = None, link_is_in_wheel_cache: bool = False +) -> DirectUrl: + if link.is_vcs: + vcs_backend = vcs.get_backend_for_scheme(link.scheme) + assert vcs_backend + url, requested_revision, _ = vcs_backend.get_url_rev_and_auth( + link.url_without_fragment + ) + # For VCS links, we need to find out and add commit_id. + if link_is_in_wheel_cache: + # If the requested VCS link corresponds to a cached + # wheel, it means the requested revision was an + # immutable commit hash, otherwise it would not have + # been cached. In that case we don't have a source_dir + # with the VCS checkout. + assert requested_revision + commit_id = requested_revision + else: + # If the wheel was not in cache, it means we have + # had to checkout from VCS to build and we have a source_dir + # which we can inspect to find out the commit id. + assert source_dir + commit_id = vcs_backend.get_revision(source_dir) + return DirectUrl( + url=url, + info=VcsInfo( + vcs=vcs_backend.name, + commit_id=commit_id, + requested_revision=requested_revision, + ), + subdirectory=link.subdirectory_fragment, + ) + elif link.is_existing_dir(): + return DirectUrl( + url=link.url_without_fragment, + info=DirInfo(), + subdirectory=link.subdirectory_fragment, + ) + else: + hash = None + hash_name = link.hash_name + if hash_name: + hash = f"{hash_name}={link.hash}" + return DirectUrl( + url=link.url_without_fragment, + info=ArchiveInfo(hash=hash), + subdirectory=link.subdirectory_fragment, + ) diff --git a/videollama2/lib/python3.10/site-packages/pip/_internal/utils/egg_link.py b/videollama2/lib/python3.10/site-packages/pip/_internal/utils/egg_link.py new file mode 100644 index 0000000000000000000000000000000000000000..4a384a63682ce53cafcf889551b13b9177a14e44 --- /dev/null +++ b/videollama2/lib/python3.10/site-packages/pip/_internal/utils/egg_link.py @@ -0,0 +1,80 @@ +import os +import re +import sys +from typing import List, Optional + +from pip._internal.locations import site_packages, user_site +from pip._internal.utils.virtualenv import ( + running_under_virtualenv, + virtualenv_no_global, +) + +__all__ = [ + "egg_link_path_from_sys_path", + "egg_link_path_from_location", +] + + +def _egg_link_names(raw_name: str) -> List[str]: + """ + Convert a Name metadata value to a .egg-link name, by applying + the same substitution as pkg_resources's safe_name function. + Note: we cannot use canonicalize_name because it has a different logic. + + We also look for the raw name (without normalization) as setuptools 69 changed + the way it names .egg-link files (https://github.com/pypa/setuptools/issues/4167). + """ + return [ + re.sub("[^A-Za-z0-9.]+", "-", raw_name) + ".egg-link", + f"{raw_name}.egg-link", + ] + + +def egg_link_path_from_sys_path(raw_name: str) -> Optional[str]: + """ + Look for a .egg-link file for project name, by walking sys.path. + """ + egg_link_names = _egg_link_names(raw_name) + for path_item in sys.path: + for egg_link_name in egg_link_names: + egg_link = os.path.join(path_item, egg_link_name) + if os.path.isfile(egg_link): + return egg_link + return None + + +def egg_link_path_from_location(raw_name: str) -> Optional[str]: + """ + Return the path for the .egg-link file if it exists, otherwise, None. + + There's 3 scenarios: + 1) not in a virtualenv + try to find in site.USER_SITE, then site_packages + 2) in a no-global virtualenv + try to find in site_packages + 3) in a yes-global virtualenv + try to find in site_packages, then site.USER_SITE + (don't look in global location) + + For #1 and #3, there could be odd cases, where there's an egg-link in 2 + locations. + + This method will just return the first one found. + """ + sites: List[str] = [] + if running_under_virtualenv(): + sites.append(site_packages) + if not virtualenv_no_global() and user_site: + sites.append(user_site) + else: + if user_site: + sites.append(user_site) + sites.append(site_packages) + + egg_link_names = _egg_link_names(raw_name) + for site in sites: + for egg_link_name in egg_link_names: + egglink = os.path.join(site, egg_link_name) + if os.path.isfile(egglink): + return egglink + return None diff --git a/videollama2/lib/python3.10/site-packages/pip/_internal/utils/filetypes.py b/videollama2/lib/python3.10/site-packages/pip/_internal/utils/filetypes.py new file mode 100644 index 0000000000000000000000000000000000000000..5948570178f3e6e79d1ff574241d09d4d8ed78de --- /dev/null +++ b/videollama2/lib/python3.10/site-packages/pip/_internal/utils/filetypes.py @@ -0,0 +1,27 @@ +"""Filetype information. +""" + +from typing import Tuple + +from pip._internal.utils.misc import splitext + +WHEEL_EXTENSION = ".whl" +BZ2_EXTENSIONS: Tuple[str, ...] = (".tar.bz2", ".tbz") +XZ_EXTENSIONS: Tuple[str, ...] = ( + ".tar.xz", + ".txz", + ".tlz", + ".tar.lz", + ".tar.lzma", +) +ZIP_EXTENSIONS: Tuple[str, ...] = (".zip", WHEEL_EXTENSION) +TAR_EXTENSIONS: Tuple[str, ...] = (".tar.gz", ".tgz", ".tar") +ARCHIVE_EXTENSIONS = ZIP_EXTENSIONS + BZ2_EXTENSIONS + TAR_EXTENSIONS + XZ_EXTENSIONS + + +def is_archive_file(name: str) -> bool: + """Return True if `name` is a considered as an archive file.""" + ext = splitext(name)[1].lower() + if ext in ARCHIVE_EXTENSIONS: + return True + return False diff --git a/videollama2/lib/python3.10/site-packages/pip/_internal/utils/glibc.py b/videollama2/lib/python3.10/site-packages/pip/_internal/utils/glibc.py new file mode 100644 index 0000000000000000000000000000000000000000..998868ff2a482648024c848c9650d584403cbc8a --- /dev/null +++ b/videollama2/lib/python3.10/site-packages/pip/_internal/utils/glibc.py @@ -0,0 +1,101 @@ +import os +import sys +from typing import Optional, Tuple + + +def glibc_version_string() -> Optional[str]: + "Returns glibc version string, or None if not using glibc." + return glibc_version_string_confstr() or glibc_version_string_ctypes() + + +def glibc_version_string_confstr() -> Optional[str]: + "Primary implementation of glibc_version_string using os.confstr." + # os.confstr is quite a bit faster than ctypes.DLL. It's also less likely + # to be broken or missing. This strategy is used in the standard library + # platform module: + # https://github.com/python/cpython/blob/fcf1d003bf4f0100c9d0921ff3d70e1127ca1b71/Lib/platform.py#L175-L183 + if sys.platform == "win32": + return None + try: + gnu_libc_version = os.confstr("CS_GNU_LIBC_VERSION") + if gnu_libc_version is None: + return None + # os.confstr("CS_GNU_LIBC_VERSION") returns a string like "glibc 2.17": + _, version = gnu_libc_version.split() + except (AttributeError, OSError, ValueError): + # os.confstr() or CS_GNU_LIBC_VERSION not available (or a bad value)... + return None + return version + + +def glibc_version_string_ctypes() -> Optional[str]: + "Fallback implementation of glibc_version_string using ctypes." + + try: + import ctypes + except ImportError: + return None + + # ctypes.CDLL(None) internally calls dlopen(NULL), and as the dlopen + # manpage says, "If filename is NULL, then the returned handle is for the + # main program". This way we can let the linker do the work to figure out + # which libc our process is actually using. + # + # We must also handle the special case where the executable is not a + # dynamically linked executable. This can occur when using musl libc, + # for example. In this situation, dlopen() will error, leading to an + # OSError. Interestingly, at least in the case of musl, there is no + # errno set on the OSError. The single string argument used to construct + # OSError comes from libc itself and is therefore not portable to + # hard code here. In any case, failure to call dlopen() means we + # can't proceed, so we bail on our attempt. + try: + process_namespace = ctypes.CDLL(None) + except OSError: + return None + + try: + gnu_get_libc_version = process_namespace.gnu_get_libc_version + except AttributeError: + # Symbol doesn't exist -> therefore, we are not linked to + # glibc. + return None + + # Call gnu_get_libc_version, which returns a string like "2.5" + gnu_get_libc_version.restype = ctypes.c_char_p + version_str: str = gnu_get_libc_version() + # py2 / py3 compatibility: + if not isinstance(version_str, str): + version_str = version_str.decode("ascii") + + return version_str + + +# platform.libc_ver regularly returns completely nonsensical glibc +# versions. E.g. on my computer, platform says: +# +# ~$ python2.7 -c 'import platform; print(platform.libc_ver())' +# ('glibc', '2.7') +# ~$ python3.5 -c 'import platform; print(platform.libc_ver())' +# ('glibc', '2.9') +# +# But the truth is: +# +# ~$ ldd --version +# ldd (Debian GLIBC 2.22-11) 2.22 +# +# This is unfortunate, because it means that the linehaul data on libc +# versions that was generated by pip 8.1.2 and earlier is useless and +# misleading. Solution: instead of using platform, use our code that actually +# works. +def libc_ver() -> Tuple[str, str]: + """Try to determine the glibc version + + Returns a tuple of strings (lib, version) which default to empty strings + in case the lookup fails. + """ + glibc_version = glibc_version_string() + if glibc_version is None: + return ("", "") + else: + return ("glibc", glibc_version) diff --git a/videollama2/lib/python3.10/site-packages/pip/_internal/utils/logging.py b/videollama2/lib/python3.10/site-packages/pip/_internal/utils/logging.py new file mode 100644 index 0000000000000000000000000000000000000000..62035fc40eca1311704175d80a5c7082a166924f --- /dev/null +++ b/videollama2/lib/python3.10/site-packages/pip/_internal/utils/logging.py @@ -0,0 +1,354 @@ +import contextlib +import errno +import logging +import logging.handlers +import os +import sys +import threading +from dataclasses import dataclass +from io import TextIOWrapper +from logging import Filter +from typing import Any, ClassVar, Generator, List, Optional, TextIO, Type + +from pip._vendor.rich.console import ( + Console, + ConsoleOptions, + ConsoleRenderable, + RenderableType, + RenderResult, + RichCast, +) +from pip._vendor.rich.highlighter import NullHighlighter +from pip._vendor.rich.logging import RichHandler +from pip._vendor.rich.segment import Segment +from pip._vendor.rich.style import Style + +from pip._internal.utils._log import VERBOSE, getLogger +from pip._internal.utils.compat import WINDOWS +from pip._internal.utils.deprecation import DEPRECATION_MSG_PREFIX +from pip._internal.utils.misc import ensure_dir + +_log_state = threading.local() +subprocess_logger = getLogger("pip.subprocessor") + + +class BrokenStdoutLoggingError(Exception): + """ + Raised if BrokenPipeError occurs for the stdout stream while logging. + """ + + +def _is_broken_pipe_error(exc_class: Type[BaseException], exc: BaseException) -> bool: + if exc_class is BrokenPipeError: + return True + + # On Windows, a broken pipe can show up as EINVAL rather than EPIPE: + # https://bugs.python.org/issue19612 + # https://bugs.python.org/issue30418 + if not WINDOWS: + return False + + return isinstance(exc, OSError) and exc.errno in (errno.EINVAL, errno.EPIPE) + + +@contextlib.contextmanager +def indent_log(num: int = 2) -> Generator[None, None, None]: + """ + A context manager which will cause the log output to be indented for any + log messages emitted inside it. + """ + # For thread-safety + _log_state.indentation = get_indentation() + _log_state.indentation += num + try: + yield + finally: + _log_state.indentation -= num + + +def get_indentation() -> int: + return getattr(_log_state, "indentation", 0) + + +class IndentingFormatter(logging.Formatter): + default_time_format = "%Y-%m-%dT%H:%M:%S" + + def __init__( + self, + *args: Any, + add_timestamp: bool = False, + **kwargs: Any, + ) -> None: + """ + A logging.Formatter that obeys the indent_log() context manager. + + :param add_timestamp: A bool indicating output lines should be prefixed + with their record's timestamp. + """ + self.add_timestamp = add_timestamp + super().__init__(*args, **kwargs) + + def get_message_start(self, formatted: str, levelno: int) -> str: + """ + Return the start of the formatted log message (not counting the + prefix to add to each line). + """ + if levelno < logging.WARNING: + return "" + if formatted.startswith(DEPRECATION_MSG_PREFIX): + # Then the message already has a prefix. We don't want it to + # look like "WARNING: DEPRECATION: ...." + return "" + if levelno < logging.ERROR: + return "WARNING: " + + return "ERROR: " + + def format(self, record: logging.LogRecord) -> str: + """ + Calls the standard formatter, but will indent all of the log message + lines by our current indentation level. + """ + formatted = super().format(record) + message_start = self.get_message_start(formatted, record.levelno) + formatted = message_start + formatted + + prefix = "" + if self.add_timestamp: + prefix = f"{self.formatTime(record)} " + prefix += " " * get_indentation() + formatted = "".join([prefix + line for line in formatted.splitlines(True)]) + return formatted + + +@dataclass +class IndentedRenderable: + renderable: RenderableType + indent: int + + def __rich_console__( + self, console: Console, options: ConsoleOptions + ) -> RenderResult: + segments = console.render(self.renderable, options) + lines = Segment.split_lines(segments) + for line in lines: + yield Segment(" " * self.indent) + yield from line + yield Segment("\n") + + +class PipConsole(Console): + def on_broken_pipe(self) -> None: + # Reraise the original exception, rich 13.8.0+ exits by default + # instead, preventing our handler from firing. + raise BrokenPipeError() from None + + +class RichPipStreamHandler(RichHandler): + KEYWORDS: ClassVar[Optional[List[str]]] = [] + + def __init__(self, stream: Optional[TextIO], no_color: bool) -> None: + super().__init__( + console=PipConsole(file=stream, no_color=no_color, soft_wrap=True), + show_time=False, + show_level=False, + show_path=False, + highlighter=NullHighlighter(), + ) + + # Our custom override on Rich's logger, to make things work as we need them to. + def emit(self, record: logging.LogRecord) -> None: + style: Optional[Style] = None + + # If we are given a diagnostic error to present, present it with indentation. + if getattr(record, "rich", False): + assert isinstance(record.args, tuple) + (rich_renderable,) = record.args + assert isinstance( + rich_renderable, (ConsoleRenderable, RichCast, str) + ), f"{rich_renderable} is not rich-console-renderable" + + renderable: RenderableType = IndentedRenderable( + rich_renderable, indent=get_indentation() + ) + else: + message = self.format(record) + renderable = self.render_message(record, message) + if record.levelno is not None: + if record.levelno >= logging.ERROR: + style = Style(color="red") + elif record.levelno >= logging.WARNING: + style = Style(color="yellow") + + try: + self.console.print(renderable, overflow="ignore", crop=False, style=style) + except Exception: + self.handleError(record) + + def handleError(self, record: logging.LogRecord) -> None: + """Called when logging is unable to log some output.""" + + exc_class, exc = sys.exc_info()[:2] + # If a broken pipe occurred while calling write() or flush() on the + # stdout stream in logging's Handler.emit(), then raise our special + # exception so we can handle it in main() instead of logging the + # broken pipe error and continuing. + if ( + exc_class + and exc + and self.console.file is sys.stdout + and _is_broken_pipe_error(exc_class, exc) + ): + raise BrokenStdoutLoggingError() + + return super().handleError(record) + + +class BetterRotatingFileHandler(logging.handlers.RotatingFileHandler): + def _open(self) -> TextIOWrapper: + ensure_dir(os.path.dirname(self.baseFilename)) + return super()._open() + + +class MaxLevelFilter(Filter): + def __init__(self, level: int) -> None: + self.level = level + + def filter(self, record: logging.LogRecord) -> bool: + return record.levelno < self.level + + +class ExcludeLoggerFilter(Filter): + """ + A logging Filter that excludes records from a logger (or its children). + """ + + def filter(self, record: logging.LogRecord) -> bool: + # The base Filter class allows only records from a logger (or its + # children). + return not super().filter(record) + + +def setup_logging(verbosity: int, no_color: bool, user_log_file: Optional[str]) -> int: + """Configures and sets up all of the logging + + Returns the requested logging level, as its integer value. + """ + + # Determine the level to be logging at. + if verbosity >= 2: + level_number = logging.DEBUG + elif verbosity == 1: + level_number = VERBOSE + elif verbosity == -1: + level_number = logging.WARNING + elif verbosity == -2: + level_number = logging.ERROR + elif verbosity <= -3: + level_number = logging.CRITICAL + else: + level_number = logging.INFO + + level = logging.getLevelName(level_number) + + # The "root" logger should match the "console" level *unless* we also need + # to log to a user log file. + include_user_log = user_log_file is not None + if include_user_log: + additional_log_file = user_log_file + root_level = "DEBUG" + else: + additional_log_file = "/dev/null" + root_level = level + + # Disable any logging besides WARNING unless we have DEBUG level logging + # enabled for vendored libraries. + vendored_log_level = "WARNING" if level in ["INFO", "ERROR"] else "DEBUG" + + # Shorthands for clarity + log_streams = { + "stdout": "ext://sys.stdout", + "stderr": "ext://sys.stderr", + } + handler_classes = { + "stream": "pip._internal.utils.logging.RichPipStreamHandler", + "file": "pip._internal.utils.logging.BetterRotatingFileHandler", + } + handlers = ["console", "console_errors", "console_subprocess"] + ( + ["user_log"] if include_user_log else [] + ) + + logging.config.dictConfig( + { + "version": 1, + "disable_existing_loggers": False, + "filters": { + "exclude_warnings": { + "()": "pip._internal.utils.logging.MaxLevelFilter", + "level": logging.WARNING, + }, + "restrict_to_subprocess": { + "()": "logging.Filter", + "name": subprocess_logger.name, + }, + "exclude_subprocess": { + "()": "pip._internal.utils.logging.ExcludeLoggerFilter", + "name": subprocess_logger.name, + }, + }, + "formatters": { + "indent": { + "()": IndentingFormatter, + "format": "%(message)s", + }, + "indent_with_timestamp": { + "()": IndentingFormatter, + "format": "%(message)s", + "add_timestamp": True, + }, + }, + "handlers": { + "console": { + "level": level, + "class": handler_classes["stream"], + "no_color": no_color, + "stream": log_streams["stdout"], + "filters": ["exclude_subprocess", "exclude_warnings"], + "formatter": "indent", + }, + "console_errors": { + "level": "WARNING", + "class": handler_classes["stream"], + "no_color": no_color, + "stream": log_streams["stderr"], + "filters": ["exclude_subprocess"], + "formatter": "indent", + }, + # A handler responsible for logging to the console messages + # from the "subprocessor" logger. + "console_subprocess": { + "level": level, + "class": handler_classes["stream"], + "stream": log_streams["stderr"], + "no_color": no_color, + "filters": ["restrict_to_subprocess"], + "formatter": "indent", + }, + "user_log": { + "level": "DEBUG", + "class": handler_classes["file"], + "filename": additional_log_file, + "encoding": "utf-8", + "delay": True, + "formatter": "indent_with_timestamp", + }, + }, + "root": { + "level": root_level, + "handlers": handlers, + }, + "loggers": {"pip._vendor": {"level": vendored_log_level}}, + } + ) + + return level_number diff --git a/videollama2/lib/python3.10/site-packages/pip/_internal/utils/misc.py b/videollama2/lib/python3.10/site-packages/pip/_internal/utils/misc.py new file mode 100644 index 0000000000000000000000000000000000000000..44f6a05fbdd7f7b5779141f53b25b523af7e15eb --- /dev/null +++ b/videollama2/lib/python3.10/site-packages/pip/_internal/utils/misc.py @@ -0,0 +1,773 @@ +import errno +import getpass +import hashlib +import logging +import os +import posixpath +import shutil +import stat +import sys +import sysconfig +import urllib.parse +from dataclasses import dataclass +from functools import partial +from io import StringIO +from itertools import filterfalse, tee, zip_longest +from pathlib import Path +from types import FunctionType, TracebackType +from typing import ( + Any, + BinaryIO, + Callable, + Generator, + Iterable, + Iterator, + List, + Mapping, + Optional, + Sequence, + TextIO, + Tuple, + Type, + TypeVar, + Union, + cast, +) + +from pip._vendor.packaging.requirements import Requirement +from pip._vendor.pyproject_hooks import BuildBackendHookCaller + +from pip import __version__ +from pip._internal.exceptions import CommandError, ExternallyManagedEnvironment +from pip._internal.locations import get_major_minor_version +from pip._internal.utils.compat import WINDOWS +from pip._internal.utils.retry import retry +from pip._internal.utils.virtualenv import running_under_virtualenv + +__all__ = [ + "rmtree", + "display_path", + "backup_dir", + "ask", + "splitext", + "format_size", + "is_installable_dir", + "normalize_path", + "renames", + "get_prog", + "ensure_dir", + "remove_auth_from_url", + "check_externally_managed", + "ConfiguredBuildBackendHookCaller", +] + +logger = logging.getLogger(__name__) + +T = TypeVar("T") +ExcInfo = Tuple[Type[BaseException], BaseException, TracebackType] +VersionInfo = Tuple[int, int, int] +NetlocTuple = Tuple[str, Tuple[Optional[str], Optional[str]]] +OnExc = Callable[[FunctionType, Path, BaseException], Any] +OnErr = Callable[[FunctionType, Path, ExcInfo], Any] + +FILE_CHUNK_SIZE = 1024 * 1024 + + +def get_pip_version() -> str: + pip_pkg_dir = os.path.join(os.path.dirname(__file__), "..", "..") + pip_pkg_dir = os.path.abspath(pip_pkg_dir) + + return f"pip {__version__} from {pip_pkg_dir} (python {get_major_minor_version()})" + + +def normalize_version_info(py_version_info: Tuple[int, ...]) -> Tuple[int, int, int]: + """ + Convert a tuple of ints representing a Python version to one of length + three. + + :param py_version_info: a tuple of ints representing a Python version, + or None to specify no version. The tuple can have any length. + + :return: a tuple of length three if `py_version_info` is non-None. + Otherwise, return `py_version_info` unchanged (i.e. None). + """ + if len(py_version_info) < 3: + py_version_info += (3 - len(py_version_info)) * (0,) + elif len(py_version_info) > 3: + py_version_info = py_version_info[:3] + + return cast("VersionInfo", py_version_info) + + +def ensure_dir(path: str) -> None: + """os.path.makedirs without EEXIST.""" + try: + os.makedirs(path) + except OSError as e: + # Windows can raise spurious ENOTEMPTY errors. See #6426. + if e.errno != errno.EEXIST and e.errno != errno.ENOTEMPTY: + raise + + +def get_prog() -> str: + try: + prog = os.path.basename(sys.argv[0]) + if prog in ("__main__.py", "-c"): + return f"{sys.executable} -m pip" + else: + return prog + except (AttributeError, TypeError, IndexError): + pass + return "pip" + + +# Retry every half second for up to 3 seconds +@retry(stop_after_delay=3, wait=0.5) +def rmtree( + dir: str, ignore_errors: bool = False, onexc: Optional[OnExc] = None +) -> None: + if ignore_errors: + onexc = _onerror_ignore + if onexc is None: + onexc = _onerror_reraise + handler: OnErr = partial(rmtree_errorhandler, onexc=onexc) + if sys.version_info >= (3, 12): + # See https://docs.python.org/3.12/whatsnew/3.12.html#shutil. + shutil.rmtree(dir, onexc=handler) # type: ignore + else: + shutil.rmtree(dir, onerror=handler) # type: ignore + + +def _onerror_ignore(*_args: Any) -> None: + pass + + +def _onerror_reraise(*_args: Any) -> None: + raise # noqa: PLE0704 - Bare exception used to reraise existing exception + + +def rmtree_errorhandler( + func: FunctionType, + path: Path, + exc_info: Union[ExcInfo, BaseException], + *, + onexc: OnExc = _onerror_reraise, +) -> None: + """ + `rmtree` error handler to 'force' a file remove (i.e. like `rm -f`). + + * If a file is readonly then it's write flag is set and operation is + retried. + + * `onerror` is the original callback from `rmtree(... onerror=onerror)` + that is chained at the end if the "rm -f" still fails. + """ + try: + st_mode = os.stat(path).st_mode + except OSError: + # it's equivalent to os.path.exists + return + + if not st_mode & stat.S_IWRITE: + # convert to read/write + try: + os.chmod(path, st_mode | stat.S_IWRITE) + except OSError: + pass + else: + # use the original function to repeat the operation + try: + func(path) + return + except OSError: + pass + + if not isinstance(exc_info, BaseException): + _, exc_info, _ = exc_info + onexc(func, path, exc_info) + + +def display_path(path: str) -> str: + """Gives the display value for a given path, making it relative to cwd + if possible.""" + path = os.path.normcase(os.path.abspath(path)) + if path.startswith(os.getcwd() + os.path.sep): + path = "." + path[len(os.getcwd()) :] + return path + + +def backup_dir(dir: str, ext: str = ".bak") -> str: + """Figure out the name of a directory to back up the given dir to + (adding .bak, .bak2, etc)""" + n = 1 + extension = ext + while os.path.exists(dir + extension): + n += 1 + extension = ext + str(n) + return dir + extension + + +def ask_path_exists(message: str, options: Iterable[str]) -> str: + for action in os.environ.get("PIP_EXISTS_ACTION", "").split(): + if action in options: + return action + return ask(message, options) + + +def _check_no_input(message: str) -> None: + """Raise an error if no input is allowed.""" + if os.environ.get("PIP_NO_INPUT"): + raise Exception( + f"No input was expected ($PIP_NO_INPUT set); question: {message}" + ) + + +def ask(message: str, options: Iterable[str]) -> str: + """Ask the message interactively, with the given possible responses""" + while 1: + _check_no_input(message) + response = input(message) + response = response.strip().lower() + if response not in options: + print( + "Your response ({!r}) was not one of the expected responses: " + "{}".format(response, ", ".join(options)) + ) + else: + return response + + +def ask_input(message: str) -> str: + """Ask for input interactively.""" + _check_no_input(message) + return input(message) + + +def ask_password(message: str) -> str: + """Ask for a password interactively.""" + _check_no_input(message) + return getpass.getpass(message) + + +def strtobool(val: str) -> int: + """Convert a string representation of truth to true (1) or false (0). + + True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values + are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if + 'val' is anything else. + """ + val = val.lower() + if val in ("y", "yes", "t", "true", "on", "1"): + return 1 + elif val in ("n", "no", "f", "false", "off", "0"): + return 0 + else: + raise ValueError(f"invalid truth value {val!r}") + + +def format_size(bytes: float) -> str: + if bytes > 1000 * 1000: + return f"{bytes / 1000.0 / 1000:.1f} MB" + elif bytes > 10 * 1000: + return f"{int(bytes / 1000)} kB" + elif bytes > 1000: + return f"{bytes / 1000.0:.1f} kB" + else: + return f"{int(bytes)} bytes" + + +def tabulate(rows: Iterable[Iterable[Any]]) -> Tuple[List[str], List[int]]: + """Return a list of formatted rows and a list of column sizes. + + For example:: + + >>> tabulate([['foobar', 2000], [0xdeadbeef]]) + (['foobar 2000', '3735928559'], [10, 4]) + """ + rows = [tuple(map(str, row)) for row in rows] + sizes = [max(map(len, col)) for col in zip_longest(*rows, fillvalue="")] + table = [" ".join(map(str.ljust, row, sizes)).rstrip() for row in rows] + return table, sizes + + +def is_installable_dir(path: str) -> bool: + """Is path is a directory containing pyproject.toml or setup.py? + + If pyproject.toml exists, this is a PEP 517 project. Otherwise we look for + a legacy setuptools layout by identifying setup.py. We don't check for the + setup.cfg because using it without setup.py is only available for PEP 517 + projects, which are already covered by the pyproject.toml check. + """ + if not os.path.isdir(path): + return False + if os.path.isfile(os.path.join(path, "pyproject.toml")): + return True + if os.path.isfile(os.path.join(path, "setup.py")): + return True + return False + + +def read_chunks( + file: BinaryIO, size: int = FILE_CHUNK_SIZE +) -> Generator[bytes, None, None]: + """Yield pieces of data from a file-like object until EOF.""" + while True: + chunk = file.read(size) + if not chunk: + break + yield chunk + + +def normalize_path(path: str, resolve_symlinks: bool = True) -> str: + """ + Convert a path to its canonical, case-normalized, absolute version. + + """ + path = os.path.expanduser(path) + if resolve_symlinks: + path = os.path.realpath(path) + else: + path = os.path.abspath(path) + return os.path.normcase(path) + + +def splitext(path: str) -> Tuple[str, str]: + """Like os.path.splitext, but take off .tar too""" + base, ext = posixpath.splitext(path) + if base.lower().endswith(".tar"): + ext = base[-4:] + ext + base = base[:-4] + return base, ext + + +def renames(old: str, new: str) -> None: + """Like os.renames(), but handles renaming across devices.""" + # Implementation borrowed from os.renames(). + head, tail = os.path.split(new) + if head and tail and not os.path.exists(head): + os.makedirs(head) + + shutil.move(old, new) + + head, tail = os.path.split(old) + if head and tail: + try: + os.removedirs(head) + except OSError: + pass + + +def is_local(path: str) -> bool: + """ + Return True if path is within sys.prefix, if we're running in a virtualenv. + + If we're not in a virtualenv, all paths are considered "local." + + Caution: this function assumes the head of path has been normalized + with normalize_path. + """ + if not running_under_virtualenv(): + return True + return path.startswith(normalize_path(sys.prefix)) + + +def write_output(msg: Any, *args: Any) -> None: + logger.info(msg, *args) + + +class StreamWrapper(StringIO): + orig_stream: TextIO + + @classmethod + def from_stream(cls, orig_stream: TextIO) -> "StreamWrapper": + ret = cls() + ret.orig_stream = orig_stream + return ret + + # compileall.compile_dir() needs stdout.encoding to print to stdout + # type ignore is because TextIOBase.encoding is writeable + @property + def encoding(self) -> str: # type: ignore + return self.orig_stream.encoding + + +# Simulates an enum +def enum(*sequential: Any, **named: Any) -> Type[Any]: + enums = dict(zip(sequential, range(len(sequential))), **named) + reverse = {value: key for key, value in enums.items()} + enums["reverse_mapping"] = reverse + return type("Enum", (), enums) + + +def build_netloc(host: str, port: Optional[int]) -> str: + """ + Build a netloc from a host-port pair + """ + if port is None: + return host + if ":" in host: + # Only wrap host with square brackets when it is IPv6 + host = f"[{host}]" + return f"{host}:{port}" + + +def build_url_from_netloc(netloc: str, scheme: str = "https") -> str: + """ + Build a full URL from a netloc. + """ + if netloc.count(":") >= 2 and "@" not in netloc and "[" not in netloc: + # It must be a bare IPv6 address, so wrap it with brackets. + netloc = f"[{netloc}]" + return f"{scheme}://{netloc}" + + +def parse_netloc(netloc: str) -> Tuple[Optional[str], Optional[int]]: + """ + Return the host-port pair from a netloc. + """ + url = build_url_from_netloc(netloc) + parsed = urllib.parse.urlparse(url) + return parsed.hostname, parsed.port + + +def split_auth_from_netloc(netloc: str) -> NetlocTuple: + """ + Parse out and remove the auth information from a netloc. + + Returns: (netloc, (username, password)). + """ + if "@" not in netloc: + return netloc, (None, None) + + # Split from the right because that's how urllib.parse.urlsplit() + # behaves if more than one @ is present (which can be checked using + # the password attribute of urlsplit()'s return value). + auth, netloc = netloc.rsplit("@", 1) + pw: Optional[str] = None + if ":" in auth: + # Split from the left because that's how urllib.parse.urlsplit() + # behaves if more than one : is present (which again can be checked + # using the password attribute of the return value) + user, pw = auth.split(":", 1) + else: + user, pw = auth, None + + user = urllib.parse.unquote(user) + if pw is not None: + pw = urllib.parse.unquote(pw) + + return netloc, (user, pw) + + +def redact_netloc(netloc: str) -> str: + """ + Replace the sensitive data in a netloc with "****", if it exists. + + For example: + - "user:pass@example.com" returns "user:****@example.com" + - "accesstoken@example.com" returns "****@example.com" + """ + netloc, (user, password) = split_auth_from_netloc(netloc) + if user is None: + return netloc + if password is None: + user = "****" + password = "" + else: + user = urllib.parse.quote(user) + password = ":****" + return f"{user}{password}@{netloc}" + + +def _transform_url( + url: str, transform_netloc: Callable[[str], Tuple[Any, ...]] +) -> Tuple[str, NetlocTuple]: + """Transform and replace netloc in a url. + + transform_netloc is a function taking the netloc and returning a + tuple. The first element of this tuple is the new netloc. The + entire tuple is returned. + + Returns a tuple containing the transformed url as item 0 and the + original tuple returned by transform_netloc as item 1. + """ + purl = urllib.parse.urlsplit(url) + netloc_tuple = transform_netloc(purl.netloc) + # stripped url + url_pieces = (purl.scheme, netloc_tuple[0], purl.path, purl.query, purl.fragment) + surl = urllib.parse.urlunsplit(url_pieces) + return surl, cast("NetlocTuple", netloc_tuple) + + +def _get_netloc(netloc: str) -> NetlocTuple: + return split_auth_from_netloc(netloc) + + +def _redact_netloc(netloc: str) -> Tuple[str]: + return (redact_netloc(netloc),) + + +def split_auth_netloc_from_url( + url: str, +) -> Tuple[str, str, Tuple[Optional[str], Optional[str]]]: + """ + Parse a url into separate netloc, auth, and url with no auth. + + Returns: (url_without_auth, netloc, (username, password)) + """ + url_without_auth, (netloc, auth) = _transform_url(url, _get_netloc) + return url_without_auth, netloc, auth + + +def remove_auth_from_url(url: str) -> str: + """Return a copy of url with 'username:password@' removed.""" + # username/pass params are passed to subversion through flags + # and are not recognized in the url. + return _transform_url(url, _get_netloc)[0] + + +def redact_auth_from_url(url: str) -> str: + """Replace the password in a given url with ****.""" + return _transform_url(url, _redact_netloc)[0] + + +def redact_auth_from_requirement(req: Requirement) -> str: + """Replace the password in a given requirement url with ****.""" + if not req.url: + return str(req) + return str(req).replace(req.url, redact_auth_from_url(req.url)) + + +@dataclass(frozen=True) +class HiddenText: + secret: str + redacted: str + + def __repr__(self) -> str: + return f"" + + def __str__(self) -> str: + return self.redacted + + # This is useful for testing. + def __eq__(self, other: Any) -> bool: + if type(self) is not type(other): + return False + + # The string being used for redaction doesn't also have to match, + # just the raw, original string. + return self.secret == other.secret + + +def hide_value(value: str) -> HiddenText: + return HiddenText(value, redacted="****") + + +def hide_url(url: str) -> HiddenText: + redacted = redact_auth_from_url(url) + return HiddenText(url, redacted=redacted) + + +def protect_pip_from_modification_on_windows(modifying_pip: bool) -> None: + """Protection of pip.exe from modification on Windows + + On Windows, any operation modifying pip should be run as: + python -m pip ... + """ + pip_names = [ + "pip", + f"pip{sys.version_info.major}", + f"pip{sys.version_info.major}.{sys.version_info.minor}", + ] + + # See https://github.com/pypa/pip/issues/1299 for more discussion + should_show_use_python_msg = ( + modifying_pip and WINDOWS and os.path.basename(sys.argv[0]) in pip_names + ) + + if should_show_use_python_msg: + new_command = [sys.executable, "-m", "pip"] + sys.argv[1:] + raise CommandError( + "To modify pip, please run the following command:\n{}".format( + " ".join(new_command) + ) + ) + + +def check_externally_managed() -> None: + """Check whether the current environment is externally managed. + + If the ``EXTERNALLY-MANAGED`` config file is found, the current environment + is considered externally managed, and an ExternallyManagedEnvironment is + raised. + """ + if running_under_virtualenv(): + return + marker = os.path.join(sysconfig.get_path("stdlib"), "EXTERNALLY-MANAGED") + if not os.path.isfile(marker): + return + raise ExternallyManagedEnvironment.from_config(marker) + + +def is_console_interactive() -> bool: + """Is this console interactive?""" + return sys.stdin is not None and sys.stdin.isatty() + + +def hash_file(path: str, blocksize: int = 1 << 20) -> Tuple[Any, int]: + """Return (hash, length) for path using hashlib.sha256()""" + + h = hashlib.sha256() + length = 0 + with open(path, "rb") as f: + for block in read_chunks(f, size=blocksize): + length += len(block) + h.update(block) + return h, length + + +def pairwise(iterable: Iterable[Any]) -> Iterator[Tuple[Any, Any]]: + """ + Return paired elements. + + For example: + s -> (s0, s1), (s2, s3), (s4, s5), ... + """ + iterable = iter(iterable) + return zip_longest(iterable, iterable) + + +def partition( + pred: Callable[[T], bool], iterable: Iterable[T] +) -> Tuple[Iterable[T], Iterable[T]]: + """ + Use a predicate to partition entries into false entries and true entries, + like + + partition(is_odd, range(10)) --> 0 2 4 6 8 and 1 3 5 7 9 + """ + t1, t2 = tee(iterable) + return filterfalse(pred, t1), filter(pred, t2) + + +class ConfiguredBuildBackendHookCaller(BuildBackendHookCaller): + def __init__( + self, + config_holder: Any, + source_dir: str, + build_backend: str, + backend_path: Optional[str] = None, + runner: Optional[Callable[..., None]] = None, + python_executable: Optional[str] = None, + ): + super().__init__( + source_dir, build_backend, backend_path, runner, python_executable + ) + self.config_holder = config_holder + + def build_wheel( + self, + wheel_directory: str, + config_settings: Optional[Mapping[str, Any]] = None, + metadata_directory: Optional[str] = None, + ) -> str: + cs = self.config_holder.config_settings + return super().build_wheel( + wheel_directory, config_settings=cs, metadata_directory=metadata_directory + ) + + def build_sdist( + self, + sdist_directory: str, + config_settings: Optional[Mapping[str, Any]] = None, + ) -> str: + cs = self.config_holder.config_settings + return super().build_sdist(sdist_directory, config_settings=cs) + + def build_editable( + self, + wheel_directory: str, + config_settings: Optional[Mapping[str, Any]] = None, + metadata_directory: Optional[str] = None, + ) -> str: + cs = self.config_holder.config_settings + return super().build_editable( + wheel_directory, config_settings=cs, metadata_directory=metadata_directory + ) + + def get_requires_for_build_wheel( + self, config_settings: Optional[Mapping[str, Any]] = None + ) -> Sequence[str]: + cs = self.config_holder.config_settings + return super().get_requires_for_build_wheel(config_settings=cs) + + def get_requires_for_build_sdist( + self, config_settings: Optional[Mapping[str, Any]] = None + ) -> Sequence[str]: + cs = self.config_holder.config_settings + return super().get_requires_for_build_sdist(config_settings=cs) + + def get_requires_for_build_editable( + self, config_settings: Optional[Mapping[str, Any]] = None + ) -> Sequence[str]: + cs = self.config_holder.config_settings + return super().get_requires_for_build_editable(config_settings=cs) + + def prepare_metadata_for_build_wheel( + self, + metadata_directory: str, + config_settings: Optional[Mapping[str, Any]] = None, + _allow_fallback: bool = True, + ) -> str: + cs = self.config_holder.config_settings + return super().prepare_metadata_for_build_wheel( + metadata_directory=metadata_directory, + config_settings=cs, + _allow_fallback=_allow_fallback, + ) + + def prepare_metadata_for_build_editable( + self, + metadata_directory: str, + config_settings: Optional[Mapping[str, Any]] = None, + _allow_fallback: bool = True, + ) -> Optional[str]: + cs = self.config_holder.config_settings + return super().prepare_metadata_for_build_editable( + metadata_directory=metadata_directory, + config_settings=cs, + _allow_fallback=_allow_fallback, + ) + + +def warn_if_run_as_root() -> None: + """Output a warning for sudo users on Unix. + + In a virtual environment, sudo pip still writes to virtualenv. + On Windows, users may run pip as Administrator without issues. + This warning only applies to Unix root users outside of virtualenv. + """ + if running_under_virtualenv(): + return + if not hasattr(os, "getuid"): + return + # On Windows, there are no "system managed" Python packages. Installing as + # Administrator via pip is the correct way of updating system environments. + # + # We choose sys.platform over utils.compat.WINDOWS here to enable Mypy platform + # checks: https://mypy.readthedocs.io/en/stable/common_issues.html + if sys.platform == "win32" or sys.platform == "cygwin": + return + + if os.getuid() != 0: + return + + logger.warning( + "Running pip as the 'root' user can result in broken permissions and " + "conflicting behaviour with the system package manager, possibly " + "rendering your system unusable. " + "It is recommended to use a virtual environment instead: " + "https://pip.pypa.io/warnings/venv. " + "Use the --root-user-action option if you know what you are doing and " + "want to suppress this warning." + ) diff --git a/videollama2/lib/python3.10/site-packages/pip/_internal/utils/retry.py b/videollama2/lib/python3.10/site-packages/pip/_internal/utils/retry.py new file mode 100644 index 0000000000000000000000000000000000000000..abfe07286ea747f656ea73f5a6919f1d66215847 --- /dev/null +++ b/videollama2/lib/python3.10/site-packages/pip/_internal/utils/retry.py @@ -0,0 +1,42 @@ +import functools +from time import perf_counter, sleep +from typing import Callable, TypeVar + +from pip._vendor.typing_extensions import ParamSpec + +T = TypeVar("T") +P = ParamSpec("P") + + +def retry( + wait: float, stop_after_delay: float +) -> Callable[[Callable[P, T]], Callable[P, T]]: + """Decorator to automatically retry a function on error. + + If the function raises, the function is recalled with the same arguments + until it returns or the time limit is reached. When the time limit is + surpassed, the last exception raised is reraised. + + :param wait: The time to wait after an error before retrying, in seconds. + :param stop_after_delay: The time limit after which retries will cease, + in seconds. + """ + + def wrapper(func: Callable[P, T]) -> Callable[P, T]: + + @functools.wraps(func) + def retry_wrapped(*args: P.args, **kwargs: P.kwargs) -> T: + # The performance counter is monotonic on all platforms we care + # about and has much better resolution than time.monotonic(). + start_time = perf_counter() + while True: + try: + return func(*args, **kwargs) + except Exception: + if perf_counter() - start_time > stop_after_delay: + raise + sleep(wait) + + return retry_wrapped + + return wrapper diff --git a/videollama2/lib/python3.10/site-packages/pip/_internal/utils/setuptools_build.py b/videollama2/lib/python3.10/site-packages/pip/_internal/utils/setuptools_build.py new file mode 100644 index 0000000000000000000000000000000000000000..96d1b2460670e20ac92a5ade7a74b7ab1cba71d8 --- /dev/null +++ b/videollama2/lib/python3.10/site-packages/pip/_internal/utils/setuptools_build.py @@ -0,0 +1,146 @@ +import sys +import textwrap +from typing import List, Optional, Sequence + +# Shim to wrap setup.py invocation with setuptools +# Note that __file__ is handled via two {!r} *and* %r, to ensure that paths on +# Windows are correctly handled (it should be "C:\\Users" not "C:\Users"). +_SETUPTOOLS_SHIM = textwrap.dedent( + """ + exec(compile(''' + # This is -- a caller that pip uses to run setup.py + # + # - It imports setuptools before invoking setup.py, to enable projects that directly + # import from `distutils.core` to work with newer packaging standards. + # - It provides a clear error message when setuptools is not installed. + # - It sets `sys.argv[0]` to the underlying `setup.py`, when invoking `setup.py` so + # setuptools doesn't think the script is `-c`. This avoids the following warning: + # manifest_maker: standard file '-c' not found". + # - It generates a shim setup.py, for handling setup.cfg-only projects. + import os, sys, tokenize + + try: + import setuptools + except ImportError as error: + print( + "ERROR: Can not execute `setup.py` since setuptools is not available in " + "the build environment.", + file=sys.stderr, + ) + sys.exit(1) + + __file__ = %r + sys.argv[0] = __file__ + + if os.path.exists(__file__): + filename = __file__ + with tokenize.open(__file__) as f: + setup_py_code = f.read() + else: + filename = "" + setup_py_code = "from setuptools import setup; setup()" + + exec(compile(setup_py_code, filename, "exec")) + ''' % ({!r},), "", "exec")) + """ +).rstrip() + + +def make_setuptools_shim_args( + setup_py_path: str, + global_options: Optional[Sequence[str]] = None, + no_user_config: bool = False, + unbuffered_output: bool = False, +) -> List[str]: + """ + Get setuptools command arguments with shim wrapped setup file invocation. + + :param setup_py_path: The path to setup.py to be wrapped. + :param global_options: Additional global options. + :param no_user_config: If True, disables personal user configuration. + :param unbuffered_output: If True, adds the unbuffered switch to the + argument list. + """ + args = [sys.executable] + if unbuffered_output: + args += ["-u"] + args += ["-c", _SETUPTOOLS_SHIM.format(setup_py_path)] + if global_options: + args += global_options + if no_user_config: + args += ["--no-user-cfg"] + return args + + +def make_setuptools_bdist_wheel_args( + setup_py_path: str, + global_options: Sequence[str], + build_options: Sequence[str], + destination_dir: str, +) -> List[str]: + # NOTE: Eventually, we'd want to also -S to the flags here, when we're + # isolating. Currently, it breaks Python in virtualenvs, because it + # relies on site.py to find parts of the standard library outside the + # virtualenv. + args = make_setuptools_shim_args( + setup_py_path, global_options=global_options, unbuffered_output=True + ) + args += ["bdist_wheel", "-d", destination_dir] + args += build_options + return args + + +def make_setuptools_clean_args( + setup_py_path: str, + global_options: Sequence[str], +) -> List[str]: + args = make_setuptools_shim_args( + setup_py_path, global_options=global_options, unbuffered_output=True + ) + args += ["clean", "--all"] + return args + + +def make_setuptools_develop_args( + setup_py_path: str, + *, + global_options: Sequence[str], + no_user_config: bool, + prefix: Optional[str], + home: Optional[str], + use_user_site: bool, +) -> List[str]: + assert not (use_user_site and prefix) + + args = make_setuptools_shim_args( + setup_py_path, + global_options=global_options, + no_user_config=no_user_config, + ) + + args += ["develop", "--no-deps"] + + if prefix: + args += ["--prefix", prefix] + if home is not None: + args += ["--install-dir", home] + + if use_user_site: + args += ["--user", "--prefix="] + + return args + + +def make_setuptools_egg_info_args( + setup_py_path: str, + egg_info_dir: Optional[str], + no_user_config: bool, +) -> List[str]: + args = make_setuptools_shim_args(setup_py_path, no_user_config=no_user_config) + + args += ["egg_info"] + + if egg_info_dir: + args += ["--egg-base", egg_info_dir] + + return args diff --git a/videollama2/lib/python3.10/site-packages/pip/_internal/utils/subprocess.py b/videollama2/lib/python3.10/site-packages/pip/_internal/utils/subprocess.py new file mode 100644 index 0000000000000000000000000000000000000000..cb2e23f007aca75c7e96e37df42ac0df6f2591e1 --- /dev/null +++ b/videollama2/lib/python3.10/site-packages/pip/_internal/utils/subprocess.py @@ -0,0 +1,245 @@ +import logging +import os +import shlex +import subprocess +from typing import Any, Callable, Iterable, List, Literal, Mapping, Optional, Union + +from pip._vendor.rich.markup import escape + +from pip._internal.cli.spinners import SpinnerInterface, open_spinner +from pip._internal.exceptions import InstallationSubprocessError +from pip._internal.utils.logging import VERBOSE, subprocess_logger +from pip._internal.utils.misc import HiddenText + +CommandArgs = List[Union[str, HiddenText]] + + +def make_command(*args: Union[str, HiddenText, CommandArgs]) -> CommandArgs: + """ + Create a CommandArgs object. + """ + command_args: CommandArgs = [] + for arg in args: + # Check for list instead of CommandArgs since CommandArgs is + # only known during type-checking. + if isinstance(arg, list): + command_args.extend(arg) + else: + # Otherwise, arg is str or HiddenText. + command_args.append(arg) + + return command_args + + +def format_command_args(args: Union[List[str], CommandArgs]) -> str: + """ + Format command arguments for display. + """ + # For HiddenText arguments, display the redacted form by calling str(). + # Also, we don't apply str() to arguments that aren't HiddenText since + # this can trigger a UnicodeDecodeError in Python 2 if the argument + # has type unicode and includes a non-ascii character. (The type + # checker doesn't ensure the annotations are correct in all cases.) + return " ".join( + shlex.quote(str(arg)) if isinstance(arg, HiddenText) else shlex.quote(arg) + for arg in args + ) + + +def reveal_command_args(args: Union[List[str], CommandArgs]) -> List[str]: + """ + Return the arguments in their raw, unredacted form. + """ + return [arg.secret if isinstance(arg, HiddenText) else arg for arg in args] + + +def call_subprocess( + cmd: Union[List[str], CommandArgs], + show_stdout: bool = False, + cwd: Optional[str] = None, + on_returncode: 'Literal["raise", "warn", "ignore"]' = "raise", + extra_ok_returncodes: Optional[Iterable[int]] = None, + extra_environ: Optional[Mapping[str, Any]] = None, + unset_environ: Optional[Iterable[str]] = None, + spinner: Optional[SpinnerInterface] = None, + log_failed_cmd: Optional[bool] = True, + stdout_only: Optional[bool] = False, + *, + command_desc: str, +) -> str: + """ + Args: + show_stdout: if true, use INFO to log the subprocess's stderr and + stdout streams. Otherwise, use DEBUG. Defaults to False. + extra_ok_returncodes: an iterable of integer return codes that are + acceptable, in addition to 0. Defaults to None, which means []. + unset_environ: an iterable of environment variable names to unset + prior to calling subprocess.Popen(). + log_failed_cmd: if false, failed commands are not logged, only raised. + stdout_only: if true, return only stdout, else return both. When true, + logging of both stdout and stderr occurs when the subprocess has + terminated, else logging occurs as subprocess output is produced. + """ + if extra_ok_returncodes is None: + extra_ok_returncodes = [] + if unset_environ is None: + unset_environ = [] + # Most places in pip use show_stdout=False. What this means is-- + # + # - We connect the child's output (combined stderr and stdout) to a + # single pipe, which we read. + # - We log this output to stderr at DEBUG level as it is received. + # - If DEBUG logging isn't enabled (e.g. if --verbose logging wasn't + # requested), then we show a spinner so the user can still see the + # subprocess is in progress. + # - If the subprocess exits with an error, we log the output to stderr + # at ERROR level if it hasn't already been displayed to the console + # (e.g. if --verbose logging wasn't enabled). This way we don't log + # the output to the console twice. + # + # If show_stdout=True, then the above is still done, but with DEBUG + # replaced by INFO. + if show_stdout: + # Then log the subprocess output at INFO level. + log_subprocess: Callable[..., None] = subprocess_logger.info + used_level = logging.INFO + else: + # Then log the subprocess output using VERBOSE. This also ensures + # it will be logged to the log file (aka user_log), if enabled. + log_subprocess = subprocess_logger.verbose + used_level = VERBOSE + + # Whether the subprocess will be visible in the console. + showing_subprocess = subprocess_logger.getEffectiveLevel() <= used_level + + # Only use the spinner if we're not showing the subprocess output + # and we have a spinner. + use_spinner = not showing_subprocess and spinner is not None + + log_subprocess("Running command %s", command_desc) + env = os.environ.copy() + if extra_environ: + env.update(extra_environ) + for name in unset_environ: + env.pop(name, None) + try: + proc = subprocess.Popen( + # Convert HiddenText objects to the underlying str. + reveal_command_args(cmd), + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT if not stdout_only else subprocess.PIPE, + cwd=cwd, + env=env, + errors="backslashreplace", + ) + except Exception as exc: + if log_failed_cmd: + subprocess_logger.critical( + "Error %s while executing command %s", + exc, + command_desc, + ) + raise + all_output = [] + if not stdout_only: + assert proc.stdout + assert proc.stdin + proc.stdin.close() + # In this mode, stdout and stderr are in the same pipe. + while True: + line: str = proc.stdout.readline() + if not line: + break + line = line.rstrip() + all_output.append(line + "\n") + + # Show the line immediately. + log_subprocess(line) + # Update the spinner. + if use_spinner: + assert spinner + spinner.spin() + try: + proc.wait() + finally: + if proc.stdout: + proc.stdout.close() + output = "".join(all_output) + else: + # In this mode, stdout and stderr are in different pipes. + # We must use communicate() which is the only safe way to read both. + out, err = proc.communicate() + # log line by line to preserve pip log indenting + for out_line in out.splitlines(): + log_subprocess(out_line) + all_output.append(out) + for err_line in err.splitlines(): + log_subprocess(err_line) + all_output.append(err) + output = out + + proc_had_error = proc.returncode and proc.returncode not in extra_ok_returncodes + if use_spinner: + assert spinner + if proc_had_error: + spinner.finish("error") + else: + spinner.finish("done") + if proc_had_error: + if on_returncode == "raise": + error = InstallationSubprocessError( + command_description=command_desc, + exit_code=proc.returncode, + output_lines=all_output if not showing_subprocess else None, + ) + if log_failed_cmd: + subprocess_logger.error("%s", error, extra={"rich": True}) + subprocess_logger.verbose( + "[bold magenta]full command[/]: [blue]%s[/]", + escape(format_command_args(cmd)), + extra={"markup": True}, + ) + subprocess_logger.verbose( + "[bold magenta]cwd[/]: %s", + escape(cwd or "[inherit]"), + extra={"markup": True}, + ) + + raise error + elif on_returncode == "warn": + subprocess_logger.warning( + 'Command "%s" had error code %s in %s', + command_desc, + proc.returncode, + cwd, + ) + elif on_returncode == "ignore": + pass + else: + raise ValueError(f"Invalid value: on_returncode={on_returncode!r}") + return output + + +def runner_with_spinner_message(message: str) -> Callable[..., None]: + """Provide a subprocess_runner that shows a spinner message. + + Intended for use with for BuildBackendHookCaller. Thus, the runner has + an API that matches what's expected by BuildBackendHookCaller.subprocess_runner. + """ + + def runner( + cmd: List[str], + cwd: Optional[str] = None, + extra_environ: Optional[Mapping[str, Any]] = None, + ) -> None: + with open_spinner(message) as spinner: + call_subprocess( + cmd, + command_desc=message, + cwd=cwd, + extra_environ=extra_environ, + spinner=spinner, + ) + + return runner diff --git a/videollama2/lib/python3.10/site-packages/pip/_internal/utils/temp_dir.py b/videollama2/lib/python3.10/site-packages/pip/_internal/utils/temp_dir.py new file mode 100644 index 0000000000000000000000000000000000000000..06668e8ab2dad131106cd9e4963d871cea147997 --- /dev/null +++ b/videollama2/lib/python3.10/site-packages/pip/_internal/utils/temp_dir.py @@ -0,0 +1,296 @@ +import errno +import itertools +import logging +import os.path +import tempfile +import traceback +from contextlib import ExitStack, contextmanager +from pathlib import Path +from typing import ( + Any, + Callable, + Dict, + Generator, + List, + Optional, + TypeVar, + Union, +) + +from pip._internal.utils.misc import enum, rmtree + +logger = logging.getLogger(__name__) + +_T = TypeVar("_T", bound="TempDirectory") + + +# Kinds of temporary directories. Only needed for ones that are +# globally-managed. +tempdir_kinds = enum( + BUILD_ENV="build-env", + EPHEM_WHEEL_CACHE="ephem-wheel-cache", + REQ_BUILD="req-build", +) + + +_tempdir_manager: Optional[ExitStack] = None + + +@contextmanager +def global_tempdir_manager() -> Generator[None, None, None]: + global _tempdir_manager + with ExitStack() as stack: + old_tempdir_manager, _tempdir_manager = _tempdir_manager, stack + try: + yield + finally: + _tempdir_manager = old_tempdir_manager + + +class TempDirectoryTypeRegistry: + """Manages temp directory behavior""" + + def __init__(self) -> None: + self._should_delete: Dict[str, bool] = {} + + def set_delete(self, kind: str, value: bool) -> None: + """Indicate whether a TempDirectory of the given kind should be + auto-deleted. + """ + self._should_delete[kind] = value + + def get_delete(self, kind: str) -> bool: + """Get configured auto-delete flag for a given TempDirectory type, + default True. + """ + return self._should_delete.get(kind, True) + + +_tempdir_registry: Optional[TempDirectoryTypeRegistry] = None + + +@contextmanager +def tempdir_registry() -> Generator[TempDirectoryTypeRegistry, None, None]: + """Provides a scoped global tempdir registry that can be used to dictate + whether directories should be deleted. + """ + global _tempdir_registry + old_tempdir_registry = _tempdir_registry + _tempdir_registry = TempDirectoryTypeRegistry() + try: + yield _tempdir_registry + finally: + _tempdir_registry = old_tempdir_registry + + +class _Default: + pass + + +_default = _Default() + + +class TempDirectory: + """Helper class that owns and cleans up a temporary directory. + + This class can be used as a context manager or as an OO representation of a + temporary directory. + + Attributes: + path + Location to the created temporary directory + delete + Whether the directory should be deleted when exiting + (when used as a contextmanager) + + Methods: + cleanup() + Deletes the temporary directory + + When used as a context manager, if the delete attribute is True, on + exiting the context the temporary directory is deleted. + """ + + def __init__( + self, + path: Optional[str] = None, + delete: Union[bool, None, _Default] = _default, + kind: str = "temp", + globally_managed: bool = False, + ignore_cleanup_errors: bool = True, + ): + super().__init__() + + if delete is _default: + if path is not None: + # If we were given an explicit directory, resolve delete option + # now. + delete = False + else: + # Otherwise, we wait until cleanup and see what + # tempdir_registry says. + delete = None + + # The only time we specify path is in for editables where it + # is the value of the --src option. + if path is None: + path = self._create(kind) + + self._path = path + self._deleted = False + self.delete = delete + self.kind = kind + self.ignore_cleanup_errors = ignore_cleanup_errors + + if globally_managed: + assert _tempdir_manager is not None + _tempdir_manager.enter_context(self) + + @property + def path(self) -> str: + assert not self._deleted, f"Attempted to access deleted path: {self._path}" + return self._path + + def __repr__(self) -> str: + return f"<{self.__class__.__name__} {self.path!r}>" + + def __enter__(self: _T) -> _T: + return self + + def __exit__(self, exc: Any, value: Any, tb: Any) -> None: + if self.delete is not None: + delete = self.delete + elif _tempdir_registry: + delete = _tempdir_registry.get_delete(self.kind) + else: + delete = True + + if delete: + self.cleanup() + + def _create(self, kind: str) -> str: + """Create a temporary directory and store its path in self.path""" + # We realpath here because some systems have their default tmpdir + # symlinked to another directory. This tends to confuse build + # scripts, so we canonicalize the path by traversing potential + # symlinks here. + path = os.path.realpath(tempfile.mkdtemp(prefix=f"pip-{kind}-")) + logger.debug("Created temporary directory: %s", path) + return path + + def cleanup(self) -> None: + """Remove the temporary directory created and reset state""" + self._deleted = True + if not os.path.exists(self._path): + return + + errors: List[BaseException] = [] + + def onerror( + func: Callable[..., Any], + path: Path, + exc_val: BaseException, + ) -> None: + """Log a warning for a `rmtree` error and continue""" + formatted_exc = "\n".join( + traceback.format_exception_only(type(exc_val), exc_val) + ) + formatted_exc = formatted_exc.rstrip() # remove trailing new line + if func in (os.unlink, os.remove, os.rmdir): + logger.debug( + "Failed to remove a temporary file '%s' due to %s.\n", + path, + formatted_exc, + ) + else: + logger.debug("%s failed with %s.", func.__qualname__, formatted_exc) + errors.append(exc_val) + + if self.ignore_cleanup_errors: + try: + # first try with @retry; retrying to handle ephemeral errors + rmtree(self._path, ignore_errors=False) + except OSError: + # last pass ignore/log all errors + rmtree(self._path, onexc=onerror) + if errors: + logger.warning( + "Failed to remove contents in a temporary directory '%s'.\n" + "You can safely remove it manually.", + self._path, + ) + else: + rmtree(self._path) + + +class AdjacentTempDirectory(TempDirectory): + """Helper class that creates a temporary directory adjacent to a real one. + + Attributes: + original + The original directory to create a temp directory for. + path + After calling create() or entering, contains the full + path to the temporary directory. + delete + Whether the directory should be deleted when exiting + (when used as a contextmanager) + + """ + + # The characters that may be used to name the temp directory + # We always prepend a ~ and then rotate through these until + # a usable name is found. + # pkg_resources raises a different error for .dist-info folder + # with leading '-' and invalid metadata + LEADING_CHARS = "-~.=%0123456789" + + def __init__(self, original: str, delete: Optional[bool] = None) -> None: + self.original = original.rstrip("/\\") + super().__init__(delete=delete) + + @classmethod + def _generate_names(cls, name: str) -> Generator[str, None, None]: + """Generates a series of temporary names. + + The algorithm replaces the leading characters in the name + with ones that are valid filesystem characters, but are not + valid package names (for both Python and pip definitions of + package). + """ + for i in range(1, len(name)): + for candidate in itertools.combinations_with_replacement( + cls.LEADING_CHARS, i - 1 + ): + new_name = "~" + "".join(candidate) + name[i:] + if new_name != name: + yield new_name + + # If we make it this far, we will have to make a longer name + for i in range(len(cls.LEADING_CHARS)): + for candidate in itertools.combinations_with_replacement( + cls.LEADING_CHARS, i + ): + new_name = "~" + "".join(candidate) + name + if new_name != name: + yield new_name + + def _create(self, kind: str) -> str: + root, name = os.path.split(self.original) + for candidate in self._generate_names(name): + path = os.path.join(root, candidate) + try: + os.mkdir(path) + except OSError as ex: + # Continue if the name exists already + if ex.errno != errno.EEXIST: + raise + else: + path = os.path.realpath(path) + break + else: + # Final fallback on the default behavior. + path = os.path.realpath(tempfile.mkdtemp(prefix=f"pip-{kind}-")) + + logger.debug("Created temporary directory: %s", path) + return path diff --git a/videollama2/lib/python3.10/site-packages/pip/_internal/utils/urls.py b/videollama2/lib/python3.10/site-packages/pip/_internal/utils/urls.py new file mode 100644 index 0000000000000000000000000000000000000000..9f34f882a1a6b7bf8e8ec5eb42c5d28f2c4e30aa --- /dev/null +++ b/videollama2/lib/python3.10/site-packages/pip/_internal/utils/urls.py @@ -0,0 +1,55 @@ +import os +import string +import urllib.parse +import urllib.request + +from .compat import WINDOWS + + +def path_to_url(path: str) -> str: + """ + Convert a path to a file: URL. The path will be made absolute and have + quoted path parts. + """ + path = os.path.normpath(os.path.abspath(path)) + url = urllib.parse.urljoin("file:", urllib.request.pathname2url(path)) + return url + + +def url_to_path(url: str) -> str: + """ + Convert a file: URL to a path. + """ + assert url.startswith( + "file:" + ), f"You can only turn file: urls into filenames (not {url!r})" + + _, netloc, path, _, _ = urllib.parse.urlsplit(url) + + if not netloc or netloc == "localhost": + # According to RFC 8089, same as empty authority. + netloc = "" + elif WINDOWS: + # If we have a UNC path, prepend UNC share notation. + netloc = "\\\\" + netloc + else: + raise ValueError( + f"non-local file URIs are not supported on this platform: {url!r}" + ) + + path = urllib.request.url2pathname(netloc + path) + + # On Windows, urlsplit parses the path as something like "/C:/Users/foo". + # This creates issues for path-related functions like io.open(), so we try + # to detect and strip the leading slash. + if ( + WINDOWS + and not netloc # Not UNC. + and len(path) >= 3 + and path[0] == "/" # Leading slash to strip. + and path[1] in string.ascii_letters # Drive letter. + and path[2:4] in (":", ":/") # Colon + end of string, or colon + absolute path. + ): + path = path[1:] + + return path diff --git a/videollama2/lib/python3.10/site-packages/pip/_internal/utils/wheel.py b/videollama2/lib/python3.10/site-packages/pip/_internal/utils/wheel.py new file mode 100644 index 0000000000000000000000000000000000000000..f85aee8a3f925ad831431de5251c4e9daa6877ea --- /dev/null +++ b/videollama2/lib/python3.10/site-packages/pip/_internal/utils/wheel.py @@ -0,0 +1,134 @@ +"""Support functions for working with wheel files. +""" + +import logging +from email.message import Message +from email.parser import Parser +from typing import Tuple +from zipfile import BadZipFile, ZipFile + +from pip._vendor.packaging.utils import canonicalize_name + +from pip._internal.exceptions import UnsupportedWheel + +VERSION_COMPATIBLE = (1, 0) + + +logger = logging.getLogger(__name__) + + +def parse_wheel(wheel_zip: ZipFile, name: str) -> Tuple[str, Message]: + """Extract information from the provided wheel, ensuring it meets basic + standards. + + Returns the name of the .dist-info directory and the parsed WHEEL metadata. + """ + try: + info_dir = wheel_dist_info_dir(wheel_zip, name) + metadata = wheel_metadata(wheel_zip, info_dir) + version = wheel_version(metadata) + except UnsupportedWheel as e: + raise UnsupportedWheel(f"{name} has an invalid wheel, {e}") + + check_compatibility(version, name) + + return info_dir, metadata + + +def wheel_dist_info_dir(source: ZipFile, name: str) -> str: + """Returns the name of the contained .dist-info directory. + + Raises AssertionError or UnsupportedWheel if not found, >1 found, or + it doesn't match the provided name. + """ + # Zip file path separators must be / + subdirs = {p.split("/", 1)[0] for p in source.namelist()} + + info_dirs = [s for s in subdirs if s.endswith(".dist-info")] + + if not info_dirs: + raise UnsupportedWheel(".dist-info directory not found") + + if len(info_dirs) > 1: + raise UnsupportedWheel( + "multiple .dist-info directories found: {}".format(", ".join(info_dirs)) + ) + + info_dir = info_dirs[0] + + info_dir_name = canonicalize_name(info_dir) + canonical_name = canonicalize_name(name) + if not info_dir_name.startswith(canonical_name): + raise UnsupportedWheel( + f".dist-info directory {info_dir!r} does not start with {canonical_name!r}" + ) + + return info_dir + + +def read_wheel_metadata_file(source: ZipFile, path: str) -> bytes: + try: + return source.read(path) + # BadZipFile for general corruption, KeyError for missing entry, + # and RuntimeError for password-protected files + except (BadZipFile, KeyError, RuntimeError) as e: + raise UnsupportedWheel(f"could not read {path!r} file: {e!r}") + + +def wheel_metadata(source: ZipFile, dist_info_dir: str) -> Message: + """Return the WHEEL metadata of an extracted wheel, if possible. + Otherwise, raise UnsupportedWheel. + """ + path = f"{dist_info_dir}/WHEEL" + # Zip file path separators must be / + wheel_contents = read_wheel_metadata_file(source, path) + + try: + wheel_text = wheel_contents.decode() + except UnicodeDecodeError as e: + raise UnsupportedWheel(f"error decoding {path!r}: {e!r}") + + # FeedParser (used by Parser) does not raise any exceptions. The returned + # message may have .defects populated, but for backwards-compatibility we + # currently ignore them. + return Parser().parsestr(wheel_text) + + +def wheel_version(wheel_data: Message) -> Tuple[int, ...]: + """Given WHEEL metadata, return the parsed Wheel-Version. + Otherwise, raise UnsupportedWheel. + """ + version_text = wheel_data["Wheel-Version"] + if version_text is None: + raise UnsupportedWheel("WHEEL is missing Wheel-Version") + + version = version_text.strip() + + try: + return tuple(map(int, version.split("."))) + except ValueError: + raise UnsupportedWheel(f"invalid Wheel-Version: {version!r}") + + +def check_compatibility(version: Tuple[int, ...], name: str) -> None: + """Raises errors or warns if called with an incompatible Wheel-Version. + + pip should refuse to install a Wheel-Version that's a major series + ahead of what it's compatible with (e.g 2.0 > 1.1); and warn when + installing a version only minor version ahead (e.g 1.2 > 1.1). + + version: a 2-tuple representing a Wheel-Version (Major, Minor) + name: name of wheel or package to raise exception about + + :raises UnsupportedWheel: when an incompatible Wheel-Version is given + """ + if version[0] > VERSION_COMPATIBLE[0]: + raise UnsupportedWheel( + "{}'s Wheel-Version ({}) is not compatible with this version " + "of pip".format(name, ".".join(map(str, version))) + ) + elif version > VERSION_COMPATIBLE: + logger.warning( + "Installing from a newer Wheel-Version (%s)", + ".".join(map(str, version)), + ) diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/_routines_statistics.cpython-310-x86_64-linux-gnu.so b/vllm/lib/python3.10/site-packages/cupy/_core/_routines_statistics.cpython-310-x86_64-linux-gnu.so new file mode 100644 index 0000000000000000000000000000000000000000..ce99b1ac87627af240fe118498f0133279fef524 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/_routines_statistics.cpython-310-x86_64-linux-gnu.so @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4886f8ecbc3079a0b55acd1aeda5a89711d4674dd18709782df832efd1c257ef +size 1246528 diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/binary_search.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/binary_search.h new file mode 100644 index 0000000000000000000000000000000000000000..c17417fc35015a443727b0d5280b85f67f514df1 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/binary_search.h @@ -0,0 +1,51 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +// the purpose of this header is to #include the binary_search.h header +// of the sequential, host, and device systems. It should be #included in any +// code which uses adl to dispatch binary_search + +#include + +// SCons can't see through the #defines below to figure out what this header +// includes, so we fake it out by specifying all possible files we might end up +// including inside an #if 0. +#if 0 +# include +# include +# include +# include +#endif + +#define __THRUST_HOST_SYSTEM_BINARY_SEARCH_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/binary_search.h> +#include __THRUST_HOST_SYSTEM_BINARY_SEARCH_HEADER +#undef __THRUST_HOST_SYSTEM_BINARY_SEARCH_HEADER + +#define __THRUST_DEVICE_SYSTEM_BINARY_SEARCH_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/binary_search.h> +#include __THRUST_DEVICE_SYSTEM_BINARY_SEARCH_HEADER +#undef __THRUST_DEVICE_SYSTEM_BINARY_SEARCH_HEADER diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/extrema.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/extrema.h new file mode 100644 index 0000000000000000000000000000000000000000..1dc3a99e8e4deb03b5fe995ab0d01110cf816b2d --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/extrema.h @@ -0,0 +1,51 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a extrema of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +// the purpose of this header is to #include the extrema.h header +// of the sequential, host, and device systems. It should be #included in any +// code which uses adl to dispatch extrema + +#include + +// SCons can't see through the #defines below to figure out what this header +// includes, so we fake it out by specifying all possible files we might end up +// including inside an #if 0. +#if 0 +# include +# include +# include +# include +#endif + +#define __THRUST_HOST_SYSTEM_EXTREMA_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/extrema.h> +#include __THRUST_HOST_SYSTEM_EXTREMA_HEADER +#undef __THRUST_HOST_SYSTEM_EXTREMA_HEADER + +#define __THRUST_DEVICE_SYSTEM_EXTREMA_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/extrema.h> +#include __THRUST_DEVICE_SYSTEM_EXTREMA_HEADER +#undef __THRUST_DEVICE_SYSTEM_EXTREMA_HEADER diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/fill.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/fill.h new file mode 100644 index 0000000000000000000000000000000000000000..4afd984f5b8a6e21d4b6bf47cb66bbffd22986ec --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/fill.h @@ -0,0 +1,51 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a fill of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +// the purpose of this header is to #include the fill.h header +// of the sequential, host, and device systems. It should be #included in any +// code which uses adl to dispatch fill + +#include + +// SCons can't see through the #defines below to figure out what this header +// includes, so we fake it out by specifying all possible files we might end up +// including inside an #if 0. +#if 0 +# include +# include +# include +# include +#endif + +#define __THRUST_HOST_SYSTEM_FILL_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/fill.h> +#include __THRUST_HOST_SYSTEM_FILL_HEADER +#undef __THRUST_HOST_SYSTEM_FILL_HEADER + +#define __THRUST_DEVICE_SYSTEM_FILL_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/fill.h> +#include __THRUST_DEVICE_SYSTEM_FILL_HEADER +#undef __THRUST_DEVICE_SYSTEM_FILL_HEADER diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/inner_product.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/inner_product.h new file mode 100644 index 0000000000000000000000000000000000000000..eaaac9aaa1a894291fe8a77338ff092ff3c353fd --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/inner_product.h @@ -0,0 +1,51 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a fill of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +// the purpose of this header is to #include the inner_product.h header +// of the sequential, host, and device systems. It should be #included in any +// code which uses adl to dispatch inner_product + +#include + +// SCons can't see through the #defines below to figure out what this header +// includes, so we fake it out by specifying all possible files we might end up +// including inside an #if 0. +#if 0 +# include +# include +# include +# include +#endif + +#define __THRUST_HOST_SYSTEM_INNER_PRODUCT_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/inner_product.h> +#include __THRUST_HOST_SYSTEM_INNER_PRODUCT_HEADER +#undef __THRUST_HOST_SYSTEM_INNER_PRODUCT_HEADER + +#define __THRUST_DEVICE_SYSTEM_INNER_PRODUCT_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/inner_product.h> +#include __THRUST_DEVICE_SYSTEM_INNER_PRODUCT_HEADER +#undef __THRUST_DEVICE_SYSTEM_INNER_PRODUCT_HEADER diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/mismatch.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/mismatch.h new file mode 100644 index 0000000000000000000000000000000000000000..8d0c83e812f83d7c80c3349d6bbefc8d5aa4771c --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/mismatch.h @@ -0,0 +1,51 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a fill of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +// the purpose of this header is to #include the mismatch.h header +// of the host and device systems. It should be #included in any +// code which uses adl to dispatch mismatch + +#include + +// SCons can't see through the #defines below to figure out what this header +// includes, so we fake it out by specifying all possible files we might end up +// including inside an #if 0. +#if 0 +# include +# include +# include +# include +#endif + +#define __THRUST_HOST_SYSTEM_MISMATCH_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/mismatch.h> +#include __THRUST_HOST_SYSTEM_MISMATCH_HEADER +#undef __THRUST_HOST_SYSTEM_MISMATCH_HEADER + +#define __THRUST_DEVICE_SYSTEM_MISMATCH_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/mismatch.h> +#include __THRUST_DEVICE_SYSTEM_MISMATCH_HEADER +#undef __THRUST_DEVICE_SYSTEM_MISMATCH_HEADER diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/partition.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/partition.h new file mode 100644 index 0000000000000000000000000000000000000000..1870fdb8a4ebfe4a8883534b5f33a145862a6c34 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/partition.h @@ -0,0 +1,51 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a fill of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +// the purpose of this header is to #include the partition.h header +// of the sequential, host, and device systems. It should be #included in any +// code which uses adl to dispatch partition + +#include + +// SCons can't see through the #defines below to figure out what this header +// includes, so we fake it out by specifying all possible files we might end up +// including inside an #if 0. +#if 0 +# include +# include +# include +# include +#endif + +#define __THRUST_HOST_SYSTEM_PARTITION_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/partition.h> +#include __THRUST_HOST_SYSTEM_PARTITION_HEADER +#undef __THRUST_HOST_SYSTEM_PARTITION_HEADER + +#define __THRUST_DEVICE_SYSTEM_PARTITION_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/partition.h> +#include __THRUST_DEVICE_SYSTEM_PARTITION_HEADER +#undef __THRUST_DEVICE_SYSTEM_PARTITION_HEADER diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/replace.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/replace.h new file mode 100644 index 0000000000000000000000000000000000000000..e1b9e7558990c22b92155095a5584b37add1ba5b --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/replace.h @@ -0,0 +1,51 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a fill of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +// the purpose of this header is to #include the replace.h header +// of the sequential, host, and device systems. It should be #included in any +// code which uses adl to dispatch replace + +#include + +// SCons can't see through the #defines below to figure out what this header +// includes, so we fake it out by specifying all possible files we might end up +// including inside an #if 0. +#if 0 +# include +# include +# include +# include +#endif + +#define __THRUST_HOST_SYSTEM_REPLACE_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/replace.h> +#include __THRUST_HOST_SYSTEM_REPLACE_HEADER +#undef __THRUST_HOST_SYSTEM_REPLACE_HEADER + +#define __THRUST_DEVICE_SYSTEM_REPLACE_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/replace.h> +#include __THRUST_DEVICE_SYSTEM_REPLACE_HEADER +#undef __THRUST_DEVICE_SYSTEM_REPLACE_HEADER diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/scan.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/scan.h new file mode 100644 index 0000000000000000000000000000000000000000..d54e8b7fb1f843ca8ae5f1d6d3d7c7436533424f --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/scan.h @@ -0,0 +1,51 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +// the purpose of this header is to #include the scan.h header +// of the host and device systems. It should be #included in any +// code which uses adl to dispatch scan + +#include + +// SCons can't see through the #defines below to figure out what this header +// includes, so we fake it out by specifying all possible files we might end up +// including inside an #if 0. +#if 0 +# include +# include +# include +# include +#endif + +#define __THRUST_HOST_SYSTEM_SCAN_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/scan.h> +#include __THRUST_HOST_SYSTEM_SCAN_HEADER +#undef __THRUST_HOST_SYSTEM_SCAN_HEADER + +#define __THRUST_DEVICE_SYSTEM_SCAN_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/scan.h> +#include __THRUST_DEVICE_SYSTEM_SCAN_HEADER +#undef __THRUST_DEVICE_SYSTEM_SCAN_HEADER diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/scan_by_key.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/scan_by_key.h new file mode 100644 index 0000000000000000000000000000000000000000..9d45e742aaeaa961eba5af5caa4f2caadc7eaed9 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/scan_by_key.h @@ -0,0 +1,51 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +// the purpose of this header is to #include the scan_by_key.h header +// of the sequential, host, and device systems. It should be #included in any +// code which uses adl to dispatch scan_by_key + +#include + +// SCons can't see through the #defines below to figure out what this header +// includes, so we fake it out by specifying all possible files we might end up +// including inside an #if 0. +#if 0 +# include +# include +# include +# include +#endif + +#define __THRUST_HOST_SYSTEM_SCAN_BY_KEY_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/scan_by_key.h> +#include __THRUST_HOST_SYSTEM_SCAN_BY_KEY_HEADER +#undef __THRUST_HOST_SYSTEM_SCAN_BY_KEY_HEADER + +#define __THRUST_DEVICE_SYSTEM_SCAN_BY_KEY_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/scan_by_key.h> +#include __THRUST_DEVICE_SYSTEM_SCAN_BY_KEY_HEADER +#undef __THRUST_DEVICE_SYSTEM_SCAN_BY_KEY_HEADER diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/scatter.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/scatter.h new file mode 100644 index 0000000000000000000000000000000000000000..ab3fd31dd8da938fbad0007eb09e5accc990c7e0 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/scatter.h @@ -0,0 +1,51 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a fill of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +// the purpose of this header is to #include the scatter.h header +// of the sequential, host, and device systems. It should be #included in any +// code which uses adl to dispatch scatter + +#include + +// SCons can't see through the #defines below to figure out what this header +// includes, so we fake it out by specifying all possible files we might end up +// including inside an #if 0. +#if 0 +# include +# include +# include +# include +#endif + +#define __THRUST_HOST_SYSTEM_SCATTER_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/scatter.h> +#include __THRUST_HOST_SYSTEM_SCATTER_HEADER +#undef __THRUST_HOST_SYSTEM_SCATTER_HEADER + +#define __THRUST_DEVICE_SYSTEM_SCATTER_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/scatter.h> +#include __THRUST_DEVICE_SYSTEM_SCATTER_HEADER +#undef __THRUST_DEVICE_SYSTEM_SCATTER_HEADER diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/transform.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/transform.h new file mode 100644 index 0000000000000000000000000000000000000000..b4970aa6d547d3363163c5017f03073df6a0f131 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/transform.h @@ -0,0 +1,51 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a fill of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +// the purpose of this header is to #include the transform.h header +// of the sequential, host, and device systems. It should be #included in any +// code which uses adl to dispatch transform + +#include + +// SCons can't see through the #defines below to figure out what this header +// includes, so we fake it out by specifying all possible files we might end up +// including inside an #if 0. +#if 0 +# include +# include +# include +# include +#endif + +#define __THRUST_HOST_SYSTEM_TRANSFORM_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/transform.h> +#include __THRUST_HOST_SYSTEM_TRANSFORM_HEADER +#undef __THRUST_HOST_SYSTEM_TRANSFORM_HEADER + +#define __THRUST_DEVICE_SYSTEM_TRANSFORM_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/transform.h> +#include __THRUST_DEVICE_SYSTEM_TRANSFORM_HEADER +#undef __THRUST_DEVICE_SYSTEM_TRANSFORM_HEADER diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/transform_reduce.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/transform_reduce.h new file mode 100644 index 0000000000000000000000000000000000000000..36ca68712fd860f6f03d637eab11d2bacbeb0210 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/transform_reduce.h @@ -0,0 +1,51 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a fill of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +// the purpose of this header is to #include the transform_reduce.h header +// of the sequential, host, and device systems. It should be #included in any +// code which uses adl to dispatch transform_reduce + +#include + +// SCons can't see through the #defines below to figure out what this header +// includes, so we fake it out by specifying all possible files we might end up +// including inside an #if 0. +#if 0 +# include +# include +# include +# include +#endif + +#define __THRUST_HOST_SYSTEM_TRANSFORM_REDUCE_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/transform_reduce.h> +#include __THRUST_HOST_SYSTEM_TRANSFORM_REDUCE_HEADER +#undef __THRUST_HOST_SYSTEM_TRANSFORM_REDUCE_HEADER + +#define __THRUST_DEVICE_SYSTEM_TRANSFORM_REDUCE_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/transform_reduce.h> +#include __THRUST_DEVICE_SYSTEM_TRANSFORM_REDUCE_HEADER +#undef __THRUST_DEVICE_SYSTEM_TRANSFORM_REDUCE_HEADER diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/uninitialized_copy.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/uninitialized_copy.h new file mode 100644 index 0000000000000000000000000000000000000000..63fbad62b2ebf39ab88d040e0379e52ab5571388 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/uninitialized_copy.h @@ -0,0 +1,51 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a fill of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +// the purpose of this header is to #include the uninitialized_copy.h header +// of the sequential, host, and device systems. It should be #included in any +// code which uses adl to dispatch uninitialized_copy + +#include + +// SCons can't see through the #defines below to figure out what this header +// includes, so we fake it out by specifying all possible files we might end up +// including inside an #if 0. +#if 0 +# include +# include +# include +# include +#endif + +#define __THRUST_HOST_SYSTEM_UNINITIALIZED_COPY_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/uninitialized_copy.h> +#include __THRUST_HOST_SYSTEM_UNINITIALIZED_COPY_HEADER +#undef __THRUST_HOST_SYSTEM_UNINITIALIZED_COPY_HEADER + +#define __THRUST_DEVICE_SYSTEM_UNINITIALIZED_COPY_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/uninitialized_copy.h> +#include __THRUST_DEVICE_SYSTEM_UNINITIALIZED_COPY_HEADER +#undef __THRUST_DEVICE_SYSTEM_UNINITIALIZED_COPY_HEADER diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/unique.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/unique.h new file mode 100644 index 0000000000000000000000000000000000000000..dc0b627d73e4058e19d3ba366c60d5d29b1246a4 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/adl/unique.h @@ -0,0 +1,51 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a fill of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +// the purpose of this header is to #include the unique.h header +// of the sequential, host, and device systems. It should be #included in any +// code which uses adl to dispatch unique + +#include + +// SCons can't see through the #defines below to figure out what this header +// includes, so we fake it out by specifying all possible files we might end up +// including inside an #if 0. +#if 0 +# include +# include +# include +# include +#endif + +#define __THRUST_HOST_SYSTEM_UNIQUE_HEADER <__THRUST_HOST_SYSTEM_ROOT/detail/unique.h> +#include __THRUST_HOST_SYSTEM_UNIQUE_HEADER +#undef __THRUST_HOST_SYSTEM_UNIQUE_HEADER + +#define __THRUST_DEVICE_SYSTEM_UNIQUE_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/detail/unique.h> +#include __THRUST_DEVICE_SYSTEM_UNIQUE_HEADER +#undef __THRUST_DEVICE_SYSTEM_UNIQUE_HEADER diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/advance.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/advance.h new file mode 100644 index 0000000000000000000000000000000000000000..cdeef9b3b0215691c8287d1bb73741007df8e6cb --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/advance.h @@ -0,0 +1,45 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ + +template +_CCCL_HOST_DEVICE void advance(InputIterator& i, Distance n); + +} // end namespace generic +} // end namespace detail +} // end namespace system +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/binary_search.inl b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/binary_search.inl new file mode 100644 index 0000000000000000000000000000000000000000..ee049bbf1a5dde3afbcdf01b417cb4e571f969ff --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/binary_search.inl @@ -0,0 +1,391 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +THRUST_NAMESPACE_BEGIN +namespace detail +{ + +// XXX WAR circular #inclusion with this forward declaration +template +class temporary_array; + +} // namespace detail +namespace system +{ +namespace detail +{ +namespace generic +{ +namespace detail +{ + +// short names to avoid nvcc bug +struct lbf +{ + template + _CCCL_HOST_DEVICE typename thrust::iterator_traits::difference_type + operator()(RandomAccessIterator begin, RandomAccessIterator end, const T& value, StrictWeakOrdering comp) + { + return thrust::system::detail::generic::scalar::lower_bound(begin, end, value, comp) - begin; + } +}; + +struct ubf +{ + template + _CCCL_HOST_DEVICE typename thrust::iterator_traits::difference_type + operator()(RandomAccessIterator begin, RandomAccessIterator end, const T& value, StrictWeakOrdering comp) + { + return thrust::system::detail::generic::scalar::upper_bound(begin, end, value, comp) - begin; + } +}; + +struct bsf +{ + template + _CCCL_HOST_DEVICE bool + operator()(RandomAccessIterator begin, RandomAccessIterator end, const T& value, StrictWeakOrdering comp) + { + RandomAccessIterator iter = thrust::system::detail::generic::scalar::lower_bound(begin, end, value, comp); + + thrust::detail::wrapped_function wrapped_comp{comp}; + + return iter != end && !wrapped_comp(value, *iter); + } +}; + +template +struct binary_search_functor +{ + ForwardIterator begin; + ForwardIterator end; + StrictWeakOrdering comp; + BinarySearchFunction func; + + _CCCL_HOST_DEVICE + binary_search_functor(ForwardIterator begin, ForwardIterator end, StrictWeakOrdering comp, BinarySearchFunction func) + : begin(begin) + , end(end) + , comp(comp) + , func(func) + {} + + template + _CCCL_HOST_DEVICE void operator()(Tuple t) + { + thrust::get<1>(t) = func(begin, end, thrust::get<0>(t), comp); + } +}; // binary_search_functor + +// Vector Implementation +template +_CCCL_HOST_DEVICE OutputIterator binary_search( + thrust::execution_policy& exec, + ForwardIterator begin, + ForwardIterator end, + InputIterator values_begin, + InputIterator values_end, + OutputIterator output, + StrictWeakOrdering comp, + BinarySearchFunction func) +{ + thrust::for_each( + exec, + thrust::make_zip_iterator(thrust::make_tuple(values_begin, output)), + thrust::make_zip_iterator(thrust::make_tuple(values_end, output + thrust::distance(values_begin, values_end))), + detail::binary_search_functor(begin, end, comp, func)); + + return output + thrust::distance(values_begin, values_end); +} + +// Scalar Implementation +template +_CCCL_HOST_DEVICE OutputType binary_search( + thrust::execution_policy& exec, + ForwardIterator begin, + ForwardIterator end, + const T& value, + StrictWeakOrdering comp, + BinarySearchFunction func) +{ + // use the vectorized path to implement the scalar version + + // allocate device buffers for value and output + thrust::detail::temporary_array d_value(exec, 1); + thrust::detail::temporary_array d_output(exec, 1); + + { // copy value to device + using value_in_system_t = typename thrust::iterator_system::type; + value_in_system_t value_in_system; + using thrust::system::detail::generic::select_system; + thrust::copy_n(select_system(thrust::detail::derived_cast(thrust::detail::strip_const(value_in_system)), + thrust::detail::derived_cast(thrust::detail::strip_const(exec))), + &value, + 1, + d_value.begin()); + } + + // perform the query + thrust::system::detail::generic::detail::binary_search( + exec, begin, end, d_value.begin(), d_value.end(), d_output.begin(), comp, func); + + OutputType output; + { // copy result to host and return + using result_out_system_t = typename thrust::iterator_system::type; + result_out_system_t result_out_system; + using thrust::system::detail::generic::select_system; + thrust::copy_n(select_system(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), + thrust::detail::derived_cast(thrust::detail::strip_const(result_out_system))), + d_output.begin(), + 1, + &output); + } + + return output; +} + +// this functor differs from thrust::less +// because it allows the types of lhs & rhs to differ +// which is required by the binary search functions +// XXX use C++14 thrust::less<> when it's ready +struct binary_search_less +{ + template + _CCCL_HOST_DEVICE bool operator()(const T1& lhs, const T2& rhs) const + { + return lhs < rhs; + } +}; + +} // end namespace detail + +////////////////////// +// Scalar Functions // +////////////////////// + +template +_CCCL_HOST_DEVICE ForwardIterator +lower_bound(thrust::execution_policy& exec, ForwardIterator begin, ForwardIterator end, const T& value) +{ + namespace p = thrust::placeholders; + return thrust::lower_bound(exec, begin, end, value, detail::binary_search_less()); +} + +template +_CCCL_HOST_DEVICE ForwardIterator lower_bound( + thrust::execution_policy& exec, + ForwardIterator begin, + ForwardIterator end, + const T& value, + StrictWeakOrdering comp) +{ + using difference_type = typename thrust::iterator_traits::difference_type; + + return begin + detail::binary_search(exec, begin, end, value, comp, detail::lbf()); +} + +template +_CCCL_HOST_DEVICE ForwardIterator +upper_bound(thrust::execution_policy& exec, ForwardIterator begin, ForwardIterator end, const T& value) +{ + namespace p = thrust::placeholders; + return thrust::upper_bound(exec, begin, end, value, detail::binary_search_less()); +} + +template +_CCCL_HOST_DEVICE ForwardIterator upper_bound( + thrust::execution_policy& exec, + ForwardIterator begin, + ForwardIterator end, + const T& value, + StrictWeakOrdering comp) +{ + using difference_type = typename thrust::iterator_traits::difference_type; + + return begin + detail::binary_search(exec, begin, end, value, comp, detail::ubf()); +} + +template +_CCCL_HOST_DEVICE bool +binary_search(thrust::execution_policy& exec, ForwardIterator begin, ForwardIterator end, const T& value) +{ + return thrust::binary_search(exec, begin, end, value, detail::binary_search_less()); +} + +template +_CCCL_HOST_DEVICE bool binary_search( + thrust::execution_policy& exec, + ForwardIterator begin, + ForwardIterator end, + const T& value, + StrictWeakOrdering comp) +{ + return detail::binary_search(exec, begin, end, value, comp, detail::bsf()); +} + +////////////////////// +// Vector Functions // +////////////////////// + +template +_CCCL_HOST_DEVICE OutputIterator lower_bound( + thrust::execution_policy& exec, + ForwardIterator begin, + ForwardIterator end, + InputIterator values_begin, + InputIterator values_end, + OutputIterator output) +{ + namespace p = thrust::placeholders; + return thrust::lower_bound(exec, begin, end, values_begin, values_end, output, detail::binary_search_less()); +} + +template +_CCCL_HOST_DEVICE OutputIterator lower_bound( + thrust::execution_policy& exec, + ForwardIterator begin, + ForwardIterator end, + InputIterator values_begin, + InputIterator values_end, + OutputIterator output, + StrictWeakOrdering comp) +{ + return detail::binary_search(exec, begin, end, values_begin, values_end, output, comp, detail::lbf()); +} + +template +_CCCL_HOST_DEVICE OutputIterator upper_bound( + thrust::execution_policy& exec, + ForwardIterator begin, + ForwardIterator end, + InputIterator values_begin, + InputIterator values_end, + OutputIterator output) +{ + namespace p = thrust::placeholders; + return thrust::upper_bound(exec, begin, end, values_begin, values_end, output, detail::binary_search_less()); +} + +template +_CCCL_HOST_DEVICE OutputIterator upper_bound( + thrust::execution_policy& exec, + ForwardIterator begin, + ForwardIterator end, + InputIterator values_begin, + InputIterator values_end, + OutputIterator output, + StrictWeakOrdering comp) +{ + return detail::binary_search(exec, begin, end, values_begin, values_end, output, comp, detail::ubf()); +} + +template +_CCCL_HOST_DEVICE OutputIterator binary_search( + thrust::execution_policy& exec, + ForwardIterator begin, + ForwardIterator end, + InputIterator values_begin, + InputIterator values_end, + OutputIterator output) +{ + namespace p = thrust::placeholders; + return thrust::binary_search(exec, begin, end, values_begin, values_end, output, detail::binary_search_less()); +} + +template +_CCCL_HOST_DEVICE OutputIterator binary_search( + thrust::execution_policy& exec, + ForwardIterator begin, + ForwardIterator end, + InputIterator values_begin, + InputIterator values_end, + OutputIterator output, + StrictWeakOrdering comp) +{ + return detail::binary_search(exec, begin, end, values_begin, values_end, output, comp, detail::bsf()); +} + +template +_CCCL_HOST_DEVICE thrust::pair equal_range( + thrust::execution_policy& exec, + ForwardIterator first, + ForwardIterator last, + const LessThanComparable& value) +{ + return thrust::equal_range(exec, first, last, value, detail::binary_search_less()); +} + +template +_CCCL_HOST_DEVICE thrust::pair equal_range( + thrust::execution_policy& exec, + ForwardIterator first, + ForwardIterator last, + const T& value, + StrictWeakOrdering comp) +{ + ForwardIterator lb = thrust::lower_bound(exec, first, last, value, comp); + ForwardIterator ub = thrust::upper_bound(exec, first, last, value, comp); + return thrust::make_pair(lb, ub); +} + +} // end namespace generic +} // end namespace detail +} // end namespace system +THRUST_NAMESPACE_END diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/copy.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/copy.h new file mode 100644 index 0000000000000000000000000000000000000000..d9365c4964eb3ac3599207d74fcffd3bb85c641a --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/copy.h @@ -0,0 +1,51 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ + +template +_CCCL_HOST_DEVICE OutputIterator +copy(thrust::execution_policy& exec, InputIterator first, InputIterator last, OutputIterator result); + +template +_CCCL_HOST_DEVICE OutputIterator +copy_n(thrust::execution_policy& exec, InputIterator first, Size n, OutputIterator result); + +} // namespace generic +} // namespace detail +} // namespace system +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/copy.inl b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/copy.inl new file mode 100644 index 0000000000000000000000000000000000000000..8a022a16c6886682121a18cc86c7b980530506ee --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/copy.inl @@ -0,0 +1,73 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include +#include +#include +#include +#include +#include +#include + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ + +template +_CCCL_HOST_DEVICE OutputIterator +copy(thrust::execution_policy& exec, InputIterator first, InputIterator last, OutputIterator result) +{ + using T = typename thrust::iterator_value::type; + return thrust::transform(exec, first, last, result, thrust::identity()); +} // end copy() + +template +_CCCL_HOST_DEVICE OutputIterator +copy_n(thrust::execution_policy& exec, InputIterator first, Size n, OutputIterator result) +{ + using value_type = typename thrust::iterator_value::type; + using xfrm_type = thrust::identity; + + using functor_type = thrust::detail::unary_transform_functor; + + using iterator_tuple = thrust::tuple; + using zip_iter = thrust::zip_iterator; + + zip_iter zipped = thrust::make_zip_iterator(thrust::make_tuple(first, result)); + + return thrust::get<1>(thrust::for_each_n(exec, zipped, n, functor_type(xfrm_type())).get_iterator_tuple()); +} // end copy_n() + +} // namespace generic +} // namespace detail +} // namespace system +THRUST_NAMESPACE_END diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/copy_if.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/copy_if.h new file mode 100644 index 0000000000000000000000000000000000000000..92d6cf5c69f11b29f5406678ad39e0a5b1511e5c --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/copy_if.h @@ -0,0 +1,64 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ + +template +_CCCL_HOST_DEVICE OutputIterator copy_if( + thrust::execution_policy& exec, + InputIterator first, + InputIterator last, + OutputIterator result, + Predicate pred); + +template +_CCCL_HOST_DEVICE OutputIterator copy_if( + thrust::execution_policy& exec, + InputIterator1 first, + InputIterator1 last, + InputIterator2 stencil, + OutputIterator result, + Predicate pred); + +} // end namespace generic +} // end namespace detail +} // end namespace system +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/copy_if.inl b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/copy_if.inl new file mode 100644 index 0000000000000000000000000000000000000000..6ccc52732c1ce8e2d235a8ca5aff2eb20def0d91 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/copy_if.inl @@ -0,0 +1,156 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ +namespace detail +{ + +template +_CCCL_HOST_DEVICE OutputIterator copy_if( + thrust::execution_policy& exec, + InputIterator1 first, + InputIterator1 last, + InputIterator2 stencil, + OutputIterator result, + Predicate pred) +{ + const auto n = static_cast(thrust::distance(first, last)); + + // compute {0,1} predicates + thrust::detail::temporary_array predicates(exec, n); + thrust::transform( + exec, stencil, stencil + n, predicates.begin(), thrust::detail::predicate_to_integral(pred)); + + // scan {0,1} predicates + thrust::detail::temporary_array scatter_indices(exec, n); + thrust::exclusive_scan( + exec, + predicates.begin(), + predicates.end(), + scatter_indices.begin(), + static_cast(0), + thrust::plus()); + + // scatter the true elements + thrust::scatter_if( + exec, first, last, scatter_indices.begin(), predicates.begin(), result, thrust::identity()); + + // find the end of the new sequence + IndexType output_size = scatter_indices[n - 1] + predicates[n - 1]; + + return result + output_size; +} + +} // end namespace detail + +template +_CCCL_HOST_DEVICE OutputIterator copy_if( + thrust::execution_policy& exec, + InputIterator first, + InputIterator last, + OutputIterator result, + Predicate pred) +{ + // XXX it's potentially expensive to send [first,last) twice + // we should probably specialize this case for POD + // since we can safely keep the input in a temporary instead + // of doing two loads + return thrust::copy_if(exec, first, last, first, result, pred); +} // end copy_if() + +template +_CCCL_HOST_DEVICE OutputIterator copy_if( + thrust::execution_policy& exec, + InputIterator1 first, + InputIterator1 last, + InputIterator2 stencil, + OutputIterator result, + Predicate pred) +{ + using difference_type = typename thrust::iterator_traits::difference_type; + + // empty sequence + if (first == last) + { + return result; + } + + difference_type n = thrust::distance(first, last); + + // create an unsigned version of n (we know n is positive from the comparison above) + // to avoid a warning in the compare below + ::cuda::std::make_unsigned_t unsigned_n(n); + + // use 32-bit indices when possible (almost always) + if (sizeof(difference_type) > sizeof(unsigned int) + && unsigned_n > thrust::detail::integer_traits::const_max) + { + result = detail::copy_if(exec, first, last, stencil, result, pred); + } // end if + else + { + result = detail::copy_if(exec, first, last, stencil, result, pred); + } // end else + + return result; +} // end copy_if() + +} // end namespace generic +} // end namespace detail +} // end namespace system +THRUST_NAMESPACE_END diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/count.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/count.h new file mode 100644 index 0000000000000000000000000000000000000000..dcef420932c46186cfac687075e24d4783dbccba --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/count.h @@ -0,0 +1,54 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ + +template +_CCCL_HOST_DEVICE typename thrust::iterator_traits::difference_type +count(thrust::execution_policy& exec, + InputIterator first, + InputIterator last, + const EqualityComparable& value); + +template +_CCCL_HOST_DEVICE typename thrust::iterator_traits::difference_type +count_if(thrust::execution_policy& exec, InputIterator first, InputIterator last, Predicate pred); + +} // end namespace generic +} // end namespace detail +} // end namespace system +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/distance.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/distance.h new file mode 100644 index 0000000000000000000000000000000000000000..30c79a2387bfbaae0f3060eb927e3a322a118e6f --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/distance.h @@ -0,0 +1,47 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ + +template +inline _CCCL_HOST_DEVICE typename thrust::iterator_traits::difference_type +distance(InputIterator first, InputIterator last); + +} // end namespace generic +} // end namespace detail +} // end namespace system +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/distance.inl b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/distance.inl new file mode 100644 index 0000000000000000000000000000000000000000..e12a0ea687947ac97d35c3599b9ba16feae4eaff --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/distance.inl @@ -0,0 +1,80 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ +namespace detail +{ + +_CCCL_EXEC_CHECK_DISABLE +template +inline _CCCL_HOST_DEVICE typename thrust::iterator_traits::difference_type +distance(InputIterator first, InputIterator last, thrust::incrementable_traversal_tag) +{ + typename thrust::iterator_traits::difference_type result(0); + + while (first != last) + { + ++first; + ++result; + } // end while + + return result; +} // end advance() + +_CCCL_EXEC_CHECK_DISABLE +template +inline _CCCL_HOST_DEVICE typename thrust::iterator_traits::difference_type +distance(InputIterator first, InputIterator last, thrust::random_access_traversal_tag) +{ + return last - first; +} // end distance() + +} // namespace detail + +_CCCL_EXEC_CHECK_DISABLE +template +inline _CCCL_HOST_DEVICE typename thrust::iterator_traits::difference_type +distance(InputIterator first, InputIterator last) +{ + // dispatch on iterator traversal + return thrust::system::detail::generic::detail::distance( + first, last, typename thrust::iterator_traversal::type()); +} // end advance() + +} // end namespace generic +} // end namespace detail +} // end namespace system +THRUST_NAMESPACE_END diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/extrema.inl b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/extrema.inl new file mode 100644 index 0000000000000000000000000000000000000000..0683250e92b3c4b4ab12904efeadc53b0670b7ed --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/extrema.inl @@ -0,0 +1,258 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file distance.h + * \brief Device implementations for distance. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include +#include +#include +#include +#include +#include +#include +#include + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ +namespace detail +{ + +////////////// +// Functors // +////////////// +// + +// return the smaller/larger element making sure to prefer the +// first occurrence of the minimum/maximum element +template +struct min_element_reduction +{ + BinaryPredicate comp; + + _CCCL_HOST_DEVICE min_element_reduction(BinaryPredicate comp) + : comp(comp) + {} + + _CCCL_HOST_DEVICE thrust::tuple + operator()(const thrust::tuple& lhs, const thrust::tuple& rhs) + { + if (comp(thrust::get<0>(lhs), thrust::get<0>(rhs))) + { + return lhs; + } + if (comp(thrust::get<0>(rhs), thrust::get<0>(lhs))) + { + return rhs; + } + + // values are equivalent, prefer value with smaller index + if (thrust::get<1>(lhs) < thrust::get<1>(rhs)) + { + return lhs; + } + else + { + return rhs; + } + } // end operator()() +}; // end min_element_reduction + +template +struct max_element_reduction +{ + BinaryPredicate comp; + + _CCCL_HOST_DEVICE max_element_reduction(BinaryPredicate comp) + : comp(comp) + {} + + _CCCL_HOST_DEVICE thrust::tuple + operator()(const thrust::tuple& lhs, const thrust::tuple& rhs) + { + if (comp(thrust::get<0>(lhs), thrust::get<0>(rhs))) + { + return rhs; + } + if (comp(thrust::get<0>(rhs), thrust::get<0>(lhs))) + { + return lhs; + } + + // values are equivalent, prefer value with smaller index + if (thrust::get<1>(lhs) < thrust::get<1>(rhs)) + { + return lhs; + } + else + { + return rhs; + } + } // end operator()() +}; // end max_element_reduction + +// return the smaller & larger element making sure to prefer the +// first occurrence of the minimum/maximum element +template +struct minmax_element_reduction +{ + BinaryPredicate comp; + + _CCCL_HOST_DEVICE minmax_element_reduction(BinaryPredicate comp) + : comp(comp) + {} + + _CCCL_HOST_DEVICE thrust::tuple, thrust::tuple> + operator()(const thrust::tuple, thrust::tuple>& lhs, + const thrust::tuple, thrust::tuple>& rhs) + { + return thrust::make_tuple( + min_element_reduction(comp)(thrust::get<0>(lhs), thrust::get<0>(rhs)), + max_element_reduction(comp)(thrust::get<1>(lhs), thrust::get<1>(rhs))); + } // end operator()() +}; // end minmax_element_reduction + +template +struct duplicate_tuple +{ + _CCCL_HOST_DEVICE thrust::tuple, thrust::tuple> + operator()(const thrust::tuple& t) + { + return thrust::make_tuple(t, t); + } +}; // end duplicate_tuple + +} // end namespace detail + +template +_CCCL_HOST_DEVICE ForwardIterator +min_element(thrust::execution_policy& exec, ForwardIterator first, ForwardIterator last) +{ + using value_type = typename thrust::iterator_value::type; + + return thrust::min_element(exec, first, last, thrust::less()); +} // end min_element() + +template +_CCCL_HOST_DEVICE ForwardIterator min_element( + thrust::execution_policy& exec, ForwardIterator first, ForwardIterator last, BinaryPredicate comp) +{ + if (first == last) + { + return last; + } + + using InputType = typename thrust::iterator_traits::value_type; + using IndexType = typename thrust::iterator_traits::difference_type; + + thrust::tuple result = thrust::reduce( + exec, + thrust::make_zip_iterator(thrust::make_tuple(first, thrust::counting_iterator(0))), + thrust::make_zip_iterator(thrust::make_tuple(first, thrust::counting_iterator(0))) + (last - first), + thrust::tuple(thrust::detail::get_iterator_value(derived_cast(exec), first), 0), + detail::min_element_reduction(comp)); + + return first + thrust::get<1>(result); +} // end min_element() + +template +_CCCL_HOST_DEVICE ForwardIterator +max_element(thrust::execution_policy& exec, ForwardIterator first, ForwardIterator last) +{ + using value_type = typename thrust::iterator_value::type; + + return thrust::max_element(exec, first, last, thrust::less()); +} // end max_element() + +template +_CCCL_HOST_DEVICE ForwardIterator max_element( + thrust::execution_policy& exec, ForwardIterator first, ForwardIterator last, BinaryPredicate comp) +{ + if (first == last) + { + return last; + } + + using InputType = typename thrust::iterator_traits::value_type; + using IndexType = typename thrust::iterator_traits::difference_type; + + thrust::tuple result = thrust::reduce( + exec, + thrust::make_zip_iterator(thrust::make_tuple(first, thrust::counting_iterator(0))), + thrust::make_zip_iterator(thrust::make_tuple(first, thrust::counting_iterator(0))) + (last - first), + thrust::tuple(thrust::detail::get_iterator_value(derived_cast(exec), first), 0), + detail::max_element_reduction(comp)); + + return first + thrust::get<1>(result); +} // end max_element() + +template +_CCCL_HOST_DEVICE thrust::pair +minmax_element(thrust::execution_policy& exec, ForwardIterator first, ForwardIterator last) +{ + using value_type = typename thrust::iterator_value::type; + + return thrust::minmax_element(exec, first, last, thrust::less()); +} // end minmax_element() + +template +_CCCL_HOST_DEVICE thrust::pair minmax_element( + thrust::execution_policy& exec, ForwardIterator first, ForwardIterator last, BinaryPredicate comp) +{ + if (first == last) + { + return thrust::make_pair(last, last); + } + + using InputType = typename thrust::iterator_traits::value_type; + using IndexType = typename thrust::iterator_traits::difference_type; + + thrust::tuple, thrust::tuple> result = + thrust::transform_reduce( + exec, + thrust::make_zip_iterator(thrust::make_tuple(first, thrust::counting_iterator(0))), + thrust::make_zip_iterator(thrust::make_tuple(first, thrust::counting_iterator(0))) + (last - first), + detail::duplicate_tuple(), + detail::duplicate_tuple()( + thrust::tuple(thrust::detail::get_iterator_value(derived_cast(exec), first), 0)), + detail::minmax_element_reduction(comp)); + + return thrust::make_pair(first + thrust::get<1>(thrust::get<0>(result)), + first + thrust::get<1>(thrust::get<1>(result))); +} // end minmax_element() + +} // end namespace generic +} // end namespace detail +} // end namespace system +THRUST_NAMESPACE_END diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/find.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/find.h new file mode 100644 index 0000000000000000000000000000000000000000..1de15f02d62d4fe5b5d675d82d8060d37033286e --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/find.h @@ -0,0 +1,55 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ + +template +_CCCL_HOST_DEVICE InputIterator +find(thrust::execution_policy& exec, InputIterator first, InputIterator last, const T& value); + +template +_CCCL_HOST_DEVICE InputIterator +find_if(thrust::execution_policy& exec, InputIterator first, InputIterator last, Predicate pred); + +template +_CCCL_HOST_DEVICE InputIterator +find_if_not(thrust::execution_policy& exec, InputIterator first, InputIterator last, Predicate pred); + +} // end namespace generic +} // end namespace detail +} // end namespace system +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/for_each.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/for_each.h new file mode 100644 index 0000000000000000000000000000000000000000..990e0789cb8ded4f3377bd9ffcfa85121acf0cae --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/for_each.h @@ -0,0 +1,66 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file for_each.h + * \brief Generic implementation of for_each & for_each_n. + * It is an error to call these functions; they have no implementation. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include +#include + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ + +template +_CCCL_HOST_DEVICE InputIterator +for_each(thrust::execution_policy&, InputIterator first, InputIterator, UnaryFunction) +{ + THRUST_STATIC_ASSERT_MSG((thrust::detail::depend_on_instantiation::value), + "unimplemented for this system"); + return first; +} // end for_each() + +template +_CCCL_HOST_DEVICE InputIterator +for_each_n(thrust::execution_policy&, InputIterator first, Size, UnaryFunction) +{ + THRUST_STATIC_ASSERT_MSG((thrust::detail::depend_on_instantiation::value), + "unimplemented for this system"); + return first; +} // end for_each_n() + +} // end namespace generic +} // end namespace detail +} // end namespace system +THRUST_NAMESPACE_END diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/gather.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/gather.h new file mode 100644 index 0000000000000000000000000000000000000000..691e5b5164f9f3779286244199ae6ad911936b80 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/gather.h @@ -0,0 +1,79 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ + +template +_CCCL_HOST_DEVICE OutputIterator gather( + thrust::execution_policy& exec, + InputIterator map_first, + InputIterator map_last, + RandomAccessIterator input_first, + OutputIterator result); + +template +_CCCL_HOST_DEVICE OutputIterator gather_if( + thrust::execution_policy& exec, + InputIterator1 map_first, + InputIterator1 map_last, + InputIterator2 stencil, + RandomAccessIterator input_first, + OutputIterator result); + +template +_CCCL_HOST_DEVICE OutputIterator gather_if( + thrust::execution_policy& exec, + InputIterator1 map_first, + InputIterator1 map_last, + InputIterator2 stencil, + RandomAccessIterator input_first, + OutputIterator result, + Predicate pred); + +} // end namespace generic +} // end namespace detail +} // end namespace system +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/gather.inl b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/gather.inl new file mode 100644 index 0000000000000000000000000000000000000000..569a7fbe366041e803c89be7aee60b36731cce33 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/gather.inl @@ -0,0 +1,104 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include +#include +#include +#include + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ + +template +_CCCL_HOST_DEVICE OutputIterator gather( + thrust::execution_policy& exec, + InputIterator map_first, + InputIterator map_last, + RandomAccessIterator input_first, + OutputIterator result) +{ + return thrust::transform( + exec, + thrust::make_permutation_iterator(input_first, map_first), + thrust::make_permutation_iterator(input_first, map_last), + result, + thrust::identity::type>()); +} // end gather() + +template +_CCCL_HOST_DEVICE OutputIterator gather_if( + thrust::execution_policy& exec, + InputIterator1 map_first, + InputIterator1 map_last, + InputIterator2 stencil, + RandomAccessIterator input_first, + OutputIterator result) +{ + using StencilType = typename thrust::iterator_value::type; + return thrust::gather_if(exec, map_first, map_last, stencil, input_first, result, thrust::identity()); +} // end gather_if() + +template +_CCCL_HOST_DEVICE OutputIterator gather_if( + thrust::execution_policy& exec, + InputIterator1 map_first, + InputIterator1 map_last, + InputIterator2 stencil, + RandomAccessIterator input_first, + OutputIterator result, + Predicate pred) +{ + using InputType = typename thrust::iterator_value::type; + return thrust::transform_if( + exec, + thrust::make_permutation_iterator(input_first, map_first), + thrust::make_permutation_iterator(input_first, map_last), + stencil, + result, + thrust::identity(), + pred); +} // end gather_if() + +} // end namespace generic +} // end namespace detail +} // end namespace system +THRUST_NAMESPACE_END diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/generate.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/generate.h new file mode 100644 index 0000000000000000000000000000000000000000..540f44af7b69b9ac5ff0549f7efb3ec220097c1d --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/generate.h @@ -0,0 +1,51 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ + +template +_CCCL_HOST_DEVICE void +generate(thrust::execution_policy& exec, ForwardIterator first, ForwardIterator last, Generator gen); + +template +_CCCL_HOST_DEVICE OutputIterator +generate_n(thrust::execution_policy& exec, OutputIterator first, Size n, Generator gen); + +} // end namespace generic +} // end namespace detail +} // end namespace system +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/generate.inl b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/generate.inl new file mode 100644 index 0000000000000000000000000000000000000000..cc72f7ca583c18188cb3b87412d717d75bd4e377 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/generate.inl @@ -0,0 +1,90 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include +#include +#include +#include + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ + +template +_CCCL_HOST_DEVICE void +generate(thrust::execution_policy& exec, ForwardIterator first, ForwardIterator last, Generator gen) +{ + // this static assert is necessary due to a workaround in generate_functor + // it takes a const reference to accept temporaries from proxy iterators + // and then const_casts the constness away + // + // this had the weird side effect of allowing generate (and fill, and whatever + // else is implemented in terms of generate) to fill through const iterators. + // this might become unnecessary once Thrust is C++11-and-above only, since the + // other solution is to take an rvalue reference in a second overload of + // operator() of the function object, but until we support pre-11, this is a + // nice solution that validates the const_cast and doesn't take away any + // functionality. + THRUST_STATIC_ASSERT_MSG( + !::cuda::std::is_const< + ::cuda::std::remove_reference_t::reference>>::value, + "generating to `const` iterators is not allowed"); + thrust::for_each(exec, first, last, typename thrust::detail::generate_functor::type(gen)); +} // end generate() + +template +_CCCL_HOST_DEVICE OutputIterator +generate_n(thrust::execution_policy& exec, OutputIterator first, Size n, Generator gen) +{ + // this static assert is necessary due to a workaround in generate_functor + // it takes a const reference to accept temporaries from proxy iterators + // and then const_casts the constness away + // + // this had the weird side effect of allowing generate (and fill, and whatever + // else is implemented in terms of generate) to fill through const iterators. + // this might become unnecessary once Thrust is C++11-and-above only, since the + // other solution is to take an rvalue reference in a second overload of + // operator() of the function object, but until we support pre-11, this is a + // nice solution that validates the const_cast and doesn't take away any + // functionality. + THRUST_STATIC_ASSERT_MSG( + !::cuda::std::is_const< + ::cuda::std::remove_reference_t::reference>>::value, + "generating to `const` iterators is not allowed"); + return thrust::for_each_n( + exec, first, n, typename thrust::detail::generate_functor::type(gen)); +} // end generate() + +} // end namespace generic +} // end namespace detail +} // end namespace system +THRUST_NAMESPACE_END diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/inner_product.inl b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/inner_product.inl new file mode 100644 index 0000000000000000000000000000000000000000..f1906ca9e5dbe62d4ce860d943e9e0e23fdad53f --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/inner_product.inl @@ -0,0 +1,78 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include +#include +#include +#include + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ + +template +_CCCL_HOST_DEVICE OutputType inner_product( + thrust::execution_policy& exec, + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2, + OutputType init) +{ + thrust::plus binary_op1; + thrust::multiplies binary_op2; + return thrust::inner_product(exec, first1, last1, first2, init, binary_op1, binary_op2); +} // end inner_product() + +template +_CCCL_HOST_DEVICE OutputType inner_product( + thrust::execution_policy& exec, + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2, + OutputType init, + BinaryFunction1 binary_op1, + BinaryFunction2 binary_op2) +{ + const auto first = thrust::make_zip_iterator(first1, first2); + const auto last = thrust::make_zip_iterator(last1, first2); // only first iterator matters + return thrust::transform_reduce(exec, first, last, thrust::make_zip_function(binary_op2), init, binary_op1); +} // end inner_product() + +} // namespace generic +} // namespace detail +} // namespace system +THRUST_NAMESPACE_END diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/logical.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/logical.h new file mode 100644 index 0000000000000000000000000000000000000000..4049140a4b0745afe8b3b5d581a46857be4d2d3e --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/logical.h @@ -0,0 +1,65 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include +#include +#include + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ + +template +_CCCL_HOST_DEVICE bool +all_of(thrust::execution_policy& exec, InputIterator first, InputIterator last, Predicate pred) +{ + return thrust::find_if(exec, first, last, thrust::not_fn(pred)) == last; +} + +template +_CCCL_HOST_DEVICE bool +any_of(thrust::execution_policy& exec, InputIterator first, InputIterator last, Predicate pred) +{ + return thrust::find_if(exec, first, last, pred) != last; +} + +template +_CCCL_HOST_DEVICE bool +none_of(thrust::execution_policy& exec, InputIterator first, InputIterator last, Predicate pred) +{ + return !thrust::any_of(exec, first, last, pred); +} + +} // namespace generic +} // namespace detail +} // namespace system +THRUST_NAMESPACE_END diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/merge.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/merge.h new file mode 100644 index 0000000000000000000000000000000000000000..f6fc6f78597f3b161b3a98cc3a3a07c490188f43 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/merge.h @@ -0,0 +1,105 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ + +// XXX calling this function is an error; there is no implementation +template +_CCCL_HOST_DEVICE OutputIterator merge( + thrust::execution_policy& exec, + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2, + InputIterator2 last2, + OutputIterator result, + StrictWeakOrdering comp); + +template +_CCCL_HOST_DEVICE OutputIterator merge( + thrust::execution_policy& exec, + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2, + InputIterator2 last2, + OutputIterator result); + +template +_CCCL_HOST_DEVICE thrust::pair merge_by_key( + thrust::execution_policy& exec, + InputIterator1 keys_first1, + InputIterator1 keys_last1, + InputIterator2 keys_first2, + InputIterator2 keys_last2, + InputIterator3 values_first1, + InputIterator4 values_first2, + OutputIterator1 keys_result, + OutputIterator2 values_result, + Compare comp); + +template +_CCCL_HOST_DEVICE thrust::pair merge_by_key( + thrust::execution_policy& exec, + InputIterator1 keys_first1, + InputIterator1 keys_last1, + InputIterator2 keys_first2, + InputIterator2 keys_last2, + InputIterator3 values_first1, + InputIterator4 values_first2, + OutputIterator1 keys_result, + OutputIterator2 values_result); + +} // end namespace generic +} // end namespace detail +} // end namespace system +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/merge.inl b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/merge.inl new file mode 100644 index 0000000000000000000000000000000000000000..67336eb87caee4188b43f8bd59b8d7718116af52 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/merge.inl @@ -0,0 +1,155 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include +#include +#include +#include +#include + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ + +template +_CCCL_HOST_DEVICE OutputIterator merge( + thrust::execution_policy&, + InputIterator1, + InputIterator1, + InputIterator2, + InputIterator2, + OutputIterator result, + StrictWeakOrdering) +{ + THRUST_STATIC_ASSERT_MSG((thrust::detail::depend_on_instantiation::value), + "unimplemented for this system"); + return result; +} // end merge() + +template +_CCCL_HOST_DEVICE OutputIterator merge( + thrust::execution_policy& exec, + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2, + InputIterator2 last2, + OutputIterator result) +{ + using value_type = typename thrust::iterator_value::type; + return thrust::merge(exec, first1, last1, first2, last2, result, thrust::less()); +} // end merge() + +template +_CCCL_HOST_DEVICE thrust::pair merge_by_key( + thrust::execution_policy& exec, + InputIterator1 keys_first1, + InputIterator1 keys_last1, + InputIterator2 keys_first2, + InputIterator2 keys_last2, + InputIterator3 values_first1, + InputIterator4 values_first2, + OutputIterator1 keys_result, + OutputIterator2 values_result, + Compare comp) +{ + using iterator_tuple1 = thrust::tuple; + using iterator_tuple2 = thrust::tuple; + using iterator_tuple3 = thrust::tuple; + + using zip_iterator1 = thrust::zip_iterator; + using zip_iterator2 = thrust::zip_iterator; + using zip_iterator3 = thrust::zip_iterator; + + zip_iterator1 zipped_first1 = thrust::make_zip_iterator(thrust::make_tuple(keys_first1, values_first1)); + zip_iterator1 zipped_last1 = thrust::make_zip_iterator(thrust::make_tuple(keys_last1, values_first1)); + + zip_iterator2 zipped_first2 = thrust::make_zip_iterator(thrust::make_tuple(keys_first2, values_first2)); + zip_iterator2 zipped_last2 = thrust::make_zip_iterator(thrust::make_tuple(keys_last2, values_first2)); + + zip_iterator3 zipped_result = thrust::make_zip_iterator(thrust::make_tuple(keys_result, values_result)); + + thrust::detail::compare_first comp_first(comp); + + iterator_tuple3 result = + thrust::merge(exec, zipped_first1, zipped_last1, zipped_first2, zipped_last2, zipped_result, comp_first) + .get_iterator_tuple(); + + return thrust::make_pair(thrust::get<0>(result), thrust::get<1>(result)); +} // end merge_by_key() + +template +_CCCL_HOST_DEVICE thrust::pair merge_by_key( + thrust::execution_policy& exec, + InputIterator1 keys_first1, + InputIterator1 keys_last1, + InputIterator2 keys_first2, + InputIterator2 keys_last2, + InputIterator3 values_first1, + InputIterator4 values_first2, + OutputIterator1 keys_result, + OutputIterator2 values_result) +{ + using value_type = typename thrust::iterator_value::type; + return thrust::merge_by_key( + exec, + keys_first1, + keys_last1, + keys_first2, + keys_last2, + values_first1, + values_first2, + keys_result, + values_result, + thrust::less()); +} // end merge_by_key() + +} // end namespace generic +} // end namespace detail +} // end namespace system +THRUST_NAMESPACE_END diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/per_device_resource.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/per_device_resource.h new file mode 100644 index 0000000000000000000000000000000000000000..76468b92f71291491c8d3a253a87f0458a605b6d --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/per_device_resource.h @@ -0,0 +1,49 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include +#include + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ + +template +_CCCL_HOST MR* get_per_device_resource(thrust::detail::execution_policy_base&) +{ + return mr::get_global_resource(); +} + +} // namespace generic +} // namespace detail +} // namespace system +THRUST_NAMESPACE_END diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/reduce.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/reduce.h new file mode 100644 index 0000000000000000000000000000000000000000..b1fe9a51ed0cc4f5265ef67953297c2ab1193691 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/reduce.h @@ -0,0 +1,60 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ + +template +_CCCL_HOST_DEVICE typename thrust::iterator_traits::value_type +reduce(thrust::execution_policy& exec, InputIterator first, InputIterator last); + +template +_CCCL_HOST_DEVICE T +reduce(thrust::execution_policy& exec, InputIterator first, InputIterator last, T init); + +template +_CCCL_HOST_DEVICE T reduce( + thrust::execution_policy& exec, + InputIterator first, + InputIterator last, + T init, + BinaryFunction binary_op); + +} // end namespace generic +} // end namespace detail +} // end namespace system +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/reduce_by_key.inl b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/reduce_by_key.inl new file mode 100644 index 0000000000000000000000000000000000000000..2d0d73859f0793bee0eccd4ab6451a0b47fc8162 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/reduce_by_key.inl @@ -0,0 +1,189 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ +namespace detail +{ + +template +struct reduce_by_key_functor +{ + AssociativeOperator binary_op; + + using result_type = typename thrust::tuple; + + _CCCL_HOST_DEVICE reduce_by_key_functor(AssociativeOperator _binary_op) + : binary_op(_binary_op) + {} + + _CCCL_HOST_DEVICE result_type operator()(result_type a, result_type b) + { + return result_type(thrust::get<1>(b) ? thrust::get<0>(b) : binary_op(thrust::get<0>(a), thrust::get<0>(b)), + thrust::get<1>(a) | thrust::get<1>(b)); + } +}; + +} // end namespace detail + +template +_CCCL_HOST_DEVICE thrust::pair reduce_by_key( + thrust::execution_policy& exec, + InputIterator1 keys_first, + InputIterator1 keys_last, + InputIterator2 values_first, + OutputIterator1 keys_output, + OutputIterator2 values_output, + BinaryPredicate binary_pred, + BinaryFunction binary_op) +{ + using difference_type = typename thrust::iterator_traits::difference_type; + + using FlagType = unsigned int; // TODO use difference_type + + // Use the input iterator's value type per https://wg21.link/P0571 + using ValueType = typename thrust::iterator_value::type; + + if (keys_first == keys_last) + { + return thrust::make_pair(keys_output, values_output); + } + + // input size + difference_type n = keys_last - keys_first; + + InputIterator2 values_last = values_first + n; + + // compute head flags + thrust::detail::temporary_array head_flags(exec, n); + thrust::transform( + exec, keys_first, keys_last - 1, keys_first + 1, head_flags.begin() + 1, thrust::not_fn(binary_pred)); + head_flags[0] = 1; + + // compute tail flags + thrust::detail::temporary_array tail_flags(exec, n); // COPY INSTEAD OF TRANSFORM + thrust::transform(exec, keys_first, keys_last - 1, keys_first + 1, tail_flags.begin(), thrust::not_fn(binary_pred)); + tail_flags[n - 1] = 1; + + // scan the values by flag + thrust::detail::temporary_array scanned_values(exec, n); + thrust::detail::temporary_array scanned_tail_flags(exec, n); + + thrust::inclusive_scan( + exec, + thrust::make_zip_iterator(thrust::make_tuple(values_first, head_flags.begin())), + thrust::make_zip_iterator(thrust::make_tuple(values_last, head_flags.end())), + thrust::make_zip_iterator(thrust::make_tuple(scanned_values.begin(), scanned_tail_flags.begin())), + detail::reduce_by_key_functor(binary_op)); + + thrust::exclusive_scan( + exec, tail_flags.begin(), tail_flags.end(), scanned_tail_flags.begin(), FlagType(0), thrust::plus()); + + // number of unique keys + FlagType N = scanned_tail_flags[n - 1] + 1; + + // scatter the keys and accumulated values + thrust::scatter_if(exec, keys_first, keys_last, scanned_tail_flags.begin(), head_flags.begin(), keys_output); + thrust::scatter_if( + exec, scanned_values.begin(), scanned_values.end(), scanned_tail_flags.begin(), tail_flags.begin(), values_output); + + return thrust::make_pair(keys_output + N, values_output + N); +} // end reduce_by_key() + +template +_CCCL_HOST_DEVICE thrust::pair reduce_by_key( + thrust::execution_policy& exec, + InputIterator1 keys_first, + InputIterator1 keys_last, + InputIterator2 values_first, + OutputIterator1 keys_output, + OutputIterator2 values_output) +{ + using KeyType = typename thrust::iterator_value::type; + + // use equal_to as default BinaryPredicate + return thrust::reduce_by_key( + exec, keys_first, keys_last, values_first, keys_output, values_output, thrust::equal_to()); +} // end reduce_by_key() + +template +_CCCL_HOST_DEVICE thrust::pair reduce_by_key( + thrust::execution_policy& exec, + InputIterator1 keys_first, + InputIterator1 keys_last, + InputIterator2 values_first, + OutputIterator1 keys_output, + OutputIterator2 values_output, + BinaryPredicate binary_pred) +{ + using T = typename thrust::detail::eval_if::value, + thrust::iterator_value, + thrust::iterator_value>::type; + + // use plus as default BinaryFunction + return thrust::reduce_by_key( + exec, keys_first, keys_last, values_first, keys_output, values_output, binary_pred, thrust::plus()); +} // end reduce_by_key() + +} // end namespace generic +} // end namespace detail +} // end namespace system +THRUST_NAMESPACE_END diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/remove.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/remove.h new file mode 100644 index 0000000000000000000000000000000000000000..09fe3d966f09272b23e6d6eed64a0ae14fcc0651 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/remove.h @@ -0,0 +1,92 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file remove.h + * \brief Generic implementations of remove functions. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ + +template +_CCCL_HOST_DEVICE ForwardIterator +remove(thrust::execution_policy& exec, ForwardIterator first, ForwardIterator last, const T& value); + +template +_CCCL_HOST_DEVICE OutputIterator remove_copy( + thrust::execution_policy& exec, + InputIterator first, + InputIterator last, + OutputIterator result, + const T& value); + +template +_CCCL_HOST_DEVICE ForwardIterator +remove_if(thrust::execution_policy& exec, ForwardIterator first, ForwardIterator last, Predicate pred); + +template +_CCCL_HOST_DEVICE ForwardIterator remove_if( + thrust::execution_policy& exec, + ForwardIterator first, + ForwardIterator last, + InputIterator stencil, + Predicate pred); + +template +_CCCL_HOST_DEVICE OutputIterator remove_copy_if( + thrust::execution_policy& exec, + InputIterator first, + InputIterator last, + OutputIterator result, + Predicate pred); + +template +_CCCL_HOST_DEVICE OutputIterator remove_copy_if( + thrust::execution_policy& exec, + InputIterator1 first, + InputIterator1 last, + InputIterator2 stencil, + OutputIterator result, + Predicate pred); + +} // end namespace generic +} // end namespace detail +} // end namespace system +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/remove.inl b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/remove.inl new file mode 100644 index 0000000000000000000000000000000000000000..cf33d4369872a230a58ece6ca3188f5b973f8e4a --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/remove.inl @@ -0,0 +1,127 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include +#include +#include +#include +#include + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ + +template +_CCCL_HOST_DEVICE ForwardIterator +remove(thrust::execution_policy& exec, ForwardIterator first, ForwardIterator last, const T& value) +{ + thrust::detail::equal_to_value pred(value); + + // XXX consider using a placeholder here + return thrust::remove_if(exec, first, last, pred); +} // end remove() + +template +_CCCL_HOST_DEVICE OutputIterator remove_copy( + thrust::execution_policy& exec, + InputIterator first, + InputIterator last, + OutputIterator result, + const T& value) +{ + thrust::detail::equal_to_value pred(value); + + // XXX consider using a placeholder here + return thrust::remove_copy_if(exec, first, last, result, pred); +} // end remove_copy() + +template +_CCCL_HOST_DEVICE ForwardIterator +remove_if(thrust::execution_policy& exec, ForwardIterator first, ForwardIterator last, Predicate pred) +{ + using InputType = typename thrust::iterator_traits::value_type; + + // create temporary storage for an intermediate result + thrust::detail::temporary_array temp(exec, first, last); + + // remove into temp + return thrust::remove_copy_if(exec, temp.begin(), temp.end(), temp.begin(), first, pred); +} // end remove_if() + +template +_CCCL_HOST_DEVICE ForwardIterator remove_if( + thrust::execution_policy& exec, + ForwardIterator first, + ForwardIterator last, + InputIterator stencil, + Predicate pred) +{ + using InputType = typename thrust::iterator_traits::value_type; + + // create temporary storage for an intermediate result + thrust::detail::temporary_array temp(exec, first, last); + + // remove into temp + return thrust::remove_copy_if(exec, temp.begin(), temp.end(), stencil, first, pred); +} // end remove_if() + +template +_CCCL_HOST_DEVICE OutputIterator remove_copy_if( + thrust::execution_policy& exec, + InputIterator first, + InputIterator last, + OutputIterator result, + Predicate pred) +{ + return thrust::remove_copy_if(exec, first, last, first, result, pred); +} // end remove_copy_if() + +template +_CCCL_HOST_DEVICE OutputIterator remove_copy_if( + thrust::execution_policy& exec, + InputIterator1 first, + InputIterator1 last, + InputIterator2 stencil, + OutputIterator result, + Predicate pred) +{ + return thrust::copy_if(exec, first, last, stencil, result, thrust::not_fn(pred)); +} // end remove_copy_if() + +} // end namespace generic +} // end namespace detail +} // end namespace system +THRUST_NAMESPACE_END diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/replace.inl b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/replace.inl new file mode 100644 index 0000000000000000000000000000000000000000..5c09b58c3113031ba4badc970ce075e44debdecd --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/replace.inl @@ -0,0 +1,181 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include +#include +#include + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ +namespace detail +{ + +// this functor receives x, and returns a new_value if predicate(x) is true; otherwise, +// it returns x +template +struct new_value_if +{ + _CCCL_HOST_DEVICE new_value_if(Predicate p, NewType nv) + : pred(p) + , new_value(nv) + {} + + template + _CCCL_HOST_DEVICE OutputType operator()(const InputType& x) const + { + return pred(x) ? new_value : x; + } // end operator()() + + // this version of operator()() works like the previous but + // feeds its second argument to pred + template + _CCCL_HOST_DEVICE OutputType operator()(const InputType& x, const PredicateArgumentType& y) + { + return pred(y) ? new_value : x; + } // end operator()() + + Predicate pred; + NewType new_value; +}; // end new_value_if + +// this unary functor ignores its argument and returns a constant +template +struct constant_unary +{ + _CCCL_HOST_DEVICE constant_unary(T _c) + : c(_c) + {} + + template + _CCCL_HOST_DEVICE T operator()(U&) + { + return c; + } // end operator()() + + T c; +}; // end constant_unary + +} // namespace detail + +template +_CCCL_HOST_DEVICE OutputIterator replace_copy_if( + thrust::execution_policy& exec, + InputIterator first, + InputIterator last, + OutputIterator result, + Predicate pred, + const T& new_value) +{ + using OutputType = typename thrust::iterator_traits::value_type; + + detail::new_value_if op(pred, new_value); + return thrust::transform(exec, first, last, result, op); +} // end replace_copy_if() + +template +_CCCL_HOST_DEVICE OutputIterator replace_copy_if( + thrust::execution_policy& exec, + InputIterator1 first, + InputIterator1 last, + InputIterator2 stencil, + OutputIterator result, + Predicate pred, + const T& new_value) +{ + using OutputType = typename thrust::iterator_traits::value_type; + + detail::new_value_if op(pred, new_value); + return thrust::transform(exec, first, last, stencil, result, op); +} // end replace_copy_if() + +template +_CCCL_HOST_DEVICE OutputIterator replace_copy( + thrust::execution_policy& exec, + InputIterator first, + InputIterator last, + OutputIterator result, + const T& old_value, + const T& new_value) +{ + using thrust::placeholders::_1; + + return thrust::replace_copy_if(exec, first, last, result, _1 == old_value, new_value); +} // end replace_copy() + +template +_CCCL_HOST_DEVICE void replace_if( + thrust::execution_policy& exec, + ForwardIterator first, + ForwardIterator last, + Predicate pred, + const T& new_value) +{ + detail::constant_unary f(new_value); + thrust::transform_if(exec, first, last, first, first, f, pred); +} // end replace_if() + +template +_CCCL_HOST_DEVICE void replace_if( + thrust::execution_policy& exec, + ForwardIterator first, + ForwardIterator last, + InputIterator stencil, + Predicate pred, + const T& new_value) +{ + detail::constant_unary f(new_value); + thrust::transform_if(exec, first, last, stencil, first, f, pred); +} // end replace_if() + +template +_CCCL_HOST_DEVICE void +replace(thrust::execution_policy& exec, + ForwardIterator first, + ForwardIterator last, + const T& old_value, + const T& new_value) +{ + using thrust::placeholders::_1; + + return thrust::replace_if(exec, first, last, _1 == old_value, new_value); +} // end replace() + +} // end namespace generic +} // end namespace detail +} // end namespace system +THRUST_NAMESPACE_END diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/reverse.inl b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/reverse.inl new file mode 100644 index 0000000000000000000000000000000000000000..acc184152c302db342ec56ea2503640861753541 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/reverse.inl @@ -0,0 +1,72 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include +#include +#include +#include +#include +#include + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ + +template +_CCCL_HOST_DEVICE void +reverse(thrust::execution_policy& exec, BidirectionalIterator first, BidirectionalIterator last) +{ + using difference_type = typename thrust::iterator_difference::type; + + // find the midpoint of [first,last) + difference_type N = thrust::distance(first, last); + BidirectionalIterator mid(first); + thrust::advance(mid, N / 2); + + // swap elements of [first,mid) with [last - 1, mid) + thrust::swap_ranges(exec, first, mid, thrust::make_reverse_iterator(last)); +} // end reverse() + +template +_CCCL_HOST_DEVICE OutputIterator reverse_copy( + thrust::execution_policy& exec, + BidirectionalIterator first, + BidirectionalIterator last, + OutputIterator result) +{ + return thrust::copy(exec, thrust::make_reverse_iterator(last), thrust::make_reverse_iterator(first), result); +} // end reverse_copy() + +} // end namespace generic +} // end namespace detail +} // end namespace system +THRUST_NAMESPACE_END diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/scalar/binary_search.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/scalar/binary_search.h new file mode 100644 index 0000000000000000000000000000000000000000..5d4132af171d1bcdff172392d33ba2acafc79c1d --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/scalar/binary_search.h @@ -0,0 +1,78 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include + +THRUST_NAMESPACE_BEGIN + +namespace system +{ + +namespace detail +{ + +namespace generic +{ + +namespace scalar +{ + +template +_CCCL_HOST_DEVICE RandomAccessIterator +lower_bound_n(RandomAccessIterator first, Size n, const T& val, BinaryPredicate comp); + +template +_CCCL_HOST_DEVICE RandomAccessIterator +lower_bound(RandomAccessIterator first, RandomAccessIterator last, const T& val, BinaryPredicate comp); + +template +_CCCL_HOST_DEVICE RandomAccessIterator +upper_bound_n(RandomAccessIterator first, Size n, const T& val, BinaryPredicate comp); + +template +_CCCL_HOST_DEVICE RandomAccessIterator +upper_bound(RandomAccessIterator first, RandomAccessIterator last, const T& val, BinaryPredicate comp); + +template +_CCCL_HOST_DEVICE pair +equal_range(RandomAccessIterator first, RandomAccessIterator last, const T& val, BinaryPredicate comp); + +template +_CCCL_HOST_DEVICE bool +binary_search(RandomAccessIterator first, RandomAccessIterator last, const T& value, Compare comp); + +} // namespace scalar + +} // namespace generic + +} // namespace detail + +} // namespace system + +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/scalar/binary_search.inl b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/scalar/binary_search.inl new file mode 100644 index 0000000000000000000000000000000000000000..52e1a637f232a439df497b9aceab97364315f224 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/scalar/binary_search.inl @@ -0,0 +1,141 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include +#include + +THRUST_NAMESPACE_BEGIN + +namespace system +{ + +namespace detail +{ + +namespace generic +{ + +namespace scalar +{ + +template +_CCCL_HOST_DEVICE RandomAccessIterator +lower_bound_n(RandomAccessIterator first, Size n, const T& val, BinaryPredicate comp) +{ + // wrap comp + thrust::detail::wrapped_function wrapped_comp{comp}; + + Size start = 0, i; + while (start < n) + { + i = start + (n - start) / 2; // Overflow-safe variant of (a+b)/2 + if (wrapped_comp(first[i], val)) + { + start = i + 1; + } + else + { + n = i; + } + } // end while + + return first + start; +} + +// XXX generalize these upon implementation of scalar::distance & scalar::advance + +template +_CCCL_HOST_DEVICE RandomAccessIterator +lower_bound(RandomAccessIterator first, RandomAccessIterator last, const T& val, BinaryPredicate comp) +{ + typename thrust::iterator_difference::type n = last - first; + return lower_bound_n(first, n, val, comp); +} + +template +_CCCL_HOST_DEVICE RandomAccessIterator +upper_bound_n(RandomAccessIterator first, Size n, const T& val, BinaryPredicate comp) +{ + // wrap comp + thrust::detail::wrapped_function wrapped_comp{comp}; + + Size start = 0, i; + while (start < n) + { + i = start + (n - start) / 2; // Overflow-safe variant of (a+b)/2 + if (wrapped_comp(val, first[i])) + { + n = i; + } + else + { + start = i + 1; + } + } // end while + + return first + start; +} + +template +_CCCL_HOST_DEVICE RandomAccessIterator +upper_bound(RandomAccessIterator first, RandomAccessIterator last, const T& val, BinaryPredicate comp) +{ + typename thrust::iterator_difference::type n = last - first; + return upper_bound_n(first, n, val, comp); +} + +template +_CCCL_HOST_DEVICE pair +equal_range(RandomAccessIterator first, RandomAccessIterator last, const T& val, BinaryPredicate comp) +{ + RandomAccessIterator lb = thrust::system::detail::generic::scalar::lower_bound(first, last, val, comp); + return thrust::make_pair(lb, thrust::system::detail::generic::scalar::upper_bound(lb, last, val, comp)); +} + +template +_CCCL_HOST_DEVICE bool binary_search(RandomAccessIterator first, RandomAccessIterator last, const T& value, Compare comp) +{ + RandomAccessIterator iter = thrust::system::detail::generic::scalar::lower_bound(first, last, value, comp); + + // wrap comp + thrust::detail::wrapped_function wrapped_comp{comp}; + + return iter != last && !wrapped_comp(value, *iter); +} + +} // namespace scalar + +} // namespace generic + +} // namespace detail + +} // namespace system + +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/sequence.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/sequence.h new file mode 100644 index 0000000000000000000000000000000000000000..8d1495dbe76e6b26ccd2bef2dde409e18c2f7951 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/sequence.h @@ -0,0 +1,55 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ + +template +_CCCL_HOST_DEVICE void +sequence(thrust::execution_policy& exec, ForwardIterator first, ForwardIterator last); + +template +_CCCL_HOST_DEVICE void +sequence(thrust::execution_policy& exec, ForwardIterator first, ForwardIterator last, T init); + +template +_CCCL_HOST_DEVICE void +sequence(thrust::execution_policy& exec, ForwardIterator first, ForwardIterator last, T init, T step); + +} // end namespace generic +} // end namespace detail +} // end namespace system +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/set_operations.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/set_operations.h new file mode 100644 index 0000000000000000000000000000000000000000..f157caca93dfdfa1e60f7d480ded81f008794a2e --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/set_operations.h @@ -0,0 +1,288 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ + +template +_CCCL_HOST_DEVICE OutputIterator set_difference( + thrust::execution_policy& exec, + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2, + InputIterator2 last2, + OutputIterator result); + +// XXX it is an error to call this function; it has no implementation +template +_CCCL_HOST_DEVICE OutputIterator set_difference( + thrust::execution_policy& exec, + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2, + InputIterator2 last2, + OutputIterator result, + StrictWeakOrdering comp); + +template +_CCCL_HOST_DEVICE thrust::pair set_difference_by_key( + thrust::execution_policy& exec, + InputIterator1 keys_first1, + InputIterator1 keys_last1, + InputIterator2 keys_first2, + InputIterator2 keys_last2, + InputIterator3 values_first1, + InputIterator4 values_first2, + OutputIterator1 keys_result, + OutputIterator2 values_result); + +template +_CCCL_HOST_DEVICE thrust::pair set_difference_by_key( + thrust::execution_policy& exec, + InputIterator1 keys_first1, + InputIterator1 keys_last1, + InputIterator2 keys_first2, + InputIterator2 keys_last2, + InputIterator3 values_first1, + InputIterator4 values_first2, + OutputIterator1 keys_result, + OutputIterator2 values_result, + StrictWeakOrdering comp); + +template +_CCCL_HOST_DEVICE OutputIterator set_intersection( + thrust::execution_policy& system, + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2, + InputIterator2 last2, + OutputIterator result); + +// XXX it is an error to call this function; it has no implementation +template +_CCCL_HOST_DEVICE OutputIterator set_intersection( + thrust::execution_policy& system, + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2, + InputIterator2 last2, + OutputIterator result, + StrictWeakOrdering comp); + +template +_CCCL_HOST_DEVICE thrust::pair set_intersection_by_key( + thrust::execution_policy& system, + InputIterator1 keys_first1, + InputIterator1 keys_last1, + InputIterator2 keys_first2, + InputIterator2 keys_last2, + InputIterator3 values_first1, + OutputIterator1 keys_result, + OutputIterator2 values_result); + +template +_CCCL_HOST_DEVICE thrust::pair set_intersection_by_key( + thrust::execution_policy& system, + InputIterator1 keys_first1, + InputIterator1 keys_last1, + InputIterator2 keys_first2, + InputIterator2 keys_last2, + InputIterator3 values_first1, + OutputIterator1 keys_result, + OutputIterator2 values_result, + StrictWeakOrdering comp); + +template +_CCCL_HOST_DEVICE OutputIterator set_symmetric_difference( + thrust::execution_policy& system, + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2, + InputIterator2 last2, + OutputIterator result); + +// XXX it is an error to call this function; it has no implementation +template +_CCCL_HOST_DEVICE OutputIterator set_symmetric_difference( + thrust::execution_policy& system, + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2, + InputIterator2 last2, + OutputIterator result, + StrictWeakOrdering comp); + +template +_CCCL_HOST_DEVICE thrust::pair set_symmetric_difference_by_key( + thrust::execution_policy& system, + InputIterator1 keys_first1, + InputIterator1 keys_last1, + InputIterator2 keys_first2, + InputIterator2 keys_last2, + InputIterator3 values_first1, + InputIterator4 values_first2, + OutputIterator1 keys_result, + OutputIterator2 values_result); + +template +_CCCL_HOST_DEVICE thrust::pair set_symmetric_difference_by_key( + thrust::execution_policy& system, + InputIterator1 keys_first1, + InputIterator1 keys_last1, + InputIterator2 keys_first2, + InputIterator2 keys_last2, + InputIterator3 values_first1, + InputIterator4 values_first2, + OutputIterator1 keys_result, + OutputIterator2 values_result, + StrictWeakOrdering comp); + +template +_CCCL_HOST_DEVICE OutputIterator set_union( + thrust::execution_policy& system, + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2, + InputIterator2 last2, + OutputIterator result); + +// XXX it is an error to call this function; it has no implementation +template +_CCCL_HOST_DEVICE OutputIterator set_union( + thrust::execution_policy& system, + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2, + InputIterator2 last2, + OutputIterator result, + StrictWeakOrdering comp); + +template +_CCCL_HOST_DEVICE thrust::pair set_union_by_key( + thrust::execution_policy& system, + InputIterator1 keys_first1, + InputIterator1 keys_last1, + InputIterator2 keys_first2, + InputIterator2 keys_last2, + InputIterator3 values_first1, + InputIterator4 values_first2, + OutputIterator1 keys_result, + OutputIterator2 values_result); + +template +_CCCL_HOST_DEVICE thrust::pair set_union_by_key( + thrust::execution_policy& system, + InputIterator1 keys_first1, + InputIterator1 keys_last1, + InputIterator2 keys_first2, + InputIterator2 keys_last2, + InputIterator3 values_first1, + InputIterator4 values_first2, + OutputIterator1 keys_result, + OutputIterator2 values_result, + StrictWeakOrdering comp); + +} // end namespace generic +} // end namespace detail +} // end namespace system +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/set_operations.inl b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/set_operations.inl new file mode 100644 index 0000000000000000000000000000000000000000..45efd79001ec387e95d1f1a0fbc87cf91030193f --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/set_operations.inl @@ -0,0 +1,486 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include +#include +#include +#include +#include +#include + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ + +template +_CCCL_HOST_DEVICE OutputIterator set_difference( + thrust::execution_policy& exec, + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2, + InputIterator2 last2, + OutputIterator result) +{ + using value_type = typename thrust::iterator_value::type; + return thrust::set_difference(exec, first1, last1, first2, last2, result, thrust::less()); +} // end set_difference() + +template +_CCCL_HOST_DEVICE thrust::pair set_difference_by_key( + thrust::execution_policy& exec, + InputIterator1 keys_first1, + InputIterator1 keys_last1, + InputIterator2 keys_first2, + InputIterator2 keys_last2, + InputIterator3 values_first1, + InputIterator4 values_first2, + OutputIterator1 keys_result, + OutputIterator2 values_result) +{ + using value_type = typename thrust::iterator_value::type; + return thrust::set_difference_by_key( + exec, + keys_first1, + keys_last1, + keys_first2, + keys_last2, + values_first1, + values_first2, + keys_result, + values_result, + thrust::less()); +} // end set_difference_by_key() + +template +_CCCL_HOST_DEVICE thrust::pair set_difference_by_key( + thrust::execution_policy& exec, + InputIterator1 keys_first1, + InputIterator1 keys_last1, + InputIterator2 keys_first2, + InputIterator2 keys_last2, + InputIterator3 values_first1, + InputIterator4 values_first2, + OutputIterator1 keys_result, + OutputIterator2 values_result, + StrictWeakOrdering comp) +{ + using iterator_tuple1 = thrust::tuple; + using iterator_tuple2 = thrust::tuple; + using iterator_tuple3 = thrust::tuple; + + using zip_iterator1 = thrust::zip_iterator; + using zip_iterator2 = thrust::zip_iterator; + using zip_iterator3 = thrust::zip_iterator; + + zip_iterator1 zipped_first1 = thrust::make_zip_iterator(thrust::make_tuple(keys_first1, values_first1)); + zip_iterator1 zipped_last1 = thrust::make_zip_iterator(thrust::make_tuple(keys_last1, values_first1)); + + zip_iterator2 zipped_first2 = thrust::make_zip_iterator(thrust::make_tuple(keys_first2, values_first2)); + zip_iterator2 zipped_last2 = thrust::make_zip_iterator(thrust::make_tuple(keys_last2, values_first2)); + + zip_iterator3 zipped_result = thrust::make_zip_iterator(thrust::make_tuple(keys_result, values_result)); + + thrust::detail::compare_first comp_first(comp); + + iterator_tuple3 result = + thrust::set_difference(exec, zipped_first1, zipped_last1, zipped_first2, zipped_last2, zipped_result, comp_first) + .get_iterator_tuple(); + + return thrust::make_pair(thrust::get<0>(result), thrust::get<1>(result)); +} // end set_difference_by_key() + +template +_CCCL_HOST_DEVICE OutputIterator set_intersection( + thrust::execution_policy& exec, + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2, + InputIterator2 last2, + OutputIterator result) +{ + using value_type = typename thrust::iterator_value::type; + return thrust::set_intersection(exec, first1, last1, first2, last2, result, thrust::less()); +} // end set_intersection() + +template +_CCCL_HOST_DEVICE thrust::pair set_intersection_by_key( + thrust::execution_policy& exec, + InputIterator1 keys_first1, + InputIterator1 keys_last1, + InputIterator2 keys_first2, + InputIterator2 keys_last2, + InputIterator3 values_first1, + OutputIterator1 keys_result, + OutputIterator2 values_result) +{ + using value_type = typename thrust::iterator_value::type; + return thrust::set_intersection_by_key( + exec, + keys_first1, + keys_last1, + keys_first2, + keys_last2, + values_first1, + keys_result, + values_result, + thrust::less()); +} // end set_intersection_by_key() + +template +_CCCL_HOST_DEVICE thrust::pair set_intersection_by_key( + thrust::execution_policy& exec, + InputIterator1 keys_first1, + InputIterator1 keys_last1, + InputIterator2 keys_first2, + InputIterator2 keys_last2, + InputIterator3 values_first1, + OutputIterator1 keys_result, + OutputIterator2 values_result, + StrictWeakOrdering comp) +{ + using value_type1 = typename thrust::iterator_value::type; + using constant_iterator = thrust::constant_iterator; + + using iterator_tuple1 = thrust::tuple; + using iterator_tuple2 = thrust::tuple; + using iterator_tuple3 = thrust::tuple; + + using zip_iterator1 = thrust::zip_iterator; + using zip_iterator2 = thrust::zip_iterator; + using zip_iterator3 = thrust::zip_iterator; + + // fabricate a values_first2 by repeating a default-constructed value_type1 + // XXX assumes value_type1 is default-constructible + constant_iterator values_first2 = thrust::make_constant_iterator(value_type1()); + + zip_iterator1 zipped_first1 = thrust::make_zip_iterator(thrust::make_tuple(keys_first1, values_first1)); + zip_iterator1 zipped_last1 = thrust::make_zip_iterator(thrust::make_tuple(keys_last1, values_first1)); + + zip_iterator2 zipped_first2 = thrust::make_zip_iterator(thrust::make_tuple(keys_first2, values_first2)); + zip_iterator2 zipped_last2 = thrust::make_zip_iterator(thrust::make_tuple(keys_last2, values_first2)); + + zip_iterator3 zipped_result = thrust::make_zip_iterator(thrust::make_tuple(keys_result, values_result)); + + thrust::detail::compare_first comp_first(comp); + + iterator_tuple3 result = + thrust::set_intersection(exec, zipped_first1, zipped_last1, zipped_first2, zipped_last2, zipped_result, comp_first) + .get_iterator_tuple(); + + return thrust::make_pair(thrust::get<0>(result), thrust::get<1>(result)); +} // end set_intersection_by_key() + +template +_CCCL_HOST_DEVICE OutputIterator set_symmetric_difference( + thrust::execution_policy& exec, + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2, + InputIterator2 last2, + OutputIterator result) +{ + using value_type = typename thrust::iterator_value::type; + return thrust::set_symmetric_difference(exec, first1, last1, first2, last2, result, thrust::less()); +} // end set_symmetric_difference() + +template +_CCCL_HOST_DEVICE thrust::pair set_symmetric_difference_by_key( + thrust::execution_policy& exec, + InputIterator1 keys_first1, + InputIterator1 keys_last1, + InputIterator2 keys_first2, + InputIterator2 keys_last2, + InputIterator3 values_first1, + InputIterator4 values_first2, + OutputIterator1 keys_result, + OutputIterator2 values_result) +{ + using value_type = typename thrust::iterator_value::type; + return thrust::set_symmetric_difference_by_key( + exec, + keys_first1, + keys_last1, + keys_first2, + keys_last2, + values_first1, + values_first2, + keys_result, + values_result, + thrust::less()); +} // end set_symmetric_difference_by_key() + +template +_CCCL_HOST_DEVICE thrust::pair set_symmetric_difference_by_key( + thrust::execution_policy& exec, + InputIterator1 keys_first1, + InputIterator1 keys_last1, + InputIterator2 keys_first2, + InputIterator2 keys_last2, + InputIterator3 values_first1, + InputIterator4 values_first2, + OutputIterator1 keys_result, + OutputIterator2 values_result, + StrictWeakOrdering comp) +{ + using iterator_tuple1 = thrust::tuple; + using iterator_tuple2 = thrust::tuple; + using iterator_tuple3 = thrust::tuple; + + using zip_iterator1 = thrust::zip_iterator; + using zip_iterator2 = thrust::zip_iterator; + using zip_iterator3 = thrust::zip_iterator; + + zip_iterator1 zipped_first1 = thrust::make_zip_iterator(thrust::make_tuple(keys_first1, values_first1)); + zip_iterator1 zipped_last1 = thrust::make_zip_iterator(thrust::make_tuple(keys_last1, values_first1)); + + zip_iterator2 zipped_first2 = thrust::make_zip_iterator(thrust::make_tuple(keys_first2, values_first2)); + zip_iterator2 zipped_last2 = thrust::make_zip_iterator(thrust::make_tuple(keys_last2, values_first2)); + + zip_iterator3 zipped_result = thrust::make_zip_iterator(thrust::make_tuple(keys_result, values_result)); + + thrust::detail::compare_first comp_first(comp); + + iterator_tuple3 result = + thrust::set_symmetric_difference( + exec, zipped_first1, zipped_last1, zipped_first2, zipped_last2, zipped_result, comp_first) + .get_iterator_tuple(); + + return thrust::make_pair(thrust::get<0>(result), thrust::get<1>(result)); +} // end set_symmetric_difference_by_key() + +template +_CCCL_HOST_DEVICE OutputIterator set_union( + thrust::execution_policy& exec, + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2, + InputIterator2 last2, + OutputIterator result) +{ + using value_type = typename thrust::iterator_value::type; + return thrust::set_union(exec, first1, last1, first2, last2, result, thrust::less()); +} // end set_union() + +template +_CCCL_HOST_DEVICE thrust::pair set_union_by_key( + thrust::execution_policy& exec, + InputIterator1 keys_first1, + InputIterator1 keys_last1, + InputIterator2 keys_first2, + InputIterator2 keys_last2, + InputIterator3 values_first1, + InputIterator4 values_first2, + OutputIterator1 keys_result, + OutputIterator2 values_result) +{ + using value_type = typename thrust::iterator_value::type; + return thrust::set_union_by_key( + exec, + keys_first1, + keys_last1, + keys_first2, + keys_last2, + values_first1, + values_first2, + keys_result, + values_result, + thrust::less()); +} // end set_union_by_key() + +template +_CCCL_HOST_DEVICE thrust::pair set_union_by_key( + thrust::execution_policy& exec, + InputIterator1 keys_first1, + InputIterator1 keys_last1, + InputIterator2 keys_first2, + InputIterator2 keys_last2, + InputIterator3 values_first1, + InputIterator4 values_first2, + OutputIterator1 keys_result, + OutputIterator2 values_result, + StrictWeakOrdering comp) +{ + using iterator_tuple1 = thrust::tuple; + using iterator_tuple2 = thrust::tuple; + using iterator_tuple3 = thrust::tuple; + + using zip_iterator1 = thrust::zip_iterator; + using zip_iterator2 = thrust::zip_iterator; + using zip_iterator3 = thrust::zip_iterator; + + zip_iterator1 zipped_first1 = thrust::make_zip_iterator(thrust::make_tuple(keys_first1, values_first1)); + zip_iterator1 zipped_last1 = thrust::make_zip_iterator(thrust::make_tuple(keys_last1, values_first1)); + + zip_iterator2 zipped_first2 = thrust::make_zip_iterator(thrust::make_tuple(keys_first2, values_first2)); + zip_iterator2 zipped_last2 = thrust::make_zip_iterator(thrust::make_tuple(keys_last2, values_first2)); + + zip_iterator3 zipped_result = thrust::make_zip_iterator(thrust::make_tuple(keys_result, values_result)); + + thrust::detail::compare_first comp_first(comp); + + iterator_tuple3 result = + thrust::set_union(exec, zipped_first1, zipped_last1, zipped_first2, zipped_last2, zipped_result, comp_first) + .get_iterator_tuple(); + + return thrust::make_pair(thrust::get<0>(result), thrust::get<1>(result)); +} // end set_union_by_key() + +template +_CCCL_HOST_DEVICE OutputIterator set_difference( + thrust::execution_policy&, + InputIterator1, + InputIterator1, + InputIterator2, + InputIterator2, + OutputIterator result, + StrictWeakOrdering) +{ + THRUST_STATIC_ASSERT_MSG((thrust::detail::depend_on_instantiation::value), + "unimplemented for this system"); + return result; +} // end set_difference() + +template +_CCCL_HOST_DEVICE OutputIterator set_intersection( + thrust::execution_policy&, + InputIterator1, + InputIterator1, + InputIterator2, + InputIterator2, + OutputIterator result, + StrictWeakOrdering) +{ + THRUST_STATIC_ASSERT_MSG((thrust::detail::depend_on_instantiation::value), + "unimplemented for this system"); + return result; +} // end set_intersection() + +template +_CCCL_HOST_DEVICE OutputIterator set_symmetric_difference( + thrust::execution_policy&, + InputIterator1, + InputIterator1, + InputIterator2, + InputIterator2, + OutputIterator result, + StrictWeakOrdering) +{ + THRUST_STATIC_ASSERT_MSG((thrust::detail::depend_on_instantiation::value), + "unimplemented for this system"); + return result; +} // end set_symmetric_difference() + +template +_CCCL_HOST_DEVICE OutputIterator set_union( + thrust::execution_policy&, + InputIterator1, + InputIterator1, + InputIterator2, + InputIterator2, + OutputIterator result, + StrictWeakOrdering) +{ + THRUST_STATIC_ASSERT_MSG((thrust::detail::depend_on_instantiation::value), + "unimplemented for this system"); + return result; +} // end set_union() + +} // end namespace generic +} // end namespace detail +} // end namespace system +THRUST_NAMESPACE_END diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/shuffle.inl b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/shuffle.inl new file mode 100644 index 0000000000000000000000000000000000000000..16a097407b04a0389178062cd0769b431e0d1f92 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/shuffle.inl @@ -0,0 +1,213 @@ +/* + * Copyright 2008-20120 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ + +// An implementation of a Feistel cipher for operating on 64 bit keys +class feistel_bijection +{ + struct round_state + { + std::uint32_t left; + std::uint32_t right; + }; + +public: + template + _CCCL_HOST_DEVICE feistel_bijection(std::uint64_t m, URBG&& g) + { + std::uint64_t total_bits = get_cipher_bits(m); + // Half bits rounded down + left_side_bits = total_bits / 2; + left_side_mask = (1ull << left_side_bits) - 1; + // Half the bits rounded up + right_side_bits = total_bits - left_side_bits; + right_side_mask = (1ull << right_side_bits) - 1; + + for (std::uint32_t i = 0; i < num_rounds; i++) + { + key[i] = g(); + } + } + + _CCCL_HOST_DEVICE std::uint64_t nearest_power_of_two() const + { + return 1ull << (left_side_bits + right_side_bits); + } + + _CCCL_HOST_DEVICE std::uint64_t operator()(const std::uint64_t val) const + { + std::uint32_t state[2] = {static_cast(val >> right_side_bits), + static_cast(val & right_side_mask)}; + for (std::uint32_t i = 0; i < num_rounds; i++) + { + std::uint32_t hi, lo; + constexpr std::uint64_t M0 = UINT64_C(0xD2B74407B1CE6E93); + mulhilo(M0, state[0], hi, lo); + lo = (lo << (right_side_bits - left_side_bits)) | state[1] >> left_side_bits; + state[0] = ((hi ^ key[i]) ^ state[1]) & left_side_mask; + state[1] = lo & right_side_mask; + } + // Combine the left and right sides together to get result + return (static_cast(state[0]) << right_side_bits) | static_cast(state[1]); + } + +private: + // Perform 64 bit multiplication and save result in two 32 bit int + static _CCCL_HOST_DEVICE void mulhilo(std::uint64_t a, std::uint64_t b, std::uint32_t& hi, std::uint32_t& lo) + { + std::uint64_t product = a * b; + hi = static_cast(product >> 32); + lo = static_cast(product); + } + + // Find the nearest power of two + static _CCCL_HOST_DEVICE std::uint64_t get_cipher_bits(std::uint64_t m) + { + if (m <= 16) + { + return 4; + } + std::uint64_t i = 0; + m--; + while (m != 0) + { + i++; + m >>= 1; + } + return i; + } + + static constexpr std::uint32_t num_rounds = 24; + std::uint64_t right_side_bits; + std::uint64_t left_side_bits; + std::uint64_t right_side_mask; + std::uint64_t left_side_mask; + std::uint32_t key[num_rounds]; +}; + +struct key_flag_tuple +{ + std::uint64_t key; + std::uint64_t flag; +}; + +// scan only flags +struct key_flag_scan_op +{ + _CCCL_HOST_DEVICE key_flag_tuple operator()(const key_flag_tuple& a, const key_flag_tuple& b) + { + return {b.key, a.flag + b.flag}; + } +}; + +struct construct_key_flag_op +{ + std::uint64_t m; + feistel_bijection bijection; + _CCCL_HOST_DEVICE construct_key_flag_op(std::uint64_t m, feistel_bijection bijection) + : m(m) + , bijection(bijection) + {} + _CCCL_HOST_DEVICE key_flag_tuple operator()(std::uint64_t idx) + { + auto gather_key = bijection(idx); + return key_flag_tuple{gather_key, (gather_key < m) ? 1ull : 0ull}; + } +}; + +template +struct write_output_op +{ + std::uint64_t m; + InputIterT in; + OutputIterT out; + // flag contains inclusive scan of valid keys + // perform gather using valid keys + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE std::size_t operator()(key_flag_tuple x) + { + if (x.key < m) + { + // -1 because inclusive scan + out[x.flag - 1] = in[x.key]; + } + return 0; // Discarded + } +}; + +template +_CCCL_HOST_DEVICE void +shuffle(thrust::execution_policy& exec, RandomIterator first, RandomIterator last, URBG&& g) +{ + using InputType = typename thrust::iterator_value_t; + + // copy input to temp buffer + thrust::detail::temporary_array temp(exec, first, last); + thrust::shuffle_copy(exec, temp.begin(), temp.end(), first, g); +} + +template +_CCCL_HOST_DEVICE void shuffle_copy( + thrust::execution_policy& exec, + RandomIterator first, + RandomIterator last, + OutputIterator result, + URBG&& g) +{ + // m is the length of the input + // we have an available bijection of length n via a feistel cipher + std::size_t m = last - first; + feistel_bijection bijection(m, g); + std::uint64_t n = bijection.nearest_power_of_two(); + + // perform stream compaction over length n bijection to get length m + // pseudorandom bijection over the original input + thrust::counting_iterator indices(0); + thrust::transform_iterator key_flag_it( + indices, construct_key_flag_op(m, bijection)); + write_output_op write_functor{m, first, result}; + auto gather_output_it = + thrust::make_transform_output_iterator(thrust::discard_iterator(), write_functor); + // the feistel_bijection outputs a stream of permuted indices in range [0,n) + // flag each value < m and compact it, so we have a set of permuted indices in + // range [0,m) each thread gathers an input element according to its + // pseudorandom permuted index + thrust::inclusive_scan(exec, key_flag_it, key_flag_it + n, gather_output_it, key_flag_scan_op()); +} + +} // end namespace generic +} // end namespace detail +} // end namespace system +THRUST_NAMESPACE_END diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/swap_ranges.inl b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/swap_ranges.inl new file mode 100644 index 0000000000000000000000000000000000000000..228ad5d3dfc4452caf9dd9dd5ac8b03f1c06724e --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/swap_ranges.inl @@ -0,0 +1,82 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include +#include +#include +#include + +#include + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ +namespace detail +{ + +// XXX define this here rather than in internal_functional.h +// to avoid circular dependence between swap.h & internal_functional.h +struct swap_pair_elements +{ + template + _CCCL_HOST_DEVICE void operator()(Tuple t) + { + // use unqualified swap to allow ADL to catch any user-defined swap + using ::cuda::std::swap; + swap(thrust::get<0>(t), thrust::get<1>(t)); + } +}; // end swap_pair_elements + +} // namespace detail + +template +_CCCL_HOST_DEVICE ForwardIterator2 swap_ranges( + thrust::execution_policy& exec, + ForwardIterator1 first1, + ForwardIterator1 last1, + ForwardIterator2 first2) +{ + using IteratorTuple = thrust::tuple; + using ZipIterator = thrust::zip_iterator; + + ZipIterator result = thrust::for_each( + exec, + thrust::make_zip_iterator(thrust::make_tuple(first1, first2)), + thrust::make_zip_iterator(thrust::make_tuple(last1, first2)), + detail::swap_pair_elements()); + return thrust::get<1>(result.get_iterator_tuple()); +} // end swap_ranges() + +} // namespace generic +} // namespace detail +} // namespace system +THRUST_NAMESPACE_END diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/tabulate.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/tabulate.h new file mode 100644 index 0000000000000000000000000000000000000000..d7e4daf34ecda8091025507aa60d5fdf20b51427 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/tabulate.h @@ -0,0 +1,47 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ + +template +_CCCL_HOST_DEVICE void tabulate( + thrust::execution_policy& exec, ForwardIterator first, ForwardIterator last, UnaryOperation unary_op); + +} // end namespace generic +} // end namespace detail +} // end namespace system +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/tag.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/tag.h new file mode 100644 index 0000000000000000000000000000000000000000..f59c9636fc4faae722b2399992e2b109e0216ac6 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/tag.h @@ -0,0 +1,53 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file generic/tag.h + * \brief Implementation of the generic backend's tag. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ + +// tag exists only to make the generic entry points the least priority match +// during ADL. tag should not be derived from and is constructible from anything +struct tag +{ + template + _CCCL_HOST_DEVICE inline tag(const T&) + {} +}; + +} // namespace generic +} // namespace detail +} // namespace system +THRUST_NAMESPACE_END diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/temporary_buffer.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/temporary_buffer.h new file mode 100644 index 0000000000000000000000000000000000000000..3e83c10614584ffc3c91c8ac613acba10c12e213 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/temporary_buffer.h @@ -0,0 +1,60 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include +#include + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ + +template +_CCCL_HOST_DEVICE +thrust::pair, typename thrust::pointer::difference_type> +get_temporary_buffer(thrust::execution_policy& exec, + typename thrust::pointer::difference_type n); + +_CCCL_EXEC_CHECK_DISABLE +template +_CCCL_HOST_DEVICE void +return_temporary_buffer(thrust::execution_policy& exec, Pointer p, std::ptrdiff_t n); + +_CCCL_EXEC_CHECK_DISABLE +template +_CCCL_HOST_DEVICE void return_temporary_buffer(thrust::execution_policy& exec, Pointer p); + +} // namespace generic +} // namespace detail +} // namespace system +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/temporary_buffer.inl b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/temporary_buffer.inl new file mode 100644 index 0000000000000000000000000000000000000000..78553b83ae54797b5c84dfab4f3c413d7ed71abd --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/temporary_buffer.inl @@ -0,0 +1,88 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include +#include +#include + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ + +template +_CCCL_HOST_DEVICE +thrust::pair, typename thrust::pointer::difference_type> +get_temporary_buffer(thrust::execution_policy& exec, + typename thrust::pointer::difference_type n) +{ + thrust::pointer ptr = thrust::malloc(exec, n); + + // check for a failed malloc + if (!ptr.get()) + { + n = 0; + } // end if + + return thrust::make_pair(ptr, n); +} // end get_temporary_buffer() + +_CCCL_EXEC_CHECK_DISABLE +template +_CCCL_HOST_DEVICE void return_temporary_buffer(thrust::execution_policy& exec, Pointer p, std::ptrdiff_t) +{ + // If we are here, no user customization of the three-argument signature with + // a size parameter of `return_temporary_buffer` was found. There may be an + // old two-argument signature `return_temporary_buffer` though, so we make + // another ADL call to try and find one. + // + // The interface layer downcast and then did ADL dispatch - there were no + // matches for DerivedPolicy (aka no one customized the three-argument + // signature), so this overload got found an implicit upcast to + // `execution_policy` was done. Now, we're looking for a + // customization of the two-argument signature so we need to downcast again. + return_temporary_buffer(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), p); +} // end return_temporary_buffer() + +_CCCL_EXEC_CHECK_DISABLE +template +_CCCL_HOST_DEVICE void return_temporary_buffer(thrust::execution_policy& exec, Pointer p) +{ + // If we are here, no user customization of either the old two-argument + // signature or the new three-argument signature with a size parameter of + // `return_temporary_buffer` was found. + thrust::free(exec, p); +} // end return_temporary_buffer() + +} // namespace generic +} // namespace detail +} // namespace system +THRUST_NAMESPACE_END diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/transform_scan.inl b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/transform_scan.inl new file mode 100644 index 0000000000000000000000000000000000000000..fbd5f24b21ea5861d6d57f08913574ecc257df75 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/transform_scan.inl @@ -0,0 +1,120 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include +#include +#include +#include + +#include + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ + +template +_CCCL_HOST_DEVICE OutputIterator transform_inclusive_scan( + thrust::execution_policy& exec, + InputIterator first, + InputIterator last, + OutputIterator result, + UnaryFunction unary_op, + BinaryFunction binary_op) +{ + // Use the input iterator's value type per https://wg21.link/P0571 + using InputType = typename thrust::iterator_value::type; + using ResultType = thrust::detail::invoke_result_t; + using ValueType = ::cuda::std::remove_cvref_t; + + thrust::transform_iterator _first(first, unary_op); + thrust::transform_iterator _last(last, unary_op); + + return thrust::inclusive_scan(exec, _first, _last, result, binary_op); +} // end transform_inclusive_scan() + +template +_CCCL_HOST_DEVICE OutputIterator transform_inclusive_scan( + thrust::execution_policy& exec, + InputIterator first, + InputIterator last, + OutputIterator result, + UnaryFunction unary_op, + InitialValueType init, + BinaryFunction binary_op) +{ + using InputType = typename thrust::iterator_value::type; + using ResultType = thrust::detail::invoke_result_t; + using ValueType = ::cuda::std::remove_cvref_t; + + thrust::transform_iterator _first(first, unary_op); + thrust::transform_iterator _last(last, unary_op); + + return thrust::inclusive_scan(exec, _first, _last, result, init, binary_op); +} // end transform_inclusive_scan() + +template +_CCCL_HOST_DEVICE OutputIterator transform_exclusive_scan( + thrust::execution_policy& exec, + InputIterator first, + InputIterator last, + OutputIterator result, + UnaryFunction unary_op, + InitialValueType init, + AssociativeOperator binary_op) +{ + // Use the initial value type per https://wg21.link/P0571 + using ValueType = ::cuda::std::remove_cvref_t; + + thrust::transform_iterator _first(first, unary_op); + thrust::transform_iterator _last(last, unary_op); + + return thrust::exclusive_scan(exec, _first, _last, result, init, binary_op); +} // end transform_exclusive_scan() + +} // end namespace generic +} // end namespace detail +} // end namespace system +THRUST_NAMESPACE_END diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/uninitialized_copy.inl b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/uninitialized_copy.inl new file mode 100644 index 0000000000000000000000000000000000000000..931d023e2dc5b46490d8d4f82004104749502052 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/uninitialized_copy.inl @@ -0,0 +1,172 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include +#include +#include +#include +#include + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ +namespace detail +{ + +template +struct uninitialized_copy_functor +{ + template + _CCCL_HOST_DEVICE void operator()(Tuple t) + { + const InputType& in = thrust::get<0>(t); + OutputType& out = thrust::get<1>(t); + + ::new (static_cast(&out)) OutputType(in); + } // end operator()() +}; // end uninitialized_copy_functor + +// non-trivial copy constructor path +template +_CCCL_HOST_DEVICE ForwardIterator uninitialized_copy( + thrust::execution_policy& exec, + InputIterator first, + InputIterator last, + ForwardIterator result, + thrust::detail::false_type) // ::cuda::std::is_trivially_copy_constructible +{ + // zip up the iterators + using IteratorTuple = thrust::tuple; + using ZipIterator = thrust::zip_iterator; + + ZipIterator begin = thrust::make_zip_iterator(thrust::make_tuple(first, result)); + ZipIterator end = begin; + + // get a zip_iterator pointing to the end + const typename thrust::iterator_difference::type n = thrust::distance(first, last); + thrust::advance(end, n); + + // create a functor + using InputType = typename iterator_traits::value_type; + using OutputType = typename iterator_traits::value_type; + + detail::uninitialized_copy_functor f; + + // do the for_each + thrust::for_each(exec, begin, end, f); + + // return the end of the output range + return thrust::get<1>(end.get_iterator_tuple()); +} // end uninitialized_copy() + +// trivial copy constructor path +template +_CCCL_HOST_DEVICE ForwardIterator uninitialized_copy( + thrust::execution_policy& exec, + InputIterator first, + InputIterator last, + ForwardIterator result, + thrust::detail::true_type) // ::cuda::std::is_trivially_copy_constructible +{ + return thrust::copy(exec, first, last, result); +} // end uninitialized_copy() + +// non-trivial copy constructor path +template +_CCCL_HOST_DEVICE ForwardIterator uninitialized_copy_n( + thrust::execution_policy& exec, + InputIterator first, + Size n, + ForwardIterator result, + thrust::detail::false_type) // ::cuda::std::is_trivially_copy_constructible +{ + // zip up the iterators + using IteratorTuple = thrust::tuple; + using ZipIterator = thrust::zip_iterator; + + ZipIterator zipped_first = thrust::make_zip_iterator(thrust::make_tuple(first, result)); + + // create a functor + using InputType = typename iterator_traits::value_type; + using OutputType = typename iterator_traits::value_type; + + detail::uninitialized_copy_functor f; + + // do the for_each_n + ZipIterator zipped_last = thrust::for_each_n(exec, zipped_first, n, f); + + // return the end of the output range + return thrust::get<1>(zipped_last.get_iterator_tuple()); +} // end uninitialized_copy_n() + +// trivial copy constructor path +template +_CCCL_HOST_DEVICE ForwardIterator uninitialized_copy_n( + thrust::execution_policy& exec, + InputIterator first, + Size n, + ForwardIterator result, + thrust::detail::true_type) // ::cuda::std::is_trivially_copy_constructible +{ + return thrust::copy_n(exec, first, n, result); +} // end uninitialized_copy_n() + +} // namespace detail + +template +_CCCL_HOST_DEVICE ForwardIterator uninitialized_copy( + thrust::execution_policy& exec, InputIterator first, InputIterator last, ForwardIterator result) +{ + using ResultType = typename iterator_traits::value_type; + + using ResultTypeHasTrivialCopyConstructor = typename ::cuda::std::is_trivially_copy_constructible::type; + + return thrust::system::detail::generic::detail::uninitialized_copy( + exec, first, last, result, ResultTypeHasTrivialCopyConstructor()); +} // end uninitialized_copy() + +template +_CCCL_HOST_DEVICE ForwardIterator uninitialized_copy_n( + thrust::execution_policy& exec, InputIterator first, Size n, ForwardIterator result) +{ + using ResultType = typename iterator_traits::value_type; + + using ResultTypeHasTrivialCopyConstructor = typename ::cuda::std::is_trivially_copy_constructible::type; + + return thrust::system::detail::generic::detail::uninitialized_copy_n( + exec, first, n, result, ResultTypeHasTrivialCopyConstructor()); +} // end uninitialized_copy_n() + +} // end namespace generic +} // end namespace detail +} // end namespace system +THRUST_NAMESPACE_END diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/uninitialized_fill.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/uninitialized_fill.h new file mode 100644 index 0000000000000000000000000000000000000000..de71693267bbbae86063ac0849a5edb4d3ffd590 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/uninitialized_fill.h @@ -0,0 +1,51 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ + +template +_CCCL_HOST_DEVICE void uninitialized_fill( + thrust::execution_policy& exec, ForwardIterator first, ForwardIterator last, const T& x); + +template +_CCCL_HOST_DEVICE ForwardIterator +uninitialized_fill_n(thrust::execution_policy& exec, ForwardIterator first, Size n, const T& x); + +} // end namespace generic +} // end namespace detail +} // end namespace system +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/unique.inl b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/unique.inl new file mode 100644 index 0000000000000000000000000000000000000000..c43581f95f0b86cdcf90001ea765e1843b4904a4 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/unique.inl @@ -0,0 +1,119 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ + +template +_CCCL_HOST_DEVICE ForwardIterator +unique(thrust::execution_policy& exec, ForwardIterator first, ForwardIterator last) +{ + using InputType = typename thrust::iterator_traits::value_type; + + return thrust::unique(exec, first, last, thrust::equal_to()); +} // end unique() + +template +_CCCL_HOST_DEVICE ForwardIterator unique( + thrust::execution_policy& exec, + ForwardIterator first, + ForwardIterator last, + BinaryPredicate binary_pred) +{ + using InputType = typename thrust::iterator_traits::value_type; + + thrust::detail::temporary_array input(exec, first, last); + + return thrust::unique_copy(exec, input.begin(), input.end(), first, binary_pred); +} // end unique() + +template +_CCCL_HOST_DEVICE OutputIterator unique_copy( + thrust::execution_policy& exec, InputIterator first, InputIterator last, OutputIterator output) +{ + using value_type = typename thrust::iterator_value::type; + return thrust::unique_copy(exec, first, last, output, thrust::equal_to()); +} // end unique_copy() + +template +_CCCL_HOST_DEVICE OutputIterator unique_copy( + thrust::execution_policy& exec, + InputIterator first, + InputIterator last, + OutputIterator output, + BinaryPredicate binary_pred) +{ + thrust::detail::head_flags stencil(first, last, binary_pred); + + using namespace thrust::placeholders; + + return thrust::copy_if(exec, first, last, stencil.begin(), output, _1); +} // end unique_copy() + +template +_CCCL_HOST_DEVICE typename thrust::iterator_traits::difference_type unique_count( + thrust::execution_policy& exec, + ForwardIterator first, + ForwardIterator last, + BinaryPredicate binary_pred) +{ + thrust::detail::head_flags stencil(first, last, binary_pred); + + using namespace thrust::placeholders; + + return thrust::count_if(exec, stencil.begin(), stencil.end(), _1); +} // end unique_copy() + +template +_CCCL_HOST_DEVICE typename thrust::iterator_traits::difference_type +unique_count(thrust::execution_policy& exec, ForwardIterator first, ForwardIterator last) +{ + using value_type = typename thrust::iterator_value::type; + return thrust::unique_count(exec, first, last, thrust::equal_to()); +} // end unique_copy() + +} // end namespace generic +} // end namespace detail +} // end namespace system +THRUST_NAMESPACE_END diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/unique_by_key.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/unique_by_key.h new file mode 100644 index 0000000000000000000000000000000000000000..21689dfc6655bccf690e0e9a9a66ae39eb8b61d0 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/unique_by_key.h @@ -0,0 +1,87 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ + +template +_CCCL_HOST_DEVICE thrust::pair unique_by_key( + thrust::execution_policy& exec, + ForwardIterator1 keys_first, + ForwardIterator1 keys_last, + ForwardIterator2 values_first); + +template +_CCCL_HOST_DEVICE thrust::pair unique_by_key( + thrust::execution_policy& exec, + ForwardIterator1 keys_first, + ForwardIterator1 keys_last, + ForwardIterator2 values_first, + BinaryPredicate binary_pred); + +template +_CCCL_HOST_DEVICE thrust::pair unique_by_key_copy( + thrust::execution_policy& exec, + InputIterator1 keys_first, + InputIterator1 keys_last, + InputIterator2 values_first, + OutputIterator1 keys_output, + OutputIterator2 values_output); + +template +_CCCL_HOST_DEVICE thrust::pair unique_by_key_copy( + thrust::execution_policy& exec, + InputIterator1 keys_first, + InputIterator1 keys_last, + InputIterator2 values_first, + OutputIterator1 keys_output, + OutputIterator2 values_output, + BinaryPredicate binary_pred); + +} // end namespace generic +} // end namespace detail +} // end namespace system +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/unique_by_key.inl b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/unique_by_key.inl new file mode 100644 index 0000000000000000000000000000000000000000..2126a9e34fb460a967bfecbc18f3451786ceef02 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system/detail/generic/unique_by_key.inl @@ -0,0 +1,133 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +THRUST_NAMESPACE_BEGIN +namespace system +{ +namespace detail +{ +namespace generic +{ + +template +_CCCL_HOST_DEVICE thrust::pair unique_by_key( + thrust::execution_policy& exec, + ForwardIterator1 keys_first, + ForwardIterator1 keys_last, + ForwardIterator2 values_first) +{ + using KeyType = typename thrust::iterator_traits::value_type; + return thrust::unique_by_key(exec, keys_first, keys_last, values_first, thrust::equal_to()); +} // end unique_by_key() + +template +_CCCL_HOST_DEVICE thrust::pair unique_by_key( + thrust::execution_policy& exec, + ForwardIterator1 keys_first, + ForwardIterator1 keys_last, + ForwardIterator2 values_first, + BinaryPredicate binary_pred) +{ + using InputType1 = typename thrust::iterator_traits::value_type; + using InputType2 = typename thrust::iterator_traits::value_type; + + ForwardIterator2 values_last = values_first + (keys_last - keys_first); + + thrust::detail::temporary_array keys(exec, keys_first, keys_last); + thrust::detail::temporary_array vals(exec, values_first, values_last); + + return thrust::unique_by_key_copy(exec, keys.begin(), keys.end(), vals.begin(), keys_first, values_first, binary_pred); +} // end unique_by_key() + +template +_CCCL_HOST_DEVICE thrust::pair unique_by_key_copy( + thrust::execution_policy& exec, + InputIterator1 keys_first, + InputIterator1 keys_last, + InputIterator2 values_first, + OutputIterator1 keys_output, + OutputIterator2 values_output) +{ + using KeyType = typename thrust::iterator_traits::value_type; + return thrust::unique_by_key_copy( + exec, keys_first, keys_last, values_first, keys_output, values_output, thrust::equal_to()); +} // end unique_by_key_copy() + +template +_CCCL_HOST_DEVICE thrust::pair unique_by_key_copy( + thrust::execution_policy& exec, + InputIterator1 keys_first, + InputIterator1 keys_last, + InputIterator2 values_first, + OutputIterator1 keys_output, + OutputIterator2 values_output, + BinaryPredicate binary_pred) +{ + using difference_type = typename thrust::iterator_traits::difference_type; + + difference_type n = thrust::distance(keys_first, keys_last); + + thrust::detail::head_flags stencil(keys_first, keys_last, binary_pred); + + using namespace thrust::placeholders; + thrust::zip_iterator> result = thrust::copy_if( + exec, + thrust::make_zip_iterator(thrust::make_tuple(keys_first, values_first)), + thrust::make_zip_iterator(thrust::make_tuple(keys_first, values_first)) + n, + stencil.begin(), + thrust::make_zip_iterator(thrust::make_tuple(keys_output, values_output)), + _1); + + difference_type output_size = result - thrust::make_zip_iterator(thrust::make_tuple(keys_output, values_output)); + + return thrust::make_pair(keys_output + output_size, values_output + output_size); +} // end unique_by_key_copy() + +} // end namespace generic +} // end namespace detail +} // end namespace system +THRUST_NAMESPACE_END