提交 4ccd5ea1 编写于 作者: Y Yu Yang 提交者: GitHub

Merge pull request #1004 from gangliao/common

Add common.h and remove DisableCopy and Typedefs
...@@ -20,15 +20,11 @@ limitations under the License. */ ...@@ -20,15 +20,11 @@ limitations under the License. */
#include <string> #include <string>
#include <vector> #include <vector>
#include "paddle/utils/GlobalConstants.h" #include "paddle/utils/GlobalConstants.h"
#include "paddle/utils/TypeDefs.h" #include "paddle/utils/common.h"
/// Import PaddlePaddle's enumeration into global namespace. /// Import PaddlePaddle's enumeration into global namespace.
using namespace paddle::enumeration_wrapper; // NOLINT using namespace paddle::enumeration_wrapper; // NOLINT
#define DISABLE_COPY_AND_ASSIGN(classname) \
classname(const classname& other); \
classname& operator=(const classname& other)
/** /**
* @brief Initialize paddle. * @brief Initialize paddle.
* *
...@@ -102,7 +98,7 @@ const size_t NO_SPARSE_ID = -1UL; ...@@ -102,7 +98,7 @@ const size_t NO_SPARSE_ID = -1UL;
struct MatrixPrivate; struct MatrixPrivate;
class Matrix { class Matrix {
Matrix(); // User Cannot Create Matrix. Matrix(); // User Cannot Create Matrix.
DISABLE_COPY_AND_ASSIGN(Matrix); DISABLE_COPY(Matrix);
static Matrix* createByPaddleMatrixPtr(void* sharedPtr); static Matrix* createByPaddleMatrixPtr(void* sharedPtr);
public: public:
...@@ -242,7 +238,7 @@ private: ...@@ -242,7 +238,7 @@ private:
struct VectorPrivate; struct VectorPrivate;
class Vector { class Vector {
DISABLE_COPY_AND_ASSIGN(Vector); DISABLE_COPY(Vector);
Vector(); Vector();
static Vector* createByPaddleVectorPtr(void* ptr); static Vector* createByPaddleVectorPtr(void* ptr);
...@@ -322,7 +318,7 @@ private: ...@@ -322,7 +318,7 @@ private:
struct IVectorPrivate; struct IVectorPrivate;
class IVector { class IVector {
IVector(); IVector();
DISABLE_COPY_AND_ASSIGN(IVector); DISABLE_COPY(IVector);
static IVector* createByPaddleVectorPtr(void* ptr); static IVector* createByPaddleVectorPtr(void* ptr);
public: public:
...@@ -402,7 +398,7 @@ struct ArgumentsPrivate; ...@@ -402,7 +398,7 @@ struct ArgumentsPrivate;
class Arguments { class Arguments {
private: private:
Arguments(); // Internal Create. Arguments(); // Internal Create.
DISABLE_COPY_AND_ASSIGN(Arguments); DISABLE_COPY(Arguments);
public: public:
/** /**
...@@ -472,7 +468,7 @@ enum GradientMatchineCreateMode { ...@@ -472,7 +468,7 @@ enum GradientMatchineCreateMode {
struct ParameterConfigPrivate; struct ParameterConfigPrivate;
class ParameterConfig { class ParameterConfig {
DISABLE_COPY_AND_ASSIGN(ParameterConfig); DISABLE_COPY(ParameterConfig);
ParameterConfig(); ParameterConfig();
/** /**
...@@ -502,7 +498,7 @@ private: ...@@ -502,7 +498,7 @@ private:
struct OptimizationConfigPrivate; struct OptimizationConfigPrivate;
class OptimizationConfig { class OptimizationConfig {
DISABLE_COPY_AND_ASSIGN(OptimizationConfig); DISABLE_COPY(OptimizationConfig);
OptimizationConfig(); OptimizationConfig();
public: public:
...@@ -526,7 +522,7 @@ struct ParameterPrivate; ...@@ -526,7 +522,7 @@ struct ParameterPrivate;
class Parameter { class Parameter {
private: private:
Parameter(); Parameter();
DISABLE_COPY_AND_ASSIGN(Parameter); DISABLE_COPY(Parameter);
public: public:
virtual ~Parameter(); virtual ~Parameter();
...@@ -568,7 +564,7 @@ struct ModelConfigPrivate; ...@@ -568,7 +564,7 @@ struct ModelConfigPrivate;
class ModelConfig { class ModelConfig {
private: private:
ModelConfig(); ModelConfig();
DISABLE_COPY_AND_ASSIGN(ModelConfig); DISABLE_COPY(ModelConfig);
public: public:
virtual ~ModelConfig(); virtual ~ModelConfig();
...@@ -589,7 +585,7 @@ struct TrainerConfigPrivate; ...@@ -589,7 +585,7 @@ struct TrainerConfigPrivate;
class TrainerConfig { class TrainerConfig {
private: private:
TrainerConfig(); TrainerConfig();
DISABLE_COPY_AND_ASSIGN(TrainerConfig); DISABLE_COPY(TrainerConfig);
public: public:
virtual ~TrainerConfig(); virtual ~TrainerConfig();
...@@ -629,7 +625,7 @@ public: ...@@ -629,7 +625,7 @@ public:
struct ParameterTraverseCallbackPrivate; struct ParameterTraverseCallbackPrivate;
class ParameterTraverseCallback { class ParameterTraverseCallback {
DISABLE_COPY_AND_ASSIGN(ParameterTraverseCallback); DISABLE_COPY(ParameterTraverseCallback);
ParameterTraverseCallback(); ParameterTraverseCallback();
public: public:
...@@ -651,7 +647,7 @@ private: ...@@ -651,7 +647,7 @@ private:
*/ */
struct ParameterOptimizerPrivate; struct ParameterOptimizerPrivate;
class ParameterOptimizer { class ParameterOptimizer {
DISABLE_COPY_AND_ASSIGN(ParameterOptimizer); DISABLE_COPY(ParameterOptimizer);
ParameterOptimizer(); ParameterOptimizer();
public: public:
...@@ -688,7 +684,7 @@ struct GradientMachinePrivate; ...@@ -688,7 +684,7 @@ struct GradientMachinePrivate;
class GradientMachine { class GradientMachine {
private: private:
GradientMachine(); GradientMachine();
DISABLE_COPY_AND_ASSIGN(GradientMachine); DISABLE_COPY(GradientMachine);
public: public:
virtual ~GradientMachine(); virtual ~GradientMachine();
...@@ -790,7 +786,7 @@ private: ...@@ -790,7 +786,7 @@ private:
TrainerPrivate* m; TrainerPrivate* m;
Trainer(); Trainer();
Trainer(TrainerConfig* optConfig, GradientMachine* gm); Trainer(TrainerConfig* optConfig, GradientMachine* gm);
DISABLE_COPY_AND_ASSIGN(Trainer); DISABLE_COPY(Trainer);
public: public:
virtual ~Trainer(); virtual ~Trainer();
...@@ -856,7 +852,7 @@ public: ...@@ -856,7 +852,7 @@ public:
struct SequenceGeneratorPrivate; struct SequenceGeneratorPrivate;
class SequenceGenerator { class SequenceGenerator {
DISABLE_COPY_AND_ASSIGN(SequenceGenerator); DISABLE_COPY(SequenceGenerator);
SequenceGenerator(); SequenceGenerator();
public: public:
......
...@@ -141,9 +141,12 @@ try: ...@@ -141,9 +141,12 @@ try:
def c_flag(self): def c_flag(self):
if self.with_coverage: if self.with_coverage:
return ["-fprofile-arcs", "-ftest-coverage", "-O0", "-g"] return [
"-fprofile-arcs", "-ftest-coverage", "-O0", "-g",
"-std=c++11"
]
else: else:
return None return ["-std=c++11"]
except ImportError: except ImportError:
class PaddleLDFlag(object): class PaddleLDFlag(object):
......
...@@ -16,7 +16,31 @@ limitations under the License. */ ...@@ -16,7 +16,31 @@ limitations under the License. */
#define HL_BASE_H_ #define HL_BASE_H_
#include <cstddef> #include <cstddef>
#include "paddle/utils/TypeDefs.h"
#ifdef PADDLE_TYPE_DOUBLE
#define HL_FLOAT_MAX 3.40282347e+38F
#define HL_FLOAT_MIN 1.17549435e-38F
using real = double;
#else
#define HL_FLOAT_MAX 1.7976931348623157e+308
#define HL_FLOAT_MIN 2.2250738585072014e-308
using real = float;
#endif
/**
* The maximum input value for exp, used to avoid overflow problem.
* currently only used for tanh function.
*/
#define EXP_MAX_INPUT 40.0
/**
* @brief DIVUP(x, y) is similar to ceil(x / y).
* @note For CUDA, DIVUP will be used to specify
* the size of blockDim.
*/
#ifndef DIVUP
#define DIVUP(x, y) (((x) + (y)-1) / (y))
#endif
/** /**
* HPPL is an internal high performance parallel computing library * HPPL is an internal high performance parallel computing library
...@@ -181,46 +205,6 @@ typedef struct { ...@@ -181,46 +205,6 @@ typedef struct {
size_t nnz; size_t nnz;
} _hl_sparse_matrix_s, *hl_sparse_matrix_s; } _hl_sparse_matrix_s, *hl_sparse_matrix_s;
#ifndef PADDLE_TYPE_DOUBLE
/**
* HPPL data type: real (float or double)
*
* if real == float
*
* HL_FLOAT_MAX: 3.40282347e+38F
*
* HL_FLOAT_MIN: 1.17549435e-38F
*/
#define HL_FLOAT_MAX 3.40282347e+38F
/**
* if real == double
*
* HL_FLOAT_MAX: 1.7976931348623157e+308
*
* HL_FLOAT_MIN: 2.2250738585072014e-308
*/
#define HL_FLOAT_MIN 1.17549435e-38F
#else
#define HL_FLOAT_MAX 1.7976931348623157e+308
#define HL_FLOAT_MIN 2.2250738585072014e-308
#endif
/**
* The maximum input value for exp, used to avoid overflow problem.
*
* Currently only used for tanh function.
*/
#define EXP_MAX_INPUT 40.0
/**
* @brief DIVUP(x, y) is similar to ceil(x / y).
* @note For CUDA, DIVUP will be used to specify
* the size of blockDim.
*/
#ifndef DIVUP
#define DIVUP(x, y) (((x) + (y)-1) / (y))
#endif
#ifdef __NVCC__ #ifdef __NVCC__
#include "cuda_runtime.h" #include "cuda_runtime.h"
......
...@@ -34,8 +34,8 @@ limitations under the License. */ ...@@ -34,8 +34,8 @@ limitations under the License. */
#include "paddle/utils/Logging.h" #include "paddle/utils/Logging.h"
#include "paddle/utils/Queue.h" #include "paddle/utils/Queue.h"
#include "paddle/utils/ThreadLocal.h" #include "paddle/utils/ThreadLocal.h"
#include "paddle/utils/TypeDefs.h"
#include "paddle/utils/Util.h" #include "paddle/utils/Util.h"
#include "paddle/utils/common.h"
namespace paddle { namespace paddle {
/** /**
......
...@@ -16,7 +16,7 @@ limitations under the License. */ ...@@ -16,7 +16,7 @@ limitations under the License. */
#include "ModelConfig.pb.h" #include "ModelConfig.pb.h"
#include "hl_gpu.h" #include "hl_gpu.h"
#include "paddle/utils/TypeDefs.h" #include "paddle/utils/common.h"
namespace paddle { namespace paddle {
......
...@@ -16,7 +16,7 @@ limitations under the License. */ ...@@ -16,7 +16,7 @@ limitations under the License. */
#include "ModelConfig.pb.h" #include "ModelConfig.pb.h"
#include "hl_gpu.h" #include "hl_gpu.h"
#include "paddle/utils/TypeDefs.h" #include "paddle/utils/common.h"
namespace paddle { namespace paddle {
......
...@@ -16,7 +16,7 @@ limitations under the License. */ ...@@ -16,7 +16,7 @@ limitations under the License. */
#include <memory> #include <memory>
#include <random> #include <random>
#include "paddle/utils/TypeDefs.h" #include "paddle/utils/common.h"
namespace paddle { namespace paddle {
......
...@@ -16,7 +16,7 @@ limitations under the License. */ ...@@ -16,7 +16,7 @@ limitations under the License. */
#include <stdint.h> #include <stdint.h>
#include <cstddef> #include <cstddef>
#include "TensorExpression.h" #include "TensorExpression.h"
#include "paddle/utils/TypeDefs.h" #include "paddle/utils/common.h"
namespace paddle { namespace paddle {
......
...@@ -27,7 +27,7 @@ limitations under the License. */ ...@@ -27,7 +27,7 @@ limitations under the License. */
#include "MemoryHandle.h" #include "MemoryHandle.h"
#include "Vector.h" #include "Vector.h"
#include "paddle/utils/ThreadLocal.h" #include "paddle/utils/ThreadLocal.h"
#include "paddle/utils/TypeDefs.h" #include "paddle/utils/common.h"
namespace paddle { namespace paddle {
......
...@@ -17,7 +17,7 @@ limitations under the License. */ ...@@ -17,7 +17,7 @@ limitations under the License. */
#include <cstddef> #include <cstddef>
#include "hl_tensor_ops.h" #include "hl_tensor_ops.h"
#include "paddle/utils/Logging.h" #include "paddle/utils/Logging.h"
#include "paddle/utils/TypeDefs.h" #include "paddle/utils/common.h"
namespace paddle { namespace paddle {
......
...@@ -22,7 +22,7 @@ limitations under the License. */ ...@@ -22,7 +22,7 @@ limitations under the License. */
#include "BaseMatrix.h" #include "BaseMatrix.h"
#include "MemoryHandle.h" #include "MemoryHandle.h"
#include "paddle/utils/Thread.h" #include "paddle/utils/Thread.h"
#include "paddle/utils/TypeDefs.h" #include "paddle/utils/common.h"
namespace paddle { namespace paddle {
......
...@@ -28,7 +28,7 @@ limitations under the License. */ ...@@ -28,7 +28,7 @@ limitations under the License. */
#include "paddle/parameter/ParameterUpdateFunctions.h" #include "paddle/parameter/ParameterUpdateFunctions.h"
#include "paddle/utils/Flags.h" #include "paddle/utils/Flags.h"
#include "paddle/utils/Locks.h" #include "paddle/utils/Locks.h"
#include "paddle/utils/TypeDefs.h" #include "paddle/utils/common.h"
#include "ParameterConfig.pb.h" #include "ParameterConfig.pb.h"
......
...@@ -29,8 +29,8 @@ limitations under the License. */ ...@@ -29,8 +29,8 @@ limitations under the License. */
#include "paddle/utils/GlobalConstants.h" #include "paddle/utils/GlobalConstants.h"
#include "paddle/utils/Locks.h" #include "paddle/utils/Locks.h"
#include "paddle/utils/ThreadLocal.h" #include "paddle/utils/ThreadLocal.h"
#include "paddle/utils/TypeDefs.h"
#include "paddle/utils/Util.h" #include "paddle/utils/Util.h"
#include "paddle/utils/common.h"
namespace paddle { namespace paddle {
......
...@@ -15,7 +15,7 @@ limitations under the License. */ ...@@ -15,7 +15,7 @@ limitations under the License. */
#pragma once #pragma once
#include "paddle/math/Vector.h" #include "paddle/math/Vector.h"
#include "paddle/utils/TypeDefs.h" #include "paddle/utils/common.h"
namespace paddle { namespace paddle {
......
...@@ -18,7 +18,7 @@ limitations under the License. */ ...@@ -18,7 +18,7 @@ limitations under the License. */
#include "paddle/math/Matrix.h" #include "paddle/math/Matrix.h"
#include "paddle/pserver/ProtoServer.h" #include "paddle/pserver/ProtoServer.h"
#include "paddle/utils/Queue.h" #include "paddle/utils/Queue.h"
#include "paddle/utils/TypeDefs.h" #include "paddle/utils/common.h"
namespace paddle { namespace paddle {
......
...@@ -26,8 +26,8 @@ limitations under the License. */ ...@@ -26,8 +26,8 @@ limitations under the License. */
#include "paddle/utils/Flags.h" #include "paddle/utils/Flags.h"
#include "paddle/utils/Locks.h" #include "paddle/utils/Locks.h"
#include "paddle/utils/Queue.h" #include "paddle/utils/Queue.h"
#include "paddle/utils/TypeDefs.h"
#include "paddle/utils/Util.h" #include "paddle/utils/Util.h"
#include "paddle/utils/common.h"
#include "ParameterService.pb.h" #include "ParameterService.pb.h"
......
...@@ -32,7 +32,7 @@ limitations under the License. */ ...@@ -32,7 +32,7 @@ limitations under the License. */
#include "paddle/utils/Locks.h" #include "paddle/utils/Locks.h"
#include "paddle/utils/Stat.h" #include "paddle/utils/Stat.h"
#include "paddle/utils/ThreadLocal.h" #include "paddle/utils/ThreadLocal.h"
#include "paddle/utils/TypeDefs.h" #include "paddle/utils/common.h"
#include "ParameterService.pb.h" #include "ParameterService.pb.h"
......
...@@ -30,8 +30,10 @@ is_lin = (system == 'linux') ...@@ -30,8 +30,10 @@ is_lin = (system == 'linux')
# The extra links will passed from COMAKE # The extra links will passed from COMAKE
# because generate paddle LDFLAGS is too complicated to do in setup.py # because generate paddle LDFLAGS is too complicated to do in setup.py
# it just read COMAKE generated LDFLAGS. # it just read COMAKE generated LDFLAGS.
extra_comps = []
extra_links = [] extra_links = []
obj = api.paddle_ld_flags.PaddleLDFlag() obj = api.paddle_ld_flags.PaddleLDFlag()
extra_comps = obj.c_flag()
ldflags = obj.ldflag_str() ldflags = obj.ldflag_str()
if ldflags is not None: if ldflags is not None:
extra_links.extend(ldflags.split(" ")) extra_links.extend(ldflags.split(" "))
...@@ -51,20 +53,15 @@ elif is_osx == True: ...@@ -51,20 +53,15 @@ elif is_osx == True:
include_dirs = [np.get_include(), "../"] # include numpy and paddle. include_dirs = [np.get_include(), "../"] # include numpy and paddle.
extra_c = obj.c_flag()
attr=dict()
if extra_c is not None:
attr["extra_compile_args"] = extra_c
setup(name="py_paddle", setup(name="py_paddle",
version="@PADDLE_VERSION@", version="@PADDLE_VERSION@",
ext_modules=[ ext_modules=[
Extension('py_paddle._swig_paddle', # Build SWIG Extension. Extension('py_paddle._swig_paddle', # Build SWIG Extension.
['Paddle_wrap.cxx'], ['Paddle_wrap.cxx'],
language = "c++",
include_dirs = include_dirs, include_dirs = include_dirs,
extra_link_args = extra_links, extra_link_args = extra_links,
**attr extra_compile_args = extra_comps
) )
], ],
packages=['py_paddle'], packages=['py_paddle'],
......
...@@ -11,7 +11,7 @@ limitations under the License. */ ...@@ -11,7 +11,7 @@ limitations under the License. */
#pragma once #pragma once
#include "DisableCopy.h" #include "common.h"
namespace paddle { namespace paddle {
......
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#pragma once
/**
* Disable copy macro.
*/
#define DISABLE_COPY(CLASS_NAME) \
CLASS_NAME(CLASS_NAME &&) = delete; \
CLASS_NAME(const CLASS_NAME &other) = delete; \
CLASS_NAME &operator=(const CLASS_NAME &other) = delete
...@@ -19,7 +19,7 @@ limitations under the License. */ ...@@ -19,7 +19,7 @@ limitations under the License. */
#include <condition_variable> #include <condition_variable>
#include <mutex> #include <mutex>
#include "DisableCopy.h" #include "common.h"
namespace paddle { namespace paddle {
......
...@@ -26,12 +26,11 @@ limitations under the License. */ ...@@ -26,12 +26,11 @@ limitations under the License. */
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#include "DisableCopy.h"
#include "Logging.h" #include "Logging.h"
#include "TrainerConfig.pb.h" #include "TrainerConfig.pb.h"
#include "common.h"
#include "Flags.h" #include "Flags.h"
#include "TypeDefs.h"
#include "hl_gpu.h" #include "hl_gpu.h"
/** /**
......
...@@ -15,7 +15,7 @@ limitations under the License. */ ...@@ -15,7 +15,7 @@ limitations under the License. */
#pragma once #pragma once
#include <stddef.h> #include <stddef.h>
#include <iostream> #include <iostream>
#include "TypeDefs.h" #include "common.h"
namespace paddle { namespace paddle {
......
...@@ -15,12 +15,19 @@ limitations under the License. */ ...@@ -15,12 +15,19 @@ limitations under the License. */
#pragma once #pragma once
namespace paddle { namespace paddle {
/**
* Disable copy macro.
*/
#define DISABLE_COPY(class_name) \
class_name(class_name &&) = delete; \
class_name(const class_name &other) = delete; \
class_name &operator=(const class_name &other) = delete
#ifdef PADDLE_TYPE_DOUBLE #ifdef PADDLE_TYPE_DOUBLE
typedef double real; using real = double;
#else #else
typedef float real; using real = float;
#endif #endif
} // namespace paddle } // namespace paddle
using paddle::real;
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册