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
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
//
|
|
|
|
// Created by raver on 4/9/2018.
|
|
|
|
//
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
#include <system/Environment.h>
|
2019-06-06 14:21:15 +02:00
|
|
|
#include "../indexreduce.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>
|
|
|
|
#include <types/types.h>
|
|
|
|
|
|
|
|
#include "../legacy_ops.h"
|
|
|
|
|
|
|
|
using namespace simdOps;
|
|
|
|
|
|
|
|
|
2019-08-27 09:37:10 +02:00
|
|
|
template <typename X, typename Z>
|
2019-06-06 14:21:15 +02:00
|
|
|
static __global__ void simpleIndexReduceGeneric(const int op,
|
2020-05-09 07:06:14 +02:00
|
|
|
void const* dx,
|
|
|
|
Nd4jLong const* xShapeInfo, int xRank,
|
2019-06-06 14:21:15 +02:00
|
|
|
void *extraParams,
|
2019-08-27 09:37:10 +02:00
|
|
|
void *result,
|
2020-05-09 07:06:14 +02:00
|
|
|
Nd4jLong const* zShapeInfo, int zRank,
|
2019-06-06 14:21:15 +02:00
|
|
|
int *dimension,
|
|
|
|
int dimensionLength,
|
2020-05-09 07:06:14 +02:00
|
|
|
int postProcessOrNot, int *allocationBuffer, void *reductionBuffer, Nd4jLong const* tadOnlyShapeInfo, Nd4jLong const* tadOffsets) {
|
2019-06-06 14:21:15 +02:00
|
|
|
|
2020-01-20 19:32:46 +01:00
|
|
|
functions::indexreduce::IndexReduce<X, Z>::transform(op,dx,xShapeInfo,extraParams,result,zShapeInfo,dimension,dimensionLength,postProcessOrNot,allocationBuffer,reductionBuffer,tadOnlyShapeInfo,tadOffsets);
|
2019-06-06 14:21:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace functions {
|
|
|
|
namespace indexreduce {
|
|
|
|
|
2019-08-27 09:37:10 +02:00
|
|
|
template <typename X, typename Z>
|
|
|
|
_CUDA_H void IndexReduce<X,Z>::executeIndexReduceScalar(dim3 launchDims, cudaStream_t *stream,
|
2019-06-06 14:21:15 +02:00
|
|
|
const int opNum,
|
2020-05-09 07:06:14 +02:00
|
|
|
void const* dx, Nd4jLong const* xShapeInfo,
|
2019-06-06 14:21:15 +02:00
|
|
|
int xRank,
|
|
|
|
void *extraParams,
|
2020-05-09 07:06:14 +02:00
|
|
|
void *result, Nd4jLong const* zShapeInfo,
|
2019-06-06 14:21:15 +02:00
|
|
|
int zRank,
|
|
|
|
int *dimension, int dimensionLength,
|
|
|
|
int postProcessOrNot,
|
|
|
|
int *allocationBuffer, void *reductionBuffer,
|
2020-05-09 07:06:14 +02:00
|
|
|
Nd4jLong const* tadOnlyShapeInfo, Nd4jLong const* tadOffsets) {
|
2019-06-06 14:21:15 +02:00
|
|
|
|
2019-08-27 09:37:10 +02:00
|
|
|
simpleIndexReduceGeneric<X, Z><<<launchDims.x,launchDims.y,launchDims.z, *stream>>>(opNum,
|
2019-06-06 14:21:15 +02:00
|
|
|
dx, xShapeInfo, xRank,
|
|
|
|
extraParams,
|
2020-01-20 19:32:46 +01:00
|
|
|
result, zShapeInfo, 0,
|
2019-06-06 14:21:15 +02:00
|
|
|
nullptr, 0,
|
|
|
|
1,
|
|
|
|
allocationBuffer, reductionBuffer,
|
|
|
|
tadOnlyShapeInfo, tadOffsets);
|
|
|
|
}
|
|
|
|
|
2019-08-27 09:37:10 +02:00
|
|
|
template <typename X, typename Z>
|
2020-05-09 07:06:14 +02:00
|
|
|
_CUDA_H void IndexReduce<X, Z>::executeIndexReduce(dim3 launchDims, cudaStream_t *stream, const int opNum, void const* dx, Nd4jLong const* xShapeInfo, int xRank, void *extraParams, void *result, Nd4jLong const* zShapeInfo, int zRank, int *dimension, int dimensionLength, int postProcessOrNot, int *allocationBuffer, void *reductionBuffer, Nd4jLong const* tadOnlyShapeInfo, Nd4jLong const* tadOffsets) {
|
2019-08-27 09:37:10 +02:00
|
|
|
simpleIndexReduceGeneric<X, Z><<<launchDims.x,launchDims.y,launchDims.z, *stream>>>(
|
2019-06-06 14:21:15 +02:00
|
|
|
opNum,
|
|
|
|
dx,
|
|
|
|
xShapeInfo, xRank,
|
|
|
|
extraParams,
|
|
|
|
result,
|
2020-01-20 19:32:46 +01:00
|
|
|
zShapeInfo, zRank,
|
2019-06-06 14:21:15 +02:00
|
|
|
dimension,
|
|
|
|
dimensionLength,
|
|
|
|
1, allocationBuffer, reductionBuffer, tadOnlyShapeInfo, tadOffsets);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is the un-specialized struct. Note that we prevent instantiation of this
|
|
|
|
// struct by putting an undefined symbol in the function body so it won't compile.
|
|
|
|
template<typename T>
|
|
|
|
struct SharedIndexValue {
|
|
|
|
// Ensure that we won't compile any un-specialized types
|
|
|
|
__device__ T * getPointer() {
|
|
|
|
extern __device__ void error(void);
|
|
|
|
error();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Following are the specializations for the following types.
|
|
|
|
// int, uint, char, uchar, short, ushort, long long, ulong long, bool, float, and double
|
|
|
|
// One could also specialize it for user-defined types.
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct SharedIndexValue<float> {
|
|
|
|
__device__ IndexValue<float> * getPointer() {
|
|
|
|
extern __shared__ IndexValue<float> s_int2[];
|
|
|
|
return s_int2;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
// Following are the specializations for the following types.
|
|
|
|
// int, uint, char, uchar, short, ushort, long long, ulong long, bool, float, and double
|
|
|
|
// One could also specialize it for user-defined types.
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct SharedIndexValue<double> {
|
|
|
|
__device__ IndexValue<double> * getPointer() {
|
|
|
|
extern __shared__ IndexValue<double> s_int6[];
|
|
|
|
return s_int6;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-08-27 09:37:10 +02:00
|
|
|
template <typename X, typename Z>
|
2019-06-06 14:21:15 +02:00
|
|
|
template <typename OpType>
|
2019-08-27 09:37:10 +02:00
|
|
|
__device__ void IndexReduce<X, Z>::aggregatePartials(IndexValue<X> **sPartialsRef, Nd4jLong tid, Nd4jLong numElements, void *vextraParams) {
|
2019-06-06 14:21:15 +02:00
|
|
|
// start the shared memory loop on the next power of 2 less
|
|
|
|
// than the block size. If block size is not a power of 2,
|
|
|
|
// accumulate the intermediate sums in the remainder range.
|
2019-08-27 09:37:10 +02:00
|
|
|
auto extraParams = static_cast<X*>(vextraParams);
|
|
|
|
IndexValue<X> *sPartials = *sPartialsRef;
|
2019-06-06 14:21:15 +02:00
|
|
|
Nd4jLong floorPow2 = blockDim.x;
|
|
|
|
|
|
|
|
if (floorPow2 & (floorPow2 - 1)) {
|
|
|
|
while ( floorPow2 & (floorPow2 - 1) ) {
|
|
|
|
floorPow2 &= floorPow2 - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tid >= floorPow2) {
|
2019-08-27 09:37:10 +02:00
|
|
|
IndexValue<X> prev = sPartials[tid - floorPow2];
|
|
|
|
IndexValue<X> curr = sPartials[tid];
|
2019-06-06 14:21:15 +02:00
|
|
|
sPartials[tid - floorPow2] = OpType::update(prev,curr,extraParams);
|
|
|
|
}
|
|
|
|
__syncthreads();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int activeThreads = floorPow2 >> 1;activeThreads; activeThreads >>= 1) {
|
|
|
|
if (tid < activeThreads && tid + activeThreads < numElements) {
|
2019-08-27 09:37:10 +02:00
|
|
|
IndexValue<X> curr = sPartials[tid];
|
|
|
|
IndexValue<X> next = sPartials[tid + activeThreads];
|
2019-06-06 14:21:15 +02:00
|
|
|
sPartials[tid] = OpType::update(curr,next,extraParams);
|
|
|
|
}
|
|
|
|
__syncthreads();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-27 09:37:10 +02:00
|
|
|
template <typename X, typename Y>
|
|
|
|
__device__ void IndexReduce<X, Y>::transform(
|
2019-06-06 14:21:15 +02:00
|
|
|
const int opNum,
|
2020-05-09 07:06:14 +02:00
|
|
|
void const* x,
|
|
|
|
Nd4jLong const* xShapeInfo,
|
2019-06-06 14:21:15 +02:00
|
|
|
void *extraParams,
|
2019-08-27 09:37:10 +02:00
|
|
|
void *result,
|
2020-05-09 07:06:14 +02:00
|
|
|
Nd4jLong const* zShapeInfo,
|
2019-06-06 14:21:15 +02:00
|
|
|
int *dimension,
|
|
|
|
int dimensionLength,
|
|
|
|
int postProcessOrNot,
|
|
|
|
int *allocationBuffer,
|
|
|
|
void *reductionBuffer,
|
2020-05-09 07:06:14 +02:00
|
|
|
Nd4jLong const* tadShapeInfo,
|
|
|
|
Nd4jLong const* tadOffset) {
|
2020-01-20 19:32:46 +01:00
|
|
|
DISPATCH_BY_OPNUM_TT(transform, PARAMS(x, xShapeInfo, extraParams, result, zShapeInfo, dimension, dimensionLength, postProcessOrNot, allocationBuffer, reductionBuffer, tadShapeInfo, tadOffset), INDEX_REDUCE_OPS);
|
2019-06-06 14:21:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-27 09:37:10 +02:00
|
|
|
template <typename X, typename Z>
|
2019-06-06 14:21:15 +02:00
|
|
|
template <typename OpType>
|
2020-05-09 07:06:14 +02:00
|
|
|
__device__ void IndexReduce<X, Z>::transform(void const* vdx, Nd4jLong const* xShapeInfo,
|
2019-06-06 14:21:15 +02:00
|
|
|
void *vextraParams,
|
2020-05-09 07:06:14 +02:00
|
|
|
void* vz, Nd4jLong const* zShapeInfo,
|
2019-06-06 14:21:15 +02:00
|
|
|
int *dimension, int dimensionLength,
|
|
|
|
int postProcessOrNot,
|
|
|
|
int *allocationBuffer, void *vreductionBuffer,
|
2020-05-09 07:06:14 +02:00
|
|
|
Nd4jLong const* tadOnlyShapeInfo, Nd4jLong const* tadOffsets){
|
2019-06-06 14:21:15 +02:00
|
|
|
/**int
|
|
|
|
* Gpu information for the problem
|
|
|
|
*/
|
2020-05-09 07:06:14 +02:00
|
|
|
auto dx = reinterpret_cast<X const*>(vdx);
|
2020-01-20 19:32:46 +01:00
|
|
|
auto z = reinterpret_cast<Z*>(vz);
|
2019-08-27 09:37:10 +02:00
|
|
|
auto extraParams = static_cast<X*>(vextraParams);
|
|
|
|
auto reductionBuffer = static_cast<X*>(vreductionBuffer);
|
2019-08-07 14:29:17 +02:00
|
|
|
auto order = shape::order(xShapeInfo);
|
2019-06-06 14:21:15 +02:00
|
|
|
int tid = blockIdx.x * blockDim.x + threadIdx.x;
|
|
|
|
__shared__ volatile int resultScalar;
|
|
|
|
|
|
|
|
//shared memory space for storing intermediate results
|
2019-08-27 09:37:10 +02:00
|
|
|
__shared__ IndexValue<X>* sPartials;
|
2019-06-06 14:21:15 +02:00
|
|
|
if(threadIdx.x == 0) {
|
|
|
|
extern __shared__ unsigned char shmem[];
|
2019-08-27 09:37:10 +02:00
|
|
|
sPartials = reinterpret_cast<IndexValue<X>*>(shmem);
|
2019-06-06 14:21:15 +02:00
|
|
|
}
|
|
|
|
__syncthreads();
|
|
|
|
|
|
|
|
sPartials[threadIdx.x] = OpType::startingIndexValue(dx);
|
|
|
|
|
|
|
|
//length for the tad
|
|
|
|
__shared__ volatile Nd4jLong xLength;
|
|
|
|
|
2020-01-20 19:32:46 +01:00
|
|
|
__shared__ volatile Nd4jLong zLen;
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
|
|
|
|
//only compute the tad indexes once
|
2019-08-27 09:37:10 +02:00
|
|
|
IndexValue<X> reduction = OpType::startingIndexValue(dx);
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
if (threadIdx.x == 0) {
|
2020-01-20 19:32:46 +01:00
|
|
|
if (zShapeInfo != nullptr)
|
|
|
|
zLen = shape::length(zShapeInfo);
|
|
|
|
else zLen = 1;
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
if (dimensionLength == 1) {
|
2020-01-20 19:32:46 +01:00
|
|
|
if (zLen == 1 && (dimension == nullptr || dimension[0] == MAX_DIMENSION))
|
2019-06-06 14:21:15 +02:00
|
|
|
resultScalar = 1;
|
|
|
|
else
|
|
|
|
resultScalar = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
resultScalar = 0;
|
|
|
|
|
2020-01-20 19:32:46 +01:00
|
|
|
if (zLen == 1)
|
2019-06-06 14:21:15 +02:00
|
|
|
resultScalar = 1;
|
|
|
|
|
|
|
|
xLength = shape::length(xShapeInfo);
|
|
|
|
}
|
|
|
|
__syncthreads();
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
if(sd::ArrayOptions::arrayType(xShapeInfo) == sd::ArrayType::EMPTY) {
|
2020-01-20 19:32:46 +01:00
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
if(sd::ArrayOptions::arrayType(zShapeInfo) == sd::ArrayType::EMPTY)
|
2020-01-20 19:32:46 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
for (uint i = blockIdx.x * blockDim.x + threadIdx.x; i < zLen; i += gridDim.x * blockDim.x)
|
|
|
|
z[i] = (Z) reduction.index;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-06-06 14:21:15 +02:00
|
|
|
if (!resultScalar) {
|
|
|
|
|
|
|
|
__shared__ Nd4jLong tadLength;
|
|
|
|
__shared__ int tadEWS;
|
|
|
|
__shared__ int numTads;
|
|
|
|
|
|
|
|
if (threadIdx.x == 0) {
|
|
|
|
tadLength = shape::length(tadOnlyShapeInfo);
|
|
|
|
tadEWS = shape::elementWiseStride(tadOnlyShapeInfo);
|
|
|
|
numTads = shape::length(xShapeInfo) / tadLength;
|
|
|
|
}
|
|
|
|
__syncthreads();
|
|
|
|
|
|
|
|
if (dimensionLength > 1 || tadEWS < 1) {
|
|
|
|
|
|
|
|
for (int r = blockIdx.x; r < numTads; r += gridDim.x) {
|
2019-09-11 19:12:09 +02:00
|
|
|
|
2019-06-06 14:21:15 +02:00
|
|
|
auto tadOffsetForBlock = tadOffsets[r];
|
|
|
|
sPartials[threadIdx.x] = OpType::startingIndexValue(dx);
|
|
|
|
|
2019-09-11 19:12:09 +02:00
|
|
|
for(int i = threadIdx.x;i < tadLength; i += blockDim.x) {
|
|
|
|
auto xOffset = tadOffsetForBlock + shape::getIndexOffset(i, tadOnlyShapeInfo);
|
2019-08-27 09:37:10 +02:00
|
|
|
IndexValue<X> comp {dx[xOffset], i};
|
2019-06-06 14:21:15 +02:00
|
|
|
sPartials[threadIdx.x] = OpType::update(sPartials[threadIdx.x], comp, extraParams);
|
|
|
|
}
|
|
|
|
|
|
|
|
__syncthreads();
|
2020-03-02 10:49:41 +01:00
|
|
|
aggregatePartials<OpType>(&sPartials, threadIdx.x, sd::math::nd4j_min<int>(blockDim.x, tadLength),extraParams);
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
__syncthreads();
|
|
|
|
if (threadIdx.x == 0) {
|
2020-01-20 19:32:46 +01:00
|
|
|
z[r] = (Z) sPartials[threadIdx.x].index;
|
2019-06-06 14:21:15 +02:00
|
|
|
}
|
2019-08-20 17:28:43 +02:00
|
|
|
__syncthreads();
|
2019-06-06 14:21:15 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
for(int i = blockIdx.x; i < numTads; i+= gridDim.x) {
|
|
|
|
Nd4jLong tadOffsetForBlock = tadOffsets[i];
|
|
|
|
|
|
|
|
sPartials[threadIdx.x] = OpType::startingIndexValue(dx);
|
|
|
|
|
|
|
|
for (int x = threadIdx.x; x < tadLength; x+= blockDim.x) {
|
2019-08-27 09:37:10 +02:00
|
|
|
IndexValue<X> comp {dx[tadOffsetForBlock + x * tadEWS], x};
|
2019-06-06 14:21:15 +02:00
|
|
|
sPartials[threadIdx.x] = OpType::update(sPartials[threadIdx.x], comp, extraParams);
|
|
|
|
}
|
|
|
|
|
|
|
|
__syncthreads();
|
2020-03-02 10:49:41 +01:00
|
|
|
aggregatePartials<OpType>(&sPartials, threadIdx.x, sd::math::nd4j_min<int>(blockDim.x, tadLength),extraParams);
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
__syncthreads();
|
|
|
|
if (threadIdx.x == 0) {
|
2020-01-20 19:32:46 +01:00
|
|
|
z[i] = (Z) sPartials[threadIdx.x].index; //postProcess(sPartials[0],tadLength ,extraParams);
|
2019-06-06 14:21:15 +02:00
|
|
|
}
|
2019-08-20 17:28:43 +02:00
|
|
|
__syncthreads();
|
2019-06-06 14:21:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
auto n = shape::length(xShapeInfo);
|
|
|
|
auto xElementWiseStride = shape::elementWiseStride(xShapeInfo);
|
|
|
|
|
2019-08-07 14:29:17 +02:00
|
|
|
if(xElementWiseStride >= 1 && order == 'c') {
|
2019-06-06 14:21:15 +02:00
|
|
|
for(Nd4jLong i = tid;i < n; i += (blockDim.x * gridDim.x)) {
|
2019-08-27 09:37:10 +02:00
|
|
|
IndexValue<X> indexVal = {dx[i * xElementWiseStride], i};
|
2019-06-06 14:21:15 +02:00
|
|
|
reduction = OpType::update(reduction, indexVal, extraParams);
|
|
|
|
}
|
|
|
|
} else {
|
2019-09-11 19:12:09 +02:00
|
|
|
|
|
|
|
for(Nd4jLong i = tid;i < n; i += blockDim.x * gridDim.x) {
|
|
|
|
auto offset = shape::getIndexOffset(i, xShapeInfo);
|
2019-08-27 09:37:10 +02:00
|
|
|
IndexValue<X> indexVal = {dx[offset], i};
|
2019-06-06 14:21:15 +02:00
|
|
|
reduction = OpType::update(reduction, indexVal, extraParams);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sPartials[threadIdx.x] = reduction;
|
|
|
|
__syncthreads();
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
aggregatePartials<OpType>(&sPartials, threadIdx.x, sd::math::nd4j_min<int>(blockDim.x, (int) n),extraParams);
|
2019-06-06 14:21:15 +02:00
|
|
|
__syncthreads();
|
|
|
|
|
|
|
|
if (gridDim.x > 1) {
|
|
|
|
__shared__ bool amLast;
|
|
|
|
unsigned int *tc = (unsigned int *) reductionBuffer;
|
|
|
|
tid = threadIdx.x;
|
|
|
|
if (threadIdx.x == 0) {
|
2019-08-27 09:37:10 +02:00
|
|
|
auto pBuffer = reinterpret_cast<IndexValue<X> *>(reductionBuffer);
|
2019-06-06 14:21:15 +02:00
|
|
|
pBuffer[blockIdx.x] = {sPartials[0].value, sPartials[0].index};
|
|
|
|
}
|
|
|
|
__threadfence();
|
|
|
|
__syncthreads();
|
|
|
|
|
|
|
|
if (tid==0) {
|
|
|
|
unsigned int ticket = atomicInc(&tc[16384], gridDim.x);
|
|
|
|
amLast = (ticket == gridDim.x-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
__syncthreads();
|
|
|
|
|
|
|
|
if (amLast) {
|
|
|
|
tc[16384] = 0;
|
2019-08-27 09:37:10 +02:00
|
|
|
IndexValue<X> *pBuffer = (IndexValue<X> *) reductionBuffer;
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
sPartials[threadIdx.x] = OpType::startingIndexValue(dx);
|
|
|
|
|
|
|
|
for (Nd4jLong i = threadIdx.x; i < gridDim.x; i += blockDim.x) {
|
|
|
|
sPartials[threadIdx.x] = OpType::update(sPartials[threadIdx.x], pBuffer[i], extraParams);
|
|
|
|
}
|
|
|
|
|
|
|
|
__syncthreads();
|
2020-03-02 10:49:41 +01:00
|
|
|
aggregatePartials<OpType>(&sPartials, threadIdx.x, sd::math::nd4j_min<int>(gridDim.x, blockDim.x),extraParams);
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
__syncthreads();
|
|
|
|
if (tid == 0) {
|
2020-01-20 19:32:46 +01:00
|
|
|
z[0] = (Z) sPartials[0].index;
|
2019-06-06 14:21:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (tid == 0) {
|
|
|
|
auto tc = reinterpret_cast<unsigned int *>(reductionBuffer);
|
|
|
|
tc[16384] = 0;
|
2020-01-20 19:32:46 +01:00
|
|
|
z[0] = (Z) sPartials[0].index;
|
2019-06-06 14:21:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-27 09:37:10 +02:00
|
|
|
BUILD_DOUBLE_TEMPLATE(template class ND4J_EXPORT IndexReduce, , LIBND4J_TYPES, INDEXING_TYPES);
|
2019-06-06 14:21:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|