Commit e02c6b92 by xiaotong

rename MultiplyElementWise as Multiply

parent a91f6809
......@@ -42,7 +42,7 @@
#include "MatrixMULBatchedCPU.h"
#include "Merge.h"
#include "MergeBlockLists.h"
#include "MultiplyElementWise.h"
#include "Multiply.h"
#include "Negate.h"
#include "Normalize.h"
#include "Power.h"
......
......@@ -20,8 +20,8 @@
*/
#include "../XTensor.h"
#include "MultiplyElementWise.h"
#include "MultiplyElementWise.cuh"
#include "Multiply.h"
#include "Multiply.cuh"
namespace nts { // namespace nts(NiuTrans.Tensor)
/*
......@@ -34,7 +34,7 @@ where i is the index of the item
>> alpha - the coefficient
>>
*/
void MultiplyElementWise(XTensor * a, XTensor * b, XTensor * c, int leadingDim, DTYPE alpha)
void Multiply(XTensor * a, XTensor * b, XTensor * c, int leadingDim, DTYPE alpha)
{
int leadingDimRDI = a->order - leadingDim - 1;
CheckNTErrors((a->unitNum <= c->unitNum && b->unitNum <= c->unitNum),
......@@ -43,7 +43,7 @@ void MultiplyElementWise(XTensor * a, XTensor * b, XTensor * c, int leadingDim,
#ifdef USE_CUDA
if (a->devID >= 0 || b->devID >= 0 || c->devID >= 0) {
CudaMultiplyElementWise(a, b, c, leadingDim, alpha);
CudaMultiply(a, b, c, leadingDim, alpha);
return;
}
#endif
......
......@@ -21,8 +21,8 @@
#include "../XDevice.h"
#include "../XTensor.h"
#include "MultiplyElementWise.h"
#include "MultiplyElementWise.cuh"
#include "Multiply.h"
#include "Multiply.cuh"
namespace nts { // namespace nts(NiuTrans.Tensor)
......@@ -120,7 +120,7 @@ where i is the item index
>> alpha - the coefficient
*/
extern "C"
void CudaMultiplyElementWise(XTensor * a, XTensor * b, XTensor * c, int leadingDim, DTYPE alpha)
void CudaMultiply(XTensor * a, XTensor * b, XTensor * c, int leadingDim, DTYPE alpha)
{
int leadingDimRDI = a->order - leadingDim - 1;
CheckNTErrors((a->unitNum <= c->unitNum && b->unitNum <= c->unitNum),
......
......@@ -19,10 +19,10 @@
* $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-24
*/
#ifndef __MULTIPLYELEMENTWISE_CUH__
#define __MULTIPLYELEMENTWISE_CUH__
#ifndef __MULTIPLY_CUH__
#define __MULTIPLY_CUH__
#include "MultiplyElementWise.h"
#include "Multiply.h"
namespace nts { // namespace nts(NiuTrans.Tensor)
......@@ -42,11 +42,11 @@ void KernelMulElementWiseTensorDynamic(DTYPE * a, DTYPE * b, DTYPE * c, DTYPE al
/* element-wise product of two tensors */
extern "C"
void CudaMultiplyElementWise(XTensor * a, XTensor * b, XTensor * c, int leadingDim, DTYPE alpha);
void CudaMultiply(XTensor * a, XTensor * b, XTensor * c, int leadingDim = 0, DTYPE alpha = 0);
#endif // USE_CUDA
} // namespace nts(NiuTrans.Tensor)
#endif // __MULTIPLYELEMENTWISE_CUH__
#endif // __MULTIPLY_CUH__
......@@ -19,8 +19,8 @@
* $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-24
*/
#ifndef __MULTIPLYELEMENTWISE_H__
#define __MULTIPLYELEMENTWISE_H__
#ifndef __MULTIPLY_H__
#define __MULTIPLY_H__
#include "../XTensor.h"
......@@ -28,8 +28,8 @@ namespace nts { // namespace nts(NiuTrans.Tensor)
/* element-wise product of two tensors */
extern "C"
void MultiplyElementWise(XTensor * a, XTensor * b, XTensor * c, int leadingDim, DTYPE alpha = 0);
void Multiply(XTensor * a, XTensor * b, XTensor * c, int leadingDim = 0, DTYPE alpha = 0);
} // namespace nts(NiuTrans.Tensor)
#endif // __MULTIPLYELEMENTWISE_H__
\ No newline at end of file
#endif // __MULTIPLY_H__
\ No newline at end of file
......@@ -23,7 +23,7 @@
#include "Softmax.cuh"
#include "Loss.cuh"
#include "../core/ReduceSum.h"
#include "../core/MultiplyElementWise.h"
#include "../core/Multiply.h"
#include "../core/Unsqueeze.h"
#include "../core/Sum.h"
#include "../XDevice.h"
......@@ -288,7 +288,7 @@ void CudaSoftmaxBackward(XTensor * gold, XTensor * y, XTensor * x,
beta->data = mem->AllocBuf(mem->devID, beta->unitNum * beta->unitSize);
/* \beta = \sum_i (dE/dy_i * y_i) */
MultiplyElementWise(dedy, y, ytmp, 0);
Multiply(dedy, y, ytmp, 0);
ReduceSum(ytmp, beta, leadDim);
/* ytmp = dE/dy_j - \beta */
......@@ -296,7 +296,7 @@ void CudaSoftmaxBackward(XTensor * gold, XTensor * y, XTensor * x,
Sum(dedy, ytmp, ytmp, -1.0F);
/* dE/ds_j = y_j * ytmp = y_j * (dE/dy_j - \beta) */
MultiplyElementWise(y, ytmp, dedx, 0);
Multiply(y, ytmp, dedx, 0);
mem->ReleaseBuf(mem->devID, y->unitNum * y->unitSize);
mem->ReleaseBuf(mem->devID, beta->unitNum * beta->unitSize);
......
......@@ -485,7 +485,7 @@ float GetProb(XTensor &output, XTensor &gold, XTensor * wordProbs)
InitTensor(&probs, &output);
/* probs[i,j] = output[i,j] * gold[i,j] */
MultiplyElementWise(&output, &gold, &probs, 0);
Multiply(&output, &gold, &probs, 0);
/* probability of each word */
XTensor wprobs;
......
......@@ -21,13 +21,13 @@
#include "../XTensor.h"
#include "../XDevice.h"
#include "../core/MultiplyElementWise.h"
#include "../core/Multiply.h"
namespace nts { // namespace nts(NiuTrans.Tensor)
/* case 1: element-wise product of two tensors, c(i) = a(i)*b(i) + \alpha * c(i)
* In this case, (2 * 1) (2 * 1) -> (2 * 1), leadingDim=0, alpha=0.
*/
bool TestMultiplyElementWise1()
bool TestMultiply1()
{
/* a source tensor of size 2 * 1 */
int sOrder1 = 2;
......@@ -77,7 +77,7 @@ bool TestMultiplyElementWise1()
t->SetZeroAll();
/* call multiplyelementwise function */
MultiplyElementWise(s1, s2, t, 0);
Multiply(s1, s2, t, 0);
/* check results */
cpuTest = t->CheckData(answer, tUnitNum);
......@@ -97,7 +97,7 @@ bool TestMultiplyElementWise1()
tGPU->SetZeroAll();
/* call multiplyelementwise function */
MultiplyElementWise(sGPU1, sGPU2, tGPU, 0);
Multiply(sGPU1, sGPU2, tGPU, 0);
/* check results */
gpuTest = tGPU->CheckData(answer, tUnitNum);
......@@ -123,7 +123,7 @@ bool TestMultiplyElementWise1()
/* case 2: element-wise product of two tensors, c(i) = a(i)*b(i) + \alpha * c(i)
* In this case, (2 * 2) (2 * 2) -> (2 * 2), leadingDim=0, alpha=0.
*/
bool TestMultiplyElementWise2()
bool TestMultiply2()
{
/* a source tensor of size (2 * 2) */
int sOrder1 = 2;
......@@ -176,7 +176,7 @@ bool TestMultiplyElementWise2()
t->SetZeroAll();
/* call multiplyelementwise function */
MultiplyElementWise(s1, s2, t, 0);
Multiply(s1, s2, t, 0);
/* check results */
cpuTest = t->CheckData(answer, tUnitNum);
......@@ -196,7 +196,7 @@ bool TestMultiplyElementWise2()
tGPU->SetZeroAll();
/* call multiplyelementwise function */
MultiplyElementWise(sGPU1, sGPU2, tGPU, 0);
Multiply(sGPU1, sGPU2, tGPU, 0);
/* check results */
gpuTest = tGPU->CheckData(answer, tUnitNum);
......@@ -218,7 +218,7 @@ bool TestMultiplyElementWise2()
/* case 3: element-wise product of two tensors, c(i) = a(i)*b(i) + \alpha * c(i)
* In this case, (2 * 2) (2 * 2) -> (2 * 2), leadingDim=1, alpha=0.
*/
bool TestMultiplyElementWise3()
bool TestMultiply3()
{
/* a source tensor of size (2 * 2) */
int sOrder1 = 2;
......@@ -271,7 +271,7 @@ bool TestMultiplyElementWise3()
t->SetZeroAll();
/* call multiplyelementwise function */
MultiplyElementWise(s1, s2, t, 1);
Multiply(s1, s2, t, 1);
/* check results */
cpuTest = t->CheckData(answer, tUnitNum);
......@@ -291,7 +291,7 @@ bool TestMultiplyElementWise3()
tGPU->SetZeroAll();
/* call multiplyelementwise function */
MultiplyElementWise(sGPU1, sGPU2, tGPU, 1);
Multiply(sGPU1, sGPU2, tGPU, 1);
/* check results */
gpuTest = tGPU->CheckData(answer, tUnitNum);
......@@ -317,13 +317,13 @@ TODO!!
/* test for MultiplyElementWise Function */
extern "C"
bool TestMultiplyElementWise()
bool TestMultiply()
{
XPRINT(0, stdout, "[TEST MULTIPLYELEMENTWISE] -------------\n");
bool returnFlag = true, caseFlag = true;
/* case 1 test */
caseFlag = TestMultiplyElementWise1();
caseFlag = TestMultiply1();
if (!caseFlag) {
returnFlag = false;
......@@ -333,7 +333,7 @@ bool TestMultiplyElementWise()
XPRINT(0, stdout, ">> case 1 passed!\n");
/* case 2 test */
caseFlag = TestMultiplyElementWise2();
caseFlag = TestMultiply2();
if (!caseFlag) {
returnFlag = false;
......@@ -343,7 +343,7 @@ bool TestMultiplyElementWise()
XPRINT(0, stdout, ">> case 2 passed!\n");
/* case 3 test */
caseFlag = TestMultiplyElementWise3();
caseFlag = TestMultiply3();
if (!caseFlag) {
returnFlag = false;
......
......@@ -19,16 +19,16 @@
* $Created by: Lin Ye (email: linye2015@outlook.com) 2018-06-15
*/
#ifndef __TEST_MULTIPLYELEMENTWISE_H__
#define __TEST_MULTIPLYELEMENTWISE_H__
#ifndef __TEST_MULTIPLY_H__
#define __TEST_MULTIPLY_H__
#include "../core/MultiplyElementWise.h"
#include "../core/Multiply.h"
namespace nts { // namespace nts(NiuTrans.Tensor)
/* test for MultiplyElementWise Function */
extern "C"
bool TestMultiplyElementWise();
bool TestMultiply();
} // namespace nts(NiuTrans.Tensor)
#endif // __TEST_MULTIPLYELEMENTWISE_H__
......@@ -35,7 +35,7 @@ bool Test()
wrong = !TestMatrixMul2D() || wrong;
wrong = !TestMatrixMulBatchedCPU() || wrong;
wrong = !TestMerge() || wrong;
wrong = !TestMultiplyElementWise() || wrong;
wrong = !TestMultiply() || wrong;
wrong = !TestNegate() || wrong;
wrong = !TestNormalize() || wrong;
//wrong = !TestPower() || wrong;
......
......@@ -28,7 +28,7 @@
#include "TMatrixMul2D.h"
#include "TMatrixMULBatchedCPU.h"
#include "TMerge.h"
#include "TMultiplyElementWise.h"
#include "TMultiply.h"
#include "TNegate.h"
#include "TNormalize.h"
#include "TPower.h"
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论