Skip to content

Commit f055200

Browse files
authored
fix style (#13142)
1 parent 856c26f commit f055200

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed

paddle/fluid/operators/math/matrix_bit_code.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ limitations under the License. */
1717
#include "paddle/fluid/framework/tensor.h"
1818
#include "paddle/fluid/platform/device_context.h"
1919

20+
#if defined(_WIN32)
21+
#include <intrin.h>
22+
#include <windows.h>
23+
#endif // _WIN32
24+
2025
namespace paddle {
2126
namespace operators {
2227
namespace math {
@@ -55,12 +60,38 @@ namespace math {
5560
* FindLastSet(x) = 1 + \floor*{\log_{2}x}
5661
* \f]
5762
*/
63+
#if !defined(_WIN32)
5864
inline constexpr size_t FindLastSet(size_t x) {
5965
return std::is_same<size_t, unsigned int>::value
6066
? (x ? 8 * sizeof(x) - __builtin_clz(x) : 0)
6167
: (std::is_same<size_t, unsigned long>::value // NOLINT
6268
? (x ? 8 * sizeof(x) - __builtin_clzl(x) : 0)
6369
: (x ? 8 * sizeof(x) - __builtin_clzll(x) : 0));
70+
71+
#else
72+
// windows don't have built-in clz, ctz function
73+
template <typename T>
74+
inline int ctz(const T& value) {
75+
DWORD trailing_zero = 0;
76+
if (_BitScanForward(&trailing_zero, value)) {
77+
return static_cast<int>(trailing_zero);
78+
} else {
79+
return static_cast<int>(0);
80+
}
81+
}
82+
83+
template <typename T>
84+
inline int clz(const T& value) {
85+
DWORD leadning_zero = 0;
86+
if (_BitScanReverse(&leadning_zero, value)) {
87+
return static_cast<int>(sizeof(T) * 8 - leadning_zero);
88+
} else {
89+
return static_cast<int>(0);
90+
}
91+
}
92+
93+
inline size_t FindLastSet(size_t x) { return sizeof(size_t) * 8 - clz(x); }
94+
#endif // !_WIN32
6495
}
6596

6697
struct SimpleCode {

paddle/fluid/operators/math/maxouting.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@ limitations under the License. */
1616
#include "paddle/fluid/framework/tensor.h"
1717
#include "paddle/fluid/platform/device_context.h"
1818
#include "paddle/fluid/platform/hostdevice.h"
19+
#include "paddle/fluid/platform/macros.h"
1920

2021
namespace paddle {
2122
namespace operators {
2223
namespace math {
2324

24-
#define FLT_MAX __FLT_MAX__
25-
2625
template <typename DeviceContext, typename T>
2726
class MaxOutFunctor {
2827
public:

paddle/fluid/operators/math/pooling.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,12 @@ limitations under the License. */
1818
#include "paddle/fluid/framework/tensor.h"
1919
#include "paddle/fluid/platform/device_context.h"
2020
#include "paddle/fluid/platform/hostdevice.h"
21+
#include "paddle/fluid/platform/macros.h"
2122

2223
namespace paddle {
2324
namespace operators {
2425
namespace math {
2526

26-
#define FLT_MAX \
27-
__FLT_MAX__ // TODO(zcd) :It might need to be placed in another file, but I'm
28-
// still wondering where to put it.
29-
3027
/*
3128
* \brief Extracting simple operations from pooling.
3229
* Both MaxPool and AvgPool need "initial", "compute" and "finalize"

paddle/fluid/platform/macros.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
1313
limitations under the License. */
1414

1515
#pragma once
16+
#include <cfloat>
1617

1718
// Disable the copy and assignment operator for a class.
1819
#ifndef DISABLE_COPY_AND_ASSIGN
@@ -23,3 +24,7 @@ limitations under the License. */
2324
classname& operator=(const classname&) = delete; \
2425
classname& operator=(classname&&) = delete
2526
#endif
27+
28+
#if defined(__FLT_MAX__)
29+
#define FLT_MAX __FLT_MAX__
30+
#endif // __FLT_MAX__

0 commit comments

Comments
 (0)