diff --git a/paddle/phi/api/lib/backend_set.h b/paddle/phi/api/lib/backend_set.h index 93f8f05b74b75290430fda723423ce121725f722..51e08374bc9d65b08e540955a18f9b346927d632 100644 --- a/paddle/phi/api/lib/backend_set.h +++ b/paddle/phi/api/lib/backend_set.h @@ -36,7 +36,7 @@ class BackendSet final { ? 0 : 1ULL << (static_cast(b) - 1)) {} - inline uint64_t bitset() const { return bitset_; } + inline uint32_t bitset() const { return bitset_; } bool inline Has(Backend b) const { PD_CHECK(b != Backend::UNDEFINED, "Backend argument can't be UNDEFINED."); @@ -62,8 +62,8 @@ class BackendSet final { } private: - constexpr BackendSet(uint64_t bitset) : bitset_(bitset) {} - uint64_t bitset_; + constexpr BackendSet(uint32_t bitset) : bitset_(bitset) {} + uint32_t bitset_; }; } // namespace experimental diff --git a/paddle/phi/api/lib/kernel_dispatch.cc b/paddle/phi/api/lib/kernel_dispatch.cc index 75ea1d493d9355131a9d832429ca891cf73aef7e..ccf070c7249fd2d4155e31b130d37f4f242bbe07 100644 --- a/paddle/phi/api/lib/kernel_dispatch.cc +++ b/paddle/phi/api/lib/kernel_dispatch.cc @@ -68,18 +68,18 @@ BackendSet GetTensorBackendSet(const phi::TensorBase& t) { return BackendSet(Backend::UNDEFINED); } -std::size_t CountLeadingZeros(uint64_t val) { +std::size_t CountLeadingZeros(uint32_t val) { #if defined(__clang__) || defined(__GNUC__) - return __builtin_clzl(val); + return __builtin_clz(val); #elif defined(_MSC_VER) - return __lzcnt64(val); + return __lzcnt(val); #else if (val == 0) { - return 64; + return 32; } std::size_t zero_bits = 0; - for (std::size_t shift = 64 >> 1; shift; shift >>= 1) { - uint64_t tmp = val >> shift; + for (std::size_t shift = 32 >> 1; shift; shift >>= 1) { + uint32_t tmp = val >> shift; if (tmp) { val = tmp; } else { diff --git a/paddle/phi/api/lib/kernel_dispatch.h b/paddle/phi/api/lib/kernel_dispatch.h index 1091e0556da8bcf22013c0303c4604469f17fbcb..1ed695f8e0a59069e74556a8c092dec2a310c6dc 100644 --- a/paddle/phi/api/lib/kernel_dispatch.h +++ b/paddle/phi/api/lib/kernel_dispatch.h @@ -36,7 +36,7 @@ namespace experimental { namespace detail { BackendSet GetTensorBackendSet(const phi::TensorBase& t); -std::size_t CountLeadingZeros(uint64_t val); +std::size_t CountLeadingZeros(uint32_t val); } // namespace detail phi::DeviceContext* GetDeviceContextByBackend(phi::Backend backend); @@ -56,7 +56,7 @@ struct KernelKeySet { // TODO(chenweihang): iterate all kernelkey for kernel selection phi::KernelKey GetHighestPriorityKernelKey() { - return phi::KernelKey(static_cast(64 - detail::CountLeadingZeros( + return phi::KernelKey(static_cast(32 - detail::CountLeadingZeros( backend_set.bitset())), layout, dtype); @@ -184,7 +184,7 @@ template Backend ParseBackend(T t, Args... args) { auto backend_set = BackendSet(ParseBackend(t)) | BackendSet(ParseBackend(args...)); - return static_cast(64 - + return static_cast(32 - detail::CountLeadingZeros(backend_set.bitset())); } Backend ParseBackendWithInputOrder(const Place& place, const Tensor& tensor);