Download dependencies/libcudacxx/libcxx/src/chrono.cpp from camenduru/thrust: direct link, hf CLI and curl.
- Browser
- Download file 6.8 kB
-
https://huggingface.co/camenduru/thrust/resolve/main/dependencies/libcudacxx/libcxx/src/chrono.cpp
- Command line
-
hf download hf://camenduru/thrust/dependencies/libcudacxx/libcxx/src/chrono.cpp
-
curl -L -o chrono.cpp https://huggingface.co/camenduru/thrust/resolve/main/dependencies/libcudacxx/libcxx/src/chrono.cpp
6.8 kB
| //===------------------------- chrono.cpp ---------------------------------===// | |
| // | |
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | |
| // See https://llvm.org/LICENSE.txt for license information. | |
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | |
| // | |
| //===----------------------------------------------------------------------===// | |
| _LIBCUDACXX_BEGIN_NAMESPACE_STD | |
| namespace chrono | |
| { | |
| // system_clock | |
| const bool system_clock::is_steady; | |
| system_clock::time_point | |
| system_clock::now() _NOEXCEPT | |
| { | |
| // FILETIME is in 100ns units | |
| using filetime_duration = | |
| _CUDA_VSTD::chrono::duration<__int64, | |
| _CUDA_VSTD::ratio_multiply<_CUDA_VSTD::ratio<100, 1>, | |
| nanoseconds::period>>; | |
| // The Windows epoch is Jan 1 1601, the Unix epoch Jan 1 1970. | |
| static _LIBCUDACXX_CONSTEXPR const seconds nt_to_unix_epoch{11644473600}; | |
| FILETIME ft; | |
| GetSystemTimePreciseAsFileTime(&ft); | |
| GetSystemTimeAsFileTime(&ft); | |
| GetSystemTimeAsFileTime(&ft); | |
| filetime_duration d{(static_cast<__int64>(ft.dwHighDateTime) << 32) | | |
| static_cast<__int64>(ft.dwLowDateTime)}; | |
| return time_point(duration_cast<duration>(d - nt_to_unix_epoch)); | |
| struct timespec tp; | |
| if (0 != clock_gettime(CLOCK_REALTIME, &tp)) | |
| __throw_system_error(errno, "clock_gettime(CLOCK_REALTIME) failed"); | |
| return time_point(seconds(tp.tv_sec) + microseconds(tp.tv_nsec / 1000)); | |
| timeval tv; | |
| gettimeofday(&tv, 0); | |
| return time_point(seconds(tv.tv_sec) + microseconds(tv.tv_usec)); | |
| } | |
| time_t | |
| system_clock::to_time_t(const time_point& t) _NOEXCEPT | |
| { | |
| return time_t(duration_cast<seconds>(t.time_since_epoch()).count()); | |
| } | |
| system_clock::time_point | |
| system_clock::from_time_t(time_t t) _NOEXCEPT | |
| { | |
| return system_clock::time_point(seconds(t)); | |
| } | |
| // steady_clock | |
| // | |
| // Warning: If this is not truly steady, then it is non-conforming. It is | |
| // better for it to not exist and have the rest of libc++ use system_clock | |
| // instead. | |
| const bool steady_clock::is_steady; | |
| // Darwin libc versions >= 1133 provide ns precision via CLOCK_UPTIME_RAW | |
| steady_clock::time_point | |
| steady_clock::now() _NOEXCEPT | |
| { | |
| struct timespec tp; | |
| if (0 != clock_gettime(CLOCK_UPTIME_RAW, &tp)) | |
| __throw_system_error(errno, "clock_gettime(CLOCK_UPTIME_RAW) failed"); | |
| return time_point(seconds(tp.tv_sec) + nanoseconds(tp.tv_nsec)); | |
| } | |
| // mach_absolute_time() * MachInfo.numer / MachInfo.denom is the number of | |
| // nanoseconds since the computer booted up. MachInfo.numer and MachInfo.denom | |
| // are run time constants supplied by the OS. This clock has no relationship | |
| // to the Gregorian calendar. It's main use is as a high resolution timer. | |
| // MachInfo.numer / MachInfo.denom is often 1 on the latest equipment. Specialize | |
| // for that case as an optimization. | |
| static | |
| steady_clock::rep | |
| steady_simplified() | |
| { | |
| return static_cast<steady_clock::rep>(mach_absolute_time()); | |
| } | |
| static | |
| double | |
| compute_steady_factor() | |
| { | |
| mach_timebase_info_data_t MachInfo; | |
| mach_timebase_info(&MachInfo); | |
| return static_cast<double>(MachInfo.numer) / MachInfo.denom; | |
| } | |
| static | |
| steady_clock::rep | |
| steady_full() | |
| { | |
| static const double factor = compute_steady_factor(); | |
| return static_cast<steady_clock::rep>(mach_absolute_time() * factor); | |
| } | |
| typedef steady_clock::rep (*FP)(); | |
| static | |
| FP | |
| init_steady_clock() | |
| { | |
| mach_timebase_info_data_t MachInfo; | |
| mach_timebase_info(&MachInfo); | |
| if (MachInfo.numer == MachInfo.denom) | |
| return &steady_simplified; | |
| return &steady_full; | |
| } | |
| steady_clock::time_point | |
| steady_clock::now() _NOEXCEPT | |
| { | |
| static FP fp = init_steady_clock(); | |
| return time_point(duration(fp())); | |
| } | |
| // https://msdn.microsoft.com/en-us/library/windows/desktop/ms644905(v=vs.85).aspx says: | |
| // If the function fails, the return value is zero. <snip> | |
| // On systems that run Windows XP or later, the function will always succeed | |
| // and will thus never return zero. | |
| static LARGE_INTEGER | |
| __QueryPerformanceFrequency() | |
| { | |
| LARGE_INTEGER val; | |
| (void) QueryPerformanceFrequency(&val); | |
| return val; | |
| } | |
| steady_clock::time_point | |
| steady_clock::now() _NOEXCEPT | |
| { | |
| static const LARGE_INTEGER freq = __QueryPerformanceFrequency(); | |
| LARGE_INTEGER counter; | |
| (void) QueryPerformanceCounter(&counter); | |
| return time_point(duration(counter.QuadPart * nano::den / freq.QuadPart)); | |
| } | |
| // On Apple platforms only CLOCK_UPTIME_RAW or mach_absolute_time are able to | |
| // time functions in the nanosecond range. Thus, they are the only acceptable | |
| // implementations of steady_clock. | |
| steady_clock::time_point | |
| steady_clock::now() _NOEXCEPT | |
| { | |
| struct timespec tp; | |
| if (0 != clock_gettime(CLOCK_MONOTONIC, &tp)) | |
| __throw_system_error(errno, "clock_gettime(CLOCK_MONOTONIC) failed"); | |
| return time_point(seconds(tp.tv_sec) + nanoseconds(tp.tv_nsec)); | |
| } | |
| } | |
| _LIBCUDACXX_END_NAMESPACE_STD | |