2021-02-01 13:31:45 +01:00
|
|
|
/* ******************************************************************************
|
|
|
|
*
|
2019-06-06 14:21:15 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2021-02-01 13:31:45 +01:00
|
|
|
* See the NOTICE file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
2019-06-06 14:21:15 +02:00
|
|
|
* 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
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Created on: Dec 28, 2015
|
|
|
|
* Author: agibsonccc
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef INDEXREDUCE_H_
|
|
|
|
#define INDEXREDUCE_H_
|
2020-07-26 14:59:27 +02:00
|
|
|
#include <helpers/shape.h>
|
2019-06-06 14:21:15 +02:00
|
|
|
#ifdef _OPENMP
|
|
|
|
#include <omp.h>
|
|
|
|
#endif
|
2020-03-02 10:49:41 +01:00
|
|
|
#include <system/dll.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>
|
|
|
|
#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>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#include <helpers/TAD.h>
|
|
|
|
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
#include "system/pairwise_util.h"
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
#include "legacy_ops.h"
|
|
|
|
|
|
|
|
namespace functions {
|
|
|
|
namespace indexreduce {
|
|
|
|
|
2019-08-27 09:37:10 +02:00
|
|
|
template<typename X, typename Z>
|
2019-06-06 14:21:15 +02:00
|
|
|
class IndexReduce {
|
|
|
|
public:
|
2020-05-09 07:06:14 +02:00
|
|
|
#ifdef __CUDABLAS__
|
2019-06-06 14:21:15 +02:00
|
|
|
|
2020-05-09 07:06:14 +02:00
|
|
|
static __device__ void transform(int opNum,
|
|
|
|
const void *x, const Nd4jLong *xShapeInfo,
|
|
|
|
void *extraParams,
|
|
|
|
void *result, const Nd4jLong *resultShapeInfo,
|
|
|
|
int *dimension,int dimensionLength,
|
|
|
|
int postProcessOrNot,
|
|
|
|
int *allocationBuffer, void *reductionBuffer,
|
|
|
|
const Nd4jLong *tadShapeInfo, const Nd4jLong *tadOffset);
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
template<typename OpType>
|
2020-07-26 14:59:27 +02:00
|
|
|
static __device__ void aggregatePartials(IndexValue<X> *sPartialsRef, Nd4jLong tid, Nd4jLong numElements, void *extraParams);
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
|
|
|
|
template<typename OpType>
|
2020-05-09 07:06:14 +02:00
|
|
|
static __device__ void transform(const void *dx, const Nd4jLong *xShapeInfo,
|
|
|
|
void *extraParams,
|
|
|
|
void *result, const Nd4jLong *resultShapeInfo,
|
|
|
|
int *dimension, int dimensionLength,
|
|
|
|
int postProcessOrNot,
|
|
|
|
int *allocationBuffer, void *reductionBuffer,
|
|
|
|
const Nd4jLong *tadOnlyShapeInfo, const Nd4jLong *tadOffsets);
|
|
|
|
|
|
|
|
|
|
|
|
static _CUDA_H void executeIndexReduceScalar(dim3 launchDims, cudaStream_t *stream,
|
|
|
|
int op,
|
|
|
|
const void *dx, const Nd4jLong *xShapeInfo,
|
|
|
|
int xRank,
|
|
|
|
void *extraParams,
|
|
|
|
void *result, const Nd4jLong *resultShapeInfo,
|
|
|
|
int zRank,
|
|
|
|
int *dimension, int dimensionLength,
|
|
|
|
int postProcessOrNot,
|
|
|
|
int *allocationBuffer, void *reductionBuffer,
|
|
|
|
const Nd4jLong *tadOnlyShapeInfo, const Nd4jLong *tadOffsets);
|
|
|
|
|
|
|
|
static _CUDA_H void executeIndexReduce(dim3 launchDims, cudaStream_t *stream,
|
|
|
|
int op,
|
|
|
|
const void *dx, const Nd4jLong *xShapeInfo,
|
|
|
|
int xRank,
|
|
|
|
void *extraParams,
|
|
|
|
void *result, const Nd4jLong *resultShapeInfo,
|
|
|
|
int zRank,
|
|
|
|
int *dimension, int dimensionLength,
|
|
|
|
int postProcessOrNot,
|
|
|
|
int *allocationBuffer, void *reductionBuffer,
|
|
|
|
const Nd4jLong *tadOnlyShapeInfo, const Nd4jLong *tadOffsets);
|
2019-11-13 15:15:18 +01:00
|
|
|
#else
|
2019-06-06 14:21:15 +02:00
|
|
|
|
2020-05-09 07:06:14 +02:00
|
|
|
static Nd4jLong execScalar(int opNum, const void *x, const Nd4jLong *xShapeInfo, void *extraParams);
|
2019-06-06 14:21:15 +02:00
|
|
|
|
2020-05-09 07:06:14 +02:00
|
|
|
static void exec(int opNum,
|
|
|
|
const void *x, const Nd4jLong *xShapeInfo,
|
|
|
|
void *extraParams,
|
|
|
|
void *result, const Nd4jLong *resultShapeInfoBuffer,
|
|
|
|
int *dimension, int dimensionLength,
|
|
|
|
const Nd4jLong *tadShapeInfo, const Nd4jLong *tadOffset);
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
template<typename OpType>
|
2020-05-09 07:06:14 +02:00
|
|
|
static _CUDA_H Nd4jLong execScalar(const void *x, const Nd4jLong *xShapeInfo, void *extraParams);
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
template<typename OpType>
|
2020-05-09 07:06:14 +02:00
|
|
|
static _CUDA_H void exec(const void *x, const Nd4jLong *xShapeInfo,
|
|
|
|
void *extraParams,
|
|
|
|
void *result, const Nd4jLong *resultShapeInfoBuffer,
|
|
|
|
int *dimension, int dimensionLength,
|
|
|
|
const Nd4jLong *tadShapeInfo, const Nd4jLong *tadOffset);
|
2019-11-13 15:15:18 +01:00
|
|
|
#endif
|
2019-06-06 14:21:15 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* INDEXREDUCE_H_ */
|
|
|
|
|