-
Notifications
You must be signed in to change notification settings - Fork 353
Cleanups for random module #6951
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
9fb7077
981b946
ae93a77
193e20c
aa9c655
62c0c92
6351f15
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,11 +21,12 @@ | |
| #endif // no system header | ||
|
|
||
| #include <cuda/std/__type_traits/enable_if.h> | ||
| #include <cuda/std/__type_traits/integral_constant.h> | ||
| #include <cuda/std/__type_traits/is_const.h> | ||
| #include <cuda/std/__type_traits/is_floating_point.h> | ||
| #include <cuda/std/__type_traits/is_integer.h> | ||
| #include <cuda/std/__type_traits/is_same.h> | ||
| #include <cuda/std/__type_traits/is_unsigned.h> | ||
| #include <cuda/std/__utility/declval.h> | ||
| #include <cuda/std/cstdint> | ||
|
|
||
| #include <cuda/std/__cccl/prologue.h> | ||
|
|
||
|
|
@@ -36,52 +37,18 @@ _CCCL_BEGIN_NAMESPACE_CUDA_STD | |
| // named RealType is undefined unless the corresponding template argument is | ||
| // cv-unqualified and is one of float, double, or long double. | ||
|
|
||
| template <class> | ||
| inline constexpr bool __libcpp_random_is_valid_realtype = false; | ||
|
|
||
| template <> | ||
| inline constexpr bool __libcpp_random_is_valid_realtype<float> = true; | ||
| template <> | ||
| inline constexpr bool __libcpp_random_is_valid_realtype<double> = true; | ||
| #if _CCCL_HAS_LONG_DOUBLE() | ||
| template <> | ||
| inline constexpr bool __libcpp_random_is_valid_realtype<long double> = true; | ||
| #endif // _CCCL_HAS_LONG_DOUBLE() | ||
| template <class _Type> | ||
| inline constexpr bool __cccl_random_is_valid_realtype = | ||
| ::cuda::std::is_floating_point_v<_Type> && !::cuda::std::is_const_v<_Type>; | ||
|
||
|
|
||
| // [rand.req.genl]/1.5: | ||
| // The effect of instantiating a template that has a template type parameter | ||
| // named IntType is undefined unless the corresponding template argument is | ||
| // cv-unqualified and is one of short, int, long, long long, unsigned short, | ||
| // unsigned int, unsigned long, or unsigned long long. | ||
|
|
||
| template <class> | ||
| inline constexpr bool __libcpp_random_is_valid_inttype = false; | ||
| template <> // extension | ||
| inline constexpr bool __libcpp_random_is_valid_inttype<int8_t> = true; | ||
| template <> | ||
| inline constexpr bool __libcpp_random_is_valid_inttype<short> = true; | ||
| template <> | ||
| inline constexpr bool __libcpp_random_is_valid_inttype<int> = true; | ||
| template <> | ||
| inline constexpr bool __libcpp_random_is_valid_inttype<long> = true; | ||
| template <> | ||
| inline constexpr bool __libcpp_random_is_valid_inttype<long long> = true; | ||
| template <> // extension | ||
| inline constexpr bool __libcpp_random_is_valid_inttype<uint8_t> = true; | ||
| template <> | ||
| inline constexpr bool __libcpp_random_is_valid_inttype<unsigned short> = true; | ||
| template <> | ||
| inline constexpr bool __libcpp_random_is_valid_inttype<unsigned int> = true; | ||
| template <> | ||
| inline constexpr bool __libcpp_random_is_valid_inttype<unsigned long> = true; | ||
| template <> | ||
| inline constexpr bool __libcpp_random_is_valid_inttype<unsigned long long> = true; | ||
| #if _CCCL_HAS_INT128() | ||
| template <> // extension | ||
| inline constexpr bool __libcpp_random_is_valid_inttype<__int128_t> = true; | ||
| template <> // extension | ||
| inline constexpr bool __libcpp_random_is_valid_inttype<__uint128_t> = true; | ||
| #endif // _CCCL_HAS_INT128() | ||
| template <class _Type> | ||
| inline constexpr bool __cccl_random_is_valid_inttype = | ||
| ::cuda::std::__cccl_is_integer_v<_Type> && !::cuda::std::is_const_v<_Type>; | ||
|
||
|
|
||
| // [rand.req.urng]/3: | ||
| // A class G meets the uniform random bit generator requirements if G models | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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 | ||
| // SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
|
|
||
| #include <cuda/std/__random_> | ||
| #include <cuda/std/array> | ||
| #include <cuda/std/cassert> | ||
| #include <cuda/std/numeric> | ||
|
|
||
| #include "test_macros.h" | ||
|
|
||
| template <class T> | ||
| __host__ __device__ void test() | ||
| { | ||
| cuda::std::array<T, 100> data; | ||
| cuda::std::philox4x64 g{}; | ||
| for (auto& v : data) | ||
| { | ||
| v = cuda::std::generate_canonical<T, cuda::std::numeric_limits<T>::digits>(g); | ||
| assert(v >= T(0) && v < T(1)); | ||
| } | ||
| auto mean = cuda::std::accumulate(data.begin(), data.end(), T(0)) / data.size(); | ||
| assert(mean > T(0.4) && mean < T(0.6)); | ||
| } | ||
|
|
||
| int main(int, char**) | ||
| { | ||
| test<float>(); | ||
| test<double>(); | ||
| return 0; | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.