ElementWiseStride==1 cases for legacy random ops (#202)

Signed-off-by: AbdelRauf <rauf@konduit.ai>
master
Abdelrauf 2020-01-31 09:57:31 +04:00 committed by GitHub
parent 5d98cfcf47
commit d39ca6d488
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 70 additions and 29 deletions

View File

@ -29,6 +29,7 @@ using namespace randomOps;
namespace functions { namespace functions {
namespace random { namespace random {
template<typename X> template<typename X>
template<typename OpClass> template<typename OpClass>
void RandomFunction<X>::execTransform(Nd4jPointer state, void RandomFunction<X>::execTransform(Nd4jPointer state,
@ -56,18 +57,32 @@ namespace functions {
if(shape::haveSameShapeAndStrides(xShapeInfo, yShapeInfo) && shape::haveSameShapeAndStrides(xShapeInfo, zShapeInfo)) { if(shape::haveSameShapeAndStrides(xShapeInfo, yShapeInfo) && shape::haveSameShapeAndStrides(xShapeInfo, zShapeInfo)) {
uint xShapeInfoCast[MAX_RANK];
const bool canCastX = nd4j::DataTypeUtils::castShapeInfo(xShapeInfo, xShapeInfoCast);
auto func = PRAGMA_THREADS_FOR { if(shape::elementWiseStride(zShapeInfo) == 1 && shape::elementWiseStride(xShapeInfo) == 1 && shape::elementWiseStride(yShapeInfo) == 1 &&
PRAGMA_OMP_SIMD shape::order(xShapeInfo) == shape::order(zShapeInfo) && shape::order(zShapeInfo) == shape::order(yShapeInfo) ){
for (auto i = start; i < stop; i += increment) {
auto offset = shape::indexOffset(i, xShapeInfo, xShapeInfoCast, canCastX); auto func = PRAGMA_THREADS_FOR {
z[offset] = OpClass::op(x[offset], y[offset], i, length, rng, extraArguments); PRAGMA_OMP_SIMD
} for (auto i = start; i < stop; i++) {
}; z[i] = OpClass::op(x[i], y[i], i, length, rng, extraArguments);
}
};
samediff::Threads::parallel_for(func, 0, length, 1);
}
else{
uint xShapeInfoCast[MAX_RANK];
const bool canCastX = nd4j::DataTypeUtils::castShapeInfo(xShapeInfo, xShapeInfoCast);
samediff::Threads::parallel_for(func, 0, length, 1); auto func = PRAGMA_THREADS_FOR {
PRAGMA_OMP_SIMD
for (auto i = start; i < stop; i += increment) {
auto offset = shape::indexOffset(i, xShapeInfo, xShapeInfoCast, canCastX);
z[offset] = OpClass::op(x[offset], y[offset], i, length, rng, extraArguments);
}
};
samediff::Threads::parallel_for(func, 0, length, 1);
}
} }
else if (shape::haveSameShapeAndStrides(xShapeInfo, yShapeInfo)) { else if (shape::haveSameShapeAndStrides(xShapeInfo, yShapeInfo)) {
@ -169,15 +184,27 @@ namespace functions {
if(shape::haveSameShapeAndStrides(xShapeInfo, zShapeInfo)) { if(shape::haveSameShapeAndStrides(xShapeInfo, zShapeInfo)) {
auto func = PRAGMA_THREADS_FOR { if(shape::elementWiseStride(zShapeInfo) == 1 && shape::elementWiseStride(xShapeInfo) == 1 && shape::order(xShapeInfo) == shape::order(zShapeInfo)){
PRAGMA_OMP_SIMD
for (uint64_t i = start; i < stop; i += increment) { auto func = PRAGMA_THREADS_FOR {
auto offset = shape::indexOffset(i, xShapeInfo, xShapeInfoCast, canCastX); PRAGMA_OMP_SIMD
z[offset] = OpClass::op(x[offset], i, length, rng, extraArguments); for (auto i = start; i < stop; i++) {
} z[i] = OpClass::op(x[i], i, length, rng, extraArguments);
}; }
};
samediff::Threads::parallel_for(func, 0, length, 1);
}
else{
auto func = PRAGMA_THREADS_FOR {
PRAGMA_OMP_SIMD
for (uint64_t i = start; i < stop; i += increment) {
auto offset = shape::indexOffset(i, xShapeInfo, xShapeInfoCast, canCastX);
z[offset] = OpClass::op(x[offset], i, length, rng, extraArguments);
}
};
samediff::Threads::parallel_for(func, 0, length, 1); samediff::Threads::parallel_for(func, 0, length, 1);
}
} }
else { else {
@ -208,20 +235,34 @@ namespace functions {
auto length = shape::length(zShapeInfo); auto length = shape::length(zShapeInfo);
nd4j::graph::RandomGenerator* rng = reinterpret_cast<nd4j::graph::RandomGenerator*>(state); nd4j::graph::RandomGenerator* rng = reinterpret_cast<nd4j::graph::RandomGenerator*>(state);
nd4j::OmpLaunchHelper info(length);
uint zShapeInfoCast[MAX_RANK]; if(shape::elementWiseStride(zShapeInfo) == 1){
const bool canCastZ = nd4j::DataTypeUtils::castShapeInfo(zShapeInfo, zShapeInfoCast);
auto func = PRAGMA_THREADS_FOR { auto func = PRAGMA_THREADS_FOR {
PRAGMA_OMP_SIMD PRAGMA_OMP_SIMD
for (uint64_t i = start; i < stop; i += increment) { for (auto i = start; i < stop; i++) {
auto offset = shape::indexOffset(i, zShapeInfo, zShapeInfoCast, canCastZ); z[i] = OpClass::op( i, length, rng, extraArguments);
z[offset] = OpClass::op(i, length, rng, extraArguments); }
} };
};
samediff::Threads::parallel_for(func, 0, length, 1); samediff::Threads::parallel_for(func, 0, length, 1);
}
else{
nd4j::OmpLaunchHelper info(length);
uint zShapeInfoCast[MAX_RANK];
const bool canCastZ = nd4j::DataTypeUtils::castShapeInfo(zShapeInfo, zShapeInfoCast);
auto func = PRAGMA_THREADS_FOR {
PRAGMA_OMP_SIMD
for (uint64_t i = start; i < stop; i += increment) {
auto offset = shape::indexOffset(i, zShapeInfo, zShapeInfoCast, canCastZ);
z[offset] = OpClass::op(i, length, rng, extraArguments);
}
};
samediff::Threads::parallel_for(func, 0, length, 1);
}
} }
template<typename X> template<typename X>