├── lib ├── backward │ ├── .gitignore │ ├── doc │ │ ├── nice.png │ │ ├── pretty.png │ │ └── rude.png │ ├── test_package │ │ ├── CMakeLists.txt │ │ ├── conanfile.py │ │ └── main.cpp │ ├── .travis.yml │ ├── backward.cpp │ ├── LICENSE.txt │ ├── builds.sh │ ├── test │ │ ├── select_signals.cpp │ │ ├── stacktrace.cpp │ │ ├── test.cpp │ │ └── suicide.cpp │ └── conanfile.py ├── TH │ ├── THBlas.c │ ├── THLapack.c │ ├── generic │ │ ├── simd │ │ │ └── convolve.h │ │ ├── THTensorCopy.h │ │ ├── THVector.h │ │ ├── THBlas.h │ │ ├── THStorageCopy.h │ │ ├── THTensorRandom.h │ │ ├── THTensorLapack.h │ │ ├── THLapack.h │ │ ├── THStorageCopy.c │ │ └── THStorage.h │ ├── THBlas.h │ ├── THConfig.cmake.in │ ├── README.md │ ├── vector │ │ ├── AVX2.h │ │ ├── AVX2.c │ │ ├── AVX.h │ │ └── NEON.c │ ├── THVector.h │ ├── THLogAdd.h │ ├── THMemoryFile.h │ ├── THGenerateAllTypes.h │ ├── TH.h │ ├── THGenerateFloatTypes.h │ ├── THGenerateIntTypes.h │ ├── THGenerateIntType.h │ ├── THVector.c │ ├── THGenerateCharType.h │ ├── THGenerateLongType.h │ ├── THGenerateFloatType.h │ ├── THGenerateShortType.h │ ├── THGenerateByteType.h │ ├── THGenerateDoubleType.h │ ├── THDiskFile.h │ ├── THGenerateHalfType.h │ ├── THMath.h │ ├── THTensor.c │ ├── THHalf.h │ ├── THLapack.h │ ├── THTensor.h │ ├── THStorage.h │ ├── THAllocator.h │ ├── THTensorMacros.h │ ├── THFilePrivate.h │ ├── THLogAdd.c │ └── THHalf.c └── THC │ ├── THCTensor.cu │ ├── generated │ ├── THCTensorSortByte.cu │ ├── THCTensorSortChar.cu │ ├── THCTensorSortHalf.cu │ ├── THCTensorSortInt.cu │ ├── THCTensorSortLong.cu │ ├── THCTensorMaskedByte.cu │ ├── THCTensorMaskedChar.cu │ ├── THCTensorMaskedHalf.cu │ ├── THCTensorMaskedInt.cu │ ├── THCTensorMaskedLong.cu │ ├── THCTensorSortDouble.cu │ ├── THCTensorSortFloat.cu │ ├── THCTensorSortShort.cu │ ├── THCTensorMaskedDouble.cu │ ├── THCTensorMaskedFloat.cu │ ├── THCTensorMaskedShort.cu │ ├── THCTensorMathReduceInt.cu │ ├── THCTensorMathCompareByte.cu │ ├── THCTensorMathCompareChar.cu │ ├── THCTensorMathCompareHalf.cu │ ├── THCTensorMathCompareInt.cu │ ├── THCTensorMathCompareLong.cu │ ├── THCTensorMathReduceByte.cu │ ├── THCTensorMathReduceChar.cu │ ├── THCTensorMathReduceFloat.cu │ ├── THCTensorMathReduceHalf.cu │ ├── THCTensorMathReduceLong.cu │ ├── THCTensorMathReduceShort.cu │ ├── THCTensorMathCompareDouble.cu │ ├── THCTensorMathCompareFloat.cu │ ├── THCTensorMathCompareShort.cu │ ├── THCTensorMathCompareTByte.cu │ ├── THCTensorMathCompareTChar.cu │ ├── THCTensorMathCompareTFloat.cu │ ├── THCTensorMathCompareTHalf.cu │ ├── THCTensorMathCompareTInt.cu │ ├── THCTensorMathCompareTLong.cu │ ├── THCTensorMathCompareTShort.cu │ ├── THCTensorMathPointwiseInt.cu │ ├── THCTensorMathReduceDouble.cu │ ├── THCTensorMathCompareTDouble.cu │ ├── THCTensorMathPointwiseByte.cu │ ├── THCTensorMathPointwiseChar.cu │ ├── THCTensorMathPointwiseDouble.cu │ ├── THCTensorMathPointwiseFloat.cu │ ├── THCTensorMathPointwiseHalf.cu │ ├── THCTensorMathPointwiseLong.cu │ └── THCTensorMathPointwiseShort.cu │ ├── THCStorageCopy.c │ ├── THCTensorCopy.c │ ├── THCTensor.c │ ├── THCStorage.c │ ├── THCStorageCopy.cu │ ├── THCTensorMathBlas.cu │ ├── THCAllocator.h │ ├── THCStorageCopy.h │ ├── THCSleep.h │ ├── THCTensorCopy.h │ ├── generic │ ├── THCTensorMathScan.h │ ├── THCTensorTopK.h │ ├── THCTensorMode.h │ ├── THCTensorScatterGather.h │ ├── THCTensorSort.h │ ├── THCTensorIndex.h │ ├── THCTensorMathBlas.h │ ├── THCTensorMathPairwise.h │ ├── THCTensorMathCompare.h │ ├── THCTensorMathCompareT.h │ ├── THCTensorRandom.h │ ├── THCTensor.cu │ ├── THCTensorMathMagma.h │ ├── THCTensorMath.h │ ├── THCTensorMasked.h │ ├── THCTensorCopy.cu │ ├── THCDeviceTensorUtils.cu │ ├── THCStorageCopy.cu │ ├── THCTensorMathReduce.h │ └── THCStorage.h │ ├── THCStorage.cu │ ├── THCSortUtils.cu │ ├── THC.h │ ├── THCGenerateIntType.h │ ├── THCGenerateCharType.h │ ├── THCGenerateLongType.h │ ├── THCThreadLocal.h │ ├── THCGenerateShortType.h │ ├── THCTensorMode.cu │ ├── THCGenerateByteType.h │ ├── THCTensor.h │ ├── THCStorage.h │ ├── THCTensorTopK.cu │ ├── THCGenerateDoubleType.h │ ├── THCSleep.cu │ ├── THCStream.h │ ├── THCCachingAllocator.h │ ├── THCTensorMathMagma.cuh │ ├── THCGenerateFloatType.h │ ├── THCTensorMathMagma.cu │ ├── THCThrustAllocator.cuh │ ├── cmake │ └── FindMAGMA.cmake │ ├── THCGenerateFloatTypes.h │ ├── THCDeviceUtils.cuh │ ├── THCGenerateHalfType.h │ ├── THCHalf.h │ ├── THCTensorMath2.cu │ ├── THCThreadLocal.c │ ├── THCGenerateAllTypes.h │ ├── THCTensorMathReduce.cu │ ├── THCReduceApplyUtils.cu │ ├── THCDeviceTensorUtils.cuh │ ├── THCCachingHostAllocator.h │ ├── THCTensorRandom.h │ ├── THCTensorConv.h │ ├── THCHalf.cu │ ├── THCTensorMath.h │ ├── THCTensorMasked.cuh │ ├── THCStream.cpp │ ├── THCAllocator.c │ ├── THCTensorSort.cu │ ├── THCAsmUtils.cuh │ ├── THCTensorMathCompareT.cuh │ ├── THCTensorMathCompare.cuh │ └── THCTensorSort.cuh ├── src └── tensor │ ├── lua │ ├── doc │ │ ├── logo.gif │ │ ├── osi-certified-72x60.png │ │ ├── index.css │ │ ├── manual.css │ │ └── lua.1 │ ├── README │ ├── src │ │ ├── lua.hpp │ │ ├── lapi.h │ │ ├── lundump.h │ │ ├── lprefix.h │ │ ├── lualib.h │ │ ├── ldebug.h │ │ ├── lstring.h │ │ ├── lzio.c │ │ ├── lzio.h │ │ ├── lfunc.h │ │ ├── linit.c │ │ ├── ltm.h │ │ ├── lctype.h │ │ ├── ldo.h │ │ ├── ltable.h │ │ ├── lctype.c │ │ ├── llex.h │ │ └── lmem.h │ └── CMakeLists.txt │ ├── xttensor.h │ ├── Context.h │ ├── record.lua │ ├── Context.cc │ ├── TensorOperator.cc │ └── CMakeLists.txt └── CMakeLists.txt /lib/backward/.gitignore: -------------------------------------------------------------------------------- 1 | build*/ 2 | *.pyc 3 | -------------------------------------------------------------------------------- /lib/backward/doc/nice.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/torch/xt/HEAD/lib/backward/doc/nice.png -------------------------------------------------------------------------------- /lib/backward/doc/pretty.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/torch/xt/HEAD/lib/backward/doc/pretty.png -------------------------------------------------------------------------------- /lib/backward/doc/rude.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/torch/xt/HEAD/lib/backward/doc/rude.png -------------------------------------------------------------------------------- /src/tensor/lua/doc/logo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/torch/xt/HEAD/src/tensor/lua/doc/logo.gif -------------------------------------------------------------------------------- /src/tensor/xttensor.h: -------------------------------------------------------------------------------- 1 | #include "xt/Tensor.h" 2 | #include "xt/TensorTH.h" 3 | #include "xt/dispatch.h" 4 | -------------------------------------------------------------------------------- /lib/TH/THBlas.c: -------------------------------------------------------------------------------- 1 | #include "THBlas.h" 2 | 3 | #include "generic/THBlas.c" 4 | #include "THGenerateAllTypes.h" 5 | -------------------------------------------------------------------------------- /lib/TH/THLapack.c: -------------------------------------------------------------------------------- 1 | #include "THLapack.h" 2 | 3 | #include "generic/THLapack.c" 4 | #include "THGenerateFloatTypes.h" 5 | -------------------------------------------------------------------------------- /lib/THC/THCTensor.cu: -------------------------------------------------------------------------------- 1 | #include "THCTensor.h" 2 | 3 | #include "generic/THCTensor.cu" 4 | #include "THCGenerateAllTypes.h" 5 | -------------------------------------------------------------------------------- /src/tensor/lua/doc/osi-certified-72x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/torch/xt/HEAD/src/tensor/lua/doc/osi-certified-72x60.png -------------------------------------------------------------------------------- /lib/TH/generic/simd/convolve.h: -------------------------------------------------------------------------------- 1 | void convolve_5x5(float* output, float* input, float* kernel, long outRows, long outCols, long inCols); -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorSortByte.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorSort.cuh" 2 | #include "../generic/THCTensorSort.cu" 3 | #include "../THCGenerateByteType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorSortChar.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorSort.cuh" 2 | #include "../generic/THCTensorSort.cu" 3 | #include "../THCGenerateCharType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorSortHalf.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorSort.cuh" 2 | #include "../generic/THCTensorSort.cu" 3 | #include "../THCGenerateHalfType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorSortInt.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorSort.cuh" 2 | #include "../generic/THCTensorSort.cu" 3 | #include "../THCGenerateIntType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorSortLong.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorSort.cuh" 2 | #include "../generic/THCTensorSort.cu" 3 | #include "../THCGenerateLongType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMaskedByte.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMasked.cuh" 2 | #include "../generic/THCTensorMasked.cu" 3 | #include "../THCGenerateByteType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMaskedChar.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMasked.cuh" 2 | #include "../generic/THCTensorMasked.cu" 3 | #include "../THCGenerateCharType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMaskedHalf.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMasked.cuh" 2 | #include "../generic/THCTensorMasked.cu" 3 | #include "../THCGenerateHalfType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMaskedInt.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMasked.cuh" 2 | #include "../generic/THCTensorMasked.cu" 3 | #include "../THCGenerateIntType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMaskedLong.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMasked.cuh" 2 | #include "../generic/THCTensorMasked.cu" 3 | #include "../THCGenerateLongType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorSortDouble.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorSort.cuh" 2 | #include "../generic/THCTensorSort.cu" 3 | #include "../THCGenerateDoubleType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorSortFloat.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorSort.cuh" 2 | #include "../generic/THCTensorSort.cu" 3 | #include "../THCGenerateFloatType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorSortShort.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorSort.cuh" 2 | #include "../generic/THCTensorSort.cu" 3 | #include "../THCGenerateShortType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMaskedDouble.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMasked.cuh" 2 | #include "../generic/THCTensorMasked.cu" 3 | #include "../THCGenerateDoubleType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMaskedFloat.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMasked.cuh" 2 | #include "../generic/THCTensorMasked.cu" 3 | #include "../THCGenerateFloatType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMaskedShort.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMasked.cuh" 2 | #include "../generic/THCTensorMasked.cu" 3 | #include "../THCGenerateShortType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMathReduceInt.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathReduce.cuh" 2 | #include "../generic/THCTensorMathReduce.cu" 3 | #include "../THCGenerateIntType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/THCStorageCopy.c: -------------------------------------------------------------------------------- 1 | #include "THCStorageCopy.h" 2 | 3 | #include "THCTensorCopy.h" 4 | 5 | #include "generic/THCStorageCopy.c" 6 | #include "THCGenerateAllTypes.h" 7 | -------------------------------------------------------------------------------- /lib/THC/THCTensorCopy.c: -------------------------------------------------------------------------------- 1 | #include "THCTensorCopy.h" 2 | #include "THCCachingHostAllocator.h" 3 | 4 | #include "generic/THCTensorCopy.c" 5 | #include "THCGenerateAllTypes.h" 6 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMathCompareByte.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathCompare.cuh" 2 | #include "../generic/THCTensorMathCompare.cu" 3 | #include "../THCGenerateByteType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMathCompareChar.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathCompare.cuh" 2 | #include "../generic/THCTensorMathCompare.cu" 3 | #include "../THCGenerateCharType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMathCompareHalf.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathCompare.cuh" 2 | #include "../generic/THCTensorMathCompare.cu" 3 | #include "../THCGenerateHalfType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMathCompareInt.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathCompare.cuh" 2 | #include "../generic/THCTensorMathCompare.cu" 3 | #include "../THCGenerateIntType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMathCompareLong.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathCompare.cuh" 2 | #include "../generic/THCTensorMathCompare.cu" 3 | #include "../THCGenerateLongType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMathReduceByte.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathReduce.cuh" 2 | #include "../generic/THCTensorMathReduce.cu" 3 | #include "../THCGenerateByteType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMathReduceChar.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathReduce.cuh" 2 | #include "../generic/THCTensorMathReduce.cu" 3 | #include "../THCGenerateCharType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMathReduceFloat.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathReduce.cuh" 2 | #include "../generic/THCTensorMathReduce.cu" 3 | #include "../THCGenerateFloatType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMathReduceHalf.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathReduce.cuh" 2 | #include "../generic/THCTensorMathReduce.cu" 3 | #include "../THCGenerateHalfType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMathReduceLong.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathReduce.cuh" 2 | #include "../generic/THCTensorMathReduce.cu" 3 | #include "../THCGenerateLongType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMathReduceShort.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathReduce.cuh" 2 | #include "../generic/THCTensorMathReduce.cu" 3 | #include "../THCGenerateShortType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMathCompareDouble.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathCompare.cuh" 2 | #include "../generic/THCTensorMathCompare.cu" 3 | #include "../THCGenerateDoubleType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMathCompareFloat.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathCompare.cuh" 2 | #include "../generic/THCTensorMathCompare.cu" 3 | #include "../THCGenerateFloatType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMathCompareShort.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathCompare.cuh" 2 | #include "../generic/THCTensorMathCompare.cu" 3 | #include "../THCGenerateShortType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMathCompareTByte.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathCompareT.cuh" 2 | #include "../generic/THCTensorMathCompareT.cu" 3 | #include "../THCGenerateByteType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMathCompareTChar.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathCompareT.cuh" 2 | #include "../generic/THCTensorMathCompareT.cu" 3 | #include "../THCGenerateCharType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMathCompareTFloat.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathCompareT.cuh" 2 | #include "../generic/THCTensorMathCompareT.cu" 3 | #include "../THCGenerateFloatType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMathCompareTHalf.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathCompareT.cuh" 2 | #include "../generic/THCTensorMathCompareT.cu" 3 | #include "../THCGenerateHalfType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMathCompareTInt.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathCompareT.cuh" 2 | #include "../generic/THCTensorMathCompareT.cu" 3 | #include "../THCGenerateIntType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMathCompareTLong.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathCompareT.cuh" 2 | #include "../generic/THCTensorMathCompareT.cu" 3 | #include "../THCGenerateLongType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMathCompareTShort.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathCompareT.cuh" 2 | #include "../generic/THCTensorMathCompareT.cu" 3 | #include "../THCGenerateShortType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMathPointwiseInt.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathPointwise.cuh" 2 | #include "../generic/THCTensorMathPointwise.cu" 3 | #include "../THCGenerateIntType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMathReduceDouble.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathReduce.cuh" 2 | #include "../generic/THCTensorMathReduce.cu" 3 | #include "../THCGenerateDoubleType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMathCompareTDouble.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathCompareT.cuh" 2 | #include "../generic/THCTensorMathCompareT.cu" 3 | #include "../THCGenerateDoubleType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMathPointwiseByte.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathPointwise.cuh" 2 | #include "../generic/THCTensorMathPointwise.cu" 3 | #include "../THCGenerateByteType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMathPointwiseChar.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathPointwise.cuh" 2 | #include "../generic/THCTensorMathPointwise.cu" 3 | #include "../THCGenerateCharType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMathPointwiseDouble.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathPointwise.cuh" 2 | #include "../generic/THCTensorMathPointwise.cu" 3 | #include "../THCGenerateDoubleType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMathPointwiseFloat.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathPointwise.cuh" 2 | #include "../generic/THCTensorMathPointwise.cu" 3 | #include "../THCGenerateFloatType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMathPointwiseHalf.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathPointwise.cuh" 2 | #include "../generic/THCTensorMathPointwise.cu" 3 | #include "../THCGenerateHalfType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMathPointwiseLong.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathPointwise.cuh" 2 | #include "../generic/THCTensorMathPointwise.cu" 3 | #include "../THCGenerateLongType.h" 4 | -------------------------------------------------------------------------------- /lib/THC/generated/THCTensorMathPointwiseShort.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathPointwise.cuh" 2 | #include "../generic/THCTensorMathPointwise.cu" 3 | #include "../THCGenerateShortType.h" 4 | -------------------------------------------------------------------------------- /src/tensor/lua/README: -------------------------------------------------------------------------------- 1 | 2 | This is Lua 5.3.4, released on 12 Jan 2017. 3 | 4 | For installation instructions, license details, and 5 | further information about Lua, see doc/readme.html. 6 | 7 | -------------------------------------------------------------------------------- /lib/THC/THCTensor.c: -------------------------------------------------------------------------------- 1 | #include "THCGeneral.h" 2 | #include "THCTensor.h" 3 | #include "THCTensorCopy.h" 4 | #include "THAtomic.h" 5 | 6 | #include "generic/THCTensor.c" 7 | #include "THCGenerateAllTypes.h" 8 | -------------------------------------------------------------------------------- /lib/THC/THCStorage.c: -------------------------------------------------------------------------------- 1 | #include "THCStorage.h" 2 | #include "THCGeneral.h" 3 | #include "THAtomic.h" 4 | 5 | #include "THCHalf.h" 6 | 7 | #include "generic/THCStorage.c" 8 | #include "THCGenerateAllTypes.h" 9 | -------------------------------------------------------------------------------- /lib/THC/THCStorageCopy.cu: -------------------------------------------------------------------------------- 1 | #include "THCStorageCopy.h" 2 | #include "THCGeneral.h" 3 | 4 | #include "THCHalf.h" 5 | #include "THCTensorCopy.h" 6 | 7 | #include "generic/THCStorageCopy.cu" 8 | #include "THCGenerateAllTypes.h" 9 | -------------------------------------------------------------------------------- /lib/TH/THBlas.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_BLAS_INC 2 | #define TH_BLAS_INC 3 | 4 | #include "THGeneral.h" 5 | 6 | #define THBlas_(NAME) TH_CONCAT_4(TH,Real,Blas_,NAME) 7 | 8 | #include "generic/THBlas.h" 9 | #include "THGenerateAllTypes.h" 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /lib/THC/THCTensorMathBlas.cu: -------------------------------------------------------------------------------- 1 | #include "THCTensorMath.h" 2 | #include "THCGeneral.h" 3 | #include "THCBlas.h" 4 | #include "THCTensorCopy.h" 5 | #include "THCNumerics.cuh" 6 | 7 | #include "generic/THCTensorMathBlas.cu" 8 | #include "THCGenerateAllTypes.h" 9 | -------------------------------------------------------------------------------- /src/tensor/lua/src/lua.hpp: -------------------------------------------------------------------------------- 1 | // lua.hpp 2 | // Lua header files for C++ 3 | // <> not supplied automatically because Lua also compiles as C++ 4 | 5 | extern "C" { 6 | #include "lua.h" 7 | #include "lualib.h" 8 | #include "lauxlib.h" 9 | } 10 | -------------------------------------------------------------------------------- /lib/THC/THCAllocator.h: -------------------------------------------------------------------------------- 1 | #ifndef THC_ALLOCATOR_INC 2 | #define THC_ALLOCATOR_INC 3 | 4 | #include "THCGeneral.h" 5 | 6 | extern THAllocator THCudaHostAllocator; 7 | extern THAllocator THCUVAAllocator; 8 | extern THCDeviceAllocator THCIpcAllocator; 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /lib/THC/THCStorageCopy.h: -------------------------------------------------------------------------------- 1 | #ifndef THC_STORAGE_COPY_INC 2 | #define THC_STORAGE_COPY_INC 3 | 4 | #include "THCStorage.h" 5 | #include "THCGeneral.h" 6 | #include "THCHalf.h" 7 | 8 | #include "generic/THCStorageCopy.h" 9 | #include "THCGenerateAllTypes.h" 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /lib/THC/THCSleep.h: -------------------------------------------------------------------------------- 1 | #ifndef THC_SPIN_INC 2 | #define THC_SPIN_INC 3 | 4 | #include "THCGeneral.h" 5 | #include 6 | 7 | // enqueues a kernel that spins for the specified number of cycles 8 | THC_API void THC_sleep(THCState* state, long long cycles); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /lib/THC/THCTensorCopy.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_CUDA_TENSOR_COPY_INC 2 | #define TH_CUDA_TENSOR_COPY_INC 3 | 4 | #include "THCTensor.h" 5 | #include "THCGeneral.h" 6 | #include "THCHalf.h" 7 | #include "THCStream.h" 8 | 9 | #include "generic/THCTensorCopy.h" 10 | #include "THCGenerateAllTypes.h" 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /lib/TH/THConfig.cmake.in: -------------------------------------------------------------------------------- 1 | # Find the TH includes and library 2 | # 3 | # TH_INCLUDE_DIR -- where to find the includes 4 | # TH_LIBRARIES -- list of libraries to link against 5 | # TH_FOUND -- set to 1 if found 6 | 7 | SET(TH_FOUND 1) 8 | SET(TH_INCLUDE_DIR "@TH_INCLUDE_DIR@") 9 | SET(TH_LIBRARIES "@TH_LIBRARIES@") 10 | -------------------------------------------------------------------------------- /lib/TH/README.md: -------------------------------------------------------------------------------- 1 | Environment variables control the disabling of certain explicit SIMD optimizations. 2 | 3 | ``` 4 | x64 options: 5 | TH_NO_AVX2=1 # disable AVX2 codepaths 6 | TH_NO_AVX=1 # disable AVX codepaths 7 | TH_NO_SSE=1 # disable SSE codepaths 8 | 9 | ppc64le options: 10 | TH_NO_VSX=1 # disable VSX codepaths 11 | ``` 12 | -------------------------------------------------------------------------------- /lib/TH/vector/AVX2.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_AVX2_H 2 | #define TH_AVX2_H 3 | 4 | #include 5 | 6 | void THDoubleVector_cadd_AVX2(double *z, const double *x, const double *y, const double c, const ptrdiff_t n); 7 | void THFloatVector_cadd_AVX2(float *z, const float *x, const float *y, const float c, const ptrdiff_t n); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /lib/THC/generic/THCTensorMathScan.h: -------------------------------------------------------------------------------- 1 | #ifndef THC_GENERIC_FILE 2 | #define THC_GENERIC_FILE "generic/THCTensorMathScan.h" 3 | #else 4 | 5 | THC_API void THCTensor_(cumsum)(THCState *state, THCTensor *self, THCTensor *src, long dim); 6 | THC_API void THCTensor_(cumprod)(THCState *state, THCTensor *self, THCTensor *src, long dim); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /lib/THC/THCStorage.cu: -------------------------------------------------------------------------------- 1 | #include "THCStorage.h" 2 | 3 | #include "THCThrustAllocator.cuh" 4 | #include 5 | #include 6 | #if CUDA_VERSION >= 7000 7 | #include 8 | #endif 9 | 10 | #include "THCHalf.h" 11 | 12 | #include "generic/THCStorage.cu" 13 | #include "THCGenerateAllTypes.h" 14 | -------------------------------------------------------------------------------- /src/tensor/lua/doc/index.css: -------------------------------------------------------------------------------- 1 | ul { 2 | list-style-type: none ; 3 | } 4 | 5 | ul.contents { 6 | padding: 0 ; 7 | } 8 | 9 | table { 10 | border: none ; 11 | border-spacing: 0 ; 12 | border-collapse: collapse ; 13 | } 14 | 15 | td { 16 | vertical-align: top ; 17 | padding: 0 ; 18 | text-align: left ; 19 | line-height: 1.25 ; 20 | width: 15% ; 21 | } 22 | -------------------------------------------------------------------------------- /src/tensor/lua/doc/manual.css: -------------------------------------------------------------------------------- 1 | h3 code { 2 | font-family: inherit ; 3 | font-size: inherit ; 4 | } 5 | 6 | pre, code { 7 | font-size: 12pt ; 8 | } 9 | 10 | span.apii { 11 | color: gray ; 12 | float: right ; 13 | font-family: inherit ; 14 | font-style: normal ; 15 | font-size: small ; 16 | } 17 | 18 | h2:before { 19 | content: "" ; 20 | padding-right: 0em ; 21 | } 22 | -------------------------------------------------------------------------------- /lib/THC/THCSortUtils.cu: -------------------------------------------------------------------------------- 1 | #include "THCSortUtils.cuh" 2 | 3 | // Returns 2^(ceil(lg(n)) from Stanford bit twiddling hacks 4 | unsigned long nextHighestPowerOf2(unsigned long n) { 5 | n--; 6 | n |= n >> 1; 7 | n |= n >> 2; 8 | n |= n >> 4; 9 | n |= n >> 8; 10 | n |= n >> 16; 11 | #ifndef _MSC_VER 12 | n |= n >> 32; 13 | #endif 14 | n++; 15 | 16 | return n; 17 | } 18 | -------------------------------------------------------------------------------- /lib/backward/test_package/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(backward-package-test) 2 | cmake_minimum_required(VERSION 2.8) 3 | 4 | include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) 5 | include(${CONAN_CMAKE-UTILS_ROOT}/conan.cmake) 6 | conan_basic_setup() 7 | 8 | add_conan_library(backward) 9 | 10 | add_executable(example main.cpp) 11 | target_link_libraries(example PRIVATE backward-conan) 12 | -------------------------------------------------------------------------------- /lib/TH/THVector.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_VECTOR_INC 2 | #define TH_VECTOR_INC 3 | 4 | #include "THGeneral.h" 5 | 6 | #define THVector_(NAME) TH_CONCAT_4(TH,Real,Vector_,NAME) 7 | 8 | /* We are going to use dynamic dispatch, and want only to generate declarations 9 | * of the vector functions */ 10 | #include "generic/THVector.h" 11 | #include "THGenerateAllTypes.h" 12 | 13 | #endif // TH_VECTOR_INC 14 | -------------------------------------------------------------------------------- /lib/TH/THLogAdd.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_LOG_ADD_INC 2 | #define TH_LOG_ADD_INC 3 | 4 | #include "THGeneral.h" 5 | 6 | TH_API const double THLog2Pi; 7 | TH_API const double THLogZero; 8 | TH_API const double THLogOne; 9 | 10 | TH_API double THLogAdd(double log_a, double log_b); 11 | TH_API double THLogSub(double log_a, double log_b); 12 | TH_API double THExpMinusApprox(const double x); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /lib/TH/THMemoryFile.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_MEMORY_FILE_INC 2 | #define TH_MEMORY_FILE_INC 3 | 4 | #include "THFile.h" 5 | #include "THStorage.h" 6 | 7 | TH_API THFile *THMemoryFile_newWithStorage(THCharStorage *storage, const char *mode); 8 | TH_API THFile *THMemoryFile_new(const char *mode); 9 | 10 | TH_API THCharStorage *THMemoryFile_storage(THFile *self); 11 | TH_API void THMemoryFile_longSize(THFile *self, int size); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /lib/TH/THGenerateAllTypes.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_GENERIC_FILE 2 | #error "You must define TH_GENERIC_FILE before including THGenerateAllTypes.h" 3 | #endif 4 | 5 | #ifndef THGenerateManyTypes 6 | #define THAllLocalGenerateManyTypes 7 | #define THGenerateManyTypes 8 | #endif 9 | 10 | #include "THGenerateFloatTypes.h" 11 | #include "THGenerateIntTypes.h" 12 | 13 | #ifdef THAllLocalGenerateManyTypes 14 | #undef THAllLocalGenerateManyTypes 15 | #undef THGenerateManyTypes 16 | #undef TH_GENERIC_FILE 17 | #endif 18 | -------------------------------------------------------------------------------- /lib/THC/THC.h: -------------------------------------------------------------------------------- 1 | #ifndef THC_INC 2 | #define THC_INC 3 | 4 | #include "THCGeneral.h" 5 | #include "THCAllocator.h" 6 | #include "THCBlas.h" 7 | #include "THCCachingAllocator.h" 8 | #include "THCCachingHostAllocator.h" 9 | #include "THCSleep.h" 10 | #include "THCStorage.h" 11 | #include "THCStorageCopy.h" 12 | #include "THCStream.h" 13 | #include "THCTensor.h" 14 | #include "THCTensorCopy.h" 15 | #include "THCTensorRandom.h" 16 | #include "THCTensorMath.h" 17 | #include "THCTensorConv.h" 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /lib/TH/TH.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_INC 2 | #define TH_INC 3 | 4 | #include "THGeneral.h" 5 | 6 | #include "THBlas.h" 7 | #ifdef USE_LAPACK 8 | #include "THLapack.h" 9 | #endif 10 | 11 | #include "THAtomic.h" 12 | #include "THVector.h" 13 | #include "THLogAdd.h" 14 | #include "THRandom.h" 15 | #include "THStorage.h" 16 | #include "THTensor.h" 17 | #include "THTensorApply.h" 18 | #include "THTensorDimApply.h" 19 | 20 | #include "THFile.h" 21 | #include "THDiskFile.h" 22 | #include "THMemoryFile.h" 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /lib/THC/THCGenerateIntType.h: -------------------------------------------------------------------------------- 1 | #ifndef THC_GENERIC_FILE 2 | #error "You must define THC_GENERIC_FILE before including THGenerateIntType.h" 3 | #endif 4 | 5 | #define real int 6 | #define accreal long 7 | #define Real Int 8 | #define CReal CudaInt 9 | #define THC_REAL_IS_INT 10 | #line 1 THC_GENERIC_FILE 11 | #include THC_GENERIC_FILE 12 | #undef real 13 | #undef accreal 14 | #undef Real 15 | #undef CReal 16 | #undef THC_REAL_IS_INT 17 | 18 | #ifndef THCGenerateAllTypes 19 | #undef THC_GENERIC_FILE 20 | #endif 21 | -------------------------------------------------------------------------------- /lib/TH/THGenerateFloatTypes.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_GENERIC_FILE 2 | #error "You must define TH_GENERIC_FILE before including THGenerateFloatTypes.h" 3 | #endif 4 | 5 | #ifndef THGenerateManyTypes 6 | #define THFloatLocalGenerateManyTypes 7 | #define THGenerateManyTypes 8 | #endif 9 | 10 | #include "THGenerateFloatType.h" 11 | #include "THGenerateDoubleType.h" 12 | 13 | #ifdef THFloatLocalGenerateManyTypes 14 | #undef THFloatLocalGenerateManyTypes 15 | #undef THGenerateManyTypes 16 | #undef TH_GENERIC_FILE 17 | #endif 18 | -------------------------------------------------------------------------------- /lib/THC/THCGenerateCharType.h: -------------------------------------------------------------------------------- 1 | #ifndef THC_GENERIC_FILE 2 | #error "You must define THC_GENERIC_FILE before including THGenerateCharType.h" 3 | #endif 4 | 5 | #define real char 6 | #define accreal long 7 | #define Real Char 8 | #define CReal CudaChar 9 | #define THC_REAL_IS_CHAR 10 | #line 1 THC_GENERIC_FILE 11 | #include THC_GENERIC_FILE 12 | #undef real 13 | #undef accreal 14 | #undef Real 15 | #undef CReal 16 | #undef THC_REAL_IS_CHAR 17 | 18 | #ifndef THCGenerateAllTypes 19 | #undef THC_GENERIC_FILE 20 | #endif 21 | -------------------------------------------------------------------------------- /lib/THC/THCGenerateLongType.h: -------------------------------------------------------------------------------- 1 | #ifndef THC_GENERIC_FILE 2 | #error "You must define THC_GENERIC_FILE before including THGenerateLongType.h" 3 | #endif 4 | 5 | #define real long 6 | #define accreal long 7 | #define Real Long 8 | #define CReal CudaLong 9 | #define THC_REAL_IS_LONG 10 | #line 1 THC_GENERIC_FILE 11 | #include THC_GENERIC_FILE 12 | #undef real 13 | #undef accreal 14 | #undef Real 15 | #undef CReal 16 | #undef THC_REAL_IS_LONG 17 | 18 | #ifndef THCGenerateAllTypes 19 | #undef THC_GENERIC_FILE 20 | #endif 21 | -------------------------------------------------------------------------------- /lib/THC/THCThreadLocal.h: -------------------------------------------------------------------------------- 1 | #ifndef THC_THREAD_LOCAL_INC 2 | #define THC_THREAD_LOCAL_INC 3 | 4 | #ifdef _WIN32 5 | #include 6 | typedef DWORD THCThreadLocal; 7 | #else 8 | #include 9 | typedef pthread_key_t THCThreadLocal; 10 | #endif 11 | 12 | THCThreadLocal THCThreadLocal_alloc(void); 13 | void THCThreadLocal_free(THCThreadLocal local); 14 | void* THCThreadLocal_get(THCThreadLocal local); 15 | void THCThreadLocal_set(THCThreadLocal local, void* value); 16 | 17 | #endif // THC_THREAD_LOCAL_INC 18 | -------------------------------------------------------------------------------- /lib/THC/THCGenerateShortType.h: -------------------------------------------------------------------------------- 1 | #ifndef THC_GENERIC_FILE 2 | #error "You must define THC_GENERIC_FILE before including THGenerateShortType.h" 3 | #endif 4 | 5 | #define real short 6 | #define accreal long 7 | #define Real Short 8 | #define CReal CudaShort 9 | #define THC_REAL_IS_SHORT 10 | #line 1 THC_GENERIC_FILE 11 | #include THC_GENERIC_FILE 12 | #undef real 13 | #undef accreal 14 | #undef Real 15 | #undef CReal 16 | #undef THC_REAL_IS_SHORT 17 | 18 | #ifndef THCGenerateAllTypes 19 | #undef THC_GENERIC_FILE 20 | #endif 21 | -------------------------------------------------------------------------------- /lib/THC/THCTensorMode.cu: -------------------------------------------------------------------------------- 1 | #include "THC.h" 2 | #include "THCThrustAllocator.cuh" 3 | #include "THCTensorTypeUtils.cuh" 4 | #include "THCReduceApplyUtils.cuh" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "THCTensorMode.cuh" 14 | 15 | #include "generic/THCTensorMode.cu" 16 | #include "THCGenerateAllTypes.h" 17 | -------------------------------------------------------------------------------- /lib/THC/THCGenerateByteType.h: -------------------------------------------------------------------------------- 1 | #ifndef THC_GENERIC_FILE 2 | #error "You must define THC_GENERIC_FILE before including THGenerateByteType.h" 3 | #endif 4 | 5 | #define real unsigned char 6 | #define accreal long 7 | #define Real Byte 8 | #define CReal CudaByte 9 | #define THC_REAL_IS_BYTE 10 | #line 1 THC_GENERIC_FILE 11 | #include THC_GENERIC_FILE 12 | #undef real 13 | #undef accreal 14 | #undef Real 15 | #undef CReal 16 | #undef THC_REAL_IS_BYTE 17 | 18 | #ifndef THCGenerateAllTypes 19 | #undef THC_GENERIC_FILE 20 | #endif 21 | -------------------------------------------------------------------------------- /lib/THC/THCTensor.h: -------------------------------------------------------------------------------- 1 | #ifndef THC_TENSOR_INC 2 | #define THC_TENSOR_INC 3 | 4 | #include "THTensor.h" 5 | #include "THCStorage.h" 6 | #include "THCGeneral.h" 7 | 8 | #define THCTensor TH_CONCAT_3(TH,CReal,Tensor) 9 | #define THCTensor_(NAME) TH_CONCAT_4(TH,CReal,Tensor_,NAME) 10 | 11 | #define THC_DESC_BUFF_LEN 64 12 | 13 | typedef struct THC_CLASS THCDescBuff 14 | { 15 | char str[THC_DESC_BUFF_LEN]; 16 | } THCDescBuff; 17 | 18 | #include "generic/THCTensor.h" 19 | #include "THCGenerateAllTypes.h" 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /lib/THC/THCStorage.h: -------------------------------------------------------------------------------- 1 | #ifndef THC_STORAGE_INC 2 | #define THC_STORAGE_INC 3 | 4 | #include "THStorage.h" 5 | #include "THCGeneral.h" 6 | 7 | #define THCStorage TH_CONCAT_3(TH,CReal,Storage) 8 | #define THCStorage_(NAME) TH_CONCAT_4(TH,CReal,Storage_,NAME) 9 | 10 | /* fast access methods */ 11 | #define THC_STORAGE_GET(storage, idx) ((storage)->data[(idx)]) 12 | #define THC_STORAGE_SET(storage, idx, value) ((storage)->data[(idx)] = (value)) 13 | 14 | #include "generic/THCStorage.h" 15 | #include "THCGenerateAllTypes.h" 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /lib/THC/THCTensorTopK.cu: -------------------------------------------------------------------------------- 1 | #include "THC.h" 2 | #include "THCReduceApplyUtils.cuh" 3 | #include "THCTensorCopy.h" 4 | #include "THCTensorMath.h" 5 | #include "THCAsmUtils.cuh" 6 | #include "THCScanUtils.cuh" 7 | #include "THCTensorTypeUtils.cuh" 8 | #include "THCTensorMathReduce.cuh" 9 | #include // for std::min 10 | 11 | #if CUDA_VERSION >= 7000 12 | #include 13 | #endif 14 | 15 | #include "THCTensorTopK.cuh" 16 | 17 | #include "generic/THCTensorTopK.cu" 18 | #include "THCGenerateAllTypes.h" 19 | 20 | -------------------------------------------------------------------------------- /lib/THC/generic/THCTensorTopK.h: -------------------------------------------------------------------------------- 1 | #ifndef THC_GENERIC_FILE 2 | #define THC_GENERIC_FILE "generic/THCTensorTopK.h" 3 | #else 4 | 5 | /* Returns the set of all kth smallest (or largest) elements, depending */ 6 | /* on `dir` */ 7 | THC_API void THCTensor_(topk)(THCState* state, 8 | THCTensor* topK, 9 | THCudaLongTensor* indices, 10 | THCTensor* input, 11 | long k, int dim, int dir, int sorted); 12 | 13 | #endif // THC_GENERIC_FILE 14 | -------------------------------------------------------------------------------- /lib/THC/THCGenerateDoubleType.h: -------------------------------------------------------------------------------- 1 | #ifndef THC_GENERIC_FILE 2 | #error "You must define THC_GENERIC_FILE before including THGenerateDoubleType.h" 3 | #endif 4 | 5 | #define real double 6 | #define accreal double 7 | #define Real Double 8 | #define CReal CudaDouble 9 | #define THC_REAL_IS_DOUBLE 10 | #line 1 THC_GENERIC_FILE 11 | #include THC_GENERIC_FILE 12 | #undef real 13 | #undef accreal 14 | #undef Real 15 | #undef CReal 16 | #undef THC_REAL_IS_DOUBLE 17 | 18 | #ifndef THCGenerateAllTypes 19 | #ifndef THCGenerateFloatTypes 20 | #undef THC_GENERIC_FILE 21 | #endif 22 | #endif 23 | -------------------------------------------------------------------------------- /lib/THC/THCSleep.cu: -------------------------------------------------------------------------------- 1 | #include "THCSleep.h" 2 | 3 | 4 | __global__ void spin_kernel(long long cycles) 5 | { 6 | // see concurrentKernels CUDA sampl 7 | long long start_clock = clock64(); 8 | long long clock_offset = 0; 9 | while (clock_offset < cycles) 10 | { 11 | clock_offset = clock64() - start_clock; 12 | } 13 | } 14 | 15 | THC_API void THC_sleep(THCState* state, long long cycles) 16 | { 17 | dim3 grid(1); 18 | dim3 block(1); 19 | spin_kernel<<>>(cycles); 20 | THCudaCheck(cudaGetLastError()); 21 | } 22 | -------------------------------------------------------------------------------- /lib/THC/THCStream.h: -------------------------------------------------------------------------------- 1 | #ifndef THC_STREAM_INC 2 | #define THC_STREAM_INC 3 | 4 | #include 5 | #include "THCGeneral.h" 6 | 7 | struct THCStream 8 | { 9 | cudaStream_t stream; 10 | int device; 11 | int refcount; 12 | }; 13 | 14 | 15 | THC_API THCStream* THCStream_new(int flags); 16 | THC_API THCStream* THCStream_defaultStream(int device); 17 | THC_API THCStream* THCStream_newWithPriority(int flags, int priority); 18 | THC_API void THCStream_free(THCStream* self); 19 | THC_API void THCStream_retain(THCStream* self); 20 | 21 | #endif // THC_STREAM_INC 22 | -------------------------------------------------------------------------------- /lib/THC/THCCachingAllocator.h: -------------------------------------------------------------------------------- 1 | #ifndef THC_DEVICE_ALLOCATOR_INC 2 | #define THC_DEVICE_ALLOCATOR_INC 3 | 4 | #if __cplusplus >= 201103L 5 | #include 6 | #endif 7 | 8 | #include "THCGeneral.h" 9 | #include "THCStream.h" 10 | 11 | THC_API THCDeviceAllocator* THCCachingAllocator_get(void); 12 | THC_API void* THCCachingAllocator_getBaseAllocation(void *ptr, size_t *size); 13 | THC_API void THCCachingAllocator_recordStream(void *ptr, THCStream* stream); 14 | 15 | #if __cplusplus >= 201103L 16 | THC_API std::mutex* THCCachingAllocator_getCudaFreeMutex(); 17 | #endif 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /lib/THC/generic/THCTensorMode.h: -------------------------------------------------------------------------------- 1 | #ifndef THC_GENERIC_FILE 2 | #define THC_GENERIC_FILE "generic/THCTensorMode.h" 3 | #else 4 | 5 | /* Returns the mode, and index of the mode, for the set of values 6 | * along a given dimension in the input tensor. */ 7 | THC_API void THCTensor_(mode)(THCState *state, 8 | THCTensor *values, 9 | THCudaLongTensor *indices, 10 | THCTensor *input, 11 | int dimension, 12 | int keepdim); 13 | 14 | #endif // THC_GENERIC_FILE 15 | -------------------------------------------------------------------------------- /lib/TH/THGenerateIntTypes.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_GENERIC_FILE 2 | #error "You must define TH_GENERIC_FILE before including THGenerateIntTypes.h" 3 | #endif 4 | 5 | #ifndef THGenerateManyTypes 6 | #define THIntLocalGenerateManyTypes 7 | #define THGenerateManyTypes 8 | #endif 9 | 10 | #include "THGenerateByteType.h" 11 | #include "THGenerateCharType.h" 12 | #include "THGenerateShortType.h" 13 | #include "THGenerateIntType.h" 14 | #include "THGenerateLongType.h" 15 | 16 | #ifdef THIntLocalGenerateManyTypes 17 | #undef THIntLocalGenerateManyTypes 18 | #undef THGenerateManyTypes 19 | #undef TH_GENERIC_FILE 20 | #endif 21 | -------------------------------------------------------------------------------- /lib/THC/THCTensorMathMagma.cuh: -------------------------------------------------------------------------------- 1 | #ifndef THC_TENSOR_MATH_MAGMA_CUH 2 | #define THC_TENSOR_MATH_MAGMA_CUH 3 | 4 | #ifdef USE_MAGMA 5 | #include 6 | #else 7 | #include "THCBlas.h" 8 | #endif 9 | 10 | #ifdef USE_MAGMA 11 | template 12 | static inline T* th_magma_malloc_pinned(size_t n) 13 | { 14 | void* ptr; 15 | if (MAGMA_SUCCESS != magma_malloc_pinned(&ptr, n * sizeof(T))) 16 | THError("$ Torch: not enough memory: you tried to allocate %dGB. Buy new RAM!", n/268435456); 17 | return reinterpret_cast(ptr); 18 | } 19 | 20 | #endif 21 | 22 | #endif // THC_TENSOR_MATH_MAGMA_CUH 23 | -------------------------------------------------------------------------------- /lib/backward/test_package/conanfile.py: -------------------------------------------------------------------------------- 1 | from conans import ConanFile, CMake 2 | import os 3 | 4 | class TestBackward(ConanFile): 5 | settings = 'os', 'compiler', 'build_type', 'arch' 6 | requires = 'cmake-utils/0.0.0@Manu343726/testing', 'backward/1.3.0@Manu343726/testing' 7 | generators = 'cmake' 8 | 9 | def build(self): 10 | cmake = CMake(self.settings) 11 | self.run('cmake {} {}'.format(self.conanfile_directory, cmake.command_line)) 12 | self.run('cmake --build . {}'.format(cmake.build_config)) 13 | 14 | def test(self): 15 | self.run(os.path.join('.', 'bin', 'example')) 16 | -------------------------------------------------------------------------------- /lib/THC/generic/THCTensorScatterGather.h: -------------------------------------------------------------------------------- 1 | #ifndef THC_GENERIC_FILE 2 | #define THC_GENERIC_FILE "generic/THCTensorScatterGather.h" 3 | #else 4 | 5 | THC_API void THCTensor_(gather)(THCState* state, THCTensor *tensor, THCTensor *src, int dim, THCudaLongTensor *index); 6 | THC_API void THCTensor_(scatter)(THCState* state, THCTensor *tensor, int dim, THCudaLongTensor *index, THCTensor *src); 7 | THC_API void THCTensor_(scatterAdd)(THCState* state, THCTensor *tensor, int dim, THCudaLongTensor *index, THCTensor *src); 8 | THC_API void THCTensor_(scatterFill)(THCState* state, THCTensor *tensor, int dim, THCudaLongTensor *index, real value); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /src/tensor/lua/src/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h,v 2.9 2015/03/06 19:49:50 roberto Exp $ 3 | ** Auxiliary functions from Lua API 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lapi_h 8 | #define lapi_h 9 | 10 | 11 | #include "llimits.h" 12 | #include "lstate.h" 13 | 14 | #define api_incr_top(L) {L->top++; api_check(L, L->top <= L->ci->top, \ 15 | "stack overflow");} 16 | 17 | #define adjustresults(L,nres) \ 18 | { if ((nres) == LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; } 19 | 20 | #define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \ 21 | "not enough elements in the stack") 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /lib/THC/THCGenerateFloatType.h: -------------------------------------------------------------------------------- 1 | #ifndef THC_GENERIC_FILE 2 | #error "You must define THC_GENERIC_FILE before including THGenerateFloatType.h" 3 | #endif 4 | 5 | #define real float 6 | /* FIXME: fp64 has bad performance on some platforms; avoid using it unless 7 | we opt into it? */ 8 | #define accreal float 9 | #define Real Float 10 | #define CReal Cuda 11 | #define THC_REAL_IS_FLOAT 12 | #line 1 THC_GENERIC_FILE 13 | #include THC_GENERIC_FILE 14 | #undef real 15 | #undef accreal 16 | #undef Real 17 | #undef CReal 18 | #undef THC_REAL_IS_FLOAT 19 | 20 | #ifndef THCGenerateAllTypes 21 | #ifndef THCGenerateFloatTypes 22 | #undef THC_GENERIC_FILE 23 | #endif 24 | #endif 25 | -------------------------------------------------------------------------------- /src/tensor/Context.h: -------------------------------------------------------------------------------- 1 | #ifndef XT_CONTEXT_H 2 | #define XT_CONTEXT_H 3 | 4 | #include 5 | 6 | struct THGenerator; 7 | struct THCState; 8 | 9 | namespace xt { 10 | 11 | class Context 12 | { 13 | public: 14 | Context(); 15 | std::shared_ptr generator(std::shared_ptr gen = nullptr); 16 | std::shared_ptr thcstate(std::shared_ptr state = nullptr); 17 | bool hasGPU(); // return true if compiled with GPU support 18 | ~Context(); 19 | private: 20 | std::shared_ptr generator_; 21 | std::shared_ptr thcstate_; 22 | }; 23 | 24 | extern thread_local Context defaultContext; 25 | 26 | } 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /lib/TH/THGenerateIntType.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_GENERIC_FILE 2 | #error "You must define TH_GENERIC_FILE before including THGenerateIntType.h" 3 | #endif 4 | 5 | #define real int 6 | #define accreal long 7 | #define TH_CONVERT_REAL_TO_ACCREAL(_val) (accreal)(_val) 8 | #define TH_CONVERT_ACCREAL_TO_REAL(_val) (real)(_val) 9 | #define Real Int 10 | #define THInf INT_MAX 11 | #define TH_REAL_IS_INT 12 | #line 1 TH_GENERIC_FILE 13 | #include TH_GENERIC_FILE 14 | #undef real 15 | #undef accreal 16 | #undef Real 17 | #undef THInf 18 | #undef TH_REAL_IS_INT 19 | #undef TH_CONVERT_REAL_TO_ACCREAL 20 | #undef TH_CONVERT_ACCREAL_TO_REAL 21 | 22 | #ifndef THGenerateManyTypes 23 | #undef TH_GENERIC_FILE 24 | #endif 25 | -------------------------------------------------------------------------------- /lib/TH/THVector.c: -------------------------------------------------------------------------------- 1 | #include "THVector.h" 2 | 3 | #include "generic/simd/simd.h" 4 | 5 | #ifdef __NEON__ 6 | #include "vector/NEON.c" 7 | #endif 8 | 9 | #ifdef __PPC64__ 10 | #include "vector/VSX.c" 11 | #endif 12 | 13 | #if defined(USE_SSE2) || defined(USE_SSE3) || defined(USE_SSSE3) \ 14 | || defined(USE_SSE4_1) || defined(USE_SSE4_2) 15 | #include "vector/SSE.c" 16 | #endif 17 | 18 | #if defined(USE_AVX) 19 | #include "vector/AVX.h" 20 | #endif 21 | 22 | #if defined(USE_AVX2) 23 | #include "vector/AVX2.h" 24 | #endif 25 | 26 | #include "generic/THVectorDefault.c" 27 | #include "THGenerateAllTypes.h" 28 | 29 | #include "generic/THVectorDispatch.c" 30 | #include "THGenerateAllTypes.h" 31 | -------------------------------------------------------------------------------- /lib/THC/THCTensorMathMagma.cu: -------------------------------------------------------------------------------- 1 | #include "THCGeneral.h" 2 | #include "THCTensorMath.h" 3 | #include "THCTensorCopy.h" 4 | #include "THCTensorMathMagma.cuh" 5 | #include 6 | 7 | #ifdef USE_MAGMA 8 | #include 9 | #else 10 | #include "THCBlas.h" 11 | #endif 12 | 13 | #ifndef DIVUP 14 | #define DIVUP(x, y) (((x) + (y) - 1) / (y)) 15 | #endif 16 | 17 | #define NoMagma(name) "No CUDA implementation of '" #name "'. Install MAGMA and rebuild cutorch (http://icl.cs.utk.edu/magma/)" 18 | 19 | void THCMagma_init(THCState *state) 20 | { 21 | #ifdef USE_MAGMA 22 | magma_init(); 23 | #endif 24 | } 25 | 26 | #include "generic/THCTensorMathMagma.cu" 27 | #include "THCGenerateAllTypes.h" 28 | -------------------------------------------------------------------------------- /lib/TH/THGenerateCharType.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_GENERIC_FILE 2 | #error "You must define TH_GENERIC_FILE before including THGenerateCharType.h" 3 | #endif 4 | 5 | #define real char 6 | #define accreal long 7 | #define Real Char 8 | #define THInf CHAR_MAX 9 | #define TH_CONVERT_REAL_TO_ACCREAL(_val) (accreal)(_val) 10 | #define TH_CONVERT_ACCREAL_TO_REAL(_val) (real)(_val) 11 | #define TH_REAL_IS_CHAR 12 | #line 1 TH_GENERIC_FILE 13 | #include TH_GENERIC_FILE 14 | #undef real 15 | #undef accreal 16 | #undef Real 17 | #undef THInf 18 | #undef TH_REAL_IS_CHAR 19 | #undef TH_CONVERT_REAL_TO_ACCREAL 20 | #undef TH_CONVERT_ACCREAL_TO_REAL 21 | 22 | #ifndef THGenerateManyTypes 23 | #undef TH_GENERIC_FILE 24 | #endif 25 | -------------------------------------------------------------------------------- /lib/TH/THGenerateLongType.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_GENERIC_FILE 2 | #error "You must define TH_GENERIC_FILE before including THGenerateLongType.h" 3 | #endif 4 | 5 | #define real long 6 | #define accreal long 7 | #define TH_CONVERT_REAL_TO_ACCREAL(_val) (accreal)(_val) 8 | #define TH_CONVERT_ACCREAL_TO_REAL(_val) (real)(_val) 9 | #define Real Long 10 | #define THInf LONG_MAX 11 | #define TH_REAL_IS_LONG 12 | #line 1 TH_GENERIC_FILE 13 | #include TH_GENERIC_FILE 14 | #undef real 15 | #undef accreal 16 | #undef Real 17 | #undef THInf 18 | #undef TH_REAL_IS_LONG 19 | #undef TH_CONVERT_REAL_TO_ACCREAL 20 | #undef TH_CONVERT_ACCREAL_TO_REAL 21 | 22 | #ifndef THGenerateManyTypes 23 | #undef TH_GENERIC_FILE 24 | #endif 25 | -------------------------------------------------------------------------------- /lib/TH/THGenerateFloatType.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_GENERIC_FILE 2 | #error "You must define TH_GENERIC_FILE before including THGenerateFloatType.h" 3 | #endif 4 | 5 | #define real float 6 | #define accreal double 7 | #define TH_CONVERT_REAL_TO_ACCREAL(_val) (accreal)(_val) 8 | #define TH_CONVERT_ACCREAL_TO_REAL(_val) (real)(_val) 9 | #define Real Float 10 | #define THInf FLT_MAX 11 | #define TH_REAL_IS_FLOAT 12 | #line 1 TH_GENERIC_FILE 13 | #include TH_GENERIC_FILE 14 | #undef accreal 15 | #undef real 16 | #undef Real 17 | #undef THInf 18 | #undef TH_REAL_IS_FLOAT 19 | #undef TH_CONVERT_REAL_TO_ACCREAL 20 | #undef TH_CONVERT_ACCREAL_TO_REAL 21 | 22 | #ifndef THGenerateManyTypes 23 | #undef TH_GENERIC_FILE 24 | #endif 25 | -------------------------------------------------------------------------------- /lib/TH/THGenerateShortType.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_GENERIC_FILE 2 | #error "You must define TH_GENERIC_FILE before including THGenerateShortType.h" 3 | #endif 4 | 5 | #define real short 6 | #define accreal long 7 | #define TH_CONVERT_REAL_TO_ACCREAL(_val) (accreal)(_val) 8 | #define TH_CONVERT_ACCREAL_TO_REAL(_val) (real)(_val) 9 | #define Real Short 10 | #define THInf SHRT_MAX 11 | #define TH_REAL_IS_SHORT 12 | #line 1 TH_GENERIC_FILE 13 | #include TH_GENERIC_FILE 14 | #undef real 15 | #undef accreal 16 | #undef Real 17 | #undef THInf 18 | #undef TH_REAL_IS_SHORT 19 | #undef TH_CONVERT_REAL_TO_ACCREAL 20 | #undef TH_CONVERT_ACCREAL_TO_REAL 21 | 22 | #ifndef THGenerateManyTypes 23 | #undef TH_GENERIC_FILE 24 | #endif 25 | -------------------------------------------------------------------------------- /lib/TH/THGenerateByteType.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_GENERIC_FILE 2 | #error "You must define TH_GENERIC_FILE before including THGenerateByteType.h" 3 | #endif 4 | 5 | #define real unsigned char 6 | #define accreal long 7 | #define Real Byte 8 | #define TH_CONVERT_REAL_TO_ACCREAL(_val) (accreal)(_val) 9 | #define TH_CONVERT_ACCREAL_TO_REAL(_val) (real)(_val) 10 | #define THInf UCHAR_MAX 11 | #define TH_REAL_IS_BYTE 12 | #line 1 TH_GENERIC_FILE 13 | #include TH_GENERIC_FILE 14 | #undef real 15 | #undef accreal 16 | #undef Real 17 | #undef THInf 18 | #undef TH_REAL_IS_BYTE 19 | #undef TH_CONVERT_REAL_TO_ACCREAL 20 | #undef TH_CONVERT_ACCREAL_TO_REAL 21 | 22 | #ifndef THGenerateManyTypes 23 | #undef TH_GENERIC_FILE 24 | #endif 25 | -------------------------------------------------------------------------------- /lib/TH/THGenerateDoubleType.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_GENERIC_FILE 2 | #error "You must define TH_GENERIC_FILE before including THGenerateDoubleType.h" 3 | #endif 4 | 5 | #define real double 6 | #define accreal double 7 | #define TH_CONVERT_REAL_TO_ACCREAL(_val) (accreal)(_val) 8 | #define TH_CONVERT_ACCREAL_TO_REAL(_val) (real)(_val) 9 | #define Real Double 10 | #define THInf DBL_MAX 11 | #define TH_REAL_IS_DOUBLE 12 | #line 1 TH_GENERIC_FILE 13 | #include TH_GENERIC_FILE 14 | #undef accreal 15 | #undef real 16 | #undef Real 17 | #undef THInf 18 | #undef TH_REAL_IS_DOUBLE 19 | #undef TH_CONVERT_REAL_TO_ACCREAL 20 | #undef TH_CONVERT_ACCREAL_TO_REAL 21 | 22 | #ifndef THGenerateManyTypes 23 | #undef TH_GENERIC_FILE 24 | #endif 25 | -------------------------------------------------------------------------------- /lib/TH/THDiskFile.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_DISK_FILE_INC 2 | #define TH_DISK_FILE_INC 3 | 4 | #include "THFile.h" 5 | 6 | TH_API THFile *THDiskFile_new(const char *name, const char *mode, int isQuiet); 7 | TH_API THFile *THPipeFile_new(const char *name, const char *mode, int isQuiet); 8 | 9 | TH_API const char *THDiskFile_name(THFile *self); 10 | 11 | TH_API int THDiskFile_isLittleEndianCPU(void); 12 | TH_API int THDiskFile_isBigEndianCPU(void); 13 | TH_API void THDiskFile_nativeEndianEncoding(THFile *self); 14 | TH_API void THDiskFile_littleEndianEncoding(THFile *self); 15 | TH_API void THDiskFile_bigEndianEncoding(THFile *self); 16 | TH_API void THDiskFile_longSize(THFile *self, int size); 17 | TH_API void THDiskFile_noBuffer(THFile *self); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /src/tensor/record.lua: -------------------------------------------------------------------------------- 1 | local Record = {} 2 | 3 | function Record.new() 4 | local self = {indent_=0, txt_={}} 5 | setmetatable(self, {__index=Record}) 6 | return self 7 | end 8 | 9 | function Record:indent() 10 | self.indent_ = self.indent_ + 2 11 | end 12 | 13 | function Record:unindent() 14 | self.indent_ = self.indent_ - 2 15 | end 16 | 17 | function Record:add(stuff) 18 | if stuff then 19 | stuff = stuff:gsub("\n", "\n" .. string.rep(" ", self.indent_)) 20 | stuff = string.rep(" ", self.indent_) .. stuff 21 | stuff = stuff:gsub("%s+$", "") 22 | table.insert(self.txt_, stuff) 23 | end 24 | end 25 | 26 | function Record:tostring() 27 | return table.concat(self.txt_, "\n") 28 | end 29 | 30 | return Record.new 31 | -------------------------------------------------------------------------------- /lib/TH/THGenerateHalfType.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_GENERIC_FILE 2 | #error "You must define TH_GENERIC_FILE before including THGenerateHalfType.h" 3 | #endif 4 | 5 | #include "THHalf.h" 6 | #define real THHalf 7 | #define accreal float 8 | #define TH_CONVERT_REAL_TO_ACCREAL(_val) TH_half2float(_val) 9 | #define TH_CONVERT_ACCREAL_TO_REAL(_val) TH_float2half(_val) 10 | #define Real Half 11 | #define THInf TH_HALF_BITS_TO_LITERAL(TH_HALF_INF) 12 | #define TH_REAL_IS_HALF 13 | #line 1 TH_GENERIC_FILE 14 | #include TH_GENERIC_FILE 15 | #undef real 16 | #undef accreal 17 | #undef Real 18 | #undef THInf 19 | #undef TH_REAL_IS_HALF 20 | #undef TH_CONVERT_REAL_TO_ACCREAL 21 | #undef TH_CONVERT_ACCREAL_TO_REAL 22 | 23 | #ifndef THGenerateManyTypes 24 | #undef TH_GENERIC_FILE 25 | #endif 26 | -------------------------------------------------------------------------------- /lib/THC/THCThrustAllocator.cuh: -------------------------------------------------------------------------------- 1 | #ifndef THC_THRUST_ALLOCATOR_INC 2 | #define THC_THRUST_ALLOCATOR_INC 3 | 4 | #include 5 | 6 | /// Allocator for Thrust to re-route its internal device allocations 7 | /// to the THC allocator 8 | class THCThrustAllocator { 9 | public: 10 | typedef char value_type; 11 | 12 | THCThrustAllocator(THCState* state) 13 | : state_(state) { 14 | } 15 | 16 | ~THCThrustAllocator() { 17 | } 18 | 19 | char* allocate(std::ptrdiff_t size) { 20 | char* out = NULL; 21 | THCudaCheck(THCudaMalloc(state_, (void**) &out, size)); 22 | return out; 23 | } 24 | 25 | void deallocate(char* p, size_t size) { 26 | THCudaCheck(THCudaFree(state_, p)); 27 | } 28 | 29 | private: 30 | THCState* state_; 31 | }; 32 | 33 | #endif // THC_THRUST_ALLOCATOR_INC 34 | -------------------------------------------------------------------------------- /lib/backward/.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | compiler: 3 | - gcc 4 | - clang 5 | 6 | addons: 7 | apt: 8 | packages: 9 | - valgrind 10 | 11 | install: 12 | - DEPS_DIR="${TRAVIS_BUILD_DIR}/deps" 13 | - mkdir ${DEPS_DIR} && cd ${DEPS_DIR} 14 | - CMAKE_URL="http://www.cmake.org/files/v3.3/cmake-3.3.2-Linux-x86_64.tar.gz" 15 | - mkdir cmake && travis_retry wget --no-check-certificate --quiet -O - ${CMAKE_URL} | tar --strip-components=1 -xz -C cmake 16 | - export PATH=${DEPS_DIR}/cmake/bin:${PATH} 17 | - pip install --user conan && export PATH=$PATH:$HOME/.local/bin 18 | - cd ${TRAVIS_BUILD_DIR} 19 | - mkdir build && cd build 20 | - cmake .. -DBACKWARD_TESTS=ON 21 | - cmake --build . 22 | 23 | script: 24 | - valgrind ctest .. --verbose 25 | - cd ${TRAVIS_BUILD_DIR} && conan test_package --build=outdated 26 | -------------------------------------------------------------------------------- /lib/TH/THMath.h: -------------------------------------------------------------------------------- 1 | #ifndef _THMATH_H 2 | #define _THMATH_H 3 | 4 | static inline double TH_sigmoid(double value) { 5 | return 1.0 / (1.0 + exp(-value)); 6 | } 7 | 8 | static inline double TH_frac(double x) { 9 | return x - trunc(x); 10 | } 11 | 12 | static inline double TH_rsqrt(double x) { 13 | return 1.0 / sqrt(x); 14 | } 15 | 16 | static inline double TH_lerp(double a, double b, double weight) { 17 | return a + weight * (b-a); 18 | } 19 | 20 | static inline float TH_sigmoidf(float value) { 21 | return 1.0f / (1.0f + expf(-value)); 22 | } 23 | 24 | static inline float TH_fracf(float x) { 25 | return x - truncf(x); 26 | } 27 | 28 | static inline float TH_rsqrtf(float x) { 29 | return 1.0f / sqrtf(x); 30 | } 31 | 32 | static inline float TH_lerpf(float a, float b, float weight) { 33 | return a + weight * (b-a); 34 | } 35 | 36 | #endif // _THMATH_H 37 | -------------------------------------------------------------------------------- /lib/THC/cmake/FindMAGMA.cmake: -------------------------------------------------------------------------------- 1 | # - Find MAGMA library 2 | # This module finds an installed MAGMA library, a matrix algebra library 3 | # similar to LAPACK for GPU and multicore systems 4 | # (see http://icl.cs.utk.edu/magma/). 5 | # 6 | # This module sets the following variables: 7 | # MAGMA_FOUND - set to true if the MAGMA library is found. 8 | # MAGMA_LIBRARIES - list of libraries to link against to use MAGMA 9 | # MAGMA_INCLUDE_DIR - include directory 10 | 11 | IF(NOT MAGMA_FOUND) 12 | 13 | include(FindPackageHandleStandardArgs) 14 | 15 | SET(MAGMA_LIBRARIES) 16 | SET(MAGMA_INCLUDE_DIR) 17 | 18 | FIND_LIBRARY(MAGMA_LIBRARIES magma /usr/local/magma/lib) 19 | FIND_PATH(MAGMA_INCLUDE_DIR magma.h /usr/local/magma/include) 20 | 21 | IF (MAGMA_LIBRARIES) 22 | SET(MAGMA_FOUND TRUE) 23 | ELSE (MAGMA_LIBRARIES) 24 | SET(MAGMA_FOUND FALSE) 25 | ENDIF (MAGMA_LIBRARIES) 26 | 27 | ENDIF(NOT MAGMA_FOUND) 28 | -------------------------------------------------------------------------------- /lib/TH/THTensor.c: -------------------------------------------------------------------------------- 1 | #include "THAtomic.h" 2 | #include "THTensor.h" 3 | #include "THVector.h" 4 | #include "generic/simd/simd.h" 5 | 6 | #include "THBlas.h" 7 | #include "THLapack.h" 8 | #include "THRandom.h" 9 | #include "THTensorDimApply.h" 10 | #include "THMath.h" 11 | 12 | #include "generic/THTensor.c" 13 | #include "THGenerateAllTypes.h" 14 | 15 | #include "generic/THTensor.c" 16 | #include "THGenerateHalfType.h" 17 | 18 | #include "generic/THTensorCopy.c" 19 | #include "THGenerateAllTypes.h" 20 | 21 | #include "generic/THTensorCopy.c" 22 | #include "THGenerateHalfType.h" 23 | 24 | #include "generic/THTensorRandom.c" 25 | #include "THGenerateAllTypes.h" 26 | 27 | #include "generic/THTensorMath.c" 28 | #include "THGenerateAllTypes.h" 29 | 30 | #include "generic/THTensorConv.c" 31 | #include "THGenerateAllTypes.h" 32 | 33 | #include "generic/THTensorLapack.c" 34 | #include "THGenerateFloatTypes.h" 35 | -------------------------------------------------------------------------------- /lib/TH/generic/THTensorCopy.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_GENERIC_FILE 2 | #define TH_GENERIC_FILE "generic/THTensorCopy.h" 3 | #else 4 | 5 | /* Support for copy between different Tensor types */ 6 | 7 | TH_API void THTensor_(copy)(THTensor *tensor, THTensor *src); 8 | TH_API void THTensor_(copyByte)(THTensor *tensor, struct THByteTensor *src); 9 | TH_API void THTensor_(copyChar)(THTensor *tensor, struct THCharTensor *src); 10 | TH_API void THTensor_(copyShort)(THTensor *tensor, struct THShortTensor *src); 11 | TH_API void THTensor_(copyInt)(THTensor *tensor, struct THIntTensor *src); 12 | TH_API void THTensor_(copyLong)(THTensor *tensor, struct THLongTensor *src); 13 | TH_API void THTensor_(copyFloat)(THTensor *tensor, struct THFloatTensor *src); 14 | TH_API void THTensor_(copyDouble)(THTensor *tensor, struct THDoubleTensor *src); 15 | TH_API void THTensor_(copyHalf)(THTensor *tensor, struct THHalfTensor *src); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /lib/backward/backward.cpp: -------------------------------------------------------------------------------- 1 | // Pick your poison. 2 | // 3 | // On GNU/Linux, you have few choices to get the most out of your stack trace. 4 | // 5 | // By default you get: 6 | // - object filename 7 | // - function name 8 | // 9 | // In order to add: 10 | // - source filename 11 | // - line and column numbers 12 | // - source code snippet (assuming the file is accessible) 13 | 14 | // Install one of the following library then uncomment one of the macro (or 15 | // better, add the detection of the lib and the macro definition in your build 16 | // system) 17 | 18 | // - apt-get install libdw-dev ... 19 | // - g++/clang++ -ldw ... 20 | // #define BACKWARD_HAS_DW 1 21 | 22 | // - apt-get install binutils-dev ... 23 | // - g++/clang++ -lbfd ... 24 | // #define BACKWARD_HAS_BFD 1 25 | 26 | #include "backward.hpp" 27 | 28 | namespace backward { 29 | 30 | backward::SignalHandling sh; 31 | 32 | } // namespace backward 33 | -------------------------------------------------------------------------------- /lib/TH/generic/THVector.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_GENERIC_FILE 2 | #define TH_GENERIC_FILE "generic/THVector.h" 3 | #else 4 | 5 | TH_API void THVector_(fill)(real *x, const real c, const ptrdiff_t n); 6 | TH_API void THVector_(cadd)(real *z, const real *x, const real *y, const real c, const ptrdiff_t n); 7 | TH_API void THVector_(adds)(real *y, const real *x, const real c, const ptrdiff_t n); 8 | TH_API void THVector_(cmul)(real *z, const real *x, const real *y, const ptrdiff_t n); 9 | TH_API void THVector_(muls)(real *y, const real *x, const real c, const ptrdiff_t n); 10 | TH_API void THVector_(cdiv)(real *z, const real *x, const real *y, const ptrdiff_t n); 11 | TH_API void THVector_(divs)(real *y, const real *x, const real c, const ptrdiff_t n); 12 | TH_API void THVector_(copy)(real *y, const real *x, const ptrdiff_t n); 13 | 14 | /* Initialize the dispatch pointers */ 15 | TH_API void THVector_(vectorDispatchInit)(void); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /lib/THC/THCGenerateFloatTypes.h: -------------------------------------------------------------------------------- 1 | #ifndef THC_GENERIC_FILE 2 | #error "You must define THC_GENERIC_FILE before including THGenerateFloatTypes.h" 3 | #endif 4 | 5 | #define THCGenerateFloatTypes 6 | 7 | #define THCTypeIdxByte 1 8 | #define THCTypeIdxChar 2 9 | #define THCTypeIdxShort 3 10 | #define THCTypeIdxInt 4 11 | #define THCTypeIdxLong 5 12 | #define THCTypeIdxFloat 6 13 | #define THCTypeIdxDouble 7 14 | #define THCTypeIdxHalf 8 15 | #define THCTypeIdx_(T) TH_CONCAT_2(THCTypeIdx,T) 16 | 17 | #include "THCGenerateHalfType.h" 18 | #include "THCGenerateFloatType.h" 19 | #include "THCGenerateDoubleType.h" 20 | 21 | #undef THCTypeIdxByte 22 | #undef THCTypeIdxChar 23 | #undef THCTypeIdxShort 24 | #undef THCTypeIdxInt 25 | #undef THCTypeIdxLong 26 | #undef THCTypeIdxFloat 27 | #undef THCTypeIdxDouble 28 | #undef THCTypeIdxHalf 29 | #undef THCTypeIdx_ 30 | 31 | #undef THCGenerateFloatTypes 32 | #undef THC_GENERIC_FILE 33 | -------------------------------------------------------------------------------- /lib/THC/THCDeviceUtils.cuh: -------------------------------------------------------------------------------- 1 | #ifndef THC_DEVICE_UTILS_INC 2 | #define THC_DEVICE_UTILS_INC 3 | 4 | /* The largest consecutive integer representable in float32 (2^24) */ 5 | #define FLOAT32_MAX_CONSECUTIVE_INT 16777216.0f 6 | 7 | /** 8 | Computes ceil(a / b) 9 | */ 10 | template 11 | __host__ __device__ __forceinline__ T THCCeilDiv(T a, T b) { 12 | return (a + b - 1) / b; 13 | } 14 | 15 | /** 16 | Computes ceil(a / b) * b; i.e., rounds up `a` to the next highest 17 | multiple of b 18 | */ 19 | template 20 | __host__ __device__ __forceinline__ T THCRoundUp(T a, T b) { 21 | return THCCeilDiv(a, b) * b; 22 | } 23 | 24 | /** 25 | * For CC 3.5+, perform a load using __ldg 26 | */ 27 | template 28 | __device__ __forceinline__ T doLdg(const T* p) { 29 | #if __CUDA_ARCH__ >= 350 30 | return __ldg(p); 31 | #else 32 | return *p; 33 | #endif 34 | } 35 | 36 | #endif // THC_DEVICE_UTILS_INC 37 | -------------------------------------------------------------------------------- /lib/THC/THCGenerateHalfType.h: -------------------------------------------------------------------------------- 1 | #ifndef THC_GENERIC_FILE 2 | #error "You must define THC_GENERIC_FILE before including THGenerateHalfType.h" 3 | #endif 4 | 5 | #include "THCHalf.h" 6 | 7 | #if defined(CUDA_HALF_TENSOR) || defined(FORCE_TH_HALF) 8 | 9 | #define real half 10 | #define accreal float 11 | #define Real Half 12 | 13 | // if only here via FORCE_TH_HALF, don't define CReal since 14 | // FORCE_TH_HALF should only be used for TH types 15 | #ifdef CUDA_HALF_TENSOR 16 | #define CReal CudaHalf 17 | #endif 18 | 19 | #define THC_REAL_IS_HALF 20 | #line 1 THC_GENERIC_FILE 21 | #include THC_GENERIC_FILE 22 | #undef real 23 | #undef accreal 24 | #undef Real 25 | 26 | #ifdef CUDA_HALF_TENSOR 27 | #undef CReal 28 | #endif 29 | 30 | #undef THC_REAL_IS_HALF 31 | 32 | #endif // defined(CUDA_HALF_TENSOR) || defined(FORCE_TH_HALF) 33 | 34 | #ifndef THCGenerateAllTypes 35 | #ifndef THCGenerateFloatTypes 36 | #undef THC_GENERIC_FILE 37 | #endif 38 | #endif 39 | -------------------------------------------------------------------------------- /src/tensor/lua/src/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h,v 1.45 2015/09/08 15:41:05 roberto Exp $ 3 | ** load precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lundump_h 8 | #define lundump_h 9 | 10 | #include "llimits.h" 11 | #include "lobject.h" 12 | #include "lzio.h" 13 | 14 | 15 | /* data to catch conversion errors */ 16 | #define LUAC_DATA "\x19\x93\r\n\x1a\n" 17 | 18 | #define LUAC_INT 0x5678 19 | #define LUAC_NUM cast_num(370.5) 20 | 21 | #define MYINT(s) (s[0]-'0') 22 | #define LUAC_VERSION (MYINT(LUA_VERSION_MAJOR)*16+MYINT(LUA_VERSION_MINOR)) 23 | #define LUAC_FORMAT 0 /* this is the official format */ 24 | 25 | /* load one chunk; from lundump.c */ 26 | LUAI_FUNC LClosure* luaU_undump (lua_State* L, ZIO* Z, const char* name); 27 | 28 | /* dump one chunk; from ldump.c */ 29 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, 30 | void* data, int strip); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /lib/THC/THCHalf.h: -------------------------------------------------------------------------------- 1 | #ifndef THC_HALF_CONVERSION_INC 2 | #define THC_HALF_CONVERSION_INC 3 | 4 | #include "THCGeneral.h" 5 | 6 | /* We compile with CudaHalfTensor support if we have this: */ 7 | #if CUDA_VERSION >= 7050 || CUDA_HAS_FP16 8 | #define CUDA_HALF_TENSOR 1 9 | #endif 10 | 11 | #ifdef CUDA_HALF_TENSOR 12 | 13 | #include 14 | #include 15 | 16 | THC_EXTERNC void THCFloat2Half(THCState *state, half *out, float *in, ptrdiff_t len); 17 | THC_EXTERNC void THCHalf2Float(THCState *state, float *out, half *in, ptrdiff_t len); 18 | THC_API half THC_float2half(float a); 19 | THC_API float THC_half2float(half a); 20 | 21 | /* Check for native fp16 support on the current device (CC 5.3+) */ 22 | THC_API int THC_nativeHalfInstructions(THCState *state); 23 | 24 | /* Check for performant native fp16 support on the current device */ 25 | THC_API int THC_fastHalfInstructions(THCState *state); 26 | 27 | #endif /* CUDA_HALF_TENSOR */ 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /lib/THC/generic/THCTensorSort.h: -------------------------------------------------------------------------------- 1 | #ifndef THC_GENERIC_FILE 2 | #define THC_GENERIC_FILE "generic/THCTensorSort.h" 3 | #else 4 | 5 | /* Performs an in-place sort of (keys, values). Only works for slice sizes 6 | <= 2048 at the moment (slice size == size of keys/values dim `dim`) */ 7 | THC_API void THCTensor_(sortKeyValueInplace)(THCState* state, 8 | THCTensor* keys, 9 | THCudaLongTensor* values, 10 | int dim, int order); 11 | 12 | /* Performs an out-of-place sort of `input`, returning the per-slice indices 13 | in `indices` and the sorted values in `sorted` */ 14 | THC_API void THCTensor_(sort)(THCState* state, 15 | THCTensor* sorted, 16 | THCudaLongTensor* indices, 17 | THCTensor* input, 18 | int dim, int order); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /lib/TH/generic/THBlas.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_GENERIC_FILE 2 | #define TH_GENERIC_FILE "generic/THBlas.h" 3 | #else 4 | 5 | /* Level 1 */ 6 | TH_API void THBlas_(swap)(long n, real *x, long incx, real *y, long incy); 7 | TH_API void THBlas_(scal)(long n, real a, real *x, long incx); 8 | TH_API void THBlas_(copy)(long n, real *x, long incx, real *y, long incy); 9 | TH_API void THBlas_(axpy)(long n, real a, real *x, long incx, real *y, long incy); 10 | TH_API real THBlas_(dot)(long n, real *x, long incx, real *y, long incy); 11 | 12 | /* Level 2 */ 13 | TH_API void THBlas_(gemv)(char trans, long m, long n, real alpha, real *a, long lda, real *x, long incx, real beta, real *y, long incy); 14 | TH_API void THBlas_(ger)(long m, long n, real alpha, real *x, long incx, real *y, long incy, real *a, long lda); 15 | 16 | /* Level 3 */ 17 | TH_API void THBlas_(gemm)(char transa, char transb, long m, long n, long k, real alpha, real *a, long lda, real *b, long ldb, real beta, real *c, long ldc); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /lib/TH/generic/THStorageCopy.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_GENERIC_FILE 2 | #define TH_GENERIC_FILE "generic/THStorageCopy.h" 3 | #else 4 | 5 | /* Support for copy between different Storage types */ 6 | 7 | TH_API void THStorage_(rawCopy)(THStorage *storage, real *src); 8 | TH_API void THStorage_(copy)(THStorage *storage, THStorage *src); 9 | TH_API void THStorage_(copyByte)(THStorage *storage, struct THByteStorage *src); 10 | TH_API void THStorage_(copyChar)(THStorage *storage, struct THCharStorage *src); 11 | TH_API void THStorage_(copyShort)(THStorage *storage, struct THShortStorage *src); 12 | TH_API void THStorage_(copyInt)(THStorage *storage, struct THIntStorage *src); 13 | TH_API void THStorage_(copyLong)(THStorage *storage, struct THLongStorage *src); 14 | TH_API void THStorage_(copyFloat)(THStorage *storage, struct THFloatStorage *src); 15 | TH_API void THStorage_(copyDouble)(THStorage *storage, struct THDoubleStorage *src); 16 | TH_API void THStorage_(copyHalf)(THStorage *storage, struct THHalfStorage *src); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /lib/THC/THCTensorMath2.cu: -------------------------------------------------------------------------------- 1 | #include "THCTensorMath.h" 2 | #include "THCGeneral.h" 3 | #include "THCBlas.h" 4 | #include "THCTensorCopy.h" 5 | #include "THCTensorRandom.h" 6 | #include "THCApply.cuh" 7 | #include "THCReduce.cuh" 8 | #include "THCTensorMathReduce.cuh" 9 | #include "THCTensorMathPointwise.cuh" 10 | 11 | struct TensorATan2Op { 12 | __device__ __forceinline__ void operator()(float* out, float* a, float* b) { 13 | *out = atan2f(*a, *b); 14 | } 15 | }; 16 | 17 | void THCudaTensor_atan2(THCState *state, THCudaTensor *self_, THCudaTensor *tx, THCudaTensor *ty) 18 | { 19 | THCAssertSameGPU(THCudaTensor_checkGPU(state, 3, self_, tx, ty)); 20 | THArgCheck(THCudaTensor_nElement(state, tx) == 21 | THCudaTensor_nElement(state, ty), 3, "sizes do not match"); 22 | THCudaTensor_resizeAs(state, self_, tx); 23 | 24 | if (!THC_pointwiseApply3(state, self_, tx, ty, TensorATan2Op())) { 25 | THArgCheck(false, 2, CUTORCH_DIM_WARNING); 26 | } 27 | 28 | THCudaCheck(cudaGetLastError()); 29 | } 30 | 31 | -------------------------------------------------------------------------------- /src/tensor/lua/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include(CheckCSourceCompiles) 2 | 3 | check_c_source_compiles( 4 | " 5 | #include 6 | int main() 7 | { 8 | return mkstemp(0); 9 | } 10 | " 11 | HAVE_MKSTEMP) 12 | 13 | if(HAVE_MKSTEMP) 14 | add_definitions(-DLUA_USE_POSIX) 15 | endif() 16 | 17 | set(src 18 | src/lapi.c 19 | src/lauxlib.c 20 | src/lbaselib.c 21 | src/lbitlib.c 22 | src/lcode.c 23 | src/lcorolib.c 24 | src/lctype.c 25 | src/ldblib.c 26 | src/ldebug.c 27 | src/ldo.c 28 | src/ldump.c 29 | src/lfunc.c 30 | src/lgc.c 31 | src/linit.c 32 | src/liolib.c 33 | src/llex.c 34 | src/lmathlib.c 35 | src/lmem.c 36 | src/loadlib.c 37 | src/lobject.c 38 | src/lopcodes.c 39 | src/loslib.c 40 | src/lparser.c 41 | src/lstate.c 42 | src/lstring.c 43 | src/lstrlib.c 44 | src/ltable.c 45 | src/ltablib.c 46 | src/ltm.c 47 | src/lua.c 48 | src/lundump.c 49 | src/lutf8lib.c 50 | src/lvm.c 51 | src/lzio.c 52 | ) 53 | 54 | include_directories(src) 55 | add_executable(lua ${src}) 56 | target_link_libraries(lua m) 57 | -------------------------------------------------------------------------------- /lib/THC/THCThreadLocal.c: -------------------------------------------------------------------------------- 1 | #include "THCThreadLocal.h" 2 | #include "THCGeneral.h" 3 | #ifdef _WIN32 4 | #include 5 | #endif 6 | 7 | 8 | THCThreadLocal THCThreadLocal_alloc(void) 9 | { 10 | #ifndef _WIN32 11 | pthread_key_t key; 12 | THAssert(pthread_key_create(&key, NULL) == 0); 13 | return key; 14 | #else 15 | DWORD key = TlsAlloc(); 16 | THAssert(key != TLS_OUT_OF_INDEXES); 17 | return key; 18 | #endif 19 | } 20 | 21 | void THCThreadLocal_free(THCThreadLocal local) 22 | { 23 | #ifndef _WIN32 24 | THAssert(pthread_key_delete(local) == 0); 25 | #else 26 | THAssert(TlsFree(local)); 27 | #endif 28 | } 29 | 30 | void* THCThreadLocal_get(THCThreadLocal local) 31 | { 32 | #ifndef _WIN32 33 | return pthread_getspecific(local); 34 | #else 35 | return TlsGetValue(local); 36 | #endif 37 | } 38 | 39 | void THCThreadLocal_set(THCThreadLocal local, void* value) 40 | { 41 | #ifndef _WIN32 42 | THAssert(pthread_setspecific(local, value) == 0); 43 | #else 44 | THAssert(TlsSetValue(local, value)); 45 | #endif 46 | } 47 | -------------------------------------------------------------------------------- /lib/TH/THHalf.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_HALF_H 2 | #define TH_HALF_H 3 | 4 | #include "THGeneral.h" 5 | #include 6 | 7 | /* Neither built-in nor included from Cutorch, use our definition lifted from CUDA */ 8 | #if defined(__GNUC__) 9 | #define __thalign__(n) __attribute__((aligned(n))) 10 | #elif defined(_WIN32) 11 | #define __thalign__(n) __declspec(align(n)) 12 | #else 13 | #define __thalign__(n) 14 | #endif 15 | 16 | typedef struct __thalign__(2){ 17 | unsigned short x; 18 | } __THHalf; 19 | 20 | typedef struct __thalign__(4) { 21 | unsigned int x; 22 | } __THHalf2; 23 | 24 | typedef __THHalf THHalf; 25 | typedef __THHalf2 THHalf2; 26 | 27 | TH_API void TH_float2halfbits(float*, unsigned short*); 28 | TH_API void TH_halfbits2float(unsigned short*, float*); 29 | 30 | TH_API THHalf TH_float2half(float); 31 | TH_API float TH_half2float(THHalf); 32 | 33 | #ifndef TH_HALF_BITS_TO_LITERAL 34 | # define TH_HALF_BITS_TO_LITERAL(n) { n } 35 | #endif 36 | 37 | #define TH_HALF_ZERO 0x0U 38 | #define TH_HALF_INF 0x7C00U 39 | 40 | #undef __thalign__ 41 | #endif 42 | -------------------------------------------------------------------------------- /lib/TH/THLapack.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_LAPACK_INC 2 | #define TH_LAPACK_INC 3 | 4 | #include "THGeneral.h" 5 | 6 | #define THLapack_(NAME) TH_CONCAT_4(TH,Real,Lapack_,NAME) 7 | 8 | #define THLapackCheck(fmt, func, info , ...) \ 9 | if (info < 0) { \ 10 | THError("Lapack Error in %s : Illegal Argument %d", func, -info); \ 11 | } else if(info > 0) { \ 12 | THError(fmt, func, info, ##__VA_ARGS__); \ 13 | } \ 14 | 15 | #define THLapackCheckWithCleanup(fmt, cleanup, func, info , ...) \ 16 | if (info < 0) { \ 17 | cleanup \ 18 | THError("Lapack Error in %s : Illegal Argument %d", func, -info); \ 19 | } else if(info > 0) { \ 20 | cleanup \ 21 | THError(fmt, func, info, ##__VA_ARGS__); \ 22 | } 23 | 24 | #include "generic/THLapack.h" 25 | #include "THGenerateAllTypes.h" 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /lib/TH/THTensor.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_TENSOR_INC 2 | #define TH_TENSOR_INC 3 | 4 | #include "THStorage.h" 5 | #include "THTensorApply.h" 6 | 7 | #define THTensor TH_CONCAT_3(TH,Real,Tensor) 8 | #define THTensor_(NAME) TH_CONCAT_4(TH,Real,Tensor_,NAME) 9 | 10 | /* basics */ 11 | #include "generic/THTensor.h" 12 | #include "THGenerateAllTypes.h" 13 | 14 | #include "generic/THTensor.h" 15 | #include "THGenerateHalfType.h" 16 | 17 | #include "generic/THTensorCopy.h" 18 | #include "THGenerateAllTypes.h" 19 | 20 | #include "generic/THTensorCopy.h" 21 | #include "THGenerateHalfType.h" 22 | 23 | #include "THTensorMacros.h" 24 | 25 | /* random numbers */ 26 | #include "THRandom.h" 27 | #include "generic/THTensorRandom.h" 28 | #include "THGenerateAllTypes.h" 29 | 30 | /* maths */ 31 | #include "generic/THTensorMath.h" 32 | #include "THGenerateAllTypes.h" 33 | 34 | /* convolutions */ 35 | #include "generic/THTensorConv.h" 36 | #include "THGenerateAllTypes.h" 37 | 38 | /* lapack support */ 39 | #include "generic/THTensorLapack.h" 40 | #include "THGenerateFloatTypes.h" 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /src/tensor/lua/src/lprefix.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lprefix.h,v 1.2 2014/12/29 16:54:13 roberto Exp $ 3 | ** Definitions for Lua code that must come before any other header file 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lprefix_h 8 | #define lprefix_h 9 | 10 | 11 | /* 12 | ** Allows POSIX/XSI stuff 13 | */ 14 | #if !defined(LUA_USE_C89) /* { */ 15 | 16 | #if !defined(_XOPEN_SOURCE) 17 | #define _XOPEN_SOURCE 600 18 | #elif _XOPEN_SOURCE == 0 19 | #undef _XOPEN_SOURCE /* use -D_XOPEN_SOURCE=0 to undefine it */ 20 | #endif 21 | 22 | /* 23 | ** Allows manipulation of large files in gcc and some other compilers 24 | */ 25 | #if !defined(LUA_32BITS) && !defined(_FILE_OFFSET_BITS) 26 | #define _LARGEFILE_SOURCE 1 27 | #define _FILE_OFFSET_BITS 64 28 | #endif 29 | 30 | #endif /* } */ 31 | 32 | 33 | /* 34 | ** Windows stuff 35 | */ 36 | #if defined(_WIN32) /* { */ 37 | 38 | #if !defined(_CRT_SECURE_NO_WARNINGS) 39 | #define _CRT_SECURE_NO_WARNINGS /* avoid warnings about ISO C functions */ 40 | #endif 41 | 42 | #endif /* } */ 43 | 44 | #endif 45 | 46 | -------------------------------------------------------------------------------- /lib/THC/THCGenerateAllTypes.h: -------------------------------------------------------------------------------- 1 | #ifndef THC_GENERIC_FILE 2 | #error "You must define THC_GENERIC_FILE before including THGenerateAllTypes.h" 3 | #endif 4 | 5 | #define THCGenerateAllTypes 6 | 7 | #define THCTypeIdxByte 1 8 | #define THCTypeIdxChar 2 9 | #define THCTypeIdxShort 3 10 | #define THCTypeIdxInt 4 11 | #define THCTypeIdxLong 5 12 | #define THCTypeIdxFloat 6 13 | #define THCTypeIdxDouble 7 14 | #define THCTypeIdxHalf 8 15 | #define THCTypeIdx_(T) TH_CONCAT_2(THCTypeIdx,T) 16 | 17 | #include "THCGenerateByteType.h" 18 | #include "THCGenerateCharType.h" 19 | #include "THCGenerateShortType.h" 20 | #include "THCGenerateIntType.h" 21 | #include "THCGenerateLongType.h" 22 | #include "THCGenerateHalfType.h" 23 | #include "THCGenerateFloatType.h" 24 | #include "THCGenerateDoubleType.h" 25 | 26 | #undef THCTypeIdxByte 27 | #undef THCTypeIdxChar 28 | #undef THCTypeIdxShort 29 | #undef THCTypeIdxInt 30 | #undef THCTypeIdxLong 31 | #undef THCTypeIdxFloat 32 | #undef THCTypeIdxDouble 33 | #undef THCTypeIdxHalf 34 | #undef THCTypeIdx_ 35 | 36 | #undef THCGenerateAllTypes 37 | #undef THC_GENERIC_FILE 38 | -------------------------------------------------------------------------------- /lib/THC/THCTensorMathReduce.cu: -------------------------------------------------------------------------------- 1 | #include "THCTensorMathReduce.cuh" 2 | 3 | THC_API int 4 | THCudaByteTensor_logicalall(THCState *state, THCudaByteTensor *self) { 5 | THCAssertSameGPU(THCudaByteTensor_checkGPU(state, 1, self)); 6 | unsigned char result; 7 | if (!THC_reduceAll(state, self, 8 | thrust::identity(), 9 | LogicalAll(), 10 | LogicalAll(), 11 | (unsigned char) 1, &result, 0)) { 12 | THArgCheck(false, 1, CUTORCH_DIM_WARNING); 13 | } 14 | 15 | return (int) result; 16 | } 17 | 18 | THC_API int 19 | THCudaByteTensor_logicalany(THCState *state, THCudaByteTensor *self) { 20 | THCAssertSameGPU(THCudaByteTensor_checkGPU(state, 1, self)); 21 | unsigned char result; 22 | if (!THC_reduceAll(state, self, 23 | thrust::identity(), 24 | LogicalAny(), 25 | LogicalAny(), 26 | (unsigned char) 0, &result, 0)) { 27 | THArgCheck(false, 1, CUTORCH_DIM_WARNING); 28 | } 29 | 30 | return (int) result; 31 | } 32 | -------------------------------------------------------------------------------- /lib/THC/generic/THCTensorIndex.h: -------------------------------------------------------------------------------- 1 | #ifndef THC_GENERIC_FILE 2 | #define THC_GENERIC_FILE "generic/THCTensorIndex.h" 3 | #else 4 | 5 | THC_API void THCTensor_(indexCopy)(THCState *state, THCTensor *res_, int dim, THCudaLongTensor *indices, THCTensor *src); 6 | THC_API void THCTensor_(indexAdd)(THCState *state, THCTensor *res_, int dim, THCudaLongTensor *indices, THCTensor *src); 7 | THC_API void THCTensor_(indexFill)(THCState *state, THCTensor *tensor, int dim, THCudaLongTensor *index, real val); 8 | THC_API void THCTensor_(indexSelect)(THCState *state, THCTensor *tensor, THCTensor *src, int dim, THCudaLongTensor *index); 9 | 10 | THC_API void THCTensor_(indexCopy_long)(THCState *state, THCTensor *res_, int dim, THLongTensor *indices, THCTensor *src); 11 | THC_API void THCTensor_(indexAdd_long)(THCState *state, THCTensor *res_, int dim, THLongTensor *indices, THCTensor *src); 12 | THC_API void THCTensor_(indexFill_long)(THCState *state, THCTensor *tensor, int dim, THLongTensor *index, real val); 13 | THC_API void THCTensor_(indexSelect_long)(THCState *state, THCTensor *tensor, THCTensor *src, int dim, THLongTensor *index); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /lib/backward/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright 2013 Google Inc. All Rights Reserved. 2 | 3 | The MIT License (MIT) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /lib/TH/THStorage.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_STORAGE_INC 2 | #define TH_STORAGE_INC 3 | 4 | #include "THGeneral.h" 5 | #include "THAllocator.h" 6 | 7 | #define THStorage TH_CONCAT_3(TH,Real,Storage) 8 | #define THStorage_(NAME) TH_CONCAT_4(TH,Real,Storage_,NAME) 9 | 10 | #define TH_DESC_BUFF_LEN 64 11 | typedef struct { 12 | char str[TH_DESC_BUFF_LEN]; 13 | } THDescBuff; 14 | 15 | /* fast access methods */ 16 | #define TH_STORAGE_GET(storage, idx) ((storage)->data[(idx)]) 17 | #define TH_STORAGE_SET(storage, idx, value) ((storage)->data[(idx)] = (value)) 18 | 19 | #include "generic/THStorage.h" 20 | #include "THGenerateAllTypes.h" 21 | 22 | #include "generic/THStorage.h" 23 | #include "THGenerateHalfType.h" 24 | 25 | #include "generic/THStorageCopy.h" 26 | #include "THGenerateAllTypes.h" 27 | 28 | #include "generic/THStorageCopy.h" 29 | #include "THGenerateHalfType.h" 30 | 31 | TH_API THDescBuff THLongStorage_sizeDesc(const THLongStorage *size); 32 | TH_API THLongStorage *THLongStorage_newInferSize(THLongStorage *size, ptrdiff_t nElement); 33 | TH_API void THLongStorage_calculateExpandGeometry(long *tensorSizes, long *tensorStrides, long tensorDim, THLongStorage *sizes, long **esz, long **est); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /lib/THC/generic/THCTensorMathBlas.h: -------------------------------------------------------------------------------- 1 | #ifndef THC_GENERIC_FILE 2 | #define THC_GENERIC_FILE "generic/THCTensorMathBlas.h" 3 | #else 4 | 5 | THC_API accreal THCTensor_(dot)(THCState *state, THCTensor *self, THCTensor *src); 6 | THC_API void THCTensor_(addmv)(THCState *state, THCTensor *self, real beta, THCTensor *t, real alpha, THCTensor *mat, THCTensor *vec); 7 | THC_API void THCTensor_(addmm)(THCState *state, THCTensor *self, real beta, THCTensor *t, real alpha, THCTensor *mat1, THCTensor *mat2); 8 | THC_API void THCTensor_(addr)(THCState *state, THCTensor *self, real beta, THCTensor *t, real alpha, THCTensor *vec1, THCTensor *vec2); 9 | THC_API void THCTensor_(addbmm)(THCState *state, THCTensor *result, real beta, THCTensor *t, real alpha, THCTensor *batch1, THCTensor *batch2); 10 | THC_API void THCTensor_(baddbmm)(THCState *state, THCTensor *result, real beta, THCTensor *t, real alpha, THCTensor *batch1, THCTensor *batch2); 11 | 12 | THC_API void THCTensor_(btrifact)(THCState *state, THCTensor *ra_, THCudaIntTensor *rpivots_, THCudaIntTensor *rinfo_, THCTensor *a); 13 | THC_API void THCTensor_(btrisolve)(THCState *state, THCTensor *rb_, THCTensor *b, THCTensor *atf, THCudaIntTensor *pivots); 14 | 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /lib/THC/THCReduceApplyUtils.cu: -------------------------------------------------------------------------------- 1 | #include "THCReduceApplyUtils.cuh" 2 | 3 | #include 4 | #include 5 | 6 | // Maximum size per grid dimension that we assume (compute capability >= 2.0) 7 | #define MAX_GRID_SIZE 65535LL 8 | 9 | void THCCheckTensorDims(THCState* state, THCudaTensor* tensor, int arg) { 10 | long dims = THCudaTensor_nDimension(state, tensor); 11 | THArgCheck(dims <= MAX_CUTORCH_DIMS, arg, CUTORCH_DIM_WARNING); 12 | } 13 | 14 | bool THC_getGridFromTiles(ptrdiff_t gridTiles, dim3& grid) { 15 | if (gridTiles > MAX_GRID_SIZE * MAX_GRID_SIZE * MAX_GRID_SIZE) { 16 | return false; 17 | } 18 | 19 | long gridX = gridTiles > MAX_GRID_SIZE ? MAX_GRID_SIZE : gridTiles; 20 | long gridY = 1; 21 | long gridZ = 1; 22 | 23 | if (gridTiles > MAX_GRID_SIZE) { 24 | gridTiles = THCCeilDiv(gridTiles, (ptrdiff_t) MAX_GRID_SIZE); 25 | gridY = gridTiles > MAX_GRID_SIZE ? MAX_GRID_SIZE : gridTiles; 26 | 27 | if (gridTiles > MAX_GRID_SIZE) { 28 | gridTiles = THCCeilDiv(gridTiles, (ptrdiff_t) MAX_GRID_SIZE); 29 | gridZ = gridTiles > MAX_GRID_SIZE ? MAX_GRID_SIZE : gridTiles; 30 | } 31 | } 32 | 33 | grid = dim3(gridX, gridY, gridZ); 34 | return true; 35 | } 36 | -------------------------------------------------------------------------------- /lib/THC/THCDeviceTensorUtils.cuh: -------------------------------------------------------------------------------- 1 | #ifndef THC_DEVICE_TENSOR_UTILS_INC 2 | #define THC_DEVICE_TENSOR_UTILS_INC 3 | 4 | #include "THCDeviceTensor.cuh" 5 | #include "THCTensor.h" 6 | #include 7 | 8 | /// Constructs a DeviceTensor initialized from a THCudaTensor by 9 | /// upcasting or downcasting the tensor to that of a different 10 | /// dimension. 11 | template class PtrTraits> 13 | THCDeviceTensor 14 | toDeviceTensorCast(THCState* state, THCudaTensor* t); 15 | 16 | template 17 | THCDeviceTensor 18 | toDeviceTensorCast(THCState* state, THCudaTensor* t) { 19 | return toDeviceTensorCast(state, t); 20 | } 21 | 22 | template 23 | THCDeviceTensor 24 | toDeviceTensorCast(THCState* state, THCudaTensor* t) { 25 | return toDeviceTensorCast(state, t); 26 | } 27 | 28 | #include "generic/THCDeviceTensorUtils.cu" 29 | #include "THCGenerateAllTypes.h" 30 | 31 | #include "THCDeviceTensorUtils-inl.cuh" 32 | 33 | #endif // THC_DEVICE_TENSOR_UTILS_INC 34 | -------------------------------------------------------------------------------- /lib/THC/generic/THCTensorMathPairwise.h: -------------------------------------------------------------------------------- 1 | #ifndef THC_GENERIC_FILE 2 | #define THC_GENERIC_FILE "generic/THCTensorMathPairwise.h" 3 | #else 4 | 5 | THC_API void THCTensor_(add)(THCState *state, THCTensor *self, THCTensor *src, real value); 6 | THC_API void THCTensor_(sub)(THCState *state, THCTensor *self, THCTensor *src, real value); 7 | THC_API void THCTensor_(mul)(THCState *state, THCTensor *self, THCTensor *src, real value); 8 | THC_API void THCTensor_(div)(THCState *state, THCTensor *self, THCTensor *src, real value); 9 | THC_API void THCTensor_(lshift)(THCState *state, THCTensor *self, THCTensor *src, real value); 10 | THC_API void THCTensor_(rshift)(THCState *state, THCTensor *self, THCTensor *src, real value); 11 | THC_API void THCTensor_(fmod)(THCState *state, THCTensor *self, THCTensor *src, real value); 12 | THC_API void THCTensor_(remainder)(THCState *state, THCTensor *self, THCTensor *src, real value); 13 | THC_API void THCTensor_(bitand)(THCState *state, THCTensor *self, THCTensor *src, real value); 14 | THC_API void THCTensor_(bitor)(THCState *state, THCTensor *self, THCTensor *src, real value); 15 | THC_API void THCTensor_(bitxor)(THCState *state, THCTensor *self, THCTensor *src, real value); 16 | 17 | THC_API int THCTensor_(equal)(THCState *state, THCTensor *self, THCTensor *src); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /lib/backward/test_package/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace backward; 7 | 8 | class TracedException : public std::runtime_error 9 | { 10 | public: 11 | TracedException() : 12 | std::runtime_error(_get_trace()) 13 | {} 14 | 15 | private: 16 | std::string _get_trace() 17 | { 18 | std::ostringstream ss; 19 | 20 | StackTrace stackTrace; 21 | TraceResolver resolver; 22 | stackTrace.load_here(); 23 | resolver.load_stacktrace(stackTrace); 24 | 25 | for(std::size_t i = 0; i < stackTrace.size(); ++i) 26 | { 27 | const ResolvedTrace trace = resolver.resolve(stackTrace[i]); 28 | 29 | ss << "#" << i << " at " << trace.object_function << "\n"; 30 | } 31 | 32 | return ss.str(); 33 | } 34 | }; 35 | 36 | void f(int i) 37 | { 38 | if(i >= 42) 39 | { 40 | throw TracedException(); 41 | } 42 | else 43 | { 44 | std::cout << "i=" << i << "\n"; 45 | f(i + 1); 46 | } 47 | } 48 | 49 | int main() 50 | { 51 | try 52 | { 53 | f(0); 54 | } catch (const TracedException& ex) 55 | { 56 | std::cout << ex.what(); 57 | } 58 | } 59 | 60 | 61 | -------------------------------------------------------------------------------- /lib/THC/THCCachingHostAllocator.h: -------------------------------------------------------------------------------- 1 | #ifndef THC_CACHING_HOST_ALLOCATOR_INC 2 | #define THC_CACHING_HOST_ALLOCATOR_INC 3 | 4 | #include "THCGeneral.h" 5 | #include "THCStream.h" 6 | 7 | // 8 | // A caching allocator for CUDA host allocations (pinned memory). 9 | // 10 | // This provides a drop-in replacement for THCudaHostAllocator, which re-uses 11 | // freed pinned (page-locked) memory allocations. This avoids device 12 | // synchronizations due to cudaFreeHost calls. 13 | // 14 | // To ensure correct behavior, THCCachingHostAllocator_recordEvent must be 15 | // called anytime a pointer from this allocator is used in a cudaMemcpyAsync 16 | // call between host and device. The THC library implements this for storages 17 | // and tensors in THCTensor_(copyAsyncCPU) and THCTensor_(copyAsyncCuda). 18 | // 19 | // Note that this allocator does not split larger allocations into smaller 20 | // blocks, unlike the caching device allocator. 21 | // 22 | THC_API THAllocator THCCachingHostAllocator; 23 | 24 | // Records an event in the specified stream. The allocation 'ptr' will not be 25 | // re-used until the event has occured. 26 | THC_API cudaError_t THCCachingHostAllocator_recordEvent(void *ptr, THCStream *stream); 27 | 28 | // Releases cached pinned memory allocations via cudaHostFree 29 | THC_API void THCCachingHostAllocator_emptyCache(void); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /lib/THC/generic/THCTensorMathCompare.h: -------------------------------------------------------------------------------- 1 | #ifndef THC_GENERIC_FILE 2 | #define THC_GENERIC_FILE "generic/THCTensorMathCompare.h" 3 | #else 4 | 5 | THC_API void THCTensor_(ltValue)(THCState *state, THCudaByteTensor *self_, THCTensor *src, real value); 6 | THC_API void THCTensor_(gtValue)(THCState *state, THCudaByteTensor *self_, THCTensor *src, real value); 7 | THC_API void THCTensor_(leValue)(THCState *state, THCudaByteTensor *self_, THCTensor *src, real value); 8 | THC_API void THCTensor_(geValue)(THCState *state, THCudaByteTensor *self_, THCTensor *src, real value); 9 | THC_API void THCTensor_(eqValue)(THCState *state, THCudaByteTensor *self_, THCTensor *src, real value); 10 | THC_API void THCTensor_(neValue)(THCState *state, THCudaByteTensor *self_, THCTensor *src, real value); 11 | 12 | THC_API void THCTensor_(ltValueT)(THCState *state, THCTensor *self_, THCTensor *src, real value); 13 | THC_API void THCTensor_(gtValueT)(THCState *state, THCTensor *self_, THCTensor *src, real value); 14 | THC_API void THCTensor_(leValueT)(THCState *state, THCTensor *self_, THCTensor *src, real value); 15 | THC_API void THCTensor_(geValueT)(THCState *state, THCTensor *self_, THCTensor *src, real value); 16 | THC_API void THCTensor_(eqValueT)(THCState *state, THCTensor *self_, THCTensor *src, real value); 17 | THC_API void THCTensor_(neValueT)(THCState *state, THCTensor *self_, THCTensor *src, real value); 18 | 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | project(XT) 3 | 4 | # RPATH stuff 5 | # see https://cmake.org/Wiki/CMake_RPATH_handling 6 | if(APPLE) 7 | set(CMAKE_MACOSX_RPATH ON) 8 | endif() 9 | set(CMAKE_SKIP_BUILD_RPATH FALSE) 10 | set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) 11 | set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") 12 | set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) 13 | list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir) 14 | if("${isSystemDir}" STREQUAL "-1") 15 | set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") 16 | endif() 17 | 18 | # C++11 19 | if(CMAKE_VERSION VERSION_LESS "3.1") 20 | set(CMAKE_CXX_FLAGS "--std=c++11 ${CMAKE_CXX_FLAGS}") 21 | else() 22 | set(CMAKE_CXX_STANDARD 11) 23 | endif() 24 | 25 | # Nice trace in debug mode 26 | # see https://github.com/bombela/backward-cpp 27 | if(CMAKE_BUILD_TYPE STREQUAL "Debug") 28 | add_subdirectory(lib/backtrace) 29 | endif() 30 | 31 | # TH stuff 32 | add_subdirectory(lib/TH) 33 | include_directories(${CMAKE_SOURCE_DIR}/lib/TH ${CMAKE_BINARY_DIR}/lib/TH) 34 | find_package(CUDA 5.5) 35 | if(CUDA_FOUND) 36 | add_definitions(-DXT_HAS_CUDA) 37 | include_directories(${CMAKE_SOURCE_DIR}/lib/THC ${CMAKE_BINARY_DIR}/lib/THC ${CUDA_INCLUDE_DIRS}) 38 | add_subdirectory(lib/THC) 39 | else() 40 | message(STATUS "CUDA not found: disabling THC") 41 | endif() 42 | 43 | add_subdirectory(src/tensor) 44 | -------------------------------------------------------------------------------- /lib/THC/THCTensorRandom.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_CUDA_TENSOR_RANDOM_INC 2 | #define TH_CUDA_TENSOR_RANDOM_INC 3 | 4 | #include "THCTensor.h" 5 | 6 | #include "generic/THCTensorRandom.h" 7 | #include "THCGenerateAllTypes.h" 8 | 9 | /* Generator */ 10 | typedef struct _Generator { 11 | struct curandStateMtgp32* gen_states; 12 | struct mtgp32_kernel_params *kernel_params; 13 | int initf; 14 | unsigned long long initial_seed; 15 | } Generator; 16 | 17 | typedef struct THCRNGState { 18 | /* One generator per GPU */ 19 | Generator* gen; 20 | int num_devices; 21 | } THCRNGState; 22 | 23 | struct THCState; 24 | 25 | THC_API void THCRandom_init(struct THCState *state, int num_devices, int current_device); 26 | THC_API void THCRandom_shutdown(struct THCState *state); 27 | THC_API unsigned long long THCRandom_seed(struct THCState *state); 28 | THC_API unsigned long long THCRandom_seedAll(struct THCState *state); 29 | THC_API void THCRandom_manualSeed(struct THCState *state, unsigned long long the_seed_); 30 | THC_API void THCRandom_manualSeedAll(struct THCState *state, unsigned long long the_seed_); 31 | THC_API unsigned long long THCRandom_initialSeed(struct THCState *state); 32 | THC_API void THCRandom_getRNGState(struct THCState *state, THByteTensor *rng_state); 33 | THC_API void THCRandom_setRNGState(struct THCState *state, THByteTensor *rng_state); 34 | 35 | THC_API struct curandStateMtgp32* THCRandom_generatorStates(struct THCState* state); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /lib/THC/generic/THCTensorMathCompareT.h: -------------------------------------------------------------------------------- 1 | #ifndef THC_GENERIC_FILE 2 | #define THC_GENERIC_FILE "generic/THCTensorMathCompareT.h" 3 | #else 4 | 5 | THC_API void THCTensor_(ltTensor)(THCState *state, THCudaByteTensor *self_, THCTensor *src1, THCTensor *src2); 6 | THC_API void THCTensor_(gtTensor)(THCState *state, THCudaByteTensor *self_, THCTensor *src1, THCTensor *src2); 7 | THC_API void THCTensor_(leTensor)(THCState *state, THCudaByteTensor *self_, THCTensor *src1, THCTensor *src2); 8 | THC_API void THCTensor_(geTensor)(THCState *state, THCudaByteTensor *self_, THCTensor *src1, THCTensor *src2); 9 | THC_API void THCTensor_(eqTensor)(THCState *state, THCudaByteTensor *self_, THCTensor *src1, THCTensor *src2); 10 | THC_API void THCTensor_(neTensor)(THCState *state, THCudaByteTensor *self_, THCTensor *src1, THCTensor *src2); 11 | 12 | THC_API void THCTensor_(ltTensorT)(THCState *state, THCTensor *self_, THCTensor *src1, THCTensor *src2); 13 | THC_API void THCTensor_(gtTensorT)(THCState *state, THCTensor *self_, THCTensor *src1, THCTensor *src2); 14 | THC_API void THCTensor_(leTensorT)(THCState *state, THCTensor *self_, THCTensor *src1, THCTensor *src2); 15 | THC_API void THCTensor_(geTensorT)(THCState *state, THCTensor *self_, THCTensor *src1, THCTensor *src2); 16 | THC_API void THCTensor_(eqTensorT)(THCState *state, THCTensor *self_, THCTensor *src1, THCTensor *src2); 17 | THC_API void THCTensor_(neTensorT)(THCState *state, THCTensor *self_, THCTensor *src1, THCTensor *src2); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /lib/THC/THCTensorConv.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_CUDA_TENSOR_CONV_INC 2 | #define TH_CUDA_TENSOR_CONV_INC 3 | 4 | #include "THCTensor.h" 5 | 6 | struct THCState; 7 | 8 | THC_API void THCudaTensor_conv2Dmv(struct THCState *state, THCudaTensor *output, 9 | float beta, THCudaTensor *input, THCudaTensor *kernel, 10 | long srow, long scol, const char *type); 11 | THC_API void THCudaTensor_conv2Dmm(struct THCState *state, THCudaTensor *output, 12 | float beta, THCudaTensor *input, THCudaTensor *kernel, 13 | long srow, long scol, const char *type); 14 | 15 | THC_API void THCudaTensor_conv2DRevger(struct THCState *state, THCudaTensor *output, 16 | float beta, float alpha, THCudaTensor *input, 17 | THCudaTensor *kernel, long srow, long scol); 18 | THC_API void THCudaTensor_conv2DRevgerm(struct THCState *state, THCudaTensor *output, 19 | float beta, float alpha, THCudaTensor *input, 20 | THCudaTensor *kernel, long srow, long scol); 21 | 22 | THC_API void THCudaTensor_conv2Dmap(struct THCState *state, THCudaTensor *output, 23 | THCudaTensor *input, THCudaTensor *kernel, 24 | long stride_x, long stride_y, THCudaTensor *table, long fanin); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /lib/THC/generic/THCTensorRandom.h: -------------------------------------------------------------------------------- 1 | #ifndef THC_GENERIC_FILE 2 | #define THC_GENERIC_FILE "generic/THCTensorRandom.h" 3 | #else 4 | 5 | #if defined(THC_REAL_IS_FLOAT) || defined(THC_REAL_IS_DOUBLE) || defined(THC_REAL_IS_HALF) 6 | 7 | THC_API void THCTensor_(uniform)(struct THCState *state, THCTensor *self, double a, double b); 8 | THC_API void THCTensor_(rand)(THCState *state, THCTensor *r_, THLongStorage *size); 9 | THC_API void THCTensor_(randn)(THCState *state, THCTensor *r_, THLongStorage *size); 10 | THC_API void THCTensor_(normal)(struct THCState *state, THCTensor *self, double mean, double stdv); 11 | THC_API void THCTensor_(logNormal)(struct THCState *state, THCTensor *self, double mean, double stdv); 12 | THC_API void THCTensor_(exponential)(struct THCState *state, THCTensor *self, double lambda); 13 | THC_API void THCTensor_(cauchy)(struct THCState *state, THCTensor *self, double median, double sigma); 14 | THC_API void THCTensor_(multinomial)(struct THCState *state, THCudaLongTensor *self, THCTensor *prob_dist, int n_sample, int with_replacement); 15 | 16 | #endif 17 | 18 | THC_API void THCTensor_(bernoulli)(struct THCState *state, THCTensor *self, double p); 19 | THC_API void THCTensor_(bernoulli_FloatTensor)(struct THCState *state, THCTensor *self, THCudaTensor *p); 20 | THC_API void THCTensor_(bernoulli_DoubleTensor)(struct THCState *state, THCTensor *self, THCudaDoubleTensor *p); 21 | THC_API void THCTensor_(geometric)(struct THCState *state, THCTensor *self, double p); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /lib/TH/generic/THTensorRandom.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_GENERIC_FILE 2 | #define TH_GENERIC_FILE "generic/THTensorRandom.h" 3 | #else 4 | 5 | TH_API void THTensor_(random)(THTensor *self, THGenerator *_generator); 6 | TH_API void THTensor_(geometric)(THTensor *self, THGenerator *_generator, double p); 7 | TH_API void THTensor_(bernoulli)(THTensor *self, THGenerator *_generator, double p); 8 | TH_API void THTensor_(bernoulli_FloatTensor)(THTensor *self, THGenerator *_generator, THFloatTensor *p); 9 | TH_API void THTensor_(bernoulli_DoubleTensor)(THTensor *self, THGenerator *_generator, THDoubleTensor *p); 10 | 11 | #if defined(TH_REAL_IS_FLOAT) || defined(TH_REAL_IS_DOUBLE) 12 | TH_API void THTensor_(uniform)(THTensor *self, THGenerator *_generator, double a, double b); 13 | TH_API void THTensor_(normal)(THTensor *self, THGenerator *_generator, double mean, double stdv); 14 | TH_API void THTensor_(exponential)(THTensor *self, THGenerator *_generator, double lambda); 15 | TH_API void THTensor_(cauchy)(THTensor *self, THGenerator *_generator, double median, double sigma); 16 | TH_API void THTensor_(logNormal)(THTensor *self, THGenerator *_generator, double mean, double stdv); 17 | TH_API void THTensor_(multinomial)(THLongTensor *self, THGenerator *_generator, THTensor *prob_dist, int n_sample, int with_replacement); 18 | #endif 19 | 20 | #if defined(TH_REAL_IS_BYTE) 21 | TH_API void THTensor_(getRNGState)(THGenerator *_generator, THTensor *self); 22 | TH_API void THTensor_(setRNGState)(THGenerator *_generator, THTensor *self); 23 | #endif 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /lib/TH/vector/AVX2.c: -------------------------------------------------------------------------------- 1 | #if defined(__AVX2__) 2 | #ifndef _MSC_VER 3 | #include 4 | #else 5 | #include 6 | #endif 7 | #include "AVX2.h" 8 | 9 | void THDoubleVector_cadd_AVX2(double *z, const double *x, const double *y, const double c, const ptrdiff_t n) { 10 | ptrdiff_t i; 11 | __m256d YMM15 = _mm256_set_pd(c, c, c, c); 12 | __m256d YMM0, YMM1, YMM2, YMM3; 13 | for (i=0; i<=((n)-8); i+=8) { 14 | YMM0 = _mm256_loadu_pd(y+i); 15 | YMM1 = _mm256_loadu_pd(y+i+4); 16 | YMM2 = _mm256_loadu_pd(x+i); 17 | YMM3 = _mm256_loadu_pd(x+i+4); 18 | YMM2 = _mm256_fmadd_pd(YMM0, YMM15, YMM2); 19 | YMM3 = _mm256_fmadd_pd(YMM1, YMM15, YMM3); 20 | _mm256_storeu_pd(z+i, YMM2); 21 | _mm256_storeu_pd(z+i+4, YMM3); 22 | } 23 | for (; i<(n); i++) { 24 | z[i] = x[i] + y[i] * c; 25 | } 26 | } 27 | 28 | void THFloatVector_cadd_AVX2(float *z, const float *x, const float *y, const float c, const ptrdiff_t n) { 29 | ptrdiff_t i; 30 | __m256 YMM15 = _mm256_set_ps(c, c, c, c, c, c, c, c); 31 | __m256 YMM0, YMM1, YMM2, YMM3; 32 | for (i=0; i<=((n)-16); i+=16) { 33 | YMM0 = _mm256_loadu_ps(y+i); 34 | YMM1 = _mm256_loadu_ps(y+i+8); 35 | YMM2 = _mm256_loadu_ps(x+i); 36 | YMM3 = _mm256_loadu_ps(x+i+8); 37 | YMM2 = _mm256_fmadd_ps(YMM0, YMM15, YMM2); 38 | YMM3 = _mm256_fmadd_ps(YMM1, YMM15, YMM3); 39 | _mm256_storeu_ps(z+i, YMM2); 40 | _mm256_storeu_ps(z+i+8, YMM3); 41 | } 42 | for (; i<(n); i++) { 43 | z[i] = x[i] + y[i] * c; 44 | } 45 | } 46 | 47 | #endif // defined(__AVX2__) 48 | -------------------------------------------------------------------------------- /src/tensor/Context.cc: -------------------------------------------------------------------------------- 1 | #include "Context.h" 2 | #include "TH.h" 3 | #ifdef XT_HAS_CUDA 4 | #include "THC.h" 5 | #endif 6 | 7 | namespace xt { 8 | 9 | thread_local Context defaultContext; 10 | 11 | Context::Context() 12 | : generator_(nullptr), thcstate_(nullptr) 13 | { 14 | } 15 | 16 | std::shared_ptr Context::generator(std::shared_ptr gen) 17 | { 18 | if(gen) { 19 | generator_ = gen; 20 | } 21 | if(!generator_) { // init on demand 22 | generator_ = std::shared_ptr(THGenerator_new(), THGenerator_free); 23 | } 24 | return generator_; 25 | } 26 | 27 | std::shared_ptr Context::thcstate(std::shared_ptr state) 28 | { 29 | if(state) { 30 | thcstate_ = state; 31 | } 32 | #ifdef XT_HAS_CUDA 33 | if(!thcstate_) { // init on demand 34 | thcstate_ = std::shared_ptr(THCState_alloc(), THCState_free); 35 | // /* Enable the caching allocator unless THC_CACHING_ALLOCATOR=0 */ 36 | // char* thc_caching_allocator = getenv("THC_CACHING_ALLOCATOR"); 37 | // if (!thc_caching_allocator || strcmp(thc_caching_allocator, "0") != 0) { 38 | // THCState_setDeviceAllocator(state, THCCachingAllocator_get()); 39 | // state->cudaHostAllocator = &THCCachingHostAllocator; 40 | // } 41 | THCudaInit(thcstate_.get()); 42 | } 43 | #endif 44 | return thcstate_; 45 | } 46 | 47 | bool Context::hasGPU() 48 | { 49 | #ifdef XT_HAS_CUDA 50 | return true; 51 | #else 52 | return false; 53 | #endif 54 | } 55 | 56 | Context::~Context() 57 | { 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /lib/TH/vector/AVX.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_AVX_H 2 | #define TH_AVX_H 3 | 4 | #include 5 | 6 | void THDoubleVector_copy_AVX(double *y, const double *x, const ptrdiff_t n); 7 | void THDoubleVector_fill_AVX(double *x, const double c, const ptrdiff_t n); 8 | void THDoubleVector_cdiv_AVX(double *z, const double *x, const double *y, const ptrdiff_t n); 9 | void THDoubleVector_divs_AVX(double *y, const double *x, const double c, const ptrdiff_t n); 10 | void THDoubleVector_cmul_AVX(double *z, const double *x, const double *y, const ptrdiff_t n); 11 | void THDoubleVector_muls_AVX(double *y, const double *x, const double c, const ptrdiff_t n); 12 | void THDoubleVector_cadd_AVX(double *z, const double *x, const double *y, const double c, const ptrdiff_t n); 13 | void THDoubleVector_adds_AVX(double *y, const double *x, const double c, const ptrdiff_t n); 14 | void THFloatVector_copy_AVX(float *y, const float *x, const ptrdiff_t n); 15 | void THFloatVector_fill_AVX(float *x, const float c, const ptrdiff_t n); 16 | void THFloatVector_cdiv_AVX(float *z, const float *x, const float *y, const ptrdiff_t n); 17 | void THFloatVector_divs_AVX(float *y, const float *x, const float c, const ptrdiff_t n); 18 | void THFloatVector_cmul_AVX(float *z, const float *x, const float *y, const ptrdiff_t n); 19 | void THFloatVector_muls_AVX(float *y, const float *x, const float c, const ptrdiff_t n); 20 | void THFloatVector_cadd_AVX(float *z, const float *x, const float *y, const float c, const ptrdiff_t n); 21 | void THFloatVector_adds_AVX(float *y, const float *x, const float c, const ptrdiff_t n); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /src/tensor/lua/src/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h,v 1.45 2017/01/12 17:14:26 roberto Exp $ 3 | ** Lua standard libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lualib_h 9 | #define lualib_h 10 | 11 | #include "lua.h" 12 | 13 | 14 | /* version suffix for environment variable names */ 15 | #define LUA_VERSUFFIX "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR 16 | 17 | 18 | LUAMOD_API int (luaopen_base) (lua_State *L); 19 | 20 | #define LUA_COLIBNAME "coroutine" 21 | LUAMOD_API int (luaopen_coroutine) (lua_State *L); 22 | 23 | #define LUA_TABLIBNAME "table" 24 | LUAMOD_API int (luaopen_table) (lua_State *L); 25 | 26 | #define LUA_IOLIBNAME "io" 27 | LUAMOD_API int (luaopen_io) (lua_State *L); 28 | 29 | #define LUA_OSLIBNAME "os" 30 | LUAMOD_API int (luaopen_os) (lua_State *L); 31 | 32 | #define LUA_STRLIBNAME "string" 33 | LUAMOD_API int (luaopen_string) (lua_State *L); 34 | 35 | #define LUA_UTF8LIBNAME "utf8" 36 | LUAMOD_API int (luaopen_utf8) (lua_State *L); 37 | 38 | #define LUA_BITLIBNAME "bit32" 39 | LUAMOD_API int (luaopen_bit32) (lua_State *L); 40 | 41 | #define LUA_MATHLIBNAME "math" 42 | LUAMOD_API int (luaopen_math) (lua_State *L); 43 | 44 | #define LUA_DBLIBNAME "debug" 45 | LUAMOD_API int (luaopen_debug) (lua_State *L); 46 | 47 | #define LUA_LOADLIBNAME "package" 48 | LUAMOD_API int (luaopen_package) (lua_State *L); 49 | 50 | 51 | /* open all previous libraries */ 52 | LUALIB_API void (luaL_openlibs) (lua_State *L); 53 | 54 | 55 | 56 | #if !defined(lua_assert) 57 | #define lua_assert(x) ((void)0) 58 | #endif 59 | 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /lib/THC/generic/THCTensor.cu: -------------------------------------------------------------------------------- 1 | #ifndef THC_GENERIC_FILE 2 | #define THC_GENERIC_FILE "generic/THCTensor.cu" 3 | #else 4 | 5 | cudaTextureObject_t THCTensor_(getTextureObject)(THCState *state, THCTensor *self) 6 | { 7 | THCAssertSameGPU(THCTensor_(checkGPU)(state, 1, self)); 8 | cudaTextureObject_t texObj; 9 | struct cudaResourceDesc resDesc; 10 | memset(&resDesc, 0, sizeof(resDesc)); 11 | resDesc.resType = cudaResourceTypeLinear; 12 | resDesc.res.linear.devPtr = THCTensor_(data)(state, self); 13 | resDesc.res.linear.sizeInBytes = THCTensor_(nElement)(state, self) * 4; 14 | resDesc.res.linear.desc = cudaCreateChannelDesc(32, 0, 0, 0, 15 | cudaChannelFormatKindFloat); 16 | struct cudaTextureDesc texDesc; 17 | memset(&texDesc, 0, sizeof(texDesc)); 18 | cudaCreateTextureObject(&texObj, &resDesc, &texDesc, NULL); 19 | cudaError errcode = cudaGetLastError(); 20 | if(errcode != cudaSuccess) { 21 | if (THCTensor_(nElement)(state, self) > 2>>27) 22 | THError("Failed to create texture object, " 23 | "nElement:%ld exceeds 27-bit addressing required for tex1Dfetch. Cuda Error: %s", 24 | THCTensor_(nElement)(state, self), cudaGetErrorString(errcode)); 25 | else 26 | THError("Failed to create texture object: %s", cudaGetErrorString(errcode)); 27 | } 28 | return texObj; 29 | } 30 | 31 | THC_API int THCTensor_(getDevice)(THCState* state, const THCTensor* tensor) { 32 | if (!tensor->storage) return -1; 33 | return THCStorage_(getDevice)(state, tensor->storage); 34 | } 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /lib/THC/generic/THCTensorMathMagma.h: -------------------------------------------------------------------------------- 1 | #ifndef THC_GENERIC_FILE 2 | #define THC_GENERIC_FILE "generic/THCTensorMathMagma.h" 3 | #else 4 | 5 | #if defined(THC_REAL_IS_FLOAT) || defined(THC_REAL_IS_DOUBLE) 6 | 7 | // MAGMA (i.e. CUDA implementation of LAPACK functions) 8 | THC_API void THCTensor_(gesv)(THCState *state, THCTensor *rb_, THCTensor *ra_, THCTensor *b_, THCTensor *a_); 9 | THC_API void THCTensor_(gels)(THCState *state, THCTensor *rb_, THCTensor *ra_, THCTensor *b_, THCTensor *a_); 10 | THC_API void THCTensor_(syev)(THCState *state, THCTensor *re_, THCTensor *rv_, THCTensor *a_, const char *jobz, const char *uplo); 11 | THC_API void THCTensor_(geev)(THCState *state, THCTensor *re_, THCTensor *rv_, THCTensor *a_, const char *jobvr); 12 | THC_API void THCTensor_(gesvd)(THCState *state, THCTensor *ru_, THCTensor *rs_, THCTensor *rv_, THCTensor *a, const char *jobu); 13 | THC_API void THCTensor_(gesvd2)(THCState *state, THCTensor *ru_, THCTensor *rs_, THCTensor *rv_, THCTensor *ra_, THCTensor *a, const char *jobu); 14 | THC_API void THCTensor_(getri)(THCState *state, THCTensor *ra_, THCTensor *a); 15 | THC_API void THCTensor_(potri)(THCState *state, THCTensor *ra_, THCTensor *a, const char *uplo); 16 | THC_API void THCTensor_(potrf)(THCState *state, THCTensor *ra_, THCTensor *a, const char *uplo); 17 | THC_API void THCTensor_(potrs)(THCState *state, THCTensor *rb_, THCTensor *a, THCTensor *b, const char *uplo); 18 | THC_API void THCTensor_(qr)(THCState *state, THCTensor *rq_, THCTensor *rr_, THCTensor *a); 19 | 20 | 21 | #endif // defined(THC_REAL_IS_FLOAT) || defined(THC_REAL_IS_DOUBLE) 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /lib/THC/THCHalf.cu: -------------------------------------------------------------------------------- 1 | #include "THCHalf.h" 2 | #include "THCThrustAllocator.cuh" 3 | #include 4 | #include 5 | 6 | struct __half2floatOp { 7 | __device__ float operator()(half v) { return __half2float(v); } 8 | }; 9 | 10 | struct __float2halfOp { 11 | __device__ half operator()(float v) { return __float2half(v); } 12 | }; 13 | 14 | void THCFloat2Half(THCState *state, half *out, float *in, ptrdiff_t len) { 15 | THCThrustAllocator thrustAlloc(state); 16 | thrust::transform( 17 | #if CUDA_VERSION >= 7000 18 | thrust::cuda::par(thrustAlloc).on(THCState_getCurrentStream(state)), 19 | #else 20 | thrust::device, 21 | #endif 22 | in, in + len, out, __float2halfOp()); 23 | } 24 | 25 | void THCHalf2Float(THCState *state, float *out, half *in, ptrdiff_t len) { 26 | THCThrustAllocator thrustAlloc(state); 27 | thrust::transform( 28 | #if CUDA_VERSION >= 7000 29 | thrust::cuda::par(thrustAlloc).on(THCState_getCurrentStream(state)), 30 | #else 31 | thrust::device, 32 | #endif 33 | in, in + len, out, __half2floatOp()); 34 | } 35 | 36 | THC_EXTERNC int THC_nativeHalfInstructions(THCState *state) { 37 | cudaDeviceProp* prop = 38 | THCState_getCurrentDeviceProperties(state); 39 | 40 | // CC 5.3+ 41 | return (prop->major > 5 || 42 | (prop->major == 5 && prop->minor == 3)); 43 | } 44 | 45 | THC_EXTERNC int THC_fastHalfInstructions(THCState *state) { 46 | cudaDeviceProp* prop = 47 | THCState_getCurrentDeviceProperties(state); 48 | 49 | // Check for CC 6.0 only (corresponds to P100) 50 | return (prop->major == 6 && prop->minor == 0); 51 | } 52 | -------------------------------------------------------------------------------- /src/tensor/lua/src/ldebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldebug.h,v 2.14 2015/05/22 17:45:56 roberto Exp $ 3 | ** Auxiliary functions from Debug Interface module 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldebug_h 8 | #define ldebug_h 9 | 10 | 11 | #include "lstate.h" 12 | 13 | 14 | #define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1) 15 | 16 | #define getfuncline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : -1) 17 | 18 | #define resethookcount(L) (L->hookcount = L->basehookcount) 19 | 20 | 21 | LUAI_FUNC l_noret luaG_typeerror (lua_State *L, const TValue *o, 22 | const char *opname); 23 | LUAI_FUNC l_noret luaG_concaterror (lua_State *L, const TValue *p1, 24 | const TValue *p2); 25 | LUAI_FUNC l_noret luaG_opinterror (lua_State *L, const TValue *p1, 26 | const TValue *p2, 27 | const char *msg); 28 | LUAI_FUNC l_noret luaG_tointerror (lua_State *L, const TValue *p1, 29 | const TValue *p2); 30 | LUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1, 31 | const TValue *p2); 32 | LUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...); 33 | LUAI_FUNC const char *luaG_addinfo (lua_State *L, const char *msg, 34 | TString *src, int line); 35 | LUAI_FUNC l_noret luaG_errormsg (lua_State *L); 36 | LUAI_FUNC void luaG_traceexec (lua_State *L); 37 | 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /lib/THC/THCTensorMath.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_CUDA_TENSOR_MATH_INC 2 | #define TH_CUDA_TENSOR_MATH_INC 3 | 4 | #include "THCTensor.h" 5 | #include "THCGeneral.h" 6 | 7 | #include "generic/THCTensorMath.h" 8 | #include "THCGenerateAllTypes.h" 9 | 10 | #include "generic/THCTensorMathBlas.h" 11 | #include "THCGenerateAllTypes.h" 12 | 13 | #include "generic/THCTensorMathMagma.h" 14 | #include "THCGenerateAllTypes.h" 15 | 16 | #include "generic/THCTensorMathPairwise.h" 17 | #include "THCGenerateAllTypes.h" 18 | 19 | #include "generic/THCTensorMathPointwise.h" 20 | #include "THCGenerateAllTypes.h" 21 | 22 | #include "generic/THCTensorMathReduce.h" 23 | #include "THCGenerateAllTypes.h" 24 | 25 | #include "generic/THCTensorMathCompare.h" 26 | #include "THCGenerateAllTypes.h" 27 | 28 | #include "generic/THCTensorMathCompareT.h" 29 | #include "THCGenerateAllTypes.h" 30 | 31 | #include "generic/THCTensorMathScan.h" 32 | #include "THCGenerateAllTypes.h" 33 | 34 | #include "generic/THCTensorMasked.h" 35 | #include "THCGenerateAllTypes.h" 36 | 37 | #include "generic/THCTensorScatterGather.h" 38 | #include "THCGenerateAllTypes.h" 39 | 40 | #include "generic/THCTensorIndex.h" 41 | #include "THCGenerateAllTypes.h" 42 | 43 | #include "generic/THCTensorSort.h" 44 | #include "THCGenerateAllTypes.h" 45 | 46 | #include "generic/THCTensorMode.h" 47 | #include "THCGenerateAllTypes.h" 48 | 49 | #include "generic/THCTensorTopK.h" 50 | #include "THCGenerateAllTypes.h" 51 | 52 | THC_API int THCudaByteTensor_logicalall(THCState *state, THCudaByteTensor *self); 53 | THC_API int THCudaByteTensor_logicalany(THCState *state, THCudaByteTensor *self); 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /lib/THC/THCTensorMasked.cuh: -------------------------------------------------------------------------------- 1 | #ifndef THC_TENSOR_MASKED_CUH 2 | #define THC_TENSOR_MASKED_CUH 3 | #include "THCTensorMath.h" 4 | #include "THCGeneral.h" 5 | #include "THCTensorCopy.h" 6 | #include "THCApply.cuh" 7 | #include "THCReduce.cuh" 8 | #include "THCThrustAllocator.cuh" 9 | 10 | #include 11 | #include 12 | #if CUDA_VERSION >= 7000 13 | #include 14 | #endif 15 | 16 | template 17 | struct TensorMaskedFillOp { 18 | TensorMaskedFillOp(T v) : value(v) {} 19 | __device__ inline void operator()(T* t, MaskT* mask) { 20 | if (*mask) { 21 | *t = value; 22 | } 23 | } 24 | 25 | T value; 26 | }; 27 | 28 | template 29 | struct TensorMaskedCopyOp { 30 | TensorMaskedCopyOp(T* s) : in(s) {} 31 | 32 | __device__ inline void operator()(T* out, 33 | MaskT* mask, 34 | MaskPrefixSumT* maskPrefixSum) { 35 | if (*mask) { 36 | *out = in[*maskPrefixSum]; 37 | } 38 | } 39 | 40 | // Where we are copying from 41 | T* in; 42 | }; 43 | 44 | template 45 | struct TensorMaskedSelectOp { 46 | TensorMaskedSelectOp(T* t) : out(t) {} 47 | __device__ inline void operator()(MaskT* mask, 48 | MaskPrefixSumT* maskPrefixSum, 49 | T* in) { 50 | if (*mask) { 51 | out[*maskPrefixSum] = *in; 52 | } 53 | } 54 | 55 | T* out; 56 | }; 57 | 58 | #endif // THC_TENSOR_MASKED_CUH 59 | -------------------------------------------------------------------------------- /src/tensor/lua/src/lstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.h,v 1.61 2015/11/03 15:36:01 roberto Exp $ 3 | ** String table (keep all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lstring_h 8 | #define lstring_h 9 | 10 | #include "lgc.h" 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | 14 | 15 | #define sizelstring(l) (sizeof(union UTString) + ((l) + 1) * sizeof(char)) 16 | 17 | #define sizeludata(l) (sizeof(union UUdata) + (l)) 18 | #define sizeudata(u) sizeludata((u)->len) 19 | 20 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ 21 | (sizeof(s)/sizeof(char))-1)) 22 | 23 | 24 | /* 25 | ** test whether a string is a reserved word 26 | */ 27 | #define isreserved(s) ((s)->tt == LUA_TSHRSTR && (s)->extra > 0) 28 | 29 | 30 | /* 31 | ** equality for short strings, which are always internalized 32 | */ 33 | #define eqshrstr(a,b) check_exp((a)->tt == LUA_TSHRSTR, (a) == (b)) 34 | 35 | 36 | LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed); 37 | LUAI_FUNC unsigned int luaS_hashlongstr (TString *ts); 38 | LUAI_FUNC int luaS_eqlngstr (TString *a, TString *b); 39 | LUAI_FUNC void luaS_resize (lua_State *L, int newsize); 40 | LUAI_FUNC void luaS_clearcache (global_State *g); 41 | LUAI_FUNC void luaS_init (lua_State *L); 42 | LUAI_FUNC void luaS_remove (lua_State *L, TString *ts); 43 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s); 44 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); 45 | LUAI_FUNC TString *luaS_new (lua_State *L, const char *str); 46 | LUAI_FUNC TString *luaS_createlngstrobj (lua_State *L, size_t l); 47 | 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /src/tensor/lua/src/lzio.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.c,v 1.37 2015/09/08 15:41:05 roberto Exp $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lzio_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "llimits.h" 18 | #include "lmem.h" 19 | #include "lstate.h" 20 | #include "lzio.h" 21 | 22 | 23 | int luaZ_fill (ZIO *z) { 24 | size_t size; 25 | lua_State *L = z->L; 26 | const char *buff; 27 | lua_unlock(L); 28 | buff = z->reader(L, z->data, &size); 29 | lua_lock(L); 30 | if (buff == NULL || size == 0) 31 | return EOZ; 32 | z->n = size - 1; /* discount char being returned */ 33 | z->p = buff; 34 | return cast_uchar(*(z->p++)); 35 | } 36 | 37 | 38 | void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { 39 | z->L = L; 40 | z->reader = reader; 41 | z->data = data; 42 | z->n = 0; 43 | z->p = NULL; 44 | } 45 | 46 | 47 | /* --------------------------------------------------------------- read --- */ 48 | size_t luaZ_read (ZIO *z, void *b, size_t n) { 49 | while (n) { 50 | size_t m; 51 | if (z->n == 0) { /* no bytes in buffer? */ 52 | if (luaZ_fill(z) == EOZ) /* try to read more */ 53 | return n; /* no more input; return number of missing bytes */ 54 | else { 55 | z->n++; /* luaZ_fill consumed first byte; put it back */ 56 | z->p--; 57 | } 58 | } 59 | m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ 60 | memcpy(b, z->p, m); 61 | z->n -= m; 62 | z->p += m; 63 | b = (char *)b + m; 64 | n -= m; 65 | } 66 | return 0; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /lib/THC/THCStream.cpp: -------------------------------------------------------------------------------- 1 | #include "THCStream.h" 2 | 3 | #include 4 | #include 5 | #include "THAtomic.h" 6 | 7 | #define MAX_DEVICES 256 8 | static THCStream default_streams[MAX_DEVICES]; 9 | 10 | static void initialize_default_streams() 11 | { 12 | for (int i = 0; i < MAX_DEVICES; i++) { 13 | default_streams[i].device = i; 14 | } 15 | } 16 | 17 | THCStream* THCStream_new(int flags) 18 | { 19 | THCStream* self = (THCStream*) malloc(sizeof(THCStream)); 20 | self->refcount = 1; 21 | THCudaCheck(cudaGetDevice(&self->device)); 22 | THCudaCheck(cudaStreamCreateWithFlags(&self->stream, flags)); 23 | return self; 24 | } 25 | 26 | THC_API THCStream* THCStream_defaultStream(int device) 27 | { 28 | // default streams aren't refcounted 29 | THAssert(device >= 0 && device < MAX_DEVICES); 30 | std::once_flag once; 31 | std::call_once(once, &initialize_default_streams); 32 | return &default_streams[device]; 33 | } 34 | 35 | THCStream* THCStream_newWithPriority(int flags, int priority) 36 | { 37 | THCStream* self = (THCStream*) malloc(sizeof(THCStream)); 38 | self->refcount = 1; 39 | THCudaCheck(cudaGetDevice(&self->device)); 40 | THCudaCheck(cudaStreamCreateWithPriority(&self->stream, flags, priority)); 41 | return self; 42 | } 43 | 44 | void THCStream_free(THCStream* self) 45 | { 46 | if (!self || !self->stream) { 47 | return; 48 | } 49 | if (THAtomicDecrementRef(&self->refcount)) { 50 | THCudaCheckWarn(cudaStreamDestroy(self->stream)); 51 | free(self); 52 | } 53 | } 54 | 55 | void THCStream_retain(THCStream* self) 56 | { 57 | if (self->stream) { 58 | THAtomicIncrementRef(&self->refcount); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /lib/TH/THAllocator.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_ALLOCATOR_INC 2 | #define TH_ALLOCATOR_INC 3 | 4 | #include "THGeneral.h" 5 | 6 | #define TH_ALLOCATOR_MAPPED_SHARED 1 7 | #define TH_ALLOCATOR_MAPPED_SHAREDMEM 2 8 | #define TH_ALLOCATOR_MAPPED_EXCLUSIVE 4 9 | #define TH_ALLOCATOR_MAPPED_NOCREATE 8 10 | #define TH_ALLOCATOR_MAPPED_KEEPFD 16 11 | #define TH_ALLOCATOR_MAPPED_FROMFD 32 12 | #define TH_ALLOCATOR_MAPPED_UNLINK 64 13 | 14 | /* Custom allocator 15 | */ 16 | typedef struct THAllocator { 17 | void* (*malloc)(void*, ptrdiff_t); 18 | void* (*realloc)(void*, void*, ptrdiff_t); 19 | void (*free)(void*, void*); 20 | } THAllocator; 21 | 22 | /* default malloc/free allocator. malloc and realloc raise an error (using 23 | * THError) on allocation failure. 24 | */ 25 | extern THAllocator THDefaultAllocator; 26 | 27 | /* file map allocator 28 | */ 29 | typedef struct THMapAllocatorContext_ THMapAllocatorContext; 30 | TH_API THMapAllocatorContext *THMapAllocatorContext_new(const char *filename, int flags); 31 | TH_API THMapAllocatorContext *THMapAllocatorContext_newWithFd(const char *filename, 32 | int fd, int flags); 33 | TH_API char * THMapAllocatorContext_filename(THMapAllocatorContext *ctx); 34 | TH_API int THMapAllocatorContext_fd(THMapAllocatorContext *ctx); 35 | TH_API ptrdiff_t THMapAllocatorContext_size(THMapAllocatorContext *ctx); 36 | TH_API void THMapAllocatorContext_free(THMapAllocatorContext *ctx); 37 | TH_API void THRefcountedMapAllocator_incref(THMapAllocatorContext *ctx, void *data); 38 | TH_API int THRefcountedMapAllocator_decref(THMapAllocatorContext *ctx, void *data); 39 | 40 | extern THAllocator THMapAllocator; 41 | extern THAllocator THRefcountedMapAllocator; 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /lib/backward/builds.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | COMPILERS_CXX98=`cat</dev/null 28 | ( 29 | cd "$builddir" 30 | cmake -DCMAKE_BUILD_TYPE=$buildtype -DBACKWARD_TESTS=ON .. 31 | ) 32 | } 33 | 34 | function build() { 35 | local builddir=$1 36 | shift 37 | make -C "$builddir" $@ 38 | } 39 | 40 | function dotest() { 41 | local builddir=$1 42 | shift 43 | make -C "$builddir" test $@ 44 | return 0 45 | } 46 | 47 | function do_action() { 48 | local lang=$1 49 | local action=$2 50 | shift 2 51 | 52 | for compiler in $COMPILERS; do 53 | local builddir="build_${lang}_${compiler}" 54 | 55 | if [[ $action == "cmake" ]]; then 56 | buildtype=$1 57 | mkbuild $compiler $lang "$buildtype" "$builddir" 58 | [[ $? != 0 ]] && exit 59 | elif [[ $action == "make" ]]; then 60 | build "$builddir" $@ 61 | [[ $? != 0 ]] && exit 62 | elif [[ $action == "test" ]]; then 63 | dotest "$builddir" $@ 64 | [[ $? != 0 ]] && exit 65 | elif [[ $action == "clean" ]]; then 66 | rm -r "$builddir" 67 | else 68 | echo "usage: $0 cmake [debug|release|relwithdbg]|make|test|clean" 69 | exit 255 70 | fi 71 | done 72 | } 73 | 74 | COMPILERS=$COMPILERS_CXX98 75 | do_action c++98 $@ 76 | COMPILERS=$COMPILERS_CXX11 77 | do_action c++11 $@ 78 | -------------------------------------------------------------------------------- /lib/TH/THTensorMacros.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_TENSOR_MACROS_INC 2 | #define TH_TENSOR_MACROS_INC 3 | 4 | /* fast method to access to tensor data */ 5 | 6 | #define THTensor_fastGet1d(self, x0) \ 7 | (((self)->storage->data+(self)->storageOffset)[(x0)*(self)->stride[0]]) 8 | 9 | #define THTensor_fastGet2d(self, x0, x1) \ 10 | (((self)->storage->data+(self)->storageOffset)[(x0)*(self)->stride[0]+(x1)*(self)->stride[1]]) 11 | 12 | #define THTensor_fastGet3d(self, x0, x1, x2) \ 13 | (((self)->storage->data+(self)->storageOffset)[(x0)*(self)->stride[0]+(x1)*(self)->stride[1]+(x2)*(self)->stride[2]]) 14 | 15 | #define THTensor_fastGet4d(self, x0, x1, x2, x3) \ 16 | (((self)->storage->data+(self)->storageOffset)[(x0)*(self)->stride[0]+(x1)*(self)->stride[1]+(x2)*(self)->stride[2]+(x3)*(self)->stride[3]]) 17 | 18 | #define THTensor_fastSet1d(self, x0, value) \ 19 | (((self)->storage->data+(self)->storageOffset)[(x0)*(self)->stride[0]] = value) 20 | 21 | #define THTensor_fastSet2d(self, x0, x1, value) \ 22 | (((self)->storage->data+(self)->storageOffset)[(x0)*(self)->stride[0]+(x1)*(self)->stride[1]] = value) 23 | 24 | #define THTensor_fastSet3d(self, x0, x1, x2, value) \ 25 | (((self)->storage->data+(self)->storageOffset)[(x0)*(self)->stride[0]+(x1)*(self)->stride[1]+(x2)*(self)->stride[2]] = value) 26 | 27 | #define THTensor_fastSet4d(self, x0, x1, x2, x3, value) \ 28 | (((self)->storage->data+(self)->storageOffset)[(x0)*(self)->stride[0]+(x1)*(self)->stride[1]+(x2)*(self)->stride[2]+(x3)*(self)->stride[3]] = value) 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /lib/THC/generic/THCTensorMath.h: -------------------------------------------------------------------------------- 1 | #ifndef THC_GENERIC_FILE 2 | #define THC_GENERIC_FILE "generic/THCTensorMath.h" 3 | #else 4 | 5 | THC_API void THCTensor_(fill)(THCState *state, THCTensor *self, real value); 6 | THC_API void THCTensor_(zero)(THCState *state, THCTensor *self); 7 | 8 | THC_API void THCTensor_(zeros)(THCState *state, THCTensor *r_, THLongStorage *size); 9 | THC_API void THCTensor_(ones)(THCState *state, THCTensor *r_, THLongStorage *size); 10 | THC_API void THCTensor_(reshape)(THCState *state, THCTensor *r_, THCTensor *t, THLongStorage *size); 11 | THC_API ptrdiff_t THCTensor_(numel)(THCState *state, THCTensor *t); 12 | THC_API void THCTensor_(cat)(THCState *state, THCTensor *result, THCTensor *ta, THCTensor *tb, int dimension); 13 | THC_API void THCTensor_(catArray)(THCState *state, THCTensor *result, THCTensor **inputs, int numInputs, int dimension); 14 | THC_API void THCTensor_(nonzero)(THCState* state, THCudaLongTensor *tensor, THCTensor *self); 15 | 16 | THC_API void THCTensor_(tril)(THCState *state, THCTensor *self, THCTensor *src, long k); 17 | THC_API void THCTensor_(triu)(THCState *state, THCTensor *self, THCTensor *src, long k); 18 | THC_API void THCTensor_(diag)(THCState *state, THCTensor *self, THCTensor *src, long k); 19 | THC_API accreal THCTensor_(trace)(THCState *state, THCTensor *self); 20 | 21 | #if defined(THC_REAL_IS_FLOAT) || defined(THC_REAL_IS_DOUBLE) || defined(THC_REAL_IS_HALF) 22 | 23 | THC_API void THCTensor_(linspace)(THCState *state, THCTensor *r_, real a, real b, long n); 24 | THC_API void THCTensor_(logspace)(THCState *state, THCTensor *r_, real a, real b, long n); 25 | 26 | #endif 27 | 28 | THC_API void THCTensor_(range)(THCState *state, THCTensor *r_, accreal xmin, accreal xmax, accreal step); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/tensor/lua/src/lzio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.h,v 1.31 2015/09/08 15:41:05 roberto Exp $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lzio_h 9 | #define lzio_h 10 | 11 | #include "lua.h" 12 | 13 | #include "lmem.h" 14 | 15 | 16 | #define EOZ (-1) /* end of stream */ 17 | 18 | typedef struct Zio ZIO; 19 | 20 | #define zgetc(z) (((z)->n--)>0 ? cast_uchar(*(z)->p++) : luaZ_fill(z)) 21 | 22 | 23 | typedef struct Mbuffer { 24 | char *buffer; 25 | size_t n; 26 | size_t buffsize; 27 | } Mbuffer; 28 | 29 | #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) 30 | 31 | #define luaZ_buffer(buff) ((buff)->buffer) 32 | #define luaZ_sizebuffer(buff) ((buff)->buffsize) 33 | #define luaZ_bufflen(buff) ((buff)->n) 34 | 35 | #define luaZ_buffremove(buff,i) ((buff)->n -= (i)) 36 | #define luaZ_resetbuffer(buff) ((buff)->n = 0) 37 | 38 | 39 | #define luaZ_resizebuffer(L, buff, size) \ 40 | ((buff)->buffer = luaM_reallocvchar(L, (buff)->buffer, \ 41 | (buff)->buffsize, size), \ 42 | (buff)->buffsize = size) 43 | 44 | #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) 45 | 46 | 47 | LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, 48 | void *data); 49 | LUAI_FUNC size_t luaZ_read (ZIO* z, void *b, size_t n); /* read next n bytes */ 50 | 51 | 52 | 53 | /* --------- Private Part ------------------ */ 54 | 55 | struct Zio { 56 | size_t n; /* bytes still unread */ 57 | const char *p; /* current position in buffer */ 58 | lua_Reader reader; /* reader function */ 59 | void *data; /* additional data */ 60 | lua_State *L; /* Lua state (for reader) */ 61 | }; 62 | 63 | 64 | LUAI_FUNC int luaZ_fill (ZIO *z); 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /lib/THC/generic/THCTensorMasked.h: -------------------------------------------------------------------------------- 1 | #ifndef THC_GENERIC_FILE 2 | #define THC_GENERIC_FILE "generic/THCTensorMasked.h" 3 | #else 4 | 5 | THC_API void THCTensor_(maskedFill)(THCState *state, 6 | THCTensor *tensor, 7 | THCudaByteTensor *mask, 8 | real value); 9 | 10 | // FIXME: remove now that we have THCudaByteTensor? 11 | THC_API void THCTensor_(maskedFillByte)(THCState *state, 12 | THCTensor *tensor, 13 | THByteTensor *mask, 14 | real value); 15 | 16 | THC_API void THCTensor_(maskedCopy)(THCState *state, 17 | THCTensor *tensor, 18 | THCudaByteTensor *mask, 19 | THCTensor *src); 20 | 21 | // FIXME: remove now that we have THCudaByteTensor? 22 | THC_API void THCTensor_(maskedCopyByte)(THCState *state, 23 | THCTensor *tensor, 24 | THByteTensor *mask, 25 | THCTensor *src); 26 | 27 | THC_API void THCTensor_(maskedSelect)(THCState *state, 28 | THCTensor *tensor, 29 | THCTensor *src, 30 | THCudaByteTensor *mask); 31 | 32 | // FIXME: remove now that we have THCudaByteTensor? 33 | THC_API void THCTensor_(maskedSelectByte)(THCState *state, 34 | THCTensor *tensor, 35 | THCTensor *src, 36 | THByteTensor *mask); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /lib/TH/generic/THTensorLapack.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_GENERIC_FILE 2 | #define TH_GENERIC_FILE "generic/THTensorLapack.h" 3 | #else 4 | 5 | TH_API void THTensor_(gesv)(THTensor *rb_, THTensor *ra_, THTensor *b_, THTensor *a_); 6 | TH_API void THTensor_(trtrs)(THTensor *rb_, THTensor *ra_, THTensor *b_, THTensor *a_, const char *uplo, const char *trans, const char *diag); 7 | TH_API void THTensor_(gels)(THTensor *rb_, THTensor *ra_, THTensor *b_, THTensor *a_); 8 | TH_API void THTensor_(syev)(THTensor *re_, THTensor *rv_, THTensor *a_, const char *jobz, const char *uplo); 9 | TH_API void THTensor_(geev)(THTensor *re_, THTensor *rv_, THTensor *a_, const char *jobvr); 10 | TH_API void THTensor_(gesvd)(THTensor *ru_, THTensor *rs_, THTensor *rv_, THTensor *a, const char *jobu); 11 | TH_API void THTensor_(gesvd2)(THTensor *ru_, THTensor *rs_, THTensor *rv_, THTensor *ra_, THTensor *a, const char *jobu); 12 | TH_API void THTensor_(getri)(THTensor *ra_, THTensor *a); 13 | TH_API void THTensor_(potrf)(THTensor *ra_, THTensor *a, const char *uplo); 14 | TH_API void THTensor_(potrs)(THTensor *rb_, THTensor *b_, THTensor *a_, const char *uplo); 15 | TH_API void THTensor_(potri)(THTensor *ra_, THTensor *a, const char *uplo); 16 | TH_API void THTensor_(qr)(THTensor *rq_, THTensor *rr_, THTensor *a); 17 | TH_API void THTensor_(geqrf)(THTensor *ra_, THTensor *rtau_, THTensor *a); 18 | TH_API void THTensor_(orgqr)(THTensor *ra_, THTensor *a, THTensor *tau); 19 | TH_API void THTensor_(ormqr)(THTensor *ra_, THTensor *a, THTensor *tau, THTensor *c, const char *side, const char *trans); 20 | TH_API void THTensor_(pstrf)(THTensor *ra_, THIntTensor *rpiv_, THTensor*a, const char* uplo, real tol); 21 | 22 | TH_API void THTensor_(btrifact)(THTensor *ra_, THIntTensor *rpivots_, THIntTensor *rinfo_, THTensor *a); 23 | TH_API void THTensor_(btrisolve)(THTensor *rb_, THTensor *b, THTensor *atf, THIntTensor *pivots); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /lib/TH/THFilePrivate.h: -------------------------------------------------------------------------------- 1 | #include "THGeneral.h" 2 | 3 | #include "THHalf.h" 4 | 5 | 6 | struct THFile__ 7 | { 8 | struct THFileVTable *vtable; 9 | 10 | int isQuiet; 11 | int isReadable; 12 | int isWritable; 13 | int isBinary; 14 | int isAutoSpacing; 15 | int hasError; 16 | }; 17 | 18 | /* virtual table definition */ 19 | 20 | struct THFileVTable 21 | { 22 | int (*isOpened)(THFile *self); 23 | 24 | size_t (*readByte)(THFile *self, unsigned char *data, size_t n); 25 | size_t (*readChar)(THFile *self, char *data, size_t n); 26 | size_t (*readShort)(THFile *self, short *data, size_t n); 27 | size_t (*readInt)(THFile *self, int *data, size_t n); 28 | size_t (*readLong)(THFile *self, long *data, size_t n); 29 | size_t (*readFloat)(THFile *self, float *data, size_t n); 30 | size_t (*readDouble)(THFile *self, double *data, size_t n); 31 | size_t (*readHalf)(THFile *self, THHalf *data, size_t n); 32 | size_t (*readString)(THFile *self, const char *format, char **str_); 33 | 34 | size_t (*writeByte)(THFile *self, unsigned char *data, size_t n); 35 | size_t (*writeChar)(THFile *self, char *data, size_t n); 36 | size_t (*writeShort)(THFile *self, short *data, size_t n); 37 | size_t (*writeInt)(THFile *self, int *data, size_t n); 38 | size_t (*writeLong)(THFile *self, long *data, size_t n); 39 | size_t (*writeFloat)(THFile *self, float *data, size_t n); 40 | size_t (*writeDouble)(THFile *self, double *data, size_t n); 41 | size_t (*writeHalf)(THFile *self, THHalf *data, size_t n); 42 | size_t (*writeString)(THFile *self, const char *str, size_t size); 43 | 44 | void (*synchronize)(THFile *self); 45 | void (*seek)(THFile *self, size_t position); 46 | void (*seekEnd)(THFile *self); 47 | size_t (*position)(THFile *self); 48 | void (*close)(THFile *self); 49 | void (*free)(THFile *self); 50 | }; 51 | -------------------------------------------------------------------------------- /src/tensor/lua/src/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h,v 2.15 2015/01/13 15:49:11 roberto Exp $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lfunc_h 8 | #define lfunc_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | #define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \ 15 | cast(int, sizeof(TValue)*((n)-1))) 16 | 17 | #define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \ 18 | cast(int, sizeof(TValue *)*((n)-1))) 19 | 20 | 21 | /* test whether thread is in 'twups' list */ 22 | #define isintwups(L) (L->twups != L) 23 | 24 | 25 | /* 26 | ** maximum number of upvalues in a closure (both C and Lua). (Value 27 | ** must fit in a VM register.) 28 | */ 29 | #define MAXUPVAL 255 30 | 31 | 32 | /* 33 | ** Upvalues for Lua closures 34 | */ 35 | struct UpVal { 36 | TValue *v; /* points to stack or to its own value */ 37 | lu_mem refcount; /* reference counter */ 38 | union { 39 | struct { /* (when open) */ 40 | UpVal *next; /* linked list */ 41 | int touched; /* mark to avoid cycles with dead threads */ 42 | } open; 43 | TValue value; /* the value (when closed) */ 44 | } u; 45 | }; 46 | 47 | #define upisopen(up) ((up)->v != &(up)->u.value) 48 | 49 | 50 | LUAI_FUNC Proto *luaF_newproto (lua_State *L); 51 | LUAI_FUNC CClosure *luaF_newCclosure (lua_State *L, int nelems); 52 | LUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nelems); 53 | LUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl); 54 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); 55 | LUAI_FUNC void luaF_close (lua_State *L, StkId level); 56 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 57 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 58 | int pc); 59 | 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /lib/THC/generic/THCTensorCopy.cu: -------------------------------------------------------------------------------- 1 | #ifndef THC_GENERIC_FILE 2 | #define THC_GENERIC_FILE "generic/THCTensorCopy.cu" 3 | #else 4 | 5 | THC_API void 6 | THCTensor_(copy)(THCState* state, THCTensor* dst, THCTensor* src) { 7 | THC_copyTensor(state, dst, src); 8 | } 9 | 10 | THC_API void 11 | THCTensor_(copyIgnoringOverlaps)(THCState* state, THCTensor* dst, THCTensor* src) { 12 | // Called when we are copying into an overlapping index `dst`, but 13 | // we don't care which writer wins. Hacky but it works. 14 | // This is itself invoked by pointwiseApply2 / THCTensor_copy in 15 | // case that there are write overlaps. 16 | // FIXME: really, overlapping writes should be illegal/an error in Torch 17 | THC_pointwiseApply2( 18 | state, dst, src, 19 | CopyOp::DataType, 20 | typename TensorUtils::DataType>(), 21 | ReadOnly, /* ignore overwrites */ 22 | ReadOnly); 23 | } 24 | 25 | #define IMPLEMENT_THC_CUDA_TENSOR_COPY(TYPEC, TYPECUDA) \ 26 | THC_API void \ 27 | THCTensor_(copyCuda##TYPEC)(THCState *state, \ 28 | THCTensor *self, \ 29 | THCuda##TYPECUDA##Tensor *src) { \ 30 | THC_copyTensor(state, self, src); \ 31 | } 32 | 33 | IMPLEMENT_THC_CUDA_TENSOR_COPY(Byte, Byte) 34 | IMPLEMENT_THC_CUDA_TENSOR_COPY(Char, Char) 35 | IMPLEMENT_THC_CUDA_TENSOR_COPY(Short, Short) 36 | IMPLEMENT_THC_CUDA_TENSOR_COPY(Int, Int) 37 | IMPLEMENT_THC_CUDA_TENSOR_COPY(Long, Long) 38 | // THCudaTensor aka the non-existent THCudaFloatTensor 39 | IMPLEMENT_THC_CUDA_TENSOR_COPY(Float, ) 40 | IMPLEMENT_THC_CUDA_TENSOR_COPY(Double, Double) 41 | #ifdef CUDA_HALF_TENSOR 42 | IMPLEMENT_THC_CUDA_TENSOR_COPY(Half, Half) 43 | #endif 44 | 45 | #undef IMPLEMENT_THC_CUDA_TENSOR_COPY 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /lib/backward/test/select_signals.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * test/segfault.cpp 3 | * Copyright 2013 Google Inc. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #include "backward.hpp" 25 | 26 | #include 27 | #include 28 | #include "test/test.hpp" 29 | 30 | using namespace backward; 31 | 32 | void badass_function() { 33 | char* ptr = (char*)42; 34 | *ptr = 42; 35 | } 36 | 37 | TEST_SEGFAULT (pprint_sigsev) { 38 | std::vector signals; 39 | signals.push_back(SIGSEGV); 40 | SignalHandling sh(signals); 41 | std::cout << std::boolalpha << "sh.loaded() == " << sh.loaded() << std::endl; 42 | badass_function(); 43 | } 44 | 45 | TEST_SEGFAULT (wont_pprint) { 46 | std::vector signals; 47 | signals.push_back(SIGABRT); 48 | SignalHandling sh(signals); 49 | std::cout << std::boolalpha << "sh.loaded() == " << sh.loaded() << std::endl; 50 | badass_function(); 51 | } 52 | -------------------------------------------------------------------------------- /lib/backward/test/stacktrace.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * test/stacktrace.cpp 3 | * Copyright 2013 Google Inc. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #include "backward.hpp" 25 | #include 26 | #include "test/test.hpp" 27 | 28 | using namespace backward; 29 | 30 | void collect_trace(StackTrace& st) { 31 | st.load_here(); 32 | } 33 | 34 | TEST (minitrace) { 35 | StackTrace st; 36 | collect_trace(st); 37 | 38 | Printer printer; 39 | printer.print(st, stdout); 40 | } 41 | 42 | void d(StackTrace& st) { 43 | st.load_here(); 44 | } 45 | 46 | void c(StackTrace& st) { 47 | return d(st); 48 | } 49 | 50 | void b(StackTrace& st) { 51 | return c(st); 52 | } 53 | 54 | __attribute__ ((noinline)) 55 | void a(StackTrace& st) { 56 | return b(st); 57 | } 58 | 59 | TEST (smalltrace) { 60 | StackTrace st; 61 | a(st); 62 | 63 | Printer printer; 64 | printer.print(st, stdout); 65 | } 66 | -------------------------------------------------------------------------------- /src/tensor/lua/src/linit.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: linit.c,v 1.39 2016/12/04 20:17:24 roberto Exp $ 3 | ** Initialization of libraries for lua.c and other clients 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #define linit_c 9 | #define LUA_LIB 10 | 11 | /* 12 | ** If you embed Lua in your program and need to open the standard 13 | ** libraries, call luaL_openlibs in your program. If you need a 14 | ** different set of libraries, copy this file to your project and edit 15 | ** it to suit your needs. 16 | ** 17 | ** You can also *preload* libraries, so that a later 'require' can 18 | ** open the library, which is already linked to the application. 19 | ** For that, do the following code: 20 | ** 21 | ** luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE); 22 | ** lua_pushcfunction(L, luaopen_modname); 23 | ** lua_setfield(L, -2, modname); 24 | ** lua_pop(L, 1); // remove PRELOAD table 25 | */ 26 | 27 | #include "lprefix.h" 28 | 29 | 30 | #include 31 | 32 | #include "lua.h" 33 | 34 | #include "lualib.h" 35 | #include "lauxlib.h" 36 | 37 | 38 | /* 39 | ** these libs are loaded by lua.c and are readily available to any Lua 40 | ** program 41 | */ 42 | static const luaL_Reg loadedlibs[] = { 43 | {"_G", luaopen_base}, 44 | {LUA_LOADLIBNAME, luaopen_package}, 45 | {LUA_COLIBNAME, luaopen_coroutine}, 46 | {LUA_TABLIBNAME, luaopen_table}, 47 | {LUA_IOLIBNAME, luaopen_io}, 48 | {LUA_OSLIBNAME, luaopen_os}, 49 | {LUA_STRLIBNAME, luaopen_string}, 50 | {LUA_MATHLIBNAME, luaopen_math}, 51 | {LUA_UTF8LIBNAME, luaopen_utf8}, 52 | {LUA_DBLIBNAME, luaopen_debug}, 53 | #if defined(LUA_COMPAT_BITLIB) 54 | {LUA_BITLIBNAME, luaopen_bit32}, 55 | #endif 56 | {NULL, NULL} 57 | }; 58 | 59 | 60 | LUALIB_API void luaL_openlibs (lua_State *L) { 61 | const luaL_Reg *lib; 62 | /* "require" functions from 'loadedlibs' and set results to global table */ 63 | for (lib = loadedlibs; lib->func; lib++) { 64 | luaL_requiref(L, lib->name, lib->func, 1); 65 | lua_pop(L, 1); /* remove lib */ 66 | } 67 | } 68 | 69 | -------------------------------------------------------------------------------- /src/tensor/TensorOperator.cc: -------------------------------------------------------------------------------- 1 | #include "Tensor.h" 2 | #include "TensorTH.h" 3 | #include "dispatch.h" 4 | 5 | namespace xt { 6 | 7 | Tensor& Tensor::operator+=(const Tensor& rhs) 8 | { 9 | add_(*this, *this, rhs); 10 | return *this; 11 | } 12 | 13 | Tensor& Tensor::operator/=(const Tensor& rhs) 14 | { 15 | if(rhs.dim() == 0) 16 | div_(*this, *this, rhs); 17 | else 18 | cdiv_(*this, *this, rhs); 19 | return *this; 20 | } 21 | 22 | Tensor Tensor::operator[](int64_t d) 23 | { 24 | return select(*this, 0, d); 25 | } 26 | 27 | bool operator!=(const Tensor& lhs, const int64_t rhs) 28 | { 29 | return !(lhs == rhs); 30 | } 31 | 32 | bool operator!=(const Tensor& lhs, const double rhs) 33 | { 34 | return !(lhs == rhs); 35 | } 36 | 37 | bool operator==(const Tensor& lhs, const Tensor& rhs) 38 | { 39 | return equal(lhs, rhs); 40 | } 41 | 42 | bool operator!=(const Tensor& lhs, const Tensor& rhs) 43 | { 44 | return !(lhs == rhs); 45 | } 46 | 47 | Tensor Tensor::operator[](const Tensor &rhs) 48 | { 49 | return (*this)[rhs.value()]; 50 | } 51 | 52 | Tensor operator+(const Tensor& lhs, const Tensor& rhs) 53 | { 54 | return add(lhs, rhs); 55 | } 56 | 57 | Tensor operator-(const Tensor& lhs, const Tensor& rhs) 58 | { 59 | return add(lhs, -1, rhs); 60 | } 61 | 62 | Tensor operator*(const Tensor& lhs, const Tensor& rhs) 63 | { 64 | if(lhs.dim() == 0 || rhs.dim() == 0) { 65 | return mul(lhs, rhs); 66 | } else if(lhs.dim() == 2 && rhs.dim() == 2) { 67 | return mm(lhs, rhs); 68 | } else if(lhs.dim() == 2 && rhs.dim() == 1) { 69 | return mv(lhs, rhs); 70 | } else { 71 | throw std::invalid_argument("mul: unsupported dimensions"); 72 | } 73 | } 74 | 75 | Tensor& Tensor::operator++(int) 76 | { 77 | add_(*this, *this, Tensor(1)); 78 | return *this; 79 | } 80 | 81 | Tensor operator/(const Tensor& lhs, const Tensor& rhs) 82 | { 83 | return div(lhs, rhs); 84 | } 85 | 86 | std::ostream& operator<<(std::ostream& stream, const Tensor& self) 87 | { 88 | return self.print(stream); 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /lib/THC/generic/THCDeviceTensorUtils.cu: -------------------------------------------------------------------------------- 1 | #ifndef THC_GENERIC_FILE 2 | #define THC_GENERIC_FILE "generic/THCDeviceTensorUtils.cu" 3 | #else 4 | 5 | /// Constructs a THCDeviceTensor initialized from a THCudaTensor. Will 6 | /// error if the dimensionality does not match exactly. 7 | template class PtrTraits> 9 | THCDeviceTensor 10 | toDeviceTensor(THCState* state, THCTensor* t); 11 | 12 | template 13 | THCDeviceTensor 14 | toDeviceTensor(THCState* state, THCTensor* t) { 15 | return toDeviceTensor(state, t); 16 | } 17 | 18 | template 19 | THCDeviceTensor 20 | toDeviceTensor(THCState* state, THCTensor* t) { 21 | return toDeviceTensor(state, t); 22 | } 23 | 24 | template class PtrTraits> 26 | THCDeviceTensor 27 | toDeviceTensor(THCState* state, THCTensor* t) { 28 | if (Dim != THCTensor_(nDimension)(state, t)) { 29 | THError("THCudaTensor dimension mismatch"); 30 | } 31 | // Determine the maximum offset into the tensor achievable; `IndexT` 32 | // must be smaller than this type in order to use it. 33 | ptrdiff_t maxOffset = 0; 34 | IndexT sizes[Dim]; 35 | IndexT strides[Dim]; 36 | 37 | for (int i = 0; i < Dim; ++i) { 38 | long size = THCTensor_(size)(state, t, i); 39 | long stride = THCTensor_(stride)(state, t, i); 40 | 41 | maxOffset += (size - 1) * stride; 42 | 43 | sizes[i] = (IndexT) size; 44 | strides[i] = (IndexT) stride; 45 | } 46 | 47 | if (maxOffset > std::numeric_limits::max()) { 48 | THError("THCudaTensor sizes too large for THCDeviceTensor conversion"); 49 | } 50 | 51 | return THCDeviceTensor( 52 | THCTensor_(data)(state, t), sizes, strides); 53 | } 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /lib/THC/THCAllocator.c: -------------------------------------------------------------------------------- 1 | #include "THCAllocator.h" 2 | 3 | static void *THCudaHostAllocator_malloc(void* ctx, ptrdiff_t size) { 4 | void* ptr; 5 | 6 | if (size < 0) THError("Invalid memory size: %ld", size); 7 | 8 | if (size == 0) return NULL; 9 | 10 | THCudaCheck(cudaMallocHost(&ptr, size)); 11 | 12 | return ptr; 13 | } 14 | 15 | static void THCudaHostAllocator_free(void* ctx, void* ptr) { 16 | if (!ptr) return; 17 | 18 | THCudaCheck(cudaFreeHost(ptr)); 19 | } 20 | 21 | THAllocator THCudaHostAllocator = { 22 | &THCudaHostAllocator_malloc, 23 | NULL, 24 | &THCudaHostAllocator_free 25 | }; 26 | 27 | static cudaError_t THCIpcAllocator_malloc(void* ctx, void** devPtr, size_t size, cudaStream_t stream) 28 | { 29 | THError("THCIpcAllocator.malloc() not supported"); 30 | return cudaSuccess; 31 | } 32 | 33 | static cudaError_t THCIpcAllocator_free(void* ctx, void* devPtr) 34 | { 35 | cudaError_t err; 36 | int prev_device; 37 | int device = (int)(long)ctx; 38 | 39 | err = cudaGetDevice(&prev_device); 40 | if (err != cudaSuccess) { return err; } 41 | 42 | err = cudaSetDevice(device); 43 | if (err != cudaSuccess) { return err; } 44 | 45 | err = cudaIpcCloseMemHandle(devPtr); 46 | 47 | cudaSetDevice(prev_device); 48 | return err; 49 | } 50 | 51 | THCDeviceAllocator THCIpcAllocator = { 52 | &THCIpcAllocator_malloc, 53 | NULL, 54 | &THCIpcAllocator_free, 55 | NULL, 56 | NULL 57 | }; 58 | 59 | static void *THCUVAAllocator_alloc(void* ctx, ptrdiff_t size) { 60 | if (size < 0) THError("Invalid memory size: %ld", size); 61 | 62 | if (size == 0) return NULL; 63 | 64 | // See J.1.1 of the CUDA_C_Programming_Guide.pdf for UVA and coherence rules 65 | // on various compute capabilities. 66 | void* ptr; 67 | THCudaCheck(cudaMallocManaged(&ptr, size, cudaMemAttachGlobal)); 68 | return ptr; 69 | } 70 | 71 | static void THCUVAAllocator_free(void* ctx, void* ptr) { 72 | if (!ptr) return; 73 | THCudaCheck(cudaFree(ptr)); 74 | } 75 | 76 | THAllocator THCUVAAllocator = { 77 | &THCUVAAllocator_alloc, 78 | NULL, 79 | &THCUVAAllocator_free 80 | }; 81 | -------------------------------------------------------------------------------- /src/tensor/lua/src/ltm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.h,v 2.22 2016/02/26 19:20:15 roberto Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltm_h 8 | #define ltm_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | /* 15 | * WARNING: if you change the order of this enumeration, 16 | * grep "ORDER TM" and "ORDER OP" 17 | */ 18 | typedef enum { 19 | TM_INDEX, 20 | TM_NEWINDEX, 21 | TM_GC, 22 | TM_MODE, 23 | TM_LEN, 24 | TM_EQ, /* last tag method with fast access */ 25 | TM_ADD, 26 | TM_SUB, 27 | TM_MUL, 28 | TM_MOD, 29 | TM_POW, 30 | TM_DIV, 31 | TM_IDIV, 32 | TM_BAND, 33 | TM_BOR, 34 | TM_BXOR, 35 | TM_SHL, 36 | TM_SHR, 37 | TM_UNM, 38 | TM_BNOT, 39 | TM_LT, 40 | TM_LE, 41 | TM_CONCAT, 42 | TM_CALL, 43 | TM_N /* number of elements in the enum */ 44 | } TMS; 45 | 46 | 47 | 48 | #define gfasttm(g,et,e) ((et) == NULL ? NULL : \ 49 | ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) 50 | 51 | #define fasttm(l,et,e) gfasttm(G(l), et, e) 52 | 53 | #define ttypename(x) luaT_typenames_[(x) + 1] 54 | 55 | LUAI_DDEC const char *const luaT_typenames_[LUA_TOTALTAGS]; 56 | 57 | 58 | LUAI_FUNC const char *luaT_objtypename (lua_State *L, const TValue *o); 59 | 60 | LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); 61 | LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, 62 | TMS event); 63 | LUAI_FUNC void luaT_init (lua_State *L); 64 | 65 | LUAI_FUNC void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, 66 | const TValue *p2, TValue *p3, int hasres); 67 | LUAI_FUNC int luaT_callbinTM (lua_State *L, const TValue *p1, const TValue *p2, 68 | StkId res, TMS event); 69 | LUAI_FUNC void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, 70 | StkId res, TMS event); 71 | LUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1, 72 | const TValue *p2, TMS event); 73 | 74 | 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /lib/TH/THLogAdd.c: -------------------------------------------------------------------------------- 1 | #include "THLogAdd.h" 2 | 3 | #include 4 | 5 | #ifdef USE_DOUBLE 6 | #define MINUS_LOG_THRESHOLD -39.14 7 | #else 8 | #define MINUS_LOG_THRESHOLD -18.42 9 | #endif 10 | 11 | const double THLog2Pi=1.83787706640934548355; 12 | const double THLogZero=-DBL_MAX; 13 | const double THLogOne=0; 14 | 15 | double THLogAdd(double log_a, double log_b) 16 | { 17 | double minusdif; 18 | 19 | if (log_a < log_b) 20 | { 21 | double tmp = log_a; 22 | log_a = log_b; 23 | log_b = tmp; 24 | } 25 | 26 | minusdif = log_b - log_a; 27 | #ifdef DEBUG 28 | if (isnan(minusdif)) 29 | THError("THLogAdd: minusdif (%f) log_b (%f) or log_a (%f) is nan", minusdif, log_b, log_a); 30 | #endif 31 | if (minusdif < MINUS_LOG_THRESHOLD) 32 | return log_a; 33 | else 34 | return log_a + log1p(exp(minusdif)); 35 | } 36 | 37 | double THLogSub(double log_a, double log_b) 38 | { 39 | double minusdif; 40 | 41 | if (log_a < log_b) 42 | THError("LogSub: log_a (%f) should be greater than log_b (%f)", log_a, log_b); 43 | 44 | minusdif = log_b - log_a; 45 | #ifdef DEBUG 46 | if (isnan(minusdif)) 47 | THError("LogSub: minusdif (%f) log_b (%f) or log_a (%f) is nan", minusdif, log_b, log_a); 48 | #endif 49 | if (log_a == log_b) 50 | return THLogZero; 51 | else if (minusdif < MINUS_LOG_THRESHOLD) 52 | return log_a; 53 | else 54 | return log_a + log1p(-exp(minusdif)); 55 | } 56 | 57 | /* Credits to Leon Bottou */ 58 | double THExpMinusApprox(const double x) 59 | { 60 | #define EXACT_EXPONENTIAL 0 61 | #if EXACT_EXPONENTIAL 62 | return exp(-x); 63 | #else 64 | /* fast approximation of exp(-x) for x positive */ 65 | # define A0 (1.0) 66 | # define A1 (0.125) 67 | # define A2 (0.0078125) 68 | # define A3 (0.00032552083) 69 | # define A4 (1.0172526e-5) 70 | if (x < 13.0) 71 | { 72 | /* assert(x>=0); */ 73 | double y; 74 | y = A0+x*(A1+x*(A2+x*(A3+x*A4))); 75 | y *= y; 76 | y *= y; 77 | y *= y; 78 | y = 1/y; 79 | return y; 80 | } 81 | return 0; 82 | # undef A0 83 | # undef A1 84 | # undef A2 85 | # undef A3 86 | # undef A4 87 | #endif 88 | } 89 | -------------------------------------------------------------------------------- /src/tensor/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Currently, we assume that long is 64 bits (TH legacy) 2 | include(CheckTypeSize) 3 | check_type_size(long SIZEOF_LONG LANGUAGE CXX) 4 | if(NOT SIZEOF_LONG EQUAL 8) 5 | message(FATAL_ERROR "Long size is ${SIZEOF_LONG}; 8 expected.") 6 | endif() 7 | 8 | include(CheckCXXSourceCompiles) 9 | check_cxx_source_compiles( 10 | " 11 | #include 12 | #include 13 | 14 | int main() 15 | { 16 | std::cout << std::defaultfloat; 17 | return 0; 18 | } 19 | " 20 | HAS_DEFAULTFLOAT 21 | ) 22 | 23 | add_subdirectory(lua) 24 | 25 | file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/xt) 26 | configure_file(Tensor.h ${CMAKE_CURRENT_BINARY_DIR}/xt COPYONLY) 27 | configure_file(Context.h ${CMAKE_CURRENT_BINARY_DIR}/xt COPYONLY) 28 | configure_file(dispatch.h ${CMAKE_CURRENT_BINARY_DIR}/xt COPYONLY) 29 | configure_file(xttensor.h ${CMAKE_CURRENT_BINARY_DIR} COPYONLY) 30 | 31 | include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/xt) 32 | 33 | add_custom_command( 34 | OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xt/TensorTH.h ${CMAKE_CURRENT_BINARY_DIR}/TensorTH.cc 35 | COMMAND lua ARGS tensor.lua ${CMAKE_CURRENT_BINARY_DIR}/xt/TensorTH.h ${CMAKE_CURRENT_BINARY_DIR}/TensorTH.cc ${CUDA_FOUND} 36 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 37 | DEPENDS lua tensor.lua interface.lua record.lua types.lua 38 | ) 39 | 40 | set(src 41 | ${CMAKE_CURRENT_BINARY_DIR}/TensorTH.cc 42 | Context.cc 43 | Tensor.cc 44 | TensorOperator.cc 45 | TensorPrint.cc 46 | ${CMAKE_CURRENT_BINARY_DIR}/xt/TensorTH.h 47 | ) 48 | 49 | if(HAS_DEFAULTFLOAT) 50 | add_definitions(-DHAS_DEFAULTFLOAT) 51 | endif() 52 | 53 | add_library(xttensor SHARED ${src}) 54 | target_link_libraries(xttensor TH) 55 | if(CUDA_FOUND) 56 | target_link_libraries(xttensor THC) 57 | endif() 58 | add_executable(test-basic test/basic.cc) 59 | target_link_libraries(test-basic xttensor) 60 | 61 | install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/xt DESTINATION include) 62 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/xttensor.h DESTINATION include) 63 | install(TARGETS xttensor LIBRARY DESTINATION lib) 64 | install(TARGETS test-basic RUNTIME DESTINATION share/xt/tensor) 65 | -------------------------------------------------------------------------------- /lib/THC/generic/THCStorageCopy.cu: -------------------------------------------------------------------------------- 1 | #ifndef THC_GENERIC_FILE 2 | #define THC_GENERIC_FILE "generic/THCStorageCopy.cu" 3 | #else 4 | 5 | void THCStorage_(rawCopy)(THCState *state, THCStorage *self, real *src) 6 | { 7 | THCudaCheck(cudaMemcpyAsync(self->data, src, self->size * sizeof(real), cudaMemcpyDeviceToDevice, THCState_getCurrentStream(state))); 8 | } 9 | 10 | // conversions are delegated to THCTensor implementation 11 | #define THC_CUDA_STORAGE_IMPLEMENT_COPY(TYPEC,TYPECUDA) \ 12 | void THCStorage_(copyCuda##TYPEC)(THCState *state, THCStorage *self, struct THCuda##TYPECUDA##Storage *src) \ 13 | { \ 14 | THArgCheck(self->size == src->size, 2, "size does not match"); \ 15 | THCTensor* selfTensor = THCTensor_(newWithStorage1d)(state, self, 0, self->size, 1); \ 16 | struct THCuda##TYPECUDA##Tensor* srcTensor = \ 17 | THCuda##TYPECUDA##Tensor_newWithStorage1d(state, src, 0, src->size, 1); \ 18 | THCTensor_(copyCuda##TYPEC)(state, selfTensor, srcTensor); \ 19 | THCuda##TYPECUDA##Tensor_free(state, srcTensor); \ 20 | THCTensor_(free)(state, selfTensor); \ 21 | } 22 | 23 | THC_CUDA_STORAGE_IMPLEMENT_COPY(Byte,Byte) 24 | THC_CUDA_STORAGE_IMPLEMENT_COPY(Char,Char) 25 | THC_CUDA_STORAGE_IMPLEMENT_COPY(Short,Short) 26 | THC_CUDA_STORAGE_IMPLEMENT_COPY(Int,Int) 27 | THC_CUDA_STORAGE_IMPLEMENT_COPY(Long,Long) 28 | THC_CUDA_STORAGE_IMPLEMENT_COPY(Float,) // i.e. float 29 | THC_CUDA_STORAGE_IMPLEMENT_COPY(Double,Double) 30 | #ifdef CUDA_HALF_TENSOR 31 | THC_CUDA_STORAGE_IMPLEMENT_COPY(Half,Half) 32 | #endif 33 | 34 | #undef THC_CUDA_STORAGE_IMPLEMENT_COPY 35 | 36 | void THCStorage_(copyCuda)(THCState *state, THCStorage *self, THCStorage *src) 37 | { 38 | THCStorage_(TH_CONCAT_2(copyCuda, Real))(state, self, src); 39 | } 40 | 41 | void THCStorage_(copy)(THCState *state, THCStorage *self, THCStorage *src) 42 | { 43 | THCStorage_(copyCuda)(state, self, src); 44 | } 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /lib/THC/THCTensorSort.cu: -------------------------------------------------------------------------------- 1 | #include "THCTensorSort.cuh" 2 | 3 | void THCudaLongTensor_fillSliceWithIndex(THCState* state, 4 | THCudaLongTensor* t, 5 | int dim) { 6 | long dims = THCudaLongTensor_nDimension(state, t); 7 | THArgCheck(dims <= MAX_CUTORCH_DIMS, 2, CUTORCH_DIM_WARNING); 8 | 9 | ptrdiff_t inElements = THCudaLongTensor_nElement(state, t); 10 | long sliceSize = THCudaLongTensor_size(state, t, dim); 11 | ptrdiff_t numSlices = inElements / sliceSize; 12 | 13 | dim3 grid; 14 | if (!THC_getGridFromTiles(numSlices, grid)) { 15 | THError("Slice to fill with indices is too large"); 16 | } 17 | 18 | long maxThreads = 19 | THCState_getCurrentDeviceProperties(state)->maxThreadsPerBlock; 20 | long numThreads = sliceSize; 21 | if (numThreads > maxThreads) { 22 | numThreads = maxThreads; 23 | } 24 | 25 | dim3 block(numThreads); 26 | 27 | #define FILL_INDEX(T, DIM) \ 28 | fillSliceWithIndex \ 29 | <<>>( \ 30 | info, numSlices, sliceSize, info.strides[collapseDim]) 31 | 32 | if (TensorUtils::canUse32BitIndexMath(state, t)) { 33 | TensorInfo info = 34 | getTensorInfo(state, t); 35 | info.reduceDim(dim); 36 | int collapseDim = info.collapseDims(dim); 37 | 38 | if (info.isContiguous()) { 39 | FILL_INDEX(unsigned int, -2); 40 | } else { 41 | if (info.dims == 1) { 42 | FILL_INDEX(unsigned int, 1); 43 | } else if (info.dims == 2) { 44 | FILL_INDEX(unsigned int, 2); 45 | } else { 46 | FILL_INDEX(unsigned int, -1); 47 | } 48 | } 49 | } else { 50 | TensorInfo info = 51 | getTensorInfo(state, t); 52 | info.reduceDim(dim); 53 | int collapseDim = info.collapseDims(dim); 54 | 55 | // catch-all implementation 56 | FILL_INDEX(unsigned long, -1); 57 | } 58 | 59 | #undef FILL_INDEX 60 | 61 | THCudaCheck(cudaGetLastError()); 62 | } 63 | -------------------------------------------------------------------------------- /src/tensor/lua/src/lctype.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lctype.h,v 1.12 2011/07/15 12:50:29 roberto Exp $ 3 | ** 'ctype' functions for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lctype_h 8 | #define lctype_h 9 | 10 | #include "lua.h" 11 | 12 | 13 | /* 14 | ** WARNING: the functions defined here do not necessarily correspond 15 | ** to the similar functions in the standard C ctype.h. They are 16 | ** optimized for the specific needs of Lua 17 | */ 18 | 19 | #if !defined(LUA_USE_CTYPE) 20 | 21 | #if 'A' == 65 && '0' == 48 22 | /* ASCII case: can use its own tables; faster and fixed */ 23 | #define LUA_USE_CTYPE 0 24 | #else 25 | /* must use standard C ctype */ 26 | #define LUA_USE_CTYPE 1 27 | #endif 28 | 29 | #endif 30 | 31 | 32 | #if !LUA_USE_CTYPE /* { */ 33 | 34 | #include 35 | 36 | #include "llimits.h" 37 | 38 | 39 | #define ALPHABIT 0 40 | #define DIGITBIT 1 41 | #define PRINTBIT 2 42 | #define SPACEBIT 3 43 | #define XDIGITBIT 4 44 | 45 | 46 | #define MASK(B) (1 << (B)) 47 | 48 | 49 | /* 50 | ** add 1 to char to allow index -1 (EOZ) 51 | */ 52 | #define testprop(c,p) (luai_ctype_[(c)+1] & (p)) 53 | 54 | /* 55 | ** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_' 56 | */ 57 | #define lislalpha(c) testprop(c, MASK(ALPHABIT)) 58 | #define lislalnum(c) testprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT))) 59 | #define lisdigit(c) testprop(c, MASK(DIGITBIT)) 60 | #define lisspace(c) testprop(c, MASK(SPACEBIT)) 61 | #define lisprint(c) testprop(c, MASK(PRINTBIT)) 62 | #define lisxdigit(c) testprop(c, MASK(XDIGITBIT)) 63 | 64 | /* 65 | ** this 'ltolower' only works for alphabetic characters 66 | */ 67 | #define ltolower(c) ((c) | ('A' ^ 'a')) 68 | 69 | 70 | /* two more entries for 0 and -1 (EOZ) */ 71 | LUAI_DDEC const lu_byte luai_ctype_[UCHAR_MAX + 2]; 72 | 73 | 74 | #else /* }{ */ 75 | 76 | /* 77 | ** use standard C ctypes 78 | */ 79 | 80 | #include 81 | 82 | 83 | #define lislalpha(c) (isalpha(c) || (c) == '_') 84 | #define lislalnum(c) (isalnum(c) || (c) == '_') 85 | #define lisdigit(c) (isdigit(c)) 86 | #define lisspace(c) (isspace(c)) 87 | #define lisprint(c) (isprint(c)) 88 | #define lisxdigit(c) (isxdigit(c)) 89 | 90 | #define ltolower(c) (tolower(c)) 91 | 92 | #endif /* } */ 93 | 94 | #endif 95 | 96 | -------------------------------------------------------------------------------- /lib/THC/generic/THCTensorMathReduce.h: -------------------------------------------------------------------------------- 1 | #ifndef THC_GENERIC_FILE 2 | #define THC_GENERIC_FILE "generic/THCTensorMathReduce.h" 3 | #else 4 | 5 | #if defined(THC_REAL_IS_FLOAT) || defined(THC_REAL_IS_DOUBLE) || defined(THC_REAL_IS_HALF) 6 | 7 | THC_API void THCTensor_(renorm)(THCState *state, THCTensor* self, THCTensor* src, real value, long dimension, real max_norm); 8 | THC_API void THCTensor_(std)(THCState *state, THCTensor *self, THCTensor *src, long dim, int flag, int keepdim); 9 | THC_API void THCTensor_(norm)(THCState *state, THCTensor* self, THCTensor* src, real value, long dimension, int keepdim); 10 | THC_API void THCTensor_(var)(THCState *state, THCTensor *self, THCTensor *src, long dim, int flag, int keepdim); 11 | 12 | THC_API accreal THCTensor_(stdall)(THCState *state, THCTensor *self); 13 | THC_API accreal THCTensor_(normall)(THCState *state, THCTensor *self, real value); 14 | THC_API accreal THCTensor_(varall)(THCState *state, THCTensor *self); 15 | 16 | #endif 17 | 18 | THC_API void THCTensor_(sum)(THCState *state, THCTensor *self, THCTensor *src, long dim, int keepdim); 19 | THC_API void THCTensor_(prod)(THCState *state, THCTensor *self, THCTensor *src, long dim, int keepdim); 20 | THC_API void THCTensor_(mean)(THCState *state, THCTensor *self, THCTensor *src, long dim, int keepdim); 21 | 22 | THC_API accreal THCTensor_(sumall)(THCState *state, THCTensor *self); 23 | THC_API accreal THCTensor_(prodall)(THCState *state, THCTensor *self); 24 | THC_API accreal THCTensor_(meanall)(THCState *state, THCTensor *self); 25 | 26 | THC_API void THCTensor_(min)(THCState *state, 27 | THCTensor *values, 28 | THCudaLongTensor *indices, 29 | THCTensor *src, long dim, int keepdim); 30 | THC_API void THCTensor_(max)(THCState *state, 31 | THCTensor *values, 32 | THCudaLongTensor *indices, 33 | THCTensor *src, long dim, int keepdim); 34 | 35 | THC_API real THCTensor_(minall)(THCState *state, THCTensor *self); 36 | THC_API real THCTensor_(maxall)(THCState *state, THCTensor *self); 37 | 38 | THC_API accreal THCTensor_(dist)(THCState *state, THCTensor *self, THCTensor *src, 39 | real value); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /src/tensor/lua/src/ldo.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldo.h,v 2.29 2015/12/21 13:02:14 roberto Exp $ 3 | ** Stack and Call structure of Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldo_h 8 | #define ldo_h 9 | 10 | 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | #include "lzio.h" 14 | 15 | 16 | /* 17 | ** Macro to check stack size and grow stack if needed. Parameters 18 | ** 'pre'/'pos' allow the macro to preserve a pointer into the 19 | ** stack across reallocations, doing the work only when needed. 20 | ** 'condmovestack' is used in heavy tests to force a stack reallocation 21 | ** at every check. 22 | */ 23 | #define luaD_checkstackaux(L,n,pre,pos) \ 24 | if (L->stack_last - L->top <= (n)) \ 25 | { pre; luaD_growstack(L, n); pos; } else { condmovestack(L,pre,pos); } 26 | 27 | /* In general, 'pre'/'pos' are empty (nothing to save) */ 28 | #define luaD_checkstack(L,n) luaD_checkstackaux(L,n,(void)0,(void)0) 29 | 30 | 31 | 32 | #define savestack(L,p) ((char *)(p) - (char *)L->stack) 33 | #define restorestack(L,n) ((TValue *)((char *)L->stack + (n))) 34 | 35 | 36 | /* type of protected functions, to be ran by 'runprotected' */ 37 | typedef void (*Pfunc) (lua_State *L, void *ud); 38 | 39 | LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name, 40 | const char *mode); 41 | LUAI_FUNC void luaD_hook (lua_State *L, int event, int line); 42 | LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults); 43 | LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults); 44 | LUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults); 45 | LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, 46 | ptrdiff_t oldtop, ptrdiff_t ef); 47 | LUAI_FUNC int luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult, 48 | int nres); 49 | LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize); 50 | LUAI_FUNC void luaD_growstack (lua_State *L, int n); 51 | LUAI_FUNC void luaD_shrinkstack (lua_State *L); 52 | LUAI_FUNC void luaD_inctop (lua_State *L); 53 | 54 | LUAI_FUNC l_noret luaD_throw (lua_State *L, int errcode); 55 | LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); 56 | 57 | #endif 58 | 59 | -------------------------------------------------------------------------------- /lib/backward/test/test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * test/test.cpp 3 | * Copyright 2013 Google Inc. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | #include "test/test.hpp" 28 | 29 | TEST (empty_test) { } 30 | 31 | TEST_FAIL_ASSERT (fail_assert) { 32 | ASSERT(1 == 2); 33 | } 34 | 35 | TEST_FAIL_ASSERT (fail_assert_ge) { 36 | ASSERT_GE(4, 5); 37 | } 38 | 39 | TEST_UNCAUGHT_EXCEPTION (uncaught_exception) { 40 | throw std::runtime_error("some random runtime error"); 41 | } 42 | 43 | TEST_UNCAUGHT_EXCEPTION (uncaught_exception_int) { 44 | throw 42; 45 | } 46 | 47 | TEST_SEGFAULT (segfault) { 48 | char* a = 0; 49 | char b = a[42]; 50 | std::cout << "result: " << b << std::endl; 51 | } 52 | 53 | TEST_ABORT (abort) { 54 | abort(); 55 | } 56 | 57 | TEST (catch_int) { 58 | ASSERT_THROW({throw 42;}, int); 59 | } 60 | 61 | TEST_FAIL_ASSERT (fail_catch_int) { 62 | ASSERT_THROW({}, int); 63 | } 64 | 65 | TEST_FAIL_ASSERT (fail_no_throw) { 66 | ASSERT_NO_THROW({throw 42;}); 67 | } 68 | 69 | TEST (any_throw) { 70 | ASSERT_ANY_THROW({throw 42;}); 71 | } 72 | 73 | TEST_FAIL_ASSERT (fail_any_throw) { 74 | ASSERT_ANY_THROW({}); 75 | } 76 | -------------------------------------------------------------------------------- /lib/THC/THCAsmUtils.cuh: -------------------------------------------------------------------------------- 1 | #ifndef THC_ASM_UTILS_INC 2 | #define THC_ASM_UTILS_INC 3 | 4 | // Collection of direct PTX functions 5 | 6 | template 7 | struct Bitfield {}; 8 | 9 | template <> 10 | struct Bitfield { 11 | static __device__ __forceinline__ 12 | unsigned int getBitfield(unsigned int val, int pos, int len) { 13 | unsigned int ret; 14 | asm("bfe.u32 %0, %1, %2, %3;" : "=r"(ret) : "r"(val), "r"(pos), "r"(len)); 15 | return ret; 16 | } 17 | 18 | static __device__ __forceinline__ 19 | unsigned int setBitfield(unsigned int val, unsigned int toInsert, int pos, int len) { 20 | unsigned int ret; 21 | asm("bfi.b32 %0, %1, %2, %3, %4;" : 22 | "=r"(ret) : "r"(toInsert), "r"(val), "r"(pos), "r"(len)); 23 | return ret; 24 | } 25 | }; 26 | 27 | template <> 28 | struct Bitfield { 29 | static __device__ __forceinline__ 30 | unsigned long long int getBitfield(unsigned long long int val, int pos, int len) { 31 | unsigned long long int ret; 32 | asm("bfe.u64 %0, %1, %2, %3;" : "=l"(ret) : "l"(val), "r"(pos), "r"(len)); 33 | return ret; 34 | } 35 | 36 | static __device__ __forceinline__ 37 | unsigned long long int setBitfield(unsigned long long int val, unsigned long long int toInsert, int pos, int len) { 38 | unsigned long long int ret; 39 | asm("bfi.b64 %0, %1, %2, %3, %4;" : 40 | "=l"(ret) : "l"(toInsert), "l"(val), "r"(pos), "r"(len)); 41 | return ret; 42 | } 43 | }; 44 | 45 | __device__ __forceinline__ int getLaneId() { 46 | int laneId; 47 | asm("mov.s32 %0, %laneid;" : "=r"(laneId) ); 48 | return laneId; 49 | } 50 | 51 | __device__ __forceinline__ unsigned getLaneMaskLt() { 52 | unsigned mask; 53 | asm("mov.u32 %0, %%lanemask_lt;" : "=r"(mask)); 54 | return mask; 55 | } 56 | 57 | __device__ __forceinline__ unsigned getLaneMaskLe() { 58 | unsigned mask; 59 | asm("mov.u32 %0, %%lanemask_le;" : "=r"(mask)); 60 | return mask; 61 | } 62 | 63 | __device__ __forceinline__ unsigned getLaneMaskGt() { 64 | unsigned mask; 65 | asm("mov.u32 %0, %%lanemask_gt;" : "=r"(mask)); 66 | return mask; 67 | } 68 | 69 | __device__ __forceinline__ unsigned getLaneMaskGe() { 70 | unsigned mask; 71 | asm("mov.u32 %0, %%lanemask_ge;" : "=r"(mask)); 72 | return mask; 73 | } 74 | 75 | 76 | #endif // THC_ASM_UTILS_INC 77 | -------------------------------------------------------------------------------- /src/tensor/lua/src/ltable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltable.h,v 2.23 2016/12/22 13:08:50 roberto Exp $ 3 | ** Lua tables (hash) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltable_h 8 | #define ltable_h 9 | 10 | #include "lobject.h" 11 | 12 | 13 | #define gnode(t,i) (&(t)->node[i]) 14 | #define gval(n) (&(n)->i_val) 15 | #define gnext(n) ((n)->i_key.nk.next) 16 | 17 | 18 | /* 'const' to avoid wrong writings that can mess up field 'next' */ 19 | #define gkey(n) cast(const TValue*, (&(n)->i_key.tvk)) 20 | 21 | /* 22 | ** writable version of 'gkey'; allows updates to individual fields, 23 | ** but not to the whole (which has incompatible type) 24 | */ 25 | #define wgkey(n) (&(n)->i_key.nk) 26 | 27 | #define invalidateTMcache(t) ((t)->flags = 0) 28 | 29 | 30 | /* true when 't' is using 'dummynode' as its hash part */ 31 | #define isdummy(t) ((t)->lastfree == NULL) 32 | 33 | 34 | /* allocated size for hash nodes */ 35 | #define allocsizenode(t) (isdummy(t) ? 0 : sizenode(t)) 36 | 37 | 38 | /* returns the key, given the value of a table entry */ 39 | #define keyfromval(v) \ 40 | (gkey(cast(Node *, cast(char *, (v)) - offsetof(Node, i_val)))) 41 | 42 | 43 | LUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key); 44 | LUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key, 45 | TValue *value); 46 | LUAI_FUNC const TValue *luaH_getshortstr (Table *t, TString *key); 47 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); 48 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); 49 | LUAI_FUNC TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key); 50 | LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key); 51 | LUAI_FUNC Table *luaH_new (lua_State *L); 52 | LUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned int nasize, 53 | unsigned int nhsize); 54 | LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize); 55 | LUAI_FUNC void luaH_free (lua_State *L, Table *t); 56 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); 57 | LUAI_FUNC int luaH_getn (Table *t); 58 | 59 | 60 | #if defined(LUA_DEBUG) 61 | LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); 62 | LUAI_FUNC int luaH_isdummy (const Table *t); 63 | #endif 64 | 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /lib/backward/conanfile.py: -------------------------------------------------------------------------------- 1 | from conans import ConanFile, CMake 2 | import os 3 | 4 | class BackwardCpp(ConanFile): 5 | settings = 'os', 'compiler', 'build_type', 'arch' 6 | name = 'backward' 7 | url = 'https://github.com/bombela/backward-cpp' 8 | license = 'MIT' 9 | version = '1.3.0' 10 | options = { 11 | 'stack_walking_unwind': [True, False], 12 | 'stack_walking_backtrace': [True, False], 13 | 'stack_details_auto_detect': [True, False], 14 | 'stack_details_backtrace_symbol': [True, False], 15 | 'stack_details_dw': [True, False], 16 | 'stack_details_bfd': [True, False], 17 | 'shared': [True, False] 18 | } 19 | default_options = ( 20 | 'stack_walking_unwind=True', 21 | 'stack_walking_backtrace=False', 22 | 'stack_details_auto_detect=True', 23 | 'stack_details_backtrace_symbol=False', 24 | 'stack_details_dw=False', 25 | 'stack_details_bfd=False', 26 | 'shared=False' 27 | ) 28 | exports = 'backward.cpp', 'backward.hpp', 'test/*', 'CMakeLists.txt', 'BackwardConfig.cmake' 29 | generators = 'cmake' 30 | 31 | def cmake_option(self, option, prefix = ''): 32 | return '-D{}{}={}'.format(prefix, option.upper(), getattr(self.options, option)) 33 | 34 | def build(self): 35 | cmake = CMake(self.settings) 36 | 37 | options = '' 38 | options += self.cmake_option('stack_walking_unwind') 39 | options += self.cmake_option('stack_walking_backtrace') 40 | options += self.cmake_option('stack_details_auto_detect') 41 | options += self.cmake_option('stack_details_backtrace_symbol') 42 | options += self.cmake_option('stack_details_dw') 43 | options += self.cmake_option('stack_details_bfd') 44 | options += self.cmake_option('shared', prefix = 'BACKWARD_') 45 | 46 | self.run('cmake {} {} {} -DBACKWARD_TESTS=OFF'.format(self.conanfile_directory, cmake.command_line, options)) 47 | self.run('cmake --build . {}'.format(cmake.build_config)) 48 | 49 | def package(self): 50 | self.copy('backward.hpp', os.path.join('include', 'backward')) 51 | self.copy('*.a', dst='lib') 52 | self.copy('*.so', dst='lib') 53 | self.copy('*.lib', dst='lib') 54 | self.copy('*.dll', dst='lib') 55 | 56 | def package_info(self): 57 | self.cpp_info.libs = ['backward'] 58 | -------------------------------------------------------------------------------- /lib/THC/THCTensorMathCompareT.cuh: -------------------------------------------------------------------------------- 1 | #ifndef THC_TENSORMATH_COMPARET_CUH 2 | #define THC_TENSORMATH_COMPARET_CUH 3 | 4 | #include "THCTensorMath.h" 5 | #include "THCGeneral.h" 6 | #include "THCTensorCopy.h" 7 | #include "THCApply.cuh" 8 | #include "THCNumerics.cuh" 9 | #include "THCReduce.cuh" 10 | 11 | template 12 | struct TensorLTOp { 13 | __device__ inline void operator()(TOut* out, T* a, T* b) { 14 | *out = ScalarConvert::to(THCNumerics::lt(*a, *b)); 15 | } 16 | }; 17 | 18 | template 19 | struct TensorGTOp { 20 | __device__ inline void operator()(TOut* out, T* a, T* b) { 21 | *out = ScalarConvert::to(THCNumerics::gt(*a, *b)); 22 | } 23 | }; 24 | 25 | template 26 | struct TensorLEOp { 27 | __device__ inline void operator()(TOut* out, T* a, T* b) { 28 | *out = ScalarConvert::to(THCNumerics::le(*a, *b)); 29 | } 30 | }; 31 | 32 | template 33 | struct TensorGEOp { 34 | __device__ inline void operator()(TOut* out, T* a, T* b) { 35 | *out = ScalarConvert::to(THCNumerics::ge(*a, *b)); 36 | } 37 | }; 38 | 39 | template 40 | struct TensorEQOp { 41 | __device__ inline void operator()(TOut* out, T* a, T* b) { 42 | *out = ScalarConvert::to(THCNumerics::eq(*a, *b)); 43 | } 44 | }; 45 | 46 | template 47 | struct TensorNEOp { 48 | __device__ inline void operator()(TOut* out, T* a, T* b) { 49 | *out = ScalarConvert::to(THCNumerics::ne(*a, *b)); 50 | } 51 | }; 52 | 53 | template 54 | void THC_logicalTensor(THCState *state, 55 | TensorTypeOut *self_, 56 | TensorType *src1, 57 | TensorType *src2, 58 | Op op) { 59 | THLongStorage* st = TensorUtils::newSizeOf(state, src1); 60 | TensorUtils::resize(state, self_, st, NULL); 61 | THLongStorage_free(st); 62 | 63 | THArgCheck(TensorUtils::getNumElements(state, src1) == 64 | TensorUtils::getNumElements(state, src2), 3, 65 | "sizes do not match"); 66 | 67 | if (!THC_pointwiseApply3(state, self_, src1, src2, op)) { 68 | THArgCheck(false, 2, CUTORCH_DIM_WARNING); 69 | } 70 | 71 | THCudaCheck(cudaGetLastError()); 72 | } 73 | 74 | #endif // THC_TENSORMATH_COMPARET_CUH 75 | -------------------------------------------------------------------------------- /src/tensor/lua/src/lctype.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lctype.c,v 1.12 2014/11/02 19:19:04 roberto Exp $ 3 | ** 'ctype' functions for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lctype_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include "lctype.h" 14 | 15 | #if !LUA_USE_CTYPE /* { */ 16 | 17 | #include 18 | 19 | LUAI_DDEF const lu_byte luai_ctype_[UCHAR_MAX + 2] = { 20 | 0x00, /* EOZ */ 21 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0. */ 22 | 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 23 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1. */ 24 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 25 | 0x0c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, /* 2. */ 26 | 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 27 | 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, /* 3. */ 28 | 0x16, 0x16, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 29 | 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 4. */ 30 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 31 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 5. */ 32 | 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x05, 33 | 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 6. */ 34 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 35 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 7. */ 36 | 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x00, 37 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 8. */ 38 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 39 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 9. */ 40 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 41 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* a. */ 42 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 43 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* b. */ 44 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 45 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* c. */ 46 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 47 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* d. */ 48 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 49 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* e. */ 50 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 51 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* f. */ 52 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 53 | }; 54 | 55 | #endif /* } */ 56 | -------------------------------------------------------------------------------- /lib/TH/vector/NEON.c: -------------------------------------------------------------------------------- 1 | static void THFloatVector_fill_NEON(float *x, const float c, const ptrdiff_t n) { 2 | long i = 0; 3 | 4 | for(; i < n-4; i += 4) 5 | { 6 | x[i] = c; 7 | x[i+1] = c; 8 | x[i+2] = c; 9 | x[i+3] = c; 10 | } 11 | 12 | for(; i < n; i++) 13 | x[i] = c; 14 | 15 | } 16 | 17 | static void THFloatVector_cmul_NEON(float *z, const float *x, const float* y, const ptrdiff_t n) { 18 | long i = 0; 19 | 20 | for(; i < n-4; i += 4) 21 | { 22 | z[i] = x[i] * y[i]; 23 | z[i+1] = x[i+1] * y[i+1]; 24 | z[i+2] = x[i+2] * y[i+2]; 25 | z[i+3] = x[i+3] * y[i+3]; 26 | } 27 | 28 | for(; i < n; i++) 29 | z[i] = x[i] * y[i]; 30 | } 31 | 32 | static void THFloatVector_muls_NEON(float *y, const float *x, const float c, const ptrdiff_t n) { 33 | long i = 0; 34 | 35 | for(; i < n-4; i += 4) 36 | { 37 | y[i] = x[i] * c; 38 | y[i+1] = x[i+1] * c; 39 | y[i+2] = x[i+2] * c; 40 | y[i+3] = x[i+3] * c; 41 | } 42 | 43 | for(; i < n; i++) 44 | y[i] = x[i] * c; 45 | } 46 | 47 | static void THFloatVector_cadd_NEON(float *z, const float *x, const float *y, const float c, const ptrdiff_t n) { 48 | long i = 0; 49 | 50 | for(;i < n-4; i += 4) 51 | { 52 | z[i] = x[i] + c * y[i]; 53 | z[i+1] = x[i+1] + c * y[i+1]; 54 | z[i+2] = x[i+2] + c * y[i+2]; 55 | z[i+3] = x[i+3] + c * y[i+3]; 56 | } 57 | 58 | for(; i < n; i++) 59 | z[i] = x[i] + c * y[i]; 60 | } 61 | 62 | static void THFloatVector_adds_NEON(float *y, const float *x, const float c, const ptrdiff_t n) { 63 | long i = 0; 64 | 65 | for(;i < n-4; i += 4) 66 | { 67 | y[i] = x[i] + c; 68 | y[i+1] = x[i+1] + c; 69 | y[i+2] = x[i+2] + c; 70 | y[i+3] = x[i+3] + c; 71 | } 72 | 73 | for(; i < n; i++) 74 | y[i] = x[i] + c; 75 | } 76 | 77 | static void THFloatVector_cdiv_NEON(float *z, const float *x, const float *y, const ptrdiff_t n) { 78 | long i = 0; 79 | 80 | for(;i < n-4; i += 4) 81 | { 82 | z[i] = x[i] / y[i]; 83 | z[i+1] = x[i+1] / y[i+1]; 84 | z[i+2] = x[i+2] / y[i+2]; 85 | z[i+3] = x[i+3] / y[i+3]; 86 | } 87 | 88 | for(; i < n; i++) 89 | z[i] = x[i] / y[i]; 90 | } 91 | 92 | static void THFloatVector_divs_NEON(float *y, const float *x, const float c, const ptrdiff_t n) { 93 | long i = 0; 94 | 95 | for(;i < n-4; i += 4) 96 | { 97 | y[i] = x[i] / c; 98 | y[i+1] = x[i+1] / c; 99 | y[i+2] = x[i+2] / c; 100 | y[i+3] = x[i+3] / c; 101 | } 102 | 103 | for(; i < n; i++) 104 | y[i] = x[i] / c; 105 | } 106 | -------------------------------------------------------------------------------- /lib/TH/generic/THLapack.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_GENERIC_FILE 2 | #define TH_GENERIC_FILE "generic/THLapack.h" 3 | #else 4 | 5 | /* AX=B */ 6 | TH_API void THLapack_(gesv)(int n, int nrhs, real *a, int lda, int *ipiv, real *b, int ldb, int* info); 7 | /* Solve a triangular system of the form A * X = B or A^T * X = B */ 8 | TH_API void THLapack_(trtrs)(char uplo, char trans, char diag, int n, int nrhs, real *a, int lda, real *b, int ldb, int* info); 9 | /* ||AX-B|| */ 10 | TH_API void THLapack_(gels)(char trans, int m, int n, int nrhs, real *a, int lda, real *b, int ldb, real *work, int lwork, int *info); 11 | /* Eigenvals */ 12 | TH_API void THLapack_(syev)(char jobz, char uplo, int n, real *a, int lda, real *w, real *work, int lwork, int *info); 13 | /* Non-sym eigenvals */ 14 | TH_API void THLapack_(geev)(char jobvl, char jobvr, int n, real *a, int lda, real *wr, real *wi, real* vl, int ldvl, real *vr, int ldvr, real *work, int lwork, int *info); 15 | /* svd */ 16 | TH_API void THLapack_(gesvd)(char jobu, char jobvt, int m, int n, real *a, int lda, real *s, real *u, int ldu, real *vt, int ldvt, real *work, int lwork, int *info); 17 | /* LU decomposition */ 18 | TH_API void THLapack_(getrf)(int m, int n, real *a, int lda, int *ipiv, int *info); 19 | TH_API void THLapack_(getrs)(char trans, int n, int nrhs, real *a, int lda, int *ipiv, real *b, int ldb, int *info); 20 | /* Matrix Inverse */ 21 | TH_API void THLapack_(getri)(int n, real *a, int lda, int *ipiv, real *work, int lwork, int* info); 22 | 23 | /* Positive Definite matrices */ 24 | /* Cholesky factorization */ 25 | void THLapack_(potrf)(char uplo, int n, real *a, int lda, int *info); 26 | /* Matrix inverse based on Cholesky factorization */ 27 | void THLapack_(potri)(char uplo, int n, real *a, int lda, int *info); 28 | /* Solve A*X = B with a symmetric positive definite matrix A using the Cholesky factorization */ 29 | void THLapack_(potrs)(char uplo, int n, int nrhs, real *a, int lda, real *b, int ldb, int *info); 30 | /* Cholesky factorization with complete pivoting. */ 31 | void THLapack_(pstrf)(char uplo, int n, real *a, int lda, int *piv, int *rank, real tol, real *work, int *info); 32 | 33 | /* QR decomposition */ 34 | void THLapack_(geqrf)(int m, int n, real *a, int lda, real *tau, real *work, int lwork, int *info); 35 | /* Build Q from output of geqrf */ 36 | void THLapack_(orgqr)(int m, int n, int k, real *a, int lda, real *tau, real *work, int lwork, int *info); 37 | /* Multiply Q with a matrix from output of geqrf */ 38 | void THLapack_(ormqr)(char side, char trans, int m, int n, int k, real *a, int lda, real *tau, real *c, int ldc, real *work, int lwork, int *info); 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /lib/THC/generic/THCStorage.h: -------------------------------------------------------------------------------- 1 | #ifndef THC_GENERIC_FILE 2 | #define THC_GENERIC_FILE "generic/THCStorage.h" 3 | #else 4 | 5 | #define TH_STORAGE_REFCOUNTED 1 6 | #define TH_STORAGE_RESIZABLE 2 7 | #define TH_STORAGE_FREEMEM 4 8 | 9 | typedef struct THCStorage 10 | { 11 | real *data; 12 | ptrdiff_t size; 13 | int refcount; 14 | char flag; 15 | THCDeviceAllocator *allocator; 16 | void *allocatorContext; 17 | struct THCStorage *view; 18 | int device; 19 | } THCStorage; 20 | 21 | 22 | THC_API real* THCStorage_(data)(THCState *state, const THCStorage*); 23 | THC_API ptrdiff_t THCStorage_(size)(THCState *state, const THCStorage*); 24 | THC_API int THCStorage_(elementSize)(THCState *state); 25 | 26 | /* slow access -- checks everything */ 27 | THC_API void THCStorage_(set)(THCState *state, THCStorage*, ptrdiff_t, real); 28 | THC_API real THCStorage_(get)(THCState *state, const THCStorage*, ptrdiff_t); 29 | 30 | THC_API THCStorage* THCStorage_(new)(THCState *state); 31 | THC_API THCStorage* THCStorage_(newWithSize)(THCState *state, ptrdiff_t size); 32 | THC_API THCStorage* THCStorage_(newWithSize1)(THCState *state, real); 33 | THC_API THCStorage* THCStorage_(newWithSize2)(THCState *state, real, real); 34 | THC_API THCStorage* THCStorage_(newWithSize3)(THCState *state, real, real, real); 35 | THC_API THCStorage* THCStorage_(newWithSize4)(THCState *state, real, real, real, real); 36 | THC_API THCStorage* THCStorage_(newWithMapping)(THCState *state, const char *filename, ptrdiff_t size, int shared); 37 | 38 | /* takes ownership of data */ 39 | THC_API THCStorage* THCStorage_(newWithData)(THCState *state, real *data, ptrdiff_t size); 40 | 41 | THC_API THCStorage* THCStorage_(newWithAllocator)( 42 | THCState *state, ptrdiff_t size, 43 | THCDeviceAllocator* allocator, 44 | void *allocatorContext); 45 | THC_API THCStorage* THCStorage_(newWithDataAndAllocator)( 46 | THCState *state, real* data, ptrdiff_t size, 47 | THCDeviceAllocator* allocator, 48 | void *allocatorContext); 49 | 50 | THC_API void THCStorage_(setFlag)(THCState *state, THCStorage *storage, const char flag); 51 | THC_API void THCStorage_(clearFlag)(THCState *state, THCStorage *storage, const char flag); 52 | THC_API void THCStorage_(retain)(THCState *state, THCStorage *storage); 53 | 54 | THC_API void THCStorage_(free)(THCState *state, THCStorage *storage); 55 | THC_API void THCStorage_(resize)(THCState *state, THCStorage *storage, ptrdiff_t size); 56 | THC_API void THCStorage_(fill)(THCState *state, THCStorage *storage, real value); 57 | 58 | THC_API int THCStorage_(getDevice)(THCState* state, const THCStorage* storage); 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /src/tensor/lua/src/llex.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: llex.h,v 1.79 2016/05/02 14:02:12 roberto Exp $ 3 | ** Lexical Analyzer 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef llex_h 8 | #define llex_h 9 | 10 | #include "lobject.h" 11 | #include "lzio.h" 12 | 13 | 14 | #define FIRST_RESERVED 257 15 | 16 | 17 | #if !defined(LUA_ENV) 18 | #define LUA_ENV "_ENV" 19 | #endif 20 | 21 | 22 | /* 23 | * WARNING: if you change the order of this enumeration, 24 | * grep "ORDER RESERVED" 25 | */ 26 | enum RESERVED { 27 | /* terminal symbols denoted by reserved words */ 28 | TK_AND = FIRST_RESERVED, TK_BREAK, 29 | TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION, 30 | TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, 31 | TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, 32 | /* other terminal symbols */ 33 | TK_IDIV, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, 34 | TK_SHL, TK_SHR, 35 | TK_DBCOLON, TK_EOS, 36 | TK_FLT, TK_INT, TK_NAME, TK_STRING 37 | }; 38 | 39 | /* number of reserved words */ 40 | #define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1)) 41 | 42 | 43 | typedef union { 44 | lua_Number r; 45 | lua_Integer i; 46 | TString *ts; 47 | } SemInfo; /* semantics information */ 48 | 49 | 50 | typedef struct Token { 51 | int token; 52 | SemInfo seminfo; 53 | } Token; 54 | 55 | 56 | /* state of the lexer plus state of the parser when shared by all 57 | functions */ 58 | typedef struct LexState { 59 | int current; /* current character (charint) */ 60 | int linenumber; /* input line counter */ 61 | int lastline; /* line of last token 'consumed' */ 62 | Token t; /* current token */ 63 | Token lookahead; /* look ahead token */ 64 | struct FuncState *fs; /* current function (parser) */ 65 | struct lua_State *L; 66 | ZIO *z; /* input stream */ 67 | Mbuffer *buff; /* buffer for tokens */ 68 | Table *h; /* to avoid collection/reuse strings */ 69 | struct Dyndata *dyd; /* dynamic structures used by the parser */ 70 | TString *source; /* current source name */ 71 | TString *envn; /* environment variable name */ 72 | } LexState; 73 | 74 | 75 | LUAI_FUNC void luaX_init (lua_State *L); 76 | LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, 77 | TString *source, int firstchar); 78 | LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l); 79 | LUAI_FUNC void luaX_next (LexState *ls); 80 | LUAI_FUNC int luaX_lookahead (LexState *ls); 81 | LUAI_FUNC l_noret luaX_syntaxerror (LexState *ls, const char *s); 82 | LUAI_FUNC const char *luaX_token2str (LexState *ls, int token); 83 | 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /lib/backward/test/suicide.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * test/suicide.cpp 3 | * Copyright 2013 Google Inc. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #include "backward.hpp" 25 | 26 | #include 27 | #include 28 | #include "test/test.hpp" 29 | 30 | using namespace backward; 31 | 32 | void badass_function() 33 | { 34 | char* ptr = (char*)42; 35 | *ptr = 42; 36 | } 37 | 38 | TEST_SEGFAULT (invalid_write) 39 | { 40 | badass_function(); 41 | } 42 | 43 | int you_shall_not_pass() 44 | { 45 | char* ptr = (char*)42; 46 | int v = *ptr; 47 | return v; 48 | } 49 | 50 | TEST_SEGFAULT(invalid_read) 51 | { 52 | int v = you_shall_not_pass(); 53 | std::cout << "v=" << v << std::endl; 54 | } 55 | 56 | void abort_abort_I_repeat_abort_abort() 57 | { 58 | std::cout << "Jumping off the boat!" << std::endl; 59 | abort(); 60 | } 61 | 62 | TEST_ABORT (calling_abort) 63 | { 64 | abort_abort_I_repeat_abort_abort(); 65 | } 66 | 67 | volatile int zero = 0; 68 | 69 | int divide_by_zero() 70 | { 71 | std::cout << "And the wild black hole appears..." << std::endl; 72 | int v = 42 / zero; 73 | return v; 74 | } 75 | 76 | TEST_DIVZERO (divide_by_zero) 77 | { 78 | int v = divide_by_zero(); 79 | std::cout << "v=" << v << std::endl; 80 | } 81 | 82 | int bye_bye_stack(int i) { 83 | return bye_bye_stack(i + 1) + bye_bye_stack(i * 2); 84 | } 85 | 86 | TEST_SEGFAULT(stackoverflow) 87 | { 88 | struct rlimit limit; 89 | limit.rlim_max = 8096; 90 | setrlimit(RLIMIT_STACK, &limit); 91 | int r = bye_bye_stack(42); 92 | std::cout << "r=" << r << std::endl; 93 | } 94 | -------------------------------------------------------------------------------- /src/tensor/lua/src/lmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.h,v 1.43 2014/12/19 17:26:14 roberto Exp $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lmem_h 8 | #define lmem_h 9 | 10 | 11 | #include 12 | 13 | #include "llimits.h" 14 | #include "lua.h" 15 | 16 | 17 | /* 18 | ** This macro reallocs a vector 'b' from 'on' to 'n' elements, where 19 | ** each element has size 'e'. In case of arithmetic overflow of the 20 | ** product 'n'*'e', it raises an error (calling 'luaM_toobig'). Because 21 | ** 'e' is always constant, it avoids the runtime division MAX_SIZET/(e). 22 | ** 23 | ** (The macro is somewhat complex to avoid warnings: The 'sizeof' 24 | ** comparison avoids a runtime comparison when overflow cannot occur. 25 | ** The compiler should be able to optimize the real test by itself, but 26 | ** when it does it, it may give a warning about "comparison is always 27 | ** false due to limited range of data type"; the +1 tricks the compiler, 28 | ** avoiding this warning but also this optimization.) 29 | */ 30 | #define luaM_reallocv(L,b,on,n,e) \ 31 | (((sizeof(n) >= sizeof(size_t) && cast(size_t, (n)) + 1 > MAX_SIZET/(e)) \ 32 | ? luaM_toobig(L) : cast_void(0)) , \ 33 | luaM_realloc_(L, (b), (on)*(e), (n)*(e))) 34 | 35 | /* 36 | ** Arrays of chars do not need any test 37 | */ 38 | #define luaM_reallocvchar(L,b,on,n) \ 39 | cast(char *, luaM_realloc_(L, (b), (on)*sizeof(char), (n)*sizeof(char))) 40 | 41 | #define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0) 42 | #define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0) 43 | #define luaM_freearray(L, b, n) luaM_realloc_(L, (b), (n)*sizeof(*(b)), 0) 44 | 45 | #define luaM_malloc(L,s) luaM_realloc_(L, NULL, 0, (s)) 46 | #define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t))) 47 | #define luaM_newvector(L,n,t) \ 48 | cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t))) 49 | 50 | #define luaM_newobject(L,tag,s) luaM_realloc_(L, NULL, tag, (s)) 51 | 52 | #define luaM_growvector(L,v,nelems,size,t,limit,e) \ 53 | if ((nelems)+1 > (size)) \ 54 | ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e))) 55 | 56 | #define luaM_reallocvector(L, v,oldn,n,t) \ 57 | ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t)))) 58 | 59 | LUAI_FUNC l_noret luaM_toobig (lua_State *L); 60 | 61 | /* not to be called directly */ 62 | LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, 63 | size_t size); 64 | LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size, 65 | size_t size_elem, int limit, 66 | const char *what); 67 | 68 | #endif 69 | 70 | -------------------------------------------------------------------------------- /lib/THC/THCTensorMathCompare.cuh: -------------------------------------------------------------------------------- 1 | #ifndef THC_TENSORMATH_COMPARE_CUH 2 | #define THC_TENSORMATH_COMPARE_CUH 3 | 4 | #include "THCTensorMath.h" 5 | #include "THCGeneral.h" 6 | #include "THCTensorCopy.h" 7 | #include "THCApply.cuh" 8 | #include "THCNumerics.cuh" 9 | 10 | template 11 | struct TensorLTValueOp { 12 | TensorLTValueOp(T v) : value(v) {} 13 | __device__ __forceinline__ void operator()(TOut* out, T* in) { 14 | *out = ScalarConvert::to(THCNumerics::lt(*in, value)); 15 | } 16 | 17 | const T value; 18 | }; 19 | 20 | template 21 | struct TensorGTValueOp { 22 | TensorGTValueOp(T v) : value(v) {} 23 | __device__ __forceinline__ void operator()(TOut* out, T* in) { 24 | *out = ScalarConvert::to(THCNumerics::gt(*in, value)); 25 | } 26 | 27 | const T value; 28 | }; 29 | 30 | 31 | template 32 | struct TensorLEValueOp { 33 | TensorLEValueOp(T v) : value(v) {} 34 | __device__ __forceinline__ void operator()(TOut* out, T* in) { 35 | *out = ScalarConvert::to(THCNumerics::le(*in, value)); 36 | } 37 | 38 | const T value; 39 | }; 40 | 41 | template 42 | struct TensorGEValueOp { 43 | TensorGEValueOp(T v) : value(v) {} 44 | __device__ __forceinline__ void operator()(TOut* out, T* in) { 45 | *out = ScalarConvert::to(THCNumerics::ge(*in, value)); 46 | } 47 | 48 | const T value; 49 | }; 50 | 51 | template 52 | struct TensorEQValueOp { 53 | TensorEQValueOp(T v) : value(v) {} 54 | __device__ __forceinline__ void operator()(TOut* out, T* in) { 55 | *out = ScalarConvert::to(THCNumerics::eq(*in, value)); 56 | } 57 | 58 | const T value; 59 | }; 60 | 61 | template 62 | struct TensorNEValueOp { 63 | TensorNEValueOp(T v) : value(v) {} 64 | __device__ __forceinline__ void operator()(TOut* out, T* in) { 65 | *out = ScalarConvert::to(THCNumerics::ne(*in, value)); 66 | } 67 | 68 | const T value; 69 | }; 70 | 71 | template 72 | void THC_logicalValue(THCState *state, 73 | TensorTypeOut *self_, 74 | TensorType *src, 75 | Op op) { 76 | THLongStorage* st = TensorUtils::newSizeOf(state, src); 77 | TensorUtils::resize(state, self_, st, NULL); 78 | THLongStorage_free(st); 79 | 80 | if (!THC_pointwiseApply2(state, self_, src, op)) { 81 | THArgCheck(false, 2, CUTORCH_DIM_WARNING); 82 | } 83 | 84 | THCudaCheck(cudaGetLastError()); 85 | } 86 | 87 | #endif // THC_TENSORMATH_COMPARE_CUH 88 | -------------------------------------------------------------------------------- /lib/TH/generic/THStorageCopy.c: -------------------------------------------------------------------------------- 1 | #ifndef TH_GENERIC_FILE 2 | #define TH_GENERIC_FILE "generic/THStorageCopy.c" 3 | #else 4 | 5 | void THStorage_(rawCopy)(THStorage *storage, real *src) 6 | { 7 | ptrdiff_t i; 8 | for(i = 0; i < storage->size; i++) 9 | storage->data[i] = src[i]; 10 | } 11 | 12 | void THStorage_(copy)(THStorage *storage, THStorage *src) 13 | { 14 | THArgCheck(storage->size == src->size, 2, "size mismatch"); 15 | THStorage_(rawCopy)(storage, src->data); 16 | } 17 | 18 | #define IMPLEMENT_THStorage_COPY(TYPENAMESRC) \ 19 | void THStorage_(copy##TYPENAMESRC)(THStorage *storage, TH##TYPENAMESRC##Storage *src) \ 20 | { \ 21 | ptrdiff_t i; \ 22 | for(i = 0; i < storage->size; i++) \ 23 | storage->data[i] = (real)src->data[i]; \ 24 | } 25 | 26 | #define IMPLEMENT_THStorage_COPY_FROM_HALF(TYPENAMESRC) \ 27 | void THStorage_(copy##TYPENAMESRC)(THStorage *storage, TH##TYPENAMESRC##Storage *src) \ 28 | { \ 29 | THArgCheck(storage->size == src->size, 2, "size mismatch"); \ 30 | ptrdiff_t i; \ 31 | for(i = 0; i < storage->size; i++) \ 32 | storage->data[i] = (real)TH_half2float(src->data[i]); \ 33 | } 34 | 35 | #define IMPLEMENT_THStorage_COPY_TO_HALF(TYPENAMESRC) \ 36 | void THStorage_(copy##TYPENAMESRC)(THStorage *storage, TH##TYPENAMESRC##Storage *src) \ 37 | { \ 38 | THArgCheck(storage->size == src->size, 2, "size mismatch"); \ 39 | ptrdiff_t i; \ 40 | for(i = 0; i < storage->size; i++) \ 41 | storage->data[i] = TH_float2half((float)(src->data[i])); \ 42 | } 43 | 44 | #define IMPLEMENT_THStorage_COPY_TO_FROM_HALF(TYPENAMESRC) \ 45 | void THStorage_(copy##TYPENAMESRC)(THStorage *storage, TH##TYPENAMESRC##Storage *src) \ 46 | { \ 47 | THArgCheck(storage->size == src->size, 2, "size mismatch"); \ 48 | ptrdiff_t i; \ 49 | for(i = 0; i < storage->size; i++) \ 50 | storage->data[i] = src->data[i]; \ 51 | } 52 | 53 | #ifndef TH_REAL_IS_HALF 54 | IMPLEMENT_THStorage_COPY(Byte) 55 | IMPLEMENT_THStorage_COPY(Char) 56 | IMPLEMENT_THStorage_COPY(Short) 57 | IMPLEMENT_THStorage_COPY(Int) 58 | IMPLEMENT_THStorage_COPY(Long) 59 | IMPLEMENT_THStorage_COPY(Float) 60 | IMPLEMENT_THStorage_COPY(Double) 61 | IMPLEMENT_THStorage_COPY_FROM_HALF(Half) 62 | #else 63 | /* only allow pass-through for Half */ 64 | IMPLEMENT_THStorage_COPY_TO_FROM_HALF(Half) 65 | IMPLEMENT_THStorage_COPY_TO_HALF(Byte) 66 | IMPLEMENT_THStorage_COPY_TO_HALF(Char) 67 | IMPLEMENT_THStorage_COPY_TO_HALF(Short) 68 | IMPLEMENT_THStorage_COPY_TO_HALF(Int) 69 | IMPLEMENT_THStorage_COPY_TO_HALF(Long) 70 | IMPLEMENT_THStorage_COPY_TO_HALF(Float) 71 | IMPLEMENT_THStorage_COPY_TO_HALF(Double) 72 | #endif 73 | 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /lib/THC/THCTensorSort.cuh: -------------------------------------------------------------------------------- 1 | #ifndef THC_TENSORSORT_CUH 2 | #define THC_TENSORSORT_CUH 3 | 4 | #include "THCReduceApplyUtils.cuh" 5 | #include "THCSortUtils.cuh" 6 | #include "THCTensorCopy.h" 7 | #include "THCTensorTypeUtils.cuh" 8 | 9 | #include "THCThrustAllocator.cuh" 10 | #include 11 | #include 12 | #if CUDA_VERSION >= 7000 13 | #include 14 | #endif 15 | 16 | template 17 | struct ThrustGTOp { 18 | __device__ bool operator()(const T& lhs, const T& rhs) const { 19 | return THCNumerics::gt(lhs, rhs); 20 | } 21 | }; 22 | 23 | template 24 | struct ThrustLTOp { 25 | __device__ bool operator()(const T& lhs, const T& rhs) const { 26 | return THCNumerics::lt(lhs, rhs); 27 | } 28 | }; 29 | 30 | // `base` is the base address of a tensor 31 | // For each slice (defined as a linear point of `out`, from 0 -> 32 | // (sliceSize - 1) * sliceStride, we fill that slice from `0` to 33 | // `sliceSize - 1`. 34 | template 35 | __global__ void 36 | fillSliceWithIndex(TensorInfo out, 37 | IndexType totalSlices, 38 | IndexType sliceSize, 39 | IndexType sliceStride) { 40 | IndexType slice = getLinearBlockId(); 41 | 42 | if (slice >= totalSlices) { 43 | return; 44 | } 45 | 46 | const unsigned long offset = 47 | IndexToOffset::get(slice, out); 48 | long* base = &out.data[offset]; 49 | 50 | for (long i = threadIdx.x; i < sliceSize; i += blockDim.x) { 51 | // Torch indices are 1-based (hence the +1) 52 | base[i * sliceStride] = i + TH_INDEX_BASE; 53 | } 54 | } 55 | 56 | // For slice sorting in Thrust; extracts a slice index from a linear 57 | // index and uses that for comparison 58 | struct SliceComp { 59 | SliceComp(long size) : sliceSize(size) {} 60 | 61 | __device__ bool operator()(const long& a, const long& b) const { 62 | // Since the slices are guaranteed to be innermost, the segment is 63 | // just via long division 64 | long segA = a / sliceSize; 65 | long segB = b / sliceSize; 66 | return segA < segB; 67 | } 68 | 69 | const long sliceSize; 70 | }; 71 | 72 | // For sorting in Thurst; extracts a within-slice index from a linear index 73 | struct GlobalIndexToPerSliceIndex { 74 | GlobalIndexToPerSliceIndex(long size) : sliceSize(size) {} 75 | 76 | __device__ inline void operator()(long& v) const { 77 | v = v % sliceSize + TH_INDEX_BASE; 78 | } 79 | 80 | const long sliceSize; 81 | }; 82 | 83 | void THCudaLongTensor_fillSliceWithIndex(THCState* state, 84 | THCudaLongTensor* t, 85 | int dim); 86 | #endif // THC_TENSORSORT_CUH 87 | -------------------------------------------------------------------------------- /src/tensor/lua/doc/lua.1: -------------------------------------------------------------------------------- 1 | .\" $Id: lua.man,v 1.14 2016/10/17 15:43:50 lhf Exp $ 2 | .TH LUA 1 "$Date: 2016/10/17 15:43:50 $" 3 | .SH NAME 4 | lua \- Lua interpreter 5 | .SH SYNOPSIS 6 | .B lua 7 | [ 8 | .I options 9 | ] 10 | [ 11 | .I script 12 | [ 13 | .I args 14 | ] 15 | ] 16 | .SH DESCRIPTION 17 | .B lua 18 | is the standalone Lua interpreter. 19 | It loads and executes Lua programs, 20 | either in textual source form or 21 | in precompiled binary form. 22 | (Precompiled binaries are output by 23 | .BR luac , 24 | the Lua compiler.) 25 | .B lua 26 | can be used as a batch interpreter and also interactively. 27 | .LP 28 | The given 29 | .I options 30 | are handled in order and then 31 | the Lua program in file 32 | .I script 33 | is loaded and executed. 34 | The given 35 | .I args 36 | are available to 37 | .I script 38 | as strings in a global table named 39 | .BR arg . 40 | If no options or arguments are given, 41 | then 42 | .B "\-v \-i" 43 | is assumed when the standard input is a terminal; 44 | otherwise, 45 | .B "\-" 46 | is assumed. 47 | .LP 48 | In interactive mode, 49 | .B lua 50 | prompts the user, 51 | reads lines from the standard input, 52 | and executes them as they are read. 53 | If the line contains an expression or list of expressions, 54 | then the line is evaluated and the results are printed. 55 | If a line does not contain a complete statement, 56 | then a secondary prompt is displayed and 57 | lines are read until a complete statement is formed or 58 | a syntax error is found. 59 | .LP 60 | At the very start, 61 | before even handling the command line, 62 | .B lua 63 | checks the contents of the environment variables 64 | .B LUA_INIT_5_3 65 | or 66 | .BR LUA_INIT , 67 | in that order. 68 | If the contents is of the form 69 | .RI '@ filename ', 70 | then 71 | .I filename 72 | is executed. 73 | Otherwise, the string is assumed to be a Lua statement and is executed. 74 | .SH OPTIONS 75 | .TP 76 | .BI \-e " stat" 77 | execute statement 78 | .IR stat . 79 | .TP 80 | .B \-i 81 | enter interactive mode after executing 82 | .IR script . 83 | .TP 84 | .BI \-l " name" 85 | execute the equivalent of 86 | .IB name =require(' name ') 87 | before executing 88 | .IR script . 89 | .TP 90 | .B \-v 91 | show version information. 92 | .TP 93 | .B \-E 94 | ignore environment variables. 95 | .TP 96 | .B \-\- 97 | stop handling options. 98 | .TP 99 | .B \- 100 | stop handling options and execute the standard input as a file. 101 | .SH "SEE ALSO" 102 | .BR luac (1) 103 | .br 104 | The documentation at lua.org, 105 | especially section 7 of the reference manual. 106 | .SH DIAGNOSTICS 107 | Error messages should be self explanatory. 108 | .SH AUTHORS 109 | R. Ierusalimschy, 110 | L. H. de Figueiredo, 111 | W. Celes 112 | .\" EOF 113 | -------------------------------------------------------------------------------- /lib/TH/generic/THStorage.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_GENERIC_FILE 2 | #define TH_GENERIC_FILE "generic/THStorage.h" 3 | #else 4 | 5 | /* on pourrait avoir un liste chainee 6 | qui initialise math, lab structures (or more). 7 | mouais -- complique. 8 | 9 | Pb: THMapStorage is kind of a class 10 | THLab_()... comment je m'en sors? 11 | 12 | en template, faudrait que je les instancie toutes!!! oh boy! 13 | Et comment je sais que c'est pour Cuda? Le type float est le meme dans les <> 14 | 15 | au bout du compte, ca serait sur des pointeurs float/double... etc... = facile. 16 | primitives?? 17 | */ 18 | 19 | #define TH_STORAGE_REFCOUNTED 1 20 | #define TH_STORAGE_RESIZABLE 2 21 | #define TH_STORAGE_FREEMEM 4 22 | #define TH_STORAGE_VIEW 8 23 | 24 | typedef struct THStorage 25 | { 26 | real *data; 27 | ptrdiff_t size; 28 | int refcount; 29 | char flag; 30 | THAllocator *allocator; 31 | void *allocatorContext; 32 | struct THStorage *view; 33 | } THStorage; 34 | 35 | TH_API real* THStorage_(data)(const THStorage*); 36 | TH_API ptrdiff_t THStorage_(size)(const THStorage*); 37 | TH_API size_t THStorage_(elementSize)(void); 38 | 39 | /* slow access -- checks everything */ 40 | TH_API void THStorage_(set)(THStorage*, ptrdiff_t, real); 41 | TH_API real THStorage_(get)(const THStorage*, ptrdiff_t); 42 | 43 | TH_API THStorage* THStorage_(new)(void); 44 | TH_API THStorage* THStorage_(newWithSize)(ptrdiff_t size); 45 | TH_API THStorage* THStorage_(newWithSize1)(real); 46 | TH_API THStorage* THStorage_(newWithSize2)(real, real); 47 | TH_API THStorage* THStorage_(newWithSize3)(real, real, real); 48 | TH_API THStorage* THStorage_(newWithSize4)(real, real, real, real); 49 | TH_API THStorage* THStorage_(newWithMapping)(const char *filename, ptrdiff_t size, int flags); 50 | 51 | /* takes ownership of data */ 52 | TH_API THStorage* THStorage_(newWithData)(real *data, ptrdiff_t size); 53 | 54 | TH_API THStorage* THStorage_(newWithAllocator)(ptrdiff_t size, 55 | THAllocator* allocator, 56 | void *allocatorContext); 57 | TH_API THStorage* THStorage_(newWithDataAndAllocator)( 58 | real* data, ptrdiff_t size, THAllocator* allocator, void *allocatorContext); 59 | 60 | /* should not differ with API */ 61 | TH_API void THStorage_(setFlag)(THStorage *storage, const char flag); 62 | TH_API void THStorage_(clearFlag)(THStorage *storage, const char flag); 63 | TH_API void THStorage_(retain)(THStorage *storage); 64 | TH_API void THStorage_(swap)(THStorage *storage1, THStorage *storage2); 65 | 66 | /* might differ with other API (like CUDA) */ 67 | TH_API void THStorage_(free)(THStorage *storage); 68 | TH_API void THStorage_(resize)(THStorage *storage, ptrdiff_t size); 69 | TH_API void THStorage_(fill)(THStorage *storage, real value); 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /lib/TH/THHalf.c: -------------------------------------------------------------------------------- 1 | #include "THHalf.h" 2 | 3 | /* Copyright 1993-2014 NVIDIA Corporation. All rights reserved. */ 4 | 5 | THHalf TH_float2half(float f) 6 | { 7 | THHalf h; 8 | TH_float2halfbits(&f, &h.x); 9 | return h; 10 | } 11 | 12 | TH_API float TH_half2float(THHalf h) 13 | { 14 | float f; 15 | TH_halfbits2float(&h.x, &f); 16 | return f; 17 | } 18 | 19 | // Host functions for converting between FP32 and FP16 formats 20 | 21 | void TH_halfbits2float(unsigned short* src, float* res) 22 | { 23 | unsigned h = *src; 24 | unsigned sign = ((h >> 15) & 1); 25 | unsigned exponent = ((h >> 10) & 0x1f); 26 | unsigned mantissa = ((h & 0x3ff) << 13); 27 | 28 | if (exponent == 0x1f) { /* NaN or Inf */ 29 | mantissa = (mantissa ? (sign = 0, 0x7fffff) : 0); 30 | exponent = 0xff; 31 | } else if (!exponent) { /* Denorm or Zero */ 32 | if (mantissa) { 33 | unsigned int msb; 34 | exponent = 0x71; 35 | do { 36 | msb = (mantissa & 0x400000); 37 | mantissa <<= 1; /* normalize */ 38 | --exponent; 39 | } while (!msb); 40 | mantissa &= 0x7fffff; /* 1.mantissa is implicit */ 41 | } 42 | } else { 43 | exponent += 0x70; 44 | } 45 | 46 | *(unsigned*)res = ((sign << 31) | (exponent << 23) | mantissa); 47 | } 48 | 49 | void TH_float2halfbits(float* src, unsigned short* dest) 50 | { 51 | unsigned x = *(unsigned*)src; 52 | unsigned u = (x & 0x7fffffff), remainder, shift, lsb, lsb_s1, lsb_m1; 53 | unsigned sign, exponent, mantissa; 54 | 55 | // Get rid of +NaN/-NaN case first. 56 | if (u > 0x7f800000) { 57 | *dest = 0x7fffU; 58 | return ; 59 | } 60 | 61 | sign = ((x >> 16) & 0x8000); 62 | 63 | // Get rid of +Inf/-Inf, +0/-0. 64 | if (u > 0x477fefff) { 65 | *dest = sign | 0x7c00U; 66 | return; 67 | } 68 | if (u < 0x33000001) { 69 | *dest = (sign | 0x0000); 70 | return; 71 | } 72 | 73 | exponent = ((u >> 23) & 0xff); 74 | mantissa = (u & 0x7fffff); 75 | 76 | if (exponent > 0x70) { 77 | shift = 13; 78 | exponent -= 0x70; 79 | } else { 80 | shift = 0x7e - exponent; 81 | exponent = 0; 82 | mantissa |= 0x800000; 83 | } 84 | lsb = (1 << shift); 85 | lsb_s1 = (lsb >> 1); 86 | lsb_m1 = (lsb - 1); 87 | 88 | // Round to nearest even. 89 | remainder = (mantissa & lsb_m1); 90 | mantissa >>= shift; 91 | if (remainder > lsb_s1 || (remainder == lsb_s1 && (mantissa & 0x1))) { 92 | ++mantissa; 93 | if (!(mantissa & 0x3ff)) { 94 | ++exponent; 95 | mantissa = 0; 96 | } 97 | } 98 | 99 | *dest = (sign | (exponent << 10) | mantissa); 100 | } 101 | --------------------------------------------------------------------------------