Commit 06053721 by xiaotong

c++ 11 by default

parent e184cac4
...@@ -266,10 +266,6 @@ XDevManager::XDevManager() ...@@ -266,10 +266,6 @@ XDevManager::XDevManager()
{ {
Clear(); Clear();
Init(); Init();
#ifndef USE_CPP11
fprintf(stderr, "Warning!!! c++ 11 is RECOMMENDED for compilation.\n");
#endif
} }
/* de-constructor */ /* de-constructor */
......
...@@ -43,13 +43,9 @@ ...@@ -43,13 +43,9 @@
/* the nts (NiuTrans.Tensor) namespace */ /* the nts (NiuTrans.Tensor) namespace */
namespace nts { namespace nts {
#if (__cplusplus >= 201103L || _MSC_VER >= 1700)
#define USE_CPP11
#endif
#define _XINLINE_ #define _XINLINE_
//#define DOUBELPRICSION //#define DOUBELPRICSION
#ifdef DOUBELPRICSION #ifdef DOUBELPRICSION
#define DTYPE double #define DTYPE double
......
...@@ -171,7 +171,7 @@ XTensor::XTensor(const XTensor &reference) ...@@ -171,7 +171,7 @@ XTensor::XTensor(const XTensor &reference)
As "reference" is constant, we cannot reset reference.data As "reference" is constant, we cannot reset reference.data
here. So we save the ADDRESS of reference.data in here. So we save the ADDRESS of reference.data in
reference.dataP, and do this work by updating "*reference.dataP". reference.dataP, and do this work by updating "*reference.dataP".
This is VERY trick and might not be the best solution :) */ This is VERY tricky and might not be the best solution :) */
*reference.dataP = NULL; *reference.dataP = NULL;
} }
else{ else{
...@@ -193,7 +193,6 @@ XTensor::XTensor(const XTensor &reference) ...@@ -193,7 +193,6 @@ XTensor::XTensor(const XTensor &reference)
} }
/* copy constructor (with right value reference) */ /* copy constructor (with right value reference) */
#ifdef USE_CPP11
XTensor::XTensor(const XTensor &&reference) XTensor::XTensor(const XTensor &&reference)
{ {
Init(); Init();
...@@ -212,7 +211,7 @@ XTensor::XTensor(const XTensor &&reference) ...@@ -212,7 +211,7 @@ XTensor::XTensor(const XTensor &&reference)
As "reference" is constant, we cannot reset reference.data As "reference" is constant, we cannot reset reference.data
here. So we save the ADDRESS of reference.data in here. So we save the ADDRESS of reference.data in
reference.dataP, and do this work by updating "*reference.dataP". reference.dataP, and do this work by updating "*reference.dataP".
This is VERY trick and might not be the best solution :) */ This is VERY tricky and might not be the best solution :) */
*reference.dataP = NULL; *reference.dataP = NULL;
XLink::Replace(&reference, this); XLink::Replace(&reference, this);
...@@ -220,7 +219,6 @@ XTensor::XTensor(const XTensor &&reference) ...@@ -220,7 +219,6 @@ XTensor::XTensor(const XTensor &&reference)
isInit = true; isInit = true;
isTmp = reference.isTmp; isTmp = reference.isTmp;
} }
#endif
/* de-constructor */ /* de-constructor */
XTensor::~XTensor() XTensor::~XTensor()
...@@ -445,7 +443,7 @@ XTensor& XTensor::operator= (const XTensor&& tensor) ...@@ -445,7 +443,7 @@ XTensor& XTensor::operator= (const XTensor&& tensor)
As "reference" is constant, we cannot reset reference.data As "reference" is constant, we cannot reset reference.data
here. So we save the ADDRESS of reference.data in here. So we save the ADDRESS of reference.data in
reference.dataP, and do this work by updating "*reference.dataP". reference.dataP, and do this work by updating "*reference.dataP".
This is VERY trick and might not be the best solution :) */ This is VERY tricky and might not be the best solution :) */
*tensor.dataP = NULL; *tensor.dataP = NULL;
XLink::Replace(&tensor, this); XLink::Replace(&tensor, this);
...@@ -520,6 +518,7 @@ void XTensor::SetDevice(int myDevId, XMem * myMem) ...@@ -520,6 +518,7 @@ void XTensor::SetDevice(int myDevId, XMem * myMem)
{ {
if (myMem != NULL) { if (myMem != NULL) {
FlushToMem(myMem); FlushToMem(myMem);
isInGlobalMem = false;
} }
else { else {
ShowNTErrors("TODO!"); ShowNTErrors("TODO!");
...@@ -1295,6 +1294,21 @@ bool XTensor::Set(DTYPE value, int index[], int size) ...@@ -1295,6 +1294,21 @@ bool XTensor::Set(DTYPE value, int index[], int size)
} }
/* /*
set the value of a cell with its offset in the array
>> value - the value we intend to set
>> offset - the offset in the array
*/
bool XTensor::Set(DTYPE value, int offset)
{
CheckNTErrors(offset >= 0 && offset < unitNum, "Invalid index!");
CheckNTErrors(data != NULL, "Cannot use an uninitialized tensor!");
DTYPE * d = (DTYPE*)data + offset;
return SetToDevice(devID, d, value);
}
/*
set the value of a cell in a 1d tensor set the value of a cell in a 1d tensor
>> value - value we tend to set >> value - value we tend to set
>> i - item offset >> i - item offset
......
...@@ -194,9 +194,7 @@ public: ...@@ -194,9 +194,7 @@ public:
XTensor(const XTensor &reference); XTensor(const XTensor &reference);
/* copy constructor (with right value reference) */ /* copy constructor (with right value reference) */
#ifdef USE_CPP11
XTensor(const XTensor &&reference); XTensor(const XTensor &&reference);
#endif
/* de-constructor */ /* de-constructor */
~XTensor(); ~XTensor();
...@@ -217,9 +215,7 @@ public: ...@@ -217,9 +215,7 @@ public:
XTensor& operator= (const XTensor &tensor); XTensor& operator= (const XTensor &tensor);
/* overloading of the equal-sign (with right value reference) */ /* overloading of the equal-sign (with right value reference) */
#ifdef USE_CPP11
XTensor& operator= (const XTensor &&tensor); XTensor& operator= (const XTensor &&tensor);
#endif
/* overloading of the plus-sign */ /* overloading of the plus-sign */
XTensor operator+ (const XTensor &tensor) const; XTensor operator+ (const XTensor &tensor) const;
...@@ -361,6 +357,9 @@ public: ...@@ -361,6 +357,9 @@ public:
/* set the value of a cell */ /* set the value of a cell */
bool Set(DTYPE value, int index[], int size = -1); bool Set(DTYPE value, int index[], int size = -1);
/* set the value of a cell with its offset in the array */
bool Set(DTYPE value, int offset);
/* set the value of a cell in a 1d tensor */ /* set the value of a cell in a 1d tensor */
bool Set1D(DTYPE value, int i); bool Set1D(DTYPE value, int i);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论