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 random {
template<typename X>
template<typename OpClass>
void RandomFunction<X>::execTransform(Nd4jPointer state,
@ -56,6 +57,19 @@ namespace functions {
if(shape::haveSameShapeAndStrides(xShapeInfo, yShapeInfo) && shape::haveSameShapeAndStrides(xShapeInfo, zShapeInfo)) {
if(shape::elementWiseStride(zShapeInfo) == 1 && shape::elementWiseStride(xShapeInfo) == 1 && shape::elementWiseStride(yShapeInfo) == 1 &&
shape::order(xShapeInfo) == shape::order(zShapeInfo) && shape::order(zShapeInfo) == shape::order(yShapeInfo) ){
auto func = PRAGMA_THREADS_FOR {
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);
@ -69,6 +83,7 @@ namespace functions {
samediff::Threads::parallel_for(func, 0, length, 1);
}
}
else if (shape::haveSameShapeAndStrides(xShapeInfo, yShapeInfo)) {
uint xShapeInfoCast[MAX_RANK];
@ -169,6 +184,17 @@ namespace functions {
if(shape::haveSameShapeAndStrides(xShapeInfo, zShapeInfo)) {
if(shape::elementWiseStride(zShapeInfo) == 1 && shape::elementWiseStride(xShapeInfo) == 1 && shape::order(xShapeInfo) == shape::order(zShapeInfo)){
auto func = PRAGMA_THREADS_FOR {
PRAGMA_OMP_SIMD
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) {
@ -179,6 +205,7 @@ namespace functions {
samediff::Threads::parallel_for(func, 0, length, 1);
}
}
else {
uint zShapeInfoCast[MAX_RANK];
@ -208,6 +235,19 @@ namespace functions {
auto length = shape::length(zShapeInfo);
nd4j::graph::RandomGenerator* rng = reinterpret_cast<nd4j::graph::RandomGenerator*>(state);
if(shape::elementWiseStride(zShapeInfo) == 1){
auto func = PRAGMA_THREADS_FOR {
PRAGMA_OMP_SIMD
for (auto i = start; i < stop; i++) {
z[i] = OpClass::op( i, length, rng, extraArguments);
}
};
samediff::Threads::parallel_for(func, 0, length, 1);
}
else{
nd4j::OmpLaunchHelper info(length);
uint zShapeInfoCast[MAX_RANK];
@ -223,6 +263,7 @@ namespace functions {
samediff::Threads::parallel_for(func, 0, length, 1);
}
}
template<typename X>
void RandomFunction<X>::execTransform(int opNum, Nd4jPointer state, void *x, Nd4jLong *xShapeInfo, void *z, Nd4jLong *zShapeInfo, void *extraArguments) {