Commit f408c730 by xiaotong

bug fixes in ReduceSumAll

parent 3bc771f4
...@@ -115,13 +115,6 @@ public: ...@@ -115,13 +115,6 @@ public:
/* read the parameters */ /* read the parameters */
void Read(FILE* file); void Read(FILE* file);
public:
/* clone the model (overloaded method of XModel) */
XModel * Clone(int devID);
/* run the neural network (overloaded method of XModel) */
bool RunSimple(XList * inputs, XList * outputs, XList * golds, XList * losses);
}; };
} }
......
...@@ -56,16 +56,12 @@ void _ReduceSumAll(const XTensor * source, XTensor * target) ...@@ -56,16 +56,12 @@ void _ReduceSumAll(const XTensor * source, XTensor * target)
int dims[1] = {source->unitNum}; int dims[1] = {source->unitNum};
if (source->mem != NULL) XTensor * all = NewTensorV2(1, dims, source->dataType, source->denseRatio, source->devID, source->mem);
source->mem->LockBuf();
XTensor * all = NewTensorBufV2(1, dims, source->dataType, source->denseRatio, source->devID, source->mem);
_CopyValues(source, all); _CopyValues(source, all);
_ReduceSum(all, target, 0); _ReduceSum(all, target, 0);
DelTensorBuf(all); DelTensor(all);
if (source->mem != NULL)
source->mem->UnlockBuf();
} }
/* /*
...@@ -76,9 +72,8 @@ sum all the items of the tensor (It should be optimized!) ...@@ -76,9 +72,8 @@ sum all the items of the tensor (It should be optimized!)
void _ReduceSumAll(const XTensor * source, DTYPE * value) void _ReduceSumAll(const XTensor * source, DTYPE * value)
{ {
int * dimSize = new int[MAX_TENSOR_DIM_NUM]; int * dimSize = new int[MAX_TENSOR_DIM_NUM];
if (source->mem != NULL)
source->mem->LockBuf(); XTensor * target = NewTensorV2(0, dimSize, source->dataType, source->denseRatio, source->devID, source->mem);
XTensor * target = NewTensorBufV2(0, dimSize, source->dataType, source->denseRatio, source->devID, source->mem);
target->SetTMPFlag(); target->SetTMPFlag();
/* call _ReduceSum function */ /* call _ReduceSum function */
...@@ -86,9 +81,7 @@ void _ReduceSumAll(const XTensor * source, DTYPE * value) ...@@ -86,9 +81,7 @@ void _ReduceSumAll(const XTensor * source, DTYPE * value)
*value = target->Get0D(); *value = target->Get0D();
delete[] dimSize; delete[] dimSize;
DelTensorBuf(target); DelTensor(target);
if (source->mem != NULL)
source->mem->UnlockBuf();
} }
/* /*
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论