Commit 509c0233 by xuchen

allocate memory in block rather than buffer for avoiding too small buffer size

parent e1ed713a
......@@ -31,10 +31,16 @@ namespace nts{
/* compute dE/dx of a node */
void XFuncGrad::MakeGrad(XTensor * node, bool isEfficient)
{
if (!isEfficient) {
CheckNTErrors(node->grad != NULL, "No gradient found!");
}
else {
CheckNTErrors(!node->isGrad || node->grad != NULL, "No gradient found!");
}
XLink &income = node->income;
int operID = income.typeID;
CheckNTErrors(node->grad != NULL, "No gradient found!");
CheckNTErrors(income.tailNum == 1, "Too many input tensors for the function!");
XTensor * input = income.tails[0];
......@@ -45,7 +51,8 @@ void XFuncGrad::MakeGrad(XTensor * node, bool isEfficient)
XTensor * dedx = input->grad;
XTensor * dedy = output->grad;
XTensor * tmp = NewTensorBufV2(output, output->devID, output->mem);
//XTensor * tmp = NewTensorBufV2(output, output->devID, output->mem);
XTensor * tmp = NewTensor(output);
if (operID == FUNC_HARDTANH)
_HardTanHBackward(output, input, dedy, tmp);
......@@ -70,7 +77,8 @@ void XFuncGrad::MakeGrad(XTensor * node, bool isEfficient)
}
_SumMe(dedx, tmp);
DelTensorBuf(tmp);
//DelTensorBuf(tmp);
DelTensor(tmp);
}
node->visitMark = NODE_FINISHED;
......
......@@ -58,7 +58,9 @@ void XLossGrad::MakeGrad(XTensor * node, bool isEfficient)
gold = income.tails[1];
XTensor* tmp = NewTensorBufV2(output, output->devID, output->mem);
//XTensor * tmp = NewTensorBufV2(output, output->devID, output->mem);
XTensor* tmp = NewTensor(output);
if (operID == LOSS_CROSSENTROPY) {
if (income.tailNum == 3)
padding = income.tails[2];
......@@ -70,7 +72,8 @@ void XLossGrad::MakeGrad(XTensor * node, bool isEfficient)
else {
ShowNTErrors("Wrong activation function type!");
}
DelTensorBuf(tmp);
//DelTensorBuf(tmp);
DelTensor(tmp);
}
node->visitMark = NODE_FINISHED;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论