cavis/libnd4j/include/loops/legacy_ops.h

413 lines
10 KiB
C
Raw Normal View History

2019-06-06 14:21:15 +02:00
/*******************************************************************************
* Copyright (c) 2015-2018 Skymind, Inc.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/
//
// @author raver119@gmail.com
//
#ifndef PROJECT_LEGACY_OPS_H
#define PROJECT_LEGACY_OPS_H
#define AGGREGATE_OPS \
(0, aggregateOps::HierarchicSoftmax) ,\
(1, aggregateOps::Dot) ,\
(2, aggregateOps::Axpy) ,\
(3, aggregateOps::SkipGram) ,\
(4, aggregateOps::CBOW) ,\
(5, aggregateOps::GEMM)
#define BROADCAST_INT_OPS \
(0, ShiftLeft), \
(1, ShiftRight), \
(2, CyclicShiftLeft), \
(3, CyclicShiftRight), \
(4, IntAnd), \
(5, IntOr), \
(6, IntXor)
2019-06-06 14:21:15 +02:00
#define BROADCAST_BOOL_OPS \
(0, EqualTo),\
(1, GreaterThan),\
(2, LessThan),\
(3, Epsilon),\
(4, GreaterThanOrEqual),\
(5, MatchCondition) ,\
2019-06-06 14:21:15 +02:00
(6, NotEqualTo),\
(7, And),\
(8, Or),\
(9, Xor) ,\
(10, Not) ,\
(11, LessThanOrEqual)
2019-06-06 14:21:15 +02:00
#define BROADCAST_OPS \
(0, Add), \
(1, Subtract), \
(2, Multiply), \
(3, Divide), \
(4, ReverseDivide), \
(5, ReverseSubtract), \
(6, CopyPws), \
(7, Pow), \
(13, MinPairwise) ,\
(14, MaxPairwise) ,\
(15, AMinPairwise) ,\
(16, AMaxPairwise) ,\
(17, SquaredSubtract),\
(18, FloorMod),\
(19, FloorDiv),\
(20, ReverseMod),\
(21, SafeDivide),\
(22, Mod) ,\
(23, TruncateDiv), \
(26, Atan2) ,\
(27, LogicalOr) ,\
(28, LogicalXor) ,\
(29, LogicalNot) ,\
(30, LogicalAnd), \
(31, DivideNoNan), \
(32, IGamma), \
Oleh powderev (#171) * Libnd4j: Add broadcastable elementwise power derivative #7461 first step of Pow_bp operation implementation Signed-off-by: Oleg <oleg.semeniv@gmail.com> * Libnd4j: Add broadcastable elementwise power derivative #7461 some corrections of calculation steps Signed-off-by: Oleg <oleg.semeniv@gmail.com> * Libnd4j: Add broadcastable elementwise power derivative #7461 some bug fixes, the PowDerevative op made broadcastable, add the raw tests for op, need refactoring to use broadcast ops * Libnd4j: Add broadcastable elementwise power derivative #7461 fixed several bugs add broadcast support and tests, need to fix scalar+array and array+scalar Signed-off-by: Oleg <oleg.semeniv@gmail.com> * Libnd4j: Add broadcastable elementwise power derivative #7461 fixed bugs for scalar inputs, fixed multinomial tests, added tests Signed-off-by: Oleg <oleg.semeniv@gmail.com> * Libnd4j: Add broadcastable elementwise power derivative #7461 fised bugs for different shapes support, tests updated * Libnd4j: Add broadcastable elementwise power derivative #7461 applied all possible variants via tiled arrays, add support of broadcast for Pow and PowDerivative ops, covered by tests, before review have to be replaced tiled implementation by applyTrueBroadcast Signed-off-by: Oleg <oleg.semeniv@gmail.com> * Libnd4j: Add broadcastable elementwise power derivative #7461 replaced tile by broadcast implementation, fixed issue with negative x input, corrected tests, need additional testing Signed-off-by: Oleg <oleg.semeniv@gmail.com> * Libnd4j: Add broadcastable elementwise power derivative #7461 added and corrected test cases, corrected implementation need review Signed-off-by: Oleg <oleg.semeniv@gmail.com> * Libnd4j: Add broadcastable elementwise power derivative #7461 code clean up * Libnd4j: Add broadcastable elementwise power derivative #7461 code clean up, removed some tests, add tests with scalar Signed-off-by: Oleg <oleg.semeniv@gmail.com> * Libnd4j: Add broadcastable elementwise power derivative #7461 code improvement and clean up, split tests Signed-off-by: Oleg <oleg.semeniv@gmail.com> * Libnd4j: Add broadcastable elementwise power derivative #7461 some code clean up Signed-off-by: Oleg <oleg.semeniv@gmail.com> * Libnd4j: Add broadcastable elementwise power derivative replace __isnanf by internal realization Signed-off-by: Oleg <oleg.semeniv@gmail.com> * pow_bp wrapper * Fixed PowBp wrapper * Tests added * Test fixed * Fix return type * Disable powBp usage * Pow backprop changed Co-authored-by: Alexander Stoyakin <alexander.stoyakin@gmail.com>
2020-01-20 10:59:12 +01:00
(33, IGammac),\
(34, PowDerivative)
2019-06-06 14:21:15 +02:00
// these ops return same data type as input
#define TRANSFORM_SAME_OPS \
(0, Abs), \
(1, Sign), \
(2, Ones), \
(3, Neg), \
(4, Round), \
(5, TimesOneMinus), \
(6, Cube), \
(7, OneMinus), \
(11, Reciprocal), \
(12, Square), \
(13, CompareAndSetTransform) ,\
(15, Identity), \
(17, Ceiling), \
(18, Floor), \
(19, ClipByValue) ,\
(21, Copy)
#define TRANSFORM_ANY_OPS \
(0, Assign)
2019-06-06 14:21:15 +02:00
// these ops return bool
#define TRANSFORM_BOOL_OPS \
(1, IsInf), \
(2, IsNan), \
(3, IsFinite), \
(4, IsInfOrNan), \
(5, MatchConditionBool), \
(6, IsPositive) , \
(7, Not), \
(8, IsNegative)
2019-06-06 14:21:15 +02:00
#define TRANSFORM_STRICT_OPS \
(2, ScaledTanh), \
(3, Affine), \
2019-06-06 14:21:15 +02:00
(4, TanhDerivative), \
(5, HardTanhDerivative), \
(6, SigmoidDerivative), \
(7, SoftSignDerivative), \
(8, TanDerivative) ,\
(9, SELUDerivative) ,\
(10, HardSigmoidDerivative) ,\
(11, RationalTanhDerivative) ,\
(12, RectifiedTanhDerivative) ,\
(13, SwishDerivative) ,\
(14, ACoshDerivative) ,\
(15, ASinhDerivative) ,\
(16, SinhDerivative), \
(17, LogSigmoidDerivative) ,\
(18, SpecialDerivative), \
(19, Stabilize), \
(20, StabilizeFP16) ,\
(21, CubeDerivative) ,\
(22, Cosine), \
(23, Exp), \
(24, Log), \
(25, SetRange), \
(26, Sigmoid), \
(27, Sin), \
(28, SoftPlus), \
(29, Tanh), \
(30, ACos), \
(31, ASin), \
(32, ATan), \
(33, HardTanh), \
(34, SoftSign), \
(36, HardSigmoid), \
(37, RationalTanh) ,\
(38, RectifiedTanh) ,\
(39, Sinh) ,\
(40, Cosh) ,\
(41, Tan) ,\
(42, SELU) ,\
(43, Swish) ,\
(44, Log1p), \
(45, Erf), \
(46, ACosh), \
(47, ASinh), \
(48, Rint), \
(49, LogSigmoid), \
(50, Erfc) ,\
(51, Expm1), \
(52, ATanh) ,\
(53, GELU) ,\
(54, GELUDerivative), \
(55, PreciseGELU) ,\
(56, PreciseGELUDerivative), \
(57, Mish),\
(58, MishDerivative)
2019-06-06 14:21:15 +02:00
// these ops return one of FLOAT data types
#define TRANSFORM_FLOAT_OPS \
(1, Sqrt), \
(3, RSqrt)
#define SUMMARY_STATS_OPS \
(0, SummaryStatsVariance), \
(1, SummaryStatsStandardDeviation)
#define SCALAR_INT_OPS \
(0, ShiftLeft) ,\
(1, ShiftRight), \
(2, CyclicShiftLeft), \
(3, CyclicShiftRight), \
(4, IntAnd), \
(5, IntOr), \
(6, IntXor)
2019-06-06 14:21:15 +02:00
#define SCALAR_BOOL_OPS \
(0, EqualTo),\
(1, GreaterThan),\
(2, LessThan),\
(3, Epsilon),\
(4, GreaterThanOrEqual),\
(5, MatchCondition) ,\
2019-06-06 14:21:15 +02:00
(6, NotEqualTo),\
(7, And),\
(8, Or),\
(9, Xor) ,\
(10, Not) ,\
(11, LessThanOrEqual)
2019-06-06 14:21:15 +02:00
#define SCALAR_OPS \
(0, Add),\
(1, Subtract),\
(2, Multiply),\
(3, Divide),\
(4, ReverseDivide),\
(5, ReverseSubtract),\
(6, MaxPairwise),\
(7, ELU), \
(8, ELUDerivative), \
2019-06-06 14:21:15 +02:00
(13, MinPairwise),\
(14, CopyPws),\
(15, Mod),\
(16, ReverseMod),\
(17, Remainder),\
(18, FMod) ,\
(19, TruncateDiv) ,\
(20, FloorDiv) ,\
(21, FloorMod), \
(22, SquaredSubtract),\
(23, SafeDivide), \
(24, AMaxPairwise), \
(25, AMinPairwise), \
(26, Atan2) ,\
(27, LogicalOr) ,\
(28, LogicalXor) ,\
(29, LogicalNot) ,\
(30, LogicalAnd) ,\
(31, Pow) ,\
(32, PowDerivative) ,\
(33, CompareAndSet) ,\
(34, SXELogitsSmoother), \
(35, LeakyRELU), \
(36, LeakyRELUDerivative), \
(37, ReplaceNans) ,\
(38, LogX) ,\
(39, RELU), \
(40, RELU6), \
(41, Step), \
(42, LstmClip), \
(43, TruncateMod) ,\
(44, SquaredReverseSubtract) ,\
(45, ReversePow), \
(46, DivideNoNan), \
(47, IGamma), \
Shyrma lstm layer bp (#370) * - start working on bp for lstm Signed-off-by: Yurii <iuriish@yahoo.com> * - further working on bp for lstmLayer Signed-off-by: Yurii <iuriish@yahoo.com> * - minor change Signed-off-by: Yurii <iuriish@yahoo.com> * - further work on bp for lstmLayer 2 Signed-off-by: Yurii <iuriish@yahoo.com> * - further work on bp for lstmLayer 3 Signed-off-by: Yurii <iuriish@yahoo.com> * - further work on bp for lstmLayer 4 Signed-off-by: Yurii <iuriish@yahoo.com> * - further work on bp for lstmLayer 5 Signed-off-by: Yurii <iuriish@yahoo.com> * - further work on bp for lstmLayer 6 Signed-off-by: Yurii <iuriish@yahoo.com> * - further work on bp for lstmLayer 7 Signed-off-by: Yurii <iuriish@yahoo.com> * - further work on bp for lstmLayer 8 Signed-off-by: Yurii <iuriish@yahoo.com> * - further work on bp for lstmLayer 9 Signed-off-by: Yurii <iuriish@yahoo.com> * - provide lstmLayerCell and lstmLayerCellBp as separate CUSTOM_OPs Signed-off-by: Yurii <iuriish@yahoo.com> * - testing and fixing lstmLayerCellBp helper Signed-off-by: Yurii <iuriish@yahoo.com> * - implement lstmLayerCellBp as separate op Signed-off-by: Yurii <iuriish@yahoo.com> * - implement lstmLayerBp as separate op (not tested) Signed-off-by: Yurii <iuriish@yahoo.com> * - fixing calculations of dLdWp and dLdb in lstmLayerCellBp Signed-off-by: Yurii <iuriish@yahoo.com> * - further work on bp for lstmLayer 10 Signed-off-by: Yurii <iuriish@yahoo.com> * - fixing typo in lstmLayerTimeLoop Signed-off-by: Yurii <iuriish@yahoo.com> * - forgot to perform clipping of c array and calculate corresponding derivative in lstmLayerCellBp Signed-off-by: Yurii <iuriish@yahoo.com> * - further work on bp for lstmLayer 10 Signed-off-by: Yurii <iuriish@yahoo.com> * - testing and fixing bugs in lstmLayer_bp op 1 Signed-off-by: Yurii <iuriish@yahoo.com> * - testing and fixing bugs in lstmLayer_bp op 2 Signed-off-by: Yurii <iuriish@yahoo.com> * - turn off heavy tests for cuda for lstmLayer_bp op Signed-off-by: Yurii <iuriish@yahoo.com> * - forgot to nullify gradients at eliminated time steps (when sequnce length array is present ) Signed-off-by: Yurii <iuriish@yahoo.com>
2020-04-13 12:21:51 +02:00
(48, IGammac), \
(49, RELUDerivative)
2019-06-06 14:21:15 +02:00
#define REDUCE3_OPS \
(0, ManhattanDistance), \
(1, EuclideanDistance), \
(2, CosineSimilarity), \
(3, Dot), \
(4, EqualsWithEps) ,\
(5, CosineDistance) ,\
(6, JaccardDistance) ,\
(7, SimpleHammingDistance)
#define REDUCE_LONG_OPS \
(0, CountNonZero), \
(1, CountZero), \
(2, MatchCondition)
#define REDUCE_BOOL_OPS \
(0, Any) ,\
(1, All), \
(2, IsFinite), \
(3, IsInfOrNan), \
(4, IsNan), \
(5, IsInf), \
(6, IsPositive), \
(7, IsNegative)
2019-06-06 14:21:15 +02:00
#define REDUCE_SAME_OPS \
(0, Sum), \
(1, Max), \
(2, Min), \
(3, Prod), \
(4, ASum), \
(5, AMax) ,\
(6, AMin) ,\
(7, ReduceSameBenchmarkOp)
#define REDUCE_FLOAT_OPS \
(0, Mean), \
(1, AMean) ,\
(2, Norm1), \
(3, Norm2), \
(4, NormMax), \
(5, NormFrobenius), \
(6, NormP), \
(7, SquaredNorm) ,\
(8, Entropy) ,\
(9, LogEntropy) ,\
(10, ShannonEntropy) ,\
(12, ReduceFloatBenchmarkOp)
#define RANDOM_OPS \
(0, UniformDistribution) ,\
(1, DropOut) ,\
(2, DropOutInverted) ,\
(3, ProbablisticMerge) ,\
(4, Linspace) ,\
(5, Choice) ,\
(6, GaussianDistribution) ,\
(7, BernoulliDistribution) ,\
(8, BinomialDistribution),\
(9, BinomialDistributionEx),\
(10, LogNormalDistribution) ,\
(11, TruncatedNormalDistribution) ,\
(12, AlphaDropOut),\
(13, ExponentialDistribution),\
(14, ExponentialDistributionInv), \
(15, PoissonDistribution), \
(16, GammaDistribution)
2019-06-06 14:21:15 +02:00
#define PAIRWISE_INT_OPS \
(0, ShiftLeft), \
(1, ShiftRight), \
(2, CyclicShiftLeft), \
(3, CyclicShiftRight), \
(4, IntAnd), \
(5, IntOr), \
(6, IntXor)
2019-06-06 14:21:15 +02:00
#define PAIRWISE_BOOL_OPS \
(0, EqualTo),\
(1, GreaterThan),\
(2, LessThan),\
(3, Epsilon),\
(4, GreaterThanOrEqual),\
(5, MatchCondition) ,\
2019-06-06 14:21:15 +02:00
(6, NotEqualTo),\
(7, And),\
(8, Or),\
(9, Xor) ,\
(10, Not) ,\
(11, LessThanOrEqual)
2019-06-06 14:21:15 +02:00
#define PAIRWISE_TRANSFORM_OPS \
(0, Add),\
(1, CopyPws),\
(2, Divide),\
(3, Multiply),\
(4, Pow),\
(5, ReverseSubtract),\
(6, Subtract),\
(7, MaxPairwise),\
(8, MinPairwise),\
(9, Copy2) ,\
(10, Axpy),\
(11, ReverseDivide),\
(12, CompareAndSet),\
(13, CompareAndReplace),\
(14, Remainder),\
(15, FMod),\
(16, Atan2) ,\
(17, TruncateDiv),\
(18, FloorDiv), \
(19, FloorMod) ,\
(20, SquaredSubtract) ,\
(21, ReverseMod),\
(22, SafeDivide), \
(23, Mod) ,\
(24, RelativeError) ,\
(25, BinaryRelativeError) ,\
(26, BinaryMinimumAbsoluteRelativeError) ,\
(27, LogicalOr) ,\
(28, LogicalXor) ,\
(29, LogicalNot) ,\
(30, LogicalAnd) ,\
(31, PowDerivative), \
(32, LogPoissonLoss), \
(33, LogPoissonLossFull) , \
(34, AMaxPairwise), \
(35, AMinPairwise) ,\
(36, TruncateMod), \
(37, ReplaceNans), \
(38, DivideNoNan), \
(39, IGamma), \
(40, IGammac)
2019-06-06 14:21:15 +02:00
#define INDEX_REDUCE_OPS \
(0, IndexMax), \
(1, IndexMin), \
(2, IndexAbsoluteMax), \
(3, IndexAbsoluteMin) , \
(4, FirstIndex) , \
(5, LastIndex)
#endif //PROJECT_LEGACY_OPS_H