diff options
| author | Matti Picus <matti.picus@gmail.com> | 2023-02-15 14:01:17 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-15 14:01:17 +0200 |
| commit | 0bd56e7ec12f8ceeb8d082340e71e60b873d5c57 (patch) | |
| tree | 4151f2f93381a1eed7b29ea5cf2aca122711a2b8 /numpy/core/src/common | |
| parent | a5f4e8e417d815cb577a8f2f9414b07a689d69b1 (diff) | |
| parent | d07d5584fc63df10025190a4ea38c4863c1b1723 (diff) | |
| download | numpy-0bd56e7ec12f8ceeb8d082340e71e60b873d5c57.tar.gz | |
Merge pull request #22315 from r-devulap/avxsort
ENH: Vectorize quicksort for 16-bit and 64-bit dtype using AVX512
Diffstat (limited to 'numpy/core/src/common')
| -rw-r--r-- | numpy/core/src/common/common.hpp | 11 | ||||
| -rw-r--r-- | numpy/core/src/common/half.hpp | 63 | ||||
| -rw-r--r-- | numpy/core/src/common/meta.hpp | 54 | ||||
| -rw-r--r-- | numpy/core/src/common/npstd.hpp | 54 | ||||
| -rw-r--r-- | numpy/core/src/common/npy_config.h | 1 |
5 files changed, 183 insertions, 0 deletions
diff --git a/numpy/core/src/common/common.hpp b/numpy/core/src/common/common.hpp new file mode 100644 index 000000000..47d790bcf --- /dev/null +++ b/numpy/core/src/common/common.hpp @@ -0,0 +1,11 @@ +#ifndef NUMPY_CORE_SRC_COMMON_COMMON_HPP +#define NUMPY_CORE_SRC_COMMON_COMMON_HPP +/* + * The following C++ headers are safe to be used standalone, however, + * they are gathered to make it easy for us and for the future need to support PCH. + */ +#include "npstd.hpp" +#include "half.hpp" +#include "meta.hpp" + +#endif // NUMPY_CORE_SRC_COMMON_COMMON_HPP diff --git a/numpy/core/src/common/half.hpp b/numpy/core/src/common/half.hpp new file mode 100644 index 000000000..399f2fa79 --- /dev/null +++ b/numpy/core/src/common/half.hpp @@ -0,0 +1,63 @@ +#ifndef NUMPY_CORE_SRC_COMMON_HALF_HPP +#define NUMPY_CORE_SRC_COMMON_HALF_HPP + +#include "npstd.hpp" + +// TODO(@seiko2plus): +// - covers half-precision operations that being supported by numpy/halffloat.h +// - support __fp16 +// - optimize x86 half<->single via cpu_fp16 +// - optimize ppc64 half<->single via cpu_vsx3 + +namespace np { + +/// @addtogroup cpp_core_types +/// @{ + +/// Provides a type that implements 16-bit floating point (half-precision). +/// This type is ensured to be 16-bit size. +class Half final { + public: + /// @name Public Constructors + /// @{ + + /// Default constructor. initialize nothing. + Half() = default; + /// Copy. + Half(const Half &r) + { + data_.u = r.data_.u; + } + + /// @} + + /// Returns a new Half constracted from the IEEE 754 binary16. + /// @param b the value of binary16. + static Half FromBits(uint16_t b) + { + Half f; + f.data_.u = b; + return f; + } + /// Returns the IEEE 754 binary16 representation. + uint16_t Bits() const + { + return data_.u; + } + + private: + union { + uint16_t u; +/* +TODO(@seiko2plus): support __fp16 +#ifdef NPY_HAVE_HW_FP16 + __fp16 f; +#endif +*/ + } data_; +}; + +/// @} cpp_core_types + +} // namespace np +#endif // NUMPY_CORE_SRC_COMMON_HALF_HPP diff --git a/numpy/core/src/common/meta.hpp b/numpy/core/src/common/meta.hpp new file mode 100644 index 000000000..27ea1857e --- /dev/null +++ b/numpy/core/src/common/meta.hpp @@ -0,0 +1,54 @@ +#ifndef NUMPY_CORE_SRC_COMMON_META_HPP +#define NUMPY_CORE_SRC_COMMON_META_HPP + +#include "npstd.hpp" + +namespace np { namespace meta { +/// @addtogroup cpp_core_meta +/// @{ + +namespace details { +template<int size, bool unsig> +struct IntBySize; + +template<bool unsig> +struct IntBySize<sizeof(uint8_t), unsig> { + using Type = typename std::conditional< + unsig, uint8_t, int8_t>::type; +}; +template<bool unsig> +struct IntBySize<sizeof(uint16_t), unsig> { + using Type = typename std::conditional< + unsig, uint16_t, int16_t>::type; +}; +template<bool unsig> +struct IntBySize<sizeof(uint32_t), unsig> { + using Type = typename std::conditional< + unsig, uint32_t, int32_t>::type; +}; +template<bool unsig> +struct IntBySize<sizeof(uint64_t), unsig> { + using Type = typename std::conditional< + unsig, uint64_t, int64_t>::type; +}; +} // namespace details + +/// Provides safe conversion of any integer type synonyms +/// to a fixed-width integer type. +template<typename T> +struct FixedWidth { + using TF_ = typename details::IntBySize< + sizeof(T), std::is_unsigned<T>::value + >::Type; + + using Type = typename std::conditional< + std::is_integral<T>::value, TF_, T + >::type; +}; + +/// @} cpp_core_meta + +}} // namespace np::meta + +#endif // NUMPY_CORE_SRC_COMMON_META_HPP + diff --git a/numpy/core/src/common/npstd.hpp b/numpy/core/src/common/npstd.hpp new file mode 100644 index 000000000..71993bd7c --- /dev/null +++ b/numpy/core/src/common/npstd.hpp @@ -0,0 +1,54 @@ +#ifndef NUMPY_CORE_SRC_COMMON_NPSTD_HPP +#define NUMPY_CORE_SRC_COMMON_NPSTD_HPP + +#include <cstddef> +#include <cstring> +#include <cctype> + +#include <string> +#include <algorithm> +#include <utility> +#include <cstdlib> +#include <cmath> +#include <complex> +#include <type_traits> + +#include <numpy/npy_common.h> + +#include "npy_config.h" + +namespace np { +/// @addtogroup cpp_core_types +/// @{ +using std::uint8_t; +using std::int8_t; +using std::uint16_t; +using std::int16_t; +using std::uint32_t; +using std::int32_t; +using std::uint64_t; +using std::int64_t; +using std::uintptr_t; +using std::intptr_t; +using std::complex; + +/** Guard for long double. + * + * The C implementation defines long double as double + * on MinGW to provide compatibility with MSVC to unify + * one behavior under Windows OS, which makes npy_longdouble + * not fit to be used with template specialization or overloading. + * + * This type will be set to `void` when `npy_longdouble` is not defined + * as `long double`. + */ +using LongDouble = typename std::conditional< + !std::is_same<npy_longdouble, long double>::value, + void, npy_longdouble +>::type; +/// @} cpp_core_types + +} // namespace np + +#endif // NUMPY_CORE_SRC_COMMON_NPSTD_HPP + diff --git a/numpy/core/src/common/npy_config.h b/numpy/core/src/common/npy_config.h index d6886c5ea..715b17777 100644 --- a/numpy/core/src/common/npy_config.h +++ b/numpy/core/src/common/npy_config.h @@ -2,6 +2,7 @@ #define NUMPY_CORE_SRC_COMMON_NPY_CONFIG_H_ #include "config.h" +#include "npy_cpu_dispatch.h" // brings NPY_HAVE_[CPU features] #include "numpy/numpyconfig.h" #include "numpy/utils.h" #include "numpy/npy_os.h" |
