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
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* broadcasting.h
|
|
|
|
*
|
|
|
|
* Created on: Dec 28, 2015
|
|
|
|
* Author: agibsonccc
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BROADCASTING_H_
|
|
|
|
#define BROADCASTING_H_
|
2020-03-02 10:49:41 +01:00
|
|
|
#include <system/dll.h>
|
2019-06-06 14:21:15 +02:00
|
|
|
#include <helpers/shape.h>
|
2020-03-02 10:49:41 +01:00
|
|
|
#include <math/templatemath.h>
|
|
|
|
#include <system/pairwise_util.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/DebugHelper.h>
|
|
|
|
|
|
|
|
#ifdef __CUDACC__
|
|
|
|
#include <cuda.h>
|
|
|
|
#include <cuda_runtime.h>
|
|
|
|
#endif
|
|
|
|
#ifdef __JNI__
|
|
|
|
#include <jni.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <helpers/TAD.h>
|
2020-02-17 14:25:10 +01:00
|
|
|
#include <helpers/LoopKind.h>
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
#include "legacy_ops.h"
|
|
|
|
|
|
|
|
namespace functions {
|
|
|
|
namespace broadcast {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Broadcast operation
|
|
|
|
* for broadcasting a smaller tensor
|
|
|
|
* along long a bigger one.
|
|
|
|
*/
|
|
|
|
template<typename X, typename Y, typename Z>
|
|
|
|
class Broadcast {
|
|
|
|
public:
|
|
|
|
|
|
|
|
#ifdef __CUDACC__
|
|
|
|
|
|
|
|
template<typename OpType>
|
|
|
|
static __device__ void transformCuda(
|
|
|
|
void *x,
|
|
|
|
Nd4jLong *xShapeInfo,
|
|
|
|
void *y,
|
|
|
|
Nd4jLong *yShapeInfo,
|
|
|
|
void *result,
|
|
|
|
Nd4jLong *resultShapeInfo,
|
|
|
|
int *dimension,
|
|
|
|
int dimensionLength, Nd4jLong *tadOnlyShapeInfo, Nd4jLong *tadOffsets, Nd4jLong *tadOnlyShapeInfoZ, Nd4jLong *tadOffsetsZ);
|
|
|
|
|
2020-03-10 14:29:09 +01:00
|
|
|
template<typename OpType>
|
|
|
|
static __device__ void transformCuda(const void *x, const Nd4jLong *xShapeInfo,
|
|
|
|
const void *y, const Nd4jLong *yShapeInfo,
|
|
|
|
void *z, const Nd4jLong *zShapeInfo);
|
|
|
|
|
2019-06-06 14:21:15 +02:00
|
|
|
template <typename OpClass>
|
|
|
|
static __host__ void intermediateBroadcast(dim3 launchDims, cudaStream_t *stream, void *x, Nd4jLong *xShapeInfo, void *y, Nd4jLong *yShapeInfo, void *result, Nd4jLong *resultShapeInfo, int *dimension, int dimensionLength, Nd4jLong *tadOnlyShapeInfo, Nd4jLong *tadOffsets, Nd4jLong *tadOnlyShapeInfoZ, Nd4jLong *tadOffsetsZ);
|
|
|
|
|
2020-03-10 14:29:09 +01:00
|
|
|
template <typename OpClass>
|
|
|
|
static __host__ void intermediateBroadcast(dim3 launchDims, cudaStream_t *stream, const void *x, const Nd4jLong *xShapeInfo, const void *y, const Nd4jLong *yShapeInfo, void *z, const Nd4jLong *zShapeInfo);
|
|
|
|
|
2019-06-06 14:21:15 +02:00
|
|
|
static __host__ void execBroadcast(dim3 launchDims, cudaStream_t *stream, int opNum, void *x, Nd4jLong *xShapeInfo, void *y, Nd4jLong *yShapeInfo, void *result, Nd4jLong *resultShapeInfo, int *dimension, int dimensionLength, Nd4jLong *tadOnlyShapeInfo, Nd4jLong *tadOffsets, Nd4jLong *tadOnlyShapeInfoZ, Nd4jLong *tadOffsetsZ);
|
|
|
|
|
2020-03-10 14:29:09 +01:00
|
|
|
static __host__ void execBroadcast(dim3 launchDims, cudaStream_t *stream, const int opNum, const void *x, const Nd4jLong *xShapeInfo, const void *y, const Nd4jLong *yShapeInfo, void *z, const Nd4jLong *zShapeInfo);
|
|
|
|
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
template<typename OpType>
|
|
|
|
static __device__ void transformInverseCuda(
|
|
|
|
void *x,
|
|
|
|
Nd4jLong *xShapeInfo,
|
|
|
|
void *y,
|
|
|
|
Nd4jLong *yShapeInfo,
|
|
|
|
void *result,
|
|
|
|
Nd4jLong *resultShapeInfo,
|
|
|
|
int *dimension,
|
|
|
|
int dimensionLength, Nd4jLong *tadOnlyShapeInfo, Nd4jLong *tadOffsets, Nd4jLong *tadOnlyShapeInfoZ, Nd4jLong *tadOffsetsZ);
|
|
|
|
|
|
|
|
template <typename OpClass>
|
|
|
|
static __host__ void intermediateInverseBroadcast(dim3 launchDims, cudaStream_t *stream, void *x, Nd4jLong *xShapeInfo, void *y, Nd4jLong *yShapeInfo, void *result, Nd4jLong *resultShapeInfo, int *dimension, int dimensionLength, Nd4jLong *tadOnlyShapeInfo, Nd4jLong *tadOffsets, Nd4jLong *tadOnlyShapeInfoZ, Nd4jLong *tadOffsetsZ);
|
|
|
|
|
|
|
|
static __host__ void execInverseBroadcast(dim3 launchDims, cudaStream_t *stream, int opNum, void *x, Nd4jLong *xShapeInfo, void *y, Nd4jLong *yShapeInfo, void *result, Nd4jLong *resultShapeInfo, int *dimension, int dimensionLength, Nd4jLong *tadOnlyShapeInfo, Nd4jLong *tadOffsets, Nd4jLong *tadOnlyShapeInfoZ, Nd4jLong *tadOffsetsZ);
|
|
|
|
|
|
|
|
|
2019-11-13 15:15:18 +01:00
|
|
|
#else
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
static void execInverse(int opNum,
|
|
|
|
void *x,
|
|
|
|
Nd4jLong *xShapeInfo,
|
|
|
|
void *y,
|
|
|
|
Nd4jLong *yShapeInfo,
|
|
|
|
void *result,
|
|
|
|
Nd4jLong *resultShapeInfo,
|
|
|
|
int *dimension,
|
|
|
|
int dimensionLength,
|
|
|
|
Nd4jLong *tadShapeInfo,
|
|
|
|
Nd4jLong *tadOffset,
|
|
|
|
Nd4jLong *tadShapeInfoZ,
|
2019-11-13 15:15:18 +01:00
|
|
|
Nd4jLong *tadOffsetZ,
|
|
|
|
uint64_t start,
|
|
|
|
uint64_t stop);
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
static void exec(int opNum,
|
|
|
|
void *x,
|
|
|
|
Nd4jLong *xShapeInfo,
|
|
|
|
void *y,
|
|
|
|
Nd4jLong *yShapeInfo,
|
|
|
|
void *result,
|
|
|
|
Nd4jLong *resultShapeInfo,
|
|
|
|
int *dimension,
|
|
|
|
int dimensionLength,
|
|
|
|
Nd4jLong *tadShapeInfo,
|
|
|
|
Nd4jLong *tadOffset,
|
|
|
|
Nd4jLong *tadShapeInfoZ,
|
2019-11-13 15:15:18 +01:00
|
|
|
Nd4jLong *tadOffsetZ,
|
2020-03-02 10:49:41 +01:00
|
|
|
sd::LoopKind::Kind loopKind,
|
2019-11-13 15:15:18 +01:00
|
|
|
uint64_t start,
|
|
|
|
uint64_t stop);
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* CPU execution
|
|
|
|
* @param x the input
|
|
|
|
* @param xShapeInfo the x shape information
|
|
|
|
* @param y the y data
|
|
|
|
* @param yShapeInfo the y shape information
|
|
|
|
* @param result the result
|
|
|
|
* @param resultShapeInfo the result shape information
|
|
|
|
* @param dimension the dimension to broadcast along long
|
|
|
|
* @param dimensionLength the length of the dimension buffer
|
|
|
|
*/
|
|
|
|
template<typename OpType>
|
|
|
|
static void exec(void *x,
|
|
|
|
Nd4jLong *xShapeInfo,
|
|
|
|
void *y,
|
|
|
|
Nd4jLong *yShapeInfo,
|
|
|
|
void *result,
|
|
|
|
Nd4jLong *resultShapeInfo,
|
|
|
|
int *dimension,
|
|
|
|
int dimensionLength,
|
|
|
|
Nd4jLong *tadShapeInfo,
|
|
|
|
Nd4jLong *tadOffset,
|
|
|
|
Nd4jLong *tadShapeInfoZ,
|
2019-11-13 15:15:18 +01:00
|
|
|
Nd4jLong *tadOffsetZ,
|
2020-03-02 10:49:41 +01:00
|
|
|
sd::LoopKind::Kind loopKind,
|
2019-11-13 15:15:18 +01:00
|
|
|
uint64_t start,
|
|
|
|
uint64_t stop);
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
template<typename OpType>
|
|
|
|
static void execInverse(void *x,
|
|
|
|
Nd4jLong *xShapeInfo,
|
|
|
|
void *y,
|
|
|
|
Nd4jLong *yShapeInfo,
|
|
|
|
void *result,
|
|
|
|
Nd4jLong *resultShapeInfo,
|
|
|
|
int *dimension,
|
|
|
|
int dimensionLength,
|
|
|
|
Nd4jLong *tadShapeInfo,
|
|
|
|
Nd4jLong *tadOffset,
|
|
|
|
Nd4jLong *tadShapeInfoZ,
|
2019-11-13 15:15:18 +01:00
|
|
|
Nd4jLong *tadOffsetZ,
|
|
|
|
uint64_t start,
|
|
|
|
uint64_t stop);
|
2020-03-10 14:29:09 +01:00
|
|
|
|
|
|
|
static void exec(const int opNum,
|
|
|
|
const void *x, const Nd4jLong *xShapeInfo,
|
|
|
|
const void *y, const Nd4jLong *yShapeInfo,
|
|
|
|
void *z, const Nd4jLong *zShapeInfo);
|
|
|
|
|
|
|
|
template<typename OpType>
|
|
|
|
static void exec(const void *x, const Nd4jLong *xShapeInfo,
|
|
|
|
const void *y, const Nd4jLong *yShapeInfo,
|
|
|
|
void *z, const Nd4jLong *zShapeInfo);
|
|
|
|
|
2019-11-13 15:15:18 +01:00
|
|
|
#endif
|
2019-06-06 14:21:15 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* BROADCASTING_H_ */
|