2019-06-06 14:21:15 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (c) 2015-2018 Skymind, Inc.
|
|
|
|
*
|
|
|
|
* This program and the accompanying materials are made available under the
|
|
|
|
* terms of the Apache License, Version 2.0 which is available at
|
|
|
|
* https://www.apache.org/licenses/LICENSE-2.0.
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* scalar.h
|
|
|
|
*
|
|
|
|
* Created on: Dec 28, 2015
|
|
|
|
* Author: agibsonccc
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SCALAR_BOOL_H_
|
|
|
|
#define SCALAR_BOOL_H_
|
2020-03-02 10:49:41 +01:00
|
|
|
#include <system/dll.h>
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
#ifdef __JNI__
|
|
|
|
#include <jni.h>
|
|
|
|
#endif
|
2020-03-02 10:49:41 +01:00
|
|
|
#include <math/templatemath.h>
|
2019-06-06 14:21:15 +02:00
|
|
|
#include <ops/ops.h>
|
2020-03-02 10:49:41 +01:00
|
|
|
#include <system/op_boilerplate.h>
|
2019-06-06 14:21:15 +02:00
|
|
|
#include "helpers/logger.h"
|
2020-03-02 10:49:41 +01:00
|
|
|
#include <helpers/OmpLaunchHelper.h>
|
2019-06-06 14:21:15 +02:00
|
|
|
#include <helpers/DebugHelper.h>
|
|
|
|
|
|
|
|
#ifdef __CUDACC__
|
|
|
|
#include <cuda.h>
|
|
|
|
#include <cuda_runtime.h>
|
|
|
|
#include <types/float16.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "legacy_ops.h"
|
|
|
|
|
|
|
|
namespace functions {
|
|
|
|
namespace scalar {
|
|
|
|
/**
|
|
|
|
* Apply a scalar
|
|
|
|
* operation to an array
|
|
|
|
*/
|
|
|
|
template<typename X, typename Z>
|
|
|
|
class ScalarBoolTransform {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
#ifdef __CUDACC__
|
|
|
|
|
|
|
|
template<typename OpType>
|
|
|
|
__device__
|
|
|
|
static void transformCuda(void* scalar, void *vy, Nd4jLong *shapeInfo, void *vparams, void *vresult, Nd4jLong *resultShapeInfo, int *allocationBuffer);
|
|
|
|
|
|
|
|
template<typename OpType>
|
|
|
|
__device__
|
|
|
|
static void transformCuda(Nd4jLong n, void* vx, void *vy, Nd4jLong yEWS, void *vparams, void *vz, Nd4jLong zEWS, int *allocationBuffer);
|
|
|
|
|
|
|
|
template<typename OpType>
|
|
|
|
__device__
|
|
|
|
static void transformCuda(void *vx, Nd4jLong *xShapeInfo, void *vextraParams, void *vz, Nd4jLong *zShapeInfo, void *vscalars, int *dimension, int dimensionLength, Nd4jLong *tadShapeInfo, Nd4jLong *tadOffsets, Nd4jLong *tadShapeInfoZ, Nd4jLong *tadOffsetsZ);
|
|
|
|
|
|
|
|
template <typename OpType>
|
|
|
|
__host__
|
|
|
|
static void intermediateAlongDimension(dim3& launchDims, cudaStream_t *stream, void *x, Nd4jLong *xShapeInfo, void *z, Nd4jLong *zShapeInfo, void *scalars, void *extraParams, int *dimension, int dimensionLength, Nd4jLong *tadShapeInfo, Nd4jLong *tadOffsets, Nd4jLong *tadShapeInfoZ, Nd4jLong *tadOffsetsZ);
|
|
|
|
|
|
|
|
template <typename OpType>
|
|
|
|
__host__
|
|
|
|
static void intermediateShaped(dim3& launchDims, cudaStream_t *stream, void *vx, Nd4jLong *xShapeInfo, void *vz, Nd4jLong *zShapeInfo, void* vscalar, void *vextraParams, int *allocPointer);
|
|
|
|
|
|
|
|
__host__
|
|
|
|
static void executeCudaShaped(dim3& launchDims, cudaStream_t *stream, int opNum, void *x, Nd4jLong *xShapeInfo, void *result, Nd4jLong *resultShapeInfo, void* scalar, void *extraParams);
|
|
|
|
|
|
|
|
__host__
|
|
|
|
static void executeCudaAlongDimension(dim3& launchDims, cudaStream_t *stream, int opNum, void *x, Nd4jLong *xShapeInfo, void *z, Nd4jLong *zShapeInfo, void *scalars, void *extraParams, int *dimension, int dimensionLength, Nd4jLong *tadShapeInfo, Nd4jLong *tadOffsets, Nd4jLong *tadShapeInfoZ, Nd4jLong *tadOffsetsZ);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
#include "cuda/scalar_temp.cu"
|
|
|
|
*/
|
2019-11-13 15:15:18 +01:00
|
|
|
#else
|
2019-06-06 14:21:15 +02:00
|
|
|
template <typename OpType>
|
2019-11-13 15:15:18 +01:00
|
|
|
static void transform(void *x, Nd4jLong *xShapeInfo, void *extraParams, void *z, Nd4jLong *zShapeInfo, void *scalars, int *dimension, int dimensionLength, Nd4jLong *tadShapeInfo, Nd4jLong *tadOffsets, Nd4jLong *tadShapeInfoZ, Nd4jLong *tadOffsetsZ, const uint64_t start, const uint64_t stop);
|
2019-06-06 14:21:15 +02:00
|
|
|
|
2019-11-13 15:15:18 +01:00
|
|
|
static void transform(int opNum, void *x, Nd4jLong *xShapeInfo, void *extraParams, void *z, Nd4jLong *zShapeInfo, void *scalars, int *dimension, int dimensionLength, Nd4jLong *tadShapeInfo, Nd4jLong *tadOffsets, Nd4jLong *tadShapeInfoZ, Nd4jLong *tadOffsetsZ, const uint64_t start, const uint64_t stop);
|
2019-06-06 14:21:15 +02:00
|
|
|
|
2019-11-13 15:15:18 +01:00
|
|
|
static void transform(const int opNum, void *x, Nd4jLong *xShapeInfo, void *result, Nd4jLong *resultShapeInfo, void *scalar, void *extraParams, const uint64_t start, const uint64_t stop);
|
2019-06-06 14:21:15 +02:00
|
|
|
|
2019-11-13 15:15:18 +01:00
|
|
|
static void transform(const int opNum, void *x, Nd4jLong xStride, void *result, Nd4jLong resultStride, void *scalar, void *extraParams, const uint64_t n, const uint64_t start, const uint64_t stop);
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ScalarOp along dimension
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CPU implementation of scalar operation
|
|
|
|
* @param x the input
|
|
|
|
* @param xStride the stride for the input
|
|
|
|
* @param result the result buffer
|
|
|
|
* @param resultStride the stride for the result
|
|
|
|
* @param scalar the scalar to apply
|
|
|
|
* @param extraParams the extra parameters where
|
|
|
|
* neccssary
|
|
|
|
* @param n the number of elements to loop over
|
|
|
|
*/
|
|
|
|
|
|
|
|
template<typename OpType>
|
2019-11-13 15:15:18 +01:00
|
|
|
static void transform(void *x, Nd4jLong *xShapeInfo, void *result, Nd4jLong *resultShapeInfo, void *scalar, void *extraParams, const uint64_t start, const uint64_t stop);
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CPU implementation of scalar operation
|
|
|
|
* @param x the input
|
|
|
|
* @param xStride the stride for the input
|
|
|
|
* @param result the result buffer
|
|
|
|
* @param resultStride the stride for the result
|
|
|
|
* @param scalar the scalar to apply
|
|
|
|
* @param extraParams the extra parameters where
|
|
|
|
* neccssary
|
|
|
|
* @param n the number of elements to loop over
|
|
|
|
*/
|
|
|
|
|
|
|
|
template<typename OpType>
|
2019-11-13 15:15:18 +01:00
|
|
|
static void transform(void *x, Nd4jLong xStride, void *result, Nd4jLong resultStride, void *scalar, void *extraParams, const uint64_t n, const uint64_t start, const uint64_t stop);
|
|
|
|
#endif
|
2019-06-06 14:21:15 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* SCALAR_H_ */
|