ElementWiseStride==1 cases for legacy random ops (#202)
Signed-off-by: AbdelRauf <rauf@konduit.ai>master
parent
5d98cfcf47
commit
d39ca6d488
|
@ -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,6 +57,19 @@ namespace functions {
|
||||||
|
|
||||||
if(shape::haveSameShapeAndStrides(xShapeInfo, yShapeInfo) && shape::haveSameShapeAndStrides(xShapeInfo, zShapeInfo)) {
|
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];
|
uint xShapeInfoCast[MAX_RANK];
|
||||||
const bool canCastX = nd4j::DataTypeUtils::castShapeInfo(xShapeInfo, xShapeInfoCast);
|
const bool canCastX = nd4j::DataTypeUtils::castShapeInfo(xShapeInfo, xShapeInfoCast);
|
||||||
|
|
||||||
|
@ -69,6 +83,7 @@ namespace functions {
|
||||||
|
|
||||||
samediff::Threads::parallel_for(func, 0, length, 1);
|
samediff::Threads::parallel_for(func, 0, length, 1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (shape::haveSameShapeAndStrides(xShapeInfo, yShapeInfo)) {
|
else if (shape::haveSameShapeAndStrides(xShapeInfo, yShapeInfo)) {
|
||||||
|
|
||||||
uint xShapeInfoCast[MAX_RANK];
|
uint xShapeInfoCast[MAX_RANK];
|
||||||
|
@ -169,6 +184,17 @@ namespace functions {
|
||||||
|
|
||||||
if(shape::haveSameShapeAndStrides(xShapeInfo, zShapeInfo)) {
|
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 {
|
auto func = PRAGMA_THREADS_FOR {
|
||||||
PRAGMA_OMP_SIMD
|
PRAGMA_OMP_SIMD
|
||||||
for (uint64_t i = start; i < stop; i += increment) {
|
for (uint64_t i = start; i < stop; i += increment) {
|
||||||
|
@ -179,6 +205,7 @@ namespace functions {
|
||||||
|
|
||||||
samediff::Threads::parallel_for(func, 0, length, 1);
|
samediff::Threads::parallel_for(func, 0, length, 1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
uint zShapeInfoCast[MAX_RANK];
|
uint zShapeInfoCast[MAX_RANK];
|
||||||
|
@ -208,6 +235,19 @@ 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);
|
||||||
|
|
||||||
|
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);
|
nd4j::OmpLaunchHelper info(length);
|
||||||
|
|
||||||
uint zShapeInfoCast[MAX_RANK];
|
uint zShapeInfoCast[MAX_RANK];
|
||||||
|
@ -223,6 +263,7 @@ namespace functions {
|
||||||
|
|
||||||
samediff::Threads::parallel_for(func, 0, length, 1);
|
samediff::Threads::parallel_for(func, 0, length, 1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template<typename X>
|
template<typename X>
|
||||||
void RandomFunction<X>::execTransform(int opNum, Nd4jPointer state, void *x, Nd4jLong *xShapeInfo, void *z, Nd4jLong *zShapeInfo, void *extraArguments) {
|
void RandomFunction<X>::execTransform(int opNum, Nd4jPointer state, void *x, Nd4jLong *xShapeInfo, void *z, Nd4jLong *zShapeInfo, void *extraArguments) {
|
||||||
|
|
Loading…
Reference in New Issue