From ac7fb903d7badf2fd042a8762fdfebd809c72a09 Mon Sep 17 00:00:00 2001 From: raver119 Date: Sat, 6 Jun 2020 15:26:55 +0300 Subject: [PATCH] C++ rearrangements (#485) * initial commit Signed-off-by: raver119@gmail.com * some minor singleton changes Signed-off-by: raver119@gmail.com * more iterations Signed-off-by: raver119 * more singletons updated Signed-off-by: raver119 * more singletons updated Signed-off-by: raver119 * more changes Signed-off-by: raver119@gmail.com * CUDA updates Signed-off-by: raver119@gmail.com * Java side update Signed-off-by: raver119@gmail.com * one commented out test Signed-off-by: raver119@gmail.com --- libnd4j/UnderstandingGraph.md | 2 +- libnd4j/include/array/ConstantDataBuffer.h | 29 +- libnd4j/include/array/ConstantOffsetsBuffer.h | 49 ++++ libnd4j/include/array/ConstantShapeBuffer.h | 49 ++++ .../include/array/CudaPointerDeallocator.h | 38 +++ libnd4j/include/array/DataTypeUtils.h | 6 +- libnd4j/include/array/NDArray.h | 21 +- libnd4j/include/array/NDArray.hXX | 169 ++++++------ libnd4j/include/array/PointerDeallocator.h | 39 +++ libnd4j/include/array/PointerWrapper.h | 49 ++++ .../include/array/PrimaryPointerDeallocator.h | 38 +++ libnd4j/include/array/TadPack.h | 9 +- libnd4j/include/array/cpu/NDArray.cpp | 2 +- .../array/cuda/CudaPointerDeallocator.cu | 29 ++ libnd4j/include/array/cuda/DataBuffer.cu | 12 +- libnd4j/include/array/cuda/NDArray.cu | 2 +- .../include/array/impl/ConstantDataBuffer.cpp | 57 ++-- .../array/impl/ConstantOffsetsBuffer.cpp | 51 ++++ .../array/impl/ConstantShapeBuffer.cpp | 51 ++++ libnd4j/include/array/impl/DataBuffer.cpp | 22 +- .../include/array/impl/PointerDeallocator.cpp | 29 ++ libnd4j/include/array/impl/PointerWrapper.cpp | 37 +++ .../array/impl/PrimaryPointerDeallocator.cpp | 29 ++ libnd4j/include/array/impl/TadPack.cpp | 16 +- libnd4j/include/execution/ThreadPool.h | 6 +- libnd4j/include/execution/Threads.h | 16 +- .../include/execution/cpu/LaunchContext.cpp | 19 +- .../include/execution/cuda/LaunchContext.cu | 52 ++-- libnd4j/include/execution/impl/ThreadPool.cpp | 30 +- libnd4j/include/execution/impl/Threads.cpp | 14 +- libnd4j/include/execution/impl/Ticket.cpp | 6 +- libnd4j/include/graph/ContextPrototype.h | 2 +- libnd4j/include/graph/GraphHolder.h | 3 +- .../graph/execution/impl/LogicReturn.cpp | 4 +- .../graph/execution/impl/LogicWhile.cpp | 2 +- libnd4j/include/graph/impl/Context.cpp | 2 +- libnd4j/include/graph/impl/Graph.cpp | 14 +- .../include/graph/impl/GraphExecutioner.cpp | 26 +- libnd4j/include/graph/impl/GraphHolder.cpp | 10 +- libnd4j/include/graph/impl/Node.cpp | 2 +- libnd4j/include/helpers/BlasHelper.h | 4 +- libnd4j/include/helpers/ConstantHelper.h | 5 +- libnd4j/include/helpers/ConstantShapeHelper.h | 18 +- libnd4j/include/helpers/ConstantTadHelper.h | 4 +- libnd4j/include/helpers/DebugHelper.h | 2 +- libnd4j/include/helpers/LoopKind.h | 2 +- libnd4j/include/helpers/Loops.h | 8 +- libnd4j/include/helpers/OpTracker.h | 4 +- .../helpers/benchmark/BroadcastBenchmark.h | 12 +- .../helpers/benchmark/DeclarableBenchmark.h | 2 +- .../helpers/benchmark/ReductionBenchmark.h | 6 +- .../include/helpers/cpu/ConstantHelper.cpp | 25 +- .../helpers/cpu/ConstantShapeHelper.cpp | 63 ++--- .../include/helpers/cpu/ConstantTadHelper.cpp | 59 +--- libnd4j/include/helpers/cpu/MmulHelper.cpp | 16 +- libnd4j/include/helpers/cpu/cublasHelper.cpp | 11 +- libnd4j/include/helpers/cublasHelper.h | 5 +- .../include/helpers/cuda/ConstantHelper.cu | 29 +- .../helpers/cuda/ConstantShapeHelper.cu | 51 ++-- .../include/helpers/cuda/ConstantTadHelper.cu | 29 +- .../include/helpers/cuda_off/MmulHelper.cu | 8 +- .../include/helpers/cuda_off/cublasHelper.cu | 13 +- libnd4j/include/helpers/helper_hash.h | 4 +- libnd4j/include/helpers/impl/BlasHelper.cpp | 29 +- .../include/helpers/impl/OmpLaunchHelper.cpp | 12 +- libnd4j/include/helpers/impl/OpTracker.cpp | 10 +- libnd4j/include/helpers/impl/ShapeUtils.cpp | 30 +- libnd4j/include/helpers/impl/helper_hash.cpp | 10 +- libnd4j/include/helpers/logger.h | 6 +- libnd4j/include/helpers/shape.h | 8 +- libnd4j/include/legacy/NativeOps.h | 10 +- .../legacy/cpu/NativeOpExecutioner.cpp | 54 ++-- libnd4j/include/legacy/cpu/NativeOps.cpp | 80 +++--- .../legacy/cuda/NativeOpExecutioner.cu | 22 +- libnd4j/include/legacy/cuda/NativeOps.cu | 246 +++++++++-------- libnd4j/include/legacy/impl/Environment.cpp | 23 +- libnd4j/include/loops/cpu/broadcasting.hpp | 6 +- .../include/loops/cpu/broadcasting_bool.hpp | 8 +- .../include/loops/cpu/broadcasting_int.hpp | 8 +- libnd4j/include/loops/cpu/indexreduce.hpp | 4 +- .../include/loops/cpu/reduce/reduce_bool.cpp | 4 +- .../include/loops/cpu/reduce/reduce_float.hpp | 6 +- .../include/loops/cpu/reduce/reduce_long.cpp | 6 +- .../include/loops/cpu/reduce/reduce_same.cpp | 6 +- libnd4j/include/loops/cpu/reduce3.hpp | 2 +- libnd4j/include/loops/cpu/scalar.hpp | 2 +- libnd4j/include/loops/cpu/scalar_bool.cpp | 2 +- libnd4j/include/loops/cpu/scalar_int.cpp | 2 +- .../include/loops/cpu/summarystatsreduce.cpp | 2 +- .../loops/cuda/legacy/transform.legacy | 2 +- libnd4j/include/loops/cuda/scalar.chpp | 2 +- libnd4j/include/loops/cuda/scalar_bool.cu | 2 +- libnd4j/include/loops/cuda/scalar_int.cu | 2 +- .../include/loops/cuda/summarystatsreduce.cu | 6 +- libnd4j/include/memory/MemoryCounter.h | 4 +- libnd4j/include/memory/MemoryRegistrator.h | 3 +- libnd4j/include/memory/MemoryTracker.h | 3 +- libnd4j/include/memory/impl/MemoryCounter.cpp | 14 +- .../include/memory/impl/MemoryRegistrator.cpp | 11 +- libnd4j/include/memory/impl/MemoryTracker.cpp | 14 +- .../include/ops/declarable/OpRegistrator.h | 2 +- .../generic/bitwise/bits_hamming_distance.cpp | 2 +- .../declarable/generic/blas/batched_gemm.cpp | 4 +- .../ops/declarable/generic/blas/matmul.cpp | 2 +- .../declarable/generic/blas/tensormmul.cpp | 2 +- .../ops/declarable/generic/boolean/choose.cpp | 4 +- .../ops/declarable/generic/boolean/where.cpp | 2 +- .../declarable/generic/boolean/where_np.cpp | 4 +- .../generic/compat/compat_sparse_to_dense.cpp | 2 +- .../generic/compat/compat_string_split.cpp | 4 +- .../declarable/generic/compression/bitmap.cpp | 4 +- .../generic/compression/threshold.cpp | 2 +- .../declarable/generic/datatypes/bitcast.cpp | 8 +- .../ops/declarable/generic/datatypes/cast.cpp | 2 +- .../generic/helpers/BroadcastHelper.h | 2 +- .../generic/images/crop_and_resize.cpp | 2 +- .../generic/images/image_resize.cpp | 2 +- .../generic/images/resize_images.cpp | 2 +- .../declarable/generic/images/rgbToGrs.cpp | 2 +- .../generic/kernels/knn_mindistance.cpp | 2 +- .../declarable/generic/linalg/diagPart.cpp | 2 +- .../ops/declarable/generic/linalg/eye.cpp | 2 +- .../ops/declarable/generic/linalg/lstsq.cpp | 8 +- .../generic/linalg/matrixDiagPart.cpp | 2 +- .../generic/linalg/matrix_determinant.cpp | 18 +- .../ops/declarable/generic/linalg/qr.cpp | 8 +- .../generic/linalg/sufficient_statistics.cpp | 4 +- .../ops/declarable/generic/linalg/svd.cpp | 4 +- .../ops/declarable/generic/linalg/trace.cpp | 2 +- .../ops/declarable/generic/linalg/tri.cpp | 2 +- .../generic/loss/absoluteDifference.cpp | 4 +- .../generic/loss/cosineDistance.cpp | 2 +- .../ops/declarable/generic/loss/hingeLoss.cpp | 4 +- .../ops/declarable/generic/loss/huberLoss.cpp | 4 +- .../ops/declarable/generic/loss/l2_loss.cpp | 2 +- .../ops/declarable/generic/loss/logLoss.cpp | 4 +- .../generic/loss/log_poisson_loss.cpp | 4 +- .../generic/loss/meanPairWsSqErr.cpp | 2 +- .../ops/declarable/generic/loss/meanSqErr.cpp | 4 +- .../generic/loss/sigmCrossEntropy.cpp | 4 +- .../generic/loss/softmaxCrossEntropy.cpp | 8 +- .../loss/softmaxCrossEntropyWithLogits.cpp | 4 +- .../generic/nn/activations/crelu.cpp | 4 +- .../ops/declarable/generic/nn/batchnorm.cpp | 4 +- .../ops/declarable/generic/nn/bias_add.cpp | 2 +- .../declarable/generic/nn/convo/deconv2d.cpp | 2 +- .../generic/nn/convo/deconv2d_tf.cpp | 2 +- .../generic/nn/convo/dilation2d.cpp | 4 +- .../generic/nn/dot_product_attention.cpp | 4 +- .../generic/nn/embedding_lookup.cpp | 4 +- .../nn/multi_head_dot_product_attention.cpp | 4 +- .../generic/nn/pooling/avgpool2d.cpp | 4 +- .../generic/nn/pooling/avgpool3d.cpp | 4 +- .../generic/nn/pooling/maxpool2d.cpp | 4 +- .../generic/nn/pooling/maxpool3d.cpp | 4 +- .../nn/pooling/maxpool_with_argmax.cpp | 4 +- .../generic/nn/pooling/pnormpool2d.cpp | 4 +- .../declarable/generic/nn/recurrent/gru.cpp | 12 +- .../generic/nn/recurrent/gruCell.cpp | 2 +- .../generic/nn/recurrent/lstmCell.cpp | 2 +- .../generic/nn/recurrent/lstmLayer.cpp | 6 +- .../declarable/generic/nn/recurrent/sru.cpp | 12 +- .../generic/nn/recurrent/sruCell.cpp | 2 +- .../generic/parity_ops/bincount.cpp | 2 +- .../parity_ops/broadcast_dynamic_shape.cpp | 2 +- .../generic/parity_ops/check_numerics.cpp | 2 +- .../parity_ops/compare_and_bitpack.cpp | 2 +- .../generic/parity_ops/confusion_matrix.cpp | 2 +- .../declarable/generic/parity_ops/expose.cpp | 2 +- .../generic/parity_ops/in_top_k.cpp | 2 +- .../generic/parity_ops/listdiff.cpp | 4 +- .../parity_ops/non_max_suppression.cpp | 4 +- .../non_max_suppression_overlaps.cpp | 2 +- .../generic/parity_ops/nth_element.cpp | 4 +- .../declarable/generic/parity_ops/onehot.cpp | 2 +- .../declarable/generic/parity_ops/top_k.cpp | 2 +- .../declarable/generic/parity_ops/unique.cpp | 12 +- .../generic/parity_ops/zero_fraction.cpp | 2 +- .../declarable/generic/random/bernoulli.cpp | 2 +- .../declarable/generic/random/exponential.cpp | 2 +- .../ops/declarable/generic/random/gamma.cpp | 2 +- .../declarable/generic/random/get_seed.cpp | 2 +- .../declarable/generic/random/multinomial.cpp | 2 +- .../ops/declarable/generic/random/normal.cpp | 2 +- .../ops/declarable/generic/random/poisson.cpp | 2 +- .../declarable/generic/random/random_crop.cpp | 2 +- .../declarable/generic/random/set_seed.cpp | 2 +- .../ops/declarable/generic/random/uniform.cpp | 2 +- .../ops/declarable/generic/reduce/argamax.cpp | 2 +- .../ops/declarable/generic/reduce/argamin.cpp | 2 +- .../ops/declarable/generic/reduce/argmax.cpp | 2 +- .../ops/declarable/generic/reduce/argmin.cpp | 2 +- .../declarable/generic/shape/broadcast_to.cpp | 2 +- .../shape/evaluate_reduction_shape.cpp | 4 +- .../declarable/generic/shape/expand_dims.cpp | 6 +- .../ops/declarable/generic/shape/flatten.cpp | 2 +- .../ops/declarable/generic/shape/order.cpp | 2 +- .../ops/declarable/generic/shape/rank.cpp | 2 +- .../ops/declarable/generic/shape/reshape.cpp | 4 +- .../ops/declarable/generic/shape/shape.cpp | 2 +- .../ops/declarable/generic/shape/shapes.cpp | 2 +- .../ops/declarable/generic/shape/size.cpp | 2 +- .../ops/declarable/generic/shape/size_at.cpp | 2 +- .../ops/declarable/generic/shape/squeeze.cpp | 6 +- .../generic/shape/tile_to_shape.cpp | 2 +- .../ops/declarable/generic/tensor/create.cpp | 2 +- .../ops/declarable/generic/tensor/fill.cpp | 2 +- .../declarable/generic/tensor/lin_space.cpp | 2 +- .../ops/declarable/generic/tensor/ones_as.cpp | 2 +- .../ops/declarable/generic/tensor/range.cpp | 14 +- .../generic/tensor/strided_slice.cpp | 14 +- .../declarable/generic/tensor/zeros_as.cpp | 2 +- .../declarable/generic/tests/test_scalar.cpp | 2 +- .../declarable/generic/tests/testcustom.cpp | 2 +- .../generic/thrid_party/firas_sparse.cpp | 2 +- .../generic/transforms/batch_to_space.cpp | 2 +- .../generic/transforms/batch_to_space_nd.cpp | 2 +- .../transforms/clip_by_global_norm.cpp | 2 +- .../declarable/generic/transforms/concat.cpp | 16 +- .../generic/transforms/depth_to_space.cpp | 2 +- .../generic/transforms/dynamic_stitch.cpp | 2 +- .../declarable/generic/transforms/gather.cpp | 2 +- .../generic/transforms/hashcode.cpp | 2 +- .../generic/transforms/histogram.cpp | 2 +- .../transforms/histogram_fixed_width.cpp | 2 +- .../generic/transforms/merge_add.cpp | 2 +- .../generic/transforms/merge_avg.cpp | 2 +- .../generic/transforms/merge_max.cpp | 2 +- .../generic/transforms/mirrorPad.cpp | 2 +- .../ops/declarable/generic/transforms/pad.cpp | 2 +- .../declarable/generic/transforms/repeat.cpp | 2 +- .../declarable/generic/transforms/slice.cpp | 8 +- .../generic/transforms/space_to_batch.cpp | 2 +- .../generic/transforms/space_to_batch_nd.cpp | 2 +- .../generic/transforms/space_to_depth.cpp | 2 +- .../declarable/generic/transforms/split.cpp | 4 +- .../declarable/generic/transforms/split_v.cpp | 2 +- .../declarable/generic/transforms/stack.cpp | 8 +- .../declarable/generic/transforms/tear.cpp | 4 +- .../declarable/generic/transforms/tile.cpp | 2 +- .../declarable/generic/transforms/unstack.cpp | 6 +- .../generic/util/print_affinity.cpp | 2 +- .../generic/util/print_variable.cpp | 4 +- .../ops/declarable/helpers/cpu/addBias.cpp | 4 +- .../ops/declarable/helpers/cpu/adjust_hue.cpp | 4 +- .../helpers/cpu/adjust_saturation.cpp | 4 +- .../declarable/helpers/cpu/batched_gemm.cpp | 6 +- .../ops/declarable/helpers/cpu/dynamic.cpp | 4 +- .../ops/declarable/helpers/cpu/gather.cpp | 16 +- .../helpers/cpu/gatherTransforms.cpp | 2 +- .../declarable/helpers/cpu/imagesHelpers.cpp | 12 +- .../helpers/cpu/indexReductions.hpp | 4 +- .../ops/declarable/helpers/cpu/ismax.cpp | 4 +- .../ops/declarable/helpers/cpu/lrn.cpp | 8 +- .../ops/declarable/helpers/cpu/lup.cpp | 2 +- .../declarable/helpers/cpu/nth_element.cpp | 2 +- .../ops/declarable/helpers/cpu/one_hot.cpp | 2 +- .../declarable/helpers/cpu/randomShuffle.cpp | 6 +- .../ops/declarable/helpers/cpu/roll.cpp | 4 +- .../ops/declarable/helpers/cpu/scatter.cpp | 8 +- .../ops/declarable/helpers/cpu/softmax.cpp | 2 +- .../ops/declarable/helpers/cpu/stack.cpp | 12 +- .../declarable/helpers/cuda/activations.cu | 4 +- .../ops/declarable/helpers/cuda/adjust_hue.cu | 18 +- .../helpers/cuda/adjust_saturation.cu | 18 +- .../ops/declarable/helpers/cuda/batchnorm.cu | 6 +- .../ops/declarable/helpers/cuda/confusion.cu | 2 +- .../ops/declarable/helpers/cuda/dynamic.cu | 8 +- .../helpers/cuda/extract_patches.cu | 4 +- .../helpers/cuda/histogramFixedWidth.cu | 6 +- .../declarable/helpers/cuda/imagesHelpers.cu | 24 +- .../helpers/cuda/indexReductions.cu | 8 +- .../ops/declarable/helpers/cuda/ismax.cu | 2 +- .../ops/declarable/helpers/cuda/lrn.cu | 8 +- .../ops/declarable/helpers/cuda/lstsq.cu | 2 +- .../ops/declarable/helpers/cuda/lup.cu | 24 +- .../declarable/helpers/cuda/matrix_band.cu | 4 +- .../helpers/cuda/matrix_diag_part.cu | 4 +- .../ops/declarable/helpers/cuda/meshgrid.cu | 2 +- .../declarable/helpers/cuda/nth_element.cu | 2 +- .../ops/declarable/helpers/cuda/percentile.cu | 2 +- .../ops/declarable/helpers/cuda/prefix.cu | 4 +- .../include/ops/declarable/helpers/cuda/qr.cu | 6 +- .../ops/declarable/helpers/cuda/reverse.cu | 4 +- .../ops/declarable/helpers/cuda/roll.cu | 2 +- .../ops/declarable/helpers/cuda/scatter.cu | 40 +-- .../declarable/helpers/cuda/scatter_simple.cu | 2 +- .../declarable/helpers/cuda/scatter_update.cu | 4 +- .../declarable/helpers/cuda/segment_max.cu | 24 +- .../declarable/helpers/cuda/segment_mean.cu | 24 +- .../declarable/helpers/cuda/segment_min.cu | 24 +- .../declarable/helpers/cuda/segment_prod.cu | 24 +- .../declarable/helpers/cuda/segment_sqrtn.cu | 12 +- .../declarable/helpers/cuda/segment_sum.cu | 20 +- .../ops/declarable/helpers/cuda/solve.cu | 10 +- .../ops/declarable/helpers/cuda/stack.cu | 8 +- .../ops/declarable/helpers/cuda/top_k.cu | 8 +- .../ops/declarable/helpers/cuda/transforms.cu | 2 +- .../helpers/cuda/triangular_solve.cu | 10 +- .../include/ops/declarable/impl/BooleanOp.cpp | 2 +- .../declarable/impl/BroadcastableBoolOp.cpp | 18 +- .../ops/declarable/impl/BroadcastableOp.cpp | 20 +- .../ops/declarable/impl/DeclarableListOp.cpp | 2 +- .../ops/declarable/impl/DeclarableOp.cpp | 30 +- .../declarable/impl/DeclarableReductionOp.cpp | 2 +- .../declarable/impl/LegacyBroadcastBoolOp.cpp | 14 +- .../ops/declarable/impl/LegacyBroadcastOp.cpp | 12 +- .../declarable/impl/LegacyIndexReduceOp.cpp | 14 +- .../impl/LegacyPairwiseTransformBoolOp.cpp | 2 +- .../ops/declarable/impl/LegacyRandomOp.cpp | 2 +- .../ops/declarable/impl/LegacyReduce3Op.cpp | 12 +- .../declarable/impl/LegacyReduceBoolOp.cpp | 12 +- .../declarable/impl/LegacyReduceFloatOp.cpp | 12 +- .../declarable/impl/LegacyReduceLongOp.cpp | 12 +- .../declarable/impl/LegacyReduceSameOp.cpp | 12 +- .../ops/declarable/impl/LegacyScalarOp.cpp | 2 +- .../ops/declarable/impl/LegacyStatsOp.cpp | 6 +- .../declarable/impl/LegacyTransformBoolOp.cpp | 2 +- .../ops/declarable/impl/OpDescriptor.cpp | 6 +- .../ops/declarable/impl/OpRegistrator.cpp | 32 +-- .../ops/declarable/impl/PlatformHelper.cpp | 2 +- libnd4j/include/ops/impl/gemm.cpp | 2 +- libnd4j/include/ops/impl/specials_double.hpp | 8 +- libnd4j/include/ops/special_random_ops.h | 12 +- libnd4j/include/system/Environment.h | 6 +- libnd4j/include/system/op_boilerplate.h | 34 +-- libnd4j/include/system/platform_boilerplate.h | 2 +- libnd4j/minifier/minifier.cpp | 2 +- libnd4j/server/GraphServer.cpp | 10 +- .../layers_tests/ConditionalTests.cpp | 12 +- .../layers_tests/ConstantShapeHelperTests.cpp | 40 +-- .../layers_tests/ConvolutionTests1.cpp | 1 - .../layers_tests/CudaBasicsTests1.cu | 26 +- .../layers_tests/CudaBasicsTests2.cu | 20 +- .../layers_tests/DataBufferTests.cpp | 26 +- .../layers_tests/DataBufferTestsCuda.cu | 34 +-- .../layers_tests/DeclarableOpsTests1.cpp | 24 +- .../layers_tests/DeclarableOpsTests12.cpp | 8 +- .../layers_tests/DeclarableOpsTests13.cpp | 6 +- .../layers_tests/DeclarableOpsTests14.cpp | 2 +- .../layers_tests/DeclarableOpsTests3.cpp | 20 +- .../layers_tests/DeclarableOpsTests4.cpp | 2 +- libnd4j/tests_cpu/layers_tests/EmptyTests.cpp | 2 +- .../layers_tests/ExtraArgumentsTests.cpp | 2 +- .../layers_tests/FlatBuffersTests.cpp | 24 +- .../layers_tests/GraphHolderTests.cpp | 28 +- .../layers_tests/GraphStateTests.cpp | 8 +- libnd4j/tests_cpu/layers_tests/GraphTests.cpp | 8 +- .../tests_cpu/layers_tests/HashUtilsTests.cpp | 4 +- .../layers_tests/JavaInteropTests.cpp | 48 ++-- .../layers_tests/LegacyOpsCudaTests.cu | 2 +- .../tests_cpu/layers_tests/LegacyOpsTests.cpp | 28 +- libnd4j/tests_cpu/layers_tests/MmapTests.cpp | 2 +- .../layers_tests/MultiDataTypeTests.cpp | 80 +++--- .../layers_tests/NDArrayCudaBasicsTests.cu | 6 +- .../tests_cpu/layers_tests/NativeOpsTests.cpp | 28 +- .../layers_tests/OmpLaunchHelperTests.cpp | 12 +- .../tests_cpu/layers_tests/OpTrackerTests.cpp | 12 +- .../layers_tests/PlaygroundTests.cpp | 16 +- .../layers_tests/ServerRelatedTests.cpp | 26 +- .../tests_cpu/layers_tests/SortCpuTests.cpp | 8 +- libnd4j/tests_cpu/layers_tests/TadTests.cpp | 4 +- .../tests_cpu/layers_tests/ThreadsTests.cpp | 24 +- .../tests_cpu/layers_tests/WorkspaceTests.cpp | 24 +- .../java/org/nd4j/nativeblas/NativeOps.java | 9 +- .../nativeblas/OpaqueConstantShapeBuffer.java | 27 ++ .../ops/executioner/CudaExecutioner.java | 10 +- .../java/org/nd4j/nativeblas/Nd4jCuda.java | 227 +++++++++++++-- .../org/nd4j/nativeblas/Nd4jCudaPresets.java | 8 +- .../nativecpu/ops/NativeOpExecutioner.java | 6 +- .../java/org/nd4j/nativeblas/Nd4jCpu.java | 259 +++++++++++++++--- .../org/nd4j/nativeblas/Nd4jCpuPresets.java | 8 +- .../profiling/PerformanceTrackerTests.java | 1 + 373 files changed, 2698 insertions(+), 1836 deletions(-) create mode 100644 libnd4j/include/array/ConstantOffsetsBuffer.h create mode 100644 libnd4j/include/array/ConstantShapeBuffer.h create mode 100644 libnd4j/include/array/CudaPointerDeallocator.h create mode 100644 libnd4j/include/array/PointerDeallocator.h create mode 100644 libnd4j/include/array/PointerWrapper.h create mode 100644 libnd4j/include/array/PrimaryPointerDeallocator.h create mode 100644 libnd4j/include/array/cuda/CudaPointerDeallocator.cu create mode 100644 libnd4j/include/array/impl/ConstantOffsetsBuffer.cpp create mode 100644 libnd4j/include/array/impl/ConstantShapeBuffer.cpp create mode 100644 libnd4j/include/array/impl/PointerDeallocator.cpp create mode 100644 libnd4j/include/array/impl/PointerWrapper.cpp create mode 100644 libnd4j/include/array/impl/PrimaryPointerDeallocator.cpp create mode 100644 nd4j/nd4j-backends/nd4j-api-parent/nd4j-native-api/src/main/java/org/nd4j/nativeblas/OpaqueConstantShapeBuffer.java diff --git a/libnd4j/UnderstandingGraph.md b/libnd4j/UnderstandingGraph.md index 7e2231c08..d1c51b428 100644 --- a/libnd4j/UnderstandingGraph.md +++ b/libnd4j/UnderstandingGraph.md @@ -77,7 +77,7 @@ If you're adding new ops, and want to make sure they run ok on your specific dev Despite being simple - it still provides you with time spent in various parts of Graph. ```c++ -Environment::getInstance()->setProfiling(true); +Environment::getInstance().setProfiling(true); auto graph = GraphExecutioner::importFromFlatBuffers("./resources/ae_00.fb"); auto profile = GraphProfilingHelper::profile(graph, 1000); diff --git a/libnd4j/include/array/ConstantDataBuffer.h b/libnd4j/include/array/ConstantDataBuffer.h index e8bafe114..197b93307 100644 --- a/libnd4j/include/array/ConstantDataBuffer.h +++ b/libnd4j/include/array/ConstantDataBuffer.h @@ -22,37 +22,40 @@ #include #include +#include +#include +#include namespace sd { class ND4J_EXPORT ConstantDataBuffer { private: - Nd4jPointer _primaryBuffer = nullptr; - Nd4jPointer _specialBuffer = nullptr; - Nd4jLong _length = 0; - Nd4jLong _sizeOf = 0; + std::shared_ptr _primaryBuffer; + std::shared_ptr _specialBuffer = nullptr; + uint64_t _length = 0; + uint8_t _sizeOf = 0; public: - ConstantDataBuffer(Nd4jPointer primary, Nd4jPointer special, Nd4jLong numEelements, Nd4jLong sizeOf); + ConstantDataBuffer(const std::shared_ptr& primary, uint64_t numEelements, DataType dype); + ConstantDataBuffer(const std::shared_ptr& primary, const std::shared_ptr& special, uint64_t numEelements, DataType dype); ConstantDataBuffer(const ConstantDataBuffer &other); ConstantDataBuffer() = default; ~ConstantDataBuffer() = default; - Nd4jLong sizeOf() const; - Nd4jLong length() const; + uint8_t sizeOf() const; + uint64_t length() const; - Nd4jPointer primary() const; - Nd4jPointer special() const; + void* primary() const; + void* special() const; ConstantDataBuffer& operator=(const ConstantDataBuffer& other) = default; ConstantDataBuffer& operator=(ConstantDataBuffer&& other) noexcept = default; + template + T* primaryAsT() const; template - T* primaryAsT(); - - template - T* specialAsT(); + T* specialAsT() const; }; } diff --git a/libnd4j/include/array/ConstantOffsetsBuffer.h b/libnd4j/include/array/ConstantOffsetsBuffer.h new file mode 100644 index 000000000..61c1e381f --- /dev/null +++ b/libnd4j/include/array/ConstantOffsetsBuffer.h @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2019-2020 Konduit K.K. + * + * 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 SD_ARRAY_CONSTANTOFFSETSBUFFER_H_ +#define SD_ARRAY_CONSTANTOFFSETSBUFFER_H_ + +#include +#include +#include +#include + +namespace sd { + +class ND4J_EXPORT ConstantOffsetsBuffer { + private: + std::shared_ptr _primaryOffsets; + std::shared_ptr _specialOffsets; + + public: + ConstantOffsetsBuffer(const std::shared_ptr &primary); + ConstantOffsetsBuffer(const std::shared_ptr &primary, const std::shared_ptr &special); + ConstantOffsetsBuffer() = default; + ~ConstantOffsetsBuffer() = default; + + const Nd4jLong* primary() const; + const Nd4jLong* special() const; + const Nd4jLong* platform() const; +}; + +} // namespace sd + +#endif //SD_ARRAY_CONSTANTOFFSETSBUFFER_H_ diff --git a/libnd4j/include/array/ConstantShapeBuffer.h b/libnd4j/include/array/ConstantShapeBuffer.h new file mode 100644 index 000000000..299653271 --- /dev/null +++ b/libnd4j/include/array/ConstantShapeBuffer.h @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2019-2020 Konduit K.K. + * + * 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 SD_ARRAY_CONSTANTSHAPEBUFFER_H_ +#define SD_ARRAY_CONSTANTSHAPEBUFFER_H_ + +#include +#include +#include +#include + +namespace sd { + +class ND4J_EXPORT ConstantShapeBuffer { + private: + std::shared_ptr _primaryShapeInfo; + std::shared_ptr _specialShapeInfo; + + public: + ConstantShapeBuffer(const std::shared_ptr &primary); + ConstantShapeBuffer(const std::shared_ptr &primary, const std::shared_ptr &special); + ConstantShapeBuffer() = default; + ~ConstantShapeBuffer() = default; + + const Nd4jLong* primary() const; + const Nd4jLong* special() const; + const Nd4jLong* platform() const; +}; + +} // namespace sd + +#endif //SD_ARRAY_CONSTANTSHAPEBUFFER_H_ diff --git a/libnd4j/include/array/CudaPointerDeallocator.h b/libnd4j/include/array/CudaPointerDeallocator.h new file mode 100644 index 000000000..c5c817aeb --- /dev/null +++ b/libnd4j/include/array/CudaPointerDeallocator.h @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2019-2020 Konduit K.K. + * + * 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 SD_CUDAYPOINTERDEALLOCATOR_H_ +#define SD_CUDAYPOINTERDEALLOCATOR_H_ + +#include +#include +#include + +namespace sd { +class ND4J_EXPORT CudaPointerDeallocator : public PointerDeallocator { + public: + CudaPointerDeallocator() = default; + ~CudaPointerDeallocator() = default; + + void release(void* ptr) override; +}; +} + +#endif //SD_CUDAYPOINTERDEALLOCATOR_H_ diff --git a/libnd4j/include/array/DataTypeUtils.h b/libnd4j/include/array/DataTypeUtils.h index bd89605d1..686b5bc97 100644 --- a/libnd4j/include/array/DataTypeUtils.h +++ b/libnd4j/include/array/DataTypeUtils.h @@ -110,7 +110,7 @@ namespace sd { // if proposed dataType is already floating point - return it if (isR(typeX)) return typeX; - return Environment::getInstance()->defaultFloatDataType(); + return Environment::getInstance().defaultFloatDataType(); } FORCEINLINE bool DataTypeUtils::isR(sd::DataType dataType) { @@ -154,7 +154,7 @@ namespace sd { // if both data types are float - return biggest one if (rX && rY) { // if we allow precision boost, then we pick bigger data type - if (sd::Environment::getInstance()->precisionBoostAllowed()) { + if (sd::Environment::getInstance().precisionBoostAllowed()) { return nd4j_max(typeX, typeY); } else { // and we return first operand otherwise @@ -165,7 +165,7 @@ namespace sd { // if that's not real type, we apply same rules if (!rX && !rY) { - if (sd::Environment::getInstance()->precisionBoostAllowed()) { + if (sd::Environment::getInstance().precisionBoostAllowed()) { return nd4j_max(typeX, typeY); } else { // and we return first operand otherwise diff --git a/libnd4j/include/array/NDArray.h b/libnd4j/include/array/NDArray.h index c314d25b6..7b32b7d49 100644 --- a/libnd4j/include/array/NDArray.h +++ b/libnd4j/include/array/NDArray.h @@ -45,6 +45,7 @@ #include #include #include +#include namespace sd { @@ -155,8 +156,8 @@ namespace sd { /** * contains shape info: matrix rank, numbers of elements per each dimension, dimensions strides, element-wise-stride, c-like or fortan-like order */ - Nd4jLong *_shapeInfo = nullptr; - Nd4jLong *_shapeInfoD = nullptr; + const Nd4jLong *_shapeInfo = nullptr; + const Nd4jLong *_shapeInfoD = nullptr; /** * pointer on device launch context (with all data needed there). @@ -1219,7 +1220,7 @@ namespace sd { void setShapeInfo(const Nd4jLong *shapeInfo); void setShapeInfo(const Nd4jLong *shapeInfo, const sd::DataType dtype); void setShapeInfo(const ShapeDescriptor& descriptor); - void setShapeInfo(const ConstantDataBuffer& shapeBuffer); + void setShapeInfo(const ConstantShapeBuffer& shapeBuffer); /** * returns absolute offset which corresponds to given sequential index @@ -1516,9 +1517,9 @@ FORCEINLINE R NDArray::templatedGet(void const* buffer, Nd4jLong index) const { ////////////////////////////////////////////////////////////////////////// void NDArray::setShapeInfo(Nd4jLong *shapeInfo) { - auto buffer = ConstantShapeHelper::getInstance()->bufferForShapeInfo(shapeInfo); - _shapeInfo = buffer.primaryAsT(); - _shapeInfoD = buffer.specialAsT(); + auto buffer = ConstantShapeHelper::getInstance().bufferForShapeInfo(shapeInfo); + _shapeInfo = buffer.primary(); + _shapeInfoD = buffer.special(); if (shapeInfo != nullptr) { _dataType = ArrayOptions::dataType(_shapeInfo); @@ -1535,9 +1536,9 @@ void NDArray::setShapeInfo(Nd4jLong *shapeInfo) { ////////////////////////////////////////////////////////////////////////// void NDArray::setShapeInfo(Nd4jLong *shapeInfo, const sd::DataType dtype) { - auto buffer = ConstantShapeHelper::getInstance()->bufferForShapeInfo(shapeInfo); - _shapeInfo = buffer.primaryAsT(); - _shapeInfoD = buffer.specialAsT(); + auto buffer = ConstantShapeHelper::getInstance().bufferForShapeInfo(shapeInfo); + _shapeInfo = buffer.primary(); + _shapeInfoD = buffer.special(); if (shapeInfo != nullptr) { _dataType = dtype; @@ -1623,7 +1624,7 @@ bool NDArray::nonNull() const { if (isEmpty()) return true; - if(!Environment::getInstance()->isCPU()) + if(!Environment::getInstance().isCPU()) return getDataBuffer()->special() != nullptr && specialShapeInfo() != nullptr; return getDataBuffer()->primary() != nullptr && shapeInfo() != nullptr; diff --git a/libnd4j/include/array/NDArray.hXX b/libnd4j/include/array/NDArray.hXX index 9e48b05de..eefe169cf 100644 --- a/libnd4j/include/array/NDArray.hXX +++ b/libnd4j/include/array/NDArray.hXX @@ -181,7 +181,7 @@ NDArray::NDArray(sd::DataType dtype, sd::LaunchContext* context, const bool isSc _buffer->setToZeroBuffers(); } else - setShapeInfo(ConstantShapeHelper::getInstance()->emptyShapeInfo(dtype)); + setShapeInfo(ConstantShapeHelper::getInstance().emptyShapeInfo(dtype)); } ////////////////////////////////////////////////////////////////////////// @@ -1088,9 +1088,11 @@ void NDArray::streamline(char o) { char order = o == 'a' ? this->ordering() : o; syncToDevice(); std::shared_ptr newBuffer = std::make_shared(this->lengthOf() * sizeOfT(), dataType(), getContext()->getWorkspace()); - auto shapeBuffer = ConstantShapeHelper::getInstance()->bufferForShapeInfo(dataType(), order, rankOf(), shapeOf()); - NativeOpExecutioner::execTransformSame(getContext(), transform::Copy, buffer(), shapeInfo(), specialBuffer(), specialShapeInfo(), newBuffer->primary(), static_cast(shapeBuffer.primary()), newBuffer->special(), static_cast(shapeBuffer.special()), nullptr, nullptr, nullptr); - setShapeInfo(static_cast(shapeBuffer.primary())); + auto shapeBuffer = ConstantShapeHelper::getInstance().bufferForShapeInfo(dataType(), order, rankOf(), shapeOf()); + NativeOpExecutioner::execTransformSame(getContext(), transform::Copy, buffer(), shapeInfo(), specialBuffer(), specialShapeInfo(), newBuffer->primary(), + shapeBuffer.primary(), newBuffer->special(), + shapeBuffer.special(), nullptr, nullptr, nullptr); + setShapeInfo(shapeBuffer); _buffer = newBuffer; _offset = 0; tickWriteDevice(); @@ -1355,7 +1357,7 @@ NDArray NDArray::reduceAlongDimension(sd::reduce::FloatOps op, const std::vector std::vector copy(dimensions); - auto newShape = ShapeUtils::evalReduceShapeInfo('c', copy, *this, isR() ? dataType() : Environment::getInstance()->defaultFloatDataType(), keepDims, supportOldShapes, getContext()->getWorkspace()); + auto newShape = ShapeUtils::evalReduceShapeInfo('c', copy, *this, isR() ? dataType() : Environment::getInstance().defaultFloatDataType(), keepDims, supportOldShapes, getContext()->getWorkspace()); NDArray result(newShape, true, getContext()); @@ -1432,7 +1434,7 @@ NDArray NDArray::reduceNumber(sd::reduce::FloatOps op, void *extraParams) const if (isS()) throw std::runtime_error("NDArray::reduceNumber FloatOps: you can't use this method on String array!"); - auto shape = ConstantShapeHelper::getInstance()->scalarShapeInfo(DataTypeUtils::pickFloatingType(dataType())); + auto shape = ConstantShapeHelper::getInstance().scalarShapeInfo(DataTypeUtils::pickFloatingType(dataType())); NDArray result(shape, true, this->getContext()); NDArray::prepareSpecialUse({&result}, {this}); @@ -1461,7 +1463,7 @@ NDArray NDArray::reduceNumber(sd::reduce::BoolOps op, void *extraParams) const { if (isS()) throw std::runtime_error("NDArray::reduceNumber BoolOps: you can't use this method on String array!"); - auto shape = ConstantShapeHelper::getInstance()->scalarShapeInfo(DataType::BOOL); + auto shape = ConstantShapeHelper::getInstance().scalarShapeInfo(DataType::BOOL); NDArray result(shape, true, this->getContext()); NDArray::prepareSpecialUse({&result}, {this}); @@ -1476,7 +1478,7 @@ NDArray NDArray::reduceNumber(sd::reduce::LongOps op, void *extraParams) const { if (isS()) throw std::runtime_error("NDArray::reduceNumber LongOps: you can't use this method on String array!"); - auto shape = ConstantShapeHelper::getInstance()->scalarShapeInfo(DataType::INT64); + auto shape = ConstantShapeHelper::getInstance().scalarShapeInfo(DataType::INT64); NDArray result(shape, true, this->getContext()); NDArray::prepareSpecialUse({&result}, {this}); @@ -1854,8 +1856,7 @@ void NDArray::setAttached(bool reallyAttached) { ////////////////////////////////////////////////////////////////////////// // calculate strides void NDArray::updateStrides(const char order) { - shape::updateStrides(_shapeInfo, order); - syncShape(); + throw std::runtime_error("Forbidden method"); } ////////////////////////////////////////////////////////////////////////// @@ -2456,7 +2457,7 @@ void NDArray::operator+=(const NDArray& other) { if (isS()) throw std::runtime_error("NDArray::operator+=: you can't use this method on String array!"); - if (!Environment::getInstance()->isExperimentalBuild() && this->dataType() != other.dataType() && (this->dataType() != DataType::BOOL || other.dataType() != BOOL)) + if (!Environment::getInstance().isExperimentalBuild() && this->dataType() != other.dataType() && (this->dataType() != DataType::BOOL || other.dataType() != BOOL)) throw sd::datatype_exception::build("NDArray operator+=: Cannot add different types", this->dataType(), other.dataType()); if (this->lengthOf() != 1 && other.lengthOf() == 1) { @@ -2490,7 +2491,7 @@ void NDArray::operator-=(const NDArray& other) { if (isS()) throw std::runtime_error("NDArray::operator-=: you can't use this method on String array!"); - if (!Environment::getInstance()->isExperimentalBuild() && this->dataType() != other.dataType() && (this->dataType() != DataType::BOOL || other.dataType() != BOOL)) + if (!Environment::getInstance().isExperimentalBuild() && this->dataType() != other.dataType() && (this->dataType() != DataType::BOOL || other.dataType() != BOOL)) throw sd::datatype_exception::build("NDArray operator-=: Cannot subtract different types", this->dataType(), other.dataType()); if (lengthOf() != 1 && other.lengthOf() == 1) { @@ -2523,7 +2524,7 @@ void NDArray::operator-=(const NDArray& other) { void NDArray::operator*=(const NDArray& other) { if (isS()) throw std::runtime_error("NDArray::operator*=: you can't use this method on String array!"); - if (!Environment::getInstance()->isExperimentalBuild() && this->dataType() != other.dataType() && (this->dataType() != DataType::BOOL || other.dataType() != BOOL)) + if (!Environment::getInstance().isExperimentalBuild() && this->dataType() != other.dataType() && (this->dataType() != DataType::BOOL || other.dataType() != BOOL)) throw sd::datatype_exception::build("NDArray operator*=: Cannot multiply different types", this->dataType(), other.dataType()); if (lengthOf() != 1 && other.lengthOf() == 1) { @@ -2559,7 +2560,7 @@ void NDArray::operator/=(const NDArray& other) { if (other.isB()) throw std::runtime_error("NDArray::operator/=: you can't divide by bool array!"); - if (!Environment::getInstance()->isExperimentalBuild() && this->dataType() != other.dataType()) { + if (!Environment::getInstance().isExperimentalBuild() && this->dataType() != other.dataType()) { throw sd::datatype_exception::build("NDArray operator/=: Cannot divide different types", this->dataType(), other.dataType()); } @@ -2832,14 +2833,14 @@ void NDArray::applyTrueBroadcast(sd::BroadcastOpsTuple op, const NDArray& other, Nd4jLong const* yShapeInfoD = other.specialShapeInfo(); if(!isSameShape(target)) { - auto xPack = ConstantShapeHelper::getInstance()->createShapeInfoWithUnitiesForBroadcast(target.shapeInfo(), shapeInfo(), getContext()->getWorkspace()); - xShapeInfoH = reinterpret_cast(xPack.primary()); - xShapeInfoD = reinterpret_cast(xPack.special()); + auto xPack = ConstantShapeHelper::getInstance().createShapeInfoWithUnitiesForBroadcast(target.shapeInfo(), shapeInfo(), getContext()->getWorkspace()); + xShapeInfoH = xPack.primary(); + xShapeInfoD = xPack.special(); } if(!other.isSameShape(target)) { - auto yPack = ConstantShapeHelper::getInstance()->createShapeInfoWithUnitiesForBroadcast(target.shapeInfo(), other.shapeInfo(), other.getContext()->getWorkspace()); - yShapeInfoH = reinterpret_cast(yPack.primary()); - yShapeInfoD = reinterpret_cast(yPack.special()); + auto yPack = ConstantShapeHelper::getInstance().createShapeInfoWithUnitiesForBroadcast(target.shapeInfo(), other.shapeInfo(), other.getContext()->getWorkspace()); + yShapeInfoH = yPack.primary(); + yShapeInfoD = yPack.special(); } NDArray::prepareSpecialUse({&target}, {this, &other}); @@ -2883,14 +2884,14 @@ void NDArray::applyTrueBroadcast(sd::BroadcastBoolOpsTuple op, const NDArray& ot Nd4jLong const* yShapeInfoD = other.specialShapeInfo(); if(!isSameShape(target)) { - auto xPack = ConstantShapeHelper::getInstance()->createShapeInfoWithUnitiesForBroadcast(target.shapeInfo(), shapeInfo(), getContext()->getWorkspace()); - xShapeInfoH = reinterpret_cast(xPack.primary()); - xShapeInfoD = reinterpret_cast(xPack.special()); + auto xPack = ConstantShapeHelper::getInstance().createShapeInfoWithUnitiesForBroadcast(target.shapeInfo(), shapeInfo(), getContext()->getWorkspace()); + xShapeInfoH = xPack.primary(); + xShapeInfoD = xPack.special(); } if(!other.isSameShape(target)) { - auto yPack = ConstantShapeHelper::getInstance()->createShapeInfoWithUnitiesForBroadcast(target.shapeInfo(), other.shapeInfo(), other.getContext()->getWorkspace()); - yShapeInfoH = reinterpret_cast(yPack.primary()); - yShapeInfoD = reinterpret_cast(yPack.special()); + auto yPack = ConstantShapeHelper::getInstance().createShapeInfoWithUnitiesForBroadcast(target.shapeInfo(), other.shapeInfo(), other.getContext()->getWorkspace()); + yShapeInfoH = yPack.primary(); + yShapeInfoD = yPack.special(); } NDArray::prepareSpecialUse({&target}, {this, &other}); @@ -2934,12 +2935,12 @@ void NDArray::applyTrueBroadcast(sd::BroadcastIntOpsTuple op, const NDArray& oth Nd4jLong const* yShapeInfoD = other.specialShapeInfo(); if(!isSameShape(target)) { - auto xPack = ConstantShapeHelper::getInstance()->createShapeInfoWithUnitiesForBroadcast(target.shapeInfo(), shapeInfo(), getContext()->getWorkspace()); + auto xPack = ConstantShapeHelper::getInstance().createShapeInfoWithUnitiesForBroadcast(target.shapeInfo(), shapeInfo(), getContext()->getWorkspace()); xShapeInfoH = reinterpret_cast(xPack.primary()); xShapeInfoD = reinterpret_cast(xPack.special()); } if(!other.isSameShape(target)) { - auto yPack = ConstantShapeHelper::getInstance()->createShapeInfoWithUnitiesForBroadcast(target.shapeInfo(), other.shapeInfo(), other.getContext()->getWorkspace()); + auto yPack = ConstantShapeHelper::getInstance().createShapeInfoWithUnitiesForBroadcast(target.shapeInfo(), other.shapeInfo(), other.getContext()->getWorkspace()); yShapeInfoH = reinterpret_cast(yPack.primary()); yShapeInfoD = reinterpret_cast(yPack.special()); } @@ -3067,7 +3068,7 @@ void NDArray::applyBroadcast(sd::broadcast::Ops op, const std::vector& dime // if (other.lengthOf() == lengthOf() && this->rankOf() == other.rankOf()) { // NDArray::prepareSpecialUse({&target}, {this, &other}); - // NativeOpExecutioner::execPairwiseTransform(getContext(), fromBroadcastToPairwise(op), buffer(), shapeInfo(), specialBuffer(), specialShapeInfo(), other.buffer(), other.shapeInfo(), other.specialBuffer(), other.specialShapeInfo(), target.buffer(), target.shapeInfo(), target.specialBuffer(), target.specialShapeInfo(), nullptr); + // NativeOpExecutioner::execPairwiseTransform(getContext(), fromBroadcastToPairwise(op), buffer(), shapeInfo(), specialBuffer(), specialShapeInfo(), other.buffer(), other.shapeInfo(), other.specialBuffer(), other.specialShapeInfo(), target.buffer(), target.shapeInfo(), target.specialBuffer(), target.special(), nullptr); // NDArray::registerSpecialUse({&target}, {this, &other}); // return; // } @@ -3088,12 +3089,12 @@ void NDArray::applyBroadcast(sd::broadcast::Ops op, const std::vector& dime Nd4jLong const* yShapeInfoD = other.specialShapeInfo(); if(!isSameShape(target)) { - auto xPack = ConstantShapeHelper::getInstance()->createShapeInfoWithUnitiesForBroadcast(target.shapeInfo(), shapeInfo(), getContext()->getWorkspace(), copy); + auto xPack = ConstantShapeHelper::getInstance().createShapeInfoWithUnitiesForBroadcast(target.shapeInfo(), shapeInfo(), getContext()->getWorkspace(), copy); xShapeInfoH = reinterpret_cast(xPack.primary()); xShapeInfoD = reinterpret_cast(xPack.special()); } if(!other.isSameShape(target)) { - auto yPack = ConstantShapeHelper::getInstance()->createShapeInfoWithUnitiesForBroadcast(target.shapeInfo(), other.shapeInfo(), other.getContext()->getWorkspace(), copy); + auto yPack = ConstantShapeHelper::getInstance().createShapeInfoWithUnitiesForBroadcast(target.shapeInfo(), other.shapeInfo(), other.getContext()->getWorkspace(), copy); yShapeInfoH = reinterpret_cast(yPack.primary()); yShapeInfoD = reinterpret_cast(yPack.special()); } @@ -3119,7 +3120,7 @@ void NDArray::applyBroadcast(sd::broadcast::BoolOps op, const std::vector& // if (other.lengthOf() == lengthOf() && this->rankOf() == other.rankOf()) { // NDArray::prepareSpecialUse({&target}, {this, &other}); - // NativeOpExecutioner::execPairwiseBoolTransform(getContext(), fromBroadcastToPairwiseBool(op), buffer(), shapeInfo(), specialBuffer(), specialShapeInfo(), other.buffer(), other.shapeInfo(), other.specialBuffer(), other.specialShapeInfo(), target.buffer(), target.shapeInfo(), target.specialBuffer(), target.specialShapeInfo(), nullptr); + // NativeOpExecutioner::execPairwiseBoolTransform(getContext(), fromBroadcastToPairwiseBool(op), buffer(), shapeInfo(), specialBuffer(), specialShapeInfo(), other.buffer(), other.shapeInfo(), other.specialBuffer(), other.specialShapeInfo(), target.buffer(), target.shapeInfo(), target.specialBuffer(), target.special(), nullptr); // NDArray::registerSpecialUse({&target}, {this, &other}); // return; // } @@ -3142,12 +3143,12 @@ void NDArray::applyBroadcast(sd::broadcast::BoolOps op, const std::vector& Nd4jLong const* yShapeInfoD = other.specialShapeInfo(); if(!isSameShape(target)) { - auto xPack = ConstantShapeHelper::getInstance()->createShapeInfoWithUnitiesForBroadcast(target.shapeInfo(), shapeInfo(), getContext()->getWorkspace(), copy); + auto xPack = ConstantShapeHelper::getInstance().createShapeInfoWithUnitiesForBroadcast(target.shapeInfo(), shapeInfo(), getContext()->getWorkspace(), copy); xShapeInfoH = reinterpret_cast(xPack.primary()); xShapeInfoD = reinterpret_cast(xPack.special()); } if(!other.isSameShape(target)) { - auto yPack = ConstantShapeHelper::getInstance()->createShapeInfoWithUnitiesForBroadcast(target.shapeInfo(), other.shapeInfo(), other.getContext()->getWorkspace(), copy); + auto yPack = ConstantShapeHelper::getInstance().createShapeInfoWithUnitiesForBroadcast(target.shapeInfo(), other.shapeInfo(), other.getContext()->getWorkspace(), copy); yShapeInfoH = reinterpret_cast(yPack.primary()); yShapeInfoD = reinterpret_cast(yPack.special()); } @@ -3174,7 +3175,7 @@ void NDArray::applyBroadcast(sd::broadcast::IntOps op, const std::vector& d // if (other.lengthOf() == lengthOf() && this->rankOf() == other.rankOf()) { // NDArray::prepareSpecialUse({&target}, {this, &other}); - // NativeOpExecutioner::execPairwiseIntTransform(getContext(), fromBroadcastToPairwiseInt(op), buffer(), shapeInfo(), specialBuffer(), specialShapeInfo(), other.buffer(), other.shapeInfo(), other.specialBuffer(), other.specialShapeInfo(), target.buffer(), target.shapeInfo(), target.specialBuffer(), target.specialShapeInfo(), nullptr); + // NativeOpExecutioner::execPairwiseIntTransform(getContext(), fromBroadcastToPairwiseInt(op), buffer(), shapeInfo(), specialBuffer(), specialShapeInfo(), other.buffer(), other.shapeInfo(), other.specialBuffer(), other.specialShapeInfo(), target.buffer(), target.shapeInfo(), target.specialBuffer(), target.special(), nullptr); // NDArray::registerSpecialUse({&target}, {this, &other}); // return; // } @@ -3197,12 +3198,12 @@ void NDArray::applyBroadcast(sd::broadcast::IntOps op, const std::vector& d Nd4jLong const* yShapeInfoD = other.specialShapeInfo(); if(!isSameShape(target)) { - auto xPack = ConstantShapeHelper::getInstance()->createShapeInfoWithUnitiesForBroadcast(target.shapeInfo(), shapeInfo(), getContext()->getWorkspace(), copy); + auto xPack = ConstantShapeHelper::getInstance().createShapeInfoWithUnitiesForBroadcast(target.shapeInfo(), shapeInfo(), getContext()->getWorkspace(), copy); xShapeInfoH = reinterpret_cast(xPack.primary()); xShapeInfoD = reinterpret_cast(xPack.special()); } if(!other.isSameShape(target)) { - auto yPack = ConstantShapeHelper::getInstance()->createShapeInfoWithUnitiesForBroadcast(target.shapeInfo(), other.shapeInfo(), other.getContext()->getWorkspace(), copy); + auto yPack = ConstantShapeHelper::getInstance().createShapeInfoWithUnitiesForBroadcast(target.shapeInfo(), other.shapeInfo(), other.getContext()->getWorkspace(), copy); yShapeInfoH = reinterpret_cast(yPack.primary()); yShapeInfoD = reinterpret_cast(yPack.special()); } @@ -3220,8 +3221,8 @@ void NDArray::applyBroadcast(sd::broadcast::Ops op, const std::initializer_list< //////////////////////////////////////////////////////////////////////// void* NDArray::operator new(size_t i) { - if (sd::memory::MemoryRegistrator::getInstance()->hasWorkspaceAttached()) { - sd::memory::Workspace* ws = sd::memory::MemoryRegistrator::getInstance()->getWorkspace(); + if (sd::memory::MemoryRegistrator::getInstance().hasWorkspaceAttached()) { + sd::memory::Workspace* ws = sd::memory::MemoryRegistrator::getInstance().getWorkspace(); return ws->allocateBytes((Nd4jLong) i); } else { @@ -3233,7 +3234,7 @@ void* NDArray::operator new(size_t i) { //////////////////////////////////////////////////////////////////////// void NDArray::operator delete(void* p) { - if (!sd::memory::MemoryRegistrator::getInstance()->hasWorkspaceAttached()) + if (!sd::memory::MemoryRegistrator::getInstance().hasWorkspaceAttached()) free(p); } @@ -3439,8 +3440,8 @@ void NDArray::varianceAlongDimension(sd::variance::Ops op, NDArray& target, cons NativeOpExecutioner::execSummaryStatsScalar(getContext(), op, buffer(), shapeInfo(), specialBuffer(), specialShapeInfo(), nullptr, target.buffer(), target.shapeInfo(), target.specialBuffer(), target.specialShapeInfo(), biasCorrected); else { std::vector copy(dimensions); - auto pDims = sd::Environment::getInstance()->isCPU() ? copy.data() : nullptr; - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(this->shapeInfo(), dimensions); + auto pDims = sd::Environment::getInstance().isCPU() ? copy.data() : nullptr; + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(this->shapeInfo(), dimensions); NativeOpExecutioner::execSummaryStats(getContext(), op, buffer(), shapeInfo(), specialBuffer(), specialShapeInfo(), nullptr, target.buffer(), target.shapeInfo(), target.specialBuffer(), target.specialShapeInfo(), pDims, dimensions.size(), packX.platformShapeInfo(), packX.platformOffsets(), biasCorrected); synchronize("NDArray::varianceAlongDimension"); } @@ -4109,8 +4110,8 @@ void NDArray::applyIndexReduce(sd::indexreduce::Ops op, NDArray& target, const s else { std::vector copy = dimensions; shape::checkDimensions(rankOf(), copy); - auto pDims = sd::Environment::getInstance()->isCPU() ? copy.data() : nullptr; - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(shapeInfo(), copy); + auto pDims = sd::Environment::getInstance().isCPU() ? copy.data() : nullptr; + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(shapeInfo(), copy); NativeOpExecutioner::execIndexReduce(getContext(), op, buffer(), shapeInfo(), specialBuffer(), specialShapeInfo(), params, target.buffer(), target.shapeInfo(), target.specialBuffer(), target.specialShapeInfo(), pDims, copy.size(), packX.platformShapeInfo(), packX.platformOffsets()); synchronize("NDArray::applyIndexReduce"); } @@ -4183,10 +4184,10 @@ NDArray NDArray::applyReduce3(sd::reduce3::Ops op, const NDArray& other, const s } else { - auto pDims = sd::Environment::getInstance()->isCPU() ? copy.data() : nullptr; + auto pDims = sd::Environment::getInstance().isCPU() ? copy.data() : nullptr; - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(shapeInfo(), copy); - auto packY = sd::ConstantTadHelper::getInstance()->tadForDimensions(other.shapeInfo(), copy); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(shapeInfo(), copy); + auto packY = sd::ConstantTadHelper::getInstance().tadForDimensions(other.shapeInfo(), copy); if(!shape::equalsSoft(packX.primaryShapeInfo(), packY.primaryShapeInfo()) || (packX.numberOfTads() != packY.numberOfTads() && packX.numberOfTads() != 1 && packY.numberOfTads() != 1)) throw std::runtime_error("NDArray::applyReduce3 cuda method: arrays tads are inconsistent !"); @@ -4212,15 +4213,15 @@ NDArray NDArray::applyAllReduce3(sd::reduce3::Ops op, const NDArray& other, cons shape::checkDimensions(rankOf(), copy); shape::checkDimensions(other.rankOf(), copy); - auto packX = ConstantTadHelper::getInstance()->tadForDimensions(shapeInfo(), copy); - auto packY = ConstantTadHelper::getInstance()->tadForDimensions(other.shapeInfo(), copy); + auto packX = ConstantTadHelper::getInstance().tadForDimensions(shapeInfo(), copy); + auto packY = ConstantTadHelper::getInstance().tadForDimensions(other.shapeInfo(), copy); // check tads shapes if(!shape::equalsSoft(packX.primaryShapeInfo(), packY.primaryShapeInfo())) throw std::runtime_error("NDArray::applyAllReduce3 method: the shapes of array tads are different !"); // set newShape for output array - auto newShape = ConstantShapeHelper::getInstance()->createShapeInfo(DataTypeUtils::pickFloatingType(dataType()), 'c', {packX.numberOfTads(), packY.numberOfTads()}); + auto newShape = ConstantShapeHelper::getInstance().createShapeInfo(DataTypeUtils::pickFloatingType(dataType()), 'c', {packX.numberOfTads(), packY.numberOfTads()}); // create output array NDArray result(newShape, true, getContext()); @@ -4228,7 +4229,7 @@ NDArray NDArray::applyAllReduce3(sd::reduce3::Ops op, const NDArray& other, cons // create dynamic array of extra parameters if array extraParams is empty (==nullptr) void* params = extraParams != nullptr ? const_cast(extraParams)->argumentsAsT(dataType()) : nullptr; - auto pDims = sd::Environment::getInstance()->isCPU() ? copy.data() : nullptr; + auto pDims = sd::Environment::getInstance().isCPU() ? copy.data() : nullptr; NDArray::prepareSpecialUse({&result}, {this, &other}); NativeOpExecutioner::execReduce3All(getContext(), op, buffer(), shapeInfo(), specialBuffer(), specialShapeInfo(), params, other.buffer(), other.shapeInfo(), other.specialBuffer(), other.specialShapeInfo(), result.buffer(), result.shapeInfo(), result.specialBuffer(), result.specialShapeInfo(), pDims, copy.size(), packX.platformShapeInfo(), packX.platformOffsets(), packY.platformShapeInfo(), packY.platformOffsets()); @@ -4260,7 +4261,7 @@ void NDArray::reduceAlongDimension(sd::reduce::FloatOps op, NDArray& target, con NativeOpExecutioner::execReduceFloatScalar(getContext(), op, buffer(), shapeInfo(), specialBuffer(), specialShapeInfo(),nullptr, target.buffer(), target.shapeInfo(), target.specialBuffer(), target.specialShapeInfo()); } else { - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(shapeInfo(), copy); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(shapeInfo(), copy); NativeOpExecutioner::execReduceFloat(getContext(), op, buffer(), shapeInfo(), specialBuffer(), specialShapeInfo(), nullptr, target.buffer(), target.shapeInfo(), target.specialBuffer(), target.specialShapeInfo(), copy.data(), copy.size(), packX.platformShapeInfo(), packX.platformOffsets()); } synchronize("NDArray::reduceAlongDimension FloatOps"); @@ -4291,8 +4292,8 @@ void NDArray::reduceAlongDimension(sd::reduce::SameOps op, NDArray& target, cons NativeOpExecutioner::execReduceSameScalar(getContext(), op, buffer(), shapeInfo(), specialBuffer(), specialShapeInfo(), nullptr, target.buffer(), target.shapeInfo(), target.specialBuffer(), target.specialShapeInfo()); } else { //if (!isEmpty()) { - auto pDims = sd::Environment::getInstance()->isCPU() ? copy.data() : nullptr; - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(this->shapeInfo(), copy); + auto pDims = sd::Environment::getInstance().isCPU() ? copy.data() : nullptr; + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(this->shapeInfo(), copy); NativeOpExecutioner::execReduceSame(getContext(), op, buffer(), shapeInfo(), specialBuffer(), specialShapeInfo(), nullptr, target.buffer(), target.shapeInfo(), target.specialBuffer(), target.specialShapeInfo(), pDims, copy.size(), packX.platformShapeInfo(), packX.platformOffsets()); } synchronize("NDArray::reduceAlongDimension SameOps"); @@ -4323,8 +4324,8 @@ void NDArray::reduceAlongDimension(sd::reduce::LongOps op, NDArray& target, cons NativeOpExecutioner::execReduceLongScalar(getContext(), op, buffer(), shapeInfo(), specialBuffer(), specialShapeInfo(), nullptr, target.buffer(), target.shapeInfo(), target.specialBuffer(), target.specialShapeInfo()); } else { - auto pDims = sd::Environment::getInstance()->isCPU() ? copy.data() : nullptr; - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(this->shapeInfo(), copy); + auto pDims = sd::Environment::getInstance().isCPU() ? copy.data() : nullptr; + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(this->shapeInfo(), copy); NativeOpExecutioner::execReduceLong(getContext(), op, buffer(), shapeInfo(), specialBuffer(), specialShapeInfo(), nullptr, target.buffer(), target.shapeInfo(), target.specialBuffer(), target.specialShapeInfo(), pDims, copy.size(), packX.platformShapeInfo(), packX.platformOffsets()); } synchronize("NDArray::reduceAlongDimension LongOps"); @@ -4355,8 +4356,8 @@ void NDArray::reduceAlongDimension(sd::reduce::BoolOps op, NDArray& target, cons NativeOpExecutioner::execReduceBoolScalar(getContext(), op, buffer(), shapeInfo(), specialBuffer(), specialShapeInfo(), nullptr, target.buffer(), target.shapeInfo(), target.specialBuffer(), target.specialShapeInfo()); } else { - auto pDims = sd::Environment::getInstance()->isCPU() ? copy.data() : nullptr; - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(this->shapeInfo(), copy); + auto pDims = sd::Environment::getInstance().isCPU() ? copy.data() : nullptr; + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(this->shapeInfo(), copy); NativeOpExecutioner::execReduceBool(getContext(), op, buffer(), shapeInfo(), specialBuffer(), specialShapeInfo(), nullptr, target.buffer(), target.shapeInfo(), target.specialBuffer(), target.specialShapeInfo(), pDims, copy.size(), packX.platformShapeInfo(), packX.platformOffsets()); } synchronize("NDArray::reduceAlongDimension LongOps"); @@ -4524,7 +4525,7 @@ void NDArray::addRowVector(const NDArray& row, NDArray& target) const { int dimension = 1; - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(this->shapeInfo(), dimension); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(this->shapeInfo(), dimension); NDArray::prepareSpecialUse({&target}, {this, &row}); NativeOpExecutioner::execBroadcast(getContext(), sd::broadcast::Ops::Add, buffer(), shapeInfo(), specialBuffer(), specialShapeInfo(), row.buffer(), row.shapeInfo(), row.specialBuffer(), row.specialShapeInfo(), target.buffer(), target.shapeInfo(), target.specialBuffer(), target.specialShapeInfo(), nullptr, 1, packX.platformShapeInfo(), packX.platformOffsets(), nullptr, nullptr); @@ -4543,7 +4544,7 @@ void NDArray::subRowVector(const NDArray& row, NDArray& target) const { int dimension = 1; - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(this->shapeInfo(), dimension); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(this->shapeInfo(), dimension); NDArray::prepareSpecialUse({&target}, {this, &row}); NativeOpExecutioner::execBroadcast(getContext(), sd::broadcast::Ops::Subtract, buffer(), shapeInfo(), specialBuffer(), specialShapeInfo(), row.buffer(), row.shapeInfo(), row.specialBuffer(), row.specialShapeInfo(), target.buffer(), target.shapeInfo(), target.specialBuffer(), target.specialShapeInfo(), &dimension, 1, packX.platformShapeInfo(), packX.platformOffsets(), nullptr, nullptr); @@ -4563,7 +4564,7 @@ void NDArray::mulRowVector(const NDArray &row, NDArray &target) const { int dimension = 1; - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(this->shapeInfo(), dimension); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(this->shapeInfo(), dimension); NDArray::prepareSpecialUse({&target}, {this, &row}); NativeOpExecutioner::execBroadcast(getContext(), sd::broadcast::Ops::Multiply, buffer(), shapeInfo(), specialBuffer(), specialShapeInfo(), row.buffer(), row.shapeInfo(), row.specialBuffer(), row.specialShapeInfo(), target.buffer(), target.shapeInfo(), target.specialBuffer(), target.specialShapeInfo(), nullptr, 1, packX.platformShapeInfo(), packX.platformOffsets(), nullptr, nullptr); @@ -4584,7 +4585,7 @@ void NDArray::divRowVector(const NDArray &row, NDArray &target) const { int dimension = 1; - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(this->shapeInfo(), dimension); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(this->shapeInfo(), dimension); NDArray::prepareSpecialUse({&target}, {this, &row}); NativeOpExecutioner::execBroadcast(getContext(), sd::broadcast::Divide, buffer(), shapeInfo(), specialBuffer(), specialShapeInfo(), row.buffer(), row.shapeInfo(), row.specialBuffer(), row.specialShapeInfo(), target.buffer(), target.shapeInfo(), target.specialBuffer(), target.specialShapeInfo(), nullptr, 1, packX.platformShapeInfo(), packX.platformOffsets(), nullptr, nullptr); @@ -4602,7 +4603,7 @@ void NDArray::addiRowVector(const NDArray& row) { int dimension = 1; - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(this->shapeInfo(), dimension); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(this->shapeInfo(), dimension); NDArray::prepareSpecialUse({this}, {&row}); NativeOpExecutioner::execBroadcast(getContext(), sd::broadcast::Ops::Add, buffer(), shapeInfo(), specialBuffer(), specialShapeInfo(), row.buffer(), row.shapeInfo(), row.specialBuffer(), row.specialShapeInfo(), this->buffer(), this->shapeInfo(), this->specialBuffer(), this->specialShapeInfo(), nullptr, 1, packX.platformShapeInfo(), packX.platformOffsets(), nullptr, nullptr); @@ -4620,7 +4621,7 @@ void NDArray::addColumnVector(const NDArray &column, NDArray &target) const { int dimension = 0; - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(this->shapeInfo(), dimension); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(this->shapeInfo(), dimension); NDArray::prepareSpecialUse({&target}, {this, &column}); NativeOpExecutioner::execBroadcast(getContext(), sd::broadcast::Ops::Add, buffer(), shapeInfo(), specialBuffer(), specialShapeInfo(), column.buffer(), column.shapeInfo(), column.specialBuffer(), column.specialShapeInfo(), target.buffer(), target.shapeInfo(), target.specialBuffer(), target.specialShapeInfo(), nullptr, 1, packX.platformShapeInfo(), packX.platformOffsets(), nullptr, nullptr); @@ -4637,7 +4638,7 @@ void NDArray::addiColumnVector(const NDArray &column) { int dimension = 0; - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(this->shapeInfo(), dimension); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(this->shapeInfo(), dimension); NDArray::prepareSpecialUse({this}, {&column}); NativeOpExecutioner::execBroadcast(getContext(), sd::broadcast::Ops::Add, buffer(), shapeInfo(), specialBuffer(), specialShapeInfo(), column.buffer(), column.shapeInfo(), column.specialBuffer(), column.specialShapeInfo(), this->buffer(), this->shapeInfo(), this->specialBuffer(), this->specialShapeInfo(), nullptr, 1, packX.platformShapeInfo(), packX.platformOffsets(), nullptr, nullptr); @@ -4654,7 +4655,7 @@ void NDArray::muliColumnVector(const NDArray& column) { int dimension = 0; - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(this->shapeInfo(), dimension); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(this->shapeInfo(), dimension); NDArray::prepareSpecialUse({this}, {&column}); NativeOpExecutioner::execBroadcast(getContext(), sd::broadcast::Ops::Multiply, buffer(), shapeInfo(), specialBuffer(), specialShapeInfo(), column.buffer(), column.shapeInfo(), column.specialBuffer(), column.specialShapeInfo(), this->buffer(), this->shapeInfo(), this->specialBuffer(), this->specialShapeInfo(), nullptr, 1, packX.platformShapeInfo(), packX.platformOffsets(), nullptr, nullptr); @@ -4695,7 +4696,7 @@ ResultSet NDArray::multipleTensorsAlongDimension(const std::vector &indices if (indices.size() == 0) return result; - auto pack = ConstantTadHelper::getInstance()->tadForDimensions(shapeInfo(), const_cast(dimensions.data()), dimensions.size()); + auto pack = ConstantTadHelper::getInstance().tadForDimensions(shapeInfo(), const_cast(dimensions.data()), dimensions.size()); auto tadLength = shape::length(pack.primaryShapeInfo()); auto numTads = lengthOf() / tadLength; @@ -4816,7 +4817,7 @@ ResultSet NDArray::allTensorsAlongDimension(const std::vector &dimensions) throw std::runtime_error("NDArray::allTensorsAlongDimension static function: all input dimensions must be smaller than rank of input array !"); - auto pack = ConstantTadHelper::getInstance()->tadForDimensions(_shapeInfo, const_cast(dimensions.data()), dimensions.size()); + auto pack = ConstantTadHelper::getInstance().tadForDimensions(_shapeInfo, const_cast(dimensions.data()), dimensions.size()); auto numTads = pack.numberOfTads(); for (Nd4jLong idx = 0; idx < numTads; idx++ ) { @@ -4929,11 +4930,11 @@ void NDArray::setShapeInfo(const Nd4jLong *shapeInfo) { if (shapeInfo != nullptr) { ShapeDescriptor descriptor(shapeInfo); - auto shapeBuffer = ConstantShapeHelper::getInstance()->bufferForShapeInfo(descriptor); + auto shapeBuffer = ConstantShapeHelper::getInstance().bufferForShapeInfo(descriptor); - _shapeInfo = reinterpret_cast(shapeBuffer.primary()); + _shapeInfo = shapeBuffer.primary(); #ifdef __CUDABLAS__ - _shapeInfoD = reinterpret_cast(shapeBuffer.special()); + _shapeInfoD = shapeBuffer.special(); #endif if(ArrayOptions::arrayType(_shapeInfo) == ArrayType::EMPTY) @@ -4956,11 +4957,11 @@ void NDArray::setShapeInfo(const Nd4jLong *shapeInfo, const sd::DataType dtype) Nd4jLong* shapeInfoTemp = ShapeBuilders::copyShapeInfoAndType(shapeInfo, dtype, true, getContext()->getWorkspace()); ShapeDescriptor descriptor(shapeInfoTemp); - auto shapeBuffer = ConstantShapeHelper::getInstance()->bufferForShapeInfo(descriptor); + auto shapeBuffer = ConstantShapeHelper::getInstance().bufferForShapeInfo(descriptor); - _shapeInfo = reinterpret_cast(shapeBuffer.primary()); + _shapeInfo = shapeBuffer.primary(); #ifdef __CUDABLAS__ - _shapeInfoD = reinterpret_cast(shapeBuffer.special()); + _shapeInfoD = shapeBuffer.special(); #endif if(ArrayOptions::arrayType(_shapeInfo) == ArrayType::EMPTY) @@ -4979,11 +4980,11 @@ void NDArray::setShapeInfo(const Nd4jLong *shapeInfo, const sd::DataType dtype) ////////////////////////////////////////////////////////////////////////// void NDArray::setShapeInfo(const ShapeDescriptor& descriptor) { - auto shapeBuffer = ConstantShapeHelper::getInstance()->bufferForShapeInfo(const_cast(descriptor)); + auto shapeBuffer = ConstantShapeHelper::getInstance().bufferForShapeInfo(const_cast(descriptor)); - _shapeInfo = reinterpret_cast(shapeBuffer.primary()); + _shapeInfo = shapeBuffer.primary(); #ifdef __CUDABLAS__ - _shapeInfoD = reinterpret_cast(shapeBuffer.special()); + _shapeInfoD = shapeBuffer.special(); #endif if(ArrayOptions::arrayType(_shapeInfo) == ArrayType::EMPTY) @@ -4995,11 +4996,11 @@ void NDArray::setShapeInfo(const ShapeDescriptor& descriptor) { } ////////////////////////////////////////////////////////////////////////// -void NDArray::setShapeInfo(const ConstantDataBuffer& shapeBuffer) { +void NDArray::setShapeInfo(const ConstantShapeBuffer& shapeBuffer) { - _shapeInfo = reinterpret_cast(const_cast(shapeBuffer).primary()); + _shapeInfo = shapeBuffer.primary(); #ifdef __CUDABLAS__ - _shapeInfoD = reinterpret_cast(const_cast(shapeBuffer).special()); + _shapeInfoD = shapeBuffer.special(); #endif if(ArrayOptions::arrayType(_shapeInfo) == ArrayType::EMPTY) @@ -5350,7 +5351,7 @@ NDArray operator+(T1&& arr1, T2&& arr2) { if (arr1.isS() || arr2.isS()) throw std::runtime_error("operator+(T&& arr1, T&& arr2): you can't use this method on String arrays!"); - if (!Environment::getInstance()->isExperimentalBuild() && arr1.dataType() != arr2.dataType() && (arr1.dataType() != DataType::BOOL || arr2.dataType() != BOOL)) + if (!Environment::getInstance().isExperimentalBuild() && arr1.dataType() != arr2.dataType() && (arr1.dataType() != DataType::BOOL || arr2.dataType() != BOOL)) throw sd::datatype_exception::build("operator+(T&& arr1, T&& arr2): Cannot multiply different types", arr1.dataType(), arr2.dataType()); PointersManager pointersManager(arr1.getContext(), "operator+(T&& arr1, T&& arr2)"); @@ -5400,7 +5401,7 @@ NDArray operator-(T1&& arr1, T2&& arr2) { if (arr1.isS() || arr2.isS()) throw std::runtime_error("operator-(T&& arr1, T&& arr2): you can't use this method on String arrays!"); - if (!Environment::getInstance()->isExperimentalBuild() && arr1.dataType() != arr2.dataType() && (arr1.dataType() != DataType::BOOL || arr2.dataType() != BOOL)) + if (!Environment::getInstance().isExperimentalBuild() && arr1.dataType() != arr2.dataType() && (arr1.dataType() != DataType::BOOL || arr2.dataType() != BOOL)) throw sd::datatype_exception::build("operator-(T&& arr1, T&& arr2): Cannot multiply different types", arr1.dataType(), arr2.dataType()); PointersManager pointersManager(arr1.getContext(), "operator-(T&& arr1, T&& arr2)"); @@ -5450,7 +5451,7 @@ NDArray operator*(T1&& arr1, T2&& arr2) { if (arr1.isS() || arr2.isS()) throw std::runtime_error("operator*(T&& arr1, T&& arr2): you can't use this method on String arrays!"); - if (!Environment::getInstance()->isExperimentalBuild() && arr1.dataType() != arr2.dataType() && (arr1.dataType() != DataType::BOOL || arr2.dataType() != BOOL)) + if (!Environment::getInstance().isExperimentalBuild() && arr1.dataType() != arr2.dataType() && (arr1.dataType() != DataType::BOOL || arr2.dataType() != BOOL)) throw sd::datatype_exception::build("operator*(T&& arr1, T&& arr2): Cannot multiply different types", arr1.dataType(), arr2.dataType()); PointersManager pointersManager(arr1.getContext(), "operator*(T&& arr1, T&& arr2)"); @@ -5500,7 +5501,7 @@ NDArray operator/(T1&& arr1, T2&& arr2) { if (arr1.isS() || arr2.isS()) throw std::runtime_error("operator/(T&& arr1, T&& arr2): you can't use this method on String arrays!"); - if (!Environment::getInstance()->isExperimentalBuild() && arr1.dataType() != arr2.dataType() && (arr1.dataType() != DataType::BOOL || arr2.dataType() != BOOL)) + if (!Environment::getInstance().isExperimentalBuild() && arr1.dataType() != arr2.dataType() && (arr1.dataType() != DataType::BOOL || arr2.dataType() != BOOL)) throw sd::datatype_exception::build("operator/(T&& arr1, T&& arr2): Cannot multiply different types", arr1.dataType(), arr2.dataType()); PointersManager pointersManager(arr1.getContext(), "operator/(T&& arr1, T&& arr2)"); diff --git a/libnd4j/include/array/PointerDeallocator.h b/libnd4j/include/array/PointerDeallocator.h new file mode 100644 index 000000000..5bf820421 --- /dev/null +++ b/libnd4j/include/array/PointerDeallocator.h @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2019-2020 Konduit K.K. + * + * 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 SD_POINTERDEALLOCATOR_H_ +#define SD_POINTERDEALLOCATOR_H_ + +#include +#include + +namespace sd { + +class ND4J_EXPORT PointerDeallocator { + public: + PointerDeallocator() = default; + ~PointerDeallocator() = default; + + virtual void release(void* ptr); +}; + +} + +#endif //SD_POINTERDEALLOCATOR_H_ diff --git a/libnd4j/include/array/PointerWrapper.h b/libnd4j/include/array/PointerWrapper.h new file mode 100644 index 000000000..9e15aaaa3 --- /dev/null +++ b/libnd4j/include/array/PointerWrapper.h @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2019-2020 Konduit K.K. + * + * 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 SD_ARRAY_POINTER_H_ +#define SD_ARRAY_POINTER_H_ + +#include +#include +#include +#include + +namespace sd { +class ND4J_EXPORT PointerWrapper { + private: + void* _pointer = nullptr; + std::shared_ptr _deallocator; + + public: + PointerWrapper(void* ptr, const std::shared_ptr &deallocator = {}); + PointerWrapper() = default; + ~PointerWrapper(); + + void* pointer() const; + + template + T* pointerAsT() const { + return reinterpret_cast(pointer()); + } +}; +} // namespace sd + +#endif //SD_ARRAY_POINTER_H_ diff --git a/libnd4j/include/array/PrimaryPointerDeallocator.h b/libnd4j/include/array/PrimaryPointerDeallocator.h new file mode 100644 index 000000000..b4fe34764 --- /dev/null +++ b/libnd4j/include/array/PrimaryPointerDeallocator.h @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2019-2020 Konduit K.K. + * + * 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 SD_PRIMARYPOINTERDEALLOCATOR_H_ +#define SD_PRIMARYPOINTERDEALLOCATOR_H_ + +#include +#include +#include + +namespace sd { +class ND4J_EXPORT PrimaryPointerDeallocator : public PointerDeallocator { + public: + PrimaryPointerDeallocator() = default; + ~PrimaryPointerDeallocator() = default; + + void release(void* ptr) override; +}; +} + +#endif //SD_PRIMARYPOINTERDEALLOCATOR_H_ diff --git a/libnd4j/include/array/TadPack.h b/libnd4j/include/array/TadPack.h index 3cd95fa59..f7ca15fd9 100644 --- a/libnd4j/include/array/TadPack.h +++ b/libnd4j/include/array/TadPack.h @@ -21,17 +21,18 @@ #ifndef DEV_TESTS_TADPACK_H #define DEV_TESTS_TADPACK_H -#include "ConstantDataBuffer.h" +#include +#include namespace sd { class ND4J_EXPORT TadPack { private: - ConstantDataBuffer _tadShape; - ConstantDataBuffer _tadOffsets; + ConstantShapeBuffer _tadShape; + ConstantOffsetsBuffer _tadOffsets; Nd4jLong _numTads = 0 ; int _shapeInfoLength = 0; public: - explicit TadPack(ConstantDataBuffer &shapes, ConstantDataBuffer &offets, Nd4jLong numTads); + explicit TadPack(const ConstantShapeBuffer &shapes, const ConstantOffsetsBuffer &offets, Nd4jLong numTads); TadPack() = default; ~TadPack() = default; diff --git a/libnd4j/include/array/cpu/NDArray.cpp b/libnd4j/include/array/cpu/NDArray.cpp index 873b3fec9..398ebe5e8 100644 --- a/libnd4j/include/array/cpu/NDArray.cpp +++ b/libnd4j/include/array/cpu/NDArray.cpp @@ -338,7 +338,7 @@ void NDArray::tile(const std::vector& reps, NDArray& target) const { const int ews = target.ews(); const auto targetLen = target.lengthOf(); if(target.ordering() == 'c' && ews == 1) { // ews == 1 always here -//#pragma omp parallel for simd if(targetLen > Environment::getInstance()->elementwiseThreshold()) schedule(guided) +//#pragma omp parallel for simd if(targetLen > Environment::getInstance().elementwiseThreshold()) schedule(guided) for(Nd4jLong i=0; i + +namespace sd { + +void CudaPointerDeallocator::release(void *ptr) { + cudaFree(ptr); +} + +} // namespace sd diff --git a/libnd4j/include/array/cuda/DataBuffer.cu b/libnd4j/include/array/cuda/DataBuffer.cu index 922b6967b..7e88e06ba 100644 --- a/libnd4j/include/array/cuda/DataBuffer.cu +++ b/libnd4j/include/array/cuda/DataBuffer.cu @@ -70,16 +70,16 @@ void DataBuffer::allocateSpecial() { auto deviceId = sd::AffinityManager::currentDeviceId(); if (_workspace == nullptr) - if (!sd::memory::MemoryCounter::getInstance()->validate(getLenInBytes())) - throw sd::allocation_exception::build("Requested amount exceeds device limits", sd::memory::MemoryCounter::getInstance()->deviceLimit(deviceId), getLenInBytes()); + if (!sd::memory::MemoryCounter::getInstance().validate(getLenInBytes())) + throw sd::allocation_exception::build("Requested amount exceeds device limits", sd::memory::MemoryCounter::getInstance().deviceLimit(deviceId), getLenInBytes()); ALLOCATE_SPECIAL(_specialBuffer, _workspace, getLenInBytes(), int8_t); _isOwnerSpecial = true; if (_workspace == nullptr) { - sd::memory::MemoryCounter::getInstance()->countIn(deviceId, getLenInBytes()); - sd::memory::MemoryCounter::getInstance()->countIn(sd::memory::MemoryType::DEVICE, getLenInBytes()); + sd::memory::MemoryCounter::getInstance().countIn(deviceId, getLenInBytes()); + sd::memory::MemoryCounter::getInstance().countIn(sd::memory::MemoryType::DEVICE, getLenInBytes()); } } } @@ -135,8 +135,8 @@ void DataBuffer::deleteSpecial() { // count out towards DataBuffer device, only if we're not in workspace if (_workspace == nullptr) { - sd::memory::MemoryCounter::getInstance()->countOut(_deviceId, getLenInBytes()); - sd::memory::MemoryCounter::getInstance()->countOut(sd::memory::MemoryType::DEVICE, getLenInBytes()); + sd::memory::MemoryCounter::getInstance().countOut(_deviceId, getLenInBytes()); + sd::memory::MemoryCounter::getInstance().countOut(sd::memory::MemoryType::DEVICE, getLenInBytes()); } } } diff --git a/libnd4j/include/array/cuda/NDArray.cu b/libnd4j/include/array/cuda/NDArray.cu index 8ed3eceeb..f28e2ba22 100644 --- a/libnd4j/include/array/cuda/NDArray.cu +++ b/libnd4j/include/array/cuda/NDArray.cu @@ -53,7 +53,7 @@ void* NDArray::platformBuffer() { return specialBuffer(); } void const* NDArray::platformBuffer() const { return specialBuffer(); } Nd4jLong const* NDArray::platformShapeInfo() const { return specialShapeInfo(); } -//Nd4jLong const* NDArray::platformShapeInfo() { return specialShapeInfo(); } +//Nd4jLong const* NDArray::platform() { return special(); } void NDArray::syncToDevice() const { auto currentDeviceId = AffinityManager::currentDeviceId(); diff --git a/libnd4j/include/array/impl/ConstantDataBuffer.cpp b/libnd4j/include/array/impl/ConstantDataBuffer.cpp index 20c842266..2aeda3b6d 100644 --- a/libnd4j/include/array/impl/ConstantDataBuffer.cpp +++ b/libnd4j/include/array/impl/ConstantDataBuffer.cpp @@ -18,29 +18,38 @@ // @author raver119@gmail.com // -#include "../ConstantDataBuffer.h" +#include +#include namespace sd { - ConstantDataBuffer::ConstantDataBuffer(Nd4jPointer primary, Nd4jPointer special, Nd4jLong numEelements, Nd4jLong sizeOf) { - _primaryBuffer = primary; - _specialBuffer = special; - _length = numEelements; - _sizeOf = sizeOf; +ConstantDataBuffer::ConstantDataBuffer( + const std::shared_ptr& primary, + uint64_t numEelements, + DataType dtype) : ConstantDataBuffer(primary, {}, numEelements, dtype) { + // +} + +ConstantDataBuffer::ConstantDataBuffer( + const std::shared_ptr& primary, + const std::shared_ptr& special, + uint64_t numEelements, + DataType dtype) : _primaryBuffer(primary), _specialBuffer(special), _length(numEelements) { + _sizeOf = DataTypeUtils::sizeOf(dtype); } - Nd4jPointer ConstantDataBuffer::primary() const { - return _primaryBuffer; + void* ConstantDataBuffer::primary() const { + return _primaryBuffer->pointer(); } - Nd4jPointer ConstantDataBuffer::special() const { - return _specialBuffer; + void* ConstantDataBuffer::special() const { + return _specialBuffer ? _specialBuffer->pointer() : nullptr; } - Nd4jLong ConstantDataBuffer::sizeOf() const { + uint8_t ConstantDataBuffer::sizeOf() const { return _sizeOf; } - Nd4jLong ConstantDataBuffer::length() const { + uint64_t ConstantDataBuffer::length() const { return _length; } @@ -52,21 +61,21 @@ namespace sd { } template - T* ConstantDataBuffer::primaryAsT() { - return reinterpret_cast(_primaryBuffer); + T* ConstantDataBuffer::primaryAsT() const { + return reinterpret_cast(_primaryBuffer->pointer()); } - template ND4J_EXPORT float* ConstantDataBuffer::primaryAsT(); - template ND4J_EXPORT double* ConstantDataBuffer::primaryAsT(); - template ND4J_EXPORT int* ConstantDataBuffer::primaryAsT(); - template ND4J_EXPORT Nd4jLong* ConstantDataBuffer::primaryAsT(); + template ND4J_EXPORT float* ConstantDataBuffer::primaryAsT() const; + template ND4J_EXPORT double* ConstantDataBuffer::primaryAsT() const; + template ND4J_EXPORT int* ConstantDataBuffer::primaryAsT() const; + template ND4J_EXPORT Nd4jLong* ConstantDataBuffer::primaryAsT() const; template - T* ConstantDataBuffer::specialAsT() { - return reinterpret_cast(_specialBuffer); + T* ConstantDataBuffer::specialAsT() const { + return reinterpret_cast(special()); } - template ND4J_EXPORT float* ConstantDataBuffer::specialAsT(); - template ND4J_EXPORT double* ConstantDataBuffer::specialAsT(); - template ND4J_EXPORT int* ConstantDataBuffer::specialAsT(); - template ND4J_EXPORT Nd4jLong* ConstantDataBuffer::specialAsT(); + template ND4J_EXPORT float* ConstantDataBuffer::specialAsT() const; + template ND4J_EXPORT double* ConstantDataBuffer::specialAsT() const; + template ND4J_EXPORT int* ConstantDataBuffer::specialAsT() const; + template ND4J_EXPORT Nd4jLong* ConstantDataBuffer::specialAsT() const; } diff --git a/libnd4j/include/array/impl/ConstantOffsetsBuffer.cpp b/libnd4j/include/array/impl/ConstantOffsetsBuffer.cpp new file mode 100644 index 000000000..38b516a84 --- /dev/null +++ b/libnd4j/include/array/impl/ConstantOffsetsBuffer.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2019-2020 Konduit K.K. + * + * 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 +// + +#include + +namespace sd { +ConstantOffsetsBuffer::ConstantOffsetsBuffer(const std::shared_ptr &primary) : + ConstantOffsetsBuffer(primary, std::shared_ptr(nullptr)) { + // +} + +ConstantOffsetsBuffer::ConstantOffsetsBuffer(const std::shared_ptr &primary, + const std::shared_ptr &special) { + _primaryOffsets = primary; + _specialOffsets = special; +} + +const Nd4jLong *ConstantOffsetsBuffer::primary() const { + return reinterpret_cast(_primaryOffsets->pointer()); +} + +const Nd4jLong *ConstantOffsetsBuffer::special() const { + return _specialOffsets ? reinterpret_cast(_specialOffsets->pointer()) : nullptr; +} + +const Nd4jLong *ConstantOffsetsBuffer::platform() const { +#ifdef __CUDABLAS__ + return special(); +#else + return primary(); +#endif // CUDABLAS +} + +} // namespace sd diff --git a/libnd4j/include/array/impl/ConstantShapeBuffer.cpp b/libnd4j/include/array/impl/ConstantShapeBuffer.cpp new file mode 100644 index 000000000..528101100 --- /dev/null +++ b/libnd4j/include/array/impl/ConstantShapeBuffer.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2019-2020 Konduit K.K. + * + * 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 +// + +#include + +namespace sd { +ConstantShapeBuffer::ConstantShapeBuffer(const std::shared_ptr &primary) : + ConstantShapeBuffer(primary, std::shared_ptr(nullptr)) { + // +} + +ConstantShapeBuffer::ConstantShapeBuffer(const std::shared_ptr &primary, + const std::shared_ptr &special) { + _primaryShapeInfo = primary; + _specialShapeInfo = special; +} + +const Nd4jLong *ConstantShapeBuffer::primary() const { + return reinterpret_cast(_primaryShapeInfo->pointer()); +} + +const Nd4jLong *ConstantShapeBuffer::special() const { + return _specialShapeInfo ? reinterpret_cast(_specialShapeInfo->pointer()) : nullptr; +} + +const Nd4jLong *ConstantShapeBuffer::platform() const { +#ifdef __CUDABLAS__ + return special(); +#else + return primary(); +#endif // CUDABLAS +} + +} // namespace sd diff --git a/libnd4j/include/array/impl/DataBuffer.cpp b/libnd4j/include/array/impl/DataBuffer.cpp index 262460e8c..89c386c3d 100644 --- a/libnd4j/include/array/impl/DataBuffer.cpp +++ b/libnd4j/include/array/impl/DataBuffer.cpp @@ -237,14 +237,14 @@ namespace sd { auto deviceId = sd::AffinityManager::currentDeviceId(); // check if this allocation won't bring us above limit if (_workspace == nullptr) { - if (Environment::getInstance()->isCPU()) { + if (Environment::getInstance().isCPU()) { // on cpu backend we validate against device 0 for now - if (!sd::memory::MemoryCounter::getInstance()->validate(getLenInBytes())) - throw sd::allocation_exception::build("Requested amount exceeds HOST device limits", sd::memory::MemoryCounter::getInstance()->deviceLimit(deviceId), getLenInBytes()); + if (!sd::memory::MemoryCounter::getInstance().validate(getLenInBytes())) + throw sd::allocation_exception::build("Requested amount exceeds HOST device limits", sd::memory::MemoryCounter::getInstance().deviceLimit(deviceId), getLenInBytes()); } else { // in heterogenous mode we valdate against device group - if (!sd::memory::MemoryCounter::getInstance()->validateGroup(sd::memory::MemoryType::HOST, getLenInBytes())) - throw sd::allocation_exception::build("Requested amount exceeds HOST group limits", sd::memory::MemoryCounter::getInstance()->groupLimit(sd::memory::MemoryType::HOST), getLenInBytes()); + if (!sd::memory::MemoryCounter::getInstance().validateGroup(sd::memory::MemoryType::HOST, getLenInBytes())) + throw sd::allocation_exception::build("Requested amount exceeds HOST group limits", sd::memory::MemoryCounter::getInstance().groupLimit(sd::memory::MemoryType::HOST), getLenInBytes()); } } @@ -253,10 +253,10 @@ namespace sd { // count in towards current deviceId if we're not in workspace mode if (_workspace == nullptr) { - if (Environment::getInstance()->isCPU()) // we don't want this counter to be added to CUDA device - sd::memory::MemoryCounter::getInstance()->countIn(deviceId, getLenInBytes()); + if (Environment::getInstance().isCPU()) // we don't want this counter to be added to CUDA device + sd::memory::MemoryCounter::getInstance().countIn(deviceId, getLenInBytes()); - sd::memory::MemoryCounter::getInstance()->countIn(sd::memory::MemoryType::HOST, getLenInBytes()); + sd::memory::MemoryCounter::getInstance().countIn(sd::memory::MemoryType::HOST, getLenInBytes()); } } } @@ -279,10 +279,10 @@ namespace sd { // count out towards DataBuffer device, only if we're not in workspace if (_workspace == nullptr) { - if (Environment::getInstance()->isCPU()) - sd::memory::MemoryCounter::getInstance()->countOut(_deviceId, getLenInBytes()); + if (Environment::getInstance().isCPU()) + sd::memory::MemoryCounter::getInstance().countOut(_deviceId, getLenInBytes()); - sd::memory::MemoryCounter::getInstance()->countOut(sd::memory::MemoryType::HOST, getLenInBytes()); + sd::memory::MemoryCounter::getInstance().countOut(sd::memory::MemoryType::HOST, getLenInBytes()); } } } diff --git a/libnd4j/include/array/impl/PointerDeallocator.cpp b/libnd4j/include/array/impl/PointerDeallocator.cpp new file mode 100644 index 000000000..2cd41cdda --- /dev/null +++ b/libnd4j/include/array/impl/PointerDeallocator.cpp @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2019-2020 Konduit K.K. + * + * 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 +// + +#include + +namespace sd { + +void PointerDeallocator::release(void *ptr) { + // noop +} + +} // namespace sd diff --git a/libnd4j/include/array/impl/PointerWrapper.cpp b/libnd4j/include/array/impl/PointerWrapper.cpp new file mode 100644 index 000000000..b39cb54aa --- /dev/null +++ b/libnd4j/include/array/impl/PointerWrapper.cpp @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2019-2020 Konduit K.K. + * + * 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 +// + +#include + +namespace sd { +PointerWrapper::PointerWrapper(void *ptr, const std::shared_ptr &deallocator): _pointer(ptr), _deallocator(deallocator) { + // +} + +PointerWrapper::~PointerWrapper() { + if (_deallocator.get() != nullptr) + _deallocator->release(_pointer); +} + +void *PointerWrapper::pointer() const { + return _pointer; +} + +} // namespace sd diff --git a/libnd4j/include/array/impl/PrimaryPointerDeallocator.cpp b/libnd4j/include/array/impl/PrimaryPointerDeallocator.cpp new file mode 100644 index 000000000..edd58d610 --- /dev/null +++ b/libnd4j/include/array/impl/PrimaryPointerDeallocator.cpp @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2019-2020 Konduit K.K. + * + * 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 +// + +#include + +namespace sd { + +void PrimaryPointerDeallocator::release(void *ptr) { + delete[] reinterpret_cast(ptr); +} + +} // namespace sd diff --git a/libnd4j/include/array/impl/TadPack.cpp b/libnd4j/include/array/impl/TadPack.cpp index 7a3bdbe36..e489d0e83 100644 --- a/libnd4j/include/array/impl/TadPack.cpp +++ b/libnd4j/include/array/impl/TadPack.cpp @@ -23,26 +23,24 @@ #include namespace sd { - TadPack::TadPack(ConstantDataBuffer &shapes, ConstantDataBuffer &offets, Nd4jLong numTads) { - _tadShape = shapes; - _tadOffsets = offets; + TadPack::TadPack(const ConstantShapeBuffer &shapes, const ConstantOffsetsBuffer &offets, Nd4jLong numTads) : _tadShape(shapes), _tadOffsets(offets) { _numTads = numTads; } const Nd4jLong* TadPack::primaryShapeInfo() const { - return reinterpret_cast(_tadShape.primary()); + return _tadShape.primary(); } const Nd4jLong* TadPack::primaryOffsets() const { - return reinterpret_cast(_tadOffsets.primary()); + return _tadOffsets.primary(); } const Nd4jLong* TadPack::specialShapeInfo() const { - return reinterpret_cast(_tadShape.special()); + return _tadShape.special(); } const Nd4jLong* TadPack::specialOffsets() const { - return reinterpret_cast(_tadOffsets.special()); + return _tadOffsets.special(); } Nd4jLong TadPack::numberOfTads() const { @@ -50,11 +48,11 @@ namespace sd { } const Nd4jLong* TadPack::platformShapeInfo() const { - return sd::Environment::getInstance()->isCPU() ? primaryShapeInfo() : specialShapeInfo(); + return sd::Environment::getInstance().isCPU() ? primaryShapeInfo() : specialShapeInfo(); } const Nd4jLong* TadPack::platformOffsets() const { - return sd::Environment::getInstance()->isCPU() ? primaryOffsets() : specialOffsets(); + return sd::Environment::getInstance().isCPU() ? primaryOffsets() : specialOffsets(); } int TadPack::shapeInfoLength() const { diff --git a/libnd4j/include/execution/ThreadPool.h b/libnd4j/include/execution/ThreadPool.h index 6811f1b1c..ce44d5ae2 100644 --- a/libnd4j/include/execution/ThreadPool.h +++ b/libnd4j/include/execution/ThreadPool.h @@ -35,9 +35,7 @@ namespace samediff { class ND4J_EXPORT ThreadPool { private: - static ThreadPool* _INSTANCE; - - std::vector _threads; + std::vector _threads; std::vector*> _queues; std::vector _interfaces; @@ -48,7 +46,7 @@ namespace samediff { ThreadPool(); ~ThreadPool(); public: - static ThreadPool* getInstance(); + static ThreadPool& getInstance(); /** * This method returns list of pointers to threads ONLY if num_threads of threads were available upon request, returning empty list otherwise diff --git a/libnd4j/include/execution/Threads.h b/libnd4j/include/execution/Threads.h index 2ea8295a8..bf35de089 100644 --- a/libnd4j/include/execution/Threads.h +++ b/libnd4j/include/execution/Threads.h @@ -107,7 +107,7 @@ namespace samediff { * @param increment * @return */ - static int parallel_for(FUNC_1D function, int64_t start, int64_t stop, int64_t increment = 1, uint32_t numThreads = sd::Environment::getInstance()->maxMasterThreads()); + static int parallel_for(FUNC_1D function, int64_t start, int64_t stop, int64_t increment = 1, uint32_t numThreads = sd::Environment::getInstance().maxMasterThreads()); /** * This function executes 1 dimensional loop for a given number of threads @@ -119,7 +119,7 @@ namespace samediff { * @param numThreads * @return */ - static int parallel_tad(FUNC_1D function, int64_t start, int64_t stop, int64_t increment = 1, uint32_t numThreads = sd::Environment::getInstance()->maxMasterThreads()); + static int parallel_tad(FUNC_1D function, int64_t start, int64_t stop, int64_t increment = 1, uint32_t numThreads = sd::Environment::getInstance().maxMasterThreads()); /** * This method will execute function splitting 2 nested loops space with multiple threads @@ -134,7 +134,7 @@ namespace samediff { * @param inc_y * @return */ - static int parallel_for(FUNC_2D function, int64_t start_x, int64_t stop_x, int64_t inc_x, int64_t start_y, int64_t stop_y, int64_t inc_y, uint64_t numThreads = sd::Environment::getInstance()->maxMasterThreads(), bool debug = false); + static int parallel_for(FUNC_2D function, int64_t start_x, int64_t stop_x, int64_t inc_x, int64_t start_y, int64_t stop_y, int64_t inc_y, uint64_t numThreads = sd::Environment::getInstance().maxMasterThreads(), bool debug = false); /** * This method will execute function splitting 3 nested loops space with multiple threads @@ -152,7 +152,7 @@ namespace samediff { * @param inc_z * @return */ - static int parallel_for(FUNC_3D function, int64_t start_x, int64_t stop_x, int64_t inc_x, int64_t start_y, int64_t stop_y, int64_t inc_y, int64_t start_z, int64_t stop_z, int64_t inc_z, uint64_t numThreads = sd::Environment::getInstance()->maxMasterThreads()); + static int parallel_for(FUNC_3D function, int64_t start_x, int64_t stop_x, int64_t inc_x, int64_t start_y, int64_t stop_y, int64_t inc_y, int64_t start_z, int64_t stop_z, int64_t inc_z, uint64_t numThreads = sd::Environment::getInstance().maxMasterThreads()); /** * @@ -160,18 +160,18 @@ namespace samediff { * @param numThreads * @return */ - static int parallel_do(FUNC_DO function, uint64_t numThreads = sd::Environment::getInstance()->maxMasterThreads()); + static int parallel_do(FUNC_DO function, uint64_t numThreads = sd::Environment::getInstance().maxMasterThreads()); - static int64_t parallel_long(FUNC_RL function, FUNC_AL aggregator, int64_t start, int64_t stop, int64_t increment = 1, uint64_t numThreads = sd::Environment::getInstance()->maxMasterThreads()); + static int64_t parallel_long(FUNC_RL function, FUNC_AL aggregator, int64_t start, int64_t stop, int64_t increment = 1, uint64_t numThreads = sd::Environment::getInstance().maxMasterThreads()); - static double parallel_double(FUNC_RD function, FUNC_AD aggregator, int64_t start, int64_t stop, int64_t increment = 1, uint64_t numThreads = sd::Environment::getInstance()->maxMasterThreads()); + static double parallel_double(FUNC_RD function, FUNC_AD aggregator, int64_t start, int64_t stop, int64_t increment = 1, uint64_t numThreads = sd::Environment::getInstance().maxMasterThreads()); /** * This method will execute function in parallel preserving the parts to be aligned increment size * PLEASE NOTE: this function can use smaller number of threads than requested. * */ - static int parallel_aligned_increment(FUNC_1D function, int64_t start, int64_t stop, int64_t increment, size_t type_size = sizeof(float), uint32_t req_numThreads = sd::Environment::getInstance()->maxMasterThreads()); + static int parallel_aligned_increment(FUNC_1D function, int64_t start, int64_t stop, int64_t increment, size_t type_size = sizeof(float), uint32_t req_numThreads = sd::Environment::getInstance().maxMasterThreads()); }; } diff --git a/libnd4j/include/execution/cpu/LaunchContext.cpp b/libnd4j/include/execution/cpu/LaunchContext.cpp index 23e78c350..31cb6889d 100644 --- a/libnd4j/include/execution/cpu/LaunchContext.cpp +++ b/libnd4j/include/execution/cpu/LaunchContext.cpp @@ -61,14 +61,19 @@ namespace sd { } - LaunchContext* LaunchContext::defaultContext() { - // TODO: we need it to be device-aware, but only once we add NUMA support for cpu - if (LaunchContext::_contexts.empty()) { - LaunchContext::_contexts.emplace_back(std::make_shared()); - } + static std::mutex _lock; - // return context for current device - return LaunchContext::_contexts[0].get(); + LaunchContext* LaunchContext::defaultContext() { + { + // synchronous block goes here + std::lock_guard lock(_lock); + // TODO: we need it to be device-aware, but only once we add NUMA support for cpu + if (LaunchContext::_contexts.empty()) + LaunchContext::_contexts.emplace_back(std::make_shared()); + } + + // return context for current device + return LaunchContext::_contexts[0].get(); } std::mutex* LaunchContext::deviceMutex() { diff --git a/libnd4j/include/execution/cuda/LaunchContext.cu b/libnd4j/include/execution/cuda/LaunchContext.cu index 8380e50bf..bd51c3504 100644 --- a/libnd4j/include/execution/cuda/LaunchContext.cu +++ b/libnd4j/include/execution/cuda/LaunchContext.cu @@ -1,5 +1,6 @@ /******************************************************************************* * Copyright (c) 2015-2018 Skymind, Inc. + * Copyright (c) 2020 Konduit K.K. * * This program and the accompanying materials are made available under the * terms of the Apache License, Version 2.0 which is available at @@ -15,7 +16,7 @@ ******************************************************************************/ // -// Created by raver119 on 30.11.17. +// @author raver119@gmail.com // #include @@ -75,36 +76,37 @@ LaunchContext::LaunchContext() { } LaunchContext* LaunchContext::defaultContext() { - /** - * This method returns LaunchContext, that has multiple entities within: - * 1) temporary buffers. they must be per-thread - * 2) CUDA stream. it must be either per-thread or per-device - * 3) cuBLAS handle. it must be per-device - */ - auto deviceId = AffinityManager::currentDeviceId(); + /** + * This method returns LaunchContext, that has multiple entities within: + * 1) temporary buffers. they must be per-thread + * 2) CUDA stream. it must be either per-thread or per-device + * 3) cuBLAS handle. it must be per-device + */ + auto deviceId = AffinityManager::currentDeviceId(); + { // we need this block synchronous, to avoid double initialization etc - _mutex.lock(); + std::lock_guard lock(_mutex); if (LaunchContext::_contexts.empty()) { - // create one context per device - auto numDevices = AffinityManager::numberOfDevices(); + // create one context per device + auto numDevices = AffinityManager::numberOfDevices(); - _contexts.resize(numDevices); - for (int e = 0; e < numDevices; e++) { - _deviceMutexes[e] = new std::mutex(); + _contexts.resize(numDevices); + for (int e = 0; e < numDevices; e++) { + _deviceMutexes[e] = new std::mutex(); - AffinityManager::setCurrentNativeDevice(e); + AffinityManager::setCurrentNativeDevice(e); - LaunchContext::_contexts[e] = std::make_shared(); - } + LaunchContext::_contexts[e] = std::make_shared(); + } - // don't forget to restore device back again - AffinityManager::setCurrentNativeDevice(deviceId); + // don't forget to restore device back again + AffinityManager::setCurrentNativeDevice(deviceId); } - _mutex.unlock(); + } - // return context for current device - return LaunchContext::_contexts[deviceId].get(); + // return context for current device + return LaunchContext::_contexts[deviceId].get(); } @@ -121,11 +123,11 @@ LaunchContext::LaunchContext() { }; void* LaunchContext::getCublasHandle() const { - return CublasHelper::getInstance()->handle(); + return CublasHelper::getInstance().handle(); }; void* LaunchContext::getCusolverHandle() const { - return CublasHelper::getInstance()->solver(); + return CublasHelper::getInstance().solver(); }; cudaStream_t* LaunchContext::getCudaStream() const { @@ -175,7 +177,7 @@ LaunchContext::LaunchContext() { } void* LaunchContext::getCuDnnHandle() const { - return CublasHelper::getInstance()->cudnn(); + return CublasHelper::getInstance().cudnn(); } sd::ErrorReference* LaunchContext::errorReference() { diff --git a/libnd4j/include/execution/impl/ThreadPool.cpp b/libnd4j/include/execution/impl/ThreadPool.cpp index b02c4c4d5..f6c3fdaca 100644 --- a/libnd4j/include/execution/impl/ThreadPool.cpp +++ b/libnd4j/include/execution/impl/ThreadPool.cpp @@ -78,7 +78,7 @@ namespace samediff { ThreadPool::ThreadPool() { // TODO: number of threads must reflect number of cores for UMA system. In case of NUMA it should be per-device pool // FIXME: on mobile phones this feature must NOT be used - _available = sd::Environment::getInstance()->maxThreads(); + _available = sd::Environment::getInstance().maxThreads(); _queues.resize(_available.load()); _threads.resize(_available.load()); @@ -88,7 +88,7 @@ namespace samediff { for (int e = 0; e < _available.load(); e++) { _queues[e] = new BlockingQueue(2); _interfaces[e] = new CallableInterface(); - _threads[e] = new std::thread(executionLoopWithInterface_, e, _interfaces[e]); + _threads[e] = std::thread(executionLoopWithInterface_, e, _interfaces[e]); _tickets.push(new Ticket()); // _threads[e] = new std::thread(executionLoop_, e, _queues[e]); @@ -125,19 +125,22 @@ namespace samediff { // stop each and every thread // release queue and thread - //delete _queues[e]; - //delete _threads[e]; + delete _queues[e]; + _threads[e].detach(); + //delete _interfaces[e]; } + + while (!_tickets.empty()) { + auto t = _tickets.front(); + _tickets.pop(); + delete t; + } + } - static std::mutex _lmutex; - - ThreadPool* ThreadPool::getInstance() { - std::unique_lock lock(_lmutex); - if (!_INSTANCE) - _INSTANCE = new ThreadPool(); - - return _INSTANCE; + ThreadPool& ThreadPool::getInstance() { + static ThreadPool instance; + return instance; } void ThreadPool::release(int numThreads) { @@ -188,7 +191,4 @@ namespace samediff { std::unique_lock lock(_lock); _tickets.push(ticket); } - - - ThreadPool* ThreadPool::_INSTANCE = 0; } diff --git a/libnd4j/include/execution/impl/Threads.cpp b/libnd4j/include/execution/impl/Threads.cpp index 51339abf1..90dd519b1 100644 --- a/libnd4j/include/execution/impl/Threads.cpp +++ b/libnd4j/include/execution/impl/Threads.cpp @@ -357,7 +357,7 @@ namespace samediff { return 1; } - auto ticket = ThreadPool::getInstance()->tryAcquire(numThreads); + auto ticket = ThreadPool::getInstance().tryAcquire(numThreads); if (ticket != nullptr) { // if we got our threads - we'll run our jobs here auto span = delta / numThreads; @@ -449,7 +449,7 @@ namespace samediff { // but we still mimic multithreaded execution return numThreads; } else { - auto ticket = ThreadPool::getInstance()->tryAcquire(numThreads); + auto ticket = ThreadPool::getInstance().tryAcquire(numThreads); if (ticket != nullptr) { for (int e = 0; e < numThreads; e++) { @@ -499,7 +499,7 @@ namespace samediff { return 1; } - auto ticket = ThreadPool::getInstance()->tryAcquire(numThreads); + auto ticket = ThreadPool::getInstance().tryAcquire(numThreads); if (ticket != nullptr) { auto splitLoop = ThreadsHelper::pickLoop3d(numThreads, itersX, itersY, itersZ); @@ -526,7 +526,7 @@ namespace samediff { } int Threads::parallel_do(FUNC_DO function, uint64_t numThreads) { - auto ticket = ThreadPool::getInstance()->tryAcquire(numThreads - 1); + auto ticket = ThreadPool::getInstance().tryAcquire(numThreads - 1); if (ticket != nullptr) { // submit tasks one by one @@ -565,7 +565,7 @@ namespace samediff { if (numThreads == 1) return function(0, start, stop, increment); - auto ticket = ThreadPool::getInstance()->tryAcquire(numThreads - 1); + auto ticket = ThreadPool::getInstance().tryAcquire(numThreads - 1); if (ticket == nullptr) return function(0, start, stop, increment); @@ -609,7 +609,7 @@ namespace samediff { if (numThreads == 1) return function(0, start, stop, increment); - auto ticket = ThreadPool::getInstance()->tryAcquire(numThreads - 1); + auto ticket = ThreadPool::getInstance().tryAcquire(numThreads - 1); if (ticket == nullptr) return function(0, start, stop, increment); @@ -668,7 +668,7 @@ namespace samediff { numThreads = static_cast(std::ceil((double)delta / spand)); auto span = static_cast(spand); - auto ticket = samediff::ThreadPool::getInstance()->tryAcquire(numThreads); + auto ticket = samediff::ThreadPool::getInstance().tryAcquire(numThreads); if (ticket != nullptr) { //tail_add is additional value of the last part //it could be negative or positive diff --git a/libnd4j/include/execution/impl/Ticket.cpp b/libnd4j/include/execution/impl/Ticket.cpp index 98cb05376..b50b8f771 100644 --- a/libnd4j/include/execution/impl/Ticket.cpp +++ b/libnd4j/include/execution/impl/Ticket.cpp @@ -31,7 +31,7 @@ namespace samediff { Ticket::Ticket() { _acquired = true; - _interfaces.resize(sd::Environment::getInstance()->maxThreads()); + _interfaces.resize(sd::Environment::getInstance().maxThreads()); } bool Ticket::acquired() { @@ -80,11 +80,11 @@ namespace samediff { _interfaces[e]->markAvailable(); // increment availability counter - ThreadPool::getInstance()->release(); + ThreadPool::getInstance().release(); } // return this ticket back to the pool - ThreadPool::getInstance()->release(this); + ThreadPool::getInstance().release(this); } diff --git a/libnd4j/include/graph/ContextPrototype.h b/libnd4j/include/graph/ContextPrototype.h index 57d773dbb..e61831fa7 100644 --- a/libnd4j/include/graph/ContextPrototype.h +++ b/libnd4j/include/graph/ContextPrototype.h @@ -61,7 +61,7 @@ namespace sd { std::vector _dataTypes; sd::ops::OpDescriptor* _opDescriptor; - bool _useMKLDNN = sd::Environment::getInstance()->isUseMKLDNN(); + bool _useMKLDNN = sd::Environment::getInstance().isUseMKLDNN(); // target engine for execution samediff::Engine _engine = DEFAULT_ENGINE; diff --git a/libnd4j/include/graph/GraphHolder.h b/libnd4j/include/graph/GraphHolder.h index 07e091f42..84aebd694 100644 --- a/libnd4j/include/graph/GraphHolder.h +++ b/libnd4j/include/graph/GraphHolder.h @@ -30,7 +30,6 @@ namespace sd { namespace graph { class ND4J_EXPORT GraphHolder { private: - static GraphHolder *_INSTANCE; MAP_IMPL _graphF; MAP_IMPL _locks; @@ -38,7 +37,7 @@ namespace sd { GraphHolder() = default; ~GraphHolder() = default; public: - static GraphHolder* getInstance(); + static GraphHolder& getInstance(); void registerGraph(Nd4jLong graphId, Graph *graph); diff --git a/libnd4j/include/graph/execution/impl/LogicReturn.cpp b/libnd4j/include/graph/execution/impl/LogicReturn.cpp index c9dbafd6d..0ee62e945 100644 --- a/libnd4j/include/graph/execution/impl/LogicReturn.cpp +++ b/libnd4j/include/graph/execution/impl/LogicReturn.cpp @@ -34,7 +34,7 @@ namespace sd { // FIXME!! outputAddr.second = e; - if (Environment::getInstance()->isDebugAndVerbose()) + if (Environment::getInstance().isDebugAndVerbose()) nd4j_debug("Return input: <%i, %i>; Return output: <%i, %i>\n", inputAddr.first, inputAddr.second, outputAddr.first, outputAddr.second); auto varIn = __variableSpace->getVariable(inputAddr); @@ -45,7 +45,7 @@ namespace sd { // FIXME: this is obviously wrong, we should keep depth track for backprop here varOut->getNDArray()->assign(varIn->getNDArray()); - if (Environment::getInstance()->isDebugAndVerbose()) + if (Environment::getInstance().isDebugAndVerbose()) nd4j_debug("In after: [%f]; Out after: [%f]\n", varIn->getNDArray()->meanNumber().e(0), varOut->getNDArray()->meanNumber().e(0)); } diff --git a/libnd4j/include/graph/execution/impl/LogicWhile.cpp b/libnd4j/include/graph/execution/impl/LogicWhile.cpp index 1dfd3aaf2..fec9a0d30 100644 --- a/libnd4j/include/graph/execution/impl/LogicWhile.cpp +++ b/libnd4j/include/graph/execution/impl/LogicWhile.cpp @@ -96,7 +96,7 @@ namespace sd { // now we should take result of the Scope run, and evaluate it auto result = __variableSpace->getVariable(lastNode)->getNDArray(); - if (Environment::getInstance()->isDebugAndVerbose()) + if (Environment::getInstance().isDebugAndVerbose()) result->printBuffer("Result of the last node:"); // if result evaluates to 0.0 - condition returned FALSE diff --git a/libnd4j/include/graph/impl/Context.cpp b/libnd4j/include/graph/impl/Context.cpp index ae5bc59a0..f76f66bbe 100644 --- a/libnd4j/include/graph/impl/Context.cpp +++ b/libnd4j/include/graph/impl/Context.cpp @@ -236,7 +236,7 @@ namespace sd { auto v = variable(p); - if (Environment::getInstance()->isDebugAndVerbose() && v != nullptr && v->getNDArray() != nullptr) { + if (Environment::getInstance().isDebugAndVerbose() && v != nullptr && v->getNDArray() != nullptr) { auto array = v->getNDArray(); std::string shape_ = ShapeUtils::shapeAsString(array); auto type = DataTypeUtils::asString(array->dataType()); diff --git a/libnd4j/include/graph/impl/Graph.cpp b/libnd4j/include/graph/impl/Graph.cpp index 177adbe07..a50d1f4b6 100644 --- a/libnd4j/include/graph/impl/Graph.cpp +++ b/libnd4j/include/graph/impl/Graph.cpp @@ -166,7 +166,7 @@ namespace sd { // aNewShape[5] = 8192; // set type as FLOAT32 by default // aNewShape[6] = 1; // aNewShape[7] = 99; - newShape = ConstantShapeHelper::getInstance()->createShapeInfo(DataType::FLOAT32, 'c', {1,1}); + newShape = ConstantShapeHelper::getInstance().createShapeInfo(DataType::FLOAT32, 'c', {1,1}); } else { auto in = node->input()->at(0); @@ -184,7 +184,7 @@ namespace sd { //shape::TAD tad(oldShape, node->getDimensions()->data(), node->getDimensions()->size()); auto numTads = shape::tadLength(oldShape, node->getDimensions()->data(), node->getDimensions()->size()); Nd4jLong shape[2] = {1, (int) numTads}; - newShape = ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(oldShape), 'c', 2, shape); + newShape = ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(oldShape), 'c', 2, shape); } std::pair pairAddr(node->id(), 0); @@ -805,7 +805,7 @@ namespace sd { // we're adding final nodes of the graph. those, not used as input anywhere nd4j_debug("Paring nodes... \n", ""); - if (Environment::getInstance()->isDebugAndVerbose()) { + if (Environment::getInstance().isDebugAndVerbose()) { // nd4j_printv("current _output", _output); } //_output.clear(); @@ -852,7 +852,7 @@ namespace sd { if (std::find(_output.begin(), _output.end(), node->id()) == _output.end()) _output.emplace_back(node->id()); - } else if (Environment::getInstance()->isDebugAndVerbose()) { + } else if (Environment::getInstance().isDebugAndVerbose()) { nd4j_debug("Node [%i:<%s>] has %i outputs announced:\n", v, node->name()->c_str(), node->output()->size()); printf("{"); for (auto s : *node->output()) { @@ -1202,7 +1202,7 @@ namespace sd { } break; default: { - opNameStr = std::string(EnumUtils::_OpTypeToString(node->opType()))+"{" + ops::OpRegistrator::getInstance()->local_to_string((int) node->opNum()) + "}"; + opNameStr = std::string(EnumUtils::_OpTypeToString(node->opType()))+"{" + ops::OpRegistrator::getInstance().local_to_string((int) node->opNum()) + "}"; } } @@ -1250,7 +1250,7 @@ namespace sd { } break; default: { - opNameStr = std::string(EnumUtils::_OpTypeToString(node->opType()))+"{" + ops::OpRegistrator::getInstance()->local_to_string((int) node->opNum()) + "}"; + opNameStr = std::string(EnumUtils::_OpTypeToString(node->opType()))+"{" + ops::OpRegistrator::getInstance().local_to_string((int) node->opNum()) + "}"; } } @@ -1447,7 +1447,7 @@ namespace sd { } - hash = ops::HashHelper::getInstance()->getLongHash(localStamp); + hash = ops::HashHelper::getInstance().getLongHash(localStamp); nd4j_debug("Graph hash: %lld\n", hash); diff --git a/libnd4j/include/graph/impl/GraphExecutioner.cpp b/libnd4j/include/graph/impl/GraphExecutioner.cpp index c673d2b31..abc3b2e0c 100644 --- a/libnd4j/include/graph/impl/GraphExecutioner.cpp +++ b/libnd4j/include/graph/impl/GraphExecutioner.cpp @@ -88,7 +88,7 @@ namespace graph { Context context(node->getContextPrototype(), variableSpace); - if (sd::Environment::getInstance()->isDebugAndVerbose()) { + if (sd::Environment::getInstance().isDebugAndVerbose()) { //nd4j_debug("Input variables: %i\n", node->input()->size()); printf(" Inputs: {"); for (int e = 0; e < node->input()->size(); e++) { @@ -215,10 +215,10 @@ Nd4jStatus GraphExecutioner::execute(Graph *graph, VariableSpace* variableSpace) } auto flowPath = __variableSpace->flowPath(); - Nd4jLong tb0 = Environment::getInstance()->isProfiling() ? GraphProfile::currentTime() : 0L; + Nd4jLong tb0 = Environment::getInstance().isProfiling() ? GraphProfile::currentTime() : 0L; graph->buildGraph(); - auto footprintForward = sd::memory::MemoryRegistrator::getInstance()->getGraphMemoryFootprint(graph->hashCode()); + auto footprintForward = sd::memory::MemoryRegistrator::getInstance().getGraphMemoryFootprint(graph->hashCode()); if (footprintForward > 0) { if (__variableSpace->launchContext()->getWorkspace() != nullptr) { // this method will work only if current workspace size is smaller then proposed value @@ -228,10 +228,10 @@ Nd4jStatus GraphExecutioner::execute(Graph *graph, VariableSpace* variableSpace) } // optionally saving graph build time - if (Environment::getInstance()->isProfiling()) + if (Environment::getInstance().isProfiling()) flowPath->profile()->setBuildTime(GraphProfile::relativeTime(tb0)); - Nd4jLong timeStart = Environment::getInstance()->isProfiling() ? GraphProfile::currentTime() : 0L; + Nd4jLong timeStart = Environment::getInstance().isProfiling() ? GraphProfile::currentTime() : 0L; bool pe = graph->getExecutorConfiguration()->_executionMode == ExecutionMode_AUTO; @@ -259,10 +259,10 @@ Nd4jStatus GraphExecutioner::execute(Graph *graph, VariableSpace* variableSpace) Node* node = graph->getOnion()->at(l)->at(n); - if (Environment::getInstance()->isProfiling()) + if (Environment::getInstance().isProfiling()) flowPath->profile()->nodeById(node->id(), node->name()->c_str()); - if (lastId != node->id() && Environment::getInstance()->isProfiling()) { + if (lastId != node->id() && Environment::getInstance().isProfiling()) { if (lastId != -10000000) flowPath->profile()->nodeById(lastId)->setTotalTime(GraphProfile::relativeTime(nodeTime)); @@ -458,7 +458,7 @@ Nd4jStatus GraphExecutioner::execute(Graph *graph, VariableSpace* variableSpace) // now we skip all branches except of this active one } - if (sd::Environment::getInstance()->isDebugAndVerbose()) { + if (sd::Environment::getInstance().isDebugAndVerbose()) { if (__variableSpace->getVariable(node->id())->hasNDArray()) { auto array = __variableSpace->getVariable(node->id())->getNDArray(); @@ -481,7 +481,7 @@ Nd4jStatus GraphExecutioner::execute(Graph *graph, VariableSpace* variableSpace) } // optionally saving execution time - if (Environment::getInstance()->isProfiling()) { + if (Environment::getInstance().isProfiling()) { flowPath->profile()->nodeById(lastId)->setTotalTime(GraphProfile::relativeTime(nodeTime)); flowPath->profile()->setExecutionTime(GraphProfile::relativeTime(timeStart)); //flowPath->profile().printOut(); @@ -491,7 +491,7 @@ Nd4jStatus GraphExecutioner::execute(Graph *graph, VariableSpace* variableSpace) if (__variableSpace->launchContext()->getWorkspace() != nullptr) { auto m = __variableSpace->launchContext()->getWorkspace()->getAllocatedSize(); auto h = graph->hashCode(); - sd::memory::MemoryRegistrator::getInstance()->setGraphMemoryFootprintIfGreater(h, m); + sd::memory::MemoryRegistrator::getInstance().setGraphMemoryFootprintIfGreater(h, m); } if (tempFlow) { @@ -523,7 +523,7 @@ Nd4jStatus GraphExecutioner::execute(Graph *graph, VariableSpace* variableSpace) // converting FlatGraph to internal representation auto nativeGraph = new Graph(restoredGraph); - if (Environment::getInstance()->isDebugAndVerbose()) { + if (Environment::getInstance().isDebugAndVerbose()) { nativeGraph->printOut(); } @@ -742,7 +742,7 @@ Graph* GraphExecutioner::importFromTensorFlow(const char *fileName) { nd4j_verbose("Node id: [%i]; name: [%s]; opName: [%s]\n", n + 1, node.name().c_str(), node.op().c_str()); - sd::ops::DeclarableOp *op = sd::ops::OpRegistrator::getInstance()->getOperationFloat(node.op().c_str()); + sd::ops::DeclarableOp *op = sd::ops::OpRegistrator::getInstance().getOperationFloat(node.op().c_str()); if (op == nullptr) { nd4j_verbose("Op wasn't found: %s\n", node.op().c_str()); @@ -859,7 +859,7 @@ flatbuffers::Offset GraphExecutioner::execute(Graph *graph, flatbuff } } - if (Environment::getInstance()->isDebugAndVerbose()) + if (Environment::getInstance().isDebugAndVerbose()) graph->printOut(); auto status = GraphExecutioner::execute(graph); diff --git a/libnd4j/include/graph/impl/GraphHolder.cpp b/libnd4j/include/graph/impl/GraphHolder.cpp index c480508f5..13c4e3896 100644 --- a/libnd4j/include/graph/impl/GraphHolder.cpp +++ b/libnd4j/include/graph/impl/GraphHolder.cpp @@ -25,11 +25,9 @@ namespace sd { namespace graph { - GraphHolder* GraphHolder::getInstance() { - if (_INSTANCE == 0) - _INSTANCE = new GraphHolder(); - - return _INSTANCE; + GraphHolder& GraphHolder::getInstance() { + static GraphHolder instance; + return instance; }; void GraphHolder::registerGraph(Nd4jLong graphId, Graph* graph) { @@ -126,7 +124,5 @@ namespace sd { return res; } - - GraphHolder* GraphHolder::_INSTANCE = 0; } } diff --git a/libnd4j/include/graph/impl/Node.cpp b/libnd4j/include/graph/impl/Node.cpp index e3ea75ef9..a3baf1a9b 100644 --- a/libnd4j/include/graph/impl/Node.cpp +++ b/libnd4j/include/graph/impl/Node.cpp @@ -636,7 +636,7 @@ namespace sd { block->setOpDescriptor(this->getCustomOp()->getOpDescriptor()); } } else if (this->_opType == OpType_CUSTOM) { - auto op = sd::ops::OpRegistrator::getInstance()->getOperation(this->opNum()); + auto op = sd::ops::OpRegistrator::getInstance().getOperation(this->opNum()); if (op == nullptr) { nd4j_verbose("Can't find operation: %lld\n", this->opNum()); throw std::runtime_error("Can't find requested operation"); diff --git a/libnd4j/include/helpers/BlasHelper.h b/libnd4j/include/helpers/BlasHelper.h index b2fe7b60c..038df67b5 100644 --- a/libnd4j/include/helpers/BlasHelper.h +++ b/libnd4j/include/helpers/BlasHelper.h @@ -364,8 +364,6 @@ namespace sd { class BlasHelper { private: - static BlasHelper* _instance; - bool _hasHgemv = false; bool _hasHgemm = false; bool _hasHgemmBatch = false; @@ -404,7 +402,7 @@ namespace sd { CusolverDnDgesvd cusolverDnDgesvd; public: - static BlasHelper* getInstance(); + static BlasHelper& getInstance(); void initializeFunctions(Nd4jPointer *functions); void initializeDeviceFunctions(Nd4jPointer *functions); diff --git a/libnd4j/include/helpers/ConstantHelper.h b/libnd4j/include/helpers/ConstantHelper.h index 3e5681fb6..7d4446d34 100644 --- a/libnd4j/include/helpers/ConstantHelper.h +++ b/libnd4j/include/helpers/ConstantHelper.h @@ -35,7 +35,6 @@ namespace sd { class ND4J_EXPORT ConstantHelper { private: - static ConstantHelper* _INSTANCE; ConstantHelper(); std::vector> _cache; @@ -48,9 +47,9 @@ namespace sd { std::vector _counters; public: - ~ConstantHelper() = default; + ~ConstantHelper(); - static ConstantHelper* getInstance(); + static ConstantHelper& getInstance(); static int getCurrentDevice(); static int getNumberOfDevices(); void* replicatePointer(void *src, size_t numBytes, memory::Workspace *workspace = nullptr); diff --git a/libnd4j/include/helpers/ConstantShapeHelper.h b/libnd4j/include/helpers/ConstantShapeHelper.h index 73281c507..25440e05c 100644 --- a/libnd4j/include/helpers/ConstantShapeHelper.h +++ b/libnd4j/include/helpers/ConstantShapeHelper.h @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include @@ -35,24 +35,22 @@ namespace sd { class ND4J_EXPORT ConstantShapeHelper { private: - static ConstantShapeHelper *_INSTANCE; - std::mutex _mutex; - std::vector> _cache; + std::vector> _cache; ConstantShapeHelper(); public: ~ConstantShapeHelper() = default; - static ConstantShapeHelper* getInstance(); + static ConstantShapeHelper & getInstance(); - ConstantDataBuffer bufferForShapeInfo(sd::DataType dataType, char order, const std::vector &shape); - ConstantDataBuffer bufferForShapeInfo(const ShapeDescriptor &descriptor); - ConstantDataBuffer bufferForShapeInfo(const Nd4jLong *shapeInfo); - ConstantDataBuffer bufferForShapeInfo(sd::DataType dataType, char order, int rank, const Nd4jLong* shape); - ConstantDataBuffer createShapeInfoWithUnitiesForBroadcast(const Nd4jLong* maxShapeInfo, const Nd4jLong* minShapeInfo, sd::memory::Workspace* workspace = nullptr, const std::vector &dimensions = {}); + ConstantShapeBuffer& bufferForShapeInfo(sd::DataType dataType, char order, const std::vector &shape); + ConstantShapeBuffer& bufferForShapeInfo(const ShapeDescriptor &descriptor); + ConstantShapeBuffer& bufferForShapeInfo(const Nd4jLong *shapeInfo); + ConstantShapeBuffer& bufferForShapeInfo(sd::DataType dataType, char order, int rank, const Nd4jLong* shape); + ConstantShapeBuffer& createShapeInfoWithUnitiesForBroadcast(const Nd4jLong* maxShapeInfo, const Nd4jLong* minShapeInfo, sd::memory::Workspace* workspace = nullptr, const std::vector &dimensions = {}); const Nd4jLong* emptyShapeInfo(sd::DataType dataType); diff --git a/libnd4j/include/helpers/ConstantTadHelper.h b/libnd4j/include/helpers/ConstantTadHelper.h index 80efaa86f..10bdd108d 100644 --- a/libnd4j/include/helpers/ConstantTadHelper.h +++ b/libnd4j/include/helpers/ConstantTadHelper.h @@ -35,8 +35,6 @@ namespace sd { class ND4J_EXPORT ConstantTadHelper { private: - static ConstantTadHelper *_INSTANCE; - std::mutex _mutex; std::vector> _cache; @@ -44,7 +42,7 @@ namespace sd { public: ~ConstantTadHelper() = default; - static ConstantTadHelper* getInstance(); + static ConstantTadHelper & getInstance(); /** * These methods calculate Tensor-Along-Dimension(s) shape and offsets diff --git a/libnd4j/include/helpers/DebugHelper.h b/libnd4j/include/helpers/DebugHelper.h index b0387dd8c..10bb1dc90 100644 --- a/libnd4j/include/helpers/DebugHelper.h +++ b/libnd4j/include/helpers/DebugHelper.h @@ -44,7 +44,7 @@ namespace sd { // cuda-specific debug functions #ifdef __CUDACC__ static FORCEINLINE void checkErrorCode(cudaStream_t *stream, int opNum = 0) { - if (Environment::getInstance()->isDebug()) { + if (Environment::getInstance().isDebug()) { cudaError_t res = cudaStreamSynchronize(*stream); if (res != 0) { diff --git a/libnd4j/include/helpers/LoopKind.h b/libnd4j/include/helpers/LoopKind.h index e3ca932b3..4efbea43a 100644 --- a/libnd4j/include/helpers/LoopKind.h +++ b/libnd4j/include/helpers/LoopKind.h @@ -206,7 +206,7 @@ LoopKind::Kind LoopKind::deduceKindOfLoopTadXZ(const Nd4jLong* xShapeInfo, const const bool tVectorOrC = shape::isCommonVector(tadShapeInfo, temp) || tOrder == 'c'; const bool zVectorOrC = shape::isCommonVector(zShapeInfo, temp) || zOrder == 'c';; - if(shape::length(tadShapeInfo) * shape::length(zShapeInfo) <= Environment::getInstance()->elementwiseThreshold() && xEws == 1 && xOrder == 'c' && xRank == 2 && + if(shape::length(tadShapeInfo) * shape::length(zShapeInfo) <= Environment::getInstance().elementwiseThreshold() && xEws == 1 && xOrder == 'c' && xRank == 2 && tEws > 1 && zEws == 1 && (allC || (tVectorOrC && zVectorOrC))) return SMALLARR2DX; if(tEws == 1 && zEws == 1 && (allC || (tVectorOrC && zVectorOrC))) diff --git a/libnd4j/include/helpers/Loops.h b/libnd4j/include/helpers/Loops.h index f18bcc63d..9bf3daede 100644 --- a/libnd4j/include/helpers/Loops.h +++ b/libnd4j/include/helpers/Loops.h @@ -702,21 +702,21 @@ namespace sd { std::vector zeroOffsets; if (xLen == yLen) { - tadPackX = sd::ConstantTadHelper::getInstance()->tadForDimensions(xShapeInfo, dims, dimsLen); - tadPackY = sd::ConstantTadHelper::getInstance()->tadForDimensions(yShapeInfo, dims, dimsLen); + tadPackX = sd::ConstantTadHelper::getInstance().tadForDimensions(xShapeInfo, dims, dimsLen); + tadPackY = sd::ConstantTadHelper::getInstance().tadForDimensions(yShapeInfo, dims, dimsLen); xTadShapeInfo = tadPackX.primaryShapeInfo(); yTadShapeInfo = tadPackY.primaryShapeInfo(); xTadOffsets = tadPackX.primaryOffsets(); yTadOffsets = tadPackY.primaryOffsets(); } else if (yLen > xLen) { - tadPackY = sd::ConstantTadHelper::getInstance()->tadForDimensions(yShapeInfo, dims, dimsLen); + tadPackY = sd::ConstantTadHelper::getInstance().tadForDimensions(yShapeInfo, dims, dimsLen); xTadShapeInfo = xShapeInfo; yTadShapeInfo = tadPackY.primaryShapeInfo(); yTadOffsets = tadPackY.primaryOffsets(); } else { - tadPackX = sd::ConstantTadHelper::getInstance()->tadForDimensions(xShapeInfo, dims, dimsLen); + tadPackX = sd::ConstantTadHelper::getInstance().tadForDimensions(xShapeInfo, dims, dimsLen); yTadShapeInfo = yShapeInfo; xTadShapeInfo = tadPackX.primaryShapeInfo(); xTadOffsets = tadPackX.primaryOffsets(); diff --git a/libnd4j/include/helpers/OpTracker.h b/libnd4j/include/helpers/OpTracker.h index 122f4f32b..dfccf5e5d 100644 --- a/libnd4j/include/helpers/OpTracker.h +++ b/libnd4j/include/helpers/OpTracker.h @@ -32,8 +32,6 @@ namespace sd { class ND4J_EXPORT OpTracker { private: - static OpTracker* _INSTANCE; - std::string _export; int _operations = 0; @@ -45,7 +43,7 @@ namespace sd { template std::string local_to_string(T value); public: - static OpTracker* getInstance(); + static OpTracker& getInstance(); int totalGroups(); int totalOperations(); diff --git a/libnd4j/include/helpers/benchmark/BroadcastBenchmark.h b/libnd4j/include/helpers/benchmark/BroadcastBenchmark.h index 3a043be59..8c61bda23 100644 --- a/libnd4j/include/helpers/benchmark/BroadcastBenchmark.h +++ b/libnd4j/include/helpers/benchmark/BroadcastBenchmark.h @@ -69,14 +69,14 @@ namespace sd { void executeOnce() override { PointersManager manager(LaunchContext::defaultContext(), "BroadcastBM"); - auto packX = ConstantTadHelper::getInstance()->tadForDimensions(_x->shapeInfo(), _axis); - auto packZ = ConstantTadHelper::getInstance()->tadForDimensions(_z->shapeInfo(), _axis); + auto packX = ConstantTadHelper::getInstance().tadForDimensions(_x->shapeInfo(), _axis); + auto packZ = ConstantTadHelper::getInstance().tadForDimensions(_z->shapeInfo(), _axis); - auto tadOnlyShapeInfo = Environment::getInstance()->isCPU() ? packX.primaryShapeInfo() : packX.specialShapeInfo(); - auto tadOffsets = Environment::getInstance()->isCPU() ? packX.primaryOffsets() : packX.specialOffsets(); + auto tadOnlyShapeInfo = Environment::getInstance().isCPU() ? packX.primaryShapeInfo() : packX.specialShapeInfo(); + auto tadOffsets = Environment::getInstance().isCPU() ? packX.primaryOffsets() : packX.specialOffsets(); - auto tadOnlyShapeInfoZ = Environment::getInstance()->isCPU() ? packZ.primaryShapeInfo() : packZ.specialShapeInfo(); - auto tadOffsetsZ = Environment::getInstance()->isCPU() ? packZ.primaryOffsets() : packZ.specialOffsets(); + auto tadOnlyShapeInfoZ = Environment::getInstance().isCPU() ? packZ.primaryShapeInfo() : packZ.specialShapeInfo(); + auto tadOffsetsZ = Environment::getInstance().isCPU() ? packZ.primaryOffsets() : packZ.specialOffsets(); NativeOpExecutioner::execBroadcast(LaunchContext::defaultContext(), _opNum, _x->buffer(), _x->shapeInfo(), _x->specialBuffer(), _x->specialShapeInfo(), _y->buffer(), _y->shapeInfo(), _y->specialBuffer(), _y->specialShapeInfo(), _z->buffer(), _z->shapeInfo(), _z->specialBuffer(), _z->specialShapeInfo(), nullptr, _axis.size(), /*Nd4jLong **/ tadOnlyShapeInfo, /*Nd4jLong */ tadOffsets, /*Nd4jLong */ tadOnlyShapeInfoZ, /*Nd4jLong */ tadOffsetsZ); diff --git a/libnd4j/include/helpers/benchmark/DeclarableBenchmark.h b/libnd4j/include/helpers/benchmark/DeclarableBenchmark.h index f9347eb05..58c018a5b 100644 --- a/libnd4j/include/helpers/benchmark/DeclarableBenchmark.h +++ b/libnd4j/include/helpers/benchmark/DeclarableBenchmark.h @@ -36,7 +36,7 @@ namespace sd { sd::graph::Context *_context = nullptr; public: DeclarableBenchmark(sd::ops::DeclarableOp &op, std::string name = 0) : OpBenchmark() { - _op = &op; //ops::OpRegistrator::getInstance()->getOperation(op.getOpHash()); + _op = &op; //ops::OpRegistrator::getInstance().getOperation(op.getOpHash()); _testName = name; } diff --git a/libnd4j/include/helpers/benchmark/ReductionBenchmark.h b/libnd4j/include/helpers/benchmark/ReductionBenchmark.h index a1dc0126f..d87c20d3c 100644 --- a/libnd4j/include/helpers/benchmark/ReductionBenchmark.h +++ b/libnd4j/include/helpers/benchmark/ReductionBenchmark.h @@ -88,10 +88,10 @@ namespace sd { else NativeOpExecutioner::execReduceSameScalar(LaunchContext::defaultContext(), _opNum, _x->buffer(), _x->shapeInfo(), _x->specialBuffer(), _x->specialShapeInfo(), nullptr, _z->buffer(), _z->shapeInfo(), _z->specialBuffer(), _z->specialShapeInfo()); else { - auto pack = ConstantTadHelper::getInstance()->tadForDimensions(_x->shapeInfo(), _axis); + auto pack = ConstantTadHelper::getInstance().tadForDimensions(_x->shapeInfo(), _axis); - auto tadOnlyShapeInfo = Environment::getInstance()->isCPU() ? pack.primaryShapeInfo() : pack.specialShapeInfo(); - auto tadOffsets = Environment::getInstance()->isCPU() ? pack.primaryOffsets() : pack.specialOffsets(); + auto tadOnlyShapeInfo = Environment::getInstance().isCPU() ? pack.primaryShapeInfo() : pack.specialShapeInfo(); + auto tadOffsets = Environment::getInstance().isCPU() ? pack.primaryOffsets() : pack.specialOffsets(); if (_opType == 0) NativeOpExecutioner::execReduceFloat(LaunchContext::defaultContext(), _opNum, _x->buffer(), _x->shapeInfo(), _x->specialBuffer(), _x->specialShapeInfo(), nullptr, _z->buffer(), _z->shapeInfo(), _z->specialBuffer(), _z->specialShapeInfo(), nullptr, _axis.size(), tadOnlyShapeInfo, tadOffsets); diff --git a/libnd4j/include/helpers/cpu/ConstantHelper.cpp b/libnd4j/include/helpers/cpu/ConstantHelper.cpp index 10b8a52c3..be6eff65c 100644 --- a/libnd4j/include/helpers/cpu/ConstantHelper.cpp +++ b/libnd4j/include/helpers/cpu/ConstantHelper.cpp @@ -27,6 +27,7 @@ #include #include #include +#include namespace sd { @@ -42,11 +43,17 @@ namespace sd { } } - ConstantHelper* ConstantHelper::getInstance() { - if (!_INSTANCE) - _INSTANCE = new sd::ConstantHelper(); +ConstantHelper::~ConstantHelper() { + for (const auto &v:_cache) { + for (const auto &c:v) { + delete c.second; + } + } +} - return _INSTANCE; +ConstantHelper& ConstantHelper::getInstance() { + static ConstantHelper instance; + return instance; } void* ConstantHelper::replicatePointer(void *src, size_t numBytes, memory::Workspace *workspace) { @@ -95,17 +102,17 @@ namespace sd { result = holder->getConstantDataBuffer(dataType); else { auto size = descriptor.length() * DataTypeUtils::sizeOf(dataType); - auto cbuff = new int8_t[size]; + auto cbuff = std::make_shared(new int8_t[size], std::make_shared()); _counters[deviceId] += size; // create buffer with this dtype if (descriptor.isFloat()) { - BUILD_DOUBLE_SELECTOR(sd::DataType::DOUBLE, dataType, sd::TypeCast::convertGeneric, (nullptr, const_cast(descriptor.floatValues().data()), descriptor.length(), cbuff), (sd::DataType::DOUBLE, double), LIBND4J_TYPES); + BUILD_DOUBLE_SELECTOR(sd::DataType::DOUBLE, dataType, sd::TypeCast::convertGeneric, (nullptr, const_cast(descriptor.floatValues().data()), descriptor.length(), cbuff->pointer()), (sd::DataType::DOUBLE, double), LIBND4J_TYPES); } else if (descriptor.isInteger()) { - BUILD_DOUBLE_SELECTOR(sd::DataType::INT64, dataType, sd::TypeCast::convertGeneric, (nullptr, const_cast(descriptor.integerValues().data()), descriptor.length(), cbuff), (sd::DataType::INT64, Nd4jLong), LIBND4J_TYPES); + BUILD_DOUBLE_SELECTOR(sd::DataType::INT64, dataType, sd::TypeCast::convertGeneric, (nullptr, const_cast(descriptor.integerValues().data()), descriptor.length(), cbuff->pointer()), (sd::DataType::INT64, Nd4jLong), LIBND4J_TYPES); } - ConstantDataBuffer dataBuffer(cbuff, nullptr, descriptor.length(), DataTypeUtils::sizeOf(dataType)); + ConstantDataBuffer dataBuffer(cbuff, descriptor.length(), dataType); holder->addBuffer(dataBuffer, dataType); result = holder->getConstantDataBuffer(dataType); @@ -122,8 +129,6 @@ namespace sd { else return _counters[deviceId]; } - - sd::ConstantHelper* sd::ConstantHelper::_INSTANCE = 0; } #endif \ No newline at end of file diff --git a/libnd4j/include/helpers/cpu/ConstantShapeHelper.cpp b/libnd4j/include/helpers/cpu/ConstantShapeHelper.cpp index fc8abe8aa..528527f36 100644 --- a/libnd4j/include/helpers/cpu/ConstantShapeHelper.cpp +++ b/libnd4j/include/helpers/cpu/ConstantShapeHelper.cpp @@ -24,51 +24,50 @@ #include #include #include +#include namespace sd { ConstantShapeHelper::ConstantShapeHelper() { _cache.resize(32); for (int e = 0; e < 32; e++) { - MAP_IMPL cache; + MAP_IMPL cache; _cache[e] = cache; } } - ConstantShapeHelper* ConstantShapeHelper::getInstance() { - if (!_INSTANCE) - _INSTANCE = new ConstantShapeHelper(); - - return _INSTANCE; + ConstantShapeHelper& ConstantShapeHelper::getInstance() { + static ConstantShapeHelper instance; + return instance; } - ConstantDataBuffer ConstantShapeHelper::bufferForShapeInfo(sd::DataType dataType, char order, const std::vector &shape) { +ConstantShapeBuffer& ConstantShapeHelper::bufferForShapeInfo(sd::DataType dataType, char order, const std::vector &shape) { ShapeDescriptor descriptor(dataType, order, shape); return bufferForShapeInfo(descriptor); } - ConstantDataBuffer ConstantShapeHelper::bufferForShapeInfo(const sd::DataType dataType, const char order, const int rank, const Nd4jLong* shape) { +ConstantShapeBuffer& ConstantShapeHelper::bufferForShapeInfo(const sd::DataType dataType, const char order, const int rank, const Nd4jLong* shape) { ShapeDescriptor descriptor(dataType, order, shape, rank); return bufferForShapeInfo(descriptor); } - ConstantDataBuffer ConstantShapeHelper::bufferForShapeInfo(const ShapeDescriptor &descriptor) { - int deviceId = 0; +ConstantShapeBuffer& ConstantShapeHelper::bufferForShapeInfo(const ShapeDescriptor &descriptor) { + int deviceId = 0; - std::lock_guard lock(_mutex); + std::lock_guard lock(_mutex); - if (_cache[deviceId].count(descriptor) == 0) { - auto hPtr = descriptor.toShapeInfo(); - ConstantDataBuffer buffer(hPtr, nullptr, shape::shapeInfoLength(hPtr)*sizeof(Nd4jLong), DataType::INT64); - ShapeDescriptor descriptor1(descriptor); - _cache[deviceId][descriptor1] = buffer; - return _cache[deviceId][descriptor1]; - } else { - return _cache[deviceId].at(descriptor); - } - } + if (_cache[deviceId].count(descriptor) == 0) { + auto hPtr = std::make_shared(descriptor.toShapeInfo(), std::make_shared()); + ConstantShapeBuffer buffer(hPtr); + ShapeDescriptor descriptor1(descriptor); + _cache[deviceId][descriptor1] = buffer; + return _cache[deviceId][descriptor1]; + } else { + return _cache[deviceId].at(descriptor); + } +} - ConstantDataBuffer ConstantShapeHelper::bufferForShapeInfo(const Nd4jLong *shapeInfo) { +ConstantShapeBuffer& ConstantShapeHelper::bufferForShapeInfo(const Nd4jLong *shapeInfo) { ShapeDescriptor descriptor(shapeInfo); return bufferForShapeInfo(descriptor); } @@ -83,7 +82,7 @@ namespace sd { const Nd4jLong* ConstantShapeHelper::createShapeInfo(const sd::DataType dataType, const char order, const int rank, const Nd4jLong* shape) { ShapeDescriptor descriptor(dataType, order, shape, rank); - return bufferForShapeInfo(descriptor).primaryAsT(); + return bufferForShapeInfo(descriptor).primary(); } const Nd4jLong* ConstantShapeHelper::createShapeInfo(const sd::DataType dataType, const Nd4jLong* shapeInfo) { @@ -92,26 +91,26 @@ namespace sd { const Nd4jLong* ConstantShapeHelper::emptyShapeInfo(const sd::DataType dataType) { auto descriptor = ShapeDescriptor::emptyDescriptor(dataType); - return bufferForShapeInfo(descriptor).primaryAsT(); + return bufferForShapeInfo(descriptor).primary(); } const Nd4jLong* ConstantShapeHelper::scalarShapeInfo(const sd::DataType dataType) { auto descriptor = ShapeDescriptor::scalarDescriptor(dataType); - return bufferForShapeInfo(descriptor).primaryAsT(); + return bufferForShapeInfo(descriptor).primary(); } const Nd4jLong* ConstantShapeHelper::vectorShapeInfo(const Nd4jLong length, const sd::DataType dataType) { auto descriptor = ShapeDescriptor::vectorDescriptor(length, dataType); - return bufferForShapeInfo(descriptor).primaryAsT(); + return bufferForShapeInfo(descriptor).primary(); } const Nd4jLong* ConstantShapeHelper::createShapeInfo(const sd::DataType dataType, const char order, const std::vector &shape) { ShapeDescriptor descriptor(dataType, order, shape); - return bufferForShapeInfo(descriptor).primaryAsT(); + return bufferForShapeInfo(descriptor).primary(); } const Nd4jLong* ConstantShapeHelper::createShapeInfo(const ShapeDescriptor &descriptor) { - return bufferForShapeInfo(descriptor).primaryAsT(); + return bufferForShapeInfo(descriptor).primary(); } const Nd4jLong* ConstantShapeHelper::createFromExisting(Nd4jLong *shapeInfo, bool destroyOriginal) { @@ -135,7 +134,7 @@ namespace sd { //////////////////////////////////////////////////////////////////////// -ConstantDataBuffer ConstantShapeHelper::createShapeInfoWithUnitiesForBroadcast(const Nd4jLong* maxShapeInfo, const Nd4jLong* minShapeInfo, sd::memory::Workspace* workspace, const std::vector &dimensions) { +ConstantShapeBuffer& ConstantShapeHelper::createShapeInfoWithUnitiesForBroadcast(const Nd4jLong* maxShapeInfo, const Nd4jLong* minShapeInfo, sd::memory::Workspace* workspace, const std::vector &dimensions) { Nd4jLong* newShapeInfo = nullptr; ALLOCATE(newShapeInfo, workspace, shape::shapeInfoLength(shape::rank(maxShapeInfo)), Nd4jLong); @@ -185,10 +184,6 @@ ConstantDataBuffer ConstantShapeHelper::createShapeInfoWithUnitiesForBroadcast(c return bufferForShapeInfo(descriptor); } - - -sd::ConstantShapeHelper* sd::ConstantShapeHelper::_INSTANCE = 0; - -} +} // namespace sd #endif \ No newline at end of file diff --git a/libnd4j/include/helpers/cpu/ConstantTadHelper.cpp b/libnd4j/include/helpers/cpu/ConstantTadHelper.cpp index ea32db7e6..9f859ee3e 100644 --- a/libnd4j/include/helpers/cpu/ConstantTadHelper.cpp +++ b/libnd4j/include/helpers/cpu/ConstantTadHelper.cpp @@ -21,6 +21,8 @@ #include "../ConstantTadHelper.h" #include #include +#include +#include #ifndef __CUDABLAS__ @@ -32,11 +34,9 @@ namespace sd { _cache.emplace_back(pack); } - ConstantTadHelper* ConstantTadHelper::getInstance() { - if (!_INSTANCE) - _INSTANCE = new ConstantTadHelper(); - - return _INSTANCE; + ConstantTadHelper& ConstantTadHelper::getInstance() { + static ConstantTadHelper instance; + return instance; } TadPack ConstantTadHelper::tadForDimensions(const Nd4jLong *originalShape, int dimension, const bool keepUnitiesInShape) { @@ -60,60 +60,31 @@ namespace sd { TadPack ConstantTadHelper::tadForDimensions(TadDescriptor &descriptor) { const int deviceId = 0; - _mutex.lock(); + std::lock_guard lock(_mutex); if (_cache[deviceId].count(descriptor) == 0) { - + // if there's no TadPack matching this descriptor - create one const auto shapeInfo = descriptor.originalShape().toShapeInfo(); const int rank = shape::rank(shapeInfo); const std::vector dimsToExclude = ShapeUtils::evalDimsToExclude(rank, descriptor.axis()); const Nd4jLong numOfSubArrs = ShapeUtils::getNumOfSubArrs(shapeInfo, dimsToExclude); const int subArrRank = (rank == dimsToExclude.size() || descriptor.areUnitiesinShape()) ? rank : rank - dimsToExclude.size(); - auto sPtr = new Nd4jLong[shape::shapeInfoLength(subArrRank)]; // shape of sub-arrays (same for all for them) - auto oPtr = new Nd4jLong[numOfSubArrs]; + auto sPtr = std::make_shared(new Nd4jLong[shape::shapeInfoLength(subArrRank)], std::make_shared()); // shape of sub-arrays (same for all for them) + auto oPtr = std::make_shared(new Nd4jLong[numOfSubArrs], std::make_shared()); if (numOfSubArrs > 0) - shape::calcSubArrsShapeInfoAndOffsets(shapeInfo, numOfSubArrs, dimsToExclude.size(), dimsToExclude.data(), sPtr, oPtr, descriptor.areUnitiesinShape()); - - - ConstantDataBuffer shapesBuffer(sPtr, nullptr, shape::shapeInfoLength(subArrRank)*sizeof(Nd4jLong), DataType::INT64); - ConstantDataBuffer offsetsBuffer(oPtr, nullptr, numOfSubArrs*sizeof(Nd4jLong), DataType::INT64); - TadPack t(shapesBuffer, offsetsBuffer, numOfSubArrs); - - - - // auto shapeInfo = descriptor.originalShape().toShapeInfo(); - // shape::TAD tad; - // tad.init(shapeInfo, descriptor.axis().data(), descriptor.axis().size()); - // tad.createTadOnlyShapeInfo(); - // tad.createOffsets(); - - // auto sPtr = new Nd4jLong[shape::shapeInfoLength(tad.tadOnlyShapeInfo)]; - // auto oPtr = new Nd4jLong[tad.numTads]; - - // memcpy(sPtr, tad.tadOnlyShapeInfo, shape::shapeInfoByteLength(tad.tadOnlyShapeInfo)); - // memcpy(oPtr, tad.tadOffsets, tad.numTads * sizeof(Nd4jLong)); - - // TadPack t(shapesBuffer, offsetsBuffer, tad.numTads); - + shape::calcSubArrsShapeInfoAndOffsets(shapeInfo, numOfSubArrs, dimsToExclude.size(), dimsToExclude.data(), sPtr->pointerAsT(), oPtr->pointerAsT(), descriptor.areUnitiesinShape()); + ConstantShapeBuffer shapeBuffer(sPtr); + ConstantOffsetsBuffer offsetsBuffer(oPtr); + TadPack t(shapeBuffer, offsetsBuffer, numOfSubArrs); _cache[deviceId][descriptor] = t; - TadPack &r = _cache[deviceId][descriptor]; - _mutex.unlock(); - delete[] shapeInfo; - - return r; - } else { - TadPack r = _cache[deviceId][descriptor]; - _mutex.unlock(); - - return r; } - } - sd::ConstantTadHelper* sd::ConstantTadHelper::_INSTANCE = 0; + return _cache[deviceId][descriptor]; + } } #endif \ No newline at end of file diff --git a/libnd4j/include/helpers/cpu/MmulHelper.cpp b/libnd4j/include/helpers/cpu/MmulHelper.cpp index 26a6643c3..437eebe1d 100644 --- a/libnd4j/include/helpers/cpu/MmulHelper.cpp +++ b/libnd4j/include/helpers/cpu/MmulHelper.cpp @@ -162,7 +162,7 @@ static void usualDot(const Nd4jLong length, const double alpha, const void* vX, const bool betaPersent = beta; T3 sum = 0; - PRAGMA_OMP_PARALLEL_FOR_ARGS(OMP_IF(length > Environment::getInstance()->elementwiseThreshold()) schedule(guided) reduction(OMP_SUMT:sum)) + PRAGMA_OMP_PARALLEL_FOR_ARGS(OMP_IF(length > Environment::getInstance().elementwiseThreshold()) schedule(guided) reduction(OMP_SUMT:sum)) for(Nd4jLong i = 0; i < length; ++i) sum += X[i * incx] * Y[i * incy]; @@ -210,7 +210,7 @@ NDArray* MmulHelper::mmulMxM(const NDArray* A, const NDArray* B, NDArray* C, con const auto cType = C->dataType(); const bool AB(aType == bType), AC(aType == cType), ABC(AB && AC); - const bool hasGemm = BlasHelper::getInstance()->hasGEMM(aType); + const bool hasGemm = BlasHelper::getInstance().hasGEMM(aType); const bool typeDouble = hasGemm && ABC && aType == DataType::DOUBLE; const bool typeFloat = hasGemm && ABC && aType == DataType::FLOAT32; @@ -261,10 +261,10 @@ NDArray* MmulHelper::mmulMxM(const NDArray* A, const NDArray* B, NDArray* C, con const int ldc = (cMcont && cNcont) ? M : !cMcont ? pC->strideAt(0) : pC->strideAt(1); if(typeFloat) { - BlasHelper::getInstance()->sgemm()(blasOrder, transAblas, transBblas, M, N, K, (float) alpha, pA->bufferAsT(), lda, pB->bufferAsT(), ldb, (float) beta, pC->bufferAsT(), ldc); + BlasHelper::getInstance().sgemm()(blasOrder, transAblas, transBblas, M, N, K, (float) alpha, pA->bufferAsT(), lda, pB->bufferAsT(), ldb, (float) beta, pC->bufferAsT(), ldc); } else if(typeDouble) { - BlasHelper::getInstance()->dgemm()(blasOrder, transAblas, transBblas, M, N, K, (double) alpha, pA->bufferAsT(), lda, pB->bufferAsT(), ldb, (double) beta, pC->bufferAsT(), ldc); + BlasHelper::getInstance().dgemm()(blasOrder, transAblas, transBblas, M, N, K, (double) alpha, pA->bufferAsT(), lda, pB->bufferAsT(), ldb, (double) beta, pC->bufferAsT(), ldc); } if(pC != C) { @@ -321,7 +321,7 @@ NDArray* MmulHelper::mmulMxV(const NDArray* A, const NDArray* X, sd::NDArray* Y, const auto yType = Y->dataType(); const bool AX(aType == xType), AY(aType == yType), AXY(AX && AY); - const bool hasGemv = BlasHelper::getInstance()->hasGEMV(aType); + const bool hasGemv = BlasHelper::getInstance().hasGEMV(aType); const bool typeDouble = hasGemv && AXY && aType == DataType::DOUBLE; const bool typeFloat = hasGemv && AXY && aType == DataType::FLOAT32; @@ -347,10 +347,10 @@ NDArray* MmulHelper::mmulMxV(const NDArray* A, const NDArray* X, sd::NDArray* Y, // choose appropriate cuda gemm api depending on data types if(typeDouble) { - BlasHelper::getInstance()->dgemv()(blasOrder, CblasNoTrans, M, N, alpha, (double*)pA->buffer(), lda, (double*)X->buffer(), incx, beta, (double*)Y->buffer(), incy); + BlasHelper::getInstance().dgemv()(blasOrder, CblasNoTrans, M, N, alpha, (double*)pA->buffer(), lda, (double*)X->buffer(), incx, beta, (double*)Y->buffer(), incy); } else if(typeFloat) { - BlasHelper::getInstance()->sgemv()(blasOrder, CblasNoTrans, M, N, (float)alpha, (float*)pA->buffer(), lda, (float*)X->buffer(), incx, (float)beta, (float*)Y->buffer(), incy); + BlasHelper::getInstance().sgemv()(blasOrder, CblasNoTrans, M, N, (float)alpha, (float*)pA->buffer(), lda, (float*)X->buffer(), incx, (float)beta, (float*)Y->buffer(), incy); } if(pA != A) @@ -617,7 +617,7 @@ static void usualGemm(const char cOrder, const bool transA, const bool transB, c const bool flagA = (flagC && transA) || (!flagC && !transA); const bool flagB = (flagC && transB) || (!flagC && !transB); - // PRAGMA_OMP_PARALLEL_FOR_ARGS(OMP_IF(M*N > Environment::getInstance()->elementwiseThreshold()) schedule(guided)) + // PRAGMA_OMP_PARALLEL_FOR_ARGS(OMP_IF(M*N > Environment::getInstance().elementwiseThreshold()) schedule(guided)) // for(uint row = 0; row < M; ++row) { // T3* c = flagC ? (C + row) : (C + row * ldc); diff --git a/libnd4j/include/helpers/cpu/cublasHelper.cpp b/libnd4j/include/helpers/cpu/cublasHelper.cpp index f6f718702..4b17e601d 100644 --- a/libnd4j/include/helpers/cpu/cublasHelper.cpp +++ b/libnd4j/include/helpers/cpu/cublasHelper.cpp @@ -37,11 +37,9 @@ namespace sd { } - CublasHelper* CublasHelper::getInstance() { - if (!_INSTANCE) - _INSTANCE = new sd::CublasHelper(); - - return _INSTANCE; + CublasHelper& CublasHelper::getInstance() { + static CublasHelper instance; + return instance; } void* CublasHelper::handle() { @@ -55,7 +53,4 @@ namespace sd { void* CublasHelper::handle(int deviceId) { return nullptr; } - - - sd::CublasHelper* sd::CublasHelper::_INSTANCE = 0; } \ No newline at end of file diff --git a/libnd4j/include/helpers/cublasHelper.h b/libnd4j/include/helpers/cublasHelper.h index 0300f3698..8ebdc66a7 100644 --- a/libnd4j/include/helpers/cublasHelper.h +++ b/libnd4j/include/helpers/cublasHelper.h @@ -29,7 +29,6 @@ namespace sd { class ND4J_EXPORT CublasHelper { private: - static CublasHelper *_INSTANCE; static std::mutex _mutex; std::vector _cache; @@ -37,9 +36,9 @@ namespace sd { std::vector _cudnn; CublasHelper(); - ~CublasHelper(); public: - static CublasHelper* getInstance(); + ~CublasHelper(); + static CublasHelper& getInstance(); void* cudnn(); void* solver(); diff --git a/libnd4j/include/helpers/cuda/ConstantHelper.cu b/libnd4j/include/helpers/cuda/ConstantHelper.cu index 62d932489..7eb9273e5 100644 --- a/libnd4j/include/helpers/cuda/ConstantHelper.cu +++ b/libnd4j/include/helpers/cuda/ConstantHelper.cu @@ -29,6 +29,7 @@ #include #include #include +#include #define CONSTANT_LIMIT 49152 @@ -84,11 +85,17 @@ namespace sd { throw cuda_exception::build("Final cudaSetDevice failed", res); } - ConstantHelper* ConstantHelper::getInstance() { - if (!_INSTANCE) - _INSTANCE = new sd::ConstantHelper(); +ConstantHelper::~ConstantHelper() { + for (const auto &v:_cache) { + for (const auto &c:v) { + delete c.second; + } + } +} - return _INSTANCE; + ConstantHelper& ConstantHelper::getInstance() { + static ConstantHelper instance; + return instance; } void* ConstantHelper::replicatePointer(void *src, size_t numBytes, memory::Workspace *workspace) { @@ -156,19 +163,21 @@ namespace sd { result = holder->getConstantDataBuffer(dataType); } else { auto numBytes = descriptor.length() * DataTypeUtils::sizeOf(dataType); - auto cbuff = new int8_t[numBytes]; + auto cbuff = std::make_shared(new int8_t[numBytes], std::make_shared()); _counters[deviceId] += numBytes; // create buffer with this dtype if (descriptor.isFloat()) { - BUILD_DOUBLE_SELECTOR(sd::DataType::DOUBLE, dataType, sd::SpecialTypeConverter::convertGeneric, (nullptr, const_cast(descriptor.floatValues().data()), descriptor.length(), cbuff), (sd::DataType::DOUBLE, double), LIBND4J_TYPES); + BUILD_DOUBLE_SELECTOR(sd::DataType::DOUBLE, dataType, sd::SpecialTypeConverter::convertGeneric, (nullptr, const_cast(descriptor.floatValues().data()), descriptor.length(), cbuff->pointer()), (sd::DataType::DOUBLE, double), LIBND4J_TYPES); } else if (descriptor.isInteger()) { - BUILD_DOUBLE_SELECTOR(sd::DataType::INT64, dataType, sd::SpecialTypeConverter::convertGeneric, (nullptr, const_cast(descriptor.integerValues().data()), descriptor.length(), cbuff), (sd::DataType::INT64, Nd4jLong), LIBND4J_TYPES); + BUILD_DOUBLE_SELECTOR(sd::DataType::INT64, dataType, sd::SpecialTypeConverter::convertGeneric, (nullptr, const_cast(descriptor.integerValues().data()), descriptor.length(), cbuff->pointer()), (sd::DataType::INT64, Nd4jLong), LIBND4J_TYPES); } - auto dbuff = replicatePointer(cbuff, descriptor.length() * DataTypeUtils::sizeOf(dataType)); + // we don't have deallocator here. + // TODO: we probably want to make use deallocator here, if we're not using constant memory + auto dbuff = std::make_shared(replicatePointer(cbuff->pointer(), descriptor.length() * DataTypeUtils::sizeOf(dataType))); - ConstantDataBuffer dataBuffer(cbuff, dbuff, descriptor.length(), DataTypeUtils::sizeOf(dataType)); + ConstantDataBuffer dataBuffer(cbuff, dbuff, descriptor.length(), dataType); holder->addBuffer(dataBuffer, dataType); result = holder->getConstantDataBuffer(dataType); @@ -184,6 +193,4 @@ namespace sd { else return _counters[deviceId]; } - - sd::ConstantHelper* sd::ConstantHelper::_INSTANCE = 0; } \ No newline at end of file diff --git a/libnd4j/include/helpers/cuda/ConstantShapeHelper.cu b/libnd4j/include/helpers/cuda/ConstantShapeHelper.cu index 2026dbb04..35ba60ca9 100644 --- a/libnd4j/include/helpers/cuda/ConstantShapeHelper.cu +++ b/libnd4j/include/helpers/cuda/ConstantShapeHelper.cu @@ -24,6 +24,8 @@ #include #include #include +#include +#include namespace sd { @@ -32,46 +34,44 @@ namespace sd { _cache.resize(numDevices); for (int e = 0; e < numDevices; e++) { - MAP_IMPL cache; + MAP_IMPL cache; _cache[e] = cache; } } - ConstantShapeHelper* ConstantShapeHelper::getInstance() { - if (!_INSTANCE) - _INSTANCE = new ConstantShapeHelper(); - - return _INSTANCE; + ConstantShapeHelper& ConstantShapeHelper::getInstance() { + static ConstantShapeHelper instance; + return instance; } - ConstantDataBuffer ConstantShapeHelper::bufferForShapeInfo(sd::DataType dataType, char order, const std::vector &shape) { + ConstantShapeBuffer& ConstantShapeHelper::bufferForShapeInfo(sd::DataType dataType, char order, const std::vector &shape) { ShapeDescriptor descriptor(dataType, order, shape); return bufferForShapeInfo(descriptor); } - ConstantDataBuffer ConstantShapeHelper::bufferForShapeInfo(const sd::DataType dataType, const char order, const int rank, const Nd4jLong* shape) { +ConstantShapeBuffer& ConstantShapeHelper::bufferForShapeInfo(const sd::DataType dataType, const char order, const int rank, const Nd4jLong* shape) { ShapeDescriptor descriptor(dataType, order, shape, rank); return bufferForShapeInfo(descriptor); } - ConstantDataBuffer ConstantShapeHelper::bufferForShapeInfo(const ShapeDescriptor &descriptor) { +ConstantShapeBuffer& ConstantShapeHelper::bufferForShapeInfo(const ShapeDescriptor &descriptor) { int deviceId = AffinityManager::currentDeviceId(); std::lock_guard lock(_mutex); if (_cache[deviceId].count(descriptor) == 0) { - auto hPtr = descriptor.toShapeInfo(); - auto dPtr = ConstantHelper::getInstance()->replicatePointer(hPtr, shape::shapeInfoByteLength(hPtr)); - ConstantDataBuffer buffer(hPtr, dPtr, shape::shapeInfoLength(hPtr) * sizeof(Nd4jLong), DataType::INT64); - ShapeDescriptor descriptor1(descriptor); - _cache[deviceId][descriptor1] = buffer; - return _cache[deviceId][descriptor1]; + auto hPtr = std::make_shared(descriptor.toShapeInfo(), std::make_shared()); + auto dPtr = std::make_shared(ConstantHelper::getInstance().replicatePointer(hPtr->pointer(), shape::shapeInfoByteLength(hPtr->pointerAsT())), std::make_shared()); + ConstantShapeBuffer buffer(hPtr, dPtr); + ShapeDescriptor descriptor1(descriptor); + _cache[deviceId][descriptor1] = buffer; + return _cache[deviceId][descriptor1]; } else { - return _cache[deviceId].at(descriptor); + return _cache[deviceId].at(descriptor); } } - ConstantDataBuffer ConstantShapeHelper::bufferForShapeInfo(const Nd4jLong *shapeInfo) { +ConstantShapeBuffer& ConstantShapeHelper::bufferForShapeInfo(const Nd4jLong *shapeInfo) { ShapeDescriptor descriptor(shapeInfo); return bufferForShapeInfo(descriptor); } @@ -85,7 +85,7 @@ namespace sd { Nd4jLong const* ConstantShapeHelper::createShapeInfo(const sd::DataType dataType, const char order, const int rank, const Nd4jLong* shape) { ShapeDescriptor descriptor(dataType, order, shape, rank); - return bufferForShapeInfo(descriptor).primaryAsT(); + return bufferForShapeInfo(descriptor).primary(); } Nd4jLong const* ConstantShapeHelper::createShapeInfo(const sd::DataType dataType, const Nd4jLong* shapeInfo) { @@ -94,26 +94,26 @@ namespace sd { Nd4jLong const* ConstantShapeHelper::emptyShapeInfo(const sd::DataType dataType) { auto descriptor = ShapeDescriptor::emptyDescriptor(dataType); - return bufferForShapeInfo(descriptor).primaryAsT(); + return bufferForShapeInfo(descriptor).primary(); } Nd4jLong const* ConstantShapeHelper::scalarShapeInfo(const sd::DataType dataType) { auto descriptor = ShapeDescriptor::scalarDescriptor(dataType); - return bufferForShapeInfo(descriptor).primaryAsT(); + return bufferForShapeInfo(descriptor).primary(); } Nd4jLong const* ConstantShapeHelper::vectorShapeInfo(const Nd4jLong length, const sd::DataType dataType) { auto descriptor = ShapeDescriptor::vectorDescriptor(length, dataType); - return bufferForShapeInfo(descriptor).primaryAsT(); + return bufferForShapeInfo(descriptor).primary(); } Nd4jLong const* ConstantShapeHelper::createShapeInfo(const sd::DataType dataType, const char order, const std::vector &shape) { ShapeDescriptor descriptor(dataType, order, shape); - return bufferForShapeInfo(descriptor).primaryAsT(); + return bufferForShapeInfo(descriptor).primary(); } Nd4jLong const* ConstantShapeHelper::createShapeInfo(const ShapeDescriptor &descriptor) { - return bufferForShapeInfo(descriptor).primaryAsT(); + return bufferForShapeInfo(descriptor).primary(); } Nd4jLong const* ConstantShapeHelper::createFromExisting(Nd4jLong *shapeInfo, bool destroyOriginal) { @@ -136,7 +136,7 @@ namespace sd { } //////////////////////////////////////////////////////////////////////// -ConstantDataBuffer ConstantShapeHelper::createShapeInfoWithUnitiesForBroadcast(const Nd4jLong* maxShapeInfo, const Nd4jLong* minShapeInfo, sd::memory::Workspace* workspace, const std::vector& dimensions) { +ConstantShapeBuffer& ConstantShapeHelper::createShapeInfoWithUnitiesForBroadcast(const Nd4jLong* maxShapeInfo, const Nd4jLong* minShapeInfo, sd::memory::Workspace* workspace, const std::vector& dimensions) { Nd4jLong* newShapeInfo = nullptr; ALLOCATE(newShapeInfo, workspace, shape::shapeInfoLength(shape::rank(maxShapeInfo)), Nd4jLong); @@ -187,7 +187,4 @@ ConstantDataBuffer ConstantShapeHelper::createShapeInfoWithUnitiesForBroadcast(c return bufferForShapeInfo(descriptor); } - -sd::ConstantShapeHelper* sd::ConstantShapeHelper::_INSTANCE = 0; - } \ No newline at end of file diff --git a/libnd4j/include/helpers/cuda/ConstantTadHelper.cu b/libnd4j/include/helpers/cuda/ConstantTadHelper.cu index 8463bab9c..662c99e7c 100644 --- a/libnd4j/include/helpers/cuda/ConstantTadHelper.cu +++ b/libnd4j/include/helpers/cuda/ConstantTadHelper.cu @@ -25,6 +25,8 @@ #include #include #include +#include +#include namespace sd { ConstantTadHelper::ConstantTadHelper() { @@ -36,11 +38,9 @@ namespace sd { } } - ConstantTadHelper* ConstantTadHelper::getInstance() { - if (!_INSTANCE) - _INSTANCE = new ConstantTadHelper(); - - return _INSTANCE; + ConstantTadHelper& ConstantTadHelper::getInstance() { + static ConstantTadHelper instance; + return instance; } TadPack ConstantTadHelper::tadForDimensions(const Nd4jLong *originalShape, int dimension, const bool keepUnitiesInShape) { @@ -73,25 +73,28 @@ namespace sd { const Nd4jLong numOfSubArrs = ShapeUtils::getNumOfSubArrs(shapeInfo, dimsToExclude); const int subArrRank = (rank == dimsToExclude.size() || descriptor.areUnitiesinShape()) ? rank : rank - dimsToExclude.size(); - auto sPtr = new Nd4jLong[shape::shapeInfoLength(subArrRank)]; - auto oPtr = new Nd4jLong[numOfSubArrs]; + auto sPtr = std::make_shared(new Nd4jLong[shape::shapeInfoLength(subArrRank)], std::make_shared()); + auto oPtr = std::make_shared(new Nd4jLong[numOfSubArrs], std::make_shared()); if (numOfSubArrs > 0) - shape::calcSubArrsShapeInfoAndOffsets(shapeInfo, numOfSubArrs, dimsToExclude.size(), dimsToExclude.data(), sPtr, oPtr, descriptor.areUnitiesinShape()); + shape::calcSubArrsShapeInfoAndOffsets(shapeInfo, numOfSubArrs, dimsToExclude.size(), dimsToExclude.data(), sPtr->pointerAsT(), oPtr->pointerAsT(), descriptor.areUnitiesinShape()); Nd4jPointer soPtr; auto res = cudaMalloc(reinterpret_cast(&soPtr), numOfSubArrs * sizeof(Nd4jLong)); if (res != 0) throw cuda_exception::build("Memory allocation for tadOffsets failed", res); - res = cudaMemcpy(soPtr, oPtr, numOfSubArrs * sizeof(Nd4jLong), cudaMemcpyHostToDevice); + res = cudaMemcpy(soPtr, oPtr->pointer(), numOfSubArrs * sizeof(Nd4jLong), cudaMemcpyHostToDevice); if (res != 0) throw cuda_exception::build("tadOffsets copy failed", res); - auto ssPtr = ConstantHelper::getInstance()->replicatePointer(sPtr, shape::shapeInfoByteLength(subArrRank)); + // TODO: add deallocator here? + auto ssPtr = std::make_shared(ConstantHelper::getInstance().replicatePointer(sPtr->pointer(), shape::shapeInfoByteLength(subArrRank))); - ConstantDataBuffer shapesBuffer(sPtr, ssPtr, shape::shapeInfoLength(subArrRank) * sizeof(Nd4jLong), DataType::INT64); - ConstantDataBuffer offsetsBuffer(oPtr, soPtr, numOfSubArrs * sizeof(Nd4jLong), DataType::INT64); + + + ConstantShapeBuffer shapesBuffer(sPtr, ssPtr); + ConstantOffsetsBuffer offsetsBuffer(oPtr, std::make_shared(soPtr, std::make_shared())); TadPack t(shapesBuffer, offsetsBuffer, numOfSubArrs); _cache[deviceId][descriptor] = t; @@ -107,6 +110,4 @@ namespace sd { return r; } } - - sd::ConstantTadHelper* sd::ConstantTadHelper::_INSTANCE = 0; } \ No newline at end of file diff --git a/libnd4j/include/helpers/cuda_off/MmulHelper.cu b/libnd4j/include/helpers/cuda_off/MmulHelper.cu index 0a3b466bc..d1122d794 100644 --- a/libnd4j/include/helpers/cuda_off/MmulHelper.cu +++ b/libnd4j/include/helpers/cuda_off/MmulHelper.cu @@ -238,7 +238,7 @@ NDArray* MmulHelper::mmulMxM(const NDArray* A, const NDArray* B, NDArray* C, dou if (C->isEmpty()) return C; - const int major = Environment::getInstance()->capabilities()[AffinityManager::currentDeviceId()].first(); + const int major = Environment::getInstance().capabilities()[AffinityManager::currentDeviceId()].first(); const auto aType = A->dataType(); const auto bType = B->dataType(); @@ -268,7 +268,7 @@ NDArray* MmulHelper::mmulMxM(const NDArray* A, const NDArray* B, NDArray* C, dou const int sharedMem = threadsPerBlock * sizeof(int) * 6 + 128; // 6 = aRank + bRank + cRank NDArray::prepareSpecialUse({C}, {A, B}); - // BUILD_TRIPLE_SELECTOR(aType, bType, cType, usualGemm, (blocksPerGrid, threadsPerBlock, sharedMem, stream, A->specialBuffer(), A->specialShapeInfo(), B->specialBuffer(), B->specialShapeInfo(), C->specialBuffer(), C->specialShapeInfo(), 0, 1, 0, 1, 0, 1, alpha, beta), NUMERIC_TYPES, NUMERIC_TYPES, FLOAT_TYPES); + // BUILD_TRIPLE_SELECTOR(aType, bType, cType, usualGemm, (blocksPerGrid, threadsPerBlock, sharedMem, stream, A->specialBuffer(), A->specialShapeInfo(), B->specialBuffer(), B->specialShapeInfo(), C->specialBuffer(), C->special(), 0, 1, 0, 1, 0, 1, alpha, beta), NUMERIC_TYPES, NUMERIC_TYPES, FLOAT_TYPES); BUILD_SINGLE_SELECTOR_THRICE(aType, usualGemm, (blocksPerGrid, threadsPerBlock, sharedMem, stream, A->specialBuffer(), A->specialShapeInfo(), B->specialBuffer(), B->specialShapeInfo(), C->specialBuffer(), C->specialShapeInfo(), 0, 1, 0, 1, 0, 1, alpha, beta), NUMERIC_TYPES) NDArray::registerSpecialUse({C}, {A, B}); @@ -411,7 +411,7 @@ NDArray* MmulHelper::mmulMxV(const NDArray* A, const NDArray* X, sd::NDArray* Y, const int blocksPerGrid = (M + threadsPerBlock - 1) / threadsPerBlock; NDArray::prepareSpecialUse({Y}, {A, X}); - // BUILD_TRIPLE_SELECTOR(aType, xType, yType, usualGemv, (blocksPerGrid, threadsPerBlock, stream, A->specialBuffer(), A->specialShapeInfo(), X->specialBuffer(), X->specialShapeInfo(), Y->specialBuffer(), Y->specialShapeInfo(), incx, incy, 0, alpha, beta), NUMERIC_TYPES, NUMERIC_TYPES, FLOAT_TYPES); + // BUILD_TRIPLE_SELECTOR(aType, xType, yType, usualGemv, (blocksPerGrid, threadsPerBlock, stream, A->specialBuffer(), A->specialShapeInfo(), X->specialBuffer(), X->specialShapeInfo(), Y->specialBuffer(), Y->special(), incx, incy, 0, alpha, beta), NUMERIC_TYPES, NUMERIC_TYPES, FLOAT_TYPES); BUILD_SINGLE_SELECTOR_THRICE(xType, usualGemv, (blocksPerGrid, threadsPerBlock, stream, A->specialBuffer(), A->specialShapeInfo(), X->specialBuffer(), X->specialShapeInfo(), Y->specialBuffer(), Y->specialShapeInfo(), incx, incy, 0, alpha, beta), NUMERIC_TYPES) NDArray::registerSpecialUse({Y}, {A, X}); @@ -667,7 +667,7 @@ NDArray* MmulHelper::mmulNxN(const NDArray* A, const NDArray* B, NDArray* C, con cBatchDims = reinterpret_cast(manager.replicatePointer(ShapeUtils::evalDimsToExclude(cRank, {cMaxis, cNaxis}).data(), (cRank - 2) * sizeof(int))); NDArray::prepareSpecialUse({C}, {A, B}); - // BUILD_TRIPLE_SELECTOR(A->dataType(), b->dataType(), C->dataType(), batchedGemm, (blocksPerGrid, threadsPerBlock, A->getContext()->getCudaStream(), A->specialBuffer(), A->specialShapeInfo(), B->specialBuffer(), B->specialShapeInfo(), C->specialBuffer(), C->specialShapeInfo(), aMaxis, aKaxis, bKaxis, bNaxis, cMaxis, cNaxis, alpha, beta), NUMERIC_TYPES, NUMERIC_TYPES, FLOAT_TYPES); + // BUILD_TRIPLE_SELECTOR(A->dataType(), b->dataType(), C->dataType(), batchedGemm, (blocksPerGrid, threadsPerBlock, A->getContext()->getCudaStream(), A->specialBuffer(), A->specialShapeInfo(), B->specialBuffer(), B->specialShapeInfo(), C->specialBuffer(), C->special(), aMaxis, aKaxis, bKaxis, bNaxis, cMaxis, cNaxis, alpha, beta), NUMERIC_TYPES, NUMERIC_TYPES, FLOAT_TYPES); BUILD_SINGLE_SELECTOR_THRICE(A->dataType(), batchedGemm, (blocksPerGrid, threadsPerBlock, sharedMem, A->getContext()->getCudaStream(), A->specialBuffer(), A->specialShapeInfo(), B->specialBuffer(), B->specialShapeInfo(), C->specialBuffer(), C->specialShapeInfo(), aBatchDims, bBatchDims, cBatchDims, aMaxis, aKaxis, bKaxis, bNaxis, cMaxis, cNaxis, alpha, beta), NUMERIC_TYPES) NDArray::registerSpecialUse({C}, {A, B}); diff --git a/libnd4j/include/helpers/cuda_off/cublasHelper.cu b/libnd4j/include/helpers/cuda_off/cublasHelper.cu index 7ab2d7d63..1773937ea 100644 --- a/libnd4j/include/helpers/cuda_off/cublasHelper.cu +++ b/libnd4j/include/helpers/cuda_off/cublasHelper.cu @@ -102,13 +102,9 @@ namespace sd { destroyHandle_(_cache[e]); } - CublasHelper* CublasHelper::getInstance() { - _mutex.lock(); - if (!_INSTANCE) - _INSTANCE = new sd::CublasHelper(); - _mutex.unlock(); - - return _INSTANCE; + CublasHelper& CublasHelper::getInstance() { + static CublasHelper instance; + return instance; } void* CublasHelper::cudnn() { @@ -138,7 +134,4 @@ namespace sd { return _cache[deviceId]; } - - - sd::CublasHelper* sd::CublasHelper::_INSTANCE = 0; } \ No newline at end of file diff --git a/libnd4j/include/helpers/helper_hash.h b/libnd4j/include/helpers/helper_hash.h index 1b032238f..fa44b04b7 100644 --- a/libnd4j/include/helpers/helper_hash.h +++ b/libnd4j/include/helpers/helper_hash.h @@ -31,8 +31,6 @@ namespace sd { namespace ops { class ND4J_EXPORT HashHelper { private: - static HashHelper* _INSTANCE; - Nd4jLong _byteTable[256]; const Nd4jLong HSTART = 0xBB40E64DA205B064L; const Nd4jLong HMULT = 7664345821815920749L; @@ -41,7 +39,7 @@ namespace sd { std::mutex _locker; public: - static HashHelper* getInstance(); + static HashHelper& getInstance(); Nd4jLong getLongHash(std::string& str); }; } diff --git a/libnd4j/include/helpers/impl/BlasHelper.cpp b/libnd4j/include/helpers/impl/BlasHelper.cpp index 378c8a6f1..70839fe2d 100644 --- a/libnd4j/include/helpers/impl/BlasHelper.cpp +++ b/libnd4j/include/helpers/impl/BlasHelper.cpp @@ -20,10 +20,9 @@ #include namespace sd { - BlasHelper* BlasHelper::getInstance() { - if (_instance == 0) - _instance = new BlasHelper(); - return _instance; + BlasHelper& BlasHelper::getInstance() { + static BlasHelper instance; + return instance; } @@ -74,7 +73,7 @@ namespace sd { template <> bool BlasHelper::hasGEMV() { - if (sd::Environment::getInstance()->blasFallback()) + if (sd::Environment::getInstance().blasFallback()) return false; #if defined(__EXTERNAL_BLAS__) || defined(HAVE_OPENBLAS) @@ -86,7 +85,7 @@ namespace sd { template <> bool BlasHelper::hasGEMV() { - if (sd::Environment::getInstance()->blasFallback()) + if (sd::Environment::getInstance().blasFallback()) return false; #if defined(__EXTERNAL_BLAS__) || defined(HAVE_OPENBLAS) @@ -138,7 +137,7 @@ namespace sd { bool BlasHelper::hasGEMV(const sd::DataType dtype) { if(dtype == DataType::FLOAT32) { - if (sd::Environment::getInstance()->blasFallback()) + if (sd::Environment::getInstance().blasFallback()) return false; #if defined(__EXTERNAL_BLAS__) || defined(HAVE_OPENBLAS) @@ -148,7 +147,7 @@ namespace sd { #endif } if(dtype == DataType::DOUBLE) { - if (sd::Environment::getInstance()->blasFallback()) + if (sd::Environment::getInstance().blasFallback()) return false; #if defined(__EXTERNAL_BLAS__) || defined(HAVE_OPENBLAS) @@ -162,7 +161,7 @@ namespace sd { template <> bool BlasHelper::hasGEMM() { - if (sd::Environment::getInstance()->blasFallback()) + if (sd::Environment::getInstance().blasFallback()) return false; #if defined(__EXTERNAL_BLAS__) || defined(HAVE_OPENBLAS) @@ -174,7 +173,7 @@ namespace sd { template <> bool BlasHelper::hasGEMM() { - if (sd::Environment::getInstance()->blasFallback()) + if (sd::Environment::getInstance().blasFallback()) return false; #if defined(__EXTERNAL_BLAS__) || defined(HAVE_OPENBLAS) @@ -226,7 +225,7 @@ namespace sd { bool BlasHelper:: hasGEMM(const sd::DataType dtype) { if(dtype == DataType::FLOAT32) { - if (sd::Environment::getInstance()->blasFallback()) + if (sd::Environment::getInstance().blasFallback()) return false; #if defined(__EXTERNAL_BLAS__) || defined(HAVE_OPENBLAS) @@ -236,7 +235,7 @@ namespace sd { #endif } if(dtype == DataType::DOUBLE) { - if (sd::Environment::getInstance()->blasFallback()) + if (sd::Environment::getInstance().blasFallback()) return false; #if defined(__EXTERNAL_BLAS__) || defined(HAVE_OPENBLAS) @@ -251,7 +250,7 @@ namespace sd { template <> bool BlasHelper::hasBatchedGEMM() { - if (sd::Environment::getInstance()->blasFallback()) + if (sd::Environment::getInstance().blasFallback()) return false; return _hasSgemmBatch; @@ -259,7 +258,7 @@ namespace sd { template <> bool BlasHelper::hasBatchedGEMM() { - if (sd::Environment::getInstance()->blasFallback()) + if (sd::Environment::getInstance().blasFallback()) return false; return _hasDgemmBatch; @@ -362,6 +361,4 @@ namespace sd { // destructor BlasHelper::~BlasHelper() noexcept { } - - BlasHelper* BlasHelper::_instance = 0; } diff --git a/libnd4j/include/helpers/impl/OmpLaunchHelper.cpp b/libnd4j/include/helpers/impl/OmpLaunchHelper.cpp index 0e409a952..b0ef97457 100644 --- a/libnd4j/include/helpers/impl/OmpLaunchHelper.cpp +++ b/libnd4j/include/helpers/impl/OmpLaunchHelper.cpp @@ -32,7 +32,7 @@ namespace sd { //////////////////////////////////////////////////////////////////////////////// OmpLaunchHelper::OmpLaunchHelper(const Nd4jLong N, float desiredNumThreads) { - auto maxItersPerThread = Environment::getInstance()->elementwiseThreshold(); + auto maxItersPerThread = Environment::getInstance().elementwiseThreshold(); if(N < maxItersPerThread) _numThreads = 1; @@ -45,7 +45,7 @@ OmpLaunchHelper::OmpLaunchHelper(const Nd4jLong N, float desiredNumThreads) { else desiredNumThreads = sd::math::nd4j_min(omp_get_max_threads(), desiredNumThreads); #else - desiredNumThreads = sd::Environment::getInstance()->maxThreads(); + desiredNumThreads = sd::Environment::getInstance().maxThreads(); #endif _numThreads = sd::math::nd4j_min(N / maxItersPerThread, desiredNumThreads); } @@ -75,12 +75,12 @@ Nd4jLong OmpLaunchHelper::betterSpan(Nd4jLong N) { #ifdef _OPENMP return betterThreads(N, omp_get_max_threads()); #else - return betterThreads(N, sd::Environment::getInstance()->maxThreads());; + return betterThreads(N, sd::Environment::getInstance().maxThreads());; #endif } int OmpLaunchHelper::betterThreads(Nd4jLong N, int maxThreads) { - auto t = Environment::getInstance()->elementwiseThreshold(); + auto t = Environment::getInstance().elementwiseThreshold(); if (N < t) return 1; else { @@ -92,7 +92,7 @@ Nd4jLong OmpLaunchHelper::betterSpan(Nd4jLong N) { #ifdef _OPENMP auto maxThreads = omp_get_max_threads(); #else - auto maxThreads = sd::Environment::getInstance()->maxThreads(); + auto maxThreads = sd::Environment::getInstance().maxThreads(); #endif // if there's only 1 thread allowed - nothing to do here @@ -102,7 +102,7 @@ Nd4jLong OmpLaunchHelper::betterSpan(Nd4jLong N) { auto totalLength = tadLength * numTads; // if array is tiny - no need to spawn any threeds - if (totalLength < Environment::getInstance()->elementwiseThreshold()) + if (totalLength < Environment::getInstance().elementwiseThreshold()) return 1; // by default we're spawning as many threads we can, but not more than number of TADs diff --git a/libnd4j/include/helpers/impl/OpTracker.cpp b/libnd4j/include/helpers/impl/OpTracker.cpp index bb82ab0d1..e36d4ab5a 100644 --- a/libnd4j/include/helpers/impl/OpTracker.cpp +++ b/libnd4j/include/helpers/impl/OpTracker.cpp @@ -29,11 +29,9 @@ using namespace sd::graph; namespace sd { - OpTracker* OpTracker::getInstance() { - if (_INSTANCE == 0) - _INSTANCE = new OpTracker(); - - return _INSTANCE; + OpTracker& OpTracker::getInstance() { + static OpTracker instance; + return instance; } void OpTracker::storeOperation(sd::graph::OpType opType, const OpDescriptor& descriptor) { @@ -118,6 +116,4 @@ namespace sd { return _export.c_str(); } - - sd::OpTracker* sd::OpTracker::_INSTANCE = 0; } diff --git a/libnd4j/include/helpers/impl/ShapeUtils.cpp b/libnd4j/include/helpers/impl/ShapeUtils.cpp index c327004bd..2c189cff1 100644 --- a/libnd4j/include/helpers/impl/ShapeUtils.cpp +++ b/libnd4j/include/helpers/impl/ShapeUtils.cpp @@ -130,7 +130,7 @@ std::vector ShapeUtils::evalShapeForTensorDot(const NDArray* a, cons Nd4jLong* outShapeInfo = ShapeBuilders::copyShapeInfoAndType(shapeInfo, dataType, true, workspace); ShapeDescriptor descriptor(outShapeInfo, dataType); RELEASE(outShapeInfo, workspace); - return ConstantShapeHelper::getInstance()->bufferForShapeInfo(descriptor).primaryAsT(); + return ConstantShapeHelper::getInstance().bufferForShapeInfo(descriptor).primary(); } const int rank = shape::rank(shapeInfo); @@ -168,7 +168,7 @@ std::vector ShapeUtils::evalShapeForTensorDot(const NDArray* a, cons ShapeDescriptor descriptor(outShapeInfo, dataType); RELEASE(outShapeInfo, workspace); - return ConstantShapeHelper::getInstance()->bufferForShapeInfo(descriptor).primaryAsT(); + return ConstantShapeHelper::getInstance().bufferForShapeInfo(descriptor).primary(); } const Nd4jLong* ShapeUtils::evalReduceShapeInfo(const char order, std::vector& dimsToExclude, const NDArray& arr, const bool keepDims, const bool supportOldShapes, sd::memory::Workspace* workspace) { @@ -207,20 +207,20 @@ std::vector ShapeUtils::evalShapeForTensorDot(const NDArray* a, cons ShapeDescriptor descriptor(newShapeInfo, dataType); RELEASE(newShapeInfo, workspace); - return ConstantShapeHelper::getInstance()->bufferForShapeInfo(descriptor).primaryAsT(); + return ConstantShapeHelper::getInstance().bufferForShapeInfo(descriptor).primary(); } else if(supportOldShapes) { ALLOCATE(newShapeInfo, workspace, shape::shapeInfoLength(2), Nd4jLong); shape::shapeOldScalar(dataType, newShapeInfo, 'c'); ShapeDescriptor descriptor(newShapeInfo, dataType); RELEASE(newShapeInfo, workspace); - return ConstantShapeHelper::getInstance()->bufferForShapeInfo(descriptor).primaryAsT(); + return ConstantShapeHelper::getInstance().bufferForShapeInfo(descriptor).primary(); } else { newShapeInfo = ShapeBuilders::createScalarShapeInfo(dataType, workspace); ShapeDescriptor descriptor(newShapeInfo, dataType); RELEASE(newShapeInfo, workspace); - return ConstantShapeHelper::getInstance()->bufferForShapeInfo(descriptor).primaryAsT(); + return ConstantShapeHelper::getInstance().bufferForShapeInfo(descriptor).primary(); } } @@ -241,7 +241,7 @@ std::vector ShapeUtils::evalShapeForTensorDot(const NDArray* a, cons ShapeUtils::updateStridesAndType(newShapeInfo, shapeInfo, order); ShapeDescriptor descriptor(newShapeInfo, dataType); RELEASE(newShapeInfo, workspace); - return ConstantShapeHelper::getInstance()->bufferForShapeInfo(descriptor).primaryAsT(); + return ConstantShapeHelper::getInstance().bufferForShapeInfo(descriptor).primary(); } int newRank = rank - dimSize; @@ -252,13 +252,13 @@ std::vector ShapeUtils::evalShapeForTensorDot(const NDArray* a, cons shape::shapeOldScalar(ArrayOptions::dataType(shapeInfo), newShapeInfo, 'c'); ShapeDescriptor descriptor(newShapeInfo, dataType); RELEASE(newShapeInfo, workspace); - return ConstantShapeHelper::getInstance()->bufferForShapeInfo(descriptor).primaryAsT(); + return ConstantShapeHelper::getInstance().bufferForShapeInfo(descriptor).primary(); } else { newShapeInfo = ShapeBuilders::createScalarShapeInfo(ArrayOptions::dataType(shapeInfo), workspace); ShapeDescriptor descriptor(newShapeInfo, dataType); RELEASE(newShapeInfo, workspace); - return ConstantShapeHelper::getInstance()->bufferForShapeInfo(descriptor).primaryAsT(); + return ConstantShapeHelper::getInstance().bufferForShapeInfo(descriptor).primary(); } } @@ -289,7 +289,7 @@ std::vector ShapeUtils::evalShapeForTensorDot(const NDArray* a, cons ShapeDescriptor descriptor(newShapeInfo, dataType); RELEASE(newShapeInfo, workspace); - return ConstantShapeHelper::getInstance()->bufferForShapeInfo(descriptor).primaryAsT(); + return ConstantShapeHelper::getInstance().bufferForShapeInfo(descriptor).primary(); } ////////////////////////////////////////////////////////////////////////// @@ -341,7 +341,7 @@ std::vector ShapeUtils::evalRepeatShape(int axis, const std::vectorbufferForShapeInfo(descriptor).primaryAsT(); + return ConstantShapeHelper::getInstance().bufferForShapeInfo(descriptor).primary(); } ////////////////////////////////////////////////////////////////////////// @@ -486,7 +486,7 @@ bool ShapeUtils::areShapesBroadcastable(const Nd4jLong *shapeInfo1, const Nd4jLo ShapeDescriptor descriptor(tmpShapeInfo); RELEASE(tmpShapeInfo, workspace); - resultShapeInfo = ConstantShapeHelper::getInstance()->bufferForShapeInfo(descriptor).primaryAsT(); + resultShapeInfo = ConstantShapeHelper::getInstance().bufferForShapeInfo(descriptor).primary(); return true; } @@ -525,7 +525,7 @@ bool ShapeUtils::areShapesBroadcastable(const Nd4jLong *shapeInfo1, const Nd4jLo ShapeDescriptor descriptor(tmpShapeInfo); RELEASE(tmpShapeInfo, workspace); - resultShapeInfo = const_cast(ConstantShapeHelper::getInstance()->createShapeInfo(descriptor)); + resultShapeInfo = const_cast(ConstantShapeHelper::getInstance().createShapeInfo(descriptor)); return true; } @@ -594,7 +594,7 @@ bool ShapeUtils::areShapesBroadcastable(const Nd4jLong *shapeInfo1, const Nd4jLo ShapeDescriptor descriptor(newShapeInfo); RELEASE(newShapeInfo, workspace); - return ConstantShapeHelper::getInstance()->bufferForShapeInfo(descriptor).primaryAsT(); + return ConstantShapeHelper::getInstance().bufferForShapeInfo(descriptor).primary(); } std::vector ShapeUtils::pullShapeFromShapeInfo(const Nd4jLong *shapeInfo) { @@ -745,7 +745,7 @@ std::vector ShapeUtils::shapeAsVector(const Nd4jLong* shapeInfo) { ShapeUtils::updateStridesAndType(outputShapeInfo, shapeInfo, shape::order(shapeInfo)); - auto result = ConstantShapeHelper::getInstance()->createShapeInfo(outputShapeInfo); + auto result = ConstantShapeHelper::getInstance().createShapeInfo(outputShapeInfo); RELEASE(outputShapeInfo, workspace); return result; } @@ -832,7 +832,7 @@ std::vector ShapeUtils::evalBroadcastBackwardAxis(const Nd4jLong *operandSh shape[1] = 1; } - auto newShape = ConstantShapeHelper::getInstance()->createShapeInfo(dtype, 'f', 2, shape); + auto newShape = ConstantShapeHelper::getInstance().createShapeInfo(dtype, 'f', 2, shape); RELEASE(shape, workspace); diff --git a/libnd4j/include/helpers/impl/helper_hash.cpp b/libnd4j/include/helpers/impl/helper_hash.cpp index b12acb273..4fde919cd 100644 --- a/libnd4j/include/helpers/impl/helper_hash.cpp +++ b/libnd4j/include/helpers/impl/helper_hash.cpp @@ -24,11 +24,9 @@ namespace sd { namespace ops { - HashHelper* HashHelper::getInstance() { - if (_INSTANCE == 0) - _INSTANCE = new HashHelper(); - - return _INSTANCE; + HashHelper& HashHelper::getInstance() { + static HashHelper instance; + return instance; } Nd4jLong HashHelper::getLongHash(std::string& str) { @@ -64,8 +62,6 @@ namespace sd { return h; } - - sd::ops::HashHelper* sd::ops::HashHelper::_INSTANCE = 0; } } diff --git a/libnd4j/include/helpers/logger.h b/libnd4j/include/helpers/logger.h index c13785ff7..b7ed88c1d 100644 --- a/libnd4j/include/helpers/logger.h +++ b/libnd4j/include/helpers/logger.h @@ -32,9 +32,9 @@ #ifndef __CUDA_ARCH__ -#define nd4j_debug(FORMAT, ...) if (sd::Environment::getInstance()->isDebug() && sd::Environment::getInstance()->isVerbose()) sd::Logger::info(FORMAT, __VA_ARGS__); -#define nd4j_logger(FORMAT, ...) if (sd::Environment::getInstance()->isDebug() && sd::Environment::getInstance()->isVerbose()) sd::Logger::info(FORMAT, __VA_ARGS__); -#define nd4j_verbose(FORMAT, ...) if (sd::Environment::getInstance()->isVerbose()) sd::Logger::info(FORMAT, __VA_ARGS__); +#define nd4j_debug(FORMAT, ...) if (sd::Environment::getInstance().isDebug() && sd::Environment::getInstance().isVerbose()) sd::Logger::info(FORMAT, __VA_ARGS__); +#define nd4j_logger(FORMAT, ...) if (sd::Environment::getInstance().isDebug() && sd::Environment::getInstance().isVerbose()) sd::Logger::info(FORMAT, __VA_ARGS__); +#define nd4j_verbose(FORMAT, ...) if (sd::Environment::getInstance().isVerbose()) sd::Logger::info(FORMAT, __VA_ARGS__); #define nd4j_printf(FORMAT, ...) sd::Logger::info(FORMAT, __VA_ARGS__); #define nd4j_printv(FORMAT, VECTOR) sd::Logger::printv(FORMAT, VECTOR); diff --git a/libnd4j/include/helpers/shape.h b/libnd4j/include/helpers/shape.h index 65cf29b66..719b086cb 100644 --- a/libnd4j/include/helpers/shape.h +++ b/libnd4j/include/helpers/shape.h @@ -384,9 +384,9 @@ namespace shape { * @param rank the rank of the shape */ - ND4J_EXPORT _CUDA_HD int isMatrix(Nd4jLong *shape, int rank); + ND4J_EXPORT _CUDA_HD int isMatrix(const Nd4jLong *shape, int rank); - INLINEDEF _CUDA_HD int isMatrix(Nd4jLong *shapeInfo); + INLINEDEF _CUDA_HD int isMatrix(const Nd4jLong *shapeInfo); /** * Returns the shape portion of an information * buffer @@ -2346,7 +2346,7 @@ INLINEDEF _CUDA_HD int numOfNonUnitDims(const int rank, const Nd4jLong* inShape) * @param shape the shape of the array * @param rank the rank of the shape */ - INLINEDEF _CUDA_HD int isMatrix(Nd4jLong *shape, int rank) { + INLINEDEF _CUDA_HD int isMatrix(const Nd4jLong *shape, int rank) { if (rank > 2) return 0; else if (rank <= 2) { @@ -2357,7 +2357,7 @@ INLINEDEF _CUDA_HD int numOfNonUnitDims(const int rank, const Nd4jLong* inShape) return 1; } - INLINEDEF _CUDA_HD int isMatrix(Nd4jLong *shapeInfo) { + INLINEDEF _CUDA_HD int isMatrix(const Nd4jLong *shapeInfo) { return isMatrix(shape::shapeOf(shapeInfo),shape::rank(shapeInfo)); } diff --git a/libnd4j/include/legacy/NativeOps.h b/libnd4j/include/legacy/NativeOps.h index c72b0d535..29c629b5a 100755 --- a/libnd4j/include/legacy/NativeOps.h +++ b/libnd4j/include/legacy/NativeOps.h @@ -1567,8 +1567,9 @@ ND4J_EXPORT void inspectArray(Nd4jPointer *extraPointers, Nd4jPointer buffer, Nd typedef sd::ConstantDataBuffer OpaqueConstantDataBuffer; +typedef sd::ConstantShapeBuffer OpaqueConstantShapeBuffer; -ND4J_EXPORT OpaqueConstantDataBuffer* shapeBuffer(int rank, Nd4jLong *shape, Nd4jLong *strides, sd::DataType dtype, char order, Nd4jLong ews, bool empty); +ND4J_EXPORT OpaqueConstantShapeBuffer* shapeBuffer(int rank, Nd4jLong *shape, Nd4jLong *strides, sd::DataType dtype, char order, Nd4jLong ews, bool empty); ND4J_EXPORT OpaqueConstantDataBuffer* constantBufferLong(sd::DataType dtype, Nd4jLong const* data, int length); ND4J_EXPORT OpaqueConstantDataBuffer* constantBufferDouble(sd::DataType dtype, double *data, int length); @@ -1577,9 +1578,12 @@ ND4J_EXPORT OpaqueConstantDataBuffer* constantBuffer(sd::DataType dtype, sd::Con ND4J_EXPORT Nd4jPointer getConstantDataBufferPrimary(OpaqueConstantDataBuffer* dbf); ND4J_EXPORT Nd4jPointer getConstantDataBufferSpecial(OpaqueConstantDataBuffer* dbf); ND4J_EXPORT Nd4jLong getConstantDataBufferLength(OpaqueConstantDataBuffer* dbf); -ND4J_EXPORT Nd4jLong getConstantDataBufferSizeOf(OpaqueConstantDataBuffer* dbf); -ND4J_EXPORT void deleteShapeBuffer(OpaqueConstantDataBuffer* ptr); +ND4J_EXPORT Nd4jPointer getConstantShapeBufferPrimary(OpaqueConstantShapeBuffer* dbf); +ND4J_EXPORT Nd4jPointer getConstantShapeBufferSpecial(OpaqueConstantShapeBuffer* dbf); + +ND4J_EXPORT void deleteConstantShapeBuffer(OpaqueConstantShapeBuffer* ptr); +ND4J_EXPORT void deleteConstantDataBuffer(OpaqueConstantDataBuffer* ptr); typedef sd::graph::Context OpaqueContext; typedef sd::graph::RandomGenerator OpaqueRandomGenerator; diff --git a/libnd4j/include/legacy/cpu/NativeOpExecutioner.cpp b/libnd4j/include/legacy/cpu/NativeOpExecutioner.cpp index ad75922e4..6b6c51a13 100644 --- a/libnd4j/include/legacy/cpu/NativeOpExecutioner.cpp +++ b/libnd4j/include/legacy/cpu/NativeOpExecutioner.cpp @@ -245,7 +245,7 @@ void NativeOpExecutioner::execInverseBroadcast(sd::LaunchContext *lc, if (shape::isEmpty(hXShapeInfo) || shape::isEmpty(hYShapeInfo)) return; - if (!sd::Environment::getInstance()->isExperimentalBuild()) + if (!sd::Environment::getInstance().isExperimentalBuild()) if ((yType != xType && yType != sd::DataType::BOOL) || xType != zType) throw sd::datatype_exception::build("NativeOps::execBroadcast both operands must have same data type", xType, yType); @@ -338,7 +338,7 @@ void NativeOpExecutioner::execInverseBroadcastBool(sd::LaunchContext *lc, if (shape::isEmpty(hXShapeInfo) || shape::isEmpty(hYShapeInfo)) return; - if (!sd::Environment::getInstance()->isExperimentalBuild()) + if (!sd::Environment::getInstance().isExperimentalBuild()) if (yType != xType || sd::DataType::BOOL != zType) throw sd::datatype_exception::build("NativeOps::execInverseBroadcastBool both operands must have same data type", xType, yType); @@ -496,7 +496,7 @@ void NativeOpExecutioner::execPairwiseTransform(sd::LaunchContext *lc, }; auto zLen = shape::length(hZShapeInfo); - samediff::Threads::parallel_for(func, 0, zLen, 1, sd::math::nd4j_max(1, sd::math::nd4j_min(zLen / 1024, sd::Environment::getInstance()->maxMasterThreads()))); + samediff::Threads::parallel_for(func, 0, zLen, 1, sd::math::nd4j_max(1, sd::math::nd4j_min(zLen / 1024, sd::Environment::getInstance().maxMasterThreads()))); #endif } @@ -531,7 +531,7 @@ void NativeOpExecutioner::execPairwiseBoolTransform(sd::LaunchContext *lc, }; auto zLen = shape::length(hZShapeInfo); - samediff::Threads::parallel_for(func, 0, zLen, 1, sd::math::nd4j_max(1, sd::math::nd4j_min(zLen / 1024, sd::Environment::getInstance()->maxMasterThreads()))); + samediff::Threads::parallel_for(func, 0, zLen, 1, sd::math::nd4j_max(1, sd::math::nd4j_min(zLen / 1024, sd::Environment::getInstance().maxMasterThreads()))); } @@ -564,7 +564,7 @@ void NativeOpExecutioner::execPairwiseIntTransform(sd::LaunchContext *lc, }; auto zLen = shape::length(hZShapeInfo); - samediff::Threads::parallel_for(func, 0, zLen, 1, sd::math::nd4j_max(1, sd::math::nd4j_min(zLen / 1024, sd::Environment::getInstance()->maxMasterThreads()))); + samediff::Threads::parallel_for(func, 0, zLen, 1, sd::math::nd4j_max(1, sd::math::nd4j_min(zLen / 1024, sd::Environment::getInstance().maxMasterThreads()))); } @@ -603,7 +603,7 @@ void NativeOpExecutioner::execReduceFloat(sd::LaunchContext *lc, const sd::LoopKind::Kind kindOfLoop = sd::LoopKind::deduceKindOfLoopTadXZ(hXShapeInfo, hZShapeInfo, tadShapeInfo); - samediff::Threads::parallel_tad(func, 0, shape::length(hZShapeInfo), 1, kindOfLoop == sd::LoopKind::Kind::SMALLARR2DX ? 1 : sd::Environment::getInstance()->maxMasterThreads()); + samediff::Threads::parallel_tad(func, 0, shape::length(hZShapeInfo), 1, kindOfLoop == sd::LoopKind::Kind::SMALLARR2DX ? 1 : sd::Environment::getInstance().maxMasterThreads()); } //////////////////////////////////////////////////////////////////////// @@ -631,7 +631,7 @@ void NativeOpExecutioner::execReduceSame(sd::LaunchContext *lc, const sd::LoopKind::Kind kindOfLoop = sd::LoopKind::deduceKindOfLoopTadXZ(hXShapeInfo, hZShapeInfo, tadShapeInfo); - samediff::Threads::parallel_tad(func, 0, shape::length(hZShapeInfo), 1, kindOfLoop == sd::LoopKind::Kind::SMALLARR2DX ? 1 : sd::Environment::getInstance()->maxMasterThreads()); + samediff::Threads::parallel_tad(func, 0, shape::length(hZShapeInfo), 1, kindOfLoop == sd::LoopKind::Kind::SMALLARR2DX ? 1 : sd::Environment::getInstance().maxMasterThreads()); } //////////////////////////////////////////////////////////////////////// @@ -659,7 +659,7 @@ void NativeOpExecutioner::execReduceBool(sd::LaunchContext *lc, const sd::LoopKind::Kind kindOfLoop = sd::LoopKind::deduceKindOfLoopTadXZ(hXShapeInfo, hZShapeInfo, tadShapeInfo); - samediff::Threads::parallel_tad(func, 0, shape::length(hZShapeInfo), 1, kindOfLoop == sd::LoopKind::Kind::SMALLARR2DX ? 1 : sd::Environment::getInstance()->maxMasterThreads()); + samediff::Threads::parallel_tad(func, 0, shape::length(hZShapeInfo), 1, kindOfLoop == sd::LoopKind::Kind::SMALLARR2DX ? 1 : sd::Environment::getInstance().maxMasterThreads()); } //////////////////////////////////////////////////////////////////////// @@ -687,7 +687,7 @@ void NativeOpExecutioner::execReduceLong(sd::LaunchContext *lc, const sd::LoopKind::Kind kindOfLoop = sd::LoopKind::deduceKindOfLoopTadXZ(hXShapeInfo, hZShapeInfo, tadShapeInfo); - samediff::Threads::parallel_tad(func, 0, shape::length(hZShapeInfo), 1, kindOfLoop == sd::LoopKind::Kind::SMALLARR2DX ? 1 : sd::Environment::getInstance()->maxMasterThreads()); + samediff::Threads::parallel_tad(func, 0, shape::length(hZShapeInfo), 1, kindOfLoop == sd::LoopKind::Kind::SMALLARR2DX ? 1 : sd::Environment::getInstance().maxMasterThreads()); } //////////////////////////////////////////////////////////////////////// @@ -844,13 +844,13 @@ void NativeOpExecutioner::execReduce3(sd::LaunchContext *lc, sd::TadPack tadPack; if(xLen == yLen) { - tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(hXShapeInfo, dimension, dimensionLength); + tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(hXShapeInfo, dimension, dimensionLength); } else if(yLen > xLen) { - tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(hYShapeInfo, dimension, dimensionLength); + tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(hYShapeInfo, dimension, dimensionLength); } else { - tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(hXShapeInfo, dimension, dimensionLength); + tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(hXShapeInfo, dimension, dimensionLength); } auto func = PRAGMA_THREADS_FOR { @@ -878,7 +878,7 @@ void NativeOpExecutioner::execReduce3All(sd::LaunchContext *lc, auto xType = sd::ArrayOptions::dataType(hXShapeInfo); auto zType = sd::ArrayOptions::dataType(hZShapeInfo); - auto tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(hXShapeInfo, dimension, dimensionLength); + auto tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(hXShapeInfo, dimension, dimensionLength); // TODO: make it 2d auto func = PRAGMA_THREADS_FOR { @@ -911,13 +911,13 @@ void NativeOpExecutioner::execReduce3TAD(sd::LaunchContext *lc, sd::TadPack tadPack; if(xLen == yLen) { - tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(hXShapeInfo, dimension, dimensionLength); + tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(hXShapeInfo, dimension, dimensionLength); } else if(yLen > xLen) { - tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(hYShapeInfo, dimension, dimensionLength); + tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(hYShapeInfo, dimension, dimensionLength); } else { - tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(hXShapeInfo, dimension, dimensionLength); + tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(hXShapeInfo, dimension, dimensionLength); } auto func = PRAGMA_THREADS_FOR { @@ -969,7 +969,7 @@ void NativeOpExecutioner::execScalar(sd::LaunchContext *lc, }; auto zLen = shape::length(hZShapeInfo); - samediff::Threads::parallel_for(func, 0, zLen, 1, !allowParallelism ? 1 : sd::math::nd4j_max(1, sd::math::nd4j_min(zLen / 1024, sd::Environment::getInstance()->maxMasterThreads()))); + samediff::Threads::parallel_for(func, 0, zLen, 1, !allowParallelism ? 1 : sd::math::nd4j_max(1, sd::math::nd4j_min(zLen / 1024, sd::Environment::getInstance().maxMasterThreads()))); #endif } @@ -1006,7 +1006,7 @@ void NativeOpExecutioner::execScalar(sd::LaunchContext *lc, }; auto yLen = shape::length(hScalarShapeInfo); - samediff::Threads::parallel_tad(func, 0, yLen, 1, sd::math::nd4j_min(yLen, sd::Environment::getInstance()->maxMasterThreads())); + samediff::Threads::parallel_tad(func, 0, yLen, 1, sd::math::nd4j_min(yLen, sd::Environment::getInstance().maxMasterThreads())); #endif } @@ -1041,7 +1041,7 @@ void NativeOpExecutioner::execScalarBool(sd::LaunchContext *lc, }; auto zLen = shape::length(hZShapeInfo); - samediff::Threads::parallel_for(func, 0, zLen, 1, !allowParallelism ? 1 : sd::math::nd4j_max(1, sd::math::nd4j_min(zLen / 1024, sd::Environment::getInstance()->maxMasterThreads()))); + samediff::Threads::parallel_for(func, 0, zLen, 1, !allowParallelism ? 1 : sd::math::nd4j_max(1, sd::math::nd4j_min(zLen / 1024, sd::Environment::getInstance().maxMasterThreads()))); } @@ -1077,7 +1077,7 @@ void NativeOpExecutioner::execScalarBool(sd::LaunchContext *lc, }; auto yLen = shape::length(hScalarShapeInfo); - samediff::Threads::parallel_tad(func, 0, yLen, 1, sd::math::nd4j_min(yLen, sd::Environment::getInstance()->maxMasterThreads())); + samediff::Threads::parallel_tad(func, 0, yLen, 1, sd::math::nd4j_min(yLen, sd::Environment::getInstance().maxMasterThreads())); } //////////////////////////////////////////////////////////////////////// @@ -1110,7 +1110,7 @@ void NativeOpExecutioner::execScalarInt(sd::LaunchContext *lc, }; auto zLen = shape::length(hZShapeInfo); - samediff::Threads::parallel_for(func, 0, zLen, 1, !allowParallelism ? 1 : sd::math::nd4j_max(1, sd::math::nd4j_min(zLen / 1024, sd::Environment::getInstance()->maxMasterThreads()))); + samediff::Threads::parallel_for(func, 0, zLen, 1, !allowParallelism ? 1 : sd::math::nd4j_max(1, sd::math::nd4j_min(zLen / 1024, sd::Environment::getInstance().maxMasterThreads()))); } @@ -1146,7 +1146,7 @@ void NativeOpExecutioner::execScalarInt(sd::LaunchContext *lc, }; auto yLen = shape::length(hScalarShapeInfo); - samediff::Threads::parallel_tad(func, 0, yLen, 1, sd::math::nd4j_min(yLen, sd::Environment::getInstance()->maxMasterThreads())); + samediff::Threads::parallel_tad(func, 0, yLen, 1, sd::math::nd4j_min(yLen, sd::Environment::getInstance().maxMasterThreads())); } //////////////////////////////////////////////////////////////////////// @@ -1259,7 +1259,7 @@ void NativeOpExecutioner::execTransformFloat(sd::LaunchContext *lc, BUILD_DOUBLE_SELECTOR(xType, zType, functions::transform::TransformFloat, ::exec(opNum, hX, hXShapeInfo, hZ, hZShapeInfo, extraParams, thread_id, numThreads), LIBND4J_TYPES, FLOAT_TYPES); }; - samediff::Threads::parallel_do(func, sd::math::nd4j_max(1, sd::math::nd4j_min(shape::length(hZShapeInfo) / 1024, sd::Environment::getInstance()->maxMasterThreads()))); + samediff::Threads::parallel_do(func, sd::math::nd4j_max(1, sd::math::nd4j_min(shape::length(hZShapeInfo) / 1024, sd::Environment::getInstance().maxMasterThreads()))); } //////////////////////////////////////////////////////////////////////// @@ -1281,7 +1281,7 @@ void NativeOpExecutioner::execTransformBool(sd::LaunchContext *lc, BUILD_DOUBLE_SELECTOR(xType, zType, functions::transform::TransformBool, ::exec(opNum, hX, hXShapeInfo, hZ, hZShapeInfo, extraParams, thread_id, numThreads), LIBND4J_TYPES, BOOL_TYPES); }; - samediff::Threads::parallel_do(func, sd::math::nd4j_max(1, sd::math::nd4j_min(shape::length(hZShapeInfo) / 1024, sd::Environment::getInstance()->maxMasterThreads()))); + samediff::Threads::parallel_do(func, sd::math::nd4j_max(1, sd::math::nd4j_min(shape::length(hZShapeInfo) / 1024, sd::Environment::getInstance().maxMasterThreads()))); } //////////////////////////////////////////////////////////////////////// @@ -1310,7 +1310,7 @@ void NativeOpExecutioner::execTransformAny(sd::LaunchContext *lc, BUILD_DOUBLE_SELECTOR(xType, zType, functions::transform::TransformAny, ::exec(opNum, hX, hXShapeInfo, hZ, hZShapeInfo, extraParams, thread_id, numThreads), LIBND4J_TYPES, LIBND4J_TYPES); }; - samediff::Threads::parallel_do(func, sd::math::nd4j_max(1, sd::math::nd4j_min(shape::length(hZShapeInfo) / 1024, sd::Environment::getInstance()->maxMasterThreads()))); + samediff::Threads::parallel_do(func, sd::math::nd4j_max(1, sd::math::nd4j_min(shape::length(hZShapeInfo) / 1024, sd::Environment::getInstance().maxMasterThreads()))); } } @@ -1333,7 +1333,7 @@ void NativeOpExecutioner::execTransformSame(sd::LaunchContext *lc, BUILD_SINGLE_SELECTOR(xType, functions::transform::TransformSame, ::exec(opNum, hX, hXShapeInfo, hZ, hZShapeInfo, extraParams, thread_id, numThreads), LIBND4J_TYPES); }; - samediff::Threads::parallel_do(func, sd::math::nd4j_max(1, sd::math::nd4j_min(shape::length(hZShapeInfo) / 1024, sd::Environment::getInstance()->maxMasterThreads()))); + samediff::Threads::parallel_do(func, sd::math::nd4j_max(1, sd::math::nd4j_min(shape::length(hZShapeInfo) / 1024, sd::Environment::getInstance().maxMasterThreads()))); } //////////////////////////////////////////////////////////////////////// @@ -1355,7 +1355,7 @@ void NativeOpExecutioner::execTransformStrict(sd::LaunchContext *lc, BUILD_SINGLE_SELECTOR(xType, functions::transform::TransformStrict, ::exec(opNum, hX, hXShapeInfo, hZ, hZShapeInfo, extraParams, thread_id, numThreads), FLOAT_TYPES); }; - samediff::Threads::parallel_do(func, sd::math::nd4j_max(1, sd::math::nd4j_min(shape::length(hZShapeInfo) / 1024, sd::Environment::getInstance()->maxMasterThreads()))); + samediff::Threads::parallel_do(func, sd::math::nd4j_max(1, sd::math::nd4j_min(shape::length(hZShapeInfo) / 1024, sd::Environment::getInstance().maxMasterThreads()))); } //////////////////////////////////////////////////////////////////////// diff --git a/libnd4j/include/legacy/cpu/NativeOps.cpp b/libnd4j/include/legacy/cpu/NativeOps.cpp index ae8a22a6a..f9e3f669c 100644 --- a/libnd4j/include/legacy/cpu/NativeOps.cpp +++ b/libnd4j/include/legacy/cpu/NativeOps.cpp @@ -85,12 +85,12 @@ using namespace sd; void setElementThreshold(int num) { if (num > 0) - sd::Environment::getInstance()->setElementwiseThreshold(num); + sd::Environment::getInstance().setElementwiseThreshold(num); } void setTADThreshold(int num) { if (num > 0) - sd::Environment::getInstance()->setTadThreshold(num); + sd::Environment::getInstance().setTadThreshold(num); } /** @@ -133,7 +133,7 @@ void execIndexReduce(Nd4jPointer *extraPointers,int opNum, auto dimension = reinterpret_cast(dbDimension->primary()); int dimensionLength = static_cast(shape::length(hDimensionShape)); - auto tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(hXShapeInfo, dimension, + auto tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(hXShapeInfo, dimension, dimensionLength); auto hTADShapeInfo = tadPack.primaryShapeInfo(); @@ -184,8 +184,8 @@ void execBroadcast(Nd4jPointer *extraPointers, auto dimension = reinterpret_cast(dbDimension->primary()); auto dimensionLength = static_cast(shape::length(hDimensionShape)); - auto tadPackX = sd::ConstantTadHelper::getInstance()->tadForDimensions(hXShapeInfo, dimension, dimensionLength); - auto tadPackZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(hZShapeInfo, dimension, dimensionLength); + auto tadPackX = sd::ConstantTadHelper::getInstance().tadForDimensions(hXShapeInfo, dimension, dimensionLength); + auto tadPackZ = sd::ConstantTadHelper::getInstance().tadForDimensions(hZShapeInfo, dimension, dimensionLength); auto hTADShapeInfo = tadPackX.primaryShapeInfo(); auto hTADOffsets = tadPackX.primaryOffsets(); @@ -223,8 +223,8 @@ void execBroadcastBool(Nd4jPointer *extraPointers, auto dimension = reinterpret_cast(dbDimension->primary()); auto dimensionLength = static_cast(shape::length(hDimensionShape)); - auto tadPackX = sd::ConstantTadHelper::getInstance()->tadForDimensions(hXShapeInfo, dimension, dimensionLength); - auto tadPackZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(hZShapeInfo, dimension, dimensionLength); + auto tadPackX = sd::ConstantTadHelper::getInstance().tadForDimensions(hXShapeInfo, dimension, dimensionLength); + auto tadPackZ = sd::ConstantTadHelper::getInstance().tadForDimensions(hZShapeInfo, dimension, dimensionLength); auto hTADShapeInfo = tadPackX.primaryShapeInfo(); auto hTADOffsets = tadPackX.primaryOffsets(); @@ -450,7 +450,7 @@ void execReduceFloat2(Nd4jPointer *extraPointers, auto dimension = reinterpret_cast(dbDimension->primary()); auto dimensionLength = static_cast(shape::length(hDimensionShape)); - auto tadPackX = sd::ConstantTadHelper::getInstance()->tadForDimensions(hXShapeInfo, dimension, dimensionLength); + auto tadPackX = sd::ConstantTadHelper::getInstance().tadForDimensions(hXShapeInfo, dimension, dimensionLength); auto hTADShapeInfo = tadPackX.primaryShapeInfo(); auto hTADOffsets = tadPackX.primaryOffsets(); @@ -485,7 +485,7 @@ void execReduceBool2(Nd4jPointer *extraPointers, auto dimension = reinterpret_cast(dbDimension->primary()); auto dimensionLength = static_cast(shape::length(hDimensionShape)); - auto tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(hXShapeInfo, dimension, + auto tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(hXShapeInfo, dimension, dimensionLength); auto hTADShapeInfo = tadPack.primaryShapeInfo(); @@ -521,7 +521,7 @@ void execReduceSame2(Nd4jPointer *extraPointers, auto dimension = reinterpret_cast(dbDimension->primary()); int dimensionLength = static_cast(shape::length(hDimensionShape)); - auto tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(hXShapeInfo, dimension, + auto tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(hXShapeInfo, dimension, dimensionLength); auto hTADShapeInfo = tadPack.primaryShapeInfo(); @@ -557,7 +557,7 @@ void execReduceLong2(Nd4jPointer *extraPointers, auto dimension = reinterpret_cast(dbDimension->primary()); int dimensionLength = static_cast(shape::length(hDimensionShape)); - auto tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(hXShapeInfo, dimension, dimensionLength); + auto tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(hXShapeInfo, dimension, dimensionLength); auto hTADShapeInfo = tadPack.primaryShapeInfo(); auto hTADOffsets = tadPack.primaryOffsets(); @@ -663,7 +663,7 @@ void execReduce3Tad(Nd4jPointer *extraPointers, yTadOnlyShapeInfo, yTadOffsets); } else { // going tad-way - auto tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(hXShapeInfo, dimension, + auto tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(hXShapeInfo, dimension, dimensionLength); auto hTADShapeInfo = tadPack.primaryShapeInfo(); @@ -1060,7 +1060,7 @@ void initializeDevicesAndFunctions() { } void initializeFunctions(Nd4jPointer *functions) { - sd::BlasHelper::getInstance()->initializeFunctions(functions); + sd::BlasHelper::getInstance().initializeFunctions(functions); } /** @@ -1208,11 +1208,11 @@ int getAvailableDevices() { } void enableDebugMode(bool reallyEnable) { - sd::Environment::getInstance()->setDebug(reallyEnable); + sd::Environment::getInstance().setDebug(reallyEnable); } void enableVerboseMode(bool reallyEnable) { - sd::Environment::getInstance()->setVerbose(reallyEnable); + sd::Environment::getInstance().setVerbose(reallyEnable); } void setGridLimit(int gridSize) { @@ -1222,7 +1222,7 @@ void setGridLimit(int gridSize) { sd::TadPack* tadOnlyShapeInfo(Nd4jLong const* hXShapeInfo, int *dimension, int dimensionLength) { auto pack = new TadPack(); try { - *pack = sd::ConstantTadHelper::getInstance()->tadForDimensions(hXShapeInfo, dimension, dimensionLength); + *pack = sd::ConstantTadHelper::getInstance().tadForDimensions(hXShapeInfo, dimension, dimensionLength); } catch (std::exception &e) { sd::LaunchContext::defaultContext()->errorReference()->setErrorCode(1); sd::LaunchContext::defaultContext()->errorReference()->setErrorMessage(e.what()); @@ -1285,7 +1285,7 @@ void pullRowsGeneric(void *vx, int elementsPerThread = n / TAD_THRESHOLD; int _threads = sd::math::nd4j_max(1, elementsPerThread); - _threads = sd::math::nd4j_min(_threads, sd::Environment::getInstance()->maxThreads()); + _threads = sd::math::nd4j_min(_threads, sd::Environment::getInstance().maxThreads()); auto func = PRAGMA_THREADS_FOR { for (auto idx = start; idx < stop; idx++) { @@ -1557,7 +1557,7 @@ void shuffle(Nd4jPointer *extras, bool isExperimentalEnabled() { - return sd::Environment::getInstance()->isExperimentalBuild(); + return sd::Environment::getInstance().isExperimentalBuild(); } @@ -1920,7 +1920,7 @@ Nd4jPointer getResultWrapperPointer(sd::graph::ResultWrapper* ptr) { } const char* getAllCustomOps() { - return sd::ops::OpRegistrator::getInstance()->getAllCustomOperations(); + return sd::ops::OpRegistrator::getInstance().getAllCustomOperations(); } template @@ -2016,7 +2016,7 @@ sd::ShapeList* _calculateOutputShapes(Nd4jPointer* extraPointers, sd::ops::Decla sd::ShapeList* calculateOutputShapes2(Nd4jPointer* extraPointers, Nd4jLong hash, Nd4jPointer* inputBuffers, Nd4jPointer* inputShapes, int numInputShapes, double* tArgs, int numTArgs, Nd4jLong *iArgs, int numIArgs, bool *bArgs, int numBArgs, int *dArgs, int numDArgs) { try { - auto op = sd::ops::OpRegistrator::getInstance()->getOperation(hash); + auto op = sd::ops::OpRegistrator::getInstance().getOperation(hash); return _calculateOutputShapes(extraPointers, op, inputBuffers, inputShapes, numInputShapes, tArgs, numTArgs, iArgs, numIArgs, bArgs, numBArgs, dArgs, numDArgs); } catch (std::exception &e) { @@ -2047,7 +2047,7 @@ sd::ShapeList* _calculateOutputShapes(Nd4jPointer* extraPointers, sd::ops::Decla sd::ShapeList* calculateOutputShapes(Nd4jPointer* extraPointers, Nd4jLong hash, Nd4jPointer* inputShapes, int numInputShapes, double* tArgs, int numTArgs, Nd4jLong *iArgs, int numIArgs) { try { - auto op = sd::ops::OpRegistrator::getInstance()->getOperation(hash); + auto op = sd::ops::OpRegistrator::getInstance().getOperation(hash); return _calculateOutputShapes(extraPointers, op, inputShapes, numInputShapes, tArgs, numTArgs, iArgs, numIArgs); } catch (std::exception &e) { @@ -2059,7 +2059,7 @@ sd::ShapeList* calculateOutputShapes(Nd4jPointer* extraPointers, Nd4jLong hash, int execCustomOp2(Nd4jPointer* extraPointers, Nd4jLong hash, Nd4jPointer opContext) { try { - auto op = sd::ops::OpRegistrator::getInstance()->getOperation(hash); + auto op = sd::ops::OpRegistrator::getInstance().getOperation(hash); auto context = reinterpret_cast(opContext); return op->execute(context); @@ -2157,7 +2157,7 @@ Nd4jStatus realExec(sd::ops::DeclarableOp* op, Nd4jPointer* extraPointers, Nd4jL int execCustomOp(Nd4jPointer* extraPointers, Nd4jLong hash, Nd4jPointer* inputBuffers, Nd4jPointer* inputShapes, int numInputs, Nd4jPointer* outputBuffers, Nd4jPointer* outputShapes, int numOutputs, double* tArgs, int numTArgs, Nd4jLong *iArgs, int numIArgs, bool* bArgs, int numBArgs, bool isInplace) { try { - auto op = sd::ops::OpRegistrator::getInstance()->getOperation(hash); + auto op = sd::ops::OpRegistrator::getInstance().getOperation(hash); return realExec(op, extraPointers, hash, inputBuffers, inputShapes, numInputs, outputBuffers, outputShapes, numOutputs, tArgs, numTArgs, iArgs, numIArgs, bArgs, numBArgs, isInplace); } catch (std::exception &e) { sd::LaunchContext::defaultContext()->errorReference()->setErrorCode(1); @@ -2170,7 +2170,7 @@ int registerGraph(Nd4jPointer *extraPointers, Nd4jLong graphId, Nd4jPointer flat try { auto graph = sd::graph::GraphExecutioner::importFromFlatPointer(flatBufferPointer); - sd::graph::GraphHolder::getInstance()->registerGraph(graphId, graph); + sd::graph::GraphHolder::getInstance().registerGraph(graphId, graph); return ND4J_STATUS_OK; } catch (std::exception &e) { @@ -2181,7 +2181,7 @@ int registerGraph(Nd4jPointer *extraPointers, Nd4jLong graphId, Nd4jPointer flat } static VariablesSet* executeStoredGraphT(Nd4jPointer *extraPointers, Nd4jLong graphId, Nd4jPointer *inputBuffers, Nd4jPointer *inputShapes, int* inputIndices, int numInputs) { - auto graph = sd::graph::GraphHolder::getInstance()->cloneGraph(graphId); + auto graph = sd::graph::GraphHolder::getInstance().cloneGraph(graphId); auto varSpace = graph->getVariableSpace(); std::vector handles; @@ -2264,7 +2264,7 @@ void* getVariableBuffer(sd::graph::Variable* variable) { int unregisterGraph(Nd4jPointer *extraPointers, Nd4jLong graphId) { - sd::graph::GraphHolder::getInstance()->dropGraphAny(graphId); + sd::graph::GraphHolder::getInstance().dropGraphAny(graphId); return sd::Status::OK(); } @@ -2294,7 +2294,7 @@ void deleteVariablesSet(sd::graph::VariablesSet* pointer) { } const char* getAllOperations() { - return sd::OpTracker::getInstance()->exportOperations(); + return sd::OpTracker::getInstance().exportOperations(); } @@ -2694,10 +2694,10 @@ void tryPointer(Nd4jPointer extra, Nd4jPointer p, int len) { } } -sd::ConstantDataBuffer* shapeBuffer(int rank, Nd4jLong *shape, Nd4jLong *strides, sd::DataType dtype, char order, Nd4jLong ews, bool empty) { +sd::ConstantShapeBuffer* shapeBuffer(int rank, Nd4jLong *shape, Nd4jLong *strides, sd::DataType dtype, char order, Nd4jLong ews, bool empty) { try { - auto buffer = new ConstantDataBuffer(); - *buffer = sd::ConstantShapeHelper::getInstance()->bufferForShapeInfo( + auto buffer = new ConstantShapeBuffer(); + *buffer = sd::ConstantShapeHelper::getInstance().bufferForShapeInfo( ShapeDescriptor(dtype, order, shape, strides, rank, ews, empty)); return buffer; } catch (std::exception &e) { @@ -2707,10 +2707,14 @@ sd::ConstantDataBuffer* shapeBuffer(int rank, Nd4jLong *shape, Nd4jLong *strides } } -void deleteShapeBuffer(sd::ConstantDataBuffer* ptr) { +void deleteConstantShapeBuffer(sd::ConstantShapeBuffer* ptr) { delete ptr; } +void deleteConstantDataBuffer(sd::ConstantDataBuffer* ptr) { + delete ptr; +} + void deleteTadPack(sd::TadPack* ptr) { delete ptr; } @@ -2725,7 +2729,7 @@ sd::ConstantDataBuffer* constantBufferDouble(sd::DataType dtype, double *data, i sd::ConstantDataBuffer* constantBuffer(sd::DataType dtype, sd::ConstantDescriptor *descriptor) { try { - return sd::ConstantHelper::getInstance()->constantBuffer(*descriptor, dtype); + return sd::ConstantHelper::getInstance().constantBuffer(*descriptor, dtype); } catch (std::exception &e) { sd::LaunchContext::defaultContext()->errorReference()->setErrorCode(1); sd::LaunchContext::defaultContext()->errorReference()->setErrorMessage(e.what()); @@ -2733,6 +2737,14 @@ sd::ConstantDataBuffer* constantBuffer(sd::DataType dtype, sd::ConstantDescripto } } +Nd4jPointer getConstantShapeBufferPrimary(sd::ConstantShapeBuffer* dbf) { + return const_cast(dbf->primary()); +} + +Nd4jPointer getConstantShapeBufferSpecial(sd::ConstantShapeBuffer* dbf) { + return const_cast(dbf->special()); +} + Nd4jPointer getConstantDataBufferPrimary(sd::ConstantDataBuffer* dbf) { return dbf->primary(); } @@ -2884,7 +2896,7 @@ Nd4jPointer shapeBufferForNumpy(Nd4jPointer npyArray) { } else { shapeBuffer = sd::ShapeBuilders::createShapeInfo(dtype, arr.fortranOrder ? 'f' : 'c', shape); } - return const_cast(sd::ConstantShapeHelper::getInstance()->createFromExisting(shapeBuffer, true)); + return const_cast(sd::ConstantShapeHelper::getInstance().createFromExisting(shapeBuffer, true)); } catch (std::exception &e) { sd::LaunchContext::defaultContext()->errorReference()->setErrorCode(1); sd::LaunchContext::defaultContext()->errorReference()->setErrorMessage(e.what()); @@ -2983,7 +2995,7 @@ const char* runLightBenchmarkSuit(bool printOut) { } Nd4jLong getCachedMemory(int deviceId) { - return sd::ConstantHelper::getInstance()->getCachedAmount(deviceId); + return sd::ConstantHelper::getInstance().getCachedAmount(deviceId); } const char* runFullBenchmarkSuit(bool printOut) { diff --git a/libnd4j/include/legacy/cuda/NativeOpExecutioner.cu b/libnd4j/include/legacy/cuda/NativeOpExecutioner.cu index f01daffd7..14cbf306a 100644 --- a/libnd4j/include/legacy/cuda/NativeOpExecutioner.cu +++ b/libnd4j/include/legacy/cuda/NativeOpExecutioner.cu @@ -252,7 +252,7 @@ void NativeOpExecutioner::execBroadcastBool(sd::LaunchContext *lc, if (yType != xType) throw std::runtime_error("NativeOpExecutioner::execBroadcastBool requires both X & Y operands to have same type"); - if (sd::Environment::getInstance()->isDebugAndVerbose()) + if (sd::Environment::getInstance().isDebugAndVerbose()) printf("F3B opNum:[%i]\n", opNum); dim3 launchDims(256, 256, 1024); @@ -437,7 +437,7 @@ void NativeOpExecutioner::execInverseBroadcastInt(sd::LaunchContext *lc, if (yType != xType || zType != xType) throw std::runtime_error("NativeOpExecutioner::execBroadcastInt requires both X & Y operands to have same type"); - if (sd::Environment::getInstance()->isDebugAndVerbose()) + if (sd::Environment::getInstance().isDebugAndVerbose()) printf("F3BI opNum:[%i]\n", opNum); dim3 launchDims(256, 256, 1024); @@ -583,7 +583,7 @@ void NativeOpExecutioner::execReduceSame(sd::LaunchContext *lc, auto stream = lc->getCudaStream(); auto reductionPointer = lc->getReductionPointer(); - if (sd::Environment::getInstance()->isDebugAndVerbose()) + if (sd::Environment::getInstance().isDebugAndVerbose()) printf("SF7 opNum:[%i]\n", opNum); auto xType = sd::ArrayOptions::dataType(hXShapeInfo); @@ -618,7 +618,7 @@ void NativeOpExecutioner::execReduceLong(sd::LaunchContext *lc, auto stream = lc->getCudaStream(); auto reductionPointer = lc->getReductionPointer(); - if (sd::Environment::getInstance()->isDebugAndVerbose()) + if (sd::Environment::getInstance().isDebugAndVerbose()) printf("LF7 opNum:[%i]\n", opNum); auto xType = sd::ArrayOptions::dataType(hXShapeInfo); @@ -654,7 +654,7 @@ void NativeOpExecutioner::execReduceBool(sd::LaunchContext *lc, auto stream = lc->getCudaStream(); auto reductionPointer = lc->getReductionPointer(); - if (sd::Environment::getInstance()->isDebugAndVerbose()) + if (sd::Environment::getInstance().isDebugAndVerbose()) printf("BF7 opNum:[%i]\n", opNum); auto xType = sd::ArrayOptions::dataType(hXShapeInfo); @@ -701,7 +701,7 @@ void NativeOpExecutioner::execIndexReduce(sd::LaunchContext *lc, auto reductionPointer = lc->getReductionPointer(); auto allocationPointer = lc->getAllocationPointer(); - if (sd::Environment::getInstance()->isDebugAndVerbose()) + if (sd::Environment::getInstance().isDebugAndVerbose()) printf("F2 opNum:[%i]\n", opNum); auto xType = sd::ArrayOptions::dataType(hXShapeInfo); @@ -745,7 +745,7 @@ void NativeOpExecutioner::execReduceFloat(sd::LaunchContext *lc, auto stream = lc->getCudaStream(); auto reductionPointer = lc->getReductionPointer(); - if (sd::Environment::getInstance()->isDebugAndVerbose()) + if (sd::Environment::getInstance().isDebugAndVerbose()) printf("F8 opNum:[%i]\n", opNum); auto xType = sd::ArrayOptions::dataType(hXShapeInfo); @@ -780,7 +780,7 @@ void NativeOpExecutioner::execIndexReduceScalar(sd::LaunchContext *lc, void *hZ, Nd4jLong const* hZShapeInfo, void *dZ, Nd4jLong const* dZShapeInfo){ - if (sd::Environment::getInstance()->isDebug()) + if (sd::Environment::getInstance().isDebug()) printf("F1 opNum:[%i]\n", opNum); auto stream = lc->getCudaStream(); @@ -792,7 +792,7 @@ void NativeOpExecutioner::execIndexReduceScalar(sd::LaunchContext *lc, auto numBlocks = CudaLaunchHelper::getReductionBlocks(xLength, blockWidth); dim3 launchDims(numBlocks == 0 ? 1 : numBlocks, blockWidth, 32768); - if (sd::Environment::getInstance()->isDebugAndVerbose() && launchDims.x == 1) + if (sd::Environment::getInstance().isDebugAndVerbose() && launchDims.x == 1) printf("AF1 opNum:[%i]\n", opNum); auto xType = sd::ArrayOptions::dataType(hXShapeInfo); @@ -1649,12 +1649,12 @@ void NativeOpExecutioner::execReduce3All(sd::LaunchContext *lc, auto allocationPointer = lc->getAllocationPointer(); auto reductionPointer = lc->getReductionPointer(); - if (sd::Environment::getInstance()->isDebugAndVerbose()) + if (sd::Environment::getInstance().isDebugAndVerbose()) printf("D119 opNum:[%i]\n", opNum); dim3 launchDims(shape::length(hZShapeInfo), 256, 32768); - if (sd::Environment::getInstance()->isVerbose() && launchDims.x == 1) + if (sd::Environment::getInstance().isVerbose() && launchDims.x == 1) printf("AD119 opNum:[%i]\n", opNum); auto xType = sd::ArrayOptions::dataType(hXShapeInfo); diff --git a/libnd4j/include/legacy/cuda/NativeOps.cu b/libnd4j/include/legacy/cuda/NativeOps.cu index 465029207..1ccc2c7d5 100755 --- a/libnd4j/include/legacy/cuda/NativeOps.cu +++ b/libnd4j/include/legacy/cuda/NativeOps.cu @@ -237,9 +237,9 @@ void execPairwiseTransform( Nd4jPointer *extraPointers, InteropDataBuffer::prepareSpecialUse({dbZ}, {dbX, dbY}); LaunchContext lc(extraPointers[1], extraPointers[4], extraPointers[5], extraPointers[3]); - NativeOpExecutioner::execPairwiseTransform(&lc, opNum, dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hXShapeInfo).specialAsT(), - dbY->primary(), hYShapeInfo, dbY->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hYShapeInfo).specialAsT(), - dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hZShapeInfo).specialAsT(), extraParams); + NativeOpExecutioner::execPairwiseTransform(&lc, opNum, dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hXShapeInfo).special(), + dbY->primary(), hYShapeInfo, dbY->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hYShapeInfo).special(), + dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hZShapeInfo).special(), extraParams); InteropDataBuffer::registerSpecialUse({dbZ}, {dbX, dbY}); } catch (std::exception &e) { @@ -260,9 +260,9 @@ void execPairwiseTransformBool(Nd4jPointer *extraPointers, LaunchContext lc(extraPointers[1], extraPointers[4], extraPointers[5], extraPointers[3]); NativeOpExecutioner::execPairwiseBoolTransform(&lc, opNum, - dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hXShapeInfo).specialAsT(), - dbY->primary(), hYShapeInfo, dbY->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hYShapeInfo).specialAsT(), - dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hZShapeInfo).specialAsT(), + dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hXShapeInfo).special(), + dbY->primary(), hYShapeInfo, dbY->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hYShapeInfo).special(), + dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hZShapeInfo).special(), extraParams); InteropDataBuffer::registerSpecialUse({dbZ}, {dbX, dbY}); @@ -284,9 +284,9 @@ void execSummaryStatsScalar(Nd4jPointer *extraPointers, LaunchContext lc(extraPointers[1], extraPointers[4], extraPointers[5], extraPointers[3]); NativeOpExecutioner::execSummaryStatsScalar(&lc, opNum, - dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hXShapeInfo).specialAsT(), + dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hXShapeInfo).special(), extraParams, - dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hZShapeInfo).specialAsT(), + dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hZShapeInfo).special(), biasCorrected); InteropDataBuffer::registerSpecialUse({dbZ}, {dbX}); @@ -319,9 +319,9 @@ void execBroadcastBool(Nd4jPointer *extraPointers, LaunchContext lc(extraPointers[1], extraPointers[4], extraPointers[5], extraPointers[3]); NativeOpExecutioner::execBroadcastBool(&lc, opNum, - dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hXShapeInfo).specialAsT(), - dbY->primary(), hYShapeInfo, dbY->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hYShapeInfo).specialAsT(), - dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hZShapeInfo).specialAsT(), + dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hXShapeInfo).special(), + dbY->primary(), hYShapeInfo, dbY->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hYShapeInfo).special(), + dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hZShapeInfo).special(), extraParams, dimension, dimensionLength, tadOnlyShapeInfo, tadOffsets, tadOnlyShapeInfoZ, tadOffsetsZ); @@ -373,9 +373,9 @@ void execBroadcast( LaunchContext lc(extraPointers[1], extraPointers[4], extraPointers[5], extraPointers[3]); NativeOpExecutioner::execBroadcast(&lc, opNum, - dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hXShapeInfo).specialAsT(), - dbY->primary(), hYShapeInfo, dbY->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hYShapeInfo).specialAsT(), - dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hZShapeInfo).specialAsT(), + dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hXShapeInfo).special(), + dbY->primary(), hYShapeInfo, dbY->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hYShapeInfo).special(), + dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hZShapeInfo).special(), dimension, dimensionLength, tadOnlyShapeInfo, tadOffsets, tadOnlyShapeInfoZ, tadOffsetsZ); @@ -407,9 +407,9 @@ void execReduceFloat(Nd4jPointer *extraPointers, LaunchContext lc(extraPointers[1], extraPointers[4], extraPointers[5], extraPointers[3]); NativeOpExecutioner::execReduceFloatScalar(&lc, opNum, - dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hXShapeInfo).specialAsT(), + dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hXShapeInfo).special(), extraParams, - dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hZShapeInfo).specialAsT()); + dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hZShapeInfo).special()); InteropDataBuffer::registerSpecialUse({dbZ}, {dbX}); } catch (std::exception &e) { @@ -429,9 +429,9 @@ void execReduceSame(Nd4jPointer *extraPointers, LaunchContext lc(extraPointers[1], extraPointers[4], extraPointers[5], extraPointers[3]); NativeOpExecutioner::execReduceSameScalar(&lc, opNum, - dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hXShapeInfo).specialAsT(), + dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hXShapeInfo).special(), extraParams, - dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hZShapeInfo).specialAsT()); + dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hZShapeInfo).special()); InteropDataBuffer::registerSpecialUse({dbZ}, {dbX}); } catch (std::exception &e) { @@ -454,15 +454,15 @@ void execReduceSame2(Nd4jPointer *extraPointers, auto dimension = reinterpret_cast(dbDimension->primary()); int dimensionLength = static_cast(shape::length(hDimensionShape)); - auto tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(hXShapeInfo, + auto tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(hXShapeInfo, dimension, shape::length(hDimensionShape)); LaunchContext lc(extraPointers[1], extraPointers[4], extraPointers[5], extraPointers[3]); NativeOpExecutioner::execReduceSame(&lc, opNum, - dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hXShapeInfo).specialAsT(), + dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hXShapeInfo).special(), extraParams, - dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hZShapeInfo).specialAsT(), + dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hZShapeInfo).special(), dimension, dimensionLength, tadPack.specialShapeInfo(), tadPack.specialOffsets()); @@ -487,15 +487,15 @@ void execReduceLong2(Nd4jPointer *extraPointers, auto dimension = reinterpret_cast(dbDimension->primary()); int dimensionLength = static_cast(shape::length(hDimensionShape)); - auto tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(hXShapeInfo, + auto tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(hXShapeInfo, dimension, shape::length(hDimensionShape)); LaunchContext lc(extraPointers[1], extraPointers[4], extraPointers[5], extraPointers[3]); NativeOpExecutioner::execReduceLong(&lc, opNum, - dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hXShapeInfo).specialAsT(), + dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hXShapeInfo).special(), extraParams, - dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hZShapeInfo).specialAsT(), + dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hZShapeInfo).special(), dimension, dimensionLength, tadPack.specialShapeInfo(), tadPack.specialOffsets()); @@ -534,9 +534,9 @@ void execReduceLong(Nd4jPointer *extraPointers, BUILD_DOUBLE_SELECTOR(xType, zType, functions::reduce::ReduceLongFunction, ::execReduceScalar(launchDims, stream, opNum, - dbX->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hXShapeInfo).specialAsT(), hXShapeInfo, + dbX->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hXShapeInfo).special(), hXShapeInfo, extraParams, - dbZ->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hZShapeInfo).specialAsT(), hXShapeInfo, + dbZ->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hZShapeInfo).special(), hXShapeInfo, nullptr, 0, reductionPointer, dTADShapeInfo), LIBND4J_TYPES, LONG_TYPES); sd::DebugHelper::checkErrorCode(stream, "execReduceLong(...) failed"); @@ -562,15 +562,15 @@ void execReduceBool2(Nd4jPointer *extraPointers, auto dimension = reinterpret_cast(dbDimension->primary()); int dimensionLength = static_cast(shape::length(hDimensionShape)); - auto tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(hXShapeInfo, + auto tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(hXShapeInfo, dimension, shape::length(hDimensionShape)); LaunchContext lc(extraPointers[1], extraPointers[4], extraPointers[5], extraPointers[3]); NativeOpExecutioner::execReduceBool(&lc, opNum, - dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hXShapeInfo).specialAsT(), + dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hXShapeInfo).special(), extraParams, - dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hZShapeInfo).specialAsT(), + dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hZShapeInfo).special(), dimension, dimensionLength, tadPack.specialShapeInfo(), tadPack.specialOffsets()); @@ -609,9 +609,9 @@ void execReduceBool(Nd4jPointer *extraPointers, BUILD_DOUBLE_SELECTOR(xType, zType, functions::reduce::ReduceBoolFunction, ::execReduceScalar(launchDims, stream, opNum, - dbX->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hXShapeInfo).specialAsT(), hXShapeInfo, + dbX->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hXShapeInfo).special(), hXShapeInfo, extraParams, - dbZ->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hZShapeInfo).specialAsT(), hZShapeInfo, + dbZ->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hZShapeInfo).special(), hZShapeInfo, nullptr, 0, reductionPointer, dTADShapeInfo), LIBND4J_TYPES, BOOL_TYPES); sd::DebugHelper::checkErrorCode(stream, "execReduceBool(...) failed"); @@ -648,15 +648,15 @@ void execIndexReduce(Nd4jPointer *extraPointers, auto dimension = reinterpret_cast(dbDimension->primary()); int dimensionLength = static_cast(shape::length(hDimensionShape)); - auto tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(hXShapeInfo, + auto tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(hXShapeInfo, dimension, shape::length(hDimensionShape)); LaunchContext lc(extraPointers[1], extraPointers[4], extraPointers[5], extraPointers[3]); NativeOpExecutioner::execIndexReduce(&lc, opNum, - dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hXShapeInfo).specialAsT(), + dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hXShapeInfo).special(), extraParams, - dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hZShapeInfo).specialAsT(), + dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hZShapeInfo).special(), (int *) dbDimension->special(), dimensionLength, tadPack.specialShapeInfo(), tadPack.specialOffsets()); @@ -690,15 +690,15 @@ void execReduceFloat2(Nd4jPointer *extraPointers, auto dimension = reinterpret_cast(dbDimension->primary()); int dimensionLength = static_cast(shape::length(hDimensionShape)); - auto tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(hXShapeInfo, + auto tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(hXShapeInfo, dimension, shape::length(hDimensionShape)); LaunchContext lc(extraPointers[1], extraPointers[4], extraPointers[5], extraPointers[3]); NativeOpExecutioner::execReduceFloat(&lc, opNum, - dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hXShapeInfo).specialAsT(), + dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hXShapeInfo).special(), extraParams, - dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hZShapeInfo).specialAsT(), + dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hZShapeInfo).special(), dimension, dimensionLength, tadPack.specialShapeInfo(), tadPack.specialOffsets()); @@ -728,9 +728,9 @@ void execIndexReduceScalar( LaunchContext lc(extraPointers[1], extraPointers[4], extraPointers[5], extraPointers[3]); NativeOpExecutioner::execIndexReduceScalar(&lc, opNum, - dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hXShapeInfo).specialAsT(), + dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hXShapeInfo).special(), extraParams, - dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hZShapeInfo).specialAsT()); + dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hZShapeInfo).special()); InteropDataBuffer::registerSpecialUse({dbZ}, {dbX}); } catch (std::exception &e) { @@ -752,8 +752,8 @@ void execTransformSame(Nd4jPointer *extraPointers,int opNum, LaunchContext lc(extraPointers[1], extraPointers[4], extraPointers[5], extraPointers[3]); NativeOpExecutioner::execTransformSame(&lc, opNum, - dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hXShapeInfo).specialAsT(), - dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hZShapeInfo).specialAsT(), + dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hXShapeInfo).special(), + dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hZShapeInfo).special(), extraParams, tadShapeInfo, tadOffsets); @@ -777,8 +777,8 @@ void execTransformBool(Nd4jPointer *extraPointers,int opNum, LaunchContext lc(extraPointers[1], extraPointers[4], extraPointers[5], extraPointers[3]); NativeOpExecutioner::execTransformBool(&lc, opNum, - dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hXShapeInfo).specialAsT(), - dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hZShapeInfo).specialAsT(), + dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hXShapeInfo).special(), + dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hZShapeInfo).special(), extraParams, tadShapeInfo, tadOffsets); @@ -803,8 +803,8 @@ void execTransformAny(Nd4jPointer *extraPointers,int opNum, reinterpret_cast(extraPointers[6])); NativeOpExecutioner::execTransformAny(&lc, opNum, - dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hXShapeInfo).specialAsT(), - dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hZShapeInfo).specialAsT(), + dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hXShapeInfo).special(), + dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hZShapeInfo).special(), extraParams, nullptr, nullptr); @@ -828,8 +828,8 @@ void execTransformStrict(Nd4jPointer *extraPointers,int opNum, LaunchContext lc(extraPointers[1], extraPointers[4], extraPointers[5], extraPointers[3]); NativeOpExecutioner::execTransformStrict(&lc, opNum, - dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hXShapeInfo).specialAsT(), - dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hZShapeInfo).specialAsT(), + dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hXShapeInfo).special(), + dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hZShapeInfo).special(), extraParams, tadShapeInfo, tadOffsets); @@ -853,8 +853,8 @@ void execTransformFloat(Nd4jPointer *extraPointers,int opNum, LaunchContext lc(extraPointers[1], extraPointers[4], extraPointers[5], extraPointers[3]); NativeOpExecutioner::execTransformFloat(&lc, opNum, - dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hXShapeInfo).specialAsT(), - dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hZShapeInfo).specialAsT(), + dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hXShapeInfo).special(), + dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hZShapeInfo).special(), extraParams, tadShapeInfo, tadOffsets); @@ -939,7 +939,7 @@ void enableP2P(bool enable) { cudaDeviceDisablePeerAccess(dY); } } else { - if (sd::Environment::getInstance()->isVerbose()) printf("Peer access [%i] -> [%i] isn't possible\n", dX, dY); + if (sd::Environment::getInstance().isVerbose()) printf("Peer access [%i] -> [%i] isn't possible\n", dX, dY); } } } @@ -983,7 +983,7 @@ void initializeDevicesAndFunctions() { } void initializeFunctions(Nd4jPointer *functions) { - sd::BlasHelper::getInstance()->initializeDeviceFunctions(functions); + sd::BlasHelper::getInstance().initializeDeviceFunctions(functions); /* cublasSgemv = (CublasSgemv)functions[0]; cublasDgemv = (CublasDgemv)functions[1]; @@ -1317,7 +1317,7 @@ int getAvailableDevices() { } void enableDebugMode(bool reallyEnable) { - sd::Environment::getInstance()->setDebug(reallyEnable); + sd::Environment::getInstance().setDebug(reallyEnable); } void setGridLimit(int gridSize) { @@ -1345,7 +1345,7 @@ void setOmpNumThreads(int threads) { } void enableVerboseMode(bool reallyEnable) { - sd::Environment::getInstance()->setVerbose(reallyEnable); + sd::Environment::getInstance().setVerbose(reallyEnable); } int getDeviceMajor(int device) { @@ -1386,7 +1386,7 @@ void specialConcat( sd::TadPack* tadOnlyShapeInfo(Nd4jLong const* dXShapeInfo, int *dimension, int dimensionLength) { try { auto pack = new TadPack(); - *pack = sd::ConstantTadHelper::getInstance()->tadForDimensions(dXShapeInfo, dimension, dimensionLength); + *pack = sd::ConstantTadHelper::getInstance().tadForDimensions(dXShapeInfo, dimension, dimensionLength); return pack; } catch (std::exception &e) { sd::LaunchContext::defaultContext()->errorReference()->setErrorCode(1); @@ -1502,7 +1502,7 @@ void average(Nd4jPointer *extras, auto dX = reinterpret_cast(dx); - if (sd::Environment::getInstance()->isDebugAndVerbose()) + if (sd::Environment::getInstance().isDebugAndVerbose()) printf("averageFloat called\n"); auto xType = sd::ArrayOptions::dataType(xShapeInfo); @@ -1536,7 +1536,7 @@ void accumulate(Nd4jPointer *extras, auto dX = reinterpret_cast(dx); - if (sd::Environment::getInstance()->isDebugAndVerbose()) + if (sd::Environment::getInstance().isDebugAndVerbose()) printf("accumulateFloat called\n"); auto xType = sd::ArrayOptions::dataType(xShapeInfo); @@ -1591,7 +1591,7 @@ void shuffle(Nd4jPointer *extras, } bool isExperimentalEnabled() { - return sd::Environment::getInstance()->isExperimentalBuild(); + return sd::Environment::getInstance().isExperimentalBuild(); } void setOmpMinThreads(int threads) { @@ -1623,9 +1623,9 @@ void execSummaryStats(Nd4jPointer *extraPointers, LaunchContext lc(extraPointers[1], extraPointers[4], extraPointers[5], extraPointers[3]); NativeOpExecutioner::execSummaryStats(&lc, opNum, - dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hXShapeInfo).specialAsT(), + dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hXShapeInfo).special(), extraParams, - dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hZShapeInfo).specialAsT(), + dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hZShapeInfo).special(), biasCorrected); InteropDataBuffer::registerSpecialUse({dbZ}, {dbX}); @@ -1653,9 +1653,9 @@ void execSummaryStatsTad(Nd4jPointer *extraPointers, LaunchContext lc(extraPointers[1], extraPointers[4], extraPointers[5], extraPointers[3]); NativeOpExecutioner::execSummaryStats(&lc, opNum, - dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hXShapeInfo).specialAsT(), + dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hXShapeInfo).special(), extraParams, - dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hZShapeInfo).specialAsT(), + dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hZShapeInfo).special(), reinterpret_cast(dbDimension->special()), dimensionLength, tadShapeInfo, tadOffsets, biasCorrected); @@ -1679,10 +1679,10 @@ void execReduce3(Nd4jPointer *extraPointers, LaunchContext lc(extraPointers[1], extraPointers[4], extraPointers[5], extraPointers[3]); NativeOpExecutioner::execReduce3(&lc, opNum, - dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hXShapeInfo).specialAsT(), + dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hXShapeInfo).special(), extraParams, - dbY->primary(), hYShapeInfo, dbY->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hYShapeInfo).specialAsT(), - dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hZShapeInfo).specialAsT()); + dbY->primary(), hYShapeInfo, dbY->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hYShapeInfo).special(), + dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hZShapeInfo).special()); InteropDataBuffer::registerSpecialUse({dbZ}, {dbX, dbY}); } catch (std::exception &e) { @@ -1708,7 +1708,7 @@ void execReduce3Tad(Nd4jPointer *extraPointers, auto dimension = reinterpret_cast(dbDimension->primary()); int dimensionLength = static_cast(shape::length(hDimensionShape)); - auto tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(hXShapeInfo, + auto tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(hXShapeInfo, dimension, shape::length(hDimensionShape)); auto tadLength = shape::length(tadPack.primaryShapeInfo()); @@ -1720,18 +1720,18 @@ void execReduce3Tad(Nd4jPointer *extraPointers, if (tadLength == yLength || tadLength == xLength) { // nd4j_printf("== way\n",""); NativeOpExecutioner::execReduce3(&lc, opNum, - dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hXShapeInfo).specialAsT(), + dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hXShapeInfo).special(), extraParams, - dbY->primary(), hYShapeInfo, dbY->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hYShapeInfo).specialAsT(), - dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hZShapeInfo).specialAsT(), + dbY->primary(), hYShapeInfo, dbY->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hYShapeInfo).special(), + dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hZShapeInfo).special(), dimension, dimensionLength, tadOnlyShapeInfo, tadOffsets, yTadOnlyShapeInfo, yTadOffsets); } else NativeOpExecutioner::execReduce3TAD(&lc, opNum, - dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hXShapeInfo).specialAsT(), + dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hXShapeInfo).special(), extraParams, - dbY->primary(), hYShapeInfo, dbY->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hYShapeInfo).specialAsT(), - dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hZShapeInfo).specialAsT(), + dbY->primary(), hYShapeInfo, dbY->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hYShapeInfo).special(), + dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hZShapeInfo).special(), dimension, dimensionLength, tadOnlyShapeInfo, yTadOffsets, yTadOnlyShapeInfo, yTadOffsets); @@ -1753,10 +1753,10 @@ void execReduce3Scalar(Nd4jPointer *extraPointers,int opNum, LaunchContext lc(extraPointers[1], extraPointers[4], extraPointers[5], extraPointers[3]); NativeOpExecutioner::execReduce3Scalar(&lc, opNum, - dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hXShapeInfo).specialAsT(), + dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hXShapeInfo).special(), extraParams, - dbY->primary(), hYShapeInfo, dbY->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hYShapeInfo).specialAsT(), - dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hZShapeInfo).specialAsT()); + dbY->primary(), hYShapeInfo, dbY->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hYShapeInfo).special(), + dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hZShapeInfo).special()); InteropDataBuffer::registerSpecialUse({dbZ}, {dbX, dbY}); } catch (std::exception &e) { @@ -1777,9 +1777,9 @@ void execScalarBool(Nd4jPointer *extraPointers, LaunchContext lc(extraPointers[1], extraPointers[4], extraPointers[5], extraPointers[3]); NativeOpExecutioner::execScalarBool(&lc, opNum, - dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hXShapeInfo).specialAsT(), - dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hZShapeInfo).specialAsT(), - dbScalar->primary(), hScalarShapeInfo, dbScalar->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hScalarShapeInfo).specialAsT(), + dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hXShapeInfo).special(), + dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hZShapeInfo).special(), + dbScalar->primary(), hScalarShapeInfo, dbScalar->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hScalarShapeInfo).special(), extraParams); InteropDataBuffer::registerSpecialUse({dbZ}, {dbX, dbScalar}); @@ -1808,10 +1808,10 @@ void execScalarBoolTad(Nd4jPointer *extraPointers, LaunchContext lc(extraPointers[1], extraPointers[4], extraPointers[5], extraPointers[3]); NativeOpExecutioner::execScalarBool(&lc, opNum, - dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hXShapeInfo).specialAsT(), + dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hXShapeInfo).special(), extraParams, - dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hZShapeInfo).specialAsT(), - dbScalars->primary(), hScalarShapeInfo, dbScalars->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hScalarShapeInfo).specialAsT(), + dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hZShapeInfo).special(), + dbScalars->primary(), hScalarShapeInfo, dbScalars->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hScalarShapeInfo).special(), dimension, dimensionLength, tadShapeInfo, tadOffsets, tadShapeInfoZ, tadOffsetsZ); @@ -1834,9 +1834,9 @@ void execScalar(Nd4jPointer *extraPointers, LaunchContext lc(extraPointers[1], extraPointers[4], extraPointers[5], extraPointers[3]); NativeOpExecutioner::execScalar(&lc, opNum, - dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hXShapeInfo).specialAsT(), - dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hZShapeInfo).specialAsT(), - dbScalar->primary(), hScalarShapeInfo, dbScalar->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hScalarShapeInfo).specialAsT(), + dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hXShapeInfo).special(), + dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hZShapeInfo).special(), + dbScalar->primary(), hScalarShapeInfo, dbScalar->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hScalarShapeInfo).special(), extraParams); InteropDataBuffer::registerSpecialUse({dbZ}, {dbX, dbScalar}); @@ -1877,7 +1877,7 @@ void execScalarTad(Nd4jPointer *extraPointers, #ifdef __ND4J_EXPERIMENTAL__ BUILD_PAIRWISE_SELECTOR(xType, yType, zType, functions::scalar::ScalarTransform, ::executeCudaAlongDimension(launchDims, stream, opNum, dX, dXShapeInfo, dZ, dZShapeInfo, dScalars, extraParams, dimension, dimensionLength, tadShapeInfo, tadOffsets, tadShapeInfoZ, tadOffsetsZ), LIBND4J_TYPES, LIBND4J_TYPES); #else - BUILD_SINGLE_SELECTOR_THRICE(xType, functions::scalar::ScalarTransform, ::executeCudaAlongDimension(launchDims, stream, opNum, dbX->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hXShapeInfo).specialAsT(), dbZ->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hZShapeInfo).specialAsT(), dbScalars->special(), extraParams, dimension, dimensionLength, tadShapeInfo, tadOffsets, tadShapeInfoZ, tadOffsetsZ), LIBND4J_TYPES); + BUILD_SINGLE_SELECTOR_THRICE(xType, functions::scalar::ScalarTransform, ::executeCudaAlongDimension(launchDims, stream, opNum, dbX->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hXShapeInfo).special(), dbZ->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hZShapeInfo).special(), dbScalars->special(), extraParams, dimension, dimensionLength, tadShapeInfo, tadOffsets, tadShapeInfoZ, tadOffsetsZ), LIBND4J_TYPES); #endif DEBUG_KERNEL(stream, opNum); @@ -1938,7 +1938,7 @@ void execRandom(Nd4jPointer *extraPointers, LaunchContext lc(extraPointers[1], extraPointers[4], extraPointers[5], extraPointers[3]); NativeOpExecutioner::execRandom(&lc, opNum, stateHost, - dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hZShapeInfo).specialAsT(), + dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hZShapeInfo).special(), extraArguments); InteropDataBuffer::registerSpecialUse({dbZ}, {}); @@ -1958,8 +1958,8 @@ void execRandom2(Nd4jPointer *extraPointers, int opNum, Nd4jPointer stateHost, LaunchContext lc(extraPointers[1], extraPointers[4], extraPointers[5], extraPointers[3]); NativeOpExecutioner::execRandom(&lc, opNum, stateHost, - dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hXShapeInfo).specialAsT(), - dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hZShapeInfo).specialAsT(), + dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hXShapeInfo).special(), + dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hZShapeInfo).special(), extraArguments); InteropDataBuffer::registerSpecialUse({dbZ}, {dbX}); @@ -1980,9 +1980,9 @@ void execRandom3(Nd4jPointer *extraPointers, int opNum, Nd4jPointer stateHost, LaunchContext lc(extraPointers[1], extraPointers[4], extraPointers[5], extraPointers[3]); NativeOpExecutioner::execRandom(&lc, opNum, stateHost, - dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hXShapeInfo).specialAsT(), - dbY->primary(), hYShapeInfo, dbY->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hYShapeInfo).specialAsT(), - dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hZShapeInfo).specialAsT(), + dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hXShapeInfo).special(), + dbY->primary(), hYShapeInfo, dbY->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hYShapeInfo).special(), + dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hZShapeInfo).special(), extraArguments); InteropDataBuffer::registerSpecialUse({dbZ}, {dbX, dbY}); @@ -2216,10 +2216,10 @@ void execReduce3All(Nd4jPointer *extraPointers, LaunchContext lc(extraPointers[1], extraPointers[4], extraPointers[5], extraPointers[3]); NativeOpExecutioner::execReduce3All(&lc, opNum, - dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hXShapeInfo).specialAsT(), + dbX->primary(), hXShapeInfo, dbX->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hXShapeInfo).special(), extraParamsVals, - dbY->primary(), hYShapeInfo, dbY->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hYShapeInfo).specialAsT(), - dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance()->bufferForShapeInfo(hZShapeInfo).specialAsT(), + dbY->primary(), hYShapeInfo, dbY->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hYShapeInfo).special(), + dbZ->primary(), hZShapeInfo, dbZ->special(), ConstantShapeHelper::getInstance().bufferForShapeInfo(hZShapeInfo).special(), reinterpret_cast(dbDimension->special()), dimensionLength, xTadShapeInfo, xOffsets, yTadShapeInfo, yOffsets); @@ -2458,7 +2458,7 @@ void sortTadByKey(Nd4jPointer *extraPointers, auto stream = reinterpret_cast(extraPointers[1]); auto context = extraPointers[0] == 0 ? LaunchContext::defaultContext() : reinterpret_cast(extraPointers[0]); - auto tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(xShapeInfo, dimension, dimensionLength); + auto tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(xShapeInfo, dimension, dimensionLength); dim3 launchDims((int) tadPack.numberOfTads(), 256, 2048); auto xType = sd::ArrayOptions::dataType(xShapeInfo); auto yType = sd::ArrayOptions::dataType(yShapeInfo); @@ -2485,7 +2485,7 @@ void sortTadByValue(Nd4jPointer *extraPointers, auto stream = reinterpret_cast(extraPointers[1]); auto context = extraPointers[0] == 0 ? LaunchContext::defaultContext() : reinterpret_cast(extraPointers[0]); - auto tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(xShapeInfo, dimension, dimensionLength); + auto tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(xShapeInfo, dimension, dimensionLength); dim3 launchDims((int) tadPack.numberOfTads(), 256, 2048); auto xType = sd::ArrayOptions::dataType(yShapeInfo); auto yType = sd::ArrayOptions::dataType(xShapeInfo); @@ -2515,7 +2515,7 @@ void sortTad(Nd4jPointer *extraPointers, auto stream = reinterpret_cast(extraPointers[1]); auto context = extraPointers[0] == 0 ? LaunchContext::defaultContext() : reinterpret_cast(extraPointers[0]); - auto tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(xShapeInfo, dimension, dimensionLength); + auto tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(xShapeInfo, dimension, dimensionLength); dim3 launchDims((int) tadPack.numberOfTads(), 512, 33768); auto xType = sd::ArrayOptions::dataType(xShapeInfo); BUILD_SINGLE_SELECTOR(xType, oesTadGeneric, @@ -2561,7 +2561,7 @@ Nd4jPointer getResultWrapperPointer(sd::graph::ResultWrapper* ptr) { const char* getAllCustomOps() { - return sd::ops::OpRegistrator::getInstance()->getAllCustomOperations(); + return sd::ops::OpRegistrator::getInstance().getAllCustomOperations(); } @@ -2608,7 +2608,7 @@ sd::ShapeList* _calculateOutputShapes(Nd4jPointer* extraPointers, sd::ops::Decla sd::ShapeList* calculateOutputShapes2(Nd4jPointer* extraPointers, Nd4jLong hash, Nd4jPointer* inputBuffers, Nd4jPointer* inputShapes, int numInputShapes, double* tArgs, int numTArgs, Nd4jLong *iArgs, int numIArgs, bool *bArgs, int numBArgs, int *dArgs, int numDArgs) { try { - auto op = sd::ops::OpRegistrator::getInstance()->getOperation(hash); + auto op = sd::ops::OpRegistrator::getInstance().getOperation(hash); return _calculateOutputShapes(extraPointers, op, inputBuffers, inputShapes, numInputShapes, tArgs, numTArgs, iArgs, numIArgs, bArgs, numBArgs, dArgs, numDArgs); @@ -2639,7 +2639,7 @@ sd::ShapeList* _calculateOutputShapes(Nd4jPointer* extraPointers, sd::ops::Decla sd::ShapeList* calculateOutputShapes(Nd4jPointer* extraPointers, Nd4jLong hash, Nd4jPointer* inputShapes, int numInputShapes, double* tArgs, int numTArgs, Nd4jLong *iArgs, int numIArgs) { try { - auto op = sd::ops::OpRegistrator::getInstance()->getOperation(hash); + auto op = sd::ops::OpRegistrator::getInstance().getOperation(hash); return _calculateOutputShapes(extraPointers, op, inputShapes, numInputShapes, tArgs, numTArgs, iArgs, numIArgs); } catch (std::exception &e) { @@ -2742,7 +2742,7 @@ static FORCEINLINE Nd4jStatus realExec(sd::ops::DeclarableOp* op, Nd4jPointer* e int execCustomOp(Nd4jPointer* extraPointers, Nd4jLong hash, Nd4jPointer* inputBuffers, Nd4jPointer* inputShapes, int numInputs, Nd4jPointer* outputBuffers, Nd4jPointer* outputShapes, int numOutputs, double* tArgs, int numTArgs, Nd4jLong *iArgs, int numIArgs, bool* bArgs, int numBArgs, bool isInplace) { try { - auto op = sd::ops::OpRegistrator::getInstance()->getOperation(hash); + auto op = sd::ops::OpRegistrator::getInstance().getOperation(hash); return realExec(op, extraPointers, hash, inputBuffers, inputShapes, numInputs, outputBuffers, outputShapes, numOutputs, tArgs, numTArgs, iArgs, numIArgs, bArgs, numBArgs, isInplace); @@ -2755,7 +2755,7 @@ int execCustomOp(Nd4jPointer* extraPointers, Nd4jLong hash, Nd4jPointer* inputBu int execCustomOp2(Nd4jPointer* extraPointers, Nd4jLong hash, Nd4jPointer opContext) { try { - auto op = sd::ops::OpRegistrator::getInstance()->getOperation(hash); + auto op = sd::ops::OpRegistrator::getInstance().getOperation(hash); auto context = reinterpret_cast(opContext); auto result = op->execute(context); @@ -2786,7 +2786,7 @@ int registerGraph(Nd4jPointer *extraPointers, Nd4jLong graphId, Nd4jPointer flat try { auto graph = sd::graph::GraphExecutioner::importFromFlatPointer(flatBufferPointer); - sd::graph::GraphHolder::getInstance()->registerGraph(graphId, graph); + sd::graph::GraphHolder::getInstance().registerGraph(graphId, graph); return ND4J_STATUS_OK; } catch (std::exception &e) { @@ -2798,7 +2798,7 @@ int registerGraph(Nd4jPointer *extraPointers, Nd4jLong graphId, Nd4jPointer flat static VariablesSet* executeStoredGraphT(Nd4jPointer *extraPointers, Nd4jLong graphId, Nd4jPointer *inputBuffers, Nd4jPointer *inputShapes, int* inputIndices, int numInputs) { - auto graph = sd::graph::GraphHolder::getInstance()->pullGraph(graphId); + auto graph = sd::graph::GraphHolder::getInstance().pullGraph(graphId); auto varSpace = graph->getVariableSpace()->clone(); std::vector handles; @@ -2887,7 +2887,7 @@ void* getVariableBuffer(sd::graph::Variable* variable) { int unregisterGraph(Nd4jPointer *extraPointers, Nd4jLong graphId) { try { - sd::graph::GraphHolder::getInstance()->dropGraphAny(graphId); + sd::graph::GraphHolder::getInstance().dropGraphAny(graphId); return ND4J_STATUS_OK; } catch (std::exception &e) { @@ -2929,7 +2929,7 @@ void deleteShapeList(Nd4jPointer shapeList) { } const char* getAllOperations() { - return sd::OpTracker::getInstance()->exportOperations(); + return sd::OpTracker::getInstance().exportOperations(); } Nd4jPointer getGraphState(Nd4jLong id) { @@ -3360,7 +3360,7 @@ void tryPointer(Nd4jPointer extra, Nd4jPointer p, int len) { cudaStream_t stream; cudaStreamCreate(&stream); - tryPointerKernel << < 256, 512, len + 64, stream >> > (p, len); + tryPointerKernel <<< 256, 512, len + 64, stream>>> (p, len); auto e = cudaStreamSynchronize(stream); if (e != 0) @@ -3376,10 +3376,11 @@ void tryPointer(Nd4jPointer extra, Nd4jPointer p, int len) { int dataTypeFromNpyHeader(void *header) { return (int) cnpy::dataTypeFromHeader(reinterpret_cast(header)); } -sd::ConstantDataBuffer* shapeBuffer(int rank, Nd4jLong *shape, Nd4jLong *strides, sd::DataType dtype, char order, Nd4jLong ews, bool empty) { + +OpaqueConstantShapeBuffer* shapeBuffer(int rank, Nd4jLong *shape, Nd4jLong *strides, sd::DataType dtype, char order, Nd4jLong ews, bool empty) { try { - auto buffer = new ConstantDataBuffer(); - *buffer = sd::ConstantShapeHelper::getInstance()->bufferForShapeInfo( + auto buffer = new ConstantShapeBuffer(); + *buffer = sd::ConstantShapeHelper::getInstance().bufferForShapeInfo( ShapeDescriptor(dtype, order, shape, strides, rank, ews, empty)); return buffer; } catch (std::exception &e) { @@ -3389,19 +3390,23 @@ sd::ConstantDataBuffer* shapeBuffer(int rank, Nd4jLong *shape, Nd4jLong *strides } } -void deleteShapeBuffer(sd::ConstantDataBuffer* ptr) { +void deleteConstantShapeBuffer(OpaqueConstantShapeBuffer* ptr) { delete ptr; } +void deleteConstantDataBuffer(OpaqueConstantDataBuffer* ptr) { + delete ptr; +} + void deleteTadPack(sd::TadPack* ptr) { delete ptr; } bool isBlasVersionMatches(int major, int minor, int build) { - auto result = major == Environment::getInstance()->_blasMajorVersion && minor == Environment::getInstance()->_blasMinorVersion && build == Environment::getInstance()->_blasPatchVersion; + auto result = major == Environment::getInstance()._blasMajorVersion && minor == Environment::getInstance()._blasMinorVersion && build == Environment::getInstance()._blasPatchVersion; if (!result) { - nd4j_printf("CUDA/cuBLAS version mismatch. Expected: %i.%i.%i but got %i.%i.%i instead\n", Environment::getInstance()->_blasMajorVersion, Environment::getInstance()->_blasMinorVersion, Environment::getInstance()->_blasPatchVersion, major, minor, build); + nd4j_printf("CUDA/cuBLAS version mismatch. Expected: %i.%i.%i but got %i.%i.%i instead\n", Environment::getInstance()._blasMajorVersion, Environment::getInstance()._blasMinorVersion, Environment::getInstance()._blasPatchVersion, major, minor, build); sd::LaunchContext::defaultContext()->errorReference()->setErrorCode(152); sd::LaunchContext::defaultContext()->errorReference()->setErrorMessage("CUDA/cuBLAS version mismatch"); } @@ -3410,15 +3415,15 @@ bool isBlasVersionMatches(int major, int minor, int build) { } sd::ConstantDataBuffer* constantBufferLong(sd::DataType dtype, Nd4jLong const* data, int length) { - return sd::ConstantHelper::getInstance()->constantBuffer(ConstantDescriptor(data, length), dtype); + return sd::ConstantHelper::getInstance().constantBuffer(ConstantDescriptor(data, length), dtype); } sd::ConstantDataBuffer* constantBufferDouble(sd::DataType dtype, double *data, int length) { - return sd::ConstantHelper::getInstance()->constantBuffer(ConstantDescriptor(data, length), dtype); + return sd::ConstantHelper::getInstance().constantBuffer(ConstantDescriptor(data, length), dtype); } sd::ConstantDataBuffer* constantBuffer(sd::DataType dtype, sd::ConstantDescriptor *descriptor) { - return sd::ConstantHelper::getInstance()->constantBuffer(*descriptor, dtype); + return sd::ConstantHelper::getInstance().constantBuffer(*descriptor, dtype); } @@ -3435,6 +3440,13 @@ Nd4jLong getConstantDataBufferSizeOf(sd::ConstantDataBuffer* dbf) { return dbf->sizeOf(); } +Nd4jPointer getConstantShapeBufferPrimary(sd::ConstantShapeBuffer* dbf) { + return const_cast(dbf->primary()); +} + +Nd4jPointer getConstantShapeBufferSpecial(sd::ConstantShapeBuffer* dbf) { + return const_cast(dbf->special()); +} sd::graph::Context* createGraphContext(int nodeId) { return new sd::graph::Context(nodeId); @@ -3563,7 +3575,7 @@ Nd4jPointer shapeBufferForNumpy(Nd4jPointer npyArray) { } else { shapeBuffer = sd::ShapeBuilders::createShapeInfo(dtype, arr.fortranOrder ? 'f' : 'c', shape); } - return (Nd4jPointer)(sd::ConstantShapeHelper::getInstance()->createFromExisting(shapeBuffer, true)); // TO DO: this can lead to unpleasant crash sometimes + return (Nd4jPointer)(sd::ConstantShapeHelper::getInstance().createFromExisting(shapeBuffer, true)); // TO DO: this can lead to unpleasant crash sometimes } catch (std::exception &e) { sd::LaunchContext::defaultContext()->errorReference()->setErrorCode(1); sd::LaunchContext::defaultContext()->errorReference()->setErrorMessage(e.what()); @@ -3612,7 +3624,7 @@ const char* runFullBenchmarkSuit(bool printOut) { } Nd4jLong getCachedMemory(int deviceId) { - return sd::ConstantHelper::getInstance()->getCachedAmount(deviceId); + return sd::ConstantHelper::getInstance().getCachedAmount(deviceId); } sd::LaunchContext* defaultLaunchContext() { diff --git a/libnd4j/include/legacy/impl/Environment.cpp b/libnd4j/include/legacy/impl/Environment.cpp index b19a7147b..38d7e82ed 100644 --- a/libnd4j/include/legacy/impl/Environment.cpp +++ b/libnd4j/include/legacy/impl/Environment.cpp @@ -214,11 +214,9 @@ namespace sd { _maxDeviceMemory = maxBytes; } - Environment *Environment::getInstance() { - if (_instance == 0) - _instance = new Environment(); - - return _instance; + Environment& Environment::getInstance() { + static Environment instance; + return instance; } bool Environment::isVerbose() { @@ -353,27 +351,27 @@ namespace sd { } void Environment::setGroupLimit(int group, Nd4jLong numBytes) { - sd::memory::MemoryCounter::getInstance()->setGroupLimit((sd::memory::MemoryType) group, numBytes); + sd::memory::MemoryCounter::getInstance().setGroupLimit((sd::memory::MemoryType) group, numBytes); } void Environment::setDeviceLimit(int deviceId, Nd4jLong numBytes) { - sd::memory::MemoryCounter::getInstance()->setDeviceLimit(deviceId, numBytes); + sd::memory::MemoryCounter::getInstance().setDeviceLimit(deviceId, numBytes); } Nd4jLong Environment::getGroupLimit(int group) { - return sd::memory::MemoryCounter::getInstance()->groupLimit((sd::memory::MemoryType) group); + return sd::memory::MemoryCounter::getInstance().groupLimit((sd::memory::MemoryType) group); } Nd4jLong Environment::getDeviceLimit(int deviceId) { - return sd::memory::MemoryCounter::getInstance()->deviceLimit(deviceId); + return sd::memory::MemoryCounter::getInstance().deviceLimit(deviceId); } Nd4jLong Environment::getGroupCounter(int group) { - return sd::memory::MemoryCounter::getInstance()->allocatedGroup((sd::memory::MemoryType) group); + return sd::memory::MemoryCounter::getInstance().allocatedGroup((sd::memory::MemoryType) group); } Nd4jLong Environment::getDeviceCounter(int deviceId) { - return sd::memory::MemoryCounter::getInstance()->allocatedDevice(deviceId); + return sd::memory::MemoryCounter::getInstance().allocatedDevice(deviceId); } uint64_t Environment::maxPrimaryMemory() { @@ -383,7 +381,4 @@ namespace sd { uint64_t Environment::maxSpecialMemory() { return _maxTotalSpecialMemory.load(); } - - sd::Environment *sd::Environment::_instance = 0; - } diff --git a/libnd4j/include/loops/cpu/broadcasting.hpp b/libnd4j/include/loops/cpu/broadcasting.hpp index c0f22313b..4c59de0ec 100644 --- a/libnd4j/include/loops/cpu/broadcasting.hpp +++ b/libnd4j/include/loops/cpu/broadcasting.hpp @@ -103,7 +103,7 @@ namespace broadcast { auto tadOffsets = xTadOffset; if (xTadShapeInfo == nullptr || tadOffsets == nullptr) { - auto tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(xShapeInfo, dimension, dimensionLength); + auto tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(xShapeInfo, dimension, dimensionLength); xTadShapeShapeInfo = tadPack.primaryShapeInfo(); tadOffsets = tadPack.primaryOffsets(); @@ -396,7 +396,7 @@ namespace broadcast { auto tadOffsets = yTadOffset; if (yTadShapeInfo == nullptr || tadOffsets == nullptr) { - auto tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(yShapeInfo, dimension, dimensionLength); + auto tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(yShapeInfo, dimension, dimensionLength); yTadShapeShapeInfo = tadPack.primaryShapeInfo(); tadOffsets = tadPack.primaryOffsets(); @@ -416,7 +416,7 @@ namespace broadcast { int tadsPerThread = tads / TAD_THRESHOLD; int threads = sd::math::nd4j_max(1, tadsPerThread); - threads = sd::math::nd4j_min(threads, sd::Environment::getInstance()->maxThreads()); + threads = sd::math::nd4j_min(threads, sd::Environment::getInstance().maxThreads()); auto yEws = shape::elementWiseStride(yTadShapeShapeInfo); auto xEws = shape::elementWiseStride(xShapeInfo); diff --git a/libnd4j/include/loops/cpu/broadcasting_bool.hpp b/libnd4j/include/loops/cpu/broadcasting_bool.hpp index 18c8705e2..a15935124 100644 --- a/libnd4j/include/loops/cpu/broadcasting_bool.hpp +++ b/libnd4j/include/loops/cpu/broadcasting_bool.hpp @@ -115,7 +115,7 @@ namespace broadcast { auto tadOffsets = xTadOffset; if (xTadShapeInfo == nullptr || tadOffsets == nullptr) { - auto tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(xShapeInfo, dimension, dimensionLength); + auto tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(xShapeInfo, dimension, dimensionLength); xTadShapeShapeInfo = const_cast(tadPack.primaryShapeInfo()); tadOffsets = const_cast(tadPack.primaryOffsets()); @@ -135,7 +135,7 @@ namespace broadcast { int tadsPerThread = tads / TAD_THRESHOLD; int threads = sd::math::nd4j_max(1, tadsPerThread); - threads = sd::math::nd4j_min(threads, sd::Environment::getInstance()->maxThreads()); + threads = sd::math::nd4j_min(threads, sd::Environment::getInstance().maxThreads()); auto xEws = shape::elementWiseStride(xTadShapeShapeInfo); auto yEws = shape::elementWiseStride(yShapeInfo); @@ -280,7 +280,7 @@ namespace broadcast { auto tadOffsets = yTadOffset; if (yTadShapeInfo == nullptr || tadOffsets == nullptr) { - auto tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(yShapeInfo, dimension, dimensionLength); + auto tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(yShapeInfo, dimension, dimensionLength); yTadShapeShapeInfo = const_cast(tadPack.primaryShapeInfo()); tadOffsets = const_cast(tadPack.primaryOffsets()); @@ -300,7 +300,7 @@ namespace broadcast { int tadsPerThread = tads / TAD_THRESHOLD; int threads = sd::math::nd4j_max(1, tadsPerThread); - threads = sd::math::nd4j_min(threads, sd::Environment::getInstance()->maxThreads()); + threads = sd::math::nd4j_min(threads, sd::Environment::getInstance().maxThreads()); auto yEws = shape::elementWiseStride(yTadShapeShapeInfo); auto xEws = shape::elementWiseStride(xShapeInfo); diff --git a/libnd4j/include/loops/cpu/broadcasting_int.hpp b/libnd4j/include/loops/cpu/broadcasting_int.hpp index 7d0a995d6..39b251594 100644 --- a/libnd4j/include/loops/cpu/broadcasting_int.hpp +++ b/libnd4j/include/loops/cpu/broadcasting_int.hpp @@ -108,7 +108,7 @@ namespace functions { auto tadOffsets = xTadOffset; if (xTadShapeInfo == nullptr || tadOffsets == nullptr) { - auto tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(xShapeInfo, dimension, dimensionLength); + auto tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(xShapeInfo, dimension, dimensionLength); xTadShapeShapeInfo = const_cast(tadPack.primaryShapeInfo()); tadOffsets = const_cast(tadPack.primaryOffsets()); @@ -128,7 +128,7 @@ namespace functions { int tadsPerThread = tads / TAD_THRESHOLD; int threads = sd::math::nd4j_max(1, tadsPerThread); - threads = sd::math::nd4j_min(threads, sd::Environment::getInstance()->maxThreads()); + threads = sd::math::nd4j_min(threads, sd::Environment::getInstance().maxThreads()); auto xEws = shape::elementWiseStride(xTadShapeShapeInfo); auto yEws = shape::elementWiseStride(yShapeInfo); @@ -271,7 +271,7 @@ namespace functions { auto tadOffsets = yTadOffset; if (yTadShapeInfo == nullptr || tadOffsets == nullptr) { - auto tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(yShapeInfo, dimension, dimensionLength); + auto tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(yShapeInfo, dimension, dimensionLength); yTadShapeShapeInfo = const_cast(tadPack.primaryShapeInfo()); tadOffsets = const_cast(tadPack.primaryOffsets()); @@ -291,7 +291,7 @@ namespace functions { int tadsPerThread = tads / TAD_THRESHOLD; int threads = sd::math::nd4j_max(1, tadsPerThread); - threads = sd::math::nd4j_min(threads, sd::Environment::getInstance()->maxThreads()); + threads = sd::math::nd4j_min(threads, sd::Environment::getInstance().maxThreads()); auto yEws = shape::elementWiseStride(yTadShapeShapeInfo); auto xEws = shape::elementWiseStride(xShapeInfo); diff --git a/libnd4j/include/loops/cpu/indexreduce.hpp b/libnd4j/include/loops/cpu/indexreduce.hpp index 9373e3feb..d46dd89d7 100644 --- a/libnd4j/include/loops/cpu/indexreduce.hpp +++ b/libnd4j/include/loops/cpu/indexreduce.hpp @@ -64,7 +64,7 @@ Nd4jLong IndexReduce::execScalar(const void *vx, const Nd4jLong *xShapeInf uint xShapeInfoCast[MAX_RANK]; bool canCastX = sd::DataTypeUtils::castShapeInfo(xShapeInfo, xShapeInfoCast); - int maxThreads = sd::math::nd4j_min(64, sd::Environment::getInstance()->maxThreads()); + int maxThreads = sd::math::nd4j_min(64, sd::Environment::getInstance().maxThreads()); IndexValue intermediatery[64]; for (int e = 0; e < maxThreads; e++) intermediatery[e].index = -1; @@ -142,7 +142,7 @@ void IndexReduce::exec(const void *vx, const Nd4jLong *xShapeInfo, if (dimensionLength < 1) return; - auto tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(xShapeInfo, dimension, dimensionLength); + auto tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(xShapeInfo, dimension, dimensionLength); tadOnlyShapeInfo = tadPack.primaryShapeInfo(); tadOffsets = tadPack.primaryOffsets(); diff --git a/libnd4j/include/loops/cpu/reduce/reduce_bool.cpp b/libnd4j/include/loops/cpu/reduce/reduce_bool.cpp index 708f3c0d7..94e156705 100644 --- a/libnd4j/include/loops/cpu/reduce/reduce_bool.cpp +++ b/libnd4j/include/loops/cpu/reduce/reduce_bool.cpp @@ -166,7 +166,7 @@ namespace functions { if (dimensionLength < 1) return; - auto tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(xShapeInfo, dimension, dimensionLength); + auto tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(xShapeInfo, dimension, dimensionLength); tadOnlyShapeInfo = tadPack.primaryShapeInfo(); tadOffsets = tadPack.primaryOffsets(); } @@ -193,7 +193,7 @@ namespace functions { Z _CUDA_H ReduceBoolFunction::execScalar(const void *vx, Nd4jLong xEws, Nd4jLong length, void *vextraParams) { auto x = reinterpret_cast(vx); auto extraParams = reinterpret_cast(vextraParams); - int maxThreads = sd::math::nd4j_min(64, sd::Environment::getInstance()->maxThreads()); + int maxThreads = sd::math::nd4j_min(64, sd::Environment::getInstance().maxThreads()); Z intermediate[64]; PRAGMA_OMP_SIMD diff --git a/libnd4j/include/loops/cpu/reduce/reduce_float.hpp b/libnd4j/include/loops/cpu/reduce/reduce_float.hpp index 1795dbc3d..6be93b1c4 100644 --- a/libnd4j/include/loops/cpu/reduce/reduce_float.hpp +++ b/libnd4j/include/loops/cpu/reduce/reduce_float.hpp @@ -70,7 +70,7 @@ namespace functions { auto startingValue = OpType::startingValue(x); uint xShapeInfoCast[MAX_RANK]; const bool canCastX = sd::DataTypeUtils::castShapeInfo(xShapeInfo, xShapeInfoCast); - int maxThreads = sd::math::nd4j_min(64, sd::Environment::getInstance()->maxThreads()); + int maxThreads = sd::math::nd4j_min(64, sd::Environment::getInstance().maxThreads()); Z intermediate[64]; PRAGMA_OMP_SIMD @@ -200,7 +200,7 @@ namespace functions { if (dimensionLength < 0) return; - auto tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(xShapeInfo, dimension, dimensionLength); + auto tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(xShapeInfo, dimension, dimensionLength); tadOnlyShapeInfo = tadPack.primaryShapeInfo(); tadOffsets = tadPack.primaryOffsets(); } @@ -229,7 +229,7 @@ namespace functions { auto x = reinterpret_cast(vx); auto extraParams = reinterpret_cast(vextraParams); - int maxThreads = sd::math::nd4j_min(64, sd::Environment::getInstance()->maxThreads()); + int maxThreads = sd::math::nd4j_min(64, sd::Environment::getInstance().maxThreads()); Z intermediate[64]; PRAGMA_OMP_SIMD diff --git a/libnd4j/include/loops/cpu/reduce/reduce_long.cpp b/libnd4j/include/loops/cpu/reduce/reduce_long.cpp index c1fd4385c..a4fae3228 100644 --- a/libnd4j/include/loops/cpu/reduce/reduce_long.cpp +++ b/libnd4j/include/loops/cpu/reduce/reduce_long.cpp @@ -65,7 +65,7 @@ namespace functions { auto startingValue = OpType::startingValue(x); uint xShapeInfoCast[MAX_RANK]; const bool canCastX = sd::DataTypeUtils::castShapeInfo(xShapeInfo, xShapeInfoCast); - int maxThreads = sd::math::nd4j_min(64, sd::Environment::getInstance()->maxThreads()); + int maxThreads = sd::math::nd4j_min(64, sd::Environment::getInstance().maxThreads()); Z intermediate[64]; PRAGMA_OMP_SIMD @@ -187,7 +187,7 @@ namespace functions { if (dimensionLength < 1) return; - auto tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(xShapeInfo, dimension, dimensionLength); + auto tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(xShapeInfo, dimension, dimensionLength); tadOnlyShapeInfo = tadPack.primaryShapeInfo(); tadOffsets = tadPack.primaryOffsets(); } @@ -215,7 +215,7 @@ namespace functions { auto x = reinterpret_cast(vx); auto extraParams = reinterpret_cast(vextraParams); - int maxThreads = sd::math::nd4j_min(64, sd::Environment::getInstance()->maxThreads()); + int maxThreads = sd::math::nd4j_min(64, sd::Environment::getInstance().maxThreads()); Z intermediate[64]; PRAGMA_OMP_SIMD diff --git a/libnd4j/include/loops/cpu/reduce/reduce_same.cpp b/libnd4j/include/loops/cpu/reduce/reduce_same.cpp index 2516767b6..10607fb6d 100644 --- a/libnd4j/include/loops/cpu/reduce/reduce_same.cpp +++ b/libnd4j/include/loops/cpu/reduce/reduce_same.cpp @@ -67,7 +67,7 @@ namespace functions { auto startingValue = OpType::startingValue(x); uint xShapeInfoCast[MAX_RANK]; const bool canCastX = sd::DataTypeUtils::castShapeInfo(xShapeInfo, xShapeInfoCast); - int maxThreads = sd::math::nd4j_min(64, sd::Environment::getInstance()->maxThreads()); + int maxThreads = sd::math::nd4j_min(64, sd::Environment::getInstance().maxThreads()); X intermediate[64]; PRAGMA_OMP_SIMD @@ -196,7 +196,7 @@ namespace functions { if (dimensionLength < 1) return; - auto tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(xShapeInfo, dimension, dimensionLength); + auto tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(xShapeInfo, dimension, dimensionLength); tadOnlyShapeInfo = tadPack.primaryShapeInfo(); tadOffsets = tadPack.primaryOffsets(); } @@ -224,7 +224,7 @@ namespace functions { auto x = reinterpret_cast(vx); auto extraParams = reinterpret_cast(vextraParams); - int maxThreads = sd::math::nd4j_min(64, sd::Environment::getInstance()->maxThreads()); + int maxThreads = sd::math::nd4j_min(64, sd::Environment::getInstance().maxThreads()); X intermediate[64]; PRAGMA_OMP_SIMD diff --git a/libnd4j/include/loops/cpu/reduce3.hpp b/libnd4j/include/loops/cpu/reduce3.hpp index 3a830377e..a19c7c1a1 100644 --- a/libnd4j/include/loops/cpu/reduce3.hpp +++ b/libnd4j/include/loops/cpu/reduce3.hpp @@ -65,7 +65,7 @@ void Reduce3::execScalar(const void *vx, const Nd4jLong *xShapeInfo, const bool canCastX = sd::DataTypeUtils::castShapeInfo(xShapeInfo, xShapeInfoCast); Z startingVal = OpType::startingValue(x); - int maxThreads = sd::math::nd4j_min(64, sd::Environment::getInstance()->maxThreads()); + int maxThreads = sd::math::nd4j_min(64, sd::Environment::getInstance().maxThreads()); Z intermediate[64]; Z extraParamsLocal[3 * 64]; diff --git a/libnd4j/include/loops/cpu/scalar.hpp b/libnd4j/include/loops/cpu/scalar.hpp index 236ba7e25..f539f387f 100644 --- a/libnd4j/include/loops/cpu/scalar.hpp +++ b/libnd4j/include/loops/cpu/scalar.hpp @@ -65,7 +65,7 @@ void ScalarTransform::transform(const void *vx, const Nd4jLong *xShapeI return; } - int num_threads = sd::math::nd4j_min(numTads, sd::Environment::getInstance()->maxThreads()); + int num_threads = sd::math::nd4j_min(numTads, sd::Environment::getInstance().maxThreads()); if (kindOfLoop == sd::LoopKind::EWS1) { for (auto r = start; r < stop; r++) { diff --git a/libnd4j/include/loops/cpu/scalar_bool.cpp b/libnd4j/include/loops/cpu/scalar_bool.cpp index 72513c10d..63182bdc3 100644 --- a/libnd4j/include/loops/cpu/scalar_bool.cpp +++ b/libnd4j/include/loops/cpu/scalar_bool.cpp @@ -66,7 +66,7 @@ namespace functions { return; } - int num_threads = sd::math::nd4j_min(numTads, sd::Environment::getInstance()->maxThreads()); + int num_threads = sd::math::nd4j_min(numTads, sd::Environment::getInstance().maxThreads()); if (kindOfLoop == sd::LoopKind::EWS1) { for (auto r = start; r < stop; r++) { diff --git a/libnd4j/include/loops/cpu/scalar_int.cpp b/libnd4j/include/loops/cpu/scalar_int.cpp index 1a8f5bcca..adf53e7f6 100644 --- a/libnd4j/include/loops/cpu/scalar_int.cpp +++ b/libnd4j/include/loops/cpu/scalar_int.cpp @@ -66,7 +66,7 @@ namespace functions { return; } - int num_threads = sd::math::nd4j_min(numTads, sd::Environment::getInstance()->maxThreads()); + int num_threads = sd::math::nd4j_min(numTads, sd::Environment::getInstance().maxThreads()); if (kindOfLoop == sd::LoopKind::EWS1) { for (auto r = start; r < stop; r++) { diff --git a/libnd4j/include/loops/cpu/summarystatsreduce.cpp b/libnd4j/include/loops/cpu/summarystatsreduce.cpp index 2d53671d2..63993d853 100644 --- a/libnd4j/include/loops/cpu/summarystatsreduce.cpp +++ b/libnd4j/include/loops/cpu/summarystatsreduce.cpp @@ -127,7 +127,7 @@ namespace functions { if (dimensionLength < 1) return; - auto tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(xShapeInfo, dimension, dimensionLength); + auto tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(xShapeInfo, dimension, dimensionLength); //pre squeezed: this is for keeping the pointer to the original //shape information for tad offset diff --git a/libnd4j/include/loops/cuda/legacy/transform.legacy b/libnd4j/include/loops/cuda/legacy/transform.legacy index e7f76751a..88a4ceb16 100644 --- a/libnd4j/include/loops/cuda/legacy/transform.legacy +++ b/libnd4j/include/loops/cuda/legacy/transform.legacy @@ -173,7 +173,7 @@ namespace functions { DISPATCH_SIMPLE(transformShaped, float16, PARAMS(x, xShape, xRank, extraParams, z, zShape, zRank, allocationPointer, reductionPointer, tadShapeInfo, tadOffsets), OPS_A(TRANSFORM_OPS)) - if (sd::Environment::getInstance()->isDebug()) + if (sd::Environment::getInstance().isDebug()) checkCudaErrors(cudaStreamSynchronize(*stream)); } diff --git a/libnd4j/include/loops/cuda/scalar.chpp b/libnd4j/include/loops/cuda/scalar.chpp index b412e4957..93b76f910 100644 --- a/libnd4j/include/loops/cuda/scalar.chpp +++ b/libnd4j/include/loops/cuda/scalar.chpp @@ -152,7 +152,7 @@ void _CUDA_H ScalarTransform::intermediateAlongDimension(dim3& launchDims template void ScalarTransform::executeCudaShaped(dim3& launchDims, cudaStream_t *stream, int opNum, void const* vx, Nd4jLong const* xShapeInfo, Nd4jLong const* hxShapeInfo, void *vz, Nd4jLong const* zShapeInfo, Nd4jLong const* hzShapeInfo, void const* vscalar, void *vextraParams) { - if (sd::Environment::getInstance()->isDebugAndVerbose()) + if (sd::Environment::getInstance().isDebugAndVerbose()) printf("H14 opNum:[%i]\n", opNum); DISPATCH_BY_OPNUM_TTT(intermediateShaped, PARAMS(launchDims, stream, vx, xShapeInfo, hxShapeInfo, vz, zShapeInfo, hzShapeInfo, vscalar, vextraParams, nullptr), SCALAR_OPS); diff --git a/libnd4j/include/loops/cuda/scalar_bool.cu b/libnd4j/include/loops/cuda/scalar_bool.cu index e23560778..0976e60ad 100644 --- a/libnd4j/include/loops/cuda/scalar_bool.cu +++ b/libnd4j/include/loops/cuda/scalar_bool.cu @@ -218,7 +218,7 @@ void ScalarBoolTransform::executeCudaShaped(dim3& launchDims, cudaStream_t void const* vscalar, void const* vextraParams) { - if (sd::Environment::getInstance()->isDebugAndVerbose()) + if (sd::Environment::getInstance().isDebugAndVerbose()) printf("H14 opNum:[%i]\n", opNum); DISPATCH_BY_OPNUM_TT(intermediateShaped, PARAMS(launchDims, stream, vx, xShapeInfo, vz, zShapeInfo, vscalar, const_cast(vextraParams), nullptr), SCALAR_BOOL_OPS); diff --git a/libnd4j/include/loops/cuda/scalar_int.cu b/libnd4j/include/loops/cuda/scalar_int.cu index 2ca0ade26..b8cac0846 100644 --- a/libnd4j/include/loops/cuda/scalar_int.cu +++ b/libnd4j/include/loops/cuda/scalar_int.cu @@ -216,7 +216,7 @@ void ScalarIntTransform::executeCudaShaped(dim3& launchDims, cudaStream_t *st void const* vscalar, void* vextraParams) { - if (sd::Environment::getInstance()->isDebugAndVerbose()) + if (sd::Environment::getInstance().isDebugAndVerbose()) printf("H14 opNum:[%i]\n", opNum); DISPATCH_BY_OPNUM_T(intermediateShaped, PARAMS(launchDims, stream, vx, xShapeInfo, vz, zShapeInfo, vscalar, vextraParams, nullptr), SCALAR_INT_OPS); diff --git a/libnd4j/include/loops/cuda/summarystatsreduce.cu b/libnd4j/include/loops/cuda/summarystatsreduce.cu index 3d94b9097..521ac5b06 100644 --- a/libnd4j/include/loops/cuda/summarystatsreduce.cu +++ b/libnd4j/include/loops/cuda/summarystatsreduce.cu @@ -344,7 +344,7 @@ void _CUDA_G summaryStatsReduceT(int op, void const* dx, Nd4jLong const* xShapeI auto z = reinterpret_cast(vz); auto reductionPointerA = reinterpret_cast(reductionBuffer); - if (sd::Environment::getInstance()->isDebugAndVerbose()) + if (sd::Environment::getInstance().isDebugAndVerbose()) printf("D16 opNum:[%i]\n", opNum); summaryStatsReduceT<<>>( @@ -369,7 +369,7 @@ void _CUDA_G summaryStatsReduceT(int op, void const* dx, Nd4jLong const* xShapeI auto z = static_cast(vz); auto extraParams = static_cast(vextraParams); - if (sd::Environment::getInstance()->isDebugAndVerbose()) + if (sd::Environment::getInstance().isDebugAndVerbose()) printf("F17 opNum:[%i]\n", opNum); auto reductionPointerA = reinterpret_cast(reductionBuffer); @@ -396,7 +396,7 @@ void _CUDA_G summaryStatsReduceT(int op, void const* dx, Nd4jLong const* xShapeI auto z = static_cast(vz); auto extraParams = static_cast(vextraParams); - if (sd::Environment::getInstance()->isDebugAndVerbose()) + if (sd::Environment::getInstance().isDebugAndVerbose()) printf("D18 opNum:[%i]\n", opNum); summaryStatsReduceT<<>>( diff --git a/libnd4j/include/memory/MemoryCounter.h b/libnd4j/include/memory/MemoryCounter.h index 91aaeecff..160c24379 100644 --- a/libnd4j/include/memory/MemoryCounter.h +++ b/libnd4j/include/memory/MemoryCounter.h @@ -34,8 +34,6 @@ namespace sd { */ class ND4J_EXPORT MemoryCounter { private: - static MemoryCounter* _INSTANCE; - // used for synchronization std::mutex _locker; @@ -56,7 +54,7 @@ namespace sd { ~MemoryCounter() = default; public: - static MemoryCounter *getInstance(); + static MemoryCounter & getInstance(); /** * This method checks if allocation of numBytes won't break through per-group or per-device limit diff --git a/libnd4j/include/memory/MemoryRegistrator.h b/libnd4j/include/memory/MemoryRegistrator.h index ad1b0333a..70afafb42 100644 --- a/libnd4j/include/memory/MemoryRegistrator.h +++ b/libnd4j/include/memory/MemoryRegistrator.h @@ -32,7 +32,6 @@ namespace sd { namespace memory { class ND4J_EXPORT MemoryRegistrator { protected: - static MemoryRegistrator* _INSTANCE; Workspace* _workspace; MAP_IMPL _footprint; std::mutex _lock; @@ -40,7 +39,7 @@ namespace sd { MemoryRegistrator(); ~MemoryRegistrator() = default; public: - static MemoryRegistrator* getInstance(); + static MemoryRegistrator& getInstance(); bool hasWorkspaceAttached(); Workspace* getWorkspace(); void attachWorkspace(Workspace* workspace); diff --git a/libnd4j/include/memory/MemoryTracker.h b/libnd4j/include/memory/MemoryTracker.h index 38bb926ca..dd99905bd 100644 --- a/libnd4j/include/memory/MemoryTracker.h +++ b/libnd4j/include/memory/MemoryTracker.h @@ -35,7 +35,6 @@ namespace sd { */ class ND4J_EXPORT MemoryTracker { private: - static MemoryTracker* _INSTANCE; std::map _allocations; std::map _released; std::mutex _locker; @@ -43,7 +42,7 @@ namespace sd { MemoryTracker(); ~MemoryTracker() = default; public: - static MemoryTracker* getInstance(); + static MemoryTracker& getInstance(); void countIn(MemoryType type, Nd4jPointer ptr, Nd4jLong numBytes); void countOut(Nd4jPointer ptr); diff --git a/libnd4j/include/memory/impl/MemoryCounter.cpp b/libnd4j/include/memory/impl/MemoryCounter.cpp index 96be34681..287b19897 100644 --- a/libnd4j/include/memory/impl/MemoryCounter.cpp +++ b/libnd4j/include/memory/impl/MemoryCounter.cpp @@ -36,19 +36,17 @@ namespace sd { } // setting initial values for limits - _groupLimits[sd::memory::MemoryType::HOST] = sd::Environment::getInstance()->maxPrimaryMemory(); - _groupLimits[sd::memory::MemoryType::DEVICE] = sd::Environment::getInstance()->maxSpecialMemory(); + _groupLimits[sd::memory::MemoryType::HOST] = sd::Environment::getInstance().maxPrimaryMemory(); + _groupLimits[sd::memory::MemoryType::DEVICE] = sd::Environment::getInstance().maxSpecialMemory(); // setting initial counter values _groupCounters[sd::memory::MemoryType::HOST] = 0; _groupCounters[sd::memory::MemoryType::DEVICE] = 0; } - MemoryCounter* MemoryCounter::getInstance() { - if (_INSTANCE == 0) - _INSTANCE = new MemoryCounter(); - - return _INSTANCE; + MemoryCounter& MemoryCounter::getInstance() { + static MemoryCounter instance; + return instance; } void MemoryCounter::countIn(int deviceId, Nd4jLong numBytes) { @@ -127,7 +125,5 @@ namespace sd { std::lock_guard lock(_locker); return _groupLimits[group]; } - - MemoryCounter* MemoryCounter::_INSTANCE = 0; } } \ No newline at end of file diff --git a/libnd4j/include/memory/impl/MemoryRegistrator.cpp b/libnd4j/include/memory/impl/MemoryRegistrator.cpp index 31b4b0eae..0ac2bf0cb 100644 --- a/libnd4j/include/memory/impl/MemoryRegistrator.cpp +++ b/libnd4j/include/memory/impl/MemoryRegistrator.cpp @@ -27,11 +27,9 @@ namespace sd { _workspace = nullptr; }; - MemoryRegistrator* MemoryRegistrator::getInstance() { - if (_INSTANCE == 0) - _INSTANCE = new MemoryRegistrator(); - - return _INSTANCE; + MemoryRegistrator& MemoryRegistrator::getInstance() { + static MemoryRegistrator instance; + return instance; } bool MemoryRegistrator::hasWorkspaceAttached() { @@ -83,8 +81,5 @@ namespace sd { return result; } - - MemoryRegistrator* MemoryRegistrator::_INSTANCE = 0; - } } \ No newline at end of file diff --git a/libnd4j/include/memory/impl/MemoryTracker.cpp b/libnd4j/include/memory/impl/MemoryTracker.cpp index 5ebb4fd16..cf2b975cf 100644 --- a/libnd4j/include/memory/impl/MemoryTracker.cpp +++ b/libnd4j/include/memory/impl/MemoryTracker.cpp @@ -40,11 +40,9 @@ namespace sd { // } - MemoryTracker* MemoryTracker::getInstance() { - if (_INSTANCE == 0) - _INSTANCE = new MemoryTracker(); - - return _INSTANCE; + MemoryTracker& MemoryTracker::getInstance() { + static MemoryTracker instance; + return instance; } #if defined(__GNUC__) && !defined(__MINGW64__) && !defined(SD_ANDROID_BUILD) && !defined(SD_IOS_BUILD) && !defined(SD_APPLE_BUILD) @@ -99,7 +97,7 @@ namespace sd { void MemoryTracker::countIn(MemoryType type, Nd4jPointer ptr, Nd4jLong numBytes) { #if defined(__GNUC__) && !defined(__MINGW64__) && !defined(SD_ANDROID_BUILD) && !defined(SD_IOS_BUILD) && !defined(SD_APPLE_BUILD) - if (Environment::getInstance()->isDetectingLeaks()) { + if (Environment::getInstance().isDetectingLeaks()) { auto lptr = reinterpret_cast(ptr); _locker.lock(); @@ -133,7 +131,7 @@ namespace sd { void MemoryTracker::countOut(Nd4jPointer ptr) { #if defined(__GNUC__) && !defined(__MINGW64__) && !defined(SD_ANDROID_BUILD) && !defined(SD_IOS_BUILD) && !defined(SD_APPLE_BUILD) - if (Environment::getInstance()->isDetectingLeaks()) { + if (Environment::getInstance().isDetectingLeaks()) { auto lptr = reinterpret_cast(ptr); _locker.lock(); @@ -172,7 +170,5 @@ namespace sd { _allocations.clear(); _released.clear(); } - - MemoryTracker* MemoryTracker::_INSTANCE = 0; } } diff --git a/libnd4j/include/ops/declarable/OpRegistrator.h b/libnd4j/include/ops/declarable/OpRegistrator.h index 3a9fb3df6..a4967d877 100644 --- a/libnd4j/include/ops/declarable/OpRegistrator.h +++ b/libnd4j/include/ops/declarable/OpRegistrator.h @@ -97,7 +97,7 @@ namespace sd { public: ~OpRegistrator(); - static OpRegistrator* getInstance(); + static OpRegistrator& getInstance(); static void exitHandler(); static void sigIntHandler(int sig); diff --git a/libnd4j/include/ops/declarable/generic/bitwise/bits_hamming_distance.cpp b/libnd4j/include/ops/declarable/generic/bitwise/bits_hamming_distance.cpp index 65f81b428..693ebf7c6 100644 --- a/libnd4j/include/ops/declarable/generic/bitwise/bits_hamming_distance.cpp +++ b/libnd4j/include/ops/declarable/generic/bitwise/bits_hamming_distance.cpp @@ -41,7 +41,7 @@ namespace sd { } DECLARE_SHAPE_FN(bits_hamming_distance) { - return SHAPELIST(ConstantShapeHelper::getInstance()->scalarShapeInfo(sd::DataType::INT64)); + return SHAPELIST(ConstantShapeHelper::getInstance().scalarShapeInfo(sd::DataType::INT64)); } DECLARE_TYPES(bits_hamming_distance) { diff --git a/libnd4j/include/ops/declarable/generic/blas/batched_gemm.cpp b/libnd4j/include/ops/declarable/generic/blas/batched_gemm.cpp index 194af35b8..79227e2ba 100644 --- a/libnd4j/include/ops/declarable/generic/blas/batched_gemm.cpp +++ b/libnd4j/include/ops/declarable/generic/blas/batched_gemm.cpp @@ -110,7 +110,7 @@ DECLARE_SHAPE_FN(batched_gemm) { auto shapeList = SHAPELIST(); if (!(M > 0 && N > 0 && K > 0 && ldA > 0 && ldB > 0 && ldC > 0 && batchSize > 0)) { - shapeList->push_back(ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(inputShape->at(0)), 'c', {1, 1})); + shapeList->push_back(ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(inputShape->at(0)), 'c', {1, 1})); return shapeList; } @@ -118,7 +118,7 @@ DECLARE_SHAPE_FN(batched_gemm) { std::vector shape({M, N}); for (int e = 0; e < batchSize; e++) { - auto newShape = ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(inputShape->at(0)), 'f', shape); + auto newShape = ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(inputShape->at(0)), 'f', shape); shapeList->push_back(newShape); } diff --git a/libnd4j/include/ops/declarable/generic/blas/matmul.cpp b/libnd4j/include/ops/declarable/generic/blas/matmul.cpp index c9d8c9476..f8ee952a8 100644 --- a/libnd4j/include/ops/declarable/generic/blas/matmul.cpp +++ b/libnd4j/include/ops/declarable/generic/blas/matmul.cpp @@ -131,7 +131,7 @@ DECLARE_SHAPE_FN(matmul) { // we just pick the higher data type out of X and Y auto dtypeZ = dtypeX > dtypeY ? dtypeX : dtypeY; - auto newShape = ConstantShapeHelper::getInstance()->createShapeInfo(dtypeZ, zOrder, zShapeOnly); + auto newShape = ConstantShapeHelper::getInstance().createShapeInfo(dtypeZ, zOrder, zShapeOnly); return SHAPELIST(newShape); } diff --git a/libnd4j/include/ops/declarable/generic/blas/tensormmul.cpp b/libnd4j/include/ops/declarable/generic/blas/tensormmul.cpp index 889bd4957..0ae64b8cd 100644 --- a/libnd4j/include/ops/declarable/generic/blas/tensormmul.cpp +++ b/libnd4j/include/ops/declarable/generic/blas/tensormmul.cpp @@ -80,7 +80,7 @@ DECLARE_SHAPE_FN(tensormmul) { std::vector shapeAt, shapeBt; auto outShape = sd::ShapeUtils::evalShapeForTensorDot(aShapeInfo, bShapeInfo, axes_0, axes_1, permutAt, permutBt, shapeAt, shapeBt); - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(ArrayOptions::dataType(aShapeInfo), 'c', outShape))); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(ArrayOptions::dataType(aShapeInfo), 'c', outShape))); } //////////////////////////////////////////////////////////////////////// diff --git a/libnd4j/include/ops/declarable/generic/boolean/choose.cpp b/libnd4j/include/ops/declarable/generic/boolean/choose.cpp index e5d67baf1..a28d8230b 100644 --- a/libnd4j/include/ops/declarable/generic/boolean/choose.cpp +++ b/libnd4j/include/ops/declarable/generic/boolean/choose.cpp @@ -86,9 +86,9 @@ namespace sd { helpers::chooseFunctorScalar(block.launchContext(), first, scalar, mode, nullptr, &numResults); } - auto newShape = ConstantShapeHelper::getInstance()->vectorShapeInfo(numResults.e(0), ArrayOptions::dataType(inputShape->at(0))); + auto newShape = ConstantShapeHelper::getInstance().vectorShapeInfo(numResults.e(0), ArrayOptions::dataType(inputShape->at(0))); - auto shapeScalar = ConstantShapeHelper::getInstance()->scalarShapeInfo(sd::DataType::INT64); + auto shapeScalar = ConstantShapeHelper::getInstance().scalarShapeInfo(sd::DataType::INT64); return SHAPELIST(newShape, shapeScalar); } diff --git a/libnd4j/include/ops/declarable/generic/boolean/where.cpp b/libnd4j/include/ops/declarable/generic/boolean/where.cpp index c26179179..a72de2ee0 100644 --- a/libnd4j/include/ops/declarable/generic/boolean/where.cpp +++ b/libnd4j/include/ops/declarable/generic/boolean/where.cpp @@ -117,7 +117,7 @@ namespace sd { theNewShape = CONSTANT(newShape); } else { - theNewShape = ConstantShapeHelper::getInstance()->emptyShapeInfo(sd::DataType::INT64); + theNewShape = ConstantShapeHelper::getInstance().emptyShapeInfo(sd::DataType::INT64); } return SHAPELIST(theNewShape); diff --git a/libnd4j/include/ops/declarable/generic/boolean/where_np.cpp b/libnd4j/include/ops/declarable/generic/boolean/where_np.cpp index 65cb52cdd..23284b2f9 100644 --- a/libnd4j/include/ops/declarable/generic/boolean/where_np.cpp +++ b/libnd4j/include/ops/declarable/generic/boolean/where_np.cpp @@ -139,11 +139,11 @@ namespace sd { // output shape - a tuple of rank(inShape) 1D tensors with numOfTrue len if (numOfTrue) { for (Nd4jLong e = 0; e < condition->rankOf(); ++e) { - shapes->push_back(ConstantShapeHelper::getInstance()->vectorShapeInfo(numOfTrue, sd::DataType::INT64)); + shapes->push_back(ConstantShapeHelper::getInstance().vectorShapeInfo(numOfTrue, sd::DataType::INT64)); } } else { - shapes->push_back(ConstantShapeHelper::getInstance()->emptyShapeInfo(sd::DataType::INT64)); + shapes->push_back(ConstantShapeHelper::getInstance().emptyShapeInfo(sd::DataType::INT64)); } } return shapes; diff --git a/libnd4j/include/ops/declarable/generic/compat/compat_sparse_to_dense.cpp b/libnd4j/include/ops/declarable/generic/compat/compat_sparse_to_dense.cpp index 95dbdfcea..a2dcd6b14 100644 --- a/libnd4j/include/ops/declarable/generic/compat/compat_sparse_to_dense.cpp +++ b/libnd4j/include/ops/declarable/generic/compat/compat_sparse_to_dense.cpp @@ -56,7 +56,7 @@ namespace sd { auto dtype = values->dataType(); // basically output shape is defined by the type of input, and desired shape input - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(dtype, 'c', shape->getBufferAsVector())); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(dtype, 'c', shape->getBufferAsVector())); } DECLARE_TYPES(compat_sparse_to_dense) { diff --git a/libnd4j/include/ops/declarable/generic/compat/compat_string_split.cpp b/libnd4j/include/ops/declarable/generic/compat/compat_string_split.cpp index 40e080a8f..009652178 100644 --- a/libnd4j/include/ops/declarable/generic/compat/compat_string_split.cpp +++ b/libnd4j/include/ops/declarable/generic/compat/compat_string_split.cpp @@ -121,8 +121,8 @@ namespace sd { // values tensor is going to be vector always // indices tensor is going to be vector with length equal to values.length * output rank - auto valuesShape = ConstantShapeHelper::getInstance()->vectorShapeInfo(cnt, sd::DataType::UTF8); - auto indicesShape = ConstantShapeHelper::getInstance()->vectorShapeInfo(cnt * (input->rankOf() + 1), sd::DataType::INT64); + auto valuesShape = ConstantShapeHelper::getInstance().vectorShapeInfo(cnt, sd::DataType::UTF8); + auto indicesShape = ConstantShapeHelper::getInstance().vectorShapeInfo(cnt * (input->rankOf() + 1), sd::DataType::INT64); return SHAPELIST(indicesShape, valuesShape); } diff --git a/libnd4j/include/ops/declarable/generic/compression/bitmap.cpp b/libnd4j/include/ops/declarable/generic/compression/bitmap.cpp index 4b77e2a45..7e89ce2c0 100644 --- a/libnd4j/include/ops/declarable/generic/compression/bitmap.cpp +++ b/libnd4j/include/ops/declarable/generic/compression/bitmap.cpp @@ -75,8 +75,8 @@ namespace sd { auto input = inputShape->at(0); auto outputLength = shape::length(input) / 16 + 5; - auto encodedShape = ConstantShapeHelper::getInstance()->vectorShapeInfo(outputLength, DataType::INT32); - auto encodedCounter = ConstantShapeHelper::getInstance()->scalarShapeInfo(DataType::INT32); + auto encodedShape = ConstantShapeHelper::getInstance().vectorShapeInfo(outputLength, DataType::INT32); + auto encodedCounter = ConstantShapeHelper::getInstance().scalarShapeInfo(DataType::INT32); return SHAPELIST(input, encodedShape, encodedCounter); } diff --git a/libnd4j/include/ops/declarable/generic/compression/threshold.cpp b/libnd4j/include/ops/declarable/generic/compression/threshold.cpp index 9512621e8..83836bb8f 100644 --- a/libnd4j/include/ops/declarable/generic/compression/threshold.cpp +++ b/libnd4j/include/ops/declarable/generic/compression/threshold.cpp @@ -65,7 +65,7 @@ namespace sd { elements = 0; // result array must have 4 additional int elements for header - return SHAPELIST(x->shapeInfo(), sd::ConstantShapeHelper::getInstance()->vectorShapeInfo(elements + 4, DataType::INT32)); + return SHAPELIST(x->shapeInfo(), sd::ConstantShapeHelper::getInstance().vectorShapeInfo(elements + 4, DataType::INT32)); } DECLARE_TYPES(encode_threshold) { diff --git a/libnd4j/include/ops/declarable/generic/datatypes/bitcast.cpp b/libnd4j/include/ops/declarable/generic/datatypes/bitcast.cpp index fe42d7057..294406cb8 100644 --- a/libnd4j/include/ops/declarable/generic/datatypes/bitcast.cpp +++ b/libnd4j/include/ops/declarable/generic/datatypes/bitcast.cpp @@ -64,11 +64,11 @@ namespace sd { auto outputSize = DataTypeUtils::sizeOf(newType); if (shape::length(inShape) == 0) - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(inShape, newType))); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(inShape, newType))); if (inputSize == outputSize) { // only type should be changed - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(inShape, newType))); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(inShape, newType))); } else if (inputSize > outputSize) { // range of output increased by 1 with inputSize / outputSize as last dimension @@ -78,7 +78,7 @@ namespace sd { shapeOf[i] = inShape[i + 1]; } shapeOf[i] = inputSize / outputSize; - auto outputShape = ConstantShapeHelper::getInstance()->createShapeInfo(newType, shape::order(inShape), shapeOf); + auto outputShape = ConstantShapeHelper::getInstance().createShapeInfo(newType, shape::order(inShape), shapeOf); return SHAPELIST(outputShape); } REQUIRE_TRUE(shape::sizeAt(inShape, -1) == outputSize / inputSize, 0, "BITCAST: %llu > %llu. So last dimension should be %i, but %i given.", inputSize, outputSize, outputSize / inputSize, shape::sizeAt(inShape, -1)); @@ -88,7 +88,7 @@ namespace sd { shapeOf[i] = inShape[i + 1]; } - auto outputShape = ConstantShapeHelper::getInstance()->createShapeInfo(newType, shape::order(inShape), shapeOf); + auto outputShape = ConstantShapeHelper::getInstance().createShapeInfo(newType, shape::order(inShape), shapeOf); return SHAPELIST(outputShape); } diff --git a/libnd4j/include/ops/declarable/generic/datatypes/cast.cpp b/libnd4j/include/ops/declarable/generic/datatypes/cast.cpp index cf8729d2f..ff071f7a9 100644 --- a/libnd4j/include/ops/declarable/generic/datatypes/cast.cpp +++ b/libnd4j/include/ops/declarable/generic/datatypes/cast.cpp @@ -49,7 +49,7 @@ namespace sd { auto it = INT_ARG(0); DataType newType = DataTypeUtils::fromInt(it); - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(inShape, newType))); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(inShape, newType))); } DECLARE_TYPES(cast) { diff --git a/libnd4j/include/ops/declarable/generic/helpers/BroadcastHelper.h b/libnd4j/include/ops/declarable/generic/helpers/BroadcastHelper.h index 7df331c4d..af7f2d8d7 100644 --- a/libnd4j/include/ops/declarable/generic/helpers/BroadcastHelper.h +++ b/libnd4j/include/ops/declarable/generic/helpers/BroadcastHelper.h @@ -40,7 +40,7 @@ namespace sd { } std::unique_ptr ptr; - if (!Environment::getInstance()->isExperimentalBuild()) { + if (!Environment::getInstance().isExperimentalBuild()) { if (y->dataType() != x->dataType()) { y = new NDArray(y->cast(x->dataType())); std::unique_ptr ptr2(y); diff --git a/libnd4j/include/ops/declarable/generic/images/crop_and_resize.cpp b/libnd4j/include/ops/declarable/generic/images/crop_and_resize.cpp index b8ce12d64..3c101070d 100644 --- a/libnd4j/include/ops/declarable/generic/images/crop_and_resize.cpp +++ b/libnd4j/include/ops/declarable/generic/images/crop_and_resize.cpp @@ -76,7 +76,7 @@ namespace sd { outputShape[2] = height; outputShape[3] = in[4]; - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(ArrayOptions::dataType(in), shape::order(in), outputShape, 4))); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(ArrayOptions::dataType(in), shape::order(in), outputShape, 4))); } DECLARE_TYPES(crop_and_resize) { diff --git a/libnd4j/include/ops/declarable/generic/images/image_resize.cpp b/libnd4j/include/ops/declarable/generic/images/image_resize.cpp index 4e680b337..8e6e29d3a 100644 --- a/libnd4j/include/ops/declarable/generic/images/image_resize.cpp +++ b/libnd4j/include/ops/declarable/generic/images/image_resize.cpp @@ -82,7 +82,7 @@ namespace sd { auto dtype = DataType::FLOAT32; if (method == helpers::ImageResizeMethods::kResizeNearest) dtype = ArrayOptions::dataType(in); - auto shape = ConstantShapeHelper::getInstance()->createShapeInfo(dtype, 'c', shape::rank(in) == 4?std::vector{in[1], height, width, in[4]}:std::vector{ height, width, in[4]}); + auto shape = ConstantShapeHelper::getInstance().createShapeInfo(dtype, 'c', shape::rank(in) == 4?std::vector{in[1], height, width, in[4]}:std::vector{ height, width, in[4]}); return SHAPELIST(shape); } diff --git a/libnd4j/include/ops/declarable/generic/images/resize_images.cpp b/libnd4j/include/ops/declarable/generic/images/resize_images.cpp index 18d048450..a26e47746 100644 --- a/libnd4j/include/ops/declarable/generic/images/resize_images.cpp +++ b/libnd4j/include/ops/declarable/generic/images/resize_images.cpp @@ -118,7 +118,7 @@ namespace sd { else if (shape::rank(in) == 3) shape = {height, width, in[3]}; - auto outShape = ConstantShapeHelper::getInstance()->createShapeInfo(DataType::FLOAT32, shape::order(in), shape); + auto outShape = ConstantShapeHelper::getInstance().createShapeInfo(DataType::FLOAT32, shape::order(in), shape); return SHAPELIST(outShape); } DECLARE_TYPES(resize_images) { diff --git a/libnd4j/include/ops/declarable/generic/images/rgbToGrs.cpp b/libnd4j/include/ops/declarable/generic/images/rgbToGrs.cpp index f7378d333..a6d80365c 100644 --- a/libnd4j/include/ops/declarable/generic/images/rgbToGrs.cpp +++ b/libnd4j/include/ops/declarable/generic/images/rgbToGrs.cpp @@ -67,7 +67,7 @@ DECLARE_SHAPE_FN(rgb_to_grs) { auto nShape = input->getShapeAsVector(); nShape[dimC] = 1; - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(input->dataType(), input->ordering(), nShape)); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(input->dataType(), input->ordering(), nShape)); } } diff --git a/libnd4j/include/ops/declarable/generic/kernels/knn_mindistance.cpp b/libnd4j/include/ops/declarable/generic/kernels/knn_mindistance.cpp index 8ef699aa2..334014ee7 100644 --- a/libnd4j/include/ops/declarable/generic/kernels/knn_mindistance.cpp +++ b/libnd4j/include/ops/declarable/generic/kernels/knn_mindistance.cpp @@ -45,7 +45,7 @@ namespace sd { auto input = inputShape->at(0); // always return scalar here - return SHAPELIST(ConstantShapeHelper::getInstance()->scalarShapeInfo(ArrayOptions::dataType(input))); + return SHAPELIST(ConstantShapeHelper::getInstance().scalarShapeInfo(ArrayOptions::dataType(input))); } DECLARE_TYPES(knn_mindistance) { diff --git a/libnd4j/include/ops/declarable/generic/linalg/diagPart.cpp b/libnd4j/include/ops/declarable/generic/linalg/diagPart.cpp index 925c4b6c1..6562a02a8 100644 --- a/libnd4j/include/ops/declarable/generic/linalg/diagPart.cpp +++ b/libnd4j/include/ops/declarable/generic/linalg/diagPart.cpp @@ -72,7 +72,7 @@ namespace ops { ShapeUtils::updateStridesAndType(outShapeInfo, inputShapeInfo, shape::order(inputShapeInfo)); - return SHAPELIST(ConstantShapeHelper::getInstance()->createFromExisting(outShapeInfo, block.workspace())); + return SHAPELIST(ConstantShapeHelper::getInstance().createFromExisting(outShapeInfo, block.workspace())); } diff --git a/libnd4j/include/ops/declarable/generic/linalg/eye.cpp b/libnd4j/include/ops/declarable/generic/linalg/eye.cpp index 41469468c..4bf339614 100644 --- a/libnd4j/include/ops/declarable/generic/linalg/eye.cpp +++ b/libnd4j/include/ops/declarable/generic/linalg/eye.cpp @@ -100,7 +100,7 @@ namespace ops { } shape::updateStrides(outShapeInfo, static_cast(-params[0])); - auto result = ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(outShapeInfo, dtype)); + auto result = ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(outShapeInfo, dtype)); RELEASE(outShapeInfo, block.getWorkspace()); return SHAPELIST(result); } diff --git a/libnd4j/include/ops/declarable/generic/linalg/lstsq.cpp b/libnd4j/include/ops/declarable/generic/linalg/lstsq.cpp index 81831e3fc..5078ff6f1 100644 --- a/libnd4j/include/ops/declarable/generic/linalg/lstsq.cpp +++ b/libnd4j/include/ops/declarable/generic/linalg/lstsq.cpp @@ -92,10 +92,10 @@ namespace sd { if (shape::isEmpty(in0) || shape::isEmpty(in1)) { shapeOf[rank - 1] = 0; // set output shape to empty } - auto resShape = ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(in0), shape::order(in1), shapeOf);//ShapeBuilders::copyShapeInfoAndType(in1, in0, true, block.workspace()); + auto resShape = ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(in0), shape::order(in1), shapeOf);//ShapeBuilders::copyShapeInfoAndType(in1, in0, true, block.workspace()); if (shapeOf[rank - 1] == 0) { // ArrayOptions::setPropertyBit(resShape, ARRAY_EMPTY); - resShape = ConstantShapeHelper::getInstance()->emptyShapeInfo(ArrayOptions::dataType(in0)); + resShape = ConstantShapeHelper::getInstance().emptyShapeInfo(ArrayOptions::dataType(in0)); } return SHAPELIST(resShape); } @@ -116,9 +116,9 @@ namespace sd { if (shape::isEmpty(in0) || shape::isEmpty(in1)) { shapeOf[rank - 1] = 0; // set output shape to empty } - auto resShape = ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(in0), shape::order(in1), shapeOf);//ShapeBuilders::copyShapeInfoAndType(in1, in0, true, block.workspace()); + auto resShape = ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(in0), shape::order(in1), shapeOf);//ShapeBuilders::copyShapeInfoAndType(in1, in0, true, block.workspace()); if (shapeOf[rank - 1] == 0) { - resShape = ConstantShapeHelper::getInstance()->emptyShapeInfo(ArrayOptions::dataType(in1)); + resShape = ConstantShapeHelper::getInstance().emptyShapeInfo(ArrayOptions::dataType(in1)); // ArrayOptions::setPropertyBit(resShape, ARRAY_EMPTY); } return SHAPELIST(resShape); diff --git a/libnd4j/include/ops/declarable/generic/linalg/matrixDiagPart.cpp b/libnd4j/include/ops/declarable/generic/linalg/matrixDiagPart.cpp index deabe8443..db73fac75 100644 --- a/libnd4j/include/ops/declarable/generic/linalg/matrixDiagPart.cpp +++ b/libnd4j/include/ops/declarable/generic/linalg/matrixDiagPart.cpp @@ -46,7 +46,7 @@ namespace sd { int lastDimension = sd::math::nd4j_min(shape::sizeAt(in, -1), shape::sizeAt(in, -2)); if(outRank == 1) { //output shape is a vector with size min(sizeAt(0), sizeAt(1)) - outShapeInfo = ConstantShapeHelper::getInstance()->vectorShapeInfo(lastDimension, ArrayOptions::dataType(in)); + outShapeInfo = ConstantShapeHelper::getInstance().vectorShapeInfo(lastDimension, ArrayOptions::dataType(in)); } else { Nd4jLong* anShapeInfo; diff --git a/libnd4j/include/ops/declarable/generic/linalg/matrix_determinant.cpp b/libnd4j/include/ops/declarable/generic/linalg/matrix_determinant.cpp index edd10e6ea..7046b69f9 100644 --- a/libnd4j/include/ops/declarable/generic/linalg/matrix_determinant.cpp +++ b/libnd4j/include/ops/declarable/generic/linalg/matrix_determinant.cpp @@ -42,13 +42,13 @@ namespace sd { int targetRank = shape::rank(inShape) - 2; // last two dimensions will be reduced to scalar if (targetRank == 0) { // scalar only - determinantShape = ConstantShapeHelper::getInstance()->scalarShapeInfo(ArrayOptions::dataType(inShape)); + determinantShape = ConstantShapeHelper::getInstance().scalarShapeInfo(ArrayOptions::dataType(inShape)); } else if (targetRank == 1) { // vector - determinantShape = ConstantShapeHelper::getInstance()->vectorShapeInfo(shape::sizeAt(inShape, 0), ArrayOptions::dataType(inShape)); + determinantShape = ConstantShapeHelper::getInstance().vectorShapeInfo(shape::sizeAt(inShape, 0), ArrayOptions::dataType(inShape)); } else { // only two last dimensions are excluded - determinantShape = ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(inShape), shape::order(inShape), targetRank, shape::shapeOf(inShape)); + determinantShape = ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(inShape), shape::order(inShape), targetRank, shape::shapeOf(inShape)); } return SHAPELIST(determinantShape); } @@ -89,13 +89,13 @@ namespace sd { int targetRank = shape::rank(inShape) - 2; // last two dimensions will be reduced to scalar if (targetRank == 0) { // scalar only - determinantShape = ConstantShapeHelper::getInstance()->scalarShapeInfo(ArrayOptions::dataType(inShape)); + determinantShape = ConstantShapeHelper::getInstance().scalarShapeInfo(ArrayOptions::dataType(inShape)); } else if (targetRank == 1) { // vector - determinantShape = ConstantShapeHelper::getInstance()->vectorShapeInfo(shape::sizeAt(inShape, 0), ArrayOptions::dataType(inShape)); + determinantShape = ConstantShapeHelper::getInstance().vectorShapeInfo(shape::sizeAt(inShape, 0), ArrayOptions::dataType(inShape)); } else { // only two last dimensions are excluded - determinantShape = ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(inShape), shape::order(inShape), targetRank, shape::shapeOf(inShape)); + determinantShape = ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(inShape), shape::order(inShape), targetRank, shape::shapeOf(inShape)); } return SHAPELIST(determinantShape); } @@ -130,13 +130,13 @@ namespace sd { int targetRank = shape::rank(inShape) - 2; // last two dimensions will be reduced to scalar if (targetRank == 0) { // scalar only - determinantShape = ConstantShapeHelper::getInstance()->scalarShapeInfo(ArrayOptions::dataType(inShape)); + determinantShape = ConstantShapeHelper::getInstance().scalarShapeInfo(ArrayOptions::dataType(inShape)); } else if (targetRank == 1) { // vector - determinantShape = ConstantShapeHelper::getInstance()->vectorShapeInfo(shape::sizeAt(inShape, 0), ArrayOptions::dataType(inShape)); + determinantShape = ConstantShapeHelper::getInstance().vectorShapeInfo(shape::sizeAt(inShape, 0), ArrayOptions::dataType(inShape)); } else { // only two last dimensions are excluded - determinantShape = ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(inShape), shape::order(inShape), targetRank, shape::shapeOf(inShape)); + determinantShape = ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(inShape), shape::order(inShape), targetRank, shape::shapeOf(inShape)); } return SHAPELIST(determinantShape); } diff --git a/libnd4j/include/ops/declarable/generic/linalg/qr.cpp b/libnd4j/include/ops/declarable/generic/linalg/qr.cpp index 9a351a13f..1cdfc6884 100644 --- a/libnd4j/include/ops/declarable/generic/linalg/qr.cpp +++ b/libnd4j/include/ops/declarable/generic/linalg/qr.cpp @@ -57,20 +57,20 @@ namespace sd { if (!fullMatricies) { // outputs are: Q is MxN and R is NxN shape[targetRank - 1] = shape::sizeAt(inShape, -1); shape[targetRank - 2] = shape[targetRank - 1]; - shapeQ = ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(inShape), + shapeQ = ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(inShape), shape::order(inShape), targetRank, shape::shapeOf(inShape)); - shapeR = ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(inShape), + shapeR = ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(inShape), shape::order(inShape), shape); } else {// otherwise outputs are Q is MxM and R is MxN with zero filled rows shape[targetRank - 1] = shape::sizeAt(inShape, -2); shape[targetRank - 2] = shape[targetRank - 1]; - shapeR = ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(inShape), + shapeR = ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(inShape), shape::order(inShape), targetRank, shape::shapeOf(inShape)); - shapeQ = ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(inShape), + shapeQ = ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(inShape), shape::order(inShape), shape); } diff --git a/libnd4j/include/ops/declarable/generic/linalg/sufficient_statistics.cpp b/libnd4j/include/ops/declarable/generic/linalg/sufficient_statistics.cpp index 9a9fb730b..915ba5fb9 100644 --- a/libnd4j/include/ops/declarable/generic/linalg/sufficient_statistics.cpp +++ b/libnd4j/include/ops/declarable/generic/linalg/sufficient_statistics.cpp @@ -71,14 +71,14 @@ namespace sd { helpers::adjustAxis(input->rankOf(), axisVector, axis); //std::vector dims = ShapeUtils::evalDimsToExclude(input->rankOf(), {axis}); - auto scalarShape = ConstantShapeHelper::getInstance()->scalarShapeInfo(ArrayOptions::dataType(inputShape->at(0))); + auto scalarShape = ConstantShapeHelper::getInstance().scalarShapeInfo(ArrayOptions::dataType(inputShape->at(0))); auto sumShape = ShapeUtils::evalReduceShapeInfo('c', axis, *input, false, false, block.workspace()); auto squareShape = ShapeUtils::evalReduceShapeInfo('c', axis, *input, false, false, block.workspace()); auto shapeList = SHAPELIST(scalarShape, sumShape, squareShape); if (block.numT() > 0) - shapeList->push_back(ConstantShapeHelper::getInstance()->scalarShapeInfo(ArrayOptions::dataType(inputShape->at(0)))); + shapeList->push_back(ConstantShapeHelper::getInstance().scalarShapeInfo(ArrayOptions::dataType(inputShape->at(0)))); return shapeList; } diff --git a/libnd4j/include/ops/declarable/generic/linalg/svd.cpp b/libnd4j/include/ops/declarable/generic/linalg/svd.cpp index ca5fd52c2..3331dcdd8 100644 --- a/libnd4j/include/ops/declarable/generic/linalg/svd.cpp +++ b/libnd4j/include/ops/declarable/generic/linalg/svd.cpp @@ -101,14 +101,14 @@ DECLARE_SHAPE_FN(svd) { shape::updateStrides(uShapeInfo, shape::order(inShapeInfo)); shape::updateStrides(vShapeInfo, shape::order(inShapeInfo)); - auto result = SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(sShapeInfo)), ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(uShapeInfo)), ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(vShapeInfo))); + auto result = SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(sShapeInfo)), ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(uShapeInfo)), ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(vShapeInfo))); RELEASE(sShapeInfo, block.workspace()); RELEASE(uShapeInfo, block.workspace()); RELEASE(vShapeInfo, block.workspace()); return result; } - return SHAPELIST(ConstantShapeHelper::getInstance()->createFromExisting(sShapeInfo, block.workspace())); + return SHAPELIST(ConstantShapeHelper::getInstance().createFromExisting(sShapeInfo, block.workspace())); } diff --git a/libnd4j/include/ops/declarable/generic/linalg/trace.cpp b/libnd4j/include/ops/declarable/generic/linalg/trace.cpp index fa9fd5f56..1a67ec754 100644 --- a/libnd4j/include/ops/declarable/generic/linalg/trace.cpp +++ b/libnd4j/include/ops/declarable/generic/linalg/trace.cpp @@ -58,7 +58,7 @@ DECLARE_SHAPE_FN(trace) { outShapeInfo[i] = inShapeInfo[i]; shape::updateStrides(outShapeInfo, shape::order(inShapeInfo)); - auto result = ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(outShapeInfo, ArrayOptions::dataType(inShapeInfo))); + auto result = ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(outShapeInfo, ArrayOptions::dataType(inShapeInfo))); RELEASE(outShapeInfo, block.getWorkspace()); return SHAPELIST(result); } diff --git a/libnd4j/include/ops/declarable/generic/linalg/tri.cpp b/libnd4j/include/ops/declarable/generic/linalg/tri.cpp index c7e1a125b..d0c1f7a6f 100644 --- a/libnd4j/include/ops/declarable/generic/linalg/tri.cpp +++ b/libnd4j/include/ops/declarable/generic/linalg/tri.cpp @@ -53,7 +53,7 @@ DECLARE_SHAPE_FN(tri) { auto dtype = block.numD() ? D_ARG(0) : DataType::FLOAT32; - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(dtype, 'c', {rows, cols})); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(dtype, 'c', {rows, cols})); } diff --git a/libnd4j/include/ops/declarable/generic/loss/absoluteDifference.cpp b/libnd4j/include/ops/declarable/generic/loss/absoluteDifference.cpp index d745b0209..0d5d1d011 100644 --- a/libnd4j/include/ops/declarable/generic/loss/absoluteDifference.cpp +++ b/libnd4j/include/ops/declarable/generic/loss/absoluteDifference.cpp @@ -121,9 +121,9 @@ DECLARE_SHAPE_FN(absolute_difference_loss) { Nd4jLong const* outShapeInfo = nullptr; if(INT_ARG(0) != 0) // in this case output is scalar - outShapeInfo = ConstantShapeHelper::getInstance()->scalarShapeInfo(outType); + outShapeInfo = ConstantShapeHelper::getInstance().scalarShapeInfo(outType); else // in this case output has the same shape as labels and predictions - outShapeInfo = ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(outType, shape::order(labelsShapeInfo), shape::shapeOf(labelsShapeInfo), shape::rank(labelsShapeInfo))); + outShapeInfo = ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(outType, shape::order(labelsShapeInfo), shape::shapeOf(labelsShapeInfo), shape::rank(labelsShapeInfo))); return SHAPELIST(outShapeInfo); } diff --git a/libnd4j/include/ops/declarable/generic/loss/cosineDistance.cpp b/libnd4j/include/ops/declarable/generic/loss/cosineDistance.cpp index 4d134f6b1..99cf2e3c1 100644 --- a/libnd4j/include/ops/declarable/generic/loss/cosineDistance.cpp +++ b/libnd4j/include/ops/declarable/generic/loss/cosineDistance.cpp @@ -143,7 +143,7 @@ DECLARE_SHAPE_FN(cosine_distance_loss) { // evaluate output shapeInfo Nd4jLong const* outShapeInfo = nullptr; if(INT_ARG(0) != 0) // in this case output is scalar - outShapeInfo = ConstantShapeHelper::getInstance()->scalarShapeInfo(outType); + outShapeInfo = ConstantShapeHelper::getInstance().scalarShapeInfo(outType); else { // in this case output has the same shape as labels reduced by dim axis std::vector dimensions = {dim}; diff --git a/libnd4j/include/ops/declarable/generic/loss/hingeLoss.cpp b/libnd4j/include/ops/declarable/generic/loss/hingeLoss.cpp index fe66387a8..71e7489ea 100644 --- a/libnd4j/include/ops/declarable/generic/loss/hingeLoss.cpp +++ b/libnd4j/include/ops/declarable/generic/loss/hingeLoss.cpp @@ -128,9 +128,9 @@ namespace sd { Nd4jLong const* outShapeInfo = nullptr; if(INT_ARG(0) != 0) // in this case output is scalar - outShapeInfo = ConstantShapeHelper::getInstance()->scalarShapeInfo(outType); + outShapeInfo = ConstantShapeHelper::getInstance().scalarShapeInfo(outType); else // in this case output has the same shape as labels and predictions - outShapeInfo = ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(outType, shape::order(labelsShapeInfo), shape::shapeOf(labelsShapeInfo), shape::rank(labelsShapeInfo))); + outShapeInfo = ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(outType, shape::order(labelsShapeInfo), shape::shapeOf(labelsShapeInfo), shape::rank(labelsShapeInfo))); return SHAPELIST(outShapeInfo); diff --git a/libnd4j/include/ops/declarable/generic/loss/huberLoss.cpp b/libnd4j/include/ops/declarable/generic/loss/huberLoss.cpp index df57092e1..2d0b44b3c 100644 --- a/libnd4j/include/ops/declarable/generic/loss/huberLoss.cpp +++ b/libnd4j/include/ops/declarable/generic/loss/huberLoss.cpp @@ -133,9 +133,9 @@ DECLARE_SHAPE_FN(huber_loss) { Nd4jLong const* outShapeInfo = nullptr; if(INT_ARG(0) != 0) // in this case output is scalar - outShapeInfo = ConstantShapeHelper::getInstance()->scalarShapeInfo(outType); + outShapeInfo = ConstantShapeHelper::getInstance().scalarShapeInfo(outType); else // in this case output has the same shape as labels and predictions - outShapeInfo = ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(outType, shape::order(labelsShapeInfo), shape::shapeOf(labelsShapeInfo), shape::rank(labelsShapeInfo))); + outShapeInfo = ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(outType, shape::order(labelsShapeInfo), shape::shapeOf(labelsShapeInfo), shape::rank(labelsShapeInfo))); return SHAPELIST(outShapeInfo); } diff --git a/libnd4j/include/ops/declarable/generic/loss/l2_loss.cpp b/libnd4j/include/ops/declarable/generic/loss/l2_loss.cpp index 3afeea2ba..48f3a64fa 100644 --- a/libnd4j/include/ops/declarable/generic/loss/l2_loss.cpp +++ b/libnd4j/include/ops/declarable/generic/loss/l2_loss.cpp @@ -38,7 +38,7 @@ namespace sd { return Status::OK(); } DECLARE_SHAPE_FN(l2_loss) { - return SHAPELIST(ConstantShapeHelper::getInstance()->scalarShapeInfo(ArrayOptions::dataType(inputShape->at(0)))); + return SHAPELIST(ConstantShapeHelper::getInstance().scalarShapeInfo(ArrayOptions::dataType(inputShape->at(0)))); } DECLARE_TYPES(l2_loss) { diff --git a/libnd4j/include/ops/declarable/generic/loss/logLoss.cpp b/libnd4j/include/ops/declarable/generic/loss/logLoss.cpp index e43e7b1d1..ab0c8923e 100644 --- a/libnd4j/include/ops/declarable/generic/loss/logLoss.cpp +++ b/libnd4j/include/ops/declarable/generic/loss/logLoss.cpp @@ -130,9 +130,9 @@ DECLARE_SHAPE_FN(log_loss) { Nd4jLong const* outShapeInfo = nullptr; if(INT_ARG(0) != 0) // in this case output is scalar - outShapeInfo = ConstantShapeHelper::getInstance()->scalarShapeInfo(outType); + outShapeInfo = ConstantShapeHelper::getInstance().scalarShapeInfo(outType); else // in this case output has the same shape as labels and predictions - outShapeInfo = ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(outType, shape::order(labelsShapeInfo), shape::shapeOf(labelsShapeInfo), shape::rank(labelsShapeInfo))); + outShapeInfo = ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(outType, shape::order(labelsShapeInfo), shape::shapeOf(labelsShapeInfo), shape::rank(labelsShapeInfo))); return SHAPELIST(outShapeInfo); } diff --git a/libnd4j/include/ops/declarable/generic/loss/log_poisson_loss.cpp b/libnd4j/include/ops/declarable/generic/loss/log_poisson_loss.cpp index b39326071..5cc6b60ab 100644 --- a/libnd4j/include/ops/declarable/generic/loss/log_poisson_loss.cpp +++ b/libnd4j/include/ops/declarable/generic/loss/log_poisson_loss.cpp @@ -133,9 +133,9 @@ namespace ops { Nd4jLong const* outShapeInfo = nullptr; if(INT_ARG(0) != 0) // in this case output is scalar - outShapeInfo = ConstantShapeHelper::getInstance()->scalarShapeInfo(outType); + outShapeInfo = ConstantShapeHelper::getInstance().scalarShapeInfo(outType); else // in this case output has the same shape as labels and predictions - outShapeInfo = ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(labelsShapeInfo, outType)); + outShapeInfo = ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(labelsShapeInfo, outType)); return SHAPELIST(outShapeInfo); } diff --git a/libnd4j/include/ops/declarable/generic/loss/meanPairWsSqErr.cpp b/libnd4j/include/ops/declarable/generic/loss/meanPairWsSqErr.cpp index 5a0e20807..f36fa3c62 100644 --- a/libnd4j/include/ops/declarable/generic/loss/meanPairWsSqErr.cpp +++ b/libnd4j/include/ops/declarable/generic/loss/meanPairWsSqErr.cpp @@ -200,7 +200,7 @@ namespace sd { Nd4jLong const* outShapeInfo = nullptr; if(INT_ARG(0) != 0) // in this case output is scalar - outShapeInfo = ConstantShapeHelper::getInstance()->scalarShapeInfo(outType); + outShapeInfo = ConstantShapeHelper::getInstance().scalarShapeInfo(outType); else { // in this case output has the shape as labels and logits minus last dimension std::vector dimensions = {-1}; outShapeInfo = ShapeUtils::evalReduceShapeInfo(shape::order(predictionsShapeInfo), dimensions, predictionsShapeInfo, false, true, block.getWorkspace()); diff --git a/libnd4j/include/ops/declarable/generic/loss/meanSqErr.cpp b/libnd4j/include/ops/declarable/generic/loss/meanSqErr.cpp index fd00a0364..6c54706c4 100644 --- a/libnd4j/include/ops/declarable/generic/loss/meanSqErr.cpp +++ b/libnd4j/include/ops/declarable/generic/loss/meanSqErr.cpp @@ -129,9 +129,9 @@ DECLARE_SHAPE_FN(mean_sqerr_loss) { Nd4jLong const* outShapeInfo = nullptr; if(INT_ARG(0) != 0) // in this case output is scalar - outShapeInfo = ConstantShapeHelper::getInstance()->scalarShapeInfo(outType); + outShapeInfo = ConstantShapeHelper::getInstance().scalarShapeInfo(outType); else // in this case output has the same shape as labels and predictions - outShapeInfo = ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(outType, shape::order(labelsShapeInfo), shape::shapeOf(labelsShapeInfo), shape::rank(labelsShapeInfo))); + outShapeInfo = ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(outType, shape::order(labelsShapeInfo), shape::shapeOf(labelsShapeInfo), shape::rank(labelsShapeInfo))); return SHAPELIST(outShapeInfo); diff --git a/libnd4j/include/ops/declarable/generic/loss/sigmCrossEntropy.cpp b/libnd4j/include/ops/declarable/generic/loss/sigmCrossEntropy.cpp index f2e665bdb..ddd28d43d 100644 --- a/libnd4j/include/ops/declarable/generic/loss/sigmCrossEntropy.cpp +++ b/libnd4j/include/ops/declarable/generic/loss/sigmCrossEntropy.cpp @@ -140,9 +140,9 @@ DECLARE_SHAPE_FN(sigm_cross_entropy_loss) { Nd4jLong const* outShapeInfo = nullptr; if(INT_ARG(0) != 0) // in this case output is scalar - outShapeInfo = ConstantShapeHelper::getInstance()->scalarShapeInfo(outType); + outShapeInfo = ConstantShapeHelper::getInstance().scalarShapeInfo(outType); else // in this case output has the same shape as labels and logits - outShapeInfo = ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(outType, shape::order(labelsShapeInfo), shape::shapeOf(labelsShapeInfo), shape::rank(labelsShapeInfo))); + outShapeInfo = ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(outType, shape::order(labelsShapeInfo), shape::shapeOf(labelsShapeInfo), shape::rank(labelsShapeInfo))); return SHAPELIST(outShapeInfo); } diff --git a/libnd4j/include/ops/declarable/generic/loss/softmaxCrossEntropy.cpp b/libnd4j/include/ops/declarable/generic/loss/softmaxCrossEntropy.cpp index f70a58a10..79d46e448 100644 --- a/libnd4j/include/ops/declarable/generic/loss/softmaxCrossEntropy.cpp +++ b/libnd4j/include/ops/declarable/generic/loss/softmaxCrossEntropy.cpp @@ -161,7 +161,7 @@ DECLARE_SHAPE_FN(softmax_cross_entropy_loss) { Nd4jLong const* outShapeInfo = nullptr; if(INT_ARG(0) != 0) // in this case output is scalar - outShapeInfo = ConstantShapeHelper::getInstance()->scalarShapeInfo(outType); + outShapeInfo = ConstantShapeHelper::getInstance().scalarShapeInfo(outType); else { // in this case output has the shape as labels and logits minus last dimension std::vector dimensions = {-1}; outShapeInfo = ShapeUtils::evalReduceShapeInfo(shape::order(logitsShapeInfo), dimensions, logitsShapeInfo, false, true, block.getWorkspace()); @@ -384,9 +384,9 @@ DECLARE_SHAPE_FN(softmax_cross_entropy_loss_grad) { auto outType = DataTypeUtils::pickFloatingType(ArrayOptions::dataType(logitsShapeInfo)); - auto dLdpShapeInfo = ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(outType, shape::order(logitsShapeInfo), shape::shapeOf(logitsShapeInfo), shape::rank(logitsShapeInfo))); - auto dLdwShapeInfo = ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(outType, shape::order(weightsShapeInfo), shape::shapeOf(weightsShapeInfo), shape::rank(weightsShapeInfo))); - auto dLdlShapeInfo = ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(outType, shape::order(labelsShapeInfo), shape::shapeOf(labelsShapeInfo), shape::rank(labelsShapeInfo))); + auto dLdpShapeInfo = ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(outType, shape::order(logitsShapeInfo), shape::shapeOf(logitsShapeInfo), shape::rank(logitsShapeInfo))); + auto dLdwShapeInfo = ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(outType, shape::order(weightsShapeInfo), shape::shapeOf(weightsShapeInfo), shape::rank(weightsShapeInfo))); + auto dLdlShapeInfo = ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(outType, shape::order(labelsShapeInfo), shape::shapeOf(labelsShapeInfo), shape::rank(labelsShapeInfo))); return SHAPELIST(dLdpShapeInfo, dLdwShapeInfo, dLdlShapeInfo); } diff --git a/libnd4j/include/ops/declarable/generic/loss/softmaxCrossEntropyWithLogits.cpp b/libnd4j/include/ops/declarable/generic/loss/softmaxCrossEntropyWithLogits.cpp index 6dab14365..0636450c7 100644 --- a/libnd4j/include/ops/declarable/generic/loss/softmaxCrossEntropyWithLogits.cpp +++ b/libnd4j/include/ops/declarable/generic/loss/softmaxCrossEntropyWithLogits.cpp @@ -127,8 +127,8 @@ DECLARE_SHAPE_FN(softmax_cross_entropy_loss_with_logits_grad) { DataType outType = DataTypeUtils::pickFloatingType(ArrayOptions::dataType(logitsShapeInfo)); - auto dLdpShapeInfo = ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(outType, shape::order(logitsShapeInfo), shape::shapeOf(logitsShapeInfo), shape::rank(logitsShapeInfo))); - auto dLdlShapeInfo = ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(outType, shape::order(labelsShapeInfo), shape::shapeOf(labelsShapeInfo), shape::rank(labelsShapeInfo))); + auto dLdpShapeInfo = ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(outType, shape::order(logitsShapeInfo), shape::shapeOf(logitsShapeInfo), shape::rank(logitsShapeInfo))); + auto dLdlShapeInfo = ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(outType, shape::order(labelsShapeInfo), shape::shapeOf(labelsShapeInfo), shape::rank(labelsShapeInfo))); return SHAPELIST(dLdpShapeInfo, dLdlShapeInfo); } diff --git a/libnd4j/include/ops/declarable/generic/nn/activations/crelu.cpp b/libnd4j/include/ops/declarable/generic/nn/activations/crelu.cpp index 539b21145..df107451a 100644 --- a/libnd4j/include/ops/declarable/generic/nn/activations/crelu.cpp +++ b/libnd4j/include/ops/declarable/generic/nn/activations/crelu.cpp @@ -61,7 +61,7 @@ namespace sd { shape.emplace_back(shape::shapeOf(inShape)[e]); shape[shape.size()-1] *= 2; - auto newShape = ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(inShape), shape::order(inShape), shape); + auto newShape = ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(inShape), shape::order(inShape), shape); return SHAPELIST(newShape); } @@ -106,7 +106,7 @@ namespace sd { DECLARE_SHAPE_FN(crelu_bp) { auto inShape = inputShape->at(0); - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(inShape))); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(inShape))); } } } diff --git a/libnd4j/include/ops/declarable/generic/nn/batchnorm.cpp b/libnd4j/include/ops/declarable/generic/nn/batchnorm.cpp index 56684c569..7018ae342 100644 --- a/libnd4j/include/ops/declarable/generic/nn/batchnorm.cpp +++ b/libnd4j/include/ops/declarable/generic/nn/batchnorm.cpp @@ -333,10 +333,10 @@ DECLARE_SHAPE_FN(batchnorm_bp) { auto shapes = SHAPELIST(); // dLdI shapeInfo - shapes->push_back(ConstantShapeHelper::getInstance()->createShapeInfo(outType, inShapeInfo)); + shapes->push_back(ConstantShapeHelper::getInstance().createShapeInfo(outType, inShapeInfo)); // dLdM shapeInfo - shapes->push_back(ConstantShapeHelper::getInstance()->createShapeInfo(outType, meanShapeInfo)); + shapes->push_back(ConstantShapeHelper::getInstance().createShapeInfo(outType, meanShapeInfo)); // dLdV shapeInfo (same as dLdM) shapes->push_back(shapes->at(shapes->size()-1)); diff --git a/libnd4j/include/ops/declarable/generic/nn/bias_add.cpp b/libnd4j/include/ops/declarable/generic/nn/bias_add.cpp index eec864c5e..bc164e952 100644 --- a/libnd4j/include/ops/declarable/generic/nn/bias_add.cpp +++ b/libnd4j/include/ops/declarable/generic/nn/bias_add.cpp @@ -58,7 +58,7 @@ DECLARE_SHAPE_FN(biasadd) { auto yShape = inputShape->at(1); auto dtype = ArrayOptions::dataType(yShape); - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(xShape, dtype))); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(xShape, dtype))); } DECLARE_TYPES(biasadd) { diff --git a/libnd4j/include/ops/declarable/generic/nn/convo/deconv2d.cpp b/libnd4j/include/ops/declarable/generic/nn/convo/deconv2d.cpp index e0440692b..d62a98d52 100644 --- a/libnd4j/include/ops/declarable/generic/nn/convo/deconv2d.cpp +++ b/libnd4j/include/ops/declarable/generic/nn/convo/deconv2d.cpp @@ -159,7 +159,7 @@ DECLARE_SHAPE_FN(deconv2d) { outputShape[3] = oC; } - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(ArrayOptions::dataType(weightsShapeInfo), shape::order(inputShapeInfo), outputShape, 4))); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(ArrayOptions::dataType(weightsShapeInfo), shape::order(inputShapeInfo), outputShape, 4))); } DECLARE_TYPES(deconv2d_bp) { diff --git a/libnd4j/include/ops/declarable/generic/nn/convo/deconv2d_tf.cpp b/libnd4j/include/ops/declarable/generic/nn/convo/deconv2d_tf.cpp index ae97c3d65..9af389bf6 100644 --- a/libnd4j/include/ops/declarable/generic/nn/convo/deconv2d_tf.cpp +++ b/libnd4j/include/ops/declarable/generic/nn/convo/deconv2d_tf.cpp @@ -144,7 +144,7 @@ DECLARE_SHAPE_FN(deconv2d_tf) { shape[3] = iC; } - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(weightsShapeInfo), shape::order(gradOShapeInfo), 4, shape)); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(weightsShapeInfo), shape::order(gradOShapeInfo), 4, shape)); } } diff --git a/libnd4j/include/ops/declarable/generic/nn/convo/dilation2d.cpp b/libnd4j/include/ops/declarable/generic/nn/convo/dilation2d.cpp index c3ecddf53..b3a0e1667 100644 --- a/libnd4j/include/ops/declarable/generic/nn/convo/dilation2d.cpp +++ b/libnd4j/include/ops/declarable/generic/nn/convo/dilation2d.cpp @@ -107,7 +107,7 @@ namespace ops { rates = r->template asVectorT(); } else { if (block.numI() < 9) { - auto newShape = ConstantShapeHelper::getInstance()->scalarShapeInfo(block.dataType()); + auto newShape = ConstantShapeHelper::getInstance().scalarShapeInfo(block.dataType()); return SHAPELIST(newShape); } @@ -127,7 +127,7 @@ namespace ops { helpers::dilation_hw(block.launchContext(), input, weights, strides, rates, isSameShape, &sH, &sW, &pH, &pW, &dH, &dW, &oH, &oW); std::array shape = {{bS, oH, oW, iC}}; - auto newShape = ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(weights), 'c', 4, shape.data()); + auto newShape = ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(weights), 'c', 4, shape.data()); return SHAPELIST(newShape); } } diff --git a/libnd4j/include/ops/declarable/generic/nn/dot_product_attention.cpp b/libnd4j/include/ops/declarable/generic/nn/dot_product_attention.cpp index c80608e03..49dc52a03 100644 --- a/libnd4j/include/ops/declarable/generic/nn/dot_product_attention.cpp +++ b/libnd4j/include/ops/declarable/generic/nn/dot_product_attention.cpp @@ -113,8 +113,8 @@ namespace ops { auto keys_shape = inputShape->at(1); auto values_shape = inputShape->at(2); - auto weights_shape = ConstantShapeHelper::getInstance()->createShapeInfo(sd::ArrayOptions::dataType(values_shape), 'c', ShapeUtils::evalShapeForMatmul(keys_shape, query_shape, true, false)); - auto output_shape = ConstantShapeHelper::getInstance()->createShapeInfo(sd::ArrayOptions::dataType(values_shape), 'c', ShapeUtils::evalShapeForMatmul(values_shape, weights_shape, false, false)); + auto weights_shape = ConstantShapeHelper::getInstance().createShapeInfo(sd::ArrayOptions::dataType(values_shape), 'c', ShapeUtils::evalShapeForMatmul(keys_shape, query_shape, true, false)); + auto output_shape = ConstantShapeHelper::getInstance().createShapeInfo(sd::ArrayOptions::dataType(values_shape), 'c', ShapeUtils::evalShapeForMatmul(values_shape, weights_shape, false, false)); if(INT_ARG(1)){ return SHAPELIST(output_shape, weights_shape); diff --git a/libnd4j/include/ops/declarable/generic/nn/embedding_lookup.cpp b/libnd4j/include/ops/declarable/generic/nn/embedding_lookup.cpp index 0888854ee..0f4a01e03 100644 --- a/libnd4j/include/ops/declarable/generic/nn/embedding_lookup.cpp +++ b/libnd4j/include/ops/declarable/generic/nn/embedding_lookup.cpp @@ -94,7 +94,7 @@ DECLARE_SHAPE_FN(embedding_lookup) { for (int e = 1; e < outRank; e++) shapeInfo[e] = shape::sizeAt(inShapeInfo, e); - auto outShapeInfo = ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(inShapeInfo), shape::order(inShapeInfo), shapeInfo); + auto outShapeInfo = ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(inShapeInfo), shape::order(inShapeInfo), shapeInfo); return SHAPELIST(outShapeInfo); } @@ -106,7 +106,7 @@ DECLARE_SHAPE_FN(embedding_lookup) { for (int e = 1; e < outRank; e++) shapeInfo[e] = shape::sizeAt(inShapeInfo, e); - auto outShapeInfo = ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(inShapeInfo), shape::order(inShapeInfo), shapeInfo); + auto outShapeInfo = ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(inShapeInfo), shape::order(inShapeInfo), shapeInfo); return SHAPELIST(outShapeInfo); } diff --git a/libnd4j/include/ops/declarable/generic/nn/multi_head_dot_product_attention.cpp b/libnd4j/include/ops/declarable/generic/nn/multi_head_dot_product_attention.cpp index f9b7284f1..7ff8eb4c5 100644 --- a/libnd4j/include/ops/declarable/generic/nn/multi_head_dot_product_attention.cpp +++ b/libnd4j/include/ops/declarable/generic/nn/multi_head_dot_product_attention.cpp @@ -138,8 +138,8 @@ namespace ops { auto numHeads = shape::sizeAt(WkShape, 0); auto timeSteps = shape::sizeAt(keysShape, 2); - auto weightsShape = ConstantShapeHelper::getInstance()->createShapeInfo(sd::ArrayOptions::dataType(valuesShape), 'c', {batchSize, numHeads, timeSteps, queryCount}); - auto outputShape = ConstantShapeHelper::getInstance()->createShapeInfo(sd::ArrayOptions::dataType(valuesShape), 'c', {batchSize, outSize, queryCount}); + auto weightsShape = ConstantShapeHelper::getInstance().createShapeInfo(sd::ArrayOptions::dataType(valuesShape), 'c', {batchSize, numHeads, timeSteps, queryCount}); + auto outputShape = ConstantShapeHelper::getInstance().createShapeInfo(sd::ArrayOptions::dataType(valuesShape), 'c', {batchSize, outSize, queryCount}); if(INT_ARG(1)){ return SHAPELIST(outputShape, weightsShape); diff --git a/libnd4j/include/ops/declarable/generic/nn/pooling/avgpool2d.cpp b/libnd4j/include/ops/declarable/generic/nn/pooling/avgpool2d.cpp index b93cbe47f..fde075667 100644 --- a/libnd4j/include/ops/declarable/generic/nn/pooling/avgpool2d.cpp +++ b/libnd4j/include/ops/declarable/generic/nn/pooling/avgpool2d.cpp @@ -133,7 +133,7 @@ DECLARE_SHAPE_FN(avgpool2d) { newShape[3] = iD; } - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(ArrayOptions::dataType(inShape), shape::order(inShape), newShape, 4))); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(ArrayOptions::dataType(inShape), shape::order(inShape), newShape, 4))); } DECLARE_TYPES(avgpool2d_bp) { @@ -210,7 +210,7 @@ DECLARE_SHAPE_FN(avgpool2d_bp) { REQUIRE_TRUE(inputShape->at(0)[0] == 4, 0, "AVGPOOL2D_BP op: input array must be 4D, but got %i instead!", inputShape->at(0)[0]); REQUIRE_TRUE(inputShape->at(1)[0] == 4, 0, "AVGPOOL2D_BP op: output's gradient array (next epsilon) must be 4D, but got %i instead!", inputShape->at(1)[0]); - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(inputShape->at(0), ArrayOptions::dataType(inputShape->at(1))))); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(inputShape->at(0), ArrayOptions::dataType(inputShape->at(1))))); } diff --git a/libnd4j/include/ops/declarable/generic/nn/pooling/avgpool3d.cpp b/libnd4j/include/ops/declarable/generic/nn/pooling/avgpool3d.cpp index 85b8d8833..d8df11385 100644 --- a/libnd4j/include/ops/declarable/generic/nn/pooling/avgpool3d.cpp +++ b/libnd4j/include/ops/declarable/generic/nn/pooling/avgpool3d.cpp @@ -135,7 +135,7 @@ DECLARE_SHAPE_FN(avgpool3dnew) { outputShape[4] = iC; } // TF DOC: A Tensor. Has the same type as input. - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(ArrayOptions::dataType(inputShapeInfo), shape::order(inputShapeInfo), outputShape, 5))); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(ArrayOptions::dataType(inputShapeInfo), shape::order(inputShapeInfo), outputShape, 5))); } DECLARE_TYPES(avgpool3dnew_bp) { @@ -202,7 +202,7 @@ CUSTOM_OP_IMPL(avgpool3dnew_bp, 2, 1, false, 0, 14) { DECLARE_SHAPE_FN(avgpool3dnew_bp) { - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(inputShape->at(0), ArrayOptions::dataType(inputShape->at(1))))); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(inputShape->at(0), ArrayOptions::dataType(inputShape->at(1))))); } diff --git a/libnd4j/include/ops/declarable/generic/nn/pooling/maxpool2d.cpp b/libnd4j/include/ops/declarable/generic/nn/pooling/maxpool2d.cpp index 31dd72fc3..8a37b90b0 100644 --- a/libnd4j/include/ops/declarable/generic/nn/pooling/maxpool2d.cpp +++ b/libnd4j/include/ops/declarable/generic/nn/pooling/maxpool2d.cpp @@ -136,7 +136,7 @@ DECLARE_SHAPE_FN(maxpool2d) { newShape[3] = iC; } - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(ArrayOptions::dataType(inShape), order, newShape, 4))); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(ArrayOptions::dataType(inShape), order, newShape, 4))); } DECLARE_TYPES(maxpool2d_bp) { @@ -215,7 +215,7 @@ DECLARE_SHAPE_FN(maxpool2d_bp) { REQUIRE_TRUE(inputShape->at(0)[0] == 4, 0, "MAXPOOL2D_BP op: input array must be 4D, but got %i instead!", inputShape->at(0)[0]); REQUIRE_TRUE(inputShape->at(1)[0] == 4, 0, "MAXPOOL2D_BP op: output's gradient array (next epsilon) must be 4D, but got %i instead!", inputShape->at(1)[0]); - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(inputShape->at(0), ArrayOptions::dataType(inputShape->at(1))))); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(inputShape->at(0), ArrayOptions::dataType(inputShape->at(1))))); } diff --git a/libnd4j/include/ops/declarable/generic/nn/pooling/maxpool3d.cpp b/libnd4j/include/ops/declarable/generic/nn/pooling/maxpool3d.cpp index d1b5928b6..fd28901cc 100644 --- a/libnd4j/include/ops/declarable/generic/nn/pooling/maxpool3d.cpp +++ b/libnd4j/include/ops/declarable/generic/nn/pooling/maxpool3d.cpp @@ -137,7 +137,7 @@ DECLARE_SHAPE_FN(maxpool3dnew) { outputShape[4] = iC; } - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(ArrayOptions::dataType(inputShapeInfo), shape::order(inputShapeInfo), outputShape, 5))); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(ArrayOptions::dataType(inputShapeInfo), shape::order(inputShapeInfo), outputShape, 5))); } DECLARE_TYPES(maxpool3dnew_bp) { @@ -217,7 +217,7 @@ CUSTOM_OP_IMPL(maxpool3dnew_bp, 2, 1, false, 0, 14) { DECLARE_SHAPE_FN(maxpool3dnew_bp) { - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(inputShape->at(0), ArrayOptions::dataType(inputShape->at(1))))); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(inputShape->at(0), ArrayOptions::dataType(inputShape->at(1))))); } diff --git a/libnd4j/include/ops/declarable/generic/nn/pooling/maxpool_with_argmax.cpp b/libnd4j/include/ops/declarable/generic/nn/pooling/maxpool_with_argmax.cpp index 111846584..eced3c2b4 100644 --- a/libnd4j/include/ops/declarable/generic/nn/pooling/maxpool_with_argmax.cpp +++ b/libnd4j/include/ops/declarable/generic/nn/pooling/maxpool_with_argmax.cpp @@ -53,8 +53,8 @@ namespace sd { DECLARE_SHAPE_FN(max_pool_with_argmax) { auto in = inputShape->at(0); - auto valuesShape = ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(in)); - auto indicesShape = ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(in, DataType::INT64)); + auto valuesShape = ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(in)); + auto indicesShape = ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(in, DataType::INT64)); return SHAPELIST(valuesShape, indicesShape); } diff --git a/libnd4j/include/ops/declarable/generic/nn/pooling/pnormpool2d.cpp b/libnd4j/include/ops/declarable/generic/nn/pooling/pnormpool2d.cpp index adcd40daa..927627ff8 100644 --- a/libnd4j/include/ops/declarable/generic/nn/pooling/pnormpool2d.cpp +++ b/libnd4j/include/ops/declarable/generic/nn/pooling/pnormpool2d.cpp @@ -130,7 +130,7 @@ namespace sd { newShape[3] = iC; } - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(ArrayOptions::dataType(inShape), order, newShape, 4))); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(ArrayOptions::dataType(inShape), order, newShape, 4))); } @@ -225,7 +225,7 @@ DECLARE_SHAPE_FN(pnormpool2d_bp) { REQUIRE_TRUE(inputShape->at(0)[0] == 4, 0, "PNORMPOOL2D_BP op: input array must be 4D, but got %i instead!", inputShape->at(0)[0]); REQUIRE_TRUE(inputShape->at(1)[0] == 4, 0, "PNORMPOOL2D_BP op: output's gradient array (next epsilon) must be 4D, but got %i instead!", inputShape->at(1)[0]); - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(inputShape->at(0), ArrayOptions::dataType(inputShape->at(1))))); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(inputShape->at(0), ArrayOptions::dataType(inputShape->at(1))))); } } diff --git a/libnd4j/include/ops/declarable/generic/nn/recurrent/gru.cpp b/libnd4j/include/ops/declarable/generic/nn/recurrent/gru.cpp index a0b1e707b..0be3c8393 100644 --- a/libnd4j/include/ops/declarable/generic/nn/recurrent/gru.cpp +++ b/libnd4j/include/ops/declarable/generic/nn/recurrent/gru.cpp @@ -91,7 +91,7 @@ DECLARE_SHAPE_FN(gru) { REQUIRE_TRUE(Wh->isSameShape(whCorrectShape), 0, "GRU operation: wrong shape of hidden-to-hidden weights array, expected is %s, but got %s instead !", ShapeUtils::shapeAsString(whCorrectShape).c_str(), ShapeUtils::shapeAsString(Wh).c_str()); REQUIRE_TRUE(b->isSameShape(bCorrectShape), 0, "GRU operation: wrong shape of biases array, expected is %s, but got %s instead !", ShapeUtils::shapeAsString(bCorrectShape).c_str(), ShapeUtils::shapeAsString(b).c_str()); - auto hShapeInfo = ConstantShapeHelper::getInstance()->createShapeInfo(hI->dataType(), hI->ordering(), {time, bS, nOut}); + auto hShapeInfo = ConstantShapeHelper::getInstance().createShapeInfo(hI->dataType(), hI->ordering(), {time, bS, nOut}); return SHAPELIST(hShapeInfo); } @@ -173,11 +173,11 @@ DECLARE_SHAPE_FN(gru_bp) { REQUIRE_TRUE(b->isSameShape(bCorrectShape), 0, "GRU_BP operation: wrong shape of biases array, expected is %s, but got %s instead !", ShapeUtils::shapeAsString(bCorrectShape).c_str(), ShapeUtils::shapeAsString(b).c_str()); REQUIRE_TRUE(dLdh->isSameShape(hCorrectShape),0, "GRU_BP operation: wrong shape of gradient vs. ff output, expected is %s, but got %s instead !", ShapeUtils::shapeAsString(hCorrectShape).c_str(), ShapeUtils::shapeAsString(dLdh).c_str()); - auto dLdxShapeInfo = ConstantShapeHelper::getInstance()->createShapeInfo(dLdh->dataType(), x->shapeInfo()); - auto dLdhIShapeInfo = ConstantShapeHelper::getInstance()->createShapeInfo(dLdh->dataType(), hI->shapeInfo()); - auto dLdWxShapeInfo = ConstantShapeHelper::getInstance()->createShapeInfo(dLdh->dataType(), Wx->shapeInfo()); - auto dLdWhShapeInfo = ConstantShapeHelper::getInstance()->createShapeInfo(dLdh->dataType(), Wh->shapeInfo()); - auto dLdbShapeInfo = ConstantShapeHelper::getInstance()->createShapeInfo(dLdh->dataType(), b->shapeInfo()); + auto dLdxShapeInfo = ConstantShapeHelper::getInstance().createShapeInfo(dLdh->dataType(), x->shapeInfo()); + auto dLdhIShapeInfo = ConstantShapeHelper::getInstance().createShapeInfo(dLdh->dataType(), hI->shapeInfo()); + auto dLdWxShapeInfo = ConstantShapeHelper::getInstance().createShapeInfo(dLdh->dataType(), Wx->shapeInfo()); + auto dLdWhShapeInfo = ConstantShapeHelper::getInstance().createShapeInfo(dLdh->dataType(), Wh->shapeInfo()); + auto dLdbShapeInfo = ConstantShapeHelper::getInstance().createShapeInfo(dLdh->dataType(), b->shapeInfo()); return SHAPELIST(dLdxShapeInfo, dLdhIShapeInfo, dLdWxShapeInfo, dLdWhShapeInfo, dLdbShapeInfo); } diff --git a/libnd4j/include/ops/declarable/generic/nn/recurrent/gruCell.cpp b/libnd4j/include/ops/declarable/generic/nn/recurrent/gruCell.cpp index 037f09736..25c8d3744 100644 --- a/libnd4j/include/ops/declarable/generic/nn/recurrent/gruCell.cpp +++ b/libnd4j/include/ops/declarable/generic/nn/recurrent/gruCell.cpp @@ -111,7 +111,7 @@ DECLARE_SHAPE_FN(gruCell) { s0[2] = nU; ShapeUtils::updateStridesAndType(s0, x, shape::order(hLast)); - auto ts0 = ConstantShapeHelper::getInstance()->createFromExisting(s0, block.workspace()); + auto ts0 = ConstantShapeHelper::getInstance().createFromExisting(s0, block.workspace()); //4 output shapes, all [bs, nU] return SHAPELIST(ts0, ts0, ts0, ts0); diff --git a/libnd4j/include/ops/declarable/generic/nn/recurrent/lstmCell.cpp b/libnd4j/include/ops/declarable/generic/nn/recurrent/lstmCell.cpp index 20a9e6710..32cb481ee 100644 --- a/libnd4j/include/ops/declarable/generic/nn/recurrent/lstmCell.cpp +++ b/libnd4j/include/ops/declarable/generic/nn/recurrent/lstmCell.cpp @@ -136,7 +136,7 @@ DECLARE_SHAPE_FN(lstmCell) { ShapeUtils::updateStridesAndType(hShapeInfo, xtShapeInfo, shape::order(ht_1ShapeInfo)); ShapeUtils::updateStridesAndType(cShapeInfo, xtShapeInfo, shape::order(ct_1ShapeInfo)); - auto result = SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(hShapeInfo), ConstantShapeHelper::getInstance()->createShapeInfo(cShapeInfo)); + auto result = SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(hShapeInfo), ConstantShapeHelper::getInstance().createShapeInfo(cShapeInfo)); RELEASE(hShapeInfo, block.workspace()); RELEASE(cShapeInfo, block.workspace()); return result; diff --git a/libnd4j/include/ops/declarable/generic/nn/recurrent/lstmLayer.cpp b/libnd4j/include/ops/declarable/generic/nn/recurrent/lstmLayer.cpp index a5c8b8d28..0a0754a8e 100644 --- a/libnd4j/include/ops/declarable/generic/nn/recurrent/lstmLayer.cpp +++ b/libnd4j/include/ops/declarable/generic/nn/recurrent/lstmLayer.cpp @@ -362,7 +362,7 @@ DECLARE_SHAPE_FN(lstmLayer) { hShape = {sL, 2, bS, nOut}; } - shapes->push_back(ConstantShapeHelper::getInstance()->createShapeInfo(type, x->ordering(), hShape)); + shapes->push_back(ConstantShapeHelper::getInstance().createShapeInfo(type, x->ordering(), hShape)); } // evaluate hL shape (output at last step) @@ -375,7 +375,7 @@ DECLARE_SHAPE_FN(lstmLayer) { else hLShape = {2, bS, nOut}; - shapes->push_back(ConstantShapeHelper::getInstance()->createShapeInfo(type, x->ordering(), hLShape)); + shapes->push_back(ConstantShapeHelper::getInstance().createShapeInfo(type, x->ordering(), hLShape)); if(retLastC) // cL and hL have same shapes shapes->push_back(shapes->at(shapes->size() - 1)); @@ -391,7 +391,7 @@ DECLARE_SHAPE_FN(lstmLayer) { else cLShape = {2, bS, nOut}; - shapes->push_back(ConstantShapeHelper::getInstance()->createShapeInfo(type, x->ordering(), cLShape)); + shapes->push_back(ConstantShapeHelper::getInstance().createShapeInfo(type, x->ordering(), cLShape)); } return shapes; diff --git a/libnd4j/include/ops/declarable/generic/nn/recurrent/sru.cpp b/libnd4j/include/ops/declarable/generic/nn/recurrent/sru.cpp index 84dd6356a..ba4e3d52f 100644 --- a/libnd4j/include/ops/declarable/generic/nn/recurrent/sru.cpp +++ b/libnd4j/include/ops/declarable/generic/nn/recurrent/sru.cpp @@ -127,7 +127,7 @@ DECLARE_SHAPE_FN(sru) { ShapeUtils::updateStridesAndType(newShapeInfo1, xShapeInfo, shape::order(xShapeInfo)); ShapeDescriptor descriptor(newShapeInfo1); RELEASE(newShapeInfo1, block.getWorkspace()); - auto result = ConstantShapeHelper::getInstance()->createShapeInfo(descriptor); + auto result = ConstantShapeHelper::getInstance().createShapeInfo(descriptor); return SHAPELIST(result, result); } @@ -311,7 +311,7 @@ DECLARE_SHAPE_FN(sru_bp) { ShapeDescriptor descriptor3(ArrayOptions::dataType(inShape), order, {1, 2 * inSize}); ShapeDescriptor descriptor4(ArrayOptions::dataType(inShape), order, {bS, inSize}); - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(descriptor1), ConstantShapeHelper::getInstance()->createShapeInfo(descriptor2), ConstantShapeHelper::getInstance()->createShapeInfo(descriptor3), ConstantShapeHelper::getInstance()->createShapeInfo(descriptor4)); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(descriptor1), ConstantShapeHelper::getInstance().createShapeInfo(descriptor2), ConstantShapeHelper::getInstance().createShapeInfo(descriptor3), ConstantShapeHelper::getInstance().createShapeInfo(descriptor4)); } @@ -396,7 +396,7 @@ DECLARE_SHAPE_FN(sru_bi) { char order = shape::order(xShapeInfo); ShapeDescriptor descriptor(ArrayOptions::dataType(xShapeInfo), order, {time, bS, 2 * inSize}); - auto result = ConstantShapeHelper::getInstance()->createShapeInfo(descriptor); + auto result = ConstantShapeHelper::getInstance().createShapeInfo(descriptor); return SHAPELIST(result, result); } @@ -505,7 +505,7 @@ DECLARE_SHAPE_FN(sru_bi_bp) { ShapeDescriptor descriptor3(ArrayOptions::dataType(xShapeInfo), order, {4 * inSize}); ShapeDescriptor descriptor4(ArrayOptions::dataType(xShapeInfo), order, {bS, 2 * inSize}); - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(descriptor1), ConstantShapeHelper::getInstance()->createShapeInfo(descriptor2), ConstantShapeHelper::getInstance()->createShapeInfo(descriptor3), ConstantShapeHelper::getInstance()->createShapeInfo(descriptor4)); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(descriptor1), ConstantShapeHelper::getInstance().createShapeInfo(descriptor2), ConstantShapeHelper::getInstance().createShapeInfo(descriptor3), ConstantShapeHelper::getInstance().createShapeInfo(descriptor4)); } } @@ -771,7 +771,7 @@ DECLARE_SHAPE_FN(sru_bi_bp) { // ShapeUtils::updateStridesAndType(newShapeInfo1, inShape, order); -// auto result = ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(newShapeInfo1)); +// auto result = ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(newShapeInfo1)); // RELEASE(newShapeInfo1, block.getWorkspace()); // return SHAPELIST(result, result); // } @@ -935,5 +935,5 @@ DECLARE_SHAPE_FN(sru_bi_bp) { // ShapeDescriptor descriptor3(ArrayOptions::dataType(inShape), order, {1, 2 * inSize}); // ShapeDescriptor descriptor4(ArrayOptions::dataType(inShape), order, {bS, inSize}); -// return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(descriptor1), ConstantShapeHelper::getInstance()->createShapeInfo(descriptor2), ConstantShapeHelper::getInstance()->createShapeInfo(descriptor3), ConstantShapeHelper::getInstance()->createShapeInfo(descriptor4)); +// return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(descriptor1), ConstantShapeHelper::getInstance().createShapeInfo(descriptor2), ConstantShapeHelper::getInstance().createShapeInfo(descriptor3), ConstantShapeHelper::getInstance().createShapeInfo(descriptor4)); // } diff --git a/libnd4j/include/ops/declarable/generic/nn/recurrent/sruCell.cpp b/libnd4j/include/ops/declarable/generic/nn/recurrent/sruCell.cpp index ee446037c..3268da453 100644 --- a/libnd4j/include/ops/declarable/generic/nn/recurrent/sruCell.cpp +++ b/libnd4j/include/ops/declarable/generic/nn/recurrent/sruCell.cpp @@ -97,7 +97,7 @@ DECLARE_SHAPE_FN(sruCell) { ShapeUtils::updateStridesAndType(hShapeInfo, ct_1ShapeInfo, shape::order(ct_1ShapeInfo)); ShapeUtils::updateStridesAndType(cShapeInfo, ct_1ShapeInfo, shape::order(ct_1ShapeInfo)); - return SHAPELIST(ConstantShapeHelper::getInstance()->createFromExisting(hShapeInfo, block.workspace()), ConstantShapeHelper::getInstance()->createFromExisting(cShapeInfo, block.workspace())); + return SHAPELIST(ConstantShapeHelper::getInstance().createFromExisting(hShapeInfo, block.workspace()), ConstantShapeHelper::getInstance().createFromExisting(cShapeInfo, block.workspace())); } diff --git a/libnd4j/include/ops/declarable/generic/parity_ops/bincount.cpp b/libnd4j/include/ops/declarable/generic/parity_ops/bincount.cpp index 3b9fc3916..45b864f26 100644 --- a/libnd4j/include/ops/declarable/generic/parity_ops/bincount.cpp +++ b/libnd4j/include/ops/declarable/generic/parity_ops/bincount.cpp @@ -111,7 +111,7 @@ namespace sd { outLength = sd::math::nd4j_min(outLength, max->e(0)); } - auto newshape = ConstantShapeHelper::getInstance()->vectorShapeInfo(outLength, dtype); + auto newshape = ConstantShapeHelper::getInstance().vectorShapeInfo(outLength, dtype); shapeList->push_back(newshape); return shapeList; diff --git a/libnd4j/include/ops/declarable/generic/parity_ops/broadcast_dynamic_shape.cpp b/libnd4j/include/ops/declarable/generic/parity_ops/broadcast_dynamic_shape.cpp index 4fc31dd51..d954a0b44 100644 --- a/libnd4j/include/ops/declarable/generic/parity_ops/broadcast_dynamic_shape.cpp +++ b/libnd4j/include/ops/declarable/generic/parity_ops/broadcast_dynamic_shape.cpp @@ -82,7 +82,7 @@ DECLARE_SHAPE_FN(broadcast_dynamic_shape) { const int maxRank = xRank > yRank ? xRank : yRank; - auto outputShapeInfo = ConstantShapeHelper::getInstance()->vectorShapeInfo(maxRank, ArrayOptions::dataType(inputShape->at(0))); + auto outputShapeInfo = ConstantShapeHelper::getInstance().vectorShapeInfo(maxRank, ArrayOptions::dataType(inputShape->at(0))); return SHAPELIST(outputShapeInfo); } diff --git a/libnd4j/include/ops/declarable/generic/parity_ops/check_numerics.cpp b/libnd4j/include/ops/declarable/generic/parity_ops/check_numerics.cpp index 561c6bb5b..3d06d4ced 100644 --- a/libnd4j/include/ops/declarable/generic/parity_ops/check_numerics.cpp +++ b/libnd4j/include/ops/declarable/generic/parity_ops/check_numerics.cpp @@ -41,7 +41,7 @@ namespace sd { } DECLARE_SHAPE_FN(check_numerics) { - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(inputShape->at(0)))); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(inputShape->at(0)))); } DECLARE_TYPES(check_numerics) { diff --git a/libnd4j/include/ops/declarable/generic/parity_ops/compare_and_bitpack.cpp b/libnd4j/include/ops/declarable/generic/parity_ops/compare_and_bitpack.cpp index 1decc65f0..f694502b3 100644 --- a/libnd4j/include/ops/declarable/generic/parity_ops/compare_and_bitpack.cpp +++ b/libnd4j/include/ops/declarable/generic/parity_ops/compare_and_bitpack.cpp @@ -53,7 +53,7 @@ namespace sd { auto inShape = inputShape->at(0); DataType newType = DataType::UINT8; - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(inShape, newType))); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(inShape, newType))); } } diff --git a/libnd4j/include/ops/declarable/generic/parity_ops/confusion_matrix.cpp b/libnd4j/include/ops/declarable/generic/parity_ops/confusion_matrix.cpp index f90513ca3..f5c5cbb91 100644 --- a/libnd4j/include/ops/declarable/generic/parity_ops/confusion_matrix.cpp +++ b/libnd4j/include/ops/declarable/generic/parity_ops/confusion_matrix.cpp @@ -77,7 +77,7 @@ namespace sd { } std::array shape = {{numClasses,numClasses}}; - auto newShape = ConstantShapeHelper::getInstance()->createShapeInfo(dtype, 'c', 2, shape.data()); + auto newShape = ConstantShapeHelper::getInstance().createShapeInfo(dtype, 'c', 2, shape.data()); return SHAPELIST(newShape); } } diff --git a/libnd4j/include/ops/declarable/generic/parity_ops/expose.cpp b/libnd4j/include/ops/declarable/generic/parity_ops/expose.cpp index fd3315157..d9c931f21 100644 --- a/libnd4j/include/ops/declarable/generic/parity_ops/expose.cpp +++ b/libnd4j/include/ops/declarable/generic/parity_ops/expose.cpp @@ -61,7 +61,7 @@ namespace sd { auto var = block.getVariable(e); if (var->variableType() == VariableType::NDARRAY) { auto inShape = inputShape->at(e); - shapeList->push_back(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(inShape))); + shapeList->push_back(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(inShape))); } } diff --git a/libnd4j/include/ops/declarable/generic/parity_ops/in_top_k.cpp b/libnd4j/include/ops/declarable/generic/parity_ops/in_top_k.cpp index a243842d2..7618de5b1 100644 --- a/libnd4j/include/ops/declarable/generic/parity_ops/in_top_k.cpp +++ b/libnd4j/include/ops/declarable/generic/parity_ops/in_top_k.cpp @@ -46,7 +46,7 @@ namespace sd { auto in = inputShape->at(1); int shapeRank = shape::rank(in); - auto aShape = ConstantShapeHelper::getInstance()->createShapeInfo(sd::DataType::BOOL, shape::order(in), shape::rank(in), shape::shapeOf(in)); + auto aShape = ConstantShapeHelper::getInstance().createShapeInfo(sd::DataType::BOOL, shape::order(in), shape::rank(in), shape::shapeOf(in)); shapeList->push_back(aShape); return shapeList; } diff --git a/libnd4j/include/ops/declarable/generic/parity_ops/listdiff.cpp b/libnd4j/include/ops/declarable/generic/parity_ops/listdiff.cpp index 49c7a2957..86a37619e 100644 --- a/libnd4j/include/ops/declarable/generic/parity_ops/listdiff.cpp +++ b/libnd4j/include/ops/declarable/generic/parity_ops/listdiff.cpp @@ -54,8 +54,8 @@ namespace sd { REQUIRE_TRUE(saved > 0, 0, "ListDiff: no matches found"); - auto shapeX = ConstantShapeHelper::getInstance()->vectorShapeInfo(saved, values->dataType()); - auto shapeY = ConstantShapeHelper::getInstance()->vectorShapeInfo(saved, DataType::INT64); + auto shapeX = ConstantShapeHelper::getInstance().vectorShapeInfo(saved, values->dataType()); + auto shapeY = ConstantShapeHelper::getInstance().vectorShapeInfo(saved, DataType::INT64); return SHAPELIST(shapeX, shapeY); } diff --git a/libnd4j/include/ops/declarable/generic/parity_ops/non_max_suppression.cpp b/libnd4j/include/ops/declarable/generic/parity_ops/non_max_suppression.cpp index ecddab3bc..91512b2f7 100644 --- a/libnd4j/include/ops/declarable/generic/parity_ops/non_max_suppression.cpp +++ b/libnd4j/include/ops/declarable/generic/parity_ops/non_max_suppression.cpp @@ -106,7 +106,7 @@ namespace sd { if (actualIndicesCount < maxOutputSize) maxOutputSize = actualIndicesCount; } - outputShape = ConstantShapeHelper::getInstance()->vectorShapeInfo(maxOutputSize, DataType::INT32); + outputShape = ConstantShapeHelper::getInstance().vectorShapeInfo(maxOutputSize, DataType::INT32); return SHAPELIST(outputShape); } @@ -211,7 +211,7 @@ namespace sd { if (len > 0) len = helpers::nonMaxSuppressionV3(block.launchContext(), boxes, scales, maxOutputSize, overlayThreshold, scoreThreshold, nullptr); - auto outputShape = ConstantShapeHelper::getInstance()->vectorShapeInfo(len, DataType::INT32); + auto outputShape = ConstantShapeHelper::getInstance().vectorShapeInfo(len, DataType::INT32); return SHAPELIST(outputShape); } diff --git a/libnd4j/include/ops/declarable/generic/parity_ops/non_max_suppression_overlaps.cpp b/libnd4j/include/ops/declarable/generic/parity_ops/non_max_suppression_overlaps.cpp index 30f59ff35..1cc4addbc 100644 --- a/libnd4j/include/ops/declarable/generic/parity_ops/non_max_suppression_overlaps.cpp +++ b/libnd4j/include/ops/declarable/generic/parity_ops/non_max_suppression_overlaps.cpp @@ -75,7 +75,7 @@ namespace sd { if (boxSize < maxOutputSize) maxOutputSize = boxSize; - auto outputShape = ConstantShapeHelper::getInstance()->vectorShapeInfo(maxOutputSize, DataType::INT32); + auto outputShape = ConstantShapeHelper::getInstance().vectorShapeInfo(maxOutputSize, DataType::INT32); return SHAPELIST(outputShape); } diff --git a/libnd4j/include/ops/declarable/generic/parity_ops/nth_element.cpp b/libnd4j/include/ops/declarable/generic/parity_ops/nth_element.cpp index b0a549c43..b9326a981 100644 --- a/libnd4j/include/ops/declarable/generic/parity_ops/nth_element.cpp +++ b/libnd4j/include/ops/declarable/generic/parity_ops/nth_element.cpp @@ -61,11 +61,11 @@ namespace sd { outShape = CONSTANT(outputShape); } else if (outRank == 1) { - outShape = ConstantShapeHelper::getInstance()->vectorShapeInfo(shape::sizeAt(in, 0), ArrayOptions::dataType(in)); + outShape = ConstantShapeHelper::getInstance().vectorShapeInfo(shape::sizeAt(in, 0), ArrayOptions::dataType(in)); } else { //outputShape = shape::createScalarShapeInfo(); - outShape = ConstantShapeHelper::getInstance()->scalarShapeInfo(ArrayOptions::dataType(in)); + outShape = ConstantShapeHelper::getInstance().scalarShapeInfo(ArrayOptions::dataType(in)); } return SHAPELIST(outShape); } diff --git a/libnd4j/include/ops/declarable/generic/parity_ops/onehot.cpp b/libnd4j/include/ops/declarable/generic/parity_ops/onehot.cpp index 6349b84fe..5b25ea7e6 100644 --- a/libnd4j/include/ops/declarable/generic/parity_ops/onehot.cpp +++ b/libnd4j/include/ops/declarable/generic/parity_ops/onehot.cpp @@ -100,7 +100,7 @@ namespace sd { shape.push_back(shape::shapeOf(inShape)[e]); shape.insert(shape.begin() + axis, depth); - auto newShape = ConstantShapeHelper::getInstance()->createShapeInfo(dtype, 'c', rank + 1, shape.data()); + auto newShape = ConstantShapeHelper::getInstance().createShapeInfo(dtype, 'c', rank + 1, shape.data()); return SHAPELIST(newShape); } diff --git a/libnd4j/include/ops/declarable/generic/parity_ops/top_k.cpp b/libnd4j/include/ops/declarable/generic/parity_ops/top_k.cpp index 799572794..b042e94fe 100644 --- a/libnd4j/include/ops/declarable/generic/parity_ops/top_k.cpp +++ b/libnd4j/include/ops/declarable/generic/parity_ops/top_k.cpp @@ -76,7 +76,7 @@ namespace sd { aShape[shapeRank] = k; shape::updateStrides(aShape, shape::order(in)); - shapeList->push_back(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(aShape, (e == 0?ArrayOptions::dataType(in):sd::DataType::INT64)))); + shapeList->push_back(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(aShape, (e == 0?ArrayOptions::dataType(in):sd::DataType::INT64)))); RELEASE(aShape, block.getWorkspace()); } diff --git a/libnd4j/include/ops/declarable/generic/parity_ops/unique.cpp b/libnd4j/include/ops/declarable/generic/parity_ops/unique.cpp index 9005348a1..9d234abaa 100644 --- a/libnd4j/include/ops/declarable/generic/parity_ops/unique.cpp +++ b/libnd4j/include/ops/declarable/generic/parity_ops/unique.cpp @@ -46,14 +46,14 @@ namespace sd { int uniqueCount = helpers::uniqueCount(block.launchContext(), source); if (uniqueCount == 0) { // empty value Shape - valuesShape = ConstantShapeHelper::getInstance()->emptyShapeInfo(source->dataType()); + valuesShape = ConstantShapeHelper::getInstance().emptyShapeInfo(source->dataType()); } else { // all output shapes are 1D arrays (vectors) - valuesShape = ConstantShapeHelper::getInstance()->vectorShapeInfo(uniqueCount, ArrayOptions::dataType(in)); + valuesShape = ConstantShapeHelper::getInstance().vectorShapeInfo(uniqueCount, ArrayOptions::dataType(in)); } // second output is always LONG - indicesShape = ConstantShapeHelper::getInstance()->vectorShapeInfo(shape::length(in), sd::DataType::INT64); + indicesShape = ConstantShapeHelper::getInstance().vectorShapeInfo(shape::length(in), sd::DataType::INT64); //COPY_SHAPE_EX(in, indicesShape, block.getWorkspace()); @@ -77,13 +77,13 @@ namespace sd { int uniqueCount = helpers::uniqueCount(block.launchContext(), source); // all output shapes are 1D arrays (vectors) // all output shapes are 1D arrays (vectors) - auto valuesShape = ConstantShapeHelper::getInstance()->vectorShapeInfo(uniqueCount, source->dataType()); + auto valuesShape = ConstantShapeHelper::getInstance().vectorShapeInfo(uniqueCount, source->dataType()); // second output is always LONG - auto indicesShape = ConstantShapeHelper::getInstance()->vectorShapeInfo(source->lengthOf(), sd::DataType::INT64); + auto indicesShape = ConstantShapeHelper::getInstance().vectorShapeInfo(source->lengthOf(), sd::DataType::INT64); // third one as well - auto countsShape = ConstantShapeHelper::getInstance()->vectorShapeInfo(uniqueCount, sd::DataType::INT64); + auto countsShape = ConstantShapeHelper::getInstance().vectorShapeInfo(uniqueCount, sd::DataType::INT64); return SHAPELIST(valuesShape, indicesShape, countsShape); } diff --git a/libnd4j/include/ops/declarable/generic/parity_ops/zero_fraction.cpp b/libnd4j/include/ops/declarable/generic/parity_ops/zero_fraction.cpp index f70e92cf5..91f0a564d 100644 --- a/libnd4j/include/ops/declarable/generic/parity_ops/zero_fraction.cpp +++ b/libnd4j/include/ops/declarable/generic/parity_ops/zero_fraction.cpp @@ -48,7 +48,7 @@ namespace sd { return Status::OK(); } DECLARE_SHAPE_FN(zero_fraction) { - return SHAPELIST(ConstantShapeHelper::getInstance()->scalarShapeInfo(sd::DataType::DOUBLE)); + return SHAPELIST(ConstantShapeHelper::getInstance().scalarShapeInfo(sd::DataType::DOUBLE)); } DECLARE_TYPES(zero_fraction) { diff --git a/libnd4j/include/ops/declarable/generic/random/bernoulli.cpp b/libnd4j/include/ops/declarable/generic/random/bernoulli.cpp index f0b2b587b..ded5bfee5 100644 --- a/libnd4j/include/ops/declarable/generic/random/bernoulli.cpp +++ b/libnd4j/include/ops/declarable/generic/random/bernoulli.cpp @@ -53,7 +53,7 @@ namespace sd { auto in = INPUT_VARIABLE(0); auto shape = in->template asVectorT(); - auto newShape = ConstantShapeHelper::getInstance()->createShapeInfo(block.dataType(), 'c', shape); + auto newShape = ConstantShapeHelper::getInstance().createShapeInfo(block.dataType(), 'c', shape); return SHAPELIST(newShape); } diff --git a/libnd4j/include/ops/declarable/generic/random/exponential.cpp b/libnd4j/include/ops/declarable/generic/random/exponential.cpp index cac3d1a88..735bab583 100644 --- a/libnd4j/include/ops/declarable/generic/random/exponential.cpp +++ b/libnd4j/include/ops/declarable/generic/random/exponential.cpp @@ -42,7 +42,7 @@ namespace sd { auto in = INPUT_VARIABLE(0); auto shape = in->template asVectorT(); - auto newShape = ConstantShapeHelper::getInstance()->createShapeInfo(block.dataType(), 'c', shape); + auto newShape = ConstantShapeHelper::getInstance().createShapeInfo(block.dataType(), 'c', shape); return SHAPELIST(newShape); } diff --git a/libnd4j/include/ops/declarable/generic/random/gamma.cpp b/libnd4j/include/ops/declarable/generic/random/gamma.cpp index e21458530..a00ce2b7e 100644 --- a/libnd4j/include/ops/declarable/generic/random/gamma.cpp +++ b/libnd4j/include/ops/declarable/generic/random/gamma.cpp @@ -68,7 +68,7 @@ namespace sd { auto dtype = ArrayOptions::dataType(alphaShape); for (auto i = 0; i < shape::rank(additionalShape); i++) shape.push_back(shape::sizeAt(additionalShape, i)); - auto newShape = ConstantShapeHelper::getInstance()->createShapeInfo(dtype, 'c', shape); + auto newShape = ConstantShapeHelper::getInstance().createShapeInfo(dtype, 'c', shape); return SHAPELIST(newShape); } diff --git a/libnd4j/include/ops/declarable/generic/random/get_seed.cpp b/libnd4j/include/ops/declarable/generic/random/get_seed.cpp index 7042ae6dd..9f768e9f3 100644 --- a/libnd4j/include/ops/declarable/generic/random/get_seed.cpp +++ b/libnd4j/include/ops/declarable/generic/random/get_seed.cpp @@ -36,7 +36,7 @@ namespace sd { } DECLARE_SHAPE_FN(get_seed) { - auto newshape = ConstantShapeHelper::getInstance()->scalarShapeInfo(DataType::INT64); + auto newshape = ConstantShapeHelper::getInstance().scalarShapeInfo(DataType::INT64); return SHAPELIST(newshape); } diff --git a/libnd4j/include/ops/declarable/generic/random/multinomial.cpp b/libnd4j/include/ops/declarable/generic/random/multinomial.cpp index 5361d1bbb..2e8225d2c 100644 --- a/libnd4j/include/ops/declarable/generic/random/multinomial.cpp +++ b/libnd4j/include/ops/declarable/generic/random/multinomial.cpp @@ -99,7 +99,7 @@ namespace sd { nShape[dimA] = numOfSamples; DataType nType = (argSize > 1) ? ( INT_ARG(1) >= 0 ? static_cast(INT_ARG(1)) : sd::DataType::INT64) : sd::DataType::INT64; - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(nType, input->ordering(), nShape)); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(nType, input->ordering(), nShape)); } DECLARE_TYPES(random_multinomial) { diff --git a/libnd4j/include/ops/declarable/generic/random/normal.cpp b/libnd4j/include/ops/declarable/generic/random/normal.cpp index f81a06786..701570784 100644 --- a/libnd4j/include/ops/declarable/generic/random/normal.cpp +++ b/libnd4j/include/ops/declarable/generic/random/normal.cpp @@ -48,7 +48,7 @@ namespace sd { auto in = INPUT_VARIABLE(0); auto shape = in->template asVectorT(); - auto newShape = ConstantShapeHelper::getInstance()->createShapeInfo(block.dataType(), 'c', shape); + auto newShape = ConstantShapeHelper::getInstance().createShapeInfo(block.dataType(), 'c', shape); return SHAPELIST(newShape); } diff --git a/libnd4j/include/ops/declarable/generic/random/poisson.cpp b/libnd4j/include/ops/declarable/generic/random/poisson.cpp index 74f3a8570..eedfbbe1f 100644 --- a/libnd4j/include/ops/declarable/generic/random/poisson.cpp +++ b/libnd4j/include/ops/declarable/generic/random/poisson.cpp @@ -51,7 +51,7 @@ namespace sd { for (auto d = 0; d < shape::rank(lambdaShape); ++d ) { shape.emplace_back(shape::sizeAt(lambdaShape, d)); } - auto newShape = ConstantShapeHelper::getInstance()->createShapeInfo(dtype, 'c', shape); + auto newShape = ConstantShapeHelper::getInstance().createShapeInfo(dtype, 'c', shape); return SHAPELIST(newShape); } diff --git a/libnd4j/include/ops/declarable/generic/random/random_crop.cpp b/libnd4j/include/ops/declarable/generic/random/random_crop.cpp index 2ac2495d3..1b30b2f91 100644 --- a/libnd4j/include/ops/declarable/generic/random/random_crop.cpp +++ b/libnd4j/include/ops/declarable/generic/random/random_crop.cpp @@ -59,7 +59,7 @@ DECLARE_SHAPE_FN(random_crop) { for (int e = 0; e < shape.size(); e++) shape[e] = (*in).e(e); - auto newShape = ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(typeShape), 'c', shape); + auto newShape = ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(typeShape), 'c', shape); return SHAPELIST(newShape); } diff --git a/libnd4j/include/ops/declarable/generic/random/set_seed.cpp b/libnd4j/include/ops/declarable/generic/random/set_seed.cpp index f4c240d50..f7050f3ab 100644 --- a/libnd4j/include/ops/declarable/generic/random/set_seed.cpp +++ b/libnd4j/include/ops/declarable/generic/random/set_seed.cpp @@ -48,7 +48,7 @@ namespace sd { } DECLARE_SHAPE_FN(set_seed) { - auto newshape = ConstantShapeHelper::getInstance()->scalarShapeInfo(block.dataType()); + auto newshape = ConstantShapeHelper::getInstance().scalarShapeInfo(block.dataType()); return SHAPELIST(newshape); } diff --git a/libnd4j/include/ops/declarable/generic/random/uniform.cpp b/libnd4j/include/ops/declarable/generic/random/uniform.cpp index 94df6b32d..d4abccf78 100644 --- a/libnd4j/include/ops/declarable/generic/random/uniform.cpp +++ b/libnd4j/include/ops/declarable/generic/random/uniform.cpp @@ -80,7 +80,7 @@ namespace sd { if (block.width() > 1) REQUIRE_TRUE(dtype == INPUT_VARIABLE(1)->dataType(), 0, "RandomUniform: data type of output and min/max args should be the same"); - auto newShape = ConstantShapeHelper::getInstance()->createShapeInfo(dtype, 'c', shape); + auto newShape = ConstantShapeHelper::getInstance().createShapeInfo(dtype, 'c', shape); return SHAPELIST(newShape); } diff --git a/libnd4j/include/ops/declarable/generic/reduce/argamax.cpp b/libnd4j/include/ops/declarable/generic/reduce/argamax.cpp index 5fb452227..a347c398a 100644 --- a/libnd4j/include/ops/declarable/generic/reduce/argamax.cpp +++ b/libnd4j/include/ops/declarable/generic/reduce/argamax.cpp @@ -84,7 +84,7 @@ namespace sd { // special case - output is scalar if (dims.empty() || (dims.size() == 1 && dims.at(0) == sd::DataTypeUtils::max())) { - return SHAPELIST(ConstantShapeHelper::getInstance()->scalarShapeInfo(dtype)); + return SHAPELIST(ConstantShapeHelper::getInstance().scalarShapeInfo(dtype)); } return SHAPELIST(ShapeUtils::evalReduceShapeInfo('c', dims, inputShape->at(0), dtype, keepDims, false, block.getWorkspace())); diff --git a/libnd4j/include/ops/declarable/generic/reduce/argamin.cpp b/libnd4j/include/ops/declarable/generic/reduce/argamin.cpp index 4f590aae8..68ad9d2e5 100644 --- a/libnd4j/include/ops/declarable/generic/reduce/argamin.cpp +++ b/libnd4j/include/ops/declarable/generic/reduce/argamin.cpp @@ -84,7 +84,7 @@ namespace sd { // special case - output is scalar if (dims.empty() || (dims.size() == 1 && dims.at(0) == sd::DataTypeUtils::max())) { - return SHAPELIST(ConstantShapeHelper::getInstance()->scalarShapeInfo(dtype)); + return SHAPELIST(ConstantShapeHelper::getInstance().scalarShapeInfo(dtype)); } return SHAPELIST(ShapeUtils::evalReduceShapeInfo('c', dims, inputShape->at(0), dtype, keepDims, false, block.getWorkspace())); diff --git a/libnd4j/include/ops/declarable/generic/reduce/argmax.cpp b/libnd4j/include/ops/declarable/generic/reduce/argmax.cpp index 9c45b4c37..f8a2486fa 100644 --- a/libnd4j/include/ops/declarable/generic/reduce/argmax.cpp +++ b/libnd4j/include/ops/declarable/generic/reduce/argmax.cpp @@ -86,7 +86,7 @@ namespace sd { // special case - output is scalar if (dims.empty() || (dims.size() == 1 && dims.at(0) == sd::DataTypeUtils::max())) { - return SHAPELIST(ConstantShapeHelper::getInstance()->scalarShapeInfo(dtype)); + return SHAPELIST(ConstantShapeHelper::getInstance().scalarShapeInfo(dtype)); } return SHAPELIST(ShapeUtils::evalReduceShapeInfo('c', dims, inputShape->at(0), dtype, keepDims, false, block.getWorkspace())); diff --git a/libnd4j/include/ops/declarable/generic/reduce/argmin.cpp b/libnd4j/include/ops/declarable/generic/reduce/argmin.cpp index 97430a24f..40648b7f6 100644 --- a/libnd4j/include/ops/declarable/generic/reduce/argmin.cpp +++ b/libnd4j/include/ops/declarable/generic/reduce/argmin.cpp @@ -88,7 +88,7 @@ namespace sd { // special case - output is scalar if (dims.empty() || (dims.size() == 1 && dims.at(0) == sd::DataTypeUtils::max())) { - return SHAPELIST(ConstantShapeHelper::getInstance()->scalarShapeInfo(dtype)); + return SHAPELIST(ConstantShapeHelper::getInstance().scalarShapeInfo(dtype)); } return SHAPELIST(ShapeUtils::evalReduceShapeInfo('c', dims, inputShape->at(0), dtype, keepDims, false, block.getWorkspace())); diff --git a/libnd4j/include/ops/declarable/generic/shape/broadcast_to.cpp b/libnd4j/include/ops/declarable/generic/shape/broadcast_to.cpp index 49961bfe2..18d10be7b 100644 --- a/libnd4j/include/ops/declarable/generic/shape/broadcast_to.cpp +++ b/libnd4j/include/ops/declarable/generic/shape/broadcast_to.cpp @@ -76,7 +76,7 @@ DECLARE_SHAPE_FN(broadcast_to) { for(int i = 1; i <= inputRank; ++i) REQUIRE_TRUE(inputShapeInfo[inputRank+1-i] == outShape[shapeLen-i] || inputShapeInfo[inputRank+1-i] == 1, 0, "BROADCAST_TO op: shape of input array %s can't be broadcasted to the shape %s !", ShapeUtils::shapeAsString(inputShapeInfo).c_str(), ShapeUtils::shapeAsString(outShape).c_str()); - auto outShapeInfo = ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(inputShapeInfo), shape::order(inputShapeInfo), outShape); + auto outShapeInfo = ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(inputShapeInfo), shape::order(inputShapeInfo), outShape); return SHAPELIST(outShapeInfo); } diff --git a/libnd4j/include/ops/declarable/generic/shape/evaluate_reduction_shape.cpp b/libnd4j/include/ops/declarable/generic/shape/evaluate_reduction_shape.cpp index 6a0ad187c..c35a81279 100644 --- a/libnd4j/include/ops/declarable/generic/shape/evaluate_reduction_shape.cpp +++ b/libnd4j/include/ops/declarable/generic/shape/evaluate_reduction_shape.cpp @@ -34,7 +34,7 @@ namespace sd { auto shape = inputShape->asVectorT(); - auto tempShapeInfo = ConstantShapeHelper::getInstance()->createShapeInfo(sd::DataType::INT64, 'c', shape); + auto tempShapeInfo = ConstantShapeHelper::getInstance().createShapeInfo(sd::DataType::INT64, 'c', shape); auto tempReductionShapeInfo = ShapeUtils::evalReduceShapeInfo('c', axis, tempShapeInfo, keepDims, oldFormat, block.workspace()); REQUIRE_TRUE(output->lengthOf() == shape::rank(tempReductionShapeInfo), 0, "evaluate_reduction_shape: output length should be %i, but got %i instead", shape::rank(tempReductionShapeInfo), output->lengthOf()); @@ -73,7 +73,7 @@ namespace sd { } } - return SHAPELIST(ConstantShapeHelper::getInstance()->vectorShapeInfo(length, sd::DataType::INT64)); + return SHAPELIST(ConstantShapeHelper::getInstance().vectorShapeInfo(length, sd::DataType::INT64)); } } } diff --git a/libnd4j/include/ops/declarable/generic/shape/expand_dims.cpp b/libnd4j/include/ops/declarable/generic/shape/expand_dims.cpp index 86900c264..df31f5109 100644 --- a/libnd4j/include/ops/declarable/generic/shape/expand_dims.cpp +++ b/libnd4j/include/ops/declarable/generic/shape/expand_dims.cpp @@ -70,13 +70,13 @@ namespace sd { if (shape::rank(inShape) == 0) { Nd4jLong x = 1; - auto newShape = ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(inShape), 'c', 1, &x); + auto newShape = ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(inShape), 'c', 1, &x); return SHAPELIST(newShape); } // FIXME: temp workaround for TF if (shape::isScalar(inShape)) { - auto newShape = ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(inShape), 'c', 2, shape::shapeOf(inShape)); + auto newShape = ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(inShape), 'c', 2, shape::shapeOf(inShape)); return SHAPELIST(newShape); } @@ -94,7 +94,7 @@ namespace sd { shape.insert(shape.begin() + axis, 1); - auto newShape = ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(inShape), order, shape); + auto newShape = ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(inShape), order, shape); return SHAPELIST(newShape); } } diff --git a/libnd4j/include/ops/declarable/generic/shape/flatten.cpp b/libnd4j/include/ops/declarable/generic/shape/flatten.cpp index 19cc4f469..8327ca1a1 100644 --- a/libnd4j/include/ops/declarable/generic/shape/flatten.cpp +++ b/libnd4j/include/ops/declarable/generic/shape/flatten.cpp @@ -60,7 +60,7 @@ namespace sd { REQUIRE_TRUE(dtype == ArrayOptions::dataType(inputShape->at(e)), 0, "Flatten: all input arrays must have the same datatype"); } - return SHAPELIST(ConstantShapeHelper::getInstance()->vectorShapeInfo(length, dtype)); + return SHAPELIST(ConstantShapeHelper::getInstance().vectorShapeInfo(length, dtype)); } } } diff --git a/libnd4j/include/ops/declarable/generic/shape/order.cpp b/libnd4j/include/ops/declarable/generic/shape/order.cpp index 5b978f48f..2d7e0994c 100644 --- a/libnd4j/include/ops/declarable/generic/shape/order.cpp +++ b/libnd4j/include/ops/declarable/generic/shape/order.cpp @@ -45,7 +45,7 @@ namespace sd { auto isFOrder = INT_ARG(0) == 1; - auto newShape = ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(input), isFOrder ? 'f' : 'c', shape::rank(input), shape::shapeOf(input)); + auto newShape = ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(input), isFOrder ? 'f' : 'c', shape::rank(input), shape::shapeOf(input)); return SHAPELIST(newShape); } } diff --git a/libnd4j/include/ops/declarable/generic/shape/rank.cpp b/libnd4j/include/ops/declarable/generic/shape/rank.cpp index 8a617dc59..d12e15239 100644 --- a/libnd4j/include/ops/declarable/generic/shape/rank.cpp +++ b/libnd4j/include/ops/declarable/generic/shape/rank.cpp @@ -37,7 +37,7 @@ namespace sd { return Status::OK(); } DECLARE_SHAPE_FN(rank) { - return SHAPELIST(ConstantShapeHelper::getInstance()->scalarShapeInfo(sd::DataType::INT32)); + return SHAPELIST(ConstantShapeHelper::getInstance().scalarShapeInfo(sd::DataType::INT32)); } diff --git a/libnd4j/include/ops/declarable/generic/shape/reshape.cpp b/libnd4j/include/ops/declarable/generic/shape/reshape.cpp index 023e9bf89..38bae587e 100644 --- a/libnd4j/include/ops/declarable/generic/shape/reshape.cpp +++ b/libnd4j/include/ops/declarable/generic/shape/reshape.cpp @@ -42,7 +42,7 @@ CUSTOM_OP_IMPL(reshape, 1, 1, false, 0, -2) { REQUIRE_TRUE(x->lengthOf() == z->lengthOf(), 0, "Reshape: lengths before and after reshape should match, but got %i vs %i", x->lengthOf(), z->lengthOf()); - if (Environment::getInstance()->isDebugAndVerbose()) + if (Environment::getInstance().isDebugAndVerbose()) nd4j_printv("Reshape: new shape", z->getShapeAsVector()); z->assign(x->reshape(z->ordering(), z->getShapeAsVector())); @@ -159,7 +159,7 @@ DECLARE_SHAPE_FN(reshape) { auto len = shape::prodLong(shapeNew.data(), shapeNew.size()); REQUIRE_TRUE(x->lengthOf() == len, 0, "Reshape: lengths before and after reshape should match, but got %i vs %i", x->lengthOf(), len); - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(x->dataType(), orderNew, shapeNew)); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(x->dataType(), orderNew, shapeNew)); } diff --git a/libnd4j/include/ops/declarable/generic/shape/shape.cpp b/libnd4j/include/ops/declarable/generic/shape/shape.cpp index e2db3db3e..098825df3 100644 --- a/libnd4j/include/ops/declarable/generic/shape/shape.cpp +++ b/libnd4j/include/ops/declarable/generic/shape/shape.cpp @@ -46,7 +46,7 @@ namespace sd { if (block.numI() > 0) dtype = DataTypeUtils::fromInt(INT_ARG(0)); - return SHAPELIST(ConstantShapeHelper::getInstance()->vectorShapeInfo(shape::rank(inShape), dtype)); + return SHAPELIST(ConstantShapeHelper::getInstance().vectorShapeInfo(shape::rank(inShape), dtype)); }; DECLARE_TYPES(shape_of) { diff --git a/libnd4j/include/ops/declarable/generic/shape/shapes.cpp b/libnd4j/include/ops/declarable/generic/shape/shapes.cpp index 6481d1db3..3f5428122 100644 --- a/libnd4j/include/ops/declarable/generic/shape/shapes.cpp +++ b/libnd4j/include/ops/declarable/generic/shape/shapes.cpp @@ -43,7 +43,7 @@ namespace sd { for (int e = 0; e < inputShape->size(); e++) { auto inShape = inputShape->at(e); - shapeList->push_back(ConstantShapeHelper::getInstance()->vectorShapeInfo(shape::rank(inShape), sd::DataType::INT64)); + shapeList->push_back(ConstantShapeHelper::getInstance().vectorShapeInfo(shape::rank(inShape), sd::DataType::INT64)); } return shapeList; diff --git a/libnd4j/include/ops/declarable/generic/shape/size.cpp b/libnd4j/include/ops/declarable/generic/shape/size.cpp index d31e782c6..c30ed1b58 100644 --- a/libnd4j/include/ops/declarable/generic/shape/size.cpp +++ b/libnd4j/include/ops/declarable/generic/shape/size.cpp @@ -37,7 +37,7 @@ namespace sd { return Status::OK(); } DECLARE_SHAPE_FN(size) { - return SHAPELIST(ConstantShapeHelper::getInstance()->scalarShapeInfo(sd::DataType::INT64)); + return SHAPELIST(ConstantShapeHelper::getInstance().scalarShapeInfo(sd::DataType::INT64)); } DECLARE_TYPES(size) { diff --git a/libnd4j/include/ops/declarable/generic/shape/size_at.cpp b/libnd4j/include/ops/declarable/generic/shape/size_at.cpp index 2c27b018a..46491e688 100644 --- a/libnd4j/include/ops/declarable/generic/shape/size_at.cpp +++ b/libnd4j/include/ops/declarable/generic/shape/size_at.cpp @@ -42,7 +42,7 @@ namespace sd { } DECLARE_SHAPE_FN(size_at) { - return SHAPELIST(ConstantShapeHelper::getInstance()->scalarShapeInfo(sd::DataType::INT64)); + return SHAPELIST(ConstantShapeHelper::getInstance().scalarShapeInfo(sd::DataType::INT64)); } DECLARE_TYPES(size_at) { diff --git a/libnd4j/include/ops/declarable/generic/shape/squeeze.cpp b/libnd4j/include/ops/declarable/generic/shape/squeeze.cpp index 0b71dae52..5698f957f 100644 --- a/libnd4j/include/ops/declarable/generic/shape/squeeze.cpp +++ b/libnd4j/include/ops/declarable/generic/shape/squeeze.cpp @@ -99,7 +99,7 @@ namespace sd { auto length = shape::length(in); if (rank == 0 || (rank == 1 && length == 1)) { - shapeList->push_back(ConstantShapeHelper::getInstance()->scalarShapeInfo(ArrayOptions::dataType(in))); + shapeList->push_back(ConstantShapeHelper::getInstance().scalarShapeInfo(ArrayOptions::dataType(in))); return shapeList; } @@ -144,11 +144,11 @@ namespace sd { } if (shape.size() == 0) { - shapeList->push_back(ConstantShapeHelper::getInstance()->scalarShapeInfo(ArrayOptions::dataType(in))); + shapeList->push_back(ConstantShapeHelper::getInstance().scalarShapeInfo(ArrayOptions::dataType(in))); return shapeList; } - auto newShape = ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(in), order, shape); + auto newShape = ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(in), order, shape); shapeList->push_back(newShape); return shapeList; } diff --git a/libnd4j/include/ops/declarable/generic/shape/tile_to_shape.cpp b/libnd4j/include/ops/declarable/generic/shape/tile_to_shape.cpp index 687d79f25..ec0476e04 100644 --- a/libnd4j/include/ops/declarable/generic/shape/tile_to_shape.cpp +++ b/libnd4j/include/ops/declarable/generic/shape/tile_to_shape.cpp @@ -48,7 +48,7 @@ namespace ops { auto conv = ArrayUtils::toLongVector(*block.getIArguments()); - auto newShape = ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(in), shape::order(in), conv); + auto newShape = ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(in), shape::order(in), conv); return SHAPELIST(newShape); } diff --git a/libnd4j/include/ops/declarable/generic/tensor/create.cpp b/libnd4j/include/ops/declarable/generic/tensor/create.cpp index c79b55497..c692a74d8 100644 --- a/libnd4j/include/ops/declarable/generic/tensor/create.cpp +++ b/libnd4j/include/ops/declarable/generic/tensor/create.cpp @@ -44,7 +44,7 @@ namespace sd { auto shape = shapeInput->getBufferAsVector(); - return SHAPELIST(sd::ConstantShapeHelper::getInstance()->createShapeInfo(dtype, order, shape)); + return SHAPELIST(sd::ConstantShapeHelper::getInstance().createShapeInfo(dtype, order, shape)); } DECLARE_TYPES(create) { diff --git a/libnd4j/include/ops/declarable/generic/tensor/fill.cpp b/libnd4j/include/ops/declarable/generic/tensor/fill.cpp index 18b9ce2b8..81cece901 100644 --- a/libnd4j/include/ops/declarable/generic/tensor/fill.cpp +++ b/libnd4j/include/ops/declarable/generic/tensor/fill.cpp @@ -80,7 +80,7 @@ namespace sd { if (block.width() > 1) { dataType = INPUT_VARIABLE(1)->dataType(); } else if (block.numT() > 0) { - dataType = Environment::getInstance()->defaultFloatDataType(); + dataType = Environment::getInstance().defaultFloatDataType(); } else if (block.numI() > 0) { dataType = sd::DataType::INT32; } else if (block.numB() > 0) { diff --git a/libnd4j/include/ops/declarable/generic/tensor/lin_space.cpp b/libnd4j/include/ops/declarable/generic/tensor/lin_space.cpp index 374456be6..97f7b390f 100644 --- a/libnd4j/include/ops/declarable/generic/tensor/lin_space.cpp +++ b/libnd4j/include/ops/declarable/generic/tensor/lin_space.cpp @@ -58,7 +58,7 @@ namespace ops { auto dataType = (nInputs > 0) ? ArrayOptions::dataType(inputShape->at(0)) : ( block.numD() > 0 ? static_cast(D_ARG(0)) : DataType::FLOAT32) ; Nd4jLong steps = (nInputs > 0) ? INPUT_VARIABLE(2)->e(0) : static_cast(I_ARG(0)); - return SHAPELIST(ConstantShapeHelper::getInstance()->vectorShapeInfo(steps, dataType)); + return SHAPELIST(ConstantShapeHelper::getInstance().vectorShapeInfo(steps, dataType)); } diff --git a/libnd4j/include/ops/declarable/generic/tensor/ones_as.cpp b/libnd4j/include/ops/declarable/generic/tensor/ones_as.cpp index 32ce54300..0fb8fe283 100644 --- a/libnd4j/include/ops/declarable/generic/tensor/ones_as.cpp +++ b/libnd4j/include/ops/declarable/generic/tensor/ones_as.cpp @@ -36,7 +36,7 @@ namespace sd { DECLARE_SHAPE_FN(ones_as) { auto in = inputShape->at(0); auto dtype = block.numD() ? D_ARG(0) : ArrayOptions::dataType(in); - auto shape = sd::ConstantShapeHelper::getInstance()->createShapeInfo(dtype, in); + auto shape = sd::ConstantShapeHelper::getInstance().createShapeInfo(dtype, in); //nd4j_printf("numD: %i; dtype: %s\n", block.numD(), DataTypeUtils::asString(dtype).c_str()); diff --git a/libnd4j/include/ops/declarable/generic/tensor/range.cpp b/libnd4j/include/ops/declarable/generic/tensor/range.cpp index a39e07912..2f88b819b 100644 --- a/libnd4j/include/ops/declarable/generic/tensor/range.cpp +++ b/libnd4j/include/ops/declarable/generic/tensor/range.cpp @@ -153,7 +153,7 @@ DECLARE_SHAPE_FN(range) { if (limit == start){ //Return [0] to match TF - return SHAPELIST(ConstantShapeHelper::getInstance()->vectorShapeInfo(0, dtype)); + return SHAPELIST(ConstantShapeHelper::getInstance().vectorShapeInfo(0, dtype)); } REQUIRE_TRUE(delta != 0, 0, "CUSTOM RANGE OP: delta should not be equal to zero !"); @@ -183,7 +183,7 @@ DECLARE_SHAPE_FN(range) { if (limit == start){ //Return [0] to match TF - return SHAPELIST(ConstantShapeHelper::getInstance()->vectorShapeInfo(0, dtype)); + return SHAPELIST(ConstantShapeHelper::getInstance().vectorShapeInfo(0, dtype)); } REQUIRE_TRUE(delta != 0, 0, "CUSTOM RANGE OP: delta should not be equal to zero !"); @@ -213,7 +213,7 @@ DECLARE_SHAPE_FN(range) { if (limit == start){ //Return [0] to match TF - return SHAPELIST(ConstantShapeHelper::getInstance()->vectorShapeInfo(0, sd::DataType::INT32)); + return SHAPELIST(ConstantShapeHelper::getInstance().vectorShapeInfo(0, sd::DataType::INT32)); } REQUIRE_TRUE(delta != 0, 0, "CUSTOM RANGE OP: delta should not be equal to zero !"); @@ -247,7 +247,7 @@ DECLARE_SHAPE_FN(range) { if (limit == start){ //Return [0] to match TF - return SHAPELIST(ConstantShapeHelper::getInstance()->vectorShapeInfo(0, Environment::getInstance()->defaultFloatDataType())); + return SHAPELIST(ConstantShapeHelper::getInstance().vectorShapeInfo(0, Environment::getInstance().defaultFloatDataType())); } @@ -256,10 +256,10 @@ DECLARE_SHAPE_FN(range) { steps = static_cast((limit - start) / delta); if (!block.numD()) { - if (Environment::getInstance()->precisionBoostAllowed()) + if (Environment::getInstance().precisionBoostAllowed()) dataType = sd::DataType::DOUBLE; else - dataType = Environment::getInstance()->defaultFloatDataType(); + dataType = Environment::getInstance().defaultFloatDataType(); } if(math::nd4j_abs(start + steps * delta) < math::nd4j_abs(limit)) @@ -270,7 +270,7 @@ DECLARE_SHAPE_FN(range) { REQUIRE_TRUE(steps > 0, 0, "CUSTOM RANGE OP: value of (limit-start)/delta should be positive !"); - return SHAPELIST(ConstantShapeHelper::getInstance()->vectorShapeInfo(steps, dataType)); + return SHAPELIST(ConstantShapeHelper::getInstance().vectorShapeInfo(steps, dataType)); } diff --git a/libnd4j/include/ops/declarable/generic/tensor/strided_slice.cpp b/libnd4j/include/ops/declarable/generic/tensor/strided_slice.cpp index 88b06a631..bbdc84ce5 100644 --- a/libnd4j/include/ops/declarable/generic/tensor/strided_slice.cpp +++ b/libnd4j/include/ops/declarable/generic/tensor/strided_slice.cpp @@ -416,13 +416,13 @@ namespace sd { Nd4jLong offset; shape::calcSubArrShapeInfoAndOffset(indices.data(), x->shapeInfo(), subArrShapeInfo, offset, true, true); - auto subArrShapeInfoPack = ConstantShapeHelper::getInstance()->bufferForShapeInfo(subArrShapeInfo); + auto subArrShapeInfoPack = ConstantShapeHelper::getInstance().bufferForShapeInfo(subArrShapeInfo); NDArray::prepareSpecialUse({z}, {x}); NativeOpExecutioner::execTransformAny(block.launchContext(), sd::transform::Assign, - x->bufferWithOffset(offset), reinterpret_cast(subArrShapeInfoPack.primary()), - x->specialBufferWithOffset(offset), reinterpret_cast(subArrShapeInfoPack.special()), + x->bufferWithOffset(offset), subArrShapeInfoPack.primary(), + x->specialBufferWithOffset(offset), subArrShapeInfoPack.special(), z->buffer(), z->shapeInfo(), z->specialBuffer(), z->specialShapeInfo(), nullptr, nullptr, nullptr, true); @@ -518,18 +518,18 @@ namespace sd { std::vector indices; bool result = _preprocess_strided_slice(&indices, &shape, input_shape, begin, end, strides, begin_mask, ellipsis_mask, end_mask, new_axis_mask, shrink_axis_mask, &is_identity, &is_simple_slice, &is_dim0); if (indices.size()) { - auto newShape = ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(inShape), 'c', + auto newShape = ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(inShape), 'c', shape); // if (inputLen > 1) { -// newShape = ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(inShape), 'c', +// newShape = ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(inShape), 'c', // shape); // } else { -// newShape = ConstantShapeHelper::getInstance()->scalarShapeInfo(ArrayOptions::dataType(inShape)); +// newShape = ConstantShapeHelper::getInstance().scalarShapeInfo(ArrayOptions::dataType(inShape)); // } return SHAPELIST(newShape); } - return SHAPELIST(ConstantShapeHelper::getInstance()->emptyShapeInfo(ArrayOptions::dataType(inShape))); + return SHAPELIST(ConstantShapeHelper::getInstance().emptyShapeInfo(ArrayOptions::dataType(inShape))); } diff --git a/libnd4j/include/ops/declarable/generic/tensor/zeros_as.cpp b/libnd4j/include/ops/declarable/generic/tensor/zeros_as.cpp index 6d475af53..7935c567e 100644 --- a/libnd4j/include/ops/declarable/generic/tensor/zeros_as.cpp +++ b/libnd4j/include/ops/declarable/generic/tensor/zeros_as.cpp @@ -39,7 +39,7 @@ namespace sd { DECLARE_SHAPE_FN(zeros_as) { auto in = inputShape->at(0); auto dtype = block.numD() ? D_ARG(0) : ArrayOptions::dataType(in); - auto shape = sd::ConstantShapeHelper::getInstance()->createShapeInfo(dtype, in); + auto shape = sd::ConstantShapeHelper::getInstance().createShapeInfo(dtype, in); return SHAPELIST(shape); } diff --git a/libnd4j/include/ops/declarable/generic/tests/test_scalar.cpp b/libnd4j/include/ops/declarable/generic/tests/test_scalar.cpp index 437222052..e67122b05 100644 --- a/libnd4j/include/ops/declarable/generic/tests/test_scalar.cpp +++ b/libnd4j/include/ops/declarable/generic/tests/test_scalar.cpp @@ -50,7 +50,7 @@ namespace sd { ArrayOptions::setDataType(newShape, ArrayOptions::dataType(inputShape->at(0))); - auto shape = ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(newShape)); + auto shape = ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(newShape)); RELEASE(newShape, block.getWorkspace()); return SHAPELIST(shape); } diff --git a/libnd4j/include/ops/declarable/generic/tests/testcustom.cpp b/libnd4j/include/ops/declarable/generic/tests/testcustom.cpp index 89480e5bc..e8d7fc6c3 100644 --- a/libnd4j/include/ops/declarable/generic/tests/testcustom.cpp +++ b/libnd4j/include/ops/declarable/generic/tests/testcustom.cpp @@ -39,7 +39,7 @@ namespace sd { for (int e = 0; e < shape::rank(inputShape->at(0)); e++) shapeOf[e] = inputShape->at(0)[e+1] * 2; - auto newShape = ConstantShapeHelper::getInstance()->createShapeInfo(block.dataType(), 'c', shape::rank(inputShape->at(0)), shapeOf); + auto newShape = ConstantShapeHelper::getInstance().createShapeInfo(block.dataType(), 'c', shape::rank(inputShape->at(0)), shapeOf); RELEASE(shapeOf, block.getWorkspace()); return SHAPELIST(newShape); } diff --git a/libnd4j/include/ops/declarable/generic/thrid_party/firas_sparse.cpp b/libnd4j/include/ops/declarable/generic/thrid_party/firas_sparse.cpp index 7860036ed..3a115b8db 100644 --- a/libnd4j/include/ops/declarable/generic/thrid_party/firas_sparse.cpp +++ b/libnd4j/include/ops/declarable/generic/thrid_party/firas_sparse.cpp @@ -93,7 +93,7 @@ namespace sd { auto inP = inputShape->at(0); std::vector shape({shape::shapeOf(inP)[0], (Nd4jLong) block.getIArguments()->size()}); - auto newShape = ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(inP), 'c', shape); + auto newShape = ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(inP), 'c', shape); return SHAPELIST(newShape); } diff --git a/libnd4j/include/ops/declarable/generic/transforms/batch_to_space.cpp b/libnd4j/include/ops/declarable/generic/transforms/batch_to_space.cpp index 607980f0d..0ffad12a2 100644 --- a/libnd4j/include/ops/declarable/generic/transforms/batch_to_space.cpp +++ b/libnd4j/include/ops/declarable/generic/transforms/batch_to_space.cpp @@ -119,7 +119,7 @@ DECLARE_SHAPE_FN(batch_to_space) { REQUIRE_TRUE(oW >= 0, 0, "BatchToSpace: crop left/right values are too big and cause negative output width dimension !"); // we always give out C order here - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(inputShapeInfo), 'c', {dim0 / (blockSize * blockSize), oH, oW, inputShapeInfo[4]})); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(inputShapeInfo), 'c', {dim0 / (blockSize * blockSize), oH, oW, inputShapeInfo[4]})); } diff --git a/libnd4j/include/ops/declarable/generic/transforms/batch_to_space_nd.cpp b/libnd4j/include/ops/declarable/generic/transforms/batch_to_space_nd.cpp index f62921cc2..1ae1a2e61 100644 --- a/libnd4j/include/ops/declarable/generic/transforms/batch_to_space_nd.cpp +++ b/libnd4j/include/ops/declarable/generic/transforms/batch_to_space_nd.cpp @@ -118,7 +118,7 @@ DECLARE_SHAPE_FN(batch_to_space_nd) { for (uint i = 0; i < numOfSpatialDims; ++i) outShape[i + 1] = outShape[i + 1] * INPUT_VARIABLE(1)->e(i) - INPUT_VARIABLE(2)->e(i,0) - INPUT_VARIABLE(2)->e(i,1); - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(inputShapeInfo), 'c', outShape)); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(inputShapeInfo), 'c', outShape)); } diff --git a/libnd4j/include/ops/declarable/generic/transforms/clip_by_global_norm.cpp b/libnd4j/include/ops/declarable/generic/transforms/clip_by_global_norm.cpp index 99a01d390..7758cf298 100644 --- a/libnd4j/include/ops/declarable/generic/transforms/clip_by_global_norm.cpp +++ b/libnd4j/include/ops/declarable/generic/transforms/clip_by_global_norm.cpp @@ -55,7 +55,7 @@ DECLARE_SHAPE_FN(clip_by_global_norm) { shapeList->push_back(CONSTANT(newShape)); } - shapeList->push_back(ConstantShapeHelper::getInstance()->scalarShapeInfo(ArrayOptions::dataType(inputShape->at(0)))); + shapeList->push_back(ConstantShapeHelper::getInstance().scalarShapeInfo(ArrayOptions::dataType(inputShape->at(0)))); return shapeList; } diff --git a/libnd4j/include/ops/declarable/generic/transforms/concat.cpp b/libnd4j/include/ops/declarable/generic/transforms/concat.cpp index 1cf750e00..6c0901201 100644 --- a/libnd4j/include/ops/declarable/generic/transforms/concat.cpp +++ b/libnd4j/include/ops/declarable/generic/transforms/concat.cpp @@ -140,9 +140,9 @@ DECLARE_SHAPE_FN(concat) { if(inputShape->at(i)[0] == 0) { if (shape::isEmpty(inputShape->at(i))) - arrShapes.push_back(ConstantShapeHelper::getInstance()->vectorShapeInfo(0, INPUT_VARIABLE(0)->dataType())); + arrShapes.push_back(ConstantShapeHelper::getInstance().vectorShapeInfo(0, INPUT_VARIABLE(0)->dataType())); else - arrShapes.push_back(ConstantShapeHelper::getInstance()->vectorShapeInfo(1, INPUT_VARIABLE(0)->dataType())); + arrShapes.push_back(ConstantShapeHelper::getInstance().vectorShapeInfo(1, INPUT_VARIABLE(0)->dataType())); } else{ arrShapes.push_back(inputShape->at(i)); @@ -191,7 +191,7 @@ DECLARE_SHAPE_FN(concat) { // for(int index : shapesToDelete) // RELEASE(arrShapes[index], block.getWorkspace()); - auto result = ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(outShapeInfo)); + auto result = ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(outShapeInfo)); RELEASE(outShapeInfo, block.getWorkspace()); return SHAPELIST(result); } @@ -244,7 +244,7 @@ DECLARE_SHAPE_FN(concat) { // if (_dimension < 0) // _dimension += first->rankOf(); - // if (sd::Environment::getInstance()->isDebugAndVerbose()) { + // if (sd::Environment::getInstance().isDebugAndVerbose()) { // printf("Shape %i: ", 0); // shape::printShapeInfoLinear((Nd4jLong *) shapes[0]); // } @@ -262,12 +262,12 @@ DECLARE_SHAPE_FN(concat) { // oldScalars &= array->rankOf() == 2 && array->isScalar(); - // if (sd::Environment::getInstance()->isDebugAndVerbose()) { + // if (sd::Environment::getInstance().isDebugAndVerbose()) { // printf("Shape %i: ", e); // shape::printShapeInfoLinear(array->shapeInfo()); // } // } - // if (sd::Environment::getInstance()->isDebugAndVerbose()) + // if (sd::Environment::getInstance().isDebugAndVerbose()) // fflush(stdout); // if (oldScalars) { @@ -279,7 +279,7 @@ DECLARE_SHAPE_FN(concat) { // STORE_RESULT(*output); - // if (sd::Environment::getInstance()->isDebugAndVerbose()) + // if (sd::Environment::getInstance().isDebugAndVerbose()) // output->printShapeInfo("Concat result shape"); // delete[] buffers; @@ -428,7 +428,7 @@ DECLARE_SHAPE_FN(concat_bp) { for (int e = 0; e < numOfInArrs - 1; e++) { auto inShape = inputShape->at(e); - shapeList->push_back(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(ArrayOptions::dataType(inShape), shape::order(inShape), shape::shapeOf(inShape), shape::rank(inShape)))); + shapeList->push_back(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(ArrayOptions::dataType(inShape), shape::order(inShape), shape::shapeOf(inShape), shape::rank(inShape)))); } return shapeList; diff --git a/libnd4j/include/ops/declarable/generic/transforms/depth_to_space.cpp b/libnd4j/include/ops/declarable/generic/transforms/depth_to_space.cpp index dcf827eb1..cb966472f 100644 --- a/libnd4j/include/ops/declarable/generic/transforms/depth_to_space.cpp +++ b/libnd4j/include/ops/declarable/generic/transforms/depth_to_space.cpp @@ -82,7 +82,7 @@ namespace ops { else shape = {{bS, oD, oH, oW }}; - auto newShape = ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(in), 'c', 4, shape.data()); + auto newShape = ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(in), 'c', 4, shape.data()); return SHAPELIST(newShape); } } diff --git a/libnd4j/include/ops/declarable/generic/transforms/dynamic_stitch.cpp b/libnd4j/include/ops/declarable/generic/transforms/dynamic_stitch.cpp index ecf0e5324..d3c419b55 100644 --- a/libnd4j/include/ops/declarable/generic/transforms/dynamic_stitch.cpp +++ b/libnd4j/include/ops/declarable/generic/transforms/dynamic_stitch.cpp @@ -79,7 +79,7 @@ namespace ops { for(int i = 1; i < outRank; ++i) outShape[i] = shape::sizeAt(restShape, i); - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(ArrayOptions::dataType(restShape), shape::order(firstShape), outShape))); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(ArrayOptions::dataType(restShape), shape::order(firstShape), outShape))); } } } diff --git a/libnd4j/include/ops/declarable/generic/transforms/gather.cpp b/libnd4j/include/ops/declarable/generic/transforms/gather.cpp index 79ce8ad29..a979c5abd 100644 --- a/libnd4j/include/ops/declarable/generic/transforms/gather.cpp +++ b/libnd4j/include/ops/declarable/generic/transforms/gather.cpp @@ -161,7 +161,7 @@ DECLARE_SHAPE_FN(gather) { ArrayOptions::setPropertyBit(outputShapeInfo, ARRAY_EMPTY); } - auto result = ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(outputShapeInfo)); + auto result = ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(outputShapeInfo)); RELEASE(outputShapeInfo, block.getWorkspace()); return SHAPELIST(result); diff --git a/libnd4j/include/ops/declarable/generic/transforms/hashcode.cpp b/libnd4j/include/ops/declarable/generic/transforms/hashcode.cpp index 4196385c1..0ef9d71ce 100644 --- a/libnd4j/include/ops/declarable/generic/transforms/hashcode.cpp +++ b/libnd4j/include/ops/declarable/generic/transforms/hashcode.cpp @@ -41,7 +41,7 @@ namespace sd { }; DECLARE_SHAPE_FN(hashcode) { - return SHAPELIST(ConstantShapeHelper::getInstance()->scalarShapeInfo(sd::DataType::INT64)); + return SHAPELIST(ConstantShapeHelper::getInstance().scalarShapeInfo(sd::DataType::INT64)); } diff --git a/libnd4j/include/ops/declarable/generic/transforms/histogram.cpp b/libnd4j/include/ops/declarable/generic/transforms/histogram.cpp index 415361894..e08fcdbf5 100644 --- a/libnd4j/include/ops/declarable/generic/transforms/histogram.cpp +++ b/libnd4j/include/ops/declarable/generic/transforms/histogram.cpp @@ -43,7 +43,7 @@ namespace sd { DECLARE_SHAPE_FN(histogram) { auto numBins = INT_ARG(0); - return SHAPELIST(ConstantShapeHelper::getInstance()->vectorShapeInfo(numBins, sd::DataType::INT64)); + return SHAPELIST(ConstantShapeHelper::getInstance().vectorShapeInfo(numBins, sd::DataType::INT64)); } diff --git a/libnd4j/include/ops/declarable/generic/transforms/histogram_fixed_width.cpp b/libnd4j/include/ops/declarable/generic/transforms/histogram_fixed_width.cpp index 36175fc01..208baa5a9 100644 --- a/libnd4j/include/ops/declarable/generic/transforms/histogram_fixed_width.cpp +++ b/libnd4j/include/ops/declarable/generic/transforms/histogram_fixed_width.cpp @@ -57,7 +57,7 @@ DECLARE_TYPES(histogram_fixed_width) { DECLARE_SHAPE_FN(histogram_fixed_width) { const int nbins = block.width() == 3 ? INPUT_VARIABLE(2)->e(0) : block.getIArguments()->empty() ? 100 : INT_ARG(0); - auto outShapeInfo = ConstantShapeHelper::getInstance()->vectorShapeInfo(nbins, DataType::INT64); + auto outShapeInfo = ConstantShapeHelper::getInstance().vectorShapeInfo(nbins, DataType::INT64); return SHAPELIST(outShapeInfo); } diff --git a/libnd4j/include/ops/declarable/generic/transforms/merge_add.cpp b/libnd4j/include/ops/declarable/generic/transforms/merge_add.cpp index 64858001a..0fade28bf 100644 --- a/libnd4j/include/ops/declarable/generic/transforms/merge_add.cpp +++ b/libnd4j/include/ops/declarable/generic/transforms/merge_add.cpp @@ -86,7 +86,7 @@ DECLARE_SYN(accumulate_n, mergeadd); for (int e = 0; e < numOfInArrs; e++) { auto inShape = inputShape->at(e); - shapeList->push_back(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(ArrayOptions::dataType(inShape), shape::order(inShape), shape::shapeOf(inShape), shape::rank(inShape)))); + shapeList->push_back(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(ArrayOptions::dataType(inShape), shape::order(inShape), shape::shapeOf(inShape), shape::rank(inShape)))); } return shapeList; diff --git a/libnd4j/include/ops/declarable/generic/transforms/merge_avg.cpp b/libnd4j/include/ops/declarable/generic/transforms/merge_avg.cpp index 83a448170..2ea0d501b 100644 --- a/libnd4j/include/ops/declarable/generic/transforms/merge_avg.cpp +++ b/libnd4j/include/ops/declarable/generic/transforms/merge_avg.cpp @@ -80,7 +80,7 @@ OP_IMPL(mergeavg, -1, 1, false) { for (int e = 0; e < numOfInArrs; e++) { auto inShape = inputShape->at(e); - shapeList->push_back(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(ArrayOptions::dataType(inShape), shape::order(inShape), shape::shapeOf(inShape), shape::rank(inShape)))); + shapeList->push_back(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(ArrayOptions::dataType(inShape), shape::order(inShape), shape::shapeOf(inShape), shape::rank(inShape)))); } return shapeList; diff --git a/libnd4j/include/ops/declarable/generic/transforms/merge_max.cpp b/libnd4j/include/ops/declarable/generic/transforms/merge_max.cpp index 49ab78f7c..e95092f38 100644 --- a/libnd4j/include/ops/declarable/generic/transforms/merge_max.cpp +++ b/libnd4j/include/ops/declarable/generic/transforms/merge_max.cpp @@ -85,7 +85,7 @@ DECLARE_SYN(MergeMax, mergemax); for (int e = 0; e < numOfInArrs; e++) { auto inShape = inputShape->at(e); - shapeList->push_back(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(ArrayOptions::dataType(inShape), shape::order(inShape), shape::shapeOf(inShape), shape::rank(inShape)))); + shapeList->push_back(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(ArrayOptions::dataType(inShape), shape::order(inShape), shape::shapeOf(inShape), shape::rank(inShape)))); } return shapeList; diff --git a/libnd4j/include/ops/declarable/generic/transforms/mirrorPad.cpp b/libnd4j/include/ops/declarable/generic/transforms/mirrorPad.cpp index 143e57a80..403272530 100644 --- a/libnd4j/include/ops/declarable/generic/transforms/mirrorPad.cpp +++ b/libnd4j/include/ops/declarable/generic/transforms/mirrorPad.cpp @@ -81,7 +81,7 @@ DECLARE_SHAPE_FN(mirror_pad) { if(rank == 1) { Nd4jLong len = input->lengthOf() + paddings->e(0) + paddings->e(1); - return SHAPELIST(ConstantShapeHelper::getInstance()->vectorShapeInfo(len, input->dataType())); + return SHAPELIST(ConstantShapeHelper::getInstance().vectorShapeInfo(len, input->dataType())); } Nd4jLong* outShapeInfo(nullptr); diff --git a/libnd4j/include/ops/declarable/generic/transforms/pad.cpp b/libnd4j/include/ops/declarable/generic/transforms/pad.cpp index d5d38aaeb..d09063a95 100644 --- a/libnd4j/include/ops/declarable/generic/transforms/pad.cpp +++ b/libnd4j/include/ops/declarable/generic/transforms/pad.cpp @@ -104,7 +104,7 @@ DECLARE_SHAPE_FN(pad) { ShapeUtils::updateStridesAndType(outShapeInfo, inputShapeInfo, shape::order(inputShapeInfo)); ShapeDescriptor descriptor(outShapeInfo); RELEASE(outShapeInfo, block.getWorkspace()); - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(descriptor)); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(descriptor)); } diff --git a/libnd4j/include/ops/declarable/generic/transforms/repeat.cpp b/libnd4j/include/ops/declarable/generic/transforms/repeat.cpp index 99ab3d635..b02f7010c 100644 --- a/libnd4j/include/ops/declarable/generic/transforms/repeat.cpp +++ b/libnd4j/include/ops/declarable/generic/transforms/repeat.cpp @@ -66,7 +66,7 @@ DECLARE_SHAPE_FN(repeat) { auto outShape = ShapeUtils::evalRepeatShape(axis, repeats, *input); - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(input->dataType(), input->ordering(), outShape))); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(input->dataType(), input->ordering(), outShape))); } } diff --git a/libnd4j/include/ops/declarable/generic/transforms/slice.cpp b/libnd4j/include/ops/declarable/generic/transforms/slice.cpp index 96e7fe6b3..822f48681 100644 --- a/libnd4j/include/ops/declarable/generic/transforms/slice.cpp +++ b/libnd4j/include/ops/declarable/generic/transforms/slice.cpp @@ -87,13 +87,13 @@ namespace sd { shape::calcSubArrShapeInfoAndOffset(indices.data(), input->shapeInfo(), subArrShapeInfo, offset, true); - auto subArrShapeInfoPack = ConstantShapeHelper::getInstance()->bufferForShapeInfo(subArrShapeInfo); + auto subArrShapeInfoPack = ConstantShapeHelper::getInstance().bufferForShapeInfo(subArrShapeInfo); NDArray::prepareSpecialUse({output}, {input}); NativeOpExecutioner::execTransformAny(block.launchContext(), sd::transform::Assign, - input->bufferWithOffset(offset), reinterpret_cast(subArrShapeInfoPack.primary()), - input->specialBufferWithOffset(offset), reinterpret_cast(subArrShapeInfoPack.special()), + input->bufferWithOffset(offset), subArrShapeInfoPack.primary(), + input->specialBufferWithOffset(offset), subArrShapeInfoPack.special(), output->buffer(), output->shapeInfo(), output->specialBuffer(), output->specialShapeInfo(), nullptr, nullptr, nullptr, true); @@ -160,7 +160,7 @@ namespace sd { shape.emplace_back(size); } - auto newShape = ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(inShape), 'c', shape); + auto newShape = ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(inShape), 'c', shape); return SHAPELIST(newShape); } diff --git a/libnd4j/include/ops/declarable/generic/transforms/space_to_batch.cpp b/libnd4j/include/ops/declarable/generic/transforms/space_to_batch.cpp index 9a1683818..ffffb5396 100644 --- a/libnd4j/include/ops/declarable/generic/transforms/space_to_batch.cpp +++ b/libnd4j/include/ops/declarable/generic/transforms/space_to_batch.cpp @@ -91,7 +91,7 @@ DECLARE_SHAPE_FN(space_to_batch) { REQUIRE_TRUE((inputShapeInfo[2] + padBottom + padTop) % blockSize == 0 && (inputShapeInfo[3] + padLeft + padRight) % blockSize == 0, 0, "SpaceToBatch: after padding, second and third dimensions of input array must be divisible by blockSize !"); - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(inputShapeInfo), 'c', {inputShapeInfo[1] * blockSize * blockSize, (inputShapeInfo[2] + padBottom + padTop) / blockSize, (inputShapeInfo[3] + padLeft + padRight) / blockSize, inputShapeInfo[4]})); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(inputShapeInfo), 'c', {inputShapeInfo[1] * blockSize * blockSize, (inputShapeInfo[2] + padBottom + padTop) / blockSize, (inputShapeInfo[3] + padLeft + padRight) / blockSize, inputShapeInfo[4]})); } } diff --git a/libnd4j/include/ops/declarable/generic/transforms/space_to_batch_nd.cpp b/libnd4j/include/ops/declarable/generic/transforms/space_to_batch_nd.cpp index 0b8c4152d..5adc35ee6 100644 --- a/libnd4j/include/ops/declarable/generic/transforms/space_to_batch_nd.cpp +++ b/libnd4j/include/ops/declarable/generic/transforms/space_to_batch_nd.cpp @@ -96,7 +96,7 @@ DECLARE_SHAPE_FN(space_to_batch_nd) { for (uint i = 0; i < numOfSpatialDims; ++i) outShape[i + 1] = (outShape[i + 1] + INPUT_VARIABLE(2)->e(i,0) + INPUT_VARIABLE(2)->e(i,1)) / INPUT_VARIABLE(1)->e(i); - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(inputShapeInfo), 'c', outShape)); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(inputShapeInfo), 'c', outShape)); } } diff --git a/libnd4j/include/ops/declarable/generic/transforms/space_to_depth.cpp b/libnd4j/include/ops/declarable/generic/transforms/space_to_depth.cpp index b831dce2f..7e108028a 100644 --- a/libnd4j/include/ops/declarable/generic/transforms/space_to_depth.cpp +++ b/libnd4j/include/ops/declarable/generic/transforms/space_to_depth.cpp @@ -80,7 +80,7 @@ namespace ops { else shape = {{bS, oD, oH, oW }}; - auto newShape = ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(in), 'c', 4, shape.data()); + auto newShape = ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(in), 'c', 4, shape.data()); return SHAPELIST(newShape); } } diff --git a/libnd4j/include/ops/declarable/generic/transforms/split.cpp b/libnd4j/include/ops/declarable/generic/transforms/split.cpp index 462f2c77e..3fb925dfc 100644 --- a/libnd4j/include/ops/declarable/generic/transforms/split.cpp +++ b/libnd4j/include/ops/declarable/generic/transforms/split.cpp @@ -115,7 +115,7 @@ namespace ops { //Edge case: splitting empty array (mainly for TF import compatibility) -> return N empty arrays // if(INPUT_VARIABLE(inputVar)->isEmpty()){ // for (int e = 0; e < num_splits; e++) { - // auto empty = ConstantShapeHelper::getInstance()->emptyShapeInfo(dataType); + // auto empty = ConstantShapeHelper::getInstance().emptyShapeInfo(dataType); // shapes->push_back(empty); // } // return shapes; @@ -136,7 +136,7 @@ namespace ops { shape[e] = shape::sizeAt(input, e); for (int e = 0; e < num_splits; e++) { - auto newShape = ConstantShapeHelper::getInstance()->createShapeInfo(dataType, shape::order(input), shape); + auto newShape = ConstantShapeHelper::getInstance().createShapeInfo(dataType, shape::order(input), shape); shapes->push_back(newShape); } diff --git a/libnd4j/include/ops/declarable/generic/transforms/split_v.cpp b/libnd4j/include/ops/declarable/generic/transforms/split_v.cpp index 0bda3a6be..decda2e2d 100644 --- a/libnd4j/include/ops/declarable/generic/transforms/split_v.cpp +++ b/libnd4j/include/ops/declarable/generic/transforms/split_v.cpp @@ -116,7 +116,7 @@ namespace ops { shape[d] = c_size; } - auto newShape = ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(input), shape::order(input), shape); + auto newShape = ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(input), shape::order(input), shape); shapeList->push_back(newShape); } diff --git a/libnd4j/include/ops/declarable/generic/transforms/stack.cpp b/libnd4j/include/ops/declarable/generic/transforms/stack.cpp index 65cd41a3a..af03d5ef1 100644 --- a/libnd4j/include/ops/declarable/generic/transforms/stack.cpp +++ b/libnd4j/include/ops/declarable/generic/transforms/stack.cpp @@ -82,16 +82,16 @@ DECLARE_SHAPE_FN(stack) { case 0: { // we're going to return rank 1 here if (block.width() == 1) { - return SHAPELIST(ConstantShapeHelper::getInstance()->vectorShapeInfo(0, ArrayOptions::dataType(inShapeInfo))); + return SHAPELIST(ConstantShapeHelper::getInstance().vectorShapeInfo(0, ArrayOptions::dataType(inShapeInfo))); } else { - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(inShapeInfo), 'c', {(Nd4jLong) block.width(), 0})); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(inShapeInfo), 'c', {(Nd4jLong) block.width(), 0})); } } } } if(rank == 0) { - return SHAPELIST(ConstantShapeHelper::getInstance()->vectorShapeInfo(block.width(), ArrayOptions::dataType(inShapeInfo))); + return SHAPELIST(ConstantShapeHelper::getInstance().vectorShapeInfo(block.width(), ArrayOptions::dataType(inShapeInfo))); } //the rank of output ShapeInfo is larger by one compared to input ShapeInfo @@ -99,7 +99,7 @@ DECLARE_SHAPE_FN(stack) { // insert (int) block.width() at dim position of input shape to get output shape outShape.insert(outShape.begin() + Nd4jLong(dim), (Nd4jLong) block.width()); - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(ArrayOptions::dataType(inShapeInfo), shape::order(inShapeInfo), outShape))); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(ArrayOptions::dataType(inShapeInfo), shape::order(inShapeInfo), outShape))); } diff --git a/libnd4j/include/ops/declarable/generic/transforms/tear.cpp b/libnd4j/include/ops/declarable/generic/transforms/tear.cpp index 61850ab0e..b2292e2b9 100644 --- a/libnd4j/include/ops/declarable/generic/transforms/tear.cpp +++ b/libnd4j/include/ops/declarable/generic/transforms/tear.cpp @@ -57,12 +57,12 @@ namespace sd { if (dims.size() > 1) std::sort(dims.begin(), dims.end()); - auto tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(inShape, dims); + auto tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(inShape, dims); auto numTads = tadPack.numberOfTads(); auto result = SHAPELIST(); for (Nd4jLong e = 0; e < numTads; e++) { - auto newShape = ConstantShapeHelper::getInstance()->createShapeInfo(block.dataType(), shape::order(inShape), shape::rank(tadPack.primaryShapeInfo()), shape::shapeOf(tadPack.primaryShapeInfo())); + auto newShape = ConstantShapeHelper::getInstance().createShapeInfo(block.dataType(), shape::order(inShape), shape::rank(tadPack.primaryShapeInfo()), shape::shapeOf(tadPack.primaryShapeInfo())); result->push_back(newShape); } diff --git a/libnd4j/include/ops/declarable/generic/transforms/tile.cpp b/libnd4j/include/ops/declarable/generic/transforms/tile.cpp index 4dc259bba..e8a502e74 100644 --- a/libnd4j/include/ops/declarable/generic/transforms/tile.cpp +++ b/libnd4j/include/ops/declarable/generic/transforms/tile.cpp @@ -93,7 +93,7 @@ DECLARE_SHAPE_FN(tile) { for (int e = 0; e < shape::rank(inShape); e++) shape[e] = shape::sizeAt(inShape, e) * reps[e]; - auto newShape = ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(inShape), shape::order(inShape), shape); + auto newShape = ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(inShape), shape::order(inShape), shape); return SHAPELIST(newShape); } diff --git a/libnd4j/include/ops/declarable/generic/transforms/unstack.cpp b/libnd4j/include/ops/declarable/generic/transforms/unstack.cpp index beebcad86..0dfe1e54c 100644 --- a/libnd4j/include/ops/declarable/generic/transforms/unstack.cpp +++ b/libnd4j/include/ops/declarable/generic/transforms/unstack.cpp @@ -77,7 +77,7 @@ DECLARE_SHAPE_FN(unstack) { auto result = SHAPELIST(); for(uint i = 0; i < numTads; ++i) - result->push_back(ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(inShapeInfo), shape::order(inShapeInfo), outShape)); + result->push_back(ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(inShapeInfo), shape::order(inShapeInfo), outShape)); return result; } @@ -88,7 +88,7 @@ DECLARE_SHAPE_FN(unstack) { auto result = SHAPELIST(); for (Nd4jLong e = 0; e < shape::length(inShapeInfo); e++) - result->push_back(ConstantShapeHelper::getInstance()->scalarShapeInfo(ArrayOptions::dataType(inShapeInfo))); + result->push_back(ConstantShapeHelper::getInstance().scalarShapeInfo(ArrayOptions::dataType(inShapeInfo))); return result; } @@ -110,7 +110,7 @@ DECLARE_SHAPE_FN(unstack) { auto result = SHAPELIST(); for (int e = 0; e < shape::shapeOf(inShapeInfo)[dim]; e++) { - auto newShape = ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(inShapeInfo), shape::order(inShapeInfo), subArrShape); + auto newShape = ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(inShapeInfo), shape::order(inShapeInfo), subArrShape); result->push_back(newShape); } return result; diff --git a/libnd4j/include/ops/declarable/generic/util/print_affinity.cpp b/libnd4j/include/ops/declarable/generic/util/print_affinity.cpp index 5518588e4..f7a758af6 100644 --- a/libnd4j/include/ops/declarable/generic/util/print_affinity.cpp +++ b/libnd4j/include/ops/declarable/generic/util/print_affinity.cpp @@ -44,7 +44,7 @@ namespace sd { } DECLARE_SHAPE_FN(print_affinity) { - return SHAPELIST(ConstantShapeHelper::getInstance()->scalarShapeInfo(DataType::INT32)); + return SHAPELIST(ConstantShapeHelper::getInstance().scalarShapeInfo(DataType::INT32)); } } } diff --git a/libnd4j/include/ops/declarable/generic/util/print_variable.cpp b/libnd4j/include/ops/declarable/generic/util/print_variable.cpp index 9d3369627..74ff99fd2 100644 --- a/libnd4j/include/ops/declarable/generic/util/print_variable.cpp +++ b/libnd4j/include/ops/declarable/generic/util/print_variable.cpp @@ -42,7 +42,7 @@ namespace sd { if (block.numB() > 0) printSpecial = B_ARG(0); - if (printSpecial && !sd::Environment::getInstance()->isCPU()) { + if (printSpecial && !sd::Environment::getInstance().isCPU()) { // only specific backends support special printout. for cpu-based backends it's the same as regular print if (block.width() == 2) @@ -69,7 +69,7 @@ namespace sd { } DECLARE_SHAPE_FN(print_variable) { - return SHAPELIST(ConstantShapeHelper::getInstance()->scalarShapeInfo(DataType::INT32)); + return SHAPELIST(ConstantShapeHelper::getInstance().scalarShapeInfo(DataType::INT32)); } } } diff --git a/libnd4j/include/ops/declarable/helpers/cpu/addBias.cpp b/libnd4j/include/ops/declarable/helpers/cpu/addBias.cpp index a03b4504f..aa86ea041 100644 --- a/libnd4j/include/ops/declarable/helpers/cpu/addBias.cpp +++ b/libnd4j/include/ops/declarable/helpers/cpu/addBias.cpp @@ -482,7 +482,7 @@ namespace sd { if (isContinuous) { //we can choose other inc and index for that case //but for now lets choose all till the last one - uint32_t req_numThreads = sd::Environment::getInstance()->maxMasterThreads(); + uint32_t req_numThreads = sd::Environment::getInstance().maxMasterThreads(); isContinuous = false; if (rank > 2) { if (req_numThreads < 2 || bases[rank - 1] >= req_numThreads) { @@ -582,7 +582,7 @@ namespace sd { if (order == 'c' && isContinuous) { //sometimes last dimension is too big and multithreading could suffer using unfair partitioning //so we will do it only when inc is smaller our value or multithreading turned off - uint32_t req_numThreads = sd::Environment::getInstance()->maxMasterThreads(); + uint32_t req_numThreads = sd::Environment::getInstance().maxMasterThreads(); if (req_numThreads < 2 || numNC >= req_numThreads || inc <= 2 * 8196 || rank == 3) { inc = numHW; } diff --git a/libnd4j/include/ops/declarable/helpers/cpu/adjust_hue.cpp b/libnd4j/include/ops/declarable/helpers/cpu/adjust_hue.cpp index 20d91ee8b..3f37666e7 100644 --- a/libnd4j/include/ops/declarable/helpers/cpu/adjust_hue.cpp +++ b/libnd4j/include/ops/declarable/helpers/cpu/adjust_hue.cpp @@ -59,8 +59,8 @@ static void adjustHue_(const NDArray *input, const NDArray* deltaScalarArr, NDAr } else { - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), dimC); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), dimC); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), dimC); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), dimC); const Nd4jLong numOfTads = packX.numberOfTads(); const Nd4jLong xDimCstride = input->stridesOf()[dimC]; diff --git a/libnd4j/include/ops/declarable/helpers/cpu/adjust_saturation.cpp b/libnd4j/include/ops/declarable/helpers/cpu/adjust_saturation.cpp index 6610b69ac..63f26c90f 100644 --- a/libnd4j/include/ops/declarable/helpers/cpu/adjust_saturation.cpp +++ b/libnd4j/include/ops/declarable/helpers/cpu/adjust_saturation.cpp @@ -58,8 +58,8 @@ static void adjustSaturation_(const NDArray *input, const NDArray* factorScalarA samediff::Threads::parallel_for(func, 0, input->lengthOf(), 3); } else { - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), dimC); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), dimC); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), dimC); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), dimC); const Nd4jLong numOfTads = packX.numberOfTads(); const Nd4jLong xDimCstride = input->stridesOf()[dimC]; diff --git a/libnd4j/include/ops/declarable/helpers/cpu/batched_gemm.cpp b/libnd4j/include/ops/declarable/helpers/cpu/batched_gemm.cpp index ec8f040a9..0c9338a8e 100644 --- a/libnd4j/include/ops/declarable/helpers/cpu/batched_gemm.cpp +++ b/libnd4j/include/ops/declarable/helpers/cpu/batched_gemm.cpp @@ -35,7 +35,7 @@ void bgemm_(const std::vector& vA, const std::vector& vB, st int batchSize = vA.size(); - if (BlasHelper::getInstance()->hasBatchedGEMM()) { + if (BlasHelper::getInstance().hasBatchedGEMM()) { auto arr = vA.at(0); CBLAS_TRANSPOSE *tA, *tB; int *tM, *tN, *tK, *tldA, *tldB, *tldC, *tsize; @@ -72,9 +72,9 @@ void bgemm_(const std::vector& vA, const std::vector& vB, st } if (std::is_same::value) { - BlasHelper::getInstance()->dgemmBatched()(CblasColMajor, tA, tB, tM, tN, tK, (double *) alphas->buffer(), (double **) buffersA.data(), tldA, (double **) buffersB.data(), tldB, (double *) betas->buffer(),(double **) buffersC.data(), tldC, vA.size(), tsize); + BlasHelper::getInstance().dgemmBatched()(CblasColMajor, tA, tB, tM, tN, tK, (double *) alphas->buffer(), (double **) buffersA.data(), tldA, (double **) buffersB.data(), tldB, (double *) betas->buffer(),(double **) buffersC.data(), tldC, vA.size(), tsize); } else if (std::is_same::value) { - BlasHelper::getInstance()->sgemmBatched()(CblasColMajor, tA, tB, tM, tN, tK, (float *) alphas->buffer(), (float **) buffersA.data(), tldA, (float **) buffersB.data(), tldB, (float *) betas->buffer(), (float **) buffersC.data(), tldC, vA.size(), tsize); + BlasHelper::getInstance().sgemmBatched()(CblasColMajor, tA, tB, tM, tN, tK, (float *) alphas->buffer(), (float **) buffersA.data(), tldA, (float **) buffersB.data(), tldB, (float *) betas->buffer(), (float **) buffersC.data(), tldC, vA.size(), tsize); } // release temporary arrays diff --git a/libnd4j/include/ops/declarable/helpers/cpu/dynamic.cpp b/libnd4j/include/ops/declarable/helpers/cpu/dynamic.cpp index 2b6b4cd02..89cf680d4 100644 --- a/libnd4j/include/ops/declarable/helpers/cpu/dynamic.cpp +++ b/libnd4j/include/ops/declarable/helpers/cpu/dynamic.cpp @@ -38,7 +38,7 @@ namespace sd { unsigned int outSize = outputList.size(); - //PRAGMA_OMP_PARALLEL_FOR_IF(outSize > Environment::getInstance()->tadThreshold()) + //PRAGMA_OMP_PARALLEL_FOR_IF(outSize > Environment::getInstance().tadThreshold()) for (unsigned int i = 0; i < outSize; i++) { outputs[i].first = outputList[i]; std::vector outDims(outputs[i].first->rankOf() - 1); @@ -52,7 +52,7 @@ namespace sd { outputs[i].second = 0; - //PRAGMA_OMP_PARALLEL_FOR_IF(indices->lengthOf() > Environment::getInstance()->elementwiseThreshold()) + //PRAGMA_OMP_PARALLEL_FOR_IF(indices->lengthOf() > Environment::getInstance().elementwiseThreshold()) for (Nd4jLong e = 0; e < indices->lengthOf(); ++e) if ((*indices).e(e) == i) listOutForCurrent.at(outputs[i].second++)->assign(listOfTensors.at(e)); diff --git a/libnd4j/include/ops/declarable/helpers/cpu/gather.cpp b/libnd4j/include/ops/declarable/helpers/cpu/gather.cpp index 1deb12752..c28101558 100644 --- a/libnd4j/include/ops/declarable/helpers/cpu/gather.cpp +++ b/libnd4j/include/ops/declarable/helpers/cpu/gather.cpp @@ -78,8 +78,8 @@ void gather(sd::LaunchContext * context, const NDArray* input, const NDArray* in const Nd4jLong numOfSubArrs = indices->lengthOf(); - auto inTadPack = ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), dimsIn); - auto outTadPack = ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), dimsOut); + auto inTadPack = ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), dimsIn); + auto outTadPack = ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), dimsOut); auto inTadShapeInfo = inTadPack.primaryShapeInfo(); auto outTadShapeInfo = outTadPack.primaryShapeInfo(); @@ -105,8 +105,8 @@ void gather(sd::LaunchContext * context, const NDArray* input, const NDArray* in auto outBuff = output->bufferWithOffset(outTadPack.primaryOffsets()[i]); NativeOpExecutioner::execTransformAny(input->getContext(), transform::Assign, - inBuff, inTadShapeInfo, nullptr/*input specialBuffer*/, nullptr/*input specialShapeInfo*/, - outBuff, outTadShapeInfo, nullptr/*output specialBuffer*/, nullptr/*output specialShapeInfo*/, + inBuff, inTadShapeInfo, nullptr/*input specialBuffer*/, nullptr/*input special*/, + outBuff, outTadShapeInfo, nullptr/*output specialBuffer*/, nullptr/*output special*/, nullptr, nullptr, nullptr, false/*allowParallelism*/); } }; @@ -129,8 +129,8 @@ void gather(sd::LaunchContext * context, const NDArray* input, const NDArray* in std::vector dims = ShapeUtils::evalDimsToExclude(input->rankOf(), {axis}); - auto inTadPack = ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), dims); - auto outTadPack = ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), dims); + auto inTadPack = ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), dims); + auto outTadPack = ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), dims); auto inTadShapeInfo = inTadPack.primaryShapeInfo(); auto outTadShapeInfo = outTadPack.primaryShapeInfo(); @@ -158,8 +158,8 @@ void gather(sd::LaunchContext * context, const NDArray* input, const NDArray* in auto outBuff = output->bufferWithOffset(outTadPack.primaryOffsets()[i]); NativeOpExecutioner::execTransformAny(input->getContext(), transform::Assign, - inBuff, inTadShapeInfo, nullptr/*input specialBuffer*/, nullptr/*input specialShapeInfo*/, - outBuff, outTadShapeInfo, nullptr/*output specialBuffer*/, nullptr/*output specialShapeInfo*/, + inBuff, inTadShapeInfo, nullptr/*input specialBuffer*/, nullptr/*input special*/, + outBuff, outTadShapeInfo, nullptr/*output specialBuffer*/, nullptr/*output special*/, nullptr, nullptr, nullptr, false/*allowParallelism*/); } diff --git a/libnd4j/include/ops/declarable/helpers/cpu/gatherTransforms.cpp b/libnd4j/include/ops/declarable/helpers/cpu/gatherTransforms.cpp index db62c4b4f..e6f1a3896 100644 --- a/libnd4j/include/ops/declarable/helpers/cpu/gatherTransforms.cpp +++ b/libnd4j/include/ops/declarable/helpers/cpu/gatherTransforms.cpp @@ -116,7 +116,7 @@ static void gather_(NDArray* input, const NDArray* indices, NDArray* output, con output->assign(scalarNDArray); } else { auto dimensions = ShapeUtils::evalDimsToExclude(input->rankOf(), {axis}); - auto tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), dimensions); + auto tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), dimensions); auto tadArr = NDArray(reinterpret_cast(reinterpret_cast(input->buffer()) + tadPack.primaryOffsets()[indices->e(0)]), tadPack.primaryShapeInfo(), output->getContext()); output->assign(&tadArr); diff --git a/libnd4j/include/ops/declarable/helpers/cpu/imagesHelpers.cpp b/libnd4j/include/ops/declarable/helpers/cpu/imagesHelpers.cpp index 2183b7d5a..108804f38 100644 --- a/libnd4j/include/ops/declarable/helpers/cpu/imagesHelpers.cpp +++ b/libnd4j/include/ops/declarable/helpers/cpu/imagesHelpers.cpp @@ -91,8 +91,8 @@ FORCEINLINE static void rgbToFromYuv_(const NDArray& input, NDArray& output, con return; } - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input.shapeInfo(), dimC); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output.shapeInfo(), dimC); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input.shapeInfo(), dimC); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output.shapeInfo(), dimC); const Nd4jLong numOfTads = packX.numberOfTads(); const Nd4jLong xDimCstride = input.stridesOf()[dimC]; @@ -149,8 +149,8 @@ FORCEINLINE static void tripleTransformer(const NDArray* input, NDArray* output, samediff::Threads::parallel_for(func, 0, input->lengthOf(), 3); } else { - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), dimC); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), dimC); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), dimC); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), dimC); const Nd4jLong numOfTads = packX.numberOfTads(); const Nd4jLong xDimCstride = input->stridesOf()[dimC]; @@ -199,8 +199,8 @@ FORCEINLINE static void tripleTransformer(const NDArray* input, NDArray* output, samediff::Threads::parallel_for(func, 0, input->lengthOf(), 3); } else { - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), dimC); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), dimC); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), dimC); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), dimC); const Nd4jLong numOfTads = packX.numberOfTads(); const Nd4jLong xDimCstride = input->stridesOf()[dimC]; diff --git a/libnd4j/include/ops/declarable/helpers/cpu/indexReductions.hpp b/libnd4j/include/ops/declarable/helpers/cpu/indexReductions.hpp index 7d376e012..910e10314 100644 --- a/libnd4j/include/ops/declarable/helpers/cpu/indexReductions.hpp +++ b/libnd4j/include/ops/declarable/helpers/cpu/indexReductions.hpp @@ -389,7 +389,7 @@ namespace sd { { Nd4jLong inner_total; Nd4jLong inner_last = 0; - int maxThreads = sd::Environment::getInstance()->maxMasterThreads(); + int maxThreads = sd::Environment::getInstance().maxMasterThreads(); if (second_rank == 1) { inner_total = inner_bases[0]; if (inner_total < threadingThreshold) { @@ -764,7 +764,7 @@ namespace sd { func(0, 0, total, 1); #else // - uint32_t numThreads = sd::Environment::getInstance()->maxMasterThreads(); + uint32_t numThreads = sd::Environment::getInstance().maxMasterThreads(); Nd4jLong inner_total = getLength(inner_bases, second_rank); if (total * inner_total <= threadingThreshold) { numThreads = 1; diff --git a/libnd4j/include/ops/declarable/helpers/cpu/ismax.cpp b/libnd4j/include/ops/declarable/helpers/cpu/ismax.cpp index 687153f99..c2bcb8399 100644 --- a/libnd4j/include/ops/declarable/helpers/cpu/ismax.cpp +++ b/libnd4j/include/ops/declarable/helpers/cpu/ismax.cpp @@ -125,8 +125,8 @@ static void ismax_(const NDArray* input, NDArray* output, const std::vector //moving all dimensions (in sorted order) //to the back. //permuted version of the input shape info for setting up the tad problem - auto tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), const_cast(dimensions.data()), dimensionsLength); - auto tadPackZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), const_cast(dimensions.data()), dimensionsLength); + auto tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), const_cast(dimensions.data()), dimensionsLength); + auto tadPackZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), const_cast(dimensions.data()), dimensionsLength); auto tadShapeShapeInfo = tadPack.primaryShapeInfo(); diff --git a/libnd4j/include/ops/declarable/helpers/cpu/lrn.cpp b/libnd4j/include/ops/declarable/helpers/cpu/lrn.cpp index 8dc31d8c0..b49f8e61c 100644 --- a/libnd4j/include/ops/declarable/helpers/cpu/lrn.cpp +++ b/libnd4j/include/ops/declarable/helpers/cpu/lrn.cpp @@ -35,13 +35,13 @@ static int lrnFunctor_(sd::graph::Context& block, NDArray* input, NDArray* outpu const int rank = input->rankOf(); - TadPack inTadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), {rank - 1}); + TadPack inTadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), {rank - 1}); TadPack outTadPack; if(shape::haveSameShapeAndStrides(input->shapeInfo(), output->shapeInfo())) outTadPack = inTadPack; else - outTadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), {rank - 1}); + outTadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), {rank - 1}); const Nd4jLong numOfTads = inTadPack.numberOfTads(); const Nd4jLong tadLen = input->sizeAt(-1); @@ -151,13 +151,13 @@ static void lrnBP_(const NDArray& input, const NDArray& gradO, NDArray& gradI, c const int rank = input.rankOf(); - TadPack inTadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(input.shapeInfo(), {rank - 1}); + TadPack inTadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(input.shapeInfo(), {rank - 1}); TadPack gradITadPack; if(shape::haveSameShapeAndStrides(input.shapeInfo(), gradI.shapeInfo())) gradITadPack = inTadPack; else - gradITadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(gradI.shapeInfo(), {rank - 1}); + gradITadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(gradI.shapeInfo(), {rank - 1}); const Nd4jLong numOfTads = inTadPack.numberOfTads(); const Nd4jLong tadLen = input.sizeAt(-1); diff --git a/libnd4j/include/ops/declarable/helpers/cpu/lup.cpp b/libnd4j/include/ops/declarable/helpers/cpu/lup.cpp index 482709455..8f45c696b 100644 --- a/libnd4j/include/ops/declarable/helpers/cpu/lup.cpp +++ b/libnd4j/include/ops/declarable/helpers/cpu/lup.cpp @@ -111,7 +111,7 @@ namespace helpers { invertedMatrix->r(i, i) /= inputMatrix->t(i, i); }; - //PRAGMA_OMP_PARALLEL_FOR_IF(n > Environment::getInstance()->elementwiseThreshold()) + //PRAGMA_OMP_PARALLEL_FOR_IF(n > Environment::getInstance().elementwiseThreshold()) auto invertUpDiagonals = PRAGMA_THREADS_FOR { for (auto i = start; i < stop; i += increment) invertedMatrix->r(i, i + 1) -= (inputMatrix->t(i, i + 1) * invertedMatrix->t(i + 1, i + 1) / diff --git a/libnd4j/include/ops/declarable/helpers/cpu/nth_element.cpp b/libnd4j/include/ops/declarable/helpers/cpu/nth_element.cpp index 53565f3c1..b9225e40d 100644 --- a/libnd4j/include/ops/declarable/helpers/cpu/nth_element.cpp +++ b/libnd4j/include/ops/declarable/helpers/cpu/nth_element.cpp @@ -47,7 +47,7 @@ namespace helpers { else { // rank greater than 1 std::vector lastDims({input->rankOf() - 1});// = ShapeUtils::evalDimsToExclude(input->rankOf(), {input->rankOf() - 1}); - auto pack = sd::ConstantTadHelper::getInstance()->tadForDimensions(sortedVals.shapeInfo(), lastDims); + auto pack = sd::ConstantTadHelper::getInstance().tadForDimensions(sortedVals.shapeInfo(), lastDims); SpecialMethods::sortTadGeneric(sortedVals.buffer(), sortedVals.shapeInfo(), lastDims.data(), lastDims.size(), pack.primaryShapeInfo(), pack.primaryOffsets(), reverse); diff --git a/libnd4j/include/ops/declarable/helpers/cpu/one_hot.cpp b/libnd4j/include/ops/declarable/helpers/cpu/one_hot.cpp index 2aa14585b..41a265ca9 100644 --- a/libnd4j/include/ops/declarable/helpers/cpu/one_hot.cpp +++ b/libnd4j/include/ops/declarable/helpers/cpu/one_hot.cpp @@ -31,7 +31,7 @@ namespace sd { auto output = reinterpret_cast(voutput); auto indices = reinterpret_cast(vindices); - auto tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(zShapeInfo, {axis}); + auto tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(zShapeInfo, {axis}); auto iLen = static_cast(shape::length(iShapeInfo)); auto tLen = static_cast(shape::length(tadPack.primaryShapeInfo())); diff --git a/libnd4j/include/ops/declarable/helpers/cpu/randomShuffle.cpp b/libnd4j/include/ops/declarable/helpers/cpu/randomShuffle.cpp index a7f40899a..ea529112d 100644 --- a/libnd4j/include/ops/declarable/helpers/cpu/randomShuffle.cpp +++ b/libnd4j/include/ops/declarable/helpers/cpu/randomShuffle.cpp @@ -46,7 +46,7 @@ void randomShuffle_(NDArray& input, NDArray& output, sd::graph::RandomGenerator& // apply Fisher-Yates shuffle if(isInplace) { - //PRAGMA_OMP_PARALLEL_FOR_IF((firstDim-1) > Environment::getInstance()->tadThreshold()) + //PRAGMA_OMP_PARALLEL_FOR_IF((firstDim-1) > Environment::getInstance().tadThreshold()) for(int i = firstDim-1; i > 0; --i) { int r = rng.relativeInt(i) % i; if(i == r) @@ -84,7 +84,7 @@ void randomShuffle_(NDArray& input, NDArray& output, sd::graph::RandomGenerator& // apply Fisher-Yates shuffle if(isInplace) { - //PRAGMA_OMP_PARALLEL_FOR_IF((firstDim-1) > Environment::getInstance()->elementwiseThreshold()) + //PRAGMA_OMP_PARALLEL_FOR_IF((firstDim-1) > Environment::getInstance().elementwiseThreshold()) for(int i = firstDim - 1; i > 0; --i) { int r = rng.relativeInt(i) % i; @@ -99,7 +99,7 @@ void randomShuffle_(NDArray& input, NDArray& output, sd::graph::RandomGenerator& std::vector indices(firstDim); std::iota(indices.begin(), indices.end(), 0); bool isZeroShuffled = false; - //PRAGMA_OMP_PARALLEL_FOR_IF((firstDim-1) > Environment::getInstance()->tadThreshold()) + //PRAGMA_OMP_PARALLEL_FOR_IF((firstDim-1) > Environment::getInstance().tadThreshold()) for(int i = firstDim - 1; i > 0; --i) { int r = rng.relativeInt(i) % i; subArrsListOut.at(i)->assign(subArrsListIn.at(indices[r])); diff --git a/libnd4j/include/ops/declarable/helpers/cpu/roll.cpp b/libnd4j/include/ops/declarable/helpers/cpu/roll.cpp index 278f3bcf5..2e3d983cd 100644 --- a/libnd4j/include/ops/declarable/helpers/cpu/roll.cpp +++ b/libnd4j/include/ops/declarable/helpers/cpu/roll.cpp @@ -43,7 +43,7 @@ namespace helpers { int remainShift = fullLen % actualShift; // stage 1) swap last actualShift elements with first ones. - //PRAGMA_OMP_PARALLEL_FOR //_IF(actualShift > Environment::getInstance()->elementwiseThreshold()) + //PRAGMA_OMP_PARALLEL_FOR //_IF(actualShift > Environment::getInstance().elementwiseThreshold()) for (int e = 0; e < actualShift; ++e) { int sourceIndex = fullLen - actualShift + e; @@ -56,7 +56,7 @@ namespace helpers { } // stage 2) swap swapped actualShift elements with rest remainShiftCount times. - //PRAGMA_OMP_PARALLEL_FOR //_IF(shiftCount > Environment::getInstance()->tadThreshold()) + //PRAGMA_OMP_PARALLEL_FOR //_IF(shiftCount > Environment::getInstance().tadThreshold()) for (int count = 1; count < shiftCount; ++count) { for (int e = 0; e < actualShift; ++e) { int destinationIndex = fullLen - (count + 1) * actualShift + e; diff --git a/libnd4j/include/ops/declarable/helpers/cpu/scatter.cpp b/libnd4j/include/ops/declarable/helpers/cpu/scatter.cpp index e19eb5dea..0693406bf 100644 --- a/libnd4j/include/ops/declarable/helpers/cpu/scatter.cpp +++ b/libnd4j/include/ops/declarable/helpers/cpu/scatter.cpp @@ -87,7 +87,7 @@ void scatter(sd::LaunchContext *context, pairwise::Ops op, const NDArray& indic } }; - samediff::Threads::parallel_tad(func, 0, indLen, 1, lock ? 1 : sd::Environment::getInstance()->maxThreads()); + samediff::Threads::parallel_tad(func, 0, indLen, 1, lock ? 1 : sd::Environment::getInstance().maxThreads()); } else { // outRank > 1 @@ -107,7 +107,7 @@ void scatter(sd::LaunchContext *context, pairwise::Ops op, const NDArray& indic } }; - samediff::Threads::parallel_tad(func, 0, indLen, 1, lock ? 1 : sd::Environment::getInstance()->maxThreads()); + samediff::Threads::parallel_tad(func, 0, indLen, 1, lock ? 1 : sd::Environment::getInstance().maxThreads()); } } @@ -129,7 +129,7 @@ void scatterND(sd::LaunchContext *context, pairwise::Ops op, const NDArray& ind } }; - samediff::Threads::parallel_tad(func, 0, indLen, 1, lock ? 1 : sd::Environment::getInstance()->maxThreads()); + samediff::Threads::parallel_tad(func, 0, indLen, 1, lock ? 1 : sd::Environment::getInstance().maxThreads()); } else { std::vector dimsToExcludeInd = ShapeUtils::evalDimsToExclude(indRank, {indRank-1}); @@ -154,7 +154,7 @@ void scatterND(sd::LaunchContext *context, pairwise::Ops op, const NDArray& ind } }; - samediff::Threads::parallel_tad(func, 0, indLen / indLastDim, 1, lock ? 1 : sd::Environment::getInstance()->maxThreads()); + samediff::Threads::parallel_tad(func, 0, indLen / indLastDim, 1, lock ? 1 : sd::Environment::getInstance().maxThreads()); } } diff --git a/libnd4j/include/ops/declarable/helpers/cpu/softmax.cpp b/libnd4j/include/ops/declarable/helpers/cpu/softmax.cpp index bfd44629c..7fd03f8e4 100644 --- a/libnd4j/include/ops/declarable/helpers/cpu/softmax.cpp +++ b/libnd4j/include/ops/declarable/helpers/cpu/softmax.cpp @@ -187,7 +187,7 @@ namespace sd { } else if(input.isSameShapeStrict(output)) { - TadPack tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(input.shapeInfo(), dimension); + TadPack tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(input.shapeInfo(), dimension); auto tadShapeInfo = tadPack.primaryShapeInfo(); auto tadOffsets = tadPack.primaryOffsets(); const uint numOfSubArrs = tadPack.numberOfTads(); diff --git a/libnd4j/include/ops/declarable/helpers/cpu/stack.cpp b/libnd4j/include/ops/declarable/helpers/cpu/stack.cpp index 694ced4cb..3db322fc8 100644 --- a/libnd4j/include/ops/declarable/helpers/cpu/stack.cpp +++ b/libnd4j/include/ops/declarable/helpers/cpu/stack.cpp @@ -47,7 +47,7 @@ static void stack_(const std::vector& inArrs, NDArray& output, c } else { - auto zTadPack = ConstantTadHelper::getInstance()->tadForDimensions(output.shapeInfo(), ShapeUtils::evalDimsToExclude(output.rankOf(), {dim})); + auto zTadPack = ConstantTadHelper::getInstance().tadForDimensions(output.shapeInfo(), ShapeUtils::evalDimsToExclude(output.rankOf(), {dim})); auto zTadShapeInfo = zTadPack.primaryShapeInfo(); auto func = PRAGMA_THREADS_FOR { @@ -57,8 +57,8 @@ static void stack_(const std::vector& inArrs, NDArray& output, c void* zBuff = output.bufferWithOffset(zTadPack.primaryOffsets()[i]); NativeOpExecutioner::execTransformAny(inArrs[0]->getContext(), transform::Assign, - inArrs[i]->buffer(), inArrs[i]->shapeInfo(), nullptr/*input specialBuffer*/, nullptr/*input specialShapeInfo*/, - zBuff, zTadShapeInfo, nullptr/*output specialBuffer*/, nullptr/*output specialShapeInfo*/, + inArrs[i]->buffer(), inArrs[i]->shapeInfo(), nullptr/*input specialBuffer*/, nullptr/*input special*/, + zBuff, zTadShapeInfo, nullptr/*output specialBuffer*/, nullptr/*output special*/, nullptr, nullptr, nullptr, false/*allowParallelism*/); } }; @@ -92,7 +92,7 @@ static void unstack_(const NDArray& input, const std::vector& outArrs, } else { - auto xTadPack = ConstantTadHelper::getInstance()->tadForDimensions(input.shapeInfo(), ShapeUtils::evalDimsToExclude(input.rankOf(), {dim})); + auto xTadPack = ConstantTadHelper::getInstance().tadForDimensions(input.shapeInfo(), ShapeUtils::evalDimsToExclude(input.rankOf(), {dim})); auto xTadShapeInfo = xTadPack.primaryShapeInfo(); auto func = PRAGMA_THREADS_FOR { @@ -100,8 +100,8 @@ static void unstack_(const NDArray& input, const std::vector& outArrs, auto xBuff = input.bufferWithOffset(xTadPack.primaryOffsets()[i]); NativeOpExecutioner::execTransformAny(input.getContext(), transform::Assign, - xBuff, xTadShapeInfo, nullptr/*input specialBuffer*/, nullptr/*input specialShapeInfo*/, - outArrs[i]->buffer(), outArrs[i]->shapeInfo(), nullptr/*output specialBuffer*/, nullptr/*output specialShapeInfo*/, + xBuff, xTadShapeInfo, nullptr/*input specialBuffer*/, nullptr/*input special*/, + outArrs[i]->buffer(), outArrs[i]->shapeInfo(), nullptr/*output specialBuffer*/, nullptr/*output special*/, nullptr, nullptr, nullptr, false/*allowParallelism*/); } }; diff --git a/libnd4j/include/ops/declarable/helpers/cuda/activations.cu b/libnd4j/include/ops/declarable/helpers/cuda/activations.cu index c8bc709a0..e675342d9 100644 --- a/libnd4j/include/ops/declarable/helpers/cuda/activations.cu +++ b/libnd4j/include/ops/declarable/helpers/cuda/activations.cu @@ -321,8 +321,8 @@ void softmax(sd::LaunchContext * context, const NDArray& input, NDArray& output, } else { - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input.shapeInfo(), {dimension}); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output.shapeInfo(), {dimension}); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input.shapeInfo(), {dimension}); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output.shapeInfo(), {dimension}); const int threadsPerBlock = MAX_NUM_THREADS / 4; const int blocksPerGrid = packZ.numberOfTads(); diff --git a/libnd4j/include/ops/declarable/helpers/cuda/adjust_hue.cu b/libnd4j/include/ops/declarable/helpers/cuda/adjust_hue.cu index 9ce00f318..fff4bfb11 100644 --- a/libnd4j/include/ops/declarable/helpers/cuda/adjust_hue.cu +++ b/libnd4j/include/ops/declarable/helpers/cuda/adjust_hue.cu @@ -81,8 +81,8 @@ static _CUDA_H void adjustHueCudaLauncher(const int blocksPerGrid, const int thr //////////////////////////////////////////////////////////////////////// void adjustHue(sd::LaunchContext* context, const NDArray *input, const NDArray* deltaScalarArr, NDArray *output, const int dimC) { - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), {dimC}); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), {dimC}); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), {dimC}); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), {dimC}); const Nd4jLong numOfTads = packX.numberOfTads(); @@ -170,11 +170,11 @@ static void _adjust_hue_single(sd::LaunchContext * context, NDArray *array, NDAr // numChannels is always 3 auto tuples = array->lengthOf() / 3; if (isNHWC) { - adjustHueSingleNHWCKernel<<<256, 256, 1024, *context->getCudaStream()>>>(array->specialBuffer(), array->specialShapeInfo(), output->specialBuffer(), output->specialShapeInfo(), tuples, delta); + adjustHueSingleNHWCKernel<<<256, 256, 1024, *context->getCudaStream()>>>(array->specialBuffer(), array->specialShapeInfo(), output->specialBuffer(), output->special(), tuples, delta); } else { // TODO: check this one - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(array->shapeInfo(), {1, 2}); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), {1, 2}); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(array->shapeInfo(), {1, 2}); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), {1, 2}); auto tadLength = shape::length(packX.primaryShapeInfo()); @@ -195,12 +195,12 @@ static void _adjust_hue_batch(sd::LaunchContext * context, NDArray *array, NDArr BUILD_SINGLE_SELECTOR(xType, _adjust_hue_single, (context, array, output, delta, isNHWC);, FLOAT_TYPES); } else { // TODO: check this one - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(array->shapeInfo(), {0, 2, 3}); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), {0, 2, 3}); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(array->shapeInfo(), {0, 2, 3}); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), {0, 2, 3}); - auto tadLength = shape::length(packX.primaryShapeInfo()); + auto tadLength = shape::length(packX.primary()); - adjustHueSingleNCHWKernel<<<256, 256, 1024, *context->getCudaStream()>>>(array->specialBuffer(), packX.platformShapeInfo(), packX.platformOffsets(), output->specialBuffer(), packZ.platformShapeInfo(), packZ.platformOffsets(), tadLength, tuples, delta); + adjustHueSingleNCHWKernel<<<256, 256, 1024, *context->getCudaStream()>>>(array->specialBuffer(), packX.platformShapeInfo(), packX.platformOffsets(), output->specialBuffer(), packZ.platform(), packZ.platform(), tadLength, tuples, delta); } } diff --git a/libnd4j/include/ops/declarable/helpers/cuda/adjust_saturation.cu b/libnd4j/include/ops/declarable/helpers/cuda/adjust_saturation.cu index fd413f8cd..36837db29 100644 --- a/libnd4j/include/ops/declarable/helpers/cuda/adjust_saturation.cu +++ b/libnd4j/include/ops/declarable/helpers/cuda/adjust_saturation.cu @@ -83,8 +83,8 @@ static _CUDA_H void adjustSaturationCudaLauncher(const int blocksPerGrid, const //////////////////////////////////////////////////////////////////////// void adjustSaturation(sd::LaunchContext* context, const NDArray *input, const NDArray* factorScalarArr, NDArray *output, const int dimC) { - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), {dimC}); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), {dimC}); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), {dimC}); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), {dimC}); const Nd4jLong numOfTads = packX.numberOfTads(); @@ -162,10 +162,10 @@ static void _adjust_saturation_single(sd::LaunchContext * context, NDArray *arra auto tuples = array->lengthOf() / 3; if (isNHWC) { - adjustSaturationSingleNHWCKernel<<<256, 256, 1024, *context->getCudaStream()>>>(array->specialBuffer(), array->specialShapeInfo(), output->specialBuffer(), output->specialShapeInfo(), tuples, delta); + adjustSaturationSingleNHWCKernel<<<256, 256, 1024, *context->getCudaStream()>>>(array->specialBuffer(), array->specialShapeInfo(), output->specialBuffer(), output->special(), tuples, delta); } else { - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(array->shapeInfo(), {1, 2}); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), {1, 2}); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(array->shapeInfo(), {1, 2}); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), {1, 2}); auto tadLength = shape::length(packX.primaryShapeInfo()); @@ -185,12 +185,12 @@ static void _adjust_saturation_batch(sd::LaunchContext * context, NDArray *array BUILD_SINGLE_SELECTOR(xType, _adjust_saturation_single, (context, array, output, delta, isNHWC);, FLOAT_TYPES); } else { // TODO: check this one - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(array->shapeInfo(), {0, 2, 3}); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), {0, 2, 3}); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(array->shapeInfo(), {0, 2, 3}); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), {0, 2, 3}); - auto tadLength = shape::length(packX.primaryShapeInfo()); + auto tadLength = shape::length(packX.primary()); - adjustSaturationSingleNCHWKernel<<<256, 256, 1024, *context->getCudaStream()>>>(array->specialBuffer(), packX.platformShapeInfo(), packX.platformOffsets(), output->specialBuffer(), packZ.platformShapeInfo(), packZ.platformOffsets(), tadLength, tuples, delta); + adjustSaturationSingleNCHWKernel<<<256, 256, 1024, *context->getCudaStream()>>>(array->specialBuffer(), packX.platformShapeInfo(), packX.platformOffsets(), output->specialBuffer(), packZ.platform(), packZ.platform(), tadLength, tuples, delta); } } diff --git a/libnd4j/include/ops/declarable/helpers/cuda/batchnorm.cu b/libnd4j/include/ops/declarable/helpers/cuda/batchnorm.cu index 791953ab7..f7f8bf966 100644 --- a/libnd4j/include/ops/declarable/helpers/cuda/batchnorm.cu +++ b/libnd4j/include/ops/declarable/helpers/cuda/batchnorm.cu @@ -201,8 +201,8 @@ void batchnorm(const NDArray* input, const NDArray* mean, const NDArray* varianc // std::vector dimsToExclude = ShapeUtils::evalDimsToExclude(input->rankOf(), axes); - // auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), dimsToExclude); - // auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), dimsToExclude); + // auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), dimsToExclude); + // auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), dimsToExclude); // const int threadsPerBlock = MAX_NUM_THREADS / 2; // const int blocksPerGrid = (mean->lengthOf() + threadsPerBlock - 1) / threadsPerBlock; @@ -210,7 +210,7 @@ void batchnorm(const NDArray* input, const NDArray* mean, const NDArray* varianc // PointersManager manager(input->getContext(), "batchnorm"); // NDArray::prepareSpecialUse({output}, {input, mean, variance, gamma, beta}); - // BUILD_SINGLE_SELECTOR(input->dataType(), batchnormCudaLauncher, (blocksPerGrid, threadsPerBlock, input->getContext()->getCudaStream(), input->specialBuffer(), input->specialShapeInfo(), mean->specialBuffer(), mean->specialShapeInfo(), variance->specialBuffer(), variance->specialShapeInfo(), gamma ? gamma->specialBuffer() : nullptr, gamma ? gamma->specialShapeInfo() : nullptr, beta ? beta->specialBuffer() : nullptr, beta ? beta->specialShapeInfo() : nullptr, output->specialBuffer(), output->specialShapeInfo(), packX.platformShapeInfo(), packX.platformOffsets(), packZ.platformShapeInfo(), packZ.platformOffsets(), epsilon), FLOAT_TYPES); + // BUILD_SINGLE_SELECTOR(input->dataType(), batchnormCudaLauncher, (blocksPerGrid, threadsPerBlock, input->getContext()->getCudaStream(), input->specialBuffer(), input->specialShapeInfo(), mean->specialBuffer(), mean->specialShapeInfo(), variance->specialBuffer(), variance->specialShapeInfo(), gamma ? gamma->specialBuffer() : nullptr, gamma ? gamma->specialShapeInfo() : nullptr, beta ? beta->specialBuffer() : nullptr, beta ? beta->specialShapeInfo() : nullptr, output->specialBuffer(), output->special(), packX.platformShapeInfo(), packX.platformOffsets(), packZ.platform(), packZ.platform(), epsilon), FLOAT_TYPES); // NDArray::registerSpecialUse({output}, {input, mean, variance, gamma, beta}); // manager.synchronize(); diff --git a/libnd4j/include/ops/declarable/helpers/cuda/confusion.cu b/libnd4j/include/ops/declarable/helpers/cuda/confusion.cu index dfa86124a..fd676ba83 100644 --- a/libnd4j/include/ops/declarable/helpers/cuda/confusion.cu +++ b/libnd4j/include/ops/declarable/helpers/cuda/confusion.cu @@ -68,7 +68,7 @@ namespace helpers { void _confusionFunctor(sd::LaunchContext * context, NDArray* labels, NDArray* predictions, NDArray* weights, NDArray* output) { auto stream = context->getCudaStream(); - auto pack = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), 1); + auto pack = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), 1); PointersManager manager(context, "helpers::confusion"); diff --git a/libnd4j/include/ops/declarable/helpers/cuda/dynamic.cu b/libnd4j/include/ops/declarable/helpers/cuda/dynamic.cu index 6f29995d3..bce7316ef 100644 --- a/libnd4j/include/ops/declarable/helpers/cuda/dynamic.cu +++ b/libnd4j/include/ops/declarable/helpers/cuda/dynamic.cu @@ -124,7 +124,7 @@ namespace sd { for (int i = sourceDimsLen; i > 0; i--) sourceDims[sourceDimsLen - i] = input->rankOf() - i; //compute tad array for given dimensions - auto packX = ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), sourceDims); + auto packX = ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), sourceDims); std::vector outBuffers(outSize); std::vector tadShapes(outSize); @@ -140,7 +140,7 @@ namespace sd { for (int k = 1; k < r; k++) outDims[k - 1] = k; - auto packZ = ConstantTadHelper::getInstance()->tadForDimensions(outputList.at(i)->shapeInfo(), outDims); + auto packZ = ConstantTadHelper::getInstance().tadForDimensions(outputList.at(i)->shapeInfo(), outDims); outBuffers[i] = outputList.at(i)->specialBuffer(); tadShapes[i] = packZ.platformShapeInfo(); @@ -262,7 +262,7 @@ namespace sd { for (int i = restDims.size(); i > 0; i--) restDims[restDims.size() - i] = output->rankOf() - i; - auto packZ = ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), restDims); + auto packZ = ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), restDims); std::vector inputBuffers(inputSize); std::vector inputTadShapes(inputSize); @@ -276,7 +276,7 @@ namespace sd { for (int i = sourceDims.size(); i > 0; i--) sourceDims[sourceDims.size() - i] = inputs[e]->rankOf() - i; - auto packX = ConstantTadHelper::getInstance()->tadForDimensions(inputs[e]->shapeInfo(), sourceDims); + auto packX = ConstantTadHelper::getInstance().tadForDimensions(inputs[e]->shapeInfo(), sourceDims); indicesBuffers[e] = indices[e]->specialBuffer(); indicesShapes[e] = indices[e]->specialShapeInfo(); diff --git a/libnd4j/include/ops/declarable/helpers/cuda/extract_patches.cu b/libnd4j/include/ops/declarable/helpers/cuda/extract_patches.cu index c5e8848cb..e1c506879 100644 --- a/libnd4j/include/ops/declarable/helpers/cuda/extract_patches.cu +++ b/libnd4j/include/ops/declarable/helpers/cuda/extract_patches.cu @@ -114,8 +114,8 @@ namespace helpers { if (sizeCol * rateCol < 3) colCast = 0; - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(images->shapeInfo(), restDims.data(), restDims.size()); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), restDims.data(), restDims.size()); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(images->shapeInfo(), restDims.data(), restDims.size()); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), restDims.data(), restDims.size()); int batchCount = packX.numberOfTads(); PointersManager manager(context, "helpers::extractPatches"); diff --git a/libnd4j/include/ops/declarable/helpers/cuda/histogramFixedWidth.cu b/libnd4j/include/ops/declarable/helpers/cuda/histogramFixedWidth.cu index adb5a3ec4..c6041b33b 100644 --- a/libnd4j/include/ops/declarable/helpers/cuda/histogramFixedWidth.cu +++ b/libnd4j/include/ops/declarable/helpers/cuda/histogramFixedWidth.cu @@ -164,9 +164,9 @@ void histogramFixedWidth(sd::LaunchContext* context, const NDArray& input, const // cudaError_t err = cudaMalloc(&outputBuffer, output.lengthOf() * sizeof(Nd4jLong)); // if (err != 0) // throw cuda_exception::build("helpers::histogramFixedWidth: Cannot allocate memory for output", err); -// copyBuffers<<<256, 512, 8192, *stream>>>(outputBuffer, output.specialBuffer(), output.specialShapeInfo(), output.lengthOf()); -// histogramFixedWidthKernel<<<256, 512, 8192, *stream>>>(outputBuffer, output.lengthOf(), input.specialBuffer(), input.specialShapeInfo(), input.lengthOf(), leftEdge, binWidth, secondEdge, lastButOneEdge); -// returnBuffers<<<256, 512, 8192, *stream>>>(output.specialBuffer(), outputBuffer, output.specialShapeInfo(), output.lengthOf()); +// copyBuffers<<<256, 512, 8192, *stream>>>(outputBuffer, output.specialBuffer(), output.special(), output.lengthOf()); +// histogramFixedWidthKernel<<<256, 512, 8192, *stream>>>(outputBuffer, output.lengthOf(), input.specialBuffer(), input.special(), input.lengthOf(), leftEdge, binWidth, secondEdge, lastButOneEdge); +// returnBuffers<<<256, 512, 8192, *stream>>>(output.specialBuffer(), outputBuffer, output.special(), output.lengthOf()); // //cudaSyncStream(*stream); // err = cudaFree(outputBuffer); // if (err != 0) diff --git a/libnd4j/include/ops/declarable/helpers/cuda/imagesHelpers.cu b/libnd4j/include/ops/declarable/helpers/cuda/imagesHelpers.cu index c26b79ee6..749f60c11 100644 --- a/libnd4j/include/ops/declarable/helpers/cuda/imagesHelpers.cu +++ b/libnd4j/include/ops/declarable/helpers/cuda/imagesHelpers.cu @@ -69,8 +69,8 @@ linkage void rgbToYuvCudaLauncher(const int blocksPerGrid, const int threadsPerB /////////////////////////////////////////////////////////////////// void transformRgbYuv(sd::LaunchContext* context, const NDArray& input, NDArray& output, const int dimC) { - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input.shapeInfo(), { dimC }); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output.shapeInfo(), { dimC }); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input.shapeInfo(), { dimC }); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output.shapeInfo(), { dimC }); const Nd4jLong numOfTads = packX.numberOfTads(); @@ -124,8 +124,8 @@ linkage void yuvToRgbCudaLauncher(const int blocksPerGrid, const int threadsPerB /////////////////////////////////////////////////////////////////// void transformYuvRgb(sd::LaunchContext* context, const NDArray& input, NDArray& output, const int dimC) { - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input.shapeInfo(), { dimC }); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output.shapeInfo(), { dimC }); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input.shapeInfo(), { dimC }); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output.shapeInfo(), { dimC }); const Nd4jLong numOfTads = packX.numberOfTads(); @@ -287,8 +287,8 @@ static _CUDA_H void rgbToHsvCudaLauncher(const int blocksPerGrid, const int thre /////////////////////////////////////////////////////////////////// void transformHsvRgb(sd::LaunchContext* context, const NDArray* input, NDArray* output, const int dimC) { - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), {dimC}); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), {dimC}); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), {dimC}); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), {dimC}); const Nd4jLong numOfTads = packX.numberOfTads(); @@ -306,8 +306,8 @@ void transformHsvRgb(sd::LaunchContext* context, const NDArray* input, NDArray* /////////////////////////////////////////////////////////////////// void transformRgbHsv(sd::LaunchContext* context, const NDArray* input, NDArray* output, const int dimC) { - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), {dimC}); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), {dimC}); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), {dimC}); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), {dimC}); const Nd4jLong numOfTads = packX.numberOfTads(); @@ -389,8 +389,8 @@ __global__ void tripleTransformerCuda(const void *vx, const Nd4jLong *xShapeInfo template static void rgbYiq(sd::LaunchContext* context, const NDArray* input, NDArray* output, const int dimC) { - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), dimC); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), dimC); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), dimC); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), dimC); NDArray::prepareSpecialUse({output}, {input}); return tripleTransformerCuda<<<256, 256, 8192, *context->getCudaStream()>>>(input->specialBuffer(), input->specialShapeInfo(), packX.platformShapeInfo(), packX.platformOffsets(), output->specialBuffer(), output->specialShapeInfo(), packZ.platformShapeInfo(), packZ.platformOffsets(), dimC, 1, packZ.numberOfTads()); @@ -399,8 +399,8 @@ static void rgbYiq(sd::LaunchContext* context, const NDArray* input, NDArray* ou template FORCEINLINE static void yiqRgb(sd::LaunchContext* context, const NDArray* input, NDArray* output, const int dimC) { - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), dimC); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), dimC); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), dimC); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), dimC); NDArray::prepareSpecialUse({output}, {input}); return tripleTransformerCuda<<<256, 256, 8192, *context->getCudaStream()>>>(input->specialBuffer(), input->specialShapeInfo(), packX.platformShapeInfo(), packX.platformOffsets(), output->specialBuffer(), output->specialShapeInfo(), packZ.platformShapeInfo(), packZ.platformOffsets(), dimC, 2, packZ.numberOfTads()); diff --git a/libnd4j/include/ops/declarable/helpers/cuda/indexReductions.cu b/libnd4j/include/ops/declarable/helpers/cuda/indexReductions.cu index 9876417df..820a6c258 100644 --- a/libnd4j/include/ops/declarable/helpers/cuda/indexReductions.cu +++ b/libnd4j/include/ops/declarable/helpers/cuda/indexReductions.cu @@ -32,7 +32,7 @@ namespace sd { NativeOpExecutioner::execIndexReduceScalar(LaunchContext::defaultContext(), indexreduce::Ops::IndexMax, input.buffer(), input.shapeInfo(), input.specialBuffer(), input.specialShapeInfo(), nullptr, output.buffer(), output.shapeInfo(), output.specialBuffer(), output.specialShapeInfo()); } else { - auto tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(input.shapeInfo(), dimensions); + auto tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(input.shapeInfo(), dimensions); NativeOpExecutioner::execIndexReduce(LaunchContext::defaultContext(), indexreduce::Ops::IndexMax, input.buffer(), input.shapeInfo(), input.specialBuffer(), input.specialShapeInfo(), @@ -51,7 +51,7 @@ namespace sd { NativeOpExecutioner::execIndexReduceScalar(LaunchContext::defaultContext(), indexreduce::Ops::IndexMin, input.buffer(), input.shapeInfo(), input.specialBuffer(), input.specialShapeInfo(), nullptr, output.buffer(), output.shapeInfo(), output.specialBuffer(), output.specialShapeInfo()); } else { - auto tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(input.shapeInfo(), dimensions); + auto tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(input.shapeInfo(), dimensions); NativeOpExecutioner::execIndexReduce(LaunchContext::defaultContext(), indexreduce::Ops::IndexMin, input.buffer(), input.shapeInfo(), input.specialBuffer(), input.specialShapeInfo(), @@ -70,7 +70,7 @@ namespace sd { NativeOpExecutioner::execIndexReduceScalar(LaunchContext::defaultContext(), indexreduce::Ops::IndexAbsoluteMax, input.buffer(), input.shapeInfo(), input.specialBuffer(), input.specialShapeInfo(), nullptr, output.buffer(), output.shapeInfo(), output.specialBuffer(), output.specialShapeInfo()); } else { - auto tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(input.shapeInfo(), dimensions); + auto tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(input.shapeInfo(), dimensions); NativeOpExecutioner::execIndexReduce(LaunchContext::defaultContext(), indexreduce::Ops::IndexAbsoluteMax, input.buffer(), input.shapeInfo(), input.specialBuffer(), input.specialShapeInfo(), @@ -89,7 +89,7 @@ namespace sd { NativeOpExecutioner::execIndexReduceScalar(LaunchContext::defaultContext(), indexreduce::Ops::IndexAbsoluteMin, input.buffer(), input.shapeInfo(), input.specialBuffer(), input.specialShapeInfo(), nullptr, output.buffer(), output.shapeInfo(), output.specialBuffer(), output.specialShapeInfo()); } else { - auto tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(input.shapeInfo(), dimensions); + auto tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(input.shapeInfo(), dimensions); NativeOpExecutioner::execIndexReduce(LaunchContext::defaultContext(), indexreduce::Ops::IndexAbsoluteMin, input.buffer(), input.shapeInfo(), input.specialBuffer(), input.specialShapeInfo(), diff --git a/libnd4j/include/ops/declarable/helpers/cuda/ismax.cu b/libnd4j/include/ops/declarable/helpers/cuda/ismax.cu index 723b0f215..f6e233aab 100644 --- a/libnd4j/include/ops/declarable/helpers/cuda/ismax.cu +++ b/libnd4j/include/ops/declarable/helpers/cuda/ismax.cu @@ -61,7 +61,7 @@ static void ismax_(sd::LaunchContext * context, const NDArray* input, NDArray* o int dimensionLength = dimensions.size(); std::vector copy(dimensions); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), copy.data(), copy.size()); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), copy.data(), copy.size()); // we launch legacy IndexMax op, to get indices of max values along dimension auto indexMaxArr = input->applyIndexReduce(indexreduce::IndexMax, dimensions); diff --git a/libnd4j/include/ops/declarable/helpers/cuda/lrn.cu b/libnd4j/include/ops/declarable/helpers/cuda/lrn.cu index ebc0732e2..123c06ac5 100644 --- a/libnd4j/include/ops/declarable/helpers/cuda/lrn.cu +++ b/libnd4j/include/ops/declarable/helpers/cuda/lrn.cu @@ -116,8 +116,8 @@ namespace helpers { template static void lrnBP_(sd::graph::Context& block, const NDArray& input, const NDArray& gradO, NDArray& gradI, const int depth, const float bias, const float alpha, const float beta) { auto rank = input.rankOf(); - auto packX = ConstantTadHelper::getInstance()->tadForDimensions(input.shapeInfo(), {rank - 1}); - auto packZ = ConstantTadHelper::getInstance()->tadForDimensions(gradI.shapeInfo(), {rank - 1}); + auto packX = ConstantTadHelper::getInstance().tadForDimensions(input.shapeInfo(), {rank - 1}); + auto packZ = ConstantTadHelper::getInstance().tadForDimensions(gradI.shapeInfo(), {rank - 1}); const auto tadLength = shape::length(packX.primaryShapeInfo()); const int numBlocks = sd::math::nd4j_min(1024, packX.numberOfTads()); @@ -144,8 +144,8 @@ namespace helpers { template static void lrnFunctor_(sd::graph::Context& block, NDArray* input, NDArray* output, int depth, double bias, double alpha, double beta) { auto rank = input->rankOf(); - auto packX = ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), {rank - 1}); - auto packZ = ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), {rank - 1}); + auto packX = ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), {rank - 1}); + auto packZ = ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), {rank - 1}); const auto tadLength = shape::length(packX.primaryShapeInfo()); const int numBlocks = sd::math::nd4j_min(1024, packX.numberOfTads()); diff --git a/libnd4j/include/ops/declarable/helpers/cuda/lstsq.cu b/libnd4j/include/ops/declarable/helpers/cuda/lstsq.cu index 8d8548be5..b28efff80 100644 --- a/libnd4j/include/ops/declarable/helpers/cuda/lstsq.cu +++ b/libnd4j/include/ops/declarable/helpers/cuda/lstsq.cu @@ -48,7 +48,7 @@ namespace helpers { template static void fillRegularizer(sd::LaunchContext* context, NDArray& ioMatrix, double const value) { - auto lastDimsTads = ConstantTadHelper::getInstance()->tadForDimensions(ioMatrix.shapeInfo(), {-2, -1}); + auto lastDimsTads = ConstantTadHelper::getInstance().tadForDimensions(ioMatrix.shapeInfo(), {-2, -1}); auto stream = context->getCudaStream(); auto rows = ioMatrix.sizeAt(-2); //auto cols = ioMatrix.sizeAt(-1); diff --git a/libnd4j/include/ops/declarable/helpers/cuda/lup.cu b/libnd4j/include/ops/declarable/helpers/cuda/lup.cu index 682b2eee9..c59ef9489 100644 --- a/libnd4j/include/ops/declarable/helpers/cuda/lup.cu +++ b/libnd4j/include/ops/declarable/helpers/cuda/lup.cu @@ -604,8 +604,8 @@ namespace helpers { // output->tickWriteDevice(); permutationVectors->applyTrueBroadcast(sd::BroadcastOpsTuple::Assign(), iota, *permutationVectors, true, nullptr); // permutationVectors->tickWriteDevice(); - auto tads = ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), {-2, -1}); - auto permutaionTads = ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), {-1}); + auto tads = ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), {-2, -1}); + auto permutaionTads = ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), {-1}); auto batchNum = tads.numberOfTads(); luBatchedKernel<<>>(reinterpret_cast(output->platformBuffer()), output->specialShapeInfo(), reinterpret_cast(permutationVectors->platformBuffer()), @@ -624,8 +624,8 @@ namespace helpers { Nd4jLong n = input->sizeAt(-1); Nd4jLong n2 = n * n; std::vector dims(); - auto packX = ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), {input->rankOf() - 2, input->rankOf() - 1}); - //auto packZ = ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), {output->rankOf() - 1}); + auto packX = ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), {input->rankOf() - 2, input->rankOf() - 1}); + //auto packZ = ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), {output->rankOf() - 1}); // DataType dtype = input->dataType(); // if (dtype != DataType::DOUBLE) // dtype = DataType::FLOAT32; @@ -640,7 +640,7 @@ namespace helpers { // if (matrix.dataType() == input->dataType()) fillMatrix<<>>(matrix.specialBuffer(), matrix.specialShapeInfo(), input->specialBuffer(), input->specialShapeInfo(), pos, n); // else -// fillMatrix<<>>(matrix.specialBuffer(), matrix.specialShapeInfo(), input->specialBuffer(), input->specialShapeInfo(), pos, n); +// fillMatrix<<>>(matrix.specialBuffer(), matrix.specialShapeInfo(), input->specialBuffer(), input->special(), pos, n); lup_(context, &matrix, nullptr, nullptr); // else // lup_(context, &matrix, nullptr, nullptr); @@ -668,8 +668,8 @@ namespace helpers { Nd4jLong n = input->sizeAt(-1); Nd4jLong n2 = n * n; std::vector dims(); - auto packX = ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), {input->rankOf() - 2, input->rankOf() - 1}); - //auto packZ = ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), {output->rankOf() - 1}); + auto packX = ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), {input->rankOf() - 2, input->rankOf() - 1}); + //auto packZ = ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), {output->rankOf() - 1}); DataType dtype = input->dataType(); if (dtype != DataType::DOUBLE) dtype = DataType::FLOAT32; @@ -685,7 +685,7 @@ namespace helpers { // if (matrix.dataType() == input->dataType()) fillMatrix<<>>(matrix.specialBuffer(), matrix.specialShapeInfo(), input->specialBuffer(), input->specialShapeInfo(), pos, n); // else -// fillMatrix<<>>(matrix.specialBuffer(), matrix.specialShapeInfo(), input->specialBuffer(), input->specialShapeInfo(), pos, n); +// fillMatrix<<>>(matrix.specialBuffer(), matrix.specialShapeInfo(), input->specialBuffer(), input->special(), pos, n); // if (matrix.dataType() == input->dataType()) lup_(context, &matrix, nullptr, nullptr); @@ -759,10 +759,10 @@ namespace helpers { NDArray lower = NDArrayFactory::create('c', {n, n}, dtype, context); NDArray compound = NDArrayFactory::create('c', {n, n}, dtype, context); NDArray permutation = NDArrayFactory::create('c', {n, n}, dtype, context); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), {input->rankOf() - 2, input->rankOf() - 1}); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), {output->rankOf() - 2, output->rankOf() - 1}); auto stream = context->getCudaStream(); @@ -849,7 +849,7 @@ namespace helpers { throw cuda_exception::build("helpers::cholesky_: Cannot create solver handle", status); } F **dArrayBatch = nullptr; - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(tempOutput.shapeInfo(), + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(tempOutput.shapeInfo(), {tempOutput.rankOf() - 2, tempOutput.rankOf() - 1}); const Nd4jLong batchSize = packX.numberOfTads(); @@ -980,7 +980,7 @@ namespace helpers { auto outputBuf = output->dataBuffer()->specialAsT(); //reinterpret_cast(output->specialBuffer()); // + e * n2; // + e * n2; auto inputBuf = tempOutput.dataBuffer()->specialAsT(); //reinterpret_cast(tempOutput.specialBuffer()); output->nullify(); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(tempOutput.shapeInfo(), + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(tempOutput.shapeInfo(), {tempOutput.rankOf() - 2, tempOutput.rankOf() - 1}); logDetKernel<<<128, 512, 256, *stream>>>(inputBuf, tempOutput.specialShapeInfo(), diff --git a/libnd4j/include/ops/declarable/helpers/cuda/matrix_band.cu b/libnd4j/include/ops/declarable/helpers/cuda/matrix_band.cu index 78249bc38..446d57b27 100644 --- a/libnd4j/include/ops/declarable/helpers/cuda/matrix_band.cu +++ b/libnd4j/include/ops/declarable/helpers/cuda/matrix_band.cu @@ -94,8 +94,8 @@ namespace helpers { std::vector lastDims({input->rankOf() - 2, input->rankOf() - 1}); std::vector dimsToExclude = ShapeUtils::evalDimsToExclude(input->rankOf(), lastDims); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), lastDims); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), lastDims); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), lastDims); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), lastDims); const Nd4jLong numTads = packX.numberOfTads(); diff --git a/libnd4j/include/ops/declarable/helpers/cuda/matrix_diag_part.cu b/libnd4j/include/ops/declarable/helpers/cuda/matrix_diag_part.cu index 30d5f0ef9..b8edcbc26 100644 --- a/libnd4j/include/ops/declarable/helpers/cuda/matrix_diag_part.cu +++ b/libnd4j/include/ops/declarable/helpers/cuda/matrix_diag_part.cu @@ -71,8 +71,8 @@ namespace helpers { //tadOnlyInputShapeInfo, tadInputOffsets, tadOnlyOutputShapeInfo, tadOutputOffsets; std::vector outputDims({output->rankOf() - 1}); std::vector inputDims({input->rankOf() - 2, input->rankOf() - 1}); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), inputDims); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), outputDims); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), inputDims); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), outputDims); if (!output->isActualOnDeviceSide()) diff --git a/libnd4j/include/ops/declarable/helpers/cuda/meshgrid.cu b/libnd4j/include/ops/declarable/helpers/cuda/meshgrid.cu index 3f2ed13b5..918dca510 100644 --- a/libnd4j/include/ops/declarable/helpers/cuda/meshgrid.cu +++ b/libnd4j/include/ops/declarable/helpers/cuda/meshgrid.cu @@ -104,7 +104,7 @@ namespace helpers { hOutBuffers[i] = outArrs[i]->specialBuffer(); - auto pack = ConstantTadHelper::getInstance()->tadForDimensions(outArrs[i]->shapeInfo(), {inIndices[i]}); + auto pack = ConstantTadHelper::getInstance().tadForDimensions(outArrs[i]->shapeInfo(), {inIndices[i]}); hOutTadShapes[i] = pack.specialShapeInfo(); hOutTadOffsets[i] = pack.specialOffsets(); hNumTads[i] = pack.numberOfTads(); diff --git a/libnd4j/include/ops/declarable/helpers/cuda/nth_element.cu b/libnd4j/include/ops/declarable/helpers/cuda/nth_element.cu index c3b4abc51..c2f34f9fe 100644 --- a/libnd4j/include/ops/declarable/helpers/cuda/nth_element.cu +++ b/libnd4j/include/ops/declarable/helpers/cuda/nth_element.cu @@ -66,7 +66,7 @@ namespace helpers { else { // rank greater than 1 std::vector lastDims({input->rankOf() - 1});// = ShapeUtils::evalDimsToExclude(input->rankOf(), {input->rankOf() - 1}); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(sortedVals.shapeInfo(), lastDims); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(sortedVals.shapeInfo(), lastDims); auto pTadShape = packX.specialShapeInfo(); auto pTadShapeH = packX.primaryShapeInfo(); diff --git a/libnd4j/include/ops/declarable/helpers/cuda/percentile.cu b/libnd4j/include/ops/declarable/helpers/cuda/percentile.cu index 7f2bcdcfd..1bc50fad7 100644 --- a/libnd4j/include/ops/declarable/helpers/cuda/percentile.cu +++ b/libnd4j/include/ops/declarable/helpers/cuda/percentile.cu @@ -97,7 +97,7 @@ namespace helpers { shape::checkDimensions(inputRank, axis); auto tempArray = input.dup(); - auto packX = ConstantTadHelper::getInstance()->tadForDimensions(tempArray.shapeInfo(), axis); + auto packX = ConstantTadHelper::getInstance().tadForDimensions(tempArray.shapeInfo(), axis); auto tadLength = shape::length(packX.primaryShapeInfo()); diff --git a/libnd4j/include/ops/declarable/helpers/cuda/prefix.cu b/libnd4j/include/ops/declarable/helpers/cuda/prefix.cu index d2832ec80..959b45865 100644 --- a/libnd4j/include/ops/declarable/helpers/cuda/prefix.cu +++ b/libnd4j/include/ops/declarable/helpers/cuda/prefix.cu @@ -148,8 +148,8 @@ static void prefixPerBlockCudaLauncher(const int blocksPerGrid, const int thread /////////////////////////////////////////////////////////////////// void prefix(sd::LaunchContext * context, scalar::Ops op, const NDArray* x, NDArray* z, const std::vector& dims, bool exclusive, bool reverse) { - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(x->shapeInfo(), dims); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(z->shapeInfo(), dims); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(x->shapeInfo(), dims); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(z->shapeInfo(), dims); const Nd4jLong numTads = packX.numberOfTads(); const Nd4jLong tadLen = x->lengthOf() / numTads; diff --git a/libnd4j/include/ops/declarable/helpers/cuda/qr.cu b/libnd4j/include/ops/declarable/helpers/cuda/qr.cu index 828867b4e..e499f21d0 100644 --- a/libnd4j/include/ops/declarable/helpers/cuda/qr.cu +++ b/libnd4j/include/ops/declarable/helpers/cuda/qr.cu @@ -60,9 +60,9 @@ namespace helpers { m({col, m.rows(), col, m.columns()}).assign(in({col, m.rows(), col, m.columns()})); // auto stream = context->getCudaStream(); -// matrixMinorKernel<<<128, 128, 256, *stream>>>(m.dataBuffer()->specialAsT(), m.specialShapeInfo(), -// matrixMinorKernel<<<128, 128, 256, *stream>>>(m.dataBuffer()->specialAsT(), m.specialShapeInfo(), -// reinterpret_cast(in.specialBuffer()), in.specialShapeInfo(), col, in.rows(), in.columns()); +// matrixMinorKernel<<<128, 128, 256, *stream>>>(m.dataBuffer()->specialAsT(), m.special(), +// matrixMinorKernel<<<128, 128, 256, *stream>>>(m.dataBuffer()->specialAsT(), m.special(), +// reinterpret_cast(in.specialBuffer()), in.special(), col, in.rows(), in.columns()); // m.tickWriteDevice(); return m; diff --git a/libnd4j/include/ops/declarable/helpers/cuda/reverse.cu b/libnd4j/include/ops/declarable/helpers/cuda/reverse.cu index 2ed45356e..6ae1b22a8 100644 --- a/libnd4j/include/ops/declarable/helpers/cuda/reverse.cu +++ b/libnd4j/include/ops/declarable/helpers/cuda/reverse.cu @@ -212,8 +212,8 @@ namespace helpers { ////////////////////////////////////////////////////////////////////////// void reverse(sd::LaunchContext * context, const NDArray* input, NDArray* output, const std::vector* intArgs) { - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), *intArgs); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), *intArgs); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), *intArgs); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), *intArgs); NDArray::prepareSpecialUse({output}, {input}); diff --git a/libnd4j/include/ops/declarable/helpers/cuda/roll.cu b/libnd4j/include/ops/declarable/helpers/cuda/roll.cu index 773f7279d..a5149c978 100644 --- a/libnd4j/include/ops/declarable/helpers/cuda/roll.cu +++ b/libnd4j/include/ops/declarable/helpers/cuda/roll.cu @@ -253,7 +253,7 @@ namespace helpers { for (int i = 0; i < dims.size(); ++i) dims[i] = axe + 1 + i; - auto packZ = ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), dims); + auto packZ = ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), dims); int numTads = packZ.numberOfTads(); int sizeAt = input->sizeAt(axe); diff --git a/libnd4j/include/ops/declarable/helpers/cuda/scatter.cu b/libnd4j/include/ops/declarable/helpers/cuda/scatter.cu index 94b0e0080..cbe8895b2 100644 --- a/libnd4j/include/ops/declarable/helpers/cuda/scatter.cu +++ b/libnd4j/include/ops/declarable/helpers/cuda/scatter.cu @@ -736,8 +736,8 @@ __global__ static void scatterLockCuda(const int opCode, std::vector yTadDims(sizeOfUpdDims); std::iota(yTadDims.begin(), yTadDims.end(), 0); - auto packY = sd::ConstantTadHelper::getInstance()->tadForDimensions(updates.shapeInfo(), ShapeUtils::evalDimsToExclude(updates.rankOf(), yTadDims)); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output.shapeInfo(), zTadDims); + auto packY = sd::ConstantTadHelper::getInstance().tadForDimensions(updates.shapeInfo(), ShapeUtils::evalDimsToExclude(updates.rankOf(), yTadDims)); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output.shapeInfo(), zTadDims); const Nd4jLong zTadLen = shape::length(packZ.primaryShapeInfo()); const Nd4jLong yTadLen = shape::length(packY.primaryShapeInfo()); @@ -963,21 +963,21 @@ __global__ static void scatterLockCuda(const int opCode, std::vector dims = {0}; auto inverted = ShapeUtils::evalDimsToExclude(output.rankOf(), dims); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(output.shapeInfo(), inverted); - auto packY = sd::ConstantTadHelper::getInstance()->tadForDimensions(updates.shapeInfo(), inverted); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(output.shapeInfo(), inverted); + auto packY = sd::ConstantTadHelper::getInstance().tadForDimensions(updates.shapeInfo(), inverted); auto psX = packX.specialShapeInfo(); - auto psY = packY.specialShapeInfo(); + auto psY = packY.special(); PointersManager manager(context, "scatter"); auto poX = packX.specialOffsets(); - auto poY = packY.specialOffsets(); + auto poY = packY.special(); NDArray::prepareSpecialUse({&output}, {&updates, &indices}); unsigned int tadLengthX = shape::length(packX.primaryShapeInfo()); - unsigned int tadLengthY = shape::length(packY.primaryShapeInfo()); + unsigned int tadLengthY = shape::length(packY.primary()); if (tadLengthX != tadLengthY) throw std::runtime_error("scatter: Lengths of TADs must be equal"); @@ -1016,9 +1016,9 @@ const int xLastDim = indices.sizeAt(-1); zTadDims[i] = zRank - 1 - j; } - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(indices.shapeInfo(), {xRank - 1}); - auto packY = sd::ConstantTadHelper::getInstance()->tadForDimensions(updates.shapeInfo(), yTadDims); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output.shapeInfo(), zTadDims); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(indices.shapeInfo(), {xRank - 1}); + auto packY = sd::ConstantTadHelper::getInstance().tadForDimensions(updates.shapeInfo(), yTadDims); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output.shapeInfo(), zTadDims); const int threadsPerBlock = MAX_NUM_THREADS / 4; const int blocksPerGrid = packZ.numberOfTads(); @@ -1152,16 +1152,16 @@ const int xLastDim = indices.sizeAt(-1); // PointersManager::printDevContentOnDev(zShapeInfo, 8); // manager.printDevContentOnHost(indices.specialBuffer(), indices.lengthOf()); - // manager.printDevContentOnHost(indices.specialShapeInfo(), shape::shapeInfoLength(indices.rankOf())); + // manager.printDevContentOnHost(indices.special(), shape::shapeInfoLength(indices.rankOf())); // manager.printDevContentOnHost(updates.specialBuffer(), updates.lengthOf()); - // manager.printDevContentOnHost(updates.specialShapeInfo(), shape::shapeInfoLength(updates.rankOf())); - // manager.printDevContentOnHost(output.specialShapeInfo(), shape::shapeInfoLength(output.rankOf())); + // manager.printDevContentOnHost(updates.special(), shape::shapeInfoLength(updates.rankOf())); + // manager.printDevContentOnHost(output.special(), shape::shapeInfoLength(output.rankOf())); // printf("!!!!!!!\n"); - // manager.printDevContentOnHost(packX.specialShapeInfo(), 2*shape::rank(packX.primaryShapeInfo()) + 4); - // manager.printDevContentOnHost(packX.specialOffsets(), packX.numberOfTads()); - // manager.printDevContentOnHost(packY.specialShapeInfo(), 2*shape::rank(packY.primaryShapeInfo()) + 4); - // manager.printDevContentOnHost(packY.specialOffsets(), packY.numberOfTads()); - // manager.printDevContentOnHost(packZ.specialShapeInfo(), 2*shape::rank(packZ.primaryShapeInfo()) + 4); - // manager.printDevContentOnHost(packZ.specialOffsets(), packZ.numberOfTads()); + // manager.printDevContentOnHost(packX.special(), 2*shape::rank(packX.primary()) + 4); + // manager.printDevContentOnHost(packX.special(), packX.numberOfTads()); + // manager.printDevContentOnHost(packY.special(), 2*shape::rank(packY.primary()) + 4); + // manager.printDevContentOnHost(packY.special(), packY.numberOfTads()); + // manager.printDevContentOnHost(packZ.special(), 2*shape::rank(packZ.primary()) + 4); + // manager.printDevContentOnHost(packZ.special(), packZ.numberOfTads()); // printf("dddddddd\n"); - // shape::printShapeInfoLinear(packY.primaryShapeInfo()); \ No newline at end of file + // shape::printShapeInfoLinear(packY.primary()); \ No newline at end of file diff --git a/libnd4j/include/ops/declarable/helpers/cuda/scatter_simple.cu b/libnd4j/include/ops/declarable/helpers/cuda/scatter_simple.cu index a17464cbd..3b422a5c2 100644 --- a/libnd4j/include/ops/declarable/helpers/cuda/scatter_simple.cu +++ b/libnd4j/include/ops/declarable/helpers/cuda/scatter_simple.cu @@ -51,7 +51,7 @@ namespace sd { void scatterSimple_(sd::LaunchContext * context, const int opId, NDArray& input, const NDArray& updates, const NDArray& indices, const std::vector& dimensions) { auto dims = ShapeUtils::evalDimsToExclude(input.rankOf(), dimensions); - auto packX = ConstantTadHelper::getInstance()->tadForDimensions(input.shapeInfo(), dims); + auto packX = ConstantTadHelper::getInstance().tadForDimensions(input.shapeInfo(), dims); auto xLength = shape::length(packX.primaryShapeInfo()); auto iLength = indices.lengthOf(); diff --git a/libnd4j/include/ops/declarable/helpers/cuda/scatter_update.cu b/libnd4j/include/ops/declarable/helpers/cuda/scatter_update.cu index 51f917a79..3a3bfef12 100644 --- a/libnd4j/include/ops/declarable/helpers/cuda/scatter_update.cu +++ b/libnd4j/include/ops/declarable/helpers/cuda/scatter_update.cu @@ -114,8 +114,8 @@ namespace sd { for (int e = 2; e < 2 + numOfDims; e++) tadDimensions[e-2] = (*intArgs)[e]; - auto packX = ConstantTadHelper::getInstance()->tadForDimensions(input.shapeInfo(), tadDimensions); - auto packY = ConstantTadHelper::getInstance()->tadForDimensions(updates.shapeInfo(), tadDimensions); + auto packX = ConstantTadHelper::getInstance().tadForDimensions(input.shapeInfo(), tadDimensions); + auto packY = ConstantTadHelper::getInstance().tadForDimensions(updates.shapeInfo(), tadDimensions); NDArray indices(const_cast(intArgs->data()) + numOfDims + 3, 'c', {numOfInd}, sd::DataType::INT32, context); diff --git a/libnd4j/include/ops/declarable/helpers/cuda/segment_max.cu b/libnd4j/include/ops/declarable/helpers/cuda/segment_max.cu index 927b1bb2f..d623c8734 100644 --- a/libnd4j/include/ops/declarable/helpers/cuda/segment_max.cu +++ b/libnd4j/include/ops/declarable/helpers/cuda/segment_max.cu @@ -185,8 +185,8 @@ namespace sd { } else { std::vector dimensions = ShapeUtils::evalDimsToExclude(input->rankOf(), {0}); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), dimensions); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), dimensions); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), dimensions); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), dimensions); auto inputTads = packX.specialShapeInfo(); auto inputTadOffsets = packX.specialOffsets(); auto outputTads = packZ.specialShapeInfo(); @@ -226,8 +226,8 @@ namespace sd { } else { std::vector dimensions = ShapeUtils::evalDimsToExclude(input->rankOf(), {0}); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), dimensions); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), dimensions); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), dimensions); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), dimensions); auto inputTads = packX.specialShapeInfo(); auto inputTadOffsets = packX.specialOffsets(); auto outputTads = packZ.specialShapeInfo(); @@ -349,10 +349,10 @@ namespace sd { } else { std::vector dimensions = ShapeUtils::evalDimsToExclude(input->rankOf(), {0}); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), dimensions); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), dimensions); - auto packGradIn = sd::ConstantTadHelper::getInstance()->tadForDimensions(tempRes.shapeInfo(), dimensions); - auto packGradOut = sd::ConstantTadHelper::getInstance()->tadForDimensions(gradOut->shapeInfo(), dimensions); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), dimensions); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), dimensions); + auto packGradIn = sd::ConstantTadHelper::getInstance().tadForDimensions(tempRes.shapeInfo(), dimensions); + auto packGradOut = sd::ConstantTadHelper::getInstance().tadForDimensions(gradOut->shapeInfo(), dimensions); Nd4jLong const* inputTads = packX.specialShapeInfo(); Nd4jLong const* inputTadOffsets = packX.specialOffsets(); Nd4jLong const* outputTads = packZ.specialShapeInfo(); @@ -397,10 +397,10 @@ namespace sd { } else { std::vector dimensions = ShapeUtils::evalDimsToExclude(input->rankOf(), {0}); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), dimensions); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), dimensions); - auto packGradIn = sd::ConstantTadHelper::getInstance()->tadForDimensions(tempRes.shapeInfo(), dimensions); - auto packGradOut = sd::ConstantTadHelper::getInstance()->tadForDimensions(gradOut->shapeInfo(), dimensions); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), dimensions); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), dimensions); + auto packGradIn = sd::ConstantTadHelper::getInstance().tadForDimensions(tempRes.shapeInfo(), dimensions); + auto packGradOut = sd::ConstantTadHelper::getInstance().tadForDimensions(gradOut->shapeInfo(), dimensions); Nd4jLong const* inputTads = packX.specialShapeInfo(); Nd4jLong const* inputTadOffsets = packX.specialOffsets(); Nd4jLong const* outputTads = packZ.specialShapeInfo(); diff --git a/libnd4j/include/ops/declarable/helpers/cuda/segment_mean.cu b/libnd4j/include/ops/declarable/helpers/cuda/segment_mean.cu index c75293c1d..5ccecf37c 100644 --- a/libnd4j/include/ops/declarable/helpers/cuda/segment_mean.cu +++ b/libnd4j/include/ops/declarable/helpers/cuda/segment_mean.cu @@ -174,8 +174,8 @@ namespace helpers { } else { std::vector dimensions = ShapeUtils::evalDimsToExclude(input->rankOf(), {0}); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), dimensions); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), dimensions); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), dimensions); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), dimensions); auto inputTads = packX.specialShapeInfo(); auto inputTadOffsets = packX.specialOffsets(); auto outputTads = packZ.specialShapeInfo(); @@ -216,8 +216,8 @@ namespace helpers { else { output->assign(0); std::vector dimensions = ShapeUtils::evalDimsToExclude(input->rankOf(), {0}); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), dimensions); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), dimensions); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), dimensions); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), dimensions); Nd4jLong const* inputTads = packX.specialShapeInfo(); Nd4jLong const* inputTadOffsets = packX.specialOffsets(); Nd4jLong const* outputTads = packZ.specialShapeInfo(); @@ -333,10 +333,10 @@ namespace helpers { } else { std::vector dimensions = ShapeUtils::evalDimsToExclude(input->rankOf(), {0}); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), dimensions); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), dimensions); -// auto packGradIn = sd::ConstantTadHelper::getInstance()->tadForDimensions(tempRes.shapeInfo(), dimensions); - auto packGradOut = sd::ConstantTadHelper::getInstance()->tadForDimensions(gradOut->shapeInfo(), dimensions); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), dimensions); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), dimensions); +// auto packGradIn = sd::ConstantTadHelper::getInstance().tadForDimensions(tempRes.shapeInfo(), dimensions); + auto packGradOut = sd::ConstantTadHelper::getInstance().tadForDimensions(gradOut->shapeInfo(), dimensions); Nd4jLong const* inputTads = packX.specialShapeInfo(); Nd4jLong const* inputTadOffsets = packX.specialOffsets(); Nd4jLong const* outputTads = packZ.specialShapeInfo(); @@ -386,10 +386,10 @@ namespace helpers { } else { std::vector dimensions = ShapeUtils::evalDimsToExclude(input->rankOf(), {0}); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), dimensions); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), dimensions); -// auto packGradIn = sd::ConstantTadHelper::getInstance()->tadForDimensions(tempRes.shapeInfo(), dimensions); - auto packGradOut = sd::ConstantTadHelper::getInstance()->tadForDimensions(gradOut->shapeInfo(), dimensions); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), dimensions); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), dimensions); +// auto packGradIn = sd::ConstantTadHelper::getInstance().tadForDimensions(tempRes.shapeInfo(), dimensions); + auto packGradOut = sd::ConstantTadHelper::getInstance().tadForDimensions(gradOut->shapeInfo(), dimensions); Nd4jLong const* inputTads = packX.specialShapeInfo(); Nd4jLong const* inputTadOffsets = packX.specialOffsets(); Nd4jLong const* outputTads = packZ.specialShapeInfo(); diff --git a/libnd4j/include/ops/declarable/helpers/cuda/segment_min.cu b/libnd4j/include/ops/declarable/helpers/cuda/segment_min.cu index c6f2d4ed2..9e825c701 100644 --- a/libnd4j/include/ops/declarable/helpers/cuda/segment_min.cu +++ b/libnd4j/include/ops/declarable/helpers/cuda/segment_min.cu @@ -177,8 +177,8 @@ namespace helpers { } else { std::vector dimensions = ShapeUtils::evalDimsToExclude(input->rankOf(), {0}); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), dimensions); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), dimensions); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), dimensions); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), dimensions); auto inputTads = packX.specialShapeInfo(); auto inputTadOffsets = packX.specialOffsets(); auto outputTads = packZ.specialShapeInfo(); @@ -222,8 +222,8 @@ namespace helpers { else { output->assign(DataTypeUtils::max()); std::vector dimensions = ShapeUtils::evalDimsToExclude(input->rankOf(), {0}); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), dimensions); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), dimensions); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), dimensions); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), dimensions); auto inputTads = packX.specialShapeInfo(); auto inputTadOffsets = packX.specialOffsets(); auto outputTads = packZ.specialShapeInfo(); @@ -347,10 +347,10 @@ namespace helpers { } else { std::vector dimensions = ShapeUtils::evalDimsToExclude(input->rankOf(), {0}); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), dimensions); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), dimensions); - auto packGradIn = sd::ConstantTadHelper::getInstance()->tadForDimensions(tempRes.shapeInfo(), dimensions); - auto packGradOut = sd::ConstantTadHelper::getInstance()->tadForDimensions(gradOut->shapeInfo(), dimensions); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), dimensions); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), dimensions); + auto packGradIn = sd::ConstantTadHelper::getInstance().tadForDimensions(tempRes.shapeInfo(), dimensions); + auto packGradOut = sd::ConstantTadHelper::getInstance().tadForDimensions(gradOut->shapeInfo(), dimensions); auto inputTads = packX.specialShapeInfo(); auto inputTadOffsets = packX.specialOffsets(); auto outputTads = packZ.specialShapeInfo(); @@ -395,10 +395,10 @@ namespace helpers { } else { std::vector dimensions = ShapeUtils::evalDimsToExclude(input->rankOf(), {0}); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), dimensions); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), dimensions); - auto packGradIn = sd::ConstantTadHelper::getInstance()->tadForDimensions(tempRes.shapeInfo(), dimensions); - auto packGradOut = sd::ConstantTadHelper::getInstance()->tadForDimensions(gradOut->shapeInfo(), dimensions); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), dimensions); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), dimensions); + auto packGradIn = sd::ConstantTadHelper::getInstance().tadForDimensions(tempRes.shapeInfo(), dimensions); + auto packGradOut = sd::ConstantTadHelper::getInstance().tadForDimensions(gradOut->shapeInfo(), dimensions); auto inputTads = packX.specialShapeInfo(); auto inputTadOffsets = packX.specialOffsets(); auto outputTads = packZ.specialShapeInfo(); diff --git a/libnd4j/include/ops/declarable/helpers/cuda/segment_prod.cu b/libnd4j/include/ops/declarable/helpers/cuda/segment_prod.cu index 026ded3e7..44e077300 100644 --- a/libnd4j/include/ops/declarable/helpers/cuda/segment_prod.cu +++ b/libnd4j/include/ops/declarable/helpers/cuda/segment_prod.cu @@ -138,8 +138,8 @@ namespace helpers { } else { std::vector dimensions = ShapeUtils::evalDimsToExclude(input->rankOf(), {0}); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), dimensions); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), dimensions); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), dimensions); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), dimensions); auto inputTads = packX.specialShapeInfo(); auto inputTadOffsets = packX.specialOffsets(); auto outputTads = packZ.specialShapeInfo(); @@ -181,8 +181,8 @@ namespace helpers { } else { std::vector dimensions = ShapeUtils::evalDimsToExclude(input->rankOf(), {0}); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), dimensions); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), dimensions); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), dimensions); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), dimensions); auto inputTads = packX.specialShapeInfo(); auto inputTadOffsets = packX.specialOffsets(); auto outputTads = packZ.specialShapeInfo(); @@ -296,10 +296,10 @@ namespace helpers { } else { std::vector dimensions = ShapeUtils::evalDimsToExclude(input->rankOf(), {0}); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), dimensions); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), dimensions); - auto packGradIn = sd::ConstantTadHelper::getInstance()->tadForDimensions(tempRes.shapeInfo(), dimensions); - auto packGradOut = sd::ConstantTadHelper::getInstance()->tadForDimensions(gradOut->shapeInfo(), dimensions); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), dimensions); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), dimensions); + auto packGradIn = sd::ConstantTadHelper::getInstance().tadForDimensions(tempRes.shapeInfo(), dimensions); + auto packGradOut = sd::ConstantTadHelper::getInstance().tadForDimensions(gradOut->shapeInfo(), dimensions); auto inputTads = packX.specialShapeInfo(); auto inputTadOffsets = packX.specialOffsets(); auto outputTads = packZ.specialShapeInfo(); @@ -346,10 +346,10 @@ namespace helpers { } else { std::vector dimensions = ShapeUtils::evalDimsToExclude(input->rankOf(), {0}); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), dimensions); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), dimensions); - auto packGradIn = sd::ConstantTadHelper::getInstance()->tadForDimensions(tempRes.shapeInfo(), dimensions); - auto packGradOut = sd::ConstantTadHelper::getInstance()->tadForDimensions(gradOut->shapeInfo(), dimensions); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), dimensions); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), dimensions); + auto packGradIn = sd::ConstantTadHelper::getInstance().tadForDimensions(tempRes.shapeInfo(), dimensions); + auto packGradOut = sd::ConstantTadHelper::getInstance().tadForDimensions(gradOut->shapeInfo(), dimensions); auto inputTads = packX.specialShapeInfo(); auto inputTadOffsets = packX.specialOffsets(); auto outputTads = packZ.specialShapeInfo(); diff --git a/libnd4j/include/ops/declarable/helpers/cuda/segment_sqrtn.cu b/libnd4j/include/ops/declarable/helpers/cuda/segment_sqrtn.cu index b72abeffc..20f232332 100644 --- a/libnd4j/include/ops/declarable/helpers/cuda/segment_sqrtn.cu +++ b/libnd4j/include/ops/declarable/helpers/cuda/segment_sqrtn.cu @@ -108,8 +108,8 @@ namespace helpers { else { output->nullify(); std::vector dimensions = ShapeUtils::evalDimsToExclude(input->rankOf(), {0}); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), dimensions); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), dimensions); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), dimensions); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), dimensions); auto inputTads = packX.specialShapeInfo(); auto inputTadOffsets = packX.specialOffsets(); auto outputTads = packZ.specialShapeInfo(); @@ -226,10 +226,10 @@ namespace helpers { } else { std::vector dimensions = ShapeUtils::evalDimsToExclude(input->rankOf(), {0}); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), dimensions); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), dimensions); -// auto packGradIn = sd::ConstantTadHelper::getInstance()->tadForDimensions(tempRes.shapeInfo(), dimensions); - auto packGradOut = sd::ConstantTadHelper::getInstance()->tadForDimensions(gradOut->shapeInfo(), dimensions); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), dimensions); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), dimensions); +// auto packGradIn = sd::ConstantTadHelper::getInstance().tadForDimensions(tempRes.shapeInfo(), dimensions); + auto packGradOut = sd::ConstantTadHelper::getInstance().tadForDimensions(gradOut->shapeInfo(), dimensions); auto inputTads = packX.specialShapeInfo(); auto inputTadOffsets = packX.specialOffsets(); auto outputTads = packZ.specialShapeInfo(); diff --git a/libnd4j/include/ops/declarable/helpers/cuda/segment_sum.cu b/libnd4j/include/ops/declarable/helpers/cuda/segment_sum.cu index 7a762a526..a2050d695 100644 --- a/libnd4j/include/ops/declarable/helpers/cuda/segment_sum.cu +++ b/libnd4j/include/ops/declarable/helpers/cuda/segment_sum.cu @@ -186,8 +186,8 @@ namespace helpers { } else { std::vector dimensions = ShapeUtils::evalDimsToExclude(input->rankOf(), {0}); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), dimensions); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), dimensions); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), dimensions); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), dimensions); auto inputTads = packX.specialShapeInfo(); auto inputTadOffsets = packX.specialOffsets(); auto outputTads = packZ.specialShapeInfo(); @@ -227,8 +227,8 @@ namespace helpers { else { output->assign(0); std::vector dimensions = ShapeUtils::evalDimsToExclude(input->rankOf(), {0}); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), dimensions); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), dimensions); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), dimensions); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), dimensions); auto inputTads = packX.specialShapeInfo(); auto inputTadOffsets = packX.specialOffsets(); auto outputTads = packZ.specialShapeInfo(); @@ -338,9 +338,9 @@ namespace helpers { } else { std::vector dimensions = ShapeUtils::evalDimsToExclude(input->rankOf(), {0}); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), dimensions); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), dimensions); - auto packGradOut = sd::ConstantTadHelper::getInstance()->tadForDimensions(gradOut->shapeInfo(), dimensions); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), dimensions); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), dimensions); + auto packGradOut = sd::ConstantTadHelper::getInstance().tadForDimensions(gradOut->shapeInfo(), dimensions); auto inputTads = packX.specialShapeInfo(); auto inputTadOffsets = packX.specialOffsets(); auto outputTads = packZ.specialShapeInfo(); @@ -379,9 +379,9 @@ namespace helpers { } else { std::vector dimensions = ShapeUtils::evalDimsToExclude(input->rankOf(), {0}); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), dimensions); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), dimensions); - auto packGradOut = sd::ConstantTadHelper::getInstance()->tadForDimensions(gradOut->shapeInfo(), dimensions); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), dimensions); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), dimensions); + auto packGradOut = sd::ConstantTadHelper::getInstance().tadForDimensions(gradOut->shapeInfo(), dimensions); auto inputTads = packX.specialShapeInfo(); auto inputTadOffsets = packX.specialOffsets(); auto outputTads = packZ.specialShapeInfo(); diff --git a/libnd4j/include/ops/declarable/helpers/cuda/solve.cu b/libnd4j/include/ops/declarable/helpers/cuda/solve.cu index cf8308bbe..43ef78c3e 100644 --- a/libnd4j/include/ops/declarable/helpers/cuda/solve.cu +++ b/libnd4j/include/ops/declarable/helpers/cuda/solve.cu @@ -73,12 +73,12 @@ namespace sd { helpers::lu(context, leftInput, &leftOutput, &permutations); auto leftLower = leftOutput.dup(); auto rightOutput = rightInput->ulike(); - auto leftLowerTad = ConstantTadHelper::getInstance()->tadForDimensions(leftLower.shapeInfo(), {-2, -1}); + auto leftLowerTad = ConstantTadHelper::getInstance().tadForDimensions(leftLower.shapeInfo(), {-2, -1}); auto stream = context->getCudaStream(); oneOnDiagonalKernel<<<128, 256, 256, *stream>>>(leftLower.dataBuffer()->specialAsT(), leftLower.specialShapeInfo(), leftLowerTad.specialShapeInfo(), leftLowerTad.specialOffsets(), leftLowerTad.numberOfTads(), leftLower.sizeAt(-1)); auto P = leftOutput.ulike(); P.nullify(); - auto PTad = ConstantTadHelper::getInstance()->tadForDimensions(P.shapeInfo(), {-2, -1}); - auto permutationsTad = ConstantTadHelper::getInstance()->tadForDimensions(permutations.shapeInfo(), {-1}); + auto PTad = ConstantTadHelper::getInstance().tadForDimensions(P.shapeInfo(), {-2, -1}); + auto permutationsTad = ConstantTadHelper::getInstance().tadForDimensions(permutations.shapeInfo(), {-1}); restorePermutationsKernel<<<128, 256, 256, *stream>>>(P.dataBuffer()->specialAsT(), P.specialShapeInfo(), permutations.dataBuffer()->specialAsT(), PTad.specialShapeInfo(), PTad.specialOffsets(), permutationsTad.specialShapeInfo(), permutationsTad.specialOffsets(), permutationsTad.numberOfTads(), permutations.sizeAt(-1)); P.tickWriteDevice(); @@ -120,8 +120,8 @@ namespace sd { template static void adjointMatrix_(sd::LaunchContext* context, NDArray const* input, NDArray* output) { NDArray::prepareSpecialUse({output}, {input}); - auto inputTads = ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), {-2, -1}); - auto outputTads = ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), {-2, -1}); + auto inputTads = ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), {-2, -1}); + auto outputTads = ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), {-2, -1}); auto stream = context->getCudaStream(); auto outputBuf = reinterpret_cast(output->specialBuffer()); auto rows = input->sizeAt(-2); diff --git a/libnd4j/include/ops/declarable/helpers/cuda/stack.cu b/libnd4j/include/ops/declarable/helpers/cuda/stack.cu index f0983b76c..2bb09c3b5 100644 --- a/libnd4j/include/ops/declarable/helpers/cuda/stack.cu +++ b/libnd4j/include/ops/declarable/helpers/cuda/stack.cu @@ -91,7 +91,7 @@ static void stack_(sd::LaunchContext* context, const std::vector } else { - auto zTadPack = ConstantTadHelper::getInstance()->tadForDimensions(output.shapeInfo(), ShapeUtils::evalDimsToExclude(output.rankOf(), {dim})); + auto zTadPack = ConstantTadHelper::getInstance().tadForDimensions(output.shapeInfo(), ShapeUtils::evalDimsToExclude(output.rankOf(), {dim})); auto zTadShapeInfo = zTadPack.primaryShapeInfo(); for (uint i = 0; i < numOfSubArrs; ++i) { @@ -179,7 +179,7 @@ static void unstack_(sd::LaunchContext* context, const NDArray& input, const std } else { - auto xTadPack = ConstantTadHelper::getInstance()->tadForDimensions(input.shapeInfo(), ShapeUtils::evalDimsToExclude(input.rankOf(), {dim})); + auto xTadPack = ConstantTadHelper::getInstance().tadForDimensions(input.shapeInfo(), ShapeUtils::evalDimsToExclude(input.rankOf(), {dim})); auto xTadShapeInfo = xTadPack.primaryShapeInfo(); for (uint i = 0; i < numOfSubArrs; ++i) { @@ -272,7 +272,7 @@ BUILD_SINGLE_TEMPLATE(template void unstack_, (sd::LaunchContext* context, const // outArrs[i]->syncToDevice(); // input.syncToDevice(); -// BUILD_SINGLE_SELECTOR(input.dataType(), unstackCudaLauncher, (blocksPerGrid, threadsPerBlock, context->getCudaStream(), input.specialBuffer(), input.specialShapeInfo(), dOutBuffers, outArrs[0]->specialShapeInfo(), axis), LIBND4J_TYPES); +// BUILD_SINGLE_SELECTOR(input.dataType(), unstackCudaLauncher, (blocksPerGrid, threadsPerBlock, context->getCudaStream(), input.specialBuffer(), input.specialShapeInfo(), dOutBuffers, outArrs[0]->special(), axis), LIBND4J_TYPES); // manager.synchronize(); @@ -350,7 +350,7 @@ BUILD_SINGLE_TEMPLATE(template void unstack_, (sd::LaunchContext* context, const // inArrs[i]->syncToDevice(); // output.syncToDevice(); -// BUILD_SINGLE_SELECTOR(output.dataType(), stackCudaLauncher, (blocksPerGrid, threadsPerBlock, context->getCudaStream(), dInBuffers, inArrs[0]->specialShapeInfo(), output.specialBuffer(), output.specialShapeInfo(), axis), LIBND4J_TYPES); +// BUILD_SINGLE_SELECTOR(output.dataType(), stackCudaLauncher, (blocksPerGrid, threadsPerBlock, context->getCudaStream(), dInBuffers, inArrs[0]->specialShapeInfo(), output.specialBuffer(), output.special(), axis), LIBND4J_TYPES); // manager.synchronize(); diff --git a/libnd4j/include/ops/declarable/helpers/cuda/top_k.cu b/libnd4j/include/ops/declarable/helpers/cuda/top_k.cu index ce19d41cc..61aefa255 100644 --- a/libnd4j/include/ops/declarable/helpers/cuda/top_k.cu +++ b/libnd4j/include/ops/declarable/helpers/cuda/top_k.cu @@ -91,7 +91,7 @@ int inTopKFunctor(sd::LaunchContext * context, const NDArray* predictions, const PointersManager manager(context, "in_top_k"); - const auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(predictions->shapeInfo(), {1}); + const auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(predictions->shapeInfo(), {1}); const int threadsPerBlock = MAX_NUM_THREADS; const int blocksPerGrid = static_cast(packX.numberOfTads()); @@ -243,9 +243,9 @@ int inTopKFunctor(sd::LaunchContext * context, const NDArray* predictions, const template static int topKFunctor_(sd::LaunchContext * context, const NDArray* input, NDArray* values, NDArray* indices, const uint k, bool needSort) { - auto packX = ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), {input->rankOf() - 1}); - auto packI = ConstantTadHelper::getInstance()->tadForDimensions(indices->shapeInfo(), {input->rankOf() - 1}); - auto packZ = ConstantTadHelper::getInstance()->tadForDimensions(values->shapeInfo(), {input->rankOf() - 1}); + auto packX = ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), {input->rankOf() - 1}); + auto packI = ConstantTadHelper::getInstance().tadForDimensions(indices->shapeInfo(), {input->rankOf() - 1}); + auto packZ = ConstantTadHelper::getInstance().tadForDimensions(values->shapeInfo(), {input->rankOf() - 1}); auto tadLength = shape::length(packX.primaryShapeInfo()); diff --git a/libnd4j/include/ops/declarable/helpers/cuda/transforms.cu b/libnd4j/include/ops/declarable/helpers/cuda/transforms.cu index f14b12e35..8d7f700dd 100644 --- a/libnd4j/include/ops/declarable/helpers/cuda/transforms.cu +++ b/libnd4j/include/ops/declarable/helpers/cuda/transforms.cu @@ -321,7 +321,7 @@ void tileBP(sd::LaunchContext * context, const NDArray& gradO /*input*/, NDArray template static __global__ void fillShuffleKernel(T* input, Nd4jLong const* inputShape, T* output, Nd4jLong const* outputShape, Nd4jLong firstDim, int* indices, sd::graph::RandomGenerator* rng) { -// PRAGMA_OMP_PARALLEL_FOR_IF((firstDim-1) > Environment::getInstance()->tadThreshold()) +// PRAGMA_OMP_PARALLEL_FOR_IF((firstDim-1) > Environment::getInstance().tadThreshold()) auto tid = blockIdx.x * blockDim.x; auto step = blockDim.x * gridDim.x; diff --git a/libnd4j/include/ops/declarable/helpers/cuda/triangular_solve.cu b/libnd4j/include/ops/declarable/helpers/cuda/triangular_solve.cu index 6302262be..e77bb4e19 100644 --- a/libnd4j/include/ops/declarable/helpers/cuda/triangular_solve.cu +++ b/libnd4j/include/ops/declarable/helpers/cuda/triangular_solve.cu @@ -141,9 +141,9 @@ namespace sd { static int triangularSolveFunctor_(sd::LaunchContext * context, NDArray* leftInput, NDArray* rightInput, bool lower, bool unitsOnDiag, NDArray* output) { NDArray::prepareSpecialUse({output}, {leftInput, rightInput}); - auto leftTads = ConstantTadHelper::getInstance()->tadForDimensions(leftInput->shapeInfo(), {-2, -1}); - auto rightTads = ConstantTadHelper::getInstance()->tadForDimensions(rightInput->shapeInfo(), {-2, -1}); - auto outputTads = ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), {-2, -1}); + auto leftTads = ConstantTadHelper::getInstance().tadForDimensions(leftInput->shapeInfo(), {-2, -1}); + auto rightTads = ConstantTadHelper::getInstance().tadForDimensions(rightInput->shapeInfo(), {-2, -1}); + auto outputTads = ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), {-2, -1}); auto stream = context->getCudaStream(); T const* leftBuf = reinterpret_cast(leftInput->specialBuffer()); @@ -243,8 +243,8 @@ namespace sd { static void adjointTriangularMatrix_(sd::LaunchContext* context, NDArray const* input, bool const lower, NDArray* output) { - auto inputTads = ConstantTadHelper::getInstance()->tadForDimensions(input->shapeInfo(), {-2, -1}); - auto outputTads = ConstantTadHelper::getInstance()->tadForDimensions(output->shapeInfo(), {-2, -1}); + auto inputTads = ConstantTadHelper::getInstance().tadForDimensions(input->shapeInfo(), {-2, -1}); + auto outputTads = ConstantTadHelper::getInstance().tadForDimensions(output->shapeInfo(), {-2, -1}); auto stream = context->getCudaStream(); auto inputBuf = reinterpret_cast(input->specialBuffer()); auto outputBuf = reinterpret_cast(output->specialBuffer()); diff --git a/libnd4j/include/ops/declarable/impl/BooleanOp.cpp b/libnd4j/include/ops/declarable/impl/BooleanOp.cpp index 00079f9ae..07960497a 100644 --- a/libnd4j/include/ops/declarable/impl/BooleanOp.cpp +++ b/libnd4j/include/ops/declarable/impl/BooleanOp.cpp @@ -33,7 +33,7 @@ namespace sd { * Output shape of any BooleanOp is ALWAYS scalar */ ShapeList *BooleanOp::calculateOutputShape(ShapeList *inputShape, sd::graph::Context &block) { - return SHAPELIST(ConstantShapeHelper::getInstance()->scalarShapeInfo(DataType::BOOL)); + return SHAPELIST(ConstantShapeHelper::getInstance().scalarShapeInfo(DataType::BOOL)); } bool BooleanOp::verify(sd::graph::Context &block) { diff --git a/libnd4j/include/ops/declarable/impl/BroadcastableBoolOp.cpp b/libnd4j/include/ops/declarable/impl/BroadcastableBoolOp.cpp index 8f0a6dcb8..634236d35 100644 --- a/libnd4j/include/ops/declarable/impl/BroadcastableBoolOp.cpp +++ b/libnd4j/include/ops/declarable/impl/BroadcastableBoolOp.cpp @@ -38,32 +38,32 @@ namespace sd { if(shape::isEmpty(x) || shape::isEmpty(y)) { // this is edge case, [3, 4] + [] = [] if ((shape::isEmpty(x) && shape::rank(x) == 0) || (shape::isEmpty(y) && shape::rank(y) == 0)) { - shapeList->push_back(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor::emptyDescriptor(dtype))); + shapeList->push_back(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor::emptyDescriptor(dtype))); return shapeList; } const Nd4jLong *newshape = nullptr; ShapeUtils::evalBroadcastShapeInfo(x, y, true, newshape, block.workspace()); - shapeList->push_back(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(newshape, dtype))); + shapeList->push_back(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(newshape, dtype))); } else if (shape::isScalar(x) && shape::isScalar(y)) { if (shape::rank(x) >= shape::rank(y)) { - shapeList->push_back(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(x, dtype))); + shapeList->push_back(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(x, dtype))); } else { - shapeList->push_back(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(y, dtype))); + shapeList->push_back(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(y, dtype))); } } else if (shape::equalsSoft(x, y)) { - shapeList->push_back(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(x, dtype))); + shapeList->push_back(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(x, dtype))); } else if (shape::isScalar(x) && !shape::isScalar(y)) { - shapeList->push_back(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(y, dtype))); + shapeList->push_back(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(y, dtype))); } else if (!shape::isScalar(x) && shape::isScalar(y)) { - shapeList->push_back(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(x, dtype))); + shapeList->push_back(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(x, dtype))); } else if (ShapeUtils::areShapesBroadcastable(x, y)) { const Nd4jLong *newshape = nullptr; ShapeUtils::evalBroadcastShapeInfo(x, y, true, newshape, block.workspace()); - shapeList->push_back(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(newshape, dtype))); + shapeList->push_back(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(newshape, dtype))); } else { // in this case we'll throw exception later - shapeList->push_back(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(x, dtype))); + shapeList->push_back(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(x, dtype))); } return shapeList; diff --git a/libnd4j/include/ops/declarable/impl/BroadcastableOp.cpp b/libnd4j/include/ops/declarable/impl/BroadcastableOp.cpp index 7f7a14861..4611d49cb 100644 --- a/libnd4j/include/ops/declarable/impl/BroadcastableOp.cpp +++ b/libnd4j/include/ops/declarable/impl/BroadcastableOp.cpp @@ -36,7 +36,7 @@ namespace sd { auto outputs = _descriptor->getOutputTypesForOutput(0); sd::DataType dtype = block.dataType(0); if (block.dataType(0) != sd::DataType::BOOL && !(outputs.size() == 1 && outputs[0] == sd::DataType::BOOL)) { - if (Environment::getInstance()->isExperimentalBuild()) { + if (Environment::getInstance().isExperimentalBuild()) { if (shape::length(y) > shape::length(x)) { dtype = DataTypeUtils::pickPairwiseResultType(y, x); } else { @@ -51,33 +51,33 @@ namespace sd { if(shape::isEmpty(x) || shape::isEmpty(y)) { // this is edge case, [3, 4] + [] = [] if ((shape::isEmpty(x) && shape::rank(x) == 0) || (shape::isEmpty(y) && shape::rank(y) == 0)) { - shapeList->push_back(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor::emptyDescriptor(dtype))); + shapeList->push_back(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor::emptyDescriptor(dtype))); return shapeList; } const Nd4jLong *newshape = nullptr; ShapeUtils::evalBroadcastShapeInfo(x, y, true, newshape, block.workspace()); - shapeList->push_back(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(newshape, dtype))); + shapeList->push_back(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(newshape, dtype))); } else if (shape::isScalar(x) && shape::isScalar(y)) { if (shape::rank(x) >= shape::rank(y)) { - shapeList->push_back(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(x, dtype))); + shapeList->push_back(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(x, dtype))); } else { - shapeList->push_back(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(y, dtype))); + shapeList->push_back(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(y, dtype))); } } else if (shape::equalsSoft(x, y)) { - shapeList->push_back(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(x, dtype))); + shapeList->push_back(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(x, dtype))); } else if (shape::isScalar(x) && !shape::isScalar(y)) { - shapeList->push_back(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(y, dtype))); + shapeList->push_back(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(y, dtype))); } else if (!shape::isScalar(x) && shape::isScalar(y)) { - shapeList->push_back(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(x, dtype))); + shapeList->push_back(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(x, dtype))); } else if (ShapeUtils::areShapesBroadcastable(x, y)) { const Nd4jLong *newshape = nullptr; ShapeUtils::evalBroadcastShapeInfo(x, y, true, newshape, block.workspace()); - shapeList->push_back(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(newshape, dtype))); + shapeList->push_back(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(newshape, dtype))); } else { // in this case we'll throw exception later - shapeList->push_back(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(x, dtype))); + shapeList->push_back(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(x, dtype))); } return shapeList; diff --git a/libnd4j/include/ops/declarable/impl/DeclarableListOp.cpp b/libnd4j/include/ops/declarable/impl/DeclarableListOp.cpp index 13aa763f8..d70355038 100644 --- a/libnd4j/include/ops/declarable/impl/DeclarableListOp.cpp +++ b/libnd4j/include/ops/declarable/impl/DeclarableListOp.cpp @@ -47,7 +47,7 @@ namespace sd { ShapeList* DeclarableListOp::calculateOutputShape(ShapeList* inputShape, sd::graph::Context& block) { // TODO: ensure this method isn't ever called - auto newShape = ConstantShapeHelper::getInstance()->createShapeInfo(block.dataType(), 'c', {1, 1}); + auto newShape = ConstantShapeHelper::getInstance().createShapeInfo(block.dataType(), 'c', {1, 1}); return SHAPELIST(newShape); } diff --git a/libnd4j/include/ops/declarable/impl/DeclarableOp.cpp b/libnd4j/include/ops/declarable/impl/DeclarableOp.cpp index 713a02666..cd8d0bdd8 100644 --- a/libnd4j/include/ops/declarable/impl/DeclarableOp.cpp +++ b/libnd4j/include/ops/declarable/impl/DeclarableOp.cpp @@ -158,7 +158,7 @@ namespace sd { auto fp = ctx.isFastPath(); - if (Environment::getInstance()->isProfiling()) { + if (Environment::getInstance().isProfiling()) { if (ctx.getVariableSpace() != nullptr && ctx.getVariableSpace()->flowPath() != nullptr) { prof = ctx.getVariableSpace()->flowPath()->profile(); node = prof->nodeById(ctx.nodeId()); @@ -166,7 +166,7 @@ namespace sd { } if (ctx.isInplace()) { - if (Environment::getInstance()->isProfiling() && node != nullptr) { + if (Environment::getInstance().isProfiling() && node != nullptr) { if (fp) { // } else { @@ -227,7 +227,7 @@ namespace sd { ShapeList inSha; int results = 0; - if (Environment::getInstance()->isProfiling() && node != nullptr) + if (Environment::getInstance().isProfiling() && node != nullptr) inputStart = std::chrono::system_clock::now(); int cntIn = 0; @@ -263,7 +263,7 @@ namespace sd { } // optionally saving input time - if (Environment::getInstance()->isProfiling() && node != nullptr) { + if (Environment::getInstance().isProfiling() && node != nullptr) { inputEnd = std::chrono::system_clock::now(); auto inputTime = std::chrono::duration_cast(inputEnd - inputStart).count(); node->setInputTime(inputTime); @@ -279,7 +279,7 @@ namespace sd { results = outSha->size(); // optionally saving shapeTime - if (Environment::getInstance()->isProfiling() && node != nullptr) { + if (Environment::getInstance().isProfiling() && node != nullptr) { shapeEnd = std::chrono::system_clock::now(); auto prepTime = std::chrono::duration_cast(shapeEnd - shapeStart).count(); node->setShapeFunctionTime(prepTime); @@ -299,7 +299,7 @@ namespace sd { std::pair pair(ctx.nodeId(), cnt++); if (!ctx.isValueAvailable(pair.second)) { - if (Environment::getInstance()->isDebugAndVerbose()) + if (Environment::getInstance().isDebugAndVerbose()) shape::printShapeInfoLinear("Going to create variable with shape", out); // we're creating non-initialized array here @@ -367,7 +367,7 @@ namespace sd { delete outSha; // saving arrayTime - if (Environment::getInstance()->isProfiling() && node != nullptr) { + if (Environment::getInstance().isProfiling() && node != nullptr) { arrayEnd = std::chrono::system_clock::now(); auto arrayTime = std::chrono::duration_cast(arrayEnd - arrayStart).count(); node->setArrayTime(arrayTime); @@ -599,7 +599,7 @@ namespace sd { Nd4jLong prepTime, outerTime; Nd4jLong memoryBefore = block->workspace() == nullptr ? 0L : block->workspace()->getSpilledSize() + block->workspace()->getUsedSize(); - if (Environment::getInstance()->isProfiling()) + if (Environment::getInstance().isProfiling()) timeEnter = std::chrono::system_clock::now(); // basic validation: ensure inputs are set @@ -615,7 +615,7 @@ namespace sd { // this method will allocate output NDArrays for this op auto numOutputs = this->prepareOutputs(*block); - if (Environment::getInstance()->isProfiling()) { + if (Environment::getInstance().isProfiling()) { timeStart = std::chrono::system_clock::now(); prepTime = std::chrono::duration_cast(timeStart - timeEnter).count(); } @@ -625,10 +625,10 @@ namespace sd { bool hasHelper = false; // platform helpers use might be forbidden for various reasons, so we'll check it out first - if (block->helpersAllowed() && sd::Environment::getInstance()->helpersAllowed()) { + if (block->helpersAllowed() && sd::Environment::getInstance().helpersAllowed()) { // if we have platform-specific helper for this op - invoke it - if (OpRegistrator::getInstance()->hasHelper(this->getOpHash(), block->engine())) { - auto helper = OpRegistrator::getInstance()->getPlatformHelper(this->getOpHash(), block->engine()); + if (OpRegistrator::getInstance().hasHelper(this->getOpHash(), block->engine())) { + auto helper = OpRegistrator::getInstance().getPlatformHelper(this->getOpHash(), block->engine()); if (helper->isUsable(*block)) { status = helper->invokeHelper(*block); hasHelper = true; @@ -641,13 +641,13 @@ namespace sd { status = this->validateAndExecute(*block); // optionally saving execution time - if (Environment::getInstance()->isProfiling()) { + if (Environment::getInstance().isProfiling()) { timeEnd = std::chrono::system_clock::now(); outerTime = std::chrono::duration_cast(timeEnd - timeStart).count(); block->setInnerTime(outerTime); } - if (Environment::getInstance()->isProfiling() && block->getVariableSpace() != nullptr) { + if (Environment::getInstance().isProfiling() && block->getVariableSpace() != nullptr) { auto fp = block->getVariableSpace()->flowPath(); if (fp != nullptr) { auto p = fp->profile(); @@ -663,7 +663,7 @@ namespace sd { // now we print out all outputs for this node - if (sd::Environment::getInstance()->isDebugAndVerbose()) { + if (sd::Environment::getInstance().isDebugAndVerbose()) { auto vs = block->getVariableSpace(); for (int e = 0; e < numOutputs; e++) { diff --git a/libnd4j/include/ops/declarable/impl/DeclarableReductionOp.cpp b/libnd4j/include/ops/declarable/impl/DeclarableReductionOp.cpp index 4f6646694..2dd281991 100644 --- a/libnd4j/include/ops/declarable/impl/DeclarableReductionOp.cpp +++ b/libnd4j/include/ops/declarable/impl/DeclarableReductionOp.cpp @@ -52,7 +52,7 @@ namespace sd { // special case - output is scalar if (dims.size() == 0 || (dims.size() == 1 && dims.at(0) == sd::DataTypeUtils::max())) { - auto newShape = ConstantShapeHelper::getInstance()->scalarShapeInfo(block.dataType()); + auto newShape = ConstantShapeHelper::getInstance().scalarShapeInfo(block.dataType()); return SHAPELIST(newShape); } diff --git a/libnd4j/include/ops/declarable/impl/LegacyBroadcastBoolOp.cpp b/libnd4j/include/ops/declarable/impl/LegacyBroadcastBoolOp.cpp index f7cb3de92..a171ff339 100644 --- a/libnd4j/include/ops/declarable/impl/LegacyBroadcastBoolOp.cpp +++ b/libnd4j/include/ops/declarable/impl/LegacyBroadcastBoolOp.cpp @@ -41,11 +41,11 @@ namespace sd { int opNum = block.opNum() < 0 ? this->_opNum : block.opNum(); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(x->shapeInfo(), dims); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(x->shapeInfo(), dims); PointersManager manager(block.launchContext(), "LegacyBroadcastBoolOp"); - auto pTadShape = Environment::getInstance()->isCPU() ? packX.primaryShapeInfo() : packX.specialShapeInfo(); //(Nd4jLong *) manager.replicatePointer(tad.tadOnlyShapeInfo, shape::shapeInfoByteLength(tad.tadOnlyShapeInfo)); - auto pTadOffsets = Environment::getInstance()->isCPU() ? packX.primaryOffsets() : packX.specialOffsets(); //(Nd4jLong *) manager.replicatePointer(tad.tadOffsets, tad.numTads * sizeof(Nd4jLong)); + auto pTadShape = Environment::getInstance().isCPU() ? packX.primaryShapeInfo() : packX.specialShapeInfo(); //(Nd4jLong *) manager.replicatePointer(tad.tadOnlyShapeInfo, shape::shapeInfoByteLength(tad.tadOnlyShapeInfo)); + auto pTadOffsets = Environment::getInstance().isCPU() ? packX.primaryOffsets() : packX.specialOffsets(); //(Nd4jLong *) manager.replicatePointer(tad.tadOffsets, tad.numTads * sizeof(Nd4jLong)); REQUIRE_TRUE(shape::length(packX.primaryShapeInfo()) == y->lengthOf(), 0, "Length of broadcast TAD should be equal to length of Y operand, but got [%i] vs [%i]", (int) shape::length(packX.primaryShapeInfo()), (int) y->lengthOf()); @@ -57,10 +57,10 @@ namespace sd { else { // this is rare, but possible use case - X and Z might have different shapes/strides/orders. In this case we prepare and pass separate TAD info - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(z->shapeInfo(), dims); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(z->shapeInfo(), dims); - auto zTadShape = Environment::getInstance()->isCPU() ? packZ.primaryShapeInfo() : packZ.specialShapeInfo(); //(Nd4jLong *) manager.replicatePointer(tadZ.tadOnlyShapeInfo, shape::shapeInfoByteLength(tadZ.tadOnlyShapeInfo)); - auto zTadOffsets = Environment::getInstance()->isCPU() ? packZ.primaryOffsets() : packZ.specialOffsets(); //(Nd4jLong *) manager.replicatePointer(tadZ.tadOffsets, tadZ.numTads * sizeof(Nd4jLong)); + auto zTadShape = Environment::getInstance().isCPU() ? packZ.primaryShapeInfo() : packZ.specialShapeInfo(); //(Nd4jLong *) manager.replicatePointer(tadZ.tadOnlyShapeInfo, shape::shapeInfoByteLength(tadZ.tadOnlyShapeInfo)); + auto zTadOffsets = Environment::getInstance().isCPU() ? packZ.primaryOffsets() : packZ.specialOffsets(); //(Nd4jLong *) manager.replicatePointer(tadZ.tadOffsets, tadZ.numTads * sizeof(Nd4jLong)); NativeOpExecutioner::execBroadcast(block.launchContext(), opNum, x->buffer(), x->shapeInfo(), x->specialBuffer(), x->specialShapeInfo(), y->buffer(), y->shapeInfo(), y->specialBuffer(), y->specialShapeInfo(), @@ -91,7 +91,7 @@ namespace sd { */ ShapeList* LegacyBroadcastBoolOp::calculateOutputShape(ShapeList *inputShape, sd::graph::Context &block) { auto inShape = inputShape->at(0); - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(inShape, DataType::BOOL))); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(inShape, DataType::BOOL))); } } } diff --git a/libnd4j/include/ops/declarable/impl/LegacyBroadcastOp.cpp b/libnd4j/include/ops/declarable/impl/LegacyBroadcastOp.cpp index 82899bbdb..c47cc9040 100644 --- a/libnd4j/include/ops/declarable/impl/LegacyBroadcastOp.cpp +++ b/libnd4j/include/ops/declarable/impl/LegacyBroadcastOp.cpp @@ -47,14 +47,14 @@ namespace sd { int opNum = block.opNum() < 0 ? this->_opNum : block.opNum(); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(x->shapeInfo(), dims); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(x->shapeInfo(), dims); auto tadLen = shape::length(packX.primaryShapeInfo()); REQUIRE_TRUE(tadLen == y->lengthOf(), 0, "Length of broadcast TAD should be equal to length of Y operand, but got [%i] vs [%i]",tadLen, (int) y->lengthOf()); PointersManager manager(block.launchContext(),"LegacyBroadcastOp"); - auto pTadShape = Environment::getInstance()->isCPU() ? packX.primaryShapeInfo() : packX.specialShapeInfo(); //(Nd4jLong *) manager.replicatePointer(tad.tadOnlyShapeInfo, shape::shapeInfoByteLength(tad.tadOnlyShapeInfo)); - auto pTadOffsets = Environment::getInstance()->isCPU() ? packX.primaryOffsets() : packX.specialOffsets(); //(Nd4jLong *) manager.replicatePointer(tad.tadOffsets, tad.numTads * sizeof(Nd4jLong)); + auto pTadShape = Environment::getInstance().isCPU() ? packX.primaryShapeInfo() : packX.specialShapeInfo(); //(Nd4jLong *) manager.replicatePointer(tad.tadOnlyShapeInfo, shape::shapeInfoByteLength(tad.tadOnlyShapeInfo)); + auto pTadOffsets = Environment::getInstance().isCPU() ? packX.primaryOffsets() : packX.specialOffsets(); //(Nd4jLong *) manager.replicatePointer(tad.tadOffsets, tad.numTads * sizeof(Nd4jLong)); if (x == z) NativeOpExecutioner::execBroadcast(block.launchContext(), opNum, x->buffer(), x->shapeInfo(), x->specialBuffer(), x->specialShapeInfo(), @@ -62,10 +62,10 @@ namespace sd { z->buffer(), z->shapeInfo(), z->specialBuffer(), z->specialShapeInfo(), dims.data(), dims.size(), pTadShape, pTadOffsets, pTadShape, pTadOffsets); else { // this is rare, but possible use case - X and Z might have different shapes/strides/orders. In this case we prepare and pass separate TAD info - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(z->shapeInfo(), dims); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(z->shapeInfo(), dims); - auto zTadShape = Environment::getInstance()->isCPU() ? packZ.primaryShapeInfo() : packZ.specialShapeInfo(); //(Nd4jLong *) manager.replicatePointer(tadZ.tadOnlyShapeInfo, shape::shapeInfoByteLength(tadZ.tadOnlyShapeInfo)); - auto zTadOffsets = Environment::getInstance()->isCPU() ? packZ.primaryOffsets() : packZ.specialOffsets(); //(Nd4jLong *) manager.replicatePointer(tadZ.tadOffsets, tadZ.numTads * sizeof(Nd4jLong)); + auto zTadShape = Environment::getInstance().isCPU() ? packZ.primaryShapeInfo() : packZ.specialShapeInfo(); //(Nd4jLong *) manager.replicatePointer(tadZ.tadOnlyShapeInfo, shape::shapeInfoByteLength(tadZ.tadOnlyShapeInfo)); + auto zTadOffsets = Environment::getInstance().isCPU() ? packZ.primaryOffsets() : packZ.specialOffsets(); //(Nd4jLong *) manager.replicatePointer(tadZ.tadOffsets, tadZ.numTads * sizeof(Nd4jLong)); NativeOpExecutioner::execBroadcast(block.launchContext(), opNum, x->buffer(), x->shapeInfo(), x->specialBuffer(), x->specialShapeInfo(), y->buffer(), y->shapeInfo(), y->specialBuffer(), y->specialShapeInfo(), diff --git a/libnd4j/include/ops/declarable/impl/LegacyIndexReduceOp.cpp b/libnd4j/include/ops/declarable/impl/LegacyIndexReduceOp.cpp index 7fc6bf793..a9e8475c0 100644 --- a/libnd4j/include/ops/declarable/impl/LegacyIndexReduceOp.cpp +++ b/libnd4j/include/ops/declarable/impl/LegacyIndexReduceOp.cpp @@ -54,7 +54,7 @@ namespace sd { newShape[6] = 1; newShape[7] = 99; - auto result = ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(newShape, DataType::INT64)); + auto result = ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(newShape, DataType::INT64)); RELEASE(newShape, block.getWorkspace()); return SHAPELIST(result); } else if (block.getAxis()->size()){ @@ -89,7 +89,7 @@ namespace sd { newShape[6] = 1; newShape[7] = 99; - auto result = ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(newShape, DataType::INT64)); + auto result = ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(newShape, DataType::INT64)); RELEASE(newShape, block.getWorkspace()); return SHAPELIST(result); } else { @@ -139,7 +139,7 @@ namespace sd { if (dims.size() > 1) std::sort(dims.begin(), dims.end()); - auto tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(x->shapeInfo(), dims); + auto tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(x->shapeInfo(), dims); NativeOpExecutioner::execIndexReduce(block.launchContext(), opNum, x->buffer(), x->shapeInfo(), x->specialBuffer(), x->specialShapeInfo(), @@ -147,7 +147,7 @@ namespace sd { reinterpret_cast(z->buffer()), z->shapeInfo(), z->specialBuffer(), z->specialShapeInfo(), nullptr, (int) dims.size(), - Environment::getInstance()->isCPU() ? tadPack.primaryShapeInfo() : tadPack.specialShapeInfo(), Environment::getInstance()->isCPU() ? tadPack.primaryOffsets() : tadPack.specialOffsets()); + Environment::getInstance().isCPU() ? tadPack.primaryShapeInfo() : tadPack.specialShapeInfo(), Environment::getInstance().isCPU() ? tadPack.primaryOffsets() : tadPack.specialOffsets()); } } else { // TF mode @@ -175,7 +175,7 @@ namespace sd { REQUIRE_TRUE(axis.size() > 0, 0, "Some dimensions required for reduction!"); - auto tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(x->shapeInfo(), axis); + auto tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(x->shapeInfo(), axis); NativeOpExecutioner::execIndexReduce(block.launchContext(), opNum, x->buffer(), x->shapeInfo(), x->specialBuffer(), x->specialShapeInfo(), @@ -183,8 +183,8 @@ namespace sd { reinterpret_cast(z->buffer()), z->shapeInfo(), z->specialBuffer(), z->specialShapeInfo(), nullptr, (int) axis.size(), - Environment::getInstance()->isCPU() ? tadPack.primaryShapeInfo() : tadPack.specialShapeInfo(), - Environment::getInstance()->isCPU() ? tadPack.primaryOffsets() : tadPack.specialOffsets()); + Environment::getInstance().isCPU() ? tadPack.primaryShapeInfo() : tadPack.specialShapeInfo(), + Environment::getInstance().isCPU() ? tadPack.primaryOffsets() : tadPack.specialOffsets()); } } diff --git a/libnd4j/include/ops/declarable/impl/LegacyPairwiseTransformBoolOp.cpp b/libnd4j/include/ops/declarable/impl/LegacyPairwiseTransformBoolOp.cpp index 11a05a76c..8b6e1406e 100644 --- a/libnd4j/include/ops/declarable/impl/LegacyPairwiseTransformBoolOp.cpp +++ b/libnd4j/include/ops/declarable/impl/LegacyPairwiseTransformBoolOp.cpp @@ -67,7 +67,7 @@ namespace sd { */ ShapeList *LegacyPairwiseTransformBoolOp::calculateOutputShape(ShapeList *inputShape, sd::graph::Context &block) { auto inShape = inputShape->at(0); - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(inShape, DataType::BOOL))); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(inShape, DataType::BOOL))); } } } \ No newline at end of file diff --git a/libnd4j/include/ops/declarable/impl/LegacyRandomOp.cpp b/libnd4j/include/ops/declarable/impl/LegacyRandomOp.cpp index 085780c56..09c0a054a 100644 --- a/libnd4j/include/ops/declarable/impl/LegacyRandomOp.cpp +++ b/libnd4j/include/ops/declarable/impl/LegacyRandomOp.cpp @@ -344,7 +344,7 @@ namespace sd { auto zShapeVector = zShapeArr->asVectorT(); auto dtype = block.dataType(); - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(dtype, 'c', zShapeVector)); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(dtype, 'c', zShapeVector)); } else throw std::runtime_error("LegacyRandomOp: Unknown input data type!"); } diff --git a/libnd4j/include/ops/declarable/impl/LegacyReduce3Op.cpp b/libnd4j/include/ops/declarable/impl/LegacyReduce3Op.cpp index f110c0c55..700e0dba9 100644 --- a/libnd4j/include/ops/declarable/impl/LegacyReduce3Op.cpp +++ b/libnd4j/include/ops/declarable/impl/LegacyReduce3Op.cpp @@ -52,16 +52,16 @@ namespace sd { if (dims[e] < 0) dims[e] += x->rankOf(); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(x->shapeInfo(), dims); - auto packZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(z->shapeInfo(), dims); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(x->shapeInfo(), dims); + auto packZ = sd::ConstantTadHelper::getInstance().tadForDimensions(z->shapeInfo(), dims); REQUIRE_TRUE(dims.size() > 0, 0, "Some dimensions requuired for reduction!"); - auto xTadShape = Environment::getInstance()->isCPU() ? packX.primaryShapeInfo() : packX.specialShapeInfo(); //(Nd4jLong *) manager.replicatePointer(tadX.tadOnlyShapeInfo, shape::shapeInfoByteLength(tadX.tadOnlyShapeInfo)); - auto xTadOffsets = Environment::getInstance()->isCPU() ? packX.primaryOffsets() : packX.specialOffsets(); //(Nd4jLong *) manager.replicatePointer(tadX.tadOffsets, tadX.numTads * sizeof(Nd4jLong)); + auto xTadShape = Environment::getInstance().isCPU() ? packX.primaryShapeInfo() : packX.specialShapeInfo(); //(Nd4jLong *) manager.replicatePointer(tadX.tadOnlyShapeInfo, shape::shapeInfoByteLength(tadX.tadOnlyShapeInfo)); + auto xTadOffsets = Environment::getInstance().isCPU() ? packX.primaryOffsets() : packX.specialOffsets(); //(Nd4jLong *) manager.replicatePointer(tadX.tadOffsets, tadX.numTads * sizeof(Nd4jLong)); - auto yTadShape = Environment::getInstance()->isCPU() ? packZ.primaryShapeInfo() : packZ.specialOffsets(); //(Nd4jLong *) manager.replicatePointer(tadY.tadOnlyShapeInfo, shape::shapeInfoByteLength(tadY.tadOnlyShapeInfo)); - auto yTadOffsets = Environment::getInstance()->isCPU() ? packZ.primaryOffsets() : packZ.specialOffsets(); //(Nd4jLong *) manager.replicatePointer(tadY.tadOffsets, tadY.numTads * sizeof(Nd4jLong)); + auto yTadShape = Environment::getInstance().isCPU() ? packZ.primaryShapeInfo() : packZ.specialOffsets(); //(Nd4jLong *) manager.replicatePointer(tadY.tadOnlyShapeInfo, shape::shapeInfoByteLength(tadY.tadOnlyShapeInfo)); + auto yTadOffsets = Environment::getInstance().isCPU() ? packZ.primaryOffsets() : packZ.specialOffsets(); //(Nd4jLong *) manager.replicatePointer(tadY.tadOffsets, tadY.numTads * sizeof(Nd4jLong)); NativeOpExecutioner::execReduce3(block.launchContext(), opNum, x->buffer(), x->shapeInfo(), x->specialBuffer(), x->specialShapeInfo(), extras.argumentsAsT(z->dataType()), diff --git a/libnd4j/include/ops/declarable/impl/LegacyReduceBoolOp.cpp b/libnd4j/include/ops/declarable/impl/LegacyReduceBoolOp.cpp index 4aced5aec..e16e71619 100644 --- a/libnd4j/include/ops/declarable/impl/LegacyReduceBoolOp.cpp +++ b/libnd4j/include/ops/declarable/impl/LegacyReduceBoolOp.cpp @@ -75,10 +75,10 @@ namespace sd { REQUIRE_TRUE(dims.size() > 0, 0, "Some dimensions required for reduction!"); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(x->shapeInfo(), dims); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(x->shapeInfo(), dims); - auto pTadShape = Environment::getInstance()->isCPU() ? packX.primaryShapeInfo() : packX.specialShapeInfo(); //manager.replicatePointer(tad.tadOnlyShapeInfo, shape::shapeInfoByteLength(tad.tadOnlyShapeInfo)); - auto pTadOffsets = Environment::getInstance()->isCPU() ? packX.primaryOffsets() : packX.specialOffsets(); //manager.replicatePointer(tad.tadOffsets, tad.numTads * sizeof(Nd4jLong)); + auto pTadShape = Environment::getInstance().isCPU() ? packX.primaryShapeInfo() : packX.specialShapeInfo(); //manager.replicatePointer(tad.tadOnlyShapeInfo, shape::shapeInfoByteLength(tad.tadOnlyShapeInfo)); + auto pTadOffsets = Environment::getInstance().isCPU() ? packX.primaryOffsets() : packX.specialOffsets(); //manager.replicatePointer(tad.tadOffsets, tad.numTads * sizeof(Nd4jLong)); NativeOpExecutioner::execReduceBool(block.launchContext(), opNum, x->buffer(), x->shapeInfo(), x->specialBuffer(), x->specialShapeInfo(), extras.argumentsAsT(x->dataType()), @@ -111,10 +111,10 @@ namespace sd { REQUIRE_TRUE(dims.size() > 0, 0, "Some dimensions required for reduction!"); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(x->shapeInfo(), dims); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(x->shapeInfo(), dims); - auto pTadShape = Environment::getInstance()->isCPU() ? packX.primaryShapeInfo() : packX.specialShapeInfo(); //(Nd4jLong *) manager.replicatePointer(tad.tadOnlyShapeInfo, shape::shapeInfoByteLength(tad.tadOnlyShapeInfo)); - auto pTadOffsets = Environment::getInstance()->isCPU() ? packX.primaryOffsets() : packX.specialOffsets(); //(Nd4jLong *) manager.replicatePointer(tad.tadOffsets, tad.numTads * sizeof(Nd4jLong)); + auto pTadShape = Environment::getInstance().isCPU() ? packX.primaryShapeInfo() : packX.specialShapeInfo(); //(Nd4jLong *) manager.replicatePointer(tad.tadOnlyShapeInfo, shape::shapeInfoByteLength(tad.tadOnlyShapeInfo)); + auto pTadOffsets = Environment::getInstance().isCPU() ? packX.primaryOffsets() : packX.specialOffsets(); //(Nd4jLong *) manager.replicatePointer(tad.tadOffsets, tad.numTads * sizeof(Nd4jLong)); NativeOpExecutioner::execReduceBool(block.launchContext(), opNum, x->buffer(), x->shapeInfo(), x->specialBuffer(), x->specialShapeInfo(), extras.argumentsAsT(x->dataType()), z->buffer(), z->shapeInfo(), z->specialBuffer(), z->specialShapeInfo(), dims.data(), (int) dims.size(), pTadShape, pTadOffsets); diff --git a/libnd4j/include/ops/declarable/impl/LegacyReduceFloatOp.cpp b/libnd4j/include/ops/declarable/impl/LegacyReduceFloatOp.cpp index 55197844a..a0ff14858 100644 --- a/libnd4j/include/ops/declarable/impl/LegacyReduceFloatOp.cpp +++ b/libnd4j/include/ops/declarable/impl/LegacyReduceFloatOp.cpp @@ -76,10 +76,10 @@ namespace sd { REQUIRE_TRUE(dims.size() > 0, 0, "Some dimensions required for reduction!"); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(x->shapeInfo(), dims); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(x->shapeInfo(), dims); - auto pTadShape = Environment::getInstance()->isCPU() ? packX.primaryShapeInfo() : packX.specialShapeInfo(); //manager.replicatePointer(tad.tadOnlyShapeInfo, shape::shapeInfoByteLength(tad.tadOnlyShapeInfo)); - auto pTadOffsets = Environment::getInstance()->isCPU() ? packX.primaryOffsets() : packX.specialOffsets(); //manager.replicatePointer(tad.tadOffsets, tad.numTads * sizeof(Nd4jLong)); + auto pTadShape = Environment::getInstance().isCPU() ? packX.primaryShapeInfo() : packX.specialShapeInfo(); //manager.replicatePointer(tad.tadOnlyShapeInfo, shape::shapeInfoByteLength(tad.tadOnlyShapeInfo)); + auto pTadOffsets = Environment::getInstance().isCPU() ? packX.primaryOffsets() : packX.specialOffsets(); //manager.replicatePointer(tad.tadOffsets, tad.numTads * sizeof(Nd4jLong)); NativeOpExecutioner::execReduceFloat(block.launchContext(), opNum, x->buffer(), x->shapeInfo(), x->specialBuffer(), x->specialShapeInfo(), extras.argumentsAsT(z->dataType()), z->buffer(), z->shapeInfo(), z->specialBuffer(), z->specialShapeInfo(), @@ -109,10 +109,10 @@ namespace sd { // TAD REQUIRE_TRUE(dims.size() > 0, 0, "Some dimensions required for reduction!"); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(x->shapeInfo(), dims); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(x->shapeInfo(), dims); - auto pTadShape = Environment::getInstance()->isCPU() ? packX.primaryShapeInfo() : packX.specialShapeInfo(); //(Nd4jLong *) manager.replicatePointer(tad.tadOnlyShapeInfo, shape::shapeInfoByteLength(tad.tadOnlyShapeInfo)); - auto pTadOffsets = Environment::getInstance()->isCPU() ? packX.primaryOffsets() : packX.specialOffsets(); //(Nd4jLong *) manager.replicatePointer(tad.tadOffsets, tad.numTads * sizeof(Nd4jLong)); + auto pTadShape = Environment::getInstance().isCPU() ? packX.primaryShapeInfo() : packX.specialShapeInfo(); //(Nd4jLong *) manager.replicatePointer(tad.tadOnlyShapeInfo, shape::shapeInfoByteLength(tad.tadOnlyShapeInfo)); + auto pTadOffsets = Environment::getInstance().isCPU() ? packX.primaryOffsets() : packX.specialOffsets(); //(Nd4jLong *) manager.replicatePointer(tad.tadOffsets, tad.numTads * sizeof(Nd4jLong)); NativeOpExecutioner::execReduceFloat(block.launchContext(), opNum, x->buffer(), x->shapeInfo(), x->specialBuffer(), x->specialShapeInfo(), extras.argumentsAsT(z->dataType()), z->buffer(), z->shapeInfo(), z->specialBuffer(), z->specialShapeInfo(), diff --git a/libnd4j/include/ops/declarable/impl/LegacyReduceLongOp.cpp b/libnd4j/include/ops/declarable/impl/LegacyReduceLongOp.cpp index 628c4cb5f..f5007ff03 100644 --- a/libnd4j/include/ops/declarable/impl/LegacyReduceLongOp.cpp +++ b/libnd4j/include/ops/declarable/impl/LegacyReduceLongOp.cpp @@ -78,10 +78,10 @@ namespace sd { REQUIRE_TRUE(dims.size() > 0, 0, "Some dimensions required for reduction!"); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(x->shapeInfo(), dims); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(x->shapeInfo(), dims); - auto pTadShape = Environment::getInstance()->isCPU() ? packX.primaryShapeInfo() : packX.specialShapeInfo(); //(Nd4jLong *) manager.replicatePointer(tad.tadOnlyShapeInfo, shape::shapeInfoByteLength(tad.tadOnlyShapeInfo)); - auto pTadOffsets = Environment::getInstance()->isCPU() ? packX.primaryOffsets() : packX.specialOffsets(); //(Nd4jLong *) manager.replicatePointer(tad.tadOffsets, tad.numTads * sizeof(Nd4jLong)); + auto pTadShape = Environment::getInstance().isCPU() ? packX.primaryShapeInfo() : packX.specialShapeInfo(); //(Nd4jLong *) manager.replicatePointer(tad.tadOnlyShapeInfo, shape::shapeInfoByteLength(tad.tadOnlyShapeInfo)); + auto pTadOffsets = Environment::getInstance().isCPU() ? packX.primaryOffsets() : packX.specialOffsets(); //(Nd4jLong *) manager.replicatePointer(tad.tadOffsets, tad.numTads * sizeof(Nd4jLong)); NativeOpExecutioner::execReduceLong(block.launchContext(), opNum, x->buffer(), x->shapeInfo(), x->specialBuffer(), x->specialShapeInfo(), extras.argumentsAsT(x->dataType()), @@ -111,10 +111,10 @@ namespace sd { // TAD REQUIRE_TRUE(dims.size() > 0, 0, "Some dimensions required for reduction!"); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(x->shapeInfo(), dims); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(x->shapeInfo(), dims); - auto pTadShape = Environment::getInstance()->isCPU() ? packX.primaryShapeInfo() : packX.specialShapeInfo(); //(Nd4jLong *) manager.replicatePointer(tad.tadOnlyShapeInfo, shape::shapeInfoByteLength(tad.tadOnlyShapeInfo)); - auto pTadOffsets = Environment::getInstance()->isCPU() ? packX.primaryOffsets() : packX.specialOffsets(); //(Nd4jLong *) manager.replicatePointer(tad.tadOffsets, tad.numTads * sizeof(Nd4jLong)); + auto pTadShape = Environment::getInstance().isCPU() ? packX.primaryShapeInfo() : packX.specialShapeInfo(); //(Nd4jLong *) manager.replicatePointer(tad.tadOnlyShapeInfo, shape::shapeInfoByteLength(tad.tadOnlyShapeInfo)); + auto pTadOffsets = Environment::getInstance().isCPU() ? packX.primaryOffsets() : packX.specialOffsets(); //(Nd4jLong *) manager.replicatePointer(tad.tadOffsets, tad.numTads * sizeof(Nd4jLong)); NativeOpExecutioner::execReduceLong(block.launchContext(), opNum, x->buffer(), x->shapeInfo(), x->specialBuffer(), x->specialShapeInfo(), extras.argumentsAsT(x->dataType()), z->buffer(), z->shapeInfo(), z->specialBuffer(), z->specialShapeInfo(), dims.data(), (int) dims.size(), pTadShape, pTadOffsets); diff --git a/libnd4j/include/ops/declarable/impl/LegacyReduceSameOp.cpp b/libnd4j/include/ops/declarable/impl/LegacyReduceSameOp.cpp index e406a3a2d..299d19f14 100644 --- a/libnd4j/include/ops/declarable/impl/LegacyReduceSameOp.cpp +++ b/libnd4j/include/ops/declarable/impl/LegacyReduceSameOp.cpp @@ -73,10 +73,10 @@ namespace sd { REQUIRE_TRUE(dims.size() > 0, 0, "Some dimensions required for reduction!"); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(x->shapeInfo(), dims); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(x->shapeInfo(), dims); - auto pTadShape = Environment::getInstance()->isCPU() ? packX.primaryShapeInfo() : packX.specialShapeInfo(); //(Nd4jLong *) manager.replicatePointer(tad.tadOnlyShapeInfo, shape::shapeInfoByteLength(tad.tadOnlyShapeInfo)); - auto pTadOffsets = Environment::getInstance()->isCPU() ? packX.primaryOffsets() : packX.specialOffsets(); //(Nd4jLong *) manager.replicatePointer(tad.tadOffsets, tad.numTads * sizeof(Nd4jLong)); + auto pTadShape = Environment::getInstance().isCPU() ? packX.primaryShapeInfo() : packX.specialShapeInfo(); //(Nd4jLong *) manager.replicatePointer(tad.tadOnlyShapeInfo, shape::shapeInfoByteLength(tad.tadOnlyShapeInfo)); + auto pTadOffsets = Environment::getInstance().isCPU() ? packX.primaryOffsets() : packX.specialOffsets(); //(Nd4jLong *) manager.replicatePointer(tad.tadOffsets, tad.numTads * sizeof(Nd4jLong)); NativeOpExecutioner::execReduceSame(block.launchContext(), opNum, x->buffer(), x->shapeInfo(), x->specialBuffer(), x->specialShapeInfo(), extras.argumentsAsT(z->dataType()), @@ -106,10 +106,10 @@ namespace sd { // TAD REQUIRE_TRUE(dims.size() > 0, 0, "Some dimensions required for reduction!"); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(x->shapeInfo(), dims); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(x->shapeInfo(), dims); - auto pTadShape = Environment::getInstance()->isCPU() ? packX.primaryShapeInfo() : packX.specialShapeInfo(); //(Nd4jLong *) manager.replicatePointer(tad.tadOnlyShapeInfo, shape::shapeInfoByteLength(tad.tadOnlyShapeInfo)); - auto pTadOffsets = Environment::getInstance()->isCPU() ? packX.primaryOffsets() : packX.specialOffsets(); //(Nd4jLong *) manager.replicatePointer(tad.tadOffsets, tad.numTads * sizeof(Nd4jLong)); + auto pTadShape = Environment::getInstance().isCPU() ? packX.primaryShapeInfo() : packX.specialShapeInfo(); //(Nd4jLong *) manager.replicatePointer(tad.tadOnlyShapeInfo, shape::shapeInfoByteLength(tad.tadOnlyShapeInfo)); + auto pTadOffsets = Environment::getInstance().isCPU() ? packX.primaryOffsets() : packX.specialOffsets(); //(Nd4jLong *) manager.replicatePointer(tad.tadOffsets, tad.numTads * sizeof(Nd4jLong)); NativeOpExecutioner::execReduceSame(block.launchContext(), opNum, x->buffer(), x->shapeInfo(), x->specialBuffer(), x->specialShapeInfo(), extras.argumentsAsT(z->dataType()), z->buffer(), z->shapeInfo(), z->specialBuffer(), z->specialShapeInfo(), diff --git a/libnd4j/include/ops/declarable/impl/LegacyScalarOp.cpp b/libnd4j/include/ops/declarable/impl/LegacyScalarOp.cpp index 3e73b10f5..0c700b88b 100644 --- a/libnd4j/include/ops/declarable/impl/LegacyScalarOp.cpp +++ b/libnd4j/include/ops/declarable/impl/LegacyScalarOp.cpp @@ -72,7 +72,7 @@ namespace sd { x->applyScalarArr(static_cast(opNum), y, *z); // NDArray::prepareSpecialUse({z}, {x, &y}); - // NativeOpExecutioner::execScalar(block.launchContext(), opNum, x->buffer(), x->shapeInfo(), x->specialBuffer(), x->specialShapeInfo(), z->buffer(), z->shapeInfo(), z->specialBuffer(), z->specialShapeInfo(), y.buffer(), y.shapeInfo(), y.specialBuffer(), y.specialShapeInfo(), extras.argumentsAsT(z->dataType(), 1)); + // NativeOpExecutioner::execScalar(block.launchContext(), opNum, x->buffer(), x->shapeInfo(), x->specialBuffer(), x->specialShapeInfo(), z->buffer(), z->shapeInfo(), z->specialBuffer(), z->specialShapeInfo(), y.buffer(), y.shapeInfo(), y.specialBuffer(), y.special(), extras.argumentsAsT(z->dataType(), 1)); manager.synchronize(); } else { diff --git a/libnd4j/include/ops/declarable/impl/LegacyStatsOp.cpp b/libnd4j/include/ops/declarable/impl/LegacyStatsOp.cpp index b8694f9ff..4a60064b5 100644 --- a/libnd4j/include/ops/declarable/impl/LegacyStatsOp.cpp +++ b/libnd4j/include/ops/declarable/impl/LegacyStatsOp.cpp @@ -58,10 +58,10 @@ namespace sd { REQUIRE_TRUE(dims.size() > 0, 0, "Some dimensions requuired for reduction!"); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(x->shapeInfo(), dims); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(x->shapeInfo(), dims); - auto pTadShape = Environment::getInstance()->isCPU() ? packX.primaryShapeInfo() : packX.specialShapeInfo(); //(Nd4jLong *) manager.replicatePointer(tad.tadOnlyShapeInfo, shape::shapeInfoByteLength(tad.tadOnlyShapeInfo)); - auto pTadOffsets = Environment::getInstance()->isCPU() ? packX.primaryOffsets() : packX.specialOffsets(); //(Nd4jLong *) manager.replicatePointer(tad.tadOffsets, tad.numTads * sizeof(Nd4jLong)); + auto pTadShape = Environment::getInstance().isCPU() ? packX.primaryShapeInfo() : packX.specialShapeInfo(); //(Nd4jLong *) manager.replicatePointer(tad.tadOnlyShapeInfo, shape::shapeInfoByteLength(tad.tadOnlyShapeInfo)); + auto pTadOffsets = Environment::getInstance().isCPU() ? packX.primaryOffsets() : packX.specialOffsets(); //(Nd4jLong *) manager.replicatePointer(tad.tadOffsets, tad.numTads * sizeof(Nd4jLong)); NativeOpExecutioner::execSummaryStats(block.launchContext(), opNum, x->buffer(), x->shapeInfo(), x->specialBuffer(), x->specialShapeInfo(), extras.argumentsAsT(z->dataType()), z->buffer(), z->shapeInfo(), z->specialBuffer(), z->specialShapeInfo(), dims.data(), (int) dims.size(), pTadShape, pTadOffsets, biasCorrected); diff --git a/libnd4j/include/ops/declarable/impl/LegacyTransformBoolOp.cpp b/libnd4j/include/ops/declarable/impl/LegacyTransformBoolOp.cpp index a0651d1fc..3bf4f1ff4 100644 --- a/libnd4j/include/ops/declarable/impl/LegacyTransformBoolOp.cpp +++ b/libnd4j/include/ops/declarable/impl/LegacyTransformBoolOp.cpp @@ -65,7 +65,7 @@ namespace sd { */ ShapeList *LegacyTransformBoolOp::calculateOutputShape(ShapeList *inputShape, sd::graph::Context &block) { auto inShape = inputShape->at(0); - return SHAPELIST(ConstantShapeHelper::getInstance()->createShapeInfo(ShapeDescriptor(inShape, DataType::BOOL))); + return SHAPELIST(ConstantShapeHelper::getInstance().createShapeInfo(ShapeDescriptor(inShape, DataType::BOOL))); } } } \ No newline at end of file diff --git a/libnd4j/include/ops/declarable/impl/OpDescriptor.cpp b/libnd4j/include/ops/declarable/impl/OpDescriptor.cpp index 398c11729..84c1bc291 100644 --- a/libnd4j/include/ops/declarable/impl/OpDescriptor.cpp +++ b/libnd4j/include/ops/declarable/impl/OpDescriptor.cpp @@ -33,7 +33,7 @@ namespace sd { _numOutputs = 1; _opName = opName; - _hash = sd::ops::HashHelper::getInstance()->getLongHash(_opName); + _hash = sd::ops::HashHelper::getInstance().getLongHash(_opName); _opClass = sd::graph::OpClass_CONDITIONAL; _scalar = isScalar; @@ -44,7 +44,7 @@ namespace sd { _numOutputs = 1; _opName = opName; - _hash = sd::ops::HashHelper::getInstance()->getLongHash(_opName); + _hash = sd::ops::HashHelper::getInstance().getLongHash(_opName); _opClass = sd::graph::OpClass_CONDITIONAL; _scalar = isScalar; @@ -77,7 +77,7 @@ namespace sd { std::string tmp(opName); _opName = tmp; _allowsInplace = allowsInplace; - _hash = sd::ops::HashHelper::getInstance()->getLongHash(tmp); + _hash = sd::ops::HashHelper::getInstance().getLongHash(tmp); _divergent = false; // just default value diff --git a/libnd4j/include/ops/declarable/impl/OpRegistrator.cpp b/libnd4j/include/ops/declarable/impl/OpRegistrator.cpp index 65d694dea..327cb0482 100644 --- a/libnd4j/include/ops/declarable/impl/OpRegistrator.cpp +++ b/libnd4j/include/ops/declarable/impl/OpRegistrator.cpp @@ -31,31 +31,29 @@ namespace sd { template __registrator::__registrator() { auto ptr = new OpName(); - OpRegistrator::getInstance()->registerOperation(ptr); + OpRegistrator::getInstance().registerOperation(ptr); } template __registratorSynonym::__registratorSynonym(const char *name, const char *oname) { - auto ptr = reinterpret_cast(OpRegistrator::getInstance()->getOperation(oname)); + auto ptr = reinterpret_cast(OpRegistrator::getInstance().getOperation(oname)); if (ptr == nullptr) { std::string newName(name); std::string oldName(oname); - OpRegistrator::getInstance()->updateMSVC(sd::ops::HashHelper::getInstance()->getLongHash(newName), oldName); + OpRegistrator::getInstance().updateMSVC(sd::ops::HashHelper::getInstance().getLongHash(newName), oldName); return; } - OpRegistrator::getInstance()->registerOperation(name, ptr); + OpRegistrator::getInstance().registerOperation(name, ptr); } /////////////////////////////// - OpRegistrator* OpRegistrator::getInstance() { - if (!_INSTANCE) - _INSTANCE = new sd::ops::OpRegistrator(); - - return _INSTANCE; + OpRegistrator& OpRegistrator::getInstance() { + static OpRegistrator instance; + return instance; } @@ -89,21 +87,15 @@ namespace sd { } void OpRegistrator::sigIntHandler(int sig) { -#ifndef _RELEASE - delete OpRegistrator::getInstance(); -#endif + } void OpRegistrator::exitHandler() { -#ifndef _RELEASE - delete OpRegistrator::getInstance(); -#endif + } void OpRegistrator::sigSegVHandler(int sig) { -#ifndef _RELEASE - delete OpRegistrator::getInstance(); -#endif + } OpRegistrator::~OpRegistrator() { @@ -156,7 +148,7 @@ namespace sd { std::pair pair(str, op); _declarablesD.insert(pair); - auto hash = sd::ops::HashHelper::getInstance()->getLongHash(str); + auto hash = sd::ops::HashHelper::getInstance().getLongHash(str); std::pair pair2(hash, op); _declarablesLD.insert(pair2); return true; @@ -256,8 +248,6 @@ namespace sd { return result; } - - sd::ops::OpRegistrator* sd::ops::OpRegistrator::_INSTANCE = 0; } } diff --git a/libnd4j/include/ops/declarable/impl/PlatformHelper.cpp b/libnd4j/include/ops/declarable/impl/PlatformHelper.cpp index dfc18d33b..245626c09 100644 --- a/libnd4j/include/ops/declarable/impl/PlatformHelper.cpp +++ b/libnd4j/include/ops/declarable/impl/PlatformHelper.cpp @@ -27,7 +27,7 @@ namespace sd { PlatformHelper::PlatformHelper(const char *name, samediff::Engine engine) { // we just store name/hash of target operation _name = std::string(name); - _hash = HashHelper::getInstance()->getLongHash(_name); + _hash = HashHelper::getInstance().getLongHash(_name); _engine = engine; } diff --git a/libnd4j/include/ops/impl/gemm.cpp b/libnd4j/include/ops/impl/gemm.cpp index 0c4ab167c..8632ddcb9 100644 --- a/libnd4j/include/ops/impl/gemm.cpp +++ b/libnd4j/include/ops/impl/gemm.cpp @@ -68,7 +68,7 @@ namespace sd { if (beta == 0.0) { Z z = 0.f; int length = M*N; - if (length <= Environment::getInstance()->elementwiseThreshold()) { + if (length <= Environment::getInstance().elementwiseThreshold()) { for (int r = 0; r < length; r++) C[r] = z; } else { diff --git a/libnd4j/include/ops/impl/specials_double.hpp b/libnd4j/include/ops/impl/specials_double.hpp index 1eaf3fbc0..d219220ac 100644 --- a/libnd4j/include/ops/impl/specials_double.hpp +++ b/libnd4j/include/ops/impl/specials_double.hpp @@ -224,8 +224,8 @@ PRAGMA_OMP_SINGLE_ARGS(nowait) auto x = reinterpret_cast(vx); auto y = reinterpret_cast(vy); - auto packX = ConstantTadHelper::getInstance()->tadForDimensions(xShapeInfo, dimension, dimensionLength); - auto packY = ConstantTadHelper::getInstance()->tadForDimensions(yShapeInfo, dimension, dimensionLength); + auto packX = ConstantTadHelper::getInstance().tadForDimensions(xShapeInfo, dimension, dimensionLength); + auto packY = ConstantTadHelper::getInstance().tadForDimensions(yShapeInfo, dimension, dimensionLength); auto xLength = shape::length(xShapeInfo); auto xTadLength = shape::length(packX.primaryShapeInfo()); @@ -248,8 +248,8 @@ PRAGMA_OMP_SINGLE_ARGS(nowait) auto x = reinterpret_cast(vx); auto y = reinterpret_cast(vy); - auto packX = ConstantTadHelper::getInstance()->tadForDimensions(xShapeInfo, dimension, dimensionLength); - auto packY = ConstantTadHelper::getInstance()->tadForDimensions(yShapeInfo, dimension, dimensionLength); + auto packX = ConstantTadHelper::getInstance().tadForDimensions(xShapeInfo, dimension, dimensionLength); + auto packY = ConstantTadHelper::getInstance().tadForDimensions(yShapeInfo, dimension, dimensionLength); auto xLength = shape::length(xShapeInfo); auto xTadLength = shape::length(packX.primaryShapeInfo()); diff --git a/libnd4j/include/ops/special_random_ops.h b/libnd4j/include/ops/special_random_ops.h index 08808e67c..f9bacf5cb 100644 --- a/libnd4j/include/ops/special_random_ops.h +++ b/libnd4j/include/ops/special_random_ops.h @@ -163,7 +163,7 @@ namespace randomOps { int elementsPerThread = zLength / TAD_THRESHOLD; int _threads = sd::math::nd4j_max(1, elementsPerThread); - _threads = sd::math::nd4j_min(_threads, sd::Environment::getInstance()->maxThreads()); + _threads = sd::math::nd4j_min(_threads, sd::Environment::getInstance().maxThreads()); if (zEWS >= 1 && xEWS >= 1 && yEWS >= 1) { auto func = PRAGMA_THREADS_FOR { @@ -315,7 +315,7 @@ namespace randomOps { int elementsPerThread = middle / TAD_THRESHOLD; int _threads = sd::math::nd4j_max(1, elementsPerThread); - _threads = sd::math::nd4j_min(_threads, sd::Environment::getInstance()->maxThreads()); + _threads = sd::math::nd4j_min(_threads, sd::Environment::getInstance().maxThreads()); int span = (middle / _threads) + 8; @@ -434,7 +434,7 @@ namespace randomOps { int elementsPerThread = zLength / TAD_THRESHOLD; int _threads = sd::math::nd4j_max(1, elementsPerThread); - _threads = sd::math::nd4j_min(_threads, sd::Environment::getInstance()->maxThreads()); + _threads = sd::math::nd4j_min(_threads, sd::Environment::getInstance().maxThreads()); T prob = extraArguments[1]; @@ -542,7 +542,7 @@ namespace randomOps { int elementsPerThread = zLength / TAD_THRESHOLD; int _threads = sd::math::nd4j_max(1, elementsPerThread); - _threads = sd::math::nd4j_min(_threads, sd::Environment::getInstance()->maxThreads()); + _threads = sd::math::nd4j_min(_threads, sd::Environment::getInstance().maxThreads()); T prob = extraArguments[1]; @@ -684,7 +684,7 @@ namespace randomOps { Nd4jLong middle = zLength / 2 + (zLength % 2); int elementsPerThread = middle / TAD_THRESHOLD; int _threads = sd::math::nd4j_max(1, elementsPerThread); - _threads = sd::math::nd4j_min(_threads, sd::Environment::getInstance()->maxThreads()); + _threads = sd::math::nd4j_min(_threads, sd::Environment::getInstance().maxThreads()); const T epsilon = static_cast(1e-5); @@ -801,7 +801,7 @@ namespace randomOps { int elementsPerThread = middle / TAD_THRESHOLD; int _threads = sd::math::nd4j_max(1, elementsPerThread); - _threads = sd::math::nd4j_min(_threads, sd::Environment::getInstance()->maxThreads()); + _threads = sd::math::nd4j_min(_threads, sd::Environment::getInstance().maxThreads()); int span = (zLength / _threads) + 8; diff --git a/libnd4j/include/system/Environment.h b/libnd4j/include/system/Environment.h index 392e70871..9b2a4b65b 100644 --- a/libnd4j/include/system/Environment.h +++ b/libnd4j/include/system/Environment.h @@ -62,11 +62,9 @@ namespace sd{ // device compute capability for CUDA std::vector _capabilities; - static Environment* _instance; - Environment(); - ~Environment(); public: + ~Environment(); /** * These 3 fields are mostly for CUDA/cuBLAS version tracking */ @@ -74,7 +72,7 @@ namespace sd{ int _blasMinorVersion = 0; int _blasPatchVersion = 0; - static Environment* getInstance(); + static Environment& getInstance(); bool isVerbose(); void setVerbose(bool reallyVerbose); diff --git a/libnd4j/include/system/op_boilerplate.h b/libnd4j/include/system/op_boilerplate.h index 1df4f0047..0c2630f22 100644 --- a/libnd4j/include/system/op_boilerplate.h +++ b/libnd4j/include/system/op_boilerplate.h @@ -118,8 +118,8 @@ #endif -#define ELEMENT_THRESHOLD sd::Environment::getInstance()->elementwiseThreshold() -#define TAD_THRESHOLD sd::Environment::getInstance()->tadThreshold() +#define ELEMENT_THRESHOLD sd::Environment::getInstance().elementwiseThreshold() +#define TAD_THRESHOLD sd::Environment::getInstance().tadThreshold() #define SHAPELIST(...) new ShapeList({__VA_ARGS__}, block.workspace() != nullptr) @@ -129,8 +129,8 @@ #define PRINT_FIRST(...) printf(__VA_ARGS__); fflush(stdout) #endif -#define DEBUG_CALL(STREAM) if (sd::Environment::getInstance()->isDebug()) { cudaError_t tRes = cudaStreamSynchronize(*STREAM); checkCudaErrors(tRes); if (tRes != 0) { throw std::runtime_error(); }; } -#define DEBUG_KERNEL(STREAM, OP_NUM) if (sd::Environment::getInstance()->isDebug()) { cudaError_t tRes = cudaStreamSynchronize(*STREAM); checkCudaErrors(tRes); if (tRes != 0) {std::string tFile(__FILE__); std::string tOp = "Kernel OpNum failed: [" + sd::StringUtils::valueToString(OP_NUM) + std::string("]; File: ") + tFile + std::string(":") + sd::StringUtils::valueToString(__LINE__); throw std::runtime_error(tOp.c_str()); }; } +#define DEBUG_CALL(STREAM) if (sd::Environment::getInstance().isDebug()) { cudaError_t tRes = cudaStreamSynchronize(*STREAM); checkCudaErrors(tRes); if (tRes != 0) { throw std::runtime_error(); }; } +#define DEBUG_KERNEL(STREAM, OP_NUM) if (sd::Environment::getInstance().isDebug()) { cudaError_t tRes = cudaStreamSynchronize(*STREAM); checkCudaErrors(tRes); if (tRes != 0) {std::string tFile(__FILE__); std::string tOp = "Kernel OpNum failed: [" + sd::StringUtils::valueToString(OP_NUM) + std::string("]; File: ") + tFile + std::string(":") + sd::StringUtils::valueToString(__LINE__); throw std::runtime_error(tOp.c_str()); }; } #define LAUNCH(A, B, C, D) <<>> @@ -1112,7 +1112,7 @@ #define _EXPAND_OP_CALL_1(NAME, TYPE, PARAMZ, NUM_A, TYPE_A) NAME>PARAMZ; #define _EXPAND_OP_DIRECT(PARAMZ, NUM_A, TYPE_A) case NUM_A: { z = TYPE_A::op PARAMZ; break; } -#define _EXPAND_OP_CALL_T(TYPE, NUM_A, TYPE_A) OpTracker::getInstance()->storeOperation(TYPE, #TYPE_A, NUM_A); +#define _EXPAND_OP_CALL_T(TYPE, NUM_A, TYPE_A) OpTracker::getInstance().storeOperation(TYPE, #TYPE_A, NUM_A); #define _EXPAND_FACTORY_CALL(TYPE, LAYER_ID, LAYER_NAME, ACTIVATION_ID, ACTIVATION_NAME) if (activationNum == ACTIVATION_ID && layerNum == LAYER_ID) { return new LAYER_NAME>(); }; @@ -1256,7 +1256,7 @@ struct __registrator_##NAME {\ __registrator_##NAME() {\ OpName *ptr = new OpName(); \ - OpRegistrator::getInstance()->registerOperation(ptr); \ + OpRegistrator::getInstance().registerOperation(ptr); \ }\ };\ static sd::ops::__registrator_##NAME zzz_register_opd_##NAME; @@ -1269,7 +1269,7 @@ struct __registrator_##NAME {\ __registrator_##NAME() {\ OpName *ptr = new OpName(); \ - OpRegistrator::getInstance()->registerOperation(ptr); \ + OpRegistrator::getInstance().registerOperation(ptr); \ }\ };\ static sd::ops::__registrator_##NAME zzz_register_opd_##NAME; @@ -1332,7 +1332,7 @@ auto shapeList = SHAPELIST(); \ auto opLimit = this->getOpDescriptor()->getNumberOfOutputs() < 1 ? block.width() : this->getOpDescriptor()->getNumberOfOutputs(); \ for (int e = 0; e < opLimit; e++) { \ - auto newshape = ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(inputShape->at(e)), shape::order(inputShape->at(e)), shape::rank(inputShape->at(e)), shape::shapeOf(inputShape->at(e))); \ + auto newshape = ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(inputShape->at(e)), shape::order(inputShape->at(e)), shape::rank(inputShape->at(e)), shape::shapeOf(inputShape->at(e))); \ shapeList->push_back(newshape); \ } \ return shapeList; \ @@ -1343,14 +1343,14 @@ #define DECLARE_SYN(NAME, ORIGINAL) template \ struct __registratorSynonym_##NAME {\ __registratorSynonym_##NAME(const char *name, const char *oname) {\ - auto ptr = reinterpret_cast(OpRegistrator::getInstance()->getOperation(oname)); \ + auto ptr = reinterpret_cast(OpRegistrator::getInstance().getOperation(oname)); \ if (ptr == nullptr) { \ std::string newName(name); \ std::string oldName(oname); \ - OpRegistrator::getInstance()->updateMSVC(sd::ops::HashHelper::getInstance()->getLongHash(newName), oldName);\ + OpRegistrator::getInstance().updateMSVC(sd::ops::HashHelper::getInstance().getLongHash(newName), oldName);\ return;\ }\ - OpRegistrator::getInstance()->registerOperation(name, ptr);\ + OpRegistrator::getInstance().registerOperation(name, ptr);\ }\ };\ static sd::ops::__registratorSynonym_##NAME zzz_register_opd_##NAME(#NAME, #ORIGINAL) @@ -1394,7 +1394,7 @@ auto shapeList = SHAPELIST(); \ auto opLimit = this->getOpDescriptor()->getNumberOfOutputs() < 1 ? block.width() : this->getOpDescriptor()->getNumberOfOutputs(); \ for (int e = 0; e < opLimit; e++) { \ - auto newshape = ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(inputShape->at(e)), shape::order(inputShape->at(e)), shape::rank(inputShape->at(e)), shape::shapeOf(inputShape->at(e))); \ + auto newshape = ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(inputShape->at(e)), shape::order(inputShape->at(e)), shape::rank(inputShape->at(e)), shape::shapeOf(inputShape->at(e))); \ shapeList->push_back(newshape); \ } \ return shapeList; \ @@ -1484,8 +1484,8 @@ #else // we intentionally add 8 tail bytes here to avoid problems with atomic operations -#define ALLOCATE_SPECIAL(VARIABLE, WORKSPACE, LENGTH, TT) if (WORKSPACE == nullptr) {auto erc_##VARIABLE = cudaMalloc(reinterpret_cast(&VARIABLE), LENGTH * sizeof(TT) + 8); if (erc_##VARIABLE != 0) {throw cuda_exception::build("[DEVICE] allocation failed", erc_##VARIABLE);} else { sd::memory::MemoryTracker::getInstance()->countIn(sd::memory::MemoryType::DEVICE, VARIABLE, LENGTH * sizeof(TT)); }; } else {VARIABLE = reinterpret_cast(WORKSPACE->allocateBytes(sd::memory::MemoryType::DEVICE, LENGTH * sizeof(TT) + 8)); } -#define RELEASE_SPECIAL(VARIABLE, WORKSPACE) if (VARIABLE != nullptr) {if (WORKSPACE == nullptr) { sd::memory::MemoryTracker::getInstance()->countOut(VARIABLE); auto erc_##VARIABLE = cudaFree(reinterpret_cast(VARIABLE)); if (erc_##VARIABLE != 0) {throw cuda_exception::build("[DEVICE] deallocation failed", erc_##VARIABLE);}; }; }; +#define ALLOCATE_SPECIAL(VARIABLE, WORKSPACE, LENGTH, TT) if (WORKSPACE == nullptr) {auto erc_##VARIABLE = cudaMalloc(reinterpret_cast(&VARIABLE), LENGTH * sizeof(TT) + 8); if (erc_##VARIABLE != 0) {throw cuda_exception::build("[DEVICE] allocation failed", erc_##VARIABLE);} else { sd::memory::MemoryTracker::getInstance().countIn(sd::memory::MemoryType::DEVICE, VARIABLE, LENGTH * sizeof(TT)); }; } else {VARIABLE = reinterpret_cast(WORKSPACE->allocateBytes(sd::memory::MemoryType::DEVICE, LENGTH * sizeof(TT) + 8)); } +#define RELEASE_SPECIAL(VARIABLE, WORKSPACE) if (VARIABLE != nullptr) {if (WORKSPACE == nullptr) { sd::memory::MemoryTracker::getInstance().countOut(VARIABLE); auto erc_##VARIABLE = cudaFree(reinterpret_cast(VARIABLE)); if (erc_##VARIABLE != 0) {throw cuda_exception::build("[DEVICE] deallocation failed", erc_##VARIABLE);}; }; }; #endif @@ -1503,12 +1503,12 @@ #else -#define ALLOCATE(VARIABLE, WORKSPACE, LENGTH, TT) if (WORKSPACE == nullptr) {VARIABLE = new TT[LENGTH]; sd::memory::MemoryTracker::getInstance()->countIn(sd::memory::MemoryType::HOST, VARIABLE, LENGTH * sizeof(TT)); } else {VARIABLE = reinterpret_cast(WORKSPACE->allocateBytes(LENGTH * sizeof(TT))); }; memset(VARIABLE, 0, LENGTH * sizeof(TT)); -#define RELEASE(VARIABLE, WORKSPACE) if (WORKSPACE == nullptr) { sd::memory::MemoryTracker::getInstance()->countOut(VARIABLE); delete[] VARIABLE;}; +#define ALLOCATE(VARIABLE, WORKSPACE, LENGTH, TT) if (WORKSPACE == nullptr) {VARIABLE = new TT[LENGTH]; sd::memory::MemoryTracker::getInstance().countIn(sd::memory::MemoryType::HOST, VARIABLE, LENGTH * sizeof(TT)); } else {VARIABLE = reinterpret_cast(WORKSPACE->allocateBytes(LENGTH * sizeof(TT))); }; memset(VARIABLE, 0, LENGTH * sizeof(TT)); +#define RELEASE(VARIABLE, WORKSPACE) if (WORKSPACE == nullptr) { sd::memory::MemoryTracker::getInstance().countOut(VARIABLE); delete[] VARIABLE;}; #endif -#define CONSTANT(SHAPE) ConstantShapeHelper::getInstance()->createFromExisting(SHAPE, block.workspace()) +#define CONSTANT(SHAPE) ConstantShapeHelper::getInstance().createFromExisting(SHAPE, block.workspace()) diff --git a/libnd4j/include/system/platform_boilerplate.h b/libnd4j/include/system/platform_boilerplate.h index bdbb1a051..b74a0530f 100644 --- a/libnd4j/include/system/platform_boilerplate.h +++ b/libnd4j/include/system/platform_boilerplate.h @@ -40,7 +40,7 @@ #define PLATFORM_IMPL_F(NAME, ENGINE, CNAME) struct ND4J_EXPORT __registratorPlatformHelper_##CNAME { \ __registratorPlatformHelper_##CNAME() { \ auto helper = new PLATFORM_##CNAME(); \ - OpRegistrator::getInstance()->registerHelper(helper); \ + OpRegistrator::getInstance().registerHelper(helper); \ } \ }; \ static __registratorPlatformHelper_##CNAME platformHelper_##CNAME; \ diff --git a/libnd4j/minifier/minifier.cpp b/libnd4j/minifier/minifier.cpp index 7846c1846..043f2b696 100644 --- a/libnd4j/minifier/minifier.cpp +++ b/libnd4j/minifier/minifier.cpp @@ -92,7 +92,7 @@ main(int argc, char *argv[]) { arch_arg = opt.arch(); std::vector descriptors; - nd4j_printf("Total available operations: %i\n", OpRegistrator::getInstance()->numberOfOperations()); + nd4j_printf("Total available operations: %i\n", OpRegistrator::getInstance().numberOfOperations()); for (auto file: opt.files()) { // all files will be checked for accessibility & size diff --git a/libnd4j/server/GraphServer.cpp b/libnd4j/server/GraphServer.cpp index a9e8c3ddc..b7615dd5c 100644 --- a/libnd4j/server/GraphServer.cpp +++ b/libnd4j/server/GraphServer.cpp @@ -43,7 +43,7 @@ namespace sd { auto graph = new Graph(flat_graph); // single data type for now - GraphHolder::getInstance()->registerGraph(flat_graph->id(), graph); + GraphHolder::getInstance().registerGraph(flat_graph->id(), graph); // sending out OK response auto response_offset = CreateFlatResponse(mb_, 0); @@ -66,7 +66,7 @@ namespace sd { auto graph = new Graph(flat_graph); // single data type for now - GraphHolder::getInstance()->replaceGraph(flat_graph->id(), graph); + GraphHolder::getInstance().replaceGraph(flat_graph->id(), graph); // sending out OK response auto response_offset = CreateFlatResponse(mb_, 0); @@ -91,7 +91,7 @@ namespace sd { auto request = request_msg->GetRoot(); // dropping out graph (any datatype) - GraphHolder::getInstance()->dropGraphAny(request->id()); + GraphHolder::getInstance().dropGraphAny(request->id()); // sending out OK response auto response_offset = CreateFlatResponse(mb_, 0); @@ -111,7 +111,7 @@ namespace sd { try { // GraphHolder - auto response_offset = GraphHolder::getInstance()->execute(request->id(), mb_, request); + auto response_offset = GraphHolder::getInstance().execute(request->id(), mb_, request); mb_.Finish(response_offset); *response_msg = mb_.ReleaseMessage(); @@ -181,7 +181,7 @@ int main(int argc, char *argv[]) { if(cmdOptionExists(argv, argv+argc, "-f")) { auto file = getCmdOption(argv, argv + argc, "-f"); auto graph = GraphExecutioner::importFromFlatBuffers(file); - sd::graph::GraphHolder::getInstance()->registerGraph(0L, graph); + sd::graph::GraphHolder::getInstance().registerGraph(0L, graph); } RunServer(port); diff --git a/libnd4j/tests_cpu/layers_tests/ConditionalTests.cpp b/libnd4j/tests_cpu/layers_tests/ConditionalTests.cpp index 00752ca0f..5167abcd1 100644 --- a/libnd4j/tests_cpu/layers_tests/ConditionalTests.cpp +++ b/libnd4j/tests_cpu/layers_tests/ConditionalTests.cpp @@ -30,13 +30,13 @@ using namespace sd::graph; class ConditionalTests : public testing::Test { public: ConditionalTests(){ - //Environment::getInstance()->setVerbose(true); - //Environment::getInstance()->setDebug(true); + //Environment::getInstance().setVerbose(true); + //Environment::getInstance().setDebug(true); } ~ConditionalTests(){ - //Environment::getInstance()->setVerbose(false); - //Environment::getInstance()->setDebug(false); + //Environment::getInstance().setVerbose(false); + //Environment::getInstance().setDebug(false); } }; @@ -139,8 +139,8 @@ TEST_F(ConditionalTests, Flat_Test_1) { * Condition is True */ TEST_F(ConditionalTests, Flat_Test_2) { - Environment::getInstance()->setDebug(true); - Environment::getInstance()->setVerbose(true); + Environment::getInstance().setDebug(true); + Environment::getInstance().setVerbose(true); sd::ops::identity op0; auto graph = GraphExecutioner::importFromFlatBuffers("./resources/simpleif_0.fb"); diff --git a/libnd4j/tests_cpu/layers_tests/ConstantShapeHelperTests.cpp b/libnd4j/tests_cpu/layers_tests/ConstantShapeHelperTests.cpp index 5b747ab5b..a9a42ac88 100644 --- a/libnd4j/tests_cpu/layers_tests/ConstantShapeHelperTests.cpp +++ b/libnd4j/tests_cpu/layers_tests/ConstantShapeHelperTests.cpp @@ -45,15 +45,15 @@ public: }; TEST_F(ConstantShapeHelperTests, test_cachedAmount_1) { - auto ttlBefore = ConstantShapeHelper::getInstance()->totalCachedEntries(); + auto ttlBefore = ConstantShapeHelper::getInstance().totalCachedEntries(); auto arrayA = NDArrayFactory::create('c', {7, 11, 17, 23, 31, 43}); - auto ttlMiddle = ConstantShapeHelper::getInstance()->totalCachedEntries(); + auto ttlMiddle = ConstantShapeHelper::getInstance().totalCachedEntries(); auto arrayB = NDArrayFactory::create('c', {7, 11, 17, 23, 31, 43}); - auto ttlAfter = ConstantShapeHelper::getInstance()->totalCachedEntries(); + auto ttlAfter = ConstantShapeHelper::getInstance().totalCachedEntries(); ASSERT_TRUE(ttlBefore <= ttlMiddle); ASSERT_EQ(ttlMiddle, ttlAfter); @@ -61,15 +61,15 @@ TEST_F(ConstantShapeHelperTests, test_cachedAmount_1) { TEST_F(ConstantTadHelperTests, test_cachedAmount_1) { auto arrayA = NDArrayFactory::create('c', {7, 11, 17, 23, 31, 43}); - auto ttlBefore = ConstantTadHelper::getInstance()->totalCachedEntries(); + auto ttlBefore = ConstantTadHelper::getInstance().totalCachedEntries(); - auto packAA = ConstantTadHelper::getInstance()->tadForDimensions(arrayA.shapeInfo(), {3, 4}); + auto packAA = ConstantTadHelper::getInstance().tadForDimensions(arrayA.shapeInfo(), {3, 4}); - auto ttlMiddle = ConstantTadHelper::getInstance()->totalCachedEntries(); + auto ttlMiddle = ConstantTadHelper::getInstance().totalCachedEntries(); - auto packAB = ConstantTadHelper::getInstance()->tadForDimensions(arrayA.shapeInfo(), {3, 4}); + auto packAB = ConstantTadHelper::getInstance().tadForDimensions(arrayA.shapeInfo(), {3, 4}); - auto ttlAfter = ConstantTadHelper::getInstance()->totalCachedEntries(); + auto ttlAfter = ConstantTadHelper::getInstance().totalCachedEntries(); ASSERT_TRUE(ttlBefore <= ttlMiddle); ASSERT_EQ(ttlMiddle, ttlAfter); @@ -88,13 +88,13 @@ TEST_F(ConstantShapeHelperTests, basic_test_1) { ASSERT_EQ(sd::DataType::BFLOAT16, descriptor.dataType()); ASSERT_FALSE(descriptor.isEmpty()); - ASSERT_FALSE(ConstantShapeHelper::getInstance()->checkBufferExistenceForShapeInfo(descriptor)); + ASSERT_FALSE(ConstantShapeHelper::getInstance().checkBufferExistenceForShapeInfo(descriptor)); - auto buffer = ConstantShapeHelper::getInstance()->bufferForShapeInfo(descriptor); + auto buffer = ConstantShapeHelper::getInstance().bufferForShapeInfo(descriptor); - ASSERT_TRUE(ConstantShapeHelper::getInstance()->checkBufferExistenceForShapeInfo(descriptor)); + ASSERT_TRUE(ConstantShapeHelper::getInstance().checkBufferExistenceForShapeInfo(descriptor)); - auto buffer2 = ConstantShapeHelper::getInstance()->bufferForShapeInfo(descriptor2); + auto buffer2 = ConstantShapeHelper::getInstance().bufferForShapeInfo(descriptor2); ASSERT_TRUE(buffer.primary() != nullptr); @@ -109,14 +109,14 @@ TEST_F(ConstantShapeHelperTests, stress_test_1) { for (auto x = 0; x < 1000; x++) { auto ptr = ShapeBuilders::createShapeInfo(sd::DataType::FLOAT32, 'c', {5, x + 10, x + 1}); ShapeDescriptor descriptor(ptr); - ConstantShapeHelper::getInstance()->createShapeInfo(descriptor); + ConstantShapeHelper::getInstance().createShapeInfo(descriptor); delete [] ptr; } ShapeDescriptor aShape(sd::DataType::FLOAT32, 'c', {(Nd4jLong)5, (Nd4jLong)382, (Nd4jLong)373}); -// nd4j_printf("%d\n", ConstantShapeHelper::getInstance()->cachedEntriesForDevice(0)); +// nd4j_printf("%d\n", ConstantShapeHelper::getInstance().cachedEntriesForDevice(0)); auto timeStart = std::chrono::system_clock::now(); - ASSERT_TRUE(ConstantShapeHelper::getInstance()->checkBufferExistenceForShapeInfo(aShape)); + ASSERT_TRUE(ConstantShapeHelper::getInstance().checkBufferExistenceForShapeInfo(aShape)); auto timeEnd = std::chrono::system_clock::now(); auto outerTime = std::chrono::duration_cast(timeEnd - timeStart).count(); @@ -146,7 +146,7 @@ TEST_F(ConstantShapeHelperTests, basic_test_4) { #ifdef __CUDABLAS__ ASSERT_TRUE(dup->specialShapeInfo() != nullptr); PointersManager manager(sd::LaunchContext ::defaultContext(), "test"); - // manager.printDevContentOnDev(dup->specialShapeInfo(), shape::shapeInfoLength(2), 0); + // manager.printDevContentOnDev(dup->special(), shape::shapeInfoLength(2), 0); #endif delete array; @@ -195,14 +195,14 @@ TEST_F(ConstantHelperTests, basic_test_1) { ConstantDescriptor descriptor({1, 2, 3}); - ConstantDataBuffer* fBuffer = ConstantHelper::getInstance()->constantBuffer(descriptor, sd::DataType::FLOAT32); + ConstantDataBuffer* fBuffer = ConstantHelper::getInstance().constantBuffer(descriptor, sd::DataType::FLOAT32); auto fPtr = fBuffer->primaryAsT(); ASSERT_NEAR(1.f, fPtr[0], 1e-5); ASSERT_NEAR(2.f, fPtr[1], 1e-5); ASSERT_NEAR(3.f, fPtr[2], 1e-5); - auto iBuffer = ConstantHelper::getInstance()->constantBuffer(descriptor, sd::DataType::INT32); + auto iBuffer = ConstantHelper::getInstance().constantBuffer(descriptor, sd::DataType::INT32); auto iPtr = iBuffer->primaryAsT(); ASSERT_EQ(1, iPtr[0]); @@ -215,14 +215,14 @@ TEST_F(ConstantHelperTests, basic_test_2) { double array[] = {1., 2., 3.}; ConstantDescriptor descriptor(array, 3); - ConstantDataBuffer* fBuffer = ConstantHelper::getInstance()->constantBuffer(descriptor, sd::DataType::FLOAT32); + ConstantDataBuffer* fBuffer = ConstantHelper::getInstance().constantBuffer(descriptor, sd::DataType::FLOAT32); auto fPtr = fBuffer->primaryAsT(); ASSERT_NEAR(1.f, fPtr[0], 1e-5); ASSERT_NEAR(2.f, fPtr[1], 1e-5); ASSERT_NEAR(3.f, fPtr[2], 1e-5); - auto iBuffer = ConstantHelper::getInstance()->constantBuffer(descriptor, sd::DataType::INT32); + auto iBuffer = ConstantHelper::getInstance().constantBuffer(descriptor, sd::DataType::INT32); auto iPtr = iBuffer->primaryAsT(); ASSERT_EQ(1, iPtr[0]); diff --git a/libnd4j/tests_cpu/layers_tests/ConvolutionTests1.cpp b/libnd4j/tests_cpu/layers_tests/ConvolutionTests1.cpp index 4438e5fe6..b87985458 100644 --- a/libnd4j/tests_cpu/layers_tests/ConvolutionTests1.cpp +++ b/libnd4j/tests_cpu/layers_tests/ConvolutionTests1.cpp @@ -2013,7 +2013,6 @@ TYPED_TEST(TypedConvolutionTests1, conv3d_test9) { ASSERT_TRUE(exp.isSameShape(z)); - shapes->destroy(); delete shapes; } diff --git a/libnd4j/tests_cpu/layers_tests/CudaBasicsTests1.cu b/libnd4j/tests_cpu/layers_tests/CudaBasicsTests1.cu index cbcbe2c15..d8ed2a264 100644 --- a/libnd4j/tests_cpu/layers_tests/CudaBasicsTests1.cu +++ b/libnd4j/tests_cpu/layers_tests/CudaBasicsTests1.cu @@ -254,7 +254,7 @@ TEST_F(CudaBasicsTests1, execIndexReduceScalar_1) { //////////////////////////////////////////////////////////////////////////// TEST_F(CudaBasicsTests1, execReduce3Scalar_1) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray x1('c', {2,2}, {1,2,3,4}, sd::DataType::INT32); @@ -970,7 +970,7 @@ TEST_F(CudaBasicsTests1, execIndexReduce_3) { //////////////////////////////////////////////////////////////////////////// TEST_F(CudaBasicsTests1, execScalar_1) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray x('c', {2,3}, {0,1,2,3,4,5}, sd::DataType::INT64); @@ -1005,7 +1005,7 @@ TEST_F(CudaBasicsTests1, execScalar_1) { //////////////////////////////////////////////////////////////////////////// TEST_F(CudaBasicsTests1, execScalar_2) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray x('c', {2,3}, {-1,-2,-3,-4,-5,-6}, sd::DataType::INT64); @@ -1041,7 +1041,7 @@ TEST_F(CudaBasicsTests1, execScalar_2) { //////////////////////////////////////////////////////////////////////////// TEST_F(CudaBasicsTests1, execScalar_3) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray x('c', {2,3,2}, {0,1,2,3,4,5,6,7,8,9,10,11}, sd::DataType::INT64); @@ -1192,7 +1192,7 @@ TEST_F(CudaBasicsTests1, execScalarBool_2) { //////////////////////////////////////////////////////////////////////////// TEST_F(CudaBasicsTests1, execBroadcast_1) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray x('c', {2,3,4}, {100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100}, sd::DataType::INT32); @@ -1252,7 +1252,7 @@ TEST_F(CudaBasicsTests1, execBroadcast_1) { //////////////////////////////////////////////////////////////////////////// TEST_F(CudaBasicsTests1, execBroadcast_2) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray x('c', {2,3,4}, {100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100}, sd::DataType::INT32); @@ -1429,7 +1429,7 @@ TEST_F(CudaBasicsTests1, execBroadcastBool_2) { //////////////////////////////////////////////////////////////////////////// TEST_F(CudaBasicsTests1, execPairwiseTransform_1) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray x('c', {2,2,2}, {1,5,3,7,2,6,4,8}, sd::DataType::INT32); @@ -2544,7 +2544,7 @@ TEST_F(CudaBasicsTests1, execReduce3TAD_1) { NDArray z('c', {3}, {100,100,100}, sd::DataType::DOUBLE); std::vector dimensions = {0,1}; - auto packX = ConstantTadHelper::getInstance()->tadForDimensions(x.shapeInfo(), dimensions); + auto packX = ConstantTadHelper::getInstance().tadForDimensions(x.shapeInfo(), dimensions); LaunchContext* context = x.getContext(); x.syncToDevice(); @@ -2858,7 +2858,7 @@ TEST_F(CudaBasicsTests1, execSummaryStats_3) { NativeOpExecutioner::execSummaryStats(&lc, sd::variance::SummaryStatsStandardDeviation, nullptr, x.shapeInfo(), x.specialBuffer(), x.specialShapeInfo(), nullptr, - nullptr, z.shapeInfo(), z.specialBuffer(), z.specialShapeInfo(), + nullptr, z.shapeInfo(), z.specialBuffer(), z.special(), (int*)devicePtrs[0], dimensions.size(), (Nd4jLong*)devicePtrs[1], (Nd4jLong*)devicePtrs[2], true); @@ -2941,13 +2941,13 @@ TEST_F(CudaBasicsTests1, execRandom_1) { // cudaResult = cudaStreamCreate(&stream); ASSERT_EQ(0, cudaResult); // LaunchContext lc(&stream); // -// // ::execRandom(extraPointers, random::GaussianDistribution, &gen, z.buffer(), z.shapeInfo(), z.specialBuffer(), z.specialShapeInfo(), &extra); +// // ::execRandom(extraPointers, random::GaussianDistribution, &gen, z.buffer(), z.shapeInfo(), z.specialBuffer(), z.special(), &extra); // // call cuda kernel which calculates result // NativeOpExecutioner::execRandom(&lc, sd::random::GaussianDistribution, // &gen, -// nullptr, z.shapeInfo(), z.specialBuffer(), z.specialShapeInfo(), -// nullptr, z.shapeInfo(), z.specialBuffer(), z.specialShapeInfo(), -// nullptr, z.shapeInfo(), z.specialBuffer(), z.specialShapeInfo(), +// nullptr, z.shapeInfo(), z.specialBuffer(), z.special(), +// nullptr, z.shapeInfo(), z.specialBuffer(), z.special(), +// nullptr, z.shapeInfo(), z.specialBuffer(), z.special(), // extraArguments.argumentsAsT(z.dataType())); // // cudaResult = cudaStreamSynchronize(stream); ASSERT_EQ(0, cudaResult); diff --git a/libnd4j/tests_cpu/layers_tests/CudaBasicsTests2.cu b/libnd4j/tests_cpu/layers_tests/CudaBasicsTests2.cu index b425ffcbb..28102cad5 100644 --- a/libnd4j/tests_cpu/layers_tests/CudaBasicsTests2.cu +++ b/libnd4j/tests_cpu/layers_tests/CudaBasicsTests2.cu @@ -40,7 +40,7 @@ public: }; TEST_F(CudaBasicsTests2, test_devices_1) { - auto caps = Environment::getInstance()->capabilities(); + auto caps = Environment::getInstance().capabilities(); ASSERT_FALSE(caps.empty()); } @@ -259,7 +259,7 @@ TEST_F(CudaBasicsTests2, mmulMxM_12) { int devCnt = 0; cudaGetDevice(&devCnt); - if(Environment::getInstance()->capabilities()[devCnt].first() < 5) return; + if(Environment::getInstance().capabilities()[devCnt].first() < 5) return; const Nd4jLong M = 4; const Nd4jLong K = 4; @@ -282,7 +282,7 @@ TEST_F(CudaBasicsTests2, mmulMxM_13) { int devCnt = 0; cudaGetDevice(&devCnt); - if(Environment::getInstance()->capabilities()[devCnt].first() < 5) return; + if(Environment::getInstance().capabilities()[devCnt].first() < 5) return; const Nd4jLong M = 3; const Nd4jLong K = 4; @@ -304,7 +304,7 @@ TEST_F(CudaBasicsTests2, mmulMxM_14) { int devCnt = 0; cudaGetDevice(&devCnt); - if(Environment::getInstance()->capabilities()[devCnt].first() < 5) return; + if(Environment::getInstance().capabilities()[devCnt].first() < 5) return; const Nd4jLong M = 3; const Nd4jLong K = 4; @@ -326,7 +326,7 @@ TEST_F(CudaBasicsTests2, mmulMxM_15) { int devCnt = 0; cudaGetDevice(&devCnt); - if(Environment::getInstance()->capabilities()[devCnt].first() < 5) return; + if(Environment::getInstance().capabilities()[devCnt].first() < 5) return; const Nd4jLong M = 3; const Nd4jLong K = 4; @@ -349,7 +349,7 @@ TEST_F(CudaBasicsTests2, mmulMxM_16) { int devCnt = 0; cudaGetDevice(&devCnt); - if(Environment::getInstance()->capabilities()[devCnt].first() < 5) return; + if(Environment::getInstance().capabilities()[devCnt].first() < 5) return; const Nd4jLong M = 3; const Nd4jLong K = 4; @@ -371,7 +371,7 @@ TEST_F(CudaBasicsTests2, mmulMxM_17) { int devCnt = 0; cudaGetDevice(&devCnt); - if(Environment::getInstance()->capabilities()[devCnt].first() < 5) return; + if(Environment::getInstance().capabilities()[devCnt].first() < 5) return; const Nd4jLong M = 3; const Nd4jLong K = 4; @@ -393,7 +393,7 @@ TEST_F(CudaBasicsTests2, mmulMxM_18) { int devCnt = 0; cudaGetDevice(&devCnt); - if(Environment::getInstance()->capabilities()[devCnt].first() < 5.3) return; + if(Environment::getInstance().capabilities()[devCnt].first() < 5.3) return; const Nd4jLong M = 3; const Nd4jLong K = 4; @@ -415,7 +415,7 @@ TEST_F(CudaBasicsTests2, mmulMxM_19) { int devCnt = 0; cudaGetDevice(&devCnt); - if(Environment::getInstance()->capabilities()[devCnt].first() < 5.3) return; + if(Environment::getInstance().capabilities()[devCnt].first() < 5.3) return; const Nd4jLong M = 3; const Nd4jLong K = 4; @@ -437,7 +437,7 @@ TEST_F(CudaBasicsTests2, mmulMxM_20) { int devCnt = 0; cudaGetDevice(&devCnt); - if(Environment::getInstance()->capabilities()[devCnt].first() < 5.3) return; + if(Environment::getInstance().capabilities()[devCnt].first() < 5.3) return; const Nd4jLong M = 3; const Nd4jLong K = 4; diff --git a/libnd4j/tests_cpu/layers_tests/DataBufferTests.cpp b/libnd4j/tests_cpu/layers_tests/DataBufferTests.cpp index 42ab543b1..b22f9e765 100644 --- a/libnd4j/tests_cpu/layers_tests/DataBufferTests.cpp +++ b/libnd4j/tests_cpu/layers_tests/DataBufferTests.cpp @@ -39,31 +39,31 @@ public: }; TEST_F(DataBufferTests, test_alloc_limit_1) { - if (!Environment::getInstance()->isCPU()) + if (!Environment::getInstance().isCPU()) return; auto deviceId = AffinityManager::currentDeviceId(); - auto odLimit = MemoryCounter::getInstance()->deviceLimit(deviceId); - auto ogLimit = MemoryCounter::getInstance()->groupLimit(MemoryType::HOST); - auto odUse = MemoryCounter::getInstance()->allocatedDevice(deviceId); - auto ogUse = MemoryCounter::getInstance()->allocatedGroup(MemoryType::HOST); + auto odLimit = MemoryCounter::getInstance().deviceLimit(deviceId); + auto ogLimit = MemoryCounter::getInstance().groupLimit(MemoryType::HOST); + auto odUse = MemoryCounter::getInstance().allocatedDevice(deviceId); + auto ogUse = MemoryCounter::getInstance().allocatedGroup(MemoryType::HOST); auto limitSize = odUse + (150 * 1024 * 1024); auto allocSize = 100000000; - MemoryCounter::getInstance()->setDeviceLimit(deviceId, odLimit + limitSize); - MemoryCounter::getInstance()->setGroupLimit(MemoryType::HOST, odLimit + limitSize); + MemoryCounter::getInstance().setDeviceLimit(deviceId, odLimit + limitSize); + MemoryCounter::getInstance().setGroupLimit(MemoryType::HOST, odLimit + limitSize); DataBuffer buffer(allocSize, DataType::INT32); // separately testing per-device limits and group limits - ASSERT_EQ(odUse + allocSize, MemoryCounter::getInstance()->allocatedDevice(deviceId)); - ASSERT_EQ(ogUse + allocSize, MemoryCounter::getInstance()->allocatedGroup(MemoryType::HOST)); + ASSERT_EQ(odUse + allocSize, MemoryCounter::getInstance().allocatedDevice(deviceId)); + ASSERT_EQ(ogUse + allocSize, MemoryCounter::getInstance().allocatedGroup(MemoryType::HOST)); // setting smaller limits, to make sure next allocation fails with OOM exception - MemoryCounter::getInstance()->setDeviceLimit(deviceId, allocSize - 100); - MemoryCounter::getInstance()->setGroupLimit(MemoryType::HOST, allocSize - 100); + MemoryCounter::getInstance().setDeviceLimit(deviceId, allocSize - 100); + MemoryCounter::getInstance().setGroupLimit(MemoryType::HOST, allocSize - 100); try { DataBuffer bufferFailed(allocSize, DataType::INT32); @@ -73,6 +73,6 @@ TEST_F(DataBufferTests, test_alloc_limit_1) { } // restore original limits, so subsequent tests do not fail - MemoryCounter::getInstance()->setDeviceLimit(deviceId, odLimit); - MemoryCounter::getInstance()->setGroupLimit(MemoryType::HOST, odLimit); + MemoryCounter::getInstance().setDeviceLimit(deviceId, odLimit); + MemoryCounter::getInstance().setGroupLimit(MemoryType::HOST, odLimit); } \ No newline at end of file diff --git a/libnd4j/tests_cpu/layers_tests/DataBufferTestsCuda.cu b/libnd4j/tests_cpu/layers_tests/DataBufferTestsCuda.cu index 730ade824..6f7d38ede 100644 --- a/libnd4j/tests_cpu/layers_tests/DataBufferTestsCuda.cu +++ b/libnd4j/tests_cpu/layers_tests/DataBufferTestsCuda.cu @@ -42,33 +42,33 @@ public: TEST_F(DataBufferTestsCuda, test_alloc_limit_1) { auto deviceId = AffinityManager::currentDeviceId(); - auto odLimit = MemoryCounter::getInstance()->deviceLimit(deviceId); + auto odLimit = MemoryCounter::getInstance().deviceLimit(deviceId); - auto opLimit = MemoryCounter::getInstance()->groupLimit(MemoryType::HOST); - auto osLimit = MemoryCounter::getInstance()->groupLimit(MemoryType::DEVICE); + auto opLimit = MemoryCounter::getInstance().groupLimit(MemoryType::HOST); + auto osLimit = MemoryCounter::getInstance().groupLimit(MemoryType::DEVICE); - auto odUse = MemoryCounter::getInstance()->allocatedDevice(deviceId); + auto odUse = MemoryCounter::getInstance().allocatedDevice(deviceId); - auto opUse = MemoryCounter::getInstance()->allocatedGroup(MemoryType::HOST); - auto osUse = MemoryCounter::getInstance()->allocatedGroup(MemoryType::DEVICE); + auto opUse = MemoryCounter::getInstance().allocatedGroup(MemoryType::HOST); + auto osUse = MemoryCounter::getInstance().allocatedGroup(MemoryType::DEVICE); auto limitSize = odUse + 150000000; auto allocSize = 100000000; - MemoryCounter::getInstance()->setDeviceLimit(deviceId, odLimit + limitSize); - MemoryCounter::getInstance()->setGroupLimit(MemoryType::HOST, opLimit + limitSize); - MemoryCounter::getInstance()->setGroupLimit(MemoryType::DEVICE, osLimit + limitSize); + MemoryCounter::getInstance().setDeviceLimit(deviceId, odLimit + limitSize); + MemoryCounter::getInstance().setGroupLimit(MemoryType::HOST, opLimit + limitSize); + MemoryCounter::getInstance().setGroupLimit(MemoryType::DEVICE, osLimit + limitSize); DataBuffer buffer(allocSize, DataType::INT32, nullptr, true); // separately testing per-device limits and group limits - ASSERT_EQ(odUse + allocSize, MemoryCounter::getInstance()->allocatedDevice(deviceId)); - ASSERT_EQ(opUse + allocSize, MemoryCounter::getInstance()->allocatedGroup(MemoryType::HOST)); - ASSERT_EQ(osUse + allocSize, MemoryCounter::getInstance()->allocatedGroup(MemoryType::DEVICE)); + ASSERT_EQ(odUse + allocSize, MemoryCounter::getInstance().allocatedDevice(deviceId)); + ASSERT_EQ(opUse + allocSize, MemoryCounter::getInstance().allocatedGroup(MemoryType::HOST)); + ASSERT_EQ(osUse + allocSize, MemoryCounter::getInstance().allocatedGroup(MemoryType::DEVICE)); // setting smaller limits, to make sure next allocation fails with OOM exception - MemoryCounter::getInstance()->setDeviceLimit(deviceId, allocSize - 100); - MemoryCounter::getInstance()->setGroupLimit(MemoryType::DEVICE, allocSize - 100); + MemoryCounter::getInstance().setDeviceLimit(deviceId, allocSize - 100); + MemoryCounter::getInstance().setGroupLimit(MemoryType::DEVICE, allocSize - 100); // this allocation should fail, since we're allocating too much @@ -82,8 +82,8 @@ TEST_F(DataBufferTestsCuda, test_alloc_limit_1) { // // restore original limits, so subsequent tests do not fail - MemoryCounter::getInstance()->setDeviceLimit(deviceId, odLimit); - MemoryCounter::getInstance()->setGroupLimit(MemoryType::HOST, opLimit); - MemoryCounter::getInstance()->setGroupLimit(MemoryType::DEVICE, osLimit); + MemoryCounter::getInstance().setDeviceLimit(deviceId, odLimit); + MemoryCounter::getInstance().setGroupLimit(MemoryType::HOST, opLimit); + MemoryCounter::getInstance().setGroupLimit(MemoryType::DEVICE, osLimit); } */ \ No newline at end of file diff --git a/libnd4j/tests_cpu/layers_tests/DeclarableOpsTests1.cpp b/libnd4j/tests_cpu/layers_tests/DeclarableOpsTests1.cpp index 959362c4d..a5715fd01 100644 --- a/libnd4j/tests_cpu/layers_tests/DeclarableOpsTests1.cpp +++ b/libnd4j/tests_cpu/layers_tests/DeclarableOpsTests1.cpp @@ -55,11 +55,11 @@ public: const int oW = (iW - kW - (kW - 1) * (dW - 1) + 2 * pW) / sW + 1; // output width DeclarableOpsTests1() { - sd::memory::MemoryTracker::getInstance()->reset(); + sd::memory::MemoryTracker::getInstance().reset(); } ~DeclarableOpsTests1() { - sd::memory::MemoryTracker::getInstance()->summarize(); + sd::memory::MemoryTracker::getInstance().summarize(); } }; @@ -144,7 +144,7 @@ TEST_F(DeclarableOpsTests1, BasicInitialization1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, BasicInitialization2) { - auto op = sd::ops::OpRegistrator::getInstance()->getOperation("concat"); + auto op = sd::ops::OpRegistrator::getInstance().getOperation("concat"); ASSERT_TRUE(op != nullptr); std::string expName("concat"); @@ -217,19 +217,19 @@ TEST_F(DeclarableOpsTests1, AXpY_Test_1) { } TEST_F(DeclarableOpsTests1, BasicInitialization3) { - auto op1 = sd::ops::OpRegistrator::getInstance()->getOperation("concat"); + auto op1 = sd::ops::OpRegistrator::getInstance().getOperation("concat"); std::string expName("concat"); - auto hash = sd::ops::HashHelper::getInstance()->getLongHash(expName); + auto hash = sd::ops::HashHelper::getInstance().getLongHash(expName); - auto op2 = sd::ops::OpRegistrator::getInstance()->getOperation(hash); + auto op2 = sd::ops::OpRegistrator::getInstance().getOperation(hash); ASSERT_TRUE(op1 == op2); } TEST_F(DeclarableOpsTests1, SynonymInitialization2) { - auto op = sd::ops::OpRegistrator::getInstance()->getOperation("Mul"); - auto op2 = sd::ops::OpRegistrator::getInstance()->getOperation("multiply"); + auto op = sd::ops::OpRegistrator::getInstance().getOperation("Mul"); + auto op2 = sd::ops::OpRegistrator::getInstance().getOperation("multiply"); ASSERT_TRUE(op != nullptr); std::string expName("multiply"); @@ -597,7 +597,7 @@ TEST_F(DeclarableOpsTests1, TestTensorDot17) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, DivergentCheck1) { - auto op = sd::ops::OpRegistrator::getInstance()->getOperation("switch"); + auto op = sd::ops::OpRegistrator::getInstance().getOperation("switch"); ASSERT_TRUE(op != nullptr); std::string expName("Switch"); @@ -1695,7 +1695,7 @@ TEST_F(DeclarableOpsTests1, Test_Cast_1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, TestRegistrator1) { - auto res = sd::ops::OpRegistrator::getInstance()->getAllCustomOperations(); + auto res = sd::ops::OpRegistrator::getInstance().getAllCustomOperations(); } // ////////////////////////////////////////////////////////////////////// @@ -1713,7 +1713,7 @@ TEST_F(DeclarableOpsTests1, TestRegistrator1) { // z->assign(120.0f); // std::string opName("add"); -// auto hash = sd::ops::HashHelper::getInstance()->getInstance()->getLongHash(opName); +// auto hash = sd::ops::HashHelper::getInstance().getInstance()->getLongHash(opName); // auto inputBuffers = new Nd4jPointer[2]; // auto inputShapes = new Nd4jPointer[2]; @@ -1763,7 +1763,7 @@ TEST_F(DeclarableOpsTests1, TestRegistrator1) { // std::string opName("add"); -// auto hash = sd::ops::HashHelper::getInstance()->getInstance()->getLongHash(opName); +// auto hash = sd::ops::HashHelper::getInstance().getInstance()->getLongHash(opName); // auto inputBuffers = new Nd4jPointer[2]; // auto inputShapes = new Nd4jPointer[2]; diff --git a/libnd4j/tests_cpu/layers_tests/DeclarableOpsTests12.cpp b/libnd4j/tests_cpu/layers_tests/DeclarableOpsTests12.cpp index 66762f79d..9e5281afe 100644 --- a/libnd4j/tests_cpu/layers_tests/DeclarableOpsTests12.cpp +++ b/libnd4j/tests_cpu/layers_tests/DeclarableOpsTests12.cpp @@ -780,8 +780,8 @@ TEST_F(DeclarableOpsTests12, pullRows_1) { std::vector dims = {1}; - auto xTadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(x.shapeInfo(), dims); - auto zTadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(z.shapeInfo(), dims); + auto xTadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(x.shapeInfo(), dims); + auto zTadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(z.shapeInfo(), dims); Nd4jPointer nativeStart[2]; @@ -816,8 +816,8 @@ TEST_F(DeclarableOpsTests12, pullRows_2) { std::vector dims = {1}; - auto xTadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(x.shapeInfo(), dims); - auto zTadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(z.shapeInfo(), dims); + auto xTadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(x.shapeInfo(), dims); + auto zTadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(z.shapeInfo(), dims); Nd4jPointer nativeStart[2]; #ifdef __CUDABLAS__ diff --git a/libnd4j/tests_cpu/layers_tests/DeclarableOpsTests13.cpp b/libnd4j/tests_cpu/layers_tests/DeclarableOpsTests13.cpp index c7222e6f7..639d90389 100644 --- a/libnd4j/tests_cpu/layers_tests/DeclarableOpsTests13.cpp +++ b/libnd4j/tests_cpu/layers_tests/DeclarableOpsTests13.cpp @@ -2717,7 +2717,7 @@ TEST_F(DeclarableOpsTests13, batchnorm_bp_test9) { int* dims = reinterpret_cast(manager.replicatePointer(dimensions.data(), dimensions.size() * sizeof(int))); input.reduceAlongDimension(sd::reduce::Mean, mean, dimensions); NDArray::prepareSpecialUse({&variance}, {&input}); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input.shapeInfo(), dimensions); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input.shapeInfo(), dimensions); NativeOpExecutioner::execSummaryStats(input.getContext(), 0,input.buffer(), input.shapeInfo(),input.specialBuffer(), input.specialShapeInfo(),nullptr,variance.buffer(), variance.shapeInfo(),variance.specialBuffer(), variance.specialShapeInfo(), dims, dimensions.size(),packX.platformShapeInfo(), packX.platformOffsets(),false); manager.synchronize(); NDArray::registerSpecialUse({&variance}, {&input}); @@ -2768,7 +2768,7 @@ TEST_F(DeclarableOpsTests13, batchnorm_bp_test10) { int* dims = reinterpret_cast(manager.replicatePointer(dimensions.data(), dimensions.size() * sizeof(int))); input.reduceAlongDimension(sd::reduce::Mean, mean, dimensions); NDArray::prepareSpecialUse({&variance}, {&input}); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input.shapeInfo(), dimensions); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input.shapeInfo(), dimensions); NativeOpExecutioner::execSummaryStats(input.getContext(), 0,input.buffer(), input.shapeInfo(),input.specialBuffer(), input.specialShapeInfo(),nullptr,variance.buffer(), variance.shapeInfo(),variance.specialBuffer(), variance.specialShapeInfo(), dims, dimensions.size(),packX.platformShapeInfo(), packX.platformOffsets(),false); manager.synchronize(); NDArray::registerSpecialUse({&variance}, {&input}); @@ -2831,7 +2831,7 @@ TEST_F(DeclarableOpsTests13, batchnorm_bp_test11) { int* dims = reinterpret_cast(manager.replicatePointer(dimensions.data(), dimensions.size() * sizeof(int))); input.reduceAlongDimension(sd::reduce::Mean, mean, dimensions, true); NDArray::prepareSpecialUse({&variance}, {&input}); - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(input.shapeInfo(), dimensions); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(input.shapeInfo(), dimensions); NativeOpExecutioner::execSummaryStats(input.getContext(), 0,input.buffer(), input.shapeInfo(),input.specialBuffer(), input.specialShapeInfo(),nullptr,variance.buffer(), variance.shapeInfo(),variance.specialBuffer(), variance.specialShapeInfo(), dims, dimensions.size(),packX.platformShapeInfo(), packX.platformOffsets(),false); manager.synchronize(); NDArray::registerSpecialUse({&variance}, {&input}); diff --git a/libnd4j/tests_cpu/layers_tests/DeclarableOpsTests14.cpp b/libnd4j/tests_cpu/layers_tests/DeclarableOpsTests14.cpp index b4c9839ab..ef35bfa72 100644 --- a/libnd4j/tests_cpu/layers_tests/DeclarableOpsTests14.cpp +++ b/libnd4j/tests_cpu/layers_tests/DeclarableOpsTests14.cpp @@ -40,7 +40,7 @@ public: TEST_F(DeclarableOpsTests14, Test_Validation_Edge_1) { auto x = NDArrayFactory::create('c', {2}, {2, 2}); - auto exp = NDArrayFactory::create('c', {2, 2}, Environment::getInstance()->defaultFloatDataType()); + auto exp = NDArrayFactory::create('c', {2, 2}, Environment::getInstance().defaultFloatDataType()); exp.assign(4.0f); sd::ops::fill op; diff --git a/libnd4j/tests_cpu/layers_tests/DeclarableOpsTests3.cpp b/libnd4j/tests_cpu/layers_tests/DeclarableOpsTests3.cpp index 38006dd50..2a099230e 100644 --- a/libnd4j/tests_cpu/layers_tests/DeclarableOpsTests3.cpp +++ b/libnd4j/tests_cpu/layers_tests/DeclarableOpsTests3.cpp @@ -1945,7 +1945,7 @@ TEST_F(DeclarableOpsTests3, svd_test1) { ASSERT_TRUE(expS.equalsTo(s)); - if(sd::Environment::getInstance()->isCPU()) { + if(sd::Environment::getInstance().isCPU()) { ASSERT_TRUE(expU.equalsTo(u)); ASSERT_TRUE(expV.equalsTo(v)); } @@ -1981,7 +1981,7 @@ TEST_F(DeclarableOpsTests3, svd_test2) { ASSERT_TRUE(expS.equalsTo(s)); - if(sd::Environment::getInstance()->isCPU()) { + if(sd::Environment::getInstance().isCPU()) { ASSERT_TRUE(expU.equalsTo(u)); ASSERT_TRUE(expV.equalsTo(v)); } @@ -2017,7 +2017,7 @@ TEST_F(DeclarableOpsTests3, svd_test3) { ASSERT_TRUE(expS.equalsTo(s)); - if(sd::Environment::getInstance()->isCPU()) { + if(sd::Environment::getInstance().isCPU()) { ASSERT_TRUE(expU.equalsTo(u)); ASSERT_TRUE(expV.equalsTo(v)); } @@ -2053,7 +2053,7 @@ TEST_F(DeclarableOpsTests3, svd_test4) { ASSERT_TRUE(expS.equalsTo(s)); - if(sd::Environment::getInstance()->isCPU()) { + if(sd::Environment::getInstance().isCPU()) { ASSERT_TRUE(expU.equalsTo(u)); ASSERT_TRUE(expV.equalsTo(v)); } @@ -2089,7 +2089,7 @@ TEST_F(DeclarableOpsTests3, svd_test5) { ASSERT_TRUE(expS.equalsTo(s)); - if(sd::Environment::getInstance()->isCPU()) { + if(sd::Environment::getInstance().isCPU()) { ASSERT_TRUE(expU.equalsTo(u)); ASSERT_TRUE(expV.equalsTo(v)); } @@ -2143,7 +2143,7 @@ TEST_F(DeclarableOpsTests3, svd_test6) { ASSERT_TRUE(expS.equalsTo(s)); - if(sd::Environment::getInstance()->isCPU()) { + if(sd::Environment::getInstance().isCPU()) { ASSERT_TRUE(expU.equalsTo(u)); ASSERT_TRUE(expV.equalsTo(v)); } @@ -2317,7 +2317,7 @@ TEST_F(DeclarableOpsTests3, svd_test7) { // ASSERT_TRUE(expS.equalsTo(s)); - // if(sd::Environment::getInstance()->isCPU()) { + // if(sd::Environment::getInstance().isCPU()) { // ASSERT_TRUE(expU.equalsTo(u)); // ASSERT_TRUE(expV.equalsTo(v)); // } @@ -2380,7 +2380,7 @@ TEST_F(DeclarableOpsTests3, svd_test9) { ASSERT_TRUE(expS.equalsTo(s)); - if(sd::Environment::getInstance()->isCPU()) { + if(sd::Environment::getInstance().isCPU()) { ASSERT_TRUE(expU.equalsTo(u)); ASSERT_TRUE(expV.equalsTo(v)); } @@ -2438,7 +2438,7 @@ TEST_F(DeclarableOpsTests3, svd_test10) { ASSERT_TRUE(expS.equalsTo(s)); - if(sd::Environment::getInstance()->isCPU()) { + if(sd::Environment::getInstance().isCPU()) { ASSERT_TRUE(expU.equalsTo(u)); ASSERT_TRUE(expV.equalsTo(v)); } @@ -2482,7 +2482,7 @@ TEST_F(DeclarableOpsTests3, svd_test11) { ASSERT_TRUE(expS.equalsTo(s)); - if(sd::Environment::getInstance()->isCPU()) { + if(sd::Environment::getInstance().isCPU()) { ASSERT_TRUE(expU.equalsTo(u)); ASSERT_TRUE(expV.equalsTo(v)); } diff --git a/libnd4j/tests_cpu/layers_tests/DeclarableOpsTests4.cpp b/libnd4j/tests_cpu/layers_tests/DeclarableOpsTests4.cpp index 1e877ecc6..56e5e213a 100644 --- a/libnd4j/tests_cpu/layers_tests/DeclarableOpsTests4.cpp +++ b/libnd4j/tests_cpu/layers_tests/DeclarableOpsTests4.cpp @@ -641,7 +641,7 @@ TEST_F(DeclarableOpsTests4, biasadd_bp_2) { } TEST_F(DeclarableOpsTests4, biasadd_4) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; auto x = NDArrayFactory::create('c', {2, 3}); diff --git a/libnd4j/tests_cpu/layers_tests/EmptyTests.cpp b/libnd4j/tests_cpu/layers_tests/EmptyTests.cpp index 81040185d..c142fb9aa 100644 --- a/libnd4j/tests_cpu/layers_tests/EmptyTests.cpp +++ b/libnd4j/tests_cpu/layers_tests/EmptyTests.cpp @@ -216,7 +216,7 @@ TEST_F(EmptyTests, test_shaped_empty_3) { } TEST_F(EmptyTests, test_shaped_empty_4) { - const auto shape = ConstantShapeHelper::getInstance()->vectorShapeInfo(0, sd::DataType::FLOAT32); + const auto shape = ConstantShapeHelper::getInstance().vectorShapeInfo(0, sd::DataType::FLOAT32); NDArray array(shape, true, sd::LaunchContext::defaultContext()); std::vector shapeOf({0}); diff --git a/libnd4j/tests_cpu/layers_tests/ExtraArgumentsTests.cpp b/libnd4j/tests_cpu/layers_tests/ExtraArgumentsTests.cpp index 87ac750b2..aa4a72f70 100644 --- a/libnd4j/tests_cpu/layers_tests/ExtraArgumentsTests.cpp +++ b/libnd4j/tests_cpu/layers_tests/ExtraArgumentsTests.cpp @@ -34,7 +34,7 @@ public: }; TEST_F(ExtraArgumentsTests, Basic_Test_1) { - if (!Environment::getInstance()->isCPU()) + if (!Environment::getInstance().isCPU()) return; ExtraArguments args({1.0, 2.0, 3.0}); diff --git a/libnd4j/tests_cpu/layers_tests/FlatBuffersTests.cpp b/libnd4j/tests_cpu/layers_tests/FlatBuffersTests.cpp index bdb8bde68..437edb525 100644 --- a/libnd4j/tests_cpu/layers_tests/FlatBuffersTests.cpp +++ b/libnd4j/tests_cpu/layers_tests/FlatBuffersTests.cpp @@ -39,15 +39,15 @@ public: Nd4jLong *fShape = new Nd4jLong[8]{2, 2, 2, 1, 2, 8192, 1, 102}; FlatBuffersTest() { - Environment::getInstance()->setDebug(false); - Environment::getInstance()->setVerbose(false); - Environment::getInstance()->setProfiling(false); + Environment::getInstance().setDebug(false); + Environment::getInstance().setVerbose(false); + Environment::getInstance().setProfiling(false); } ~FlatBuffersTest() { - Environment::getInstance()->setDebug(false); - Environment::getInstance()->setVerbose(false); - Environment::getInstance()->setProfiling(false); + Environment::getInstance().setDebug(false); + Environment::getInstance().setVerbose(false); + Environment::getInstance().setProfiling(false); delete[] cShape; delete[] fShape; @@ -676,8 +676,8 @@ TEST_F(FlatBuffersTest, Test_Stitches) { } TEST_F(FlatBuffersTest, Test_GruDynamicMnist) { - sd::Environment::getInstance()->setDebug(false); - sd::Environment::getInstance()->setVerbose(false); + sd::Environment::getInstance().setDebug(false); + sd::Environment::getInstance().setVerbose(false); auto graph = GraphExecutioner::importFromFlatBuffers("./resources/gru_dynamic_mnist.fb"); //graph->printOut(); @@ -696,8 +696,8 @@ TEST_F(FlatBuffersTest, Test_GruDynamicMnist) { } TEST_F(FlatBuffersTest, Test_Non2D_2) { - sd::Environment::getInstance()->setDebug(false); - sd::Environment::getInstance()->setVerbose(false); + sd::Environment::getInstance().setDebug(false); + sd::Environment::getInstance().setVerbose(false); sd::ops::realdiv op0; auto graph = GraphExecutioner::importFromFlatBuffers("./resources/non2d_2.fb"); @@ -711,8 +711,8 @@ TEST_F(FlatBuffersTest, Test_Non2D_2) { TEST_F(FlatBuffersTest, Test_TensorDotMisc) { - Environment::getInstance()->setVerbose(false); - Environment::getInstance()->setDebug(false); + Environment::getInstance().setVerbose(false); + Environment::getInstance().setDebug(false); auto e = NDArrayFactory::create('c', {1, 3, 16, 20}, {4.f, 6.f, 6.f, 5.f, 6.f, 4.f, 2.f, 3.f, 5.f, 5.f, 1.f, 4.f, 6.f, 3.f, 2.f, 1.f, 5.f, 4.f, 4.f, 4.f, 4.f, 4.f, 3.f, 4.f, 2.f, 3.f, 3.f, 5.f, 3.f, 6.f, 5.f, 4.f, 4.f, 3.f, 6.f, 1.f, 2.f, 4.f, 2.f, 6.f, 4.f, 2.f, 3.f, 2.f, 3.f, 1.f, 2.f, 4.f, 3.f, 5.f, 3.f, 3.f, 5.f, 2.f, 6.f, 3.f, 4.f, 4.f, 4.f, 4.f, 6.f, 4.f, 5.f, 2.f, 5.f, 5.f, 5.f, 5.f, 2.f, 4.f, 4.f, 4.f, 5.f, 4.f, 3.f, 6.f, 3.f, 4.f, 5.f, 2.f, 5.f, 4.f, 4.f, 5.f, 4.f, 3.f, 4.f, 5.f, 5.f, 3.f, 5.f, 6.f, 6.f, 3.f, 4.f, 5.f, 7.f, 6.f, 5.f, 2.f, 4.f, 5.f, 5.f, 4.f, 5.f, 4.f, 4.f, 6.f, 3.f, 4.f, 5.f, 4.f, 6.f, 2.f, 3.f, 4.f, 3.f, 3.f, 2.f, 2.f, 3.f, 4.f, 7.f, 3.f, 5.f, 4.f, 5.f, 4.f, 4.f, 4.f, 4.f, 6.f, 2.f, 3.f, 2.f, 5.f, 5.f, 4.f, 5.f, 2.f, 2.f, 1.f, 6.f, 2.f, 2.f, 3.f, 4.f, 5.f, 5.f, 3.f, 6.f, 6.f, 4.f, 3.f, 3.f, 3.f, 3.f, 3.f, 4.f, 5.f, 4.f, 4.f, 3.f, 5.f, 2.f, 3.f, 4.f, 5.f, 3.f, 4.f, 5.f, 5.f, 8.f, 4.f, 5.f, 3.f, 3.f, 4.f, 4.f, 5.f, 4.f, 5.f, 3.f, 3.f, 7.f, 2.f, 3.f, 2.f, 6.f, 6.f, 4.f, 4.f, 3.f, 5.f, 6.f, 2.f, 4.f, 3.f, 3.f, 4.f, 5.f, 3.f, 3.f, 6.f, 5.f, 3.f, 2.f, 5.f, 4.f, 4.f, 3.f, 5.f, 5.f, 6.f, 7.f, 3.f, 4.f, 3.f, 5.f, 6.f, 7.f, 5.f, 6.f, 5.f, 7.f, 4.f, 6.f, 5.f, 5.f, 6.f, 4.f, 2.f, 5.f, 4.f, 3.f, 4.f, 1.f, 5.f, 5.f, 3.f, 2.f, 2.f, 6.f, 5.f, 5.f, 2.f, 5.f, 2.f, 4.f, 4.f, 5.f, 5.f, 4.f, 3.f, 7.f, 4.f, 5.f, 3.f, 3.f, 3.f, 2.f, 3.f, 2.f, 3.f, 3.f, 4.f, 4.f, 2.f, 4.f, 5.f, 3.f, 4.f, 5.f, 3.f, 7.f, 2.f, 1.f, 3.f, 2.f, 3.f, 2.f, 3.f, 3.f, 4.f, 3.f, 4.f, 2.f, 4.f, 4.f, 4.f, 5.f, 3.f, 5.f, 3.f, 6.f, 6.f, 5.f, 3.f, 5.f, 3.f, 4.f, 3.f, 5.f, 3.f, 5.f, 6.f, 5.f, 3.f, 4.f, 5.f, 5.f, 3.f, 3.f, 3.f, 4.f, 6.f, 4.f, 3.f, 7.f, 4.f, 4.f, 6.f, 7.f, 5.f, 5.f, 3.f, 1.f, 2.f, 5.f, 5.f, 2.f, 5.f, 7.f, 5.f, 3.f, 1.f, 4.f, 6.f, 5.f, 7.f, 5.f, 6.f, 5.f, 6.f, 4.f, 3.f, 3.f, 4.f, 3.f, 4.f, 4.f, 4.f, 4.f, 3.f, 5.f, 2.f, 4.f, 5.f, 2.f, 5.f, 5.f, 4.f, 5.f, 4.f, 5.f, 2.f, 3.f, 5.f, 3.f, 6.f, 3.f, 4.f, 5.f, 3.f, 6.f, 5.f, 5.f, 6.f, 4.f, 6.f, 7.f, 4.f, 5.f, 3.f, 5.f, 4.f, 4.f, 4.f, 2.f, 2.f, 5.f, 3.f, 5.f, 3.f, 4.f, 6.f, 3.f, 5.f, 5.f, 3.f, 5.f, 4.f, 4.f, 4.f, 5.f, 2.f, 3.f, 5.f, 4.f, 2.f, 4.f, 5.f, 4.f, 2.f, 3.f, 4.f, 4.f, 5.f, 5.f, 1.f, 4.f, 4.f, 4.f, 3.f, 4.f, 5.f, 5.f, 8.f, 4.f, 4.f, 4.f, 3.f, 6.f, 2.f, 3.f, 4.f, 4.f, 4.f, 3.f, 2.f, 3.f, 4.f, 8.f, 3.f, 5.f, 5.f, 5.f, 3.f, 3.f, 4.f, 5.f, 7.f, 3.f, 3.f, 3.f, 6.f, 6.f, 5.f, 5.f, 3.f, 4.f, 3.f, 8.f, 3.f, 4.f, 2.f, 3.f, 4.f, 4.f, 3.f, 5.f, 5.f, 3.f, 2.f, 3.f, 3.f, 3.f, 4.f, 4.f, 4.f, 6.f, 6.f, 5.f, 6.f, 4.f, 5.f, 4.f, 6.f, 4.f, 5.f, 5.f, 4.f, 7.f, 3.f, 5.f, 5.f, 3.f, 5.f, 5.f, 6.f, 4.f, 5.f, 4.f, 2.f, 7.f, 2.f, 3.f, 1.f, 4.f, 5.f, 5.f, 4.f, 4.f, 5.f, 7.f, 2.f, 3.f, 3.f, 4.f, 4.f, 5.f, 3.f, 3.f, 6.f, 6.f, 3.f, 2.f, 4.f, 3.f, 3.f, 3.f, 3.f, 4.f, 4.f, 5.f, 1.f, 2.f, 3.f, 3.f, 4.f, 5.f, 4.f, 5.f, 4.f, 5.f, 6.f, 6.f, 6.f, 6.f, 7.f, 4.f, 3.f, 4.f, 5.f, 4.f, 4.f, 2.f, 5.f, 6.f, 4.f, 2.f, 2.f, 6.f, 5.f, 5.f, 1.f, 4.f, 2.f, 3.f, 4.f, 5.f, 5.f, 4.f, 5.f, 9.f, 4.f, 6.f, 4.f, 5.f, 5.f, 3.f, 4.f, 5.f, 5.f, 5.f, 4.f, 3.f, 1.f, 3.f, 4.f, 3.f, 4.f, 4.f, 3.f, 6.f, 2.f, 3.f, 3.f, 2.f, 3.f, 3.f, 4.f, 5.f, 6.f, 5.f, 5.f, 3.f, 4.f, 5.f, 5.f, 4.f, 3.f, 4.f, 3.f, 6.f, 7.f, 6.f, 4.f, 6.f, 4.f, 3.f, 3.f, 4.f, 3.f, 5.f, 5.f, 4.f, 2.f, 3.f, 4.f, 5.f, 3.f, 4.f, 2.f, 4.f, 5.f, 3.f, 3.f, 7.f, 4.f, 2.f, 5.f, 6.f, 5.f, 5.f, 3.f, 1.f, 2.f, 4.f, 4.f, 1.f, 3.f, 6.f, 3.f, 3.f, 1.f, 4.f, 4.f, 4.f, 5.f, 3.f, 4.f, 3.f, 4.f, 2.f, 3.f, 3.f, 4.f, 3.f, 4.f, 3.f, 3.f, 4.f, 2.f, 5.f, 1.f, 3.f, 4.f, 2.f, 6.f, 4.f, 3.f, 4.f, 3.f, 3.f, 1.f, 2.f, 5.f, 2.f, 6.f, 4.f, 5.f, 6.f, 3.f, 6.f, 4.f, 4.f, 5.f, 3.f, 5.f, 6.f, 3.f, 4.f, 2.f, 4.f, 5.f, 5.f, 5.f, 2.f, 3.f, 4.f, 3.f, 5.f, 3.f, 3.f, 9.f, 6.f, 7.f, 7.f, 4.f, 4.f, 3.f, 3.f, 4.f, 4.f, 3.f, 4.f, 6.f, 5.f, 3.f, 5.f, 5.f, 5.f, 2.f, 4.f, 6.f, 7.f, 7.f, 5.f, 3.f, 4.f, 5.f, 4.f, 4.f, 5.f, 5.f, 5.f, 8.f, 4.f, 4.f, 4.f, 3.f, 5.f, 3.f, 3.f, 4.f, 4.f, 5.f, 3.f, 3.f, 2.f, 3.f, 6.f, 2.f, 5.f, 4.f, 4.f, 3.f, 3.f, 3.f, 5.f, 7.f, 2.f, 3.f, 2.f, 5.f, 5.f, 4.f, 4.f, 2.f, 2.f, 1.f, 6.f, 1.f, 2.f, 2.f, 3.f, 5.f, 4.f, 3.f, 5.f, 5.f, 3.f, 2.f, 2.f, 2.f, 2.f, 4.f, 3.f, 4.f, 4.f, 4.f, 4.f, 5.f, 2.f, 4.f, 4.f, 5.f, 2.f, 4.f, 4.f, 5.f, 9.f, 4.f, 5.f, 4.f, 3.f, 5.f, 5.f, 6.f, 4.f, 4.f, 3.f, 3.f, 6.f, 2.f, 3.f, 2.f, 5.f, 6.f, 4.f, 4.f, 3.f, 5.f, 6.f, 4.f, 5.f, 5.f, 6.f, 7.f, 4.f, 2.f, 3.f, 5.f, 4.f, 4.f, 3.f, 5.f, 5.f, 4.f, 3.f, 4.f, 5.f, 4.f, 6.f, 3.f, 4.f, 4.f, 5.f, 6.f, 6.f, 4.f, 6.f, 6.f, 6.f, 5.f, 6.f, 6.f, 7.f, 7.f, 4.f, 3.f, 4.f, 4.f, 4.f, 5.f, 2.f, 5.f, 7.f, 5.f, 2.f, 1.f, 5.f, 5.f, 4.f, 1.f, 4.f, 1.f, 3.f, 3.f, 5.f, 4.f, 4.f, 3.f, 7.f, 3.f, 6.f, 3.f, 3.f, 4.f, 1.f, 3.f, 2.f, 3.f, 3.f, 4.f, 3.f, 1.f, 3.f, 4.f, 2.f, 4.f, 4.f, 2.f, 6.f, 1.f, 2.f, 2.f, 2.f, 3.f, 2.f, 3.f, 3.f, 4.f, 4.f, 4.f, 2.f, 4.f, 4.f, 4.f, 5.f, 5.f, 5.f, 4.f, 8.f, 5.f, 5.f, 3.f, 5.f, 3.f, 3.f, 2.f, 4.f, 3.f, 5.f, 6.f, 5.f, 3.f, 4.f, 5.f, 5.f, 3.f, 4.f, 3.f, 4.f, 8.f, 6.f, 5.f, 9.f, 6.f}); diff --git a/libnd4j/tests_cpu/layers_tests/GraphHolderTests.cpp b/libnd4j/tests_cpu/layers_tests/GraphHolderTests.cpp index f1f7195e7..a50091840 100644 --- a/libnd4j/tests_cpu/layers_tests/GraphHolderTests.cpp +++ b/libnd4j/tests_cpu/layers_tests/GraphHolderTests.cpp @@ -33,13 +33,13 @@ public: TEST_F(GraphHolderTests, SimpleTests_1) { Graph graph; Nd4jLong graphId = 119; - GraphHolder::getInstance()->registerGraph(graphId, &graph); + GraphHolder::getInstance().registerGraph(graphId, &graph); - ASSERT_TRUE(GraphHolder::getInstance()->hasGraph(graphId)); + ASSERT_TRUE(GraphHolder::getInstance().hasGraph(graphId)); - GraphHolder::getInstance()->forgetGraph(graphId); + GraphHolder::getInstance().forgetGraph(graphId); - ASSERT_FALSE(GraphHolder::getInstance()->hasGraph(graphId)); + ASSERT_FALSE(GraphHolder::getInstance().hasGraph(graphId)); } @@ -47,18 +47,18 @@ TEST_F(GraphHolderTests, SimpleTests_1) { TEST_F(GraphHolderTests, SimpleTests_2) { auto graph = new Graph; Nd4jLong graphId = 117; - GraphHolder::getInstance()->registerGraph(graphId, graph); + GraphHolder::getInstance().registerGraph(graphId, graph); - ASSERT_TRUE(GraphHolder::getInstance()->hasGraph(graphId)); + ASSERT_TRUE(GraphHolder::getInstance().hasGraph(graphId)); - auto graph2 = GraphHolder::getInstance()->cloneGraph(graphId); + auto graph2 = GraphHolder::getInstance().cloneGraph(graphId); ASSERT_TRUE(graph != graph2); ASSERT_TRUE(graph2 != nullptr); - GraphHolder::getInstance()->forgetGraph(graphId); + GraphHolder::getInstance().forgetGraph(graphId); - ASSERT_FALSE(GraphHolder::getInstance()->hasGraph(graphId)); + ASSERT_FALSE(GraphHolder::getInstance().hasGraph(graphId)); delete graph; delete graph2; @@ -68,18 +68,18 @@ TEST_F(GraphHolderTests, SimpleTests_2) { TEST_F(GraphHolderTests, SimpleTests_3) { auto graph = new Graph; Nd4jLong graphId = 117; - GraphHolder::getInstance()->registerGraph(graphId, graph); + GraphHolder::getInstance().registerGraph(graphId, graph); - ASSERT_TRUE(GraphHolder::getInstance()->hasGraph(graphId)); + ASSERT_TRUE(GraphHolder::getInstance().hasGraph(graphId)); - auto graph2 = GraphHolder::getInstance()->cloneGraph(graphId); + auto graph2 = GraphHolder::getInstance().cloneGraph(graphId); ASSERT_TRUE(graph != graph2); ASSERT_TRUE(graph2 != nullptr); - GraphHolder::getInstance()->dropGraph(graphId); + GraphHolder::getInstance().dropGraph(graphId); - ASSERT_FALSE(GraphHolder::getInstance()->hasGraph(graphId)); + ASSERT_FALSE(GraphHolder::getInstance().hasGraph(graphId)); delete graph2; diff --git a/libnd4j/tests_cpu/layers_tests/GraphStateTests.cpp b/libnd4j/tests_cpu/layers_tests/GraphStateTests.cpp index 878b05712..16c1ed623 100644 --- a/libnd4j/tests_cpu/layers_tests/GraphStateTests.cpp +++ b/libnd4j/tests_cpu/layers_tests/GraphStateTests.cpp @@ -31,13 +31,13 @@ using namespace sd::graph; class GraphStateTests : public testing::Test { public: GraphStateTests() { - Environment::getInstance()->setDebug(false); - Environment::getInstance()->setVerbose(false); + Environment::getInstance().setDebug(false); + Environment::getInstance().setVerbose(false); }; ~GraphStateTests() { - Environment::getInstance()->setDebug(false); - Environment::getInstance()->setVerbose(false); + Environment::getInstance().setDebug(false); + Environment::getInstance().setVerbose(false); } }; diff --git a/libnd4j/tests_cpu/layers_tests/GraphTests.cpp b/libnd4j/tests_cpu/layers_tests/GraphTests.cpp index 73aac9c3b..6d21b00f2 100644 --- a/libnd4j/tests_cpu/layers_tests/GraphTests.cpp +++ b/libnd4j/tests_cpu/layers_tests/GraphTests.cpp @@ -39,8 +39,8 @@ public: int fShape[] = {2, 2, 2, 1, 2, 0, 1, 102}; */ GraphTests() { - //Environment::getInstance()->setDebug(true); - //Environment::getInstance()->setVerbose(true); + //Environment::getInstance().setDebug(true); + //Environment::getInstance().setVerbose(true); } }; @@ -910,7 +910,7 @@ TEST_F(GraphTests, TestMultiOutput1) { auto nodeB0 = new Node(OpType_TRANSFORM_SAME, transform::Abs, 2, {-2}, {11}); nodeB0->markInplace(false); - auto op = sd::ops::OpRegistrator::getInstance()->getOperation("testop2i2o"); + auto op = sd::ops::OpRegistrator::getInstance().getOperation("testop2i2o"); // this op will add 1.0 to first input, and 2.0 for second input auto nodeT = new Node(op, 11, {1, 2}, {21, 31}, {}, 0.0f); @@ -951,7 +951,7 @@ TEST_F(GraphTests, TestMultiOutput1) { } TEST_F(GraphTests, TestDivergentNode1) { - auto op = sd::ops::OpRegistrator::getInstance()->getOperation("Switch"); + auto op = sd::ops::OpRegistrator::getInstance().getOperation("Switch"); auto nodeY = new Node(op, 1); ASSERT_TRUE(nodeY->isDivergencePoint()); diff --git a/libnd4j/tests_cpu/layers_tests/HashUtilsTests.cpp b/libnd4j/tests_cpu/layers_tests/HashUtilsTests.cpp index da513f7d4..431a4bc14 100644 --- a/libnd4j/tests_cpu/layers_tests/HashUtilsTests.cpp +++ b/libnd4j/tests_cpu/layers_tests/HashUtilsTests.cpp @@ -29,7 +29,7 @@ class HashUtilsTests : public testing::Test { TEST_F(HashUtilsTests, TestEquality1) { std::string str("Conv2D"); - Nd4jLong hash1 = sd::ops::HashHelper::getInstance()->getLongHash(str); + Nd4jLong hash1 = sd::ops::HashHelper::getInstance().getLongHash(str); ASSERT_EQ(-1637140380760460323L, hash1); } @@ -38,6 +38,6 @@ TEST_F(HashUtilsTests, TestEquality1) { TEST_F(HashUtilsTests, TestEquality2) { std::string str("switch"); - Nd4jLong hash1 = sd::ops::HashHelper::getInstance()->getLongHash(str); + Nd4jLong hash1 = sd::ops::HashHelper::getInstance().getLongHash(str); ASSERT_EQ(-1988317239813741487L, hash1); } \ No newline at end of file diff --git a/libnd4j/tests_cpu/layers_tests/JavaInteropTests.cpp b/libnd4j/tests_cpu/layers_tests/JavaInteropTests.cpp index e6992d7a2..23080161a 100644 --- a/libnd4j/tests_cpu/layers_tests/JavaInteropTests.cpp +++ b/libnd4j/tests_cpu/layers_tests/JavaInteropTests.cpp @@ -356,8 +356,8 @@ TEST_F(JavaInteropTests, TestInplace_1) { } TEST_F(JavaInteropTests, Test_Synonyms_1) { - auto op = OpRegistrator::getInstance()->getOperation("RDiv"); - auto opRef = OpRegistrator::getInstance()->getOperation("reversedivide"); + auto op = OpRegistrator::getInstance().getOperation("RDiv"); + auto opRef = OpRegistrator::getInstance().getOperation("reversedivide"); std::string nameExp("reversedivide"); ASSERT_TRUE(op != nullptr); @@ -371,8 +371,8 @@ TEST_F(JavaInteropTests, Test_Synonyms_1) { } TEST_F(JavaInteropTests, Test_Synonyms_2) { - auto op = OpRegistrator::getInstance()->getOperation("RDiv"); - auto opRef = OpRegistrator::getInstance()->getOperation("reversedivide"); + auto op = OpRegistrator::getInstance().getOperation("RDiv"); + auto opRef = OpRegistrator::getInstance().getOperation("reversedivide"); std::string nameExp("reversedivide"); ASSERT_TRUE(op != nullptr); @@ -386,8 +386,8 @@ TEST_F(JavaInteropTests, Test_Synonyms_2) { } TEST_F(JavaInteropTests, Test_Synonyms_3) { - auto op = OpRegistrator::getInstance()->getOperation("RDiv"); - auto opRef = OpRegistrator::getInstance()->getOperation("reversedivide"); + auto op = OpRegistrator::getInstance().getOperation("RDiv"); + auto opRef = OpRegistrator::getInstance().getOperation("reversedivide"); std::string nameExp("reversedivide"); ASSERT_TRUE(op != nullptr); @@ -486,7 +486,7 @@ TEST_F(JavaInteropTests, test_avgpooling_edge_1) { Nd4jPointer ptrsInShapes[] = {(Nd4jPointer) x.shapeInfo(), x.specialShapeInfo()}; Nd4jPointer ptrsOutBuffers[] = {(Nd4jPointer) z.buffer(), z.specialBuffer()}; - Nd4jPointer ptrsOutShapes[] = {(Nd4jPointer) z.shapeInfo(), z.specialShapeInfo()}; + Nd4jPointer ptrsOutShapes[] = {(Nd4jPointer) z.shapeInfo(), z.special()}; auto result = execCustomOp(nullptr, op.getOpHash(), ptrsInBuffer, ptrsInShapes, 1, ptrsOutBuffers, ptrsOutShapes, 1, nullptr, 0, exp, 11, nullptr, 0, false); @@ -563,19 +563,19 @@ TEST_F(JavaInteropTests, Test_GraphReuse_1) { registerGraph(nullptr, 119, (Nd4jPointer) data); - ASSERT_TRUE(GraphHolder::getInstance()->hasGraph(119)); + ASSERT_TRUE(GraphHolder::getInstance().hasGraph(119)); unregisterGraph(nullptr, 119); - ASSERT_FALSE(GraphHolder::getInstance()->hasGraph(119)); + ASSERT_FALSE(GraphHolder::getInstance().hasGraph(119)); delete[] data; } TEST_F(JavaInteropTests, Test_GraphReuse_2) { - //Environment::getInstance()->setDebug(true); - //Environment::getInstance()->setVerbose(true); + //Environment::getInstance().setDebug(true); + //Environment::getInstance().setVerbose(true); auto exp0 = NDArrayFactory::create('c', {3}, {3, 3, 3}); auto exp1 = NDArrayFactory::create('c', {3}, {6, 6, 6}); @@ -585,13 +585,13 @@ TEST_F(JavaInteropTests, Test_GraphReuse_2) { uint8_t* data = sd::graph::readFlatBuffers("./resources/reduce_dim_false.fb"); // we ensure that there's no such a graph stored earlier - ASSERT_FALSE(GraphHolder::getInstance()->hasGraph(119)); + ASSERT_FALSE(GraphHolder::getInstance().hasGraph(119)); // register the graph, to call for it later registerGraph(nullptr, 119, (Nd4jPointer) data); // and ensure we're ok - ASSERT_TRUE(GraphHolder::getInstance()->hasGraph(119)); + ASSERT_TRUE(GraphHolder::getInstance().hasGraph(119)); @@ -647,7 +647,7 @@ TEST_F(JavaInteropTests, Test_GraphReuse_2) { //////// clean out unregisterGraph(nullptr, 119); - ASSERT_FALSE(GraphHolder::getInstance()->hasGraph(119)); + ASSERT_FALSE(GraphHolder::getInstance().hasGraph(119)); delete[] data; @@ -830,8 +830,8 @@ TEST_F(JavaInteropTests, Test_Reduce3_EdgeCase) { extraPointers = new Nd4jPointer[6] {nullptr, context->getCudaStream(), context->getScalarPointer(), nullptr, context->getCudaSpecialStream(), context->getReductionPointer()}; #endif - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(x.shapeInfo(), {0,1}); - auto packY = sd::ConstantTadHelper::getInstance()->tadForDimensions(y.shapeInfo(), {0,1}); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(x.shapeInfo(), {0,1}); + auto packY = sd::ConstantTadHelper::getInstance().tadForDimensions(y.shapeInfo(), {0,1}); NDArray::prepareSpecialUse({&z}, {&x, &y, &dims}); OpaqueDataBuffer xBuf(x.dataBuffer()); @@ -853,14 +853,14 @@ TEST_F(JavaInteropTests, Test_Reduce3_EdgeCase) { /* TEST_F(JavaInteropTests, Test_SimpleIf_Output) { - Environment::getInstance()->setDebug(true); - Environment::getInstance()->setVerbose(false); + Environment::getInstance().setDebug(true); + Environment::getInstance().setVerbose(false); auto pl = sd::graph::readFlatBuffers("./resources/simpleif_0_1.fb"); auto ptr = executeFlatGraph(nullptr, pl); - Environment::getInstance()->setDebug(false); - Environment::getInstance()->setVerbose(false); + Environment::getInstance().setDebug(false); + Environment::getInstance().setVerbose(false); delete[] pl; delete ptr; @@ -979,7 +979,7 @@ TEST_F(JavaInteropTests, Test_AveragePooling_FF_TF_float) { } TEST_F(JavaInteropTests, Test_Mixed_Add_1) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; auto arrayX = NDArrayFactory::create({1, 2, 3, 4}); @@ -1226,7 +1226,7 @@ TEST_F(JavaInteropTests, Test_Fastpath_7) { } TEST_F(JavaInteropTests, test_bfloat16_rng) { - if (!Environment::getInstance()->isCPU()) + if (!Environment::getInstance().isCPU()) return; auto z = NDArrayFactory::create('c', {10}); @@ -1307,7 +1307,7 @@ TEST_F(JavaInteropTests, test_expandable_array_op_1) { } TEST_F(JavaInteropTests, test_workspace_backed_arrays_1) { - if (!Environment::getInstance()->isCPU()) + if (!Environment::getInstance().isCPU()) return; auto x = NDArrayFactory::create('c', {4, 3, 4, 4}); @@ -1338,7 +1338,7 @@ TEST_F(JavaInteropTests, test_workspace_backed_arrays_1) { } TEST_F(JavaInteropTests, test_linspace_shape_1) { - if (!Environment::getInstance()->isCPU()) + if (!Environment::getInstance().isCPU()) return; sd::ops::lin_space op; diff --git a/libnd4j/tests_cpu/layers_tests/LegacyOpsCudaTests.cu b/libnd4j/tests_cpu/layers_tests/LegacyOpsCudaTests.cu index 622ce9fbb..922d94afd 100644 --- a/libnd4j/tests_cpu/layers_tests/LegacyOpsCudaTests.cu +++ b/libnd4j/tests_cpu/layers_tests/LegacyOpsCudaTests.cu @@ -48,7 +48,7 @@ TEST_F(LegacyOpsCudaTests, test_sortTad_1) { auto e = NDArrayFactory::create('c', {3, 5}, {0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f, 11.f, 12.f, 13.f, 14.f}); int axis = 1; - auto packX = ConstantTadHelper::getInstance()->tadForDimensions(x.shapeInfo(), axis); + auto packX = ConstantTadHelper::getInstance().tadForDimensions(x.shapeInfo(), axis); Nd4jPointer extras[2] = {nullptr, LaunchContext::defaultContext()->getCudaStream()}; diff --git a/libnd4j/tests_cpu/layers_tests/LegacyOpsTests.cpp b/libnd4j/tests_cpu/layers_tests/LegacyOpsTests.cpp index 7c7734b38..fe9c5a7a0 100644 --- a/libnd4j/tests_cpu/layers_tests/LegacyOpsTests.cpp +++ b/libnd4j/tests_cpu/layers_tests/LegacyOpsTests.cpp @@ -394,7 +394,7 @@ TEST_F(LegacyOpsTests, BroadcastingTests_2) { int axis = 1; // shape::printShapeInfoLinear("tad shape", tad.tadOnlyShapeInfo); - auto packY = sd::ConstantTadHelper::getInstance()->tadForDimensions(y.shapeInfo(), {axis}); + auto packY = sd::ConstantTadHelper::getInstance().tadForDimensions(y.shapeInfo(), {axis}); NDArray::prepareSpecialUse({&y}, {&x}); @@ -466,8 +466,8 @@ TEST_F(LegacyOpsTests, Reduce3_2) { extraPointers = new Nd4jPointer[7] {nullptr, context->getCudaStream(), context->getScalarPointer(), nullptr, context->getCudaSpecialStream(), context->getReductionPointer(), context->getAllocationPointer()}; #endif - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(x.shapeInfo(), {1}); - auto packY = sd::ConstantTadHelper::getInstance()->tadForDimensions(y.shapeInfo(), {1}); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(x.shapeInfo(), {1}); + auto packY = sd::ConstantTadHelper::getInstance().tadForDimensions(y.shapeInfo(), {1}); NDArray::prepareSpecialUse({&z}, {&x, &y, &dim}); OpaqueDataBuffer xBuf(x.dataBuffer()); @@ -506,8 +506,8 @@ TEST_F(LegacyOpsTests, Reduce3_3) { extraPointers = new Nd4jPointer[7] {nullptr, context->getCudaStream(), context->getScalarPointer(), nullptr, context->getCudaSpecialStream(), context->getReductionPointer(), context->getAllocationPointer()}; #endif - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(x.shapeInfo(), {1}); - auto packY = sd::ConstantTadHelper::getInstance()->tadForDimensions(y.shapeInfo(), {1}); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(x.shapeInfo(), {1}); + auto packY = sd::ConstantTadHelper::getInstance().tadForDimensions(y.shapeInfo(), {1}); NDArray::prepareSpecialUse({&z}, {&x, &y, &dim}); OpaqueDataBuffer xBuf(x.dataBuffer()); @@ -546,8 +546,8 @@ TEST_F(LegacyOpsTests, Reduce3_4) { extraPointers = new Nd4jPointer[7] {nullptr, context->getCudaStream(), context->getScalarPointer(), nullptr, context->getCudaSpecialStream(), context->getReductionPointer(), context->getAllocationPointer()}; #endif - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(x.shapeInfo(), {1}); - auto packY = sd::ConstantTadHelper::getInstance()->tadForDimensions(y.shapeInfo(), {1}); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(x.shapeInfo(), {1}); + auto packY = sd::ConstantTadHelper::getInstance().tadForDimensions(y.shapeInfo(), {1}); NDArray::prepareSpecialUse({&z}, {&x, &y, &dim}); OpaqueDataBuffer xBuf(x.dataBuffer()); @@ -588,8 +588,8 @@ TEST_F(LegacyOpsTests, Reduce3_5) { extraPointers = new Nd4jPointer[7] {nullptr, context->getCudaStream(), context->getScalarPointer(), nullptr, context->getCudaSpecialStream(), context->getReductionPointer(), context->getAllocationPointer()}; #endif - auto packX = sd::ConstantTadHelper::getInstance()->tadForDimensions(x.shapeInfo(), {1}); - auto packY = sd::ConstantTadHelper::getInstance()->tadForDimensions(y.shapeInfo(), {1}); + auto packX = sd::ConstantTadHelper::getInstance().tadForDimensions(x.shapeInfo(), {1}); + auto packY = sd::ConstantTadHelper::getInstance().tadForDimensions(y.shapeInfo(), {1}); NDArray::prepareSpecialUse({&z}, {&x, &y, &dim}); @@ -616,8 +616,8 @@ TEST_F(LegacyOpsTests, test_Reduce3_All_1) { auto z = NDArrayFactory::create('c', {1000, 1}); auto dim = NDArrayFactory::create('c', {1}, {-1}); - auto tadPackX = sd::ConstantTadHelper::getInstance()->tadForDimensions(x.shapeInfo(), -1); - auto tadPackY = sd::ConstantTadHelper::getInstance()->tadForDimensions(y.shapeInfo(), -1); + auto tadPackX = sd::ConstantTadHelper::getInstance().tadForDimensions(x.shapeInfo(), -1); + auto tadPackY = sd::ConstantTadHelper::getInstance().tadForDimensions(y.shapeInfo(), -1); sd::LaunchContext* context = sd::LaunchContext::defaultContext(); @@ -652,7 +652,7 @@ TEST_F(LegacyOpsTests, test_inverse_broadcast_1) { auto e = NDArrayFactory::create('c', {3, 4}); e.assign(2.0f); - auto tadPackY = sd::ConstantTadHelper::getInstance()->tadForDimensions(y.shapeInfo(), 1); + auto tadPackY = sd::ConstantTadHelper::getInstance().tadForDimensions(y.shapeInfo(), 1); y.tickWriteDevice(); @@ -680,7 +680,7 @@ TEST_F(LegacyOpsTests, test_inverse_broadcast_2) { auto erow = e(1, {0}); erow.assign(true); - auto tadPackY = sd::ConstantTadHelper::getInstance()->tadForDimensions(y.shapeInfo(), 1); + auto tadPackY = sd::ConstantTadHelper::getInstance().tadForDimensions(y.shapeInfo(), 1); z.tickWriteDevice(); @@ -739,7 +739,7 @@ TEST_F(LegacyOpsTests, test_legacy_reduce_empty_3) { } TEST_F(LegacyOpsTests, test_legacy_reduce_empty_4) { - if (!Environment::getInstance()->isCPU()) + if (!Environment::getInstance().isCPU()) return; int a = 0; diff --git a/libnd4j/tests_cpu/layers_tests/MmapTests.cpp b/libnd4j/tests_cpu/layers_tests/MmapTests.cpp index c1df42fd1..7200dc034 100644 --- a/libnd4j/tests_cpu/layers_tests/MmapTests.cpp +++ b/libnd4j/tests_cpu/layers_tests/MmapTests.cpp @@ -34,7 +34,7 @@ public: TEST_F(MmapTests, Test_Basic_Mmap_1) { // FIXME: we must adopt this for CUDA as well - if (!Environment::getInstance()->isCPU()) + if (!Environment::getInstance().isCPU()) return; // just 10GB diff --git a/libnd4j/tests_cpu/layers_tests/MultiDataTypeTests.cpp b/libnd4j/tests_cpu/layers_tests/MultiDataTypeTests.cpp index 803029216..79f2ffa1e 100644 --- a/libnd4j/tests_cpu/layers_tests/MultiDataTypeTests.cpp +++ b/libnd4j/tests_cpu/layers_tests/MultiDataTypeTests.cpp @@ -56,7 +56,7 @@ TEST_F(MultiDataTypeTests, DataTypeUtils_Test_3) { //////////////////////////////////////////////////////////////////////////////// TEST_F(MultiDataTypeTests, Basic_Test_1) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; auto x = NDArrayFactory::create('c', {2, 3}, {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f}); @@ -70,7 +70,7 @@ TEST_F(MultiDataTypeTests, Basic_Test_1) { //////////////////////////////////////////////////////////////////////////////// TEST_F(MultiDataTypeTests, Basic_Test_2) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; auto x = NDArrayFactory::create('c', {2, 3}, {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f}); @@ -84,7 +84,7 @@ TEST_F(MultiDataTypeTests, Basic_Test_2) { //////////////////////////////////////////////////////////////////////////////// TEST_F(MultiDataTypeTests, Basic_Test_3) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; auto x = NDArrayFactory::create('c', {2, 3}, {0, 1, 2, 3, 4, 5}); @@ -98,7 +98,7 @@ TEST_F(MultiDataTypeTests, Basic_Test_3) { //////////////////////////////////////////////////////////////////////////////// TEST_F(MultiDataTypeTests, Basic_Test_4) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; auto x = NDArrayFactory::create('c', {2, 3}, {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f}); @@ -112,7 +112,7 @@ TEST_F(MultiDataTypeTests, Basic_Test_4) { //////////////////////////////////////////////////////////////////////////////// TEST_F(MultiDataTypeTests, Basic_Test_5) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; auto x = NDArrayFactory::create('c', {2, 3}, {0, 1, 2, 3, 4, 5}); @@ -125,7 +125,7 @@ TEST_F(MultiDataTypeTests, Basic_Test_5) { } TEST_F(MultiDataTypeTests, Basic_Test_7) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; auto x = NDArrayFactory::create('c', {2, 3}, {0, 1, 2, 3, 4, 5}); @@ -143,7 +143,7 @@ TEST_F(MultiDataTypeTests, Basic_Test_7) { //////////////////////////////////////////////////////////////////////////////// TEST_F(MultiDataTypeTests, Basic_Test_6) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; auto x = NDArrayFactory::create('c', {2, 3}, {0, 1, 2, 3, 4, 5}); @@ -301,7 +301,7 @@ TEST_F(MultiDataTypeTests, ndarray_varianceNumber_test1) { //////////////////////////////////////////////////////////////////////////////// TEST_F(MultiDataTypeTests, ndarray_operatorPlus_test1) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray x1('c', {2, 2}, {0, 1, 2, 3}, sd::DataType::INT64); @@ -316,7 +316,7 @@ TEST_F(MultiDataTypeTests, ndarray_operatorPlus_test1) { //////////////////////////////////////////////////////////////////////////////// TEST_F(MultiDataTypeTests, ndarray_operatorPlus_test2) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray x1('c', {2, 2}, {0, 1, 2, 3}, sd::DataType::INT64); @@ -340,7 +340,7 @@ TEST_F(MultiDataTypeTests, ndarray_operatorPlus_test2) { //////////////////////////////////////////////////////////////////////////////// TEST_F(MultiDataTypeTests, ndarray_operatorMinus_test1) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray x1('c', {2, 2}, {0, 1, 2, 3}, sd::DataType::INT64); @@ -355,7 +355,7 @@ TEST_F(MultiDataTypeTests, ndarray_operatorMinus_test1) { //////////////////////////////////////////////////////////////////////////////// TEST_F(MultiDataTypeTests, ndarray_operatorMinus_test2) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray x1('c', {2, 2}, {0, 1, 2, 3}, sd::DataType::INT64); @@ -382,7 +382,7 @@ TEST_F(MultiDataTypeTests, ndarray_operatorMinus_test2) { //////////////////////////////////////////////////////////////////////////////// multiply TEST_F(MultiDataTypeTests, ndarray_operatorMultiply_test1) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray x1('c', {2, 2}, {0, 1, 2, 3}, sd::DataType::INT64); @@ -397,7 +397,7 @@ TEST_F(MultiDataTypeTests, ndarray_operatorMultiply_test1) { //////////////////////////////////////////////////////////////////////////////// TEST_F(MultiDataTypeTests, ndarray_operatorMultiply_test2) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray x1('c', {2, 2}, {0, 1, 2, 3}, sd::DataType::INT64); @@ -422,7 +422,7 @@ TEST_F(MultiDataTypeTests, ndarray_operatorMultiply_test2) { //////////////////////////////////////////////////////////////////////////////// multiply TEST_F(MultiDataTypeTests, ndarray_operatorDivide_test1) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray x1('c', {2, 2}, {4, 1, 2, 3}, sd::DataType::HALF); @@ -438,7 +438,7 @@ TEST_F(MultiDataTypeTests, ndarray_operatorDivide_test1) { //////////////////////////////////////////////////////////////////////////////// TEST_F(MultiDataTypeTests, ndarray_operatorDivide_test2) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray x1('c', {2, 2}, {1, 2, 3, 4}, sd::DataType::INT64); @@ -470,7 +470,7 @@ TEST_F(MultiDataTypeTests, ndarray_operatorDivide_test2) { //////////////////////////////////////////////////////////////////////////////// TEST_F(MultiDataTypeTests, ndarray_operatorPlusEqual_test1) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray scalar1('c', {0}, std::vector{4}, sd::DataType::INT32); @@ -510,7 +510,7 @@ TEST_F(MultiDataTypeTests, ndarray_operatorPlusEqual_test1) { //////////////////////////////////////////////////////////////////////////////// TEST_F(MultiDataTypeTests, ndarray_operatorPlusEqual_test2) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray x1('c', {2,2}, {0, 1, 2, 3}, sd::DataType::FLOAT32); @@ -548,7 +548,7 @@ TEST_F(MultiDataTypeTests, ndarray_operatorPlusEqual_test2) { //////////////////////////////////////////////////////////////////////////////// TEST_F(MultiDataTypeTests, ndarray_operatorMinusEqual_test1) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray scalar1('c', {0}, std::vector{4}, sd::DataType::INT32); @@ -588,7 +588,7 @@ TEST_F(MultiDataTypeTests, ndarray_operatorMinusEqual_test1) { //////////////////////////////////////////////////////////////////////////////// TEST_F(MultiDataTypeTests, ndarray_operatorMinusEqual_test2) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray x1('c', {2,2}, {0, 1, 2, 3}, sd::DataType::FLOAT32); @@ -626,7 +626,7 @@ TEST_F(MultiDataTypeTests, ndarray_operatorMinusEqual_test2) { //////////////////////////////////////////////////////////////////////////////// TEST_F(MultiDataTypeTests, ndarray_operatorMultiplyEqual_test1) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray scalar1('c', {0}, std::vector{3}, sd::DataType::INT32); @@ -666,7 +666,7 @@ TEST_F(MultiDataTypeTests, ndarray_operatorMultiplyEqual_test1) { //////////////////////////////////////////////////////////////////////////////// TEST_F(MultiDataTypeTests, ndarray_operatorMultiplyEqual_test2) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray x1('c', {2,2}, {0, 1, 2, 3}, sd::DataType::FLOAT32); @@ -704,7 +704,7 @@ TEST_F(MultiDataTypeTests, ndarray_operatorMultiplyEqual_test2) { //////////////////////////////////////////////////////////////////////////////// TEST_F(MultiDataTypeTests, ndarray_operatorDivideEqual_test1) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray scalar1('c', {0}, std::vector{3}, sd::DataType::INT32); @@ -744,7 +744,7 @@ TEST_F(MultiDataTypeTests, ndarray_operatorDivideEqual_test1) { //////////////////////////////////////////////////////////////////////////////// TEST_F(MultiDataTypeTests, ndarray_operatorDivideEqual_test2) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray x1('c', {2,2}, {0, 2, 4, 6}, sd::DataType::FLOAT32); @@ -782,7 +782,7 @@ TEST_F(MultiDataTypeTests, ndarray_operatorDivideEqual_test2) { //////////////////////////////////////////////////////////////////////////////// TEST_F(MultiDataTypeTests, ndarray_reduceNumberFloat_test1) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray x1('c', {2,2}, {0, 1, 2, 3}, sd::DataType::INT64); @@ -819,7 +819,7 @@ TEST_F(MultiDataTypeTests, ndarray_reduceNumberFloat_test1) { //////////////////////////////////////////////////////////////////////////////// TEST_F(MultiDataTypeTests, ndarray_reduceNumberSame_test1) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray x1('c', {2,2}, {0, 1, 2, 3}, sd::DataType::INT64); @@ -856,7 +856,7 @@ TEST_F(MultiDataTypeTests, ndarray_reduceNumberSame_test1) { //////////////////////////////////////////////////////////////////////////////// TEST_F(MultiDataTypeTests, ndarray_reduceNumberBool_test1) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray x1('c', {2,2}, {0, -1, 2, -3}, sd::DataType::INT64); @@ -889,7 +889,7 @@ TEST_F(MultiDataTypeTests, ndarray_reduceNumberBool_test1) { ////////////////////////////////////////////////////////////////////////////// TEST_F(MultiDataTypeTests, ndarray_reduceNumberLong_test1) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray x1('c', {2,2}, {0, 1, 2, 3}, sd::DataType::INT64); @@ -925,7 +925,7 @@ TEST_F(MultiDataTypeTests, ndarray_reduceNumberLong_test1) { ////////////////////////////////////////////////////////////////////////////// TEST_F(MultiDataTypeTests, ndarray_indexReduceNumber_test1) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray x1('c', {2,2}, {0, 1, 2, 3}, sd::DataType::INT32); @@ -948,7 +948,7 @@ TEST_F(MultiDataTypeTests, ndarray_indexReduceNumber_test1) { ////////////////////////////////////////////////////////////////////////////// TEST_F(MultiDataTypeTests, ndarray_applyTransformFloat_test1) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray x1('c', {2,2}, {0, 4, 9, 16}, sd::DataType::INT64); @@ -986,7 +986,7 @@ TEST_F(MultiDataTypeTests, ndarray_applyTransformFloat_test1) { ////////////////////////////////////////////////////////////////////////////// TEST_F(MultiDataTypeTests, ndarray_applyTransformSame_test1) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray x1('c', {2,2}, {0, 1, 2, 3}, sd::DataType::INT64); @@ -1031,7 +1031,7 @@ TEST_F(MultiDataTypeTests, ndarray_applyTransformSame_test1) { ////////////////////////////////////////////////////////////////////////////// TEST_F(MultiDataTypeTests, ndarray_applyTransformBool_test1) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray x1('c', {2,2}, {0, 1, 2, 3}, sd::DataType::INT64); @@ -1067,7 +1067,7 @@ TEST_F(MultiDataTypeTests, ndarray_applyTransformBool_test1) { ////////////////////////////////////////////////////////////////////////////// TEST_F(MultiDataTypeTests, ndarray_applyTransformStrict_test1) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray x1('c', {2,2}, {0, 1, 2, 3}, sd::DataType::HALF); @@ -1113,7 +1113,7 @@ TEST_F(MultiDataTypeTests, ndarray_applyTransformStrict_test1) { ////////////////////////////////////////////////////////////////////////////// TEST_F(MultiDataTypeTests, ndarray_applyPairwiseTransform_test1) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray x1('c', {2,3}, {0, 1, 2, 3, 4, 5}, sd::DataType::INT32); @@ -1147,7 +1147,7 @@ TEST_F(MultiDataTypeTests, ndarray_applyPairwiseTransform_test1) { ////////////////////////////////////////////////////////////////////////////// TEST_F(MultiDataTypeTests, ndarray_applyPairwiseTransform_test2) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray x1('c', {2,3}, {1, 1, 2, 3, 4, 5}, sd::DataType::INT32); @@ -1176,7 +1176,7 @@ TEST_F(MultiDataTypeTests, ndarray_applyPairwiseTransform_test2) { ////////////////////////////////////////////////////////////////////////////// TEST_F(MultiDataTypeTests, ndarray_applyBroadcast_test1) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray x1('c', {2,3}, {10, 20, 30, 40, 50, 60}, sd::DataType::INT32); @@ -1222,7 +1222,7 @@ TEST_F(MultiDataTypeTests, ndarray_applyBroadcast_test2) { ////////////////////////////////////////////////////////////////////////////// TEST_F(MultiDataTypeTests, ndarray_applyTrueBroadcast_test1) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray x1('c', {2,2}, {10, 20, 30, 40}, sd::DataType::INT32); @@ -1281,7 +1281,7 @@ TEST_F(MultiDataTypeTests, ndarray_applyTrueBroadcast_test1) { ////////////////////////////////////////////////////////////////////////////// TEST_F(MultiDataTypeTests, ndarray_applyTrueBroadcast_test2) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray x1('c', {2,2}, {10, 20, 30, 40}, sd::DataType::HALF); @@ -1310,7 +1310,7 @@ TEST_F(MultiDataTypeTests, ndarray_applyTrueBroadcast_test2) { ////////////////////////////////////////////////////////////////////////////// TEST_F(MultiDataTypeTests, ndarray_applyScalar_test1) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray x1('c', {2,2}, {0, 1, 2, 3}, sd::DataType::INT64); @@ -1697,7 +1697,7 @@ TEST_F(MultiDataTypeTests, applyAllReduce3_test1) { ////////////////////////////////////////////////////////////////////// TEST_F(MultiDataTypeTests, RowCol_test1) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray x1('c', {2,3}, {1,2,3,4,5,6}, sd::DataType::INT32); @@ -1726,7 +1726,7 @@ TEST_F(MultiDataTypeTests, RowCol_test1) { ////////////////////////////////////////////////////////////////////// TEST_F(MultiDataTypeTests, RowCol_test2) { - if (!Environment::getInstance()->isExperimentalBuild()) + if (!Environment::getInstance().isExperimentalBuild()) return; NDArray x1('c', {2,3}, {1,2,3,4,5,6}, sd::DataType::INT32); diff --git a/libnd4j/tests_cpu/layers_tests/NDArrayCudaBasicsTests.cu b/libnd4j/tests_cpu/layers_tests/NDArrayCudaBasicsTests.cu index f95705f08..01510dc91 100644 --- a/libnd4j/tests_cpu/layers_tests/NDArrayCudaBasicsTests.cu +++ b/libnd4j/tests_cpu/layers_tests/NDArrayCudaBasicsTests.cu @@ -686,7 +686,7 @@ TEST_F(NDArrayCudaBasicsTests, Test_PrimitiveCosine_3) { TEST_F(NDArrayCudaBasicsTests, TestRawBroadcast_2) { - //if (!Environment::getInstance()->isExperimentalBuild()) + //if (!Environment::getInstance().isExperimentalBuild()) // return; NDArray x = NDArrayFactory::create('c', {2,3,4}); @@ -746,7 +746,7 @@ TEST_F(NDArrayCudaBasicsTests, TestRawBroadcast_2) { TEST_F(NDArrayCudaBasicsTests, TestRawBroadcast_3) { - //if (!Environment::getInstance()->isExperimentalBuild()) + //if (!Environment::getInstance().isExperimentalBuild()) // return; NDArray x('c', {2,3,4}, sd::DataType::DOUBLE); @@ -944,7 +944,7 @@ TEST_F(NDArrayCudaBasicsTests, TestBroadcastMultiply_002) { //////////////////////////////////////////////////////////////////////////// TEST_F(NDArrayCudaBasicsTests, TestBroadcastRaw_1) { - //if (!Environment::getInstance()->isExperimentalBuild()) + //if (!Environment::getInstance().isExperimentalBuild()) // return; NDArray x('c', {2,3,4}, {100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100}, sd::DataType::INT32); diff --git a/libnd4j/tests_cpu/layers_tests/NativeOpsTests.cpp b/libnd4j/tests_cpu/layers_tests/NativeOpsTests.cpp index 3d0df208f..2f87b5099 100644 --- a/libnd4j/tests_cpu/layers_tests/NativeOpsTests.cpp +++ b/libnd4j/tests_cpu/layers_tests/NativeOpsTests.cpp @@ -95,7 +95,7 @@ TEST_F(NativeOpsTests, ThresholdTests_1) { printf("Unsupported for cuda now.\n"); #else ::setElementThreshold(4); - ASSERT_TRUE(4 == sd::Environment::getInstance()->elementwiseThreshold()); + ASSERT_TRUE(4 == sd::Environment::getInstance().elementwiseThreshold()); #endif } @@ -107,7 +107,7 @@ TEST_F(NativeOpsTests, ThresholdTests_2) { printf("Unsupported for cuda now.\n"); #else ::setTADThreshold(4); - ASSERT_TRUE(4 == sd::Environment::getInstance()->tadThreshold()); + ASSERT_TRUE(4 == sd::Environment::getInstance().tadThreshold()); #endif } @@ -644,8 +644,8 @@ TEST_F(NativeOpsTests, Reduce3Test_4) { x.syncToDevice(); dimension.syncToHost(); int* dimensions = reinterpret_cast(dimension.buffer()); - auto tadPackX = sd::ConstantTadHelper::getInstance()->tadForDimensions(x.shapeInfo(), dimensions, dimension.lengthOf()); - auto tadPackY = sd::ConstantTadHelper::getInstance()->tadForDimensions(y.shapeInfo(), dimensions, dimension.lengthOf()); + auto tadPackX = sd::ConstantTadHelper::getInstance().tadForDimensions(x.shapeInfo(), dimensions, dimension.lengthOf()); + auto tadPackY = sd::ConstantTadHelper::getInstance().tadForDimensions(y.shapeInfo(), dimensions, dimension.lengthOf()); auto hTADShapeInfoX = tadPackX.primaryShapeInfo(); auto hTADOffsetsX = tadPackX.primaryOffsets(); @@ -963,8 +963,8 @@ TEST_F(NativeOpsTests, ScalarTadTest_1) { z.syncToDevice(); auto dimension = NDArrayFactory::create({0, 1}); auto dimensions = reinterpret_cast(dimension.buffer()); - auto tadPackX = sd::ConstantTadHelper::getInstance()->tadForDimensions(x.shapeInfo(), dimensions, dimension.lengthOf()); - auto tadPackZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(z.shapeInfo(), dimensions, dimension.lengthOf()); + auto tadPackX = sd::ConstantTadHelper::getInstance().tadForDimensions(x.shapeInfo(), dimensions, dimension.lengthOf()); + auto tadPackZ = sd::ConstantTadHelper::getInstance().tadForDimensions(z.shapeInfo(), dimensions, dimension.lengthOf()); OpaqueDataBuffer xBuf(x.dataBuffer()); OpaqueDataBuffer yBuf(y.dataBuffer()); @@ -1008,8 +1008,8 @@ TEST_F(NativeOpsTests, ScalarTadTest_2) { z.syncToDevice(); auto dimension = NDArrayFactory::create({0, 1}); auto dimensions = reinterpret_cast(dimension.buffer()); - auto tadPackX = sd::ConstantTadHelper::getInstance()->tadForDimensions(x.shapeInfo(), dimensions, dimension.lengthOf()); - auto tadPackZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(z.shapeInfo(), dimensions, dimension.lengthOf()); + auto tadPackX = sd::ConstantTadHelper::getInstance().tadForDimensions(x.shapeInfo(), dimensions, dimension.lengthOf()); + auto tadPackZ = sd::ConstantTadHelper::getInstance().tadForDimensions(z.shapeInfo(), dimensions, dimension.lengthOf()); z.assign(true); OpaqueDataBuffer xBuf(x.dataBuffer()); @@ -1057,8 +1057,8 @@ TEST_F(NativeOpsTests, ConcatTest_2) { int d = 0; auto dimension = NDArrayFactory::create('c', {1}, {d}); auto dimensions = reinterpret_cast(dimension.buffer()); - //auto tadPackX = sd::ConstantTadHelper::getInstance()->tadForDimensions(x.shapeInfo(), dimensions, dimension.lengthOf()); - auto tadPackZ = sd::ConstantTadHelper::getInstance()->tadForDimensions(z.shapeInfo(), dimensions, dimension.lengthOf()); + //auto tadPackX = sd::ConstantTadHelper::getInstance().tadForDimensions(x.shapeInfo(), dimensions, dimension.lengthOf()); + auto tadPackZ = sd::ConstantTadHelper::getInstance().tadForDimensions(z.shapeInfo(), dimensions, dimension.lengthOf()); exp.linspace(1); Nd4jPointer datas[] = {x.buffer(), y.buffer()}; Nd4jPointer shapes[] = {(Nd4jPointer)x.shapeInfo(), (Nd4jPointer)y.shapeInfo()}; @@ -1125,8 +1125,8 @@ TEST_F(NativeOpsTests, PullRowsTest_1) { std::vector dims = {1}; - auto xTadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(x.shapeInfo(), dims); - auto zTadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(z.shapeInfo(), dims); + auto xTadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(x.shapeInfo(), dims); + auto zTadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(z.shapeInfo(), dims); Nd4jPointer nativeStart[2]; @@ -1230,7 +1230,7 @@ TEST_F(NativeOpsTests, ShuffleTest_1) { Nd4jPointer zShapeList[] = {(Nd4jPointer)z.shapeInfo(), (Nd4jPointer)z.shapeInfo()}; Nd4jPointer dzShapeList[] = {(Nd4jPointer)z.specialShapeInfo(), (Nd4jPointer)z.specialShapeInfo()}; int shuffleMap[] = {1, 0, 4, 3, 2}; - auto zTadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(x.shapeInfo(), {1}); + auto zTadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(x.shapeInfo(), {1}); Nd4jPointer zListOffset[] = {(Nd4jPointer)zTadPack.platformOffsets(), (Nd4jPointer)zTadPack.platformOffsets()}; Nd4jPointer zListTADs[] = {(Nd4jPointer)zTadPack.platformShapeInfo(), (Nd4jPointer)zTadPack.platformShapeInfo()}; ::shuffle(nullptr, @@ -1411,7 +1411,7 @@ TEST_F(NativeOpsTests, SortTest_4) { auto exp = NDArrayFactory::create('c', {3, 6}, {1, 5, 5, 10, 34, 120, 3, 29, 78, 111, 138, 331, 4, 50, 56, 71, 73, 91}); std::vector dims({1}); - auto packX = ConstantTadHelper::getInstance()->tadForDimensions(sortedVals.shapeInfo(), {1}); + auto packX = ConstantTadHelper::getInstance().tadForDimensions(sortedVals.shapeInfo(), {1}); ::sortTad(nullptr, sortedVals.buffer(), sortedVals.shapeInfo(), sortedVals.specialBuffer(), sortedVals.specialShapeInfo(), dims.data(), dims.size(), packX.platformShapeInfo(), packX.platformOffsets(), false); // sortedVals.printBuffer("OUT"); diff --git a/libnd4j/tests_cpu/layers_tests/OmpLaunchHelperTests.cpp b/libnd4j/tests_cpu/layers_tests/OmpLaunchHelperTests.cpp index a7c7eae24..af327d653 100644 --- a/libnd4j/tests_cpu/layers_tests/OmpLaunchHelperTests.cpp +++ b/libnd4j/tests_cpu/layers_tests/OmpLaunchHelperTests.cpp @@ -31,12 +31,12 @@ private: int ewt = 0; public: OmpLaunchHelperTests() { - this->ewt = Environment::getInstance()->elementwiseThreshold(); - Environment::getInstance()->setElementwiseThreshold(1000); + this->ewt = Environment::getInstance().elementwiseThreshold(); + Environment::getInstance().setElementwiseThreshold(1000); }; ~OmpLaunchHelperTests() { - Environment::getInstance()->setElementwiseThreshold(this->ewt); + Environment::getInstance().setElementwiseThreshold(this->ewt); } }; @@ -85,7 +85,7 @@ TEST_F(OmpLaunchHelperTests, test_tad_threads_1) { Nd4jLong numTads = 16; Nd4jLong tadLength = 16; -// nd4j_printf("TT: [%i]; ET: [%i];\n", Environment::getInstance()->tadThreshold(), Environment::getInstance()->elementwiseThreshold()); +// nd4j_printf("TT: [%i]; ET: [%i];\n", Environment::getInstance().tadThreshold(), Environment::getInstance().elementwiseThreshold()); ASSERT_EQ(1, OmpLaunchHelper::tadThreads(tadLength, numTads)); } @@ -94,7 +94,7 @@ TEST_F(OmpLaunchHelperTests, test_tad_threads_2) { return; Nd4jLong numTads = 2; - Nd4jLong tadLength = Environment::getInstance()->elementwiseThreshold(); + Nd4jLong tadLength = Environment::getInstance().elementwiseThreshold(); ASSERT_EQ(2, OmpLaunchHelper::tadThreads(tadLength, numTads)); } @@ -117,7 +117,7 @@ TEST_F(OmpLaunchHelperTests, test_tad_threads_5) { auto exp = omp_get_max_threads(); Nd4jLong numTads = exp; - Nd4jLong tadLength = Environment::getInstance()->elementwiseThreshold(); + Nd4jLong tadLength = Environment::getInstance().elementwiseThreshold(); ASSERT_EQ(exp, OmpLaunchHelper::tadThreads(tadLength, numTads)); } \ No newline at end of file diff --git a/libnd4j/tests_cpu/layers_tests/OpTrackerTests.cpp b/libnd4j/tests_cpu/layers_tests/OpTrackerTests.cpp index fe581e09e..a14971ad5 100644 --- a/libnd4j/tests_cpu/layers_tests/OpTrackerTests.cpp +++ b/libnd4j/tests_cpu/layers_tests/OpTrackerTests.cpp @@ -42,24 +42,24 @@ public: TEST_F(OpTrackerTests, Test_Existence_1) { sd::_loader loader; - // nd4j_printf("Groups: %i; Operations: %i\n", OpTracker::getInstance()->totalGroups(), OpTracker::getInstance()->totalOperations()); + // nd4j_printf("Groups: %i; Operations: %i\n", OpTracker::getInstance().totalGroups(), OpTracker::getInstance().totalOperations()); - ASSERT_TRUE(OpTracker::getInstance()->totalGroups() > 0); - ASSERT_TRUE(OpTracker::getInstance()->totalOperations() > 0); + ASSERT_TRUE(OpTracker::getInstance().totalGroups() > 0); + ASSERT_TRUE(OpTracker::getInstance().totalOperations() > 0); - OpTracker::getInstance()->exportOperations(); + OpTracker::getInstance().exportOperations(); } TEST_F(OpTrackerTests, Test_Ops_List_1) { sd::ops::less op; - auto vec = OpRegistrator::getInstance()->getAllHashes(); + auto vec = OpRegistrator::getInstance().getAllHashes(); // nd4j_printf("Total ops: %lld\n", vec.size()); // nd4j_printf("Less hash: %lld\n", op.getOpHash()); for (const auto &v: vec) { if (v == 5484196977525668316L) { - auto op = OpRegistrator::getInstance()->getOperation(v); + auto op = OpRegistrator::getInstance().getOperation(v); // nd4j_printf("OpName: %s\n", op->getOpName()->c_str()); } } diff --git a/libnd4j/tests_cpu/layers_tests/PlaygroundTests.cpp b/libnd4j/tests_cpu/layers_tests/PlaygroundTests.cpp index 91ddcbd30..a8f45cc48 100644 --- a/libnd4j/tests_cpu/layers_tests/PlaygroundTests.cpp +++ b/libnd4j/tests_cpu/layers_tests/PlaygroundTests.cpp @@ -124,12 +124,12 @@ TEST_F(PlaygroundTests, test_bert_full_1) { */ - sd::Environment::getInstance()->setProfiling(true); + sd::Environment::getInstance().setProfiling(true); auto profile = GraphProfilingHelper::profile(graph, 1); profile->printOut(); - sd::Environment::getInstance()->setProfiling(false); + sd::Environment::getInstance().setProfiling(false); delete profile; /* @@ -185,12 +185,12 @@ TEST_F(PlaygroundTests, test_bert_1) { ASSERT_EQ(z, *array); */ - sd::Environment::getInstance()->setProfiling(true); + sd::Environment::getInstance().setProfiling(true); auto profile = GraphProfilingHelper::profile(graph, 1); profile->printOut(); - sd::Environment::getInstance()->setProfiling(false); + sd::Environment::getInstance().setProfiling(false); delete profile; /* @@ -237,12 +237,12 @@ TEST_F(PlaygroundTests, test_bert_2) { ASSERT_EQ(z, *array); */ - sd::Environment::getInstance()->setProfiling(true); + sd::Environment::getInstance().setProfiling(true); auto profile = GraphProfilingHelper::profile(graph, 1); profile->printOut(); - sd::Environment::getInstance()->setProfiling(false); + sd::Environment::getInstance().setProfiling(false); delete profile; /* @@ -631,7 +631,7 @@ TEST_F(PlaygroundTests, test_s_0) { for (auto shape: shapes) { for (auto t: threads) { - sd::Environment::getInstance()->setMaxMasterThreads(t); + sd::Environment::getInstance().setMaxMasterThreads(t); auto x = NDArrayFactory::create('c', shape); auto y = NDArrayFactory::create('c', {shape[3]}); @@ -670,7 +670,7 @@ TEST_F(PlaygroundTests, test_s_1) { for (auto shape: shapes) { for (auto t: threads) { - sd::Environment::getInstance()->setMaxMasterThreads(t); + sd::Environment::getInstance().setMaxMasterThreads(t); auto x = NDArrayFactory::create('c', shape); auto y = NDArrayFactory::create('c', {shape[1]}); diff --git a/libnd4j/tests_cpu/layers_tests/ServerRelatedTests.cpp b/libnd4j/tests_cpu/layers_tests/ServerRelatedTests.cpp index e0d03731b..50c1f4b19 100644 --- a/libnd4j/tests_cpu/layers_tests/ServerRelatedTests.cpp +++ b/libnd4j/tests_cpu/layers_tests/ServerRelatedTests.cpp @@ -29,13 +29,13 @@ using namespace sd::graph; class ServerRelatedTests : public testing::Test { public: ServerRelatedTests() { - Environment::getInstance()->setDebug(true); - Environment::getInstance()->setVerbose(true); + Environment::getInstance().setDebug(true); + Environment::getInstance().setVerbose(true); } ~ServerRelatedTests() { - Environment::getInstance()->setDebug(false); - Environment::getInstance()->setVerbose(false); + Environment::getInstance().setDebug(false); + Environment::getInstance().setVerbose(false); } }; /* @@ -89,9 +89,9 @@ TEST_F(ServerRelatedTests, Basic_Execution_Test_1) { auto exp = NDArrayFactory::create('c', {3}, {3.f, 3.f, 3.f}); - GraphHolder::getInstance()->registerGraph(11901L, oGraph); + GraphHolder::getInstance().registerGraph(11901L, oGraph); - auto cGraph = GraphHolder::getInstance()->cloneGraph(11901L); + auto cGraph = GraphHolder::getInstance().cloneGraph(11901L); ASSERT_TRUE(oGraph != cGraph); @@ -108,7 +108,7 @@ TEST_F(ServerRelatedTests, Basic_Execution_Test_1) { delete cGraph; - GraphHolder::getInstance()->dropGraphAny(11901L); + GraphHolder::getInstance().dropGraphAny(11901L); } TEST_F(ServerRelatedTests, Basic_Execution_Test_2) { @@ -120,9 +120,9 @@ TEST_F(ServerRelatedTests, Basic_Execution_Test_2) { auto input0 = NDArrayFactory::create('c', {3, 3}, {2.f,2.f,2.f, 2.f,2.f,2.f, 2.f,2.f,2.f}); auto exp = NDArrayFactory::create('c', {3}, {6.f, 6.f, 6.f}); - GraphHolder::getInstance()->registerGraph(11902L, oGraph); + GraphHolder::getInstance().registerGraph(11902L, oGraph); - auto cGraph = GraphHolder::getInstance()->cloneGraph(11902L); + auto cGraph = GraphHolder::getInstance().cloneGraph(11902L); ASSERT_TRUE(oGraph != cGraph); @@ -148,7 +148,7 @@ TEST_F(ServerRelatedTests, Basic_Execution_Test_2) { delete cGraph; - GraphHolder::getInstance()->dropGraphAny(11902L); + GraphHolder::getInstance().dropGraphAny(11902L); } TEST_F(ServerRelatedTests, BasicExecutionTests_3) { @@ -160,7 +160,7 @@ TEST_F(ServerRelatedTests, BasicExecutionTests_3) { auto input0 = NDArrayFactory::create('c', {3, 3}, {2.f,2.f,2.f, 2.f,2.f,2.f, 2.f,2.f,2.f}); auto exp = NDArrayFactory::create('c', {3}, {6.f, 6.f, 6.f}); - GraphHolder::getInstance()->registerGraph(11903L, oGraph); + GraphHolder::getInstance().registerGraph(11903L, oGraph); // mastering InferenceRequest InferenceRequest ir(11903L); @@ -172,7 +172,7 @@ TEST_F(ServerRelatedTests, BasicExecutionTests_3) { auto fir = GetFlatInferenceRequest(fptr); - auto flatResult = GraphHolder::getInstance()->execute(fir->id(), builder, fir); + auto flatResult = GraphHolder::getInstance().execute(fir->id(), builder, fir); builder.Finish(flatResult); auto ptr = builder.GetBufferPointer(); @@ -183,6 +183,6 @@ TEST_F(ServerRelatedTests, BasicExecutionTests_3) { ASSERT_EQ(exp, *restored.at(0)->getNDArray()); - GraphHolder::getInstance()->dropGraphAny(11903L); + GraphHolder::getInstance().dropGraphAny(11903L); } #endif diff --git a/libnd4j/tests_cpu/layers_tests/SortCpuTests.cpp b/libnd4j/tests_cpu/layers_tests/SortCpuTests.cpp index 4dcedf035..a31547561 100644 --- a/libnd4j/tests_cpu/layers_tests/SortCpuTests.cpp +++ b/libnd4j/tests_cpu/layers_tests/SortCpuTests.cpp @@ -34,7 +34,7 @@ public: TEST_F(SortCpuTests, test_linear_sort_by_key_1) { - if (!Environment::getInstance()->isCPU()) + if (!Environment::getInstance().isCPU()) return; auto k = NDArrayFactory::create('c', {10}, {1, 3, 5, 9, 0, 2, 4, 6, 7, 8}); @@ -51,7 +51,7 @@ TEST_F(SortCpuTests, test_linear_sort_by_key_1) { } TEST_F(SortCpuTests, test_linear_sort_by_val_1) { - if (!Environment::getInstance()->isCPU()) + if (!Environment::getInstance().isCPU()) return; auto k = NDArrayFactory::create('c', {10}, {1, 3, 5, 9, 0, 2, 4, 6, 7, 8}); @@ -68,7 +68,7 @@ TEST_F(SortCpuTests, test_linear_sort_by_val_1) { } TEST_F(SortCpuTests, test_tad_sort_by_key_1) { - if (!Environment::getInstance()->isCPU()) + if (!Environment::getInstance().isCPU()) return; auto k = NDArrayFactory::create('c', {2, 10}, {1, 3, 5, 9, 0, 2, 4, 6, 7, 8, 1, 3, 5, 9, 0, 2, 4, 6, 7, 8}); @@ -86,7 +86,7 @@ TEST_F(SortCpuTests, test_tad_sort_by_key_1) { } TEST_F(SortCpuTests, test_tad_sort_by_val_1) { - if (!Environment::getInstance()->isCPU()) + if (!Environment::getInstance().isCPU()) return; auto k = NDArrayFactory::create('c', {2, 10}, {1, 3, 5, 9, 0, 2, 4, 6, 7, 8, 1, 3, 5, 9, 0, 2, 4, 6, 7, 8}); diff --git a/libnd4j/tests_cpu/layers_tests/TadTests.cpp b/libnd4j/tests_cpu/layers_tests/TadTests.cpp index a2cdec003..947927bfb 100644 --- a/libnd4j/tests_cpu/layers_tests/TadTests.cpp +++ b/libnd4j/tests_cpu/layers_tests/TadTests.cpp @@ -245,13 +245,13 @@ TEST_F(TadTests, test_tad_order_4) { TEST_F(TadTests, test_column_1) { auto x = NDArrayFactory::create('c', {5, 2}); - auto tadPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(x.shapeInfo(), 0); + auto tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(x.shapeInfo(), 0); ASSERT_EQ(1, shape::rank(tadPack.primaryShapeInfo())); ASSERT_EQ(5, shape::length(tadPack.primaryShapeInfo())); ASSERT_TRUE(shape::isVector(tadPack.primaryShapeInfo())); - auto scalarViewPack = sd::ConstantTadHelper::getInstance()->tadForDimensions(tadPack.primaryShapeInfo(), 0); + auto scalarViewPack = sd::ConstantTadHelper::getInstance().tadForDimensions(tadPack.primaryShapeInfo(), 0); ASSERT_TRUE(shape::equalsStrict(tadPack.primaryShapeInfo(), scalarViewPack.primaryShapeInfo())); } diff --git a/libnd4j/tests_cpu/layers_tests/ThreadsTests.cpp b/libnd4j/tests_cpu/layers_tests/ThreadsTests.cpp index a9450e9d0..71957bc59 100644 --- a/libnd4j/tests_cpu/layers_tests/ThreadsTests.cpp +++ b/libnd4j/tests_cpu/layers_tests/ThreadsTests.cpp @@ -208,9 +208,31 @@ TEST_F(ThreadsTests, reduction_test_1) { ASSERT_EQ(8192, sum); } +static void _code(int thread_id) { + auto x = NDArrayFactory::create('c', {65536 * 16}); + x.assign(1.1f); +} + +TEST_F(ThreadsTests, crash_test_1) { + if (!Environment::getInstance().isCPU()) + return; + + for (int e = 0; e < 3; e++) { + std::vector threads(std::thread::hardware_concurrency()); + + // creating some threads + for (int t = 0; t < threads.size(); t++) + threads[t] = std::thread(_code, t); + + // blocking until everything is finished + for (auto &t:threads) + t.join(); + } +} + /* TEST_F(ThreadsTests, basic_test_1) { - if (!Environment::getInstance()->isCPU()) + if (!Environment::getInstance().isCPU()) return; auto instance = samediff::ThreadPool::getInstance(); diff --git a/libnd4j/tests_cpu/layers_tests/WorkspaceTests.cpp b/libnd4j/tests_cpu/layers_tests/WorkspaceTests.cpp index 571db71f3..b291e5fbb 100644 --- a/libnd4j/tests_cpu/layers_tests/WorkspaceTests.cpp +++ b/libnd4j/tests_cpu/layers_tests/WorkspaceTests.cpp @@ -112,7 +112,7 @@ TEST_F(WorkspaceTests, ResetTest1) { TEST_F(WorkspaceTests, StretchTest1) { - if (!Environment::getInstance()->isCPU()) + if (!Environment::getInstance().isCPU()) return; Workspace workspace(128); @@ -147,7 +147,7 @@ TEST_F(WorkspaceTests, StretchTest1) { } TEST_F(WorkspaceTests, NewInWorkspaceTest1) { - if (!Environment::getInstance()->isCPU()) + if (!Environment::getInstance().isCPU()) return; Workspace ws(65536); @@ -155,11 +155,11 @@ TEST_F(WorkspaceTests, NewInWorkspaceTest1) { ASSERT_EQ(65536, ws.getCurrentSize()); ASSERT_EQ(0, ws.getCurrentOffset()); - ASSERT_FALSE(MemoryRegistrator::getInstance()->hasWorkspaceAttached()); + ASSERT_FALSE(MemoryRegistrator::getInstance().hasWorkspaceAttached()); - MemoryRegistrator::getInstance()->attachWorkspace(&ws); + MemoryRegistrator::getInstance().attachWorkspace(&ws); - ASSERT_TRUE(MemoryRegistrator::getInstance()->hasWorkspaceAttached()); + ASSERT_TRUE(MemoryRegistrator::getInstance().hasWorkspaceAttached()); auto ast = NDArrayFactory::create_('c', {5, 5}); @@ -167,10 +167,10 @@ TEST_F(WorkspaceTests, NewInWorkspaceTest1) { delete ast; - MemoryRegistrator::getInstance()->forgetWorkspace(); + MemoryRegistrator::getInstance().forgetWorkspace(); - ASSERT_FALSE(MemoryRegistrator::getInstance()->hasWorkspaceAttached()); - ASSERT_TRUE(MemoryRegistrator::getInstance()->getWorkspace() == nullptr); + ASSERT_FALSE(MemoryRegistrator::getInstance().hasWorkspaceAttached()); + ASSERT_TRUE(MemoryRegistrator::getInstance().getWorkspace() == nullptr); } @@ -182,7 +182,7 @@ TEST_F(WorkspaceTests, NewInWorkspaceTest2) { ASSERT_EQ(65536, ws.getCurrentSize()); ASSERT_EQ(0, ws.getCurrentOffset()); - MemoryRegistrator::getInstance()->attachWorkspace(&ws); + MemoryRegistrator::getInstance().attachWorkspace(&ws); auto ast = NDArrayFactory::create_('c', {5, 5}, &ctx); @@ -190,11 +190,11 @@ TEST_F(WorkspaceTests, NewInWorkspaceTest2) { delete ast; - MemoryRegistrator::getInstance()->forgetWorkspace(); + MemoryRegistrator::getInstance().forgetWorkspace(); } TEST_F(WorkspaceTests, CloneTest1) { - if (!Environment::getInstance()->isCPU()) + if (!Environment::getInstance().isCPU()) return; Workspace ws(65536); @@ -250,7 +250,7 @@ TEST_F(WorkspaceTests, Test_Graph_1) { #endif TEST_F(WorkspaceTests, Test_Externalized_1) { - if (!Environment::getInstance()->isCPU()) + if (!Environment::getInstance().isCPU()) return; char buffer[10000]; diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-native-api/src/main/java/org/nd4j/nativeblas/NativeOps.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-native-api/src/main/java/org/nd4j/nativeblas/NativeOps.java index ae9ff1e94..b4bd62096 100644 --- a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-native-api/src/main/java/org/nd4j/nativeblas/NativeOps.java +++ b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-native-api/src/main/java/org/nd4j/nativeblas/NativeOps.java @@ -1119,7 +1119,7 @@ public interface NativeOps { */ int dataTypeFromNpyHeader(Pointer numpyHeader); - OpaqueConstantDataBuffer shapeBuffer(int rank, LongPointer shape, LongPointer strides, int dtype, char order, long ews, boolean empty); + OpaqueConstantShapeBuffer shapeBuffer(int rank, LongPointer shape, LongPointer strides, int dtype, char order, long ews, boolean empty); OpaqueConstantDataBuffer constantBufferDouble(int dtype, DoublePointer data, int length); @@ -1128,9 +1128,12 @@ public interface NativeOps { Pointer getConstantDataBufferPrimary(OpaqueConstantDataBuffer dbf); Pointer getConstantDataBufferSpecial(OpaqueConstantDataBuffer dbf); long getConstantDataBufferLength(OpaqueConstantDataBuffer dbf); - long getConstantDataBufferSizeOf(OpaqueConstantDataBuffer dbf); - void deleteShapeBuffer(OpaqueConstantDataBuffer state); + Pointer getConstantShapeBufferPrimary(OpaqueConstantShapeBuffer dbf); + Pointer getConstantShapeBufferSpecial(OpaqueConstantShapeBuffer dbf); + + void deleteConstantShapeBuffer(OpaqueConstantShapeBuffer state); + void deleteConstantDataBuffer(OpaqueConstantDataBuffer state); OpaqueContext createGraphContext(int nodeId); OpaqueRandomGenerator getGraphContextRandomGenerator(OpaqueContext ptr); diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-native-api/src/main/java/org/nd4j/nativeblas/OpaqueConstantShapeBuffer.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-native-api/src/main/java/org/nd4j/nativeblas/OpaqueConstantShapeBuffer.java new file mode 100644 index 000000000..977747fb6 --- /dev/null +++ b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-native-api/src/main/java/org/nd4j/nativeblas/OpaqueConstantShapeBuffer.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2015-2019 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 + ******************************************************************************/ + +package org.nd4j.nativeblas; + +import org.bytedeco.javacpp.Pointer; + +/** + * + * @author saudet + */ +public class OpaqueConstantShapeBuffer extends Pointer { + public OpaqueConstantShapeBuffer(Pointer p) { super(p); } +} diff --git a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/ops/executioner/CudaExecutioner.java b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/ops/executioner/CudaExecutioner.java index afca1daa5..65bfa24fc 100644 --- a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/ops/executioner/CudaExecutioner.java +++ b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/ops/executioner/CudaExecutioner.java @@ -2156,14 +2156,14 @@ public class CudaExecutioner extends DefaultOpExecutioner { if (nativeOps.lastErrorCode() != 0) throw new RuntimeException(nativeOps.lastErrorMessage()); - OpaqueConstantDataBuffer dbf = nativeOps.shapeBuffer(shape.length, new LongPointer(shape), new LongPointer(stride), dtype.toInt(), order, elementWiseStride, empty); + val dbf = nativeOps.shapeBuffer(shape.length, new LongPointer(shape), new LongPointer(stride), dtype.toInt(), order, elementWiseStride, empty); if (nativeOps.lastErrorCode() != 0) throw new RuntimeException(nativeOps.lastErrorMessage()); - val result = new CudaLongDataBuffer(nativeOps.getConstantDataBufferPrimary(dbf), nativeOps.getConstantDataBufferSpecial(dbf), Shape.shapeInfoLength(shape.length)); + val result = new CudaLongDataBuffer(nativeOps.getConstantShapeBufferPrimary(dbf), nativeOps.getConstantShapeBufferSpecial(dbf), Shape.shapeInfoLength(shape.length)); - nativeOps.deleteShapeBuffer(dbf); + nativeOps.deleteConstantShapeBuffer(dbf); return result; } @@ -2191,7 +2191,7 @@ public class CudaExecutioner extends DefaultOpExecutioner { if (nativeOps.lastErrorCode() != 0) throw new RuntimeException(nativeOps.lastErrorMessage()); - OpaqueConstantDataBuffer dbf = nativeOps.constantBufferLong(desiredType.toInt(), new LongPointer(values), values.length); + val dbf = nativeOps.constantBufferLong(desiredType.toInt(), new LongPointer(values), values.length); if (nativeOps.lastErrorCode() != 0) throw new RuntimeException(nativeOps.lastErrorMessage()); @@ -2207,7 +2207,7 @@ public class CudaExecutioner extends DefaultOpExecutioner { if (nativeOps.lastErrorCode() != 0) throw new RuntimeException(nativeOps.lastErrorMessage()); - OpaqueConstantDataBuffer dbf = nativeOps.constantBufferDouble(desiredType.toInt(), new DoublePointer(values), values.length); + val dbf = nativeOps.constantBufferDouble(desiredType.toInt(), new DoublePointer(values), values.length); if (nativeOps.lastErrorCode() != 0) throw new RuntimeException(nativeOps.lastErrorMessage()); diff --git a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/nativeblas/Nd4jCuda.java b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/nativeblas/Nd4jCuda.java index cc6ffc19a..38c7188f1 100644 --- a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/nativeblas/Nd4jCuda.java +++ b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/nativeblas/Nd4jCuda.java @@ -469,6 +469,73 @@ public class Nd4jCuda extends org.nd4j.nativeblas.Nd4jCudaHelper { // #endif //DEV_TESTS_DATABUFFER_H +// Parsed from array/PointerDeallocator.h + +/******************************************************************************* + * Copyright (c) 2019-2020 Konduit K.K. + * + * 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 SD_POINTERDEALLOCATOR_H_ +// #define SD_POINTERDEALLOCATOR_H_ + +// #include +// #include + + + +// #endif //SD_POINTERDEALLOCATOR_H_ + + +// Parsed from array/PointerWrapper.h + +/******************************************************************************* + * Copyright (c) 2019-2020 Konduit K.K. + * + * 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 SD_ARRAY_POINTER_H_ +// #define SD_ARRAY_POINTER_H_ + +// #include +// #include +// #include +// #include + // namespace sd + +// #endif //SD_ARRAY_POINTER_H_ + + // Parsed from array/ConstantDescriptor.h /******************************************************************************* @@ -581,6 +648,9 @@ public class Nd4jCuda extends org.nd4j.nativeblas.Nd4jCudaHelper { // #include // #include +// #include +// #include +// #include @Namespace("sd") @NoOffset public static class ConstantDataBuffer extends Pointer { static { Loader.load(); } /** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */ @@ -592,18 +662,16 @@ public class Nd4jCuda extends org.nd4j.nativeblas.Nd4jCudaHelper { return (ConstantDataBuffer)super.position(position); } - public ConstantDataBuffer(@Cast("Nd4jPointer") Pointer primary, @Cast("Nd4jPointer") Pointer special, @Cast("Nd4jLong") long numEelements, @Cast("Nd4jLong") long sizeOf) { super((Pointer)null); allocate(primary, special, numEelements, sizeOf); } - private native void allocate(@Cast("Nd4jPointer") Pointer primary, @Cast("Nd4jPointer") Pointer special, @Cast("Nd4jLong") long numEelements, @Cast("Nd4jLong") long sizeOf); public ConstantDataBuffer(@Const @ByRef ConstantDataBuffer other) { super((Pointer)null); allocate(other); } private native void allocate(@Const @ByRef ConstantDataBuffer other); public ConstantDataBuffer() { super((Pointer)null); allocate(); } private native void allocate(); - public native @Cast("Nd4jLong") long sizeOf(); - public native @Cast("Nd4jLong") long length(); + public native @Cast("uint8_t") byte sizeOf(); + public native @Cast("uint64_t") long length(); - public native @Cast("Nd4jPointer") Pointer primary(); - public native @Cast("Nd4jPointer") Pointer special(); + public native Pointer primary(); + public native Pointer special(); public native @ByRef @Name("operator =") ConstantDataBuffer put(@Const @ByRef ConstantDataBuffer other); } @@ -612,6 +680,114 @@ public class Nd4jCuda extends org.nd4j.nativeblas.Nd4jCudaHelper { // #endif //DEV_TESTS_CONSTANTDATABUFFER_H +// Parsed from array/ConstantShapeBuffer.h + +/******************************************************************************* + * Copyright (c) 2019-2020 Konduit K.K. + * + * 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 SD_ARRAY_CONSTANTSHAPEBUFFER_H_ +// #define SD_ARRAY_CONSTANTSHAPEBUFFER_H_ + +// #include +// #include +// #include +// #include + +@Namespace("sd") public static class ConstantShapeBuffer extends Pointer { + static { Loader.load(); } + /** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */ + public ConstantShapeBuffer(Pointer p) { super(p); } + /** Native array allocator. Access with {@link Pointer#position(long)}. */ + public ConstantShapeBuffer(long size) { super((Pointer)null); allocateArray(size); } + private native void allocateArray(long size); + @Override public ConstantShapeBuffer position(long position) { + return (ConstantShapeBuffer)super.position(position); + } + + public ConstantShapeBuffer() { super((Pointer)null); allocate(); } + private native void allocate(); + + public native @Cast("const Nd4jLong*") LongPointer primary(); + public native @Cast("const Nd4jLong*") LongPointer special(); + public native @Cast("const Nd4jLong*") LongPointer platform(); +} + + // namespace sd + +// #endif //SD_ARRAY_CONSTANTSHAPEBUFFER_H_ + + +// Parsed from array/ConstantOffsetsBuffer.h + +/******************************************************************************* + * Copyright (c) 2019-2020 Konduit K.K. + * + * 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 SD_ARRAY_CONSTANTOFFSETSBUFFER_H_ +// #define SD_ARRAY_CONSTANTOFFSETSBUFFER_H_ + +// #include +// #include +// #include +// #include + +@Namespace("sd") public static class ConstantOffsetsBuffer extends Pointer { + static { Loader.load(); } + /** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */ + public ConstantOffsetsBuffer(Pointer p) { super(p); } + /** Native array allocator. Access with {@link Pointer#position(long)}. */ + public ConstantOffsetsBuffer(long size) { super((Pointer)null); allocateArray(size); } + private native void allocateArray(long size); + @Override public ConstantOffsetsBuffer position(long position) { + return (ConstantOffsetsBuffer)super.position(position); + } + + public ConstantOffsetsBuffer() { super((Pointer)null); allocate(); } + private native void allocate(); + + public native @Cast("const Nd4jLong*") LongPointer primary(); + public native @Cast("const Nd4jLong*") LongPointer special(); + public native @Cast("const Nd4jLong*") LongPointer platform(); +} + + // namespace sd + +// #endif //SD_ARRAY_CONSTANTOFFSETSBUFFER_H_ + + // Parsed from array/TadPack.h /******************************************************************************* @@ -637,7 +813,8 @@ public class Nd4jCuda extends org.nd4j.nativeblas.Nd4jCudaHelper { // #ifndef DEV_TESTS_TADPACK_H // #define DEV_TESTS_TADPACK_H -// #include "ConstantDataBuffer.h" +// #include +// #include @Namespace("sd") @NoOffset public static class TadPack extends Pointer { static { Loader.load(); } /** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */ @@ -649,8 +826,8 @@ public class Nd4jCuda extends org.nd4j.nativeblas.Nd4jCudaHelper { return (TadPack)super.position(position); } - public TadPack(@ByRef ConstantDataBuffer shapes, @ByRef ConstantDataBuffer offets, @Cast("Nd4jLong") long numTads) { super((Pointer)null); allocate(shapes, offets, numTads); } - private native void allocate(@ByRef ConstantDataBuffer shapes, @ByRef ConstantDataBuffer offets, @Cast("Nd4jLong") long numTads); + public TadPack(@Const @ByRef ConstantShapeBuffer shapes, @Const @ByRef ConstantOffsetsBuffer offets, @Cast("Nd4jLong") long numTads) { super((Pointer)null); allocate(shapes, offets, numTads); } + private native void allocate(@Const @ByRef ConstantShapeBuffer shapes, @Const @ByRef ConstantOffsetsBuffer offets, @Cast("Nd4jLong") long numTads); public TadPack() { super((Pointer)null); allocate(); } private native void allocate(); @@ -859,7 +1036,7 @@ public class Nd4jCuda extends org.nd4j.nativeblas.Nd4jCudaHelper { public native int _blasMinorVersion(); public native Environment _blasMinorVersion(int setter); public native int _blasPatchVersion(); public native Environment _blasPatchVersion(int setter); - public static native Environment getInstance(); + public static native @ByRef Environment getInstance(); public native @Cast("bool") boolean isVerbose(); public native void setVerbose(@Cast("bool") boolean reallyVerbose); @@ -3048,9 +3225,9 @@ public native void inspectArray(@Cast("Nd4jPointer*") PointerPointer extraPointe public native void inspectArray(@Cast("Nd4jPointer*") PointerPointer extraPointers, @Cast("Nd4jPointer") Pointer buffer, @Cast("Nd4jLong*") LongBuffer shapeInfo, @Cast("Nd4jPointer") Pointer specialBuffer, @Cast("Nd4jLong*") LongBuffer specialShapeInfo, @Cast("Nd4jPointer") Pointer debugInfo); public native void inspectArray(@Cast("Nd4jPointer*") PointerPointer extraPointers, @Cast("Nd4jPointer") Pointer buffer, @Cast("Nd4jLong*") long[] shapeInfo, @Cast("Nd4jPointer") Pointer specialBuffer, @Cast("Nd4jLong*") long[] specialShapeInfo, @Cast("Nd4jPointer") Pointer debugInfo); -public native OpaqueConstantDataBuffer shapeBuffer(int rank, @Cast("Nd4jLong*") LongPointer shape, @Cast("Nd4jLong*") LongPointer strides, @Cast("sd::DataType") int dtype, char order, @Cast("Nd4jLong") long ews, @Cast("bool") boolean empty); -public native OpaqueConstantDataBuffer shapeBuffer(int rank, @Cast("Nd4jLong*") LongBuffer shape, @Cast("Nd4jLong*") LongBuffer strides, @Cast("sd::DataType") int dtype, char order, @Cast("Nd4jLong") long ews, @Cast("bool") boolean empty); -public native OpaqueConstantDataBuffer shapeBuffer(int rank, @Cast("Nd4jLong*") long[] shape, @Cast("Nd4jLong*") long[] strides, @Cast("sd::DataType") int dtype, char order, @Cast("Nd4jLong") long ews, @Cast("bool") boolean empty); +public native OpaqueConstantShapeBuffer shapeBuffer(int rank, @Cast("Nd4jLong*") LongPointer shape, @Cast("Nd4jLong*") LongPointer strides, @Cast("sd::DataType") int dtype, char order, @Cast("Nd4jLong") long ews, @Cast("bool") boolean empty); +public native OpaqueConstantShapeBuffer shapeBuffer(int rank, @Cast("Nd4jLong*") LongBuffer shape, @Cast("Nd4jLong*") LongBuffer strides, @Cast("sd::DataType") int dtype, char order, @Cast("Nd4jLong") long ews, @Cast("bool") boolean empty); +public native OpaqueConstantShapeBuffer shapeBuffer(int rank, @Cast("Nd4jLong*") long[] shape, @Cast("Nd4jLong*") long[] strides, @Cast("sd::DataType") int dtype, char order, @Cast("Nd4jLong") long ews, @Cast("bool") boolean empty); public native OpaqueConstantDataBuffer constantBufferLong(@Cast("sd::DataType") int dtype, @Cast("const Nd4jLong*") LongPointer data, int length); public native OpaqueConstantDataBuffer constantBufferLong(@Cast("sd::DataType") int dtype, @Cast("const Nd4jLong*") LongBuffer data, int length); @@ -3063,9 +3240,12 @@ public native OpaqueConstantDataBuffer constantBuffer(@Cast("sd::DataType") int public native @Cast("Nd4jPointer") Pointer getConstantDataBufferPrimary(OpaqueConstantDataBuffer dbf); public native @Cast("Nd4jPointer") Pointer getConstantDataBufferSpecial(OpaqueConstantDataBuffer dbf); public native @Cast("Nd4jLong") long getConstantDataBufferLength(OpaqueConstantDataBuffer dbf); -public native @Cast("Nd4jLong") long getConstantDataBufferSizeOf(OpaqueConstantDataBuffer dbf); -public native void deleteShapeBuffer(OpaqueConstantDataBuffer ptr); +public native @Cast("Nd4jPointer") Pointer getConstantShapeBufferPrimary(OpaqueConstantShapeBuffer dbf); +public native @Cast("Nd4jPointer") Pointer getConstantShapeBufferSpecial(OpaqueConstantShapeBuffer dbf); + +public native void deleteConstantShapeBuffer(OpaqueConstantShapeBuffer ptr); +public native void deleteConstantDataBuffer(OpaqueConstantDataBuffer ptr); public native OpaqueContext createGraphContext(int nodeId); public native OpaqueRandomGenerator getGraphContextRandomGenerator(OpaqueContext ptr); @@ -3639,6 +3819,7 @@ public native @Cast("bool") boolean isOptimalRequirementsMet(); // #include // #include // #include +// #include @@ -4478,7 +4659,7 @@ public native @Cast("bool") boolean isOptimalRequirementsMet(); public native void setShapeInfo(@Cast("const Nd4jLong*") LongBuffer shapeInfo, @Cast("const sd::DataType") int dtype); public native void setShapeInfo(@Cast("const Nd4jLong*") long[] shapeInfo, @Cast("const sd::DataType") int dtype); public native void setShapeInfo(@Const @ByRef ShapeDescriptor descriptor); - public native void setShapeInfo(@Const @ByRef ConstantDataBuffer shapeBuffer); + public native void setShapeInfo(@Const @ByRef ConstantShapeBuffer shapeBuffer); /** * returns absolute offset which corresponds to given sequential index @@ -7202,13 +7383,13 @@ public static final int PREALLOC_SIZE = 33554432; * @param rank the rank of the shape */ - @Namespace("shape") public static native int isMatrix(@Cast("Nd4jLong*") LongPointer shape, int rank); - @Namespace("shape") public static native int isMatrix(@Cast("Nd4jLong*") LongBuffer shape, int rank); - @Namespace("shape") public static native int isMatrix(@Cast("Nd4jLong*") long[] shape, int rank); + @Namespace("shape") public static native int isMatrix(@Cast("const Nd4jLong*") LongPointer shape, int rank); + @Namespace("shape") public static native int isMatrix(@Cast("const Nd4jLong*") LongBuffer shape, int rank); + @Namespace("shape") public static native int isMatrix(@Cast("const Nd4jLong*") long[] shape, int rank); - @Namespace("shape") public static native int isMatrix(@Cast("Nd4jLong*") LongPointer shapeInfo); - @Namespace("shape") public static native int isMatrix(@Cast("Nd4jLong*") LongBuffer shapeInfo); - @Namespace("shape") public static native int isMatrix(@Cast("Nd4jLong*") long[] shapeInfo); + @Namespace("shape") public static native int isMatrix(@Cast("const Nd4jLong*") LongPointer shapeInfo); + @Namespace("shape") public static native int isMatrix(@Cast("const Nd4jLong*") LongBuffer shapeInfo); + @Namespace("shape") public static native int isMatrix(@Cast("const Nd4jLong*") long[] shapeInfo); /** * Returns the shape portion of an information * buffer @@ -10143,7 +10324,7 @@ public static final int PREALLOC_SIZE = 33554432; public OpRegistrator(Pointer p) { super(p); } - public static native OpRegistrator getInstance(); + public static native @ByRef OpRegistrator getInstance(); public static native void exitHandler(); public static native void sigIntHandler(int sig); diff --git a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/nativeblas/Nd4jCudaPresets.java b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/nativeblas/Nd4jCudaPresets.java index 05b335c87..6ac8e133a 100644 --- a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/nativeblas/Nd4jCudaPresets.java +++ b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/nativeblas/Nd4jCudaPresets.java @@ -34,8 +34,12 @@ import org.bytedeco.javacpp.tools.InfoMapper; value = {@Platform(define = "LIBND4J_ALL_OPS", include = { "array/DataType.h", "array/DataBuffer.h", + "array/PointerDeallocator.h", + "array/PointerWrapper.h", "array/ConstantDescriptor.h", "array/ConstantDataBuffer.h", + "array/ConstantShapeBuffer.h", + "array/ConstantOffsetsBuffer.h", "array/TadPack.h", "execution/ErrorReference.h", "execution/Engine.h", @@ -166,6 +170,8 @@ public class Nd4jCudaPresets implements LoadEnabled, InfoMapper { .put(new Info("OpaqueVariablesSet").pointerTypes("OpaqueVariablesSet")) .put(new Info("OpaqueVariable").pointerTypes("OpaqueVariable")) .put(new Info("OpaqueConstantDataBuffer").pointerTypes("OpaqueConstantDataBuffer")) + .put(new Info("OpaqueConstantShapeBuffer").pointerTypes("OpaqueConstantShapeBuffer")) + .put(new Info("OpaqueConstantOffsetsBuffer").pointerTypes("OpaqueConstantOffsetsBuffer")) .put(new Info("OpaqueContext").pointerTypes("OpaqueContext")) .put(new Info("OpaqueRandomGenerator").pointerTypes("OpaqueRandomGenerator")) .put(new Info("OpaqueLaunchContext").pointerTypes("OpaqueLaunchContext")) @@ -187,7 +193,7 @@ public class Nd4jCudaPresets implements LoadEnabled, InfoMapper { infoMap.put(new Info("__CUDACC__", "MAX_UINT", "HAVE_MKLDNN").define(false)) .put(new Info("__JAVACPP_HACK__", "LIBND4J_ALL_OPS","__CUDABLAS__").define(true)) .put(new Info("std::initializer_list", "cnpy::NpyArray", "sd::NDArray::applyLambda", "sd::NDArray::applyPairwiseLambda", - "sd::graph::FlatResult", "sd::graph::FlatVariable", "sd::NDArray::subarray").skip()) + "sd::graph::FlatResult", "sd::graph::FlatVariable", "sd::NDArray::subarray", "std::shared_ptr", "sd::PointerWrapper", "sd::PointerDeallocator").skip()) .put(new Info("std::string").annotations("@StdString").valueTypes("BytePointer", "String") .pointerTypes("@Cast({\"char*\", \"std::string*\"}) BytePointer")) .put(new Info("std::pair").pointerTypes("IntIntPair").define()) diff --git a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/ops/NativeOpExecutioner.java b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/ops/NativeOpExecutioner.java index 508144f26..5e12f1dfd 100644 --- a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/ops/NativeOpExecutioner.java +++ b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/ops/NativeOpExecutioner.java @@ -2018,13 +2018,13 @@ public class NativeOpExecutioner extends DefaultOpExecutioner { @Override public DataBuffer createShapeInfo(long[] shape, long[] stride, long elementWiseStride, char order, DataType dtype, boolean empty) { - OpaqueConstantDataBuffer dbf = loop.shapeBuffer(shape.length, new LongPointer(shape), new LongPointer(stride), dtype.toInt(), order, elementWiseStride, empty); + val dbf = loop.shapeBuffer(shape.length, new LongPointer(shape), new LongPointer(stride), dtype.toInt(), order, elementWiseStride, empty); if (loop.lastErrorCode() != 0) throw new RuntimeException(loop.lastErrorMessage()); - val result = new LongBuffer(loop.getConstantDataBufferPrimary(dbf), Shape.shapeInfoLength(shape.length)); + val result = new LongBuffer(loop.getConstantShapeBufferPrimary(dbf), Shape.shapeInfoLength(shape.length)); - loop.deleteShapeBuffer(dbf); + loop.deleteConstantShapeBuffer(dbf); return result; } diff --git a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/nativeblas/Nd4jCpu.java b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/nativeblas/Nd4jCpu.java index f17f11093..2926c06b9 100644 --- a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/nativeblas/Nd4jCpu.java +++ b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/nativeblas/Nd4jCpu.java @@ -491,6 +491,73 @@ public class Nd4jCpu extends org.nd4j.nativeblas.Nd4jCpuHelper { // #endif //DEV_TESTS_DATABUFFER_H +// Parsed from array/PointerDeallocator.h + +/******************************************************************************* + * Copyright (c) 2019-2020 Konduit K.K. + * + * 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 SD_POINTERDEALLOCATOR_H_ +// #define SD_POINTERDEALLOCATOR_H_ + +// #include +// #include + + + +// #endif //SD_POINTERDEALLOCATOR_H_ + + +// Parsed from array/PointerWrapper.h + +/******************************************************************************* + * Copyright (c) 2019-2020 Konduit K.K. + * + * 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 SD_ARRAY_POINTER_H_ +// #define SD_ARRAY_POINTER_H_ + +// #include +// #include +// #include +// #include + // namespace sd + +// #endif //SD_ARRAY_POINTER_H_ + + // Parsed from array/ConstantDataBuffer.h /******************************************************************************* @@ -517,6 +584,9 @@ public class Nd4jCpu extends org.nd4j.nativeblas.Nd4jCpuHelper { // #include // #include +// #include +// #include +// #include @Namespace("sd") @NoOffset public static class ConstantDataBuffer extends Pointer { static { Loader.load(); } /** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */ @@ -528,18 +598,16 @@ public class Nd4jCpu extends org.nd4j.nativeblas.Nd4jCpuHelper { return (ConstantDataBuffer)super.position(position); } - public ConstantDataBuffer(@Cast("Nd4jPointer") Pointer primary, @Cast("Nd4jPointer") Pointer special, @Cast("Nd4jLong") long numEelements, @Cast("Nd4jLong") long sizeOf) { super((Pointer)null); allocate(primary, special, numEelements, sizeOf); } - private native void allocate(@Cast("Nd4jPointer") Pointer primary, @Cast("Nd4jPointer") Pointer special, @Cast("Nd4jLong") long numEelements, @Cast("Nd4jLong") long sizeOf); public ConstantDataBuffer(@Const @ByRef ConstantDataBuffer other) { super((Pointer)null); allocate(other); } private native void allocate(@Const @ByRef ConstantDataBuffer other); public ConstantDataBuffer() { super((Pointer)null); allocate(); } private native void allocate(); - public native @Cast("Nd4jLong") long sizeOf(); - public native @Cast("Nd4jLong") long length(); + public native @Cast("uint8_t") byte sizeOf(); + public native @Cast("uint64_t") long length(); - public native @Cast("Nd4jPointer") Pointer primary(); - public native @Cast("Nd4jPointer") Pointer special(); + public native Pointer primary(); + public native Pointer special(); public native @ByRef @Name("operator =") ConstantDataBuffer put(@Const @ByRef ConstantDataBuffer other); } @@ -548,6 +616,114 @@ public class Nd4jCpu extends org.nd4j.nativeblas.Nd4jCpuHelper { // #endif //DEV_TESTS_CONSTANTDATABUFFER_H +// Parsed from array/ConstantShapeBuffer.h + +/******************************************************************************* + * Copyright (c) 2019-2020 Konduit K.K. + * + * 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 SD_ARRAY_CONSTANTSHAPEBUFFER_H_ +// #define SD_ARRAY_CONSTANTSHAPEBUFFER_H_ + +// #include +// #include +// #include +// #include + +@Namespace("sd") public static class ConstantShapeBuffer extends Pointer { + static { Loader.load(); } + /** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */ + public ConstantShapeBuffer(Pointer p) { super(p); } + /** Native array allocator. Access with {@link Pointer#position(long)}. */ + public ConstantShapeBuffer(long size) { super((Pointer)null); allocateArray(size); } + private native void allocateArray(long size); + @Override public ConstantShapeBuffer position(long position) { + return (ConstantShapeBuffer)super.position(position); + } + + public ConstantShapeBuffer() { super((Pointer)null); allocate(); } + private native void allocate(); + + public native @Cast("const Nd4jLong*") LongPointer primary(); + public native @Cast("const Nd4jLong*") LongPointer special(); + public native @Cast("const Nd4jLong*") LongPointer platform(); +} + + // namespace sd + +// #endif //SD_ARRAY_CONSTANTSHAPEBUFFER_H_ + + +// Parsed from array/ConstantOffsetsBuffer.h + +/******************************************************************************* + * Copyright (c) 2019-2020 Konduit K.K. + * + * 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 SD_ARRAY_CONSTANTOFFSETSBUFFER_H_ +// #define SD_ARRAY_CONSTANTOFFSETSBUFFER_H_ + +// #include +// #include +// #include +// #include + +@Namespace("sd") public static class ConstantOffsetsBuffer extends Pointer { + static { Loader.load(); } + /** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */ + public ConstantOffsetsBuffer(Pointer p) { super(p); } + /** Native array allocator. Access with {@link Pointer#position(long)}. */ + public ConstantOffsetsBuffer(long size) { super((Pointer)null); allocateArray(size); } + private native void allocateArray(long size); + @Override public ConstantOffsetsBuffer position(long position) { + return (ConstantOffsetsBuffer)super.position(position); + } + + public ConstantOffsetsBuffer() { super((Pointer)null); allocate(); } + private native void allocate(); + + public native @Cast("const Nd4jLong*") LongPointer primary(); + public native @Cast("const Nd4jLong*") LongPointer special(); + public native @Cast("const Nd4jLong*") LongPointer platform(); +} + + // namespace sd + +// #endif //SD_ARRAY_CONSTANTOFFSETSBUFFER_H_ + + // Parsed from array/ConstantDescriptor.h /******************************************************************************* @@ -659,7 +835,8 @@ public class Nd4jCpu extends org.nd4j.nativeblas.Nd4jCpuHelper { // #ifndef DEV_TESTS_TADPACK_H // #define DEV_TESTS_TADPACK_H -// #include "ConstantDataBuffer.h" +// #include +// #include @Namespace("sd") @NoOffset public static class TadPack extends Pointer { static { Loader.load(); } /** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */ @@ -671,8 +848,8 @@ public class Nd4jCpu extends org.nd4j.nativeblas.Nd4jCpuHelper { return (TadPack)super.position(position); } - public TadPack(@ByRef ConstantDataBuffer shapes, @ByRef ConstantDataBuffer offets, @Cast("Nd4jLong") long numTads) { super((Pointer)null); allocate(shapes, offets, numTads); } - private native void allocate(@ByRef ConstantDataBuffer shapes, @ByRef ConstantDataBuffer offets, @Cast("Nd4jLong") long numTads); + public TadPack(@Const @ByRef ConstantShapeBuffer shapes, @Const @ByRef ConstantOffsetsBuffer offets, @Cast("Nd4jLong") long numTads) { super((Pointer)null); allocate(shapes, offets, numTads); } + private native void allocate(@Const @ByRef ConstantShapeBuffer shapes, @Const @ByRef ConstantOffsetsBuffer offets, @Cast("Nd4jLong") long numTads); public TadPack() { super((Pointer)null); allocate(); } private native void allocate(); @@ -863,7 +1040,7 @@ public class Nd4jCpu extends org.nd4j.nativeblas.Nd4jCpuHelper { public native int _blasMinorVersion(); public native Environment _blasMinorVersion(int setter); public native int _blasPatchVersion(); public native Environment _blasPatchVersion(int setter); - public static native Environment getInstance(); + public static native @ByRef Environment getInstance(); public native @Cast("bool") boolean isVerbose(); public native void setVerbose(@Cast("bool") boolean reallyVerbose); @@ -3052,9 +3229,9 @@ public native void inspectArray(@Cast("Nd4jPointer*") PointerPointer extraPointe public native void inspectArray(@Cast("Nd4jPointer*") PointerPointer extraPointers, @Cast("Nd4jPointer") Pointer buffer, @Cast("Nd4jLong*") LongBuffer shapeInfo, @Cast("Nd4jPointer") Pointer specialBuffer, @Cast("Nd4jLong*") LongBuffer specialShapeInfo, @Cast("Nd4jPointer") Pointer debugInfo); public native void inspectArray(@Cast("Nd4jPointer*") PointerPointer extraPointers, @Cast("Nd4jPointer") Pointer buffer, @Cast("Nd4jLong*") long[] shapeInfo, @Cast("Nd4jPointer") Pointer specialBuffer, @Cast("Nd4jLong*") long[] specialShapeInfo, @Cast("Nd4jPointer") Pointer debugInfo); -public native OpaqueConstantDataBuffer shapeBuffer(int rank, @Cast("Nd4jLong*") LongPointer shape, @Cast("Nd4jLong*") LongPointer strides, @Cast("sd::DataType") int dtype, char order, @Cast("Nd4jLong") long ews, @Cast("bool") boolean empty); -public native OpaqueConstantDataBuffer shapeBuffer(int rank, @Cast("Nd4jLong*") LongBuffer shape, @Cast("Nd4jLong*") LongBuffer strides, @Cast("sd::DataType") int dtype, char order, @Cast("Nd4jLong") long ews, @Cast("bool") boolean empty); -public native OpaqueConstantDataBuffer shapeBuffer(int rank, @Cast("Nd4jLong*") long[] shape, @Cast("Nd4jLong*") long[] strides, @Cast("sd::DataType") int dtype, char order, @Cast("Nd4jLong") long ews, @Cast("bool") boolean empty); +public native OpaqueConstantShapeBuffer shapeBuffer(int rank, @Cast("Nd4jLong*") LongPointer shape, @Cast("Nd4jLong*") LongPointer strides, @Cast("sd::DataType") int dtype, char order, @Cast("Nd4jLong") long ews, @Cast("bool") boolean empty); +public native OpaqueConstantShapeBuffer shapeBuffer(int rank, @Cast("Nd4jLong*") LongBuffer shape, @Cast("Nd4jLong*") LongBuffer strides, @Cast("sd::DataType") int dtype, char order, @Cast("Nd4jLong") long ews, @Cast("bool") boolean empty); +public native OpaqueConstantShapeBuffer shapeBuffer(int rank, @Cast("Nd4jLong*") long[] shape, @Cast("Nd4jLong*") long[] strides, @Cast("sd::DataType") int dtype, char order, @Cast("Nd4jLong") long ews, @Cast("bool") boolean empty); public native OpaqueConstantDataBuffer constantBufferLong(@Cast("sd::DataType") int dtype, @Cast("const Nd4jLong*") LongPointer data, int length); public native OpaqueConstantDataBuffer constantBufferLong(@Cast("sd::DataType") int dtype, @Cast("const Nd4jLong*") LongBuffer data, int length); @@ -3067,9 +3244,12 @@ public native OpaqueConstantDataBuffer constantBuffer(@Cast("sd::DataType") int public native @Cast("Nd4jPointer") Pointer getConstantDataBufferPrimary(OpaqueConstantDataBuffer dbf); public native @Cast("Nd4jPointer") Pointer getConstantDataBufferSpecial(OpaqueConstantDataBuffer dbf); public native @Cast("Nd4jLong") long getConstantDataBufferLength(OpaqueConstantDataBuffer dbf); -public native @Cast("Nd4jLong") long getConstantDataBufferSizeOf(OpaqueConstantDataBuffer dbf); -public native void deleteShapeBuffer(OpaqueConstantDataBuffer ptr); +public native @Cast("Nd4jPointer") Pointer getConstantShapeBufferPrimary(OpaqueConstantShapeBuffer dbf); +public native @Cast("Nd4jPointer") Pointer getConstantShapeBufferSpecial(OpaqueConstantShapeBuffer dbf); + +public native void deleteConstantShapeBuffer(OpaqueConstantShapeBuffer ptr); +public native void deleteConstantDataBuffer(OpaqueConstantDataBuffer ptr); public native OpaqueContext createGraphContext(int nodeId); public native OpaqueRandomGenerator getGraphContextRandomGenerator(OpaqueContext ptr); @@ -3643,6 +3823,7 @@ public native @Cast("bool") boolean isOptimalRequirementsMet(); // #include // #include // #include +// #include @@ -4482,7 +4663,7 @@ public native @Cast("bool") boolean isOptimalRequirementsMet(); public native void setShapeInfo(@Cast("const Nd4jLong*") LongBuffer shapeInfo, @Cast("const sd::DataType") int dtype); public native void setShapeInfo(@Cast("const Nd4jLong*") long[] shapeInfo, @Cast("const sd::DataType") int dtype); public native void setShapeInfo(@Const @ByRef ShapeDescriptor descriptor); - public native void setShapeInfo(@Const @ByRef ConstantDataBuffer shapeBuffer); + public native void setShapeInfo(@Const @ByRef ConstantShapeBuffer shapeBuffer); /** * returns absolute offset which corresponds to given sequential index @@ -7206,13 +7387,13 @@ public static final int PREALLOC_SIZE = 33554432; * @param rank the rank of the shape */ - @Namespace("shape") public static native int isMatrix(@Cast("Nd4jLong*") LongPointer shape, int rank); - @Namespace("shape") public static native int isMatrix(@Cast("Nd4jLong*") LongBuffer shape, int rank); - @Namespace("shape") public static native int isMatrix(@Cast("Nd4jLong*") long[] shape, int rank); + @Namespace("shape") public static native int isMatrix(@Cast("const Nd4jLong*") LongPointer shape, int rank); + @Namespace("shape") public static native int isMatrix(@Cast("const Nd4jLong*") LongBuffer shape, int rank); + @Namespace("shape") public static native int isMatrix(@Cast("const Nd4jLong*") long[] shape, int rank); - @Namespace("shape") public static native int isMatrix(@Cast("Nd4jLong*") LongPointer shapeInfo); - @Namespace("shape") public static native int isMatrix(@Cast("Nd4jLong*") LongBuffer shapeInfo); - @Namespace("shape") public static native int isMatrix(@Cast("Nd4jLong*") long[] shapeInfo); + @Namespace("shape") public static native int isMatrix(@Cast("const Nd4jLong*") LongPointer shapeInfo); + @Namespace("shape") public static native int isMatrix(@Cast("const Nd4jLong*") LongBuffer shapeInfo); + @Namespace("shape") public static native int isMatrix(@Cast("const Nd4jLong*") long[] shapeInfo); /** * Returns the shape portion of an information * buffer @@ -10072,10 +10253,10 @@ public static final int ALL_FLOATS =BFLOAT16; // #endif -public static native @MemberGetter int ELEMENT_THRESHOLD(); -public static final int ELEMENT_THRESHOLD = ELEMENT_THRESHOLD(); -public static native @MemberGetter int TAD_THRESHOLD(); -public static final int TAD_THRESHOLD = TAD_THRESHOLD(); +public static native @MemberGetter double ELEMENT_THRESHOLD(); +public static final double ELEMENT_THRESHOLD = ELEMENT_THRESHOLD(); +public static native @MemberGetter double TAD_THRESHOLD(); +public static final double TAD_THRESHOLD = TAD_THRESHOLD(); // #define SHAPELIST(...) new ShapeList({__VA_ARGS__}, block.workspace() != nullptr) @@ -10085,8 +10266,8 @@ public static final int TAD_THRESHOLD = TAD_THRESHOLD(); // #define PRINT_FIRST(...) printf(__VA_ARGS__); fflush(stdout) // #endif -// #define DEBUG_CALL(STREAM) if (sd::Environment::getInstance()->isDebug()) { cudaError_t tRes = cudaStreamSynchronize(*STREAM); checkCudaErrors(tRes); if (tRes != 0) { throw std::runtime_error(); }; } -// #define DEBUG_KERNEL(STREAM, OP_NUM) if (sd::Environment::getInstance()->isDebug()) { cudaError_t tRes = cudaStreamSynchronize(*STREAM); checkCudaErrors(tRes); if (tRes != 0) {std::string tFile(__FILE__); std::string tOp = "Kernel OpNum failed: [" + sd::StringUtils::valueToString(OP_NUM) + std::string("]; File: ") + tFile + std::string(":") + sd::StringUtils::valueToString(__LINE__); throw std::runtime_error(tOp.c_str()); }; } +// #define DEBUG_CALL(STREAM) if (sd::Environment::getInstance().isDebug()) { cudaError_t tRes = cudaStreamSynchronize(*STREAM); checkCudaErrors(tRes); if (tRes != 0) { throw std::runtime_error(); }; } +// #define DEBUG_KERNEL(STREAM, OP_NUM) if (sd::Environment::getInstance().isDebug()) { cudaError_t tRes = cudaStreamSynchronize(*STREAM); checkCudaErrors(tRes); if (tRes != 0) {std::string tFile(__FILE__); std::string tOp = "Kernel OpNum failed: [" + sd::StringUtils::valueToString(OP_NUM) + std::string("]; File: ") + tFile + std::string(":") + sd::StringUtils::valueToString(__LINE__); throw std::runtime_error(tOp.c_str()); }; } // #define LAUNCH(A, B, C, D) <<>> @@ -11067,7 +11248,7 @@ public static final int TAD_THRESHOLD = TAD_THRESHOLD(); // #define _EXPAND_OP_CALL_1(NAME, TYPE, PARAMZ, NUM_A, TYPE_A) NAME>PARAMZ; // #define _EXPAND_OP_DIRECT(PARAMZ, NUM_A, TYPE_A) case NUM_A: { z = TYPE_A::op PARAMZ; break; } -// #define _EXPAND_OP_CALL_T(TYPE, NUM_A, TYPE_A) OpTracker::getInstance()->storeOperation(TYPE, #TYPE_A, NUM_A); +// #define _EXPAND_OP_CALL_T(TYPE, NUM_A, TYPE_A) OpTracker::getInstance().storeOperation(TYPE, #TYPE_A, NUM_A); // #define _EXPAND_FACTORY_CALL(TYPE, LAYER_ID, LAYER_NAME, ACTIVATION_ID, ACTIVATION_NAME) if (activationNum == ACTIVATION_ID && layerNum == LAYER_ID) { return new LAYER_NAME>(); }; @@ -11209,7 +11390,7 @@ public static final int TAD_THRESHOLD = TAD_THRESHOLD(); // struct __registrator_##NAME { // __registrator_##NAME() { // OpName *ptr = new OpName(); -// OpRegistrator::getInstance()->registerOperation(ptr); +// OpRegistrator::getInstance().registerOperation(ptr); // } // }; // static sd::ops::__registrator_##NAME zzz_register_opd_##NAME; @@ -11277,7 +11458,7 @@ public static final int TAD_THRESHOLD = TAD_THRESHOLD(); // auto shapeList = SHAPELIST(); // auto opLimit = this->getOpDescriptor()->getNumberOfOutputs() < 1 ? block.width() : this->getOpDescriptor()->getNumberOfOutputs(); // for (int e = 0; e < opLimit; e++) { -// auto newshape = ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(inputShape->at(e)), shape::order(inputShape->at(e)), shape::rank(inputShape->at(e)), shape::shapeOf(inputShape->at(e))); +// auto newshape = ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(inputShape->at(e)), shape::order(inputShape->at(e)), shape::rank(inputShape->at(e)), shape::shapeOf(inputShape->at(e))); // shapeList->push_back(newshape); // } // return shapeList; @@ -11288,14 +11469,14 @@ public static final int TAD_THRESHOLD = TAD_THRESHOLD(); // #define DECLARE_SYN(NAME, ORIGINAL) template // struct __registratorSynonym_##NAME { // __registratorSynonym_##NAME(const char *name, const char *oname) { -// auto ptr = reinterpret_cast(OpRegistrator::getInstance()->getOperation(oname)); +// auto ptr = reinterpret_cast(OpRegistrator::getInstance().getOperation(oname)); // if (ptr == nullptr) { // std::string newName(name); // std::string oldName(oname); -// OpRegistrator::getInstance()->updateMSVC(sd::ops::HashHelper::getInstance()->getLongHash(newName), oldName); +// OpRegistrator::getInstance().pdateMSVC(sd::ops::HashHelper::getInstance().getLongHash(newName), oldName); // return; // } -// OpRegistrator::getInstance()->registerOperation(name, ptr); +// OpRegistrator::getInstance().registerOperation(name, ptr); // } // }; // static sd::ops::__registratorSynonym_##NAME zzz_register_opd_##NAME(#NAME, #ORIGINAL) @@ -11339,7 +11520,7 @@ public static final int TAD_THRESHOLD = TAD_THRESHOLD(); // auto shapeList = SHAPELIST(); // auto opLimit = this->getOpDescriptor()->getNumberOfOutputs() < 1 ? block.width() : this->getOpDescriptor()->getNumberOfOutputs(); // for (int e = 0; e < opLimit; e++) { -// auto newshape = ConstantShapeHelper::getInstance()->createShapeInfo(ArrayOptions::dataType(inputShape->at(e)), shape::order(inputShape->at(e)), shape::rank(inputShape->at(e)), shape::shapeOf(inputShape->at(e))); +// auto newshape = ConstantShapeHelper::getInstance().createShapeInfo(ArrayOptions::dataType(inputShape->at(e)), shape::order(inputShape->at(e)), shape::rank(inputShape->at(e)), shape::shapeOf(inputShape->at(e))); // shapeList->push_back(newshape); // } // return shapeList; @@ -11434,12 +11615,12 @@ public static final int TAD_THRESHOLD = TAD_THRESHOLD(); // #else -// #define ALLOCATE(VARIABLE, WORKSPACE, LENGTH, TT) if (WORKSPACE == nullptr) {VARIABLE = new TT[LENGTH]; sd::memory::MemoryTracker::getInstance()->countIn(sd::memory::MemoryType::HOST, VARIABLE, LENGTH * sizeof(TT)); } else {VARIABLE = reinterpret_cast(WORKSPACE->allocateBytes(LENGTH * sizeof(TT))); }; memset(VARIABLE, 0, LENGTH * sizeof(TT)); -// #define RELEASE(VARIABLE, WORKSPACE) if (WORKSPACE == nullptr) { sd::memory::MemoryTracker::getInstance()->countOut(VARIABLE); delete[] VARIABLE;}; +// #define ALLOCATE(VARIABLE, WORKSPACE, LENGTH, TT) if (WORKSPACE == nullptr) {VARIABLE = new TT[LENGTH]; sd::memory::MemoryTracker::getInstance().countIn(sd::memory::MemoryType::HOST, VARIABLE, LENGTH * sizeof(TT)); } else {VARIABLE = reinterpret_cast(WORKSPACE->allocateBytes(LENGTH * sizeof(TT))); }; memset(VARIABLE, 0, LENGTH * sizeof(TT)); +// #define RELEASE(VARIABLE, WORKSPACE) if (WORKSPACE == nullptr) { sd::memory::MemoryTracker::getInstance().countOut(VARIABLE); delete[] VARIABLE;}; // #endif -// #define CONSTANT(SHAPE) ConstantShapeHelper::getInstance()->createFromExisting(SHAPE, block.workspace()) +// #define CONSTANT(SHAPE) ConstantShapeHelper::getInstance().createFromExisting(SHAPE, block.workspace()) @@ -12372,7 +12553,7 @@ public static final int TAD_THRESHOLD = TAD_THRESHOLD(); public OpRegistrator(Pointer p) { super(p); } - public static native OpRegistrator getInstance(); + public static native @ByRef OpRegistrator getInstance(); public static native void exitHandler(); public static native void sigIntHandler(int sig); diff --git a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/nativeblas/Nd4jCpuPresets.java b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/nativeblas/Nd4jCpuPresets.java index c6e57e876..f10410314 100644 --- a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/nativeblas/Nd4jCpuPresets.java +++ b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/nativeblas/Nd4jCpuPresets.java @@ -37,7 +37,11 @@ import java.util.Scanner; "memory/MemoryType.h", "array/DataType.h", "array/DataBuffer.h", + "array/PointerDeallocator.h", + "array/PointerWrapper.h", "array/ConstantDataBuffer.h", + "array/ConstantShapeBuffer.h", + "array/ConstantOffsetsBuffer.h", "array/ConstantDescriptor.h", "array/TadPack.h", "execution/ErrorReference.h", @@ -164,6 +168,8 @@ public class Nd4jCpuPresets implements InfoMapper, BuildEnabled { .put(new Info("OpaqueVariablesSet").pointerTypes("OpaqueVariablesSet")) .put(new Info("OpaqueVariable").pointerTypes("OpaqueVariable")) .put(new Info("OpaqueConstantDataBuffer").pointerTypes("OpaqueConstantDataBuffer")) + .put(new Info("OpaqueConstantShapeBuffer").pointerTypes("OpaqueConstantShapeBuffer")) + .put(new Info("OpaqueConstantOffsetsBuffer").pointerTypes("OpaqueConstantOffsetsBuffer")) .put(new Info("OpaqueDataBuffer").pointerTypes("OpaqueDataBuffer")) .put(new Info("OpaqueContext").pointerTypes("OpaqueContext")) .put(new Info("OpaqueRandomGenerator").pointerTypes("OpaqueRandomGenerator")) @@ -185,7 +191,7 @@ public class Nd4jCpuPresets implements InfoMapper, BuildEnabled { infoMap.put(new Info("__CUDACC__", "MAX_UINT", "HAVE_MKLDNN", "__CUDABLAS__").define(false)) .put(new Info("__JAVACPP_HACK__", "LIBND4J_ALL_OPS").define(true)) .put(new Info("std::initializer_list", "cnpy::NpyArray", "sd::NDArray::applyLambda", "sd::NDArray::applyPairwiseLambda", - "sd::graph::FlatResult", "sd::graph::FlatVariable", "sd::NDArray::subarray").skip()) + "sd::graph::FlatResult", "sd::graph::FlatVariable", "sd::NDArray::subarray", "std::shared_ptr", "sd::PointerWrapper", "sd::PointerDeallocator").skip()) .put(new Info("std::string").annotations("@StdString").valueTypes("BytePointer", "String") .pointerTypes("@Cast({\"char*\", \"std::string*\"}) BytePointer")) .put(new Info("std::pair").pointerTypes("IntIntPair").define()) diff --git a/nd4j/nd4j-backends/nd4j-tests/src/test/java/org/nd4j/linalg/profiling/PerformanceTrackerTests.java b/nd4j/nd4j-backends/nd4j-tests/src/test/java/org/nd4j/linalg/profiling/PerformanceTrackerTests.java index b4dfe31f1..24ba20057 100644 --- a/nd4j/nd4j-backends/nd4j-tests/src/test/java/org/nd4j/linalg/profiling/PerformanceTrackerTests.java +++ b/nd4j/nd4j-backends/nd4j-tests/src/test/java/org/nd4j/linalg/profiling/PerformanceTrackerTests.java @@ -124,6 +124,7 @@ public class PerformanceTrackerTests extends BaseNd4jTest { } @Test + @Ignore("useless these days") public void testTrackerGpu_1() { if (!Nd4j.getExecutioner().getClass().getCanonicalName().toLowerCase().contains("cuda")) return;