├── .gitignore ├── .travis.yml ├── CONTRIBUTING.md ├── Dockerfile ├── LICENSE ├── README.md ├── README_Windows.md ├── cmake └── FindCUDA │ ├── FindCUDA.cmake │ └── FindCUDA │ ├── make2cmake.cmake │ ├── parse_cubin.cmake │ ├── run_nvcc.cmake │ └── select_compute_arch.cmake ├── docs ├── Makefile ├── make.bat ├── requirements.txt └── source │ ├── _static │ ├── css │ │ └── pytorch_theme.css │ └── img │ │ ├── dynamic_graph.gif │ │ ├── pytorch-logo-dark.png │ │ ├── pytorch-logo-dark.svg │ │ ├── pytorch-logo-flame.png │ │ ├── pytorch-logo-flame.svg │ │ └── tensor_illustration.png │ ├── autograd.rst │ ├── conf.py │ ├── cuda.rst │ ├── data.rst │ ├── ffi.rst │ ├── index.rst │ ├── legacy.rst │ ├── model_zoo.rst │ ├── multiprocessing.rst │ ├── nn.rst │ ├── notes │ ├── autograd.rst │ ├── cuda.rst │ ├── extending.rst │ ├── multiprocessing.rst │ └── serialization.rst │ ├── optim.rst │ ├── sparse.rst │ ├── storage.rst │ ├── tensors.rst │ ├── torch.rst │ └── torchvision │ ├── datasets.rst │ ├── models.rst │ ├── torchvision.rst │ ├── transforms.rst │ └── utils.rst ├── requirements.txt ├── setup.py ├── test ├── common.py ├── common_nn.py ├── data │ ├── network1.py │ └── network2.py ├── error_messages │ └── storage.py ├── ffi │ └── src │ │ ├── cpu │ │ ├── lib.h │ │ ├── lib1.c │ │ └── lib2.c │ │ ├── cuda │ │ ├── cudalib.c │ │ └── cudalib.h │ │ └── lib.h ├── optim │ ├── compare.sh │ ├── test.lua │ ├── test.py │ └── tests.json ├── run_test.bat ├── run_test.sh ├── test_autograd.py ├── test_cuda.py ├── test_dataloader.py ├── test_distributed.py ├── test_legacy_nn.py ├── test_multiprocessing.py ├── test_nccl.py ├── test_nn.py ├── test_optim.py ├── test_sparse.py ├── test_torch.py └── test_utils.py ├── tools ├── __init__.py ├── convert.vim ├── cwrap │ ├── __init__.py │ ├── cwrap.py │ └── plugins │ │ ├── ArgcountChecker.py │ │ ├── ArgcountSortPlugin.py │ │ ├── ArgumentReferences.py │ │ ├── AutoGPU.py │ │ ├── BeforeAfterCall.py │ │ ├── BoolOption.py │ │ ├── ConstantArguments.py │ │ ├── CuDNNPlugin.py │ │ ├── GILRelease.py │ │ ├── GenericNN.py │ │ ├── KwargsPlugin.py │ │ ├── NullableArguments.py │ │ ├── OptionalArguments.py │ │ ├── ReturnArguments.py │ │ ├── StandaloneExtension.py │ │ ├── THPPlugin.py │ │ ├── WrapDim.py │ │ ├── __init__.py │ │ └── templates │ │ └── module_tail.cpp ├── nnwrap │ ├── __init__.py │ └── generate_wrappers.py └── setup_helpers │ ├── __init__.py │ ├── cuda.py │ ├── cudnn.py │ ├── env.py │ └── split_types.py ├── torch ├── __init__.py ├── _six.py ├── _tensor_docs.py ├── _tensor_str.py ├── _thnn │ ├── __init__.py │ └── utils.py ├── _torch_docs.py ├── _utils.py ├── autograd │ ├── __init__.py │ ├── _functions │ │ ├── __init__.py │ │ ├── basic_ops.py │ │ ├── blas.py │ │ ├── compare.py │ │ ├── linalg.py │ │ ├── pointwise.py │ │ ├── reduce.py │ │ ├── replace.vim │ │ ├── stochastic.py │ │ └── tensor.py │ ├── function.py │ ├── gradcheck.py │ ├── stochastic_function.py │ └── variable.py ├── backends │ ├── __init__.py │ └── cudnn │ │ ├── __init__.py │ │ └── rnn.py ├── csrc │ ├── DynamicTypes.cpp │ ├── DynamicTypes.h │ ├── Exceptions.cpp │ ├── Exceptions.h │ ├── Generator.cpp │ ├── Generator.h │ ├── Module.cpp │ ├── Module.h │ ├── ModuleSparse.cpp │ ├── PtrWrapper.cpp │ ├── PtrWrapper.h │ ├── Size.cpp │ ├── Size.h │ ├── Storage.cpp │ ├── Storage.h │ ├── THP.h │ ├── THP_API.h │ ├── Tensor.cpp │ ├── Tensor.h │ ├── Types.h │ ├── allocators.cpp │ ├── allocators.h │ ├── autograd │ │ ├── autograd.h │ │ ├── engine.cpp │ │ ├── engine.h │ │ ├── function.cpp │ │ ├── function.h │ │ ├── function_hook.h │ │ ├── functions │ │ │ ├── accumulate_grad.cpp │ │ │ ├── accumulate_grad.h │ │ │ ├── basic_ops.cpp │ │ │ ├── basic_ops.h │ │ │ ├── batch_normalization.cpp │ │ │ ├── batch_normalization.h │ │ │ ├── convolution.cpp │ │ │ ├── convolution.h │ │ │ ├── init.cpp │ │ │ ├── tensor.cpp │ │ │ ├── tensor.h │ │ │ ├── utils.cpp │ │ │ └── utils.h │ │ ├── init.cpp │ │ ├── input_buffer.cpp │ │ ├── input_buffer.h │ │ ├── python_cpp_function.cpp │ │ ├── python_cpp_function.h │ │ ├── python_engine.cpp │ │ ├── python_engine.h │ │ ├── python_function.cpp │ │ ├── python_function.h │ │ ├── python_hook.cpp │ │ ├── python_hook.h │ │ ├── python_variable.cpp │ │ ├── python_variable.h │ │ ├── variable.cpp │ │ ├── variable.h │ │ └── variable_version.h │ ├── byte_order.cpp │ ├── byte_order.h │ ├── copy_utils.h │ ├── cuda │ │ ├── AutoGPU.cpp │ │ ├── AutoGPU.h │ │ ├── Module.cpp │ │ ├── Module.h │ │ ├── ModuleSparse.cpp │ │ ├── Storage.cpp │ │ ├── Storage.h │ │ ├── Stream.cpp │ │ ├── Stream.h │ │ ├── THCP.h │ │ ├── Tensor.cpp │ │ ├── Tensor.h │ │ ├── override_macros.h │ │ ├── restore_macros.h │ │ ├── serialization.cpp │ │ ├── serialization.h │ │ ├── undef_macros.h │ │ ├── utils.cpp │ │ └── utils.h │ ├── cudnn │ │ ├── BatchNorm.cpp │ │ ├── BatchNorm.h │ │ ├── Conv.cpp │ │ ├── Conv.h │ │ ├── Descriptors.h │ │ ├── Exceptions.h │ │ ├── Handles.cpp │ │ ├── Handles.h │ │ ├── Module.h │ │ ├── Types.cpp │ │ ├── Types.h │ │ └── cuDNN.cwrap │ ├── distributed │ │ ├── Module.cpp │ │ ├── Storage.cpp │ │ ├── Storage.h │ │ ├── THDP.h │ │ ├── Tensor.cpp │ │ ├── Tensor.h │ │ ├── override_macros.h │ │ ├── undef_macros.h │ │ ├── utils.cpp │ │ └── utils.h │ ├── dl.c │ ├── generic │ │ ├── SparseTensor.cpp │ │ ├── Storage.cpp │ │ ├── Storage.h │ │ ├── StorageMethods.cpp │ │ ├── StorageSharing.cpp │ │ ├── Tensor.cpp │ │ ├── Tensor.h │ │ ├── TensorMethods.cwrap │ │ ├── methods │ │ │ ├── SparseTensor.cwrap │ │ │ ├── Tensor.cwrap │ │ │ ├── TensorApply.cwrap │ │ │ ├── TensorCompare.cwrap │ │ │ ├── TensorCuda.cwrap │ │ │ ├── TensorMath.cwrap │ │ │ ├── TensorRandom.cwrap │ │ │ └── TensorSerialization.cwrap │ │ ├── serialization.cpp │ │ ├── serialization.h │ │ ├── utils.cpp │ │ └── utils.h │ ├── nn │ │ ├── .gitkeep │ │ └── THNN_generic.inc.h │ ├── serialization.cpp │ ├── serialization.h │ ├── utils.cpp │ ├── utils.h │ └── utils │ │ ├── auto_gil.h │ │ ├── auto_gpu.h │ │ ├── auto_stream.h │ │ ├── object_ptr.cpp │ │ ├── object_ptr.h │ │ ├── python_numbers.h │ │ ├── python_strings.h │ │ ├── tuple_parser.cpp │ │ └── tuple_parser.h ├── cuda │ ├── __init__.py │ ├── comm.py │ ├── nccl.py │ ├── random.py │ ├── sparse.py │ └── streams.py ├── distributed │ ├── __init__.py │ ├── collectives.py │ └── remote_types.py ├── functional.py ├── legacy │ ├── __init__.py │ ├── nn │ │ ├── Abs.py │ │ ├── AbsCriterion.py │ │ ├── Add.py │ │ ├── AddConstant.py │ │ ├── BCECriterion.py │ │ ├── BatchNormalization.py │ │ ├── Bilinear.py │ │ ├── CAddTable.py │ │ ├── CDivTable.py │ │ ├── CMul.py │ │ ├── CMulTable.py │ │ ├── CSubTable.py │ │ ├── Clamp.py │ │ ├── ClassNLLCriterion.py │ │ ├── ClassSimplexCriterion.py │ │ ├── Concat.py │ │ ├── ConcatTable.py │ │ ├── Container.py │ │ ├── Contiguous.py │ │ ├── Copy.py │ │ ├── Cosine.py │ │ ├── CosineDistance.py │ │ ├── CosineEmbeddingCriterion.py │ │ ├── Criterion.py │ │ ├── CriterionTable.py │ │ ├── CrossEntropyCriterion.py │ │ ├── DepthConcat.py │ │ ├── DistKLDivCriterion.py │ │ ├── DotProduct.py │ │ ├── Dropout.py │ │ ├── ELU.py │ │ ├── Euclidean.py │ │ ├── Exp.py │ │ ├── FlattenTable.py │ │ ├── GradientReversal.py │ │ ├── HardShrink.py │ │ ├── HardTanh.py │ │ ├── HingeEmbeddingCriterion.py │ │ ├── Identity.py │ │ ├── Index.py │ │ ├── JoinTable.py │ │ ├── L1Cost.py │ │ ├── L1HingeEmbeddingCriterion.py │ │ ├── L1Penalty.py │ │ ├── LeakyReLU.py │ │ ├── Linear.py │ │ ├── Log.py │ │ ├── LogSigmoid.py │ │ ├── LogSoftMax.py │ │ ├── LookupTable.py │ │ ├── MM.py │ │ ├── MSECriterion.py │ │ ├── MV.py │ │ ├── MarginCriterion.py │ │ ├── MarginRankingCriterion.py │ │ ├── MaskedSelect.py │ │ ├── Max.py │ │ ├── Mean.py │ │ ├── Min.py │ │ ├── MixtureTable.py │ │ ├── Module.py │ │ ├── Mul.py │ │ ├── MulConstant.py │ │ ├── MultiCriterion.py │ │ ├── MultiLabelMarginCriterion.py │ │ ├── MultiLabelSoftMarginCriterion.py │ │ ├── MultiMarginCriterion.py │ │ ├── Narrow.py │ │ ├── NarrowTable.py │ │ ├── Normalize.py │ │ ├── PReLU.py │ │ ├── Padding.py │ │ ├── PairwiseDistance.py │ │ ├── Parallel.py │ │ ├── ParallelCriterion.py │ │ ├── ParallelTable.py │ │ ├── PartialLinear.py │ │ ├── Power.py │ │ ├── RReLU.py │ │ ├── ReLU.py │ │ ├── ReLU6.py │ │ ├── Replicate.py │ │ ├── Reshape.py │ │ ├── Select.py │ │ ├── SelectTable.py │ │ ├── Sequential.py │ │ ├── Sigmoid.py │ │ ├── SmoothL1Criterion.py │ │ ├── SoftMarginCriterion.py │ │ ├── SoftMax.py │ │ ├── SoftMin.py │ │ ├── SoftPlus.py │ │ ├── SoftShrink.py │ │ ├── SoftSign.py │ │ ├── SpatialAdaptiveMaxPooling.py │ │ ├── SpatialAveragePooling.py │ │ ├── SpatialBatchNormalization.py │ │ ├── SpatialClassNLLCriterion.py │ │ ├── SpatialContrastiveNormalization.py │ │ ├── SpatialConvolution.py │ │ ├── SpatialConvolutionLocal.py │ │ ├── SpatialConvolutionMap.py │ │ ├── SpatialCrossMapLRN.py │ │ ├── SpatialDilatedConvolution.py │ │ ├── SpatialDivisiveNormalization.py │ │ ├── SpatialDropout.py │ │ ├── SpatialFractionalMaxPooling.py │ │ ├── SpatialFullConvolution.py │ │ ├── SpatialFullConvolutionMap.py │ │ ├── SpatialLPPooling.py │ │ ├── SpatialMaxPooling.py │ │ ├── SpatialMaxUnpooling.py │ │ ├── SpatialReflectionPadding.py │ │ ├── SpatialReplicationPadding.py │ │ ├── SpatialSoftMax.py │ │ ├── SpatialSubSampling.py │ │ ├── SpatialSubtractiveNormalization.py │ │ ├── SpatialUpSamplingNearest.py │ │ ├── SpatialZeroPadding.py │ │ ├── SplitTable.py │ │ ├── Sqrt.py │ │ ├── Square.py │ │ ├── Squeeze.py │ │ ├── Sum.py │ │ ├── Tanh.py │ │ ├── TanhShrink.py │ │ ├── TemporalConvolution.py │ │ ├── TemporalMaxPooling.py │ │ ├── TemporalSubSampling.py │ │ ├── Threshold.py │ │ ├── Transpose.py │ │ ├── Unsqueeze.py │ │ ├── View.py │ │ ├── VolumetricAveragePooling.py │ │ ├── VolumetricBatchNormalization.py │ │ ├── VolumetricConvolution.py │ │ ├── VolumetricDropout.py │ │ ├── VolumetricFullConvolution.py │ │ ├── VolumetricMaxPooling.py │ │ ├── VolumetricMaxUnpooling.py │ │ ├── VolumetricReplicationPadding.py │ │ ├── WeightedEuclidean.py │ │ ├── WeightedMSECriterion.py │ │ ├── __init__.py │ │ ├── convert.vim │ │ └── utils.py │ └── optim │ │ ├── __init__.py │ │ ├── adadelta.py │ │ ├── adagrad.py │ │ ├── adam.py │ │ ├── adamax.py │ │ ├── asgd.py │ │ ├── cg.py │ │ ├── lbfgs.py │ │ ├── nag.py │ │ ├── rmsprop.py │ │ ├── rprop.py │ │ └── sgd.py ├── lib │ ├── README.md │ ├── TH │ │ ├── CMakeLists.txt │ │ ├── README.md │ │ ├── TH.h │ │ ├── THAllocator.c │ │ ├── THAllocator.h │ │ ├── THAtomic.c │ │ ├── THAtomic.h │ │ ├── THBlas.c │ │ ├── THBlas.h │ │ ├── THConfig.cmake.in │ │ ├── THDiskFile.c │ │ ├── THDiskFile.h │ │ ├── THFile.c │ │ ├── THFile.h │ │ ├── THFilePrivate.h │ │ ├── THGeneral.c │ │ ├── THGeneral.h.in │ │ ├── THGenerateAllTypes.h │ │ ├── THGenerateByteType.h │ │ ├── THGenerateCharType.h │ │ ├── THGenerateDoubleType.h │ │ ├── THGenerateFloatType.h │ │ ├── THGenerateFloatTypes.h │ │ ├── THGenerateHalfType.h │ │ ├── THGenerateIntType.h │ │ ├── THGenerateIntTypes.h │ │ ├── THGenerateLongType.h │ │ ├── THGenerateShortType.h │ │ ├── THHalf.c │ │ ├── THHalf.h │ │ ├── THLapack.c │ │ ├── THLapack.h │ │ ├── THLogAdd.c │ │ ├── THLogAdd.h │ │ ├── THMath.h │ │ ├── THMemoryFile.c │ │ ├── THMemoryFile.h │ │ ├── THRandom.c │ │ ├── THRandom.h │ │ ├── THStorage.c │ │ ├── THStorage.h │ │ ├── THTensor.c │ │ ├── THTensor.h │ │ ├── THTensorApply.h │ │ ├── THTensorDimApply.h │ │ ├── THTensorMacros.h │ │ ├── THVector.c │ │ ├── THVector.h │ │ ├── cmake │ │ │ ├── FindARM.cmake │ │ │ ├── FindBLAS.cmake │ │ │ ├── FindLAPACK.cmake │ │ │ ├── FindMKL.cmake │ │ │ └── FindSSE.cmake │ │ ├── generic │ │ │ ├── THBlas.c │ │ │ ├── THBlas.h │ │ │ ├── THLapack.c │ │ │ ├── THLapack.h │ │ │ ├── THStorage.c │ │ │ ├── THStorage.h │ │ │ ├── THStorageCopy.c │ │ │ ├── THStorageCopy.h │ │ │ ├── THTensor.c │ │ │ ├── THTensor.h │ │ │ ├── THTensorConv.c │ │ │ ├── THTensorConv.h │ │ │ ├── THTensorCopy.c │ │ │ ├── THTensorCopy.h │ │ │ ├── THTensorLapack.c │ │ │ ├── THTensorLapack.h │ │ │ ├── THTensorMath.c │ │ │ ├── THTensorMath.h │ │ │ ├── THTensorRandom.c │ │ │ ├── THTensorRandom.h │ │ │ ├── THVector.h │ │ │ ├── THVectorDefault.c │ │ │ ├── THVectorDispatch.c │ │ │ └── simd │ │ │ │ ├── common_simd.h │ │ │ │ ├── convolve.c │ │ │ │ ├── convolve.h │ │ │ │ ├── convolve5x5_avx.c │ │ │ │ ├── convolve5x5_sse.c │ │ │ │ └── simd.h │ │ └── vector │ │ │ ├── AVX.c │ │ │ ├── AVX.h │ │ │ ├── AVX2.c │ │ │ ├── AVX2.h │ │ │ ├── NEON.c │ │ │ ├── SSE.c │ │ │ └── VSX.c │ ├── THC │ │ ├── CMakeLists.txt │ │ ├── THC.h │ │ ├── THCAllocator.c │ │ ├── THCAllocator.h │ │ ├── THCApply.cuh │ │ ├── THCAsmUtils.cuh │ │ ├── THCAtomics.cuh │ │ ├── THCBlas.cu │ │ ├── THCBlas.h │ │ ├── THCCachingAllocator.cpp │ │ ├── THCCachingAllocator.h │ │ ├── THCCachingHostAllocator.cpp │ │ ├── THCCachingHostAllocator.h │ │ ├── THCDeviceTensor-inl.cuh │ │ ├── THCDeviceTensor.cuh │ │ ├── THCDeviceTensorUtils-inl.cuh │ │ ├── THCDeviceTensorUtils.cuh │ │ ├── THCDeviceUtils.cuh │ │ ├── THCGeneral.c │ │ ├── THCGeneral.h.in │ │ ├── THCGenerateAllTypes.h │ │ ├── THCGenerateByteType.h │ │ ├── THCGenerateCharType.h │ │ ├── THCGenerateDoubleType.h │ │ ├── THCGenerateFloatType.h │ │ ├── THCGenerateFloatTypes.h │ │ ├── THCGenerateHalfType.h │ │ ├── THCGenerateIntType.h │ │ ├── THCGenerateLongType.h │ │ ├── THCGenerateShortType.h │ │ ├── THCHalf.cu │ │ ├── THCHalf.h │ │ ├── THCNumerics.cuh │ │ ├── THCReduce.cuh │ │ ├── THCReduceAll.cuh │ │ ├── THCReduceApplyUtils.cu │ │ ├── THCReduceApplyUtils.cuh │ │ ├── THCScanUtils.cuh │ │ ├── THCSleep.cu │ │ ├── THCSleep.h │ │ ├── THCSortUtils.cu │ │ ├── THCSortUtils.cuh │ │ ├── THCStorage.c │ │ ├── THCStorage.cu │ │ ├── THCStorage.h │ │ ├── THCStorageCopy.c │ │ ├── THCStorageCopy.cu │ │ ├── THCStorageCopy.h │ │ ├── THCStream.cpp │ │ ├── THCStream.h │ │ ├── THCTensor.c │ │ ├── THCTensor.cu │ │ ├── THCTensor.h │ │ ├── THCTensorConv.cu │ │ ├── THCTensorConv.h │ │ ├── THCTensorCopy.c │ │ ├── THCTensorCopy.cu │ │ ├── THCTensorCopy.h │ │ ├── THCTensorIndex.cu │ │ ├── THCTensorInfo.cuh │ │ ├── THCTensorMasked.cuh │ │ ├── THCTensorMath.cu │ │ ├── THCTensorMath.cuh │ │ ├── THCTensorMath.h │ │ ├── THCTensorMath2.cu │ │ ├── THCTensorMathBlas.cu │ │ ├── THCTensorMathCompare.cuh │ │ ├── THCTensorMathCompareT.cuh │ │ ├── THCTensorMathMagma.cu │ │ ├── THCTensorMathMagma.cuh │ │ ├── THCTensorMathPairwise.cu │ │ ├── THCTensorMathPointwise.cuh │ │ ├── THCTensorMathReduce.cu │ │ ├── THCTensorMathReduce.cuh │ │ ├── THCTensorMathScan.cu │ │ ├── THCTensorMode.cu │ │ ├── THCTensorMode.cuh │ │ ├── THCTensorRandom.cpp │ │ ├── THCTensorRandom.cu │ │ ├── THCTensorRandom.cuh │ │ ├── THCTensorRandom.h │ │ ├── THCTensorScatterGather.cu │ │ ├── THCTensorSort.cu │ │ ├── THCTensorSort.cuh │ │ ├── THCTensorTopK.cu │ │ ├── THCTensorTopK.cuh │ │ ├── THCTensorTypeUtils.cu │ │ ├── THCTensorTypeUtils.cuh │ │ ├── THCThreadLocal.c │ │ ├── THCThreadLocal.h │ │ ├── THCThrustAllocator.cuh │ │ ├── cmake │ │ │ ├── FindMAGMA.cmake │ │ │ └── select_compute_arch.cmake │ │ ├── generated │ │ │ ├── THCTensorMaskedByte.cu │ │ │ ├── THCTensorMaskedChar.cu │ │ │ ├── THCTensorMaskedDouble.cu │ │ │ ├── THCTensorMaskedFloat.cu │ │ │ ├── THCTensorMaskedHalf.cu │ │ │ ├── THCTensorMaskedInt.cu │ │ │ ├── THCTensorMaskedLong.cu │ │ │ ├── THCTensorMaskedShort.cu │ │ │ ├── THCTensorMathCompareByte.cu │ │ │ ├── THCTensorMathCompareChar.cu │ │ │ ├── THCTensorMathCompareDouble.cu │ │ │ ├── THCTensorMathCompareFloat.cu │ │ │ ├── THCTensorMathCompareHalf.cu │ │ │ ├── THCTensorMathCompareInt.cu │ │ │ ├── THCTensorMathCompareLong.cu │ │ │ ├── THCTensorMathCompareShort.cu │ │ │ ├── THCTensorMathCompareTByte.cu │ │ │ ├── THCTensorMathCompareTChar.cu │ │ │ ├── THCTensorMathCompareTDouble.cu │ │ │ ├── THCTensorMathCompareTFloat.cu │ │ │ ├── THCTensorMathCompareTHalf.cu │ │ │ ├── THCTensorMathCompareTInt.cu │ │ │ ├── THCTensorMathCompareTLong.cu │ │ │ ├── THCTensorMathCompareTShort.cu │ │ │ ├── THCTensorMathPointwiseByte.cu │ │ │ ├── THCTensorMathPointwiseChar.cu │ │ │ ├── THCTensorMathPointwiseDouble.cu │ │ │ ├── THCTensorMathPointwiseFloat.cu │ │ │ ├── THCTensorMathPointwiseHalf.cu │ │ │ ├── THCTensorMathPointwiseInt.cu │ │ │ ├── THCTensorMathPointwiseLong.cu │ │ │ ├── THCTensorMathPointwiseShort.cu │ │ │ ├── THCTensorMathReduceByte.cu │ │ │ ├── THCTensorMathReduceChar.cu │ │ │ ├── THCTensorMathReduceDouble.cu │ │ │ ├── THCTensorMathReduceFloat.cu │ │ │ ├── THCTensorMathReduceHalf.cu │ │ │ ├── THCTensorMathReduceInt.cu │ │ │ ├── THCTensorMathReduceLong.cu │ │ │ ├── THCTensorMathReduceShort.cu │ │ │ ├── THCTensorSortByte.cu │ │ │ ├── THCTensorSortChar.cu │ │ │ ├── THCTensorSortDouble.cu │ │ │ ├── THCTensorSortFloat.cu │ │ │ ├── THCTensorSortHalf.cu │ │ │ ├── THCTensorSortInt.cu │ │ │ ├── THCTensorSortLong.cu │ │ │ └── THCTensorSortShort.cu │ │ └── generic │ │ │ ├── THCDeviceTensorUtils.cu │ │ │ ├── THCStorage.c │ │ │ ├── THCStorage.cu │ │ │ ├── THCStorage.h │ │ │ ├── THCStorageCopy.c │ │ │ ├── THCStorageCopy.cu │ │ │ ├── THCStorageCopy.h │ │ │ ├── THCTensor.c │ │ │ ├── THCTensor.cu │ │ │ ├── THCTensor.h │ │ │ ├── THCTensorCopy.c │ │ │ ├── THCTensorCopy.cu │ │ │ ├── THCTensorCopy.h │ │ │ ├── THCTensorIndex.cu │ │ │ ├── THCTensorIndex.h │ │ │ ├── THCTensorMasked.cu │ │ │ ├── THCTensorMasked.h │ │ │ ├── THCTensorMath.cu │ │ │ ├── THCTensorMath.h │ │ │ ├── THCTensorMathBlas.cu │ │ │ ├── THCTensorMathBlas.h │ │ │ ├── THCTensorMathCompare.cu │ │ │ ├── THCTensorMathCompare.h │ │ │ ├── THCTensorMathCompareT.cu │ │ │ ├── THCTensorMathCompareT.h │ │ │ ├── THCTensorMathMagma.cu │ │ │ ├── THCTensorMathMagma.h │ │ │ ├── THCTensorMathPairwise.cu │ │ │ ├── THCTensorMathPairwise.h │ │ │ ├── THCTensorMathPointwise.cu │ │ │ ├── THCTensorMathPointwise.h │ │ │ ├── THCTensorMathReduce.cu │ │ │ ├── THCTensorMathReduce.h │ │ │ ├── THCTensorMathScan.cu │ │ │ ├── THCTensorMathScan.h │ │ │ ├── THCTensorMode.cu │ │ │ ├── THCTensorMode.h │ │ │ ├── THCTensorRandom.cu │ │ │ ├── THCTensorRandom.h │ │ │ ├── THCTensorScatterGather.cu │ │ │ ├── THCTensorScatterGather.h │ │ │ ├── THCTensorSort.cu │ │ │ ├── THCTensorSort.h │ │ │ ├── THCTensorTopK.cu │ │ │ └── THCTensorTopK.h │ ├── THCS │ │ ├── CMakeLists.txt │ │ ├── THCS.h │ │ ├── THCSGenerateAllTypes.h │ │ ├── THCSGenerateByteType.h │ │ ├── THCSGenerateCharType.h │ │ ├── THCSGenerateDoubleType.h │ │ ├── THCSGenerateFloatType.h │ │ ├── THCSGenerateFloatTypes.h │ │ ├── THCSGenerateHalfType.h │ │ ├── THCSGenerateIntType.h │ │ ├── THCSGenerateLongType.h │ │ ├── THCSGenerateShortType.h │ │ ├── THCSTensor.c │ │ ├── THCSTensor.cu │ │ ├── THCSTensor.h │ │ ├── THCSparse.cu │ │ ├── THCSparse.h │ │ ├── cmake │ │ │ ├── FindMAGMA.cmake │ │ │ └── select_compute_arch.cmake │ │ └── generic │ │ │ ├── THCSTensor.c │ │ │ ├── THCSTensor.cu │ │ │ ├── THCSTensor.h │ │ │ ├── THCSTensorMath.cu │ │ │ └── THCSTensorMath.h │ ├── THCUNN │ │ ├── Abs.cu │ │ ├── AbsCriterion.cu │ │ ├── BCECriterion.cu │ │ ├── BatchNormalization.cu │ │ ├── CMakeLists.txt │ │ ├── ClassNLLCriterion.cu │ │ ├── DistKLDivCriterion.cu │ │ ├── ELU.cu │ │ ├── FusedRNNKernel.cu │ │ ├── GatedLinearUnit.cu │ │ ├── HardTanh.cu │ │ ├── IndexLinear.cu │ │ ├── L1Cost.cu │ │ ├── LeakyReLU.cu │ │ ├── LogSigmoid.cu │ │ ├── LogSoftMax.cu │ │ ├── LookupTable.cu │ │ ├── MSECriterion.cu │ │ ├── MarginCriterion.cu │ │ ├── MultiLabelMarginCriterion.cu │ │ ├── MultiMarginCriterion.cu │ │ ├── PReLU.cu │ │ ├── RReLU.cu │ │ ├── SharedMem.cuh │ │ ├── Sigmoid.cu │ │ ├── SmoothL1Criterion.cu │ │ ├── SoftMarginCriterion.cu │ │ ├── SoftMax.cu │ │ ├── SoftPlus.cu │ │ ├── SoftShrink.cu │ │ ├── SparseLinear.cu │ │ ├── SpatialAdaptiveAveragePooling.cu │ │ ├── SpatialAdaptiveMaxPooling.cu │ │ ├── SpatialAveragePooling.cu │ │ ├── SpatialClassNLLCriterion.cu │ │ ├── SpatialConvolutionLocal.cu │ │ ├── SpatialConvolutionMM.cu │ │ ├── SpatialCrossMapLRN.cu │ │ ├── SpatialDilatedConvolution.cu │ │ ├── SpatialDilatedMaxPooling.cu │ │ ├── SpatialFractionalMaxPooling.cu │ │ ├── SpatialFullConvolution.cu │ │ ├── SpatialMaxPooling.cu │ │ ├── SpatialMaxUnpooling.cu │ │ ├── SpatialReflectionPadding.cu │ │ ├── SpatialReplicationPadding.cu │ │ ├── SpatialSubSampling.cu │ │ ├── SpatialUpSamplingBilinear.cu │ │ ├── SpatialUpSamplingNearest.cu │ │ ├── Sqrt.cu │ │ ├── Square.cu │ │ ├── THCHalfAutoNumerics.cuh │ │ ├── THCUNN.h │ │ ├── Tanh.cu │ │ ├── TemporalConvolution.cu │ │ ├── TemporalMaxPooling.cu │ │ ├── TemporalRowConvolution.cu │ │ ├── Threshold.cu │ │ ├── VolumetricAveragePooling.cu │ │ ├── VolumetricConvolution.cu │ │ ├── VolumetricDilatedConvolution.cu │ │ ├── VolumetricDilatedMaxPooling.cu │ │ ├── VolumetricFractionalMaxPooling.cu │ │ ├── VolumetricFullConvolution.cu │ │ ├── VolumetricMaxPooling.cu │ │ ├── VolumetricMaxUnpooling.cu │ │ ├── VolumetricReplicationPadding.cu │ │ ├── cmake │ │ │ └── select_compute_arch.cmake │ │ ├── common.h │ │ ├── generic │ │ │ ├── Abs.cu │ │ │ ├── AbsCriterion.cu │ │ │ ├── BCECriterion.cu │ │ │ ├── BatchNormalization.cu │ │ │ ├── ClassNLLCriterion.cu │ │ │ ├── DistKLDivCriterion.cu │ │ │ ├── ELU.cu │ │ │ ├── FusedRNNKernel.cu │ │ │ ├── GatedLinearUnit.cu │ │ │ ├── HardTanh.cu │ │ │ ├── IndexLinear.cu │ │ │ ├── L1Cost.cu │ │ │ ├── LeakyReLU.cu │ │ │ ├── LogSigmoid.cu │ │ │ ├── LogSoftMax.cu │ │ │ ├── LookupTable.cu │ │ │ ├── MSECriterion.cu │ │ │ ├── MarginCriterion.cu │ │ │ ├── MultiLabelMarginCriterion.cu │ │ │ ├── MultiMarginCriterion.cu │ │ │ ├── PReLU.cu │ │ │ ├── RReLU.cu │ │ │ ├── Sigmoid.cu │ │ │ ├── SmoothL1Criterion.cu │ │ │ ├── SoftMarginCriterion.cu │ │ │ ├── SoftMax.cu │ │ │ ├── SoftPlus.cu │ │ │ ├── SoftShrink.cu │ │ │ ├── SparseLinear.cu │ │ │ ├── SpatialAdaptiveAveragePooling.cu │ │ │ ├── SpatialAdaptiveMaxPooling.cu │ │ │ ├── SpatialAveragePooling.cu │ │ │ ├── SpatialClassNLLCriterion.cu │ │ │ ├── SpatialConvolutionLocal.cu │ │ │ ├── SpatialConvolutionMM.cu │ │ │ ├── SpatialCrossMapLRN.cu │ │ │ ├── SpatialDilatedConvolution.cu │ │ │ ├── SpatialDilatedMaxPooling.cu │ │ │ ├── SpatialFractionalMaxPooling.cu │ │ │ ├── SpatialFullConvolution.cu │ │ │ ├── SpatialMaxPooling.cu │ │ │ ├── SpatialMaxUnpooling.cu │ │ │ ├── SpatialReflectionPadding.cu │ │ │ ├── SpatialReplicationPadding.cu │ │ │ ├── SpatialSubSampling.cu │ │ │ ├── SpatialUpSamplingBilinear.cu │ │ │ ├── SpatialUpSamplingNearest.cu │ │ │ ├── Sqrt.cu │ │ │ ├── Square.cu │ │ │ ├── THCUNN.h │ │ │ ├── Tanh.cu │ │ │ ├── TemporalConvolution.cu │ │ │ ├── TemporalMaxPooling.cu │ │ │ ├── TemporalRowConvolution.cu │ │ │ ├── Threshold.cu │ │ │ ├── VolumetricAveragePooling.cu │ │ │ ├── VolumetricConvolution.cu │ │ │ ├── VolumetricDilatedConvolution.cu │ │ │ ├── VolumetricDilatedMaxPooling.cu │ │ │ ├── VolumetricFractionalMaxPooling.cu │ │ │ ├── VolumetricFullConvolution.cu │ │ │ ├── VolumetricMaxPooling.cu │ │ │ ├── VolumetricMaxUnpooling.cu │ │ │ └── VolumetricReplicationPadding.cu │ │ ├── im2col.h │ │ ├── row2col.h │ │ └── vol2col.h │ ├── THD │ │ ├── CMakeLists.txt │ │ ├── README.md │ │ ├── THD.h │ │ ├── base │ │ │ ├── ChannelEnvVars.hpp │ │ │ ├── ChannelType.h │ │ │ ├── ChannelUtils.cpp │ │ │ ├── ChannelUtils.hpp │ │ │ ├── DataChannel.cpp │ │ │ ├── DataChannel.h │ │ │ ├── DataChannel.hpp │ │ │ ├── DataChannelRequest.cpp │ │ │ ├── DataChannelRequest.h │ │ │ ├── DataChannelRequest.hpp │ │ │ ├── Scalar.hpp │ │ │ ├── THDGenerateAllTypes.h │ │ │ ├── TensorDescriptor.cpp │ │ │ ├── TensorDescriptor.h │ │ │ ├── TensorDescriptor.hpp │ │ │ └── data_channels │ │ │ │ ├── DataChannelGloo.cpp │ │ │ │ ├── DataChannelGloo.hpp │ │ │ │ ├── DataChannelMPI.cpp │ │ │ │ ├── DataChannelMPI.hpp │ │ │ │ ├── DataChannelTCP.cpp │ │ │ │ ├── DataChannelTCP.hpp │ │ │ │ ├── DataChannelUtils.hpp │ │ │ │ ├── GlooCache.hpp │ │ │ │ ├── Store.cpp │ │ │ │ └── Store.hpp │ │ ├── benchmark │ │ │ ├── benchmark.py │ │ │ └── run_benchmark │ │ ├── build.sh │ │ ├── cmake │ │ │ └── FindGloo.cmake │ │ ├── master_worker │ │ │ ├── common │ │ │ │ ├── ByteArray.cpp │ │ │ │ ├── ByteArray.hpp │ │ │ │ ├── CommandChannel.cpp │ │ │ │ ├── CommandChannel.hpp │ │ │ │ ├── Functions.hpp │ │ │ │ ├── RPC-inl.hpp │ │ │ │ ├── RPC.cpp │ │ │ │ ├── RPC.hpp │ │ │ │ └── Traits.hpp │ │ │ ├── master │ │ │ │ ├── Master.cpp │ │ │ │ ├── Master.h │ │ │ │ ├── Master.hpp │ │ │ │ ├── State.cpp │ │ │ │ ├── State.h │ │ │ │ ├── State.hpp │ │ │ │ ├── THDRandom.cpp │ │ │ │ ├── THDRandom.h │ │ │ │ ├── THDStorage.cpp │ │ │ │ ├── THDStorage.h │ │ │ │ ├── THDTensor.cpp │ │ │ │ ├── THDTensor.h │ │ │ │ ├── Utils.hpp │ │ │ │ └── generic │ │ │ │ │ ├── THDStorage.cpp │ │ │ │ │ ├── THDStorage.h │ │ │ │ │ ├── THDTensor.cpp │ │ │ │ │ ├── THDTensor.h │ │ │ │ │ ├── THDTensorCopy.cpp │ │ │ │ │ ├── THDTensorCopy.h │ │ │ │ │ ├── THDTensorLapack.cpp │ │ │ │ │ ├── THDTensorLapack.h │ │ │ │ │ ├── THDTensorMath.cpp │ │ │ │ │ ├── THDTensorMath.h │ │ │ │ │ ├── THDTensorMeta.cpp │ │ │ │ │ ├── THDTensorRandom.cpp │ │ │ │ │ └── THDTensorRandom.h │ │ │ └── worker │ │ │ │ ├── Dispatch.cpp │ │ │ │ ├── Dispatch.hpp │ │ │ │ ├── Worker.cpp │ │ │ │ ├── Worker.h │ │ │ │ ├── Worker.hpp │ │ │ │ └── dispatch │ │ │ │ ├── Communication.cpp │ │ │ │ ├── Generator.cpp │ │ │ │ ├── Storage.cpp │ │ │ │ ├── Tensor.cpp │ │ │ │ ├── TensorLapack.cpp │ │ │ │ ├── TensorMath.cpp │ │ │ │ └── TensorRandom.cpp │ │ ├── process_group │ │ │ ├── Collectives.cpp │ │ │ ├── Collectives.h │ │ │ ├── Collectives.hpp │ │ │ ├── General.cpp │ │ │ ├── General.h │ │ │ └── General.hpp │ │ └── test │ │ │ ├── TestUtils.hpp │ │ │ ├── command_channel_smoke.cpp │ │ │ ├── data_channel_collectives.cpp │ │ │ ├── data_channel_gloo_cache.cpp │ │ │ ├── data_channel_mpi_smoke.cpp │ │ │ ├── data_channel_tcp_accept_timeout.cpp │ │ │ ├── data_channel_tcp_slow_master.cpp │ │ │ ├── data_channel_tcp_smoke.cpp │ │ │ ├── rpc_serialization.cpp │ │ │ └── tensor_smoke.cpp │ ├── THNN │ │ ├── CMakeLists.txt │ │ ├── README.md │ │ ├── THNN.h │ │ ├── doc │ │ │ ├── api_reference.md │ │ │ ├── generate_reference.lua │ │ │ └── style_guidelines.md │ │ ├── generic │ │ │ ├── Abs.c │ │ │ ├── AbsCriterion.c │ │ │ ├── BCECriterion.c │ │ │ ├── BatchNormalization.c │ │ │ ├── ClassNLLCriterion.c │ │ │ ├── DistKLDivCriterion.c │ │ │ ├── ELU.c │ │ │ ├── FusedRNNKernel.c │ │ │ ├── GatedLinearUnit.c │ │ │ ├── HardShrink.c │ │ │ ├── HardTanh.c │ │ │ ├── IndexLinear.c │ │ │ ├── L1Cost.c │ │ │ ├── LeakyReLU.c │ │ │ ├── Linear.c │ │ │ ├── LogSigmoid.c │ │ │ ├── LogSoftMax.c │ │ │ ├── LookupTable.c │ │ │ ├── MSECriterion.c │ │ │ ├── MarginCriterion.c │ │ │ ├── MultiLabelMarginCriterion.c │ │ │ ├── MultiMarginCriterion.c │ │ │ ├── PReLU.c │ │ │ ├── RReLU.c │ │ │ ├── Sigmoid.c │ │ │ ├── SmoothL1Criterion.c │ │ │ ├── SoftMarginCriterion.c │ │ │ ├── SoftMax.c │ │ │ ├── SoftPlus.c │ │ │ ├── SoftShrink.c │ │ │ ├── SparseLinear.c │ │ │ ├── SpatialAdaptiveAveragePooling.c │ │ │ ├── SpatialAdaptiveMaxPooling.c │ │ │ ├── SpatialAveragePooling.c │ │ │ ├── SpatialClassNLLCriterion.c │ │ │ ├── SpatialConvolutionLocal.c │ │ │ ├── SpatialConvolutionMM.c │ │ │ ├── SpatialConvolutionMap.c │ │ │ ├── SpatialDilatedConvolution.c │ │ │ ├── SpatialDilatedMaxPooling.c │ │ │ ├── SpatialFractionalMaxPooling.c │ │ │ ├── SpatialFullConvolution.c │ │ │ ├── SpatialFullConvolutionMap.c │ │ │ ├── SpatialMaxPooling.c │ │ │ ├── SpatialMaxUnpooling.c │ │ │ ├── SpatialReflectionPadding.c │ │ │ ├── SpatialReplicationPadding.c │ │ │ ├── SpatialSubSampling.c │ │ │ ├── SpatialUpSamplingBilinear.c │ │ │ ├── SpatialUpSamplingNearest.c │ │ │ ├── Sqrt.c │ │ │ ├── Square.c │ │ │ ├── THNN.h │ │ │ ├── Tanh.c │ │ │ ├── TemporalConvolution.c │ │ │ ├── TemporalMaxPooling.c │ │ │ ├── TemporalRowConvolution.c │ │ │ ├── TemporalSubSampling.c │ │ │ ├── Threshold.c │ │ │ ├── VolumetricAveragePooling.c │ │ │ ├── VolumetricConvolution.c │ │ │ ├── VolumetricConvolutionMM.c │ │ │ ├── VolumetricDilatedConvolution.c │ │ │ ├── VolumetricDilatedMaxPooling.c │ │ │ ├── VolumetricFractionalMaxPooling.c │ │ │ ├── VolumetricFullConvolution.c │ │ │ ├── VolumetricMaxPooling.c │ │ │ ├── VolumetricMaxUnpooling.c │ │ │ ├── VolumetricReplicationPadding.c │ │ │ └── unfold.c │ │ └── init.c │ ├── THPP │ │ ├── CMakeLists.txt │ │ ├── Generator.hpp │ │ ├── Storage.hpp │ │ ├── THPP.h │ │ ├── THPPGeneral.h │ │ ├── Tensor.hpp │ │ ├── Traits.cpp │ │ ├── Traits.hpp │ │ ├── TraitsCuda.cpp │ │ ├── TraitsCuda.hpp │ │ ├── Type.hpp │ │ ├── generators │ │ │ ├── THCGenerator.cpp │ │ │ ├── THCGenerator.hpp │ │ │ ├── THGenerator.cpp │ │ │ └── THGenerator.hpp │ │ ├── storages │ │ │ ├── THCStorage.cpp │ │ │ ├── THCStorage.hpp │ │ │ ├── THStorage.cpp │ │ │ ├── THStorage.hpp │ │ │ └── generic │ │ │ │ ├── THCStorage.cpp │ │ │ │ ├── THCStorage.hpp │ │ │ │ ├── THStorage.cpp │ │ │ │ └── THStorage.hpp │ │ └── tensors │ │ │ ├── THCSTensor.cpp │ │ │ ├── THCSTensor.hpp │ │ │ ├── THCTensor.cpp │ │ │ ├── THCTensor.hpp │ │ │ ├── THSTensor.cpp │ │ │ ├── THSTensor.hpp │ │ │ ├── THTensor.cpp │ │ │ ├── THTensor.hpp │ │ │ └── generic │ │ │ ├── THCSTensor.cpp │ │ │ ├── THCSTensor.hpp │ │ │ ├── THCTensor.cpp │ │ │ ├── THCTensor.hpp │ │ │ ├── THSTensor.cpp │ │ │ ├── THSTensor.hpp │ │ │ ├── THTensor.cpp │ │ │ └── THTensor.hpp │ ├── THS │ │ ├── CMakeLists.txt │ │ ├── THS.h │ │ ├── THSGenerateAllTypes.h │ │ ├── THSGenerateFloatTypes.h │ │ ├── THSGenerateIntTypes.h │ │ ├── THSTensor.c │ │ ├── THSTensor.h │ │ └── generic │ │ │ ├── THSTensor.c │ │ │ ├── THSTensor.h │ │ │ ├── THSTensorMath.c │ │ │ └── THSTensorMath.h │ ├── build_all.bat │ ├── build_all.sh │ ├── libshm │ │ ├── CMakeLists.txt │ │ ├── alloc_info.h │ │ ├── core.cpp │ │ ├── err.h │ │ ├── libshm.h │ │ ├── manager.cpp │ │ └── socket.h │ ├── libshm_windows │ │ ├── CMakeLists.txt │ │ ├── core.cpp │ │ ├── err.h │ │ └── libshm.h │ └── nccl │ │ ├── .gitignore │ │ ├── CMakeLists.txt │ │ ├── LICENSE.txt │ │ ├── Makefile │ │ ├── README.md │ │ ├── debian │ │ ├── .gitignore │ │ ├── changelog.in │ │ ├── compat │ │ ├── control.in │ │ ├── copyright │ │ ├── libnccl-dev.install │ │ ├── libnccl-dev.manpages │ │ ├── libnccl1.install.in │ │ ├── nccl.7 │ │ ├── rules │ │ ├── shlibs.local.in │ │ └── source │ │ │ └── format │ │ ├── fortran │ │ ├── Makefile │ │ ├── src │ │ │ ├── cudafor.f90 │ │ │ └── ncclfor.f90 │ │ └── test │ │ │ ├── allgather_arr_out.f90 │ │ │ ├── allgather_ptr_out.f90 │ │ │ ├── allreduce_arr_out.f90 │ │ │ ├── allreduce_ptr_out.f90 │ │ │ ├── broadcast_arr.f90 │ │ │ ├── broadcast_ptr.f90 │ │ │ ├── reduce_arr_out.f90 │ │ │ ├── reduce_ptr_out.f90 │ │ │ ├── reducescatter_arr_out.f90 │ │ │ └── reducescatter_ptr_out.f90 │ │ ├── src │ │ ├── all_gather.cu │ │ ├── all_reduce.cu │ │ ├── broadcast.cu │ │ ├── common_coll.h │ │ ├── common_kernel.h │ │ ├── copy_kernel.h │ │ ├── core.cu │ │ ├── core.h │ │ ├── enqueue.h │ │ ├── libwrap.cu │ │ ├── libwrap.h │ │ ├── nccl.h │ │ ├── primitives.h │ │ ├── reduce.cu │ │ ├── reduce_kernel.h │ │ └── reduce_scatter.cu │ │ └── test │ │ ├── include │ │ └── test_utilities.h │ │ ├── mpi │ │ └── mpi_test.cu │ │ └── single │ │ ├── all_gather_scan.cu │ │ ├── all_gather_test.cu │ │ ├── all_reduce_scan.cu │ │ ├── all_reduce_test.cu │ │ ├── broadcast_scan.cu │ │ ├── broadcast_test.cu │ │ ├── reduce_scan.cu │ │ ├── reduce_scatter_scan.cu │ │ ├── reduce_scatter_test.cu │ │ └── reduce_test.cu ├── multiprocessing │ ├── __init__.py │ ├── pool.py │ ├── queue.py │ └── reductions.py ├── nn │ ├── __init__.py │ ├── _functions │ │ ├── __init__.py │ │ ├── activation.py │ │ ├── conv.py │ │ ├── dropout.py │ │ ├── linear.py │ │ ├── loss.py │ │ ├── padding.py │ │ ├── rnn.py │ │ └── thnn │ │ │ ├── __init__.py │ │ │ ├── activation.py │ │ │ ├── auto.py │ │ │ ├── loss.py │ │ │ ├── normalization.py │ │ │ ├── pooling.py │ │ │ ├── rnnFusedPointwise.py │ │ │ ├── sparse.py │ │ │ └── upsampling.py │ ├── backends │ │ ├── __init__.py │ │ ├── backend.py │ │ └── thnn.py │ ├── functional.py │ ├── init.py │ ├── modules │ │ ├── __init__.py │ │ ├── activation.py │ │ ├── batchnorm.py │ │ ├── container.py │ │ ├── conv.py │ │ ├── distance.py │ │ ├── dropout.py │ │ ├── instancenorm.py │ │ ├── linear.py │ │ ├── loss.py │ │ ├── module.py │ │ ├── normalization.py │ │ ├── padding.py │ │ ├── pixelshuffle.py │ │ ├── pooling.py │ │ ├── rnn.py │ │ ├── sparse.py │ │ ├── upsampling.py │ │ └── utils.py │ ├── parallel │ │ ├── __init__.py │ │ ├── _functions.py │ │ ├── data_parallel.py │ │ ├── parallel_apply.py │ │ ├── replicate.py │ │ └── scatter_gather.py │ ├── parameter.py │ └── utils │ │ ├── __init__.py │ │ ├── clip_grad.py │ │ └── rnn.py ├── optim │ ├── __init__.py │ ├── adadelta.py │ ├── adagrad.py │ ├── adam.py │ ├── adamax.py │ ├── asgd.py │ ├── lbfgs.py │ ├── optimizer.py │ ├── rmsprop.py │ ├── rprop.py │ └── sgd.py ├── serialization.py ├── sparse │ └── __init__.py ├── storage.py ├── tensor.py └── utils │ ├── __init__.py │ ├── data │ ├── __init__.py │ ├── dataloader.py │ ├── dataset.py │ └── sampler.py │ ├── ffi │ └── __init__.py │ ├── hooks.py │ ├── model_zoo.py │ ├── serialization │ ├── __init__.py │ └── read_lua_file.py │ └── trainer │ ├── __init__.py │ ├── plugins │ ├── __init__.py │ ├── accuracy.py │ ├── logger.py │ ├── loss.py │ ├── monitor.py │ ├── plugin.py │ ├── progress.py │ └── time.py │ └── trainer.py └── tox.ini /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | dist/ 3 | torch.egg-info/ 4 | */**/__pycache__ 5 | torch/version.py 6 | torch/csrc/generic/TensorMethods.cpp 7 | torch/lib/*.so* 8 | torch/lib/*.a* 9 | torch/lib/*.dylib* 10 | torch/lib/*.h 11 | torch/lib/*.dll 12 | torch/lib/*.lib 13 | torch/lib/build 14 | torch/lib/tmp_install 15 | torch/lib/include 16 | torch/lib/torch_shm_manager 17 | torch/csrc/cudnn/cuDNN.cpp 18 | torch/csrc/nn/THNN.cwrap 19 | torch/csrc/nn/THNN.cpp 20 | torch/csrc/nn/THCUNN.cwrap 21 | torch/csrc/nn/THCUNN.cpp 22 | torch/csrc/nn/THNN_generic.cwrap 23 | torch/csrc/nn/THNN_generic.cpp 24 | torch/csrc/nn/THNN_generic.h 25 | torch/csrc/generated 26 | docs/src/**/* 27 | test/data/legacy_modules.t7 28 | test/data/gpu_tensors.pt 29 | test/htmlcov 30 | test/.coverage 31 | */*.pyc 32 | */**/*.pyc 33 | */**/**/*.pyc 34 | */**/**/**/*.pyc 35 | */**/**/**/**/*.pyc 36 | */*.so* 37 | */**/*.so* 38 | */**/*.dylib* 39 | test/data/legacy_serialized.pt 40 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=source 11 | set BUILDDIR=build 12 | set SPHINXPROJ=PyTorch 13 | 14 | if "%1" == "" goto help 15 | 16 | %SPHINXBUILD% >NUL 2>NUL 17 | if errorlevel 9009 ( 18 | echo. 19 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 20 | echo.installed, then set the SPHINXBUILD environment variable to point 21 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 22 | echo.may add the Sphinx directory to PATH. 23 | echo. 24 | echo.If you don't have Sphinx installed, grab it from 25 | echo.http://sphinx-doc.org/ 26 | exit /b 1 27 | ) 28 | 29 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% 30 | goto end 31 | 32 | :help 33 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% 34 | 35 | :end 36 | popd 37 | -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | sphinx 2 | -e git://github.com/snide/sphinx_rtd_theme.git#egg=sphinx_rtd_theme 3 | -------------------------------------------------------------------------------- /docs/source/_static/img/dynamic_graph.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tylergenter/pytorch/42459c2544bc6c2e37c3459caaeca7c9eb1a8906/docs/source/_static/img/dynamic_graph.gif -------------------------------------------------------------------------------- /docs/source/_static/img/pytorch-logo-dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tylergenter/pytorch/42459c2544bc6c2e37c3459caaeca7c9eb1a8906/docs/source/_static/img/pytorch-logo-dark.png -------------------------------------------------------------------------------- /docs/source/_static/img/pytorch-logo-flame.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tylergenter/pytorch/42459c2544bc6c2e37c3459caaeca7c9eb1a8906/docs/source/_static/img/pytorch-logo-flame.png -------------------------------------------------------------------------------- /docs/source/_static/img/tensor_illustration.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tylergenter/pytorch/42459c2544bc6c2e37c3459caaeca7c9eb1a8906/docs/source/_static/img/tensor_illustration.png -------------------------------------------------------------------------------- /docs/source/cuda.rst: -------------------------------------------------------------------------------- 1 | torch.cuda 2 | =================================== 3 | 4 | .. currentmodule:: torch.cuda 5 | 6 | .. automodule:: torch.cuda 7 | :members: 8 | 9 | Communication collectives 10 | ------------------------- 11 | 12 | .. autofunction:: torch.cuda.comm.broadcast 13 | 14 | .. autofunction:: torch.cuda.comm.reduce_add 15 | 16 | .. autofunction:: torch.cuda.comm.scatter 17 | 18 | .. autofunction:: torch.cuda.comm.gather 19 | 20 | Streams and events 21 | ------------------ 22 | 23 | .. autoclass:: Stream 24 | :members: 25 | 26 | .. autoclass:: Event 27 | :members: 28 | -------------------------------------------------------------------------------- /docs/source/data.rst: -------------------------------------------------------------------------------- 1 | torch.utils.data 2 | =================================== 3 | 4 | .. automodule:: torch.utils.data 5 | .. autoclass:: Dataset 6 | .. autoclass:: TensorDataset 7 | .. autoclass:: DataLoader 8 | .. autoclass:: torch.utils.data.sampler.Sampler 9 | .. autoclass:: torch.utils.data.sampler.SequentialSampler 10 | .. autoclass:: torch.utils.data.sampler.RandomSampler 11 | .. autoclass:: torch.utils.data.sampler.SubsetRandomSampler 12 | .. autoclass:: torch.utils.data.sampler.WeightedRandomSampler 13 | -------------------------------------------------------------------------------- /docs/source/ffi.rst: -------------------------------------------------------------------------------- 1 | torch.utils.ffi 2 | =============== 3 | 4 | .. currentmodule:: torch.utils.ffi 5 | .. autofunction:: create_extension 6 | 7 | -------------------------------------------------------------------------------- /docs/source/legacy.rst: -------------------------------------------------------------------------------- 1 | Legacy package - torch.legacy 2 | =================================== 3 | 4 | .. automodule:: torch.legacy 5 | -------------------------------------------------------------------------------- /docs/source/model_zoo.rst: -------------------------------------------------------------------------------- 1 | torch.utils.model_zoo 2 | =================================== 3 | 4 | .. automodule:: torch.utils.model_zoo 5 | .. autofunction:: load_url 6 | -------------------------------------------------------------------------------- /docs/source/notes/serialization.rst: -------------------------------------------------------------------------------- 1 | 2 | Serialization semantics 3 | ======================= 4 | 5 | Best practices 6 | -------------- 7 | 8 | .. _recommend-saving-models: 9 | 10 | Recommended approach for saving a model 11 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12 | 13 | There are two main approaches for serializing and restoring a model. 14 | 15 | The first (recommended) saves and loads only the model parameters:: 16 | 17 | torch.save(the_model.state_dict(), PATH) 18 | 19 | Then later:: 20 | 21 | the_model = TheModelClass(*args, **kwargs) 22 | the_model.load_state_dict(torch.load(PATH)) 23 | 24 | The second saves and loads the entire model:: 25 | 26 | torch.save(the_model, PATH) 27 | 28 | Then later:: 29 | 30 | the_model = torch.load(PATH) 31 | 32 | However in this case, the serialized data is bound to the specific classes 33 | and the exact directory structure used, so it can break in various ways when 34 | used in other projects, or after some serious refactors. 35 | -------------------------------------------------------------------------------- /docs/source/storage.rst: -------------------------------------------------------------------------------- 1 | torch.Storage 2 | =================================== 3 | 4 | A :class:`torch.Storage` is a contiguous, one-dimensional array of a single 5 | data type. 6 | 7 | Every :class:`torch.Tensor` has a corresponding storage of the same data type. 8 | 9 | .. autoclass:: torch.FloatStorage 10 | :members: 11 | :undoc-members: 12 | :inherited-members: 13 | -------------------------------------------------------------------------------- /docs/source/torchvision/models.rst: -------------------------------------------------------------------------------- 1 | torchvision.models 2 | =================== 3 | 4 | .. currentmodule:: torchvision.models 5 | 6 | 7 | .. automodule:: torchvision.models 8 | :members: alexnet, resnet18, resnet34, resnet50, resnet101, resnet152, 9 | vgg11, vgg11_bn, vgg13, vgg13_bn, vgg16, vgg16_bn, vgg19, 10 | vgg19_bn 11 | :undoc-members: 12 | -------------------------------------------------------------------------------- /docs/source/torchvision/torchvision.rst: -------------------------------------------------------------------------------- 1 | torchvision 2 | =================== 3 | 4 | The :mod:`torchvision` package consists of popular datasets, model 5 | architectures, and common image transformations for computer vision. 6 | 7 | .. automodule:: torchvision 8 | :members: 9 | -------------------------------------------------------------------------------- /docs/source/torchvision/transforms.rst: -------------------------------------------------------------------------------- 1 | torchvision.transforms 2 | ====================== 3 | 4 | .. currentmodule:: torchvision.transforms 5 | 6 | .. autoclass:: Compose 7 | 8 | Transforms on PIL.Image 9 | ----------------------- 10 | 11 | .. autoclass:: Scale 12 | 13 | .. autoclass:: CenterCrop 14 | 15 | .. autoclass:: RandomCrop 16 | 17 | .. autoclass:: RandomHorizontalFlip 18 | 19 | .. autoclass:: RandomSizedCrop 20 | 21 | .. autoclass:: Pad 22 | 23 | Transforms on torch.\*Tensor 24 | ---------------------------- 25 | 26 | .. autoclass:: Normalize 27 | 28 | 29 | Conversion Transforms 30 | --------------------- 31 | 32 | .. autoclass:: ToTensor 33 | 34 | .. autoclass:: ToPILImage 35 | 36 | Generic Transforms 37 | ------------------ 38 | 39 | .. autoclass:: Lambda 40 | 41 | -------------------------------------------------------------------------------- /docs/source/torchvision/utils.rst: -------------------------------------------------------------------------------- 1 | torchvision.utils 2 | =================== 3 | 4 | .. currentmodule:: torchvision.utils 5 | 6 | .. autofunction:: make_grid 7 | 8 | .. autofunction:: save_image 9 | 10 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pyyaml 2 | -------------------------------------------------------------------------------- /test/data/network1.py: -------------------------------------------------------------------------------- 1 | import torch.nn as nn 2 | 3 | 4 | class Net(nn.Module): 5 | 6 | def __init__(self): 7 | super(Net, self).__init__() 8 | self.linear = nn.Linear(10, 20) 9 | -------------------------------------------------------------------------------- /test/data/network2.py: -------------------------------------------------------------------------------- 1 | import torch.nn as nn 2 | 3 | 4 | class Net(nn.Module): 5 | 6 | def __init__(self): 7 | super(Net, self).__init__() 8 | self.linear = nn.Linear(10, 20) 9 | self.relu = nn.ReLU() 10 | -------------------------------------------------------------------------------- /test/ffi/src/cpu/lib.h: -------------------------------------------------------------------------------- 1 | 2 | void good_func(THFloatTensor *tensor, int a, float b); 3 | void bad_func(THFloatTensor *tensor, int a, float b); 4 | THFloatTensor * new_tensor(int a); 5 | float int_to_float(int a); 6 | 7 | -------------------------------------------------------------------------------- /test/ffi/src/cpu/lib1.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void good_func(THFloatTensor *tensor, int a, float b) 4 | { 5 | THFloatTensor_mul(tensor, tensor, a); 6 | THFloatTensor_add(tensor, tensor, b); 7 | } 8 | 9 | THFloatTensor * new_tensor(int a) 10 | { 11 | THFloatTensor *t = THFloatTensor_newWithSize2d(a, a); 12 | THFloatTensor_fill(t, a); 13 | return t; 14 | } 15 | 16 | float int_to_float(int a) 17 | { 18 | return a; 19 | } 20 | -------------------------------------------------------------------------------- /test/ffi/src/cpu/lib2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void bad_func(THFloatTensor *tensor, int a, float b) 4 | { 5 | THFloatTensor_mul(tensor, tensor, a); 6 | THFloatTensor_add(tensor, tensor, b); 7 | THFloatTensor_addbmm(tensor, 1, tensor, 1, tensor, tensor); 8 | } 9 | -------------------------------------------------------------------------------- /test/ffi/src/cuda/cudalib.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | extern THCState *state; 5 | 6 | #include "../cpu/lib1.c" 7 | 8 | void cuda_func(THCudaTensor *tensor, int a, float b) 9 | { 10 | THCudaTensor_mul(state, tensor, tensor, a); 11 | THCudaTensor_add(state, tensor, tensor, b); 12 | } 13 | -------------------------------------------------------------------------------- /test/ffi/src/cuda/cudalib.h: -------------------------------------------------------------------------------- 1 | 2 | void good_func(THFloatTensor *tensor, int a, float b); 3 | void cuda_func(THCudaTensor *tensor, int a, float b); 4 | THFloatTensor * new_tensor(int a); 5 | float int_to_float(int a); 6 | -------------------------------------------------------------------------------- /test/ffi/src/lib.h: -------------------------------------------------------------------------------- 1 | 2 | void my_func(THFloatTensor *tensor, int a, float b); 3 | void my_cuda_func(THCudaTensor *tensor, int a, float b); 4 | THFloatTensor * new_t(int a); 5 | float new_int(int a); 6 | -------------------------------------------------------------------------------- /test/optim/compare.sh: -------------------------------------------------------------------------------- 1 | 2 | th test.lua > lua.out 3 | python3 test.py > python.out 4 | 5 | diff lua.out python.out >/dev/null 2>&1 6 | RESULT=$? 7 | if [[ RESULT -eq 0 ]]; then 8 | echo "PASS" 9 | else 10 | echo "FAIL" 11 | echo "Press ENTER to open vimdiff" 12 | read 13 | vimdiff lua.out python.out 14 | fi 15 | -------------------------------------------------------------------------------- /test/run_test.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | echo Running torch tests 4 | %PYCMD% test_torch.py 5 | 6 | echo Running autograd tests 7 | %PYCMD% test_autograd.py 8 | 9 | echo Running sparse tests 10 | %PYCMD% test_sparse.py 11 | 12 | echo Running nn tests 13 | %PYCMD% test_nn.py 14 | 15 | echo Running legacy nn tests 16 | %PYCMD% test_legacy_nn.py 17 | 18 | echo Running optim tests 19 | %PYCMD% test_optim.py 20 | 21 | echo Running multiprocessing tests 22 | set MULTIPROCESSING_METHOD="" 23 | %PYCMD% test_multiprocessing.py 24 | set MULTIPROCESSING_METHOD=spawn 25 | %PYCMD% test_multiprocessing.py 26 | set MULTIPROCESSING_METHOD=forkserver 27 | %PYCMD% test_multiprocessing.py 28 | 29 | echo Running util tests 30 | %PYCMD% test_utils.py 31 | 32 | echo Running dataloader tests 33 | %PYCMD% test_dataloader.py 34 | 35 | echo Running cuda tests 36 | %PYCMD% test_cuda.py 37 | 38 | echo Running NCCL tests 39 | %PYCMD% test_nccl.py 40 | 41 | -------------------------------------------------------------------------------- /tools/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tylergenter/pytorch/42459c2544bc6c2e37c3459caaeca7c9eb1a8906/tools/__init__.py -------------------------------------------------------------------------------- /tools/cwrap/__init__.py: -------------------------------------------------------------------------------- 1 | from .cwrap import cwrap 2 | -------------------------------------------------------------------------------- /tools/cwrap/plugins/ArgcountChecker.py: -------------------------------------------------------------------------------- 1 | from . import CWrapPlugin 2 | 3 | 4 | class ArgcountChecker(CWrapPlugin): 5 | 6 | def process_all_checks(self, checks, option): 7 | if not checks: 8 | checks = '__argcount == 0' 9 | else: 10 | indent = '\n ' 11 | argcount = option['num_checked_args'] + option.get('argcount_offset', 0) 12 | checks = '__argcount == {} &&'.format(str(argcount)) + indent + checks 13 | return checks 14 | -------------------------------------------------------------------------------- /tools/cwrap/plugins/ArgcountSortPlugin.py: -------------------------------------------------------------------------------- 1 | from . import CWrapPlugin 2 | 3 | 4 | class ArgcountSortPlugin(CWrapPlugin): 5 | 6 | def __init__(self, descending=True): 7 | self.descending = descending 8 | 9 | def process_declarations(self, declarations): 10 | def num_checked_args(option): 11 | return sum(map(lambda a: not a.get('ignore_check', False), option['arguments'])) 12 | for declaration in declarations: 13 | declaration['options'].sort(key=num_checked_args, reverse=self.descending) 14 | return declarations 15 | -------------------------------------------------------------------------------- /tools/cwrap/plugins/AutoGPU.py: -------------------------------------------------------------------------------- 1 | from . import CWrapPlugin 2 | 3 | 4 | class AutoGPU(CWrapPlugin): 5 | 6 | def __init__(self, has_self=True, condition=None): 7 | self.has_self = has_self 8 | self.condition = condition 9 | 10 | DEFINES = """ 11 | #ifdef THC_GENERIC_FILE 12 | #define THCP_AUTO_GPU 1 13 | #else 14 | #define THCP_AUTO_GPU 0 15 | #endif 16 | """ 17 | 18 | def process_pre_arg_assign(self, template, option): 19 | if not option.get('auto_gpu', True): 20 | return template 21 | call = 'THCPAutoGPU __autogpu_guard = THCPAutoGPU(args{});'.format( 22 | ', (PyObject*)self' if self.has_self else '') 23 | 24 | if self.condition is not None: 25 | call = "#if {0}\n {1}\n#endif\n".format(self.condition, call) 26 | 27 | return [call] + template 28 | 29 | def process_full_file(self, code): 30 | return self.DEFINES + code 31 | -------------------------------------------------------------------------------- /tools/cwrap/plugins/ConstantArguments.py: -------------------------------------------------------------------------------- 1 | from . import CWrapPlugin 2 | from string import Template 3 | 4 | 5 | class ConstantArguments(CWrapPlugin): 6 | 7 | def process_declarations(self, declarations): 8 | for declaration in declarations: 9 | for option in declaration['options']: 10 | for arg in option['arguments']: 11 | if arg['type'] == 'CONSTANT': 12 | arg['ignore_check'] = True 13 | return declarations 14 | 15 | def get_type_unpack(self, arg, option): 16 | if arg['type'] == 'CONSTANT': 17 | return Template('$arg') 18 | 19 | def get_arg_accessor(self, arg, option): 20 | if arg['type'] == 'CONSTANT': 21 | return arg['name'] 22 | -------------------------------------------------------------------------------- /tools/cwrap/plugins/GILRelease.py: -------------------------------------------------------------------------------- 1 | from . import CWrapPlugin 2 | from string import Template 3 | 4 | 5 | class GILRelease(CWrapPlugin): 6 | 7 | OPTION_START = [ 8 | 'PyThreadState *_save = NULL;', 9 | 'try {', 10 | ] 11 | 12 | BEFORE_CALL = 'Py_UNBLOCK_THREADS;' 13 | 14 | AFTER_CALL = 'Py_BLOCK_THREADS;' 15 | 16 | OPTION_END = [ 17 | '} catch (...) {', 18 | 'if (_save) {', 19 | 'Py_BLOCK_THREADS;', 20 | '}', 21 | 'throw;', 22 | '}', 23 | ] 24 | 25 | def process_option_code_template(self, template, option): 26 | call_idx = template.index('$call') 27 | template.insert(call_idx, self.BEFORE_CALL) 28 | template.insert(call_idx + 2, self.AFTER_CALL) 29 | return self.OPTION_START + template + self.OPTION_END 30 | -------------------------------------------------------------------------------- /tools/cwrap/plugins/NullableArguments.py: -------------------------------------------------------------------------------- 1 | from . import CWrapPlugin 2 | 3 | 4 | class NullableArguments(CWrapPlugin): 5 | 6 | def process_single_check(self, code, arg, arg_accessor): 7 | if 'nullable' in arg and arg['nullable']: 8 | return '({} || {} == Py_None)'.format(code, arg_accessor) 9 | return code 10 | 11 | def process_single_unpack(self, code, arg, arg_accessor): 12 | if 'nullable' in arg and arg['nullable']: 13 | return '({} == Py_None ? NULL : {})'.format(arg_accessor, code) 14 | return code 15 | -------------------------------------------------------------------------------- /tools/cwrap/plugins/templates/module_tail.cpp: -------------------------------------------------------------------------------- 1 | 2 | #if PY_MAJOR_VERSION != 2 3 | static struct PyModuleDef module_def = { 4 | PyModuleDef_HEAD_INIT, 5 | "$full_name", 6 | NULL, 7 | -1, 8 | module_methods 9 | }; 10 | #endif 11 | 12 | #if PY_MAJOR_VERSION == 2 13 | PyMODINIT_FUNC init$short_name() 14 | #else 15 | PyMODINIT_FUNC PyInit_$short_name() 16 | #endif 17 | { 18 | #if PY_MAJOR_VERSION == 2 19 | #define ASSERT_TRUE(cmd) if (!(cmd)) {PyErr_SetString(PyExc_ImportError, "initialization error"); return;} 20 | #else 21 | #define ASSERT_TRUE(cmd) if (!(cmd)) return NULL 22 | #endif 23 | PyObject *module; 24 | 25 | #if PY_MAJOR_VERSION == 2 26 | ASSERT_TRUE(module = Py_InitModule("$full_name", module_methods)); 27 | #else 28 | ASSERT_TRUE(module = PyModule_Create(&module_def)); 29 | #endif 30 | 31 | #if PY_MAJOR_VERSION != 2 32 | return module; 33 | #endif 34 | 35 | #undef ASSERT_TRUE 36 | } 37 | -------------------------------------------------------------------------------- /tools/nnwrap/__init__.py: -------------------------------------------------------------------------------- 1 | from .generate_wrappers import generate_wrappers, wrap_function, \ 2 | import_module, wrap_generic_function 3 | -------------------------------------------------------------------------------- /tools/setup_helpers/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tylergenter/pytorch/42459c2544bc6c2e37c3459caaeca7c9eb1a8906/tools/setup_helpers/__init__.py -------------------------------------------------------------------------------- /tools/setup_helpers/cuda.py: -------------------------------------------------------------------------------- 1 | import ctypes.util 2 | import os 3 | import platform 4 | 5 | from .env import check_env_flag 6 | 7 | if check_env_flag('NO_CUDA'): 8 | WITH_CUDA = False 9 | CUDA_HOME = None 10 | else: 11 | if platform.system() == 'Windows': 12 | CUDA_HOME = os.getenv('CUDA_PATH', 'C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0').replace('\\','/') 13 | 14 | else: 15 | CUDA_HOME = os.getenv('CUDA_HOME', '/usr/local/cuda') 16 | if not os.path.exists(CUDA_HOME): 17 | cudart_path = ctypes.util.find_library('cudart') 18 | if cudart_path is not None: 19 | CUDA_HOME = os.path.dirname(cudart_path) 20 | else: 21 | CUDA_HOME = None 22 | WITH_CUDA = CUDA_HOME is not None 23 | -------------------------------------------------------------------------------- /tools/setup_helpers/env.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | 4 | def check_env_flag(name): 5 | return os.getenv(name) in ['ON', '1', 'YES', 'TRUE', 'Y'] 6 | -------------------------------------------------------------------------------- /torch/autograd/_functions/__init__.py: -------------------------------------------------------------------------------- 1 | from .basic_ops import * 2 | from .tensor import * 3 | from .pointwise import * 4 | from .reduce import * 5 | from .linalg import * 6 | from .blas import * 7 | from .stochastic import * 8 | from .compare import * 9 | -------------------------------------------------------------------------------- /torch/autograd/_functions/compare.py: -------------------------------------------------------------------------------- 1 | import torch 2 | 3 | from ..function import Function 4 | 5 | 6 | class _CompareOp(Function): 7 | 8 | def __init__(self, scalar=None): 9 | super(_CompareOp, self).__init__() 10 | self.scalar = scalar 11 | 12 | def forward(self, tensor1, tensor2=None): 13 | other = tensor2 if tensor2 is not None else self.scalar 14 | mask = getattr(tensor1, self.fn_name)(other) 15 | self.mark_non_differentiable(mask) 16 | return mask 17 | 18 | 19 | class Eq(_CompareOp): 20 | fn_name = 'eq' 21 | 22 | 23 | class Ne(_CompareOp): 24 | fn_name = 'ne' 25 | 26 | 27 | class Gt(_CompareOp): 28 | fn_name = 'gt' 29 | 30 | 31 | class Ge(_CompareOp): 32 | fn_name = 'ge' 33 | 34 | 35 | class Lt(_CompareOp): 36 | fn_name = 'lt' 37 | 38 | 39 | class Le(_CompareOp): 40 | fn_name = 'le' 41 | -------------------------------------------------------------------------------- /torch/autograd/_functions/replace.vim: -------------------------------------------------------------------------------- 1 | %s/self/ctx/g 2 | %s/\s\+def forward/ @staticmethod\r def forward/g 3 | %s/\s\+def backward/ @staticmethod\r @once_differentiable\r def backward/g 4 | -------------------------------------------------------------------------------- /torch/backends/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tylergenter/pytorch/42459c2544bc6c2e37c3459caaeca7c9eb1a8906/torch/backends/__init__.py -------------------------------------------------------------------------------- /torch/csrc/DynamicTypes.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Provides conversions between Python tensor objects and thpp::Tensors. 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | namespace torch { 10 | 11 | // Register a PyTypeObject* with the given attributes 12 | void registerPyTypeObject( 13 | PyTypeObject *pytype, const std::string& name, 14 | bool is_cuda, bool is_sparse); 15 | 16 | // Gets the PyTypeObject* corresponding to the Tensor 17 | PyTypeObject* getPyTypeObject(const thpp::Tensor& tensor); 18 | 19 | // Creates a Tensor from a Python tensor object 20 | std::unique_ptr createTensor(PyObject *data); 21 | 22 | // Creates Python tensor object from a Tensor 23 | PyObject* createPyObject(const thpp::Tensor& tensor); 24 | 25 | } // namespace torch 26 | -------------------------------------------------------------------------------- /torch/csrc/Exceptions.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "THP.h" 4 | 5 | PyObject *THPException_FatalError; 6 | 7 | #define ASSERT_TRUE(cond) if (!(cond)) return false 8 | bool THPException_init(PyObject *module) 9 | { 10 | ASSERT_TRUE(THPException_FatalError = PyErr_NewException("torch.FatalError", NULL, NULL)); 11 | ASSERT_TRUE(PyModule_AddObject(module, "FatalError", THPException_FatalError) == 0); 12 | return true; 13 | } 14 | -------------------------------------------------------------------------------- /torch/csrc/Generator.h: -------------------------------------------------------------------------------- 1 | #ifndef THP_GENERATOR_H 2 | #define THP_GENERATOR_H 3 | 4 | struct THPGenerator { 5 | PyObject_HEAD 6 | THGenerator *cdata; 7 | }; 8 | 9 | #define THPGenerator_Check(obj) \ 10 | PyObject_IsInstance(obj, THPGeneratorClass) 11 | 12 | #define THPGenerator_CData(obj) \ 13 | ((THPGenerator*)obj)->cdata 14 | 15 | THP_API PyObject * THPGenerator_New(); 16 | THP_API PyObject *THPGeneratorClass; 17 | 18 | #ifdef _THP_CORE 19 | bool THPGenerator_init(PyObject *module); 20 | #endif 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /torch/csrc/Module.h: -------------------------------------------------------------------------------- 1 | #ifndef THP_MODULE_INC 2 | #define THP_MODULE_INC 3 | 4 | #define THP_STATELESS_ATTRIBUTE_NAME "_torch" 5 | 6 | extern PyObject *THPDefaultTensorClass; 7 | extern THPGenerator *THPDefaultGenerator; 8 | 9 | #ifdef _THP_CORE 10 | bool THPModule_isTensor(PyObject *obj); 11 | #endif 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /torch/csrc/PtrWrapper.h: -------------------------------------------------------------------------------- 1 | #ifndef THP_PTR_WRAPPER_H 2 | #define THP_PTR_WRAPPER_H 3 | 4 | #include 5 | #include 6 | 7 | /** 8 | * Python wrapper around arbitrary opaque C++ class 9 | */ 10 | 11 | bool THPWrapper_init(PyObject *module); 12 | 13 | PyObject * THPWrapper_New(void *data, void (*destructor)(void*)); 14 | void * THPWrapper_get(PyObject * obj); 15 | bool THPWrapper_check(PyObject * obj); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /torch/csrc/Size.h: -------------------------------------------------------------------------------- 1 | #ifndef THP_SIZE_INC 2 | #define THP_SIZE_INC 3 | 4 | #include 5 | #include "THP.h" 6 | 7 | extern PyObject *THPSizeClass; 8 | 9 | #define THPSize_Check(obj) ((PyObject*)Py_TYPE(obj) == THPSizeClass) 10 | 11 | PyObject * THPSize_New(int dim, int64_t *sizes); 12 | 13 | #ifdef _THP_CORE 14 | bool THPSize_init(PyObject *module); 15 | #endif 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /torch/csrc/Storage.cpp: -------------------------------------------------------------------------------- 1 | #ifdef _MSC_VER 2 | #include 3 | #endif 4 | #include 5 | #include 6 | 7 | #define THP_HOST_HALF 8 | 9 | #include 10 | #include 11 | #include 12 | #include "THP.h" 13 | #include "copy_utils.h" 14 | 15 | #include "generic/Storage.cpp" 16 | #include 17 | 18 | #include "generic/Storage.cpp" 19 | #include 20 | -------------------------------------------------------------------------------- /torch/csrc/THP_API.h: -------------------------------------------------------------------------------- 1 | #ifndef THP_API_H 2 | #define THP_API_H 3 | 4 | #ifdef _THP_CORE 5 | #error Using the THP API header, but _THP_CORE is defined! This macro should \ 6 | be defined only when compiling the core torch package. 7 | #endif 8 | 9 | #ifdef WITH_CUDA 10 | #include "cuda/THCP.h" 11 | #include "cuda/undef_macros.h" 12 | #endif 13 | 14 | #include "THP.h" 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /torch/csrc/Tensor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define THP_HOST_HALF 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "torch/csrc/THP.h" 13 | #include "torch/csrc/copy_utils.h" 14 | #include "torch/csrc/DynamicTypes.h" 15 | 16 | //generic_include TH torch/csrc/generic/Tensor.cpp 17 | -------------------------------------------------------------------------------- /torch/csrc/Types.h: -------------------------------------------------------------------------------- 1 | #ifndef THP_TYPES_INC 2 | #define THP_TYPES_INC 3 | 4 | #include 5 | #include 6 | 7 | template struct THPTypeInfo {}; 8 | 9 | namespace torch { 10 | 11 | typedef struct THVoidStorage 12 | { 13 | void *data; 14 | ptrdiff_t size; 15 | int refcount; 16 | char flag; 17 | void *allocator; 18 | void *allocatorContext; 19 | THVoidStorage *view; 20 | } THVoidStorage; 21 | 22 | typedef struct THVoidTensor 23 | { 24 | long *size; 25 | long *stride; 26 | int nDimension; 27 | THVoidStorage *storage; 28 | ptrdiff_t storageOffset; 29 | int refcount; 30 | char flag; 31 | } THVoidTensor; 32 | 33 | struct THPVoidTensor { 34 | PyObject_HEAD 35 | THVoidTensor *cdata; 36 | char device_type; 37 | char data_type; 38 | }; 39 | 40 | } // namespace torch 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /torch/csrc/autograd/autograd.h: -------------------------------------------------------------------------------- 1 | #ifndef THP_AUTOGRAD_H 2 | #define THP_AUTOGRAD_H 3 | 4 | PyObject * THPAutograd_initExtension(PyObject *_unused); 5 | bool THPAutograd_initFunctions(PyObject* module); 6 | 7 | #include "torch/csrc/autograd/python_function.h" 8 | #include "torch/csrc/autograd/python_variable.h" 9 | #include "torch/csrc/autograd/python_engine.h" 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /torch/csrc/autograd/function_hook.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | // A hook that's called on gradients 7 | 8 | namespace torch { namespace autograd { 9 | 10 | struct Variable; 11 | using variable_list = std::vector>; 12 | 13 | struct FunctionPreHook { 14 | virtual variable_list operator()(const variable_list& grads) = 0; 15 | }; 16 | 17 | struct FunctionPostHook { 18 | virtual variable_list operator()(const variable_list& grad_input, const variable_list& grad_output) = 0; 19 | }; 20 | 21 | }} // namespace torch::autograd 22 | -------------------------------------------------------------------------------- /torch/csrc/autograd/functions/accumulate_grad.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "torch/csrc/autograd/function.h" 7 | #include "torch/csrc/autograd/variable.h" 8 | 9 | namespace torch { namespace autograd { 10 | 11 | struct AccumulateGrad : public Function { 12 | AccumulateGrad(std::shared_ptr variable); 13 | 14 | virtual variable_list apply(const variable_list& inputs) override; 15 | void acc_inplace(std::shared_ptr& grad, 16 | std::shared_ptr& new_grad); 17 | 18 | std::weak_ptr variable; 19 | std::weak_ptr variable_grad; 20 | }; 21 | 22 | }} 23 | 24 | 25 | -------------------------------------------------------------------------------- /torch/csrc/autograd/functions/tensor.cpp: -------------------------------------------------------------------------------- 1 | #include "tensor.h" 2 | 3 | #include "torch/csrc/autograd/variable.h" 4 | #include "torch/csrc/autograd/functions/utils.h" 5 | #include "torch/csrc/utils/auto_gpu.h" 6 | 7 | namespace torch { namespace autograd { 8 | 9 | auto Identity::apply(const variable_list& inputs) -> variable_list { 10 | return inputs; 11 | }; 12 | 13 | auto Clone::apply(const variable_list& inputs) -> variable_list { 14 | if (inputs.size() != 1) throw std::runtime_error("Clone expects exactly 1 input"); 15 | auto& input = inputs[0]->data; 16 | AutoGPU guard(input->getDevice()); 17 | 18 | std::unique_ptr output {input->clone()}; 19 | 20 | return wrap_outputs(inputs, as_tensor_list(std::move(output)), [&](FunctionFlags f) { 21 | return std::make_shared(std::move(f)); 22 | }); 23 | }; 24 | 25 | }} // namespace torch::autograd 26 | 27 | 28 | -------------------------------------------------------------------------------- /torch/csrc/autograd/functions/tensor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "torch/csrc/autograd/function.h" 7 | #include "torch/csrc/autograd/variable.h" 8 | 9 | namespace torch { namespace autograd { 10 | 11 | struct Identity : public Function { 12 | Identity(FunctionFlags&& f) 13 | : Function(std::move(f)) {}; 14 | 15 | virtual variable_list apply(const variable_list& inputs) override; 16 | }; 17 | 18 | struct Clone : public Function { 19 | Clone() {} 20 | 21 | virtual variable_list apply(const variable_list& inputs) override; 22 | }; 23 | 24 | }} 25 | 26 | 27 | -------------------------------------------------------------------------------- /torch/csrc/autograd/functions/utils.cpp: -------------------------------------------------------------------------------- 1 | #include "torch/csrc/autograd/functions/utils.h" 2 | 3 | namespace torch { namespace autograd { 4 | 5 | variable_list wrap_outputs(const variable_list& inputs, tensor_list&& outputs, 6 | function_constructor ctr) { 7 | auto flags = Function::flags(inputs); 8 | variable_list result; 9 | result.reserve(outputs.size()); 10 | if (flags.is_volatile) { 11 | for (auto& output : outputs) { 12 | result.emplace_back(Variable::of(std::move(output), true)); 13 | } 14 | } else { 15 | auto grad_fn = ctr(std::move(flags)); 16 | for (auto& output : outputs) { 17 | if (output) { 18 | result.emplace_back(std::make_shared(std::move(output), grad_fn)); 19 | } else { 20 | result.emplace_back(nullptr); 21 | } 22 | } 23 | } 24 | return result; 25 | } 26 | 27 | }} 28 | -------------------------------------------------------------------------------- /torch/csrc/autograd/python_engine.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | bool THPEngine_initModule(PyObject *module); 6 | -------------------------------------------------------------------------------- /torch/csrc/autograd/python_hook.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "torch/csrc/autograd/function_hook.h" 4 | #include "torch/csrc/utils/object_ptr.h" 5 | #include 6 | 7 | namespace torch { namespace autograd { 8 | 9 | struct PyFunctionPreHook : public FunctionPreHook { 10 | PyFunctionPreHook(PyObject* dict, int value_idx); 11 | ~PyFunctionPreHook(); 12 | variable_list operator()(const variable_list& values) override; 13 | PyObject* dict; 14 | int value_idx; 15 | }; 16 | 17 | struct PyFunctionPostHook : public FunctionPostHook { 18 | PyFunctionPostHook(PyObject* dict); 19 | ~PyFunctionPostHook(); 20 | variable_list operator()(const variable_list& outputs, const variable_list& inputs) override; 21 | PyObject* dict; 22 | }; 23 | 24 | }} // namespace torch::autograd 25 | -------------------------------------------------------------------------------- /torch/csrc/autograd/python_variable.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "torch/csrc/autograd/variable.h" 7 | 8 | struct THPVariable { 9 | PyObject_HEAD 10 | std::shared_ptr cdata; 11 | PyObject* data; 12 | PyObject* backward_hooks; 13 | }; 14 | 15 | extern PyObject *THPVariableClass; 16 | 17 | bool THPVariable_initModule(PyObject *module); 18 | PyObject * THPVariable_NewVolatile(PyObject *data); 19 | PyObject * THPVariable_NewLeaf(PyObject *data); 20 | PyObject * THPVariable_New(PyObject *data, PyObject *grad_fn); 21 | PyObject * THPVariable_Wrap(const std::shared_ptr& var); 22 | PyObject * THPVariable_get_data(THPVariable *self); 23 | 24 | inline bool THPVariable_Check(PyObject *obj) 25 | { 26 | return THPVariableClass && PyObject_IsInstance(obj, THPVariableClass); 27 | } 28 | -------------------------------------------------------------------------------- /torch/csrc/cuda/AutoGPU.h: -------------------------------------------------------------------------------- 1 | #ifndef THCP_AUTOGPU_INC 2 | #define THCP_AUTOGPU_INC 3 | 4 | #include 5 | #include "THP.h" 6 | #include "torch/csrc/utils/auto_gpu.h" 7 | 8 | class THP_CLASS THCPAutoGPU : public AutoGPU { 9 | public: 10 | explicit THCPAutoGPU(int device_id=-1); 11 | THCPAutoGPU(PyObject *args, PyObject *self=NULL); 12 | void setObjDevice(PyObject *obj); 13 | }; 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /torch/csrc/cuda/Module.h: -------------------------------------------------------------------------------- 1 | #ifndef THCP_CUDA_MODULE_INC 2 | #define THCP_CUDA_MODULE_INC 3 | 4 | extern THCState *state; 5 | 6 | #ifdef _THP_CORE 7 | void THCPModule_setDevice(int idx); 8 | PyObject * THCPModule_getDevice_wrap(PyObject *self); 9 | PyObject * THCPModule_setDevice_wrap(PyObject *self, PyObject *arg); 10 | PyObject * THCPModule_getDriverVersion(PyObject *self); 11 | PyObject * THCPModule_isDriverSufficient(PyObject *self); 12 | PyObject * THCPModule_getCurrentBlasHandle_wrap(PyObject *self); 13 | #endif 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /torch/csrc/cuda/Storage.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include "THCP.h" 6 | 7 | #include "override_macros.h" 8 | #include "torch/csrc/copy_utils.h" 9 | 10 | #define THC_GENERIC_FILE "torch/csrc/generic/Storage.cpp" 11 | #include 12 | -------------------------------------------------------------------------------- /torch/csrc/cuda/Stream.h: -------------------------------------------------------------------------------- 1 | #ifndef THCP_STREAM_INC 2 | #define THCP_STREAM_INC 3 | 4 | #include 5 | #include 6 | 7 | 8 | struct THCPStream { 9 | PyObject_HEAD 10 | THCStream *cdata; 11 | int device; 12 | cudaStream_t cuda_stream; 13 | }; 14 | extern PyObject *THCPStreamClass; 15 | 16 | bool THCPStream_init(PyObject *module); 17 | 18 | inline bool THCPStream_Check(PyObject* obj) { 19 | return THCPStreamClass && PyObject_IsInstance(obj, THCPStreamClass); 20 | } 21 | 22 | #endif // THCP_STREAM_INC 23 | -------------------------------------------------------------------------------- /torch/csrc/cuda/THCP.h: -------------------------------------------------------------------------------- 1 | #ifndef THCP_H 2 | #define THCP_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #include "torch/csrc/THP.h" 12 | #include "serialization.h" 13 | #include "AutoGPU.h" 14 | #include "Module.h" 15 | #include "Storage.h" 16 | #include "Tensor.h" 17 | #include "Stream.h" 18 | #ifdef _THP_CORE 19 | #include "utils.h" 20 | #endif 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /torch/csrc/cuda/Tensor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "torch/csrc/cuda/THCP.h" 10 | 11 | #include "torch/csrc/cuda/override_macros.h" 12 | #include "torch/csrc/copy_utils.h" 13 | #include "DynamicTypes.h" 14 | 15 | //generic_include THC torch/csrc/generic/Tensor.cpp 16 | 17 | #include "torch/csrc/cuda/undef_macros.h" 18 | #include "torch/csrc/cuda/restore_macros.h" 19 | -------------------------------------------------------------------------------- /torch/csrc/cuda/restore_macros.h: -------------------------------------------------------------------------------- 1 | 2 | #define THTensor TH_CONCAT_3(TH,Real,Tensor) 3 | #define THTensor_(NAME) TH_CONCAT_4(TH,Real,Tensor_,NAME) 4 | 5 | #define THPTensor TH_CONCAT_3(THP,Real,Tensor) 6 | #define THPTensorStr TH_CONCAT_STRING_3(torch.,Real,Tensor) 7 | #define THPTensorClass TH_CONCAT_3(THP,Real,TensorClass) 8 | #define THPTensor_(NAME) TH_CONCAT_4(THP,Real,Tensor_,NAME) 9 | 10 | #define THPStorage TH_CONCAT_3(THP,Real,Storage) 11 | #define THPStorageStr TH_CONCAT_STRING_3(torch.,Real,Storage) 12 | #define THPStorageClass TH_CONCAT_3(THP,Real,StorageClass) 13 | #define THPStorage_(NAME) TH_CONCAT_4(THP,Real,Storage_,NAME) 14 | 15 | #ifdef _THP_CORE 16 | #define THStoragePtr TH_CONCAT_3(TH,Real,StoragePtr) 17 | #define THTensorPtr TH_CONCAT_3(TH,Real,TensorPtr) 18 | #define THPStoragePtr TH_CONCAT_3(THP,Real,StoragePtr) 19 | #define THPTensorPtr TH_CONCAT_3(THP,Real,TensorPtr) 20 | #endif 21 | -------------------------------------------------------------------------------- /torch/csrc/cuda/serialization.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "THCP.h" 4 | 5 | #include "override_macros.h" 6 | 7 | #include 8 | #include 9 | 10 | #define THC_GENERIC_FILE "torch/csrc/generic/serialization.cpp" 11 | #include 12 | 13 | -------------------------------------------------------------------------------- /torch/csrc/cuda/serialization.h: -------------------------------------------------------------------------------- 1 | #ifndef THCP_SERIALIZATION_INC 2 | #define THCP_SERIALIZATION_INC 3 | 4 | #include "override_macros.h" 5 | 6 | #define THC_GENERIC_FILE "torch/csrc/generic/serialization.h" 7 | #include 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /torch/csrc/cuda/utils.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "THCP.h" 5 | 6 | #include "override_macros.h" 7 | 8 | #define THC_GENERIC_FILE "torch/csrc/generic/utils.cpp" 9 | #include 10 | -------------------------------------------------------------------------------- /torch/csrc/cuda/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef THCP_UTILS_H 2 | #define THCP_UTILS_H 3 | 4 | #define THCPUtils_(NAME) TH_CONCAT_4(THCP,Real,Utils_,NAME) 5 | 6 | #define THCStoragePtr TH_CONCAT_3(THC,Real,StoragePtr) 7 | #define THCTensorPtr TH_CONCAT_3(THC,Real,TensorPtr) 8 | #define THCPStoragePtr TH_CONCAT_3(THCP,Real,StoragePtr) 9 | #define THCPTensorPtr TH_CONCAT_3(THCP,Real,TensorPtr) 10 | 11 | #define THCSTensorPtr TH_CONCAT_3(THCS,Real,TensorPtr) 12 | #define THCSPTensorPtr TH_CONCAT_3(THCSP,Real,TensorPtr) 13 | 14 | #include "override_macros.h" 15 | 16 | #define THC_GENERIC_FILE "torch/csrc/generic/utils.h" 17 | #include 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /torch/csrc/cudnn/Handles.cpp: -------------------------------------------------------------------------------- 1 | #include "Handles.h" 2 | 3 | #include 4 | #include 5 | #include "Exceptions.h" 6 | 7 | namespace torch { namespace cudnn { 8 | 9 | namespace { 10 | 11 | struct Handle { 12 | cudnnHandle_t handle; 13 | Handle() : handle(NULL) { 14 | CHECK(cudnnCreate(&handle)); 15 | } 16 | ~Handle() { 17 | if (handle) { 18 | cudnnDestroy(handle); 19 | } 20 | } 21 | }; 22 | 23 | std::mutex mutex; 24 | std::unordered_map handles; 25 | 26 | } // namespace 27 | 28 | 29 | cudnnHandle_t getCudnnHandle() 30 | { 31 | int device; 32 | CUDA_CHECK(cudaGetDevice(&device)); 33 | 34 | std::lock_guard guard(mutex); 35 | return handles[device].handle; 36 | } 37 | 38 | }} // namespace torch::cudnn 39 | -------------------------------------------------------------------------------- /torch/csrc/cudnn/Handles.h: -------------------------------------------------------------------------------- 1 | #ifndef THP_CUDNN_HANDLE_INC 2 | #define THP_CUDNN_HANDLE_INC 3 | 4 | #include 5 | 6 | namespace torch { namespace cudnn { 7 | 8 | cudnnHandle_t getCudnnHandle(); 9 | 10 | }} // namespace 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /torch/csrc/cudnn/Module.h: -------------------------------------------------------------------------------- 1 | #ifndef THP_CUDNN_MODULE_INC 2 | #define THP_CUDNN_MODULE_INC 3 | 4 | #include 5 | 6 | PyMethodDef* THCUDNN_methods(); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /torch/csrc/cudnn/Types.h: -------------------------------------------------------------------------------- 1 | #ifndef THP_CUDNN_TYPES_INC 2 | #define THP_CUDNN_TYPES_INC 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "../Types.h" 9 | #include 10 | 11 | namespace torch { namespace cudnn { 12 | 13 | PyObject * getTensorClass(PyObject *args); 14 | cudnnDataType_t getCudnnDataType(PyObject *tensorClass); 15 | cudnnDataType_t getCudnnDataType(const thpp::Tensor& tensor); 16 | void _THVoidTensor_assertContiguous(THVoidTensor *tensor, const std::string& name); 17 | 18 | #define THVoidTensor_assertContiguous(tensor) \ 19 | _THVoidTensor_assertContiguous(tensor, #tensor " tensor") 20 | 21 | }} // namespace torch::cudnn 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /torch/csrc/distributed/Storage.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include "THDP.h" 6 | 7 | #include "override_macros.h" 8 | 9 | #define THD_GENERIC_FILE "torch/csrc/generic/Storage.cpp" 10 | #include 11 | 12 | //#define THD_GENERIC_FILE "torch/csrc/generic/StorageCopy.cpp" 13 | //#include 14 | 15 | -------------------------------------------------------------------------------- /torch/csrc/distributed/THDP.h: -------------------------------------------------------------------------------- 1 | #ifndef THDP_H 2 | #define THDP_H 3 | 4 | #include 5 | 6 | #include "torch/csrc/THP.h" 7 | #include "Module.h" 8 | #include "Storage.h" 9 | #include "Tensor.h" 10 | #include "../PtrWrapper.h" 11 | #ifdef _THP_CORE 12 | #include "utils.h" 13 | #endif 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /torch/csrc/distributed/Tensor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "THDP.h" 10 | 11 | #include "override_macros.h" 12 | 13 | #define THD_GENERIC_FILE "torch/csrc/generic/Tensor.cpp" 14 | #include 15 | 16 | //#define THD_GENERIC_FILE "torch/csrc/generic/TensorCopy.cpp" 17 | //#include 18 | 19 | //#include "undef_macros.h" 20 | //#include "restore_macros.h" 21 | 22 | //#include "generic/TensorCopyAsync.cpp" 23 | //#include 24 | -------------------------------------------------------------------------------- /torch/csrc/distributed/undef_macros.h: -------------------------------------------------------------------------------- 1 | #undef TH_GENERIC_FILE 2 | #undef LIBRARY_STATE 3 | #undef LIBRARY_STATE_NOARGS 4 | 5 | #undef THPTensor_ 6 | #undef THPTensor_stateless_ 7 | #undef THPTensor 8 | #undef THPTensorStr 9 | #undef THPTensorBaseStr 10 | #undef THPTensorClass 11 | 12 | #undef THPTensorStatelessType 13 | #undef THPTensorStateless 14 | #undef THPTensorType 15 | 16 | #undef THPStorage_ 17 | #undef THPStorage 18 | #undef THPStorageBaseStr 19 | #undef THPStorageStr 20 | #undef THPStorageClass 21 | #undef THPStorageType 22 | 23 | #undef THStorage 24 | #undef THStorage_ 25 | #undef THTensor 26 | #undef THTensor_ 27 | 28 | #undef THStoragePtr 29 | #undef THPStoragePtr 30 | #undef THTensorPtr 31 | #undef THPTensorPtr 32 | 33 | #undef THHostTensor 34 | #undef THHostTensor_ 35 | #undef THHostStorage 36 | #undef THHostStorage_ 37 | -------------------------------------------------------------------------------- /torch/csrc/distributed/utils.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "THDP.h" 3 | 4 | #include "override_macros.h" 5 | 6 | template<> 7 | void THPPointer::free() { 8 | if (ptr) 9 | THDTensorDescriptor_free(ptr); 10 | } 11 | template class THPPointer; 12 | 13 | #define THD_GENERIC_FILE "torch/csrc/generic/utils.cpp" 14 | #include 15 | -------------------------------------------------------------------------------- /torch/csrc/distributed/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef THDP_UTILS_H 2 | #define THDP_UTILS_H 3 | 4 | #include "THDP.h" 5 | 6 | #define THDPUtils_(NAME) TH_CONCAT_4(THDP,Real,Utils_,NAME) 7 | 8 | #define THDStoragePtr TH_CONCAT_3(THD,Real,StoragePtr) 9 | #define THDTensorPtr TH_CONCAT_3(THD,Real,TensorPtr) 10 | #define THDPStoragePtr TH_CONCAT_3(THDP,Real,StoragePtr) 11 | #define THDPTensorPtr TH_CONCAT_3(THDP,Real,TensorPtr) 12 | 13 | #include "override_macros.h" 14 | 15 | #define THD_GENERIC_FILE "torch/csrc/generic/utils.h" 16 | #include 17 | 18 | typedef THPPointer THDPTensorDesc; 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /torch/csrc/generic/Storage.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_GENERIC_FILE 2 | #define TH_GENERIC_FILE "generic/Storage.h" 3 | #else 4 | 5 | struct THPStorage { 6 | PyObject_HEAD 7 | THStorage *cdata; 8 | }; 9 | 10 | THP_API PyObject * THPStorage_(New)(THStorage *ptr); 11 | extern PyObject *THPStorageClass; 12 | 13 | #ifdef _THP_CORE 14 | #include "torch/csrc/Types.h" 15 | 16 | bool THPStorage_(init)(PyObject *module); 17 | 18 | extern PyTypeObject THPStorageType; 19 | template <> struct THPTypeInfo { 20 | static PyTypeObject* pyType() { return &THPStorageType; } 21 | static THStorage* cdata(PyObject* p) { return ((THPStorage*)p)->cdata; } 22 | }; 23 | #endif 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /torch/csrc/generic/serialization.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_GENERIC_FILE 2 | #define TH_GENERIC_FILE "generic/serialization.h" 3 | #else 4 | 5 | void THPTensor_(writeMetadataRaw)(THTensor *self, int fd); 6 | THTensor * THPTensor_(newWithMetadataFileRaw)(int fd, THStorage *storage); 7 | void THPStorage_(writeFileRaw)(THStorage *self, int fd); 8 | THStorage * THPStorage_(readFileRaw)(int fd, THStorage *storage); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /torch/csrc/nn/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tylergenter/pytorch/42459c2544bc6c2e37c3459caaeca7c9eb1a8906/torch/csrc/nn/.gitkeep -------------------------------------------------------------------------------- /torch/csrc/serialization.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "THP.h" 5 | 6 | #include "generic/serialization.cpp" 7 | #include 8 | 9 | #include "generic/serialization.cpp" 10 | #include 11 | -------------------------------------------------------------------------------- /torch/csrc/serialization.h: -------------------------------------------------------------------------------- 1 | #ifndef THP_SERIALIZATION_INC 2 | #define THP_SERIALIZATION_INC 3 | 4 | #include "generic/serialization.h" 5 | #include 6 | 7 | #include "generic/serialization.h" 8 | #include 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /torch/csrc/utils/auto_gil.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // RAII structs to acquire and release Python's global interpreter lock (GIL) 4 | 5 | #include 6 | 7 | // Acquires the GIL on construction 8 | struct AutoGIL { 9 | AutoGIL() : gstate(PyGILState_Ensure()) { 10 | } 11 | ~AutoGIL() { 12 | PyGILState_Release(gstate); 13 | } 14 | 15 | PyGILState_STATE gstate; 16 | }; 17 | 18 | // Releases the GIL on construction 19 | struct AutoNoGIL { 20 | AutoNoGIL() : save(PyEval_SaveThread()) { 21 | } 22 | ~AutoNoGIL() { 23 | PyEval_RestoreThread(save); 24 | } 25 | 26 | PyThreadState* save; 27 | }; 28 | -------------------------------------------------------------------------------- /torch/csrc/utils/auto_stream.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // RAII structs to set CUDA stream 4 | 5 | #ifdef WITH_CUDA 6 | #include 7 | extern THCState* state; 8 | #endif 9 | 10 | struct AutoStream { 11 | #ifdef WITH_CUDA 12 | explicit AutoStream(THCStream* stream) 13 | : original_stream(THCState_getStream(state)) 14 | { 15 | THCStream_retain(original_stream); 16 | THCState_setStream(state, stream); 17 | } 18 | 19 | ~AutoStream() { 20 | THCState_setStream(state, original_stream); 21 | THCStream_free(original_stream); 22 | } 23 | 24 | THCStream* original_stream; 25 | #endif 26 | }; 27 | -------------------------------------------------------------------------------- /torch/csrc/utils/object_ptr.cpp: -------------------------------------------------------------------------------- 1 | #include "torch/csrc/utils/object_ptr.h" 2 | 3 | #include 4 | 5 | template<> 6 | void THPPointer::free() { 7 | if (ptr) 8 | Py_DECREF(ptr); 9 | } 10 | 11 | template class THPPointer; 12 | -------------------------------------------------------------------------------- /torch/csrc/utils/object_ptr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | template 6 | class THPPointer { 7 | public: 8 | THPPointer(): ptr(nullptr) {}; 9 | THPPointer(T *ptr): ptr(ptr) {}; 10 | THPPointer(THPPointer &&p) { free(); ptr = p.ptr; p.ptr = nullptr; }; 11 | 12 | ~THPPointer() { free(); }; 13 | T * get() { return ptr; } 14 | const T * get() const { return ptr; } 15 | T * release() { T *tmp = ptr; ptr = NULL; return tmp; } 16 | operator T*() { return ptr; } 17 | THPPointer& operator =(T *new_ptr) { free(); ptr = new_ptr; return *this; } 18 | THPPointer& operator =(THPPointer &&p) { free(); ptr = p.ptr; p.ptr = nullptr; return *this; } 19 | T * operator ->() { return ptr; } 20 | operator bool() { return ptr != nullptr; } 21 | 22 | private: 23 | void free(); 24 | T *ptr = nullptr; 25 | }; 26 | 27 | typedef THPPointer THPObjectPtr; 28 | -------------------------------------------------------------------------------- /torch/csrc/utils/tuple_parser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace torch { 9 | 10 | struct TupleParser { 11 | TupleParser(PyObject* args, int num_args=-1); 12 | 13 | void parse(bool& x); 14 | void parse(int& x); 15 | void parse(double& x); 16 | void parse(std::unique_ptr& x); 17 | void parse(std::shared_ptr& x); 18 | void parse(std::vector& x); 19 | void parse(std::string& x); 20 | 21 | protected: 22 | std::runtime_error invalid_type(const char* expected); 23 | PyObject* next_arg(); 24 | 25 | private: 26 | PyObject* args; 27 | int idx; 28 | }; 29 | 30 | } // namespace torch 31 | -------------------------------------------------------------------------------- /torch/legacy/__init__.py: -------------------------------------------------------------------------------- 1 | """Package containing code ported from Lua torch. 2 | 3 | To make it possible to work with existing models and ease the transition 4 | for current Lua torch users, we've created this package. You can find the 5 | ``nn`` code in ``torch.legacy.nn``, and ``optim`` in ``torch.legacy.optim``. 6 | The APIs should exactly match Lua torch. 7 | """ 8 | -------------------------------------------------------------------------------- /torch/legacy/nn/Abs.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from .Module import Module 3 | 4 | 5 | class Abs(Module): 6 | 7 | def __init__(self): 8 | super(Abs, self).__init__() 9 | 10 | def updateOutput(self, input): 11 | self._backend.Abs_updateOutput( 12 | self._backend.library_state, 13 | input, 14 | self.output 15 | ) 16 | return self.output 17 | 18 | def updateGradInput(self, input, gradOutput): 19 | self._backend.Abs_updateGradInput( 20 | self._backend.library_state, 21 | input, 22 | gradOutput, 23 | self.gradInput 24 | ) 25 | return self.gradInput 26 | -------------------------------------------------------------------------------- /torch/legacy/nn/CDivTable.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from .Module import Module 3 | 4 | 5 | class CDivTable(Module): 6 | 7 | def __init__(self, ): 8 | super(CDivTable, self).__init__() 9 | self.gradInput = [] 10 | 11 | def updateOutput(self, input): 12 | self.output.resize_as_(input[0]).copy_(input[0]) 13 | self.output.div_(input[1]) 14 | return self.output 15 | 16 | def updateGradInput(self, input, gradOutput): 17 | while len(self.gradInput) < 2: 18 | self.gradInput.append(input[0].new()) 19 | self.gradInput[0].resize_as_(input[0]).copy_(gradOutput).div_(input[1]) 20 | self.gradInput[1].resize_as_(input[1]).zero_().addcdiv_(-1, self.gradInput[0], input[1]).mul_(input[0]) 21 | 22 | del self.gradInput[len(input):] 23 | 24 | return self.gradInput 25 | -------------------------------------------------------------------------------- /torch/legacy/nn/CSubTable.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from .Module import Module 3 | 4 | 5 | class CSubTable(Module): 6 | 7 | def __init__(self, ): 8 | super(CSubTable, self).__init__() 9 | self.gradInput = [torch.Tensor(), torch.Tensor()] 10 | 11 | def updateOutput(self, input): 12 | self.output.resize_as_(input[0]).copy_(input[0]) 13 | self.output.add_(-1, input[1]) 14 | return self.output 15 | 16 | def updateGradInput(self, input, gradOutput): 17 | if self.gradInput[0] is None: 18 | self.gradInput[0] = input[0].new() 19 | if self.gradInput[1] is None: 20 | self.gradInput[1] = input[1].new() 21 | self.gradInput[0].resize_as_(input[0]).copy_(gradOutput) 22 | self.gradInput[1].resize_as_(input[1]).copy_(gradOutput).mul_(-1) 23 | 24 | self.gradInput = self.gradInput[:2] 25 | return self.gradInput 26 | -------------------------------------------------------------------------------- /torch/legacy/nn/Clamp.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from .HardTanh import HardTanh 3 | 4 | 5 | class Clamp(HardTanh): 6 | 7 | def __init__(self, min_value, max_value): 8 | super(Clamp, self,).__init__(min_value, max_value) 9 | -------------------------------------------------------------------------------- /torch/legacy/nn/Contiguous.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from .Module import Module 3 | 4 | 5 | class Contiguous(Module): 6 | 7 | def updateOutput(self, input): 8 | if not input.is_contiguous(): 9 | self.output.resize_as_(input).copy_(input) 10 | else: 11 | self.output.set_(input) 12 | 13 | return self.output 14 | 15 | def updateGradInput(self, input, gradOutput): 16 | if not gradOutput.is_contiguous(): 17 | self.gradInput.resize_as_(gradOutput).copy_(gradOutput) 18 | else: 19 | self.gradInput.set_(gradOutput) 20 | 21 | return self.gradInput 22 | -------------------------------------------------------------------------------- /torch/legacy/nn/Copy.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from .Module import Module 3 | 4 | 5 | class Copy(Module): 6 | 7 | def __init__(self, intype, outtype, dontCast=False): 8 | self.dontCast = dontCast 9 | super(Copy, self).__init__() 10 | self.gradInput = intype() 11 | self.output = outtype() 12 | 13 | def updateOutput(self, input): 14 | self.output.resize_(input.size()).copy_(input) 15 | return self.output 16 | 17 | def updateGradInput(self, input, gradOutput): 18 | self.gradInput.resize_(gradOutput.size()).copy_(gradOutput) 19 | return self.gradInput 20 | 21 | def type(self, type=None, tensorCache=None): 22 | if type and self.dontCast: 23 | return self 24 | 25 | return super(Copy, self).type(self, type, tensorCache) 26 | -------------------------------------------------------------------------------- /torch/legacy/nn/CriterionTable.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from .Module import Module 3 | 4 | 5 | class CriterionTable(Module): 6 | 7 | def __init__(self, criterion): 8 | super(CriterionTable, self).__init__() 9 | self.criterion = criterion 10 | self.gradInput = [criterion.gradInput] 11 | 12 | def updateOutput(self, input): 13 | self.output = self.criterion.updateOutput(*input) 14 | return self.output 15 | 16 | def updateGradInput(self, input, grad_output): 17 | self.criterion.updateGradInput(*input) 18 | return self.gradInput 19 | -------------------------------------------------------------------------------- /torch/legacy/nn/Exp.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from .Module import Module 3 | 4 | 5 | class Exp(Module): 6 | 7 | def updateOutput(self, input): 8 | return torch.exp(input, out=self.output) 9 | 10 | def updateGradInput(self, input, gradOutput): 11 | return torch.mul(self.output, gradOutput, out=self.gradInput) 12 | -------------------------------------------------------------------------------- /torch/legacy/nn/GradientReversal.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from .Module import Module 3 | 4 | 5 | class GradientReversal(Module): 6 | 7 | def __init__(self, lambd=1): 8 | super(GradientReversal, self).__init__() 9 | self.lambd = lambd 10 | 11 | def setLambda(self, lambd): 12 | self.lambd = lambd 13 | 14 | def updateOutput(self, input): 15 | self.output.set_(input) 16 | return self.output 17 | 18 | def updateGradInput(self, input, gradOutput): 19 | self.gradInput.resize_as_(gradOutput) 20 | self.gradInput.copy_(gradOutput) 21 | self.gradInput.mul_(-self.lambd) 22 | return self.gradInput 23 | -------------------------------------------------------------------------------- /torch/legacy/nn/HardShrink.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from .Module import Module 3 | 4 | 5 | class HardShrink(Module): 6 | 7 | def __init__(self, lambd=0.5): 8 | assert type(lambd) == float 9 | super(HardShrink, self).__init__() 10 | self.lambd = lambd 11 | 12 | def updateOutput(self, input): 13 | self._backend.HardShrink_updateOutput( 14 | self._backend.library_state, 15 | input, 16 | self.output, 17 | self.lambd 18 | ) 19 | return self.output 20 | 21 | def updateGradInput(self, input, gradOutput): 22 | self._backend.HardShrink_updateGradInput( 23 | self._backend.library_state, 24 | input, 25 | gradOutput, 26 | self.gradInput, 27 | self.lambd 28 | ) 29 | return self.gradInput 30 | -------------------------------------------------------------------------------- /torch/legacy/nn/Identity.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from .Module import Module 3 | from .utils import clear 4 | 5 | 6 | class Identity(Module): 7 | 8 | def updateOutput(self, input): 9 | self.output = input 10 | return self.output 11 | 12 | def updateGradInput(self, input, gradOutput): 13 | self.gradInput = gradOutput 14 | return self.gradInput 15 | 16 | def clearState(self): 17 | clear(self, [ 18 | 'output', 19 | 'gradInput', 20 | ]) 21 | return super(Identity, self).clearState() 22 | -------------------------------------------------------------------------------- /torch/legacy/nn/Index.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from .Module import Module 3 | 4 | 5 | class Index(Module): 6 | 7 | def __init__(self, dimension): 8 | super(Index, self).__init__() 9 | self.dimension = dimension 10 | self.gradInput = [self.gradInput] 11 | 12 | def updateOutput(self, input): 13 | t = input[0] 14 | index = input[1] 15 | torch.index_select(t, self.dimension, index, out=self.output) 16 | return self.output 17 | 18 | def updateGradInput(self, input, gradOutput): 19 | t = input[0] 20 | index = input[1] 21 | 22 | gradInput = self.gradInput[0] # no gradient for the index variable 23 | gradInput.resize_as_(t).zero_() 24 | gradInput.index_add_(self.dimension, index, gradOutput) 25 | return self.gradInput 26 | -------------------------------------------------------------------------------- /torch/legacy/nn/Log.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from .Module import Module 3 | 4 | 5 | class Log(Module): 6 | 7 | def updateOutput(self, input): 8 | self.output.resize_as_(input) 9 | self.output.copy_(input) 10 | self.output.log_() 11 | return self.output 12 | 13 | def updateGradInput(self, input, gradOutput): 14 | self.gradInput.resize_as_(input) 15 | self.gradInput.fill_(1) 16 | self.gradInput.div_(input) 17 | self.gradInput.mul_(gradOutput) 18 | return self.gradInput 19 | -------------------------------------------------------------------------------- /torch/legacy/nn/LogSigmoid.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from .Module import Module 3 | from .utils import clear 4 | 5 | 6 | class LogSigmoid(Module): 7 | 8 | def __init__(self): 9 | super(LogSigmoid, self).__init__() 10 | self.buffer = None 11 | 12 | def updateOutput(self, input): 13 | if self.buffer is None: 14 | self.buffer = input.new() 15 | self._backend.LogSigmoid_updateOutput( 16 | self._backend.library_state, 17 | input, 18 | self.output, 19 | self.buffer 20 | ) 21 | return self.output 22 | 23 | def updateGradInput(self, input, gradOutput): 24 | self._backend.LogSigmoid_updateGradInput( 25 | self._backend.library_state, 26 | input, 27 | gradOutput, 28 | self.gradInput, 29 | self.buffer 30 | ) 31 | return self.gradInput 32 | 33 | def clearState(self): 34 | clear(self, 'buffer') 35 | return super(LogSigmoid, self).clearState() 36 | -------------------------------------------------------------------------------- /torch/legacy/nn/LogSoftMax.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from .Module import Module 3 | 4 | 5 | class LogSoftMax(Module): 6 | 7 | def updateOutput(self, input): 8 | self._backend.LogSoftMax_updateOutput( 9 | self._backend.library_state, 10 | input, 11 | self.output 12 | ) 13 | return self.output 14 | 15 | def updateGradInput(self, input, gradOutput): 16 | self._backend.LogSoftMax_updateGradInput( 17 | self._backend.library_state, 18 | input, 19 | gradOutput, 20 | self.gradInput, 21 | self.output 22 | ) 23 | return self.gradInput 24 | -------------------------------------------------------------------------------- /torch/legacy/nn/Mean.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from .Sum import Sum 3 | 4 | """ 5 | 6 | This file is still here because of backward compatibility. 7 | 8 | Please use instead "nn.Sum(dimension, nInputDims, sizeAverage)" 9 | 10 | """ 11 | 12 | 13 | class Mean(Sum): 14 | 15 | def __init__(self, dimension): 16 | super(Mean, self).__init__(dimension, True) 17 | -------------------------------------------------------------------------------- /torch/legacy/nn/Power.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from .Module import Module 3 | 4 | 5 | class Power(Module): 6 | 7 | def __init__(self, p): 8 | super(Power, self).__init__() 9 | self.pow = p 10 | 11 | def updateOutput(self, input): 12 | self.output.resize_as_(input).copy_(input) 13 | self.output.pow_(self.pow) 14 | return self.output 15 | 16 | def updateGradInput(self, input, gradOutput): 17 | self.gradInput.resize_as_(input).copy_(input) 18 | self.gradInput.pow_(self.pow - 1) 19 | self.gradInput.mul_(gradOutput).mul_(self.pow) 20 | return self.gradInput 21 | -------------------------------------------------------------------------------- /torch/legacy/nn/ReLU.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from .Threshold import Threshold 3 | 4 | 5 | class ReLU(Threshold): 6 | 7 | def __init__(self, inplace=False): 8 | super(ReLU, self).__init__(0, 0, inplace) 9 | -------------------------------------------------------------------------------- /torch/legacy/nn/ReLU6.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from .Module import Module 3 | 4 | 5 | class ReLU6(Module): 6 | 7 | def __init__(self, inplace=False): 8 | super(ReLU6, self).__init__() 9 | self.inplace = inplace 10 | 11 | def updateOutput(self, input): 12 | self._backend.HardTanh_updateOutput( 13 | self._backend.library_state, 14 | input, 15 | self.output, 16 | 0, 6, self.inplace 17 | ) 18 | return self.output 19 | 20 | def updateGradInput(self, input, gradOutput): 21 | self._backend.HardTanh_updateGradInput( 22 | self._backend.library_state, 23 | input, 24 | gradOutput, 25 | self.gradInput, 26 | 0, 6, self.inplace 27 | ) 28 | return self.gradInput 29 | -------------------------------------------------------------------------------- /torch/legacy/nn/Select.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from .Module import Module 3 | 4 | 5 | class Select(Module): 6 | 7 | def __init__(self, dimension, index): 8 | super(Select, self).__init__() 9 | self.dimension = dimension 10 | self.index = index 11 | 12 | def updateOutput(self, input): 13 | index = self.index if self.index >= 0 else input.size(self.dimension) + self.index 14 | output = input.select(self.dimension, index) 15 | self.output.resize_as_(output) 16 | return self.output.copy_(output) 17 | 18 | def updateGradInput(self, input, gradOutput): 19 | index = self.index if self.index >= 0 else input.size(self.dimension) + self.index 20 | self.gradInput.resize_as_(input) 21 | self.gradInput.zero_() 22 | self.gradInput.select(self.dimension, index).copy_(gradOutput) 23 | return self.gradInput 24 | -------------------------------------------------------------------------------- /torch/legacy/nn/Sigmoid.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from .Module import Module 3 | 4 | 5 | class Sigmoid(Module): 6 | 7 | def updateOutput(self, input): 8 | self._backend.Sigmoid_updateOutput( 9 | self._backend.library_state, 10 | input, 11 | self.output 12 | ) 13 | return self.output 14 | 15 | def updateGradInput(self, input, gradOutput): 16 | self._backend.Sigmoid_updateGradInput( 17 | self._backend.library_state, 18 | input, 19 | gradOutput, 20 | self.gradInput, 21 | self.output 22 | ) 23 | return self.gradInput 24 | -------------------------------------------------------------------------------- /torch/legacy/nn/SoftMax.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from .Module import Module 3 | 4 | 5 | class SoftMax(Module): 6 | 7 | def updateOutput(self, input): 8 | self._backend.SoftMax_updateOutput( 9 | self._backend.library_state, 10 | input, 11 | self.output 12 | ) 13 | return self.output 14 | 15 | def updateGradInput(self, input, gradOutput): 16 | self._backend.SoftMax_updateGradInput( 17 | self._backend.library_state, 18 | input, 19 | gradOutput, 20 | self.gradInput, 21 | self.output 22 | ) 23 | return self.gradInput 24 | -------------------------------------------------------------------------------- /torch/legacy/nn/SoftShrink.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from .Module import Module 3 | 4 | 5 | class SoftShrink(Module): 6 | 7 | def __init__(self, lambd=0.5): 8 | super(SoftShrink, self).__init__() 9 | self.lambd = lambd 10 | 11 | def updateOutput(self, input): 12 | self._backend.SoftShrink_updateOutput( 13 | self._backend.library_state, 14 | input, 15 | self.output, 16 | self.lambd 17 | ) 18 | return self.output 19 | 20 | def updateGradInput(self, input, gradOutput): 21 | self._backend.SoftShrink_updateGradInput( 22 | self._backend.library_state, 23 | input, 24 | gradOutput, 25 | self.gradInput, 26 | self.lambd 27 | ) 28 | return self.gradInput 29 | -------------------------------------------------------------------------------- /torch/legacy/nn/SpatialSoftMax.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from .Module import Module 3 | 4 | 5 | class SpatialSoftMax(Module): 6 | 7 | def updateOutput(self, input): 8 | self._backend.SoftMax_updateOutput( 9 | self._backend.library_state, 10 | input, 11 | self.output 12 | ) 13 | return self.output 14 | 15 | def updateGradInput(self, input, gradOutput): 16 | self._backend.SoftMax_updateGradInput( 17 | self._backend.library_state, 18 | input, 19 | gradOutput, 20 | self.gradInput, 21 | self.output 22 | ) 23 | return self.gradInput 24 | -------------------------------------------------------------------------------- /torch/legacy/nn/Sqrt.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from .Module import Module 3 | 4 | 5 | class Sqrt(Module): 6 | 7 | def __init__(self, b=0, eps=0): 8 | super(Sqrt, self).__init__() 9 | self.eps = b 10 | self.eps = eps 11 | 12 | def updateOutput(self, input): 13 | self._backend.Sqrt_updateOutput( 14 | self._backend.library_state, 15 | input, 16 | self.output, 17 | self.eps 18 | ) 19 | return self.output 20 | 21 | def updateGradInput(self, input, gradOutput): 22 | self._backend.Sqrt_updateGradInput( 23 | self._backend.library_state, 24 | input, 25 | gradOutput, 26 | self.gradInput, 27 | self.output 28 | ) 29 | return self.gradInput 30 | -------------------------------------------------------------------------------- /torch/legacy/nn/Square.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from .Module import Module 3 | 4 | 5 | class Square(Module): 6 | 7 | def updateOutput(self, input): 8 | self._backend.Square_updateOutput( 9 | self._backend.library_state, 10 | input, 11 | self.output 12 | ) 13 | return self.output 14 | 15 | def updateGradInput(self, input, gradOutput): 16 | self._backend.Square_updateGradInput( 17 | self._backend.library_state, 18 | input, 19 | gradOutput, 20 | self.gradInput 21 | ) 22 | return self.gradInput 23 | -------------------------------------------------------------------------------- /torch/legacy/nn/Squeeze.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from .Module import Module 3 | 4 | 5 | class Squeeze(Module): 6 | 7 | def __init__(self, dim=None): 8 | super(Squeeze, self).__init__() 9 | self.dim = dim 10 | 11 | def updateOutput(self, input): 12 | dim = self.dim 13 | self.output.set_(input.squeeze(dim) if dim is not None else input.squeeze()) 14 | return self.output 15 | 16 | def updateGradInput(self, input, gradOutput): 17 | assert input.nelement() == gradOutput.nelement() 18 | self.gradInput.set_(gradOutput.contiguous().view_as(input)) 19 | return self.gradInput 20 | -------------------------------------------------------------------------------- /torch/legacy/nn/Tanh.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from .Module import Module 3 | 4 | 5 | class Tanh(Module): 6 | 7 | def updateOutput(self, input): 8 | self._backend.Tanh_updateOutput( 9 | self._backend.library_state, 10 | input, 11 | self.output 12 | ) 13 | return self.output 14 | 15 | def updateGradInput(self, input, gradOutput): 16 | self._backend.Tanh_updateGradInput( 17 | self._backend.library_state, 18 | input, 19 | gradOutput, 20 | self.gradInput, 21 | self.output 22 | ) 23 | return self.gradInput 24 | -------------------------------------------------------------------------------- /torch/legacy/nn/TanhShrink.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from .Module import Module 3 | from .Tanh import Tanh 4 | 5 | 6 | class TanhShrink(Module): 7 | 8 | def __init__(self): 9 | super(TanhShrink, self).__init__() 10 | self.tanh = Tanh() 11 | 12 | def updateOutput(self, input): 13 | th = self.tanh.updateOutput(input) 14 | self.output.resize_as_(input).copy_(input) 15 | self.output.add_(-1, th) 16 | return self.output 17 | 18 | def updateGradInput(self, input, gradOutput): 19 | dth = self.tanh.updateGradInput(input, gradOutput) 20 | self.gradInput.resize_as_(input).copy_(gradOutput) 21 | self.gradInput.add_(-1, dth) 22 | return self.gradInput 23 | -------------------------------------------------------------------------------- /torch/legacy/nn/Transpose.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from .Module import Module 3 | 4 | 5 | class Transpose(Module): 6 | # transpose dimensions: 7 | # n = nn.Transpose({1, 4}, {1, 3}) 8 | # will transpose dims 1 and 4,: 1 and 3... 9 | 10 | def __init__(self, *args): 11 | super(Transpose, self).__init__() 12 | self.permutations = args 13 | 14 | def updateOutput(self, input): 15 | for perm in self.permutations: 16 | input = input.transpose(*perm) 17 | self.output.resize_as_(input).copy_(input) 18 | return self.output 19 | 20 | def updateGradInput(self, input, gradOutput): 21 | for perm in self.permutations[::-1]: 22 | gradOutput = gradOutput.transpose(*perm) 23 | self.gradInput.resize_as_(gradOutput).copy_(gradOutput) 24 | return self.gradInput 25 | -------------------------------------------------------------------------------- /torch/legacy/nn/Unsqueeze.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from .Module import Module 3 | from .utils import addSingletondimension 4 | 5 | 6 | class Unsqueeze(Module): 7 | 8 | def __init__(self, dim): 9 | super(Unsqueeze, self).__init__() 10 | self.dim = dim 11 | 12 | def updateOutput(self, input): 13 | addSingletondimension(self.output, input, self.dim) 14 | return self.output 15 | 16 | def updateGradInput(self, input, gradOutput): 17 | assert input.nelement() == gradOutput.nelement() 18 | self.gradInput = gradOutput.contiguous().view(input.size()) 19 | return self.gradInput 20 | 21 | def __repr__(self): 22 | return super(Unsqueeze, self).__repr__() + '({})'.format(self.dim) 23 | -------------------------------------------------------------------------------- /torch/legacy/nn/VolumetricBatchNormalization.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from .Module import Module 3 | from .BatchNormalization import BatchNormalization 4 | 5 | 6 | class VolumetricBatchNormalization(BatchNormalization): 7 | nDim = 5 8 | -------------------------------------------------------------------------------- /torch/legacy/optim/__init__.py: -------------------------------------------------------------------------------- 1 | from .adadelta import adadelta 2 | from .adagrad import adagrad 3 | from .adam import adam 4 | from .adamax import adamax 5 | from .asgd import asgd 6 | from .cg import cg 7 | from .nag import nag 8 | from .rmsprop import rmsprop 9 | from .rprop import rprop 10 | from .sgd import sgd 11 | from .lbfgs import lbfgs 12 | -------------------------------------------------------------------------------- /torch/lib/README.md: -------------------------------------------------------------------------------- 1 | This directory contains the low-level tensor libraries for PyTorch. 2 | This code traces its lineage from the original Torch. There are 3 | multiple variants of the library, summarized here: 4 | 5 | * TH = TorcH 6 | * THC = TorcH Cuda 7 | * THCS = TorcH Cuda Sparse 8 | * THCUNN = TorcH CUda Neural Network (see cunn) 9 | * THD = TorcH Distributed 10 | * THNN = TorcH Neural Network 11 | * THPP = TorcH C++ (note: this library is not the same as https://github.com/facebook/thpp, but rather a standalone C++ wrapper of Torch Tensors) 12 | * THS = TorcH Sparse 13 | 14 | (You'll also see these abbreviations show up in symbol names.) 15 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/lib/TH/THBlas.c: -------------------------------------------------------------------------------- 1 | #include "THBlas.h" 2 | 3 | #include "generic/THBlas.c" 4 | #include "THGenerateAllTypes.h" 5 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/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 uint8_t 6 | #define ureal uint8_t 7 | #define accreal int64_t 8 | #define Real Byte 9 | #define TH_CONVERT_REAL_TO_ACCREAL(_val) (accreal)(_val) 10 | #define TH_CONVERT_ACCREAL_TO_REAL(_val) (real)(_val) 11 | #define THInf UCHAR_MAX 12 | #define TH_REAL_IS_BYTE 13 | #line 1 TH_GENERIC_FILE 14 | #include TH_GENERIC_FILE 15 | #undef real 16 | #undef ureal 17 | #undef accreal 18 | #undef Real 19 | #undef THInf 20 | #undef TH_REAL_IS_BYTE 21 | #undef TH_CONVERT_REAL_TO_ACCREAL 22 | #undef TH_CONVERT_ACCREAL_TO_REAL 23 | 24 | #ifndef THGenerateManyTypes 25 | #undef TH_GENERIC_FILE 26 | #endif 27 | -------------------------------------------------------------------------------- /torch/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 int8_t 6 | #define ureal uint8_t 7 | #define accreal int64_t 8 | #define Real Char 9 | #define THInf CHAR_MAX 10 | #define TH_CONVERT_REAL_TO_ACCREAL(_val) (accreal)(_val) 11 | #define TH_CONVERT_ACCREAL_TO_REAL(_val) (real)(_val) 12 | #define TH_REAL_IS_CHAR 13 | #line 1 TH_GENERIC_FILE 14 | #include TH_GENERIC_FILE 15 | #undef real 16 | #undef ureal 17 | #undef accreal 18 | #undef Real 19 | #undef THInf 20 | #undef TH_REAL_IS_CHAR 21 | #undef TH_CONVERT_REAL_TO_ACCREAL 22 | #undef TH_CONVERT_ACCREAL_TO_REAL 23 | 24 | #ifndef THGenerateManyTypes 25 | #undef TH_GENERIC_FILE 26 | #endif 27 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/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 int32_t 6 | #define ureal uint32_t 7 | #define accreal int64_t 8 | #define TH_CONVERT_REAL_TO_ACCREAL(_val) (accreal)(_val) 9 | #define TH_CONVERT_ACCREAL_TO_REAL(_val) (real)(_val) 10 | #define Real Int 11 | #define THInf INT_MAX 12 | #define TH_REAL_IS_INT 13 | #line 1 TH_GENERIC_FILE 14 | #include TH_GENERIC_FILE 15 | #undef real 16 | #undef ureal 17 | #undef accreal 18 | #undef Real 19 | #undef THInf 20 | #undef TH_REAL_IS_INT 21 | #undef TH_CONVERT_REAL_TO_ACCREAL 22 | #undef TH_CONVERT_ACCREAL_TO_REAL 23 | 24 | #ifndef THGenerateManyTypes 25 | #undef TH_GENERIC_FILE 26 | #endif 27 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/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 int64_t 6 | #define ureal uint64_t 7 | #define accreal int64_t 8 | #define TH_CONVERT_REAL_TO_ACCREAL(_val) (accreal)(_val) 9 | #define TH_CONVERT_ACCREAL_TO_REAL(_val) (real)(_val) 10 | #define Real Long 11 | #define THInf LONG_MAX 12 | #define TH_REAL_IS_LONG 13 | #line 1 TH_GENERIC_FILE 14 | #include TH_GENERIC_FILE 15 | #undef real 16 | #undef ureal 17 | #undef accreal 18 | #undef Real 19 | #undef THInf 20 | #undef TH_REAL_IS_LONG 21 | #undef TH_CONVERT_REAL_TO_ACCREAL 22 | #undef TH_CONVERT_ACCREAL_TO_REAL 23 | 24 | #ifndef THGenerateManyTypes 25 | #undef TH_GENERIC_FILE 26 | #endif 27 | -------------------------------------------------------------------------------- /torch/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 int16_t 6 | #define ureal uint16_t 7 | #define accreal int64_t 8 | #define TH_CONVERT_REAL_TO_ACCREAL(_val) (accreal)(_val) 9 | #define TH_CONVERT_ACCREAL_TO_REAL(_val) (real)(_val) 10 | #define Real Short 11 | #define THInf SHRT_MAX 12 | #define TH_REAL_IS_SHORT 13 | #line 1 TH_GENERIC_FILE 14 | #include TH_GENERIC_FILE 15 | #undef real 16 | #undef ureal 17 | #undef accreal 18 | #undef Real 19 | #undef THInf 20 | #undef TH_REAL_IS_SHORT 21 | #undef TH_CONVERT_REAL_TO_ACCREAL 22 | #undef TH_CONVERT_ACCREAL_TO_REAL 23 | 24 | #ifndef THGenerateManyTypes 25 | #undef TH_GENERIC_FILE 26 | #endif 27 | -------------------------------------------------------------------------------- /torch/lib/TH/THLapack.c: -------------------------------------------------------------------------------- 1 | #include "THLapack.h" 2 | 3 | #include "generic/THLapack.c" 4 | #include "THGenerateFloatTypes.h" 5 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/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 | #endif // _THMATH_H 21 | 22 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/lib/TH/generic/simd/convolve.h: -------------------------------------------------------------------------------- 1 | void convolve_5x5(float* output, float* input, float* kernel, int64_t outRows, int64_t outCols, int64_t inCols); -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/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 | THC_API THCDeviceAllocator THCIpcAllocator; 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /torch/lib/THC/THCCachingAllocator.h: -------------------------------------------------------------------------------- 1 | #ifndef THC_DEVICE_ALLOCATOR_INC 2 | #define THC_DEVICE_ALLOCATOR_INC 3 | 4 | #if (__cplusplus >= 201103L) || (defined(_MSC_VER) && defined(__cplusplus)) 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) || (defined(_MSC_VER) && defined(__cplusplus)) 16 | THC_API std::mutex* THCCachingAllocator_getCudaFreeMutex(); 17 | #endif 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/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 uint8_t 6 | #define accreal int64_t 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 | -------------------------------------------------------------------------------- /torch/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 int8_t 6 | #define accreal int64_t 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 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/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 int32_t 6 | #define accreal int64_t 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 | -------------------------------------------------------------------------------- /torch/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 int64_t 6 | #define accreal int64_t 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 | -------------------------------------------------------------------------------- /torch/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 int16_t 6 | #define accreal int64_t 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 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/lib/THC/THCSleep.cu: -------------------------------------------------------------------------------- 1 | #include "THCSleep.h" 2 | 3 | 4 | __global__ void spin_kernel(int64_t cycles) 5 | { 6 | // see concurrentKernels CUDA sampl 7 | int64_t start_clock = clock64(); 8 | int64_t 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, int64_t cycles) 16 | { 17 | dim3 grid(1); 18 | dim3 block(1); 19 | spin_kernel<<>>(cycles); 20 | THCudaCheck(cudaGetLastError()); 21 | } 22 | -------------------------------------------------------------------------------- /torch/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, int64_t cycles); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /torch/lib/THC/THCSortUtils.cu: -------------------------------------------------------------------------------- 1 | #include "THCSortUtils.cuh" 2 | 3 | // Returns 2^(ceil(lg(n)) from Stanford bit twiddling hacks 4 | uint64_t nextHighestPowerOf2(uint64_t 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 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/lib/THC/THCStorageCopy.c: -------------------------------------------------------------------------------- 1 | #include "THCStorageCopy.h" 2 | 3 | #include "THCTensorCopy.h" 4 | 5 | #include "generic/THCStorageCopy.c" 6 | #include "THCGenerateAllTypes.h" 7 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/lib/THC/THCTensor.cu: -------------------------------------------------------------------------------- 1 | #include "THCTensor.h" 2 | 3 | #include "generic/THCTensor.cu" 4 | #include "THCGenerateAllTypes.h" 5 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/lib/THC/THCTensorCopy.c: -------------------------------------------------------------------------------- 1 | #include "THCTensorCopy.h" 2 | #include "THCCachingHostAllocator.h" 3 | 4 | #include "generic/THCTensorCopy.c" 5 | #include "THCGenerateAllTypes.h" 6 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMaskedByte.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMasked.cuh" 2 | #include "../generic/THCTensorMasked.cu" 3 | #include "../THCGenerateByteType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMaskedChar.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMasked.cuh" 2 | #include "../generic/THCTensorMasked.cu" 3 | #include "../THCGenerateCharType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMaskedDouble.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMasked.cuh" 2 | #include "../generic/THCTensorMasked.cu" 3 | #include "../THCGenerateDoubleType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMaskedFloat.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMasked.cuh" 2 | #include "../generic/THCTensorMasked.cu" 3 | #include "../THCGenerateFloatType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMaskedHalf.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMasked.cuh" 2 | #include "../generic/THCTensorMasked.cu" 3 | #include "../THCGenerateHalfType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMaskedInt.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMasked.cuh" 2 | #include "../generic/THCTensorMasked.cu" 3 | #include "../THCGenerateIntType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMaskedLong.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMasked.cuh" 2 | #include "../generic/THCTensorMasked.cu" 3 | #include "../THCGenerateLongType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMaskedShort.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMasked.cuh" 2 | #include "../generic/THCTensorMasked.cu" 3 | #include "../THCGenerateShortType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMathCompareByte.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathCompare.cuh" 2 | #include "../generic/THCTensorMathCompare.cu" 3 | #include "../THCGenerateByteType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMathCompareChar.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathCompare.cuh" 2 | #include "../generic/THCTensorMathCompare.cu" 3 | #include "../THCGenerateCharType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMathCompareDouble.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathCompare.cuh" 2 | #include "../generic/THCTensorMathCompare.cu" 3 | #include "../THCGenerateDoubleType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMathCompareFloat.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathCompare.cuh" 2 | #include "../generic/THCTensorMathCompare.cu" 3 | #include "../THCGenerateFloatType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMathCompareHalf.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathCompare.cuh" 2 | #include "../generic/THCTensorMathCompare.cu" 3 | #include "../THCGenerateHalfType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMathCompareInt.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathCompare.cuh" 2 | #include "../generic/THCTensorMathCompare.cu" 3 | #include "../THCGenerateIntType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMathCompareLong.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathCompare.cuh" 2 | #include "../generic/THCTensorMathCompare.cu" 3 | #include "../THCGenerateLongType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMathCompareShort.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathCompare.cuh" 2 | #include "../generic/THCTensorMathCompare.cu" 3 | #include "../THCGenerateShortType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMathCompareTByte.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathCompareT.cuh" 2 | #include "../generic/THCTensorMathCompareT.cu" 3 | #include "../THCGenerateByteType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMathCompareTChar.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathCompareT.cuh" 2 | #include "../generic/THCTensorMathCompareT.cu" 3 | #include "../THCGenerateCharType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMathCompareTDouble.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathCompareT.cuh" 2 | #include "../generic/THCTensorMathCompareT.cu" 3 | #include "../THCGenerateDoubleType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMathCompareTFloat.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathCompareT.cuh" 2 | #include "../generic/THCTensorMathCompareT.cu" 3 | #include "../THCGenerateFloatType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMathCompareTHalf.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathCompareT.cuh" 2 | #include "../generic/THCTensorMathCompareT.cu" 3 | #include "../THCGenerateHalfType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMathCompareTInt.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathCompareT.cuh" 2 | #include "../generic/THCTensorMathCompareT.cu" 3 | #include "../THCGenerateIntType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMathCompareTLong.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathCompareT.cuh" 2 | #include "../generic/THCTensorMathCompareT.cu" 3 | #include "../THCGenerateLongType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMathCompareTShort.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathCompareT.cuh" 2 | #include "../generic/THCTensorMathCompareT.cu" 3 | #include "../THCGenerateShortType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMathPointwiseByte.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathPointwise.cuh" 2 | #include "../generic/THCTensorMathPointwise.cu" 3 | #include "../THCGenerateByteType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMathPointwiseChar.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathPointwise.cuh" 2 | #include "../generic/THCTensorMathPointwise.cu" 3 | #include "../THCGenerateCharType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMathPointwiseDouble.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathPointwise.cuh" 2 | #include "../generic/THCTensorMathPointwise.cu" 3 | #include "../THCGenerateDoubleType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMathPointwiseFloat.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathPointwise.cuh" 2 | #include "../generic/THCTensorMathPointwise.cu" 3 | #include "../THCGenerateFloatType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMathPointwiseHalf.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathPointwise.cuh" 2 | #include "../generic/THCTensorMathPointwise.cu" 3 | #include "../THCGenerateHalfType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMathPointwiseInt.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathPointwise.cuh" 2 | #include "../generic/THCTensorMathPointwise.cu" 3 | #include "../THCGenerateIntType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMathPointwiseLong.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathPointwise.cuh" 2 | #include "../generic/THCTensorMathPointwise.cu" 3 | #include "../THCGenerateLongType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMathPointwiseShort.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathPointwise.cuh" 2 | #include "../generic/THCTensorMathPointwise.cu" 3 | #include "../THCGenerateShortType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMathReduceByte.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathReduce.cuh" 2 | #include "../generic/THCTensorMathReduce.cu" 3 | #include "../THCGenerateByteType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMathReduceChar.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathReduce.cuh" 2 | #include "../generic/THCTensorMathReduce.cu" 3 | #include "../THCGenerateCharType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMathReduceDouble.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathReduce.cuh" 2 | #include "../generic/THCTensorMathReduce.cu" 3 | #include "../THCGenerateDoubleType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMathReduceFloat.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathReduce.cuh" 2 | #include "../generic/THCTensorMathReduce.cu" 3 | #include "../THCGenerateFloatType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMathReduceHalf.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathReduce.cuh" 2 | #include "../generic/THCTensorMathReduce.cu" 3 | #include "../THCGenerateHalfType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMathReduceInt.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathReduce.cuh" 2 | #include "../generic/THCTensorMathReduce.cu" 3 | #include "../THCGenerateIntType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMathReduceLong.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathReduce.cuh" 2 | #include "../generic/THCTensorMathReduce.cu" 3 | #include "../THCGenerateLongType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorMathReduceShort.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorMathReduce.cuh" 2 | #include "../generic/THCTensorMathReduce.cu" 3 | #include "../THCGenerateShortType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorSortByte.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorSort.cuh" 2 | #include "../generic/THCTensorSort.cu" 3 | #include "../THCGenerateByteType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorSortChar.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorSort.cuh" 2 | #include "../generic/THCTensorSort.cu" 3 | #include "../THCGenerateCharType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorSortDouble.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorSort.cuh" 2 | #include "../generic/THCTensorSort.cu" 3 | #include "../THCGenerateDoubleType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorSortFloat.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorSort.cuh" 2 | #include "../generic/THCTensorSort.cu" 3 | #include "../THCGenerateFloatType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorSortHalf.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorSort.cuh" 2 | #include "../generic/THCTensorSort.cu" 3 | #include "../THCGenerateHalfType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorSortInt.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorSort.cuh" 2 | #include "../generic/THCTensorSort.cu" 3 | #include "../THCGenerateIntType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorSortLong.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorSort.cuh" 2 | #include "../generic/THCTensorSort.cu" 3 | #include "../THCGenerateLongType.h" 4 | -------------------------------------------------------------------------------- /torch/lib/THC/generated/THCTensorSortShort.cu: -------------------------------------------------------------------------------- 1 | #include "../THCTensorSort.cuh" 2 | #include "../generic/THCTensorSort.cu" 3 | #include "../THCGenerateShortType.h" 4 | -------------------------------------------------------------------------------- /torch/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, int dim); 6 | THC_API void THCTensor_(cumprod)(THCState *state, THCTensor *self, THCTensor *src, int dim); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /torch/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 | 13 | #endif // THC_GENERIC_FILE 14 | -------------------------------------------------------------------------------- /torch/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_(scatterFill)(THCState* state, THCTensor *tensor, int dim, THCudaLongTensor *index, real value); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /torch/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 | -------------------------------------------------------------------------------- /torch/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 | int64_t k, int dim, int dir, int sorted); 12 | 13 | #endif // THC_GENERIC_FILE 14 | -------------------------------------------------------------------------------- /torch/lib/THCS/THCS.h: -------------------------------------------------------------------------------- 1 | #ifndef THCS_INC 2 | #define THCS_INC 3 | 4 | #include 5 | #include "THCSTensor.h" 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /torch/lib/THCS/THCSGenerateByteType.h: -------------------------------------------------------------------------------- 1 | #ifndef THCS_GENERIC_FILE 2 | #error "You must define THCS_GENERIC_FILE before including THGenerateByteType.h" 3 | #endif 4 | 5 | #define real uint8_t 6 | #define accreal int64_t 7 | #define Real Byte 8 | #define CReal CudaByte 9 | #define THCS_REAL_IS_BYTE 10 | #line 1 THCS_GENERIC_FILE 11 | #include THCS_GENERIC_FILE 12 | #undef real 13 | #undef accreal 14 | #undef Real 15 | #undef CReal 16 | #undef THCS_REAL_IS_BYTE 17 | 18 | #ifndef THCSGenerateAllTypes 19 | #undef THCS_GENERIC_FILE 20 | #endif 21 | -------------------------------------------------------------------------------- /torch/lib/THCS/THCSGenerateCharType.h: -------------------------------------------------------------------------------- 1 | #ifndef THCS_GENERIC_FILE 2 | #error "You must define THCS_GENERIC_FILE before including THGenerateCharType.h" 3 | #endif 4 | 5 | #define real int8_t 6 | #define accreal int64_t 7 | #define Real Char 8 | #define CReal CudaChar 9 | #define THCS_REAL_IS_CHAR 10 | #line 1 THCS_GENERIC_FILE 11 | #include THCS_GENERIC_FILE 12 | #undef real 13 | #undef accreal 14 | #undef Real 15 | #undef CReal 16 | #undef THCS_REAL_IS_CHAR 17 | 18 | #ifndef THCSGenerateAllTypes 19 | #undef THCS_GENERIC_FILE 20 | #endif 21 | -------------------------------------------------------------------------------- /torch/lib/THCS/THCSGenerateDoubleType.h: -------------------------------------------------------------------------------- 1 | #ifndef THCS_GENERIC_FILE 2 | #error "You must define THCS_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 THCS_REAL_IS_DOUBLE 10 | #line 1 THCS_GENERIC_FILE 11 | #include THCS_GENERIC_FILE 12 | #undef real 13 | #undef accreal 14 | #undef Real 15 | #undef CReal 16 | #undef THCS_REAL_IS_DOUBLE 17 | 18 | #ifndef THCSGenerateAllTypes 19 | #ifndef THCSGenerateFloatTypes 20 | #undef THCS_GENERIC_FILE 21 | #endif 22 | #endif 23 | -------------------------------------------------------------------------------- /torch/lib/THCS/THCSGenerateFloatType.h: -------------------------------------------------------------------------------- 1 | #ifndef THCS_GENERIC_FILE 2 | #error "You must define THCS_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 THCS_REAL_IS_FLOAT 12 | #line 1 THCS_GENERIC_FILE 13 | #include THCS_GENERIC_FILE 14 | #undef real 15 | #undef accreal 16 | #undef Real 17 | #undef CReal 18 | #undef THCS_REAL_IS_FLOAT 19 | 20 | #ifndef THCSGenerateAllTypes 21 | #ifndef THCSGenerateFloatTypes 22 | #undef THCS_GENERIC_FILE 23 | #endif 24 | #endif 25 | -------------------------------------------------------------------------------- /torch/lib/THCS/THCSGenerateFloatTypes.h: -------------------------------------------------------------------------------- 1 | #ifndef THCS_GENERIC_FILE 2 | #error "You must define THCS_GENERIC_FILE before including THGenerateFloatTypes.h" 3 | #endif 4 | 5 | #define THCSGenerateFloatTypes 6 | 7 | #define THCSTypeIdxByte 1 8 | #define THCSTypeIdxChar 2 9 | #define THCSTypeIdxShort 3 10 | #define THCSTypeIdxInt 4 11 | #define THCSTypeIdxLong 5 12 | #define THCSTypeIdxFloat 6 13 | #define THCSTypeIdxDouble 7 14 | #define THCSTypeIdxHalf 8 15 | #define THCSTypeIdx_(T) TH_CONCAT_2(THCSTypeIdx,T) 16 | 17 | #include "THCSGenerateHalfType.h" 18 | #include "THCSGenerateFloatType.h" 19 | #include "THCSGenerateDoubleType.h" 20 | 21 | #undef THCSTypeIdxByte 22 | #undef THCSTypeIdxChar 23 | #undef THCSTypeIdxShort 24 | #undef THCSTypeIdxInt 25 | #undef THCSTypeIdxLong 26 | #undef THCSTypeIdxFloat 27 | #undef THCSTypeIdxDouble 28 | #undef THCSTypeIdxHalf 29 | #undef THCSTypeIdx_ 30 | 31 | #undef THCSGenerateFloatTypes 32 | #undef THCS_GENERIC_FILE 33 | -------------------------------------------------------------------------------- /torch/lib/THCS/THCSGenerateHalfType.h: -------------------------------------------------------------------------------- 1 | #ifndef THCS_GENERIC_FILE 2 | #error "You must define THCS_GENERIC_FILE before including THGenerateHalfType.h" 3 | #endif 4 | 5 | #include 6 | 7 | #ifdef CUDA_HALF_TENSOR 8 | 9 | #define real half 10 | #define accreal float 11 | #define Real Half 12 | #define CReal CudaHalf 13 | #define THCS_REAL_IS_HALF 14 | #line 1 THCS_GENERIC_FILE 15 | #include THCS_GENERIC_FILE 16 | #undef real 17 | #undef accreal 18 | #undef Real 19 | #undef CReal 20 | #undef THCS_REAL_IS_HALF 21 | 22 | #endif // CUDA_HALF_TENSOR 23 | 24 | #ifndef THCSGenerateAllTypes 25 | #ifndef THCSGenerateFloatTypes 26 | #undef THCS_GENERIC_FILE 27 | #endif 28 | #endif 29 | -------------------------------------------------------------------------------- /torch/lib/THCS/THCSGenerateIntType.h: -------------------------------------------------------------------------------- 1 | #ifndef THCS_GENERIC_FILE 2 | #error "You must define THCS_GENERIC_FILE before including THGenerateIntType.h" 3 | #endif 4 | 5 | #define real int32_t 6 | #define accreal int64_t 7 | #define Real Int 8 | #define CReal CudaInt 9 | #define THCS_REAL_IS_INT 10 | #line 1 THCS_GENERIC_FILE 11 | #include THCS_GENERIC_FILE 12 | #undef real 13 | #undef accreal 14 | #undef Real 15 | #undef CReal 16 | #undef THCS_REAL_IS_INT 17 | 18 | #ifndef THCSGenerateAllTypes 19 | #undef THCS_GENERIC_FILE 20 | #endif 21 | -------------------------------------------------------------------------------- /torch/lib/THCS/THCSGenerateLongType.h: -------------------------------------------------------------------------------- 1 | #ifndef THCS_GENERIC_FILE 2 | #error "You must define THCS_GENERIC_FILE before including THGenerateLongType.h" 3 | #endif 4 | 5 | #define real int64_t 6 | #define accreal int64_t 7 | #define Real Long 8 | #define CReal CudaLong 9 | #define THCS_REAL_IS_LONG 10 | #line 1 THCS_GENERIC_FILE 11 | #include THCS_GENERIC_FILE 12 | #undef real 13 | #undef accreal 14 | #undef Real 15 | #undef CReal 16 | #undef THCS_REAL_IS_LONG 17 | 18 | #ifndef THCSGenerateAllTypes 19 | #undef THCS_GENERIC_FILE 20 | #endif 21 | -------------------------------------------------------------------------------- /torch/lib/THCS/THCSGenerateShortType.h: -------------------------------------------------------------------------------- 1 | #ifndef THCS_GENERIC_FILE 2 | #error "You must define THCS_GENERIC_FILE before including THGenerateShortType.h" 3 | #endif 4 | 5 | #define real int16_t 6 | #define accreal int64_t 7 | #define Real Short 8 | #define CReal CudaShort 9 | #define THCS_REAL_IS_SHORT 10 | #line 1 THCS_GENERIC_FILE 11 | #include THCS_GENERIC_FILE 12 | #undef real 13 | #undef accreal 14 | #undef Real 15 | #undef CReal 16 | #undef THCS_REAL_IS_SHORT 17 | 18 | #ifndef THCSGenerateAllTypes 19 | #undef THCS_GENERIC_FILE 20 | #endif 21 | -------------------------------------------------------------------------------- /torch/lib/THCS/THCSTensor.c: -------------------------------------------------------------------------------- 1 | #include "THCSTensor.h" 2 | 3 | #include "generic/THCSTensor.c" 4 | #include "THCSGenerateAllTypes.h" 5 | -------------------------------------------------------------------------------- /torch/lib/THCS/THCSTensor.h: -------------------------------------------------------------------------------- 1 | #ifndef THCS_TENSOR_INC 2 | #define THCS_TENSOR_INC 3 | 4 | #include 5 | #include 6 | 7 | #include "THCSparse.h" 8 | 9 | #define THCSTensor TH_CONCAT_3(THCS,Real,Tensor) 10 | #define THCSTensor_(NAME) TH_CONCAT_4(THCS,Real,Tensor_,NAME) 11 | 12 | #define THCIndexTensor THCudaLongTensor 13 | #define THCIndexTensor_(NAME) TH_CONCAT_2(THCudaLongTensor_,NAME) 14 | #define indexT int64_t 15 | 16 | #include "generic/THCSTensor.h" 17 | #include "THCSGenerateAllTypes.h" 18 | 19 | #include "generic/THCSTensorMath.h" 20 | #include "THCSGenerateAllTypes.h" 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /torch/lib/THCS/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 | -------------------------------------------------------------------------------- /torch/lib/THCUNN/Abs.cu: -------------------------------------------------------------------------------- 1 | #include "THCUNN.h" 2 | #include "THCHalf.h" 3 | #include "THCHalfAutoNumerics.cuh" 4 | #include 5 | 6 | template 7 | struct absupdateOutput_functor 8 | { 9 | __device__ void operator()(T* output, const T* input) const 10 | { 11 | *output = abs(*input); 12 | } 13 | }; 14 | 15 | template 16 | struct absupdateGradInput_functor 17 | { 18 | __device__ void operator()(T* gradInput, const T* input, const T* gradOutput) const 19 | { 20 | *gradInput = *input < 0 ? - *gradOutput : *gradOutput; 21 | } 22 | }; 23 | 24 | #include "generic/Abs.cu" 25 | #include "THCGenerateFloatTypes.h" 26 | -------------------------------------------------------------------------------- /torch/lib/THCUNN/AbsCriterion.cu: -------------------------------------------------------------------------------- 1 | #include "THCUNN.h" 2 | #include "common.h" 3 | #include "THCHalf.h" 4 | #include "THCHalfAutoNumerics.cuh" 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | template 13 | struct abs_functor 14 | { 15 | __host__ __device__ Acctype operator()(const Dtype& x, const Dtype& y) const 16 | { 17 | Dtype z = x-y; 18 | return ScalarConvert::to(z >= 0 ? z : -z); 19 | } 20 | }; 21 | 22 | template 23 | struct abs_updateGradInput_functor 24 | { 25 | const Dtype norm; 26 | 27 | abs_updateGradInput_functor(Dtype norm_) 28 | : norm(norm_) 29 | {} 30 | 31 | __host__ __device__ Dtype operator()(const Dtype& x, const Dtype& y) const 32 | { 33 | return (x - y) >= 0 ? norm : -norm; 34 | } 35 | }; 36 | 37 | #include "generic/AbsCriterion.cu" 38 | #include "THCGenerateFloatTypes.h" 39 | -------------------------------------------------------------------------------- /torch/lib/THCUNN/L1Cost.cu: -------------------------------------------------------------------------------- 1 | #include "THCUNN.h" 2 | #include "common.h" 3 | #include "THCHalf.h" 4 | #include "THCHalfAutoNumerics.cuh" 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | template 11 | struct l1cost_functor 12 | { 13 | __host__ __device__ Acctype operator()(Dtype x) const 14 | { 15 | return THCNumerics::abs(ScalarConvert::to(x)); 16 | } 17 | }; 18 | 19 | template 20 | struct l1cost_updateGradInput_functor 21 | { 22 | __host__ __device__ Dtype operator()(Dtype x) const 23 | { 24 | if (x > 0) 25 | return ScalarConvert::to(1); 26 | else if (x < 0) 27 | return ScalarConvert::to(-1); 28 | else 29 | return ScalarConvert::to(0); 30 | } 31 | }; 32 | 33 | #include "generic/L1Cost.cu" 34 | #include "THCGenerateFloatTypes.h" 35 | -------------------------------------------------------------------------------- /torch/lib/THCUNN/SharedMem.cuh: -------------------------------------------------------------------------------- 1 | // Based on the simpleTempltes CUDA example 2 | 3 | #ifndef THCUNN_SHAREDMEM_H 4 | #define THCUNN_SHAREDMEM_H 5 | 6 | template 7 | struct SharedMem { 8 | __device__ T *getPointer() 9 | { 10 | extern __device__ void error(void); 11 | error(); 12 | return NULL; 13 | } 14 | }; 15 | 16 | #ifdef CUDA_HALF_TENSOR 17 | template <> 18 | struct SharedMem 19 | { 20 | __device__ half *getPointer() { 21 | extern __shared__ half s_half[]; 22 | return s_half; 23 | } 24 | }; 25 | #endif 26 | 27 | template <> 28 | struct SharedMem 29 | { 30 | __device__ float *getPointer() { 31 | extern __shared__ float s_float[]; 32 | return s_float; 33 | } 34 | }; 35 | 36 | template <> 37 | struct SharedMem 38 | { 39 | __device__ double *getPointer() { 40 | extern __shared__ double s_double[]; 41 | return s_double; 42 | } 43 | }; 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /torch/lib/THCUNN/SpatialConvolutionLocal.cu: -------------------------------------------------------------------------------- 1 | #include "THCUNN.h" 2 | #include "common.h" 3 | #include "im2col.h" 4 | 5 | #include "THCHalf.h" 6 | #include "THCHalfAutoNumerics.cuh" 7 | 8 | #include "generic/SpatialConvolutionLocal.cu" 9 | #include "THCGenerateFloatTypes.h" 10 | -------------------------------------------------------------------------------- /torch/lib/THCUNN/SpatialConvolutionMM.cu: -------------------------------------------------------------------------------- 1 | #include "THCUNN.h" 2 | #include "common.h" 3 | #include "im2col.h" 4 | 5 | #include "THCHalf.h" 6 | #include "THCHalfAutoNumerics.cuh" 7 | 8 | #include "generic/SpatialConvolutionMM.cu" 9 | #include "THCGenerateFloatTypes.h" 10 | -------------------------------------------------------------------------------- /torch/lib/THCUNN/SpatialDilatedConvolution.cu: -------------------------------------------------------------------------------- 1 | #include "THCUNN.h" 2 | #include "common.h" 3 | #include "im2col.h" 4 | 5 | #include "THCHalf.h" 6 | #include "THCHalfAutoNumerics.cuh" 7 | 8 | #include "generic/SpatialDilatedConvolution.cu" 9 | #include "THCGenerateFloatTypes.h" 10 | -------------------------------------------------------------------------------- /torch/lib/THCUNN/SpatialFullConvolution.cu: -------------------------------------------------------------------------------- 1 | #include "THCUNN.h" 2 | #include "im2col.h" 3 | 4 | #include "THCHalf.h" 5 | #include "THCHalfAutoNumerics.cuh" 6 | 7 | #include "generic/SpatialFullConvolution.cu" 8 | #include "THCGenerateFloatTypes.h" 9 | -------------------------------------------------------------------------------- /torch/lib/THCUNN/SpatialMaxPooling.cu: -------------------------------------------------------------------------------- 1 | #include "THCUNN.h" 2 | 3 | #include "generic/SpatialMaxPooling.cu" 4 | #include "THCGenerateFloatTypes.h" 5 | -------------------------------------------------------------------------------- /torch/lib/THCUNN/Sqrt.cu: -------------------------------------------------------------------------------- 1 | #include "THCUNN.h" 2 | #include "THCHalf.h" 3 | #include "THCHalfAutoNumerics.cuh" 4 | #include 5 | 6 | template 7 | struct sqrtupdateOutput_functor 8 | { 9 | const T bias; 10 | 11 | sqrtupdateOutput_functor(T bias_) 12 | : bias(bias_) 13 | {} 14 | 15 | __device__ void operator()(T *output, const T *input) const 16 | { 17 | *output = sqrt(*input + bias); 18 | } 19 | }; 20 | 21 | template 22 | struct sqrtupdateGradInput_functor 23 | { 24 | sqrtupdateGradInput_functor() {} 25 | 26 | __device__ void operator()(T *gradInput, const T *output, const T *gradOutput) const 27 | { 28 | *gradInput = (THCNumerics::eq(*output,ScalarConvert::to(0.0f))) ? ScalarConvert::to(0.0f) : ((ScalarConvert::to(0.5f) * *gradOutput) / *output); 29 | } 30 | }; 31 | 32 | #include "generic/Sqrt.cu" 33 | #include "THCGenerateFloatTypes.h" 34 | -------------------------------------------------------------------------------- /torch/lib/THCUNN/Square.cu: -------------------------------------------------------------------------------- 1 | #include "THCUNN.h" 2 | #include "THCHalf.h" 3 | #include "THCHalfAutoNumerics.cuh" 4 | #include 5 | 6 | template 7 | struct squareupdateOutput_functor 8 | { 9 | __device__ void operator()(T* output, const T* input) const 10 | { 11 | *output = (*input) * (*input); 12 | } 13 | }; 14 | 15 | template 16 | struct squareupdateGradInput_functor 17 | { 18 | __device__ void operator()(T* gradInput, const T* input, const T* gradOutput) const 19 | { 20 | *gradInput = ScalarConvert::to(2.0) * (*gradOutput) * (*input); 21 | } 22 | }; 23 | 24 | #include "generic/Square.cu" 25 | #include "THCGenerateFloatTypes.h" 26 | -------------------------------------------------------------------------------- /torch/lib/THCUNN/THCUNN.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define THCIndexTensor THCudaLongTensor 4 | #define THCIndexTensor_(NAME) THCudaLongTensor_ ## NAME 5 | typedef int64_t THCIndex_t; 6 | 7 | #define THNN_(NAME) TH_CONCAT_3(THNN_, CReal, NAME) 8 | 9 | #include "generic/THCUNN.h" 10 | #include 11 | -------------------------------------------------------------------------------- /torch/lib/THCUNN/TemporalConvolution.cu: -------------------------------------------------------------------------------- 1 | #include "THCUNN.h" 2 | #include "common.h" 3 | #include "THCHalf.h" 4 | #include "THCHalfAutoNumerics.cuh" 5 | 6 | #include "generic/TemporalConvolution.cu" 7 | #include "THCGenerateFloatTypes.h" 8 | -------------------------------------------------------------------------------- /torch/lib/THCUNN/TemporalRowConvolution.cu: -------------------------------------------------------------------------------- 1 | #include "THCUNN.h" 2 | #include "common.h" 3 | #include "row2col.h" 4 | 5 | #include "THCHalf.h" 6 | #include "THCHalfAutoNumerics.cuh" 7 | 8 | #include "generic/TemporalRowConvolution.cu" 9 | 10 | #include "THCGenerateFloatTypes.h" 11 | -------------------------------------------------------------------------------- /torch/lib/THCUNN/VolumetricDilatedConvolution.cu: -------------------------------------------------------------------------------- 1 | #include "THCUNN.h" 2 | #include "common.h" 3 | #include "vol2col.h" 4 | #include "THCHalf.h" 5 | #include "THCHalfAutoNumerics.cuh" 6 | 7 | #include "generic/VolumetricDilatedConvolution.cu" 8 | #include "THCGenerateFloatTypes.h" 9 | -------------------------------------------------------------------------------- /torch/lib/THCUNN/VolumetricFullConvolution.cu: -------------------------------------------------------------------------------- 1 | #include "THCUNN.h" 2 | #include "common.h" 3 | #include "vol2col.h" 4 | #include "THCHalf.h" 5 | #include "THCHalfAutoNumerics.cuh" 6 | 7 | #include "generic/VolumetricFullConvolution.cu" 8 | #include "THCGenerateFloatTypes.h" 9 | -------------------------------------------------------------------------------- /torch/lib/THCUNN/VolumetricMaxPooling.cu: -------------------------------------------------------------------------------- 1 | #include "THCUNN.h" 2 | #include "common.h" 3 | #include "THCDeviceTensor.cuh" 4 | #include "THCDeviceTensorUtils.cuh" 5 | #include "THCDeviceUtils.cuh" 6 | 7 | #include 8 | 9 | #include "generic/VolumetricMaxPooling.cu" 10 | #include "THCGenerateFloatTypes.h" 11 | -------------------------------------------------------------------------------- /torch/lib/THCUNN/generic/Abs.cu: -------------------------------------------------------------------------------- 1 | #ifndef THC_GENERIC_FILE 2 | #define THC_GENERIC_FILE "generic/Abs.cu" 3 | #else 4 | 5 | #include "../common.h" 6 | 7 | void THNN_(Abs_updateOutput)( 8 | THCState *state, 9 | THCTensor *input, 10 | THCTensor *output) 11 | { 12 | THCUNN_assertSameGPU(state, 2, input, output); 13 | THCTensor_(resizeAs)(state, output, input); 14 | THC_pointwiseApply2(state, output, input, absupdateOutput_functor()); 15 | } 16 | 17 | void THNN_(Abs_updateGradInput)( 18 | THCState *state, 19 | THCTensor *input, 20 | THCTensor *gradOutput, 21 | THCTensor *gradInput) 22 | { 23 | THCUNN_check_nElement(state, input, gradOutput); 24 | THCUNN_assertSameGPU(state, 3, input, gradOutput, gradInput); 25 | THCTensor_(resizeAs)(state, gradInput, input); 26 | THC_pointwiseApply3(state, gradInput, input, gradOutput, absupdateGradInput_functor()); 27 | } 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /torch/lib/THCUNN/generic/Sigmoid.cu: -------------------------------------------------------------------------------- 1 | #ifndef THC_GENERIC_FILE 2 | #define THC_GENERIC_FILE "generic/Sigmoid.cu" 3 | #else 4 | 5 | #include "../common.h" 6 | 7 | void THNN_(Sigmoid_updateOutput)( 8 | THCState *state, 9 | THCTensor *input, 10 | THCTensor *output) 11 | { 12 | THCUNN_assertSameGPU(state, 2, input, output); 13 | THCTensor_(sigmoid)(state, output, input); 14 | } 15 | 16 | void THNN_(Sigmoid_updateGradInput)( 17 | THCState *state, 18 | THCTensor *input, 19 | THCTensor *gradOutput, 20 | THCTensor *gradInput, 21 | THCTensor *output) 22 | { 23 | THCUNN_check_nElement(state, output, gradOutput); 24 | THCUNN_assertSameGPU(state, 3, output, gradOutput, gradInput); 25 | THCTensor_(resizeAs)(state, gradInput, output); 26 | THC_pointwiseApply3(state, gradInput, output, gradOutput, sigmoid_updateGradInput_functor()); 27 | } 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /torch/lib/THCUNN/generic/Square.cu: -------------------------------------------------------------------------------- 1 | #ifndef THC_GENERIC_FILE 2 | #define THC_GENERIC_FILE "generic/Square.cu" 3 | #else 4 | 5 | #include "../common.h" 6 | 7 | void THNN_(Square_updateOutput)( 8 | THCState *state, 9 | THCTensor *input, 10 | THCTensor *output) 11 | { 12 | THCUNN_assertSameGPU(state, 2, input, output); 13 | THCTensor_(resizeAs)(state, output, input); 14 | THC_pointwiseApply2(state, output, input, squareupdateOutput_functor()); 15 | } 16 | 17 | void THNN_(Square_updateGradInput)( 18 | THCState *state, 19 | THCTensor *input, 20 | THCTensor *gradOutput, 21 | THCTensor *gradInput) 22 | { 23 | THCUNN_check_shape(state, input, gradOutput); 24 | THCUNN_assertSameGPU(state, 3, input, gradOutput, gradInput); 25 | THCTensor_(resizeAs)(state, gradInput, input); 26 | THC_pointwiseApply3(state, gradInput, input, gradOutput, squareupdateGradInput_functor()); 27 | } 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /torch/lib/THCUNN/generic/Tanh.cu: -------------------------------------------------------------------------------- 1 | #ifndef THC_GENERIC_FILE 2 | #define THC_GENERIC_FILE "generic/Tanh.cu" 3 | #else 4 | 5 | #include "../common.h" 6 | 7 | void THNN_(Tanh_updateOutput)( 8 | THCState *state, 9 | THCTensor *input, 10 | THCTensor *output) 11 | { 12 | THCUNN_assertSameGPU(state, 2, input, output); 13 | THCTensor_(resizeAs)(state, output, input); 14 | THCTensor_(tanh)(state, output, input); 15 | } 16 | 17 | void THNN_(Tanh_updateGradInput)( 18 | THCState *state, 19 | THCTensor *input, 20 | THCTensor *gradOutput, 21 | THCTensor *gradInput, 22 | THCTensor *output) 23 | { 24 | THCUNN_check_shape(state, output, gradOutput); 25 | THCUNN_assertSameGPU(state, 3, output, gradOutput, gradInput); 26 | THCTensor_(resizeAs)(state, gradInput, output); 27 | THC_pointwiseApply3(state, gradInput, output, gradOutput, tanh_updateGradInput_functor()); 28 | } 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /torch/lib/THD/README.md: -------------------------------------------------------------------------------- 1 | # Dependecies 2 | 3 | - Asio C++ Library 4 | 5 | ## macOS 6 | 7 | ``` 8 | brew install asio 9 | ``` 10 | -------------------------------------------------------------------------------- /torch/lib/THD/THD.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __cplusplus 4 | #define THD_API extern "C" 5 | #else 6 | #define THD_API 7 | #endif 8 | 9 | #ifndef _THD_CORE 10 | #include "base/TensorDescriptor.h" 11 | #include "base/DataChannelRequest.h" 12 | #else 13 | #include "base/TensorDescriptor.hpp" 14 | #include "base/DataChannelRequest.hpp" 15 | #endif 16 | #include "base/ChannelType.h" 17 | 18 | #include "process_group/General.h" 19 | #include "process_group/Collectives.h" 20 | 21 | #include "master_worker/master/Master.h" 22 | #include "master_worker/master/State.h" 23 | #include "master_worker/master/THDRandom.h" 24 | #include "master_worker/master/THDStorage.h" 25 | #include "master_worker/master/THDTensor.h" 26 | 27 | #include "master_worker/worker/Worker.h" 28 | -------------------------------------------------------------------------------- /torch/lib/THD/base/ChannelEnvVars.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace thd { 4 | 5 | constexpr char RANK_ENV[] = "RANK"; 6 | constexpr char WORLD_SIZE_ENV[] = "WORLD_SIZE"; 7 | constexpr char MASTER_PORT_ENV[] = "MASTER_PORT"; 8 | constexpr char MASTER_ADDR_ENV[] = "MASTER_ADDR"; 9 | 10 | } 11 | -------------------------------------------------------------------------------- /torch/lib/THD/base/ChannelType.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | enum THDChannelType { 4 | THDChannelTCP = 0, 5 | THDChannelMPI, 6 | THDChannelGloo 7 | }; 8 | -------------------------------------------------------------------------------- /torch/lib/THD/base/DataChannel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | enum THDReduceOp { 4 | THDReduceMIN = 0, 5 | THDReduceMAX, 6 | THDReduceSUM, 7 | THDReducePRODUCT, 8 | }; 9 | 10 | typedef int THDGroup; 11 | const THDGroup THDGroupWORLD = 0; 12 | -------------------------------------------------------------------------------- /torch/lib/THD/base/DataChannelRequest.cpp: -------------------------------------------------------------------------------- 1 | #include "DataChannelRequest.hpp" 2 | 3 | 4 | THD_API void THDRequest_free(THDRequest* request) { 5 | delete request; 6 | } 7 | -------------------------------------------------------------------------------- /torch/lib/THD/base/DataChannelRequest.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../THD.h" 4 | 5 | #ifndef _THD_CORE 6 | struct _THDRequest; 7 | typedef struct _THDRequest THDRequest; 8 | #endif 9 | 10 | THD_API void THDRequest_free(THDRequest* req); 11 | -------------------------------------------------------------------------------- /torch/lib/THD/base/DataChannelRequest.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "DataChannel.hpp" 4 | using THDRequest = thd::DataChannel::Request; 5 | 6 | #include "DataChannelRequest.h" 7 | -------------------------------------------------------------------------------- /torch/lib/THD/base/TensorDescriptor.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | using THDTensorDescriptor = thpp::Tensor; 5 | 6 | #include "TensorDescriptor.h" 7 | -------------------------------------------------------------------------------- /torch/lib/THD/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ $(basename $(pwd)) != "THD" ]]; then 4 | echo "The build script has to be executed from the root directory of THD!" 5 | exit 2 6 | fi 7 | 8 | cd .. 9 | lib_dir="$(pwd)" 10 | cd THD 11 | 12 | mkdir -p build 13 | cd build 14 | 15 | LD_POSTFIX=".so.1" 16 | if [[ $(uname) == 'Darwin' ]]; then 17 | LD_POSTFIX=".1.dylib" 18 | fi 19 | 20 | cmake .. -DCMAKE_CXX_FLAGS=" -I${lib_dir}/tmp_install/include -pthread \ 21 | -I${lib_dir}/THPP " \ 22 | -DCMAKE_SHARED_LINKER_FLAGS="-L${lib_dir}/tmp_install/lib " \ 23 | -DCMAKE_EXE_LINKER_FLAGS="-L${lib_dir}/tmp_install/lib -pthread " \ 24 | -DTH_LIBRARIES="${lib_dir}/libTH$LD_POSTFIX" \ 25 | -DTHC_LIBRARIES="${lib_dir}/libTHC$LD_POSTFIX" \ 26 | -DTHPP_LIBRARIES="${lib_dir}/libTHPP$LD_POSTFIX" \ 27 | -DTHD_WITH_TESTS="1" \ 28 | -DTorch_FOUND="1" 29 | make 30 | -------------------------------------------------------------------------------- /torch/lib/THD/cmake/FindGloo.cmake: -------------------------------------------------------------------------------- 1 | IF(NOT GLOO_FOUND) 2 | 3 | include(FindPackageHandleStandardArgs) 4 | 5 | SET(GLOO_LIBRARIES) 6 | SET(GLOO_INCLUDE_DIR) 7 | 8 | FIND_LIBRARY(GLOO_HOST_LIBRARIES gloo) 9 | FIND_LIBRARY(GLOO_CUDA_LIBRARIES gloo_cuda) 10 | FIND_PATH(GLOO_INCLUDE_DIR gloo) 11 | SET(GLOO_LIBRARIES ${GLOO_HOST_LIBRARIES} ${GLOO_CUDA_LIBRARIES}) 12 | 13 | IF (GLOO_LIBRARIES) 14 | SET(GLOO_FOUND TRUE) 15 | ELSE (GLOO_LIBRARIES) 16 | SET(GLOO_FOUND FALSE) 17 | ENDIF (GLOO_LIBRARIES) 18 | 19 | MESSAGE(STATUS "Found Gloo: ${GLOO_FOUND}") 20 | 21 | ENDIF(NOT GLOO_FOUND) 22 | 23 | -------------------------------------------------------------------------------- /torch/lib/THD/master_worker/common/ByteArray.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace thd { namespace rpc { 7 | 8 | struct ByteArray { 9 | using size_type = std::size_t; 10 | 11 | ByteArray(); 12 | ByteArray(std::size_t size); 13 | ByteArray(const char* arr, std::size_t size); 14 | ByteArray(ByteArray&& arr); 15 | ByteArray(const ByteArray& arr); 16 | ~ByteArray(); 17 | 18 | ByteArray& append(const char* arr, std::size_t size); 19 | const char* data() const; 20 | size_type length() const; 21 | 22 | std::string to_string() const; 23 | 24 | private: 25 | std::string _data; 26 | }; 27 | 28 | }} // namespace rpc, thd 29 | 30 | -------------------------------------------------------------------------------- /torch/lib/THD/master_worker/master/Master.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../../THD.h" 4 | 5 | THD_API bool THDMasterWorkerInit(THDChannelType channel_type); 6 | -------------------------------------------------------------------------------- /torch/lib/THD/master_worker/master/Master.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../common/CommandChannel.hpp" 4 | #include "../../base/DataChannel.hpp" 5 | 6 | #include 7 | 8 | namespace thd { 9 | namespace master { 10 | 11 | extern std::unique_ptr masterCommandChannel; 12 | 13 | } // namespace master 14 | } // namespace thd 15 | -------------------------------------------------------------------------------- /torch/lib/THD/master_worker/master/State.cpp: -------------------------------------------------------------------------------- 1 | #include "State.hpp" 2 | 3 | #include 4 | #include 5 | 6 | namespace thd { 7 | namespace master { 8 | 9 | thread_local size_t THDState::s_current_worker = 1; 10 | std::uint64_t THDState::s_nextId = 0; 11 | 12 | } // namespace master 13 | } // namespace thd 14 | -------------------------------------------------------------------------------- /torch/lib/THD/master_worker/master/State.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | THD_API int THDGetNode(); 4 | THD_API int THDSetNode(); 5 | THD_API int THDGetDevice(); 6 | THD_API int THDSetDevice(); 7 | -------------------------------------------------------------------------------- /torch/lib/THD/master_worker/master/State.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace thd { 8 | namespace master { 9 | 10 | struct WorkerState { 11 | }; 12 | 13 | struct THDState { 14 | static std::vector s_workers; 15 | thread_local static std::size_t s_current_worker; 16 | static std::uint64_t s_nextId; 17 | }; 18 | 19 | } // namespace master 20 | } // namespace thd 21 | -------------------------------------------------------------------------------- /torch/lib/THD/master_worker/master/THDRandom.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "../../THD.h" 5 | 6 | typedef struct THDGenerator { 7 | // Additional fields 8 | unsigned long long generator_id; 9 | } THDGenerator; 10 | 11 | /* Manipulate THDGenerator objects */ 12 | THD_API THDGenerator * THDGenerator_new(void); 13 | THD_API THDGenerator * THDGenerator_copy(THDGenerator *self, THDGenerator *from); 14 | THD_API void THDGenerator_free(THDGenerator *gen); 15 | 16 | /* Initializes the random number generator from /dev/urandom (or on Windows 17 | platforms with the current time (granularity: seconds)) and returns the seed. */ 18 | THD_API unsigned long THDRandom_seed(THDGenerator *_generator); 19 | 20 | /* Initializes the random number generator with the given long "the_seed_". */ 21 | THD_API void THDRandom_manualSeed(THDGenerator *_generator, unsigned long the_seed_); 22 | -------------------------------------------------------------------------------- /torch/lib/THD/master_worker/master/THDStorage.cpp: -------------------------------------------------------------------------------- 1 | #include "THD.h" 2 | #include "State.hpp" 3 | #include "Utils.hpp" 4 | #include "master_worker/common/RPC.hpp" 5 | #include "master_worker/common/Functions.hpp" 6 | #include "master_worker/master/Master.hpp" 7 | #include "process_group/General.hpp" 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | #include "master_worker/master/generic/THDStorage.cpp" 15 | #include "TH/THGenerateAllTypes.h" 16 | 17 | -------------------------------------------------------------------------------- /torch/lib/THD/master_worker/master/THDStorage.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "../../THD.h" 5 | 6 | #define THDStorage TH_CONCAT_3(THD,Real,Storage) 7 | #define THDStorage_(NAME) TH_CONCAT_4(THD,Real,Storage_,NAME) 8 | 9 | #include "generic/THDStorage.h" 10 | #include 11 | -------------------------------------------------------------------------------- /torch/lib/THD/master_worker/master/THDTensor.cpp: -------------------------------------------------------------------------------- 1 | #include "THDTensor.h" 2 | #include "State.hpp" 3 | #include "Utils.hpp" 4 | #include "master_worker/common/RPC.hpp" 5 | #include "master_worker/common/Functions.hpp" 6 | #include "master_worker/master/Master.hpp" 7 | #include "process_group/General.hpp" 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | #include "master_worker/master/generic/THDTensorMeta.cpp" 15 | #include "TH/THGenerateAllTypes.h" 16 | 17 | #include "master_worker/master/generic/THDTensor.cpp" 18 | #include "TH/THGenerateAllTypes.h" 19 | 20 | #include "master_worker/master/generic/THDTensorCopy.cpp" 21 | #include "TH/THGenerateAllTypes.h" 22 | 23 | #include "master_worker/master/generic/THDTensorRandom.cpp" 24 | #include "TH/THGenerateAllTypes.h" 25 | 26 | #include "master_worker/master/generic/THDTensorMath.cpp" 27 | #include "TH/THGenerateAllTypes.h" 28 | 29 | #include "master_worker/master/generic/THDTensorLapack.cpp" 30 | #include "TH/THGenerateFloatTypes.h" 31 | -------------------------------------------------------------------------------- /torch/lib/THD/master_worker/master/THDTensor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "../../THD.h" 5 | 6 | #define THDTensor TH_CONCAT_3(THD,Real,Tensor) 7 | #define THDTensor_(NAME) TH_CONCAT_4(THD,Real,Tensor_,NAME) 8 | 9 | #define THD_DESC_BUFF_LEN 64 10 | typedef struct { 11 | char str[THD_DESC_BUFF_LEN]; 12 | } THDDescBuff; 13 | 14 | #include "generic/THDTensor.h" 15 | #include 16 | 17 | #include "generic/THDTensorCopy.h" 18 | #include 19 | 20 | #include "generic/THDTensorRandom.h" 21 | #include 22 | 23 | #include "generic/THDTensorMath.h" 24 | #include 25 | 26 | #include "generic/THDTensorLapack.h" 27 | #include 28 | -------------------------------------------------------------------------------- /torch/lib/THD/master_worker/master/Utils.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "process_group/General.hpp" 4 | 5 | #include 6 | 7 | template 8 | T receiveValueFromWorker(int worker_id) { 9 | thpp::Type type = thpp::type_traits::type; 10 | if (thpp::isInteger(type)) { 11 | thd::IntScalar wrapped_value; 12 | thd::dataChannel->receive(wrapped_value, worker_id); 13 | return static_cast(wrapped_value.value()); 14 | } else if (thpp::isFloat(type)) { 15 | thd::FloatScalar wrapped_value; 16 | thd::dataChannel->receive(wrapped_value, worker_id); 17 | return static_cast(wrapped_value.value()); 18 | } else { 19 | throw std::invalid_argument("expected scalar type"); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /torch/lib/THD/master_worker/master/generic/THDTensorCopy.cpp: -------------------------------------------------------------------------------- 1 | #ifndef TH_GENERIC_FILE 2 | #define TH_GENERIC_FILE "master_worker/master/generic/THDTensorCopy.cpp" 3 | #else 4 | 5 | // TODO implement 6 | void THDTensor_(copy)(THDTensor *tensor, THDTensor *src) { 7 | throw std::runtime_error("copy not implemented yet"); 8 | } 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /torch/lib/THD/master_worker/master/generic/THDTensorCopy.h: -------------------------------------------------------------------------------- 1 | #ifndef TH_GENERIC_FILE 2 | #define TH_GENERIC_FILE "master_worker/master/generic/THDTensorCopy.h" 3 | #else 4 | 5 | THD_API void THDTensor_(copy)(THDTensor *tensor, THDTensor *src); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /torch/lib/THD/master_worker/worker/Dispatch.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../common/RPC.hpp" 4 | 5 | #include 6 | 7 | namespace thd { 8 | namespace worker { 9 | 10 | void execute(std::unique_ptr raw_message_ptr); 11 | 12 | } // namespace worker 13 | } // namespace thd 14 | -------------------------------------------------------------------------------- /torch/lib/THD/master_worker/worker/Worker.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../../THD.h" 4 | 5 | THD_API void THDWorkerMain(); 6 | -------------------------------------------------------------------------------- /torch/lib/THD/master_worker/worker/Worker.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../common/CommandChannel.hpp" 4 | #include "../../base/DataChannel.hpp" 5 | 6 | #include 7 | 8 | #include 9 | 10 | namespace thd { namespace worker { 11 | extern std::unique_ptr workerCommandChannel; 12 | extern std::unordered_map> 13 | workerTensors; 14 | extern std::unordered_map> 15 | workerStorages; 16 | extern std::unordered_map> 17 | workerGenerators; 18 | }} // namespace worker, thd 19 | -------------------------------------------------------------------------------- /torch/lib/THD/master_worker/worker/dispatch/Communication.cpp: -------------------------------------------------------------------------------- 1 | 2 | static void sendTensor(rpc::RPCMessage& raw_message) { 3 | thpp::Tensor *tensor = unpackRetrieveTensor(raw_message); 4 | int dst_rank = unpackInteger(raw_message); 5 | finalize(raw_message); 6 | dataChannel->send(*tensor, dst_rank); 7 | } 8 | 9 | static void sendStorage(rpc::RPCMessage& raw_message) { 10 | thpp::Storage *storage = unpackRetrieveStorage(raw_message); 11 | int dst_rank = unpackInteger(raw_message); 12 | finalize(raw_message); 13 | fprintf(stderr, "sending storage (to be implemented)\n"); 14 | } 15 | -------------------------------------------------------------------------------- /torch/lib/THD/process_group/Collectives.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "base/TensorDescriptor.hpp" 4 | #include "Collectives.h" 5 | -------------------------------------------------------------------------------- /torch/lib/THD/process_group/General.cpp: -------------------------------------------------------------------------------- 1 | #include "General.hpp" 2 | 3 | namespace thd { 4 | std::unique_ptr dataChannel; 5 | } // namespace thd 6 | 7 | using namespace thd; 8 | 9 | bool THDProcessGroupInit(THDChannelType channel_type) { 10 | dataChannel = std::unique_ptr( 11 | thd::DataChannel::newChannel(channel_type)); 12 | if (!dataChannel->init()) return false; 13 | return true; 14 | } 15 | -------------------------------------------------------------------------------- /torch/lib/THD/process_group/General.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../THD.h" 4 | 5 | THD_API bool THDProcessGroupInit(THDChannelType channel_type); 6 | 7 | -------------------------------------------------------------------------------- /torch/lib/THD/process_group/General.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "base/DataChannel.hpp" 4 | #include "General.h" 5 | #include 6 | 7 | namespace thd { 8 | extern std::unique_ptr dataChannel; 9 | } // namespace thd 10 | -------------------------------------------------------------------------------- /torch/lib/THD/test/data_channel_mpi_smoke.cpp: -------------------------------------------------------------------------------- 1 | #include "../base/data_channels/DataChannelMPI.hpp" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | constexpr int WORKERS_NUM = 2; 9 | 10 | int main(int argc, char **argv) { 11 | if (argc == 1) { 12 | execlp("mpirun", "mpirun", "-n", std::to_string(WORKERS_NUM + 1).data(), argv[0], "1", NULL); 13 | } 14 | 15 | auto dataChannel = std::make_shared(); 16 | assert(dataChannel->init()); 17 | assert(dataChannel->getNumProcesses() == (WORKERS_NUM + 1)); 18 | std::cout << "OK (id: " << dataChannel->getRank() << ")" << std::endl; 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /torch/lib/THD/test/data_channel_tcp_accept_timeout.cpp: -------------------------------------------------------------------------------- 1 | #include "../base/data_channels/DataChannelTCP.hpp" 2 | #include "../base/ChannelEnvVars.hpp" 3 | #include "TestUtils.hpp" 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | constexpr int WORKERS_NUM = 2; 11 | constexpr int MASTER_PORT = 45680; 12 | 13 | void master() 14 | { 15 | setenv(thd::WORLD_SIZE_ENV, std::to_string((WORKERS_NUM + 1)).data(), 1); 16 | setenv(thd::RANK_ENV, "0", 1); 17 | setenv(thd::MASTER_PORT_ENV, std::to_string(MASTER_PORT).data(), 1); 18 | auto masterChannel = std::make_shared(2000); // timeout after 2s 19 | 20 | ASSERT_THROWS(std::exception, masterChannel->init()) 21 | } 22 | 23 | 24 | int main() { 25 | std::thread master_thread(master); 26 | master_thread.join(); 27 | std::cout << "OK" << std::endl; 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /torch/lib/THNN/THNN.h: -------------------------------------------------------------------------------- 1 | #ifndef THNN_H 2 | #define THNN_H 3 | 4 | #include 5 | #include 6 | #ifdef _OPENMP 7 | #include 8 | #endif 9 | 10 | #define THNN_(NAME) TH_CONCAT_3(THNN_, Real, NAME) 11 | 12 | #define THIndexTensor THLongTensor 13 | #define THIndexTensor_(NAME) THLongTensor_ ## NAME 14 | 15 | #define THIntegerTensor THIntTensor 16 | #define THIntegerTensor_(NAME) THIntTensor_ ## NAME 17 | 18 | typedef int64_t THIndex_t; 19 | typedef int32_t THInteger_t; 20 | typedef void THNNState; 21 | 22 | #define THNN_resizeAs_indices(I1, I2) \ 23 | THLongStorage *size2 = THIndexTensor_(newSizeOf)(I2); \ 24 | if (!THTensor_(isSize)(I1, size2)) \ 25 | { \ 26 | THTensor_(resize)(I1, size2, NULL); \ 27 | } \ 28 | THLongStorage_free(size2); 29 | 30 | #include "generic/THNN.h" 31 | #include 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /torch/lib/THNN/generic/Abs.c: -------------------------------------------------------------------------------- 1 | #ifndef TH_GENERIC_FILE 2 | #define TH_GENERIC_FILE "generic/Abs.c" 3 | #else 4 | 5 | void THNN_(Abs_updateOutput)( 6 | THNNState *state, 7 | THTensor *input, 8 | THTensor *output) 9 | { 10 | THTensor_(resizeAs)(output, input); 11 | THTensor_(abs)(output, input); 12 | } 13 | 14 | void THNN_(Abs_updateGradInput)( 15 | THNNState *state, 16 | THTensor *input, 17 | THTensor *gradOutput, 18 | THTensor *gradInput) 19 | { 20 | THNN_CHECK_NELEMENT(input, gradOutput); 21 | THTensor_(resizeAs)(gradInput, input); 22 | TH_TENSOR_APPLY3(real, gradInput, real, gradOutput, real, input, 23 | real z = *input_data; 24 | *gradInput_data = *gradOutput_data * (z >= 0 ? 1 : -1); 25 | ); 26 | } 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /torch/lib/THNN/generic/L1Cost.c: -------------------------------------------------------------------------------- 1 | #ifndef TH_GENERIC_FILE 2 | #define TH_GENERIC_FILE "generic/L1Cost.c" 3 | #else 4 | 5 | void THNN_(L1Cost_updateOutput)( 6 | THNNState *state, 7 | THTensor *input, 8 | THTensor *output) 9 | { 10 | THNN_CHECK_DIM_SIZE(output, 1, 0, 1); 11 | accreal sum = 0; 12 | 13 | TH_TENSOR_APPLY(real, input, 14 | sum += fabs(*input_data); 15 | ); 16 | 17 | THTensor_(set1d)(output, 0, sum); 18 | } 19 | 20 | void THNN_(L1Cost_updateGradInput)( 21 | THNNState *state, 22 | THTensor *input, 23 | THTensor *gradOutput, 24 | THTensor *gradInput) 25 | { 26 | THNN_CHECK_NELEMENT(input, gradOutput); 27 | THTensor_(resizeAs)(gradInput, input); 28 | TH_TENSOR_APPLY2(real, gradInput, real, input, 29 | if (*input_data > 0) 30 | *gradInput_data = 1; 31 | else if (*input_data < 0) 32 | *gradInput_data = -1; 33 | else 34 | *gradInput_data = 0; 35 | ); 36 | } 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /torch/lib/THNN/generic/Sigmoid.c: -------------------------------------------------------------------------------- 1 | #ifndef TH_GENERIC_FILE 2 | #define TH_GENERIC_FILE "generic/Sigmoid.c" 3 | #else 4 | 5 | void THNN_(Sigmoid_updateOutput)( 6 | THNNState *state, 7 | THTensor *input, 8 | THTensor *output) 9 | { 10 | THTensor_(sigmoid)(output, input); 11 | } 12 | 13 | void THNN_(Sigmoid_updateGradInput)( 14 | THNNState *state, 15 | THTensor *input, 16 | THTensor *gradOutput, 17 | THTensor *gradInput, 18 | THTensor *output) 19 | { 20 | THNN_CHECK_NELEMENT(output, gradOutput); 21 | THTensor_(resizeAs)(gradInput, output); 22 | TH_TENSOR_APPLY3(real, gradInput, real, gradOutput, real, output, 23 | real z = *output_data; 24 | *gradInput_data = *gradOutput_data * (1. - z) * z; 25 | ); 26 | } 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /torch/lib/THPP/Generator.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace thpp { 4 | 5 | struct Generator { 6 | Generator() {}; 7 | Generator(const Generator& other) = delete; 8 | Generator(Generator&& other) = delete; 9 | virtual ~Generator() {}; 10 | 11 | virtual Generator& copy(const Generator& other) = 0; 12 | virtual Generator& free() = 0; 13 | 14 | virtual unsigned long seed() = 0; 15 | virtual Generator& manualSeed(unsigned long seed) = 0; 16 | }; 17 | 18 | } // namespace thpp 19 | -------------------------------------------------------------------------------- /torch/lib/THPP/THPP.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "THPPGeneral.h" 4 | #include "Generator.hpp" 5 | #include "Storage.hpp" 6 | #include "Tensor.hpp" 7 | #include "Type.hpp" 8 | #include "Traits.hpp" 9 | -------------------------------------------------------------------------------- /torch/lib/THPP/THPPGeneral.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef _WIN32 4 | # ifdef THPP_EXPORTS 5 | # define THPP_API THC_EXTERNC __declspec(dllexport) 6 | # define THPP_CLASS __declspec(dllexport) 7 | # else 8 | # define THPP_API THC_EXTERNC __declspec(dllimport) 9 | # define THPP_CLASS __declspec(dllimport) 10 | # endif 11 | #else 12 | # define THPP_API extern 13 | # define THPP_CLASS 14 | #endif 15 | -------------------------------------------------------------------------------- /torch/lib/THPP/Traits.cpp: -------------------------------------------------------------------------------- 1 | #include "Traits.hpp" 2 | 3 | namespace thpp { 4 | 5 | constexpr Type type_traits::type; 6 | constexpr Type type_traits::type; 7 | constexpr Type type_traits::type; 8 | constexpr Type type_traits::type; 9 | constexpr Type type_traits::type; 10 | constexpr Type type_traits::type; 11 | constexpr Type type_traits::type; 12 | constexpr Type type_traits::type; 13 | constexpr Type type_traits::type; 14 | //constexpr Type type_traits::type; 15 | constexpr Type type_traits::type; 16 | //constexpr Type type_traits::type; 17 | constexpr Type type_traits::type; 18 | 19 | } // namespace thpp 20 | -------------------------------------------------------------------------------- /torch/lib/THPP/TraitsCuda.cpp: -------------------------------------------------------------------------------- 1 | #include "TraitsCuda.hpp" 2 | 3 | namespace thpp { 4 | 5 | constexpr Type type_traits::type; 6 | 7 | } // namespace thpp 8 | -------------------------------------------------------------------------------- /torch/lib/THPP/TraitsCuda.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Traits.hpp" 4 | #include 5 | 6 | namespace thpp { 7 | 8 | template<> 9 | struct type_traits { 10 | static constexpr Type type = Type::HALF; 11 | static constexpr bool is_floating_point = true; 12 | }; 13 | 14 | } // namespace thpp 15 | -------------------------------------------------------------------------------- /torch/lib/THPP/generators/THCGenerator.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../Generator.hpp" 6 | 7 | namespace thpp { 8 | 9 | struct THCGenerator : public Generator { 10 | THCGenerator(THCState* state); 11 | virtual ~THCGenerator(); 12 | 13 | virtual THCGenerator& copy(const Generator& from) override; 14 | virtual THCGenerator& free() override; 15 | 16 | virtual unsigned long seed() override; 17 | virtual THCGenerator& manualSeed(unsigned long seed) override; 18 | 19 | protected: 20 | THCState *state; 21 | }; 22 | 23 | } 24 | -------------------------------------------------------------------------------- /torch/lib/THPP/generators/THGenerator.cpp: -------------------------------------------------------------------------------- 1 | #include "THGenerator.hpp" 2 | 3 | #define const_generator_cast(generator) \ 4 | dynamic_cast(generator) 5 | 6 | namespace thpp { 7 | 8 | THGenerator::THGenerator() 9 | : generator(THGenerator_new()) 10 | {} 11 | 12 | THGenerator::~THGenerator() { 13 | if (generator) 14 | THGenerator_free(generator); 15 | } 16 | 17 | THGenerator& THGenerator::copy(const Generator& from) { 18 | THGenerator_copy(generator, const_generator_cast(from).generator); 19 | return *this; 20 | } 21 | 22 | THGenerator& THGenerator::free() { 23 | THGenerator_free(generator); 24 | return *this; 25 | } 26 | 27 | unsigned long THGenerator::seed() { 28 | return THRandom_seed(generator); 29 | } 30 | 31 | THGenerator& THGenerator::manualSeed(unsigned long seed) { 32 | THRandom_manualSeed(generator, seed); 33 | return *this; 34 | } 35 | 36 | } // namespace thpp 37 | -------------------------------------------------------------------------------- /torch/lib/THPP/generators/THGenerator.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../Generator.hpp" 6 | #include "../tensors/THTensor.hpp" 7 | 8 | namespace thpp { 9 | 10 | struct th_generator_traits { 11 | using generator_type = THGenerator; 12 | }; 13 | 14 | } // namespace thpp 15 | 16 | namespace thpp { 17 | 18 | struct THGenerator : public Generator { 19 | template 20 | friend struct THTensor; 21 | 22 | using generator_type = th_generator_traits::generator_type; 23 | 24 | THGenerator(); 25 | virtual ~THGenerator(); 26 | 27 | virtual THGenerator& copy(const Generator& from) override; 28 | virtual THGenerator& free() override; 29 | 30 | virtual unsigned long seed() override; 31 | virtual THGenerator& manualSeed(unsigned long seed) override; 32 | 33 | protected: 34 | generator_type *generator; 35 | }; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /torch/lib/THPP/storages/THCStorage.cpp: -------------------------------------------------------------------------------- 1 | #include "THCStorage.hpp" 2 | #include "../Traits.hpp" 3 | 4 | #include "../tensors/THCTensor.hpp" 5 | 6 | namespace thpp { 7 | 8 | #include "generic/THCStorage.cpp" 9 | #include 10 | 11 | } // namespace thpp 12 | -------------------------------------------------------------------------------- /torch/lib/THPP/storages/THStorage.cpp: -------------------------------------------------------------------------------- 1 | #include "THStorage.hpp" 2 | #include "../Traits.hpp" 3 | 4 | 5 | namespace thpp { 6 | 7 | #include "generic/THStorage.cpp" 8 | #include 9 | 10 | } // namespace thpp 11 | -------------------------------------------------------------------------------- /torch/lib/THPP/storages/generic/THCStorage.hpp: -------------------------------------------------------------------------------- 1 | #ifndef THC_GENERIC_FILE 2 | #define THC_GENERIC_FILE "storages/generic/THCStorage.hpp" 3 | #else 4 | 5 | template<> 6 | struct thc_storage_traits { 7 | using storage_type = THCRealStorage; 8 | }; 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /torch/lib/THPP/storages/generic/THStorage.hpp: -------------------------------------------------------------------------------- 1 | #ifndef TH_GENERIC_FILE 2 | #define TH_GENERIC_FILE "storages/generic/THStorage.hpp" 3 | #else 4 | 5 | template<> 6 | struct th_storage_traits { 7 | using storage_type = THRealStorage; 8 | }; 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /torch/lib/THPP/tensors/THCSTensor.cpp: -------------------------------------------------------------------------------- 1 | #include "THCSTensor.hpp" 2 | #include "../TraitsCuda.hpp" 3 | 4 | namespace thpp { 5 | 6 | #include "generic/THCSTensor.cpp" 7 | #include 8 | 9 | } // namespace thpp 10 | -------------------------------------------------------------------------------- /torch/lib/THPP/tensors/THCTensor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "THCTensor.hpp" 4 | #include "THCSTensor.hpp" 5 | #include "THCHalf.h" 6 | #include "../TraitsCuda.hpp" 7 | 8 | namespace thpp { 9 | 10 | #include "generic/THCTensor.cpp" 11 | #include 12 | 13 | } // namespace thpp 14 | -------------------------------------------------------------------------------- /torch/lib/THPP/tensors/THSTensor.cpp: -------------------------------------------------------------------------------- 1 | #include "THSTensor.hpp" 2 | #include "../Traits.hpp" 3 | 4 | namespace thpp { 5 | 6 | #include "generic/THSTensor.cpp" 7 | #include 8 | 9 | } // namespace thpp 10 | -------------------------------------------------------------------------------- /torch/lib/THPP/tensors/THTensor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "THTensor.hpp" 4 | #include "THSTensor.hpp" 5 | #include "../Traits.hpp" 6 | 7 | namespace thpp { 8 | 9 | #include "generic/THTensor.cpp" 10 | #include 11 | 12 | } // namespace thpp 13 | -------------------------------------------------------------------------------- /torch/lib/THPP/tensors/generic/THCSTensor.hpp: -------------------------------------------------------------------------------- 1 | #ifndef THCS_GENERIC_FILE 2 | #define THCS_GENERIC_FILE "tensors/generic/THCSTensor.hpp" 3 | #else 4 | 5 | template<> 6 | struct thcs_tensor_traits { 7 | using tensor_type = THCSRealTensor; 8 | }; 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /torch/lib/THPP/tensors/generic/THCTensor.hpp: -------------------------------------------------------------------------------- 1 | #ifndef THC_GENERIC_FILE 2 | #define THC_GENERIC_FILE "tensors/generic/THCTensor.hpp" 3 | #else 4 | 5 | template<> 6 | struct thc_tensor_traits { 7 | using tensor_type = THCRealTensor; 8 | }; 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /torch/lib/THPP/tensors/generic/THSTensor.hpp: -------------------------------------------------------------------------------- 1 | #ifndef THS_GENERIC_FILE 2 | #define THS_GENERIC_FILE "tensors/generic/THSTensor.hpp" 3 | #else 4 | 5 | template<> 6 | struct ths_tensor_traits { 7 | using tensor_type = THSRealTensor; 8 | }; 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /torch/lib/THPP/tensors/generic/THTensor.hpp: -------------------------------------------------------------------------------- 1 | #ifndef TH_GENERIC_FILE 2 | #define TH_GENERIC_FILE "tensors/generic/THTensor.hpp" 3 | #else 4 | 5 | template<> 6 | struct th_tensor_traits { 7 | using tensor_type = THRealTensor; 8 | }; 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /torch/lib/THS/THS.h: -------------------------------------------------------------------------------- 1 | #ifndef THS_INC 2 | #define THS_INC 3 | 4 | #include "THGeneral.h" 5 | #include "THSTensor.h" 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /torch/lib/THS/THSGenerateFloatTypes.h: -------------------------------------------------------------------------------- 1 | #ifndef THS_GENERIC_FILE 2 | #error "You must define THS_GENERIC_FILE before including THSGenerateAllTypes.h" 3 | #endif 4 | 5 | #define real float 6 | #define accreal double 7 | #define Real Float 8 | #define THSInf FLT_MAX 9 | #define THS_REAL_IS_FLOAT 10 | #line 1 THS_GENERIC_FILE 11 | #include THS_GENERIC_FILE 12 | #undef accreal 13 | #undef real 14 | #undef Real 15 | #undef THSInf 16 | #undef THS_REAL_IS_FLOAT 17 | 18 | #define real double 19 | #define accreal double 20 | #define Real Double 21 | #define THSInf DBL_MAX 22 | #define THS_REAL_IS_DOUBLE 23 | #line 1 THS_GENERIC_FILE 24 | #include THS_GENERIC_FILE 25 | #undef accreal 26 | #undef real 27 | #undef Real 28 | #undef THSInf 29 | #undef THS_REAL_IS_DOUBLE 30 | 31 | #undef THS_GENERIC_FILE 32 | -------------------------------------------------------------------------------- /torch/lib/THS/THSTensor.c: -------------------------------------------------------------------------------- 1 | #include "THSTensor.h" 2 | 3 | #include "generic/THSTensor.c" 4 | #include "THSGenerateAllTypes.h" 5 | 6 | #include "generic/THSTensorMath.c" 7 | #include "THSGenerateAllTypes.h" 8 | -------------------------------------------------------------------------------- /torch/lib/THS/THSTensor.h: -------------------------------------------------------------------------------- 1 | #ifndef THS_TENSOR_INC 2 | #define THS_TENSOR_INC 3 | 4 | #include "TH.h" 5 | #include 6 | 7 | #define THSTensor TH_CONCAT_3(THS,Real,Tensor) 8 | #define THSTensor_(NAME) TH_CONCAT_4(THS,Real,Tensor_,NAME) 9 | 10 | #include "generic/THSTensor.h" 11 | #include "THSGenerateAllTypes.h" 12 | 13 | #include "generic/THSTensorMath.h" 14 | #include "THSGenerateAllTypes.h" 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /torch/lib/libshm/alloc_info.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | struct AllocInfo { 6 | pid_t pid; 7 | char free; 8 | char filename[60]; 9 | }; 10 | -------------------------------------------------------------------------------- /torch/lib/libshm/err.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #define SYSCHECK(call) { auto __ret = (call); if (__ret < 0) { throw std::system_error(errno, std::system_category()); } } 6 | -------------------------------------------------------------------------------- /torch/lib/libshm/libshm.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBSHM_H 2 | #define LIBSHM_H 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | #define EXPORT_API extern "C" 8 | #else 9 | #define EXPORT_API 10 | #endif 11 | 12 | typedef struct { 13 | char *manager_handle; 14 | THMapAllocatorContext *th_context; 15 | } libshm_context; 16 | 17 | EXPORT_API void libshm_init(const char *manager_exec_path); 18 | EXPORT_API libshm_context * libshm_context_new(const char *manager_handle, const char *filename, int flags); 19 | EXPORT_API void libshm_context_free(libshm_context *context); 20 | 21 | extern THAllocator THManagedSharedAllocator; 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /torch/lib/libshm_windows/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | CMAKE_MINIMUM_REQUIRED(VERSION 2.6 FATAL_ERROR) 2 | CMAKE_POLICY(VERSION 2.6) 3 | 4 | 5 | IF(NOT LIBSHM_INSTALL_LIB_SUBDIR) 6 | SET(LIBSHM_INSTALL_BIN_SUBDIR "bin" CACHE PATH "libshm install binary directory") 7 | SET(LIBSHM_INSTALL_LIB_SUBDIR "lib" CACHE PATH "libshm install library directory") 8 | ENDIF() 9 | 10 | ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE=1) 11 | ADD_DEFINITIONS(-DSHM_EXPORTS) 12 | 13 | IF (CMAKE_VERSION VERSION_LESS "3.1") 14 | SET(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}") 15 | ELSE () 16 | SET(CMAKE_CXX_STANDARD 11) 17 | ENDIF () 18 | 19 | ADD_LIBRARY(shm SHARED core.cpp) 20 | INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) 21 | TARGET_LINK_LIBRARIES(shm ${TH_LIBRARIES}) 22 | 23 | 24 | INSTALL(TARGETS shm 25 | RUNTIME DESTINATION "${LIBSHM_INSTALL_BIN_SUBDIR}" 26 | LIBRARY DESTINATION "${LIBSHM_INSTALL_LIB_SUBDIR}" 27 | ARCHIVE DESTINATION "${LIBSHM_INSTALL_LIB_SUBDIR}") 28 | INSTALL(FILES libshm.h DESTINATION "include") 29 | -------------------------------------------------------------------------------- /torch/lib/libshm_windows/err.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #define SYSCHECK(call) { auto __ret = (call); if (__ret < 0) { throw std::system_error(errno, std::system_category()); } } 4 | -------------------------------------------------------------------------------- /torch/lib/libshm_windows/libshm.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBSHM_H 2 | #define LIBSHM_H 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | #define SHM_EXTERNC extern "C" 8 | #else 9 | #define SHM_EXTERNC 10 | #endif 11 | 12 | #ifdef SHM_EXPORTS 13 | # define SHM_API SHM_EXTERNC __declspec(dllexport) 14 | #else 15 | # define SHM_API SHM_EXTERNC __declspec(dllimport) 16 | #endif 17 | 18 | typedef struct { 19 | char *manager_handle; 20 | THMapAllocatorContext *th_context; 21 | } libshm_context; 22 | 23 | SHM_API void libshm_init(const char *manager_exec_path); 24 | SHM_API libshm_context * libshm_context_new(const char *manager_handle, const char *filename, int flags); 25 | SHM_API void libshm_context_free(libshm_context *context); 26 | 27 | SHM_API THAllocator THManagedSharedAllocator; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /torch/lib/nccl/.gitignore: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2015-2016, NVIDIA CORPORATION. All rights reserved. 2 | /build 3 | -------------------------------------------------------------------------------- /torch/lib/nccl/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR) 2 | CMAKE_POLICY(VERSION 2.8) 3 | 4 | IF(NOT CUDA_FOUND) 5 | FIND_PACKAGE(CUDA 7.0 REQUIRED) 6 | ENDIF() 7 | 8 | ADD_CUSTOM_COMMAND( 9 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 10 | OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lib/libnccl.so 11 | COMMAND env CUDA_HOME=${CUDA_TOOLKIT_ROOT_DIR} NVCC=${CUDA_NVCC_EXECUTABLE} BUILDDIR=${CMAKE_CURRENT_BINARY_DIR} make -j `getconf _NPROCESSORS_ONLN` 12 | ) 13 | 14 | ADD_CUSTOM_TARGET(nccl ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/lib/libnccl.so) 15 | 16 | INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/nccl.h DESTINATION "include") 17 | -------------------------------------------------------------------------------- /torch/lib/nccl/debian/.gitignore: -------------------------------------------------------------------------------- 1 | /*.debhelper.log 2 | /*.debhelper 3 | /*.substvars 4 | /tmp/ 5 | /files 6 | /libnccl1/ 7 | /libnccl-dev/ 8 | -------------------------------------------------------------------------------- /torch/lib/nccl/debian/changelog.in: -------------------------------------------------------------------------------- 1 | nccl (${nccl:Major}.${nccl:Minor}.${nccl:Patch}-${deb:Revision}+cuda${cuda:Major}.${cuda:Minor}) trusty; urgency=medium 2 | 3 | * Automatic Debian package from build 4 | 5 | -- cudatools ${deb:Timestamp} 6 | -------------------------------------------------------------------------------- /torch/lib/nccl/debian/compat: -------------------------------------------------------------------------------- 1 | 9 2 | -------------------------------------------------------------------------------- /torch/lib/nccl/debian/copyright: -------------------------------------------------------------------------------- 1 | ../LICENSE.txt -------------------------------------------------------------------------------- /torch/lib/nccl/debian/libnccl-dev.install: -------------------------------------------------------------------------------- 1 | include/nccl.h usr/include 2 | lib/libnccl.so /usr/lib/x86_64-linux-gnu 3 | -------------------------------------------------------------------------------- /torch/lib/nccl/debian/libnccl-dev.manpages: -------------------------------------------------------------------------------- 1 | debian/nccl.7 2 | -------------------------------------------------------------------------------- /torch/lib/nccl/debian/libnccl1.install.in: -------------------------------------------------------------------------------- 1 | lib/libnccl.so.${nccl:Major} /usr/lib/x86_64-linux-gnu 2 | lib/libnccl.so.${nccl:Major}.${nccl:Minor}.${nccl:Patch} /usr/lib/x86_64-linux-gnu 3 | -------------------------------------------------------------------------------- /torch/lib/nccl/debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | 3 | %: 4 | dh $@ --parallel 5 | 6 | override_dh_auto_install: 7 | PREFIX=debian/tmp dh_auto_install 8 | 9 | override_dh_auto_test: 10 | # Do not make test 11 | 12 | override_dh_auto_clean: 13 | # Do not make clean 14 | -------------------------------------------------------------------------------- /torch/lib/nccl/debian/shlibs.local.in: -------------------------------------------------------------------------------- 1 | libcudart ${cuda:Major}.${cuda:Minor} cuda-cudart-${cuda:Major}-${cuda:Minor} 2 | -------------------------------------------------------------------------------- /torch/lib/nccl/debian/source/format: -------------------------------------------------------------------------------- 1 | 3.0 (native) 2 | -------------------------------------------------------------------------------- /torch/nn/__init__.py: -------------------------------------------------------------------------------- 1 | from .modules import * 2 | from .parameter import Parameter 3 | from .parallel import DataParallel 4 | -------------------------------------------------------------------------------- /torch/nn/_functions/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tylergenter/pytorch/42459c2544bc6c2e37c3459caaeca7c9eb1a8906/torch/nn/_functions/__init__.py -------------------------------------------------------------------------------- /torch/nn/_functions/activation.py: -------------------------------------------------------------------------------- 1 | from torch.autograd.function import Function 2 | 3 | 4 | class Softsign(Function): 5 | 6 | def forward(self, input): 7 | self.buffer = input.clone().abs_().add_(1) 8 | self.buffer_squared = False 9 | output = input.clone().div_(self.buffer) 10 | return output 11 | 12 | def backward(self, grad_output): 13 | if not self.buffer_squared: 14 | self.buffer.mul_(self.buffer) 15 | self.buffer_squared = True 16 | grad_input = grad_output.clone().div_(self.buffer) 17 | return grad_input 18 | -------------------------------------------------------------------------------- /torch/nn/_functions/thnn/__init__.py: -------------------------------------------------------------------------------- 1 | _all_functions = [] 2 | 3 | from .auto import * 4 | from .normalization import * 5 | from .activation import * 6 | from .pooling import * 7 | from .sparse import * 8 | from .loss import * 9 | from .upsampling import * 10 | from .rnnFusedPointwise import * 11 | -------------------------------------------------------------------------------- /torch/nn/backends/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tylergenter/pytorch/42459c2544bc6c2e37c3459caaeca7c9eb1a8906/torch/nn/backends/__init__.py -------------------------------------------------------------------------------- /torch/nn/backends/backend.py: -------------------------------------------------------------------------------- 1 | 2 | class FunctionBackend(object): 3 | 4 | def __init__(self): 5 | self.function_classes = {} 6 | 7 | def __getattr__(self, name): 8 | fn = self.function_classes.get(name) 9 | if fn is None: 10 | raise NotImplementedError 11 | return fn 12 | 13 | def register_function(self, name, function_class): 14 | if self.function_classes.get(name): 15 | raise RuntimeError("Trying to register second function under name " + name + " in " + type(self).__name__) 16 | self.function_classes[name] = function_class 17 | -------------------------------------------------------------------------------- /torch/nn/modules/normalization.py: -------------------------------------------------------------------------------- 1 | from .module import Module 2 | 3 | 4 | class CrossMapLRN2d(Module): 5 | 6 | def __init__(self, size, alpha=1e-4, beta=0.75, k=1): 7 | super(CrossMapLRN2d, self).__init__() 8 | self.size = size 9 | self.alpha = alpha 10 | self.beta = beta 11 | self.k = k 12 | 13 | def forward(self, input): 14 | return self._backend.CrossMapLRN2d(self.size, self.alpha, self.beta, 15 | self.k)(input) 16 | 17 | def __repr__(self): 18 | return self.__class__.__name__ + ' (' \ 19 | + ', alpha=' + str(self.alpha) \ 20 | + ', beta=' + str(self.beta) \ 21 | + ', k=' + str(self.k) \ 22 | + ')' 23 | 24 | 25 | # TODO: ContrastiveNorm2d 26 | # TODO: DivisiveNorm2d 27 | # TODO: SubtractiveNorm2d 28 | -------------------------------------------------------------------------------- /torch/nn/modules/utils.py: -------------------------------------------------------------------------------- 1 | import collections 2 | from itertools import repeat 3 | 4 | 5 | def _ntuple(n): 6 | def parse(x): 7 | if isinstance(x, collections.Iterable): 8 | return x 9 | return tuple(repeat(x, n)) 10 | return parse 11 | 12 | _single = _ntuple(1) 13 | _pair = _ntuple(2) 14 | _triple = _ntuple(3) 15 | _quadruple = _ntuple(4) 16 | -------------------------------------------------------------------------------- /torch/nn/parallel/__init__.py: -------------------------------------------------------------------------------- 1 | from .parallel_apply import parallel_apply 2 | from .replicate import replicate 3 | from .data_parallel import DataParallel, data_parallel 4 | from .scatter_gather import scatter, gather 5 | 6 | __all__ = ['replicate', 'scatter', 'parallel_apply', 'gather', 'data_parallel', 7 | 'DataParallel'] 8 | -------------------------------------------------------------------------------- /torch/nn/utils/__init__.py: -------------------------------------------------------------------------------- 1 | from . import rnn 2 | from .clip_grad import clip_grad_norm 3 | -------------------------------------------------------------------------------- /torch/optim/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | :mod:`torch.optim` is a package implementing various optimization algorithms. 3 | Most commonly used methods are already supported, and the interface is general 4 | enough, so that more sophisticated ones can be also easily integrated in the 5 | future. 6 | """ 7 | 8 | from .adadelta import Adadelta 9 | from .adagrad import Adagrad 10 | from .adam import Adam 11 | from .adamax import Adamax 12 | from .asgd import ASGD 13 | from .sgd import SGD 14 | from .rprop import Rprop 15 | from .rmsprop import RMSprop 16 | from .optimizer import Optimizer 17 | from .lbfgs import LBFGS 18 | 19 | del adadelta 20 | del adagrad 21 | del adam 22 | del adamax 23 | del asgd 24 | del sgd 25 | del rprop 26 | del rmsprop 27 | del optimizer 28 | del lbfgs 29 | -------------------------------------------------------------------------------- /torch/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tylergenter/pytorch/42459c2544bc6c2e37c3459caaeca7c9eb1a8906/torch/utils/__init__.py -------------------------------------------------------------------------------- /torch/utils/data/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from .dataset import Dataset, TensorDataset 3 | from .dataloader import DataLoader 4 | -------------------------------------------------------------------------------- /torch/utils/hooks.py: -------------------------------------------------------------------------------- 1 | import weakref 2 | 3 | 4 | class RemovableHandle(object): 5 | """A handle which provides the capability to remove a hook.""" 6 | 7 | next_id = 0 8 | 9 | def __init__(self, hooks_dict): 10 | self.hooks_dict_ref = weakref.ref(hooks_dict) 11 | self.id = RemovableHandle.next_id 12 | RemovableHandle.next_id += 1 13 | 14 | def remove(self): 15 | hooks_dict = self.hooks_dict_ref() 16 | if hooks_dict is not None and self.id in hooks_dict: 17 | del hooks_dict[self.id] 18 | 19 | def __enter__(self): 20 | return self 21 | 22 | def __exit__(self, type, value, tb): 23 | self.remove() 24 | -------------------------------------------------------------------------------- /torch/utils/serialization/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from .read_lua_file import load_lua, T7Reader 3 | -------------------------------------------------------------------------------- /torch/utils/trainer/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from .trainer import Trainer 3 | -------------------------------------------------------------------------------- /torch/utils/trainer/plugins/__init__.py: -------------------------------------------------------------------------------- 1 | from .progress import ProgressMonitor 2 | from .accuracy import AccuracyMonitor 3 | from .time import TimeMonitor 4 | from .loss import LossMonitor 5 | from .logger import Logger 6 | -------------------------------------------------------------------------------- /torch/utils/trainer/plugins/accuracy.py: -------------------------------------------------------------------------------- 1 | from .monitor import Monitor 2 | 3 | 4 | class AccuracyMonitor(Monitor): 5 | stat_name = 'accuracy' 6 | 7 | def __init__(self, *args, **kwargs): 8 | kwargs.setdefault('unit', '%') 9 | kwargs.setdefault('precision', 2) 10 | super(AccuracyMonitor, self).__init__(*args, **kwargs) 11 | 12 | def _get_value(self, iteration, input, target, output, loss): 13 | batch_size = input.size(0) 14 | predictions = output.max(1)[1].type_as(target) 15 | correct = predictions.eq(target) 16 | if not hasattr(correct, 'sum'): 17 | correct = correct.cpu() 18 | correct = correct.sum() 19 | return 100. * correct / batch_size 20 | -------------------------------------------------------------------------------- /torch/utils/trainer/plugins/loss.py: -------------------------------------------------------------------------------- 1 | from .monitor import Monitor 2 | 3 | 4 | class LossMonitor(Monitor): 5 | stat_name = 'loss' 6 | 7 | def _get_value(self, iteration, input, target, output, loss): 8 | return loss[0] 9 | -------------------------------------------------------------------------------- /torch/utils/trainer/plugins/plugin.py: -------------------------------------------------------------------------------- 1 | 2 | class Plugin(object): 3 | 4 | def __init__(self, interval=None): 5 | if interval is None: 6 | interval = [] 7 | self.trigger_interval = interval 8 | 9 | def register(self, trainer): 10 | raise NotImplementedError 11 | -------------------------------------------------------------------------------- /torch/utils/trainer/plugins/time.py: -------------------------------------------------------------------------------- 1 | from __future__ import absolute_import 2 | import time 3 | 4 | from .monitor import Monitor 5 | 6 | 7 | class TimeMonitor(Monitor): 8 | stat_name = 'time' 9 | 10 | def __init__(self, *args, **kwargs): 11 | kwargs.setdefault('unit', 'ms') 12 | kwargs.setdefault('precision', 0) 13 | super(TimeMonitor, self).__init__(*args, **kwargs) 14 | self.last_time = None 15 | 16 | def _get_value(self, *args): 17 | if self.last_time: 18 | now = time.time() 19 | duration = now - self.last_time 20 | self.last_time = now 21 | return duration * 1000 22 | else: 23 | self.last_time = time.time() 24 | return 0 25 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [flake8] 2 | max-line-length = 120 3 | ignore = E305,E402,E721,F401,F403,F405,F821,F841 4 | exclude = docs/src,venv 5 | --------------------------------------------------------------------------------