chore: import upstream snapshot with attribution
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,168 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
* Broadcast operations (non-integer) - uses SD_COMMON_TYPES
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
// Selective rendering - MUST be included before types.h to define HAS_* flags
|
||||
#include <system/selective_rendering/core.h>
|
||||
#include <system/selective_rendering/bool_types.h>
|
||||
#include <system/selective_rendering/float_types.h>
|
||||
#include <system/selective_rendering/bfloat_types.h>
|
||||
#include <system/selective_rendering/int_types.h>
|
||||
#include <system/selective_rendering/uint_types.h>
|
||||
|
||||
#include <exceptions/datatype_exception.h>
|
||||
#include <execution/Threads.h>
|
||||
#include <helpers/LoopKind.h>
|
||||
#include <legacy/NativeOpExecutioner.h>
|
||||
#include <loops/broadcasting.h>
|
||||
#include <loops/broadcasting_bool.h>
|
||||
#include <types/types.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
void NativeOpExecutioner::execBroadcast(sd::LaunchContext *lc, int opNum, const void *hX,
|
||||
const sd::LongType *hXShapeInfo, const void *dX,
|
||||
const sd::LongType *dXShapeInfo, const void *hY,
|
||||
const sd::LongType *hYShapeInfo, const void *dY,
|
||||
const sd::LongType *dYShapeInfo, void *hZ, const sd::LongType *hZShapeInfo,
|
||||
void *dZ, const sd::LongType *dZShapeInfo, sd::LongType *dimension, sd::LongType dimensionLength,
|
||||
const sd::LongType *tadOnlyShapeInfo, const sd::LongType *tadOffsets,
|
||||
const sd::LongType *tadOnlyShapeInfoZ, const sd::LongType *tadOffsetsZ) {
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
auto yType = sd::ArrayOptions::dataType(hYShapeInfo);
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
auto loopKind = sd::LoopKind::deduceKindOfLoopBroadcast(hXShapeInfo, hYShapeInfo, hZShapeInfo);
|
||||
auto func = PRAGMA_THREADS_FOR {
|
||||
BUILD_SINGLE_SELECTOR_THRICE(
|
||||
xType, functions::broadcast::Broadcast,
|
||||
::exec(opNum, hX, hXShapeInfo, hY, hYShapeInfo, hZ, hZShapeInfo, dimension, dimensionLength, tadOnlyShapeInfo,
|
||||
tadOffsets, tadOnlyShapeInfoZ, tadOffsetsZ, loopKind, start, stop),
|
||||
SD_COMMON_TYPES);
|
||||
};
|
||||
|
||||
sd::LongType numTads = shape::tensorsAlongDimension(hXShapeInfo, dimension, dimensionLength);
|
||||
samediff::Threads::parallel_tad(func, 0, numTads);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
void NativeOpExecutioner::execBroadcast(sd::LaunchContext *lc, const int opNum, const void *hX,
|
||||
const sd::LongType *hXShapeInfo, const void *dX,
|
||||
const sd::LongType *dXShapeInfo, const void *hY,
|
||||
const sd::LongType *hYShapeInfo, const void *dY,
|
||||
const sd::LongType *dYShapeInfo, void *hZ, const sd::LongType *hZShapeInfo,
|
||||
void *dZ, const sd::LongType *dZShapeInfo) {
|
||||
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
auto yType = sd::ArrayOptions::dataType(hYShapeInfo);
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
|
||||
BUILD_SINGLE_SELECTOR_THRICE(xType, functions::broadcast::Broadcast,
|
||||
::exec(opNum, hX, hXShapeInfo, hY, hYShapeInfo, hZ, hZShapeInfo), SD_COMMON_TYPES);
|
||||
}
|
||||
|
||||
void NativeOpExecutioner::execInverseBroadcast(
|
||||
sd::LaunchContext *lc, int opNum, const void *hX, const sd::LongType *hXShapeInfo, const void *dX,
|
||||
const sd::LongType *dXShapeInfo, const void *hY, const sd::LongType *hYShapeInfo, const void *dY,
|
||||
const sd::LongType *dYShapeInfo, void *hZ, const sd::LongType *hZShapeInfo, void *dZ,
|
||||
const sd::LongType *dZShapeInfo,sd::LongType *dimension, sd::LongType dimensionLength, const sd::LongType *tadOnlyShapeInfo,
|
||||
const sd::LongType *tadOffsets, const sd::LongType *tadOnlyShapeInfoZ, const sd::LongType *tadOffsetsZ) {
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
auto yType = sd::ArrayOptions::dataType(hYShapeInfo);
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
|
||||
|
||||
if (!sd::Environment::getInstance().isExperimentalBuild())
|
||||
if ((yType != xType && yType != sd::DataType::BOOL) || xType != zType)
|
||||
THROW_EXCEPTION(sd::datatype_exception::build("NativeOps::execBroadcast both operands must have same data type", xType,
|
||||
yType).what());
|
||||
|
||||
auto func = PRAGMA_THREADS_FOR {
|
||||
BUILD_SINGLE_SELECTOR_THRICE(
|
||||
xType, functions::broadcast::Broadcast,
|
||||
::execInverse(opNum, hX, hXShapeInfo, hY, hYShapeInfo, hZ, hZShapeInfo, dimension, dimensionLength,
|
||||
tadOnlyShapeInfo, tadOffsets, tadOnlyShapeInfoZ, tadOffsetsZ, start, stop),
|
||||
SD_COMMON_TYPES);
|
||||
};
|
||||
|
||||
auto xLen = shape::length(hXShapeInfo);
|
||||
auto yLen = shape::length(hYShapeInfo);
|
||||
auto numTads = yLen / xLen;
|
||||
|
||||
samediff::Threads::parallel_tad(func, 0, numTads);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
void NativeOpExecutioner::execBroadcastBool(sd::LaunchContext *lc, int opNum, const void *hX,
|
||||
const sd::LongType *hXShapeInfo, const void *dX,
|
||||
const sd::LongType *dXShapeInfo, const void *hY,
|
||||
const sd::LongType *hYShapeInfo, const void *dY,
|
||||
const sd::LongType *dYShapeInfo, void *hZ, const sd::LongType *hZShapeInfo,
|
||||
void *dZ, const sd::LongType *dZShapeInfo, void *extraParams,
|
||||
sd::LongType *dimension, sd::LongType dimensionLength, const sd::LongType *tadOnlyShapeInfo,
|
||||
const sd::LongType *tadOffsets, const sd::LongType *tadOnlyShapeInfoZ,
|
||||
const sd::LongType *tadOffsetsZ) {
|
||||
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
auto func = PRAGMA_THREADS_FOR {
|
||||
BUILD_DOUBLE_SELECTOR(
|
||||
xType, zType, functions::broadcast::BroadcastBool,
|
||||
::exec(opNum, hX, hXShapeInfo, hY, hYShapeInfo, hZ, hZShapeInfo, extraParams, dimension, dimensionLength,
|
||||
tadOnlyShapeInfo, tadOffsets, tadOnlyShapeInfoZ, tadOffsetsZ, start, stop),
|
||||
SD_COMMON_TYPES, SD_BOOL_TYPES);
|
||||
};
|
||||
auto xLen = shape::length(hXShapeInfo);
|
||||
auto yLen = shape::length(hYShapeInfo);
|
||||
auto numTads = xLen / yLen;
|
||||
|
||||
samediff::Threads::parallel_tad(func, 0, numTads);
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
void NativeOpExecutioner::execBroadcastBool(sd::LaunchContext *lc, const int opNum, const void *hX,
|
||||
const sd::LongType *hXShapeInfo, const void *dX,
|
||||
const sd::LongType *dXShapeInfo, const void *hY,
|
||||
const sd::LongType *hYShapeInfo, const void *dY,
|
||||
const sd::LongType *dYShapeInfo, void *hZ, const sd::LongType *hZShapeInfo,
|
||||
void *dZ, const sd::LongType *dZShapeInfo, void *extraParams) {
|
||||
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
BUILD_DOUBLE_SELECTOR(xType, zType, functions::broadcast::BroadcastBool,
|
||||
::exec(opNum, hX, hXShapeInfo, hY, hYShapeInfo, hZ, hZShapeInfo, extraParams), SD_COMMON_TYPES,
|
||||
SD_BOOL_TYPES);
|
||||
}
|
||||
|
||||
void NativeOpExecutioner::execInverseBroadcastBool(
|
||||
sd::LaunchContext *lc, int opNum, const void *hX, const sd::LongType *hXShapeInfo, const void *dX,
|
||||
const sd::LongType *dXShapeInfo, const void *hY, const sd::LongType *hYShapeInfo, const void *dY,
|
||||
const sd::LongType *dYShapeInfo, void *hZ, const sd::LongType *hZShapeInfo, void *dZ,
|
||||
const sd::LongType *dZShapeInfo, void *extraParams,sd::LongType *dimension, sd::LongType dimensionLength,
|
||||
const sd::LongType *tadOnlyShapeInfo, const sd::LongType *tadOffsets, const sd::LongType *tadOnlyShapeInfoZ,
|
||||
const sd::LongType *tadOffsetsZ) {
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
auto yType = sd::ArrayOptions::dataType(hYShapeInfo);
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
|
||||
|
||||
if (!sd::Environment::getInstance().isExperimentalBuild())
|
||||
if (yType != xType || sd::DataType::BOOL != zType)
|
||||
THROW_EXCEPTION(sd::datatype_exception::build("NativeOps::execInverseBroadcastBool both operands must have same data type",
|
||||
xType, yType).what());
|
||||
|
||||
auto func = PRAGMA_THREADS_FOR {
|
||||
BUILD_DOUBLE_SELECTOR(
|
||||
xType, zType, functions::broadcast::BroadcastBool,
|
||||
::execInverse(opNum, hX, hXShapeInfo, hY, hYShapeInfo, hZ, hZShapeInfo, extraParams, dimension, dimensionLength,
|
||||
tadOnlyShapeInfo, tadOffsets, tadOnlyShapeInfoZ, tadOffsetsZ, start, stop),
|
||||
SD_COMMON_TYPES, SD_BOOL_TYPES);
|
||||
};
|
||||
auto xLen = shape::length(hXShapeInfo);
|
||||
auto yLen = shape::length(hYShapeInfo);
|
||||
auto numTads = yLen / xLen;
|
||||
|
||||
samediff::Threads::parallel_tad(func, 0, numTads);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
* IndexReduce operations - uses SD_COMMON_TYPES and SD_INDEXING_TYPES
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
// Selective rendering - MUST be included before types.h to define HAS_* flags
|
||||
#include <system/selective_rendering/core.h>
|
||||
#include <system/selective_rendering/bool_types.h>
|
||||
#include <system/selective_rendering/float_types.h>
|
||||
#include <system/selective_rendering/bfloat_types.h>
|
||||
#include <system/selective_rendering/int_types.h>
|
||||
#include <system/selective_rendering/uint_types.h>
|
||||
|
||||
#include <legacy/NativeOpExecutioner.h>
|
||||
#include <loops/indexreduce.h>
|
||||
#include <types/types.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
void NativeOpExecutioner::execIndexReduceScalar(sd::LaunchContext *lc, int opNum, const void *hX,
|
||||
const sd::LongType *hXShapeInfo, const void *dX,
|
||||
const sd::LongType *dXShapeInfo, void *extraParams, void *hZ,
|
||||
const sd::LongType *hZShapeInfo, void *dZ,
|
||||
const sd::LongType *dZShapeInfo) {
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
auto hz = reinterpret_cast<sd::LongType *>(hZ);
|
||||
BUILD_DOUBLE_SELECTOR(xType, zType, hz[0] = functions::indexreduce::IndexReduce,
|
||||
::execScalar(opNum, hX, hXShapeInfo, extraParams), SD_COMMON_TYPES, SD_INDEXING_TYPES);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
void NativeOpExecutioner::execIndexReduce(sd::LaunchContext *lc, int opNum, const void *hX,
|
||||
const sd::LongType *hXShapeInfo, const void *dX,
|
||||
const sd::LongType *dXShapeInfo, void *extraParams, void *hZ,
|
||||
const sd::LongType *hZShapeInfo, void *dZ, const sd::LongType *dZShapeInfo,
|
||||
sd::LongType *dimension, sd::LongType dimensionLength, const sd::LongType *tadShapeInfo,
|
||||
const sd::LongType *tadOffsets) {
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
auto hz = reinterpret_cast<sd::LongType *>(hZ);
|
||||
BUILD_DOUBLE_SELECTOR(xType, zType, functions::indexreduce::IndexReduce,
|
||||
::exec(opNum, hX, hXShapeInfo, extraParams, hz, hZShapeInfo, dimension, dimensionLength,
|
||||
tadShapeInfo, tadOffsets),
|
||||
SD_COMMON_TYPES, SD_INDEXING_TYPES);
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
* Integer-only operations - uses ONLY integer types
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
// Selective rendering - MUST be included before types.h to define HAS_* flags
|
||||
// Note: DataTypeUtils.h->logger.h uses SD_COMMON_TYPES, so we need all core types
|
||||
#include <system/selective_rendering/core.h>
|
||||
#include <system/selective_rendering/bool_types.h>
|
||||
#include <system/selective_rendering/float_types.h>
|
||||
#include <system/selective_rendering/bfloat_types.h>
|
||||
#include <system/selective_rendering/int_types.h>
|
||||
#include <system/selective_rendering/uint_types.h>
|
||||
|
||||
#include <array/DataTypeUtils.h>
|
||||
#include <exceptions/datatype_exception.h>
|
||||
#include <execution/Threads.h>
|
||||
#include <helpers/LoopKind.h>
|
||||
#include <legacy/NativeOpExecutioner.h>
|
||||
#include <loops/broadcasting_int.h>
|
||||
#include <loops/pairwise_int.h>
|
||||
#include <loops/scalar_int.h>
|
||||
#include <types/types.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
void NativeOpExecutioner::execBroadcastInt(
|
||||
sd::LaunchContext *lc, int opNum, const void *hX, const sd::LongType *hXShapeInfo, const void *dX,
|
||||
const sd::LongType *dXShapeInfo, const void *hY, const sd::LongType *hYShapeInfo, const void *dY,
|
||||
const sd::LongType *dYShapeInfo, void *hZ, const sd::LongType *hZShapeInfo, void *dZ,
|
||||
const sd::LongType *dZShapeInfo,sd::LongType *dimension, sd::LongType dimensionLength, const sd::LongType *tadOnlyShapeInfo,
|
||||
const sd::LongType *tadOffsets, const sd::LongType *tadOnlyShapeInfoZ, const sd::LongType *tadOffsetsZ) {
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
auto yType = sd::ArrayOptions::dataType(hYShapeInfo);
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
|
||||
|
||||
if (xType != yType || xType != zType)
|
||||
THROW_EXCEPTION(sd::datatype_exception::build("NativeOpExecutioner::execBroadcastInt", zType, xType, yType).what());
|
||||
|
||||
if (!sd::DataTypeUtils::isZ(zType))
|
||||
THROW_EXCEPTION(sd::datatype_exception::build("NativeOpExecutioner::execBroadcastInt requires integer data type", zType).what());
|
||||
auto func = PRAGMA_THREADS_FOR {
|
||||
BUILD_SINGLE_SELECTOR(xType, functions::broadcast::BroadcastInt,
|
||||
::exec(opNum, hX, hXShapeInfo, hY, hYShapeInfo, hZ, hZShapeInfo, dimension, dimensionLength,
|
||||
tadOnlyShapeInfo, tadOffsets, tadOnlyShapeInfoZ, tadOffsetsZ, start, stop),
|
||||
SD_INTEGER_TYPES);
|
||||
};
|
||||
|
||||
auto xLen = shape::length(hXShapeInfo);
|
||||
auto yLen = shape::length(hYShapeInfo);
|
||||
auto numTads = xLen / yLen;
|
||||
|
||||
samediff::Threads::parallel_tad(func, 0, numTads);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
void NativeOpExecutioner::execBroadcastInt(sd::LaunchContext *lc, const int opNum, const void *hX,
|
||||
const sd::LongType *hXShapeInfo, const void *dX,
|
||||
const sd::LongType *dXShapeInfo, const void *hY,
|
||||
const sd::LongType *hYShapeInfo, const void *dY,
|
||||
const sd::LongType *dYShapeInfo, void *hZ, const sd::LongType *hZShapeInfo,
|
||||
void *dZ, const sd::LongType *dZShapeInfo) {
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
auto yType = sd::ArrayOptions::dataType(hYShapeInfo);
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
|
||||
|
||||
if (xType != yType || xType != zType)
|
||||
THROW_EXCEPTION(sd::datatype_exception::build("NativeOpExecutioner::execBroadcastInt", zType, xType, yType).what());
|
||||
|
||||
if (!sd::DataTypeUtils::isZ(zType))
|
||||
THROW_EXCEPTION(sd::datatype_exception::build("NativeOpExecutioner::execBroadcastInt requires integer data type", zType).what());
|
||||
BUILD_SINGLE_SELECTOR(xType, functions::broadcast::BroadcastInt,
|
||||
::exec(opNum, hX, hXShapeInfo, hY, hYShapeInfo, hZ, hZShapeInfo), SD_INTEGER_TYPES);
|
||||
}
|
||||
|
||||
void NativeOpExecutioner::execInverseBroadcastInt(
|
||||
sd::LaunchContext *lc, int opNum, const void *hX, const sd::LongType *hXShapeInfo, const void *dX,
|
||||
const sd::LongType *dXShapeInfo, const void *hY, const sd::LongType *hYShapeInfo, const void *dY,
|
||||
const sd::LongType *dYShapeInfo, void *hZ, const sd::LongType *hZShapeInfo, void *dZ,
|
||||
const sd::LongType *dZShapeInfo,sd::LongType *dimension, sd::LongType dimensionLength, const sd::LongType *tadOnlyShapeInfo,
|
||||
const sd::LongType *tadOffsets, const sd::LongType *tadOnlyShapeInfoZ, const sd::LongType *tadOffsetsZ) {
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
auto yType = sd::ArrayOptions::dataType(hYShapeInfo);
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
|
||||
|
||||
if (xType != yType || xType != zType)
|
||||
THROW_EXCEPTION(sd::datatype_exception::build("NativeOpExecutioner::execInverseBroadcastInt", zType, xType, yType).what());
|
||||
|
||||
if (!sd::DataTypeUtils::isZ(zType))
|
||||
THROW_EXCEPTION(sd::datatype_exception::build("NativeOpExecutioner::execInverseBroadcastInt requires integer data type",
|
||||
zType).what());
|
||||
auto func = PRAGMA_THREADS_FOR {
|
||||
BUILD_SINGLE_SELECTOR(
|
||||
xType, functions::broadcast::BroadcastInt,
|
||||
::execInverse(opNum, hX, hXShapeInfo, hY, hYShapeInfo, hZ, hZShapeInfo, dimension, dimensionLength,
|
||||
tadOnlyShapeInfo, tadOffsets, tadOnlyShapeInfoZ, tadOffsetsZ, start, stop),
|
||||
SD_INTEGER_TYPES);
|
||||
};
|
||||
|
||||
auto xLen = shape::length(hXShapeInfo);
|
||||
auto yLen = shape::length(hYShapeInfo);
|
||||
auto numTads = yLen / xLen;
|
||||
|
||||
samediff::Threads::parallel_tad(func, 0, numTads);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// execPairwiseIntTransform moved to NativeOpExecutioner_pairwise_int.cpp
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
void NativeOpExecutioner::execScalarInt(sd::LaunchContext *lc, int opNum, const void *hX,
|
||||
const sd::LongType *hXShapeInfo, const void *dX,
|
||||
const sd::LongType *dXShapeInfo, void *hZ, const sd::LongType *hZShapeInfo,
|
||||
void *dZ, const sd::LongType *dZShapeInfo, const void *hScalar,
|
||||
const sd::LongType *hSscalarShapeInfo, const void *dScalar,
|
||||
const sd::LongType *dSscalarShapeInfo, void *extraParams,
|
||||
bool allowParallelism) {
|
||||
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
auto yType = sd::ArrayOptions::dataType(hSscalarShapeInfo);
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
if (!sd::DataTypeUtils::isZ(zType)) {
|
||||
std::string errorMessage;
|
||||
errorMessage += "NativeOpExecutioner::execScalarInt requires result type to be an integer type";
|
||||
errorMessage += "X data type: ";
|
||||
errorMessage += sd::DataTypeUtils::asString(xType);
|
||||
errorMessage += ", Y data type: ";
|
||||
errorMessage += sd::DataTypeUtils::asString(yType);
|
||||
errorMessage += ", Z data type: ";
|
||||
errorMessage += sd::DataTypeUtils::asString(zType);
|
||||
THROW_EXCEPTION(errorMessage.c_str());
|
||||
|
||||
}
|
||||
|
||||
auto func = PRAGMA_THREADS_FOR {
|
||||
BUILD_SINGLE_SELECTOR(xType, functions::scalar::ScalarIntTransform,
|
||||
::transform(opNum, hX, hXShapeInfo, hZ, hZShapeInfo, hScalar, extraParams, start, stop),
|
||||
SD_INTEGER_TYPES);
|
||||
};
|
||||
|
||||
auto zLen = shape::length(hZShapeInfo);
|
||||
samediff::Threads::parallel_for(
|
||||
func, 0, zLen, 1,
|
||||
!allowParallelism
|
||||
? 1
|
||||
: sd::math::sd_max<int>(
|
||||
1, sd::math::sd_min<int>(zLen / 1024, sd::Environment::getInstance().maxMasterThreads())));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// TAD execScalarInt moved to NativeOpExecutioner_scalar_tad_ints.cpp
|
||||
@@ -0,0 +1,46 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
* Pairwise operations - BOOL TYPES OUTPUT ONLY
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#include <system/op_boilerplate.h>
|
||||
|
||||
#include <array/DataTypeUtils.h>
|
||||
#include <exceptions/datatype_exception.h>
|
||||
#include <execution/Threads.h>
|
||||
#include <legacy/NativeOpExecutioner.h>
|
||||
#include <loops/pairwise_bool.h>
|
||||
#include <types/types.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
void NativeOpExecutioner::execPairwiseBoolTransform(sd::LaunchContext *lc, int opNum, const void *hX,
|
||||
const sd::LongType *hXShapeInfo, const void *dX,
|
||||
const sd::LongType *dXShapeInfo, const void *hY,
|
||||
const sd::LongType *hYShapeInfo, const void *dY,
|
||||
const sd::LongType *dYShapeInfo, void *hZ,
|
||||
const sd::LongType *hZShapeInfo, void *dZ,
|
||||
const sd::LongType *dZShapeInfo, void *extraParams) {
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
auto yType = sd::ArrayOptions::dataType(hYShapeInfo);
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
|
||||
if (zType != sd::DataType::BOOL) {
|
||||
std::string errorMessage;
|
||||
errorMessage += "NativeOpExecutioner::execPairwiseBoolTransform";
|
||||
errorMessage += " zType must be BOOL";
|
||||
errorMessage += " zType: ";
|
||||
errorMessage += sd::DataTypeUtils::asString(zType);
|
||||
THROW_EXCEPTION(errorMessage.c_str());
|
||||
}
|
||||
auto func = PRAGMA_THREADS_FOR {
|
||||
BUILD_DOUBLE_SELECTOR(xType, zType, functions::pairwise_transforms::PairWiseBoolTransform,
|
||||
::exec(opNum, hX, hXShapeInfo, hY, hYShapeInfo, hZ, hZShapeInfo, extraParams, start, stop),
|
||||
SD_COMMON_TYPES, SD_BOOL_TYPES);
|
||||
};
|
||||
|
||||
auto zLen = shape::length(hZShapeInfo);
|
||||
samediff::Threads::parallel_for(
|
||||
func, 0, zLen, 1,
|
||||
sd::math::sd_max<int>(1, sd::math::sd_min<int>(zLen / 1024, sd::Environment::getInstance().maxMasterThreads())));
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
* Pairwise operations - GENERIC/FLOAT TYPES
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
// Selective rendering - MUST be included before types.h to define HAS_* flags
|
||||
#include <system/selective_rendering/core.h>
|
||||
#include <system/selective_rendering/bool_types.h>
|
||||
#include <system/selective_rendering/float_types.h>
|
||||
#include <system/selective_rendering/bfloat_types.h>
|
||||
#include <system/selective_rendering/int_types.h>
|
||||
#include <system/selective_rendering/uint_types.h>
|
||||
|
||||
#include <array/DataTypeUtils.h>
|
||||
#include <exceptions/datatype_exception.h>
|
||||
#include <execution/Threads.h>
|
||||
#include <legacy/NativeOpExecutioner.h>
|
||||
#include <loops/pairwise_transform.h>
|
||||
#include <types/types.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
void NativeOpExecutioner::execPairwiseTransform(sd::LaunchContext *lc, int opNum, const void *hX,
|
||||
const sd::LongType *hXShapeInfo, const void *dX,
|
||||
const sd::LongType *dXShapeInfo, const void *hY,
|
||||
const sd::LongType *hYShapeInfo, const void *dY,
|
||||
const sd::LongType *dYShapeInfo, void *hZ,
|
||||
const sd::LongType *hZShapeInfo, void *dZ,
|
||||
const sd::LongType *dZShapeInfo, void *extraParams) {
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
auto yType = sd::ArrayOptions::dataType(hYShapeInfo);
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
|
||||
if (sd::DataTypeUtils::isS(xType) || sd::DataTypeUtils::isS(yType) || sd::DataTypeUtils::isS(zType)) {
|
||||
std::string errorMessage;
|
||||
errorMessage += "NativeOpExecutioner::execPairwiseTransform:: unable to execute on strings. ";
|
||||
errorMessage += "X type: ";
|
||||
errorMessage += sd::DataTypeUtils::asString(xType);
|
||||
errorMessage += " Y type: ";
|
||||
errorMessage += sd::DataTypeUtils::asString(yType);
|
||||
errorMessage += " Z type: ";
|
||||
errorMessage += sd::DataTypeUtils::asString(zType);
|
||||
THROW_EXCEPTION(errorMessage.c_str());
|
||||
}
|
||||
|
||||
if (xType != zType && yType != zType) {
|
||||
std::string errorMessage;
|
||||
errorMessage += "NativeOpExecutioner::execPairwiseTransform both operands must have same data type. ";
|
||||
errorMessage += "X type: ";
|
||||
errorMessage += sd::DataTypeUtils::asString(xType);
|
||||
errorMessage += " Y type: ";
|
||||
errorMessage += sd::DataTypeUtils::asString(yType);
|
||||
errorMessage += " Z type: ";
|
||||
errorMessage += sd::DataTypeUtils::asString(zType);
|
||||
THROW_EXCEPTION(errorMessage.c_str());
|
||||
}
|
||||
|
||||
auto func = PRAGMA_THREADS_FOR {
|
||||
BUILD_TRIPLE_SELECTOR(xType, yType, zType, functions::pairwise_transforms::PairWiseTransform,
|
||||
::exec(opNum, hX, hXShapeInfo, hY, hYShapeInfo, hZ, hZShapeInfo, extraParams, start, stop),
|
||||
SD_NUMERIC_TYPES, SD_NUMERIC_TYPES, SD_NUMERIC_TYPES);
|
||||
};
|
||||
|
||||
auto zLen = shape::length(hZShapeInfo);
|
||||
samediff::Threads::parallel_for(
|
||||
func, 0, zLen, 1,
|
||||
sd::math::sd_max<int>(1, sd::math::sd_min<int>(zLen / 1024, sd::Environment::getInstance().maxMasterThreads())));
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
* Pairwise operations - INTEGER TYPES OUTPUT ONLY
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#include <system/op_boilerplate.h>
|
||||
|
||||
#include <array/DataTypeUtils.h>
|
||||
#include <exceptions/datatype_exception.h>
|
||||
#include <execution/Threads.h>
|
||||
#include <legacy/NativeOpExecutioner.h>
|
||||
#include <loops/pairwise_int.h>
|
||||
#include <types/types.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
void NativeOpExecutioner::execPairwiseIntTransform(sd::LaunchContext *lc, int opNum, const void *hX,
|
||||
const sd::LongType *hXShapeInfo, const void *dX,
|
||||
const sd::LongType *dXShapeInfo, const void *hY,
|
||||
const sd::LongType *hYShapeInfo, const void *dY,
|
||||
const sd::LongType *dYShapeInfo, void *hZ,
|
||||
const sd::LongType *hZShapeInfo, void *dZ,
|
||||
const sd::LongType *dZShapeInfo, void *extraParams) {
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
|
||||
auto func = PRAGMA_THREADS_FOR {
|
||||
// PairWiseIntTransform only takes ONE template parameter (X type)
|
||||
BUILD_SINGLE_SELECTOR(xType, functions::pairwise_transforms::PairWiseIntTransform,
|
||||
::exec(opNum, hX, hXShapeInfo, hY, hYShapeInfo, hZ, hZShapeInfo, extraParams, start, stop),
|
||||
SD_COMMON_TYPES);
|
||||
};
|
||||
|
||||
auto zLen = shape::length(hZShapeInfo);
|
||||
samediff::Threads::parallel_for(
|
||||
func, 0, zLen, 1,
|
||||
sd::math::sd_max<int>(1, sd::math::sd_min<int>(zLen / 1024, sd::Environment::getInstance().maxMasterThreads())));
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
* Random operations - uses ONLY float types
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
// Selective rendering - MUST be included before types.h to define HAS_* flags
|
||||
// Note: NativeOpExecutioner.h->NDArray.h uses SD_COMMON_TYPES, so we need all core types
|
||||
#include <system/selective_rendering/core.h>
|
||||
#include <system/selective_rendering/bool_types.h>
|
||||
#include <system/selective_rendering/float_types.h>
|
||||
#include <system/selective_rendering/bfloat_types.h>
|
||||
#include <system/selective_rendering/int_types.h>
|
||||
#include <system/selective_rendering/uint_types.h>
|
||||
|
||||
#include <legacy/NativeOpExecutioner.h>
|
||||
#include <loops/random.h>
|
||||
#include <types/types.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
void NativeOpExecutioner::execRandom(sd::LaunchContext *lc, int opNum, sd::Pointer state, void *hZ,
|
||||
const sd::LongType *hZShapeInfo, void *dZ, const sd::LongType *dZShapeInfo,
|
||||
void *extraArguments) {
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
BUILD_SINGLE_SELECTOR(zType, functions::random::RandomFunction,
|
||||
::execTransform(opNum, state, hZ, hZShapeInfo, extraArguments), SD_FLOAT_TYPES);
|
||||
auto rng = reinterpret_cast<sd::graph::RandomGenerator *>(state);
|
||||
rng->rewindH(shape::length(hZShapeInfo));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
void NativeOpExecutioner::execRandom(sd::LaunchContext *lc, int opNum, sd::Pointer state, const void *hX,
|
||||
const sd::LongType *hXShapeInfo, const void *dX, const sd::LongType *dXShapeInfo,
|
||||
void *hZ, const sd::LongType *hZShapeInfo, void *dZ,
|
||||
const sd::LongType *dZShapeInfo, void *extraArguments) {
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
BUILD_SINGLE_SELECTOR(zType, functions::random::RandomFunction,
|
||||
::execTransform(opNum, state, hX, hXShapeInfo, hZ, hZShapeInfo, extraArguments),
|
||||
SD_FLOAT_TYPES);
|
||||
auto rng = reinterpret_cast<sd::graph::RandomGenerator *>(state);
|
||||
rng->rewindH(shape::length(hZShapeInfo));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
void NativeOpExecutioner::execRandom(sd::LaunchContext *lc, int opNum, sd::Pointer state, const void *hX,
|
||||
const sd::LongType *hXShapeInfo, const void *dX, const sd::LongType *dXShapeInfo,
|
||||
const void *hY, const sd::LongType *hYShapeInfo, const void *dY,
|
||||
const sd::LongType *dYShapeInfo, void *hZ, const sd::LongType *hZShapeInfo,
|
||||
void *dZ, const sd::LongType *dZShapeInfo, void *extraArguments) {
|
||||
auto xType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
BUILD_SINGLE_SELECTOR(
|
||||
xType, functions::random::RandomFunction,
|
||||
::execTransform(opNum, state, hX, hXShapeInfo, hY, hYShapeInfo, hZ, hZShapeInfo, extraArguments), SD_FLOAT_TYPES);
|
||||
auto rng = reinterpret_cast<sd::graph::RandomGenerator *>(state);
|
||||
rng->rewindH(shape::length(hZShapeInfo));
|
||||
}
|
||||
@@ -0,0 +1,277 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
* Reduce operations - uses SD_NUMERIC_TYPES, SD_FLOAT_TYPES, SD_COMMON_TYPES, SD_BOOL_TYPES
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
// Selective rendering - MUST be included before types.h to define HAS_* flags
|
||||
#include <system/selective_rendering/core.h>
|
||||
#include <system/selective_rendering/bool_types.h>
|
||||
#include <system/selective_rendering/float_types.h>
|
||||
#include <system/selective_rendering/bfloat_types.h>
|
||||
#include <system/selective_rendering/int_types.h>
|
||||
#include <system/selective_rendering/uint_types.h>
|
||||
|
||||
#include <array/TadPack.h>
|
||||
#include <execution/Threads.h>
|
||||
#include <helpers/ConstantTadHelper.h>
|
||||
#include <legacy/NativeOpExecutioner.h>
|
||||
#include <loops/reduce3.h>
|
||||
#include <loops/reduce_bool.h>
|
||||
#include <loops/reduce_float.h>
|
||||
#include <loops/reduce_long.h>
|
||||
#include <loops/reduce_same.h>
|
||||
#include <types/types.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
void NativeOpExecutioner::execReduceFloat(sd::LaunchContext *lc, int opNum, const void *hX,
|
||||
const sd::LongType *hXShapeInfo, const void *dX,
|
||||
const sd::LongType *dXShapeInfo, void *extraParams, void *hZ,
|
||||
const sd::LongType *hZShapeInfo, void *dZ, const sd::LongType *dZShapeInfo,
|
||||
sd::LongType *dimension, sd::LongType dimensionLength) {
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
BUILD_DOUBLE_SELECTOR(
|
||||
xType, zType, functions::reduce::ReduceFloatFunction,
|
||||
::exec(opNum, lc ? lc->getWorkspace() : nullptr, hX, hXShapeInfo, extraParams, hZ, hZShapeInfo, dimension),
|
||||
SD_NUMERIC_TYPES, SD_FLOAT_TYPES);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
void NativeOpExecutioner::execReduceSame(sd::LaunchContext *lc, int opNum, const void *hX,
|
||||
const sd::LongType *hXShapeInfo, const void *dX,
|
||||
const sd::LongType *dXShapeInfo, void *extraParams, void *hZ,
|
||||
const sd::LongType *hZShapeInfo, void *dZ, const sd::LongType *dZShapeInfo,
|
||||
sd::LongType *dimension, sd::LongType dimensionLength) {
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
BUILD_SINGLE_SELECTOR(
|
||||
xType, functions::reduce::ReduceSameFunction,
|
||||
::exec(opNum, lc ? lc->getWorkspace() : nullptr, hX, hXShapeInfo, extraParams, hZ, hZShapeInfo, dimension),
|
||||
SD_NUMERIC_TYPES);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
void NativeOpExecutioner::execReduceBool(sd::LaunchContext *lc, int opNum, const void *hX,
|
||||
const sd::LongType *hXShapeInfo, const void *dX,
|
||||
const sd::LongType *dXShapeInfo, void *extraParams, void *hZ,
|
||||
const sd::LongType *hZShapeInfo, void *dZ, const sd::LongType *dZShapeInfo,
|
||||
sd::LongType *dimension, sd::LongType dimensionLength) {
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
BUILD_DOUBLE_SELECTOR(
|
||||
xType, zType, functions::reduce::ReduceBoolFunction,
|
||||
::exec(opNum, lc ? lc->getWorkspace() : nullptr, hX, hXShapeInfo, extraParams, hZ, hZShapeInfo, dimension),
|
||||
SD_COMMON_TYPES, SD_BOOL_TYPES);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
void NativeOpExecutioner::execReduceLong(sd::LaunchContext *lc, int opNum, const void *hX,
|
||||
const sd::LongType *hXShapeInfo, const void *dX,
|
||||
const sd::LongType *dXShapeInfo, void *extraParams, void *hZ,
|
||||
const sd::LongType *hZShapeInfo, void *dZ, const sd::LongType *dZShapeInfo,
|
||||
sd::LongType *dimension, sd::LongType dimensionLength) {
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
|
||||
// Explicit double handling for REDUCE_LONG dimensional operations
|
||||
// BUILD_DOUBLE_SELECTOR may not generate cases for double->long conversions in some build configurations
|
||||
if (xType == sd::DataType::DOUBLE) {
|
||||
if (zType == sd::DataType::INT64) {
|
||||
functions::reduce::ReduceLongFunction<double, sd::LongType>::exec(
|
||||
opNum, lc ? lc->getWorkspace() : nullptr, hX, hXShapeInfo, extraParams, hZ, hZShapeInfo, dimension);
|
||||
return;
|
||||
} else if (zType == sd::DataType::UINT64) {
|
||||
functions::reduce::ReduceLongFunction<double, sd::UnsignedLong>::exec(
|
||||
opNum, lc ? lc->getWorkspace() : nullptr, hX, hXShapeInfo, extraParams, hZ, hZShapeInfo, dimension);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
BUILD_DOUBLE_SELECTOR(
|
||||
xType, zType, functions::reduce::ReduceLongFunction,
|
||||
::exec(opNum, lc ? lc->getWorkspace() : nullptr, hX, hXShapeInfo, extraParams, hZ, hZShapeInfo, dimension),
|
||||
SD_COMMON_TYPES, SD_LONG_TYPES);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
void NativeOpExecutioner::execReduceFloatScalar(sd::LaunchContext *lc, int opNum, const void *hX,
|
||||
const sd::LongType *hXShapeInfo, const void *dX,
|
||||
const sd::LongType *dXShapeInfo, void *extraParams, void *hZ,
|
||||
const sd::LongType *hZShapeInfo, void *dZ,
|
||||
const sd::LongType *dZShapeInfo) {
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
BUILD_DOUBLE_SELECTOR(xType, zType, functions::reduce::ReduceFloatFunction,
|
||||
::execScalar(opNum, hX, hXShapeInfo, extraParams, hZ, hZShapeInfo), SD_NUMERIC_TYPES,
|
||||
SD_FLOAT_TYPES);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
void NativeOpExecutioner::execReduceSameScalar(sd::LaunchContext *lc, int opNum, const void *hX,
|
||||
const sd::LongType *hXShapeInfo, const void *dX,
|
||||
const sd::LongType *dXShapeInfo, void *extraParams, void *hZ,
|
||||
const sd::LongType *hZShapeInfo, void *dZ,
|
||||
const sd::LongType *dZShapeInfo) {
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
BUILD_SINGLE_SELECTOR(xType, functions::reduce::ReduceSameFunction,
|
||||
::execScalar(opNum, hX, hXShapeInfo, extraParams, hZ, hZShapeInfo), SD_NUMERIC_TYPES);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
void NativeOpExecutioner::execReduceBoolScalar(sd::LaunchContext *lc, int opNum, const void *hX,
|
||||
const sd::LongType *hXShapeInfo, const void *dX,
|
||||
const sd::LongType *dXShapeInfo, void *extraParams, void *hZ,
|
||||
const sd::LongType *hZShapeInfo, void *dZ,
|
||||
const sd::LongType *dZShapeInfo) {
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
BUILD_DOUBLE_SELECTOR(xType, zType, functions::reduce::ReduceBoolFunction,
|
||||
::execScalar(opNum, hX, hXShapeInfo, extraParams, hZ, hZShapeInfo), SD_COMMON_TYPES,
|
||||
SD_BOOL_TYPES);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
void NativeOpExecutioner::execReduceLongScalar(sd::LaunchContext *lc, int opNum, const void *hX,
|
||||
const sd::LongType *hXShapeInfo, const void *dX,
|
||||
const sd::LongType *dXShapeInfo, void *extraParams, void *hZ,
|
||||
const sd::LongType *hZShapeInfo, void *dZ,
|
||||
const sd::LongType *dZShapeInfo) {
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
|
||||
// Explicit double handling for REDUCE_LONG scalar operations
|
||||
// BUILD_DOUBLE_SELECTOR may not generate cases for double->long conversions in some build configurations
|
||||
if (xType == sd::DataType::DOUBLE) {
|
||||
if (zType == sd::DataType::INT64) {
|
||||
functions::reduce::ReduceLongFunction<double, sd::LongType>::execScalar(
|
||||
opNum, hX, hXShapeInfo, extraParams, hZ, hZShapeInfo);
|
||||
return;
|
||||
} else if (zType == sd::DataType::UINT64) {
|
||||
functions::reduce::ReduceLongFunction<double, sd::UnsignedLong>::execScalar(
|
||||
opNum, hX, hXShapeInfo, extraParams, hZ, hZShapeInfo);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
BUILD_DOUBLE_SELECTOR(xType, zType, functions::reduce::ReduceLongFunction,
|
||||
::execScalar(opNum, hX, hXShapeInfo, extraParams, hZ, hZShapeInfo), SD_COMMON_TYPES,
|
||||
SD_LONG_TYPES);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
void NativeOpExecutioner::execReduce3Scalar(sd::LaunchContext *lc, int opNum, const void *hX,
|
||||
const sd::LongType *hXShapeInfo, const void *dX,
|
||||
const sd::LongType *dXShapeInfo, void *extraParamsVals, const void *hY,
|
||||
const sd::LongType *hYShapeInfo, const void *dY,
|
||||
const sd::LongType *dYShapeInfo, void *hZ, const sd::LongType *hZShapeInfo,
|
||||
void *dZ, const sd::LongType *dZShapeInfo) {
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
BUILD_DOUBLE_SELECTOR(xType, zType, functions::reduce3::Reduce3,
|
||||
::execScalar(opNum, hX, hXShapeInfo, extraParamsVals, hY, hYShapeInfo, hZ, hZShapeInfo),
|
||||
SD_COMMON_TYPES, SD_FLOAT_TYPES);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
void NativeOpExecutioner::execReduce3(sd::LaunchContext *lc, int opNum, const void *hX, const sd::LongType *hXShapeInfo,
|
||||
const void *dX, const sd::LongType *dXShapeInfo, void *extraParamsVals,
|
||||
const void *hY, const sd::LongType *hYShapeInfo, const void *dY,
|
||||
const sd::LongType *dYShapeInfo, void *hZ, const sd::LongType *hZShapeInfo,
|
||||
void *dZ, const sd::LongType *dZShapeInfo) {
|
||||
NativeOpExecutioner::execReduce3Scalar(lc, opNum, hX, hXShapeInfo, dX, dXShapeInfo, extraParamsVals, hY, hYShapeInfo,
|
||||
dY, dYShapeInfo, hZ, hZShapeInfo, dZ, dZShapeInfo);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
void NativeOpExecutioner::execReduce3(sd::LaunchContext *lc, int opNum, const void *hX, const sd::LongType *hXShapeInfo,
|
||||
const void *dX, const sd::LongType *dXShapeInfo, void *extraParamsVals,
|
||||
const void *hY, const sd::LongType *hYShapeInfo, const void *dY,
|
||||
const sd::LongType *dYShapeInfo, void *hZ, const sd::LongType *hZShapeInfo,
|
||||
void *dZ, const sd::LongType *dZShapeInfo,sd::LongType *dimension, sd::LongType dimensionLength,
|
||||
const sd::LongType *xTadOnlyShapeInfo, const sd::LongType *xTadOffsets,
|
||||
const sd::LongType *yTadOnlyShapeInfo, const sd::LongType *yTadOffsets) {
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
|
||||
const auto xLen = shape::length(hXShapeInfo);
|
||||
const auto yLen = shape::length(hYShapeInfo);
|
||||
|
||||
std::shared_ptr<sd::TadPack> tadPack;
|
||||
sd::LongType *castedConst = const_cast<sd::LongType *>(hXShapeInfo);
|
||||
sd::LongType *hYShapeInfoNonConst = const_cast<sd::LongType *>(hYShapeInfo);
|
||||
if (xLen == yLen) {
|
||||
tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(castedConst, dimension, dimensionLength);
|
||||
} else if (yLen > xLen) {
|
||||
tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(hYShapeInfoNonConst, dimension, dimensionLength);
|
||||
} else {
|
||||
tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(castedConst, dimension, dimensionLength);
|
||||
}
|
||||
|
||||
auto func = PRAGMA_THREADS_FOR {
|
||||
BUILD_DOUBLE_SELECTOR(xType, zType, functions::reduce3::Reduce3,
|
||||
::exec(opNum, hX, hXShapeInfo, extraParamsVals, hY, hYShapeInfo, hZ, hZShapeInfo, dimension,
|
||||
dimensionLength, start, stop),
|
||||
SD_COMMON_TYPES, SD_FLOAT_TYPES);
|
||||
};
|
||||
|
||||
samediff::Threads::parallel_tad(func, 0, tadPack->numberOfTads());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
void NativeOpExecutioner::execReduce3All(sd::LaunchContext *lc, int opNum, const void *hX,
|
||||
const sd::LongType *hXShapeInfo, const void *dX,
|
||||
const sd::LongType *dXShapeInfo, void *extraParamsVals, const void *hY,
|
||||
const sd::LongType *hYShapeInfo, const void *dY,
|
||||
const sd::LongType *dYShapeInfo, void *hZ, const sd::LongType *hZShapeInfo,
|
||||
void *dZ, const sd::LongType *dZShapeInfo,sd::LongType *dimension, sd::LongType dimensionLength,
|
||||
const sd::LongType *xTadShapeInfo, const sd::LongType *xOffsets,
|
||||
const sd::LongType *yTadShapeInfo, const sd::LongType *yOffsets) {
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
|
||||
auto tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(const_cast<sd::LongType *>(hXShapeInfo), dimension, dimensionLength);
|
||||
auto func = PRAGMA_THREADS_FOR {
|
||||
BUILD_DOUBLE_SELECTOR(
|
||||
xType, zType, functions::reduce3::Reduce3,
|
||||
::execAll(opNum, hX, hXShapeInfo, extraParamsVals, hY, hYShapeInfo, hZ, hZShapeInfo, dimension, dimensionLength,
|
||||
xTadShapeInfo, xOffsets, yTadShapeInfo, yOffsets, start, stop),
|
||||
SD_COMMON_TYPES, SD_FLOAT_TYPES);
|
||||
};
|
||||
|
||||
samediff::Threads::parallel_tad(func, 0, tadPack->numberOfTads());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
void NativeOpExecutioner::execReduce3TAD(sd::LaunchContext *lc, int opNum, const void *hX,
|
||||
const sd::LongType *hXShapeInfo, const void *dX,
|
||||
const sd::LongType *dXShapeInfo, void *extraParamsVals, const void *hY,
|
||||
const sd::LongType *hYShapeInfo, const void *dY,
|
||||
const sd::LongType *dYShapeInfo, void *hZ, const sd::LongType *hZShapeInfo,
|
||||
void *dZ, const sd::LongType *dZShapeInfo,sd::LongType *dimension, sd::LongType dimensionLength,
|
||||
const sd::LongType *tadShapeInfo, const sd::LongType *tadOffsets,
|
||||
const sd::LongType *yTadShapeInfo, const sd::LongType *yTadOffsets) {
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
|
||||
const auto xLen = shape::length(hXShapeInfo);
|
||||
const auto yLen = shape::length(hYShapeInfo);
|
||||
|
||||
std::shared_ptr<sd::TadPack> tadPack;
|
||||
sd::LongType *castedConst = const_cast<sd::LongType *>(hXShapeInfo);
|
||||
sd::LongType *hYShapeInfoNonConst = const_cast<sd::LongType *>(hYShapeInfo);
|
||||
if (xLen == yLen) {
|
||||
tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(castedConst, dimension, dimensionLength);
|
||||
} else if (yLen > xLen) {
|
||||
tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(hYShapeInfoNonConst, dimension, dimensionLength);
|
||||
} else {
|
||||
tadPack = sd::ConstantTadHelper::getInstance().tadForDimensions(castedConst, dimension, dimensionLength);
|
||||
}
|
||||
auto func = PRAGMA_THREADS_FOR {
|
||||
BUILD_DOUBLE_SELECTOR(xType, zType, functions::reduce3::Reduce3,
|
||||
::exec(opNum, hX, hXShapeInfo, extraParamsVals, hY, hYShapeInfo, hZ, hZShapeInfo, dimension,
|
||||
dimensionLength, tadShapeInfo, tadOffsets, start, stop),
|
||||
SD_NUMERIC_TYPES, SD_FLOAT_TYPES);
|
||||
};
|
||||
|
||||
samediff::Threads::parallel_tad(func, 0, tadPack->numberOfTads());
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
* Scalar operations - BOOL TYPES ONLY (non-TAD version)
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#include <array/DataTypeUtils.h>
|
||||
#include <exceptions/datatype_exception.h>
|
||||
#include <execution/Threads.h>
|
||||
#include <legacy/NativeOpExecutioner.h>
|
||||
#include <loops/scalar.h>
|
||||
#include <system/op_boilerplate.h>
|
||||
#include <types/types.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
void NativeOpExecutioner::execScalarBool(sd::LaunchContext *lc, int opNum, const void *hX, const sd::LongType *hXShapeInfo,
|
||||
const void *dX, const sd::LongType *dXShapeInfo, void *hZ,
|
||||
const sd::LongType *hZShapeInfo, void *dZ, const sd::LongType *dZShapeInfo,
|
||||
const void *hScalar, const sd::LongType *hScalarShapeInfo, const void *dScalar,
|
||||
const sd::LongType *dScalarShapeInfo, void *extraParams, bool allowParallelism) {
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
auto yType = sd::ArrayOptions::dataType(hScalarShapeInfo);
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
|
||||
// Only handle operations that result in boolean output
|
||||
if (zType != sd::DataType::BOOL) {
|
||||
return; // Let other files handle non-bool result types
|
||||
}
|
||||
|
||||
auto func = PRAGMA_THREADS_FOR {
|
||||
BUILD_TRIPLE_SELECTOR(xType,yType,zType,functions::scalar::ScalarTransform,
|
||||
::transform(opNum, hX, hXShapeInfo, hZ, hZShapeInfo, hScalar, extraParams, start, stop),
|
||||
SD_COMMON_TYPES,SD_COMMON_TYPES,SD_BOOL_TYPES);
|
||||
};
|
||||
|
||||
auto zLen = shape::length(hZShapeInfo);
|
||||
samediff::Threads::parallel_for(
|
||||
func, 0, zLen, 1,
|
||||
!allowParallelism
|
||||
? 1
|
||||
: sd::math::sd_max<int>(
|
||||
1, sd::math::sd_min<int>(zLen / 1024, sd::Environment::getInstance().maxMasterThreads())));
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
* Scalar operations - FLOAT TYPES ONLY
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
// Selective rendering - include ALL types (this is the master implementation)
|
||||
#include <system/op_boilerplate.h>
|
||||
|
||||
#include <array/DataTypeUtils.h>
|
||||
#include <exceptions/datatype_exception.h>
|
||||
#include <execution/Threads.h>
|
||||
#include <legacy/NativeOpExecutioner.h>
|
||||
#include <loops/scalar.h>
|
||||
#include <types/types.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Non-TAD execScalar using BUILD_TRIPLE_SELECTOR (manageable with 4 types = 64 combinations)
|
||||
void NativeOpExecutioner::execScalar(sd::LaunchContext *lc, int opNum, const void *hX, const sd::LongType *hXShapeInfo,
|
||||
const void *dX, const sd::LongType *dXShapeInfo, void *hZ,
|
||||
const sd::LongType *hZShapeInfo, void *dZ, const sd::LongType *dZShapeInfo,
|
||||
const void *hScalar, const sd::LongType *hScalarShapeInfo, const void *dScalar,
|
||||
const sd::LongType *dScalarShapeInfo, void *extraParams, bool allowParallelism) {
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
auto yType = sd::ArrayOptions::dataType(hScalarShapeInfo);
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
|
||||
auto zLen = shape::length(hZShapeInfo);
|
||||
|
||||
auto func = PRAGMA_THREADS_FOR {
|
||||
BUILD_TRIPLE_SELECTOR(xType, yType, zType, functions::scalar::ScalarTransform,
|
||||
::transform(opNum, hX, hXShapeInfo, hZ, hZShapeInfo, hScalar, extraParams, start, stop),
|
||||
SD_COMMON_TYPES, SD_COMMON_TYPES, SD_COMMON_TYPES);
|
||||
};
|
||||
|
||||
samediff::Threads::parallel_for(
|
||||
func, 0, zLen, 1,
|
||||
!allowParallelism ? 1 : sd::math::sd_max<int>(1, sd::math::sd_min<int>(zLen / 1024, sd::Environment::getInstance().maxMasterThreads())));
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
* Scalar TAD operations - BOOL TYPES ONLY
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#include <array/DataTypeUtils.h>
|
||||
#include <exceptions/datatype_exception.h>
|
||||
#include <execution/Threads.h>
|
||||
#include <legacy/NativeOpExecutioner.h>
|
||||
#include <loops/scalar.h>
|
||||
#include <system/op_boilerplate.h>
|
||||
#include <types/types.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// TAD version of execScalarBool for bool output types
|
||||
// NOTE: extraParams comes BEFORE hZ in the TAD version signature!
|
||||
void NativeOpExecutioner::execScalarBool(sd::LaunchContext *lc, int opNum, const void *hX, const sd::LongType *hXShapeInfo,
|
||||
const void *dX, const sd::LongType *dXShapeInfo, void *extraParams, void *hZ,
|
||||
const sd::LongType *hZShapeInfo, void *dZ, const sd::LongType *dZShapeInfo,
|
||||
const void *hScalars, const sd::LongType *hScalarShapeInfo, const void *dScalars,
|
||||
const sd::LongType *dScalarShapeInfo, sd::LongType *dimension, sd::LongType dimensionLength,
|
||||
const sd::LongType *tadShapeInfo, const sd::LongType *tadOffsets,
|
||||
const sd::LongType *tadShapeInfoZ, const sd::LongType *tadOffsetsZ) {
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
auto yType = sd::ArrayOptions::dataType(hScalarShapeInfo);
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
|
||||
// Only handle operations that result in boolean output
|
||||
if (zType != sd::DataType::BOOL) {
|
||||
return; // Let other files handle non-bool result types
|
||||
}
|
||||
|
||||
auto func = PRAGMA_THREADS_FOR {
|
||||
BUILD_TRIPLE_SELECTOR(xType,yType,zType,functions::scalar::ScalarTransform,
|
||||
::transform(opNum, hX, hXShapeInfo, extraParams, hZ, hZShapeInfo, hScalars, dimension, dimensionLength,
|
||||
tadShapeInfo, tadOffsets, tadShapeInfoZ, tadOffsetsZ, start, stop),
|
||||
SD_COMMON_TYPES,SD_COMMON_TYPES,SD_BOOL_TYPES);
|
||||
};
|
||||
|
||||
auto yLen = shape::length(hScalarShapeInfo);
|
||||
samediff::Threads::parallel_tad(func, 0, yLen, 1,
|
||||
sd::math::sd_min<int>(yLen, sd::Environment::getInstance().maxMasterThreads()));
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
* Scalar TAD operations - FLOAT OUTPUT TYPES ONLY
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#include <system/op_boilerplate.h>
|
||||
|
||||
#include <array/DataTypeUtils.h>
|
||||
#include <exceptions/datatype_exception.h>
|
||||
#include <execution/Threads.h>
|
||||
#include <legacy/NativeOpExecutioner.h>
|
||||
#include <loops/scalar.h>
|
||||
#include <types/types.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// TAD execScalar - float output types only (13 x 13 x 4 = 676 combinations)
|
||||
void NativeOpExecutioner::execScalar(sd::LaunchContext *lc, int opNum, void const *hX, sd::LongType const *hXShapeInfo,
|
||||
void const *dX, sd::LongType const *dXShapeInfo, void *extraParams, void *hZ,
|
||||
sd::LongType const *hZShapeInfo, void *dZ, sd::LongType const *dZShapeInfo,
|
||||
void const *hScalars, sd::LongType const *hScalarShapeInfo, void const *dScalars,
|
||||
sd::LongType const *dScalarShapeInfo,sd::LongType *dimension, sd::LongType dimensionLength,
|
||||
sd::LongType const *tadShapeInfo, sd::LongType const *tadOffsets,
|
||||
sd::LongType const *tadShapeInfoZ, sd::LongType const *tadOffsetsZ) {
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
auto yType = sd::ArrayOptions::dataType(hScalarShapeInfo);
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
|
||||
auto yLen = shape::length(hScalarShapeInfo);
|
||||
|
||||
auto func = PRAGMA_THREADS_FOR {
|
||||
BUILD_TRIPLE_SELECTOR(xType, yType, zType, functions::scalar::ScalarTransform,
|
||||
::transform(opNum, hX, hXShapeInfo, extraParams, hZ, hZShapeInfo, hScalars, dimension, dimensionLength,
|
||||
tadShapeInfo, tadOffsets, tadShapeInfoZ, tadOffsetsZ, start, stop),
|
||||
SD_COMMON_TYPES, SD_COMMON_TYPES, SD_FLOAT_TYPES);
|
||||
};
|
||||
|
||||
samediff::Threads::parallel_tad(func, 0, yLen, 1, sd::math::sd_min<int>(yLen, sd::Environment::getInstance().maxMasterThreads()));
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
* Scalar TAD operations - INTEGER OUTPUT TYPES ONLY
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#include <system/op_boilerplate.h>
|
||||
|
||||
#include <array/DataTypeUtils.h>
|
||||
#include <exceptions/datatype_exception.h>
|
||||
#include <execution/Threads.h>
|
||||
#include <legacy/NativeOpExecutioner.h>
|
||||
#include <loops/scalar.h>
|
||||
#include <types/types.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// TAD execScalarInt - integer output types only (13 x 13 x 9 = 1,521 combinations)
|
||||
void NativeOpExecutioner::execScalarInt(sd::LaunchContext *lc, int opNum, void const *hX, sd::LongType const *hXShapeInfo,
|
||||
void const *dX, sd::LongType const *dXShapeInfo, void *extraParams, void *hZ,
|
||||
sd::LongType const *hZShapeInfo, void *dZ, sd::LongType const *dZShapeInfo,
|
||||
void const *hScalars, sd::LongType const *hScalarShapeInfo, void const *dScalars,
|
||||
sd::LongType const *dScalarShapeInfo, sd::LongType *dimension, sd::LongType dimensionLength,
|
||||
sd::LongType const *tadShapeInfo, sd::LongType const *tadOffsets,
|
||||
sd::LongType const *tadShapeInfoZ, sd::LongType const *tadOffsetsZ) {
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
auto yType = sd::ArrayOptions::dataType(hScalarShapeInfo);
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
|
||||
auto yLen = shape::length(hScalarShapeInfo);
|
||||
|
||||
auto func = PRAGMA_THREADS_FOR {
|
||||
BUILD_TRIPLE_SELECTOR(xType, yType, zType, functions::scalar::ScalarTransform,
|
||||
::transform(opNum, hX, hXShapeInfo, extraParams, hZ, hZShapeInfo, hScalars, dimension, dimensionLength,
|
||||
tadShapeInfo, tadOffsets, tadShapeInfoZ, tadOffsetsZ, start, stop),
|
||||
SD_COMMON_TYPES, SD_COMMON_TYPES, SD_INTEGER_TYPES);
|
||||
};
|
||||
|
||||
samediff::Threads::parallel_tad(func, 0, yLen, 1, sd::math::sd_min<int>(yLen, sd::Environment::getInstance().maxMasterThreads()));
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
* SummaryStats operations - uses SD_COMMON_TYPES and SD_FLOAT_TYPES
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
// Selective rendering - MUST be included before types.h to define HAS_* flags
|
||||
#include <system/selective_rendering/core.h>
|
||||
#include <system/selective_rendering/bool_types.h>
|
||||
#include <system/selective_rendering/float_types.h>
|
||||
#include <system/selective_rendering/bfloat_types.h>
|
||||
#include <system/selective_rendering/int_types.h>
|
||||
#include <system/selective_rendering/uint_types.h>
|
||||
|
||||
#include <legacy/NativeOpExecutioner.h>
|
||||
#include <loops/summarystatsreduce.h>
|
||||
#include <types/types.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
void NativeOpExecutioner::execSummaryStats(sd::LaunchContext *lc, int opNum, const void *hX,
|
||||
sd::LongType *hXShapeInfo, const void *dX,
|
||||
sd::LongType *dXShapeInfo, void *extraParams, void *hZ,
|
||||
sd::LongType *hZShapeInfo, void *dZ, sd::LongType *dZShapeInfo,
|
||||
bool biasCorrected) {
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
BUILD_DOUBLE_SELECTOR(xType, zType, functions::summarystats::SummaryStatsReduce,
|
||||
::exec(opNum, biasCorrected, const_cast<void *>(hX), hXShapeInfo, extraParams, hZ, hZShapeInfo, nullptr, 1),
|
||||
SD_COMMON_TYPES, SD_FLOAT_TYPES);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
void NativeOpExecutioner::execSummaryStatsScalar(sd::LaunchContext *lc, int opNum, const void *hX,
|
||||
sd::LongType *hXShapeInfo, const void *dX,
|
||||
sd::LongType *dXShapeInfo, void *extraParams, void *hZ,
|
||||
sd::LongType *hZShapeInfo, void *dZ,
|
||||
sd::LongType *dZShapeInfo, bool biasCorrected) {
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
BUILD_DOUBLE_SELECTOR(xType, zType, functions::summarystats::SummaryStatsReduce,
|
||||
::execScalar(opNum, biasCorrected, const_cast<void *>(hX), hXShapeInfo, extraParams, hZ, hZShapeInfo),
|
||||
SD_COMMON_TYPES, SD_FLOAT_TYPES);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
void NativeOpExecutioner::execSummaryStats(sd::LaunchContext *lc, int opNum, const void *hX,
|
||||
sd::LongType *hXShapeInfo, const void *dX,
|
||||
sd::LongType *dXShapeInfo, void *extraParams, void *hZ,
|
||||
sd::LongType *hZShapeInfo, void *dZ, sd::LongType *dZShapeInfo,
|
||||
sd::LongType *dimension, sd::LongType dimensionLength, sd::LongType *tadShapeInfo,
|
||||
sd::LongType *tadOffsets, bool biasCorrected) {
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
BUILD_DOUBLE_SELECTOR(
|
||||
xType, zType, functions::summarystats::SummaryStatsReduce,
|
||||
::exec(opNum, biasCorrected, const_cast<void *>(hX), hXShapeInfo, extraParams, hZ, hZShapeInfo, dimension, dimensionLength),
|
||||
SD_COMMON_TYPES, SD_FLOAT_TYPES);
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
* Transform operations - uses SD_COMMON_TYPES, SD_FLOAT_TYPES, SD_BOOL_TYPES, SD_STRING_TYPES
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
// Selective rendering - MUST be included before types.h to define HAS_* flags
|
||||
// Note: string_types.h removed to reduce file size - strings will be added separately later
|
||||
#include <system/selective_rendering/core.h>
|
||||
#include <system/selective_rendering/bool_types.h>
|
||||
#include <system/selective_rendering/float_types.h>
|
||||
#include <system/selective_rendering/bfloat_types.h>
|
||||
#include <system/selective_rendering/int_types.h>
|
||||
#include <system/selective_rendering/uint_types.h>
|
||||
|
||||
#include <array/DataTypeUtils.h>
|
||||
#include <exceptions/datatype_exception.h>
|
||||
#include <execution/Threads.h>
|
||||
#include <legacy/NativeOpExecutioner.h>
|
||||
#include <loops/transform_any.h>
|
||||
#include <loops/transform_bool.h>
|
||||
#include <loops/transform_float.h>
|
||||
#include <loops/transform_same.h>
|
||||
#include <loops/transform_strict.h>
|
||||
#include <types/types.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
void NativeOpExecutioner::execTransformFloat(sd::LaunchContext *lc, int opNum, const void *hX,
|
||||
const sd::LongType *hXShapeInfo, const void *dX,
|
||||
const sd::LongType *dXShapeInfo, void *hZ, const sd::LongType *hZShapeInfo,
|
||||
void *dZ, const sd::LongType *dZShapeInfo, void *extraParams) {
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
auto func = PRAGMA_THREADS_DO {
|
||||
BUILD_DOUBLE_SELECTOR(xType, zType, functions::transform::TransformFloat,
|
||||
::exec(opNum, hX, hXShapeInfo, hZ, hZShapeInfo, extraParams, thread_id, numThreads),
|
||||
SD_COMMON_TYPES, SD_FLOAT_TYPES);
|
||||
};
|
||||
|
||||
samediff::Threads::parallel_do(
|
||||
func, sd::math::sd_max<int>(1, sd::math::sd_min<int>(shape::length(hZShapeInfo) / 1024,
|
||||
sd::Environment::getInstance().maxMasterThreads())));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
void NativeOpExecutioner::execTransformBool(sd::LaunchContext *lc, int opNum, const void *hX,
|
||||
const sd::LongType *hXShapeInfo, const void *dX,
|
||||
const sd::LongType *dXShapeInfo, void *hZ, const sd::LongType *hZShapeInfo,
|
||||
void *dZ, const sd::LongType *dZShapeInfo, void *extraParams) {
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
|
||||
auto func = PRAGMA_THREADS_DO {
|
||||
BUILD_DOUBLE_SELECTOR(xType, zType, functions::transform::TransformBool,
|
||||
::exec(opNum, hX, hXShapeInfo, hZ, hZShapeInfo, extraParams, thread_id, numThreads),
|
||||
SD_COMMON_TYPES, SD_BOOL_TYPES);
|
||||
};
|
||||
|
||||
samediff::Threads::parallel_do(
|
||||
func, sd::math::sd_max<int>(1, sd::math::sd_min<int>(shape::length(hZShapeInfo) / 1024,
|
||||
sd::Environment::getInstance().maxMasterThreads())));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
void NativeOpExecutioner::execTransformAny(sd::LaunchContext *lc, int opNum, const void *hX,
|
||||
const sd::LongType *hXShapeInfo, const void *dX,
|
||||
const sd::LongType *dXShapeInfo, void *hZ, const sd::LongType *hZShapeInfo,
|
||||
void *dZ, const sd::LongType *dZShapeInfo, void *extraParams,
|
||||
bool allowParallelism) {
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
|
||||
// String type handling removed temporarily - will be added in separate file to manage compilation size
|
||||
{
|
||||
auto func = PRAGMA_THREADS_DO {
|
||||
BUILD_DOUBLE_SELECTOR(xType, zType, functions::transform::TransformAny,
|
||||
::exec(opNum,
|
||||
hX,
|
||||
hXShapeInfo,
|
||||
hZ, hZShapeInfo,
|
||||
extraParams,
|
||||
thread_id,
|
||||
numThreads),
|
||||
SD_COMMON_TYPES, SD_COMMON_TYPES);
|
||||
};
|
||||
|
||||
samediff::Threads::parallel_do(
|
||||
func, sd::math::sd_max(static_cast<sd::LongType>(1),
|
||||
sd::math::sd_min(shape::length(hZShapeInfo) / 1024,
|
||||
static_cast<sd::LongType>(sd::Environment::getInstance().maxMasterThreads()))));
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
void NativeOpExecutioner::execTransformSame(sd::LaunchContext *lc, int opNum, const void *hX,
|
||||
const sd::LongType *hXShapeInfo, const void *dX,
|
||||
const sd::LongType *dXShapeInfo, void *hZ, const sd::LongType *hZShapeInfo,
|
||||
void *dZ, const sd::LongType *dZShapeInfo, void *extraParams,
|
||||
const sd::LongType *tadShapeInfo, const sd::LongType *tadOffsets) {
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
|
||||
auto func = PRAGMA_THREADS_DO {
|
||||
BUILD_SINGLE_SELECTOR(xType, functions::transform::TransformSame,
|
||||
::exec(opNum, hX, hXShapeInfo, hZ, hZShapeInfo, extraParams, thread_id, numThreads),
|
||||
SD_COMMON_TYPES);
|
||||
};
|
||||
|
||||
samediff::Threads::parallel_do(
|
||||
func, sd::math::sd_max<int>(1, sd::math::sd_min<int>(shape::length(hZShapeInfo) / 1024,
|
||||
sd::Environment::getInstance().maxMasterThreads())));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
void NativeOpExecutioner::execTransformStrict(sd::LaunchContext *lc, int opNum, const void *hX,
|
||||
const sd::LongType *hXShapeInfo, const void *dX,
|
||||
const sd::LongType *dXShapeInfo, void *hZ,
|
||||
const sd::LongType *hZShapeInfo, void *dZ,
|
||||
const sd::LongType *dZShapeInfo, void *extraParams) {
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
auto func = PRAGMA_THREADS_DO {
|
||||
BUILD_SINGLE_SELECTOR(xType, functions::transform::TransformStrict,
|
||||
::exec(opNum, hX, hXShapeInfo, hZ, hZShapeInfo, extraParams, thread_id, numThreads),
|
||||
SD_FLOAT_TYPES);
|
||||
};
|
||||
|
||||
samediff::Threads::parallel_do(
|
||||
func, sd::math::sd_max<int>(1, sd::math::sd_min<int>(shape::length(hZShapeInfo) / 1024,
|
||||
sd::Environment::getInstance().maxMasterThreads())));
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,21 @@
|
||||
#include <legacy/NativeOps.h>
|
||||
#include <array/DataBufferLifecycleTracker.h>
|
||||
#include <array/DataBuffer.h>
|
||||
#include <vector>
|
||||
|
||||
SD_LIB_EXPORT void recordJavaDataBufferAllocation(OpaqueDataBuffer *buffer, long size, int dataType, bool isWorkspace) {
|
||||
#if defined(SD_GCC_FUNCTRACE)
|
||||
if (buffer != nullptr) {
|
||||
sd::array::DataBufferLifecycleTracker::getInstance().recordAllocation(
|
||||
buffer->primary(), size, (sd::DataType)dataType, sd::array::BufferType::PRIMARY, buffer, isWorkspace, sd::array::DataBufferSegment::JAVA);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
SD_LIB_EXPORT void recordJavaDataBufferDeallocation(OpaqueDataBuffer *buffer) {
|
||||
#if defined(SD_GCC_FUNCTRACE)
|
||||
if (buffer != nullptr) {
|
||||
sd::array::DataBufferLifecycleTracker::getInstance().recordDeallocation(buffer->primary(), sd::array::BufferType::PRIMARY);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#include <legacy/NativeOps.h>
|
||||
#include <array/NDArrayLifecycleTracker.h>
|
||||
#include <array/NDArray.h>
|
||||
#include <vector>
|
||||
|
||||
SD_LIB_EXPORT void recordJavaNDArrayAllocation(OpaqueNDArray array, long size, int dataType, bool isView) {
|
||||
#if defined(SD_GCC_FUNCTRACE)
|
||||
auto ptr = reinterpret_cast<sd::NDArray*>(array);
|
||||
std::vector<sd::LongType> shapeVector;
|
||||
if(ptr != nullptr && ptr->shapeInfo() != nullptr) {
|
||||
for(int i = 0; i < ptr->rankOf(); i++) {
|
||||
shapeVector.push_back(ptr->shapeOf()[i]);
|
||||
}
|
||||
}
|
||||
sd::array::NDArrayLifecycleTracker::getInstance().recordAllocation(
|
||||
array, size, (sd::DataType)dataType, shapeVector, isView, sd::array::NDArraySegment::JAVA);
|
||||
#endif
|
||||
}
|
||||
|
||||
SD_LIB_EXPORT void recordJavaNDArrayDeallocation(OpaqueNDArray array) {
|
||||
#if defined(SD_GCC_FUNCTRACE)
|
||||
sd::array::NDArrayLifecycleTracker::getInstance().recordDeallocation(array);
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#include <legacy/NativeOps.h>
|
||||
#include <graph/OpContextLifecycleTracker.h>
|
||||
#include <graph/Context.h>
|
||||
|
||||
|
||||
void recordJavaOpContextAllocation(OpaqueContext *context, int nodeId, long fastpathInSize, long fastpathOutSize, long intermediateResultsSize, long handlesSize, bool hasWorkspace, bool isFastPath) {
|
||||
#if defined(SD_GCC_FUNCTRACE)
|
||||
if (context != nullptr) {
|
||||
sd::graph::OpContextLifecycleTracker::getInstance().recordAllocation(
|
||||
context, nodeId, fastpathInSize, fastpathOutSize, intermediateResultsSize, handlesSize, hasWorkspace, isFastPath, sd::graph::OpContextSegment::JAVA);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void recordJavaOpContextDeallocation(OpaqueContext *context) {
|
||||
#if defined(SD_GCC_FUNCTRACE)
|
||||
if (context != nullptr) {
|
||||
sd::graph::OpContextLifecycleTracker::getInstance().recordDeallocation(context);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user