Skip to content

Commit 4ccd5ea

Browse files
authored
Merge pull request #1004 from gangliao/common
Add common.h and remove DisableCopy and Typedefs
2 parents e641f94 + c8d0791 commit 4ccd5ea

24 files changed

+78
-115
lines changed

paddle/api/PaddleAPI.h

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,11 @@ limitations under the License. */
2020
#include <string>
2121
#include <vector>
2222
#include "paddle/utils/GlobalConstants.h"
23-
#include "paddle/utils/TypeDefs.h"
23+
#include "paddle/utils/common.h"
2424

2525
/// Import PaddlePaddle's enumeration into global namespace.
2626
using namespace paddle::enumeration_wrapper; // NOLINT
2727

28-
#define DISABLE_COPY_AND_ASSIGN(classname) \
29-
classname(const classname& other); \
30-
classname& operator=(const classname& other)
31-
3228
/**
3329
* @brief Initialize paddle.
3430
*
@@ -102,7 +98,7 @@ const size_t NO_SPARSE_ID = -1UL;
10298
struct MatrixPrivate;
10399
class Matrix {
104100
Matrix(); // User Cannot Create Matrix.
105-
DISABLE_COPY_AND_ASSIGN(Matrix);
101+
DISABLE_COPY(Matrix);
106102
static Matrix* createByPaddleMatrixPtr(void* sharedPtr);
107103

108104
public:
@@ -242,7 +238,7 @@ class Matrix {
242238

243239
struct VectorPrivate;
244240
class Vector {
245-
DISABLE_COPY_AND_ASSIGN(Vector);
241+
DISABLE_COPY(Vector);
246242
Vector();
247243
static Vector* createByPaddleVectorPtr(void* ptr);
248244

@@ -322,7 +318,7 @@ class Vector {
322318
struct IVectorPrivate;
323319
class IVector {
324320
IVector();
325-
DISABLE_COPY_AND_ASSIGN(IVector);
321+
DISABLE_COPY(IVector);
326322
static IVector* createByPaddleVectorPtr(void* ptr);
327323

328324
public:
@@ -402,7 +398,7 @@ struct ArgumentsPrivate;
402398
class Arguments {
403399
private:
404400
Arguments(); // Internal Create.
405-
DISABLE_COPY_AND_ASSIGN(Arguments);
401+
DISABLE_COPY(Arguments);
406402

407403
public:
408404
/**
@@ -472,7 +468,7 @@ enum GradientMatchineCreateMode {
472468

473469
struct ParameterConfigPrivate;
474470
class ParameterConfig {
475-
DISABLE_COPY_AND_ASSIGN(ParameterConfig);
471+
DISABLE_COPY(ParameterConfig);
476472
ParameterConfig();
477473

478474
/**
@@ -502,7 +498,7 @@ class ParameterConfig {
502498

503499
struct OptimizationConfigPrivate;
504500
class OptimizationConfig {
505-
DISABLE_COPY_AND_ASSIGN(OptimizationConfig);
501+
DISABLE_COPY(OptimizationConfig);
506502
OptimizationConfig();
507503

508504
public:
@@ -526,7 +522,7 @@ struct ParameterPrivate;
526522
class Parameter {
527523
private:
528524
Parameter();
529-
DISABLE_COPY_AND_ASSIGN(Parameter);
525+
DISABLE_COPY(Parameter);
530526

531527
public:
532528
virtual ~Parameter();
@@ -568,7 +564,7 @@ struct ModelConfigPrivate;
568564
class ModelConfig {
569565
private:
570566
ModelConfig();
571-
DISABLE_COPY_AND_ASSIGN(ModelConfig);
567+
DISABLE_COPY(ModelConfig);
572568

573569
public:
574570
virtual ~ModelConfig();
@@ -589,7 +585,7 @@ struct TrainerConfigPrivate;
589585
class TrainerConfig {
590586
private:
591587
TrainerConfig();
592-
DISABLE_COPY_AND_ASSIGN(TrainerConfig);
588+
DISABLE_COPY(TrainerConfig);
593589

594590
public:
595591
virtual ~TrainerConfig();
@@ -629,7 +625,7 @@ class UpdateCallback {
629625

630626
struct ParameterTraverseCallbackPrivate;
631627
class ParameterTraverseCallback {
632-
DISABLE_COPY_AND_ASSIGN(ParameterTraverseCallback);
628+
DISABLE_COPY(ParameterTraverseCallback);
633629
ParameterTraverseCallback();
634630

635631
public:
@@ -651,7 +647,7 @@ class ParameterTraverseCallback {
651647
*/
652648
struct ParameterOptimizerPrivate;
653649
class ParameterOptimizer {
654-
DISABLE_COPY_AND_ASSIGN(ParameterOptimizer);
650+
DISABLE_COPY(ParameterOptimizer);
655651
ParameterOptimizer();
656652

657653
public:
@@ -688,7 +684,7 @@ struct GradientMachinePrivate;
688684
class GradientMachine {
689685
private:
690686
GradientMachine();
691-
DISABLE_COPY_AND_ASSIGN(GradientMachine);
687+
DISABLE_COPY(GradientMachine);
692688

693689
public:
694690
virtual ~GradientMachine();
@@ -790,7 +786,7 @@ class Trainer {
790786
TrainerPrivate* m;
791787
Trainer();
792788
Trainer(TrainerConfig* optConfig, GradientMachine* gm);
793-
DISABLE_COPY_AND_ASSIGN(Trainer);
789+
DISABLE_COPY(Trainer);
794790

795791
public:
796792
virtual ~Trainer();
@@ -856,7 +852,7 @@ class ISequenceResults {
856852

857853
struct SequenceGeneratorPrivate;
858854
class SequenceGenerator {
859-
DISABLE_COPY_AND_ASSIGN(SequenceGenerator);
855+
DISABLE_COPY(SequenceGenerator);
860856
SequenceGenerator();
861857

862858
public:

paddle/api/paddle_ld_flags.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,12 @@ def cmake_bool(cmake_str):
141141

142142
def c_flag(self):
143143
if self.with_coverage:
144-
return ["-fprofile-arcs", "-ftest-coverage", "-O0", "-g"]
144+
return [
145+
"-fprofile-arcs", "-ftest-coverage", "-O0", "-g",
146+
"-std=c++11"
147+
]
145148
else:
146-
return None
149+
return ["-std=c++11"]
147150
except ImportError:
148151

149152
class PaddleLDFlag(object):

paddle/cuda/include/hl_base.h

Lines changed: 25 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,31 @@ limitations under the License. */
1616
#define HL_BASE_H_
1717

1818
#include <cstddef>
19-
#include "paddle/utils/TypeDefs.h"
19+
20+
#ifdef PADDLE_TYPE_DOUBLE
21+
#define HL_FLOAT_MAX 3.40282347e+38F
22+
#define HL_FLOAT_MIN 1.17549435e-38F
23+
using real = double;
24+
#else
25+
#define HL_FLOAT_MAX 1.7976931348623157e+308
26+
#define HL_FLOAT_MIN 2.2250738585072014e-308
27+
using real = float;
28+
#endif
29+
30+
/**
31+
* The maximum input value for exp, used to avoid overflow problem.
32+
* currently only used for tanh function.
33+
*/
34+
#define EXP_MAX_INPUT 40.0
35+
36+
/**
37+
* @brief DIVUP(x, y) is similar to ceil(x / y).
38+
* @note For CUDA, DIVUP will be used to specify
39+
* the size of blockDim.
40+
*/
41+
#ifndef DIVUP
42+
#define DIVUP(x, y) (((x) + (y)-1) / (y))
43+
#endif
2044

2145
/**
2246
* HPPL is an internal high performance parallel computing library
@@ -181,46 +205,6 @@ typedef struct {
181205
size_t nnz;
182206
} _hl_sparse_matrix_s, *hl_sparse_matrix_s;
183207

184-
#ifndef PADDLE_TYPE_DOUBLE
185-
/**
186-
* HPPL data type: real (float or double)
187-
*
188-
* if real == float
189-
*
190-
* HL_FLOAT_MAX: 3.40282347e+38F
191-
*
192-
* HL_FLOAT_MIN: 1.17549435e-38F
193-
*/
194-
#define HL_FLOAT_MAX 3.40282347e+38F
195-
/**
196-
* if real == double
197-
*
198-
* HL_FLOAT_MAX: 1.7976931348623157e+308
199-
*
200-
* HL_FLOAT_MIN: 2.2250738585072014e-308
201-
*/
202-
#define HL_FLOAT_MIN 1.17549435e-38F
203-
#else
204-
#define HL_FLOAT_MAX 1.7976931348623157e+308
205-
#define HL_FLOAT_MIN 2.2250738585072014e-308
206-
#endif
207-
208-
/**
209-
* The maximum input value for exp, used to avoid overflow problem.
210-
*
211-
* Currently only used for tanh function.
212-
*/
213-
#define EXP_MAX_INPUT 40.0
214-
215-
/**
216-
* @brief DIVUP(x, y) is similar to ceil(x / y).
217-
* @note For CUDA, DIVUP will be used to specify
218-
* the size of blockDim.
219-
*/
220-
#ifndef DIVUP
221-
#define DIVUP(x, y) (((x) + (y)-1) / (y))
222-
#endif
223-
224208
#ifdef __NVCC__
225209

226210
#include "cuda_runtime.h"

paddle/gserver/dataproviders/DataProvider.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ limitations under the License. */
3434
#include "paddle/utils/Logging.h"
3535
#include "paddle/utils/Queue.h"
3636
#include "paddle/utils/ThreadLocal.h"
37-
#include "paddle/utils/TypeDefs.h"
3837
#include "paddle/utils/Util.h"
38+
#include "paddle/utils/common.h"
3939

4040
namespace paddle {
4141
/**

paddle/gserver/layers/GruCompute.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ limitations under the License. */
1616

1717
#include "ModelConfig.pb.h"
1818
#include "hl_gpu.h"
19-
#include "paddle/utils/TypeDefs.h"
19+
#include "paddle/utils/common.h"
2020

2121
namespace paddle {
2222

paddle/gserver/layers/LstmCompute.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ limitations under the License. */
1616

1717
#include "ModelConfig.pb.h"
1818
#include "hl_gpu.h"
19-
#include "paddle/utils/TypeDefs.h"
19+
#include "paddle/utils/common.h"
2020

2121
namespace paddle {
2222

paddle/gserver/layers/MultinomialSampler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ limitations under the License. */
1616

1717
#include <memory>
1818
#include <random>
19-
#include "paddle/utils/TypeDefs.h"
19+
#include "paddle/utils/common.h"
2020

2121
namespace paddle {
2222

paddle/math/BaseMatrix.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ limitations under the License. */
1616
#include <stdint.h>
1717
#include <cstddef>
1818
#include "TensorExpression.h"
19-
#include "paddle/utils/TypeDefs.h"
19+
#include "paddle/utils/common.h"
2020

2121
namespace paddle {
2222

paddle/math/Matrix.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ limitations under the License. */
2727
#include "MemoryHandle.h"
2828
#include "Vector.h"
2929
#include "paddle/utils/ThreadLocal.h"
30-
#include "paddle/utils/TypeDefs.h"
30+
#include "paddle/utils/common.h"
3131

3232
namespace paddle {
3333

paddle/math/TensorExpression.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ limitations under the License. */
1717
#include <cstddef>
1818
#include "hl_tensor_ops.h"
1919
#include "paddle/utils/Logging.h"
20-
#include "paddle/utils/TypeDefs.h"
20+
#include "paddle/utils/common.h"
2121

2222
namespace paddle {
2323

0 commit comments

Comments
 (0)