├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── data ├── fnnlm │ ├── test │ │ └── wsj.test │ └── train │ │ └── wsj.train └── transformer │ ├── train │ └── train.data │ └── valid │ └── valid.data ├── doc ├── manual.md └── pic │ ├── embeding-pos.jpg │ ├── self-attention-tensor-figure.jpg │ ├── self-attention.jpg │ ├── transformer-architecture.jpg │ ├── transformer-training.jpg │ └── transformer-translate.jpg └── source ├── Main.cpp ├── network ├── XBackwardFunc.cpp ├── XBackwardFunc.h ├── XBackwardLoss.cpp ├── XBackwardLoss.h ├── XBackwardMath.cpp ├── XBackwardMath.h ├── XBackwardShape.cpp ├── XBackwardShape.h ├── XNet.cpp ├── XNet.h ├── XNoder.cpp └── XNoder.h ├── sample ├── fnnlm │ ├── FNNLM.cpp │ └── FNNLM.h └── transformer │ ├── Config.cpp │ ├── Config.h │ ├── DataSet.cpp │ ├── DataSet.h │ ├── Decoder.cpp │ ├── Decoder.h │ ├── Encoder.cpp │ ├── Encoder.h │ ├── Model.cpp │ ├── Model.h │ ├── NMT.cpp │ ├── NMT.h │ ├── T2TDecoder.cpp │ ├── T2TDecoder.h │ ├── T2TEncoder.cpp │ ├── T2TEncoder.h │ ├── T2TModel.cpp │ ├── T2TModel.h │ ├── Transformer.cpp │ ├── Transformer.h │ ├── module │ ├── T2TAttention.cpp │ ├── T2TAttention.h │ ├── T2TCommonModules.cpp │ ├── T2TCommonModules.h │ ├── T2TEmbedding.cpp │ ├── T2TEmbedding.h │ ├── T2TFNN.cpp │ ├── T2TFNN.h │ ├── T2TGatedLinearUnit.cpp │ ├── T2TGatedLinearUnit.h │ ├── T2TLayerHistory.cpp │ ├── T2TLayerHistory.h │ ├── T2TLayerNormal.cpp │ ├── T2TLayerNormal.h │ ├── T2TNNUtil.cpp │ ├── T2TNNUtil.h │ ├── T2TOutput.cpp │ ├── T2TOutput.h │ ├── T2TUtility.cpp │ └── T2TUtility.h │ ├── submodel │ ├── Attention.cpp │ ├── Attention.h │ ├── CommonModules.cpp │ ├── CommonModules.h │ ├── Embedding.cpp │ ├── Embedding.h │ ├── FFN.cpp │ ├── FFN.h │ ├── GLU.cpp │ ├── GLU.h │ ├── LayerHistory.cpp │ ├── LayerHistory.h │ ├── LayerNorm.cpp │ ├── LayerNorm.h │ ├── NNUtil.cpp │ ├── NNUtil.h │ ├── Output.cpp │ └── Output.h │ ├── train │ ├── T2TBatchLoader.cpp │ ├── T2TBatchLoader.h │ ├── T2TTrainer.cpp │ ├── T2TTrainer.h │ ├── TrainDataSet.cpp │ ├── TrainDataSet.h │ ├── Trainer.cpp │ └── Trainer.h │ └── translate │ ├── LengthPenalty.cpp │ ├── LengthPenalty.h │ ├── Predictor.cpp │ ├── Predictor.h │ ├── Searcher.cpp │ ├── Searcher.h │ ├── T2TDataSet.cpp │ ├── T2TDataSet.h │ ├── T2TLengthPenalty.cpp │ ├── T2TLengthPenalty.h │ ├── T2TPredictor.cpp │ ├── T2TPredictor.h │ ├── T2TSearch.cpp │ ├── T2TSearch.h │ ├── T2TTranslator.cpp │ ├── T2TTranslator.h │ ├── T2TVocab.cpp │ ├── T2TVocab.h │ ├── TranslateDataSet.cpp │ ├── TranslateDataSet.h │ ├── Translator.cpp │ ├── Translator.h │ ├── Vocab.cpp │ └── Vocab.h ├── tensor ├── XBLAS.cpp ├── XBLAS.h ├── XCall.cpp ├── XCall.h ├── XConfig.cpp ├── XConfig.h ├── XDataType.cpp ├── XDataType.h ├── XDevice.cpp ├── XDevice.h ├── XGlobal.cpp ├── XGlobal.h ├── XHeap.cpp ├── XHeap.h ├── XLink.cpp ├── XLink.h ├── XList.cpp ├── XList.h ├── XMem.cpp ├── XMem.h ├── XName.cpp ├── XName.h ├── XPRunner.cpp ├── XPRunner.h ├── XQueue.cpp ├── XQueue.h ├── XStream.cpp ├── XStream.h ├── XTensor.cpp ├── XTensor.h ├── XThread.cpp ├── XThread.h ├── XUtility.cpp ├── XUtility.h ├── core │ ├── CHeader.h │ ├── arithmetic │ │ ├── Div.cpp │ │ ├── Div.cu │ │ ├── Div.cuh │ │ ├── Div.h │ │ ├── DivDim.cpp │ │ ├── DivDim.cu │ │ ├── DivDim.cuh │ │ ├── DivDim.h │ │ ├── Mask.cpp │ │ ├── Mask.cu │ │ ├── Mask.cuh │ │ ├── Mask.h │ │ ├── MatrixMul.cpp │ │ ├── MatrixMul.h │ │ ├── MatrixMul2D.cpp │ │ ├── MatrixMul2D.cu │ │ ├── MatrixMul2D.cuh │ │ ├── MatrixMul2D.h │ │ ├── MatrixMul2DMultiTheading.cpp │ │ ├── MatrixMul2DMultiTheading.h │ │ ├── MatrixMul2DParallel.cpp │ │ ├── MatrixMul2DParallel.h │ │ ├── MatrixMulBatched.cpp │ │ ├── MatrixMulBatched.h │ │ ├── MulAndShift.cpp │ │ ├── MulAndShift.h │ │ ├── Multiply.cpp │ │ ├── Multiply.cu │ │ ├── Multiply.cuh │ │ ├── Multiply.h │ │ ├── MultiplyDim.cpp │ │ ├── MultiplyDim.cu │ │ ├── MultiplyDim.cuh │ │ ├── MultiplyDim.h │ │ ├── Sub.cpp │ │ ├── Sub.h │ │ ├── Sum.cpp │ │ ├── Sum.cu │ │ ├── Sum.cuh │ │ ├── Sum.h │ │ ├── SumDim.cpp │ │ ├── SumDim.cu │ │ ├── SumDim.cuh │ │ ├── SumDim.h │ │ ├── XTensorBLAS.cpp │ │ ├── XTensorBLAS.cu │ │ └── XTensorBLAS.h │ ├── getandset │ │ ├── ConvertDataType.cpp │ │ ├── ConvertDataType.cu │ │ ├── ConvertDataType.cuh │ │ ├── ConvertDataType.h │ │ ├── OnehotAndIndex.cpp │ │ ├── OnehotAndIndex.cu │ │ ├── OnehotAndIndex.cuh │ │ ├── OnehotAndIndex.h │ │ ├── Select.cpp │ │ ├── Select.cu │ │ ├── Select.cuh │ │ ├── Select.h │ │ ├── SetData.cpp │ │ ├── SetData.cu │ │ ├── SetData.cuh │ │ └── SetData.h │ ├── math │ │ ├── Binary.cpp │ │ ├── Binary.cu │ │ ├── Binary.cuh │ │ ├── Binary.h │ │ ├── Clip.cpp │ │ ├── Clip.cu │ │ ├── Clip.cuh │ │ ├── Clip.h │ │ ├── Compare.cpp │ │ ├── Compare.cu │ │ ├── Compare.cuh │ │ ├── Compare.h │ │ ├── Normalize.cpp │ │ ├── Normalize.cu │ │ ├── Normalize.cuh │ │ ├── Normalize.h │ │ ├── ScaleAndShift.cpp │ │ ├── ScaleAndShift.cu │ │ ├── ScaleAndShift.cuh │ │ ├── ScaleAndShift.h │ │ ├── Unary.cpp │ │ ├── Unary.cu │ │ ├── Unary.cuh │ │ └── Unary.h │ ├── movement │ │ ├── CopyBlocks.cpp │ │ ├── CopyBlocks.h │ │ ├── CopyBlocksInGrid.cpp │ │ ├── CopyBlocksInGrid.cu │ │ ├── CopyBlocksInGrid.cuh │ │ ├── CopyBlocksInGrid.h │ │ ├── CopyBlocksOnSite.cpp │ │ ├── CopyBlocksOnSite.cu │ │ ├── CopyBlocksOnSite.cuh │ │ ├── CopyBlocksOnSite.h │ │ ├── CopyBlocksSelected.cu │ │ ├── CopyBlocksSelected.cuh │ │ ├── CopyData2D.cpp │ │ ├── CopyData2D.h │ │ ├── CopyInGrid.cpp │ │ ├── CopyInGrid.h │ │ ├── CopyIndexed.cpp │ │ ├── CopyIndexed.cu │ │ ├── CopyIndexed.cuh │ │ ├── CopyIndexed.h │ │ ├── CopyValues.cpp │ │ ├── CopyValues.cu │ │ ├── CopyValues.cuh │ │ ├── CopyValues.h │ │ ├── Gather.cpp │ │ ├── Gather.cu │ │ ├── Gather.cuh │ │ ├── Gather.h │ │ ├── Spread.cpp │ │ ├── Spread.cu │ │ ├── Spread.cuh │ │ └── Spread.h │ ├── reduce │ │ ├── ReduceMax.cpp │ │ ├── ReduceMax.cu │ │ ├── ReduceMax.cuh │ │ ├── ReduceMax.h │ │ ├── ReduceMean.cpp │ │ ├── ReduceMean.h │ │ ├── ReduceStandardVariance.h │ │ ├── ReduceSum.cpp │ │ ├── ReduceSum.cu │ │ ├── ReduceSum.cuh │ │ ├── ReduceSum.h │ │ ├── ReduceSumAll.cpp │ │ ├── ReduceSumAll.h │ │ ├── ReduceSumSquared.cpp │ │ ├── ReduceSumSquared.h │ │ ├── ReduceVariance.cpp │ │ ├── ReduceVariance.h │ │ ├── VectorBuffer.cpp │ │ └── VectorBuffer.h │ ├── shape │ │ ├── Concatenate.cpp │ │ ├── Concatenate.h │ │ ├── ConcatenateSolely.cpp │ │ ├── ConcatenateSolely.h │ │ ├── IsSameShaped.cpp │ │ ├── IsSameShaped.h │ │ ├── MakeMergeBlockIndex.cpp │ │ ├── MakeMergeBlockIndex.cu │ │ ├── MakeMergeBlockIndex.cuh │ │ ├── MakeMergeBlockIndex.h │ │ ├── MakeSplitBlockIndex.cpp │ │ ├── MakeSplitBlockIndex.cu │ │ ├── MakeSplitBlockIndex.cuh │ │ ├── MakeSplitBlockIndex.h │ │ ├── Merge.cpp │ │ ├── Merge.h │ │ ├── MergeBlockLists.cpp │ │ ├── MergeBlockLists.cu │ │ ├── MergeBlockLists.cuh │ │ ├── MergeBlockLists.h │ │ ├── Permute.cpp │ │ ├── Permute.h │ │ ├── Reshape.cpp │ │ ├── Reshape.h │ │ ├── Split.cpp │ │ ├── Split.h │ │ ├── Squeeze.cpp │ │ ├── Squeeze.h │ │ ├── Stack.cpp │ │ ├── Stack.h │ │ ├── Transpose.cpp │ │ ├── Transpose.h │ │ ├── Unsqueeze.cpp │ │ ├── Unsqueeze.cu │ │ ├── Unsqueeze.cuh │ │ └── Unsqueeze.h │ ├── sort │ │ ├── Sort.cpp │ │ ├── Sort.cu │ │ ├── Sort.cuh │ │ ├── Sort.h │ │ ├── TopK.cpp │ │ ├── TopK.cu │ │ ├── TopK.cuh │ │ └── TopK.h │ └── utilities │ │ ├── CheckData.cpp │ │ ├── CheckData.h │ │ ├── Float16.cpp │ │ ├── Float16.h │ │ ├── FlushToMem.cpp │ │ ├── FlushToMem.cu │ │ ├── FlushToMem.cuh │ │ ├── FlushToMem.h │ │ ├── SetAscendingOrder.cpp │ │ ├── SetAscendingOrder.cu │ │ ├── SetAscendingOrder.cuh │ │ ├── SetAscendingOrder.h │ │ ├── XMatrixSegment.cpp │ │ └── XMatrixSegment.h ├── function │ ├── Dropout.cpp │ ├── Dropout.cu │ ├── Dropout.cuh │ ├── Dropout.h │ ├── DropoutWithIndex.cpp │ ├── DropoutWithIndex.cu │ ├── DropoutWithIndex.cuh │ ├── DropoutWithIndex.h │ ├── FHeader.h │ ├── HardTanH.cpp │ ├── HardTanH.cu │ ├── HardTanH.cuh │ ├── HardTanH.h │ ├── Identity.cpp │ ├── Identity.h │ ├── LogSoftmax.cpp │ ├── LogSoftmax.cu │ ├── LogSoftmax.cuh │ ├── LogSoftmax.h │ ├── Loss.cpp │ ├── Loss.cu │ ├── Loss.cuh │ ├── Loss.h │ ├── Rectify.cpp │ ├── Rectify.cu │ ├── Rectify.cuh │ ├── Rectify.h │ ├── Sigmoid.cpp │ ├── Sigmoid.cu │ ├── Sigmoid.cuh │ ├── Sigmoid.h │ ├── Softmax.cpp │ ├── Softmax.cu │ ├── Softmax.cuh │ └── Softmax.h ├── loss │ ├── CrossEntropy.cpp │ ├── CrossEntropy.cu │ ├── CrossEntropy.cuh │ ├── CrossEntropy.h │ └── LHeader.h └── test │ ├── TAbsolute.cpp │ ├── TAbsolute.h │ ├── TClip.cpp │ ├── TClip.h │ ├── TCompare.cpp │ ├── TCompare.h │ ├── TConcatenate.cpp │ ├── TConcatenate.h │ ├── TConcatenateSolely.cpp │ ├── TConcatenateSolely.h │ ├── TConvertDataType.cpp │ ├── TConvertDataType.h │ ├── TCopyIndexed.cpp │ ├── TCopyIndexed.h │ ├── TCopyValues.cpp │ ├── TCopyValues.h │ ├── TCos.cpp │ ├── TCos.h │ ├── TCrossEntropy.cpp │ ├── TCrossEntropy.h │ ├── TDiv.cpp │ ├── TDiv.h │ ├── TDivDim.cpp │ ├── TDivDim.h │ ├── TDropout.cpp │ ├── TDropout.h │ ├── TExp.cpp │ ├── TExp.h │ ├── TGather.cpp │ ├── TGather.h │ ├── THardTanH.cpp │ ├── THardTanH.h │ ├── TIdentity.cpp │ ├── TIdentity.h │ ├── TLog.cpp │ ├── TLog.h │ ├── TLogSoftmax.cpp │ ├── TLogSoftmax.h │ ├── TLoss.cpp │ ├── TLoss.h │ ├── TMatrixMul.cpp │ ├── TMatrixMul.h │ ├── TMatrixMul2D.cpp │ ├── TMatrixMul2D.h │ ├── TMatrixMul2DParallel.cpp │ ├── TMatrixMul2DParallel.h │ ├── TMatrixMulBatched.cpp │ ├── TMatrixMulBatched.h │ ├── TMerge.cpp │ ├── TMerge.h │ ├── TMultiply.cpp │ ├── TMultiply.h │ ├── TMultiplyDim.cpp │ ├── TMultiplyDim.h │ ├── TNegate.cpp │ ├── TNegate.h │ ├── TNormalize.cpp │ ├── TNormalize.h │ ├── TPower.cpp │ ├── TPower.h │ ├── TRectify.cpp │ ├── TRectify.h │ ├── TReduceMax.cpp │ ├── TReduceMax.h │ ├── TReduceMean.cpp │ ├── TReduceMean.h │ ├── TReduceSum.cpp │ ├── TReduceSum.h │ ├── TReduceSumAll.cpp │ ├── TReduceSumAll.h │ ├── TReduceSumSquared.cpp │ ├── TReduceSumSquared.h │ ├── TReduceVariance.cpp │ ├── TReduceVariance.h │ ├── TRound.cpp │ ├── TRound.h │ ├── TScaleAndShift.cpp │ ├── TScaleAndShift.h │ ├── TSelect.cpp │ ├── TSelect.h │ ├── TSetAscendingOrder.cpp │ ├── TSetAscendingOrder.h │ ├── TSetData.cpp │ ├── TSetData.h │ ├── TSigmoid.cpp │ ├── TSigmoid.h │ ├── TSign.cpp │ ├── TSign.h │ ├── TSin.cpp │ ├── TSin.h │ ├── TSoftmax.cpp │ ├── TSoftmax.h │ ├── TSort.cpp │ ├── TSort.h │ ├── TSplit.cpp │ ├── TSplit.h │ ├── TSpread.cpp │ ├── TSpread.h │ ├── TSub.cpp │ ├── TSub.h │ ├── TSum.cpp │ ├── TSum.h │ ├── TSumDim.cpp │ ├── TSumDim.h │ ├── TTan.cpp │ ├── TTan.h │ ├── TTopK.cpp │ ├── TTopK.h │ ├── TTranspose.cpp │ ├── TTranspose.h │ ├── TUnsqueeze.cpp │ ├── TUnsqueeze.h │ ├── TXMem.cpp │ ├── TXMem.h │ ├── Test.cpp │ └── Test.h └── train ├── TTrain.cpp ├── TTrain.h ├── XBaseTemplate.cpp ├── XBaseTemplate.h ├── XLeader.cpp ├── XLeader.h ├── XLeaderAllReduce.cpp ├── XLeaderAllReduce.h ├── XLeaderPS.cpp ├── XLeaderPS.h ├── XLearningRate.cpp ├── XLearningRate.h ├── XModel.cpp ├── XModel.h ├── XNNRecord.cpp ├── XNNRecord.h ├── XOptimizer.cpp ├── XOptimizer.h ├── XTensorKeeper.cpp ├── XTensorKeeper.h ├── XTrainer.cpp ├── XTrainer.h ├── XWorker.cpp ├── XWorker.h ├── XWorkerBroadcast.cpp ├── XWorkerBroadcast.h ├── XWorkerCollect.cpp ├── XWorkerCollect.h ├── XWorkerJob.cpp ├── XWorkerJob.h ├── XWorkerUpdate.cpp ├── XWorkerUpdate.h └── optimizer ├── Adam.cpp ├── Adam.h └── OHeader.h /.gitignore: -------------------------------------------------------------------------------- 1 | NiuTrans.Tensor.vcxproj 2 | NiuTrans.Tensor.vcxproj.filters 3 | x64/ 4 | vc140.pdb 5 | NiuTrans.Tensor.vcxproj.user 6 | NiuTrans.Tensor.aps 7 | -------------------------------------------------------------------------------- /data/transformer/train/train.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NiuTrans/NiuTensor/38d1d7668f5cce16de410fb6a01836f47f43af16/data/transformer/train/train.data -------------------------------------------------------------------------------- /data/transformer/valid/valid.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NiuTrans/NiuTensor/38d1d7668f5cce16de410fb6a01836f47f43af16/data/transformer/valid/valid.data -------------------------------------------------------------------------------- /doc/pic/embeding-pos.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NiuTrans/NiuTensor/38d1d7668f5cce16de410fb6a01836f47f43af16/doc/pic/embeding-pos.jpg -------------------------------------------------------------------------------- /doc/pic/self-attention-tensor-figure.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NiuTrans/NiuTensor/38d1d7668f5cce16de410fb6a01836f47f43af16/doc/pic/self-attention-tensor-figure.jpg -------------------------------------------------------------------------------- /doc/pic/self-attention.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NiuTrans/NiuTensor/38d1d7668f5cce16de410fb6a01836f47f43af16/doc/pic/self-attention.jpg -------------------------------------------------------------------------------- /doc/pic/transformer-architecture.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NiuTrans/NiuTensor/38d1d7668f5cce16de410fb6a01836f47f43af16/doc/pic/transformer-architecture.jpg -------------------------------------------------------------------------------- /doc/pic/transformer-training.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NiuTrans/NiuTensor/38d1d7668f5cce16de410fb6a01836f47f43af16/doc/pic/transformer-training.jpg -------------------------------------------------------------------------------- /doc/pic/transformer-translate.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NiuTrans/NiuTensor/38d1d7668f5cce16de410fb6a01836f47f43af16/doc/pic/transformer-translate.jpg -------------------------------------------------------------------------------- /source/network/XBackwardFunc.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2018, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * backward computation for activation function 20 | * $Created by: XIAO Tong (xiaotong@mail.neu.edu.cn) 2018-07-18 21 | * Dingdang won 5 games in the GO training yesterday, hahaha ... 22 | */ 23 | 24 | #include "../tensor/XTensor.h" 25 | #include "../tensor/function/FHeader.h" 26 | 27 | #ifndef __XBACKWARDFUNC_H__ 28 | #define __XBACKWARDFUNC_H__ 29 | 30 | namespace nts{ 31 | 32 | /* this class computes the gradient for activation functions given a node */ 33 | class XFuncGrad 34 | { 35 | public: 36 | /* compute dE/dx of a node */ 37 | static 38 | void MakeGrad(XTensor * node, bool isEfficient); 39 | 40 | /* indicates whether the node is for an activation function */ 41 | static 42 | bool IsFunc(XTensor * node); 43 | }; 44 | 45 | } 46 | 47 | #endif -------------------------------------------------------------------------------- /source/network/XNoder.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2018, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * low-level utilities 20 | * $Created by: XIAO Tong (xiaotong@mail.neu.edu.cn) 2018-07-18 21 | */ 22 | 23 | #include "../tensor/core/CHeader.h" 24 | 25 | #ifndef __XNODER_H__ 26 | #define __XNODER_H__ 27 | 28 | namespace nts{ 29 | 30 | #define NODE_UNFINISHED 0 31 | #define NODE_DOING 1 32 | #define NODE_FINISHED 2 33 | 34 | /* node management */ 35 | class XNoder 36 | { 37 | public: 38 | /* make gradient tensor for a node */ 39 | static 40 | void MakeGrad(XTensor * node); 41 | 42 | /* the node is a leaf node (intput) or not */ 43 | static 44 | bool IsLeaf(XTensor * node); 45 | 46 | /* the node is a root node (output) or not */ 47 | static 48 | bool IsRoot(XTensor * node); 49 | 50 | /* the node keeps the gradinent or not */ 51 | static 52 | bool IsGrad(XTensor * node); 53 | }; 54 | 55 | } 56 | 57 | #endif -------------------------------------------------------------------------------- /source/sample/fnnlm/FNNLM.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NiuTrans/NiuTensor/38d1d7668f5cce16de410fb6a01836f47f43af16/source/sample/fnnlm/FNNLM.h -------------------------------------------------------------------------------- /source/sample/transformer/NMT.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2018, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * Efficient Neural Machine Translation with NiuTrans.Tensor 20 | */ 21 | 22 | #ifndef __NMT_H__ 23 | #define __NMT_H__ 24 | 25 | /* the nmt namespace */ 26 | namespace nmt 27 | { 28 | 29 | /* entrance of the program */ 30 | int NMTMain(int argc, const char** argv); 31 | 32 | } /* end of the nmt namespace */ 33 | 34 | #endif /* __NMT_H__ */ -------------------------------------------------------------------------------- /source/sample/transformer/Transformer.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2020, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * 20 | * An implementation of the transformer system. See more details 21 | * about FNNLM in 22 | * "Attention Is All You Need" by Vaswani et al. 23 | * https://arxiv.org/pdf/1706.03762.pdf 24 | * 25 | * $Created by: XIAO Tong (xiaotong@mail.neu.edu.cn) 2018-07-31 26 | * I start writing the code related to NMT - a long time since my last coding 27 | * work on MT 28 | */ 29 | 30 | #ifndef __TRANSFORMER_H__ 31 | #define __TRANSFORMER_H__ 32 | 33 | #include "../../tensor/XGlobal.h" 34 | #include "../../tensor/XTensor.h" 35 | #include "../../tensor/core/CHeader.h" 36 | 37 | namespace transformer 38 | { 39 | 40 | /* entrance of the program */ 41 | int TransformerMain(int argc, const char** argv); 42 | 43 | } 44 | 45 | #endif -------------------------------------------------------------------------------- /source/sample/transformer/module/T2TCommonModules.cpp: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2020, Natural Language Processing Lab, Northestern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Bei Li (libei_neu@outlook.com) 2020-02-05 20 | * This file includes some common modules of the Transformer model 21 | */ 22 | 23 | #include 24 | 25 | #include "T2TCommonModules.h" 26 | #include "../../../tensor/core/CHeader.h" 27 | #include "../../../tensor/function/FHeader.h" 28 | 29 | namespace transformer 30 | { 31 | 32 | /* 33 | flexible layer normalization for the Transformer 34 | >> input - input tensor 35 | >> ln - the layernorm network 36 | >> prenorm - whether we use prenorm or not 37 | >> before - whether we use layernorm before attention/fnn 38 | >> after - whether we use layernorm after attention/fnn 39 | */ 40 | XTensor LayerNorm(XTensor& input, T2TLN& ln, bool prenorm, bool before, bool after) 41 | { 42 | if (after ^ prenorm) 43 | return ln.Make(input); 44 | else 45 | return input; 46 | } 47 | 48 | } -------------------------------------------------------------------------------- /source/sample/transformer/module/T2TCommonModules.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2020, Natural Language Processing Lab, Northestern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Bei Li (libei_neu@outlook.com) 2020-02-03 20 | */ 21 | 22 | #ifndef __COMMONMODULE_H__ 23 | #define __COMMONMODULE_H__ 24 | 25 | #include "T2TLayerNormal.h" 26 | #include "T2TCommonModules.h" 27 | 28 | using namespace nts; 29 | 30 | namespace transformer 31 | { 32 | 33 | /* the layer normalization module to control pre-norm or post-norm*/ 34 | XTensor LayerNorm(XTensor& input, T2TLN& ln, bool prenorm, bool before, bool after); 35 | 36 | } 37 | 38 | #endif -------------------------------------------------------------------------------- /source/sample/transformer/module/T2TLayerNormal.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2020, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (xiaotong@mail.neu.edu.cn) 2018-07-31 20 | * $Modified by: HU Chi (huchinlp@gmail.com) 2020-04 21 | */ 22 | 23 | #ifndef __T2TLAYERNORMAL_H__ 24 | #define __T2TLAYERNORMAL_H__ 25 | 26 | #include "T2TUtility.h" 27 | #include "../../../network/XNet.h" 28 | 29 | using namespace nts; 30 | 31 | namespace transformer 32 | { 33 | 34 | /* layer normalization: y = norm(x) * w + b 35 | where norm(x) = (x - mean)/standardDeviation */ 36 | class T2TLN 37 | { 38 | public: 39 | /* device id */ 40 | int devID; 41 | 42 | /* the transformation matrix w */ 43 | XTensor w; 44 | 45 | /* the bias term b */ 46 | XTensor b; 47 | 48 | /* dimension size of the model */ 49 | int d; 50 | 51 | public: 52 | /* constructor */ 53 | T2TLN(); 54 | 55 | /* de-constructor */ 56 | ~T2TLN(); 57 | 58 | /* initialize the model */ 59 | void InitModel(T2TConfig& config); 60 | 61 | /* make the network */ 62 | XTensor Make(XTensor& input); 63 | }; 64 | 65 | } 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /source/sample/transformer/module/T2TNNUtil.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2020, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Chi (huchinlp@foxmail.com) 2020-03-21 20 | */ 21 | 22 | #ifndef __T2TNNUTIL_H__ 23 | #define __T2TNNUTIL_H__ 24 | 25 | #include "../../../tensor/XGlobal.h" 26 | #include "../../../tensor/core/CHeader.h" 27 | #include "../../../tensor/function/FHeader.h" 28 | 29 | using namespace nts; 30 | 31 | namespace transformer 32 | { 33 | 34 | /* the gather function for tensor with any dimension */ 35 | XTensor AutoGather(XTensor& src, XTensor& index); 36 | 37 | } 38 | 39 | #endif -------------------------------------------------------------------------------- /source/sample/transformer/submodel/CommonModules.cpp: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2018, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Bei Li (libei_neu@outlook.com) 2020-02-05 20 | * This file includes some common modules of the Transformer model 21 | */ 22 | 23 | #include "CommonModules.h" 24 | #include "../../../tensor/core/CHeader.h" 25 | #include "../../../tensor/function/FHeader.h" 26 | 27 | /* the nmt namespace */ 28 | namespace nmt 29 | { 30 | 31 | /* 32 | flexible layer normalization for the Transformer 33 | >> input - input tensor 34 | >> ln - the layernorm network 35 | >> prenorm - whether we use prenorm or not 36 | >> before - whether we use layernorm before attention/ffn 37 | >> after - whether we use layernorm after attention/ffn 38 | */ 39 | XTensor LN(XTensor& input, LayerNorm& ln, bool prenorm, bool before, bool after) 40 | { 41 | if (after ^ prenorm) 42 | return ln.Run(input); 43 | else 44 | return input; 45 | } 46 | 47 | } /* end of the nmt namespace */ -------------------------------------------------------------------------------- /source/sample/transformer/submodel/CommonModules.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2018, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Bei Li (libei_neu@outlook.com) 2020-02-03 20 | */ 21 | 22 | #ifndef __COMMONMODULE_H__ 23 | #define __COMMONMODULE_H__ 24 | 25 | #include "LayerNorm.h" 26 | #include "CommonModules.h" 27 | 28 | using namespace nts; 29 | 30 | /* the nmt namespace */ 31 | namespace nmt 32 | { 33 | 34 | /* the layer normalization module to control pre-norm or post-norm*/ 35 | XTensor LN(XTensor& input, LayerNorm& ln, bool prenorm, bool before, bool after); 36 | 37 | } /* end of the nmt namespace */ 38 | 39 | #endif -------------------------------------------------------------------------------- /source/sample/transformer/submodel/NNUtil.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2018, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: HU Chi (huchinlp@foxmail.com) 2020-03-21 20 | */ 21 | 22 | #ifndef __NNUTIL_H__ 23 | #define __NNUTIL_H__ 24 | 25 | #include "../../../tensor/XGlobal.h" 26 | #include "../../../tensor/core/CHeader.h" 27 | #include "../../../tensor/function/FHeader.h" 28 | 29 | using namespace nts; 30 | 31 | /* the nmt namespace */ 32 | namespace nmt 33 | { 34 | 35 | /* the gather function for tensor with any dimension */ 36 | XTensor AutoGather(XTensor& src, XTensor& index); 37 | 38 | } /* end of the nmt namespace */ 39 | 40 | #endif /* __NNUTIL_H__ */ -------------------------------------------------------------------------------- /source/sample/transformer/translate/LengthPenalty.cpp: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2018, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (xiaotong@mail.neu.edu.cn) 2019-04-08 20 | * Start of a new week - I just finished several documents. 21 | * Writing document is harder than writing code :) 22 | * $Modified by: HU Chi (huchinlp@gmail.com) 2020-04 23 | */ 24 | 25 | #include "LengthPenalty.h" 26 | 27 | using namespace nts; 28 | 29 | /* the nmt namespace */ 30 | namespace nmt 31 | { 32 | 33 | /* 34 | GNMT-like length penalty: pl = ((5 + n)/(5 + 1))^\alpha 35 | where n = length of the sequence 36 | >> length - length of the sequence 37 | >> alpha - the parameter controls the length preference 38 | << return - length penalty of the sequence 39 | */ 40 | float LengthPenalizer::GNMT(float length, float alpha) 41 | { 42 | float base; 43 | float lp; 44 | 45 | base = (length + 5.0F) / (1.0F + 5.0F); 46 | 47 | lp = (float)pow(base, alpha); 48 | 49 | return lp; 50 | } 51 | 52 | } /* end of the nmt namespace */ -------------------------------------------------------------------------------- /source/sample/transformer/translate/LengthPenalty.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2018, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (xiaotong@mail.neu.edu.cn) 2019-04-08 20 | * Start of a new week - I just finished several documents. 21 | * Writing document is harder than writing code :) 22 | * $Modified by: HU Chi (huchinlp@gmail.com) 2020-04 23 | */ 24 | 25 | #ifndef __LENGTHPENALTY_H__ 26 | #define __LENGTHPENALTY_H__ 27 | 28 | #include "../../../tensor/XTensor.h" 29 | 30 | using namespace nts; 31 | 32 | /* the nmt namespace */ 33 | namespace nmt 34 | { 35 | 36 | /* We intend to penalize short sequences because they have higher score 37 | in product of a sequence of probability-like terms and have more chances 38 | to beat others in search. */ 39 | class LengthPenalizer 40 | { 41 | public: 42 | /* GNMT-like length penalty: pl = ((5 + n)/(5 + 1))^\alpha 43 | where n = length of the sequence */ 44 | static float GNMT(float length, float alpha); 45 | }; 46 | 47 | } /* end of the nmt namespace */ 48 | 49 | #endif /* __LENGTHPENALTY_H__ */ 50 | -------------------------------------------------------------------------------- /source/sample/transformer/translate/T2TLengthPenalty.cpp: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2020, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (xiaotong@mail.neu.edu.cn) 2019-04-08 20 | * Start of a new week - I just finished several documents. 21 | * Writing document is harder than writing code :) 22 | * $Modified by: HU Chi (huchinlp@gmail.com) 2020-04 23 | */ 24 | 25 | #include "T2TLengthPenalty.h" 26 | 27 | using namespace nts; 28 | 29 | namespace transformer 30 | { 31 | 32 | /* 33 | GNMT-like length penalty: pl = ((5 + n)/(5 + 1))^\alpha 34 | where n = length of the sequence 35 | >> length - length of the sequence 36 | >> alpha - the parameter controls the length preference 37 | << return - length penalty of the sequence 38 | */ 39 | float T2TLengthPenalizer::GNMT(float length, float alpha) 40 | { 41 | float base; 42 | float lp; 43 | 44 | base = (length + 5.0F) / (1.0F + 5.0F); 45 | 46 | lp = pow(base, alpha); 47 | 48 | return lp; 49 | } 50 | 51 | } -------------------------------------------------------------------------------- /source/sample/transformer/translate/T2TLengthPenalty.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2020, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (xiaotong@mail.neu.edu.cn) 2019-04-08 20 | * Start of a new week - I just finished several documents. 21 | * Writing document is harder than writing code :) 22 | * $Modified by: HU Chi (huchinlp@gmail.com) 2020-04 23 | */ 24 | 25 | #ifndef __T2TLENGTHPENALTY_H__ 26 | #define __T2TLENGTHPENALTY_H__ 27 | 28 | #include "../module/T2TUtility.h" 29 | #include "../../../tensor/XTensor.h" 30 | 31 | using namespace nts; 32 | 33 | namespace transformer 34 | { 35 | 36 | /* We intend to penalize short sequences because they have higher score 37 | in product of a sequence of probability-like terms and have more chances 38 | to beat others in search. */ 39 | class T2TLengthPenalizer 40 | { 41 | public: 42 | /* GNMT-like length penalty: pl = ((5 + n)/(5 + 1))^\alpha 43 | where n = length of the sequence */ 44 | static float GNMT(float length, float alpha); 45 | }; 46 | 47 | } 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /source/sample/transformer/translate/T2TVocab.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2018, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: HU Chi (huchinlp@foxmail.com) 2020-01-03 20 | */ 21 | 22 | #ifndef __T2TVOCAB_H__ 23 | #define __T2TVOCAB_H__ 24 | 25 | #include 26 | #include 27 | 28 | using namespace std; 29 | 30 | namespace nts { 31 | 32 | /* user-defined symbols */ 33 | #define UNK 0 34 | #define PAD 1 35 | #define SOS 2 36 | #define EOS 2 37 | 38 | /* the vocabulary class */ 39 | struct Vocab 40 | { 41 | /* the start id for words */ 42 | int startID; 43 | 44 | /* size of the vocabulary */ 45 | int vocabSize; 46 | 47 | /* a dict that maps words to ids */ 48 | unordered_map word2id; 49 | 50 | /* a dict that maps ids to words */ 51 | unordered_map id2word; 52 | 53 | /* load a vocabulary from a file */ 54 | void Load(const string& src); 55 | 56 | /* save a vocabulary to a file */ 57 | void Save(const string& src); 58 | 59 | /* copy data from another vocab */ 60 | void CopyFrom(const Vocab& v); 61 | }; 62 | 63 | } 64 | 65 | #endif -------------------------------------------------------------------------------- /source/tensor/XBLAS.cpp: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * 20 | * This is a wrapper of the BLAS (Basic Linear Algebra Subprograms http://www.netlib.org/blas/) 21 | * libraries. By using BLAS, we can access very fast matrix operations although they 22 | * are also implemented in NiuTrans in a native manner. To use BLAS, 23 | * set USE_BLAS. 24 | * 25 | * $Created by: XIAO Tong (xiaotong@mail.neu.edu.cn) 2016-04-08 26 | * 27 | */ 28 | 29 | 30 | /* the nts (NiuTrans.Tensor) namespace */ 31 | namespace nts{ 32 | 33 | 34 | } /* end of the nts (NiuTrans.Tensor) namespace */ -------------------------------------------------------------------------------- /source/tensor/core/arithmetic/DivDim.cuh: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2018, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-08-15 20 | */ 21 | 22 | #ifndef __DIVDIM_CUH__ 23 | #define __DIVDIM_CUH__ 24 | 25 | #include "../../XTensor.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | #ifdef USE_CUDA 30 | 31 | /* 32 | tensor division 33 | c(i) = a/b + \alpha * c 34 | where the size of b is equal to the n-th dimension of a, 35 | i.e., a is divided with b by broadcasting (cuda version) 36 | */ 37 | void _CudaDivDim(const XTensor * a, const XTensor * b, XTensor * c, int n, DTYPE alpha = (DTYPE)0.0); 38 | 39 | #endif 40 | 41 | } // namespace nts(NiuTrans.Tensor) 42 | 43 | #endif // __DIVDIM_CUH__ 44 | -------------------------------------------------------------------------------- /source/tensor/core/arithmetic/Mask.cuh: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2019-04-24 20 | * I'll attend several conferences and workshops in the following weeks - 21 | * busy days :( 22 | */ 23 | 24 | #ifndef __MASK_CUH__ 25 | #define __MASK_CUH__ 26 | 27 | #include "../../XTensor.h" 28 | 29 | namespace nts { // namespace nts(NiuTrans.Tensor) 30 | 31 | #ifdef USE_CUDA 32 | 33 | /* mask entries of a given tensor (cuda version) */ 34 | void _CudaMask(const XTensor * a, const XTensor * mask, XTensor * c = NULL, DTYPE alpha = (DTYPE)1.0); 35 | 36 | #endif // USE_CUDA 37 | 38 | } // namespace nts(NiuTrans.Tensor) 39 | 40 | #endif // __MASK_CUH__ -------------------------------------------------------------------------------- /source/tensor/core/arithmetic/MatrixMul2D.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-24 20 | */ 21 | 22 | #ifndef __MATRIXMUL2D_H__ 23 | #define __MATRIXMUL2D_H__ 24 | 25 | #include "../../XTensor.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* 30 | matrix multiplication (for 2d tensors) 31 | c = trans(a) * trans(b) * alpha + c * beta 32 | where trans() return the transposed matrix if the flag is fired 33 | */ 34 | void _MatrixMul2D(const XTensor * a, MATRIX_TRANS_TYPE transposedA, const XTensor * b, MATRIX_TRANS_TYPE transposedB, XTensor * c, 35 | DTYPE alpha = (DTYPE)1.0, DTYPE beta = 0, XPRunner * parallelRunner = NULL); 36 | 37 | } // namespace nts(NiuTrans.Tensor) 38 | 39 | #endif // __MATRIXMUL2D_H__ 40 | -------------------------------------------------------------------------------- /source/tensor/core/arithmetic/MatrixMul2DMultiTheading.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-24 20 | */ 21 | 22 | #ifndef __MATRIXMUL2DMULTITHEADING_H__ 23 | #define __MATRIXMUL2DMULTITHEADING_H__ 24 | 25 | #include "../../XTensor.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* 30 | matrix multiplication for a block (x1,y1) - (x2,y2) 31 | where (x1,y1) is the upper-left corner and (x2,y2) is the bottom-right corner 32 | */ 33 | void _MatrixMul2DMultiTheading(TensorList * args); 34 | 35 | } // namespace nts(NiuTrans.Tensor) 36 | 37 | #endif // __MATRIXMUL2DMULTITHEADING_H__ -------------------------------------------------------------------------------- /source/tensor/core/arithmetic/MatrixMul2DParallel.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-24 20 | */ 21 | 22 | #ifndef __MATRIXMUL2DPARALLEL_H__ 23 | #define __MATRIXMUL2DPARALLEL_H__ 24 | 25 | #include "../../XTensor.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* 30 | matrix multiplication (for 2d tensors) with multi-threading. 31 | c = trans(a) * trans(b) * alpha + c * beta 32 | where trans() return the transposed matrix if the flag is fired. 33 | */ 34 | void _MatrixMul2DParallel(const XTensor * a, MATRIX_TRANS_TYPE transposedA, const XTensor * b, MATRIX_TRANS_TYPE transposedB, 35 | XTensor * c, DTYPE alpha = (DTYPE)1.0, DTYPE beta = 0, XPRunner * parallelRunner = NULL); 36 | 37 | } // namespace nts(NiuTrans.Tensor) 38 | 39 | #endif // __MATRIXMUL2DPARALLEL_H__ -------------------------------------------------------------------------------- /source/tensor/core/arithmetic/MulAndShift.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: JIANG Yufan (email: jiangyufan2018@outlook.com) 2019-02-27 20 | */ 21 | 22 | #ifndef __MULANDSHIFT_H__ 23 | #define __MULANDSHIFT_H__ 24 | 25 | #include "../../XTensor.h" 26 | #include "../CHeader.h" 27 | 28 | namespace nts { // namespace nts(NiuTrans.Tensor) 29 | 30 | 31 | XTensor MulAndShift(const XTensor &x, const XTensor &w, const XTensor &b, 32 | DTYPE alpha = (DTYPE)1.0, XPRunner * parallelRunner = NULL); 33 | 34 | XTensor MulAndShift(const XTensor &x, MATRIX_TRANS_TYPE transposedX, 35 | const XTensor &w, MATRIX_TRANS_TYPE transposedW, 36 | const XTensor &b, DTYPE alpha = (DTYPE)1.0, XPRunner * parallelRunner = NULL); 37 | 38 | } // namespace nts(NiuTrans.Tensor) 39 | 40 | #endif // __OPERATION_H__ 41 | -------------------------------------------------------------------------------- /source/tensor/core/arithmetic/MultiplyDim.cuh: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2018, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: JIANG Yufan (email: jiangyufan2018@outlook.com) 2018-08-14 20 | */ 21 | 22 | #ifndef __MULTIPLYDIM_CUH__ 23 | #define __MULTIPLYDIM_CUH__ 24 | 25 | #include "../../XTensor.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | #ifdef USE_CUDA 30 | 31 | /* tensor summation a * b + \alpha * c where the size of b is equal to the n-th dimension of a, 32 | i.e., a is multiplied with b by broadcasting (cuda version) */ 33 | void _CudaMultiplyDim(const XTensor * a, const XTensor * b, XTensor * c, int n, DTYPE alpha = 0); 34 | 35 | #endif 36 | 37 | } // namespace nts(NiuTrans.Tensor) 38 | 39 | #endif // __MULTIPLYDIM_CUH__ 40 | -------------------------------------------------------------------------------- /source/tensor/core/arithmetic/Sum.cuh: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-24 20 | */ 21 | 22 | #ifndef __SUM_CUH__ 23 | #define __SUM_CUH__ 24 | 25 | #include "Sum.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | #ifdef USE_CUDA 30 | 31 | /* summation of data arrays (CUDA Kernel) */ 32 | template __global__ 33 | void KernelADD(T * a, T * b, T * c, int size, T beta = (T)1.0); 34 | 35 | /* tensor summation c = a + b * \beta (cuda version) */ 36 | void _CudaSum(const XTensor * a, const XTensor * b, XTensor * c = NULL, DTYPE beta = (DTYPE)1.0); 37 | 38 | /* tensor summation c = a + b * \beta (cuda version) with an input handle */ 39 | void _CudaSumWithHandle(int devID, cublasHandle_t * handle, DTYPE * a, DTYPE * b, DTYPE * c, int size, DTYPE beta = (DTYPE)1.0); 40 | 41 | #endif // USE_CUDA 42 | 43 | } // namespace nts(NiuTrans.Tensor) 44 | 45 | #endif // __SUM_CUH__ 46 | -------------------------------------------------------------------------------- /source/tensor/core/arithmetic/SumDim.cuh: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2018, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-07-29 20 | * &Updated by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-12-26 21 | * Add summation by broadcasting. 22 | */ 23 | 24 | #ifndef __SUMDIM_CUH__ 25 | #define __SUMDIM_CUH__ 26 | 27 | #include "../../XTensor.h" 28 | 29 | namespace nts { // namespace nts(NiuTrans.Tensor) 30 | 31 | #ifdef USE_CUDA 32 | 33 | /* tensor summation c = a + b * \beta where the size of b is equal to the n-th dimension of a, 34 | i.e., a is summed with b by broadcasting (cuda version) */ 35 | void _CudaSumDim(const XTensor * a, const XTensor * b, XTensor * c, int n, DTYPE beta = (DTYPE)1.0); 36 | 37 | #endif 38 | 39 | } // namespace nts(NiuTrans.Tensor) 40 | 41 | #endif // __SUMDIM_CUH__ 42 | -------------------------------------------------------------------------------- /source/tensor/core/getandset/ConvertDataType.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: LI Yinqiao (li.yin.qiao.2012@hotmail.com) 2018-7-11 20 | */ 21 | 22 | #ifndef __CONVERTDATATYPE_H__ 23 | #define __CONVERTDATATYPE_H__ 24 | 25 | #include "../../XTensor.h" 26 | #include "../../XDataType.h" 27 | 28 | namespace nts { // namespace nts(NiuTrans.Tensor) 29 | 30 | /* data conversion (for lower precision computation) */ 31 | void ConvertDataType(int devID, 32 | void * s, TENSOR_DATA_TYPE typeS, 33 | void * t, TENSOR_DATA_TYPE typeT, int size); 34 | 35 | /* convert data type */ 36 | void _ConvertDataType(const XTensor * input, XTensor * output); 37 | 38 | /* convert data type (return an XTensor structure) */ 39 | XTensor ConvertDataType(const XTensor & input, TENSOR_DATA_TYPE dataType); 40 | 41 | /* convert data type */ 42 | void ConvertDataType(const XTensor & input, XTensor & output, TENSOR_DATA_TYPE dataType); 43 | 44 | } // namespace nts(NiuTrans.Tensor) 45 | 46 | #endif // __CONVERTDATATYPE_H__ 47 | -------------------------------------------------------------------------------- /source/tensor/core/getandset/OnehotAndIndex.cuh: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-12-17 20 | */ 21 | 22 | #ifndef __ONEHOTANDINDEX_CUH__ 23 | #define __ONEHOTANDINDEX_CUH__ 24 | 25 | #include "../../XTensor.h" 26 | 27 | namespace nts{ // namespace nts(NiuTrans.Tensor) 28 | 29 | /* convert onehot tensor to index tensor (cuda version) */ 30 | void _CudaOnehotToIndex(const XTensor * onehot, XTensor * index, int size); 31 | 32 | /* convert index tensor to onehot tensor (cuda version) */ 33 | void _CudaIndexToOnehot(const XTensor * index, XTensor * onehot, 34 | int size, float confidence, float lowconfidence); 35 | 36 | } // namespace nts(NiuTrans.Tensor) 37 | 38 | #endif // __ONEHOTANDINDEX_CUH__ -------------------------------------------------------------------------------- /source/tensor/core/getandset/Select.cu: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NiuTrans/NiuTensor/38d1d7668f5cce16de410fb6a01836f47f43af16/source/tensor/core/getandset/Select.cu -------------------------------------------------------------------------------- /source/tensor/core/getandset/Select.cuh: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2018, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-07-04 20 | */ 21 | 22 | #ifndef __SELECT_CUH__ 23 | #define __SELECT_CUH__ 24 | 25 | #include "Select.h" 26 | 27 | namespace nts{ // namespace nts(NiuTrans.Tensor) 28 | 29 | /* generate a tensor with selected data c = select(a) */ 30 | void _CudaSelect(const XTensor * a, XTensor * c, XTensor * indexCPU); 31 | 32 | /* 33 | generate a tensor with selected data in range[low,high] along the given dimension 34 | c = select(a) 35 | */ 36 | void _CudaSelectRange(const XTensor * a, XTensor * c, int dim, int low, int high); 37 | 38 | } // namespace nts(NiuTrans.Tensor) 39 | 40 | #endif // __SELECT_CUH__ -------------------------------------------------------------------------------- /source/tensor/core/math/Binary.cuh: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: JIANG Yufan (email: jiangyufan2018@outlook.com) 2019-04-05 20 | */ 21 | 22 | #ifndef __BINARY_CUH__ 23 | #define __BINARY_CUH__ 24 | 25 | #include "../../XTensor.h" 26 | #include "Binary.h" 27 | 28 | namespace nts { // namespace nts(NiuTrans.Tensor) 29 | 30 | #ifdef USE_CUDA 31 | 32 | /* descale each entry */ 33 | template 34 | void _CudaDescale(const XTensor * a, XTensor * b, T num); 35 | 36 | /* power each entry */ 37 | template 38 | void _CudaPower(const XTensor * a, XTensor * b, T num); 39 | 40 | /* mod each entry */ 41 | template 42 | void _CudaMod(const XTensor * a, XTensor * b, T base); 43 | 44 | /* scale each entry */ 45 | template 46 | void _CudaScale(const XTensor * a, XTensor * b, T num); 47 | 48 | /* shift each entry */ 49 | template 50 | void _CudaShift(const XTensor * a, XTensor * b, T num); 51 | 52 | #endif // USE_CUDA 53 | 54 | } // namespace nts(NiuTrans.Tensor) 55 | 56 | #endif // __BINARY_CUH__ 57 | -------------------------------------------------------------------------------- /source/tensor/core/math/Clip.cuh: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Lin Ye (email: linye2015@outlook.com) 2018-08-03 20 | */ 21 | 22 | #ifndef __CLIP_CUH__ 23 | #define __CLIP_CUH__ 24 | 25 | #include "Clip.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | #ifdef USE_CUDA 30 | 31 | /* set each entry to its clip value (CUDA Kernel) */ 32 | template __global__ 33 | void KernelClip(T * a, T * b, T lower, T upper, int size); 34 | 35 | /* set each entry to its clip value */ 36 | void _CudaClip(const XTensor * a, XTensor * b, DTYPE lower, DTYPE upper); 37 | 38 | /* backward of Clip function (CUDA Kernel) */ 39 | __global__ 40 | void KernelClipBackward(DTYPE * dedy, DTYPE * dedx, DTYPE * y, DTYPE * x, DTYPE lower, DTYPE upper, int size); 41 | 42 | /* backward of Clip function */ 43 | void _CudaClipBackward(XTensor * y, XTensor * x, XTensor * dedy, XTensor * dedx, DTYPE lower, DTYPE upper); 44 | 45 | #endif // USE_CUDA 46 | 47 | } // namespace nts(NiuTrans.Tensor) 48 | 49 | #endif // __CLIP_H__ -------------------------------------------------------------------------------- /source/tensor/core/math/ScaleAndShift.cuh: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-24 20 | */ 21 | 22 | #ifndef __SCALEANDSHIFT_CUH__ 23 | #define __SCALEANDSHIFT_CUH__ 24 | 25 | #include "ScaleAndShift.h" 26 | 27 | namespace nts{ // namespace nts(NiuTrans.Tensor) 28 | 29 | #ifdef USE_CUDA 30 | 31 | /* scale and shift all tensor entires b = a * scale + shift (CUDA Kernel) */ 32 | __global__ 33 | void KernelScaleAndShift(DTYPE * a, DTYPE * b, int size, DTYPE scale, DTYPE shift); 34 | 35 | /* scale and shift all tensor entires b = a * scale + shift (CUDA Kernel) with float16 data type */ 36 | __global__ 37 | void KernelScaleAndShift(__half * a, __half * b, int size, __half scale, __half shift); 38 | 39 | /* scale and shift all tensor entires b = a * scale + shift (cuda version) */ 40 | void _CudaScaleAndShift(const XTensor * a, XTensor * b, DTYPE scale, DTYPE shift); 41 | 42 | #endif // USE_CUDA 43 | 44 | } // namespace nts(NiuTrans.Tensor) 45 | 46 | #endif // __SCALEANDSHIFT_CUH__ -------------------------------------------------------------------------------- /source/tensor/core/movement/CopyBlocks.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-24 20 | */ 21 | 22 | #ifndef __COPYBLOCKS_H__ 23 | #define __COPYBLOCKS_H__ 24 | 25 | #include "../../XTensor.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* copy a number of blocks to target positions */ 30 | void _CopyBlocks(void * source, int unitSize, int blockSize, int blockNum, void * target, int * targetBlocks, XMem * myMem, int devID); 31 | 32 | /* copy a number of blocks from source positions to target positions */ 33 | void _CopyBlocks(void * source, int unitSize, int blockSize, int * sourceBlocks, int blockNum, void * target, int * targetBlocks, XMem * myMem, int devID); 34 | 35 | } // namespace nts(NiuTrans.Tensor) 36 | 37 | #endif // __COPYBLOCKS_H__ 38 | -------------------------------------------------------------------------------- /source/tensor/core/movement/CopyBlocksInGrid.cuh: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-24 20 | */ 21 | 22 | #ifndef __COPYBLOCKSINGRID_CUH__ 23 | #define __COPYBLOCKSINGRID_CUH__ 24 | 25 | #include "../../XTensor.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | #ifdef USE_CUDA 30 | 31 | /* copy data by index */ 32 | void _CudaCopyBlocksInGrid(void * source, int blockSize, int blockNum, int gridNum, void * target, int * index, int unitSize, XMem * myMem); 33 | 34 | #endif // USE_CUDA 35 | 36 | } // namespace nts(NiuTrans.Tensor) 37 | 38 | #endif // __COPYBLOCKSINGRID_CUH__ -------------------------------------------------------------------------------- /source/tensor/core/movement/CopyBlocksInGrid.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-24 20 | */ 21 | 22 | #ifndef __COPYBLOCKSINGRID_H__ 23 | #define __COPYBLOCKSINGRID_H__ 24 | 25 | #include "../../XTensor.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* copy a number of blocks in grid */ 30 | void _CopyBlocksInGrid(void * source, int blockSize, int blockNum, int gridNum, void * target, int * index, int unitSize, bool isIndexOnDev, XMem * myMem); 31 | 32 | } // namespace nts(NiuTrans.Tensor) 33 | 34 | #endif // __COPYBLOCKSINGRID_H__ 35 | -------------------------------------------------------------------------------- /source/tensor/core/movement/CopyBlocksOnSite.cuh: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-24 20 | */ 21 | 22 | #ifndef __COPYBLOCKS_CUH__ 23 | #define __COPYBLOCKS_CUH__ 24 | 25 | #include "../../XTensor.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | #ifdef USE_CUDA 30 | 31 | /* copy a number of blocks to target positions (cuda version) */ 32 | void _CudaCopyBlocks(void * source, int unitSize, int blockSize, int blockNum, void * target, int * targetBlocks, int devID); 33 | 34 | #endif // USE_CUDA 35 | 36 | } // namespace nts(NiuTrans.Tensor) 37 | 38 | #endif // __COPYBLOCKS_CUH__ 39 | -------------------------------------------------------------------------------- /source/tensor/core/movement/CopyBlocksOnSite.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-24 20 | */ 21 | 22 | #ifndef __COPYBLOCKSONSITE_H__ 23 | #define __COPYBLOCKSONSITE_H__ 24 | 25 | #include "../../XTensor.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* copy a number of blocks to target positions (on site) */ 30 | void _CopyBlocksOnSite(void * source, int unitSize, int blockSize, int blockNum, void * target, int * targetBlocks, int devID); 31 | 32 | } // namespace nts(NiuTrans.Tensor) 33 | 34 | #endif // __COPYBLOCKSONSITE_H__ 35 | -------------------------------------------------------------------------------- /source/tensor/core/movement/CopyBlocksSelected.cuh: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-24 20 | */ 21 | 22 | #ifndef __COPYBLOCKSSELECTED_CUH__ 23 | #define __COPYBLOCKSSELECTED_CUH__ 24 | 25 | #include "../../XTensor.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | #ifdef USE_CUDA 30 | 31 | /* copy a number of blocks form source positions to target positions (cuda version) */ 32 | void _CudaCopyBlocksSelected(void * source, int unitSize, int blockSize, int * sourceBlocks, int blockNum, void * target, int * targetBlocks, XMem * myMem, int devID); 33 | 34 | #endif // USE_CUDA 35 | 36 | } // namespace nts(NiuTrans.Tensor) 37 | 38 | #endif // __COPYBLOCKSSELECTED_CUH__ -------------------------------------------------------------------------------- /source/tensor/core/movement/CopyData2D.cpp: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-24 20 | */ 21 | 22 | #include "../../XTensor.h" 23 | #include "CopyData2D.h" 24 | #include "../../XUtility.h" 25 | 26 | namespace nts { // namespace nts(NiuTrans.Tensor) 27 | 28 | /* 29 | copy data blocks by 2d layout 30 | >> s - array of pointers to source data blocks 31 | >> sPitch - source pitch size 32 | >> t - array of pointers to target data blocks 33 | >> tPitch - target pitch size 34 | >> blockNum - number of source blocks 35 | >> mSize - width of each data block to copy 36 | >> n - height of each block 37 | >> myMem - the memory pool 38 | */ 39 | void _CopyData2D(void ** s, int sPitch, void ** t, int tPitch, int blockNum, int mSize, int n, XMem * myMem) 40 | { 41 | int devID = myMem != NULL ? myMem->devID : -1; 42 | 43 | for (int i = 0; i < blockNum; i++) { 44 | XMemCopy2D(t[i], tPitch, devID, s[i], sPitch, devID, mSize, n); 45 | } 46 | } 47 | 48 | } // namespace nts(NiuTrans.Tensor) -------------------------------------------------------------------------------- /source/tensor/core/movement/CopyData2D.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-24 20 | */ 21 | 22 | #ifndef __COPYDATA2D_H__ 23 | #define __COPYDATA2D_H__ 24 | 25 | #include "../../XTensor.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* copy data blocks by 2d layout */ 30 | void _CopyData2D(void ** s, int sPitch, void ** t, int tPitch, int count, int mSize, int n, XMem * myMem); 31 | 32 | } // namespace nts(NiuTrans.Tensor) 33 | 34 | #endif // __COPYDATA2D_H__ 35 | -------------------------------------------------------------------------------- /source/tensor/core/movement/CopyInGrid.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-24 20 | */ 21 | 22 | #ifndef __COPYINGRID_H__ 23 | #define __COPYINGRID_H__ 24 | 25 | #include "../../XTensor.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* copy a number of blocks in grid. i.e., reorder the data blocks in the same memory piece*/ 30 | void _CopyInGrid(const XTensor * s, XTensor * t, int * index, int blockDim, int blockNumInGrid, bool isIndexOnDev = false); 31 | 32 | } // namespace nts(NiuTrans.Tensor) 33 | 34 | #endif // __COPYINGRID_H__ 35 | -------------------------------------------------------------------------------- /source/tensor/core/movement/CopyIndexed.cuh: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-11-30 20 | * Tomorrow is the celebration of the laboratory, I'm so happy! 21 | */ 22 | 23 | #ifndef __CopyIndexed_CUH__ 24 | #define __CopyIndexed_CUH__ 25 | 26 | #include "../../XTensor.h" 27 | #include "CopyIndexed.h" 28 | 29 | namespace nts { // namespace nts(NiuTrans.Tensor) 30 | 31 | #ifdef USE_CUDA 32 | 33 | /* copy selected sub-tensors where indeces are kept in tensors (cuda version) */ 34 | void _CudaCopyIndexed(const XTensor * s, XTensor * t, int dim, 35 | const XTensor * srcIndex, const XTensor * tgtIndex, 36 | int copyNum); 37 | 38 | #endif // USE_CUDA 39 | 40 | } // namespace nts(NiuTrans.Tensor) 41 | 42 | #endif // __CopyIndexed_CUH__ -------------------------------------------------------------------------------- /source/tensor/core/movement/CopyValues.cuh: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-24 20 | */ 21 | 22 | #ifndef __COPYVALUES_CUH__ 23 | #define __COPYVALUES_CUH__ 24 | 25 | #include "../../XTensor.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | #ifdef USE_CUDA 30 | 31 | /* copy all elements from a source matrix to a target matrix */ 32 | void _CudaCopyValues(const XTensor * s, XTensor * t); 33 | 34 | #endif // USE_CUDA 35 | 36 | } // namespace nts(NiuTrans.Tensor) 37 | 38 | #endif // __COPYVALUES_CUH__ -------------------------------------------------------------------------------- /source/tensor/core/movement/CopyValues.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-24 20 | */ 21 | 22 | #ifndef __COPYVALUES_H__ 23 | #define __COPYVALUES_H__ 24 | 25 | #include "../../XTensor.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* copy s to t */ 30 | void _CopyValues(const XTensor * s, XTensor * t); 31 | 32 | /* copy a segment of s to t */ 33 | void _CopyValues(const XTensor * s, const int sBeg, const int sLen, XTensor * t, const int tBeg); 34 | 35 | /* copy s to t (rename _CopyValues) */ 36 | void CopyValues(const XTensor &s, XTensor &t); 37 | 38 | /* 39 | copy s to t (return an XTensor structure) 40 | make a new tensor to keep the result and return it 41 | */ 42 | XTensor CopyValues(const XTensor &s); 43 | 44 | } // namespace nts(NiuTrans.Tensor) 45 | 46 | #endif // __COPYVALUES_H__ 47 | -------------------------------------------------------------------------------- /source/tensor/core/movement/Gather.cuh: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-11-27 20 | */ 21 | 22 | #ifndef __GATHER_CUH__ 23 | #define __GATHER_CUH__ 24 | 25 | #include "../../XTensor.h" 26 | #include "Gather.h" 27 | 28 | namespace nts { // namespace nts(NiuTrans.Tensor) 29 | 30 | #ifdef USE_CUDA 31 | 32 | /* gather indexed sub-tensors(cuda version) */ 33 | void _CudaGather(const XTensor * s, XTensor * t, XTensor * srcIndex); 34 | 35 | void _CudaGather(const XTensor * s, XTensor * t, XTensor * srcIndex,int dim); 36 | 37 | #endif // USE_CUDA 38 | 39 | } // namespace nts(NiuTrans.Tensor) 40 | 41 | #endif // __GATHER_CUH__ -------------------------------------------------------------------------------- /source/tensor/core/movement/Gather.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-09-18 20 | */ 21 | 22 | #ifndef __GATHER_H__ 23 | #define __GATHER_H__ 24 | 25 | #include "../../XTensor.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* gather selected sub-tensors */ 30 | void _Gather(const XTensor * s, XTensor * t, XTensor * srcIndex); 31 | 32 | /* gather selected sub-tensors accoding to the dimension */ 33 | void _Gather(const XTensor * s, XTensor * t, XTensor * srcIndex, int dim); 34 | 35 | /* gather selected sub-tensors (return an XTensor structure) 36 | make a new tensor to keep the result and return it */ 37 | XTensor Gather(XTensor &s, XTensor &index); 38 | 39 | } // namespace nts(NiuTrans.Tensor) 40 | 41 | #endif // __GATHER_H__ -------------------------------------------------------------------------------- /source/tensor/core/reduce/ReduceMax.cuh: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-24 20 | */ 21 | 22 | #ifndef __REDUCEMAX_CUH__ 23 | #define __REDUCEMAX_CUH__ 24 | 25 | #include "ReduceMax.h" 26 | 27 | namespace nts{ // namespace nts(NiuTrans.Tensor) 28 | 29 | #ifdef USE_CUDA 30 | 31 | /* get the max-valued items along a dimension of the tensor (cuda version) */ 32 | void _CudaReduceMax(const XTensor * input, XTensor * output, int dim); 33 | 34 | /* get the min-valued items along a dimension of the tensor (cuda version) */ 35 | void _CudaReduceMin(const XTensor * input, XTensor * output, int dim); 36 | 37 | #endif // USE_CUDA 38 | 39 | } // namespace nts(NiuTrans.Tensor) 40 | 41 | #endif // __REDUCEMAX_CUH__ 42 | 43 | -------------------------------------------------------------------------------- /source/tensor/core/reduce/ReduceMean.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-24 20 | */ 21 | 22 | #ifndef __REDUCEMEAN_H__ 23 | #define __REDUCEMEAN_H__ 24 | 25 | #include "../../XTensor.h" 26 | 27 | namespace nts{ // namespace nts(NiuTrans.Tensor) 28 | 29 | /* 30 | get the mean value along a dimension of the tensor 31 | For a 1-dimensional data array a, mean = (1/n) * sum_i input_i 32 | */ 33 | void _ReduceMean(const XTensor * input, XTensor * output, int dim); 34 | 35 | /* 36 | get the mean value along a dimension of the tensor (return an XTensor structure) 37 | make a new tenosr to keep the result and return it 38 | For a 1-dimensional data array a, mean = (1/n) * sum_i input_i 39 | */ 40 | XTensor ReduceMean(const XTensor &input, int dim); 41 | 42 | /* 43 | get the mean value along a dimension of the tensor 44 | For a 1-dimensional data array a, mean = (1/n) * sum_i input_i 45 | */ 46 | void ReduceMean(const XTensor &input, XTensor &output, int dim); 47 | 48 | } // namespace nts(NiuTrans.Tensor) 49 | 50 | #endif // __REDUCEMEAN_H__ 51 | -------------------------------------------------------------------------------- /source/tensor/core/reduce/ReduceStandardVariance.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-24 20 | */ 21 | 22 | #ifndef __REDUCESTANDARDVARIANCE_H__ 23 | #define __REDUCESTANDARDVARIANCE_H__ 24 | 25 | #include "../../XTensor.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* 30 | standard variance of the items along a dimension of the tensor 31 | For a 1-dimensional data array a, 32 | variance = (1/n * \sum_i (a_i - mean)^2)^0.5 33 | */ 34 | void _ReduceStandardVariance(XTensor * input, XTensor * output, int dim, XTensor * mean); 35 | 36 | } // namespace nts(NiuTrans.Tensor) 37 | 38 | #endif // __REDUCESTANDARDVARIANCE_H__ -------------------------------------------------------------------------------- /source/tensor/core/reduce/ReduceSum.cuh: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-24 20 | */ 21 | 22 | #ifndef __REDUCESUM_CUH__ 23 | #define __REDUCESUM_CUH__ 24 | 25 | #include "ReduceSum.h" 26 | 27 | namespace nts{ // namespace nts(NiuTrans.Tensor) 28 | 29 | #ifdef USE_CUDA 30 | 31 | /* 32 | sum the items along a dimension of the tensor (cuda version). 33 | For a 1-dimensional data array a, 34 | sum = \sum_i ((a_i + shift)^power) if isExp == false 35 | sum = \sum_i exp((a_i + shift)^power) if isExp == true 36 | */ 37 | void _CudaReduceSum(const XTensor * input, XTensor * output, int dim, const XTensor * shift, DTYPE power, bool isExp); 38 | 39 | #endif // USE_CUDA 40 | 41 | } // namespace nts(NiuTrans.Tensor) 42 | 43 | #endif // __REDUCESUM_CUH__ -------------------------------------------------------------------------------- /source/tensor/core/reduce/ReduceSumAll.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: LI Yinqqiao (email: li.yin.qiao.2012@hotmail.com) 2020-01-09 20 | */ 21 | 22 | 23 | #ifndef __REDUCESUMALL_H__ 24 | #define __REDUCESUMALL_H__ 25 | 26 | #include "../../XTensor.h" 27 | 28 | namespace nts{ // namespace nts(NiuTrans.Tensor) 29 | 30 | /* sum all the items of the tensor */ 31 | void _ReduceSumAll(const XTensor * source, XTensor * target); 32 | 33 | /* sum all the items of the tensor */ 34 | void _ReduceSumAll(const XTensor * source, DTYPE * target); 35 | 36 | /* sum all the items of the tensor */ 37 | XTensor ReduceSumAll(const XTensor & source); 38 | 39 | /* sum all the items of the tensor */ 40 | DTYPE ReduceSumAllValue(const XTensor & source); 41 | 42 | } // namespace nts(NiuTrans.Tensor) 43 | 44 | #endif // __REDUCESUMALL_H__ -------------------------------------------------------------------------------- /source/tensor/core/reduce/VectorBuffer.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: ZHANG Yuhao (email: zhangyuhao@stu.neu.edu.cn) 2019-07-23 20 | */ 21 | 22 | #include "../../XGlobal.h" 23 | 24 | namespace nts { 25 | class VectorBuffer { 26 | private: 27 | /* buffer for concluter */ 28 | DTYPE values[32 / sizeof(DTYPE)] = { 0 }; 29 | public: 30 | /* data size for each buffer */ 31 | static int size(); 32 | 33 | /* constructor */ 34 | VectorBuffer(); 35 | 36 | /* constructor */ 37 | VectorBuffer(DTYPE val); 38 | 39 | /* load data */ 40 | static VectorBuffer loadu(const DTYPE* ptr, bool isExp = false, DTYPE power = (DTYPE)1.0F, DTYPE* bias = NULL); 41 | 42 | /* overloading [] */ 43 | const DTYPE& operator[](int idx)const; 44 | 45 | /* overloading + */ 46 | VectorBuffer operator+(const VectorBuffer &a); 47 | 48 | /* conculte the max of two buffer */ 49 | VectorBuffer maxData(const VectorBuffer &a); 50 | 51 | /* conculte the max of two buffer */ 52 | VectorBuffer minData(const VectorBuffer &a); 53 | }; 54 | } -------------------------------------------------------------------------------- /source/tensor/core/shape/ConcatenateSolely.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-24 20 | */ 21 | 22 | #ifndef __CONCATENATESOLELY_H__ 23 | #define __CONCATENATESOLELY_H__ 24 | 25 | #include "../../XTensor.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* concatenate a list of tensors along a given dimension */ 30 | void _ConcatenateSolely(const TensorList * smalls, XTensor * big, int dim); 31 | 32 | } // namespace nts(NiuTrans.Tensor) 33 | 34 | #endif // __CONCATENATESOLELY_H__ 35 | -------------------------------------------------------------------------------- /source/tensor/core/shape/IsSameShaped.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: LI Yinqiao (email: li.yin.qiao.2012@hotmail.com) 2019-10-22 20 | */ 21 | 22 | #ifndef __ISSAMESHAPED_H__ 23 | #define __ISSAMESHAPED_H__ 24 | 25 | #include "../../XTensor.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* judge whether the two matrices are in the same type and size */ 30 | bool _IsSameShaped(const XTensor * a, const XTensor * b); 31 | 32 | /* judge whether the two matrices are in the same type and size */ 33 | bool IsSameShaped(const XTensor & a, const XTensor & b); 34 | 35 | /* judge whether the three matrices are in the same type and size */ 36 | bool _IsSameShaped(const XTensor * a, const XTensor * b, const XTensor * c); 37 | 38 | /* judge whether the three matrices are in the same type and size */ 39 | bool IsSameShaped(const XTensor & a, const XTensor & b, const XTensor & c); 40 | 41 | } // namespace nts(NiuTrans.Tensor) 42 | 43 | #endif // __ISSAMESHAPED_H__ -------------------------------------------------------------------------------- /source/tensor/core/shape/MakeMergeBlockIndex.cuh: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-24 20 | */ 21 | 22 | #ifndef __CUDAMAKEMERGEBLOCKINDEX_CUH__ 23 | #define __CUDAMAKEMERGEBLOCKINDEX_CUH__ 24 | 25 | #include "../../XTensor.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | #ifdef USE_CUDA 30 | 31 | /* set target data block index for the data movement in split */ 32 | void _CudaMakeMergeBlockIndex(int devID, int * blockIndex, int blockNum, int blockNumInMerge, 33 | int splitSizeInGrid, int gridSize, int gridNum); 34 | 35 | #endif // USE_CUDA 36 | 37 | } // namespace nts(NiuTrans.Tensor) 38 | 39 | #endif // __CUDAMAKEMERGEBLOCKINDEX_CUH__ -------------------------------------------------------------------------------- /source/tensor/core/shape/MakeMergeBlockIndex.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-24 20 | */ 21 | 22 | #ifndef __MAKEMERGEBLOCKINDEX_H__ 23 | #define __MAKEMERGEBLOCKINDEX_H__ 24 | 25 | #include "../../XTensor.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* set target data block index for the data movement in merge */ 30 | void _MakeMergeBlockIndex(int * blockIndex, int blockNum, int blockNumInMerge, 31 | int splitSizeInGrid, int gridSize, int gridNum, int devID); 32 | 33 | } // namespace nts(NiuTrans.Tensor) 34 | 35 | #endif // __MAKEMERGEBLOCKINDEX_H__ -------------------------------------------------------------------------------- /source/tensor/core/shape/MakeSplitBlockIndex.cuh: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-24 20 | */ 21 | 22 | #ifndef __MAKESPLITBLOCKINDEX_CUH__ 23 | #define __MAKESPLITBLOCKINDEX_CUH__ 24 | 25 | #include "MakeSplitBlockIndex.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | #ifdef USE_CUDA 30 | 31 | /* set target data block index for the data movement in split */ 32 | void _CudaMakeSplitBlockIndex(int devID, int * blockIndex, int splitNum, int blockSplitSize, int blockNum); 33 | 34 | #endif // USE_CUDA 35 | 36 | } // namespace nts(NiuTrans.Tensor) 37 | 38 | #endif // __MAKESPLITBLOCKINDEX_CUH__ 39 | 40 | -------------------------------------------------------------------------------- /source/tensor/core/shape/MakeSplitBlockIndex.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-24 20 | */ 21 | 22 | #ifndef __MAKESPLITBLOCKINDEX_H__ 23 | #define __MAKESPLITBLOCKINDEX_H__ 24 | 25 | #include "../../XTensor.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* set target data block index for the data movement in split */ 30 | void _MakeSplitBlockIndex(int * blockIndex, int splitNum, int blockSplitSize, int blockNum, int devID); 31 | 32 | } // namespace nts(NiuTrans.Tensor) 33 | 34 | #endif // __MAKESPLITBLOCKINDEX_H__ -------------------------------------------------------------------------------- /source/tensor/core/shape/MergeBlockLists.cuh: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-24 20 | */ 21 | 22 | #ifndef __MERGEBLOCKLISTS_CUH__ 23 | #define __MERGEBLOCKLISTS_CUH__ 24 | 25 | #include "MergeBlockLists.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | #ifdef USE_CUDA 30 | 31 | /* copy a number of blocks (of different sizes) to target positions */ 32 | __global__ 33 | void KernelCopyBlockLists(DTYPE ** sourceList, int * sourceBlockSizes, int sourceBlockNum, DTYPE ** targetList); 34 | 35 | /* merge data by blocks (cuda version) */ 36 | void _CudaMergeBlockLists(const StrList* sourceList, int * blockSizes, int blockNum, void * target, XMem * myMem); 37 | 38 | #endif // USE_CUDA 39 | 40 | } // namespace nts(NiuTrans.Tensor) 41 | 42 | #endif // __MERGEBLOCKLISTS_CUH__ 43 | 44 | -------------------------------------------------------------------------------- /source/tensor/core/shape/MergeBlockLists.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-24 20 | */ 21 | 22 | #ifndef __MERGEBLOCKLISTS_H__ 23 | #define __MERGEBLOCKLISTS_H__ 24 | 25 | #include "../../XTensor.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* merge data by blocks */ 30 | void _MergeBlockLists(const StrList* sourceList, int * blockSizes, int blockNum, void * target, XMem * myMem); 31 | 32 | } // namespace nts(NiuTrans.Tensor) 33 | 34 | #endif // __MERGEBLOCKLISTS_H__ -------------------------------------------------------------------------------- /source/tensor/core/shape/Permute.cpp: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /source/tensor/core/shape/Reshape.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-09-25 20 | */ 21 | 22 | #ifndef __RESHAPE_H__ 23 | #define __RESHAPE_H__ 24 | 25 | #include "../../XTensor.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* reshape the tensor */ 30 | XTensor Reshape(XTensor &s, int order, int * dimSize); 31 | 32 | void Reshape(XTensor &s, XTensor &t, int order, int * dimSize); 33 | 34 | } // namespace nts(NiuTrans.Tensor) 35 | #endif // __RESHAPE_H__ 36 | -------------------------------------------------------------------------------- /source/tensor/core/shape/Stack.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2019-10-13 20 | * It's so cold outside. It's too hard for me to get out. 21 | */ 22 | 23 | #ifndef __STACK_H__ 24 | #define __STACK_H__ 25 | 26 | #include "../../XTensor.h" 27 | 28 | namespace nts { // namespace nts(NiuTrans.Tensor) 29 | 30 | /* stack small tensors into a big tensor along with a dimension */ 31 | void _Stack(const TensorList * smalls, XTensor * t, int dim); 32 | 33 | /* stack small tensors into a big tensor along with a dimension (return an XTensor structure) */ 34 | XTensor Stack(const TensorList &smalls, int dim); 35 | 36 | /* stack small tensors into a big tensor along with a dimension */ 37 | void Stack(const TensorList &smalls, XTensor &t, int dim); 38 | 39 | } // namespace nts(NiuTrans.Tensor) 40 | 41 | #endif // __STACK_H__ -------------------------------------------------------------------------------- /source/tensor/core/shape/Transpose.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-07-05 20 | * It will rain tomorrow - end of the hot days :) 21 | */ 22 | 23 | #ifndef __TRANSPOSE_H__ 24 | #define __TRANSPOSE_H__ 25 | 26 | #include "../../XTensor.h" 27 | 28 | namespace nts { // namespace nts(NiuTrans.Tensor) 29 | 30 | /* 31 | tensor transposition of dimensions i and j 32 | b = transposed(a) 33 | */ 34 | void _Transpose(const XTensor * a, XTensor * b, const int i, const int j); 35 | 36 | /* 37 | tensor transposition of dimensions i and j (return an XTensor structure). 38 | make a new tensor to keep the result and return it. 39 | b = transposed(a) 40 | */ 41 | XTensor Transpose(const XTensor &a, const int i, const int j); 42 | 43 | } // namespace nts(NiuTrans.Tensor) 44 | 45 | #endif // __TRANSPOSE_H__ 46 | -------------------------------------------------------------------------------- /source/tensor/core/shape/Unsqueeze.cuh: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-24 20 | */ 21 | 22 | #ifndef __UNSQUEEZE_CUH__ 23 | #define __UNSQUEEZE_CUH__ 24 | 25 | #include "Unsqueeze.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | #ifdef USE_CUDA 30 | 31 | /* duplicate the data along a given dimension */ 32 | void _CudaUnsqueeze(const XTensor * a, XTensor * b, int dim, int dSize); 33 | 34 | #endif // USE_CUDA 35 | 36 | } // namespace nts(NiuTrans.Tensor) 37 | 38 | #endif // __UNSQUEEZE_CUH__ -------------------------------------------------------------------------------- /source/tensor/core/shape/Unsqueeze.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-24 20 | */ 21 | 22 | #ifndef __UNSQUEEZE_H__ 23 | #define __UNSQUEEZE_H__ 24 | 25 | #include "../../XTensor.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* insert a dimension by copying the blocks for x times 30 | (where x is the size of the inerted dimension) */ 31 | void _Unsqueeze(const XTensor * a, XTensor * b, int dim, int dSize); 32 | 33 | /* insert a dimension by copying the blocks for x times 34 | (where x is the size of the inerted dimension) (return an XTensor structure) 35 | make a new tensor to keep the result and return it */ 36 | XTensor Unsqueeze(const XTensor &a, int dim, int dSize); 37 | 38 | void Unsqueeze(const XTensor &a, XTensor &b, int dim, int dSize); 39 | 40 | } // namespace nts(NiuTrans.Tensor) 41 | 42 | #endif // __UNSQUEEZE_H__ 43 | -------------------------------------------------------------------------------- /source/tensor/core/sort/Sort.cuh: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-24 20 | */ 21 | 22 | #ifndef __SORT_CUH__ 23 | #define __SORT_CUH__ 24 | 25 | #include "Sort.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | #ifdef USE_CUDA 30 | 31 | /* sort the tensor along a given dimension */ 32 | void _CudaSortBig(const XTensor * a, XTensor * b, XTensor * indexA, XTensor * indexB, int dim, int k = -1); 33 | 34 | #endif // USE_CUDA 35 | 36 | } // namespace nts(NiuTrans.Tensor) 37 | 38 | #endif // __SORT_CUH__ 39 | 40 | -------------------------------------------------------------------------------- /source/tensor/core/sort/Sort.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-24 20 | */ 21 | 22 | #ifndef __SORT_H__ 23 | #define __SORT_H__ 24 | 25 | #include "../../XTensor.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* sort the data along a given dimension */ 30 | void _Sort(const XTensor * a, XTensor * b, XTensor * index, int dim); 31 | 32 | /* 33 | sort the data along a given dimension (do it on site) 34 | keep the result in the input tensor a and return nothing 35 | */ 36 | void _SortMe(XTensor * a, XTensor * index, int dim); 37 | 38 | /* 39 | sort the data along a given dimension (do it on site) 40 | keep the result in the input tensor a and return nothing 41 | */ 42 | void SortMe(XTensor & a, XTensor & index, int dim); 43 | 44 | /* 45 | sort the data along a given dimension (return an XTensor structure) 46 | make a new tensor to keep the result and return it 47 | */ 48 | void Sort(XTensor & a, XTensor & b, XTensor & index, int dim); 49 | 50 | } // namespace nts(NiuTrans.Tensor) 51 | 52 | #endif // __SORT_H__ -------------------------------------------------------------------------------- /source/tensor/core/sort/TopK.cuh: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-24 20 | */ 21 | 22 | #ifndef __TOPK_CUH__ 23 | #define __TOPK_CUH__ 24 | 25 | #include "TopK.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | #ifdef USE_CUDA 30 | 31 | /* get the top-k items along a given dimension */ 32 | void _CudaTopK(const XTensor * a, XTensor * b, XTensor * index, int dim, int k, bool isSorted); 33 | 34 | #endif // USE_CUDA 35 | 36 | } // namespace nts(NiuTrans.Tensor) 37 | 38 | #endif // __TOPK_CUH__ -------------------------------------------------------------------------------- /source/tensor/core/sort/TopK.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-24 20 | */ 21 | 22 | #ifndef __TOPK_H__ 23 | #define __TOPK_H__ 24 | 25 | #include "../../XTensor.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* get the top-k items along a given dimension */ 30 | void _TopK(const XTensor * a, XTensor * b, XTensor * index, int dim, int k, bool isSorted = false); 31 | 32 | /* get the top-k items along a given dimension */ 33 | void TopK(XTensor &a, XTensor &b, XTensor &index, int dim, int k, bool isSorted = false); 34 | 35 | } // namespace nts(NiuTrans.Tensor) 36 | 37 | #endif // __TOPK_H__ 38 | -------------------------------------------------------------------------------- /source/tensor/core/utilities/CheckData.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: LI Yinqiao (email: li.yin.qiao.2012@hotmail.com) 2019-10-22 20 | */ 21 | 22 | #ifndef __CHECKDATA_H__ 23 | #define __CHECKDATA_H__ 24 | 25 | #include "../../XTensor.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* check whether the data array is the same as the answer */ 30 | bool _CheckData(const XTensor * tensor, const void * answer, int num, int beg = 0); 31 | 32 | /* check whether the data array is the same as the answer */ 33 | bool _CheckData(const XTensor * tensor, const void * answer, int num, float tolerance, int beg = 0); 34 | 35 | } // namespace nts(NiuTrans.Tensor) 36 | 37 | #endif // __CHECKDATA_H__ -------------------------------------------------------------------------------- /source/tensor/core/utilities/FlushToMem.cpp: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2018, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (xiaotong@mail.neu.edu.cn) 2018-06-22 20 | */ 21 | 22 | #include "../../XUtility.h" 23 | #include "FlushToMem.h" 24 | #include "FlushToMem.cuh" 25 | 26 | namespace nts { // namespace nts(NiuTrans.Tensor) 27 | 28 | /* 29 | flush a list of XTensor to GPU memory 30 | >> mList - list of the tensors 31 | >> devID - target GPU id 32 | >> GPUMem - memory pool for the GPU 33 | */ 34 | void CPUToGPUFlush(TensorList * mList, int devID, XMem * GPUMem) 35 | { 36 | #ifdef USE_CUDA 37 | CudaCPUToGPUFlush(mList, devID, GPUMem); 38 | #endif 39 | } 40 | 41 | /* copy the data from GPU memory to CPU memory */ 42 | void GPUToCPUFlush(XTensor * tensor) 43 | { 44 | #ifdef USE_CUDA 45 | CudaGPUToCPUFlush(tensor); 46 | #endif 47 | } 48 | 49 | } // namespace nts(NiuTrans.Tensor) -------------------------------------------------------------------------------- /source/tensor/core/utilities/FlushToMem.cuh: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: LI Yinqiao (li.yin.qiao.2012@hotmail.com) 2018-06-14 20 | */ 21 | 22 | #ifndef __FLUSHTOMEM_CUH__ 23 | #define __FLUSHTOMEM_CUH__ 24 | 25 | #include "../../XTensor.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | #ifdef USE_CUDA 30 | 31 | /* flush a list of XTensor to GPU memory */ 32 | void CudaCPUToGPUFlush(TensorList * mList, int devID, XMem * GPUMem); 33 | 34 | /* copy the data from GPU memory to CPU memory (memory pool) */ 35 | void CudaGPUToCPUFlush(XTensor * tensor, int devID, XMem * CPUMem); 36 | 37 | /* copy the data from GPU memory to CPU memory ((dataHost)) and do not delete the data */ 38 | void CudaGPUToCPUFlush(XTensor * tensor); 39 | 40 | #endif // USE_CUDA 41 | 42 | } // namespace nts(NiuTrans.Tensor) 43 | 44 | #endif // __FLUSHTOMEM_CUH__ -------------------------------------------------------------------------------- /source/tensor/core/utilities/FlushToMem.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2018, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (xiaotong@mail.neu.edu.cn) 2018-06-22 20 | */ 21 | 22 | #ifndef __FLUSHTOMEM_H__ 23 | #define __FLUSHTOMEM_H__ 24 | 25 | #include "../../XTensor.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* flush a list of XTensor to GPU memory */ 30 | void CPUToGPUFlush(TensorList * mList, int devID, XMem * GPUMem); 31 | 32 | /* copy the data from GPU memory to CPU memory */ 33 | void GPUToCPUFlush(XTensor * tensor); 34 | 35 | } // namespace nts(NiuTrans.Tensor) 36 | 37 | #endif // __FLUSHTOMEM_H__ 38 | -------------------------------------------------------------------------------- /source/tensor/core/utilities/SetAscendingOrder.cuh: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: LI Yinqiao (li.yin.qiao.2012@hotmail.com) 2018-06-14 20 | */ 21 | 22 | #ifndef __SETASCENDINGORDER_CUH__ 23 | #define __SETASCENDINGORDER_CUH__ 24 | 25 | #include "../../XTensor.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | #ifdef USE_CUDA 30 | 31 | /* set the cell to the ascending order along a given dimension */ 32 | void CudaSetAscendingOrder(XTensor * a, int dim); 33 | 34 | #endif // USE_CUDA 35 | 36 | } // namespace nts(NiuTrans.Tensor) 37 | 38 | #endif // __SETASCENDINGORDER_CUH__ -------------------------------------------------------------------------------- /source/tensor/core/utilities/SetAscendingOrder.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: LI Yinqiao (email: li.yin.qiao.2012@hotmail.com) 2019-10-23 20 | */ 21 | 22 | #ifndef __SETASCENDINGORDER_H__ 23 | #define __SETASCENDINGORDER_H__ 24 | 25 | #include "../../XTensor.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* set the cell to the ascending order along a given dimension */ 30 | void SetAscendingOrder(XTensor & tensor, int dim); 31 | 32 | } // namespace nts(NiuTrans.Tensor) 33 | 34 | #endif // __SETASCENDINGORDER_H__ -------------------------------------------------------------------------------- /source/tensor/core/utilities/XMatrixSegment.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-24 20 | */ 21 | 22 | #ifndef __XMATRIXSEGMENT_H__ 23 | #define __XMATRIXSEGMENT_H__ 24 | 25 | #include "../../XTensor.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* segmentation and parallel processing for 2d tensors (i.e., matrices) */ 30 | /* segment a 2d tensor (i.e., matrix) into blocks and run jobs in parallel */ 31 | void RunParallel2D(XPRunner * parallelRunner, void * job, int opNum, int rowNum, int colNum, int argNum, ...); 32 | 33 | /* segment a block into sub-blocks */ 34 | int SegmentTensor2D(int rowNum, int colNum, int blockNum, int * blockIndex); 35 | 36 | /* segment a block into sub-blocks */ 37 | int SegmentTensor2DInRows(int rowNum, int colNum, int blockNum, int * blockIndex); 38 | 39 | } // namespace nts(NiuTrans.Tensor) 40 | 41 | #endif // __XMATRIXSEGMENT_H__ -------------------------------------------------------------------------------- /source/tensor/function/Dropout.cuh: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-09-12 20 | */ 21 | 22 | #ifndef __DROPOUT_CUH__ 23 | #define __DROPOUT_CUH__ 24 | 25 | #include "../XTensor.h" 26 | #include "Loss.h" 27 | 28 | namespace nts{ // namespace nts(NiuTrans.Tensor) 29 | 30 | #ifdef USE_CUDA 31 | 32 | /* dropout function (Cuda version) */ 33 | void _CudaDropout(const XTensor * x, XTensor * y, const XTensor * r, DTYPE scaleFactor); 34 | 35 | /* de/dx (Cuda version) */ 36 | void _CudaDropoutBackward(const XTensor * y, const XTensor * x, 37 | const XTensor * dedy, XTensor * dedx, 38 | const XTensor * mask, DTYPE scaleFactor); 39 | 40 | #endif // USE_CUDA 41 | 42 | } // namespace nts(NiuTrans.Tensor) 43 | 44 | #endif // __DROPOUT_CUH__ -------------------------------------------------------------------------------- /source/tensor/function/DropoutWithIndex.cuh: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Jiang Yufan (email: jiangyufan2018@outlook.com) 2019-03-20 20 | */ 21 | 22 | #ifndef __DROPOUTWITHINDEX_CUH__ 23 | #define __DROPOUTWITHINDEX_CUH__ 24 | 25 | #include "../XTensor.h" 26 | #include "DropoutWithIndex.h" 27 | 28 | namespace nts { // namespace nts(NiuTrans.Tensor) 29 | 30 | #ifdef USE_CUDA 31 | 32 | /* dropout with index (cuda version) */ 33 | void _CudaDropoutWithIndex(const XTensor * x, XTensor * maskIndex, XTensor * c); 34 | 35 | #endif // USE_CUDA 36 | 37 | } // namespace nts(NiuTrans.Tensor) 38 | 39 | #endif // __DROPOUTWITHINDEX_CUH__ 40 | -------------------------------------------------------------------------------- /source/tensor/function/DropoutWithIndex.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Jiang Yufan (email: jiangyufan2018@outlook.com) 2019-03-20 20 | */ 21 | 22 | #ifndef __DROPOUTWITHINDEX_H__ 23 | #define __DROPOUTWITHINDEX_H__ 24 | 25 | #include "../XTensor.h" 26 | 27 | namespace nts { 28 | 29 | void _DropoutWithIndex(const XTensor * x, XTensor * maskIndex, XTensor * c); 30 | 31 | XTensor DropoutWithIndex(const XTensor &x, XTensor &mask, DTYPE scale); 32 | 33 | } // namespace nts(NiuTrans.Tensor) 34 | 35 | #endif // !__DROPOUTWITHINDEX_H__ 36 | 37 | -------------------------------------------------------------------------------- /source/tensor/function/FHeader.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-24 20 | */ 21 | 22 | /* this is a header to include all functions in the "function" workspace */ 23 | 24 | #ifndef __FHEADER_H__ 25 | #define __FHEADER_H__ 26 | 27 | #include "../XTensor.h" 28 | 29 | #include "Dropout.h" 30 | #include "DropoutWithIndex.h" 31 | #include "HardTanH.h" 32 | #include "Identity.h" 33 | #include "LogSoftmax.h" 34 | #include "Loss.h" 35 | #include "Rectify.h" 36 | #include "Sigmoid.h" 37 | #include "Softmax.h" 38 | 39 | #endif // __FHEADER_H__ -------------------------------------------------------------------------------- /source/tensor/function/HardTanH.cuh: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-25 20 | */ 21 | 22 | #ifndef __HARDTANH_CUH__ 23 | #define __HARDTANH_CUH__ 24 | 25 | #include "../XTensor.h" 26 | 27 | namespace nts{ // namespace nts(NiuTrans.Tensor) 28 | 29 | #ifdef USE_CUDA 30 | 31 | /* 32 | rectify function 33 | y = 1 if x > 1 34 | x if -1 <= x <= 1 35 | -1 if x < -1 36 | */ 37 | void _CudaHardTanH(const XTensor * input, XTensor * output); 38 | 39 | /* de/dx (Cuda version) */ 40 | void _CudaHardTanHBackward(XTensor * y, XTensor * x, 41 | XTensor * dedy, XTensor * dedx); 42 | 43 | #endif // USE_CUDA 44 | 45 | } // namespace nts(NiuTrans.Tensor) 46 | 47 | #endif // __HARDTANH_CUH__ -------------------------------------------------------------------------------- /source/tensor/function/HardTanH.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-25 20 | */ 21 | 22 | #ifndef __HARDHANH_H__ 23 | #define __HARDHANH_H__ 24 | 25 | #include "../XTensor.h" 26 | 27 | namespace nts{ // namespace nts(NiuTrans.Tensor) 28 | 29 | #define HTanH HardTanH 30 | 31 | /* 32 | hard tanh function 33 | y = 1 if x > 1 34 | x if -1 <= x <= 1 35 | -1 if x < -1 36 | */ 37 | void _HardTanH(const XTensor * x, XTensor * y); 38 | 39 | /* hard tanh function (return an XTensor structure) */ 40 | XTensor HardTanH(const XTensor &x); 41 | 42 | void HardTanH(const XTensor &x, XTensor &y); 43 | 44 | /* de/dx */ 45 | void _HardTanHBackward(XTensor * y, XTensor * x, 46 | XTensor * dedy, XTensor * dedx); 47 | 48 | } // namespace nts(NiuTrans.Tensor) 49 | 50 | #endif // __HARDHANH_H__ -------------------------------------------------------------------------------- /source/tensor/function/Identity.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-27 20 | */ 21 | 22 | #ifndef __IDENTITY_H__ 23 | #define __IDENTITY_H__ 24 | 25 | #include "../XTensor.h" 26 | 27 | namespace nts{ // namespace nts(NiuTrans.Tensor) 28 | 29 | /* identity function y = x */ 30 | void _Identity(const XTensor * x, XTensor * y); 31 | 32 | /* identity function y = x (return an XTensor structure) */ 33 | XTensor Identity(const XTensor &x); 34 | 35 | void Identity(const XTensor &x, XTensor &y); 36 | 37 | /* de/dx */ 38 | void _IdentityBackward(const XTensor * y, const XTensor * x, 39 | const XTensor * dedy, XTensor * dedx); 40 | 41 | } // namespace nts(NiuTrans.Tensor) 42 | 43 | #endif // __IDENTITY_H__ -------------------------------------------------------------------------------- /source/tensor/function/LogSoftmax.cuh: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-26 20 | */ 21 | 22 | #ifndef __LOGSOFTMAX_CUH__ 23 | #define __LOGSOFTMAX_CUH__ 24 | 25 | #include "../XTensor.h" 26 | #include "Loss.h" 27 | 28 | namespace nts { // namespace nts(NiuTrans.Tensor) 29 | 30 | #ifdef USE_CUDA 31 | 32 | /* log scale softmax y = log(e^x / \sum_{i} e^{x_i}) (Cuda version) */ 33 | void _CudaLogSoftmax(const XTensor * input, XTensor * output, int leadDim); 34 | 35 | /* log scale softmax y = log(e^x / \sum_{i} e^{x_i}) (Cuda version) */ 36 | void _CudaLogSoftmaxSumMax(XTensor * x, XTensor * y, int leadDim, XTensor * sum, XTensor * max); 37 | 38 | /* de/dx (Cuda version) */ 39 | void _CudaLogSoftmaxBackward(XTensor * gold, XTensor * y, XTensor * x, 40 | XTensor * dedy, XTensor * dedx, 41 | XTensor * padding, int leadDim, 42 | LOSS_FUNCTION_NAME lossName); 43 | 44 | #endif // USE_CUDA 45 | 46 | } // namespace nts(NiuTrans.Tensor) 47 | 48 | #endif // __LOGSOFTMAX_CUH__ -------------------------------------------------------------------------------- /source/tensor/function/Rectify.cuh: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-24 20 | */ 21 | 22 | #ifndef __RECTIFY_CUH__ 23 | #define __RECTIFY_CUH__ 24 | 25 | #include "../XTensor.h" 26 | 27 | namespace nts{ // namespace nts(NiuTrans.Tensor) 28 | 29 | #ifdef USE_CUDA 30 | 31 | /* rectify function y = max(0, x) (Cuda version) */ 32 | void _CudaRectify(const XTensor * input, XTensor * output); 33 | 34 | /* de/dx (Cuda version) */ 35 | void _CudaRectifyBackward(XTensor * y, XTensor * x, 36 | XTensor * dedy, XTensor * dedx); 37 | 38 | #endif // USE_CUDA 39 | 40 | } // namespace nts(NiuTrans.Tensor) 41 | 42 | #endif // __RECTIFY_CUH__ -------------------------------------------------------------------------------- /source/tensor/function/Rectify.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-24 20 | */ 21 | 22 | #ifndef __RECTIFY_H__ 23 | #define __RECTIFY_H__ 24 | 25 | #include "../XTensor.h" 26 | 27 | namespace nts{ // namespace nts(NiuTrans.Tensor) 28 | 29 | /* rectify function y = max(0, x) */ 30 | void _Rectify(const XTensor * x, XTensor * y); 31 | 32 | /* rectify function y = max(0, x) (return an XTensor structure) */ 33 | XTensor Rectify(const XTensor &x); 34 | 35 | void Rectify(const XTensor &x, XTensor &y); 36 | 37 | /* de/dx */ 38 | void _RectifyBackward(XTensor * y, XTensor * x, 39 | XTensor * dedy, XTensor * dedx); 40 | 41 | } // namespace nts(NiuTrans.Tensor) 42 | 43 | #endif // __RECTIFY_H__ -------------------------------------------------------------------------------- /source/tensor/function/Sigmoid.cuh: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-25 20 | */ 21 | 22 | #ifndef __SIGMOID_CUH__ 23 | #define __SIGMOID_CUH__ 24 | 25 | #include "../XTensor.h" 26 | 27 | namespace nts{ // namespace nts(NiuTrans.Tensor) 28 | 29 | #ifdef USE_CUDA 30 | 31 | /* sigmoid function y = 1/(1+exp(-x)) (Cuda version) */ 32 | void _CudaSigmoid(const XTensor * input, XTensor * output); 33 | 34 | /* de/dx (Cuda version) */ 35 | void _CudaSigmoidBackward(XTensor * y, XTensor * x, 36 | XTensor * dedy, XTensor * dedx); 37 | 38 | #endif // USE_CUDA 39 | 40 | } // namespace nts(NiuTrans.Tensor) 41 | 42 | #endif // __SIGMOID_CUH__ -------------------------------------------------------------------------------- /source/tensor/function/Sigmoid.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-25 20 | */ 21 | 22 | #ifndef __SIGMOID_H__ 23 | #define __SIGMOID_H__ 24 | 25 | #include "../XTensor.h" 26 | 27 | namespace nts{ // namespace nts(NiuTrans.Tensor) 28 | 29 | /* sigmoid function y = 1/(1+exp(-x)) */ 30 | void _Sigmoid(const XTensor * x, XTensor * y); 31 | 32 | /* sigmoid function y = 1/(1+exp(-x)) (return an XTensor structure) */ 33 | XTensor Sigmoid(const XTensor &x); 34 | 35 | void Sigmoid(const XTensor &x, XTensor &y); 36 | 37 | /* de/dx */ 38 | void _SigmoidBackward(XTensor * y, XTensor * x, 39 | XTensor * dedy, XTensor * dedx); 40 | 41 | } // namespace nts(NiuTrans.Tensor) 42 | 43 | #endif // __SIGMOID_H__ -------------------------------------------------------------------------------- /source/tensor/function/Softmax.cuh: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-27 20 | */ 21 | 22 | #ifndef __SOFTMAX_CUH__ 23 | #define __SOFTMAX_CUH__ 24 | 25 | #include "../XTensor.h" 26 | #include "Loss.h" 27 | 28 | namespace nts { // namespace nts(NiuTrans.Tensor) 29 | 30 | #ifdef USE_CUDA 31 | 32 | /* softmax y = e^x / \sum_{i} e^{x_i} (Cuda version) */ 33 | void _CudaSoftmax(const XTensor * input, XTensor * output, int leadDim); 34 | 35 | /* softmax y = e^x / \sum_{i} e^{x_i} (Cuda version) */ 36 | void _CudaSoftmaxSumMax(const XTensor * x, XTensor * y, int leadDim, XTensor * sum, XTensor * max); 37 | 38 | /* de/dx (Cuda version) */ 39 | void _CudaSoftmaxBackward(XTensor * gold, XTensor * y, XTensor * x, 40 | XTensor * dedy, XTensor * dedx, 41 | XTensor * padding, int leadDim, 42 | LOSS_FUNCTION_NAME lossName); 43 | 44 | #endif // USE_CUDA 45 | 46 | } // namespace nts(NiuTrans.Tensor) 47 | 48 | #endif // __SOFTMAX_CUH__ -------------------------------------------------------------------------------- /source/tensor/function/Softmax.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-04-27 20 | */ 21 | 22 | #ifndef __SOFTMAX_H__ 23 | #define __SOFTMAX_H__ 24 | 25 | #include "../XTensor.h" 26 | #include "Loss.h" 27 | 28 | namespace nts{ // namespace nts(NiuTrans.Tensor) 29 | 30 | /* softmax y = e^x / \sum_{i} e^{x_i} */ 31 | void _Softmax(const XTensor * x, XTensor * y, int leadDim); 32 | 33 | /* softmax y = e^x / \sum_{i} e^{x_i} (return an XTensor structure) */ 34 | XTensor Softmax(const XTensor &x, int leadDim); 35 | 36 | void Softmax(const XTensor &x, XTensor &y, int leadDim); 37 | 38 | /* de/dx */ 39 | void _SoftmaxBackward(XTensor * gold, XTensor * y, XTensor * x, 40 | XTensor * dedy, XTensor * dedx, 41 | XTensor * padding, int leadDim, 42 | LOSS_FUNCTION_NAME lossName); 43 | 44 | } // namespace nts(NiuTrans.Tensor) 45 | 46 | #endif // __SOFTMAX_H__ -------------------------------------------------------------------------------- /source/tensor/loss/LHeader.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2019-4-22 20 | */ 21 | 22 | /* this is a header to include all loss computations in the "loss" workspace */ 23 | 24 | #ifndef __LHEADER_H__ 25 | #define __LHEADER_H__ 26 | 27 | #include "CrossEntropy.h" 28 | 29 | #endif // __LHEADER_H__ -------------------------------------------------------------------------------- /source/tensor/test/TAbsolute.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-07-12 20 | */ 21 | 22 | #ifndef __TEST_ABSOLUTE_H__ 23 | #define __TEST_ABSOLUTE_H__ 24 | 25 | 26 | namespace nts { // namespace nts(NiuTrans.Tensor) 27 | 28 | /* test for Absolute Function */ 29 | bool TestAbsolute(); 30 | 31 | } // namespace nts(NiuTrans.Tensor) 32 | #endif // __TEST_ABSOLUTE_H__ 33 | -------------------------------------------------------------------------------- /source/tensor/test/TClip.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Lin Ye (email: linye2015@outlook.com) 2018-08-03 20 | */ 21 | 22 | #ifndef __TEST_CLIP_H__ 23 | #define __TEST_CLIP_H__ 24 | 25 | #include "../core/math/Clip.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for Clip Function */ 30 | extern "C" 31 | bool TestClip(); 32 | 33 | } // namespace nts(NiuTrans.Tensor) 34 | #endif // __TEST_CLIP_H__ 35 | -------------------------------------------------------------------------------- /source/tensor/test/TCompare.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-12-10 20 | */ 21 | 22 | #ifndef __TEST_Compare_H__ 23 | #define __TEST_Compare_H__ 24 | 25 | 26 | namespace nts { // namespace nts(NiuTrans.Tensor) 27 | 28 | /* test for Compare Function */ 29 | bool TestCompare(); 30 | 31 | } // namespace nts(NiuTrans.Tensor) 32 | 33 | #endif // __TEST_Compare_H__ 34 | -------------------------------------------------------------------------------- /source/tensor/test/TConcatenate.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Lin Ye (email: linye2015@outlook.com) 2018-06-14 20 | */ 21 | 22 | #ifndef __TEST_CONCATENATE_H__ 23 | #define __TEST_CONCATENATE_H__ 24 | 25 | #include "../core/shape/Concatenate.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for Concatenate Function */ 30 | bool TestConcatenate(); 31 | 32 | } // namespace nts(NiuTrans.Tensor) 33 | #endif // __TEST_CONCATENATE_H__ 34 | -------------------------------------------------------------------------------- /source/tensor/test/TConcatenateSolely.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Lin Ye (email: linye2015@outlook.com) 2018-06-14 20 | */ 21 | 22 | #ifndef __TEST_CONCATENATESOLELY_H__ 23 | #define __TEST_CONCATENATESOLELY_H__ 24 | 25 | #include "../core/shape/ConcatenateSolely.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for ConcatenateSolely Function */ 30 | bool TestConcatenateSolely(); 31 | 32 | } // namespace nts(NiuTrans.Tensor) 33 | #endif // __TEST_CONCATENATESOLELY_H__ 34 | -------------------------------------------------------------------------------- /source/tensor/test/TConvertDataType.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-07-12 20 | */ 21 | 22 | #ifndef __TEST_CONVERTDATATYPE_H__ 23 | #define __TEST_CONVERTDATATYPE_H__ 24 | 25 | #include "../core/getandset/ConvertDataType.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for ConvertDataType Function */ 30 | bool TestConvertDataType(); 31 | 32 | } // namespace nts(NiuTrans.Tensor) 33 | #endif // __TEST_CONVERTDATATYPE_H__ 34 | -------------------------------------------------------------------------------- /source/tensor/test/TCopyIndexed.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-06-27 20 | */ 21 | 22 | #ifndef __TEST_COPYINDEXED_H__ 23 | #define __TEST_COPYINDEXED_H__ 24 | 25 | #include "../core/movement/CopyIndexed.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for CopyIndexed Function */ 30 | bool TestCopyIndexed(); 31 | 32 | } // namespace nts(NiuTrans.Tensor) 33 | #endif // __TEST_COPYINDEXED_H__ 34 | -------------------------------------------------------------------------------- /source/tensor/test/TCopyValues.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-06-27 20 | */ 21 | 22 | #ifndef __TEST_COPYVALUES_H__ 23 | #define __TEST_COPYVALUES_H__ 24 | 25 | #include "../core/movement/CopyValues.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for CopyValues Function */ 30 | bool TestCopyValues(); 31 | 32 | } // namespace nts(NiuTrans.Tensor) 33 | #endif // __TEST_COPYVALUES_H__ 34 | -------------------------------------------------------------------------------- /source/tensor/test/TCrossEntropy.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-09-17 20 | */ 21 | 22 | #ifndef __TEST_CROSSENTROPY_H__ 23 | #define __TEST_CROSSENTROPY_H__ 24 | 25 | namespace nts { // namespace nts(NiuTrans.Tensor) 26 | 27 | /* test for CrossEntropy Function */ 28 | bool TestCrossEntropy(); 29 | 30 | } // namespace nts(NiuTrans.Tensor) 31 | #endif // __TEST_CROSSENTROPY_H__ 32 | -------------------------------------------------------------------------------- /source/tensor/test/TDiv.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-08-01 20 | */ 21 | 22 | #ifndef __TEST_DIV_H__ 23 | #define __TEST_DIV_H__ 24 | 25 | #include "../core/arithmetic/Div.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for Div Function */ 30 | extern "C" 31 | bool TestDiv(); 32 | 33 | } // namespace nts(NiuTrans.Tensor) 34 | 35 | #endif // __TEST_DIV_H__ 36 | -------------------------------------------------------------------------------- /source/tensor/test/TDivDim.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-08-14 20 | */ 21 | 22 | #ifndef __TEST_DIVDIM_H__ 23 | #define __TEST_DIVDIM_H__ 24 | 25 | #include "../core/arithmetic/DivDim.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for DivDim Function */ 30 | bool TestDivDim(); 31 | 32 | } // namespace nts(NiuTrans.Tensor) 33 | #endif // __TEST_DIVDIM_H__ 34 | -------------------------------------------------------------------------------- /source/tensor/test/TDropout.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-09-12 20 | */ 21 | 22 | #ifndef __TEST_DROPOUT_H__ 23 | #define __TEST_DROPOUT_H__ 24 | 25 | #include "../function/Dropout.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for Dropout Function */ 30 | bool TestDropout(); 31 | 32 | } // namespace nts(NiuTrans.Tensor) 33 | #endif // __TEST_DROPOUT_H__ 34 | -------------------------------------------------------------------------------- /source/tensor/test/TExp.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-07-31 20 | */ 21 | 22 | #ifndef __TEST_EXP_H__ 23 | #define __TEST_EXP_H__ 24 | 25 | namespace nts { // namespace nts(NiuTrans.Tensor) 26 | 27 | /* test for Exp Function */ 28 | bool TestExp(); 29 | 30 | } // namespace nts(NiuTrans.Tensor) 31 | #endif // __TEST_EXP_H__ 32 | -------------------------------------------------------------------------------- /source/tensor/test/TGather.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-09-18 20 | */ 21 | 22 | #ifndef __TEST_GATHER_H__ 23 | #define __TEST_GATHER_H__ 24 | 25 | #include "../core/movement/Gather.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for Gather Function */ 30 | bool TestGather(); 31 | 32 | } // namespace nts(NiuTrans.Tensor) 33 | #endif // __TEST_GATHER_H__ 34 | -------------------------------------------------------------------------------- /source/tensor/test/THardTanH.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Lin Ye (email: linye2015@outlook.com) 2018-06-20 20 | */ 21 | 22 | #ifndef __TEST_THARDTANH_H__ 23 | #define __TEST_THARDTANH_H__ 24 | 25 | #include "../function/HardTanH.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for HardTanH Function */ 30 | bool TestHardTanH(); 31 | 32 | } // namespace nts(NiuTrans.Tensor) 33 | #endif // __TEST_HARDTANH_H__ 34 | -------------------------------------------------------------------------------- /source/tensor/test/TIdentity.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-06-29 20 | */ 21 | 22 | #ifndef __TEST_IDENTITY_H__ 23 | #define __TEST_IDENTITY_H__ 24 | 25 | #include "../function/Identity.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for Identity Function */ 30 | bool TestIdentity(); 31 | 32 | } // namespace nts(NiuTrans.Tensor) 33 | #endif // __TEST_IDENTITY_H__ 34 | -------------------------------------------------------------------------------- /source/tensor/test/TLog.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-07-12 20 | */ 21 | 22 | #ifndef __TEST_LOG_H__ 23 | #define __TEST_LOG_H__ 24 | 25 | namespace nts { // namespace nts(NiuTrans.Tensor) 26 | 27 | /* test for Log Function */ 28 | bool TestLog(); 29 | 30 | } // namespace nts(NiuTrans.Tensor) 31 | #endif // __TEST_LOG_H__ 32 | -------------------------------------------------------------------------------- /source/tensor/test/TLogSoftmax.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-07-02 20 | */ 21 | 22 | #ifndef __TEST_LOGSOFTMAX_H__ 23 | #define __TEST_LOGSOFTMAX_H__ 24 | 25 | #include "../function/LogSoftmax.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for LogSoftmax Function */ 30 | bool TestLogSoftmax(); 31 | 32 | } // namespace nts(NiuTrans.Tensor) 33 | #endif // __TEST_LOGSOFTMAX_H__ 34 | -------------------------------------------------------------------------------- /source/tensor/test/TLoss.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: LI Yinqiao (li.yin.qiao.2012@hotmail.com) 2018-04-30 20 | */ 21 | 22 | #ifndef __TEST_LOSS_H__ 23 | #define __TEST_LOSS_H__ 24 | 25 | #include "../function/Loss.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for Loss Function */ 30 | bool TestLoss(); 31 | 32 | } // namespace nts(NiuTrans.Tensor) 33 | #endif // __TEST_LOSS_H__ 34 | -------------------------------------------------------------------------------- /source/tensor/test/TMatrixMul.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-06-14 20 | */ 21 | 22 | #ifndef __TEST_MATRIXMUL_H__ 23 | #define __TEST_MATRIXMUL_H__ 24 | 25 | #include "../core/arithmetic/MatrixMul.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for MatrixMul Function */ 30 | bool TestMatrixMul(); 31 | 32 | } // namespace nts(NiuTrans.Tensor) 33 | #endif // __TEST_MATRIXMUL_H__ 34 | -------------------------------------------------------------------------------- /source/tensor/test/TMatrixMul2D.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-06-15 20 | */ 21 | 22 | #ifndef __TEST_MATRIXMUL2D_H__ 23 | #define __TEST_MATRIXMUL2D_H__ 24 | 25 | #include "../core/arithmetic/MatrixMul2D.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for MatrixMul2D Function */ 30 | bool TestMatrixMul2D(); 31 | 32 | } // namespace nts(NiuTrans.Tensor) 33 | #endif // __TEST_MATRIXMUL2D_H__ 34 | -------------------------------------------------------------------------------- /source/tensor/test/TMatrixMul2DParallel.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-07-06 20 | */ 21 | 22 | #ifndef __TEST_MATRIXMUL2DPARALLEL_H__ 23 | #define __TEST_MATRIXMUL2DPARALLEL_H__ 24 | 25 | #include "../core/arithmetic/MatrixMul2DParallel.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for MatrixMul2DParallel Function */ 30 | bool TestMatrixMul2DParallel(); 31 | 32 | } // namespace nts(NiuTrans.Tensor) 33 | #endif // __TEST_MATRIXMUL2DPARALLEL_H__ 34 | -------------------------------------------------------------------------------- /source/tensor/test/TMatrixMulBatched.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-06-15 20 | */ 21 | 22 | #ifndef __TEST_MATRIXMULBATCHED_H__ 23 | #define __TEST_MATRIXMULBATCHED_H__ 24 | 25 | #include "../core/arithmetic/MatrixMulBatched.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for MatrixMulBatched Function */ 30 | extern "C" 31 | bool TestMatrixMulBatched(); 32 | 33 | } // namespace nts(NiuTrans.Tensor) 34 | #endif // __TEST_MATRIXMULBATCHED_H__ 35 | -------------------------------------------------------------------------------- /source/tensor/test/TMerge.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-06-13 20 | */ 21 | 22 | #ifndef __TEST_MERGE_H__ 23 | #define __TEST_MERGE_H__ 24 | 25 | #include "../core/shape/Merge.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for Merge Function */ 30 | extern "C" 31 | bool TestMerge(); 32 | 33 | } // namespace nts(NiuTrans.Tensor) 34 | #endif // __TEST_MERGE_H__ 35 | -------------------------------------------------------------------------------- /source/tensor/test/TMultiply.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Lin Ye (email: linye2015@outlook.com) 2018-06-15 20 | */ 21 | 22 | #ifndef __TEST_MULTIPLY_H__ 23 | #define __TEST_MULTIPLY_H__ 24 | 25 | #include "../core/arithmetic/Multiply.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for Multiply Function */ 30 | extern "C" 31 | bool TestMultiply(); 32 | 33 | } // namespace nts(NiuTrans.Tensor) 34 | 35 | #endif // __TEST_MULTIPLY_H__ 36 | -------------------------------------------------------------------------------- /source/tensor/test/TMultiplyDim.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-07-30 20 | */ 21 | 22 | #ifndef __TEST_MULTIPLYDIM_H__ 23 | #define __TEST_MULTIPLYDIM_H__ 24 | 25 | #include "../core/arithmetic/MultiplyDim.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for MultiplyDim Function */ 30 | bool TestMultiplyDim(); 31 | 32 | } // namespace nts(NiuTrans.Tensor) 33 | #endif // __TEST_MULTIPLYDIM_H__ -------------------------------------------------------------------------------- /source/tensor/test/TNegate.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Lin Ye (email: linye2015@outlook.com) 2018-06-14 20 | */ 21 | 22 | #ifndef __TEST_NEGATE_H__ 23 | #define __TEST_NEGATE_H__ 24 | 25 | #include "../core/math/Unary.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for Negate Function */ 30 | extern "C" 31 | bool TestNegate(); 32 | 33 | } // namespace nts(NiuTrans.Tensor) 34 | #endif // __TEST_NEGATE_H__ 35 | -------------------------------------------------------------------------------- /source/tensor/test/TNormalize.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Lin Ye (email: linye2015@outlook.com) 2018-06-20 20 | */ 21 | 22 | #ifndef __TEST_NORMALIZE_H__ 23 | #define __TEST_NORMALIZE_H__ 24 | 25 | #include "../core/math/Normalize.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for Normalize Function */ 30 | extern "C" 31 | bool TestNormalize(); 32 | 33 | } // namespace nts(NiuTrans.Tensor) 34 | #endif // __TEST_NORMALIZE_H__ 35 | -------------------------------------------------------------------------------- /source/tensor/test/TPower.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Lin Ye (email: linye2015@outlook.com) 2018-06-15 20 | */ 21 | 22 | #ifndef __TEST_POWER_H__ 23 | #define __TEST_POWER_H__ 24 | 25 | namespace nts { // namespace nts(NiuTrans.Tensor) 26 | 27 | /* test for Power Function */ 28 | extern "C" 29 | bool TestPower(); 30 | 31 | } // namespace nts(NiuTrans.Tensor) 32 | #endif // __TEST_POWER_H__ 33 | -------------------------------------------------------------------------------- /source/tensor/test/TRectify.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Lin Ye (email: linye2015@outlook.com) 2018-06-14 20 | */ 21 | 22 | #ifndef __TEST_RECTIFY_H__ 23 | #define __TEST_RECTIFY_H__ 24 | 25 | #include "../function/Rectify.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for Rectify Function */ 30 | extern "C" 31 | bool TestRectify(); 32 | 33 | } // namespace nts(NiuTrans.Tensor) 34 | #endif // __TEST_RECTIFY_H__ 35 | -------------------------------------------------------------------------------- /source/tensor/test/TReduceMax.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-06-30 20 | */ 21 | 22 | #ifndef __TEST_REDUCEMAX_H__ 23 | #define __TEST_REDUCEMAX_H__ 24 | 25 | #include "../core/reduce/ReduceMax.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for ReduceMax Function */ 30 | extern "C" 31 | bool TestReduceMax(); 32 | 33 | } // namespace nts(NiuTrans.Tensor) 34 | #endif // __TEST_REDUCEMAX_H__ 35 | -------------------------------------------------------------------------------- /source/tensor/test/TReduceMean.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: LI Yinqiao (email: li.yin.qiao.2012@hotmail.com) 2018-04-30 20 | */ 21 | 22 | #ifndef __TEST_REDUCEMEAN_H__ 23 | #define __TEST_REDUCEMEAN_H__ 24 | 25 | #include "../core/reduce/ReduceMean.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for ReduceMean Function */ 30 | extern "C" 31 | bool TestReduceMean(); 32 | 33 | } // namespace nts(NiuTrans.Tensor) 34 | #endif // __TEST_REDUCEMEAN_H__ 35 | 36 | 37 | -------------------------------------------------------------------------------- /source/tensor/test/TReduceSum.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: LI Yinqiao (email: li.yin.qiao.2012@hotmail.com) 2018-04-30 20 | */ 21 | 22 | #ifndef __TEST_REDUCESUM_H__ 23 | #define __TEST_REDUCESUM_H__ 24 | 25 | #include "../core/reduce/ReduceSum.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for ReduceSum Function */ 30 | extern "C" 31 | bool TestReduceSum(); 32 | 33 | } // namespace nts(NiuTrans.Tensor) 34 | #endif // __TEST_REDUCESUM_H__ 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /source/tensor/test/TReduceSumAll.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-09-27 20 | */ 21 | 22 | #ifndef __TEST_REDUCESUMALL_H__ 23 | #define __TEST_REDUCESUMALL_H__ 24 | 25 | #include "../core/reduce/ReduceSumAll.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for ReduceSumAll Function */ 30 | bool TestReduceSumAll(); 31 | 32 | } // namespace nts(NiuTrans.Tensor) 33 | 34 | #endif // __TEST_REDUCESUMALL_H__ 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /source/tensor/test/TReduceSumSquared.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-06-27 20 | */ 21 | 22 | #ifndef __TEST_REDUCESUMSQUARED_H__ 23 | #define __TEST_REDUCESUMSQUARED_H__ 24 | 25 | #include "../core/reduce/ReduceSumSquared.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for ReduceSumSquared Function */ 30 | extern "C" 31 | bool TestReduceSumSquared(); 32 | 33 | } // namespace nts(NiuTrans.Tensor) 34 | #endif // __TEST_REDUCESUMSQUARED_H__ 35 | -------------------------------------------------------------------------------- /source/tensor/test/TReduceVariance.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-07-06 20 | */ 21 | 22 | #ifndef __TEST_REDUCEVARIANCE_H__ 23 | #define __TEST_REDUCEVARIANCE_H__ 24 | 25 | #include "../core/reduce/ReduceVariance.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for ReduceVariance Function */ 30 | extern "C" 31 | bool TestReduceVariance(); 32 | 33 | } // namespace nts(NiuTrans.Tensor) 34 | #endif // __TEST_REDUCEVARIANCE_H__ 35 | -------------------------------------------------------------------------------- /source/tensor/test/TRound.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-08-03 20 | */ 21 | 22 | #ifndef __TEST_ROUND_H__ 23 | #define __TEST_ROUND_H__ 24 | 25 | namespace nts { // namespace nts(NiuTrans.Tensor) 26 | 27 | /* test for Round Function */ 28 | bool TestRound(); 29 | 30 | } // namespace nts(NiuTrans.Tensor) 31 | #endif // __TEST_ROUND_H__ 32 | -------------------------------------------------------------------------------- /source/tensor/test/TScaleAndShift.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-06-27 20 | */ 21 | 22 | #ifndef __TEST_SCALEANDSHIFT_H__ 23 | #define __TEST_SCALEANDSHIFT_H__ 24 | 25 | #include "../core/math/ScaleAndShift.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for ScaleAndShift Function */ 30 | extern "C" 31 | bool TestScaleAndShift(); 32 | 33 | } // namespace nts(NiuTrans.Tensor) 34 | #endif // __TEST_SCALEANDSHIFT_H__ 35 | -------------------------------------------------------------------------------- /source/tensor/test/TSelect.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-07-04 20 | */ 21 | 22 | #ifndef __TEST_SELECT_H__ 23 | #define __TEST_SELECT_H__ 24 | 25 | #include "../core/getandset/Select.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for Select Function */ 30 | extern "C" 31 | bool TestSelect(); 32 | 33 | } // namespace nts(NiuTrans.Tensor) 34 | #endif // __TEST_SELECT_H__ 35 | -------------------------------------------------------------------------------- /source/tensor/test/TSetAscendingOrder.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-07-06 20 | */ 21 | 22 | #ifndef __TEST_SETASCENDINGORDER_H__ 23 | #define __TEST_SETASCENDINGORDER_H__ 24 | 25 | #include "../XTensor.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for SetAscendingOrder Function */ 30 | extern "C" 31 | bool TestSetAscendingOrder(); 32 | 33 | } // namespace nts(NiuTrans.Tensor) 34 | #endif // __TEST_SETASCENDINGORDER_H__ 35 | -------------------------------------------------------------------------------- /source/tensor/test/TSetData.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-07-06 20 | */ 21 | 22 | #ifndef __TEST_SETDATA_H__ 23 | #define __TEST_SETDATA_H__ 24 | 25 | #include "../XTensor.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for SetData Function */ 30 | extern "C" 31 | bool TestSetData(); 32 | 33 | } // namespace nts(NiuTrans.Tensor) 34 | #endif // __TEST_SETDATA_H__ 35 | -------------------------------------------------------------------------------- /source/tensor/test/TSigmoid.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-06-19 20 | */ 21 | 22 | #ifndef __TEST_SIGMOID_H__ 23 | #define __TEST_SIGMOID_H__ 24 | 25 | #include "../function/Sigmoid.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for Sigmoid Function */ 30 | extern "C" 31 | bool TestSigmoid(); 32 | 33 | } // namespace nts(NiuTrans.Tensor) 34 | #endif // __TEST_SIGMOID_H__ 35 | -------------------------------------------------------------------------------- /source/tensor/test/TSign.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-07-12 20 | */ 21 | 22 | #ifndef __TEST_SIGN_H__ 23 | #define __TEST_SIGN_H__ 24 | 25 | #include "../core/math/Unary.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for Sign Function */ 30 | extern "C" 31 | bool TestSign(); 32 | 33 | } // namespace nts(NiuTrans.Tensor) 34 | #endif // __TEST_SIGN_H__ 35 | -------------------------------------------------------------------------------- /source/tensor/test/TSin.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-07-31 20 | */ 21 | 22 | #ifndef __TEST_SIN_H__ 23 | #define __TEST_SIN_H__ 24 | 25 | namespace nts { // namespace nts(NiuTrans.Tensor) 26 | 27 | /* test for Sin Function */ 28 | bool TestSin(); 29 | 30 | } // namespace nts(NiuTrans.Tensor) 31 | #endif // __TEST_SIN_H__ 32 | -------------------------------------------------------------------------------- /source/tensor/test/TSoftmax.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-06-19 20 | */ 21 | 22 | #ifndef __TEST_SOFTMAX_H__ 23 | #define __TEST_SOFTMAX_H__ 24 | 25 | #include "../function/Softmax.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for Softmax Function */ 30 | extern "C" 31 | bool TestSoftmax(); 32 | 33 | } // namespace nts(NiuTrans.Tensor) 34 | #endif // __TEST_SOFTMAX_H__ 35 | -------------------------------------------------------------------------------- /source/tensor/test/TSort.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: LI Yinqiao (li.yin.qiao.2012@hotmail.com) 2018-04-30 20 | */ 21 | 22 | #ifndef __TEST_SORT_H__ 23 | #define __TEST_SORT_H__ 24 | 25 | #include "../core/sort/Sort.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for Sort Function */ 30 | extern "C" 31 | bool TestSort(); 32 | 33 | } // namespace nts(NiuTrans.Tensor) 34 | #endif // __TEST_SORT_H__ 35 | -------------------------------------------------------------------------------- /source/tensor/test/TSplit.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Lin Ye (email: linye2015@outlook.com) 2018-06-13 20 | */ 21 | 22 | #ifndef __TEST_SPLIT_H__ 23 | #define __TEST_SPLIT_H__ 24 | 25 | #include "../core/shape/Split.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for Split Function */ 30 | extern "C" 31 | bool TestSplit(); 32 | 33 | } // namespace nts(NiuTrans.Tensor) 34 | #endif // __TEST_SPLIT_H__ 35 | -------------------------------------------------------------------------------- /source/tensor/test/TSpread.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-09-25 20 | */ 21 | 22 | #ifndef __TEST_SPREAD_H__ 23 | #define __TEST_SPREAD_H__ 24 | 25 | #include "../XTensor.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for Spread Function */ 30 | bool TestSpread(); 31 | 32 | } // namespace nts(NiuTrans.Tensor) 33 | 34 | #endif // __TEST_SPREAD_H__ -------------------------------------------------------------------------------- /source/tensor/test/TSub.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-08-01 20 | */ 21 | 22 | #ifndef __TEST_SUB_H__ 23 | #define __TEST_SUB_H__ 24 | 25 | #include "../core/arithmetic/Sub.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for Sub Function */ 30 | bool TestSub(); 31 | 32 | } // namespace nts(NiuTrans.Tensor) 33 | #endif // __TEST_SUB_H__ 34 | -------------------------------------------------------------------------------- /source/tensor/test/TSum.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: LI Yinqiao (li.yin.qiao.2012@hotmail.com) 2018-04-30 20 | */ 21 | 22 | #ifndef __TEST_SUM_H__ 23 | #define __TEST_SUM_H__ 24 | 25 | #include "../core/arithmetic/Sum.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for Sum Function */ 30 | extern "C" 31 | bool TestSum(); 32 | 33 | } // namespace nts(NiuTrans.Tensor) 34 | #endif // __TEST_SUM_H__ 35 | -------------------------------------------------------------------------------- /source/tensor/test/TSumDim.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-07-30 20 | * I finish my summer holidays and go back to study. 21 | */ 22 | 23 | #ifndef __TEST_SUMDIM_H__ 24 | #define __TEST_SUMDIM_H__ 25 | 26 | #include "../core/arithmetic/SumDim.h" 27 | 28 | namespace nts { // namespace nts(NiuTrans.Tensor) 29 | 30 | /* test for SumDim Function */ 31 | extern "C" 32 | bool TestSumDim(); 33 | 34 | } // namespace nts(NiuTrans.Tensor) 35 | #endif // __TEST_SUMDIM_H__ 36 | -------------------------------------------------------------------------------- /source/tensor/test/TTan.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-07-31 20 | */ 21 | 22 | #ifndef __TEST_TAN_H__ 23 | #define __TEST_TAN_H__ 24 | 25 | namespace nts { // namespace nts(NiuTrans.Tensor) 26 | 27 | /* test for Tan Function */ 28 | bool TestTan(); 29 | 30 | } // namespace nts(NiuTrans.Tensor) 31 | #endif // __TEST_TAN_H__ 32 | -------------------------------------------------------------------------------- /source/tensor/test/TTopK.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-06-27 20 | */ 21 | 22 | #ifndef __TEST_TOPK_H__ 23 | #define __TEST_TOPK_H__ 24 | 25 | #include "../core/sort/TopK.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for TopK Function */ 30 | extern "C" 31 | bool TestTopK(); 32 | 33 | } // namespace nts(NiuTrans.Tensor) 34 | #endif // __TEST_TOPK_H__ 35 | -------------------------------------------------------------------------------- /source/tensor/test/TTranspose.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-07-30 20 | */ 21 | 22 | #ifndef __TEST_TRANSPOSE_H__ 23 | #define __TEST_TRANSPOSE_H__ 24 | 25 | #include "../core/shape/Transpose.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for Transpose Function */ 30 | bool TestTranspose(); 31 | 32 | } // namespace nts(NiuTrans.Tensor) 33 | #endif // __TEST_TRANSPOSE_H__ 34 | -------------------------------------------------------------------------------- /source/tensor/test/TUnsqueeze.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: Xu Chen (email: hello_master1954@163.com) 2018-06-27 20 | */ 21 | 22 | #ifndef __TEST_UNSQUEEZE_H__ 23 | #define __TEST_UNSQUEEZE_H__ 24 | 25 | #include "../core/shape/Unsqueeze.h" 26 | 27 | namespace nts { // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for Unsqueeze Function */ 30 | extern "C" 31 | bool TestUnsqueeze(); 32 | 33 | } // namespace nts(NiuTrans.Tensor) 34 | #endif // __TEST_UNSQUEEZE_H__ 35 | -------------------------------------------------------------------------------- /source/tensor/test/TXMem.h: -------------------------------------------------------------------------------- 1 | /* NiuTrans.Tensor - an open-source tensor library 2 | * Copyright (C) 2018, Natural Language Processing Lab, Northeastern University. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * $Created by: XIAO Tong (xiaotong@mail.neu.edu.cn) 2018-6-24 20 | */ 21 | 22 | #ifndef __TXMEM_H__ 23 | #define __TXMEM_H__ 24 | 25 | #include "../XMem.h" 26 | 27 | namespace nts{ // namespace nts(NiuTrans.Tensor) 28 | 29 | /* test for memory pool class */ 30 | extern "C" 31 | bool TestXMem(); 32 | 33 | } // namespace nts(NiuTrans.Tensor) 34 | #endif // __TXMEM_H__ 35 | -------------------------------------------------------------------------------- /source/train/XLearningRate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * NiuTrans.Tensor - an open-source tensor library 3 | * Copyright (C) 2016-2021 4 | * Natural Language Processing Lab, Northeastern University 5 | * and 6 | * NiuTrans Research 7 | * All rights reserved. 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | /* 23 | * This a learning rate generator. E.g., one can adjust learning rate as 24 | * the training process proceeds. 25 | * 26 | * $Created by: XIAO Tong (xiaotong@mail.neu.edu.cn) 2021-03-16 27 | * I wore my coat again after the rain yesterday. 28 | */ 29 | 30 | #ifndef __XLEARNINGRATE_H__ 31 | #define __XLEARNINGRATE_H__ 32 | 33 | namespace nts { // namespace nts(NiuTrans.Tensor) 34 | 35 | /* Learning rate scheduler */ 36 | class XLearningRate 37 | { 38 | public: 39 | /* constructor */ 40 | XLearningRate(); 41 | 42 | /* de-constructor */ 43 | ~XLearningRate(); 44 | 45 | /* a Transformer-style scheduler */ 46 | float MakeLRTransformer(const float lrate, const int nstep, const int nwarmup, const float warmupInitLR); 47 | }; 48 | 49 | } 50 | 51 | #endif -------------------------------------------------------------------------------- /source/train/XNNRecord.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * NiuTrans.Tensor - an open-source tensor library 3 | * Copyright (C) 2016-2021 4 | * Natural Language Processing Lab, Northeastern University 5 | * and 6 | * NiuTrans Research 7 | * All rights reserved. 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | /* 23 | * A record that keeps some information in running and training neural networks 24 | * 25 | * $Created by: XIAO Tong (xiaotong@mail.neu.edu.cn) 2021-03-06 26 | * I will climb mountains with my wife and son this afternoon, hahaha :) 27 | */ 28 | 29 | #include "XNNRecord.h" 30 | 31 | namespace nts { // namespace nts(NiuTrans.Tensor) 32 | 33 | /* constructor */ 34 | XNNRecord::XNNRecord() 35 | { 36 | Clear(); 37 | MUTEX_INIT(mutex); 38 | } 39 | 40 | /* de-constructor */ 41 | XNNRecord::~XNNRecord() 42 | { 43 | MUTEX_DELE(mutex); 44 | } 45 | 46 | /* clear it */ 47 | void XNNRecord::Clear() 48 | { 49 | lossAll = 0; 50 | sampleNum = 0; 51 | predictNum = 0; 52 | state = XWORKER_UNSTARTED; 53 | } 54 | 55 | /* update me with another record */ 56 | void XNNRecord::Update(XNNRecord & record) 57 | { 58 | lossAll += record.lossAll; 59 | sampleNum += record.sampleNum; 60 | predictNum += record.predictNum; 61 | 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /source/train/XTensorKeeper.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * NiuTrans.Tensor - an open-source tensor library 3 | * Copyright (C) 2016-2021 4 | * Natural Language Processing Lab, Northeastern University 5 | * and 6 | * NiuTrans Research 7 | * All rights reserved. 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | /* 23 | * We define a class that keeps a tensor (could be either a parameter or 24 | * gradient). 25 | * 26 | * $Created by: XIAO Tong (xiaotong@mail.neu.edu.cn) 2021-03-25 27 | */ 28 | 29 | #include "XTensorKeeper.h" 30 | 31 | namespace nts { // namespace nts(NiuTrans.Tensor) 32 | 33 | /* constructor */ 34 | XTensorKeeper::XTensorKeeper() 35 | { 36 | tensor = NULL; 37 | grad = NULL; 38 | flag = PARAM_STATE_NOT_READY; 39 | trainFlag = PARAM_STATE_NOT_READY; 40 | MUTEX_INIT(accessLock); 41 | MUTEX_INIT(trainLock); 42 | } 43 | 44 | /* constructor */ 45 | XTensorKeeper::~XTensorKeeper() 46 | { 47 | MUTEX_DELE(accessLock); 48 | MUTEX_DELE(trainLock); 49 | } 50 | 51 | } -------------------------------------------------------------------------------- /source/train/optimizer/OHeader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * NiuTrans.Tensor - an open-source tensor library 3 | * Copyright (C) 2016-2021 4 | * Natural Language Processing Lab, Northeastern University 5 | * and 6 | * NiuTrans Research 7 | * All rights reserved. 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | /* 23 | * This ia header that includes all optimizer headers. 24 | * 25 | * $Created by: XIAO Tong (xiaotong@mail.neu.edu.cn) 2021-03-15 26 | */ 27 | 28 | #ifndef __OHEADER_H__ 29 | #define __OHEADER_H__ 30 | 31 | #include "Adam.h" 32 | 33 | #endif --------------------------------------------------------------------------------